@yugoo-design/dsh-design-studio-ui 0.2.8 → 0.3.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 +26 -9
- package/lib/index.d.ts +36 -20
- package/lib/index.js +131 -49
- package/licenses/dsh-distribution.json +53 -53
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Fragment, createContext, useCallback, useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
2
2
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
|
+
import { STUDIO_ARCHIVE_MAX_JSON_BYTES, STUDIO_SOURCE_MAX_BYTES } from "@yugoo-design/dsh-design-studio/types";
|
|
4
5
|
import { Unzip, UnzipInflate, unzipSync, zipSync } from "fflate";
|
|
5
6
|
//#region src/controller.ts
|
|
6
7
|
function state(value) {
|
|
@@ -736,7 +737,8 @@ ${CONVERSATION_ACTIVITY_CSS}
|
|
|
736
737
|
box-sizing:border-box;position:relative;display:flex;flex-direction:column;width:100%;height:100%;min-height:24rem;
|
|
737
738
|
background:var(--ds-background);color:var(--ds-text);
|
|
738
739
|
font-family:var(--ds-body-font);font-size:var(--ds-base-font-size);line-height:var(--ds-line-height)}
|
|
739
|
-
.ygd-studio-workspace *{box-sizing:border-box}
|
|
740
|
+
.ygd-studio-workspace *{box-sizing:border-box;scrollbar-width:thin;scrollbar-color:color-mix(in srgb,var(--ds-text-secondary) 55%,transparent) transparent}
|
|
741
|
+
.ygd-studio-workspace :hover,.ygd-studio-workspace :focus-visible{scrollbar-color:var(--ds-text-secondary) transparent}
|
|
740
742
|
.ygd-studio-workspace .ygd-studio-select{
|
|
741
743
|
--ds-bg-white:var(--ds-surface);--ds-fill-5:var(--ds-border);--ds-border-default:var(--ds-border);
|
|
742
744
|
--ds-text-primary:var(--ds-text);--ds-icon-outline-default:var(--ds-text-secondary);
|
|
@@ -866,7 +868,7 @@ button.ygd-studio-select>span:last-child{display:flex;flex:none;align-items:cent
|
|
|
866
868
|
.ygd-studio-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;
|
|
867
869
|
padding:var(--ds-space-6);text-align:center;color:var(--ds-text-secondary);font-size:14px}
|
|
868
870
|
|
|
869
|
-
.ygd-studio-mounts-editor{display:flex;flex:1;min-height:0;min-width:0;flex-direction:column;padding:
|
|
871
|
+
.ygd-studio-mounts-editor{display:flex;flex:1;min-height:0;min-width:0;flex-direction:column;padding:var(--ds-space-4) 20px;gap:12px;container-type:inline-size;container-name:studio-mounts}
|
|
870
872
|
.ygd-studio-mounts-columns{display:grid;grid-template-columns:minmax(240px,300px) minmax(0,1fr);gap:24px;flex:1;min-height:0;min-width:0}
|
|
871
873
|
.ygd-studio-mounts-column{display:flex;flex-direction:column;gap:12px;min-width:0;min-height:0}
|
|
872
874
|
.ygd-studio-mounts-heading{display:flex;align-items:center;gap:8px;min-height:32px}
|
|
@@ -1447,7 +1449,7 @@ function NoticeFeedback({ feedbackId, tone, title, message, details = [], action
|
|
|
1447
1449
|
restoreFocus.current = true;
|
|
1448
1450
|
setDismissed(void 0);
|
|
1449
1451
|
},
|
|
1450
|
-
children: zh ? "
|
|
1452
|
+
children: zh ? "查看提示" : "Show notice"
|
|
1451
1453
|
})]
|
|
1452
1454
|
});
|
|
1453
1455
|
const hasDetails = !!message || details.length > 0;
|
|
@@ -1469,7 +1471,7 @@ function NoticeFeedback({ feedbackId, tone, title, message, details = [], action
|
|
|
1469
1471
|
"aria-expanded": open,
|
|
1470
1472
|
"aria-controls": detailsId,
|
|
1471
1473
|
onClick: () => setExpanded(open ? void 0 : feedbackId),
|
|
1472
|
-
children: open ? zh ? "收起详情" : "Hide details" : zh ? "
|
|
1474
|
+
children: open ? zh ? "收起详情" : "Hide details" : zh ? "查看详情" : "View details"
|
|
1473
1475
|
}),
|
|
1474
1476
|
actions.map((action) => /* @__PURE__ */ jsx("button", {
|
|
1475
1477
|
type: "button",
|
|
@@ -1618,11 +1620,11 @@ function FileExplorer({ paths, selected, openFile, disabled = false }) {
|
|
|
1618
1620
|
const FILE_ROLES = {
|
|
1619
1621
|
"mindset.md": {
|
|
1620
1622
|
zh: "设计心智:描述领域设计方法、判断原则,以及如何选择和协同使用技能包。",
|
|
1621
|
-
en: "
|
|
1623
|
+
en: "Domain methods, decision criteria, and guidance for choosing and combining Bundles."
|
|
1622
1624
|
},
|
|
1623
1625
|
"kit.yaml": {
|
|
1624
1626
|
zh: "挂载清单:声明此设计套件引用的技能包及其顺序。",
|
|
1625
|
-
en: "
|
|
1627
|
+
en: "Lists the Bundles used by this Kit and their order."
|
|
1626
1628
|
},
|
|
1627
1629
|
"relations.yaml": {
|
|
1628
1630
|
zh: "关系词汇:定义此设计套件扩展的知识关联类型,不是项目设计内容。",
|
|
@@ -1630,7 +1632,7 @@ const FILE_ROLES = {
|
|
|
1630
1632
|
},
|
|
1631
1633
|
"SKILL.md": {
|
|
1632
1634
|
zh: "技能方法:描述适用场景、设计方法、证据要求与交付规范。",
|
|
1633
|
-
en: "
|
|
1635
|
+
en: "Explains when to use this Bundle, how to carry out the work, and what evidence and outputs to provide."
|
|
1634
1636
|
},
|
|
1635
1637
|
"skill.yaml": {
|
|
1636
1638
|
zh: "技能包声明:定义身份、展示名称、执行策略、面板模式及可选摘要规则。",
|
|
@@ -1662,7 +1664,7 @@ const FILE_ROLES = {
|
|
|
1662
1664
|
},
|
|
1663
1665
|
"reference/cooperation-guide.md": {
|
|
1664
1666
|
zh: "协作指南:说明与其他技能包需要对齐或补充的信息及事实边界。",
|
|
1665
|
-
en: "
|
|
1667
|
+
en: "Information to align or supplement across Bundles, including who owns each fact."
|
|
1666
1668
|
},
|
|
1667
1669
|
"reference/runtime-guide.md": {
|
|
1668
1670
|
zh: "运行指南:记录此技能包特有的执行、环境或工具使用要求。",
|
|
@@ -2955,7 +2957,11 @@ function MountEditorSession({ client, record, locale, onSaved, onActions, onDirt
|
|
|
2955
2957
|
}), /* @__PURE__ */ jsxs("div", {
|
|
2956
2958
|
className: "ygd-studio-mounts-card-list",
|
|
2957
2959
|
children: [[...selected].map((key) => {
|
|
2958
|
-
const
|
|
2960
|
+
const mounted = record.mounts.find((mount) => keyOf(mount.bundle) === key);
|
|
2961
|
+
const bundle = mounted?.display ? {
|
|
2962
|
+
...mounted.bundle,
|
|
2963
|
+
...mounted.display
|
|
2964
|
+
} : choices.get(key) ?? mounted?.bundle ?? {
|
|
2959
2965
|
name: key.split("@")[0],
|
|
2960
2966
|
version: key.split("@")[1]
|
|
2961
2967
|
};
|
|
@@ -3031,6 +3037,7 @@ function useSourceCandidate(options) {
|
|
|
3031
3037
|
const generation = useRef(0), callbacks = useRef(options);
|
|
3032
3038
|
callbacks.current = options;
|
|
3033
3039
|
const submitted = useRef(false), selected = useRef(), readOwner = useRef(client);
|
|
3040
|
+
const submittedRecord = useRef();
|
|
3034
3041
|
const isSaveSubmitted = useCallback(() => submitted.current, []);
|
|
3035
3042
|
const request = prepared?.request, candidate = prepared?.candidate;
|
|
3036
3043
|
const zh = options?.locale === "zh";
|
|
@@ -3044,6 +3051,7 @@ function useSourceCandidate(options) {
|
|
|
3044
3051
|
if (selected.current !== key) {
|
|
3045
3052
|
selected.current = key;
|
|
3046
3053
|
submitted.current = false;
|
|
3054
|
+
submittedRecord.current = void 0;
|
|
3047
3055
|
setSaved(false);
|
|
3048
3056
|
setSaveUnverified(false);
|
|
3049
3057
|
}
|
|
@@ -3085,6 +3093,7 @@ function useSourceCandidate(options) {
|
|
|
3085
3093
|
const current = generation.current;
|
|
3086
3094
|
const isCurrent = () => generation.current === current && callbacks.current?.client === client && currentKey() === key && callbacks.current?.instanceId === instanceId;
|
|
3087
3095
|
submitted.current = true;
|
|
3096
|
+
submittedRecord.current = currentRecord;
|
|
3088
3097
|
setBusy(true);
|
|
3089
3098
|
try {
|
|
3090
3099
|
const value = await client.saveChanges({
|
|
@@ -3108,6 +3117,62 @@ function useSourceCandidate(options) {
|
|
|
3108
3117
|
if (isCurrent()) setBusy(false);
|
|
3109
3118
|
}
|
|
3110
3119
|
};
|
|
3120
|
+
const verifySave = async () => {
|
|
3121
|
+
if (!saveUnverified || busy || !submitted.current || !request || !candidate || !client) return;
|
|
3122
|
+
const current = generation.current;
|
|
3123
|
+
const isCurrent = () => generation.current === current && callbacks.current?.client === client && currentKey() === key && callbacks.current?.instanceId === instanceId;
|
|
3124
|
+
setBusy(true);
|
|
3125
|
+
try {
|
|
3126
|
+
const value = await client.read({ id: request.id });
|
|
3127
|
+
if (!isCurrent()) return;
|
|
3128
|
+
if (value.id !== request.id || value.kind !== submittedRecord.current?.kind || value.deletedAt) throw Error(zh ? "无法核对当前副本,草稿已保留。" : "The current copy could not be verified. Your draft is retained.");
|
|
3129
|
+
if (value.revision === request.expectedRevision) {
|
|
3130
|
+
submitted.current = false;
|
|
3131
|
+
setSaveUnverified(false);
|
|
3132
|
+
setRecord(value);
|
|
3133
|
+
setError("");
|
|
3134
|
+
return;
|
|
3135
|
+
}
|
|
3136
|
+
let matchesSaved = value.revision === candidate.revision;
|
|
3137
|
+
if (matchesSaved && !value.files) throw Error(zh ? "未能读取已保存文件清单,草稿已保留。请重试核对。" : "The saved file list is unavailable. Your draft is retained. Retry verification.");
|
|
3138
|
+
if (matchesSaved) for (const change of request.changes) {
|
|
3139
|
+
const exists = value.files?.some((file) => file.path === change.path);
|
|
3140
|
+
if (change.content === null) {
|
|
3141
|
+
if (exists) matchesSaved = false;
|
|
3142
|
+
continue;
|
|
3143
|
+
}
|
|
3144
|
+
if (!exists) {
|
|
3145
|
+
matchesSaved = false;
|
|
3146
|
+
break;
|
|
3147
|
+
}
|
|
3148
|
+
const file = await client.readFile({
|
|
3149
|
+
id: request.id,
|
|
3150
|
+
path: change.path
|
|
3151
|
+
});
|
|
3152
|
+
if (!isCurrent()) return;
|
|
3153
|
+
if (file.id !== request.id || file.path !== change.path || file.revision !== value.revision || file.content !== change.content) {
|
|
3154
|
+
matchesSaved = false;
|
|
3155
|
+
break;
|
|
3156
|
+
}
|
|
3157
|
+
}
|
|
3158
|
+
if (!matchesSaved) {
|
|
3159
|
+
submitted.current = false;
|
|
3160
|
+
setSaveUnverified(false);
|
|
3161
|
+
setError(zh ? "已保存内容与这次修改不同,草稿已保留。请对比当前内容后重新准备修改。" : "The saved content differs from these changes. Your draft is retained. Compare the current content and prepare changes again.");
|
|
3162
|
+
return;
|
|
3163
|
+
}
|
|
3164
|
+
setRecord(value);
|
|
3165
|
+
setSaved(true);
|
|
3166
|
+
setSaveUnverified(false);
|
|
3167
|
+
setError("");
|
|
3168
|
+
callbacks.current?.onDirtyChange?.(false);
|
|
3169
|
+
callbacks.current?.onSaved(value);
|
|
3170
|
+
} catch (failure) {
|
|
3171
|
+
if (isCurrent()) setError(failure instanceof Error ? failure.message : String(failure));
|
|
3172
|
+
} finally {
|
|
3173
|
+
if (isCurrent()) setBusy(false);
|
|
3174
|
+
}
|
|
3175
|
+
};
|
|
3111
3176
|
return prepared ? {
|
|
3112
3177
|
prepared,
|
|
3113
3178
|
record: currentRecord,
|
|
@@ -3118,6 +3183,7 @@ function useSourceCandidate(options) {
|
|
|
3118
3183
|
matches,
|
|
3119
3184
|
canSave,
|
|
3120
3185
|
save,
|
|
3186
|
+
verifySave,
|
|
3121
3187
|
isSaveSubmitted
|
|
3122
3188
|
} : void 0;
|
|
3123
3189
|
}
|
|
@@ -3263,6 +3329,7 @@ function InstanceWorkbench({ client, id, locale, onBack, onChanged, onExport, re
|
|
|
3263
3329
|
const draftKey = draftRequest ? JSON.stringify(draftRequest) : void 0;
|
|
3264
3330
|
const draftClient = useMemo(() => client.saveChanges ? {
|
|
3265
3331
|
read: client.read.bind(client),
|
|
3332
|
+
readFile: client.readFile.bind(client),
|
|
3266
3333
|
saveChanges: client.saveChanges.bind(client)
|
|
3267
3334
|
} : void 0, [client]);
|
|
3268
3335
|
const currentPrepared = sourceDirty ? preparedDraft && preparedDraft.key === draftKey ? preparedDraft.prepared : void 0 : proposal;
|
|
@@ -3571,6 +3638,10 @@ function InstanceWorkbench({ client, id, locale, onBack, onChanged, onExport, re
|
|
|
3571
3638
|
if (mountActions.saveUnverified) mountActions.verifySave();
|
|
3572
3639
|
return;
|
|
3573
3640
|
}
|
|
3641
|
+
if (candidateState?.isSaveSubmitted()) {
|
|
3642
|
+
if (candidateState.saveUnverified) candidateState.verifySave();
|
|
3643
|
+
return;
|
|
3644
|
+
}
|
|
3574
3645
|
if (busy || candidateBusy || !discard()) return;
|
|
3575
3646
|
const current = generation.current;
|
|
3576
3647
|
mutate(async () => {
|
|
@@ -3658,7 +3729,7 @@ function InstanceWorkbench({ client, id, locale, onBack, onChanged, onExport, re
|
|
|
3658
3729
|
sourceDirty
|
|
3659
3730
|
]);
|
|
3660
3731
|
const file = record?.files?.find((entry) => entry.path === path);
|
|
3661
|
-
const exportDisabled = !record || record.id !== id ||
|
|
3732
|
+
const exportDisabled = !record || record.id !== id || busy || candidateBusy || candidateState?.saveUnverified || mountActions?.isSaveSubmitted();
|
|
3662
3733
|
const exportSaved = () => {
|
|
3663
3734
|
if (!exportDisabled && record) onExport?.(structuredClone(record));
|
|
3664
3735
|
};
|
|
@@ -3684,7 +3755,7 @@ function InstanceWorkbench({ client, id, locale, onBack, onChanged, onExport, re
|
|
|
3684
3755
|
if (candidatePending) dismissChanges();
|
|
3685
3756
|
};
|
|
3686
3757
|
const sourceStatus = candidateState?.saveUnverified ? zh ? "保存结果待确认" : "Save needs verification" : sourcePending ? zh ? `${draftRequest?.changes.length ?? proposal?.request.changes.length ?? 1} 个文件未保存` : `${draftRequest?.changes.length ?? proposal?.request.changes.length ?? 1} unsaved files` : zh ? "已保存" : "Saved";
|
|
3687
|
-
const exportDisabledReason = !exportDisabled ? void 0 : !record || record.id !== id ? zh ? "正在打开内容,请稍后再导出。" : "Wait for the content to open before exporting." : candidateState?.saveUnverified || mountActions?.saveUnverified ? zh ? "请先核对保存结果,再导出。" : "Verify the save result before exporting." :
|
|
3758
|
+
const exportDisabledReason = !exportDisabled ? void 0 : !record || record.id !== id ? zh ? "正在打开内容,请稍后再导出。" : "Wait for the content to open before exporting." : candidateState?.saveUnverified || mountActions?.saveUnverified ? zh ? "请先核对保存结果,再导出。" : "Verify the save result before exporting." : zh ? "请等待当前操作完成,再导出。" : "Wait for the current operation to finish before exporting.";
|
|
3688
3759
|
const editSource = (text) => {
|
|
3689
3760
|
if (sourceLocked || !loaded || readOnly || text === content) return;
|
|
3690
3761
|
++prepareRequest.current;
|
|
@@ -4492,7 +4563,7 @@ function ComponentLibrary({ library, locale }) {
|
|
|
4492
4563
|
className: "ygd-studio-component-content",
|
|
4493
4564
|
children: tab === "preview" && entry.panelYaml ? /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("div", {
|
|
4494
4565
|
className: `ygd-studio-component-preview ygd-studio-component-preview-${entry.previewLayout ?? "inline"}`,
|
|
4495
|
-
"aria-label": zh ? "固定样例预览" : "
|
|
4566
|
+
"aria-label": zh ? "固定样例预览" : "Component example",
|
|
4496
4567
|
children: /* @__PURE__ */ jsx("div", {
|
|
4497
4568
|
className: "ygd-studio-component-stage",
|
|
4498
4569
|
children: library.renderExample(entry.id, { locale })
|
|
@@ -4500,8 +4571,8 @@ function ComponentLibrary({ library, locale }) {
|
|
|
4500
4571
|
}, `${entry.id}:${locale}`) }) : tab === "preview" ? /* @__PURE__ */ jsxs("div", {
|
|
4501
4572
|
className: "ygd-studio-component-unavailable",
|
|
4502
4573
|
children: [
|
|
4503
|
-
/* @__PURE__ */ jsx("h3", { children: zh ? "需要完整工作区或宿主数据" : "
|
|
4504
|
-
/* @__PURE__ */ jsx("p", { children: zh ? "此组件已注册,但暂未提供独立交互样例。请查看声明与用法,通过同版本作者工具核对绑定。" : "This
|
|
4574
|
+
/* @__PURE__ */ jsx("h3", { children: zh ? "需要完整工作区或宿主数据" : "No standalone example yet" }),
|
|
4575
|
+
/* @__PURE__ */ jsx("p", { children: zh ? "此组件已注册,但暂未提供独立交互样例。请查看声明与用法,通过同版本作者工具核对绑定。" : "This component needs workspace or host data. Read its usage and check bindings with the authoring tool from the same installed version." }),
|
|
4505
4576
|
/* @__PURE__ */ jsx("button", {
|
|
4506
4577
|
className: "ygd-studio-btn-secondary",
|
|
4507
4578
|
type: "button",
|
|
@@ -4513,7 +4584,7 @@ function ComponentLibrary({ library, locale }) {
|
|
|
4513
4584
|
className: "ygd-studio-component-doc",
|
|
4514
4585
|
children: [
|
|
4515
4586
|
/* @__PURE__ */ jsx("p", { children: entry.description }),
|
|
4516
|
-
/* @__PURE__ */ jsx("p", { children: zh ? "用途和参数以已安装的同版本组件契约为准;下面的查询不运行模型、不创建项目。" : "Use the component contract from the same installed version.
|
|
4587
|
+
/* @__PURE__ */ jsx("p", { children: zh ? "用途和参数以已安装的同版本组件契约为准;下面的查询不运行模型、不创建项目。" : "Use the component contract from the same installed version. The query below reads its definition without running a model or creating a project." }),
|
|
4517
4588
|
/* @__PURE__ */ jsx("pre", { children: JSON.stringify({
|
|
4518
4589
|
name: entry.id,
|
|
4519
4590
|
reference: "contract"
|
|
@@ -4523,7 +4594,7 @@ function ComponentLibrary({ library, locale }) {
|
|
|
4523
4594
|
tabIndex: 0,
|
|
4524
4595
|
children: entry.panelYaml
|
|
4525
4596
|
})] }),
|
|
4526
|
-
/* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", { children: zh ? "组件扩展 Skill(可手动复制)" : "Component Extension Skill
|
|
4597
|
+
/* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", { children: zh ? "组件扩展 Skill(可手动复制)" : "Component Extension Skill" }), /* @__PURE__ */ jsx("pre", {
|
|
4527
4598
|
tabIndex: 0,
|
|
4528
4599
|
children: library.skillSource
|
|
4529
4600
|
})] })
|
|
@@ -4531,7 +4602,7 @@ function ComponentLibrary({ library, locale }) {
|
|
|
4531
4602
|
})
|
|
4532
4603
|
})
|
|
4533
4604
|
]
|
|
4534
|
-
}) : /* @__PURE__ */ jsx("p", { children: zh ? "该宿主没有提供组件目录。" : "This host
|
|
4605
|
+
}) : /* @__PURE__ */ jsx("p", { children: zh ? "该宿主没有提供组件目录。" : "This host does not provide a component catalog." })]
|
|
4535
4606
|
})]
|
|
4536
4607
|
});
|
|
4537
4608
|
}
|
|
@@ -4540,7 +4611,7 @@ function ComponentLibrary({ library, locale }) {
|
|
|
4540
4611
|
/** Browser transport only. Core still validates every original byte and definition. */
|
|
4541
4612
|
const MANIFEST = "studio-manifest.json";
|
|
4542
4613
|
const MAX_FILES = 4097;
|
|
4543
|
-
const MAX_BYTES
|
|
4614
|
+
const MAX_BYTES = STUDIO_ARCHIVE_MAX_JSON_BYTES;
|
|
4544
4615
|
const encoder = new TextEncoder();
|
|
4545
4616
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
4546
4617
|
function safeEntry(name) {
|
|
@@ -4613,14 +4684,18 @@ function verifyLocalEntries(bytes) {
|
|
|
4613
4684
|
}
|
|
4614
4685
|
/** Ordinary ZIP with readable source tree and a version/integrity manifest. */
|
|
4615
4686
|
function encodeStudioContentZip(source) {
|
|
4687
|
+
if (encoder.encode(source).byteLength > MAX_BYTES) throw Error("Archive JSON exceeds 64 MiB.");
|
|
4616
4688
|
const archive = JSON.parse(source);
|
|
4617
4689
|
if (archive.format !== "studio-content-archive/v1" || !Array.isArray(archive.files)) throw Error("Unsupported content archive.");
|
|
4618
4690
|
const entries = Object.create(null);
|
|
4691
|
+
let sourceBytes = 0;
|
|
4619
4692
|
const files = archive.files.map(({ base64, ...file }) => {
|
|
4620
4693
|
const name = `content/${file.path}`;
|
|
4621
4694
|
safeEntry(name);
|
|
4622
4695
|
if (entries[name]) throw Error("Duplicate ZIP file path.");
|
|
4623
4696
|
entries[name] = fromBase64(base64);
|
|
4697
|
+
sourceBytes += entries[name].byteLength;
|
|
4698
|
+
if (sourceBytes > STUDIO_SOURCE_MAX_BYTES) throw Error("ZIP source content exceeds 32 MiB.");
|
|
4624
4699
|
return file;
|
|
4625
4700
|
});
|
|
4626
4701
|
entries[MANIFEST] = encoder.encode(JSON.stringify({
|
|
@@ -4630,12 +4705,12 @@ function encodeStudioContentZip(source) {
|
|
|
4630
4705
|
files
|
|
4631
4706
|
}
|
|
4632
4707
|
}, null, 2));
|
|
4633
|
-
if (Object.keys(entries).length > MAX_FILES || Object.values(entries).reduce((sum, bytes) => sum + bytes.length, 0) > MAX_BYTES
|
|
4708
|
+
if (Object.keys(entries).length > MAX_FILES || Object.values(entries).reduce((sum, bytes) => sum + bytes.length, 0) > MAX_BYTES) throw Error("ZIP content exceeds the supported size or file count.");
|
|
4634
4709
|
return zipSync(entries, { level: 6 });
|
|
4635
4710
|
}
|
|
4636
4711
|
/** Bounded ZIP -> existing JSON transport; never extracts to a filesystem. */
|
|
4637
4712
|
function readStudioZipEntries(bytes) {
|
|
4638
|
-
if (bytes.length >
|
|
4713
|
+
if (bytes.length > MAX_BYTES) throw Error("ZIP file exceeds the 64 MiB transport limit.");
|
|
4639
4714
|
verifyLocalEntries(bytes);
|
|
4640
4715
|
const expected = /* @__PURE__ */ new Map(), names = /* @__PURE__ */ new Set();
|
|
4641
4716
|
let declared = 0;
|
|
@@ -4646,7 +4721,7 @@ function readStudioZipEntries(bytes) {
|
|
|
4646
4721
|
names.add(folded);
|
|
4647
4722
|
expected.set(file.name, file.originalSize);
|
|
4648
4723
|
declared += file.originalSize;
|
|
4649
|
-
if (expected.size > MAX_FILES || declared > MAX_BYTES
|
|
4724
|
+
if (expected.size > MAX_FILES || declared > MAX_BYTES) throw Error("ZIP content exceeds the supported size or file count.");
|
|
4650
4725
|
return false;
|
|
4651
4726
|
} });
|
|
4652
4727
|
const entries = /* @__PURE__ */ new Map(), started = /* @__PURE__ */ new Set();
|
|
@@ -4660,7 +4735,7 @@ function readStudioZipEntries(bytes) {
|
|
|
4660
4735
|
if (error) throw error;
|
|
4661
4736
|
length += data.length;
|
|
4662
4737
|
total += data.length;
|
|
4663
|
-
if (length > expected.get(file.name) || total > MAX_BYTES
|
|
4738
|
+
if (length > expected.get(file.name) || total > MAX_BYTES) {
|
|
4664
4739
|
file.terminate();
|
|
4665
4740
|
throw Error("ZIP expanded content exceeds its declared size.");
|
|
4666
4741
|
}
|
|
@@ -4690,6 +4765,7 @@ function decodeStudioContentZip(bytes) {
|
|
|
4690
4765
|
const manifest = JSON.parse(decoder.decode(entries.get(MANIFEST)));
|
|
4691
4766
|
if (manifest.format !== "studio-content-zip/v1" || !Array.isArray(manifest.archive?.files)) throw Error("Unsupported ZIP manifest.");
|
|
4692
4767
|
const used = /* @__PURE__ */ new Set([MANIFEST]);
|
|
4768
|
+
let sourceBytes = 0;
|
|
4693
4769
|
const files = manifest.archive.files.map((file) => {
|
|
4694
4770
|
if (typeof file.path !== "string" || Object.hasOwn(file, "base64")) throw Error("Invalid ZIP file manifest.");
|
|
4695
4771
|
const name = `content/${file.path}`;
|
|
@@ -4698,23 +4774,26 @@ function decodeStudioContentZip(bytes) {
|
|
|
4698
4774
|
if (!data || used.has(name)) throw Error(`Missing or duplicate ZIP content: ${file.path}`);
|
|
4699
4775
|
if (data.length !== file.bytes) throw Error(`ZIP file size mismatch: ${file.path}`);
|
|
4700
4776
|
used.add(name);
|
|
4777
|
+
sourceBytes += data.byteLength;
|
|
4778
|
+
if (sourceBytes > STUDIO_SOURCE_MAX_BYTES) throw Error("ZIP source content exceeds 32 MiB.");
|
|
4701
4779
|
return {
|
|
4702
4780
|
...file,
|
|
4703
4781
|
base64: toBase64(data)
|
|
4704
4782
|
};
|
|
4705
4783
|
});
|
|
4706
4784
|
if (used.size !== entries.size) throw Error("ZIP contains files that are not listed in its manifest.");
|
|
4707
|
-
|
|
4785
|
+
const source = JSON.stringify({
|
|
4708
4786
|
...manifest.archive,
|
|
4709
4787
|
files
|
|
4710
4788
|
});
|
|
4789
|
+
if (encoder.encode(source).byteLength > MAX_BYTES) throw Error("Archive JSON exceeds 64 MiB.");
|
|
4790
|
+
return source;
|
|
4711
4791
|
}
|
|
4712
4792
|
function isStudioZip(bytes) {
|
|
4713
4793
|
return bytes[0] === 80 && bytes[1] === 75;
|
|
4714
4794
|
}
|
|
4715
4795
|
//#endregion
|
|
4716
4796
|
//#region src/content-source-import.ts
|
|
4717
|
-
const MAX_BYTES = 12582912;
|
|
4718
4797
|
function base64(bytes) {
|
|
4719
4798
|
let value = "";
|
|
4720
4799
|
for (let index = 0; index < bytes.length; index += 8192) value += String.fromCharCode(...bytes.subarray(index, index + 8192));
|
|
@@ -4722,6 +4801,7 @@ function base64(bytes) {
|
|
|
4722
4801
|
}
|
|
4723
4802
|
function checkSources(input) {
|
|
4724
4803
|
const names = /* @__PURE__ */ new Set();
|
|
4804
|
+
let sourceBytes = 0;
|
|
4725
4805
|
for (const file of input.files) {
|
|
4726
4806
|
if (/[\\\u0000-\u001f:*?"<>|]/u.test(file.path) || file.path !== file.path.normalize("NFC") || file.path.split("/").some((part) => !part || [
|
|
4727
4807
|
".",
|
|
@@ -4735,11 +4815,13 @@ function checkSources(input) {
|
|
|
4735
4815
|
const key = file.path.toLowerCase();
|
|
4736
4816
|
if (names.has(key)) throw Error(`Duplicate or case-conflicting file path: ${file.path}`);
|
|
4737
4817
|
names.add(key);
|
|
4818
|
+
sourceBytes += file.base64.length / 4 * 3 - (file.base64.endsWith("==") ? 2 : file.base64.endsWith("=") ? 1 : 0);
|
|
4738
4819
|
}
|
|
4739
|
-
if (input.files.length > 4096 ||
|
|
4820
|
+
if (input.files.length > 4096 || sourceBytes > STUDIO_SOURCE_MAX_BYTES) throw Error("Import source exceeds 32 MiB or 4096 files. No content was truncated.");
|
|
4821
|
+
if (new TextEncoder().encode(JSON.stringify({
|
|
4740
4822
|
method: "studioInstanceImportSources",
|
|
4741
4823
|
params: input
|
|
4742
|
-
})).length >
|
|
4824
|
+
})).length > STUDIO_ARCHIVE_MAX_JSON_BYTES) throw Error("Import transport exceeds 64 MiB. No content was truncated.");
|
|
4743
4825
|
const required = input.kind === "bundle" ? ["SKILL.md"] : ["mindset.md", "kit.yaml"];
|
|
4744
4826
|
for (const path of required) if (!input.files.some((file) => file.path === path)) throw Error(`Missing required file: ${path}`);
|
|
4745
4827
|
return input;
|
|
@@ -4771,11 +4853,12 @@ function normalize(kind, files) {
|
|
|
4771
4853
|
}
|
|
4772
4854
|
async function readStudioImportFiles(kind, selected, readArchive) {
|
|
4773
4855
|
if (!selected.length) throw Error("No file selected.");
|
|
4774
|
-
if (selected.length > 4096 || selected.reduce((size, file) => size + file.size, 0) >
|
|
4856
|
+
if (selected.length > 4096 || selected.reduce((size, file) => size + file.size, 0) > STUDIO_ARCHIVE_MAX_JSON_BYTES) throw Error("Import transport exceeds 64 MiB or 4096 files.");
|
|
4775
4857
|
const loaded = await Promise.all(selected.map(async (file) => ({
|
|
4776
4858
|
path: file.webkitRelativePath || file.name,
|
|
4777
4859
|
bytes: file.arrayBuffer ? new Uint8Array(await file.arrayBuffer()) : new TextEncoder().encode(await file.text())
|
|
4778
4860
|
})));
|
|
4861
|
+
if (loaded.reduce((size, file) => size + file.bytes.byteLength, 0) > STUDIO_ARCHIVE_MAX_JSON_BYTES) throw Error("Import transport exceeds 64 MiB.");
|
|
4779
4862
|
if (loaded.length === 1 && !selected[0].webkitRelativePath) {
|
|
4780
4863
|
const { bytes, path } = loaded[0];
|
|
4781
4864
|
let archive;
|
|
@@ -4811,7 +4894,7 @@ async function readStudioImportFiles(kind, selected, readArchive) {
|
|
|
4811
4894
|
}
|
|
4812
4895
|
//#endregion
|
|
4813
4896
|
//#region src/content-transfer.ts
|
|
4814
|
-
const
|
|
4897
|
+
const ARCHIVE_BYTES = STUDIO_ARCHIVE_MAX_JSON_BYTES;
|
|
4815
4898
|
/** Presentation only: preserve the validator's detail without exposing its virtual root. */
|
|
4816
4899
|
function formatStudioImportError(error, locale) {
|
|
4817
4900
|
const lines = error.replaceAll("/studio-content-archive-virtual/", "").split("\n").map((line) => {
|
|
@@ -4822,18 +4905,15 @@ function formatStudioImportError(error, locale) {
|
|
|
4822
4905
|
}).join("\n");
|
|
4823
4906
|
return locale === "zh" ? `导入失败:${lines}\n请检查文件后重新导入。` : `Import failed: ${lines}\nCheck the file and import it again.`;
|
|
4824
4907
|
}
|
|
4825
|
-
/**
|
|
4908
|
+
/** Match the archive reader's content limit; host RPC envelopes are host-owned. */
|
|
4826
4909
|
function assertStudioImportRequestSize(source) {
|
|
4827
|
-
if (new TextEncoder().encode(JSON.
|
|
4828
|
-
method: "studioContentImport",
|
|
4829
|
-
params: { source }
|
|
4830
|
-
})).byteLength > HTTP_BYTES) throw Error("Archive request exceeds the 12 MiB HTTP limit. No content was truncated or sent.");
|
|
4910
|
+
if (new TextEncoder().encode(source).byteLength > ARCHIVE_BYTES) throw Error("Archive JSON exceeds 64 MiB. No content was truncated or sent.");
|
|
4831
4911
|
}
|
|
4832
4912
|
/** Download the exact saved content. Export never requests metadata from the user. */
|
|
4833
4913
|
function downloadStudioContent(source, filename) {
|
|
4834
4914
|
assertStudioImportRequestSize(source);
|
|
4835
4915
|
const zip = encodeStudioContentZip(source);
|
|
4836
|
-
if (zip.byteLength >
|
|
4916
|
+
if (zip.byteLength > ARCHIVE_BYTES) throw Error("ZIP exceeds the 64 MiB transport limit.");
|
|
4837
4917
|
const url = URL.createObjectURL(new Blob([zip], { type: "application/zip" }));
|
|
4838
4918
|
try {
|
|
4839
4919
|
const anchor = document.createElement("a");
|
|
@@ -4920,20 +5000,20 @@ const STRINGS = {
|
|
|
4920
5000
|
mountedBundlesLabel: "Mounted Bundles",
|
|
4921
5001
|
openWorkspace: "Open workspace",
|
|
4922
5002
|
openInBundleWorkspace: "Open in bundle workspace",
|
|
4923
|
-
mountedBy: (kits) => `Mounted
|
|
5003
|
+
mountedBy: (kits) => `Mounted in ${kits}`,
|
|
4924
5004
|
usedBy: (kits) => `Used by ${kits}`,
|
|
4925
5005
|
noMountedBy: "no installed Kits",
|
|
4926
5006
|
mountedInKits: "Mounted in Kits:",
|
|
4927
|
-
noKits: "No
|
|
4928
|
-
noBundles: "No
|
|
4929
|
-
noMounts: "This Kit
|
|
4930
|
-
noFiles: "
|
|
5007
|
+
noKits: "No Kits found.",
|
|
5008
|
+
noBundles: "No Bundles match your search.",
|
|
5009
|
+
noMounts: "This Kit has no mounted Bundles.",
|
|
5010
|
+
noFiles: "No readable files in this Bundle.",
|
|
4931
5011
|
resources: "Resources",
|
|
4932
|
-
resourcesNone: "
|
|
5012
|
+
resourcesNone: "None",
|
|
4933
5013
|
tabMindset: "Kit Files",
|
|
4934
5014
|
tabRelations: "KAG Relations",
|
|
4935
5015
|
tabMounts: "Bundles",
|
|
4936
|
-
noRelations: "This Kit
|
|
5016
|
+
noRelations: "This Kit uses the built-in relationship types without extensions.",
|
|
4937
5017
|
sourceFiles: "Source Files",
|
|
4938
5018
|
richToggle: "Read",
|
|
4939
5019
|
sourceToggle: "Source",
|
|
@@ -4944,11 +5024,11 @@ const STRINGS = {
|
|
|
4944
5024
|
requiredWord: "required",
|
|
4945
5025
|
optionalWord: "optional",
|
|
4946
5026
|
validationSummaryTitle: "Validation Summary",
|
|
4947
|
-
validationRules: (rules, drivers) => `${rules} ${rules === 1 ? "rule" : "rules"} ·
|
|
4948
|
-
driversNone: "
|
|
5027
|
+
validationRules: (rules, drivers) => `${rules} ${rules === 1 ? "rule" : "rules"} · Drivers: ${drivers}`,
|
|
5028
|
+
driversNone: "None",
|
|
4949
5029
|
panelProviderOwned: "provider-owned",
|
|
4950
5030
|
panelDeclarative: "declarative",
|
|
4951
|
-
panelReadonly: "
|
|
5031
|
+
panelReadonly: "read-only",
|
|
4952
5032
|
requestFailed: "Request failed",
|
|
4953
5033
|
loading: "Loading…"
|
|
4954
5034
|
},
|
|
@@ -5041,12 +5121,13 @@ function StudioDialog({ title, children, close, busy = false }) {
|
|
|
5041
5121
|
});
|
|
5042
5122
|
}
|
|
5043
5123
|
/** Installed content is a reading surface; edits use the same current-content editor. */
|
|
5044
|
-
function InstalledPreview({ authoring, client, kit, bundle, locale, declarative, onEdit }) {
|
|
5124
|
+
function InstalledPreview({ authoring, renderPreview: render, client, kit, bundle, locale, declarative, onEdit }) {
|
|
5045
5125
|
const [result, setResult] = useState();
|
|
5046
5126
|
const [busy, setBusy] = useState(false), [error, setError] = useState("");
|
|
5047
5127
|
const [sourceError, setSourceError] = useState(""), [panelSource, setPanelSource] = useState();
|
|
5048
5128
|
const [retry, setRetry] = useState(0);
|
|
5049
|
-
const
|
|
5129
|
+
const renderPreview = render ?? authoring?.renderPreview;
|
|
5130
|
+
const previewInstalled = renderPreview ? client.previewInstalled ?? authoring?.client.previewInstalled : void 0;
|
|
5050
5131
|
useEffect(() => {
|
|
5051
5132
|
let active = true;
|
|
5052
5133
|
setResult(void 0);
|
|
@@ -5157,8 +5238,8 @@ function InstalledPreview({ authoring, client, kit, bundle, locale, declarative,
|
|
|
5157
5238
|
title: locale === "zh" ? "面板预览未能生成" : "Panel preview could not be generated",
|
|
5158
5239
|
details: result.diagnostics.map((item) => ({ message: item.message }))
|
|
5159
5240
|
})),
|
|
5160
|
-
result?.preview &&
|
|
5161
|
-
readOnly:
|
|
5241
|
+
result?.preview && renderPreview?.(result.preview, () => {}, {
|
|
5242
|
+
readOnly: true,
|
|
5162
5243
|
toolbarTarget: null
|
|
5163
5244
|
})
|
|
5164
5245
|
]
|
|
@@ -5333,7 +5414,7 @@ function StudioWorkspace({ client, controller: supplied, authoring, renderPrevie
|
|
|
5333
5414
|
}
|
|
5334
5415
|
};
|
|
5335
5416
|
const exportInstance = (record) => {
|
|
5336
|
-
if (!contentClient || record.deletedAt
|
|
5417
|
+
if (!contentClient || record.deletedAt) return;
|
|
5337
5418
|
exportContent({
|
|
5338
5419
|
id: record.id,
|
|
5339
5420
|
expectedRevision: record.revision
|
|
@@ -6029,6 +6110,7 @@ function StudioWorkspace({ client, controller: supplied, authoring, renderPrevie
|
|
|
6029
6110
|
children: /* @__PURE__ */ jsx(InstalledPreview, {
|
|
6030
6111
|
client,
|
|
6031
6112
|
authoring,
|
|
6113
|
+
renderPreview,
|
|
6032
6114
|
onEdit: instances?.editCurrent ? () => {
|
|
6033
6115
|
editInstalled("bundle", bundleWorkspace);
|
|
6034
6116
|
} : void 0,
|