@evandu/super-pi 0.1.236 → 0.1.237
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/dist/client/.super-pi-client-sources.json +8 -7
- package/dist/client/assets/{CodeMirrorEditor-o_5EQTv_.js → CodeMirrorEditor-C0egC0LO.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-BH8jsKMm.js → GitDiffEditor-aldh2_D_.js} +2 -2
- package/dist/client/assets/index-BWLRPUnY.css +1 -0
- package/dist/client/assets/index-Bolukoov.js +340 -0
- package/dist/client/index.html +2 -2
- package/dist/server/file-name-index.js +14 -5
- package/dist/server/http-server.js +19 -0
- package/dist/server/store.d.ts +2 -0
- package/dist/server/store.js +30 -0
- package/dist/shared/file-mentions.d.ts +1 -1
- package/dist/shared/file-mentions.js +2 -0
- package/dist/shared/session-search.d.ts +14 -0
- package/dist/shared/session-search.js +1 -0
- package/package.json +1 -1
- package/dist/client/assets/index-CPZJ8qsj.css +0 -1
- package/dist/client/assets/index-Dg6iMr6l.js +0 -340
package/dist/client/index.html
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
<link rel="alternate icon" href="/favicon.ico" />
|
|
9
9
|
<link rel="apple-touch-icon" href="/favicon.svg" />
|
|
10
10
|
<title>Super Pi</title>
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-Bolukoov.js"></script>
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-XKyaHtl9.js">
|
|
13
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
13
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BWLRPUnY.css">
|
|
14
14
|
</head>
|
|
15
15
|
<body>
|
|
16
16
|
<div id="root"></div>
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { readdir, stat } from "node:fs/promises";
|
|
35
35
|
import { resolve } from "node:path";
|
|
36
|
+
import { matchPathMentions } from "../shared/file-mentions.js";
|
|
36
37
|
import { createRootGuard, toRelative } from "./files.js";
|
|
37
38
|
import { belowPath, blockedBy, inScope, matchesDirectoryReads } from "./file-index.js";
|
|
38
39
|
import { explorerInternalPath } from "./workspace-file-operations.js";
|
|
@@ -247,21 +248,29 @@ export class FileNameIndex {
|
|
|
247
248
|
* `app` return every file in `application/` as well - a result set nobody can read.
|
|
248
249
|
*/
|
|
249
250
|
search(needle, linksOnly = false) {
|
|
250
|
-
const
|
|
251
|
+
const normalized = needle.trim().replaceAll("\\", "/").replace(/^\.\//u, "");
|
|
252
|
+
const query = normalized.toLowerCase();
|
|
251
253
|
if (!query) {
|
|
252
254
|
return { hits: [], total: 0, indexed: this.indexed, progress: this.progress, incomplete: this.incomplete };
|
|
253
255
|
}
|
|
254
256
|
const hits = [];
|
|
257
|
+
const withDirectory = query.includes("/");
|
|
255
258
|
for (const entry of this.entries.values()) {
|
|
256
259
|
if (entry.kind !== "file" || linksOnly && !entry.openLink)
|
|
257
260
|
continue;
|
|
258
|
-
if (entry.name.toLowerCase().includes(query))
|
|
261
|
+
if (linksOnly || (withDirectory ? entry.path : entry.name).toLowerCase().includes(query))
|
|
259
262
|
hits.push(entry);
|
|
260
263
|
}
|
|
261
|
-
|
|
264
|
+
if (withDirectory && !linksOnly) {
|
|
265
|
+
hits.sort((a, b) => Number(b.path === normalized) - Number(a.path === normalized)
|
|
266
|
+
|| Number(b.path.toLowerCase() === query) - Number(a.path.toLowerCase() === query) || compareNameHits(a, b, query));
|
|
267
|
+
}
|
|
268
|
+
else if (!linksOnly)
|
|
269
|
+
hits.sort((a, b) => compareNameHits(a, b, query));
|
|
270
|
+
const results = linksOnly ? matchPathMentions(hits, query, 100) : hits;
|
|
262
271
|
return {
|
|
263
|
-
hits,
|
|
264
|
-
total:
|
|
272
|
+
hits: results,
|
|
273
|
+
total: results.length,
|
|
265
274
|
indexed: this.indexed,
|
|
266
275
|
progress: this.progress,
|
|
267
276
|
incomplete: this.incomplete,
|
|
@@ -2797,6 +2797,25 @@ export function createHttpServer(options) {
|
|
|
2797
2797
|
}
|
|
2798
2798
|
return;
|
|
2799
2799
|
}
|
|
2800
|
+
if (url.pathname === "/api/session-search") {
|
|
2801
|
+
if (request.method !== "GET") {
|
|
2802
|
+
json(405, { error: "会话搜索需要 GET 请求。" });
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2805
|
+
const workspaceId = url.searchParams.get("workspaceId")?.trim();
|
|
2806
|
+
const workspace = workspaceId ? store.workspace(workspaceId) : undefined;
|
|
2807
|
+
if (!workspaceId || !workspace || workspace.closedAt) {
|
|
2808
|
+
json(404, { error: "请先选择有效工作区。" });
|
|
2809
|
+
return;
|
|
2810
|
+
}
|
|
2811
|
+
const query = url.searchParams.get("q")?.trim() ?? "";
|
|
2812
|
+
if (query.length > 256 || /[\r\n]/.test(query)) {
|
|
2813
|
+
json(400, { error: "搜索词只能是一行,且不超过 256 个字符。" });
|
|
2814
|
+
return;
|
|
2815
|
+
}
|
|
2816
|
+
json(200, query ? store.searchConversationMessages(workspaceId, query) : { hits: [], truncated: false });
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2800
2819
|
if (url.pathname === "/api/files/search") {
|
|
2801
2820
|
const json = (status, body) => { response.writeHead(status, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(body)); };
|
|
2802
2821
|
try {
|
package/dist/server/store.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SessionSearchResult } from "../shared/session-search.js";
|
|
1
2
|
import type { AppStateRepository } from "./persistence/app-state-repository.js";
|
|
2
3
|
import { defaultJsonStatePath } from "./persistence/json-state-repository.js";
|
|
3
4
|
import type { ScheduledTask } from "./scheduled-tasks.js";
|
|
@@ -182,6 +183,7 @@ export declare class Store {
|
|
|
182
183
|
snapshot(): AppState;
|
|
183
184
|
/** Cheap scalar/entity reads for hot paths. Never expose the live mutable state object. */
|
|
184
185
|
hasWorkspace(workspaceId: string): boolean;
|
|
186
|
+
searchConversationMessages(workspaceId: string, query: string): SessionSearchResult;
|
|
185
187
|
conversationStatus(conversationId: string): Conversation["status"] | undefined;
|
|
186
188
|
question(conversationId: string, messageId: string, index: number): ToolCallQuestion | undefined;
|
|
187
189
|
pendingQuestion(conversationId: string): {
|
package/dist/server/store.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SESSION_SEARCH_LIMIT } from "../shared/session-search.js";
|
|
1
2
|
import { rename } from "node:fs/promises";
|
|
2
3
|
import { JsonStateRepository, defaultJsonStatePath } from "./persistence/json-state-repository.js";
|
|
3
4
|
import { normalizeTodos } from "./task-tool.js";
|
|
@@ -1078,6 +1079,35 @@ export class Store {
|
|
|
1078
1079
|
hasWorkspace(workspaceId) {
|
|
1079
1080
|
return this.state.workspaces.some((workspace) => workspace.id === workspaceId);
|
|
1080
1081
|
}
|
|
1082
|
+
searchConversationMessages(workspaceId, query) {
|
|
1083
|
+
const literal = new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "iu");
|
|
1084
|
+
const sessions = this.state.conversations
|
|
1085
|
+
.filter(item => item.workspaceId === workspaceId && !item.archivedAt && !item.warmSession)
|
|
1086
|
+
.sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
1087
|
+
const hits = [];
|
|
1088
|
+
for (const session of sessions) {
|
|
1089
|
+
for (let index = session.messages.length - 1; index >= 0; index--) {
|
|
1090
|
+
const { id, content, role, delivery } = session.messages[index];
|
|
1091
|
+
if (delivery || (role !== "user" && role !== "assistant"))
|
|
1092
|
+
continue;
|
|
1093
|
+
const match = literal.exec(content);
|
|
1094
|
+
if (!match)
|
|
1095
|
+
continue;
|
|
1096
|
+
if (hits.length === SESSION_SEARCH_LIMIT)
|
|
1097
|
+
return { hits, truncated: true };
|
|
1098
|
+
const start = Math.max(0, match.index - 72);
|
|
1099
|
+
const endOfMatch = match.index + match[0].length;
|
|
1100
|
+
const end = Math.min(content.length, endOfMatch + 96);
|
|
1101
|
+
hits.push({
|
|
1102
|
+
conversationId: session.id, title: session.title, messageId: id, role,
|
|
1103
|
+
before: (start ? "…" : "") + content.slice(start, match.index),
|
|
1104
|
+
match: match[0],
|
|
1105
|
+
after: content.slice(endOfMatch, end) + (end < content.length ? "…" : ""),
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
return { hits, truncated: false };
|
|
1110
|
+
}
|
|
1081
1111
|
conversationStatus(conversationId) {
|
|
1082
1112
|
return this.state.conversations.find((conversation) => conversation.id === conversationId)?.status;
|
|
1083
1113
|
}
|
|
@@ -9,7 +9,7 @@ export interface MentionToken {
|
|
|
9
9
|
}
|
|
10
10
|
/** Only a standalone @ token opens completion; email addresses and escaped @ stay literal. */
|
|
11
11
|
export declare function findMentionToken(text: string, caret: number, selectionEnd?: number): MentionToken | undefined;
|
|
12
|
-
export declare function matchPathMentions(entries: Iterable<
|
|
12
|
+
export declare function matchPathMentions<T extends PathMentionEntry>(entries: Iterable<T>, query: string, limit?: number): T[];
|
|
13
13
|
export declare function insertPathMention(text: string, token: MentionToken, entry: PathMentionEntry): {
|
|
14
14
|
text: string;
|
|
15
15
|
caret: number;
|
|
@@ -13,6 +13,8 @@ export function findMentionToken(text, caret, selectionEnd = caret) {
|
|
|
13
13
|
/** Ordered-character matching supports abbreviations such as sct -> src/client/theme.tsx. */
|
|
14
14
|
function fuzzyScore(path, query) {
|
|
15
15
|
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
16
|
+
if (path === query)
|
|
17
|
+
return -1;
|
|
16
18
|
if (name === query)
|
|
17
19
|
return 0;
|
|
18
20
|
if (name.startsWith(query))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const SESSION_SEARCH_LIMIT = 60;
|
|
2
|
+
export interface SessionSearchHit {
|
|
3
|
+
conversationId: string;
|
|
4
|
+
title: string;
|
|
5
|
+
messageId: string;
|
|
6
|
+
role: "user" | "assistant";
|
|
7
|
+
before: string;
|
|
8
|
+
match: string;
|
|
9
|
+
after: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SessionSearchResult {
|
|
12
|
+
hits: SessionSearchHit[];
|
|
13
|
+
truncated: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SESSION_SEARCH_LIMIT = 60;
|