opencode-rag-plugin 1.20.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ReadMe.md CHANGED
@@ -53,9 +53,9 @@ opencode-rag query "authentication middleware"
53
53
 
54
54
  ## Web UI
55
55
 
56
- A browser-based dashboard for exploring the indexed vector database - browse and inspect chunks and evaluate the OpenCode sessions in terms of retrieved chunks, consumed tokens and more.
56
+ A browser-based dashboard for exploring the indexed vector database - browse, visualize and inspect chunks and evaluate the OpenCode sessions in terms of retrieved chunks, consumed tokens and more.
57
57
 
58
- ![OpenCodeRAG Web UI](doc/assets/webui-dashboard.png)
58
+ ![OpenCodeRAG Web UI](doc/assets/webui-3d.png)
59
59
 
60
60
  Launch with `opencode-rag ui`. See [Web UI documentation](doc/webui.md) for details.
61
61
 
package/dist/api.d.ts CHANGED
@@ -21,6 +21,8 @@ export interface SearchOptions {
21
21
  pathHints?: string[];
22
22
  /** Filter results to files matching these language identifiers. */
23
23
  languageHints?: string[];
24
+ /** Filter results to files matching these dot-prefixed extensions (e.g. [".ts"]). */
25
+ fileExtensions?: string[];
24
26
  /** Include explanation metadata in results. */
25
27
  explain?: boolean;
26
28
  }
package/dist/api.js CHANGED
@@ -56,6 +56,7 @@ export async function search(query, options = {}) {
56
56
  filter: {
57
57
  pathPatterns: options.pathHints,
58
58
  languages: options.languageHints,
59
+ fileExtensions: options.fileExtensions,
59
60
  kinds: CODE_SEARCH_FILTER.kinds,
60
61
  },
61
62
  });
@@ -1,3 +1,4 @@
1
+ import { normalizeKeepAlive } from "../core/ollama.js";
1
2
  import { postJson } from "../embedder/http.js";
2
3
  import { uuid } from "./uuid.js";
3
4
  const MAX_CHUNK_CHARS = 4000;
@@ -67,7 +68,7 @@ class OllamaImageVisionProvider {
67
68
  options: { num_ctx: this.numCtx },
68
69
  };
69
70
  if (this.keepAlive) {
70
- body.keep_alive = this.keepAlive;
71
+ body.keep_alive = normalizeKeepAlive(this.keepAlive);
71
72
  }
72
73
  let lastError;
73
74
  for (let attempt = 0; attempt <= VISION_RETRY_MAX; attempt++) {
@@ -202,7 +202,7 @@ export function generateSkillFile() {
202
202
  "",
203
203
  "### Parameters",
204
204
  "",
205
- "- `search_semantic`: `query` (req), `pathHints?`, `languageHints?`, `topK?`",
205
+ "- `search_semantic`: `query` (req), `pathHints?`, `languageHints?`, `fileExtensions?`, `topK?`",
206
206
  "- `get_file_skeleton`: `filePath` (req)",
207
207
  "- `find_usages`: `symbolName` (req), `pathHint?`, `topK?`",
208
208
  "- `describe_image`: `filePath` (req), `systemPrompt?`",
@@ -215,6 +215,7 @@ export function generateSkillFile() {
215
215
  "",
216
216
  "- Use `pathHints` to narrow searches to specific directories",
217
217
  "- Use `languageHints` to filter by file type",
218
+ "- Use `fileExtensions` to filter by file extension (e.g. `\".ts\"`)",
218
219
  "- `find_usages` is essential before refactoring — it shows every reference",
219
220
  "- Pass `systemPrompt` to `describe_image` when you need specific details (e.g. `\"focus on the chart's axes and values\"`)",
220
221
  "- If no results appear, the workspace may not be indexed yet — run `opencode-rag index`",
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @fileoverview Shared helpers for MetadataFilter matching across stores
3
+ * (LanceDB, memory, keyword index) so extension handling stays consistent.
4
+ */
5
+ /**
6
+ * Normalize a raw file-extension list: lowercase, strip leading dots so both
7
+ * "ts" and ".ts" are accepted, and re-prefix with a single dot.
8
+ * Empty/blank entries are dropped.
9
+ */
10
+ export declare function normalizeFileExtensions(extensions?: string[]): string[];
11
+ /**
12
+ * Case-insensitive suffix match of a file path against a normalized extension
13
+ * list (e.g. "src/auth.ts" matches ".ts"). Returns true when the list is empty.
14
+ */
15
+ export declare function matchesFileExtension(filePath: string, extensions: string[]): boolean;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @fileoverview Shared helpers for MetadataFilter matching across stores
3
+ * (LanceDB, memory, keyword index) so extension handling stays consistent.
4
+ */
5
+ /**
6
+ * Normalize a raw file-extension list: lowercase, strip leading dots so both
7
+ * "ts" and ".ts" are accepted, and re-prefix with a single dot.
8
+ * Empty/blank entries are dropped.
9
+ */
10
+ export function normalizeFileExtensions(extensions) {
11
+ if (!extensions)
12
+ return [];
13
+ const seen = new Set();
14
+ const out = [];
15
+ for (const raw of extensions) {
16
+ const ext = raw.trim().toLowerCase().replace(/^\.+/, "");
17
+ if (ext.length === 0)
18
+ continue;
19
+ const normalized = `.${ext}`;
20
+ if (!seen.has(normalized)) {
21
+ seen.add(normalized);
22
+ out.push(normalized);
23
+ }
24
+ }
25
+ return out;
26
+ }
27
+ /**
28
+ * Case-insensitive suffix match of a file path against a normalized extension
29
+ * list (e.g. "src/auth.ts" matches ".ts"). Returns true when the list is empty.
30
+ */
31
+ export function matchesFileExtension(filePath, extensions) {
32
+ if (extensions.length === 0)
33
+ return true;
34
+ const lower = filePath.toLowerCase();
35
+ return extensions.some((ext) => lower.endsWith(ext));
36
+ }
37
+ //# sourceMappingURL=filters.js.map
@@ -220,7 +220,7 @@ export interface VectorStore {
220
220
  */
221
221
  checkIntegrity?(): Promise<boolean>;
222
222
  }
223
- /** Filter criteria for narrowing search results by file path, language, or kind. */
223
+ /** Filter criteria for narrowing search results by file path, language, kind, or extension. */
224
224
  export interface MetadataFilter {
225
225
  /** Glob-style path patterns (e.g. "src/**", "lib/auth/*"). */
226
226
  pathPatterns?: string[];
@@ -228,6 +228,8 @@ export interface MetadataFilter {
228
228
  languages?: string[];
229
229
  /** Synthetic kind filters (e.g. ["quirk"]). */
230
230
  kinds?: string[];
231
+ /** Dot-prefixed file extensions (e.g. [".ts", ".py"]). Matching is case-insensitive. */
232
+ fileExtensions?: string[];
231
233
  }
232
234
  /**
233
235
  * Filter for general code/document retrieval that excludes quirk memory
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @fileoverview Shared Ollama request-body helpers.
3
+ */
4
+ /**
5
+ * Ollama's `keep_alive` field accepts either a duration string with a unit
6
+ * (e.g. "30m", "24h") or a bare integer (e.g. -1 for keep-in-memory forever,
7
+ * 0 to unload immediately). A bare integer passed as a string (e.g. "-1")
8
+ * fails server-side with `time: missing unit in duration "-1"`.
9
+ *
10
+ * Returns the numeric form for bare integers and passes other strings through
11
+ * unchanged.
12
+ */
13
+ export declare function normalizeKeepAlive(keepAlive?: string): string | number | undefined;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @fileoverview Shared Ollama request-body helpers.
3
+ */
4
+ /**
5
+ * Ollama's `keep_alive` field accepts either a duration string with a unit
6
+ * (e.g. "30m", "24h") or a bare integer (e.g. -1 for keep-in-memory forever,
7
+ * 0 to unload immediately). A bare integer passed as a string (e.g. "-1")
8
+ * fails server-side with `time: missing unit in duration "-1"`.
9
+ *
10
+ * Returns the numeric form for bare integers and passes other strings through
11
+ * unchanged.
12
+ */
13
+ export function normalizeKeepAlive(keepAlive) {
14
+ if (keepAlive === undefined || keepAlive === "") {
15
+ return undefined;
16
+ }
17
+ if (/^-?\d+$/.test(keepAlive)) {
18
+ return Number(keepAlive);
19
+ }
20
+ return keepAlive;
21
+ }
22
+ //# sourceMappingURL=ollama.js.map
@@ -1,3 +1,4 @@
1
+ import { normalizeKeepAlive } from "../core/ollama.js";
1
2
  import { postJson } from "../embedder/http.js";
2
3
  import { buildUserMessage, buildBatchUserMessage, parseBatchDescriptions, sleep } from "./shared.js";
3
4
  import pLimit from "p-limit";
@@ -178,7 +179,7 @@ export class LlmDescriptionProvider {
178
179
  ? `${baseUrl}/chat`
179
180
  : `${baseUrl}${baseUrl.endsWith("/v1") ? "" : "/v1"}/chat/completions`;
180
181
  const body = isOllama
181
- ? { model: this.config.model, messages, stream: false, think: this.config.think ?? false, options: { num_ctx: this.config.numCtx }, keep_alive: this.config.keepAlive }
182
+ ? { model: this.config.model, messages, stream: false, think: this.config.think ?? false, options: { num_ctx: this.config.numCtx }, keep_alive: normalizeKeepAlive(this.config.keepAlive) }
182
183
  : { model: this.config.model, messages };
183
184
  const headers = {};
184
185
  if (this.config.apiKey) {
@@ -1,3 +1,4 @@
1
+ import { normalizeKeepAlive } from "../core/ollama.js";
1
2
  import { postJson } from "./http.js";
2
3
  import path from "node:path";
3
4
  import { appendDebugLog } from "../core/fileLogger.js";
@@ -51,8 +52,9 @@ export class OllamaProvider {
51
52
  model: this.model,
52
53
  input: texts.length === 1 ? texts[0] : texts,
53
54
  };
54
- if (this.keepAlive) {
55
- body.keep_alive = this.keepAlive;
55
+ const keepAlive = normalizeKeepAlive(this.keepAlive);
56
+ if (keepAlive !== undefined) {
57
+ body.keep_alive = keepAlive;
56
58
  }
57
59
  const response = await postJson(`${this.baseUrl}/embed`, body, headers, this.timeoutMs, this.proxy);
58
60
  if (!response.ok) {
@@ -22,6 +22,8 @@ export interface SearchSemanticParams {
22
22
  pathHints?: string[];
23
23
  /** Optional language hints to filter by language. */
24
24
  languageHints?: string[];
25
+ /** Optional dot-prefixed file extensions to filter by (e.g. [".ts"]). */
26
+ fileExtensions?: string[];
25
27
  /** Maximum number of results (1-25). */
26
28
  topK?: number;
27
29
  }
@@ -2,6 +2,7 @@
2
2
  * @fileoverview Handler implementations for all MCP tools: semantic search, file skeleton, symbol usage lookup, and image description.
3
3
  */
4
4
  import { CODE_SEARCH_FILTER } from "../core/interfaces.js";
5
+ import { normalizeFileExtensions } from "../core/filters.js";
5
6
  import { SUPPORTED_IMAGE_EXTENSIONS } from "../chunker/image.js";
6
7
  import { retrieve } from "../retriever/retriever.js";
7
8
  import { optimizeContext, DEFAULT_CONTEXT_OPTIMIZATION } from "../retriever/context-optimizer.js";
@@ -177,6 +178,10 @@ export async function handleSearchSemantic(params, embedder, store, cfg, keyword
177
178
  parts.push(`Language hints: ${params.languageHints.join(", ")}`);
178
179
  const query = parts.join("\n");
179
180
  const topK = params.topK ?? cfg.retrieval.topK;
181
+ const fileExtensions = normalizeFileExtensions(params.fileExtensions);
182
+ const filter = fileExtensions.length > 0
183
+ ? { ...CODE_SEARCH_FILTER, fileExtensions }
184
+ : CODE_SEARCH_FILTER;
180
185
  const retrieveOpts = {
181
186
  topK,
182
187
  minScore: cfg.retrieval.minScore,
@@ -184,7 +189,7 @@ export async function handleSearchSemantic(params, embedder, store, cfg, keyword
184
189
  keywordWeight: cfg.retrieval.hybridSearch?.keywordWeight,
185
190
  hybridEnabled: cfg.retrieval.hybridSearch?.enabled,
186
191
  queryPrefix: cfg.embedding.queryPrefix,
187
- filter: CODE_SEARCH_FILTER,
192
+ filter,
188
193
  };
189
194
  const rawResults = await retrieveFn_(query, embedder, store, retrieveOpts);
190
195
  if (rawResults.length === 0) {
@@ -23,6 +23,7 @@ export async function createMcpServer(options) {
23
23
  query: z.string().min(1, "A search query is required."),
24
24
  pathHints: z.array(z.string().min(1)).max(10).optional(),
25
25
  languageHints: z.array(z.string().min(1)).max(10).optional(),
26
+ fileExtensions: z.array(z.string().min(1)).max(10).optional(),
26
27
  topK: z.number().int().min(1).max(25).optional(),
27
28
  }, async (args) => {
28
29
  try {
@@ -14,7 +14,7 @@ export const END_MARKER = "<!-- END opencode-rag -->";
14
14
  */
15
15
  export const MANDATORY_GUIDANCE_LINES = [
16
16
  "MANDATORY: OpenCodeRAG tools MUST be used before any code task:",
17
- "- `search_semantic(query)`: retrieve relevant code chunks. Call BEFORE planning, editing, or answering. Accepts `pathHints` and `languageHints`.",
17
+ "- `search_semantic(query)`: retrieve relevant code chunks. Call BEFORE planning, editing, or answering. Accepts `pathHints`, `languageHints`, and `fileExtensions`.",
18
18
  "- `get_file_skeleton(filePath)`: structural overview of a file. Call BEFORE reading any file.",
19
19
  "- `find_usages(symbolName)`: find all references. Call BEFORE editing any function, class, or variable.",
20
20
  "- `describe_image(filePath, systemPrompt?)`: describe an image file using a vision model. Call when user refers to a screenshot, diagram, or image. Optional `systemPrompt` steers the description toward specific features.",
package/dist/plugin.js CHANGED
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { tool } from "@opencode-ai/plugin/tool";
7
7
  import { CODE_SEARCH_FILTER } from "./core/interfaces.js";
8
+ import { normalizeFileExtensions } from "./core/filters.js";
8
9
  import { loadConfig, findConfigFile, DEFAULT_CONFIG, resolveLogConfig, persistProbedDimension } from "./core/config.js";
9
10
  import { createEmbedder } from "./embedder/factory.js";
10
11
  import { createDescriptionProvider } from "./describer/factory.js";
@@ -298,23 +299,23 @@ function buildRetrievalQuery(hints) {
298
299
  * Perform a retrieval query against the vector store with the given parameters.
299
300
  * Returns an empty array for blank queries.
300
301
  */
301
- async function retrieveContext(query, embedder, store, topK, retrieveFn = retrieve, minScore = 0, keywordIndex, keywordWeight, queryPrefix, explain = false, hybridEnabled) {
302
+ async function retrieveContext(query, embedder, store, topK, retrieveFn = retrieve, minScore = 0, keywordIndex, keywordWeight, queryPrefix, explain = false, hybridEnabled, filter) {
302
303
  if (query.trim().length === 0)
303
304
  return [];
304
- return retrieveFn(query, embedder, store, { topK, minScore, keywordIndex, keywordWeight, hybridEnabled, queryPrefix, explain });
305
+ return retrieveFn(query, embedder, store, { topK, minScore, keywordIndex, keywordWeight, hybridEnabled, queryPrefix, explain, filter });
305
306
  }
306
307
  /**
307
308
  * Load results from one or two queries (primary + optional extra), optimize
308
309
  * them via context optimization (adjacent merge, similarity dedup, file cap),
309
310
  * sort by descending score, and limit to maxContextChunks from config.
310
311
  */
311
- async function loadRetrievedResults(query, embedder, store, cfg, retrieveFn = retrieve, topK = cfg.retrieval.topK, extraQuery, keywordIndex, queryPrefix, explain = false) {
312
+ async function loadRetrievedResults(query, embedder, store, cfg, retrieveFn = retrieve, topK = cfg.retrieval.topK, extraQuery, keywordIndex, queryPrefix, explain = false, filter) {
312
313
  const minScore = cfg.retrieval.minScore;
313
314
  const kw = cfg.retrieval.hybridSearch?.keywordWeight;
314
315
  const hybridEnabled = cfg.retrieval.hybridSearch?.enabled;
315
- const primaryResults = await retrieveContext(query, embedder, store, topK, retrieveFn, minScore, keywordIndex, kw, queryPrefix, explain, hybridEnabled);
316
+ const primaryResults = await retrieveContext(query, embedder, store, topK, retrieveFn, minScore, keywordIndex, kw, queryPrefix, explain, hybridEnabled, filter);
316
317
  const extraResults = extraQuery
317
- ? await retrieveContext(extraQuery, embedder, store, topK, retrieveFn, minScore, keywordIndex, kw, queryPrefix, explain, hybridEnabled)
318
+ ? await retrieveContext(extraQuery, embedder, store, topK, retrieveFn, minScore, keywordIndex, kw, queryPrefix, explain, hybridEnabled, filter)
318
319
  : [];
319
320
  const optCfg = cfg.retrieval.contextOptimization ?? DEFAULT_CONTEXT_OPTIMIZATION;
320
321
  return optimizeContext([...primaryResults, ...extraResults], { topK, config: optCfg })
@@ -467,6 +468,7 @@ export function createRagHooks(options) {
467
468
  query: tool.schema.string().min(1, "A retrieval query is required."),
468
469
  pathHints: tool.schema.array(tool.schema.string().min(1)).max(10).optional(),
469
470
  languageHints: tool.schema.array(tool.schema.string().min(1)).max(10).optional(),
471
+ fileExtensions: tool.schema.array(tool.schema.string().min(1)).max(10).optional(),
470
472
  topK: tool.schema.number().int().min(1).max(25).optional(),
471
473
  explain: tool.schema.boolean().optional(),
472
474
  },
@@ -478,6 +480,7 @@ export function createRagHooks(options) {
478
480
  query: args.query,
479
481
  pathHints: args.pathHints ?? [],
480
482
  languageHints: args.languageHints ?? [],
483
+ fileExtensions: args.fileExtensions ?? [],
481
484
  topK: args.topK ?? getEffectiveCfg().retrieval.topK,
482
485
  });
483
486
  return {
@@ -498,12 +501,15 @@ export function createRagHooks(options) {
498
501
  });
499
502
  const topK = args.topK ?? effectiveCfg.retrieval.topK;
500
503
  const explain = args.explain ?? false;
501
- const results = await loadRetrievedResults(query, embedder, store, effectiveCfg, dependencies.retrieve, topK, undefined, keywordIndex, effectiveCfg.embedding.queryPrefix, explain);
504
+ const fileExtensions = normalizeFileExtensions(args.fileExtensions);
505
+ const filter = fileExtensions.length > 0 ? { fileExtensions } : undefined;
506
+ const results = await loadRetrievedResults(query, embedder, store, effectiveCfg, dependencies.retrieve, topK, undefined, keywordIndex, effectiveCfg.embedding.queryPrefix, explain, filter);
502
507
  if (results.length === 0) {
503
508
  appendVerboseLog(options.logFilePath, CONTEXT_TOOL_NAME, "retrieval completed with no matching chunks", {
504
509
  query,
505
510
  pathHints: args.pathHints ?? [],
506
511
  languageHints: args.languageHints ?? [],
512
+ fileExtensions: args.fileExtensions ?? [],
507
513
  topK,
508
514
  });
509
515
  return {
@@ -521,6 +527,7 @@ export function createRagHooks(options) {
521
527
  query,
522
528
  pathHints: args.pathHints ?? [],
523
529
  languageHints: args.languageHints ?? [],
530
+ fileExtensions: args.fileExtensions ?? [],
524
531
  topK,
525
532
  results: results.map((result) => ({
526
533
  filePath: result.chunk.metadata.filePath,
@@ -541,6 +548,7 @@ export function createRagHooks(options) {
541
548
  indexed: true,
542
549
  pathHints: args.pathHints ?? [],
543
550
  languageHints: args.languageHints ?? [],
551
+ fileExtensions: args.fileExtensions ?? [],
544
552
  },
545
553
  };
546
554
  }
@@ -1,4 +1,5 @@
1
1
  import { normalizeFilePath } from "../core/manifest.js";
2
+ import { normalizeFileExtensions, matchesFileExtension } from "../core/filters.js";
2
3
  const INDEX_VERSION = 2;
3
4
  /** Suffix-stripping stemmer. Only stems words >= 6 characters to reduce false positives. */
4
5
  function stem(word) {
@@ -304,6 +305,8 @@ function matchesFilter(chunk, filter) {
304
305
  if (filter.pathPatterns?.length) {
305
306
  return filter.pathPatterns.some((p) => globMatch(p, chunk.metadata.filePath));
306
307
  }
308
+ if (!matchesFileExtension(chunk.metadata.filePath, normalizeFileExtensions(filter.fileExtensions)))
309
+ return false;
307
310
  return true;
308
311
  }
309
312
  //# sourceMappingURL=keyword-index.js.map
@@ -5,6 +5,7 @@ import * as lancedb from "@lancedb/lancedb";
5
5
  import fs from "node:fs/promises";
6
6
  import path from "node:path";
7
7
  import { normalizeFilePath, manifestPathFor } from "../core/manifest.js";
8
+ import { normalizeFileExtensions, matchesFileExtension } from "../core/filters.js";
8
9
  const TABLE_NAME = "chunks";
9
10
  const QUERY_COLUMNS = ["id", "content", "description", "filePath", "startLine", "endLine", "language", "kind", "quirkType", "tags"];
10
11
  /**
@@ -1234,6 +1235,10 @@ function buildWhereClause(filter) {
1234
1235
  });
1235
1236
  parts.push(`(${likes.join(" OR ")})`);
1236
1237
  }
1238
+ if (filter.fileExtensions?.length) {
1239
+ const likes = normalizeFileExtensions(filter.fileExtensions).map((ext) => `filePath LIKE '%${ext}'`);
1240
+ parts.push(`(${likes.join(" OR ")})`);
1241
+ }
1237
1242
  return parts.length ? parts.join(" AND ") : undefined;
1238
1243
  }
1239
1244
  /** Client-side metadata filter for use as a fallback when LanceDB WHERE panics. */
@@ -1247,6 +1252,8 @@ function matchesFilterLocal(chunk, filter) {
1247
1252
  if (filter.pathPatterns?.length) {
1248
1253
  return filter.pathPatterns.some((p) => globMatchLocal(p, chunk.metadata.filePath));
1249
1254
  }
1255
+ if (!matchesFileExtension(chunk.metadata.filePath, normalizeFileExtensions(filter.fileExtensions)))
1256
+ return false;
1250
1257
  return true;
1251
1258
  }
1252
1259
  function globMatchLocal(pattern, filePath) {
@@ -1,3 +1,4 @@
1
+ import { normalizeFileExtensions, matchesFileExtension } from "../core/filters.js";
1
2
  /** Ephemeral in-memory vector store using cosine similarity search. */
2
3
  export class InMemoryVectorStore {
3
4
  chunks = [];
@@ -123,6 +124,8 @@ function matchesFilter(chunk, filter) {
123
124
  if (filter.pathPatterns?.length) {
124
125
  return filter.pathPatterns.some((p) => globMatch(p, chunk.metadata.filePath));
125
126
  }
127
+ if (!matchesFileExtension(chunk.metadata.filePath, normalizeFileExtensions(filter.fileExtensions)))
128
+ return false;
126
129
  return true;
127
130
  }
128
131
  function cosineSimilarity(a, b) {
package/dist/web/api.js CHANGED
@@ -384,7 +384,7 @@ async function handleSearch(keywordIndex, params) {
384
384
  }
385
385
  /**
386
386
  * Perform a full vector+hybrid semantic search via the retrieve() pipeline.
387
- * Accepts GET or POST with query parameters: q, topK, minScore, keywordWeight, hybrid, path, lang, explain.
387
+ * Accepts GET or POST with query parameters: q, topK, minScore, keywordWeight, hybrid, path, lang, ext, explain.
388
388
  * The embedder is lazily initialized on the first call; returns 202 if still initializing.
389
389
  */
390
390
  async function handleRetrieve(store, keywordIndex, getEmbedder, cfg, params) {
@@ -414,6 +414,7 @@ async function handleRetrieve(store, keywordIndex, getEmbedder, cfg, params) {
414
414
  const explain = params.get("explain") !== "false";
415
415
  const pathFilter = params.get("path") ?? undefined;
416
416
  const langFilter = params.get("lang") ?? undefined;
417
+ const extFilter = params.get("ext") ?? undefined;
417
418
  try {
418
419
  const results = await retrieve(q, embedder, store, {
419
420
  topK,
@@ -426,6 +427,7 @@ async function handleRetrieve(store, keywordIndex, getEmbedder, cfg, params) {
426
427
  filter: {
427
428
  pathPatterns: pathFilter ? pathFilter.split(",").map((s) => s.trim()).filter(Boolean) : undefined,
428
429
  languages: langFilter ? langFilter.split(",").map((s) => s.trim()).filter(Boolean) : undefined,
430
+ fileExtensions: extFilter ? extFilter.split(",").map((s) => s.trim()).filter(Boolean) : undefined,
429
431
  kinds: CODE_SEARCH_FILTER.kinds,
430
432
  },
431
433
  });
@@ -1,4 +1,4 @@
1
- import{A as vi,h as Mi,u as Vl}from"./index-BdPHzjQh.js";import"./vendor-Dy7HKFCY.js";/**
1
+ import{A as vi,h as Mi,u as Vl}from"./index-DOSfQsyL.js";import"./vendor-Dy7HKFCY.js";/**
2
2
  * @license
3
3
  * Copyright 2010-2026 Three.js Authors
4
4
  * SPDX-License-Identifier: MIT
@@ -0,0 +1,4 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ScatterPlot3D-CzbmvDSQ.js","assets/vendor-Dy7HKFCY.js"])))=>i.map(i=>d[i]);
2
+ import{l as D,S as ie,C as Ne,t as cn,k as rt,F as it,R as dn}from"./vendor-Dy7HKFCY.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))l(r);new MutationObserver(r=>{for(const a of r)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&l(i)}).observe(document,{childList:!0,subtree:!0});function s(r){const a={};return r.integrity&&(a.integrity=r.integrity),r.referrerPolicy&&(a.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?a.credentials="include":r.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function l(r){if(r.ep)return;r.ep=!0;const a=s(r);fetch(r.href,a)}})();var un=0;function t(e,n,s,l,r,a){n||(n={});var i,o,c=n;if("ref"in c)for(o in c={},n)o=="ref"?i=n[o]:c[o]=n[o];var d={type:e,props:c,key:s,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--un,__i:-1,__u:0,__source:r,__self:a};if(typeof e=="function"&&(i=e.defaultProps))for(o in i)c[o]===void 0&&(c[o]=i[o]);return D.vnode&&D.vnode(d),d}var Fe,E,tt,pt,Ae=0,Kt=[],A=D,xt=A.__b,vt=A.__r,gt=A.diffed,bt=A.__c,_t=A.unmount,yt=A.__;function dt(e,n){A.__h&&A.__h(E,e,Ae||n),Ae=0;var s=E.__H||(E.__H={__:[],__h:[]});return e>=s.__.length&&s.__.push({}),s.__[e]}function g(e){return Ae=1,hn(Wt,e)}function hn(e,n,s){var l=dt(Fe++,2);if(l.t=e,!l.__c&&(l.__=[s?s(n):Wt(void 0,n),function(o){var c=l.__N?l.__N[0]:l.__[0],d=l.t(c,o);c!==d&&(l.__N=[d,l.__[1]],l.__c.setState({}))}],l.__c=E,!E.__f)){var r=function(o,c,d){if(!l.__c.__H)return!0;var u=!1,f=l.__c.props!==o;if(l.__c.__H.__.some(function(h){if(h.__N){u=!0;var p=h.__[0];h.__=h.__N,h.__N=void 0,p!==h.__[0]&&(f=!0)}}),a){var x=a.call(this,o,c,d);return u?x||f:x}return!u||f};E.__f=!0;var a=E.shouldComponentUpdate,i=E.componentWillUpdate;E.componentWillUpdate=function(o,c,d){if(this.__e){var u=a;a=void 0,r(o,c,d),a=u}i&&i.call(this,o,c,d)},E.shouldComponentUpdate=r}return l.__N||l.__}function O(e,n){var s=dt(Fe++,3);!A.__s&&Bt(s.__H,n)&&(s.__=e,s.u=n,E.__H.__h.push(s))}function te(e){return Ae=5,le(function(){return{current:e}},[])}function le(e,n){var s=dt(Fe++,7);return Bt(s.__H,n)&&(s.__=e(),s.__H=n,s.__h=e),s.__}function Nt(e,n){return Ae=8,le(function(){return e},n)}function fn(){for(var e;e=Kt.shift();){var n=e.__H;if(e.__P&&n)try{n.__h.some(Be),n.__h.some(ot),n.__h=[]}catch(s){n.__h=[],A.__e(s,e.__v)}}}A.__b=function(e){E=null,xt&&xt(e)},A.__=function(e,n){e&&n.__k&&n.__k.__m&&(e.__m=n.__k.__m),yt&&yt(e,n)},A.__r=function(e){vt&&vt(e),Fe=0;var n=(E=e.__c).__H;n&&(tt===E?(n.__h=[],E.__h=[],n.__.some(function(s){s.__N&&(s.__=s.__N),s.u=s.__N=void 0})):(n.__h.some(Be),n.__h.some(ot),n.__h=[],Fe=0)),tt=E},A.diffed=function(e){gt&&gt(e);var n=e.__c;n&&n.__H&&(n.__H.__h.length&&(Kt.push(n)!==1&&pt===A.requestAnimationFrame||((pt=A.requestAnimationFrame)||mn)(fn)),n.__H.__.some(function(s){s.u&&(s.__H=s.u,s.u=void 0)})),tt=E=null},A.__c=function(e,n){n.some(function(s){try{s.__h.some(Be),s.__h=s.__h.filter(function(l){return!l.__||ot(l)})}catch(l){n.some(function(r){r.__h&&(r.__h=[])}),n=[],A.__e(l,s.__v)}}),bt&&bt(e,n)},A.unmount=function(e){_t&&_t(e);var n,s=e.__c;s&&s.__H&&(s.__H.__.some(function(l){try{Be(l)}catch(r){n=r}}),s.__H=void 0,n&&A.__e(n,s.__v))};var wt=typeof requestAnimationFrame=="function";function mn(e){var n,s=function(){clearTimeout(l),wt&&cancelAnimationFrame(n),setTimeout(e)},l=setTimeout(s,35);wt&&(n=requestAnimationFrame(s))}function Be(e){var n=E,s=e.__c;typeof s=="function"&&(e.__c=void 0,s()),E=n}function ot(e){var n=E;e.__c=e.__(),E=n}function Bt(e,n){return!e||e.length!==n.length||n.some(function(s,l){return s!==e[l]})}function Wt(e,n){return typeof n=="function"?n(e):n}function kt(){const e=location.hash.slice(1)||"dashboard",n=e.indexOf("?"),s=n>=0?e.slice(0,n):e,l={};if(n>=0){const r=e.slice(n+1);for(const a of r.split("&")){const i=a.indexOf("=");if(i>=0)try{l[decodeURIComponent(a.slice(0,i))]=decodeURIComponent(a.slice(i+1))}catch{}}}return{view:s||"dashboard",params:l}}function De(){const[e,n]=g(kt);return O(()=>{const s=()=>n(kt());return addEventListener("hashchange",s),()=>removeEventListener("hashchange",s)},[]),e}var pn=Symbol.for("preact-signals");function Je(){if(ne>1)ne--;else{var e,n=!1;for(function(){var r=Ge;for(Ge=void 0;r!==void 0;){var a=r.S;if(a.v===r.v)for(var i=a.t;i!==void 0;i=i.x)i.i===r.i&&(i.i=a.i);r=r.o}}();Ee!==void 0;){var s=Ee;for(Ee=void 0,Ve++;s!==void 0;){var l=s.u;if(s.u=void 0,s.f&=-3,!(8&s.f)&&Gt(s))try{s.c()}catch(r){n||(e=r,n=!0)}s=l}}if(Ve=0,ne--,n)throw e}}function xn(e){if(ne>0)return e();ct=++vn,ne++;try{return e()}finally{Je()}}var Re,C=void 0;function et(e){var n=C,s=Re;C=void 0,Re=void 0;try{return e()}finally{C=n,Re=s}}var Ee=void 0,ne=0,Ve=0,vn=0,ct=0,Ge=void 0,Qe=0;function Vt(e){if(C!==void 0){var n=e.n;if(n===void 0||n.t!==C)return n={i:0,S:e,p:C.s,n:void 0,t:C,e:void 0,x:void 0,r:n},C.s!==void 0&&(C.s.n=n),C.s=n,e.n=n,32&C.f&&e.S(n),n;if(n.i===-1)return n.i=0,n.n!==void 0&&(n.n.p=n.p,n.p!==void 0&&(n.p.n=n.n),n.p=C.s,n.n=void 0,C.s.n=n,C.s=n),n}}function U(e,n){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=n==null?void 0:n.watched,this.Z=n==null?void 0:n.unwatched,this.name=n==null?void 0:n.name}U.prototype.brand=pn;U.prototype.h=function(){return!0};U.prototype.S=function(e){var n=this,s=this.t;s!==e&&e.e===void 0&&(e.x=s,this.t=e,s!==void 0?s.e=e:et(function(){var l;(l=n.W)==null||l.call(n)}))};U.prototype.U=function(e){var n=this;if(this.t!==void 0){var s=e.e,l=e.x;s!==void 0&&(s.x=l,e.e=void 0),l!==void 0&&(l.e=s,e.x=void 0),e===this.t&&(this.t=l,l===void 0&&et(function(){var r;(r=n.Z)==null||r.call(n)}))}};U.prototype.subscribe=function(e){var n=this;return Oe(function(){var s=n.value;et(function(){return e(s)})},{name:"sub"})};U.prototype.valueOf=function(){return this.value};U.prototype.toString=function(){return this.value+""};U.prototype.toJSON=function(){return this.value};U.prototype.peek=function(){var e=this;return et(function(){return e.value})};Object.defineProperty(U.prototype,"value",{get:function(){var e=Vt(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ve>100)throw new Error("Cycle detected");(function(s){ne!==0&&Ve===0&&s.l!==ct&&(s.l=ct,Ge={S:s,v:s.v,i:s.i,o:Ge})})(this),this.v=e,this.i++,Qe++,ne++;try{for(var n=this.t;n!==void 0;n=n.x)n.t.N()}finally{Je()}}}});function L(e,n){return new U(e,n)}function Gt(e){for(var n=e.s;n!==void 0;n=n.n)if(n.S.i!==n.i||!n.S.h()||n.S.i!==n.i)return!0;return!1}function Qt(e){for(var n=e.s;n!==void 0;n=n.n){var s=n.S.n;if(s!==void 0&&(n.r=s),n.S.n=n,n.i=-1,n.n===void 0){e.s=n;break}}}function Xt(e){for(var n=e.s,s=void 0;n!==void 0;){var l=n.p;n.i===-1?(n.S.U(n),l!==void 0&&(l.n=n.n),n.n!==void 0&&(n.n.p=l)):s=n,n.S.n=n.r,n.r!==void 0&&(n.r=void 0),n=l}e.s=s}function ue(e,n){U.call(this,void 0,n),this.x=e,this.s=void 0,this.g=Qe-1,this.f=4}ue.prototype=new U;ue.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Qe))return!0;if(this.g=Qe,this.f|=1,this.i>0&&!Gt(this))return this.f&=-2,!0;var e=C;try{Qt(this),C=this;var n=this.x();(16&this.f||this.v!==n||this.i===0)&&(this.v=n,this.f&=-17,this.i++)}catch(s){this.v=s,this.f|=16,this.i++}return C=e,Xt(this),this.f&=-2,!0};ue.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var n=this.s;n!==void 0;n=n.n)n.S.S(n)}U.prototype.S.call(this,e)};ue.prototype.U=function(e){if(this.t!==void 0&&(U.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var n=this.s;n!==void 0;n=n.n)n.S.U(n)}};ue.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(ue.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Vt(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function St(e,n){return new ue(e,n)}function Zt(e){var n=e.m;if(e.m=void 0,typeof n=="function"){ne++;var s=C;C=void 0;try{n()}catch(l){throw e.f&=-2,e.f|=8,ut(e),l}finally{C=s,Je()}}}function ut(e){for(var n=e.s;n!==void 0;n=n.n)n.S.U(n);e.x=void 0,e.s=void 0,Zt(e)}function gn(e){if(C!==this)throw new Error("Out-of-order effect");Xt(this),C=e,this.f&=-2,8&this.f&&ut(this),Je()}function we(e,n){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=n==null?void 0:n.name,Re&&Re.push(this)}we.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var n=this.x();typeof n=="function"&&(this.m=n)}finally{e()}};we.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Zt(this),Qt(this),ne++;var e=C;return C=this,gn.bind(this,e)};we.prototype.N=function(){2&this.f||(this.f|=2,this.u=Ee,Ee=this)};we.prototype.d=function(){this.f|=8,1&this.f||ut(this)};we.prototype.dispose=function(){this.d()};function Oe(e,n){var s=new we(e,n);try{s.c()}catch(r){throw s.d(),r}var l=s.d.bind(s);return l[Symbol.dispose]=l,l}var Yt,ze,bn=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Jt=[];Oe(function(){Yt=this.N})();function ke(e,n){D[e]=n.bind(null,D[e]||function(){})}function Xe(e){if(ze){var n=ze;ze=void 0,n()}ze=e&&e.S()}function en(e){var n=this,s=e.data,l=yn(s);l.name="ReactiveDom",l.value=s;var r=le(function(){for(var o=n,c=n.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=St(function(){var h=l.value.value;return h===0?0:h===!0?"":h||""}),u=St(function(){return!Array.isArray(d.value)&&!cn(d.value)}),f=Oe(function(){if(this.N=tn,u.value){var h=d.value;o.__v&&o.__v.__e&&o.__v.__e.nodeType===3&&(o.__v.__e.data=h)}}),x=n.__$u.d;return n.__$u.d=function(){f(),x.call(this)},[u,d]},[]),a=r[0],i=r[1];return a.value?i.peek():i.value}en.displayName="ReactiveTextNode";Object.defineProperties(U.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:en},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});ke("__b",function(e,n){if(typeof n.type=="string"){var s,l=n.props;for(var r in l)if(r!=="children"){var a=l[r];a instanceof U&&(s||(n.__np=s={}),s[r]=a,l[r]=a.peek())}}e(n)});ke("__r",function(e,n){if(e(n),n.type!==ie){Xe();var s,l=n.__c;l&&(l.__$f&=-2,(s=l.__$u)===void 0&&(l.__$u=s=function(r,a){var i;return Oe(function(){i=this},{name:a}),i.c=r,i}(function(){var r;bn&&((r=s.y)==null||r.call(s)),l.__$f|=1,l.setState({})},typeof n.type=="function"?n.type.displayName||n.type.name:""))),Xe(s)}});ke("__e",function(e,n,s,l){Xe(),e(n,s,l)});ke("diffed",function(e,n){Xe();var s;if(typeof n.type=="string"&&(s=n.__e)){var l=n.__np,r=n.props,a=s.U;if(a)for(var i in a){var o=a[i];o===void 0||l&&i in l||(o.d(),a[i]=void 0)}if(l){a||(a={},s.U=a);for(var c in l){var d=a[c],u=l[c];d===void 0?(d=_n(s,c,u,r),a[c]=d):d.o(u,r)}}}e(n)});function _n(e,n,s,l){var r=n in e&&e.ownerSVGElement===void 0,a=L(s);return{o:function(i,o){a.value=i,l=o},d:Oe(function(){this.N=tn;var i=a.value.value;l[n]!==i&&(l[n]=i,r?e[n]=i:i!=null&&(i!==!1||n[4]==="-")?e.setAttribute(n,i):e.removeAttribute(n))})}}ke("unmount",function(e,n){if(typeof n.type=="string"){var s=n.__e;if(s){var l=s.U;if(l){s.U=void 0;for(var r in l){var a=l[r];a&&a.d()}}}var i=n.__np;if(i){var o=n.props;for(var c in i)o[c]=i[c]}n.__np=void 0}else{var d=n.__c;if(d){var u=d.__$u;u&&(d.__$u=void 0,u.d())}}e(n)});ke("__h",function(e,n,s,l){l<3&&(n.__$f|=2),e(n,s,l)});Ne.prototype.shouldComponentUpdate=function(e,n){if(this.__R)return!0;var s=this.__$u,l=s&&s.s!==void 0;for(var r in n)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var a=2&this.__$f;if(!(l||a||4&this.__$f)||1&this.__$f)return!0}else if(!(l||4&this.__$f)||3&this.__$f)return!0;for(var i in e)if(i!=="__source"&&e[i]!==this.props[i])return!0;for(var o in this.props)if(!(o in e))return!0;return!1};function yn(e,n){return le(function(){return L(e,n)},[])}var Nn=function(e){queueMicrotask(function(){queueMicrotask(e)})};function wn(){xn(function(){for(var e;e=Jt.shift();)Yt.call(e)})}function tn(){Jt.push(this)===1&&(D.requestAnimationFrame||Nn)(wn)}const nt=L("dashboard"),de=L(null),_e=L(null),ye=L(null),Pe=L(0),kn=L(50),X=L(new Set),st=L(new Set),W=L(""),b=L({topK:10,minScore:.35,keywordWeight:.4,hybrid:!0,pathFilter:"",langFilter:"",extFilter:""}),ae=L([]),Ze=L([]);L(!1);L(null);L([]);L(new Set);L(null);L(null);const se=L(typeof localStorage<"u"?localStorage.getItem("theme")??"dark":"dark"),qe=L(!0),Ie=L([]);let Sn=0;function re(e,n,s=4e3){const l=Sn++;Ie.value=[...Ie.value,{id:l,type:e,message:n,duration:s}],setTimeout(()=>{Ie.value=Ie.value.filter(r=>r.id!==l)},s)}function j(e){window.location.hash=e}function Cn(){O(()=>{document.documentElement.classList.toggle("dark",se.value==="dark"),localStorage.setItem("theme",se.value)},[se.value]);const e=()=>{se.value=se.value==="dark"?"light":"dark"};return{theme:se.value,toggle:e}}function $n(){O(()=>{let e=null,n=null;const s=()=>{e&&(clearTimeout(e),e=null),n&&(window.removeEventListener("keydown",n),n=null)},l=r=>{const a=r.target,i=a.tagName==="INPUT"||a.tagName==="TEXTAREA"||a.isContentEditable;if((r.metaKey||r.ctrlKey)&&r.key==="k"){r.preventDefault(),j("search"),setTimeout(()=>{var o;(o=document.querySelector(".global-search-input"))==null||o.focus()},0);return}if(!i&&r.key==="g"){const o={d:()=>j("dashboard"),s:()=>j("search"),c:()=>j("chunks"),f:()=>j("files"),e:()=>j("evaluate"),q:()=>j("quirks")};s();const c=d=>{var u;(u=o[d.key])==null||u.call(o),s()};n=c,window.addEventListener("keydown",c),e=setTimeout(s,500);return}};return window.addEventListener("keydown",l),()=>{window.removeEventListener("keydown",l),s()}},[])}function Ln(){return t("div",{className:"fixed top-4 right-4 z-[9999] flex flex-col gap-2 pointer-events-none",children:Ie.value.map(e=>t("div",{className:`pointer-events-auto px-4 py-2.5 rounded-lg shadow-lg text-sm font-medium transition-all duration-300 animate-slide-in ${e.type==="success"?"bg-green-600 text-white":e.type==="error"?"bg-red-600 text-white":"bg-brand-600 text-white"}`,children:e.message},e.id))})}function Tn(){const e=se.value==="dark";return t("button",{className:"p-2 rounded-lg transition-colors",style:{color:"var(--text-muted)"},onClick:()=>{se.value=e?"light":"dark"},"aria-label":e?"Switch to light mode":"Switch to dark mode",title:e?"Light mode":"Dark mode",children:[t("span",{className:"sr-only",children:e?"Switch to light mode":"Switch to dark mode"}),e?t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})}):t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})})]})}function ht(e,n){const[s,l]=g(e);return O(()=>{const r=setTimeout(()=>l(e),n);return()=>clearTimeout(r)},[e,n]),s}const Pn="/api",Ct="opencode-rag-token";function In(){const e=new URLSearchParams(window.location.search).get("token");if(e){sessionStorage.setItem(Ct,e);const n=window.location.pathname+window.location.hash;return window.history.replaceState(null,"",n),e}return sessionStorage.getItem(Ct)}function Rn(){const e=In();return e?{Authorization:`Bearer ${e}`}:{}}function $t(e){const n=new URLSearchParams;for(const[s,l]of Object.entries(e))l!==void 0&&l!==""&&n.set(s,String(l));return n.toString()}async function R(e,n){const s={...(n==null?void 0:n.headers)??{},...Rn()},l=await fetch(Pn+e,{...n,headers:s}),r=await l.json();if(!l.ok)throw new Error(r.error??l.statusText);return r}const $={stats:()=>R("/stats"),files:()=>R("/files"),chunks:e=>R(`/chunks?${$t(e)}`),chunk:e=>R(`/chunks/${encodeURIComponent(e)}`),search:(e,n=20)=>R(`/search?q=${encodeURIComponent(e)}&topK=${n}`),compare:e=>R(`/compare?ids=${e.join(",")}`),retrieve:e=>R(`/retrieve?${$t(e)}`),evalSessions:()=>R("/eval/sessions"),evalSession:e=>R(`/eval/sessions/${encodeURIComponent(e)}`),evalDeleteSession:e=>R(`/eval/sessions/${encodeURIComponent(e)}`,{method:"DELETE"}),evalCompare:(e,n)=>R(`/eval/compare?a=${e}&b=${n}`),evalTokenCompare:(e,n)=>R(`/eval/token-compare?a=${e}&b=${n}`),evalAnalysis:e=>R(`/eval/sessions/${encodeURIComponent(e)}/analysis`),evalProjectSavings:e=>R("/eval/project-savings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),quirks:()=>R("/quirks"),quirkLint:()=>R("/quirks/lint"),deleteQuirk:e=>R(`/quirks/${encodeURIComponent(e)}`,{method:"DELETE"}),indexStatus:()=>R("/indexing/status"),triggerReindex:()=>R("/indexing/reindex",{method:"POST"}),config:()=>R("/config"),embeddingProj:(e=5e3,n=2)=>R(`/embeddings/projection?maxChunks=${e}&dims=${n}`)},En={typescript:"text-blue-400",javascript:"text-yellow-400",python:"text-green-400",java:"text-red-400",go:"text-cyan-400",rust:"text-orange-400",ruby:"text-pink-400",csharp:"text-purple-400",cpp:"text-indigo-400",c:"text-gray-400",markdown:"text-gray-300",html:"text-orange-300",css:"text-blue-300",json:"text-yellow-300",kotlin:"text-purple-300",swift:"text-orange-400",tex:"text-emerald-400",sql:"text-cyan-300"};function je(e){return En[e]??"text-slate-400"}function he(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${je(e)} bg-slate-800">${Mn(e)}</span>`}function Mn(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function k(e){return typeof e!="string"?"":e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Lt(e,n=80){const s=typeof e=="string"?e:String(e??"");return s.length>n?s.slice(0,n)+"...":s}function Fn(){const[e,n]=g(""),[s,l]=g([]),[r,a]=g(!1),i=te(null),o=te(null),c=ht(e,300);O(()=>{if(!c.trim()){l([]),a(!1);return}let f=!1;return $.search(c,10).then(x=>{f||(l((x==null?void 0:x.results)??[]),a(!0))}).catch(()=>{f||a(!1)}),()=>{f=!0}},[c]),O(()=>{const f=x=>{o.current&&!o.current.contains(x.target)&&a(!1)};return document.addEventListener("click",f),()=>document.removeEventListener("click",f)},[]);const d=f=>{f.key==="Escape"&&a(!1)},u=async f=>{a(!1),n(""),j("chunks")};return t("div",{ref:o,className:"relative",children:[t("input",{ref:i,type:"text",placeholder:"Search codebase...",value:e,onInput:f=>n(f.target.value),onKeyDown:d,className:"global-search-input w-56 px-3 py-1.5 bg-slate-800 border border-slate-600 rounded text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400","aria-label":"Global search",role:"combobox","aria-expanded":r}),r&&s.length>0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 max-h-80 overflow-y-auto",role:"listbox",children:s.map(f=>t("div",{className:"search-result p-2 hover:bg-slate-700 cursor-pointer border-b border-slate-700 last:border-0",onClick:()=>u(f.chunk.id),role:"option",children:[t("div",{className:"flex items-center gap-2 text-xs",children:[t("span",{className:"text-yellow-400 font-mono",children:[k(f.chunk.filePath),":",f.chunk.startLine,"-",f.chunk.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(f.chunk.language)}}),t("span",{className:"ml-auto text-slate-500",children:f.score})]}),t("div",{className:"text-xs text-slate-400 mt-1 truncate",children:k(f.chunk.content??"").slice(0,80)})]},f.chunk.id))}),r&&e.trim()&&s.length===0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 p-3 text-sm text-slate-500",children:"No results"})]})}function J(e,n=[]){const[s,l]=g(null),[r,a]=g(!0),[i,o]=g(null),[c,d]=g(0);return O(()=>{let u=!1;return a(!0),o(null),e().then(f=>{u||(l(f),a(!1))}).catch(f=>{u||(o(f.message),a(!1))}),()=>{u=!0}},[...n,c]),{data:s,isLoading:r,error:i,refresh:()=>d(u=>u+1)}}function An(){const{data:e}=J(()=>$.files()),n=e??[],[s,l]=g(""),r=ht(s,300),a=r?n.filter(i=>i.filePath.toLowerCase().includes(r.toLowerCase())):n;return t("div",{className:"flex flex-col h-full",children:[t("div",{className:"flex items-center justify-between mb-2 px-3 pt-3",children:[t("h2",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wide",children:"Files"}),t("span",{className:"text-xs text-slate-500",children:a.length})]}),t("div",{className:"px-3 mb-2",children:t("input",{type:"text",placeholder:"Filter files...",value:s,onInput:i=>l(i.target.value),className:"w-full px-2 py-1 bg-slate-900 border border-slate-700 rounded text-xs focus:outline-none focus:border-brand-400 text-slate-200 placeholder-slate-500"})}),t("div",{className:"flex-1 overflow-y-auto px-1",children:t(Dn,{files:a})})]})}function Dn({files:e}){const n={};for(const s of e){const l=s.filePath.split("/");let r=n;for(let a=0;a<l.length-1;a++)r[l[a]]||(r[l[a]]={}),r=r[l[a]];r.__files||(r.__files=[]),r.__files.push(s)}return t(sn,{obj:n,depth:0,parentPath:""})}function nn(e){let n=(e.__files||[]).length;for(const[s,l]of Object.entries(e))s!=="__files"&&(n+=nn(l));return n}function sn({obj:e,depth:n,parentPath:s}){const l=Object.entries(e).filter(([a])=>a!=="__files").sort(([a],[i])=>a.localeCompare(i)),r=e.__files||[];return t(ie,{children:[l.map(([a,i])=>{const o=s?`${s}/${a}`:a,c=nn(i),d=st.value.has(o),u=d?"▸":"▾";return t("div",{children:[t("div",{className:"file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer text-slate-400 hover:text-white",style:{paddingLeft:`${n*12+8}px`},onClick:()=>{const f=new Set(st.value);f.has(o)?f.delete(o):f.add(o),st.value=f},role:"treeitem","aria-expanded":!d,children:[t("span",{className:"text-xs",children:u}),t("span",{className:"text-xs",children:"📁"}),t("span",{className:"text-xs",children:k(a)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:c})]}),!d&&t("div",{className:"dir-children",children:t(sn,{obj:i,depth:n+1,parentPath:o})})]},o)}),r.map(a=>{const i=a.filePath.split("/").pop()??a.filePath,o=de.value===a.filePath;return t("div",{className:`file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer ${o?"active text-white":"text-slate-400 hover:text-white"}`,style:{paddingLeft:`${n*12+8}px`},onClick:()=>{de.value=a.filePath,j(`chunks?file=${encodeURIComponent(a.filePath)}`)},role:"treeitem",tabIndex:0,children:[t("span",{className:`text-xs ${je(a.language)}`,children:"♦"}),t("span",{className:"text-xs truncate",children:k(i)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:a.chunkCount})]},a.filePath)})]})}const Z="bg-gradient-to-r from-slate-700 via-slate-600 to-slate-700 bg-[length:200%_100%]";function G({type:e="card"}){return t("div",{className:"animate-pulse space-y-4",children:[t("div",{className:`h-8 ${Z} rounded w-48`}),e==="card"&&t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[1,2,3,4].map(n=>t("div",{className:"h-24 bg-slate-800 rounded-lg border border-slate-700 p-4",children:[t("div",{className:`h-3 ${Z} rounded w-16 mb-2`}),t("div",{className:`h-6 ${Z} rounded w-24`})]},n))}),e==="table"&&t("div",{className:"space-y-2",children:[t("div",{className:`h-10 ${Z} rounded w-full`}),[1,2,3,4,5].map(n=>t("div",{className:`h-8 ${Z} rounded w-full`},n))]}),e==="chart"&&t("div",{className:`h-64 ${Z} rounded-lg`}),e==="detail"&&t("div",{className:"flex gap-4",children:[t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${Z} rounded w-48`}),t("div",{className:`h-4 ${Z} rounded w-32`}),t("div",{className:`h-32 ${Z} rounded-lg`})]}),t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${Z} rounded w-48`}),t("div",{className:`h-4 ${Z} rounded w-32`}),t("div",{className:`h-32 ${Z} rounded-lg`})]})]})]})}function ee({message:e,onRetry:n}){return t("div",{className:"flex flex-col items-center justify-center py-12 text-center",role:"alert",children:[t("span",{className:"text-4xl mb-3",children:"⚠️"}),t("p",{className:"text-slate-400 mb-4",children:e}),n&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:n,children:"Retry"})]})}function fe({icon:e,message:n,action:s}){return t("div",{className:"flex flex-col items-center justify-center py-16 text-center",role:"status",children:[t("span",{className:"text-5xl mb-4",role:"img","aria-label":e,children:e}),t("p",{className:"text-slate-400 mb-4",children:n}),s&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:s.onClick,children:s.label})]})}function V({label:e,value:n,icon:s}){return t("div",{className:"kpi-card p-4",children:[s&&t("span",{className:"text-lg mb-1 block",children:s}),t("div",{className:"text-slate-400 text-xs mb-1",children:e}),t("div",{className:"text-3xl font-bold text-white",children:n})]})}function H(e){return e>=1e6?(e/1e6).toFixed(1)+"M":e>=1e3?(e/1e3).toFixed(1)+"k":String(e)}function Ye(e){return e===0?"$0.00":e<.01?"$"+e.toFixed(4):"$"+e.toFixed(2)}function On(e){return e>=6e4?(e/6e4).toFixed(1)+"m":e>=1e3?(e/1e3).toFixed(1)+"s":e+"ms"}function an(e){if(!e)return"-";const n=new Date(e);return n.toLocaleDateString()+" "+n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function jn(e){const n=Date.now()-new Date(e).getTime(),s=Math.floor(n/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const l=Math.floor(s/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`}function Un(){var x;const[e,n]=g(null),[s,l]=g(!0),[r,a]=g(!1),i=te(null),o=async()=>{try{const h=await $.indexStatus();n(h.body??h)}catch{}l(!1)};O(()=>{o()},[]),O(()=>()=>{i.current&&clearInterval(i.current)},[]);const c=async()=>{var h;a(!0);try{await $.triggerReindex(),re("info","Reindex started in background");const p=(h=e==null?void 0:e.manifest)==null?void 0:h.lastIndexedAt,m=Date.now();i.current=setInterval(async()=>{var _;if(Date.now()-m>10*6e4){i.current&&clearInterval(i.current),i.current=null,a(!1),re("info","Reindex is still running — check back later");return}try{const T=await $.indexStatus(),M=T.body??T;((_=M.manifest)==null?void 0:_.lastIndexedAt)!==p&&(i.current&&clearInterval(i.current),i.current=null,n(M),a(!1),re("success","Reindex complete!"))}catch{}},2e3)}catch(p){const m=p.message??"";re("error",/already running/i.test(m)?"A reindex is already running":`Reindex failed: ${m}`),a(!1)}};if(s)return null;const d=(x=e==null?void 0:e.manifest)!=null&&x.lastIndexedAt?jn(e.manifest.lastIndexedAt):"Never",u=(e==null?void 0:e.staleFileCount)??0,f=u===0?"text-green-400":u<50?"text-amber-400":"text-red-400";return t("div",{className:"kpi-card p-4 mb-6",children:[t("div",{className:"flex items-center justify-between mb-3",children:t("h2",{className:"text-lg font-semibold",children:"Index Status"})}),e!=null&&e.manifest?t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Last Indexed"}),t("span",{className:"text-sm font-mono",children:d})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Chunks"}),t("span",{className:"text-sm font-mono",children:H(e.manifest.totalChunks)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Files"}),t("span",{className:"text-sm font-mono",children:H(e.manifest.totalFiles)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Schema Version"}),t("span",{className:"text-sm font-mono",children:e.manifest.schemaVersion})]}),t("div",{className:"col-span-2",children:[t("span",{className:"text-xs text-slate-500 block",children:"Index Freshness"}),t("span",{className:`text-sm font-mono ${f}`,children:u===0?"✓ Up to date":`⚠ ${u} file${u!==1?"s":""} modified since last index`})]}),t("div",{className:"col-span-2 flex items-end",children:r?t("div",{className:"flex items-center gap-2",children:[t("span",{className:"animate-spin",children:"⟳"}),t("span",{className:"text-sm text-amber-400",children:"Reindexing..."})]}):t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-1.5 rounded text-sm transition-colors",onClick:c,children:"Reindex Now"})})]}):t("div",{className:"text-sm text-slate-400",children:["No index found. Run ",t("code",{className:"text-brand-400",children:"opencode-rag index"})," first."]})]})}function zn(){var x,h,p;const{data:e,isLoading:n,error:s,refresh:l}=J(()=>$.stats()),{data:r}=J(()=>$.files());if(n)return t(G,{type:"card"});if(s)return t(ee,{message:s,onRetry:l});if(!e)return t(fe,{icon:"📊",message:"No dashboard data available."});const a=e,i=((x=r==null?void 0:r.body)==null?void 0:x.length)??a.totalFiles??0,o=a.totalChunks??0,c=((h=a.languages)==null?void 0:h.length)??0,d=i>0?(o/i).toFixed(1):"0",u=(a.languages??[]).slice(0,8),f=((p=u[0])==null?void 0:p.count)??1;return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Dashboard"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[t(V,{label:"Total Chunks",value:o.toLocaleString(),icon:"🧩"}),t(V,{label:"Total Files",value:i.toLocaleString(),icon:"📄"}),t(V,{label:"Languages",value:c,icon:"🔤"}),t(V,{label:"Avg Chunks/File",value:d,icon:"📊"})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Language Distribution"}),t("div",{className:"space-y-2",children:u.map(m=>t("div",{className:"flex items-center gap-3",children:[t("span",{className:`w-24 text-xs text-right ${je(m.language)}`,children:m.language}),t("div",{className:"flex-1 bg-slate-800 rounded-full h-5 overflow-hidden",children:t("div",{className:"h-full rounded-full bg-brand-500 flex items-center pl-2",style:{width:`${Math.max(8,m.count/f*100)}%`},children:t("span",{className:"text-xs font-medium text-white",children:m.count})})}),t("span",{className:"text-xs text-slate-500 w-12 text-right",children:[(m.count/o*100).toFixed(0),"%"]})]},m.language))})]}),t(Un,{}),t("div",{className:"mt-6",children:t("h2",{className:"text-lg font-semibold mb-3",children:t("a",{href:"#config",className:"hover:text-brand-400 transition-colors",children:"Configuration"})})})]})}function Tt({text:e,color:n,onDismiss:s}){return t("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-mono bg-slate-800 ${n??"text-slate-400"}`,children:[e,s&&t("button",{className:"ml-0.5 text-slate-500 hover:text-white",onClick:s,"aria-label":`Dismiss ${e} filter`,children:"×"})]})}function qn(){const e=De();O(()=>{e.params.file&&(de.value=e.params.file),e.params.lang&&(_e.value=e.params.lang)},[e.params.file,e.params.lang]);const n=Pe.value,s=kn.value,l=de.value,r=_e.value,{data:a,isLoading:i,error:o,refresh:c}=J(()=>$.chunks({offset:n,limit:s,lang:r??"",file:l??""}),[n,s,l,r]);if(i)return t(G,{type:"detail"});if(o)return t(ee,{message:o,onRetry:c});const d=(a==null?void 0:a.chunks)??[],u=(a==null?void 0:a.total)??d.length,f=Math.ceil(u/s),x=Math.floor(n/s)+1;return t("div",{className:"flex gap-4 h-full",children:[t("div",{className:"w-1/2 flex flex-col",children:[t("div",{className:"flex items-center gap-3 mb-3 flex-wrap",children:[t("h2",{className:"text-lg font-semibold text-white",children:"Chunks"}),t("span",{className:"text-sm text-slate-400",children:[u," total"]}),_e.value&&t(Tt,{text:_e.value,color:je(_e.value),onDismiss:()=>{_e.value=null,ye.value=null,Pe.value=0}}),de.value&&t(Tt,{text:de.value,onDismiss:()=>{de.value=null,ye.value=null,Pe.value=0}})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden flex-1",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8",children:t("input",{type:"checkbox",className:"accent-brand-500",checked:d.length>0&&d.every(h=>X.value.has(h.id||`chunk-${d.indexOf(h)}`)),onChange:()=>{const h=d.map((_,T)=>_.id||`chunk-${T}`),p=h.every(_=>X.value.has(_)),m=new Set(X.value);for(const _ of h)p?m.delete(_):m.add(_);X.value=m},"aria-label":"Select all chunks on this page"})}),t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Lang"}),t("th",{className:"px-3 py-2 text-left",children:"Description"})]})}),t("tbody",{children:d.length===0?t("tr",{children:t("td",{colSpan:4,className:"px-3 py-8 text-center text-slate-500",children:[t("span",{className:"text-2xl block mb-2",children:"🔍"}),"No chunks found"]})}):d.map((h,p)=>{const m=h.id||`chunk-${p}`,_=ye.value===m,T=X.value.has(m);return t("tr",{className:`chunk-row border-t border-slate-800 cursor-pointer ${_?"selected":""}`,onClick:()=>{ye.value=m},role:"row",tabIndex:0,children:[t("td",{className:"px-2 py-2",onClick:M=>M.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:T,onChange:()=>{const M=new Set(X.value);M.has(m)?M.delete(m):M.add(m),X.value=M},"aria-label":`Select chunk ${m}`})}),t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:[k(h.filePath),":",h.startLine,"-",h.endLine]}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:he(h.language)}}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:k(h.description??"").slice(0,50)})]},m)})})]})}),t("div",{className:"flex items-center justify-between mt-3",children:[t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:x<=1,onClick:()=>{Pe.value=Math.max(0,n-s)},children:"Previous"}),t("span",{className:"text-sm text-slate-400",children:["Page ",x," of ",f||1]}),t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:x>=f,onClick:()=>{Pe.value+=s},children:"Next"})]}),X.value.size>=2&&X.value.size<=3&&t("div",{className:"fixed bottom-6 right-6 z-50",children:t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-6 py-3 rounded-full shadow-lg font-bold transition-all transform hover:scale-105",onClick:()=>{const h=[...X.value];X.value=new Set,j(`compare?ids=${h.join(",")}`)},children:["Compare (",X.value.size,")"]})})]}),t("div",{className:"w-1/2 overflow-y-auto",children:ye.value?t(Hn,{chunkId:ye.value,chunks:d}):t("div",{className:"flex items-center justify-center h-full text-slate-500",children:t("div",{className:"text-center",children:[t("div",{className:"text-4xl mb-2",children:"📄"}),t("div",{className:"text-sm",children:"Select a chunk to view details"})]})})})]})}function Hn({chunkId:e,chunks:n}){const[s,l]=g(null),[r,a]=g(!1),i=te(null);if(O(()=>{let u=!1;const f=n.find(x=>x.id===e);return f?l(f):$.chunk(e).then(x=>{u||l(x)}).catch(()=>{u||l({id:e,content:"",filePath:"not found",language:"",startLine:0,endLine:0,description:""})}),()=>{u=!0}},[e,n]),O(()=>()=>{i.current&&clearTimeout(i.current)},[]),!s)return t(G,{type:"detail"});const o=s,c=o.language==="image",d=()=>{navigator.clipboard.writeText(o.content).then(()=>{a(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>a(!1),1500)})};return t("div",{children:[t("div",{className:"mb-3",children:[t("div",{className:"flex items-center gap-3 mb-1",children:t("span",{className:"text-yellow-400 font-mono text-sm",children:k(o.filePath)})}),t("div",{className:"flex items-center gap-3 text-sm text-slate-400",children:[t("span",{children:["Lines ",o.startLine,"-",o.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(o.language)}}),o.id&&t("span",{className:"text-xs text-slate-600 font-mono",children:o.id})]})]}),o.description&&t("div",{className:"kpi-card p-3 mb-3",children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Description"}),t("p",{className:"text-sm text-slate-300",children:k(o.description)})]}),c&&t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden mb-3",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700",children:t("span",{className:"text-xs text-slate-400",children:"Image Preview"})}),t("div",{className:"p-3 flex items-center justify-center bg-slate-950",children:t("img",{src:`/api/file?path=${encodeURIComponent(o.filePath)}`,alt:o.filePath,className:"max-w-full max-h-[60vh] object-contain rounded",onError:u=>{const f=u.currentTarget;f.style.display="none",f.parentElement.innerHTML='<span class="text-slate-500 text-sm">Image not available</span>'}})})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700 flex items-center justify-between",children:[t("span",{className:"text-xs text-slate-400",children:c?"Vision Analysis":"Source Code"}),t("button",{className:"text-xs text-slate-500 hover:text-white transition-colors",onClick:d,children:r?"Copied!":"Copy"})]}),t("pre",{className:"p-3 overflow-x-auto text-sm max-h-[calc(100vh-220px)]",children:t("code",{className:`language-${c?"text":o.language}`,children:k(o.content)})})]})]})}function Kn(){const{data:e,isLoading:n,error:s,refresh:l}=J(()=>$.files());if(n)return t(G,{type:"table"});if(s)return t(ee,{message:s,onRetry:l});const r=e??[];if(r.length===0)return t(fe,{icon:"📂",message:"No files indexed yet."});const a=r.reduce((i,o)=>i+o.chunkCount,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Files"}),t("span",{className:"text-sm text-slate-400",children:[r.length," files, ",a," chunks"]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:t("table",{className:"w-full text-sm",role:"table","aria-label":"Indexed files",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-28",children:"Language"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Chunks"}),t("th",{className:"px-3 py-2 text-left w-24"})]})}),t("tbody",{children:r.map(i=>t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>j(`chunks?file=${encodeURIComponent(i.filePath)}`),role:"row",tabIndex:0,onKeyDown:o=>{o.key==="Enter"&&j(`chunks?file=${encodeURIComponent(i.filePath)}`)},children:[t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:i.filePath}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:he(i.language)}}),t("td",{className:"px-3 py-2 text-slate-300",children:i.chunkCount}),t("td",{className:"px-3 py-2 text-slate-500 text-xs",children:t("span",{className:"hover:text-white transition-colors",children:"View chunks"})})]},i.filePath))})]})})]})}function Bn({segments:e,size:n=180,innerRadius:s,centerLabel:l}){const r=n/2,a=n/2,i=n/2-10,o=s??i*.6,c=e.reduce((x,h)=>x+h.value,0);if(c===0)return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,children:[t("circle",{cx:r,cy:a,r:i,fill:"none",stroke:"#334155","stroke-width":i-o}),t("circle",{cx:r,cy:a,r:o,fill:"#0f172a"})]});let d=0;const u=e.map(x=>{const h=x.value/c*360,p=d,m=d+h;return d+=h,`<path d="${Wn(r,a,i,p,m,o)}" fill="${x.color}" />`}).join(""),f=l??"";return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:"chart-svg",children:[t("g",{dangerouslySetInnerHTML:{__html:u}}),t("text",{x:r,y:a-6,"text-anchor":"middle",fill:"white","font-size":"22","font-weight":"bold",children:f}),t("text",{x:r,y:a+14,"text-anchor":"middle",fill:"#64748b","font-size":"11",children:"tokens"})]})}function Wn(e,n,s,l,r,a){const i=r-l;if(i>=359.99)return`M${e},${n-s} A${s},${s} 0 1,1 ${e-.01},${n-s} L${e-.01},${n-a} A${a},${a} 0 1,0 ${e},${n-a} Z`;const o=T=>(T-90)*Math.PI/180,c=e+s*Math.cos(o(l)),d=n+s*Math.sin(o(l)),u=e+s*Math.cos(o(r)),f=n+s*Math.sin(o(r)),x=e+a*Math.cos(o(r)),h=n+a*Math.sin(o(r)),p=e+a*Math.cos(o(l)),m=n+a*Math.sin(o(l)),_=i>180?1:0;return[`M${c},${d}`,`A${s},${s} 0 ${_} 1 ${u},${f}`,`L${x},${h}`,`A${a},${a} 0 ${_} 0 ${p},${m}`,"Z"].join(" ")}function Vn(){const e=De();return e.params.compare?t(Xn,{ids:[e.params.a??"",e.params.b??""]}):e.params.session?t(Qn,{sessionId:e.params.session}):t(Gn,{})}function Gn(){const{data:e,isLoading:n,error:s,refresh:l}=J(()=>$.evalSessions()),[r,a]=g(new Set);if(n)return t(G,{type:"table"});if(s)return t(ee,{message:s,onRetry:l});const i=(e==null?void 0:e.sessions)??[];if(i.length===0)return t(fe,{icon:"📊",message:"No sessions recorded yet."});const o=c=>{const d=new Set(r);d.has(c)?d.delete(c):d.add(c),a(d)};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Evaluate"}),t("div",{className:"flex gap-2",children:[r.size===2&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-3 py-1 rounded text-sm transition-colors",onClick:()=>{const[c,d]=[...r];j(`evaluate?compare&a=${encodeURIComponent(c)}&b=${encodeURIComponent(d)}`)},children:"Compare Selected"}),r.size>0&&t("button",{className:"text-xs text-slate-400 hover:text-white",onClick:()=>a(new Set),children:["Clear (",r.size,")"]})]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-x-auto",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8"}),t("th",{className:"px-3 py-2 text-left",children:"Session"}),t("th",{className:"px-3 py-2 text-left",children:"Last Activity"}),t("th",{className:"px-3 py-2 text-right",children:"Messages"}),t("th",{className:"px-3 py-2 text-right",children:"Input Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Output Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Cost"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Calls"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Tokens"}),t("th",{className:"px-3 py-2 text-left",children:"Model"}),t("th",{className:"px-3 py-2 w-8"})]})}),t("tbody",{children:i.map(c=>{var d,u,f,x;return t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>j(`evaluate?session=${encodeURIComponent(c.sessionID)}`),children:[t("td",{className:"px-2 py-2",onClick:h=>h.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:r.has(c.sessionID),onChange:()=>o(c.sessionID),"aria-label":`Select session ${c.title??c.sessionID}`})}),t("td",{className:"px-3 py-2 text-slate-200 font-mono text-xs",children:c.title??c.sessionID.slice(0,8)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:an(c.lastEventAt)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:c.messageCount}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:H((((d=c.totalTokens)==null?void 0:d.input)??0)+(((u=c.totalTokens)==null?void 0:u.cacheRead)??0))}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:H(((f=c.totalTokens)==null?void 0:f.output)??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:Ye(c.totalCost??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:c.ragContextCount??0}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:H(c.ragContextTokens??0)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:((x=c.models)==null?void 0:x[0])??"-"}),t("td",{className:"px-3 py-2",onClick:h=>h.stopPropagation(),children:t("button",{className:"text-slate-600 hover:text-red-400 text-xs",onClick:async()=>{if(confirm("Delete this session?"))try{await $.evalDeleteSession(c.sessionID),re("success","Session deleted"),l()}catch(h){re("error",`Delete failed: ${h.message}`)}},"aria-label":"Delete session",children:"🗑"})})]},c.sessionID)})})]})})]})}function Qn({sessionId:e}){var f,x,h,p,m,_,T,M;const{data:n,isLoading:s,error:l,refresh:r}=J(()=>$.evalSession(e));if(s)return t(G,{type:"detail"});if(l)return t(ee,{message:l,onRetry:r});const a=(n==null?void 0:n.summary)??n,i=(n==null?void 0:n.events)??[],o=a.toolCallCounts??{};["search_semantic","get_file_skeleton","find_usages","describe_image"].reduce((y,Y)=>y+(o[Y]??0),0);const d=[{label:"Input",value:(((f=a.totalTokens)==null?void 0:f.input)??0)+(((x=a.totalTokens)==null?void 0:x.cacheRead)??0),color:"#3b82f6"},{label:"Output",value:((h=a.totalTokens)==null?void 0:h.output)??0,color:"#a855f7"},{label:"RAG",value:a.ragContextTokens??0,color:"#06b6d4"},{label:"Reasoning",value:((p=a.totalTokens)==null?void 0:p.reasoning)??0,color:"#f59e0b"}].filter(y=>y.value>0),u=d.reduce((y,Y)=>y+Y.value,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>j("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:a.title??((m=a.sessionID)==null?void 0:m.slice(0,12))})]}),t("div",{className:"grid grid-cols-3 lg:grid-cols-5 gap-3 mb-6",children:[t(V,{label:"Total Tokens",value:H(u)}),t(V,{label:"Input",value:H((((_=a.totalTokens)==null?void 0:_.input)??0)+(((T=a.totalTokens)==null?void 0:T.cacheRead)??0))}),t(V,{label:"Output",value:H(((M=a.totalTokens)==null?void 0:M.output)??0)}),t(V,{label:"Cost",value:Ye(a.totalCost??0)}),t(V,{label:"RAG Context",value:H(a.ragContextTokens??0)})]}),t("div",{className:"flex items-center gap-6 mb-6",children:[t(Bn,{segments:d,centerLabel:H(u)}),t("div",{className:"flex flex-wrap gap-3",children:d.map(y=>t("div",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("span",{className:"inline-block w-3 h-3 rounded-sm",style:{background:y.color}}),y.label,": ",H(y.value)," (",(y.value/u*100).toFixed(1),"%)"]},y.label))})]}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 mb-6",children:[t(V,{label:"Messages",value:a.messageCount??0}),t(V,{label:"Steps",value:a.totalSteps??0}),t(V,{label:"RAG Injections",value:a.ragContextCount??0}),t(V,{label:"Avg Response",value:On(a.avgResponseTimeMs??0)})]}),Object.keys(o).length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Tool Calls"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2",children:Object.entries(o).map(([y,Y])=>t("div",{className:"flex justify-between text-xs text-slate-400",children:[t("span",{className:"font-mono",children:y}),t("span",{className:"text-white",children:String(Y)})]},y))})]}),a.models&&a.models.length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:"Models"}),t("div",{className:"flex flex-wrap gap-2",children:a.models.map(y=>t("span",{className:"px-2 py-0.5 rounded text-xs font-mono bg-slate-800 text-slate-300",children:y},y))})]}),i.length>0&&t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Event Timeline"}),t("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:i.map((y,Y)=>t("div",{className:"flex gap-2 text-xs border-b border-slate-700/50 py-1",children:[t("span",{className:"text-slate-500 shrink-0 w-16",children:an(y.ts)}),t("span",{className:"text-slate-400",children:y.event}),y.tool&&t("span",{className:"text-slate-500 font-mono",children:y.tool}),y.toolStatus&&t("span",{className:`text-xs ${y.toolStatus==="completed"?"text-green-400":y.toolStatus==="running"?"text-amber-400":"text-slate-500"}`,children:y.toolStatus})]},Y))})]})]})}function Xn({ids:e}){var f,x,h,p,m,_,T,M;const[n,s]=e,{data:l,isLoading:r,error:a}=J(()=>Promise.all([$.evalCompare(n,s),$.evalTokenCompare(n,s)]),[n,s]);if(r)return t(G,{type:"chart"});if(a)return t(ee,{message:a});if(!l)return null;const i=l[0],o=l[1],c=((f=o.sessionA)==null?void 0:f.savings)??0,d=((x=o.sessionB)==null?void 0:x.savings)??0,u=c>0&&d>0?"RAG saves tokens":"Mixed results";return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>j("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:"Session Comparison"})]}),t("div",{className:`px-4 py-3 rounded-lg mb-4 font-semibold text-sm ${c>0&&d>0?"bg-green-900/50 text-green-300 border border-green-700":"bg-amber-900/50 text-amber-300 border border-amber-700"}`,children:u}),t("div",{className:"grid grid-cols-2 gap-4",children:[t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((h=i.sessionA)==null?void 0:h.title)??"Session A"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:H(((p=i.sessionA)==null?void 0:p.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Ye(((m=i.sessionA)==null?void 0:m.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:c>0?"text-green-400":"text-red-400",children:[H(Math.abs(c))," (",c>0?"+":"",c>0?"+":"",")"]})]})]})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((_=i.sessionB)==null?void 0:_.title)??"Session B"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:H(((T=i.sessionB)==null?void 0:T.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Ye(((M=i.sessionB)==null?void 0:M.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:d>0?"text-green-400":"text-red-400",children:H(Math.abs(d))})]})]})]})]})]})}const Zn={gotcha:"text-amber-400 bg-amber-900/20",preference:"text-emerald-400 bg-emerald-900/20",decision:"text-sky-400 bg-sky-900/20","environment-constraint":"text-rose-400 bg-rose-900/20"};function Yn(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${Zn[e]??"text-slate-400 bg-slate-800"}">${k(e||"general")}</span>`}function Jn(){const{data:e,isLoading:n,error:s,refresh:l}=J(()=>$.quirks()),[r,a]=g(null),[i,o]=g(null),[c,d]=g(!1);if(n)return t(G,{type:"card"});if(s)return t(ee,{message:s,onRetry:l});const u=(e==null?void 0:e.quirks)??[],f=[...new Set(u.map(m=>m.type||"general"))],x=r?u.filter(m=>(m.type||"general")===r):u,h=async m=>{if(confirm("Delete this quirk?"))try{await $.deleteQuirk(m),re("success","Quirk deleted"),l()}catch(_){re("error",`Delete failed: ${_.message}`)}};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Quirks"}),t("button",{className:"bg-slate-700 hover:bg-slate-600 text-white px-3 py-1 rounded text-sm transition-colors",onClick:async()=>{d(!0);try{const m=await $.quirkLint();o(m)}catch(m){o({error:m.message})}d(!1)},disabled:c,children:c?"Linting...":"Lint"})]}),t("div",{className:"flex gap-2 mb-4 flex-wrap",children:[t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${r===null?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>a(null),children:"All"}),f.map(m=>t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${r===m?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>a(m),children:m},m))]}),i&&t("div",{className:`mb-4 p-3 rounded-lg border text-sm ${i.success?"bg-green-900/30 border-green-700 text-green-300":i.error?"bg-red-900/30 border-red-700 text-red-300":"bg-amber-900/30 border-amber-700 text-amber-300"}`,children:t("pre",{className:"text-xs whitespace-pre-wrap",children:JSON.stringify(i,null,2)})}),x.length===0?t(fe,{icon:"💡",message:"No quirks stored yet."}):t("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:x.map(m=>t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 p-3 flex flex-col",children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("span",{dangerouslySetInnerHTML:{__html:Yn(m.type)}}),t("span",{className:`text-xs font-mono ${m.confidence>.7?"text-green-400":m.confidence>.4?"text-amber-400":"text-red-400"}`,children:[(m.confidence*100).toFixed(0),"%"]})]}),t("p",{className:"text-sm text-slate-200 mb-2 flex-1",children:k(m.content)}),m.tags&&m.tags.length>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:m.tags.map(_=>t("span",{className:"text-xs bg-slate-800 text-slate-400 px-1.5 py-0.5 rounded",children:["#",_]},_))}),t("div",{className:"flex items-center justify-between text-xs text-slate-600 mt-auto",children:[m.sourceRef&&t("span",{className:"font-mono",children:k(m.sourceRef)}),t("span",{className:"font-mono",children:m.id})]}),t("button",{className:"self-end mt-2 text-xs text-slate-600 hover:text-red-400 transition-colors",onClick:()=>h(m.id),"aria-label":"Delete quirk",children:"Delete"})]},m.id))})]})}function es(){const[e,n]=g([]),[s,l]=g(!1),[r,a]=g(null),[i,o]=g(!1),c=ht(b.value,300);return O(()=>{const d=W.value.trim();if(!d){n([]),a(null),l(!1),ae.value=[];return}let u=!1;return(async()=>{var x,h;l(!0),a(null);try{const p=await $.retrieve({q:d,topK:c.topK,minScore:c.minScore,keywordWeight:c.keywordWeight,hybrid:c.hybrid?"true":"false",path:c.pathFilter||void 0,lang:c.langFilter||void 0,ext:c.extFilter||void 0,explain:"true"});if(u)return;if(p.status===503){a(((x=p.body)==null?void 0:x.error)??"Embedding model unavailable"),l(!1);return}o(!1);const m=((h=p.body)==null?void 0:h.results)??p.results??[];n(m),ae.value=m;const _={query:d,params:{...c}};Ze.value=[_,...Ze.value.filter(T=>T.query!==d).slice(0,19)]}catch(p){u||a(p.message)}finally{u||l(!1)}})(),()=>{u=!0}},[W.value,c]),{results:e,isLoading:s,isInitializing:i,error:r,setResults:n}}function ts({explanation:e}){const{vectorScore:n,keywordScore:s,rawVectorScore:l,rawKeywordScore:r,keywordWeight:a,vectorRank:i,keywordRank:o}=e.scoreBreakdown,c=Math.max(n+s,.001),d=(n/c*100).toFixed(0),u=(s/c*100).toFixed(0);return t("div",{className:"mb-2",children:[t("div",{className:"flex items-center gap-2 text-xs mb-1",children:[t("span",{className:"text-cyan-400",title:`Vector: ${l.toFixed(3)}${i!==void 0?`, rank #${i+1}`:""}`,children:["Vector ",d,"%"]}),t("span",{className:"text-amber-400",title:`Keyword: ${r.toFixed(3)}${o!==void 0?`, rank #${o+1}`:""}`,children:["Keyword ",u,"%"]}),t("span",{className:"text-slate-500 ml-auto",children:["kw=",a.toFixed(1)]})]}),t("div",{className:"h-2 bg-slate-700 rounded-full overflow-hidden flex",children:[t("div",{className:"h-full bg-cyan-500 transition-all duration-200",style:{width:`${d}%`}}),t("div",{className:"h-full bg-amber-500 transition-all duration-200",style:{width:`${u}%`}})]})]})}function ns(){const e=De(),{results:n,isLoading:s,isInitializing:l,error:r}=es();return O(()=>{e.params.query&&(W.value=e.params.query,b.value={...b.value,topK:parseInt(e.params.topK??"10",10),minScore:parseFloat(e.params.minScore??"0.35"),keywordWeight:parseFloat(e.params.keywordWeight??"0.4"),hybrid:e.params.hybrid!=="false",pathFilter:e.params.path??"",langFilter:e.params.lang??"",extFilter:e.params.ext??""})},[]),O(()=>{if(W.value.trim()){const a=new URLSearchParams({query:W.value,topK:String(b.value.topK),minScore:String(b.value.minScore),keywordWeight:String(b.value.keywordWeight),hybrid:String(b.value.hybrid)});b.value.pathFilter&&a.set("path",b.value.pathFilter),b.value.langFilter&&a.set("lang",b.value.langFilter),b.value.extFilter&&a.set("ext",b.value.extFilter);const i=`search?${a.toString()}`;location.hash!==`#${i}`&&history.replaceState(null,"",`#${i}`)}},[W.value,b.value]),t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Semantic Search"}),t("div",{className:"flex gap-3 mb-4",children:t("input",{type:"text",value:W.value,onInput:a=>{W.value=a.target.value,ae.value=[]},onKeyDown:a=>{a.key==="Enter"&&W.value.trim()},placeholder:"Search your codebase semantically... (e.g., 'how does authentication work?')",className:"flex-1 px-4 py-2 bg-slate-800 border border-slate-600 rounded-lg text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400",autoFocus:!0,"aria-label":"Semantic search query"})}),t("details",{className:"mb-4 bg-slate-800 rounded-lg border border-slate-700",children:[t("summary",{className:"px-3 py-2 text-xs text-slate-400 cursor-pointer hover:text-white font-medium",children:"Search Parameters"}),t("div",{className:"px-3 pb-3 space-y-3",children:[t(at,{label:"topK",min:1,max:25,step:1,value:b.value.topK,onChange:a=>{b.value={...b.value,topK:a}}}),t(at,{label:"minScore",min:0,max:1,step:.05,value:b.value.minScore,onChange:a=>{b.value={...b.value,minScore:a}}}),t(at,{label:"keywordWeight",min:0,max:1,step:.1,value:b.value.keywordWeight,onChange:a=>{b.value={...b.value,keywordWeight:a}}}),t("div",{className:"flex items-center gap-2",children:[t("label",{className:"text-xs text-slate-400 w-28",children:"Hybrid mode"}),t("input",{type:"checkbox",checked:b.value.hybrid,onChange:a=>{b.value={...b.value,hybrid:a.target.checked}},className:"accent-brand-500"})]}),t("div",{className:"flex items-center gap-3",children:[t("label",{className:"text-xs text-slate-400 w-28 shrink-0",children:"Extensions"}),t("input",{type:"text",value:b.value.extFilter,onInput:a=>{b.value={...b.value,extFilter:a.target.value}},placeholder:".ts, .py (comma-separated)",className:"flex-1 px-2 py-1 bg-slate-900 border border-slate-600 rounded text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400","aria-label":"File extension filter"})]}),t("div",{className:"flex items-center gap-3",children:[t("label",{className:"text-xs text-slate-400 w-28 shrink-0",children:"Languages"}),t("input",{type:"text",value:b.value.langFilter,onInput:a=>{b.value={...b.value,langFilter:a.target.value}},placeholder:"typescript, python (comma-separated)",className:"flex-1 px-2 py-1 bg-slate-900 border border-slate-600 rounded text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400","aria-label":"Language filter"})]}),t("div",{className:"flex items-center gap-3",children:[t("label",{className:"text-xs text-slate-400 w-28 shrink-0",children:"Path"}),t("input",{type:"text",value:b.value.pathFilter,onInput:a=>{b.value={...b.value,pathFilter:a.target.value}},placeholder:"src/** (comma-separated)",className:"flex-1 px-2 py-1 bg-slate-900 border border-slate-600 rounded text-xs text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400","aria-label":"Path filter"})]})]})]}),l&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Initializing embedding model..."]}),r&&t(ee,{message:r}),!s&&!r&&W.value.trim()&&n.length===0&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:['No results found for "',k(W.value),'"']})]}),!s&&!r&&!W.value.trim()&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:"Enter a query to search your codebase"}),Ze.value.length>0&&t("div",{className:"mt-6",children:[t("p",{className:"text-xs text-slate-600 mb-2",children:"Recent queries:"}),t("div",{className:"flex flex-wrap gap-2 justify-center",children:Ze.value.slice(0,10).map((a,i)=>t("button",{className:"px-2 py-1 bg-slate-800 rounded text-xs text-slate-400 hover:text-white hover:bg-slate-700 transition-colors",onClick:()=>{W.value=a.query},children:k(a.query)},i))})]})]}),n.length>0&&t("div",{className:"space-y-3",children:[t("div",{className:"flex items-center justify-between text-sm text-slate-400 mb-2",children:[t("span",{children:[n.length," result",n.length!==1?"s":""]}),s&&t("span",{className:"text-xs text-brand-400 animate-pulse",children:"Searching..."})]}),n.map(a=>t(ss,{result:a},a.chunk.id))]}),s&&n.length===0&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Searching..."]})]})}function ss({result:e}){var l,r;const n=e.chunk,s=e.score;return t("div",{className:"bg-slate-800 rounded-lg p-4 border border-slate-700 hover:border-brand-500/50 transition-colors cursor-pointer",onClick:()=>j(`chunks?id=${encodeURIComponent(n.id)}`),children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("div",{className:"flex items-center gap-2 min-w-0",children:[t("span",{className:"text-sm text-yellow-400 font-mono truncate",children:[k(n.filePath),":",n.startLine,"-",n.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(n.language)}})]}),t("span",{className:"text-lg font-bold shrink-0 ml-2",style:{color:as(s)},children:s.toFixed(2)})]}),e.explanation&&t(ts,{explanation:e.explanation}),((r=(l=e.explanation)==null?void 0:l.matchedTerms)==null?void 0:r.length)>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:e.explanation.matchedTerms.map(a=>t("span",{className:"text-xs bg-amber-500/20 text-amber-300 px-1.5 py-0.5 rounded",children:k(a)},a))}),n.description&&t("p",{className:"text-sm text-slate-400 mb-2 line-clamp-2",children:k(n.description)}),t("pre",{className:"text-xs overflow-x-auto max-h-32 rounded bg-slate-900/50 p-2",children:t("code",{children:k(n.content??"").slice(0,500)})})]})}function as(e){return e>=.8?"#22c55e":e>=.6?"#06b6d4":e>=.4?"#f59e0b":"#ef4444"}function at({label:e,min:n,max:s,step:l,value:r,onChange:a}){return t("div",{className:"flex items-center gap-3",children:[t("label",{className:"text-xs text-slate-400 w-28 shrink-0",children:e}),t("input",{type:"range",min:n,max:s,step:l,value:r,onInput:i=>a(parseFloat(i.target.value)),className:"flex-1 accent-brand-500"}),t("span",{className:"text-xs text-slate-300 font-mono w-12 text-right",children:r})]})}function ls(){var c;const n=((c=De().params.ids)==null?void 0:c.split(",").filter(Boolean))??[],[s,l]=g([]),[r,a]=g(!0),[i,o]=g(null);return O(()=>{let d=!1;if(n.length<2){o("Select 2-3 chunks to compare."),a(!1);return}return $.compare(n).then(u=>{var f;d||(l(((f=u==null?void 0:u.body)==null?void 0:f.chunks)??(u==null?void 0:u.chunks)??[]),a(!1))}).catch(u=>{d||(o(u.message),a(!1))}),()=>{d=!0}},[n.join(",")]),r?t(G,{type:"detail"}):i?t(ee,{message:i}):s.length<2?t(fe,{icon:"📋",message:"Select 2-3 chunks from the Chunks view to compare them."}):t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Chunk Comparison"}),t("button",{className:"text-sm text-slate-400 hover:text-white transition-colors",onClick:()=>j("chunks"),children:"← Back to Chunks"})]}),t("div",{className:`grid gap-4 ${s.length===2?"grid-cols-2":"grid-cols-3"}`,children:s.map((d,u)=>t(rs,{chunk:d,index:u,baseChunk:u>0?s[0]:void 0},d.id))})]})}function rs({chunk:e,index:n,baseChunk:s}){const l=e.content.split(`
3
+ `),r=(s==null?void 0:s.content.split(`
4
+ `))??[];return t("div",{className:"bg-slate-800 rounded-lg border border-slate-700 overflow-hidden flex flex-col",children:[t("div",{className:"p-3 border-b border-slate-700 bg-slate-800/80",children:[t("div",{className:"flex items-center justify-between mb-1",children:[t("span",{className:"text-sm font-mono text-brand-400 truncate mr-2",children:[k(e.filePath),":",e.startLine,"-",e.endLine]}),t("span",{className:"shrink-0",dangerouslySetInnerHTML:{__html:he(e.language)}})]}),e.description&&t("p",{className:"text-xs text-slate-400 truncate",children:k(e.description)})]}),t("div",{className:"overflow-x-auto flex-1 max-h-[70vh]",children:t("table",{className:"w-full text-xs font-mono border-collapse",children:t("tbody",{children:l.map((a,i)=>{const o=(e.startLine??1)+i,c=r[i]===void 0?"bg-green-900/30":a===""&&r[i]!==""?"bg-red-900/30":a!==r[i]?"bg-amber-900/20":"";return t("tr",{className:c,children:[t("td",{className:"text-right text-slate-600 select-none px-2 w-10 border-r border-slate-700 align-top",children:o}),t("td",{className:"px-3 py-0 whitespace-pre-wrap break-all",children:k(a)||" "})]},i)})})})}),t("div",{className:"px-3 py-1.5 bg-slate-900 border-t border-slate-700 text-xs text-slate-500",children:["Chunk ",n+1,n===0&&t("span",{className:"text-slate-600 ml-1",children:"(reference)"})]})]})}function is(){var a;const{data:e,isLoading:n,error:s,refresh:l}=J(()=>$.config());if(n)return t(G,{type:"card"});if(s)return t(ee,{message:s,onRetry:l});const r=((a=e==null?void 0:e.body)==null?void 0:a.config)??(e==null?void 0:e.config);return r?t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Configuration"}),t("p",{className:"text-sm text-slate-400 mb-4",children:["Effective configuration from ",t("code",{className:"text-brand-400",children:"opencode-rag.json"}),". API keys are redacted."]}),t("div",{className:"space-y-4",children:Object.entries(r).map(([i,o])=>t("details",{className:"bg-slate-800 rounded-lg border border-slate-700",open:!0,children:[t("summary",{className:"px-4 py-2 cursor-pointer hover:bg-slate-700 font-mono text-sm font-semibold capitalize text-slate-300",children:i.replace(/([A-Z])/g," $1")}),t("div",{className:"px-4 pb-3",children:typeof o=="object"&&o!==null?Object.entries(o).map(([c,d])=>t("div",{className:"flex justify-between py-1 border-b border-slate-700/50 text-sm",children:[t("span",{className:"text-slate-400 font-mono",children:c}),t("span",{className:"text-slate-200 font-mono text-xs text-right ml-4",children:os(d)})]},c)):t("div",{className:"flex justify-between py-1 text-sm",children:t("span",{className:"text-slate-200 font-mono",children:String(o)})})})]},i))})]}):t(fe,{icon:"⚙",message:"No configuration available."})}function os(e){return e===null?"null":e===void 0?"undefined":typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.join(", ")}]`:typeof e=="object"?JSON.stringify(e).slice(0,150):String(e)}const cs="modulepreload",ds=function(e){return"/ui/"+e},Pt={},us=function(n,s,l){let r=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),o=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));r=Promise.allSettled(s.map(c=>{if(c=ds(c),c in Pt)return;Pt[c]=!0;const d=c.endsWith(".css"),u=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${u}`))return;const f=document.createElement("link");if(f.rel=d?"stylesheet":cs,d||(f.as="script"),f.crossOrigin="",f.href=c,o&&f.setAttribute("nonce",o),document.head.appendChild(f),d)return new Promise((x,h)=>{f.addEventListener("load",x),f.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${c}`)))})}))}function a(i){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i}return r.then(i=>{for(const o of i||[])o.status==="rejected"&&a(o.reason);return n().catch(a)})};function hs(e,n){for(var s in n)e[s]=n[s];return e}function It(e,n){for(var s in e)if(s!=="__source"&&!(s in n))return!0;for(var l in n)if(l!=="__source"&&e[l]!==n[l])return!0;return!1}function Rt(e,n){this.props=e,this.context=n}(Rt.prototype=new Ne).isPureReactComponent=!0,Rt.prototype.shouldComponentUpdate=function(e,n){return It(this.props,e)||It(this.state,n)};var Et=D.__b;D.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),Et&&Et(e)};var fs=D.__e;D.__e=function(e,n,s,l){if(e.then){for(var r,a=n;a=a.__;)if((r=a.__c)&&r.__c)return n.__e==null&&(n.__e=s.__e,n.__k=s.__k||[]),r.__c(e,n)}fs(e,n,s,l)};var Mt=D.unmount;function ln(e,n,s){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(l){typeof l.__c=="function"&&l.__c()}),e.__c.__H=null),(e=hs({},e)).__c!=null&&(e.__c.__P===s&&(e.__c.__P=n),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(l){return ln(l,n,s)})),e}function rn(e,n,s){return e&&s&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(l){return rn(l,n,s)}),e.__c&&e.__c.__P===n&&(e.__e&&s.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=s)),e}function We(){this.__u=0,this.o=null,this.__b=null}function on(e){var n=e.__&&e.__.__c;return n&&n.__a&&n.__a(e)}function ms(e){var n,s,l,r=null;function a(i){if(n||(n=e()).then(function(o){o&&(r=o.default||o),l=!0},function(o){s=o,l=!0}),s)throw s;if(!l)throw n;return r?rt(r,i):null}return a.displayName="Lazy",a.__f=!0,a}function He(){this.i=null,this.l=null}D.unmount=function(e){var n=e.__c;n&&(n.__z=!0),n&&n.__R&&n.__R(),n&&32&e.__u&&(e.type=null),Mt&&Mt(e)},(We.prototype=new Ne).__c=function(e,n){var s=n.__c,l=this;l.o==null&&(l.o=[]),l.o.push(s);var r=on(l.__v),a=!1,i=function(){a||l.__z||(a=!0,s.__R=null,r?r(c):c())};s.__R=i;var o=s.__P;s.__P=null;var c=function(){if(!--l.__u){if(l.state.__a){var d=l.state.__a;l.__v.__k[0]=rn(d,d.__c.__P,d.__c.__O)}var u;for(l.setState({__a:l.__b=null});u=l.o.pop();)u.__P=o,u.forceUpdate()}};l.__u++||32&n.__u||l.setState({__a:l.__b=l.__v.__k[0]}),e.then(i,i)},We.prototype.componentWillUnmount=function(){this.o=[]},We.prototype.render=function(e,n){if(this.__b){if(this.__v.__k){var s=document.createElement("div"),l=this.__v.__k[0].__c;this.__v.__k[0]=ln(this.__b,s,l.__O=l.__P)}this.__b=null}var r=n.__a&&rt(ie,null,e.fallback);return r&&(r.__u&=-33),[rt(ie,null,n.__a?null:e.children),r]};var Ft=function(e,n,s){if(++s[1]===s[0]&&e.l.delete(n),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(s=e.i;s;){for(;s.length>3;)s.pop()();if(s[1]<s[0])break;e.i=s=s[2]}};(He.prototype=new Ne).__a=function(e){var n=this,s=on(n.__v),l=n.l.get(e);return l[0]++,function(r){var a=function(){n.props.revealOrder?(l.push(r),Ft(n,e,l)):r()};s?s(a):a()}},He.prototype.render=function(e){this.i=null,this.l=new Map;var n=it(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&n.reverse();for(var s=n.length;s--;)this.l.set(n[s],this.i=[1,0,this.i]);return e.children},He.prototype.componentDidUpdate=He.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(n,s){Ft(e,s,n)})};var ps=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,xs=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,vs=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,gs=/[A-Z0-9]/g,bs=typeof document<"u",_s=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};Ne.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(Ne.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(n){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:n})}})});var At=D.event;D.event=function(e){return At&&(e=At(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var ys={configurable:!0,get:function(){return this.class}},Dt=D.vnode;D.vnode=function(e){typeof e.type=="string"&&function(n){var s=n.props,l=n.type,r={},a=l.indexOf("-")==-1;for(var i in s){var o=s[i];if(!(i==="value"&&"defaultValue"in s&&o==null||bs&&i==="children"&&l==="noscript"||i==="class"||i==="className")){var c=i.toLowerCase();i==="defaultValue"&&"value"in s&&s.value==null?i="value":i==="download"&&o===!0?o="":c==="translate"&&o==="no"?o=!1:c[0]==="o"&&c[1]==="n"?c==="ondoubleclick"?i="ondblclick":c!=="onchange"||l!=="input"&&l!=="textarea"||_s(s.type)?c==="onfocus"?i="onfocusin":c==="onblur"?i="onfocusout":vs.test(i)&&(i=c):c=i="oninput":a&&xs.test(i)?i=i.replace(gs,"-$&").toLowerCase():o===null&&(o=void 0),c==="oninput"&&r[i=c]&&(i="oninputCapture"),r[i]=o}}l=="select"&&(r.multiple&&Array.isArray(r.value)&&(r.value=it(s.children).forEach(function(d){d.props.selected=r.value.indexOf(d.props.value)!=-1})),r.defaultValue!=null&&(r.value=it(s.children).forEach(function(d){d.props.selected=r.multiple?r.defaultValue.indexOf(d.props.value)!=-1:r.defaultValue==d.props.value}))),s.class&&!s.className?(r.class=s.class,Object.defineProperty(r,"className",ys)):s.className&&(r.class=r.className=s.className),n.props=r}(e),e.$$typeof=ps,Dt&&Dt(e)};var Ot=D.__r;D.__r=function(e){Ot&&Ot(e),e.__c};var jt=D.diffed;D.diffed=function(e){jt&&jt(e);var n=e.props,s=e.__e;s!=null&&e.type==="textarea"&&"value"in n&&n.value!==s.value&&(s.value=n.value==null?"":n.value)};const Ns=10;function ws({points:e,width:n=800,height:s=600,onPointClick:l,renderTooltip:r}){const a=te(null),[i,o]=g({x:0,y:0,scale:1}),[c,d]=g(null),[u,f]=g(!1),x=te({x:0,y:0}),h=te(null),p=te(null),m=te(e);m.current=e;const _=Nt(S=>{h.current=S(h.current??i),p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null,h.current&&(o(h.current),h.current=null)}))},[i]);O(()=>()=>{p.current!==null&&cancelAnimationFrame(p.current)},[]);const T=Nt((S,N)=>{const I=a.current;if(!I)return null;const K=I.getBoundingClientRect(),B=h.current??i,me=S-K.left,pe=N-K.top;let Se=null,F=Ns;for(const xe of m.current){const ve=xe.x*n*B.scale+B.x,ge=xe.y*s*B.scale+B.y,oe=me-ve,Ce=pe-ge,$e=Math.sqrt(oe*oe+Ce*Ce);$e<=F&&(F=$e,Se=xe)}return Se},[i,n,s]);O(()=>{const S=a.current;if(!S)return;const N=S.getContext("2d");if(!N)return;const I=window.devicePixelRatio||1;S.width=n*I,S.height=s*I,N.scale(I,I),N.clearRect(0,0,n,s),N.save(),N.translate(i.x,i.y),N.scale(i.scale,i.scale);for(const K of e){const B=K.x*n,me=K.y*s,pe=(K.radius??3)*(K.highlighted?2:1);N.beginPath(),N.arc(B,me,pe,0,Math.PI*2),N.fillStyle=K.color,N.globalAlpha=K.highlighted?1:.6,N.fill(),K.highlighted&&(N.strokeStyle="#22d3ee",N.lineWidth=2,N.stroke())}N.restore()},[e,i,n,s]);const M=S=>{S.preventDefault();const N=S.deltaY>0?.9:1.1;_(I=>({...I,scale:Math.max(.5,Math.min(10,I.scale*N))}))},y=S=>{f(!0),x.current={x:S.clientX-i.x,y:S.clientY-i.y}},Y=S=>{if(u){_(I=>({...I,x:S.clientX-x.current.x,y:S.clientY-x.current.y}));return}const N=T(S.clientX,S.clientY);d(I=>(I==null?void 0:I.id)===(N==null?void 0:N.id)?I:N)},Ue=()=>f(!1);return t("div",{className:"relative overflow-hidden rounded-lg border border-slate-700 bg-slate-900",style:{width:n,height:s},children:[t("canvas",{ref:a,className:"absolute inset-0 cursor-grab active:cursor-grabbing",onMouseDown:y,onMouseMove:Y,onMouseUp:Ue,onMouseLeave:Ue,onClick:S=>{if(u)return;const N=T(S.clientX,S.clientY);N&&(l==null||l(N.id))},onWheel:M}),c&&r&&t("div",{className:"absolute bg-slate-800 border border-slate-600 rounded-lg p-3 shadow-xl text-sm z-10 pointer-events-none",style:{left:Math.min(c.x*n*i.scale+i.x+12,n-200),top:Math.min(c.y*s*i.scale+i.y-12,s-80)},children:r(c)}),i.scale!==1&&t("button",{className:"absolute bottom-3 right-3 px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors z-20",onClick:()=>{o({x:0,y:0,scale:1}),h.current=null},children:"Reset zoom"})]})}function Me(e,n){const s=e.x-n.x,l=e.y-n.y,r=(e.z??0)-(n.z??0);return Math.sqrt(s*s+l*l+r*r)}function ks(e,n=8,s=20){const l=e.length;if(l<=n)return e.map((i,o)=>o);const r=new Array(l).fill(0),a=[];a.push(e[Math.floor(Math.random()*l)]);for(let i=1;i<n;i++){const o=e.map(u=>Math.min(...a.map(f=>Me(u,f)))),c=o.reduce((u,f)=>u+f*f,0);let d=Math.random()*c;for(let u=0;u<l;u++)if(d-=o[u]*o[u],d<=0){a.push(e[u]);break}}for(let i=0;i<s;i++){for(let c=0;c<l;c++){let d=0,u=Me(e[c],a[0]);for(let f=1;f<a.length;f++){const x=Me(e[c],a[f]);x<u&&(u=x,d=f)}r[c]=d}const o=a.map(()=>({x:0,y:0,z:0,count:0}));for(let c=0;c<l;c++){const d=r[c];o[d].x+=e[c].x,o[d].y+=e[c].y,o[d].z+=e[c].z??0,o[d].count++}a.forEach((c,d)=>{o[d].count>0&&(c.x=o[d].x/o[d].count,c.y=o[d].y/o[d].count,c.z!==void 0&&(c.z=o[d].z/o[d].count))})}return r}function Ss(e,n,s){const l=s.map((a,i)=>{const c=e.filter((f,x)=>n[x]===i).map(f=>Me(f,a)),d=c.reduce((f,x)=>f+x,0)/c.length,u=c.reduce((f,x)=>f+(x-d)**2,0)/c.length;return Math.sqrt(u)}),r=new Set;for(let a=0;a<e.length;a++){const i=n[a];Me(e[a],s[i])>2*(l[i]??0)&&r.add(a)}return r}const Cs=ms(()=>us(()=>import("./ScatterPlot3D-CzbmvDSQ.js"),__vite__mapDeps([0,1])).then(e=>({default:e.ScatterPlot3D}))),Ke=["#3b82f6","#ef4444","#22c55e","#f59e0b","#a855f7","#06b6d4","#ec4899","#84cc16","#f97316","#14b8a6","#8b5cf6","#e11d48","#65a30d","#0ea5e9","#d946ef","#ca8a04","#64748b","#4ade80","#fb7185","#38bdf8"],lt=2,Ut=50,zt=5,qt=200,$s=20,Ls=12;function Ts(){var ft,mt;const{data:e,isLoading:n,error:s,refresh:l}=J(()=>$.embeddingProj(5e3,3)),[r,a]=g("language"),[i,o]=g("3d"),[c,d]=g(!1),[u,f]=g(8),[x,h]=g(20),[p,m]=g(!1),[_,T]=g(new Set),[M,y]=g(5),[Y,Ue]=g(0),[z,S]=g(null),[N,I]=g(!1),K=te(0),[B,me]=g(null),[pe,Se]=g(new Set),F=((ft=e==null?void 0:e.body)==null?void 0:ft.points)??(e==null?void 0:e.points)??[],xe=((mt=e==null?void 0:e.body)==null?void 0:mt.totalChunks)??(e==null?void 0:e.totalChunks)??0;if(O(()=>{var v;if(r==="cluster"&&F.length>0){const P=Math.max(lt,Math.min(u,F.length)),w=ks(F,P,x);if(me(w),c){const q=[];for(let be=0;be<P;be++){const Q=F.filter((Le,ce)=>w[ce]===be);if(Q.length>0){const Le=((v=Q[0])==null?void 0:v.z)!==void 0;q.push({x:Q.reduce((ce,Te)=>ce+Te.x,0)/Q.length,y:Q.reduce((ce,Te)=>ce+Te.y,0)/Q.length,...Le?{z:Q.reduce((ce,Te)=>ce+(Te.z??0),0)/Q.length}:{}})}}Se(Ss(F,w,q))}}else me(null),Se(new Set)},[r,c,u,x,F]),O(()=>{p&&ae.value.length>0?T(new Set(ae.value.map(v=>v.chunk.id))):T(new Set)},[p,ae.value]),n)return t(G,{type:"chart"});if(s)return t(ee,{message:s,onRetry:l});if(F.length===0)return t(fe,{icon:"🌐",message:"No embedding data available. Index some files first."});const ve=le(()=>Is(F),[F]),ge=le(()=>F.map((v,P)=>{let w;if(r==="language")w=je(v.language)==="text-slate-400"?"#94a3b8":Rs(v.language);else if(r==="file")w=ve.get(v.filePath)??"#94a3b8";else{const Le=(B==null?void 0:B[P])??0;w=Ke[Le%Ke.length]}const q=pe.has(P),Q=_.has(v.id);return{id:v.id,x:v.x,y:v.y,z:v.z??.5,color:Q?"#22d3ee":q?"#f97316":w,label:`${v.filePath}:${v.startLine}-${v.endLine} [${v.language}]`,radius:Q?6:q?5:3,highlighted:Q}}),[F,r,B,pe,_,ve]),oe=le(()=>{if(r!=="file")return[];const v=Ps(F.map(w=>w.filePath)),P=new Map;for(const w of F)P.set(w.filePath,(P.get(w.filePath)??0)+1);return[...P.entries()].sort((w,q)=>q[1]-w[1]).slice(0,Ls).map(([w,q])=>({label:w.slice(v.length)||w,count:q,color:ve.get(w)??"#94a3b8"}))},[r,F,ve]),Ce=le(()=>r!=="file"?0:new Set(F.map(v=>v.filePath)).size-oe.length,[r,F,oe]),$e=v=>{const P=++K.current;S(null),I(!0),$.chunk(v).then(w=>{P===K.current&&(S(w),I(!1))}).catch(()=>{P===K.current&&(S({id:v,content:"",filePath:"not found",language:"",startLine:0,endLine:0,description:"Error loading chunk details."}),I(!1))})};return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Embedding Space Explorer"}),t("div",{className:"flex flex-wrap gap-3 mb-4 items-center",children:[t("div",{className:"flex items-center gap-1 bg-slate-800 border border-slate-600 rounded-lg p-0.5",children:["2d","3d"].map(v=>t("button",{className:`px-2 py-0.5 rounded text-xs transition-colors ${i===v?"bg-slate-600 text-white":"text-slate-400 hover:text-slate-200"}`,onClick:()=>o(v),children:v.toUpperCase()},v))}),t("label",{className:"text-xs text-slate-400",children:"Color by:"}),t("select",{className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1",value:r,onChange:v=>a(v.target.value),children:[t("option",{value:"language",children:"Language"}),t("option",{value:"file",children:"File"}),t("option",{value:"cluster",children:"Cluster"})]}),r==="cluster"&&t(ie,{children:[t("label",{className:"text-xs text-slate-400",children:"K:"}),t("input",{type:"number",min:lt,max:Ut,value:u,onChange:v=>f(Ht(v.target,lt,Ut,8)),className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1 w-16",title:"Number of clusters"}),t("label",{className:"text-xs text-slate-400",children:"Iterations:"}),t("input",{type:"number",min:zt,max:qt,value:x,onChange:v=>h(Ht(v.target,zt,qt,20)),className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1 w-20",title:"Maximum k-means iterations"})]}),t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:c,onChange:v=>d(v.target.checked)}),"Outliers"]}),ae.value.length>0&&t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:p,onChange:v=>m(v.target.checked)}),"Search overlay (",ae.value.length," results)"]}),i==="3d"&&t(ie,{children:[t("label",{className:"text-xs text-slate-400",children:"Point size:"}),t("input",{type:"range",min:1,max:20,value:M,onChange:v=>y(Number(v.target.value)),className:"w-24 accent-brand-500"}),t("button",{className:"px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors",onClick:()=>Ue(v=>v+1),children:"Reset camera"})]})]}),r==="cluster"&&B&&t("div",{className:"flex flex-wrap gap-2 mb-3 text-xs",children:(()=>{const v=Array.from(new Set(B)).sort((q,be)=>q-be),P=v.slice(0,$s),w=v.length-P.length;return t(ie,{children:[P.map(q=>t("span",{className:"flex items-center gap-1 text-slate-400",children:[t("span",{className:"inline-block w-2 h-2 rounded-full",style:{background:Ke[q%Ke.length]}}),"Cluster ",q+1]},q)),w>0&&t("span",{className:"text-slate-500",children:["+",w," more"]})]})})()}),r==="file"&&oe.length>0&&t("div",{className:"flex flex-wrap gap-2 mb-3 text-xs",children:[oe.map(({label:v,count:P,color:w})=>t("span",{className:"flex items-center gap-1 text-slate-400",title:v,children:[t("span",{className:"inline-block w-2 h-2 rounded-full",style:{background:w}}),k(Lt(v,40))," (",P,")"]},v)),Ce>0&&t("span",{className:"text-slate-500",children:["+",Ce," more files"]})]}),i==="3d"?t(We,{fallback:t(G,{type:"chart"}),children:t(Cs,{points:ge,width:900,height:600,onPointClick:$e,pointSize:M,resetKey:Y,selectedId:(z==null?void 0:z.id)??null})}):t(ws,{points:ge,width:900,height:600,onPointClick:$e,renderTooltip:v=>{const P=F.find(w=>w.id===v.id);return t("div",{children:[t("div",{className:"text-yellow-400 font-mono text-xs",children:k(v.label)}),(P==null?void 0:P.description)&&t("div",{className:"text-slate-400 text-xs mt-1",children:k(Lt(P.description,80))})]})}}),N&&t(G,{type:"detail"}),z&&!N&&t("div",{className:"kpi-card p-4 mt-4",children:[t("div",{className:"flex items-center gap-3 mb-1 flex-wrap",children:[t("span",{className:"text-yellow-400 font-mono text-sm",children:k(z.filePath)}),t("span",{className:"text-slate-400 text-xs",children:["Lines ",z.startLine,"-",z.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(z.language)}}),z.id&&t("span",{className:"text-xs text-slate-600 font-mono",children:z.id}),t("button",{className:"ml-auto px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors",onClick:()=>j(`chunks?id=${encodeURIComponent(z.id)}`),children:"Open in Chunks"})]}),z.description&&t("div",{className:"mb-3",children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Description"}),t("p",{className:"text-sm text-slate-300",children:k(z.description)})]}),z.content&&t("div",{children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Content"}),t("pre",{className:"text-xs text-slate-300 bg-slate-900 border border-slate-700 rounded p-3 overflow-auto max-h-64 font-mono whitespace-pre",children:k(z.content)})]})]}),t("p",{className:"text-xs text-slate-500 mt-2",children:[ge.length," of ",xe," chunks displayed",ge.length<xe&&" (chunks without embeddings omitted)"]})]})}function Ht(e,n,s,l){const r=parseInt((e==null?void 0:e.value)??"",10);return Number.isNaN(r)?l:Math.max(n,Math.min(s,r))}function Ps(e){if(e.length===0)return"";let n=e[0]??"";for(const l of e)for(;l&&n&&!l.startsWith(n);)n=n.slice(0,-1);const s=n.lastIndexOf("/");return s>=0?n.slice(0,s+1):""}function Is(e){const n=new Map;for(const h of e){const p=n.get(h.filePath)??{x:0,y:0,z:0,n:0};p.x+=h.x,p.y+=h.y,p.z+=h.z??0,p.n++,n.set(h.filePath,p)}const s=[];for(const[h,p]of n)s.push({file:h,x:p.x/p.n,y:p.y/p.n,z:p.z/p.n});const l=s.reduce((h,p)=>h+p.x,0)/s.length,r=s.reduce((h,p)=>h+p.y,0)/s.length,a=s.reduce((h,p)=>h+p.z,0)/s.length,i=s.reduce((h,p)=>h+(p.x-l)**2,0),o=s.reduce((h,p)=>h+(p.y-r)**2,0),c=s.reduce((h,p)=>h+(p.z-a)**2,0),d=i>=o&&i>=c?"x":o>=c?"y":"z",u=["x","y","z"].filter(h=>h!==d);s.sort((h,p)=>h[d]-p[d]||h[u[0]]-p[u[0]]||h[u[1]]-p[u[1]]);const f=new Map,x=137.508;for(let h=0;h<s.length;h++){const p=h*x%360,m=h%2===0?55:40;f.set(s[h].file,`hsl(${p.toFixed(1)}, 80%, ${m}%)`)}return f}function Rs(e){return{typescript:"#60a5fa",javascript:"#facc15",python:"#4ade80",java:"#f87171",go:"#22d3ee",rust:"#fb923c",ruby:"#f472b6",csharp:"#a78bfa",cpp:"#818cf8",c:"#9ca3af",markdown:"#d1d5db",html:"#fdba74",css:"#60a5fa",json:"#fde047",kotlin:"#c084fc",swift:"#fb923c",tex:"#34d399",sql:"#67e8f9",text:"#94a3b8",image:"#a78bfa",quirk:"#fbbf24"}[e]??"#94a3b8"}const Es=[{view:"dashboard",label:"Dashboard",icon:"📊"},{view:"search",label:"Search",icon:"🔍"},{view:"embeddings",label:"Embeddings",icon:"🌐"},{view:"chunks",label:"Chunks",icon:"🧩"},{view:"files",label:"Files",icon:"📄"},{view:"evaluate",label:"Evaluate",icon:"📈"},{view:"quirks",label:"Quirks",icon:"💡"}];function Ms(){Cn(),$n();const e=De();nt.value=e.view;const n=()=>{qe.value=!qe.value};return t("div",{className:"h-screen flex flex-col overflow-hidden",children:[t("header",{className:"flex items-center gap-3 px-4 py-2 border-b shrink-0",style:{borderColor:"var(--border)"},children:[t("h1",{className:"text-lg font-bold shrink-0",style:{color:"var(--accent)"},children:"OpenCodeRAG"}),t("nav",{className:"flex gap-1 flex-1",role:"navigation","aria-label":"Main navigation",children:Es.map(s=>t("button",{id:`nav-${s.view}`,className:`nav-btn ${nt.value===s.view?"active":""}`,onClick:()=>window.location.hash=s.view,role:"tab","aria-selected":nt.value===s.view,children:[s.icon," ",s.label]},s.view))}),t(Fn,{}),t(Tn,{}),t("button",{className:"p-2 rounded-lg transition-colors hidden lg:block",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"}),t("button",{className:"p-2 rounded-lg transition-colors lg:hidden",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"})]}),t("div",{className:"flex flex-1 overflow-hidden",children:[qe.value&&t(ie,{children:[t("div",{className:"fixed inset-0 z-30 lg:hidden",style:{background:"rgba(0,0,0,0.5)"},onClick:()=>{qe.value=!1}}),t("aside",{className:"w-64 overflow-y-auto shrink-0 border-r z-40 fixed lg:relative inset-y-0 left-0",style:{background:"var(--bg-secondary)",borderColor:"var(--border)"},role:"tree","aria-label":"File tree",children:t(An,{})})]}),t("main",{className:"flex-1 overflow-y-auto p-6",id:"main-content",tabIndex:-1,children:[e.view==="dashboard"&&t(zn,{}),e.view==="search"&&t(ns,{}),e.view==="embeddings"&&t(Ts,{}),e.view==="compare"&&t(ls,{}),e.view==="chunks"&&t(qn,{}),e.view==="files"&&t(Kn,{}),e.view==="evaluate"&&t(Vn,{}),e.view==="quirks"&&t(Jn,{}),e.view==="config"&&t(is,{})]})]}),t(Ln,{})]})}dn(t(Ms,{}),document.getElementById("app"));export{te as A,O as h,t as u};
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>OpenCodeRAG</title>
7
7
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🔎</text></svg>">
8
- <script type="module" crossorigin src="/ui/assets/index-BdPHzjQh.js"></script>
8
+ <script type="module" crossorigin src="/ui/assets/index-DOSfQsyL.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/ui/assets/vendor-Dy7HKFCY.js">
10
10
  <link rel="stylesheet" crossorigin href="/ui/assets/index-BLzCza1W.css">
11
11
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-rag-plugin",
3
- "version": "1.20.0",
3
+ "version": "1.21.0",
4
4
  "description": "OpenCode plugin for local-first RAG-based semantic code search",
5
5
  "type": "module",
6
6
  "main": "./dist/plugin-entry.js",
@@ -1,4 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ScatterPlot3D-BFWO5sAH.js","assets/vendor-Dy7HKFCY.js"])))=>i.map(i=>d[i]);
2
- import{l as O,S as ie,C as Ne,t as cn,k as lt,F as it,R as dn}from"./vendor-Dy7HKFCY.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))a(l);new MutationObserver(l=>{for(const r of l)if(r.type==="childList")for(const i of r.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&a(i)}).observe(document,{childList:!0,subtree:!0});function s(l){const r={};return l.integrity&&(r.integrity=l.integrity),l.referrerPolicy&&(r.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?r.credentials="include":l.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function a(l){if(l.ep)return;l.ep=!0;const r=s(l);fetch(l.href,r)}})();var un=0;function t(e,n,s,a,l,r){n||(n={});var i,o,c=n;if("ref"in c)for(o in c={},n)o=="ref"?i=n[o]:c[o]=n[o];var d={type:e,props:c,key:s,ref:i,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--un,__i:-1,__u:0,__source:l,__self:r};if(typeof e=="function"&&(i=e.defaultProps))for(o in i)c[o]===void 0&&(c[o]=i[o]);return O.vnode&&O.vnode(d),d}var Ae,E,tt,pt,De=0,Kt=[],D=O,xt=D.__b,vt=D.__r,gt=D.diffed,bt=D.__c,_t=D.unmount,yt=D.__;function dt(e,n){D.__h&&D.__h(E,e,De||n),De=0;var s=E.__H||(E.__H={__:[],__h:[]});return e>=s.__.length&&s.__.push({}),s.__[e]}function g(e){return De=1,hn(Wt,e)}function hn(e,n,s){var a=dt(Ae++,2);if(a.t=e,!a.__c&&(a.__=[s?s(n):Wt(void 0,n),function(o){var c=a.__N?a.__N[0]:a.__[0],d=a.t(c,o);c!==d&&(a.__N=[d,a.__[1]],a.__c.setState({}))}],a.__c=E,!E.__f)){var l=function(o,c,d){if(!a.__c.__H)return!0;var u=!1,f=a.__c.props!==o;if(a.__c.__H.__.some(function(h){if(h.__N){u=!0;var p=h.__[0];h.__=h.__N,h.__N=void 0,p!==h.__[0]&&(f=!0)}}),r){var x=r.call(this,o,c,d);return u?x||f:x}return!u||f};E.__f=!0;var r=E.shouldComponentUpdate,i=E.componentWillUpdate;E.componentWillUpdate=function(o,c,d){if(this.__e){var u=r;r=void 0,l(o,c,d),r=u}i&&i.call(this,o,c,d)},E.shouldComponentUpdate=l}return a.__N||a.__}function j(e,n){var s=dt(Ae++,3);!D.__s&&Bt(s.__H,n)&&(s.__=e,s.u=n,E.__H.__h.push(s))}function te(e){return De=5,re(function(){return{current:e}},[])}function re(e,n){var s=dt(Ae++,7);return Bt(s.__H,n)&&(s.__=e(),s.__H=n,s.__h=e),s.__}function Nt(e,n){return De=8,re(function(){return e},n)}function fn(){for(var e;e=Kt.shift();){var n=e.__H;if(e.__P&&n)try{n.__h.some(Be),n.__h.some(ot),n.__h=[]}catch(s){n.__h=[],D.__e(s,e.__v)}}}D.__b=function(e){E=null,xt&&xt(e)},D.__=function(e,n){e&&n.__k&&n.__k.__m&&(e.__m=n.__k.__m),yt&&yt(e,n)},D.__r=function(e){vt&&vt(e),Ae=0;var n=(E=e.__c).__H;n&&(tt===E?(n.__h=[],E.__h=[],n.__.some(function(s){s.__N&&(s.__=s.__N),s.u=s.__N=void 0})):(n.__h.some(Be),n.__h.some(ot),n.__h=[],Ae=0)),tt=E},D.diffed=function(e){gt&&gt(e);var n=e.__c;n&&n.__H&&(n.__H.__h.length&&(Kt.push(n)!==1&&pt===D.requestAnimationFrame||((pt=D.requestAnimationFrame)||mn)(fn)),n.__H.__.some(function(s){s.u&&(s.__H=s.u,s.u=void 0)})),tt=E=null},D.__c=function(e,n){n.some(function(s){try{s.__h.some(Be),s.__h=s.__h.filter(function(a){return!a.__||ot(a)})}catch(a){n.some(function(l){l.__h&&(l.__h=[])}),n=[],D.__e(a,s.__v)}}),bt&&bt(e,n)},D.unmount=function(e){_t&&_t(e);var n,s=e.__c;s&&s.__H&&(s.__H.__.some(function(a){try{Be(a)}catch(l){n=l}}),s.__H=void 0,n&&D.__e(n,s.__v))};var wt=typeof requestAnimationFrame=="function";function mn(e){var n,s=function(){clearTimeout(a),wt&&cancelAnimationFrame(n),setTimeout(e)},a=setTimeout(s,35);wt&&(n=requestAnimationFrame(s))}function Be(e){var n=E,s=e.__c;typeof s=="function"&&(e.__c=void 0,s()),E=n}function ot(e){var n=E;e.__c=e.__(),E=n}function Bt(e,n){return!e||e.length!==n.length||n.some(function(s,a){return s!==e[a]})}function Wt(e,n){return typeof n=="function"?n(e):n}function kt(){const e=location.hash.slice(1)||"dashboard",n=e.indexOf("?"),s=n>=0?e.slice(0,n):e,a={};if(n>=0){const l=e.slice(n+1);for(const r of l.split("&")){const i=r.indexOf("=");if(i>=0)try{a[decodeURIComponent(r.slice(0,i))]=decodeURIComponent(r.slice(i+1))}catch{}}}return{view:s||"dashboard",params:a}}function Oe(){const[e,n]=g(kt);return j(()=>{const s=()=>n(kt());return addEventListener("hashchange",s),()=>removeEventListener("hashchange",s)},[]),e}var pn=Symbol.for("preact-signals");function Je(){if(ne>1)ne--;else{var e,n=!1;for(function(){var l=Ge;for(Ge=void 0;l!==void 0;){var r=l.S;if(r.v===l.v)for(var i=r.t;i!==void 0;i=i.x)i.i===l.i&&(i.i=r.i);l=l.o}}();Ee!==void 0;){var s=Ee;for(Ee=void 0,Ve++;s!==void 0;){var a=s.u;if(s.u=void 0,s.f&=-3,!(8&s.f)&&Gt(s))try{s.c()}catch(l){n||(e=l,n=!0)}s=a}}if(Ve=0,ne--,n)throw e}}function xn(e){if(ne>0)return e();ct=++vn,ne++;try{return e()}finally{Je()}}var Ie,C=void 0;function et(e){var n=C,s=Ie;C=void 0,Ie=void 0;try{return e()}finally{C=n,Ie=s}}var Ee=void 0,ne=0,Ve=0,vn=0,ct=0,Ge=void 0,Qe=0;function Vt(e){if(C!==void 0){var n=e.n;if(n===void 0||n.t!==C)return n={i:0,S:e,p:C.s,n:void 0,t:C,e:void 0,x:void 0,r:n},C.s!==void 0&&(C.s.n=n),C.s=n,e.n=n,32&C.f&&e.S(n),n;if(n.i===-1)return n.i=0,n.n!==void 0&&(n.n.p=n.p,n.p!==void 0&&(n.p.n=n.n),n.p=C.s,n.n=void 0,C.s.n=n,C.s=n),n}}function U(e,n){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=n==null?void 0:n.watched,this.Z=n==null?void 0:n.unwatched,this.name=n==null?void 0:n.name}U.prototype.brand=pn;U.prototype.h=function(){return!0};U.prototype.S=function(e){var n=this,s=this.t;s!==e&&e.e===void 0&&(e.x=s,this.t=e,s!==void 0?s.e=e:et(function(){var a;(a=n.W)==null||a.call(n)}))};U.prototype.U=function(e){var n=this;if(this.t!==void 0){var s=e.e,a=e.x;s!==void 0&&(s.x=a,e.e=void 0),a!==void 0&&(a.e=s,e.x=void 0),e===this.t&&(this.t=a,a===void 0&&et(function(){var l;(l=n.Z)==null||l.call(n)}))}};U.prototype.subscribe=function(e){var n=this;return je(function(){var s=n.value;et(function(){return e(s)})},{name:"sub"})};U.prototype.valueOf=function(){return this.value};U.prototype.toString=function(){return this.value+""};U.prototype.toJSON=function(){return this.value};U.prototype.peek=function(){var e=this;return et(function(){return e.value})};Object.defineProperty(U.prototype,"value",{get:function(){var e=Vt(this);return e!==void 0&&(e.i=this.i),this.v},set:function(e){if(e!==this.v){if(Ve>100)throw new Error("Cycle detected");(function(s){ne!==0&&Ve===0&&s.l!==ct&&(s.l=ct,Ge={S:s,v:s.v,i:s.i,o:Ge})})(this),this.v=e,this.i++,Qe++,ne++;try{for(var n=this.t;n!==void 0;n=n.x)n.t.N()}finally{Je()}}}});function L(e,n){return new U(e,n)}function Gt(e){for(var n=e.s;n!==void 0;n=n.n)if(n.S.i!==n.i||!n.S.h()||n.S.i!==n.i)return!0;return!1}function Qt(e){for(var n=e.s;n!==void 0;n=n.n){var s=n.S.n;if(s!==void 0&&(n.r=s),n.S.n=n,n.i=-1,n.n===void 0){e.s=n;break}}}function Xt(e){for(var n=e.s,s=void 0;n!==void 0;){var a=n.p;n.i===-1?(n.S.U(n),a!==void 0&&(a.n=n.n),n.n!==void 0&&(n.n.p=a)):s=n,n.S.n=n.r,n.r!==void 0&&(n.r=void 0),n=a}e.s=s}function ue(e,n){U.call(this,void 0,n),this.x=e,this.s=void 0,this.g=Qe-1,this.f=4}ue.prototype=new U;ue.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Qe))return!0;if(this.g=Qe,this.f|=1,this.i>0&&!Gt(this))return this.f&=-2,!0;var e=C;try{Qt(this),C=this;var n=this.x();(16&this.f||this.v!==n||this.i===0)&&(this.v=n,this.f&=-17,this.i++)}catch(s){this.v=s,this.f|=16,this.i++}return C=e,Xt(this),this.f&=-2,!0};ue.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(var n=this.s;n!==void 0;n=n.n)n.S.S(n)}U.prototype.S.call(this,e)};ue.prototype.U=function(e){if(this.t!==void 0&&(U.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(var n=this.s;n!==void 0;n=n.n)n.S.U(n)}};ue.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var e=this.t;e!==void 0;e=e.x)e.t.N()}};Object.defineProperty(ue.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var e=Vt(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function St(e,n){return new ue(e,n)}function Zt(e){var n=e.m;if(e.m=void 0,typeof n=="function"){ne++;var s=C;C=void 0;try{n()}catch(a){throw e.f&=-2,e.f|=8,ut(e),a}finally{C=s,Je()}}}function ut(e){for(var n=e.s;n!==void 0;n=n.n)n.S.U(n);e.x=void 0,e.s=void 0,Zt(e)}function gn(e){if(C!==this)throw new Error("Out-of-order effect");Xt(this),C=e,this.f&=-2,8&this.f&&ut(this),Je()}function we(e,n){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=n==null?void 0:n.name,Ie&&Ie.push(this)}we.prototype.c=function(){var e=this.S();try{if(8&this.f||this.x===void 0)return;var n=this.x();typeof n=="function"&&(this.m=n)}finally{e()}};we.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Zt(this),Qt(this),ne++;var e=C;return C=this,gn.bind(this,e)};we.prototype.N=function(){2&this.f||(this.f|=2,this.u=Ee,Ee=this)};we.prototype.d=function(){this.f|=8,1&this.f||ut(this)};we.prototype.dispose=function(){this.d()};function je(e,n){var s=new we(e,n);try{s.c()}catch(l){throw s.d(),l}var a=s.d.bind(s);return a[Symbol.dispose]=a,a}var Yt,ze,bn=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Jt=[];je(function(){Yt=this.N})();function ke(e,n){O[e]=n.bind(null,O[e]||function(){})}function Xe(e){if(ze){var n=ze;ze=void 0,n()}ze=e&&e.S()}function en(e){var n=this,s=e.data,a=yn(s);a.name="ReactiveDom",a.value=s;var l=re(function(){for(var o=n,c=n.__v;c=c.__;)if(c.__c){c.__c.__$f|=4;break}var d=St(function(){var h=a.value.value;return h===0?0:h===!0?"":h||""}),u=St(function(){return!Array.isArray(d.value)&&!cn(d.value)}),f=je(function(){if(this.N=tn,u.value){var h=d.value;o.__v&&o.__v.__e&&o.__v.__e.nodeType===3&&(o.__v.__e.data=h)}}),x=n.__$u.d;return n.__$u.d=function(){f(),x.call(this)},[u,d]},[]),r=l[0],i=l[1];return r.value?i.peek():i.value}en.displayName="ReactiveTextNode";Object.defineProperties(U.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:en},props:{configurable:!0,get:function(){var e=this;return{data:{get value(){return e.value}}}}},__b:{configurable:!0,value:1}});ke("__b",function(e,n){if(typeof n.type=="string"){var s,a=n.props;for(var l in a)if(l!=="children"){var r=a[l];r instanceof U&&(s||(n.__np=s={}),s[l]=r,a[l]=r.peek())}}e(n)});ke("__r",function(e,n){if(e(n),n.type!==ie){Xe();var s,a=n.__c;a&&(a.__$f&=-2,(s=a.__$u)===void 0&&(a.__$u=s=function(l,r){var i;return je(function(){i=this},{name:r}),i.c=l,i}(function(){var l;bn&&((l=s.y)==null||l.call(s)),a.__$f|=1,a.setState({})},typeof n.type=="function"?n.type.displayName||n.type.name:""))),Xe(s)}});ke("__e",function(e,n,s,a){Xe(),e(n,s,a)});ke("diffed",function(e,n){Xe();var s;if(typeof n.type=="string"&&(s=n.__e)){var a=n.__np,l=n.props,r=s.U;if(r)for(var i in r){var o=r[i];o===void 0||a&&i in a||(o.d(),r[i]=void 0)}if(a){r||(r={},s.U=r);for(var c in a){var d=r[c],u=a[c];d===void 0?(d=_n(s,c,u,l),r[c]=d):d.o(u,l)}}}e(n)});function _n(e,n,s,a){var l=n in e&&e.ownerSVGElement===void 0,r=L(s);return{o:function(i,o){r.value=i,a=o},d:je(function(){this.N=tn;var i=r.value.value;a[n]!==i&&(a[n]=i,l?e[n]=i:i!=null&&(i!==!1||n[4]==="-")?e.setAttribute(n,i):e.removeAttribute(n))})}}ke("unmount",function(e,n){if(typeof n.type=="string"){var s=n.__e;if(s){var a=s.U;if(a){s.U=void 0;for(var l in a){var r=a[l];r&&r.d()}}}var i=n.__np;if(i){var o=n.props;for(var c in i)o[c]=i[c]}n.__np=void 0}else{var d=n.__c;if(d){var u=d.__$u;u&&(d.__$u=void 0,u.d())}}e(n)});ke("__h",function(e,n,s,a){a<3&&(n.__$f|=2),e(n,s,a)});Ne.prototype.shouldComponentUpdate=function(e,n){if(this.__R)return!0;var s=this.__$u,a=s&&s.s!==void 0;for(var l in n)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var r=2&this.__$f;if(!(a||r||4&this.__$f)||1&this.__$f)return!0}else if(!(a||4&this.__$f)||3&this.__$f)return!0;for(var i in e)if(i!=="__source"&&e[i]!==this.props[i])return!0;for(var o in this.props)if(!(o in e))return!0;return!1};function yn(e,n){return re(function(){return L(e,n)},[])}var Nn=function(e){queueMicrotask(function(){queueMicrotask(e)})};function wn(){xn(function(){for(var e;e=Jt.shift();)Yt.call(e)})}function tn(){Jt.push(this)===1&&(O.requestAnimationFrame||Nn)(wn)}const nt=L("dashboard"),de=L(null),_e=L(null),ye=L(null),Pe=L(0),kn=L(50),X=L(new Set),st=L(new Set),W=L(""),S=L({topK:10,minScore:.35,keywordWeight:.4,hybrid:!0,pathFilter:"",langFilter:""}),ae=L([]),Ze=L([]);L(!1);L(null);L([]);L(new Set);L(null);L(null);const se=L(typeof localStorage<"u"?localStorage.getItem("theme")??"dark":"dark"),qe=L(!0),Re=L([]);let Sn=0;function le(e,n,s=4e3){const a=Sn++;Re.value=[...Re.value,{id:a,type:e,message:n,duration:s}],setTimeout(()=>{Re.value=Re.value.filter(l=>l.id!==a)},s)}function F(e){window.location.hash=e}function Cn(){j(()=>{document.documentElement.classList.toggle("dark",se.value==="dark"),localStorage.setItem("theme",se.value)},[se.value]);const e=()=>{se.value=se.value==="dark"?"light":"dark"};return{theme:se.value,toggle:e}}function $n(){j(()=>{let e=null,n=null;const s=()=>{e&&(clearTimeout(e),e=null),n&&(window.removeEventListener("keydown",n),n=null)},a=l=>{const r=l.target,i=r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable;if((l.metaKey||l.ctrlKey)&&l.key==="k"){l.preventDefault(),F("search"),setTimeout(()=>{var o;(o=document.querySelector(".global-search-input"))==null||o.focus()},0);return}if(!i&&l.key==="g"){const o={d:()=>F("dashboard"),s:()=>F("search"),c:()=>F("chunks"),f:()=>F("files"),e:()=>F("evaluate"),q:()=>F("quirks")};s();const c=d=>{var u;(u=o[d.key])==null||u.call(o),s()};n=c,window.addEventListener("keydown",c),e=setTimeout(s,500);return}};return window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a),s()}},[])}function Ln(){return t("div",{className:"fixed top-4 right-4 z-[9999] flex flex-col gap-2 pointer-events-none",children:Re.value.map(e=>t("div",{className:`pointer-events-auto px-4 py-2.5 rounded-lg shadow-lg text-sm font-medium transition-all duration-300 animate-slide-in ${e.type==="success"?"bg-green-600 text-white":e.type==="error"?"bg-red-600 text-white":"bg-brand-600 text-white"}`,children:e.message},e.id))})}function Tn(){const e=se.value==="dark";return t("button",{className:"p-2 rounded-lg transition-colors",style:{color:"var(--text-muted)"},onClick:()=>{se.value=e?"light":"dark"},"aria-label":e?"Switch to light mode":"Switch to dark mode",title:e?"Light mode":"Dark mode",children:[t("span",{className:"sr-only",children:e?"Switch to light mode":"Switch to dark mode"}),e?t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"})}):t("svg",{className:"w-5 h-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor","aria-hidden":"true",children:t("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})})]})}function ht(e,n){const[s,a]=g(e);return j(()=>{const l=setTimeout(()=>a(e),n);return()=>clearTimeout(l)},[e,n]),s}const Pn="/api",Ct="opencode-rag-token";function Rn(){const e=new URLSearchParams(window.location.search).get("token");if(e){sessionStorage.setItem(Ct,e);const n=window.location.pathname+window.location.hash;return window.history.replaceState(null,"",n),e}return sessionStorage.getItem(Ct)}function In(){const e=Rn();return e?{Authorization:`Bearer ${e}`}:{}}function $t(e){const n=new URLSearchParams;for(const[s,a]of Object.entries(e))a!==void 0&&a!==""&&n.set(s,String(a));return n.toString()}async function I(e,n){const s={...(n==null?void 0:n.headers)??{},...In()},a=await fetch(Pn+e,{...n,headers:s}),l=await a.json();if(!a.ok)throw new Error(l.error??a.statusText);return l}const $={stats:()=>I("/stats"),files:()=>I("/files"),chunks:e=>I(`/chunks?${$t(e)}`),chunk:e=>I(`/chunks/${encodeURIComponent(e)}`),search:(e,n=20)=>I(`/search?q=${encodeURIComponent(e)}&topK=${n}`),compare:e=>I(`/compare?ids=${e.join(",")}`),retrieve:e=>I(`/retrieve?${$t(e)}`),evalSessions:()=>I("/eval/sessions"),evalSession:e=>I(`/eval/sessions/${encodeURIComponent(e)}`),evalDeleteSession:e=>I(`/eval/sessions/${encodeURIComponent(e)}`,{method:"DELETE"}),evalCompare:(e,n)=>I(`/eval/compare?a=${e}&b=${n}`),evalTokenCompare:(e,n)=>I(`/eval/token-compare?a=${e}&b=${n}`),evalAnalysis:e=>I(`/eval/sessions/${encodeURIComponent(e)}/analysis`),evalProjectSavings:e=>I("/eval/project-savings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),quirks:()=>I("/quirks"),quirkLint:()=>I("/quirks/lint"),deleteQuirk:e=>I(`/quirks/${encodeURIComponent(e)}`,{method:"DELETE"}),indexStatus:()=>I("/indexing/status"),triggerReindex:()=>I("/indexing/reindex",{method:"POST"}),config:()=>I("/config"),embeddingProj:(e=5e3,n=2)=>I(`/embeddings/projection?maxChunks=${e}&dims=${n}`)},En={typescript:"text-blue-400",javascript:"text-yellow-400",python:"text-green-400",java:"text-red-400",go:"text-cyan-400",rust:"text-orange-400",ruby:"text-pink-400",csharp:"text-purple-400",cpp:"text-indigo-400",c:"text-gray-400",markdown:"text-gray-300",html:"text-orange-300",css:"text-blue-300",json:"text-yellow-300",kotlin:"text-purple-300",swift:"text-orange-400",tex:"text-emerald-400",sql:"text-cyan-300"};function Fe(e){return En[e]??"text-slate-400"}function he(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${Fe(e)} bg-slate-800">${Mn(e)}</span>`}function Mn(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function w(e){return typeof e!="string"?"":e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function Lt(e,n=80){const s=typeof e=="string"?e:String(e??"");return s.length>n?s.slice(0,n)+"...":s}function An(){const[e,n]=g(""),[s,a]=g([]),[l,r]=g(!1),i=te(null),o=te(null),c=ht(e,300);j(()=>{if(!c.trim()){a([]),r(!1);return}let f=!1;return $.search(c,10).then(x=>{f||(a((x==null?void 0:x.results)??[]),r(!0))}).catch(()=>{f||r(!1)}),()=>{f=!0}},[c]),j(()=>{const f=x=>{o.current&&!o.current.contains(x.target)&&r(!1)};return document.addEventListener("click",f),()=>document.removeEventListener("click",f)},[]);const d=f=>{f.key==="Escape"&&r(!1)},u=async f=>{r(!1),n(""),F("chunks")};return t("div",{ref:o,className:"relative",children:[t("input",{ref:i,type:"text",placeholder:"Search codebase...",value:e,onInput:f=>n(f.target.value),onKeyDown:d,className:"global-search-input w-56 px-3 py-1.5 bg-slate-800 border border-slate-600 rounded text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400","aria-label":"Global search",role:"combobox","aria-expanded":l}),l&&s.length>0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 max-h-80 overflow-y-auto",role:"listbox",children:s.map(f=>t("div",{className:"search-result p-2 hover:bg-slate-700 cursor-pointer border-b border-slate-700 last:border-0",onClick:()=>u(f.chunk.id),role:"option",children:[t("div",{className:"flex items-center gap-2 text-xs",children:[t("span",{className:"text-yellow-400 font-mono",children:[w(f.chunk.filePath),":",f.chunk.startLine,"-",f.chunk.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(f.chunk.language)}}),t("span",{className:"ml-auto text-slate-500",children:f.score})]}),t("div",{className:"text-xs text-slate-400 mt-1 truncate",children:w(f.chunk.content??"").slice(0,80)})]},f.chunk.id))}),l&&e.trim()&&s.length===0&&t("div",{className:"absolute top-full right-0 mt-1 w-96 bg-slate-800 border border-slate-600 rounded-lg shadow-xl z-50 p-3 text-sm text-slate-500",children:"No results"})]})}function J(e,n=[]){const[s,a]=g(null),[l,r]=g(!0),[i,o]=g(null),[c,d]=g(0);return j(()=>{let u=!1;return r(!0),o(null),e().then(f=>{u||(a(f),r(!1))}).catch(f=>{u||(o(f.message),r(!1))}),()=>{u=!0}},[...n,c]),{data:s,isLoading:l,error:i,refresh:()=>d(u=>u+1)}}function Dn(){const{data:e}=J(()=>$.files()),n=e??[],[s,a]=g(""),l=ht(s,300),r=l?n.filter(i=>i.filePath.toLowerCase().includes(l.toLowerCase())):n;return t("div",{className:"flex flex-col h-full",children:[t("div",{className:"flex items-center justify-between mb-2 px-3 pt-3",children:[t("h2",{className:"text-xs font-semibold text-slate-400 uppercase tracking-wide",children:"Files"}),t("span",{className:"text-xs text-slate-500",children:r.length})]}),t("div",{className:"px-3 mb-2",children:t("input",{type:"text",placeholder:"Filter files...",value:s,onInput:i=>a(i.target.value),className:"w-full px-2 py-1 bg-slate-900 border border-slate-700 rounded text-xs focus:outline-none focus:border-brand-400 text-slate-200 placeholder-slate-500"})}),t("div",{className:"flex-1 overflow-y-auto px-1",children:t(On,{files:r})})]})}function On({files:e}){const n={};for(const s of e){const a=s.filePath.split("/");let l=n;for(let r=0;r<a.length-1;r++)l[a[r]]||(l[a[r]]={}),l=l[a[r]];l.__files||(l.__files=[]),l.__files.push(s)}return t(sn,{obj:n,depth:0,parentPath:""})}function nn(e){let n=(e.__files||[]).length;for(const[s,a]of Object.entries(e))s!=="__files"&&(n+=nn(a));return n}function sn({obj:e,depth:n,parentPath:s}){const a=Object.entries(e).filter(([r])=>r!=="__files").sort(([r],[i])=>r.localeCompare(i)),l=e.__files||[];return t(ie,{children:[a.map(([r,i])=>{const o=s?`${s}/${r}`:r,c=nn(i),d=st.value.has(o),u=d?"▸":"▾";return t("div",{children:[t("div",{className:"file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer text-slate-400 hover:text-white",style:{paddingLeft:`${n*12+8}px`},onClick:()=>{const f=new Set(st.value);f.has(o)?f.delete(o):f.add(o),st.value=f},role:"treeitem","aria-expanded":!d,children:[t("span",{className:"text-xs",children:u}),t("span",{className:"text-xs",children:"📁"}),t("span",{className:"text-xs",children:w(r)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:c})]}),!d&&t("div",{className:"dir-children",children:t(sn,{obj:i,depth:n+1,parentPath:o})})]},o)}),l.map(r=>{const i=r.filePath.split("/").pop()??r.filePath,o=de.value===r.filePath;return t("div",{className:`file-item flex items-center gap-1 py-0.5 px-2 rounded cursor-pointer ${o?"active text-white":"text-slate-400 hover:text-white"}`,style:{paddingLeft:`${n*12+8}px`},onClick:()=>{de.value=r.filePath,F(`chunks?file=${encodeURIComponent(r.filePath)}`)},role:"treeitem",tabIndex:0,children:[t("span",{className:`text-xs ${Fe(r.language)}`,children:"♦"}),t("span",{className:"text-xs truncate",children:w(i)}),t("span",{className:"text-xs text-slate-600 ml-auto",children:r.chunkCount})]},r.filePath)})]})}const Z="bg-gradient-to-r from-slate-700 via-slate-600 to-slate-700 bg-[length:200%_100%]";function G({type:e="card"}){return t("div",{className:"animate-pulse space-y-4",children:[t("div",{className:`h-8 ${Z} rounded w-48`}),e==="card"&&t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[1,2,3,4].map(n=>t("div",{className:"h-24 bg-slate-800 rounded-lg border border-slate-700 p-4",children:[t("div",{className:`h-3 ${Z} rounded w-16 mb-2`}),t("div",{className:`h-6 ${Z} rounded w-24`})]},n))}),e==="table"&&t("div",{className:"space-y-2",children:[t("div",{className:`h-10 ${Z} rounded w-full`}),[1,2,3,4,5].map(n=>t("div",{className:`h-8 ${Z} rounded w-full`},n))]}),e==="chart"&&t("div",{className:`h-64 ${Z} rounded-lg`}),e==="detail"&&t("div",{className:"flex gap-4",children:[t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${Z} rounded w-48`}),t("div",{className:`h-4 ${Z} rounded w-32`}),t("div",{className:`h-32 ${Z} rounded-lg`})]}),t("div",{className:"flex-1 space-y-3",children:[t("div",{className:`h-6 ${Z} rounded w-48`}),t("div",{className:`h-4 ${Z} rounded w-32`}),t("div",{className:`h-32 ${Z} rounded-lg`})]})]})]})}function ee({message:e,onRetry:n}){return t("div",{className:"flex flex-col items-center justify-center py-12 text-center",role:"alert",children:[t("span",{className:"text-4xl mb-3",children:"⚠️"}),t("p",{className:"text-slate-400 mb-4",children:e}),n&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:n,children:"Retry"})]})}function fe({icon:e,message:n,action:s}){return t("div",{className:"flex flex-col items-center justify-center py-16 text-center",role:"status",children:[t("span",{className:"text-5xl mb-4",role:"img","aria-label":e,children:e}),t("p",{className:"text-slate-400 mb-4",children:n}),s&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-2 rounded transition-colors",onClick:s.onClick,children:s.label})]})}function V({label:e,value:n,icon:s}){return t("div",{className:"kpi-card p-4",children:[s&&t("span",{className:"text-lg mb-1 block",children:s}),t("div",{className:"text-slate-400 text-xs mb-1",children:e}),t("div",{className:"text-3xl font-bold text-white",children:n})]})}function H(e){return e>=1e6?(e/1e6).toFixed(1)+"M":e>=1e3?(e/1e3).toFixed(1)+"k":String(e)}function Ye(e){return e===0?"$0.00":e<.01?"$"+e.toFixed(4):"$"+e.toFixed(2)}function jn(e){return e>=6e4?(e/6e4).toFixed(1)+"m":e>=1e3?(e/1e3).toFixed(1)+"s":e+"ms"}function an(e){if(!e)return"-";const n=new Date(e);return n.toLocaleDateString()+" "+n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Fn(e){const n=Date.now()-new Date(e).getTime(),s=Math.floor(n/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const a=Math.floor(s/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function Un(){var x;const[e,n]=g(null),[s,a]=g(!0),[l,r]=g(!1),i=te(null),o=async()=>{try{const h=await $.indexStatus();n(h.body??h)}catch{}a(!1)};j(()=>{o()},[]),j(()=>()=>{i.current&&clearInterval(i.current)},[]);const c=async()=>{var h;r(!0);try{await $.triggerReindex(),le("info","Reindex started in background");const p=(h=e==null?void 0:e.manifest)==null?void 0:h.lastIndexedAt,m=Date.now();i.current=setInterval(async()=>{var b;if(Date.now()-m>10*6e4){i.current&&clearInterval(i.current),i.current=null,r(!1),le("info","Reindex is still running — check back later");return}try{const T=await $.indexStatus(),M=T.body??T;((b=M.manifest)==null?void 0:b.lastIndexedAt)!==p&&(i.current&&clearInterval(i.current),i.current=null,n(M),r(!1),le("success","Reindex complete!"))}catch{}},2e3)}catch(p){const m=p.message??"";le("error",/already running/i.test(m)?"A reindex is already running":`Reindex failed: ${m}`),r(!1)}};if(s)return null;const d=(x=e==null?void 0:e.manifest)!=null&&x.lastIndexedAt?Fn(e.manifest.lastIndexedAt):"Never",u=(e==null?void 0:e.staleFileCount)??0,f=u===0?"text-green-400":u<50?"text-amber-400":"text-red-400";return t("div",{className:"kpi-card p-4 mb-6",children:[t("div",{className:"flex items-center justify-between mb-3",children:t("h2",{className:"text-lg font-semibold",children:"Index Status"})}),e!=null&&e.manifest?t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Last Indexed"}),t("span",{className:"text-sm font-mono",children:d})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Chunks"}),t("span",{className:"text-sm font-mono",children:H(e.manifest.totalChunks)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Total Files"}),t("span",{className:"text-sm font-mono",children:H(e.manifest.totalFiles)})]}),t("div",{children:[t("span",{className:"text-xs text-slate-500 block",children:"Schema Version"}),t("span",{className:"text-sm font-mono",children:e.manifest.schemaVersion})]}),t("div",{className:"col-span-2",children:[t("span",{className:"text-xs text-slate-500 block",children:"Index Freshness"}),t("span",{className:`text-sm font-mono ${f}`,children:u===0?"✓ Up to date":`⚠ ${u} file${u!==1?"s":""} modified since last index`})]}),t("div",{className:"col-span-2 flex items-end",children:l?t("div",{className:"flex items-center gap-2",children:[t("span",{className:"animate-spin",children:"⟳"}),t("span",{className:"text-sm text-amber-400",children:"Reindexing..."})]}):t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-4 py-1.5 rounded text-sm transition-colors",onClick:c,children:"Reindex Now"})})]}):t("div",{className:"text-sm text-slate-400",children:["No index found. Run ",t("code",{className:"text-brand-400",children:"opencode-rag index"})," first."]})]})}function zn(){var x,h,p;const{data:e,isLoading:n,error:s,refresh:a}=J(()=>$.stats()),{data:l}=J(()=>$.files());if(n)return t(G,{type:"card"});if(s)return t(ee,{message:s,onRetry:a});if(!e)return t(fe,{icon:"📊",message:"No dashboard data available."});const r=e,i=((x=l==null?void 0:l.body)==null?void 0:x.length)??r.totalFiles??0,o=r.totalChunks??0,c=((h=r.languages)==null?void 0:h.length)??0,d=i>0?(o/i).toFixed(1):"0",u=(r.languages??[]).slice(0,8),f=((p=u[0])==null?void 0:p.count)??1;return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Dashboard"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[t(V,{label:"Total Chunks",value:o.toLocaleString(),icon:"🧩"}),t(V,{label:"Total Files",value:i.toLocaleString(),icon:"📄"}),t(V,{label:"Languages",value:c,icon:"🔤"}),t(V,{label:"Avg Chunks/File",value:d,icon:"📊"})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Language Distribution"}),t("div",{className:"space-y-2",children:u.map(m=>t("div",{className:"flex items-center gap-3",children:[t("span",{className:`w-24 text-xs text-right ${Fe(m.language)}`,children:m.language}),t("div",{className:"flex-1 bg-slate-800 rounded-full h-5 overflow-hidden",children:t("div",{className:"h-full rounded-full bg-brand-500 flex items-center pl-2",style:{width:`${Math.max(8,m.count/f*100)}%`},children:t("span",{className:"text-xs font-medium text-white",children:m.count})})}),t("span",{className:"text-xs text-slate-500 w-12 text-right",children:[(m.count/o*100).toFixed(0),"%"]})]},m.language))})]}),t(Un,{}),t("div",{className:"mt-6",children:t("h2",{className:"text-lg font-semibold mb-3",children:t("a",{href:"#config",className:"hover:text-brand-400 transition-colors",children:"Configuration"})})})]})}function Tt({text:e,color:n,onDismiss:s}){return t("span",{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs font-mono bg-slate-800 ${n??"text-slate-400"}`,children:[e,s&&t("button",{className:"ml-0.5 text-slate-500 hover:text-white",onClick:s,"aria-label":`Dismiss ${e} filter`,children:"×"})]})}function qn(){const e=Oe();j(()=>{e.params.file&&(de.value=e.params.file),e.params.lang&&(_e.value=e.params.lang)},[e.params.file,e.params.lang]);const n=Pe.value,s=kn.value,a=de.value,l=_e.value,{data:r,isLoading:i,error:o,refresh:c}=J(()=>$.chunks({offset:n,limit:s,lang:l??"",file:a??""}),[n,s,a,l]);if(i)return t(G,{type:"detail"});if(o)return t(ee,{message:o,onRetry:c});const d=(r==null?void 0:r.chunks)??[],u=(r==null?void 0:r.total)??d.length,f=Math.ceil(u/s),x=Math.floor(n/s)+1;return t("div",{className:"flex gap-4 h-full",children:[t("div",{className:"w-1/2 flex flex-col",children:[t("div",{className:"flex items-center gap-3 mb-3 flex-wrap",children:[t("h2",{className:"text-lg font-semibold text-white",children:"Chunks"}),t("span",{className:"text-sm text-slate-400",children:[u," total"]}),_e.value&&t(Tt,{text:_e.value,color:Fe(_e.value),onDismiss:()=>{_e.value=null,ye.value=null,Pe.value=0}}),de.value&&t(Tt,{text:de.value,onDismiss:()=>{de.value=null,ye.value=null,Pe.value=0}})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden flex-1",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8",children:t("input",{type:"checkbox",className:"accent-brand-500",checked:d.length>0&&d.every(h=>X.value.has(h.id||`chunk-${d.indexOf(h)}`)),onChange:()=>{const h=d.map((b,T)=>b.id||`chunk-${T}`),p=h.every(b=>X.value.has(b)),m=new Set(X.value);for(const b of h)p?m.delete(b):m.add(b);X.value=m},"aria-label":"Select all chunks on this page"})}),t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Lang"}),t("th",{className:"px-3 py-2 text-left",children:"Description"})]})}),t("tbody",{children:d.length===0?t("tr",{children:t("td",{colSpan:4,className:"px-3 py-8 text-center text-slate-500",children:[t("span",{className:"text-2xl block mb-2",children:"🔍"}),"No chunks found"]})}):d.map((h,p)=>{const m=h.id||`chunk-${p}`,b=ye.value===m,T=X.value.has(m);return t("tr",{className:`chunk-row border-t border-slate-800 cursor-pointer ${b?"selected":""}`,onClick:()=>{ye.value=m},role:"row",tabIndex:0,children:[t("td",{className:"px-2 py-2",onClick:M=>M.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:T,onChange:()=>{const M=new Set(X.value);M.has(m)?M.delete(m):M.add(m),X.value=M},"aria-label":`Select chunk ${m}`})}),t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:[w(h.filePath),":",h.startLine,"-",h.endLine]}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:he(h.language)}}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:w(h.description??"").slice(0,50)})]},m)})})]})}),t("div",{className:"flex items-center justify-between mt-3",children:[t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:x<=1,onClick:()=>{Pe.value=Math.max(0,n-s)},children:"Previous"}),t("span",{className:"text-sm text-slate-400",children:["Page ",x," of ",f||1]}),t("button",{className:"px-3 py-1 bg-slate-700 rounded text-sm hover:bg-slate-600 disabled:opacity-50",disabled:x>=f,onClick:()=>{Pe.value+=s},children:"Next"})]}),X.value.size>=2&&X.value.size<=3&&t("div",{className:"fixed bottom-6 right-6 z-50",children:t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-6 py-3 rounded-full shadow-lg font-bold transition-all transform hover:scale-105",onClick:()=>{const h=[...X.value];X.value=new Set,F(`compare?ids=${h.join(",")}`)},children:["Compare (",X.value.size,")"]})})]}),t("div",{className:"w-1/2 overflow-y-auto",children:ye.value?t(Hn,{chunkId:ye.value,chunks:d}):t("div",{className:"flex items-center justify-center h-full text-slate-500",children:t("div",{className:"text-center",children:[t("div",{className:"text-4xl mb-2",children:"📄"}),t("div",{className:"text-sm",children:"Select a chunk to view details"})]})})})]})}function Hn({chunkId:e,chunks:n}){const[s,a]=g(null),[l,r]=g(!1),i=te(null);if(j(()=>{let u=!1;const f=n.find(x=>x.id===e);return f?a(f):$.chunk(e).then(x=>{u||a(x)}).catch(()=>{u||a({id:e,content:"",filePath:"not found",language:"",startLine:0,endLine:0,description:""})}),()=>{u=!0}},[e,n]),j(()=>()=>{i.current&&clearTimeout(i.current)},[]),!s)return t(G,{type:"detail"});const o=s,c=o.language==="image",d=()=>{navigator.clipboard.writeText(o.content).then(()=>{r(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>r(!1),1500)})};return t("div",{children:[t("div",{className:"mb-3",children:[t("div",{className:"flex items-center gap-3 mb-1",children:t("span",{className:"text-yellow-400 font-mono text-sm",children:w(o.filePath)})}),t("div",{className:"flex items-center gap-3 text-sm text-slate-400",children:[t("span",{children:["Lines ",o.startLine,"-",o.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(o.language)}}),o.id&&t("span",{className:"text-xs text-slate-600 font-mono",children:o.id})]})]}),o.description&&t("div",{className:"kpi-card p-3 mb-3",children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Description"}),t("p",{className:"text-sm text-slate-300",children:w(o.description)})]}),c&&t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden mb-3",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700",children:t("span",{className:"text-xs text-slate-400",children:"Image Preview"})}),t("div",{className:"p-3 flex items-center justify-center bg-slate-950",children:t("img",{src:`/api/file?path=${encodeURIComponent(o.filePath)}`,alt:o.filePath,className:"max-w-full max-h-[60vh] object-contain rounded",onError:u=>{const f=u.currentTarget;f.style.display="none",f.parentElement.innerHTML='<span class="text-slate-500 text-sm">Image not available</span>'}})})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:[t("div",{className:"px-3 py-1.5 bg-slate-800 border-b border-slate-700 flex items-center justify-between",children:[t("span",{className:"text-xs text-slate-400",children:c?"Vision Analysis":"Source Code"}),t("button",{className:"text-xs text-slate-500 hover:text-white transition-colors",onClick:d,children:l?"Copied!":"Copy"})]}),t("pre",{className:"p-3 overflow-x-auto text-sm max-h-[calc(100vh-220px)]",children:t("code",{className:`language-${c?"text":o.language}`,children:w(o.content)})})]})]})}function Kn(){const{data:e,isLoading:n,error:s,refresh:a}=J(()=>$.files());if(n)return t(G,{type:"table"});if(s)return t(ee,{message:s,onRetry:a});const l=e??[];if(l.length===0)return t(fe,{icon:"📂",message:"No files indexed yet."});const r=l.reduce((i,o)=>i+o.chunkCount,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Files"}),t("span",{className:"text-sm text-slate-400",children:[l.length," files, ",r," chunks"]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-hidden",children:t("table",{className:"w-full text-sm",role:"table","aria-label":"Indexed files",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-3 py-2 text-left",children:"File"}),t("th",{className:"px-3 py-2 text-left w-28",children:"Language"}),t("th",{className:"px-3 py-2 text-left w-20",children:"Chunks"}),t("th",{className:"px-3 py-2 text-left w-24"})]})}),t("tbody",{children:l.map(i=>t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>F(`chunks?file=${encodeURIComponent(i.filePath)}`),role:"row",tabIndex:0,onKeyDown:o=>{o.key==="Enter"&&F(`chunks?file=${encodeURIComponent(i.filePath)}`)},children:[t("td",{className:"px-3 py-2 text-yellow-400 font-mono text-xs",children:i.filePath}),t("td",{className:"px-3 py-2",dangerouslySetInnerHTML:{__html:he(i.language)}}),t("td",{className:"px-3 py-2 text-slate-300",children:i.chunkCount}),t("td",{className:"px-3 py-2 text-slate-500 text-xs",children:t("span",{className:"hover:text-white transition-colors",children:"View chunks"})})]},i.filePath))})]})})]})}function Bn({segments:e,size:n=180,innerRadius:s,centerLabel:a}){const l=n/2,r=n/2,i=n/2-10,o=s??i*.6,c=e.reduce((x,h)=>x+h.value,0);if(c===0)return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,children:[t("circle",{cx:l,cy:r,r:i,fill:"none",stroke:"#334155","stroke-width":i-o}),t("circle",{cx:l,cy:r,r:o,fill:"#0f172a"})]});let d=0;const u=e.map(x=>{const h=x.value/c*360,p=d,m=d+h;return d+=h,`<path d="${Wn(l,r,i,p,m,o)}" fill="${x.color}" />`}).join(""),f=a??"";return t("svg",{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:"chart-svg",children:[t("g",{dangerouslySetInnerHTML:{__html:u}}),t("text",{x:l,y:r-6,"text-anchor":"middle",fill:"white","font-size":"22","font-weight":"bold",children:f}),t("text",{x:l,y:r+14,"text-anchor":"middle",fill:"#64748b","font-size":"11",children:"tokens"})]})}function Wn(e,n,s,a,l,r){const i=l-a;if(i>=359.99)return`M${e},${n-s} A${s},${s} 0 1,1 ${e-.01},${n-s} L${e-.01},${n-r} A${r},${r} 0 1,0 ${e},${n-r} Z`;const o=T=>(T-90)*Math.PI/180,c=e+s*Math.cos(o(a)),d=n+s*Math.sin(o(a)),u=e+s*Math.cos(o(l)),f=n+s*Math.sin(o(l)),x=e+r*Math.cos(o(l)),h=n+r*Math.sin(o(l)),p=e+r*Math.cos(o(a)),m=n+r*Math.sin(o(a)),b=i>180?1:0;return[`M${c},${d}`,`A${s},${s} 0 ${b} 1 ${u},${f}`,`L${x},${h}`,`A${r},${r} 0 ${b} 0 ${p},${m}`,"Z"].join(" ")}function Vn(){const e=Oe();return e.params.compare?t(Xn,{ids:[e.params.a??"",e.params.b??""]}):e.params.session?t(Qn,{sessionId:e.params.session}):t(Gn,{})}function Gn(){const{data:e,isLoading:n,error:s,refresh:a}=J(()=>$.evalSessions()),[l,r]=g(new Set);if(n)return t(G,{type:"table"});if(s)return t(ee,{message:s,onRetry:a});const i=(e==null?void 0:e.sessions)??[];if(i.length===0)return t(fe,{icon:"📊",message:"No sessions recorded yet."});const o=c=>{const d=new Set(l);d.has(c)?d.delete(c):d.add(c),r(d)};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Evaluate"}),t("div",{className:"flex gap-2",children:[l.size===2&&t("button",{className:"bg-brand-600 hover:bg-brand-500 text-white px-3 py-1 rounded text-sm transition-colors",onClick:()=>{const[c,d]=[...l];F(`evaluate?compare&a=${encodeURIComponent(c)}&b=${encodeURIComponent(d)}`)},children:"Compare Selected"}),l.size>0&&t("button",{className:"text-xs text-slate-400 hover:text-white",onClick:()=>r(new Set),children:["Clear (",l.size,")"]})]})]}),t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 overflow-x-auto",children:t("table",{className:"w-full text-sm",role:"table",children:[t("thead",{children:t("tr",{className:"bg-slate-800 text-slate-400 text-xs",children:[t("th",{className:"px-2 py-2 w-8"}),t("th",{className:"px-3 py-2 text-left",children:"Session"}),t("th",{className:"px-3 py-2 text-left",children:"Last Activity"}),t("th",{className:"px-3 py-2 text-right",children:"Messages"}),t("th",{className:"px-3 py-2 text-right",children:"Input Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Output Tokens"}),t("th",{className:"px-3 py-2 text-right",children:"Cost"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Calls"}),t("th",{className:"px-3 py-2 text-right",children:"RAG Tokens"}),t("th",{className:"px-3 py-2 text-left",children:"Model"}),t("th",{className:"px-3 py-2 w-8"})]})}),t("tbody",{children:i.map(c=>{var d,u,f,x;return t("tr",{className:"border-t border-slate-800 hover:bg-slate-800 cursor-pointer",onClick:()=>F(`evaluate?session=${encodeURIComponent(c.sessionID)}`),children:[t("td",{className:"px-2 py-2",onClick:h=>h.stopPropagation(),children:t("input",{type:"checkbox",className:"accent-brand-500",checked:l.has(c.sessionID),onChange:()=>o(c.sessionID),"aria-label":`Select session ${c.title??c.sessionID}`})}),t("td",{className:"px-3 py-2 text-slate-200 font-mono text-xs",children:c.title??c.sessionID.slice(0,8)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:an(c.lastEventAt)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:c.messageCount}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:H((((d=c.totalTokens)==null?void 0:d.input)??0)+(((u=c.totalTokens)==null?void 0:u.cacheRead)??0))}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:H(((f=c.totalTokens)==null?void 0:f.output)??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:Ye(c.totalCost??0)}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:c.ragContextCount??0}),t("td",{className:"px-3 py-2 text-slate-300 text-right",children:H(c.ragContextTokens??0)}),t("td",{className:"px-3 py-2 text-slate-400 text-xs",children:((x=c.models)==null?void 0:x[0])??"-"}),t("td",{className:"px-3 py-2",onClick:h=>h.stopPropagation(),children:t("button",{className:"text-slate-600 hover:text-red-400 text-xs",onClick:async()=>{if(confirm("Delete this session?"))try{await $.evalDeleteSession(c.sessionID),le("success","Session deleted"),a()}catch(h){le("error",`Delete failed: ${h.message}`)}},"aria-label":"Delete session",children:"🗑"})})]},c.sessionID)})})]})})]})}function Qn({sessionId:e}){var f,x,h,p,m,b,T,M;const{data:n,isLoading:s,error:a,refresh:l}=J(()=>$.evalSession(e));if(s)return t(G,{type:"detail"});if(a)return t(ee,{message:a,onRetry:l});const r=(n==null?void 0:n.summary)??n,i=(n==null?void 0:n.events)??[],o=r.toolCallCounts??{};["search_semantic","get_file_skeleton","find_usages","describe_image"].reduce((_,Y)=>_+(o[Y]??0),0);const d=[{label:"Input",value:(((f=r.totalTokens)==null?void 0:f.input)??0)+(((x=r.totalTokens)==null?void 0:x.cacheRead)??0),color:"#3b82f6"},{label:"Output",value:((h=r.totalTokens)==null?void 0:h.output)??0,color:"#a855f7"},{label:"RAG",value:r.ragContextTokens??0,color:"#06b6d4"},{label:"Reasoning",value:((p=r.totalTokens)==null?void 0:p.reasoning)??0,color:"#f59e0b"}].filter(_=>_.value>0),u=d.reduce((_,Y)=>_+Y.value,0);return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>F("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:r.title??((m=r.sessionID)==null?void 0:m.slice(0,12))})]}),t("div",{className:"grid grid-cols-3 lg:grid-cols-5 gap-3 mb-6",children:[t(V,{label:"Total Tokens",value:H(u)}),t(V,{label:"Input",value:H((((b=r.totalTokens)==null?void 0:b.input)??0)+(((T=r.totalTokens)==null?void 0:T.cacheRead)??0))}),t(V,{label:"Output",value:H(((M=r.totalTokens)==null?void 0:M.output)??0)}),t(V,{label:"Cost",value:Ye(r.totalCost??0)}),t(V,{label:"RAG Context",value:H(r.ragContextTokens??0)})]}),t("div",{className:"flex items-center gap-6 mb-6",children:[t(Bn,{segments:d,centerLabel:H(u)}),t("div",{className:"flex flex-wrap gap-3",children:d.map(_=>t("div",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("span",{className:"inline-block w-3 h-3 rounded-sm",style:{background:_.color}}),_.label,": ",H(_.value)," (",(_.value/u*100).toFixed(1),"%)"]},_.label))})]}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-3 mb-6",children:[t(V,{label:"Messages",value:r.messageCount??0}),t(V,{label:"Steps",value:r.totalSteps??0}),t(V,{label:"RAG Injections",value:r.ragContextCount??0}),t(V,{label:"Avg Response",value:jn(r.avgResponseTimeMs??0)})]}),Object.keys(o).length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Tool Calls"}),t("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2",children:Object.entries(o).map(([_,Y])=>t("div",{className:"flex justify-between text-xs text-slate-400",children:[t("span",{className:"font-mono",children:_}),t("span",{className:"text-white",children:String(Y)})]},_))})]}),r.models&&r.models.length>0&&t("div",{className:"kpi-card p-4 mb-6",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:"Models"}),t("div",{className:"flex flex-wrap gap-2",children:r.models.map(_=>t("span",{className:"px-2 py-0.5 rounded text-xs font-mono bg-slate-800 text-slate-300",children:_},_))})]}),i.length>0&&t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-3",children:"Event Timeline"}),t("div",{className:"space-y-1 max-h-64 overflow-y-auto",children:i.map((_,Y)=>t("div",{className:"flex gap-2 text-xs border-b border-slate-700/50 py-1",children:[t("span",{className:"text-slate-500 shrink-0 w-16",children:an(_.ts)}),t("span",{className:"text-slate-400",children:_.event}),_.tool&&t("span",{className:"text-slate-500 font-mono",children:_.tool}),_.toolStatus&&t("span",{className:`text-xs ${_.toolStatus==="completed"?"text-green-400":_.toolStatus==="running"?"text-amber-400":"text-slate-500"}`,children:_.toolStatus})]},Y))})]})]})}function Xn({ids:e}){var f,x,h,p,m,b,T,M;const[n,s]=e,{data:a,isLoading:l,error:r}=J(()=>Promise.all([$.evalCompare(n,s),$.evalTokenCompare(n,s)]),[n,s]);if(l)return t(G,{type:"chart"});if(r)return t(ee,{message:r});if(!a)return null;const i=a[0],o=a[1],c=((f=o.sessionA)==null?void 0:f.savings)??0,d=((x=o.sessionB)==null?void 0:x.savings)??0,u=c>0&&d>0?"RAG saves tokens":"Mixed results";return t("div",{children:[t("div",{className:"flex items-center gap-3 mb-4",children:[t("button",{className:"text-sm text-slate-400 hover:text-white",onClick:()=>F("evaluate"),children:"← Back"}),t("h1",{className:"text-xl font-bold",children:"Session Comparison"})]}),t("div",{className:`px-4 py-3 rounded-lg mb-4 font-semibold text-sm ${c>0&&d>0?"bg-green-900/50 text-green-300 border border-green-700":"bg-amber-900/50 text-amber-300 border border-amber-700"}`,children:u}),t("div",{className:"grid grid-cols-2 gap-4",children:[t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((h=i.sessionA)==null?void 0:h.title)??"Session A"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:H(((p=i.sessionA)==null?void 0:p.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Ye(((m=i.sessionA)==null?void 0:m.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:c>0?"text-green-400":"text-red-400",children:[H(Math.abs(c))," (",c>0?"+":"",c>0?"+":"",")"]})]})]})]}),t("div",{className:"kpi-card p-4",children:[t("h3",{className:"text-sm font-semibold text-slate-300 mb-2",children:((b=i.sessionB)==null?void 0:b.title)??"Session B"}),t("div",{className:"space-y-1 text-sm",children:[t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Total Tokens"}),t("span",{children:H(((T=i.sessionB)==null?void 0:T.totalTokens)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"Cost"}),t("span",{children:Ye(((M=i.sessionB)==null?void 0:M.totalCost)??0)})]}),t("div",{className:"flex justify-between",children:[t("span",{className:"text-slate-400",children:"RAG Savings"}),t("span",{className:d>0?"text-green-400":"text-red-400",children:H(Math.abs(d))})]})]})]})]})]})}const Zn={gotcha:"text-amber-400 bg-amber-900/20",preference:"text-emerald-400 bg-emerald-900/20",decision:"text-sky-400 bg-sky-900/20","environment-constraint":"text-rose-400 bg-rose-900/20"};function Yn(e){return`<span class="inline-block px-1.5 py-0.5 rounded text-xs font-mono ${Zn[e]??"text-slate-400 bg-slate-800"}">${w(e||"general")}</span>`}function Jn(){const{data:e,isLoading:n,error:s,refresh:a}=J(()=>$.quirks()),[l,r]=g(null),[i,o]=g(null),[c,d]=g(!1);if(n)return t(G,{type:"card"});if(s)return t(ee,{message:s,onRetry:a});const u=(e==null?void 0:e.quirks)??[],f=[...new Set(u.map(m=>m.type||"general"))],x=l?u.filter(m=>(m.type||"general")===l):u,h=async m=>{if(confirm("Delete this quirk?"))try{await $.deleteQuirk(m),le("success","Quirk deleted"),a()}catch(b){le("error",`Delete failed: ${b.message}`)}};return t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Quirks"}),t("button",{className:"bg-slate-700 hover:bg-slate-600 text-white px-3 py-1 rounded text-sm transition-colors",onClick:async()=>{d(!0);try{const m=await $.quirkLint();o(m)}catch(m){o({error:m.message})}d(!1)},disabled:c,children:c?"Linting...":"Lint"})]}),t("div",{className:"flex gap-2 mb-4 flex-wrap",children:[t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${l===null?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>r(null),children:"All"}),f.map(m=>t("button",{className:`px-2 py-1 rounded text-xs font-medium transition-colors ${l===m?"bg-brand-600 text-white":"bg-slate-700 text-slate-300 hover:bg-slate-600"}`,onClick:()=>r(m),children:m},m))]}),i&&t("div",{className:`mb-4 p-3 rounded-lg border text-sm ${i.success?"bg-green-900/30 border-green-700 text-green-300":i.error?"bg-red-900/30 border-red-700 text-red-300":"bg-amber-900/30 border-amber-700 text-amber-300"}`,children:t("pre",{className:"text-xs whitespace-pre-wrap",children:JSON.stringify(i,null,2)})}),x.length===0?t(fe,{icon:"💡",message:"No quirks stored yet."}):t("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:x.map(m=>t("div",{className:"bg-slate-900 rounded-lg border border-slate-700 p-3 flex flex-col",children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("span",{dangerouslySetInnerHTML:{__html:Yn(m.type)}}),t("span",{className:`text-xs font-mono ${m.confidence>.7?"text-green-400":m.confidence>.4?"text-amber-400":"text-red-400"}`,children:[(m.confidence*100).toFixed(0),"%"]})]}),t("p",{className:"text-sm text-slate-200 mb-2 flex-1",children:w(m.content)}),m.tags&&m.tags.length>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:m.tags.map(b=>t("span",{className:"text-xs bg-slate-800 text-slate-400 px-1.5 py-0.5 rounded",children:["#",b]},b))}),t("div",{className:"flex items-center justify-between text-xs text-slate-600 mt-auto",children:[m.sourceRef&&t("span",{className:"font-mono",children:w(m.sourceRef)}),t("span",{className:"font-mono",children:m.id})]}),t("button",{className:"self-end mt-2 text-xs text-slate-600 hover:text-red-400 transition-colors",onClick:()=>h(m.id),"aria-label":"Delete quirk",children:"Delete"})]},m.id))})]})}function es(){const[e,n]=g([]),[s,a]=g(!1),[l,r]=g(null),[i,o]=g(!1),c=ht(S.value,300);return j(()=>{const d=W.value.trim();if(!d){n([]),r(null),a(!1),ae.value=[];return}let u=!1;return(async()=>{var x,h;a(!0),r(null);try{const p=await $.retrieve({q:d,topK:c.topK,minScore:c.minScore,keywordWeight:c.keywordWeight,hybrid:c.hybrid?"true":"false",explain:"true"});if(u)return;if(p.status===503){r(((x=p.body)==null?void 0:x.error)??"Embedding model unavailable"),a(!1);return}o(!1);const m=((h=p.body)==null?void 0:h.results)??p.results??[];n(m),ae.value=m;const b={query:d,params:{...c}};Ze.value=[b,...Ze.value.filter(T=>T.query!==d).slice(0,19)]}catch(p){u||r(p.message)}finally{u||a(!1)}})(),()=>{u=!0}},[W.value,c]),{results:e,isLoading:s,isInitializing:i,error:l,setResults:n}}function ts({explanation:e}){const{vectorScore:n,keywordScore:s,rawVectorScore:a,rawKeywordScore:l,keywordWeight:r,vectorRank:i,keywordRank:o}=e.scoreBreakdown,c=Math.max(n+s,.001),d=(n/c*100).toFixed(0),u=(s/c*100).toFixed(0);return t("div",{className:"mb-2",children:[t("div",{className:"flex items-center gap-2 text-xs mb-1",children:[t("span",{className:"text-cyan-400",title:`Vector: ${a.toFixed(3)}${i!==void 0?`, rank #${i+1}`:""}`,children:["Vector ",d,"%"]}),t("span",{className:"text-amber-400",title:`Keyword: ${l.toFixed(3)}${o!==void 0?`, rank #${o+1}`:""}`,children:["Keyword ",u,"%"]}),t("span",{className:"text-slate-500 ml-auto",children:["kw=",r.toFixed(1)]})]}),t("div",{className:"h-2 bg-slate-700 rounded-full overflow-hidden flex",children:[t("div",{className:"h-full bg-cyan-500 transition-all duration-200",style:{width:`${d}%`}}),t("div",{className:"h-full bg-amber-500 transition-all duration-200",style:{width:`${u}%`}})]})]})}function ns(){const e=Oe(),{results:n,isLoading:s,isInitializing:a,error:l}=es();return j(()=>{e.params.query&&(W.value=e.params.query,S.value={...S.value,topK:parseInt(e.params.topK??"10",10),minScore:parseFloat(e.params.minScore??"0.35"),keywordWeight:parseFloat(e.params.keywordWeight??"0.4"),hybrid:e.params.hybrid!=="false",pathFilter:e.params.path??"",langFilter:e.params.lang??""})},[]),j(()=>{if(W.value.trim()){const r=new URLSearchParams({query:W.value,topK:String(S.value.topK),minScore:String(S.value.minScore),keywordWeight:String(S.value.keywordWeight),hybrid:String(S.value.hybrid)});S.value.pathFilter&&r.set("path",S.value.pathFilter),S.value.langFilter&&r.set("lang",S.value.langFilter);const i=`search?${r.toString()}`;location.hash!==`#${i}`&&history.replaceState(null,"",`#${i}`)}},[W.value,S.value]),t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Semantic Search"}),t("div",{className:"flex gap-3 mb-4",children:t("input",{type:"text",value:W.value,onInput:r=>{W.value=r.target.value,ae.value=[]},onKeyDown:r=>{r.key==="Enter"&&W.value.trim()},placeholder:"Search your codebase semantically... (e.g., 'how does authentication work?')",className:"flex-1 px-4 py-2 bg-slate-800 border border-slate-600 rounded-lg text-sm text-slate-200 placeholder-slate-500 focus:outline-none focus:border-brand-400",autoFocus:!0,"aria-label":"Semantic search query"})}),t("details",{className:"mb-4 bg-slate-800 rounded-lg border border-slate-700",children:[t("summary",{className:"px-3 py-2 text-xs text-slate-400 cursor-pointer hover:text-white font-medium",children:"Search Parameters"}),t("div",{className:"px-3 pb-3 space-y-3",children:[t(at,{label:"topK",min:1,max:25,step:1,value:S.value.topK,onChange:r=>{S.value={...S.value,topK:r}}}),t(at,{label:"minScore",min:0,max:1,step:.05,value:S.value.minScore,onChange:r=>{S.value={...S.value,minScore:r}}}),t(at,{label:"keywordWeight",min:0,max:1,step:.1,value:S.value.keywordWeight,onChange:r=>{S.value={...S.value,keywordWeight:r}}}),t("div",{className:"flex items-center gap-2",children:[t("label",{className:"text-xs text-slate-400 w-28",children:"Hybrid mode"}),t("input",{type:"checkbox",checked:S.value.hybrid,onChange:r=>{S.value={...S.value,hybrid:r.target.checked}},className:"accent-brand-500"})]})]})]}),a&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Initializing embedding model..."]}),l&&t(ee,{message:l}),!s&&!l&&W.value.trim()&&n.length===0&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:['No results found for "',w(W.value),'"']})]}),!s&&!l&&!W.value.trim()&&t("div",{className:"text-center py-16 text-slate-500",children:[t("div",{className:"text-4xl mb-2",children:"🔍"}),t("div",{children:"Enter a query to search your codebase"}),Ze.value.length>0&&t("div",{className:"mt-6",children:[t("p",{className:"text-xs text-slate-600 mb-2",children:"Recent queries:"}),t("div",{className:"flex flex-wrap gap-2 justify-center",children:Ze.value.slice(0,10).map((r,i)=>t("button",{className:"px-2 py-1 bg-slate-800 rounded text-xs text-slate-400 hover:text-white hover:bg-slate-700 transition-colors",onClick:()=>{W.value=r.query},children:w(r.query)},i))})]})]}),n.length>0&&t("div",{className:"space-y-3",children:[t("div",{className:"flex items-center justify-between text-sm text-slate-400 mb-2",children:[t("span",{children:[n.length," result",n.length!==1?"s":""]}),s&&t("span",{className:"text-xs text-brand-400 animate-pulse",children:"Searching..."})]}),n.map(r=>t(ss,{result:r},r.chunk.id))]}),s&&n.length===0&&t("div",{className:"text-center py-10 text-slate-400",children:[t("span",{className:"animate-spin inline-block mr-2",children:"⟳"}),"Searching..."]})]})}function ss({result:e}){var a,l;const n=e.chunk,s=e.score;return t("div",{className:"bg-slate-800 rounded-lg p-4 border border-slate-700 hover:border-brand-500/50 transition-colors cursor-pointer",onClick:()=>F(`chunks?id=${encodeURIComponent(n.id)}`),children:[t("div",{className:"flex items-center justify-between mb-2",children:[t("div",{className:"flex items-center gap-2 min-w-0",children:[t("span",{className:"text-sm text-yellow-400 font-mono truncate",children:[w(n.filePath),":",n.startLine,"-",n.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(n.language)}})]}),t("span",{className:"text-lg font-bold shrink-0 ml-2",style:{color:as(s)},children:s.toFixed(2)})]}),e.explanation&&t(ts,{explanation:e.explanation}),((l=(a=e.explanation)==null?void 0:a.matchedTerms)==null?void 0:l.length)>0&&t("div",{className:"flex gap-1 flex-wrap mb-2",children:e.explanation.matchedTerms.map(r=>t("span",{className:"text-xs bg-amber-500/20 text-amber-300 px-1.5 py-0.5 rounded",children:w(r)},r))}),n.description&&t("p",{className:"text-sm text-slate-400 mb-2 line-clamp-2",children:w(n.description)}),t("pre",{className:"text-xs overflow-x-auto max-h-32 rounded bg-slate-900/50 p-2",children:t("code",{children:w(n.content??"").slice(0,500)})})]})}function as(e){return e>=.8?"#22c55e":e>=.6?"#06b6d4":e>=.4?"#f59e0b":"#ef4444"}function at({label:e,min:n,max:s,step:a,value:l,onChange:r}){return t("div",{className:"flex items-center gap-3",children:[t("label",{className:"text-xs text-slate-400 w-28 shrink-0",children:e}),t("input",{type:"range",min:n,max:s,step:a,value:l,onInput:i=>r(parseFloat(i.target.value)),className:"flex-1 accent-brand-500"}),t("span",{className:"text-xs text-slate-300 font-mono w-12 text-right",children:l})]})}function rs(){var c;const n=((c=Oe().params.ids)==null?void 0:c.split(",").filter(Boolean))??[],[s,a]=g([]),[l,r]=g(!0),[i,o]=g(null);return j(()=>{let d=!1;if(n.length<2){o("Select 2-3 chunks to compare."),r(!1);return}return $.compare(n).then(u=>{var f;d||(a(((f=u==null?void 0:u.body)==null?void 0:f.chunks)??(u==null?void 0:u.chunks)??[]),r(!1))}).catch(u=>{d||(o(u.message),r(!1))}),()=>{d=!0}},[n.join(",")]),l?t(G,{type:"detail"}):i?t(ee,{message:i}):s.length<2?t(fe,{icon:"📋",message:"Select 2-3 chunks from the Chunks view to compare them."}):t("div",{children:[t("div",{className:"flex items-center justify-between mb-4",children:[t("h1",{className:"text-2xl font-bold",children:"Chunk Comparison"}),t("button",{className:"text-sm text-slate-400 hover:text-white transition-colors",onClick:()=>F("chunks"),children:"← Back to Chunks"})]}),t("div",{className:`grid gap-4 ${s.length===2?"grid-cols-2":"grid-cols-3"}`,children:s.map((d,u)=>t(ls,{chunk:d,index:u,baseChunk:u>0?s[0]:void 0},d.id))})]})}function ls({chunk:e,index:n,baseChunk:s}){const a=e.content.split(`
3
- `),l=(s==null?void 0:s.content.split(`
4
- `))??[];return t("div",{className:"bg-slate-800 rounded-lg border border-slate-700 overflow-hidden flex flex-col",children:[t("div",{className:"p-3 border-b border-slate-700 bg-slate-800/80",children:[t("div",{className:"flex items-center justify-between mb-1",children:[t("span",{className:"text-sm font-mono text-brand-400 truncate mr-2",children:[w(e.filePath),":",e.startLine,"-",e.endLine]}),t("span",{className:"shrink-0",dangerouslySetInnerHTML:{__html:he(e.language)}})]}),e.description&&t("p",{className:"text-xs text-slate-400 truncate",children:w(e.description)})]}),t("div",{className:"overflow-x-auto flex-1 max-h-[70vh]",children:t("table",{className:"w-full text-xs font-mono border-collapse",children:t("tbody",{children:a.map((r,i)=>{const o=(e.startLine??1)+i,c=l[i]===void 0?"bg-green-900/30":r===""&&l[i]!==""?"bg-red-900/30":r!==l[i]?"bg-amber-900/20":"";return t("tr",{className:c,children:[t("td",{className:"text-right text-slate-600 select-none px-2 w-10 border-r border-slate-700 align-top",children:o}),t("td",{className:"px-3 py-0 whitespace-pre-wrap break-all",children:w(r)||" "})]},i)})})})}),t("div",{className:"px-3 py-1.5 bg-slate-900 border-t border-slate-700 text-xs text-slate-500",children:["Chunk ",n+1,n===0&&t("span",{className:"text-slate-600 ml-1",children:"(reference)"})]})]})}function is(){var r;const{data:e,isLoading:n,error:s,refresh:a}=J(()=>$.config());if(n)return t(G,{type:"card"});if(s)return t(ee,{message:s,onRetry:a});const l=((r=e==null?void 0:e.body)==null?void 0:r.config)??(e==null?void 0:e.config);return l?t("div",{children:[t("h1",{className:"text-2xl font-bold mb-6",children:"Configuration"}),t("p",{className:"text-sm text-slate-400 mb-4",children:["Effective configuration from ",t("code",{className:"text-brand-400",children:"opencode-rag.json"}),". API keys are redacted."]}),t("div",{className:"space-y-4",children:Object.entries(l).map(([i,o])=>t("details",{className:"bg-slate-800 rounded-lg border border-slate-700",open:!0,children:[t("summary",{className:"px-4 py-2 cursor-pointer hover:bg-slate-700 font-mono text-sm font-semibold capitalize text-slate-300",children:i.replace(/([A-Z])/g," $1")}),t("div",{className:"px-4 pb-3",children:typeof o=="object"&&o!==null?Object.entries(o).map(([c,d])=>t("div",{className:"flex justify-between py-1 border-b border-slate-700/50 text-sm",children:[t("span",{className:"text-slate-400 font-mono",children:c}),t("span",{className:"text-slate-200 font-mono text-xs text-right ml-4",children:os(d)})]},c)):t("div",{className:"flex justify-between py-1 text-sm",children:t("span",{className:"text-slate-200 font-mono",children:String(o)})})})]},i))})]}):t(fe,{icon:"⚙",message:"No configuration available."})}function os(e){return e===null?"null":e===void 0?"undefined":typeof e=="boolean"?e?"true":"false":Array.isArray(e)?`[${e.join(", ")}]`:typeof e=="object"?JSON.stringify(e).slice(0,150):String(e)}const cs="modulepreload",ds=function(e){return"/ui/"+e},Pt={},us=function(n,s,a){let l=Promise.resolve();if(s&&s.length>0){document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),o=(i==null?void 0:i.nonce)||(i==null?void 0:i.getAttribute("nonce"));l=Promise.allSettled(s.map(c=>{if(c=ds(c),c in Pt)return;Pt[c]=!0;const d=c.endsWith(".css"),u=d?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${u}`))return;const f=document.createElement("link");if(f.rel=d?"stylesheet":cs,d||(f.as="script"),f.crossOrigin="",f.href=c,o&&f.setAttribute("nonce",o),document.head.appendChild(f),d)return new Promise((x,h)=>{f.addEventListener("load",x),f.addEventListener("error",()=>h(new Error(`Unable to preload CSS for ${c}`)))})}))}function r(i){const o=new Event("vite:preloadError",{cancelable:!0});if(o.payload=i,window.dispatchEvent(o),!o.defaultPrevented)throw i}return l.then(i=>{for(const o of i||[])o.status==="rejected"&&r(o.reason);return n().catch(r)})};function hs(e,n){for(var s in n)e[s]=n[s];return e}function Rt(e,n){for(var s in e)if(s!=="__source"&&!(s in n))return!0;for(var a in n)if(a!=="__source"&&e[a]!==n[a])return!0;return!1}function It(e,n){this.props=e,this.context=n}(It.prototype=new Ne).isPureReactComponent=!0,It.prototype.shouldComponentUpdate=function(e,n){return Rt(this.props,e)||Rt(this.state,n)};var Et=O.__b;O.__b=function(e){e.type&&e.type.__f&&e.ref&&(e.props.ref=e.ref,e.ref=null),Et&&Et(e)};var fs=O.__e;O.__e=function(e,n,s,a){if(e.then){for(var l,r=n;r=r.__;)if((l=r.__c)&&l.__c)return n.__e==null&&(n.__e=s.__e,n.__k=s.__k||[]),l.__c(e,n)}fs(e,n,s,a)};var Mt=O.unmount;function rn(e,n,s){return e&&(e.__c&&e.__c.__H&&(e.__c.__H.__.forEach(function(a){typeof a.__c=="function"&&a.__c()}),e.__c.__H=null),(e=hs({},e)).__c!=null&&(e.__c.__P===s&&(e.__c.__P=n),e.__c.__e=!0,e.__c=null),e.__k=e.__k&&e.__k.map(function(a){return rn(a,n,s)})),e}function ln(e,n,s){return e&&s&&(e.__v=null,e.__k=e.__k&&e.__k.map(function(a){return ln(a,n,s)}),e.__c&&e.__c.__P===n&&(e.__e&&s.appendChild(e.__e),e.__c.__e=!0,e.__c.__P=s)),e}function We(){this.__u=0,this.o=null,this.__b=null}function on(e){var n=e.__&&e.__.__c;return n&&n.__a&&n.__a(e)}function ms(e){var n,s,a,l=null;function r(i){if(n||(n=e()).then(function(o){o&&(l=o.default||o),a=!0},function(o){s=o,a=!0}),s)throw s;if(!a)throw n;return l?lt(l,i):null}return r.displayName="Lazy",r.__f=!0,r}function He(){this.i=null,this.l=null}O.unmount=function(e){var n=e.__c;n&&(n.__z=!0),n&&n.__R&&n.__R(),n&&32&e.__u&&(e.type=null),Mt&&Mt(e)},(We.prototype=new Ne).__c=function(e,n){var s=n.__c,a=this;a.o==null&&(a.o=[]),a.o.push(s);var l=on(a.__v),r=!1,i=function(){r||a.__z||(r=!0,s.__R=null,l?l(c):c())};s.__R=i;var o=s.__P;s.__P=null;var c=function(){if(!--a.__u){if(a.state.__a){var d=a.state.__a;a.__v.__k[0]=ln(d,d.__c.__P,d.__c.__O)}var u;for(a.setState({__a:a.__b=null});u=a.o.pop();)u.__P=o,u.forceUpdate()}};a.__u++||32&n.__u||a.setState({__a:a.__b=a.__v.__k[0]}),e.then(i,i)},We.prototype.componentWillUnmount=function(){this.o=[]},We.prototype.render=function(e,n){if(this.__b){if(this.__v.__k){var s=document.createElement("div"),a=this.__v.__k[0].__c;this.__v.__k[0]=rn(this.__b,s,a.__O=a.__P)}this.__b=null}var l=n.__a&&lt(ie,null,e.fallback);return l&&(l.__u&=-33),[lt(ie,null,n.__a?null:e.children),l]};var At=function(e,n,s){if(++s[1]===s[0]&&e.l.delete(n),e.props.revealOrder&&(e.props.revealOrder[0]!=="t"||!e.l.size))for(s=e.i;s;){for(;s.length>3;)s.pop()();if(s[1]<s[0])break;e.i=s=s[2]}};(He.prototype=new Ne).__a=function(e){var n=this,s=on(n.__v),a=n.l.get(e);return a[0]++,function(l){var r=function(){n.props.revealOrder?(a.push(l),At(n,e,a)):l()};s?s(r):r()}},He.prototype.render=function(e){this.i=null,this.l=new Map;var n=it(e.children);e.revealOrder&&e.revealOrder[0]==="b"&&n.reverse();for(var s=n.length;s--;)this.l.set(n[s],this.i=[1,0,this.i]);return e.children},He.prototype.componentDidUpdate=He.prototype.componentDidMount=function(){var e=this;this.l.forEach(function(n,s){At(e,s,n)})};var ps=typeof Symbol<"u"&&Symbol.for&&Symbol.for("react.element")||60103,xs=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,vs=/^on(Ani|Tra|Tou|BeforeInp|Compo)/,gs=/[A-Z0-9]/g,bs=typeof document<"u",_s=function(e){return(typeof Symbol<"u"&&typeof Symbol()=="symbol"?/fil|che|rad/:/fil|che|ra/).test(e)};Ne.prototype.isReactComponent=!0,["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(e){Object.defineProperty(Ne.prototype,e,{configurable:!0,get:function(){return this["UNSAFE_"+e]},set:function(n){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:n})}})});var Dt=O.event;O.event=function(e){return Dt&&(e=Dt(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var ys={configurable:!0,get:function(){return this.class}},Ot=O.vnode;O.vnode=function(e){typeof e.type=="string"&&function(n){var s=n.props,a=n.type,l={},r=a.indexOf("-")==-1;for(var i in s){var o=s[i];if(!(i==="value"&&"defaultValue"in s&&o==null||bs&&i==="children"&&a==="noscript"||i==="class"||i==="className")){var c=i.toLowerCase();i==="defaultValue"&&"value"in s&&s.value==null?i="value":i==="download"&&o===!0?o="":c==="translate"&&o==="no"?o=!1:c[0]==="o"&&c[1]==="n"?c==="ondoubleclick"?i="ondblclick":c!=="onchange"||a!=="input"&&a!=="textarea"||_s(s.type)?c==="onfocus"?i="onfocusin":c==="onblur"?i="onfocusout":vs.test(i)&&(i=c):c=i="oninput":r&&xs.test(i)?i=i.replace(gs,"-$&").toLowerCase():o===null&&(o=void 0),c==="oninput"&&l[i=c]&&(i="oninputCapture"),l[i]=o}}a=="select"&&(l.multiple&&Array.isArray(l.value)&&(l.value=it(s.children).forEach(function(d){d.props.selected=l.value.indexOf(d.props.value)!=-1})),l.defaultValue!=null&&(l.value=it(s.children).forEach(function(d){d.props.selected=l.multiple?l.defaultValue.indexOf(d.props.value)!=-1:l.defaultValue==d.props.value}))),s.class&&!s.className?(l.class=s.class,Object.defineProperty(l,"className",ys)):s.className&&(l.class=l.className=s.className),n.props=l}(e),e.$$typeof=ps,Ot&&Ot(e)};var jt=O.__r;O.__r=function(e){jt&&jt(e),e.__c};var Ft=O.diffed;O.diffed=function(e){Ft&&Ft(e);var n=e.props,s=e.__e;s!=null&&e.type==="textarea"&&"value"in n&&n.value!==s.value&&(s.value=n.value==null?"":n.value)};const Ns=10;function ws({points:e,width:n=800,height:s=600,onPointClick:a,renderTooltip:l}){const r=te(null),[i,o]=g({x:0,y:0,scale:1}),[c,d]=g(null),[u,f]=g(!1),x=te({x:0,y:0}),h=te(null),p=te(null),m=te(e);m.current=e;const b=Nt(k=>{h.current=k(h.current??i),p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null,h.current&&(o(h.current),h.current=null)}))},[i]);j(()=>()=>{p.current!==null&&cancelAnimationFrame(p.current)},[]);const T=Nt((k,y)=>{const R=r.current;if(!R)return null;const K=R.getBoundingClientRect(),B=h.current??i,me=k-K.left,pe=y-K.top;let Se=null,A=Ns;for(const xe of m.current){const ve=xe.x*n*B.scale+B.x,ge=xe.y*s*B.scale+B.y,oe=me-ve,Ce=pe-ge,$e=Math.sqrt(oe*oe+Ce*Ce);$e<=A&&(A=$e,Se=xe)}return Se},[i,n,s]);j(()=>{const k=r.current;if(!k)return;const y=k.getContext("2d");if(!y)return;const R=window.devicePixelRatio||1;k.width=n*R,k.height=s*R,y.scale(R,R),y.clearRect(0,0,n,s),y.save(),y.translate(i.x,i.y),y.scale(i.scale,i.scale);for(const K of e){const B=K.x*n,me=K.y*s,pe=(K.radius??3)*(K.highlighted?2:1);y.beginPath(),y.arc(B,me,pe,0,Math.PI*2),y.fillStyle=K.color,y.globalAlpha=K.highlighted?1:.6,y.fill(),K.highlighted&&(y.strokeStyle="#22d3ee",y.lineWidth=2,y.stroke())}y.restore()},[e,i,n,s]);const M=k=>{k.preventDefault();const y=k.deltaY>0?.9:1.1;b(R=>({...R,scale:Math.max(.5,Math.min(10,R.scale*y))}))},_=k=>{f(!0),x.current={x:k.clientX-i.x,y:k.clientY-i.y}},Y=k=>{if(u){b(R=>({...R,x:k.clientX-x.current.x,y:k.clientY-x.current.y}));return}const y=T(k.clientX,k.clientY);d(R=>(R==null?void 0:R.id)===(y==null?void 0:y.id)?R:y)},Ue=()=>f(!1);return t("div",{className:"relative overflow-hidden rounded-lg border border-slate-700 bg-slate-900",style:{width:n,height:s},children:[t("canvas",{ref:r,className:"absolute inset-0 cursor-grab active:cursor-grabbing",onMouseDown:_,onMouseMove:Y,onMouseUp:Ue,onMouseLeave:Ue,onClick:k=>{if(u)return;const y=T(k.clientX,k.clientY);y&&(a==null||a(y.id))},onWheel:M}),c&&l&&t("div",{className:"absolute bg-slate-800 border border-slate-600 rounded-lg p-3 shadow-xl text-sm z-10 pointer-events-none",style:{left:Math.min(c.x*n*i.scale+i.x+12,n-200),top:Math.min(c.y*s*i.scale+i.y-12,s-80)},children:l(c)}),i.scale!==1&&t("button",{className:"absolute bottom-3 right-3 px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors z-20",onClick:()=>{o({x:0,y:0,scale:1}),h.current=null},children:"Reset zoom"})]})}function Me(e,n){const s=e.x-n.x,a=e.y-n.y,l=(e.z??0)-(n.z??0);return Math.sqrt(s*s+a*a+l*l)}function ks(e,n=8,s=20){const a=e.length;if(a<=n)return e.map((i,o)=>o);const l=new Array(a).fill(0),r=[];r.push(e[Math.floor(Math.random()*a)]);for(let i=1;i<n;i++){const o=e.map(u=>Math.min(...r.map(f=>Me(u,f)))),c=o.reduce((u,f)=>u+f*f,0);let d=Math.random()*c;for(let u=0;u<a;u++)if(d-=o[u]*o[u],d<=0){r.push(e[u]);break}}for(let i=0;i<s;i++){for(let c=0;c<a;c++){let d=0,u=Me(e[c],r[0]);for(let f=1;f<r.length;f++){const x=Me(e[c],r[f]);x<u&&(u=x,d=f)}l[c]=d}const o=r.map(()=>({x:0,y:0,z:0,count:0}));for(let c=0;c<a;c++){const d=l[c];o[d].x+=e[c].x,o[d].y+=e[c].y,o[d].z+=e[c].z??0,o[d].count++}r.forEach((c,d)=>{o[d].count>0&&(c.x=o[d].x/o[d].count,c.y=o[d].y/o[d].count,c.z!==void 0&&(c.z=o[d].z/o[d].count))})}return l}function Ss(e,n,s){const a=s.map((r,i)=>{const c=e.filter((f,x)=>n[x]===i).map(f=>Me(f,r)),d=c.reduce((f,x)=>f+x,0)/c.length,u=c.reduce((f,x)=>f+(x-d)**2,0)/c.length;return Math.sqrt(u)}),l=new Set;for(let r=0;r<e.length;r++){const i=n[r];Me(e[r],s[i])>2*(a[i]??0)&&l.add(r)}return l}const Cs=ms(()=>us(()=>import("./ScatterPlot3D-BFWO5sAH.js"),__vite__mapDeps([0,1])).then(e=>({default:e.ScatterPlot3D}))),Ke=["#3b82f6","#ef4444","#22c55e","#f59e0b","#a855f7","#06b6d4","#ec4899","#84cc16","#f97316","#14b8a6","#8b5cf6","#e11d48","#65a30d","#0ea5e9","#d946ef","#ca8a04","#64748b","#4ade80","#fb7185","#38bdf8"],rt=2,Ut=50,zt=5,qt=200,$s=20,Ls=12;function Ts(){var ft,mt;const{data:e,isLoading:n,error:s,refresh:a}=J(()=>$.embeddingProj(5e3,3)),[l,r]=g("language"),[i,o]=g("3d"),[c,d]=g(!1),[u,f]=g(8),[x,h]=g(20),[p,m]=g(!1),[b,T]=g(new Set),[M,_]=g(5),[Y,Ue]=g(0),[z,k]=g(null),[y,R]=g(!1),K=te(0),[B,me]=g(null),[pe,Se]=g(new Set),A=((ft=e==null?void 0:e.body)==null?void 0:ft.points)??(e==null?void 0:e.points)??[],xe=((mt=e==null?void 0:e.body)==null?void 0:mt.totalChunks)??(e==null?void 0:e.totalChunks)??0;if(j(()=>{var v;if(l==="cluster"&&A.length>0){const P=Math.max(rt,Math.min(u,A.length)),N=ks(A,P,x);if(me(N),c){const q=[];for(let be=0;be<P;be++){const Q=A.filter((Le,ce)=>N[ce]===be);if(Q.length>0){const Le=((v=Q[0])==null?void 0:v.z)!==void 0;q.push({x:Q.reduce((ce,Te)=>ce+Te.x,0)/Q.length,y:Q.reduce((ce,Te)=>ce+Te.y,0)/Q.length,...Le?{z:Q.reduce((ce,Te)=>ce+(Te.z??0),0)/Q.length}:{}})}}Se(Ss(A,N,q))}}else me(null),Se(new Set)},[l,c,u,x,A]),j(()=>{p&&ae.value.length>0?T(new Set(ae.value.map(v=>v.chunk.id))):T(new Set)},[p,ae.value]),n)return t(G,{type:"chart"});if(s)return t(ee,{message:s,onRetry:a});if(A.length===0)return t(fe,{icon:"🌐",message:"No embedding data available. Index some files first."});const ve=re(()=>Rs(A),[A]),ge=re(()=>A.map((v,P)=>{let N;if(l==="language")N=Fe(v.language)==="text-slate-400"?"#94a3b8":Is(v.language);else if(l==="file")N=ve.get(v.filePath)??"#94a3b8";else{const Le=(B==null?void 0:B[P])??0;N=Ke[Le%Ke.length]}const q=pe.has(P),Q=b.has(v.id);return{id:v.id,x:v.x,y:v.y,z:v.z??.5,color:Q?"#22d3ee":q?"#f97316":N,label:`${v.filePath}:${v.startLine}-${v.endLine} [${v.language}]`,radius:Q?6:q?5:3,highlighted:Q}}),[A,l,B,pe,b,ve]),oe=re(()=>{if(l!=="file")return[];const v=Ps(A.map(N=>N.filePath)),P=new Map;for(const N of A)P.set(N.filePath,(P.get(N.filePath)??0)+1);return[...P.entries()].sort((N,q)=>q[1]-N[1]).slice(0,Ls).map(([N,q])=>({label:N.slice(v.length)||N,count:q,color:ve.get(N)??"#94a3b8"}))},[l,A,ve]),Ce=re(()=>l!=="file"?0:new Set(A.map(v=>v.filePath)).size-oe.length,[l,A,oe]),$e=v=>{const P=++K.current;k(null),R(!0),$.chunk(v).then(N=>{P===K.current&&(k(N),R(!1))}).catch(()=>{P===K.current&&(k({id:v,content:"",filePath:"not found",language:"",startLine:0,endLine:0,description:"Error loading chunk details."}),R(!1))})};return t("div",{children:[t("h1",{className:"text-2xl font-bold mb-4",children:"Embedding Space Explorer"}),t("div",{className:"flex flex-wrap gap-3 mb-4 items-center",children:[t("div",{className:"flex items-center gap-1 bg-slate-800 border border-slate-600 rounded-lg p-0.5",children:["2d","3d"].map(v=>t("button",{className:`px-2 py-0.5 rounded text-xs transition-colors ${i===v?"bg-slate-600 text-white":"text-slate-400 hover:text-slate-200"}`,onClick:()=>o(v),children:v.toUpperCase()},v))}),t("label",{className:"text-xs text-slate-400",children:"Color by:"}),t("select",{className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1",value:l,onChange:v=>r(v.target.value),children:[t("option",{value:"language",children:"Language"}),t("option",{value:"file",children:"File"}),t("option",{value:"cluster",children:"Cluster"})]}),l==="cluster"&&t(ie,{children:[t("label",{className:"text-xs text-slate-400",children:"K:"}),t("input",{type:"number",min:rt,max:Ut,value:u,onChange:v=>f(Ht(v.target,rt,Ut,8)),className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1 w-16",title:"Number of clusters"}),t("label",{className:"text-xs text-slate-400",children:"Iterations:"}),t("input",{type:"number",min:zt,max:qt,value:x,onChange:v=>h(Ht(v.target,zt,qt,20)),className:"bg-slate-800 border border-slate-600 rounded text-xs text-slate-200 px-2 py-1 w-20",title:"Maximum k-means iterations"})]}),t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:c,onChange:v=>d(v.target.checked)}),"Outliers"]}),ae.value.length>0&&t("label",{className:"flex items-center gap-1.5 text-xs text-slate-400",children:[t("input",{type:"checkbox",className:"accent-brand-500",checked:p,onChange:v=>m(v.target.checked)}),"Search overlay (",ae.value.length," results)"]}),i==="3d"&&t(ie,{children:[t("label",{className:"text-xs text-slate-400",children:"Point size:"}),t("input",{type:"range",min:1,max:20,value:M,onChange:v=>_(Number(v.target.value)),className:"w-24 accent-brand-500"}),t("button",{className:"px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors",onClick:()=>Ue(v=>v+1),children:"Reset camera"})]})]}),l==="cluster"&&B&&t("div",{className:"flex flex-wrap gap-2 mb-3 text-xs",children:(()=>{const v=Array.from(new Set(B)).sort((q,be)=>q-be),P=v.slice(0,$s),N=v.length-P.length;return t(ie,{children:[P.map(q=>t("span",{className:"flex items-center gap-1 text-slate-400",children:[t("span",{className:"inline-block w-2 h-2 rounded-full",style:{background:Ke[q%Ke.length]}}),"Cluster ",q+1]},q)),N>0&&t("span",{className:"text-slate-500",children:["+",N," more"]})]})})()}),l==="file"&&oe.length>0&&t("div",{className:"flex flex-wrap gap-2 mb-3 text-xs",children:[oe.map(({label:v,count:P,color:N})=>t("span",{className:"flex items-center gap-1 text-slate-400",title:v,children:[t("span",{className:"inline-block w-2 h-2 rounded-full",style:{background:N}}),w(Lt(v,40))," (",P,")"]},v)),Ce>0&&t("span",{className:"text-slate-500",children:["+",Ce," more files"]})]}),i==="3d"?t(We,{fallback:t(G,{type:"chart"}),children:t(Cs,{points:ge,width:900,height:600,onPointClick:$e,pointSize:M,resetKey:Y,selectedId:(z==null?void 0:z.id)??null})}):t(ws,{points:ge,width:900,height:600,onPointClick:$e,renderTooltip:v=>{const P=A.find(N=>N.id===v.id);return t("div",{children:[t("div",{className:"text-yellow-400 font-mono text-xs",children:w(v.label)}),(P==null?void 0:P.description)&&t("div",{className:"text-slate-400 text-xs mt-1",children:w(Lt(P.description,80))})]})}}),y&&t(G,{type:"detail"}),z&&!y&&t("div",{className:"kpi-card p-4 mt-4",children:[t("div",{className:"flex items-center gap-3 mb-1 flex-wrap",children:[t("span",{className:"text-yellow-400 font-mono text-sm",children:w(z.filePath)}),t("span",{className:"text-slate-400 text-xs",children:["Lines ",z.startLine,"-",z.endLine]}),t("span",{dangerouslySetInnerHTML:{__html:he(z.language)}}),z.id&&t("span",{className:"text-xs text-slate-600 font-mono",children:z.id}),t("button",{className:"ml-auto px-2 py-1 bg-slate-700 hover:bg-slate-600 rounded text-xs text-white transition-colors",onClick:()=>F(`chunks?id=${encodeURIComponent(z.id)}`),children:"Open in Chunks"})]}),z.description&&t("div",{className:"mb-3",children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Description"}),t("p",{className:"text-sm text-slate-300",children:w(z.description)})]}),z.content&&t("div",{children:[t("h3",{className:"text-xs font-semibold text-slate-400 mb-1",children:"Content"}),t("pre",{className:"text-xs text-slate-300 bg-slate-900 border border-slate-700 rounded p-3 overflow-auto max-h-64 font-mono whitespace-pre",children:w(z.content)})]})]}),t("p",{className:"text-xs text-slate-500 mt-2",children:[ge.length," of ",xe," chunks displayed",ge.length<xe&&" (chunks without embeddings omitted)"]})]})}function Ht(e,n,s,a){const l=parseInt((e==null?void 0:e.value)??"",10);return Number.isNaN(l)?a:Math.max(n,Math.min(s,l))}function Ps(e){if(e.length===0)return"";let n=e[0]??"";for(const a of e)for(;a&&n&&!a.startsWith(n);)n=n.slice(0,-1);const s=n.lastIndexOf("/");return s>=0?n.slice(0,s+1):""}function Rs(e){const n=new Map;for(const h of e){const p=n.get(h.filePath)??{x:0,y:0,z:0,n:0};p.x+=h.x,p.y+=h.y,p.z+=h.z??0,p.n++,n.set(h.filePath,p)}const s=[];for(const[h,p]of n)s.push({file:h,x:p.x/p.n,y:p.y/p.n,z:p.z/p.n});const a=s.reduce((h,p)=>h+p.x,0)/s.length,l=s.reduce((h,p)=>h+p.y,0)/s.length,r=s.reduce((h,p)=>h+p.z,0)/s.length,i=s.reduce((h,p)=>h+(p.x-a)**2,0),o=s.reduce((h,p)=>h+(p.y-l)**2,0),c=s.reduce((h,p)=>h+(p.z-r)**2,0),d=i>=o&&i>=c?"x":o>=c?"y":"z",u=["x","y","z"].filter(h=>h!==d);s.sort((h,p)=>h[d]-p[d]||h[u[0]]-p[u[0]]||h[u[1]]-p[u[1]]);const f=new Map,x=137.508;for(let h=0;h<s.length;h++){const p=h*x%360,m=h%2===0?55:40;f.set(s[h].file,`hsl(${p.toFixed(1)}, 80%, ${m}%)`)}return f}function Is(e){return{typescript:"#60a5fa",javascript:"#facc15",python:"#4ade80",java:"#f87171",go:"#22d3ee",rust:"#fb923c",ruby:"#f472b6",csharp:"#a78bfa",cpp:"#818cf8",c:"#9ca3af",markdown:"#d1d5db",html:"#fdba74",css:"#60a5fa",json:"#fde047",kotlin:"#c084fc",swift:"#fb923c",tex:"#34d399",sql:"#67e8f9",text:"#94a3b8",image:"#a78bfa",quirk:"#fbbf24"}[e]??"#94a3b8"}const Es=[{view:"dashboard",label:"Dashboard",icon:"📊"},{view:"search",label:"Search",icon:"🔍"},{view:"embeddings",label:"Embeddings",icon:"🌐"},{view:"chunks",label:"Chunks",icon:"🧩"},{view:"files",label:"Files",icon:"📄"},{view:"evaluate",label:"Evaluate",icon:"📈"},{view:"quirks",label:"Quirks",icon:"💡"}];function Ms(){Cn(),$n();const e=Oe();nt.value=e.view;const n=()=>{qe.value=!qe.value};return t("div",{className:"h-screen flex flex-col overflow-hidden",children:[t("header",{className:"flex items-center gap-3 px-4 py-2 border-b shrink-0",style:{borderColor:"var(--border)"},children:[t("h1",{className:"text-lg font-bold shrink-0",style:{color:"var(--accent)"},children:"OpenCodeRAG"}),t("nav",{className:"flex gap-1 flex-1",role:"navigation","aria-label":"Main navigation",children:Es.map(s=>t("button",{id:`nav-${s.view}`,className:`nav-btn ${nt.value===s.view?"active":""}`,onClick:()=>window.location.hash=s.view,role:"tab","aria-selected":nt.value===s.view,children:[s.icon," ",s.label]},s.view))}),t(An,{}),t(Tn,{}),t("button",{className:"p-2 rounded-lg transition-colors hidden lg:block",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"}),t("button",{className:"p-2 rounded-lg transition-colors lg:hidden",style:{color:"var(--text-muted)"},onClick:n,"aria-label":"Toggle file tree",title:"Toggle file tree",children:"☰"})]}),t("div",{className:"flex flex-1 overflow-hidden",children:[qe.value&&t(ie,{children:[t("div",{className:"fixed inset-0 z-30 lg:hidden",style:{background:"rgba(0,0,0,0.5)"},onClick:()=>{qe.value=!1}}),t("aside",{className:"w-64 overflow-y-auto shrink-0 border-r z-40 fixed lg:relative inset-y-0 left-0",style:{background:"var(--bg-secondary)",borderColor:"var(--border)"},role:"tree","aria-label":"File tree",children:t(Dn,{})})]}),t("main",{className:"flex-1 overflow-y-auto p-6",id:"main-content",tabIndex:-1,children:[e.view==="dashboard"&&t(zn,{}),e.view==="search"&&t(ns,{}),e.view==="embeddings"&&t(Ts,{}),e.view==="compare"&&t(rs,{}),e.view==="chunks"&&t(qn,{}),e.view==="files"&&t(Kn,{}),e.view==="evaluate"&&t(Vn,{}),e.view==="quirks"&&t(Jn,{}),e.view==="config"&&t(is,{})]})]}),t(Ln,{})]})}dn(t(Ms,{}),document.getElementById("app"));export{te as A,j as h,t as u};