@evandu/super-pi 0.1.274 → 0.1.276

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.
Files changed (52) hide show
  1. package/agents/super-pi-documents/index.ts +16 -1
  2. package/agents/super-pi-task/core.ts +1 -1
  3. package/bin/render-presentation.ps1 +35 -0
  4. package/desktop/main.cjs +16 -9
  5. package/desktop/notifications.cjs +2 -1
  6. package/desktop/relaunch.cjs +5 -2
  7. package/desktop/restart-handoff.cjs +35 -0
  8. package/desktop/shell-entries.cjs +14 -2
  9. package/dist/.super-pi-check-inputs.json +4 -0
  10. package/dist/client/.super-pi-client-sources.json +26 -19
  11. package/dist/client/assets/CodeMirrorEditor-WFfkDO6N.js +2 -0
  12. package/dist/client/assets/{GitDiffEditor-CpoDDQrA.css → GitDiffEditor-DOFVNrEW.css} +1 -1
  13. package/dist/client/assets/GitDiffEditor-PPULzRIU.js +29 -0
  14. package/dist/client/assets/index-BjauxoWZ.js +350 -0
  15. package/dist/client/assets/index-CnNljc5p.css +1 -0
  16. package/dist/client/index.html +2 -2
  17. package/dist/server/agents.d.ts +1 -1
  18. package/dist/server/agents.js +10 -3
  19. package/dist/server/application/document-service.d.ts +134 -0
  20. package/dist/server/application/document-service.js +9 -0
  21. package/dist/server/application/run-service.d.ts +1 -0
  22. package/dist/server/application/run-service.js +33 -7
  23. package/dist/server/http-server.js +32 -3
  24. package/dist/server/length-continuation.d.ts +2 -9
  25. package/dist/server/length-continuation.js +10 -10
  26. package/dist/server/pi-session-events.js +3 -1
  27. package/dist/server/presentations/brief.d.ts +49 -0
  28. package/dist/server/presentations/brief.js +132 -0
  29. package/dist/server/presentations/inspect.d.ts +15 -0
  30. package/dist/server/presentations/inspect.js +30 -0
  31. package/dist/server/presentations/native.d.ts +8 -0
  32. package/dist/server/presentations/native.js +33 -0
  33. package/dist/server/presentations/render.d.ts +16 -0
  34. package/dist/server/presentations/render.js +152 -0
  35. package/dist/server/presentations/service.d.ts +176 -0
  36. package/dist/server/presentations/service.js +155 -0
  37. package/dist/server/runtime.js +3 -2
  38. package/dist/server/turn-failure.d.ts +2 -0
  39. package/dist/server/turn-failure.js +15 -1
  40. package/dist/shared/message-source-link.d.ts +1 -0
  41. package/dist/shared/message-source-link.js +4 -0
  42. package/dist/shared/output-recovery.d.ts +4 -0
  43. package/dist/shared/output-recovery.js +6 -0
  44. package/dist/shared/workspace-file-preview.d.ts +1 -1
  45. package/dist/shared/workspace-file-preview.js +2 -0
  46. package/package.json +4 -1
  47. package/skills/presentation/SKILL.md +23 -1
  48. package/skills/presentation/references/spec.md +15 -0
  49. package/dist/client/assets/CodeMirrorEditor-DjMbNm7l.js +0 -2
  50. package/dist/client/assets/GitDiffEditor-Cwim9Ua1.js +0 -29
  51. package/dist/client/assets/index-BL9o4WZN.js +0 -350
  52. package/dist/client/assets/index-D1qJmoVY.css +0 -1
@@ -37,7 +37,9 @@ export function formatTurnFailure(error) {
37
37
  // PROVIDER QUOTA / RATE LIMIT - the only reason the user is in this branch is because Pi was
38
38
  // answering them a moment ago and now the model will not let it. The action is "wait or change
39
39
  // model"; the wording has to make that obvious from the banner alone, without a tooltip.
40
- if (/\b429\b|quota|rate limit|usage limit|too many requests|5-hour|5h|resource_exhausted|resourc exhaust|hit your limit|usage cap|usage restrict/.test(lower)) {
40
+ if (isProviderQuotaError(error)) {
41
+ if (/Token Plan.*用量上限|\(2056\)/i.test(raw))
42
+ return "模型额度已用完:供应商报告账户或套餐用量达到上限。请检查供应商控制台的用量,额度恢复后重试,或更换模型。";
41
43
  return "模型额度已用完(5 小时限额或类似上限),Pi 已停止回答。可以等待重置后重试,或在会话里换一个模型再发。";
42
44
  }
43
45
  // RPC CHANNEL DEAD - Pi died without producing a `settled` event. Anything in the turn is now
@@ -142,6 +144,8 @@ export class LengthExceededError extends Error {
142
144
  export function isLengthExceededError(error) {
143
145
  if (!error)
144
146
  return false;
147
+ if (isProviderQuotaError(error))
148
+ return false;
145
149
  if (error instanceof LengthExceededError)
146
150
  return true;
147
151
  if (error?.stopReason === "length")
@@ -149,6 +153,16 @@ export function isLengthExceededError(error) {
149
153
  const msg = error instanceof Error ? error.message : typeof error === "string" ? error : "";
150
154
  return msg.includes("模型输出达到本轮长度上限") || msg.includes("达到本轮长度上限") || msg.includes("单次输出达到长度上限");
151
155
  }
156
+ /** An explicit provider limit overrides a contradictory output-length marker. */
157
+ export function isProviderQuotaError(error) {
158
+ if (!error)
159
+ return false;
160
+ const record = error;
161
+ if (record.status === 429 || record.statusCode === 429)
162
+ return true;
163
+ const text = typeof error === "string" ? error : [record.message, record.errorMessage].filter(value => typeof value === "string").join("\n");
164
+ return /\b429\b|quota|rate[_ ]limit|usage limit|too many requests|5-hour|5h|resource_exhausted|resourc exhaust|hit your limit|usage cap|usage restrict|Token Plan.*(?:用量|上限)|用量上限|配额(?:耗尽|不足)|额度(?:已用完|耗尽|不足)|余额不足/i.test(text);
165
+ }
152
166
  export function controllerAborted(error) {
153
167
  if (!error)
154
168
  return false;
@@ -3,6 +3,7 @@ type Position = {
3
3
  path: string;
4
4
  line: number;
5
5
  column?: number;
6
+ artifact?: boolean;
6
7
  };
7
8
  export type SourceLinkScope = {
8
9
  root: string;
@@ -1,5 +1,9 @@
1
1
  export const SOURCE_LINK_GUIDANCE = "When referencing code locations, use Markdown links with paths relative to your working directory and a line fragment, such as [`function_name`](./src/example.cpp#L397). Do not prefix them with a localhost URL.";
2
2
  function position(value) {
3
+ // Managed presentations are artifacts, not code locations, but use the same scoped opener.
4
+ const artifact = sourcePath(value);
5
+ if (artifact && /\.pptx$/i.test(artifact))
6
+ return { path: value, line: 1, artifact: true };
3
7
  const marker = /#L([1-9]\d*)(?:C([1-9]\d*))?(?:-L?[1-9]\d*)?$/i.exec(value)
4
8
  ?? /:([1-9]\d*)(?::([1-9]\d*))?$/.exec(value);
5
9
  if (!marker || marker.index === 0)
@@ -0,0 +1,4 @@
1
+ export declare const LENGTH_CONTINUATION_ENVELOPE = "continue_output";
2
+ export declare const MANUAL_OUTPUT_RECOVERY_TEXT = "\u8BF7\u57FA\u4E8E\u4E0A\u9762\u7684\u8BF7\u6C42\u3001\u5DF2\u8F93\u51FA\u7684\u5185\u5BB9\u548C\u5DF2\u5B8C\u6210\u7684\u64CD\u4F5C\u7EE7\u7EED\u5B8C\u6210\u4EFB\u52A1\u3002\u4F18\u5148\u7ED9\u51FA\u7B80\u6D01\u7ED3\u8BBA\u6216\u6267\u884C\u5FC5\u8981\u7684\u5C0F\u6B65\u9AA4\uFF0C\u4E0D\u8981\u91CD\u590D\u5DF2\u6709\u5185\u5BB9\u6216\u5DF2\u6210\u529F\u7684\u5199\u5165\u3002";
3
+ /** Decode a system recovery order without displaying its transport envelope. */
4
+ export declare function outputRecoveryText(content: string): string | undefined;
@@ -0,0 +1,6 @@
1
+ export const LENGTH_CONTINUATION_ENVELOPE = "continue_output";
2
+ export const MANUAL_OUTPUT_RECOVERY_TEXT = "请基于上面的请求、已输出的内容和已完成的操作继续完成任务。优先给出简洁结论或执行必要的小步骤,不要重复已有内容或已成功的写入。";
3
+ /** Decode a system recovery order without displaying its transport envelope. */
4
+ export function outputRecoveryText(content) {
5
+ return /^\s*<continue_output>([\s\S]*?)<\/continue_output>\s*$/.exec(content)?.[1].trim();
6
+ }
@@ -1,4 +1,4 @@
1
- export type WorkspacePreviewKind = "image" | "pdf" | "audio" | "video" | "table" | "document" | "download";
1
+ export type WorkspacePreviewKind = "image" | "pdf" | "audio" | "video" | "table" | "document" | "presentation" | "download";
2
2
  export declare function workspaceFileExtension(path: string): string;
3
3
  export declare function workspaceFileMime(path: string): string | undefined;
4
4
  export declare function workspacePreviewKind(path: string): WorkspacePreviewKind | undefined;
@@ -24,5 +24,7 @@ export function workspacePreviewKind(path) {
24
24
  return "table";
25
25
  if (/\.docx$/i.test(path))
26
26
  return "document";
27
+ if (/\.pptx$/i.test(path))
28
+ return "presentation";
27
29
  return undefined;
28
30
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "superPi": {
4
4
  "managedDirectListener": true
5
5
  },
6
- "version": "0.1.274",
6
+ "version": "0.1.276",
7
7
  "description": "Web control plane and companion for Pi",
8
8
  "license": "MIT",
9
9
  "type": "module",
@@ -267,6 +267,7 @@
267
267
  "scripts/skills-discovery.test.mjs",
268
268
  "scripts/built-in-skills.test.mjs",
269
269
  "scripts/presentation-schema.test.mjs",
270
+ "scripts/presentation-tools.test.mjs",
270
271
  "scripts/session-state-icon.test.mjs",
271
272
  "scripts/provider-fetch-models.test.mjs",
272
273
  "scripts/shared-chrome.test.mjs",
@@ -443,6 +444,7 @@
443
444
  "scripts/ux-polish-browser.test.mjs",
444
445
  "scripts/prompt-templates-browser.test.mjs",
445
446
  "scripts/documents-browser.test.mjs",
447
+ "scripts/presentation-browser.test.mjs",
446
448
  "scripts/feishu-browser.test.mjs",
447
449
  "scripts/session-read-state-regression.test.mjs",
448
450
  "scripts/orchestrated-order-role-browser.test.mjs",
@@ -516,6 +518,7 @@
516
518
  },
517
519
  "optionalDependencies": {
518
520
  "@huggingface/transformers": "^4.3.1",
521
+ "@resvg/resvg-js": "^2.6.2",
519
522
  "cfb": "^1.2.2",
520
523
  "docx": "^9.14.0",
521
524
  "exceljs": "^4.4.0",
@@ -24,7 +24,29 @@ Treat a deck as a communication artifact, not a document split across slides. Pr
24
24
  - Read [references/data.md](references/data.md) for tables, quantitative claims, and chart selection.
25
25
  - Read [references/templates-and-editing.md](references/templates-and-editing.md) when a template or existing deck must be preserved or edited.
26
26
  - Read [references/quality.md](references/quality.md) before final validation and delivery.
27
+ - Read [references/spec.md](references/spec.md) only when a semantic brief cannot express the requested layout; it documents positioned JSON without needing a custom generator.
27
28
 
28
29
  ## Current tool boundary
29
30
 
30
- The legacy `document_write` PPT path accepts Markdown and produces a clean text-first deck. It cannot faithfully implement positioned elements, images, native charts, templates, object-level edits, or visual rendering. When those capabilities are absent, produce the strongest honest text-first deck possible and state the limitation; do not simulate visual completion in prose.
31
+ Use `presentation_create` for new decks. Submit one compact JSON brief (inline or a JSON file) with the content, data and notes. The platform handles reusable layouts, native editable charts/tables, PPTX output and all slide layout previews in one call. Do not write a Python/JS framework, COM wrapper, OOXML patcher, or per-slide checker for a normal deck. Use existing generic computation tools for calculations, not a new rendering program. Aim for a usable ten-slide draft in five to ten minutes; visual polish is a bounded second pass.
32
+
33
+ Example brief:
34
+ ```json
35
+ {"title":"试点评审","data":{"budget":2000},"slides":[
36
+ {"id":"intro","layout":"cover","title":"建议开展六周试点","subtitle":"工程与财务联合评审","notes":"说明本次需要批准的事项。"},
37
+ {"id":"benefit","layout":"chart","title":"三组试点均减少处理时间","chart":{"type":"column","categories":["A组","B组","C组"],"series":[{"name":"每周节省分钟","values":[30,42,36]}]},"notes":"口径为每人每周,样本不足以推断因果。"},
38
+ {"id":"decision","layout":"body","title":"批准预算 {{budget}} 元后开始试点","bullets":["明确负责人和退出条件","每周回顾收益与质量"],"notes":"预算来自统一数据绑定,修改时全稿更新。"}
39
+ ]}
40
+ ```
41
+
42
+ Layouts: cover/subtitle, body/bullets, comparison/columns (1–3), chart/chart, table/table (rectangular rows, first row header), timeline/steps (1–5), metrics/metrics (1–5). Each slide needs a stable ASCII id and title. Charts accept bar/column/line/area/pie/doughnut and numeric series matching categories. Supply sources and speaker notes. Keep slides short; put detail into notes. Platform diagnostics are estimates, not proof of typography fidelity. Imported templates, image elements and scatter charts are not supported by this first writer; state that limitation rather than silently dropping objects.
43
+
44
+ `presentation_create` already produces all PNG previews, ten-page contact sheets and diagnostics. On Windows the platform also tries its managed PowerPoint adapter when installed and not already in use; it preserves existing user presentations. It returns `verification: native-office` only after actual export. Otherwise it returns `layout-only` and a nativeReason. Other platforms currently use layout previews. Do not probe Office, inspect Super Pi source, or write a COM/rendering wrapper: the platform has already handled that decision. Missing native rendering is a reported limitation, not a reason to rebuild the deck with another framework. Requesting PNG previews does not require native rendering; describe the actual preview type honestly.
45
+
46
+ Use `presentation_render` once per ten-page contact sheet to SEE the cached image. Review the whole deck, then inspect full-size PNG paths only where needed. Fix flagged pages with small patches instead of rewriting everything. Do not generate a throwaway probe deck before the real deck. Distinguish structural checks, layout approximation and native rendering in delivery; do not claim checks beyond the returned verification. Engine installation/distribution and arbitrary-template fidelity remain future work.
47
+
48
+ The tool result's inspection reports actual OOXML slide/notes/chart/table/text/workbook counts, canvas size and relationship completeness. Reuse that evidence instead of writing a ZIP checker. It does not prove that your numbers match external source data; check those using your calculations. If PNG **or** PDF was requested, PNG already satisfies that request: do not add a PDF pipeline unless the user needs it. A content brief and data calculations are reproducible sources; they do not need a generation program. Keep new revisions at new paths even when the original was only a draft, and link the latest version. Never delete a managed draft merely to reuse its filename.
49
+
50
+ For a revision, use `presentation_read` to get the source and etag, then `presentation_edit` with a different outputPath and a compact patch: `{"data":{"budget":2500},"slides":{"benefit":{"chart":{"type":"bar","categories":["A组","B组","C组"],"series":[{"name":"每周节省分钟","values":[30,42,36]}]}}}}`. Slide field arrays are replaced entirely; existing fields otherwise stay. The original file is immutable. Do not rebuild it to compare versions. Identical retries reuse a verified artifact; conflicting targets require another filename.
51
+
52
+ Deliver a clickable Markdown link `[查看演示稿](relative/path.pptx)`; do not leave only backtick paths. PPTX opens in the main file tab with all page previews and notes; source JSON can be downloaded there. The legacy `document_write` Markdown PPT path remains a text-only fallback. Arbitrary imported PPTX can be read as text with `document_read` and downloaded; they do not have editable managed sources or automatic layout previews.
@@ -0,0 +1,15 @@
1
+ # Positioned specification (only when a brief cannot express the requested layout)
2
+
3
+ Prefer the compact semantic brief for normal decks. Do not inspect Super Pi source or build a generator to discover this contract. The same `presentation_create` brief/briefPath accepts the following JSON instead:
4
+
5
+ ```json
6
+ {"version":1,"metadata":{"title":"评审","author":"团队","language":"zh-CN"},"canvas":{"width":13.333,"height":7.5},"slides":[{"id":"page-1","title":"试点收益","notes":"模拟数据。","background":"F8FAFD","elements":[
7
+ {"id":"title-1","type":"text","x":0.7,"y":0.5,"width":12,"height":0.9,"text":"试点收益需要质量护栏","fontSize":28,"bold":true,"color":"233047"},
8
+ {"id":"chart-1","type":"chart","x":0.8,"y":1.6,"width":8,"height":4.8,"chart":"column","categories":["基线","试点"],"series":[{"name":"中位周期(小时)","values":[18,14.5]}],"showLegend":true,"showValues":true},
9
+ {"id":"caption-1","type":"text","x":9.3,"y":2,"width":3,"height":3,"text":"这是观察结果,不能推断因果。","fontSize":22,"color":"233047"}
10
+ ]}]}
11
+ ```
12
+
13
+ All dimensions are inches; fontSize is points. All frames must fit the canvas. IDs are unique across the deck, start with a letter, and contain only ASCII letters/digits/dot/underscore/hyphen. Colors are six-digit RGB, with optional leading #. Text fields: fontFamily, fontSize, color, bold, italic, align (left/center/right/justify), verticalAlign (top/middle/bottom). Shape fields: shape (rectangle/roundRectangle/ellipse/triangle/chevron), fill, stroke, strokeWidth. Line fields: stroke, strokeWidth. Table fields: rectangular rows (string/number/boolean/null) and headerRows. Chart fields as above, plus chart types bar/column/line/area/pie/doughnut. Null data values, scatter and images are not supported by the writer; do not silently replace them. Layout PNG approximates these shapes; native-office previews are actual PowerPoint output.
14
+
15
+ Semantic brief data bindings: strings can contain `{{budget.monthly}}`; objects/arrays can be shared as `{"$ref":"teamChart"}`. A chart/table reference resolves from the brief's data object before validation. Updating that data through presentation_edit updates every reference. References cannot execute code or access files. Patch slide fields by ID; positioned slides can replace their elements array as a unit. Preserve IDs of unchanged elements. Object-level insert/remove patches and arbitrary imported deck editing remain future work.
@@ -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-B3-a6uF0.js","assets/dist-CX_Hm4GS.js","assets/dist-Cus6_oaF.js","assets/dist-J6XWqRpB.js","assets/dist-scBkrwv-.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{c as t,d as n,l as r,n as i,s as a,t as o,u as s}from"./index-BL9o4WZN.js";var c=e(n(),1),l=s(),u=262144,d=131072;function f(e){return e.split(`.`).pop()?.toLowerCase()??``}function p(e){return getComputedStyle(document.documentElement).getPropertyValue(e).trim()}function m(e,t){return e.HighlightStyle.define([{tag:t.tags.keyword,color:p(`--cm-keyword`)},{tag:t.tags.string,color:p(`--cm-string`)},{tag:t.tags.number,color:p(`--cm-number`)},{tag:t.tags.comment,color:p(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:p(`--cm-function`)},{tag:t.tags.typeName,color:p(`--cm-type`)},{tag:t.tags.className,color:p(`--cm-type`)},{tag:t.tags.propertyName,color:p(`--cm-property`)},{tag:t.tags.operator,color:p(`--cm-operator`)},{tag:t.tags.variableName,color:p(`--cm-variable`)}])}function h({path:e,value:n,onChange:s,jumpToLine:p,onSave:h,workspaceId:g,blame:_,onPosition:v,readOnly:y=!1,languageOverride:b}){let x=(0,c.useRef)(null),S=(0,c.useRef)(null),C=(0,c.useRef)(void 0),w=(0,c.useRef)(null),T=(0,c.useRef)(null),E=(0,c.useRef)(null),D=(0,c.useRef)(null),O=(0,c.useRef)(null),k=(0,c.useRef)(null),A=(0,c.useRef)(s),j=(0,c.useRef)(h);A.current=s,j.current=h;let[M,N]=(0,c.useState)(!1),[P,F]=(0,c.useState)(!1),[I,L]=(0,c.useState)(`0,0`),[R,z]=(0,c.useState)(0);(0,c.useEffect)(()=>{let a=!1,o,s,c,l,d;return(async()=>{try{let p=b??f(e),h=t(p),[_,v,M,P,I,R,B,V]=await Promise.all([r(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([0,1])),r(()=>import(`./dist-B3-a6uF0.js`).then(e=>e.s),__vite__mapDeps([2,1,0])),r(()=>import(`./dist-CX_Hm4GS.js`),__vite__mapDeps([3,0,1,2,4,5])),r(()=>import(`./dist-scBkrwv-.js`),__vite__mapDeps([6,0,1,2])),r(()=>import(`./dist-J6XWqRpB.js`).then(e=>e.d),__vite__mapDeps([5,1,0,2,4])),r(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,1])),h?h().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${p}:`,e),null)):Promise.resolve(null),i().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null))]);if(a||!x.current)return;l=I,d=R,T.current=_.Annotation.define(),E.current=_.Transaction.addToHistory;let H=n.length<=u&&B!==null;s=new _.Compartment;let U=[v.lineNumbers(),v.highlightActiveLine(),v.drawSelection(),M.history(),v.keymap.of([M.indentWithTab,...M.defaultKeymap,...M.historyKeymap,...P.searchKeymap,{key:`Mod-s`,run:()=>(j.current(),!0)}]),v.EditorView.updateListener.of(e=>{e.docChanged&&!(T.current&&e.transactions.some(e=>e.annotation(T.current)===!0))&&A.current(e.state.doc.toString()),e.selectionSet&&L(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),v.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(y&&U.push(_.EditorState.readOnly.of(!0),v.EditorView.editable.of(!1)),V&&!y&&(c=new _.Compartment,U.splice(1,0,c.of([])),U.push(V.base)),B)try{U.push(B)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${p}:`,e),H=!1}if(H&&s&&l&&d)try{U.push(s.of(l.syntaxHighlighting(m(l,d))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${p}:`,e),H=!1}let W=C.current,G=W?.scope===JSON.stringify([g,e])&&W.state.doc.toString()===n,K=G?W.state.update({effects:_.StateEffect.reconfigure.of(U)}).state:_.EditorState.create({doc:n,extensions:U});if(o=new v.EditorView({state:K,parent:x.current}),G&&(o.scrollDOM.scrollTop=W.top,o.scrollDOM.scrollLeft=W.left),a){o.destroy();return}S.current=o,N(H),F(!0),D.current=V,O.current=c??null,k.current=null,z(e=>e+1);let q=new MutationObserver(()=>{let e=S.current;if(e&&H&&s&&l&&d)try{e.dispatch({effects:s.reconfigure(l.syntaxHighlighting(m(l,d)))})}catch{}});w.current=q,q.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),a||F(!0)}})(),()=>{a=!0,w.current?.disconnect(),w.current=null,o&&(C.current={scope:JSON.stringify([g,e]),state:o.state,top:o.scrollDOM.scrollTop,left:o.scrollDOM.scrollLeft}),o?.destroy(),S.current=null,F(!1),x.current&&(x.current.textContent=``)}},[e,y,b]),(0,c.useEffect)(()=>{let e=S.current;if(!e)return;let t=e.state.doc.toString();t!==n&&e.dispatch({changes:{from:0,to:t.length,insert:n},annotations:T.current?T.current.of(!0):void 0})},[n]),(0,c.useEffect)(()=>{let e=S.current;if(!e||!p)return;let t=e.state.doc.line(Math.min(Math.max(1,p.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(p.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},scrollIntoView:!0}),e.focus()},[p,P]);let B=!!(_&&_.state===`ready`&&_.response&&_.path===e&&_.workspaceId===g);(0,c.useEffect)(()=>{let t=S.current,n=D.current,r=O.current;if(!t||!n||!r)return;let i=_&&_.state===`ready`&&_.response&&_.path===e&&_.workspaceId===g?_.response:null,a=i?o(i):null;k.current!==a&&(k.current=a,t.dispatch({effects:[n.setBlame.of(a),r.reconfigure(a?n.gutter:[])]}))},[_?.state,_?.response,_?.path,_?.workspaceId,e,g,R]);let V=S.current?.state.doc.toString()??n,H=V.length<=d?V:V.slice(0,d),U=b??f(e),W=a(U),G=S.current?.state,K=G?.selection.main.head,q=K===void 0?void 0:G?.doc.lineAt(K),J=q?.number,Y=K!==void 0&&q?K-q.from+1:void 0;return(0,c.useEffect)(()=>{P&&J!==void 0&&Y!==void 0&&v?.({line:J,column:Y,language:M&&W||`纯文本`,highlight:M?U:`plain`})},[P,J,Y,M,W,U,v]),(0,c.useEffect)(()=>()=>v?.(),[v]),(0,l.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":H,"data-file-content-truncated":V.length>d?`1`:`0`,"data-file-selection":I,"data-file-editor-ready":P?`1`:`0`,"data-file-blame-gutter":B?`1`:void 0,onMouseDown:()=>S.current?.focus(),children:[(0,l.jsx)(`div`,{className:`file-cm`,ref:x,"aria-label":`${y?`查看`:`编辑`} ${e}`}),(!P||!v)&&(0,l.jsxs)(`div`,{className:`file-editor-status`,children:[!P&&(0,l.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),P&&K!==void 0&&q&&(0,l.jsxs)(`span`,{children:[`第 `,q.number,` 行,第 `,K-q.from+1,` 列`]}),P&&!M&&(0,l.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),P&&M&&W&&(0,l.jsx)(`span`,{"data-file-highlight-status":U,children:W})]})]})}export{h as CodeMirrorEditor,m as themeHighlightStyle};