@evandu/super-pi 0.1.322 → 0.1.324
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/agents/super-pi-managed-model/index.ts +8 -1
- package/dist/.super-pi-check-inputs.json +2 -2
- package/dist/client/.super-pi-client-sources.json +24 -19
- package/dist/client/assets/CodeMirrorEditor-eVHUQY8Y.js +2 -0
- package/dist/client/assets/GitDiffEditor-Cebgkg-9.js +31 -0
- package/dist/client/assets/index-A2acEU1u.css +1 -0
- package/dist/client/assets/index-D9r6d2wH.js +363 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/group-chat-service.js +54 -4
- package/dist/server/application/provider-service.d.ts +2 -0
- package/dist/server/application/provider-service.js +28 -0
- package/dist/server/application/run-service.d.ts +2 -0
- package/dist/server/application/run-service.js +14 -2
- package/dist/server/file-review-threads.d.ts +5 -2
- package/dist/server/file-review-threads.js +83 -5
- package/dist/server/git.d.ts +7 -7
- package/dist/server/git.js +25 -8
- package/dist/server/group-primary-executor.js +9 -1
- package/dist/server/http-server.js +22 -10
- package/dist/server/managed-http.js +87 -18
- package/dist/server/managed-model-adapter.d.ts +8 -0
- package/dist/server/managed-model-adapter.js +46 -2
- package/dist/server/managed-model-gateway.d.ts +38 -0
- package/dist/server/managed-model-gateway.js +24 -3
- package/dist/server/managed-servers.d.ts +1 -0
- package/dist/server/managed-servers.js +15 -8
- package/dist/server/runtime.d.ts +1 -0
- package/dist/server/shared-model-catalog.d.ts +8 -0
- package/dist/server/shared-model-catalog.js +45 -0
- package/dist/server/store.d.ts +11 -1
- package/dist/server/store.js +85 -1
- package/dist/server/types.d.ts +9 -0
- package/dist/server/ws-server.d.ts +2 -2
- package/dist/server/ws-server.js +19 -5
- package/dist/shared/file-review.d.ts +39 -0
- package/dist/shared/file-review.js +14 -0
- package/dist/shared/group-chat.d.ts +2 -0
- package/dist/shared/managed-servers.d.ts +1 -0
- package/dist/shared/model-configuration.d.ts +12 -0
- package/dist/shared/model-configuration.js +3 -0
- package/dist/shared/request-timing.d.ts +8 -0
- package/dist/shared/request-timing.js +1 -0
- package/package.json +2 -1
- package/dist/client/assets/CodeMirrorEditor-BsMtOxUG.js +0 -2
- package/dist/client/assets/GitDiffEditor-L_OuYDQ2.js +0 -29
- package/dist/client/assets/index-Cvx8i65V.css +0 -1
- package/dist/client/assets/index-DeMK1efe.js +0 -358
package/dist/server/types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type ModelFilterRule = {
|
|
|
7
7
|
import type { WorkflowRun } from "./workflow.js";
|
|
8
8
|
import type { BackgroundTaskDetails } from "../shared/background-task.js";
|
|
9
9
|
import type { GroupActivityUpdate } from "../shared/group-chat.js";
|
|
10
|
+
import type { RequestTiming } from "../shared/request-timing.js";
|
|
10
11
|
import type { ScheduledTask } from "./scheduled-tasks.js";
|
|
11
12
|
import type { ThinkingLevelMap } from "../shared/thinking-levels.js";
|
|
12
13
|
import type { ConversationCompaction } from "../shared/context-compaction.js";
|
|
@@ -114,6 +115,9 @@ export type ToolCallQuestion = {
|
|
|
114
115
|
answers?: QuestionAnswer[];
|
|
115
116
|
};
|
|
116
117
|
export type Message = {
|
|
118
|
+
requestTiming?: RequestTiming;
|
|
119
|
+
timingRequestIds?: string[];
|
|
120
|
+
timingReplyEnded?: boolean;
|
|
117
121
|
actualModel?: ModelSelection;
|
|
118
122
|
backgroundBatch?: Pick<Message, "id" | "content" | "createdAt" | "backgroundTask">[];
|
|
119
123
|
batchedInto?: string;
|
|
@@ -1737,6 +1741,7 @@ export type ClientCommandBody =
|
|
|
1737
1741
|
} | {
|
|
1738
1742
|
type: "state.subscribe";
|
|
1739
1743
|
conversationId?: string;
|
|
1744
|
+
transcriptRevision?: string;
|
|
1740
1745
|
}
|
|
1741
1746
|
/** Asks for the agent catalog read from disk. Answered by `agent.catalog`. */
|
|
1742
1747
|
| {
|
|
@@ -2096,6 +2101,10 @@ export type ServerEvent = {
|
|
|
2096
2101
|
} | {
|
|
2097
2102
|
type: "state";
|
|
2098
2103
|
state: AppState;
|
|
2104
|
+
retainedTranscript?: {
|
|
2105
|
+
conversationId: string;
|
|
2106
|
+
revision: string;
|
|
2107
|
+
};
|
|
2099
2108
|
} | {
|
|
2100
2109
|
type: "message.delta";
|
|
2101
2110
|
conversationId: string;
|
|
@@ -74,8 +74,8 @@ export declare class WsBroadcaster implements EventBroadcaster {
|
|
|
74
74
|
conversationId?: string;
|
|
75
75
|
}): void;
|
|
76
76
|
unregister(socket: WebSocket): void;
|
|
77
|
-
subscribe(socket: WebSocket, conversationId?: string): void;
|
|
78
|
-
sendState(socket: WebSocket): void;
|
|
77
|
+
subscribe(socket: WebSocket, conversationId?: string, transcriptRevision?: string): void;
|
|
78
|
+
sendState(socket: WebSocket, transcriptRevision?: string): void;
|
|
79
79
|
private scheduleRuntimeReplay;
|
|
80
80
|
private clearRuntimeReplay;
|
|
81
81
|
subscribeFileIndex(socket: WebSocket, workspaceId?: string, cwd?: string): void;
|
package/dist/server/ws-server.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isBrowserAuthorized } from "./browser-access.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { WebSocket, WebSocketServer } from "ws";
|
|
3
4
|
import { remoteModelRelay } from "./managed-model-relay.js";
|
|
4
5
|
import { isAuthorized, isLoopbackAddress } from "./http-server.js";
|
|
@@ -110,14 +111,14 @@ export class WsBroadcaster {
|
|
|
110
111
|
this.fileIndexScopes.delete(socket);
|
|
111
112
|
this.sockets.delete(socket);
|
|
112
113
|
}
|
|
113
|
-
subscribe(socket, conversationId) {
|
|
114
|
+
subscribe(socket, conversationId, transcriptRevision) {
|
|
114
115
|
// Finish the old transcript before replacing it. A later delta then belongs to the new scope,
|
|
115
116
|
// and the authoritative snapshot reconstructs anything not streamed while it was unselected.
|
|
116
117
|
this.flushStreaming(socket);
|
|
117
118
|
this.scopes.set(socket, conversationId ? { conversationId } : {});
|
|
118
|
-
this.sendState(socket);
|
|
119
|
+
this.sendState(socket, transcriptRevision);
|
|
119
120
|
}
|
|
120
|
-
sendState(socket) {
|
|
121
|
+
sendState(socket, transcriptRevision) {
|
|
121
122
|
if (socket.readyState !== WebSocket.OPEN)
|
|
122
123
|
return;
|
|
123
124
|
if (socket.bufferedAmount > MAX_WS_BUFFERED_BYTES) {
|
|
@@ -133,7 +134,18 @@ export class WsBroadcaster {
|
|
|
133
134
|
if (!safeSend(socket, JSON.stringify(event)))
|
|
134
135
|
this.scheduleRuntimeReplay(socket);
|
|
135
136
|
}
|
|
136
|
-
|
|
137
|
+
let event = { type: "state", state };
|
|
138
|
+
if (transcriptRevision && scope?.conversationId) {
|
|
139
|
+
const selected = state.conversations.find(item => item.id === scope.conversationId && item.messagesLoaded === true && !item.archivedAt);
|
|
140
|
+
if (selected && createHash("sha256").update(JSON.stringify(selected.messages)).digest("hex") === transcriptRevision) {
|
|
141
|
+
event = {
|
|
142
|
+
type: "state",
|
|
143
|
+
state: { ...state, conversations: state.conversations.map(item => item === selected ? { ...item, messages: [] } : item) },
|
|
144
|
+
retainedTranscript: { conversationId: selected.id, revision: transcriptRevision },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (!safeSend(socket, JSON.stringify(event))) {
|
|
137
149
|
this.scheduleRuntimeReplay(socket);
|
|
138
150
|
}
|
|
139
151
|
}
|
|
@@ -579,7 +591,9 @@ export class WsServer {
|
|
|
579
591
|
safeSend(socket, JSON.stringify({ type: "error", message: "会话订阅标识必须是字符串。" }));
|
|
580
592
|
return;
|
|
581
593
|
}
|
|
582
|
-
|
|
594
|
+
const revision = typeof parsed.transcriptRevision === "string" && /^[a-f0-9]{64}$/.test(parsed.transcriptRevision)
|
|
595
|
+
? parsed.transcriptRevision : undefined;
|
|
596
|
+
this.broadcaster.subscribe(socket, parsed.conversationId, revision);
|
|
583
597
|
return;
|
|
584
598
|
}
|
|
585
599
|
// A send or selected queued turn is a streaming operation. It must leave the socket's command
|
|
@@ -5,6 +5,41 @@ export type ReviewLine = {
|
|
|
5
5
|
side: ReviewSide;
|
|
6
6
|
number: number;
|
|
7
7
|
};
|
|
8
|
+
export type ReviewVersion = {
|
|
9
|
+
kind: "commit" | "blob" | "content";
|
|
10
|
+
hash: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "missing" | "unknown";
|
|
13
|
+
};
|
|
14
|
+
export type ReviewVersions = {
|
|
15
|
+
before: ReviewVersion;
|
|
16
|
+
after: ReviewVersion;
|
|
17
|
+
};
|
|
18
|
+
export type ReviewDiffRef = ReviewVersions & {
|
|
19
|
+
id: string;
|
|
20
|
+
path: string;
|
|
21
|
+
previousPath?: string;
|
|
22
|
+
};
|
|
23
|
+
export type ReviewDiffContent = {
|
|
24
|
+
mode: "patch";
|
|
25
|
+
diff: string | null;
|
|
26
|
+
kind: "text" | "binary" | "untracked";
|
|
27
|
+
limited?: boolean;
|
|
28
|
+
versions: ReviewVersions;
|
|
29
|
+
} | {
|
|
30
|
+
mode: "text";
|
|
31
|
+
before: string | null;
|
|
32
|
+
after: string | null;
|
|
33
|
+
beforeUnknown?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type ReviewDiffInput = ReviewDiffContent & {
|
|
36
|
+
path: string;
|
|
37
|
+
previousPath?: string;
|
|
38
|
+
};
|
|
39
|
+
export type ReviewDiffReplay = {
|
|
40
|
+
ref: ReviewDiffRef;
|
|
41
|
+
content: ReviewDiffContent;
|
|
42
|
+
};
|
|
8
43
|
export type ReviewAnchor = {
|
|
9
44
|
side: ReviewSide;
|
|
10
45
|
start?: number;
|
|
@@ -39,7 +74,11 @@ export type ReviewThread = ReviewAnchor & {
|
|
|
39
74
|
createdAt: string;
|
|
40
75
|
resolvedAt?: string;
|
|
41
76
|
agentName?: string;
|
|
77
|
+
diffSnapshot?: ReviewDiffRef;
|
|
42
78
|
replies: ReviewReply[];
|
|
43
79
|
};
|
|
80
|
+
export declare function reviewContentHash(text: string): string;
|
|
81
|
+
export declare function reviewTextVersions(before: string | null, after: string | null, beforeUnknown?: boolean): ReviewVersions;
|
|
82
|
+
export declare function sameReviewVersions(a: ReviewVersions, b: ReviewVersions): boolean;
|
|
44
83
|
export declare function reviewExcerpt(lines: readonly string[]): string;
|
|
45
84
|
export declare function workspaceReviewPath(path: string, cwd?: string): string;
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
2
|
+
import { bytesToHex } from "@noble/hashes/utils";
|
|
1
3
|
export const FILE_REVIEW_DISCUSSION_TOOLS = ["review_list", "review_reply"];
|
|
2
4
|
export const FILE_REVIEW_TOOLS = [...FILE_REVIEW_DISCUSSION_TOOLS, "review_create"];
|
|
5
|
+
export function reviewContentHash(text) { return bytesToHex(sha256(text)); }
|
|
6
|
+
export function reviewTextVersions(before, after, beforeUnknown = false) {
|
|
7
|
+
const version = (text) => text === null ? { kind: "missing" } : { kind: "content", hash: reviewContentHash(text) };
|
|
8
|
+
return { before: beforeUnknown ? { kind: "unknown" } : version(before), after: version(after) };
|
|
9
|
+
}
|
|
10
|
+
export function sameReviewVersions(a, b) {
|
|
11
|
+
return ["before", "after"].every(side => {
|
|
12
|
+
const left = a[side], right = b[side];
|
|
13
|
+
return left.kind !== "unknown" && left.kind === right.kind
|
|
14
|
+
&& (!("hash" in left) || "hash" in right && left.hash === right.hash);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
3
17
|
export function reviewExcerpt(lines) {
|
|
4
18
|
const text = lines.join("\n");
|
|
5
19
|
return text.length > 3000 ? text.slice(0, 3000) + "\n[…摘录截断]" : text;
|
|
@@ -155,6 +155,7 @@ export type MeetingAgenda = {
|
|
|
155
155
|
todos: MeetingTodo[];
|
|
156
156
|
};
|
|
157
157
|
export type GroupUserPost = GroupPost & {
|
|
158
|
+
requestTiming?: import("./request-timing.js").RequestTiming;
|
|
158
159
|
role: "user";
|
|
159
160
|
memberIds: string[];
|
|
160
161
|
replyTo?: string;
|
|
@@ -173,6 +174,7 @@ export type GroupUserPost = GroupPost & {
|
|
|
173
174
|
};
|
|
174
175
|
export type GroupReply = GroupPost & {
|
|
175
176
|
executionConversationId?: string;
|
|
177
|
+
executionRequestId?: string;
|
|
176
178
|
role: "assistant";
|
|
177
179
|
memberId: string;
|
|
178
180
|
memberName?: string;
|
|
@@ -59,6 +59,7 @@ export interface ManagedServerProfile {
|
|
|
59
59
|
ssh: "offline" | "connecting" | "online" | "needsTrust" | "awaitingVerification";
|
|
60
60
|
service: "unknown" | "offline" | "online";
|
|
61
61
|
modelChannel: "offline" | "online";
|
|
62
|
+
modelMode?: import("./model-configuration.js").ModelConfigurationMode;
|
|
62
63
|
modelTransport?: "direct";
|
|
63
64
|
modelChannelPaused?: boolean;
|
|
64
65
|
phase: "idle" | "connecting" | "needsTrust" | "awaitingVerification" | "deploying" | "ready" | "failed";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ModelConfigurationMode = "independent" | "shared-catalog" | "unified";
|
|
2
|
+
export declare function isModelConfigurationMode(value: unknown): value is ModelConfigurationMode;
|
|
3
|
+
export interface ModelConfigurationStatus {
|
|
4
|
+
paired: boolean;
|
|
5
|
+
mode: ModelConfigurationMode;
|
|
6
|
+
syncedAt?: string;
|
|
7
|
+
skippedModels?: number;
|
|
8
|
+
providers: {
|
|
9
|
+
id: string;
|
|
10
|
+
modelCount: number;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type RequestOutcome = "completed" | "failed" | "stopped" | "incomplete" | "interrupted";
|
|
2
|
+
/** Lifecycle timestamps recorded by the backend. The enclosing message owns the accepted timestamp. */
|
|
3
|
+
export type RequestTiming = {
|
|
4
|
+
startedAt?: string;
|
|
5
|
+
responseEndedAt?: string;
|
|
6
|
+
endedAt?: string;
|
|
7
|
+
outcome?: RequestOutcome;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"superPi": {
|
|
4
4
|
"managedDirectListener": true
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.324",
|
|
7
7
|
"description": "Web control plane and companion for Pi",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"type": "module",
|
|
@@ -516,6 +516,7 @@
|
|
|
516
516
|
"@electron/get": "5.1.0",
|
|
517
517
|
"@electron/packager": "20.3.0",
|
|
518
518
|
"@git-diff-view/react": "^0.1.8",
|
|
519
|
+
"@noble/hashes": "1.8.0",
|
|
519
520
|
"@types/diff": "^5.2.3",
|
|
520
521
|
"@xterm/addon-fit": "^0.11.0",
|
|
521
522
|
"@xterm/xterm": "^6.0.0",
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-D978o95T.js","assets/rolldown-runtime-XKyaHtl9.js","assets/dist-DTIPfQj7.js","assets/dist-S5ntGzJB.js","assets/dist-Cus6_oaF.js","assets/dist-DP4hrTBF.js","assets/dist-Qjm1p8SR.js","assets/dist-BJHpSQV1.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{C as t,S as n,T as r,c as i,d as a,i as o,l as s,o as c,r as l,s as u,u as d,w as f,x as p}from"./index-DeMK1efe.js";var m=e(r(),1);function ee(e,t,n,r){return[n.EditorView.decorations.compute([`selection`,`doc`],e=>n.Decoration.set(e.selection.ranges.filter(e=>!e.empty).map(e=>n.Decoration.mark({class:`cm-workbench-selectedText`}).range(e.from,e.to)),!0)),n.ViewPlugin.define(e=>{let n=null,i,a=!1,o=e=>{n&&(e===`expanded`?(a=!a,l()):n.querySelector(`input[name="${e===`caseSensitive`?`case`:e===`wholeWord`?`word`:`re`}"]`)?.click())},c=e=>{let t=s(e);t&&(e.preventDefault(),e.stopPropagation(),o(t))},l=()=>{if(!n||!i)return;let r=t.getSearchQuery(e.state);if(n.dataset.editorSearchExpanded=String(a),i.update({caseSensitive:r.caseSensitive,wholeWord:r.wholeWord,regexp:r.regexp,expanded:a}),n.querySelector(`[data-find-error]`)?.remove(),r.search&&!r.valid){let e=document.createElement(`output`);e.dataset.findError=``,e.setAttribute(`role`,`alert`),e.textContent=`正则表达式无效`,n.append(e)}},u=()=>{let s=r.querySelector(`.cm-panel.cm-search`);if(s===n)return;if(n?.removeEventListener(`keydown`,c,!0),i?.destroy(),n=s,!n){i=void 0;return}for(let[e,t,r]of[[`next`,`↓`,`下一处`],[`prev`,`↑`,`上一处`]]){let i=n.querySelector(`button[name="${e}"]`);i&&(i.textContent=t,i.setAttribute(`aria-label`,r),i.title=r)}let u=document.createElement(`span`);u.dataset.findControls=``,n.prepend(u);let f=t.getSearchQuery(e.state);a=!1,i=d(u,{...f,expanded:a},o),n.addEventListener(`keydown`,c,!0),l()},f=new MutationObserver(u);return f.observe(r,{childList:!0,subtree:!0}),u(),{update(){l()},destroy(){f.disconnect(),n?.removeEventListener(`keydown`,c,!0),i?.destroy()}}}),e.Prec.highest(n.keymap.of([{key:`Mod-Shift-l`,run:t.selectSelectionMatches},{key:`Mod-h`,scope:`editor search-panel`,run:e=>(t.searchPanelOpen(e.state)||t.openSearchPanel(e),requestAnimationFrame(()=>{e.dom.isConnected&&r.querySelector(`[data-editor-search-options][aria-expanded="false"]`)?.click()}),!0)},...[`c`,`w`,`r`].map(e=>({key:`Alt-${e}`,run:n=>{t.searchPanelOpen(n.state)||t.openSearchPanel(n);let r=t.getSearchQuery(n.state);return n.dispatch({effects:t.setSearchQuery.of(new t.SearchQuery({...r,...e===`c`?{caseSensitive:!r.caseSensitive}:e===`w`?{wholeWord:!r.wholeWord}:{regexp:!r.regexp}}))}),!0}}))])),n.panels({topContainer:r}),n.EditorView.scrollMargins.of(()=>({top:r.querySelector(`.cm-search`)?Math.min(r.getBoundingClientRect().height+8,Math.max(0,(r.parentElement?.clientHeight??0)-32)):0})),t.highlightSelectionMatches({wholeWords:!0,minSelectionLength:1,maxMatches:1e3}),t.search({top:!0}),e.EditorState.phrases.of({Find:`查找`,Replace:`替换为`,next:`下一处`,previous:`上一处`,all:`全部选中`,"match case":`区分大小写`,regexp:`正则表达式`,"by word":`全词匹配`,replace:`替换`,"replace all":`全部替换`,close:`关闭查找`,"current match":`当前匹配`,"on line":`所在行`})]}function te(e,t,n,r,a){let o=new e.Compartment,s=()=>{let r=c();return[e.EditorState.tabSize.of(r.tabSize),n.indentUnit.of(r.indent===`tabs`?` `:` `.repeat(r.tabSize)),r.wrap?t.EditorView.lineWrapping:[],r.whitespace?[t.highlightWhitespace(),t.highlightTrailingWhitespace()]:[]]};return[e.EditorState.allowMultipleSelections.of(!0),t.rectangularSelection(),t.crosshairCursor({key:`Alt`}),e.EditorState.phrases.of({"folded code":`已折叠代码`,unfold:`展开代码`,"Fold line":`折叠代码`,"Unfold line":`展开代码`}),t.highlightActiveLineGutter(),t.highlightSpecialChars(),t.dropCursor(),n.bracketMatching(),n.indentOnInput(),n.foldGutter(),r.closeBrackets(),e.Prec.highest(t.keymap.of([...r.closeBracketsKeymap,...n.foldKeymap,{key:`Alt-z`,run:()=>(u({wrap:!c().wrap}),!0)},{key:`Mod-Shift-z`,run:a.redo},{key:`Mod-y`,run:a.redo}])),o.of(s()),t.ViewPlugin.define(e=>({destroy:i(()=>{e.dispatch({effects:o.reconfigure(s())})})}))]}var h=new Map;function ne(e){let t=h.get(e);return t&&(h.delete(e),h.set(e,t)),t}function g(e,t){h.delete(e),h.set(e,t);let n=[...h.values()].reduce((e,t)=>e+t.state.doc.length,0);for(;h.size>32||n>16777216;){let e=h.keys().next().value;n-=h.get(e).state.doc.length,h.delete(e)}}var _=f(),re=262144,v=131072;function ie(e){return e.split(`.`).pop()?.toLowerCase()??``}function y(e,t,n=!1){let r=e=>n?`var(--git-diff-${e.slice(5)}, var(${e}))`:`var(${e})`;return e.HighlightStyle.define([{tag:t.tags.keyword,color:r(`--cm-keyword`)},{tag:t.tags.string,color:r(`--cm-string`)},{tag:t.tags.number,color:r(`--cm-number`)},{tag:t.tags.comment,color:r(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:r(`--cm-function`)},{tag:t.tags.typeName,color:r(`--cm-type`)},{tag:t.tags.className,color:r(`--cm-type`)},{tag:t.tags.propertyName,color:r(`--cm-property`)},{tag:t.tags.operator,color:r(`--cm-operator`)},{tag:t.tags.variableName,color:r(`--cm-variable`)}])}function b({path:e,value:r,onChange:i,jumpToLine:s,onSave:c,workspaceId:u,cwd:d=``,blame:f,onPosition:h,onView:b,readOnly:x=!1,languageOverride:S,onReviewLine:C}){let w=(0,m.useRef)(null),T=(0,m.useRef)(null),E=(0,m.useRef)(null),ae=(0,m.useRef)(null),D=JSON.stringify([u,d,e]),O=(0,m.useRef)(void 0),k=(0,m.useRef)(null),A=(0,m.useRef)(null),oe=(0,m.useRef)(null),j=(0,m.useRef)(null),M=(0,m.useRef)(null),N=(0,m.useRef)(null),P=(0,m.useRef)(i),F=(0,m.useRef)(c),I=(0,m.useRef)(r);I.current=r;let L=(0,m.useRef)(!1),R=(0,m.useRef)(b);R.current=b;let z=(0,m.useRef)(C);z.current=C;let B=!!C;P.current=i,F.current=c;let[V,se]=(0,m.useState)(!1),[H,U]=(0,m.useState)(!1),[W,ce]=(0,m.useState)(`0,0`),[G,le]=(0,m.useState)(0),[K,ue]=(0,m.useState)(1);(0,m.useEffect)(()=>{let i=!1,s,c,l,u,d;return(async()=>{try{let f=S??ie(e),p=n(f),[m,h,g,_,v,b,C,V,H]=await Promise.all([t(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([0,1])),t(()=>import(`./dist-DTIPfQj7.js`).then(e=>e.s),__vite__mapDeps([2,1,0])),t(()=>import(`./dist-S5ntGzJB.js`),__vite__mapDeps([3,0,1,2,4,5])),t(()=>import(`./dist-Qjm1p8SR.js`),__vite__mapDeps([6,0,1,2])),t(()=>import(`./dist-DP4hrTBF.js`).then(e=>e.d),__vite__mapDeps([5,1,0,2,4])),t(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,1])),p?p().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${f}:`,e),null)):Promise.resolve(null),o().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null)),t(()=>import(`./dist-BJHpSQV1.js`).then(e=>e.r),__vite__mapDeps([7,1,0,2,5,4]))]);if(i||!w.current||!T.current)return;ae.current=h.EditorView,u=v,d=b,A.current=m.Annotation.define(),oe.current=m.Transaction.addToHistory;let W=r.length<=re&&C!==null;c=new m.Compartment;let G=[h.lineNumbers(),h.highlightActiveLine(),h.drawSelection(),g.history(),h.keymap.of([g.indentWithTab,...g.defaultKeymap,...g.historyKeymap,..._.searchKeymap,{key:`Mod-s`,run:()=>(F.current(),!0)}]),h.EditorView.updateListener.of(e=>{e.docChanged&&!(A.current&&e.transactions.some(e=>e.annotation(A.current)===!0))&&P.current(e.state.doc.toString()),e.selectionSet&&ce(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),h.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(B&&G.push(a(h,e=>z.current?.(e),`file`)),G.push(h.EditorView.updateListener.of(e=>{e.selectionSet&&ue(e.state.selection.ranges.length),e.docChanged?L.current=!1:e.selectionSet&&(L.current=e.transactions.some(e=>e.isUserEvent(`select.search`)||e.isUserEvent(`select.pointer`)))}),ee(m,_,h,T.current),te(m,h,v,H,g)),x&&G.push(m.EditorState.readOnly.of(!0),h.EditorView.editable.of(!1),h.EditorView.contentAttributes.of({tabindex:`0`})),V&&!x&&(l=new m.Compartment,G.splice(1,0,l.of([])),G.push(V.base)),C)try{G.push(C)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${f}:`,e),W=!1}if(W&&c&&u&&d)try{G.push(c.of(u.syntaxHighlighting(y(u,d))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${f}:`,e),W=!1}let K=ne(D),q=K&&K.state.doc.toString()===I.current,J=q?K.state.update({effects:m.StateEffect.reconfigure.of(G)}).state:m.EditorState.create({doc:I.current,extensions:G});if(s=new h.EditorView({state:J,parent:w.current}),O.current=q?K.jump:void 0,ue(s.state.selection.ranges.length),ce(`${s.state.selection.main.from},${s.state.selection.main.to}`),q&&(s.scrollDOM.scrollTop=K.top,s.scrollDOM.scrollLeft=K.left,O.current=K.jump),i){s.destroy();return}E.current=s,R.current?.(s),se(W),U(!0),j.current=V,M.current=l??null,N.current=null,le(e=>e+1);let Y=new MutationObserver(()=>{let e=E.current;if(e&&W&&c&&u&&d)try{e.dispatch({effects:c.reconfigure(u.syntaxHighlighting(y(u,d)))})}catch{}});k.current=Y,Y.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),i||U(!0)}})(),()=>{i=!0,k.current?.disconnect(),k.current=null,s&&g(D,{state:s.state,top:s.scrollDOM.scrollTop,left:s.scrollDOM.scrollLeft,jump:O.current}),s?.destroy(),E.current=null,R.current?.(),U(!1),w.current&&(w.current.textContent=``)}},[D,x,S,B]),(0,m.useEffect)(()=>{let e=E.current;if(!e)return;let t=e.state.doc.toString();t!==r&&e.dispatch({changes:{from:0,to:t.length,insert:r},annotations:A.current?A.current.of(!0):void 0})},[r,H]),(0,m.useEffect)(()=>{let e=E.current;if(!e||!s||O.current===s.request)return;O.current=s.request;let t=e.state.doc.line(Math.min(Math.max(1,s.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(s.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},effects:ae.current?.scrollIntoView(n,{y:`start`,yMargin:Math.round(e.scrollDOM.clientHeight/3)})}),e.focus()},[s,H]);let q=!!(f&&f.state===`ready`&&f.response&&f.path===e&&f.workspaceId===u);(0,m.useEffect)(()=>{let t=E.current,n=j.current,r=M.current;if(!t||!n||!r)return;let i=f&&f.state===`ready`&&f.response&&f.path===e&&f.workspaceId===u?f.response:null,a=i?l(i):null;N.current!==a&&(N.current=a,t.dispatch({effects:[n.setBlame.of(a),r.reconfigure(a?n.gutter:[])]}))},[f?.state,f?.response,f?.path,f?.workspaceId,e,u,G]);let J=E.current?.state.doc.toString()??r,Y=J.length<=v?J:J.slice(0,v),X=S??ie(e),Z=p(X),de=E.current?.state,Q=de?.selection.main.head,$=Q===void 0?void 0:de?.doc.lineAt(Q),fe=$?.number,pe=Q!==void 0&&$?Q-$.from+1:void 0;return(0,m.useEffect)(()=>{let e=E.current;if(H&&e&&(!s||O.current===s.request)){let t=e.state.selection.main.head,n=e.state.doc.lineAt(t);h?.({line:n.number,column:t-n.from+1,language:V&&Z||`纯文本`,highlight:V?X:`plain`,navigation:L.current,selections:e.state.selection.ranges.length})}},[H,fe,pe,V,Z,X,h,K,s?.request]),(0,m.useEffect)(()=>()=>h?.(),[h]),(0,_.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":Y,"data-file-content-truncated":J.length>v?`1`:`0`,"data-file-selection":W,"data-editor-selection-count":K,"data-file-editor-ready":H?`1`:`0`,"data-file-blame-gutter":q?`1`:void 0,onMouseDown:e=>{e.target.closest(`.cm-panels`)||E.current?.focus()},children:[(0,_.jsx)(`div`,{className:`file-cm`,ref:w,"aria-label":`${x?`查看`:`编辑`} ${e}`}),(0,_.jsx)(`div`,{className:`workbench-editor-search`,ref:T,"data-editor-find-host":`file`}),(!H||!h)&&(0,_.jsxs)(`div`,{className:`file-editor-status`,children:[!H&&(0,_.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),H&&Q!==void 0&&$&&(0,_.jsxs)(`span`,{children:[`第 `,$.number,` 行,第 `,Q-$.from+1,` 列`]}),H&&!V&&(0,_.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),H&&V&&Z&&(0,_.jsx)(`span`,{"data-file-highlight-status":X,children:Z})]})]})}export{b as CodeMirrorEditor,ee as n,te as t,y as themeHighlightStyle};
|