@michengai/dsh-im-connect 0.1.12 → 0.1.14
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.en.md +2 -1
- package/README.md +2 -1
- package/client.js +60 -87
- package/lib/client.js +60 -87
- package/lib/engine/assistant-settings.d.ts +2 -4
- package/lib/engine/assistant-settings.d.ts.map +1 -1
- package/lib/engine/assistant-settings.js +8 -8
- package/lib/engine/assistant-settings.js.map +1 -1
- package/lib/engine/gateway.d.ts +1 -1
- package/lib/engine/gateway.d.ts.map +1 -1
- package/lib/engine/gateway.js.map +1 -1
- package/lib/engine/router.d.ts +4 -0
- package/lib/engine/router.d.ts.map +1 -1
- package/lib/engine/router.js +4 -3
- package/lib/engine/router.js.map +1 -1
- package/lib/engine/types.d.ts +1 -1
- package/lib/engine/types.d.ts.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/lib/manager.d.ts +7 -0
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +19 -4
- package/lib/manager.js.map +1 -1
- package/package.json +2 -1
- package/src/engine/assistant-settings.ts +7 -9
- package/src/engine/gateway.ts +1 -1
- package/src/engine/router.ts +8 -3
- package/src/engine/types.ts +1 -1
- package/src/index.ts +3 -3
- package/src/manager.ts +45 -16
- package/src/optional-modules.d.ts +0 -3
package/README.en.md
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
[](LICENSE)
|
|
14
14
|
[](https://www.npmjs.com/package/@michengai/dsh-im-connect)
|
|
15
|
+
[](https://www.npmjs.com/package/@michengai/dsh-im-connect)
|
|
15
16
|
[](https://github.com/MichengAI/dsh-im-connect)
|
|
16
17
|
[](https://nodejs.org/)
|
|
17
18
|
[](#-supported-channels)
|
|
@@ -213,7 +214,7 @@ DingTalk replies prefer official AI Card streaming and fall back to plain text.
|
|
|
213
214
|
| WeChat protocol | Official iLink only; no reverse-engineered personal WeChat protocol |
|
|
214
215
|
| Tool approval | Only an allowlisted user in a DM can grant or deny; group chats cannot approve |
|
|
215
216
|
|
|
216
|
-
Do not expose DSH Web beyond this machine. Permission presets
|
|
217
|
+
Do not expose DSH Web beyond this machine. Permission presets use the same host sandbox-policy values as Chat; `danger-full-access` does not wrap a sandbox.
|
|
217
218
|
|
|
218
219
|
## Secondary development
|
|
219
220
|
|
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
[](LICENSE)
|
|
14
14
|
[](https://www.npmjs.com/package/@michengai/dsh-im-connect)
|
|
15
|
+
[](https://www.npmjs.com/package/@michengai/dsh-im-connect)
|
|
15
16
|
[](https://github.com/MichengAI/dsh-im-connect)
|
|
16
17
|
[](https://nodejs.org/)
|
|
17
18
|
[](#-支持的渠道)
|
|
@@ -213,7 +214,7 @@ dsh --profile web --dump-config
|
|
|
213
214
|
| 微信协议 | 只走腾讯官方 iLink,不使用逆向个人微信协议 |
|
|
214
215
|
| 工具批准 | 仅私聊且发送者已在白名单时生效,不能跨会话、也不能在群里批准 |
|
|
215
216
|
|
|
216
|
-
不要把 DSH Web
|
|
217
|
+
不要把 DSH Web 暴露到非本机地址。权限预设与 Chat 使用相同的 Host sandbox-policy;`danger-full-access` 不套沙箱。
|
|
217
218
|
|
|
218
219
|
## 二次开发
|
|
219
220
|
|
package/client.js
CHANGED
|
@@ -10,7 +10,7 @@ window.__ModuleLoader__.load({
|
|
|
10
10
|
const { useState, useEffect, useLayoutEffect, useCallback, useRef, useSyncExternalStore } = React;
|
|
11
11
|
const ReactDOM = require("react-dom");
|
|
12
12
|
const EMPTY_EXTRA_TABS = [];
|
|
13
|
-
const inject = ["slots", "sessions", "workspaces"];
|
|
13
|
+
const inject = ["slots", "sessions", "workspaces", "locale"];
|
|
14
14
|
const API_BASE = "/dsh-im-connect/api";
|
|
15
15
|
const TAB_KEY = "dsh-im-connect.sidebar-tab";
|
|
16
16
|
const h = React.createElement;
|
|
@@ -129,7 +129,7 @@ window.__ModuleLoader__.load({
|
|
|
129
129
|
.ima-radio small{display:block;color:var(--ima-muted);margin-top:2px}
|
|
130
130
|
.ima-ok{color:var(--ima-ok);font-size:14px;text-align:center;padding:24px 0}
|
|
131
131
|
.ima-modal .ima-error{color:var(--ima-danger)}
|
|
132
|
-
.ima-risk-warning{display:flex;gap:10px;align-items:flex-start;margin:0 0 16px;color:var(--ima-muted);font-size:14px;line-height:1.6}.ima-risk-warning b{display:grid;place-items:center;width:18px;height:18px;flex:none;border:1.5px solid var(--ima-danger);border-radius:50%;color:var(--ima-danger);font-size:12px;line-height:1}.ima-risk-warning p{margin:0}.ima-risk-check{display:flex;gap:8px;align-items:center;font-size:14px;cursor:pointer}.ima-risk-check input{width:16px;height:16px;margin:0;accent-color:var(--ima-accent)}.ima-risk-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:24px}.ima-risk-actions .ima-btn{border-radius:999px}.ima-risk-actions .ima-btn.primary:disabled{opacity:.48;cursor:not-allowed}
|
|
132
|
+
.ima-risk-warning{display:flex;gap:10px;align-items:flex-start;margin:0 0 16px;color:var(--ima-muted);font-size:14px;line-height:1.6}.ima-risk-warning b{display:grid;place-items:center;width:18px;height:18px;flex:none;border:1.5px solid var(--ima-danger);border-radius:50%;color:var(--ima-danger);font-size:12px;line-height:1}.ima-risk-warning p{margin:0}.ima-risk-check{display:flex;gap:8px;align-items:center;font-size:14px;cursor:pointer}.ima-risk-check input{width:16px;height:16px;margin:0;accent-color:var(--ima-accent)}.ima-risk-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:24px}.ima-risk-actions .ima-btn{border-radius:999px}.ima-risk-actions .ima-btn.primary:disabled{opacity:.48;cursor:not-allowed}.ima-full-access-dialog{margin:auto}.ima-full-access-dialog::backdrop{background:var(--dsw-alias-bg-mask-1,rgba(0,0,0,.45));backdrop-filter:var(--dsw-mask-blur,blur(8px))}
|
|
133
133
|
@media (prefers-reduced-motion:reduce){.ima-switch i{transition:none}}
|
|
134
134
|
`;
|
|
135
135
|
|
|
@@ -455,12 +455,17 @@ window.__ModuleLoader__.load({
|
|
|
455
455
|
);
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
+
const BUILT_IN_PERMISSION_LABELS = new Map([
|
|
459
|
+
["read-only", ["preset.readOnly", "Read Only"]],
|
|
460
|
+
["workspace-write", ["preset.workspaceWrite", "Workspace Write"]],
|
|
461
|
+
["danger-full-access", ["preset.fullAccess", "Full access"]],
|
|
462
|
+
]);
|
|
458
463
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
+
function permissionLabel(option, t) {
|
|
465
|
+
const builtIn = BUILT_IN_PERMISSION_LABELS.get(option.value);
|
|
466
|
+
if (builtIn && (option.name === option.value || option.name === builtIn[1])) return t(builtIn[0]);
|
|
467
|
+
return option.name || option.value;
|
|
468
|
+
}
|
|
464
469
|
const DEFAULT_EFFORTS = [
|
|
465
470
|
{ id: "low", name: "Low" },
|
|
466
471
|
{ id: "medium", name: "Medium" },
|
|
@@ -511,7 +516,7 @@ window.__ModuleLoader__.load({
|
|
|
511
516
|
props.suffix && h("span", { className: "ima-chip-effort" }, props.suffix),
|
|
512
517
|
h("em"),
|
|
513
518
|
),
|
|
514
|
-
props.open && h("div", { className: "ima-chip-menu" + (props.align === "end" ? " is-end" : "") }, props.children),
|
|
519
|
+
props.open && h("div", { className: "ima-chip-menu" + (props.align === "end" ? " is-end" : ""), role: "menu" }, props.children),
|
|
515
520
|
);
|
|
516
521
|
}
|
|
517
522
|
|
|
@@ -519,6 +524,7 @@ window.__ModuleLoader__.load({
|
|
|
519
524
|
return h("button", {
|
|
520
525
|
type: "button",
|
|
521
526
|
className: "ima-chip-row" + (props.active ? " is-on" : "") + (props.kv ? " is-kv" : ""),
|
|
527
|
+
role: "menuitem",
|
|
522
528
|
onClick: props.onClick,
|
|
523
529
|
},
|
|
524
530
|
h("span", { className: "ima-chip-row-main" },
|
|
@@ -533,53 +539,34 @@ window.__ModuleLoader__.load({
|
|
|
533
539
|
);
|
|
534
540
|
}
|
|
535
541
|
|
|
536
|
-
function
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
"
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
),
|
|
565
|
-
h("div", { className: "ima-risk-warning" },
|
|
566
|
-
h("b", { "aria-hidden": true }, "!"),
|
|
567
|
-
h("p", null, "启用 完全访问 后,agent 将减少确认步骤,并且可以直接执行更多操作,包括敏感操作、文件修改或外部命令。仅建议在你信任当前任务时使用。"),
|
|
568
|
-
),
|
|
569
|
-
h("label", { className: "ima-risk-check" },
|
|
570
|
-
h("input", {
|
|
571
|
-
type: "checkbox",
|
|
572
|
-
checked: props.acknowledged,
|
|
573
|
-
autoFocus: true,
|
|
574
|
-
onChange: (event) => props.onAcknowledgedChange(event.currentTarget.checked),
|
|
575
|
-
}),
|
|
576
|
-
h("span", null, "我已了解风险,并愿意继续"),
|
|
577
|
-
),
|
|
578
|
-
h("div", { className: "ima-risk-actions" },
|
|
579
|
-
h("button", { className: "ima-btn", onClick: props.onCancel }, "取消"),
|
|
580
|
-
h("button", { className: "ima-btn primary", disabled: !props.acknowledged, onClick: props.onConfirm }, "启用 完全访问"),
|
|
581
|
-
),
|
|
582
|
-
)), document.body);
|
|
542
|
+
function openFullAccessConfirmation(onConfirm, t) {
|
|
543
|
+
document.getElementById("ima-full-access-confirmation")?.remove();
|
|
544
|
+
const dialog = document.createElement("dialog");
|
|
545
|
+
dialog.id = "ima-full-access-confirmation";
|
|
546
|
+
dialog.className = "ima-modal ima-full-access-dialog";
|
|
547
|
+
dialog.setAttribute("aria-label", t("confirm.title"));
|
|
548
|
+
dialog.innerHTML = '<div class="ima-modal-h"><h2 data-copy="title"></h2><button class="ima-x" type="button" aria-label="关闭">×</button></div><div class="ima-risk-warning"><b aria-hidden="true">!</b><p data-copy="description"></p></div><label class="ima-risk-check"><input type="checkbox"><span data-copy="acknowledge"></span></label><div class="ima-risk-actions"><button class="ima-btn" type="button" data-copy="cancel"></button><button class="ima-btn primary" type="button" data-copy="confirm" disabled></button></div>';
|
|
549
|
+
dialog.querySelector('[data-copy="title"]').textContent = t("confirm.title");
|
|
550
|
+
dialog.querySelector('[data-copy="description"]').textContent = t("confirm.description");
|
|
551
|
+
dialog.querySelector('[data-copy="acknowledge"]').textContent = t("confirm.acknowledge");
|
|
552
|
+
dialog.querySelector('[data-copy="cancel"]').textContent = t("confirm.cancel");
|
|
553
|
+
dialog.querySelector('[data-copy="confirm"]').textContent = t("confirm.enable");
|
|
554
|
+
const acknowledgement = dialog.querySelector("input");
|
|
555
|
+
const [closeButton, cancelButton, confirmButton] = dialog.querySelectorAll("button");
|
|
556
|
+
const close = (confirmed) => dialog.close(confirmed ? "confirm" : "cancel");
|
|
557
|
+
acknowledgement.addEventListener("change", () => { confirmButton.disabled = !acknowledgement.checked; });
|
|
558
|
+
closeButton.addEventListener("click", () => close(false));
|
|
559
|
+
cancelButton.addEventListener("click", () => close(false));
|
|
560
|
+
confirmButton.addEventListener("click", () => close(true));
|
|
561
|
+
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(false); });
|
|
562
|
+
dialog.addEventListener("close", () => {
|
|
563
|
+
const confirmed = dialog.returnValue === "confirm";
|
|
564
|
+
dialog.remove();
|
|
565
|
+
if (confirmed) onConfirm();
|
|
566
|
+
}, { once: true });
|
|
567
|
+
document.body.append(dialog);
|
|
568
|
+
dialog.showModal();
|
|
569
|
+
acknowledgement.focus();
|
|
583
570
|
}
|
|
584
571
|
|
|
585
572
|
function ComposerBar(props) {
|
|
@@ -587,13 +574,12 @@ window.__ModuleLoader__.load({
|
|
|
587
574
|
? (props.useWorkspaces((state) => (state && state.items) || []) || [])
|
|
588
575
|
: [];
|
|
589
576
|
const [providers, setProviders] = useState([]);
|
|
577
|
+
const [permissions, setPermissions] = useState([]);
|
|
590
578
|
const [provider, setProvider] = useState("");
|
|
591
579
|
const [model, setModel] = useState("");
|
|
592
580
|
const [effort, setEffort] = useState("");
|
|
593
581
|
const [cwd, setCwd] = useState("");
|
|
594
|
-
const [permission, setPermission] = useState("
|
|
595
|
-
const [confirmingFullAccess, setConfirmingFullAccess] = useState(false);
|
|
596
|
-
const [fullAccessAcknowledged, setFullAccessAcknowledged] = useState(false);
|
|
582
|
+
const [permission, setPermission] = useState("");
|
|
597
583
|
const [open, setOpen] = useState("");
|
|
598
584
|
const [modelPane, setModelPane] = useState("root");
|
|
599
585
|
const [hint, setHint] = useState("");
|
|
@@ -606,6 +592,7 @@ window.__ModuleLoader__.load({
|
|
|
606
592
|
if (!data.ok) { setHint(data.error || "无法加载全局配置"); return; }
|
|
607
593
|
const list = data.providers || [];
|
|
608
594
|
setProviders(list);
|
|
595
|
+
setPermissions(data.permissions || []);
|
|
609
596
|
const current = data.assistant || {};
|
|
610
597
|
const nextProvider = current.provider || (list[0] && list[0].id) || "";
|
|
611
598
|
const models = ((list.find((item) => item.id === nextProvider) || {}).models) || [];
|
|
@@ -615,7 +602,7 @@ window.__ModuleLoader__.load({
|
|
|
615
602
|
setModel(nextModel);
|
|
616
603
|
setEffort(current.reasoningEffort || (found && found.reasoning && found.reasoning.defaultEffort) || "");
|
|
617
604
|
setCwd(data.cwd || "");
|
|
618
|
-
setPermission(data.permission || "
|
|
605
|
+
setPermission(data.permission || "");
|
|
619
606
|
if (!list.length) setHint("当前 Host 还没有可用模型,请先在网页里配置提供商");
|
|
620
607
|
}).catch(() => setHint("无法加载全局配置"));
|
|
621
608
|
}, []);
|
|
@@ -644,7 +631,11 @@ window.__ModuleLoader__.load({
|
|
|
644
631
|
? currentModel.reasoning.efforts.map((item) => ({ id: item.id, name: item.name || item.id }))
|
|
645
632
|
: DEFAULT_EFFORTS;
|
|
646
633
|
const effortLabel = (efforts.find((item) => item.id === effort) || {}).name || "";
|
|
647
|
-
const
|
|
634
|
+
const permissionOptions = permissions.map((item) => ({
|
|
635
|
+
...item,
|
|
636
|
+
label: permissionLabel(item, props.permissionT),
|
|
637
|
+
}));
|
|
638
|
+
const perm = permissionOptions.find((item) => item.value === permission) || { label: permission || "权限" };
|
|
648
639
|
|
|
649
640
|
const addWorkspace = (path) => {
|
|
650
641
|
const next = (path || "").trim();
|
|
@@ -666,24 +657,16 @@ window.__ModuleLoader__.load({
|
|
|
666
657
|
const selectPermission = (next) => {
|
|
667
658
|
setOpen("");
|
|
668
659
|
if (next === permission) return;
|
|
669
|
-
if (next === "full-access") {
|
|
670
|
-
|
|
671
|
-
|
|
660
|
+
if (next === "danger-full-access") {
|
|
661
|
+
openFullAccessConfirmation(() => {
|
|
662
|
+
setPermission("danger-full-access");
|
|
663
|
+
save({ permission: "danger-full-access" });
|
|
664
|
+
}, props.permissionT);
|
|
672
665
|
return;
|
|
673
666
|
}
|
|
674
667
|
setPermission(next);
|
|
675
668
|
save({ permission: next });
|
|
676
669
|
};
|
|
677
|
-
const cancelFullAccessConfirmation = () => {
|
|
678
|
-
setFullAccessAcknowledged(false);
|
|
679
|
-
setConfirmingFullAccess(false);
|
|
680
|
-
};
|
|
681
|
-
const confirmFullAccess = () => {
|
|
682
|
-
if (!fullAccessAcknowledged) return;
|
|
683
|
-
setPermission("full-access");
|
|
684
|
-
save({ permission: "full-access" });
|
|
685
|
-
cancelFullAccessConfirmation();
|
|
686
|
-
};
|
|
687
670
|
|
|
688
671
|
const onAddWorkspace = () => {
|
|
689
672
|
setOpen("");
|
|
@@ -733,7 +716,7 @@ window.__ModuleLoader__.load({
|
|
|
733
716
|
label: perm.label,
|
|
734
717
|
ariaLabel: "权限",
|
|
735
718
|
},
|
|
736
|
-
...
|
|
719
|
+
...permissionOptions.map((item) => h(ChipRow, {
|
|
737
720
|
key: item.value,
|
|
738
721
|
icon: h(ShieldIcon),
|
|
739
722
|
label: item.label,
|
|
@@ -870,7 +853,7 @@ window.__ModuleLoader__.load({
|
|
|
870
853
|
h("p", { className: "ima-sub" }, "配置 IM 频道,让本机助手接收来自钉钉、飞书等平台的消息。频道配置仅保存在本机。"),
|
|
871
854
|
),
|
|
872
855
|
),
|
|
873
|
-
h(ComposerBar, { useWorkspaces: props.useWorkspaces, createWorkspace: props.createWorkspace, pickDirectory: props.pickDirectory }),
|
|
856
|
+
h(ComposerBar, { useWorkspaces: props.useWorkspaces, createWorkspace: props.createWorkspace, pickDirectory: props.pickDirectory, permissionT: props.permissionT }),
|
|
874
857
|
error && h("div", { className: "ima-error" }, error),
|
|
875
858
|
pending && pending.length > 0 && h("div", { className: "ima-pending" },
|
|
876
859
|
h("div", null, "有访问请求。批准后该用户才能驱动本机助手。"),
|
|
@@ -1041,13 +1024,6 @@ window.__ModuleLoader__.load({
|
|
|
1041
1024
|
),
|
|
1042
1025
|
),
|
|
1043
1026
|
),
|
|
1044
|
-
h(FullAccessConfirmation, {
|
|
1045
|
-
open: confirmingFullAccess,
|
|
1046
|
-
acknowledged: fullAccessAcknowledged,
|
|
1047
|
-
onAcknowledgedChange: setFullAccessAcknowledged,
|
|
1048
|
-
onCancel: cancelFullAccessConfirmation,
|
|
1049
|
-
onConfirm: confirmFullAccess,
|
|
1050
|
-
}),
|
|
1051
1027
|
);
|
|
1052
1028
|
}
|
|
1053
1029
|
function IconPlayOutline() {
|
|
@@ -1682,6 +1658,7 @@ window.__ModuleLoader__.load({
|
|
|
1682
1658
|
|
|
1683
1659
|
function apply(ctx) {
|
|
1684
1660
|
ensureStyle();
|
|
1661
|
+
const permissionT = ctx.locale.bind("permission.access");
|
|
1685
1662
|
openImSession = (id) => {
|
|
1686
1663
|
try { ctx.sessions.open(id); return true; }
|
|
1687
1664
|
catch (error) { console.warn("[dsh-im-connect] 无法打开会话", id, error); return false; }
|
|
@@ -1695,6 +1672,7 @@ window.__ModuleLoader__.load({
|
|
|
1695
1672
|
inject: () => ({
|
|
1696
1673
|
createWorkspace: (input) => ctx.workspaces.create(input),
|
|
1697
1674
|
pickDirectory: () => ctx.workspaces.pickDirectory(),
|
|
1675
|
+
permissionT,
|
|
1698
1676
|
}),
|
|
1699
1677
|
}, SettingsPage));
|
|
1700
1678
|
|
|
@@ -1811,8 +1789,3 @@ window.__ModuleLoader__.load({
|
|
|
1811
1789
|
|
|
1812
1790
|
|
|
1813
1791
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
package/lib/client.js
CHANGED
|
@@ -10,7 +10,7 @@ window.__ModuleLoader__.load({
|
|
|
10
10
|
const { useState, useEffect, useLayoutEffect, useCallback, useRef, useSyncExternalStore } = React;
|
|
11
11
|
const ReactDOM = require("react-dom");
|
|
12
12
|
const EMPTY_EXTRA_TABS = [];
|
|
13
|
-
const inject = ["slots", "sessions", "workspaces"];
|
|
13
|
+
const inject = ["slots", "sessions", "workspaces", "locale"];
|
|
14
14
|
const API_BASE = "/dsh-im-connect/api";
|
|
15
15
|
const TAB_KEY = "dsh-im-connect.sidebar-tab";
|
|
16
16
|
const h = React.createElement;
|
|
@@ -129,7 +129,7 @@ window.__ModuleLoader__.load({
|
|
|
129
129
|
.ima-radio small{display:block;color:var(--ima-muted);margin-top:2px}
|
|
130
130
|
.ima-ok{color:var(--ima-ok);font-size:14px;text-align:center;padding:24px 0}
|
|
131
131
|
.ima-modal .ima-error{color:var(--ima-danger)}
|
|
132
|
-
.ima-risk-warning{display:flex;gap:10px;align-items:flex-start;margin:0 0 16px;color:var(--ima-muted);font-size:14px;line-height:1.6}.ima-risk-warning b{display:grid;place-items:center;width:18px;height:18px;flex:none;border:1.5px solid var(--ima-danger);border-radius:50%;color:var(--ima-danger);font-size:12px;line-height:1}.ima-risk-warning p{margin:0}.ima-risk-check{display:flex;gap:8px;align-items:center;font-size:14px;cursor:pointer}.ima-risk-check input{width:16px;height:16px;margin:0;accent-color:var(--ima-accent)}.ima-risk-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:24px}.ima-risk-actions .ima-btn{border-radius:999px}.ima-risk-actions .ima-btn.primary:disabled{opacity:.48;cursor:not-allowed}
|
|
132
|
+
.ima-risk-warning{display:flex;gap:10px;align-items:flex-start;margin:0 0 16px;color:var(--ima-muted);font-size:14px;line-height:1.6}.ima-risk-warning b{display:grid;place-items:center;width:18px;height:18px;flex:none;border:1.5px solid var(--ima-danger);border-radius:50%;color:var(--ima-danger);font-size:12px;line-height:1}.ima-risk-warning p{margin:0}.ima-risk-check{display:flex;gap:8px;align-items:center;font-size:14px;cursor:pointer}.ima-risk-check input{width:16px;height:16px;margin:0;accent-color:var(--ima-accent)}.ima-risk-actions{display:flex;justify-content:flex-end;gap:10px;margin-top:24px}.ima-risk-actions .ima-btn{border-radius:999px}.ima-risk-actions .ima-btn.primary:disabled{opacity:.48;cursor:not-allowed}.ima-full-access-dialog{margin:auto}.ima-full-access-dialog::backdrop{background:var(--dsw-alias-bg-mask-1,rgba(0,0,0,.45));backdrop-filter:var(--dsw-mask-blur,blur(8px))}
|
|
133
133
|
@media (prefers-reduced-motion:reduce){.ima-switch i{transition:none}}
|
|
134
134
|
`;
|
|
135
135
|
|
|
@@ -455,12 +455,17 @@ window.__ModuleLoader__.load({
|
|
|
455
455
|
);
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
+
const BUILT_IN_PERMISSION_LABELS = new Map([
|
|
459
|
+
["read-only", ["preset.readOnly", "Read Only"]],
|
|
460
|
+
["workspace-write", ["preset.workspaceWrite", "Workspace Write"]],
|
|
461
|
+
["danger-full-access", ["preset.fullAccess", "Full access"]],
|
|
462
|
+
]);
|
|
458
463
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
+
function permissionLabel(option, t) {
|
|
465
|
+
const builtIn = BUILT_IN_PERMISSION_LABELS.get(option.value);
|
|
466
|
+
if (builtIn && (option.name === option.value || option.name === builtIn[1])) return t(builtIn[0]);
|
|
467
|
+
return option.name || option.value;
|
|
468
|
+
}
|
|
464
469
|
const DEFAULT_EFFORTS = [
|
|
465
470
|
{ id: "low", name: "Low" },
|
|
466
471
|
{ id: "medium", name: "Medium" },
|
|
@@ -511,7 +516,7 @@ window.__ModuleLoader__.load({
|
|
|
511
516
|
props.suffix && h("span", { className: "ima-chip-effort" }, props.suffix),
|
|
512
517
|
h("em"),
|
|
513
518
|
),
|
|
514
|
-
props.open && h("div", { className: "ima-chip-menu" + (props.align === "end" ? " is-end" : "") }, props.children),
|
|
519
|
+
props.open && h("div", { className: "ima-chip-menu" + (props.align === "end" ? " is-end" : ""), role: "menu" }, props.children),
|
|
515
520
|
);
|
|
516
521
|
}
|
|
517
522
|
|
|
@@ -519,6 +524,7 @@ window.__ModuleLoader__.load({
|
|
|
519
524
|
return h("button", {
|
|
520
525
|
type: "button",
|
|
521
526
|
className: "ima-chip-row" + (props.active ? " is-on" : "") + (props.kv ? " is-kv" : ""),
|
|
527
|
+
role: "menuitem",
|
|
522
528
|
onClick: props.onClick,
|
|
523
529
|
},
|
|
524
530
|
h("span", { className: "ima-chip-row-main" },
|
|
@@ -533,53 +539,34 @@ window.__ModuleLoader__.load({
|
|
|
533
539
|
);
|
|
534
540
|
}
|
|
535
541
|
|
|
536
|
-
function
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
"
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
),
|
|
565
|
-
h("div", { className: "ima-risk-warning" },
|
|
566
|
-
h("b", { "aria-hidden": true }, "!"),
|
|
567
|
-
h("p", null, "启用 完全访问 后,agent 将减少确认步骤,并且可以直接执行更多操作,包括敏感操作、文件修改或外部命令。仅建议在你信任当前任务时使用。"),
|
|
568
|
-
),
|
|
569
|
-
h("label", { className: "ima-risk-check" },
|
|
570
|
-
h("input", {
|
|
571
|
-
type: "checkbox",
|
|
572
|
-
checked: props.acknowledged,
|
|
573
|
-
autoFocus: true,
|
|
574
|
-
onChange: (event) => props.onAcknowledgedChange(event.currentTarget.checked),
|
|
575
|
-
}),
|
|
576
|
-
h("span", null, "我已了解风险,并愿意继续"),
|
|
577
|
-
),
|
|
578
|
-
h("div", { className: "ima-risk-actions" },
|
|
579
|
-
h("button", { className: "ima-btn", onClick: props.onCancel }, "取消"),
|
|
580
|
-
h("button", { className: "ima-btn primary", disabled: !props.acknowledged, onClick: props.onConfirm }, "启用 完全访问"),
|
|
581
|
-
),
|
|
582
|
-
)), document.body);
|
|
542
|
+
function openFullAccessConfirmation(onConfirm, t) {
|
|
543
|
+
document.getElementById("ima-full-access-confirmation")?.remove();
|
|
544
|
+
const dialog = document.createElement("dialog");
|
|
545
|
+
dialog.id = "ima-full-access-confirmation";
|
|
546
|
+
dialog.className = "ima-modal ima-full-access-dialog";
|
|
547
|
+
dialog.setAttribute("aria-label", t("confirm.title"));
|
|
548
|
+
dialog.innerHTML = '<div class="ima-modal-h"><h2 data-copy="title"></h2><button class="ima-x" type="button" aria-label="关闭">×</button></div><div class="ima-risk-warning"><b aria-hidden="true">!</b><p data-copy="description"></p></div><label class="ima-risk-check"><input type="checkbox"><span data-copy="acknowledge"></span></label><div class="ima-risk-actions"><button class="ima-btn" type="button" data-copy="cancel"></button><button class="ima-btn primary" type="button" data-copy="confirm" disabled></button></div>';
|
|
549
|
+
dialog.querySelector('[data-copy="title"]').textContent = t("confirm.title");
|
|
550
|
+
dialog.querySelector('[data-copy="description"]').textContent = t("confirm.description");
|
|
551
|
+
dialog.querySelector('[data-copy="acknowledge"]').textContent = t("confirm.acknowledge");
|
|
552
|
+
dialog.querySelector('[data-copy="cancel"]').textContent = t("confirm.cancel");
|
|
553
|
+
dialog.querySelector('[data-copy="confirm"]').textContent = t("confirm.enable");
|
|
554
|
+
const acknowledgement = dialog.querySelector("input");
|
|
555
|
+
const [closeButton, cancelButton, confirmButton] = dialog.querySelectorAll("button");
|
|
556
|
+
const close = (confirmed) => dialog.close(confirmed ? "confirm" : "cancel");
|
|
557
|
+
acknowledgement.addEventListener("change", () => { confirmButton.disabled = !acknowledgement.checked; });
|
|
558
|
+
closeButton.addEventListener("click", () => close(false));
|
|
559
|
+
cancelButton.addEventListener("click", () => close(false));
|
|
560
|
+
confirmButton.addEventListener("click", () => close(true));
|
|
561
|
+
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(false); });
|
|
562
|
+
dialog.addEventListener("close", () => {
|
|
563
|
+
const confirmed = dialog.returnValue === "confirm";
|
|
564
|
+
dialog.remove();
|
|
565
|
+
if (confirmed) onConfirm();
|
|
566
|
+
}, { once: true });
|
|
567
|
+
document.body.append(dialog);
|
|
568
|
+
dialog.showModal();
|
|
569
|
+
acknowledgement.focus();
|
|
583
570
|
}
|
|
584
571
|
|
|
585
572
|
function ComposerBar(props) {
|
|
@@ -587,13 +574,12 @@ window.__ModuleLoader__.load({
|
|
|
587
574
|
? (props.useWorkspaces((state) => (state && state.items) || []) || [])
|
|
588
575
|
: [];
|
|
589
576
|
const [providers, setProviders] = useState([]);
|
|
577
|
+
const [permissions, setPermissions] = useState([]);
|
|
590
578
|
const [provider, setProvider] = useState("");
|
|
591
579
|
const [model, setModel] = useState("");
|
|
592
580
|
const [effort, setEffort] = useState("");
|
|
593
581
|
const [cwd, setCwd] = useState("");
|
|
594
|
-
const [permission, setPermission] = useState("
|
|
595
|
-
const [confirmingFullAccess, setConfirmingFullAccess] = useState(false);
|
|
596
|
-
const [fullAccessAcknowledged, setFullAccessAcknowledged] = useState(false);
|
|
582
|
+
const [permission, setPermission] = useState("");
|
|
597
583
|
const [open, setOpen] = useState("");
|
|
598
584
|
const [modelPane, setModelPane] = useState("root");
|
|
599
585
|
const [hint, setHint] = useState("");
|
|
@@ -606,6 +592,7 @@ window.__ModuleLoader__.load({
|
|
|
606
592
|
if (!data.ok) { setHint(data.error || "无法加载全局配置"); return; }
|
|
607
593
|
const list = data.providers || [];
|
|
608
594
|
setProviders(list);
|
|
595
|
+
setPermissions(data.permissions || []);
|
|
609
596
|
const current = data.assistant || {};
|
|
610
597
|
const nextProvider = current.provider || (list[0] && list[0].id) || "";
|
|
611
598
|
const models = ((list.find((item) => item.id === nextProvider) || {}).models) || [];
|
|
@@ -615,7 +602,7 @@ window.__ModuleLoader__.load({
|
|
|
615
602
|
setModel(nextModel);
|
|
616
603
|
setEffort(current.reasoningEffort || (found && found.reasoning && found.reasoning.defaultEffort) || "");
|
|
617
604
|
setCwd(data.cwd || "");
|
|
618
|
-
setPermission(data.permission || "
|
|
605
|
+
setPermission(data.permission || "");
|
|
619
606
|
if (!list.length) setHint("当前 Host 还没有可用模型,请先在网页里配置提供商");
|
|
620
607
|
}).catch(() => setHint("无法加载全局配置"));
|
|
621
608
|
}, []);
|
|
@@ -644,7 +631,11 @@ window.__ModuleLoader__.load({
|
|
|
644
631
|
? currentModel.reasoning.efforts.map((item) => ({ id: item.id, name: item.name || item.id }))
|
|
645
632
|
: DEFAULT_EFFORTS;
|
|
646
633
|
const effortLabel = (efforts.find((item) => item.id === effort) || {}).name || "";
|
|
647
|
-
const
|
|
634
|
+
const permissionOptions = permissions.map((item) => ({
|
|
635
|
+
...item,
|
|
636
|
+
label: permissionLabel(item, props.permissionT),
|
|
637
|
+
}));
|
|
638
|
+
const perm = permissionOptions.find((item) => item.value === permission) || { label: permission || "权限" };
|
|
648
639
|
|
|
649
640
|
const addWorkspace = (path) => {
|
|
650
641
|
const next = (path || "").trim();
|
|
@@ -666,24 +657,16 @@ window.__ModuleLoader__.load({
|
|
|
666
657
|
const selectPermission = (next) => {
|
|
667
658
|
setOpen("");
|
|
668
659
|
if (next === permission) return;
|
|
669
|
-
if (next === "full-access") {
|
|
670
|
-
|
|
671
|
-
|
|
660
|
+
if (next === "danger-full-access") {
|
|
661
|
+
openFullAccessConfirmation(() => {
|
|
662
|
+
setPermission("danger-full-access");
|
|
663
|
+
save({ permission: "danger-full-access" });
|
|
664
|
+
}, props.permissionT);
|
|
672
665
|
return;
|
|
673
666
|
}
|
|
674
667
|
setPermission(next);
|
|
675
668
|
save({ permission: next });
|
|
676
669
|
};
|
|
677
|
-
const cancelFullAccessConfirmation = () => {
|
|
678
|
-
setFullAccessAcknowledged(false);
|
|
679
|
-
setConfirmingFullAccess(false);
|
|
680
|
-
};
|
|
681
|
-
const confirmFullAccess = () => {
|
|
682
|
-
if (!fullAccessAcknowledged) return;
|
|
683
|
-
setPermission("full-access");
|
|
684
|
-
save({ permission: "full-access" });
|
|
685
|
-
cancelFullAccessConfirmation();
|
|
686
|
-
};
|
|
687
670
|
|
|
688
671
|
const onAddWorkspace = () => {
|
|
689
672
|
setOpen("");
|
|
@@ -733,7 +716,7 @@ window.__ModuleLoader__.load({
|
|
|
733
716
|
label: perm.label,
|
|
734
717
|
ariaLabel: "权限",
|
|
735
718
|
},
|
|
736
|
-
...
|
|
719
|
+
...permissionOptions.map((item) => h(ChipRow, {
|
|
737
720
|
key: item.value,
|
|
738
721
|
icon: h(ShieldIcon),
|
|
739
722
|
label: item.label,
|
|
@@ -870,7 +853,7 @@ window.__ModuleLoader__.load({
|
|
|
870
853
|
h("p", { className: "ima-sub" }, "配置 IM 频道,让本机助手接收来自钉钉、飞书等平台的消息。频道配置仅保存在本机。"),
|
|
871
854
|
),
|
|
872
855
|
),
|
|
873
|
-
h(ComposerBar, { useWorkspaces: props.useWorkspaces, createWorkspace: props.createWorkspace, pickDirectory: props.pickDirectory }),
|
|
856
|
+
h(ComposerBar, { useWorkspaces: props.useWorkspaces, createWorkspace: props.createWorkspace, pickDirectory: props.pickDirectory, permissionT: props.permissionT }),
|
|
874
857
|
error && h("div", { className: "ima-error" }, error),
|
|
875
858
|
pending && pending.length > 0 && h("div", { className: "ima-pending" },
|
|
876
859
|
h("div", null, "有访问请求。批准后该用户才能驱动本机助手。"),
|
|
@@ -1041,13 +1024,6 @@ window.__ModuleLoader__.load({
|
|
|
1041
1024
|
),
|
|
1042
1025
|
),
|
|
1043
1026
|
),
|
|
1044
|
-
h(FullAccessConfirmation, {
|
|
1045
|
-
open: confirmingFullAccess,
|
|
1046
|
-
acknowledged: fullAccessAcknowledged,
|
|
1047
|
-
onAcknowledgedChange: setFullAccessAcknowledged,
|
|
1048
|
-
onCancel: cancelFullAccessConfirmation,
|
|
1049
|
-
onConfirm: confirmFullAccess,
|
|
1050
|
-
}),
|
|
1051
1027
|
);
|
|
1052
1028
|
}
|
|
1053
1029
|
function IconPlayOutline() {
|
|
@@ -1682,6 +1658,7 @@ window.__ModuleLoader__.load({
|
|
|
1682
1658
|
|
|
1683
1659
|
function apply(ctx) {
|
|
1684
1660
|
ensureStyle();
|
|
1661
|
+
const permissionT = ctx.locale.bind("permission.access");
|
|
1685
1662
|
openImSession = (id) => {
|
|
1686
1663
|
try { ctx.sessions.open(id); return true; }
|
|
1687
1664
|
catch (error) { console.warn("[dsh-im-connect] 无法打开会话", id, error); return false; }
|
|
@@ -1695,6 +1672,7 @@ window.__ModuleLoader__.load({
|
|
|
1695
1672
|
inject: () => ({
|
|
1696
1673
|
createWorkspace: (input) => ctx.workspaces.create(input),
|
|
1697
1674
|
pickDirectory: () => ctx.workspaces.pickDirectory(),
|
|
1675
|
+
permissionT,
|
|
1698
1676
|
}),
|
|
1699
1677
|
}, SettingsPage));
|
|
1700
1678
|
|
|
@@ -1811,8 +1789,3 @@ window.__ModuleLoader__.load({
|
|
|
1811
1789
|
|
|
1812
1790
|
|
|
1813
1791
|
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
@@ -4,9 +4,7 @@ export interface AssistantModel {
|
|
|
4
4
|
model: string;
|
|
5
5
|
reasoningEffort?: string;
|
|
6
6
|
}
|
|
7
|
-
export type PermissionPreset =
|
|
8
|
-
/** IM 保存的权限名需转换为 Chat 识别的沙箱模式。 */
|
|
9
|
-
export declare function sandboxModeForPermission(permission: PermissionPreset): 'read-only' | 'workspace-write' | 'danger-full-access';
|
|
7
|
+
export type PermissionPreset = string;
|
|
10
8
|
export declare function normalizeAssistantModel(input: {
|
|
11
9
|
provider?: unknown;
|
|
12
10
|
model?: unknown;
|
|
@@ -14,6 +12,6 @@ export declare function normalizeAssistantModel(input: {
|
|
|
14
12
|
}): AssistantModel | undefined;
|
|
15
13
|
export declare function pickAssistantModel(...candidates: Array<AssistantModel | undefined>): AssistantModel | undefined;
|
|
16
14
|
export declare function normalizeWorkspacePath(input: unknown): string | undefined;
|
|
17
|
-
export declare function normalizePermission(input: unknown): PermissionPreset | undefined;
|
|
15
|
+
export declare function normalizePermission(input: unknown, officialNames?: readonly string[]): PermissionPreset | undefined;
|
|
18
16
|
export declare function normalizeEffort(input: unknown): string | undefined;
|
|
19
17
|
//# sourceMappingURL=assistant-settings.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-settings.d.ts","sourceRoot":"","sources":["../../src/engine/assistant-settings.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,MAAM,gBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"assistant-settings.d.ts","sourceRoot":"","sources":["../../src/engine/assistant-settings.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAA;AAErC,wBAAgB,uBAAuB,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,cAAc,GAAG,SAAS,CAM7I;AAED,wBAAgB,kBAAkB,CAAC,GAAG,UAAU,EAAE,KAAK,CAAC,cAAc,GAAG,SAAS,CAAC,GAAG,cAAc,GAAG,SAAS,CAK/G;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIzE;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,gBAAgB,GAAG,SAAS,CAMnH;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKlE"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/** IM 保存的权限名需转换为 Chat 识别的沙箱模式。 */
|
|
2
|
-
export function sandboxModeForPermission(permission) {
|
|
3
|
-
return permission === 'full-access' ? 'danger-full-access' : permission;
|
|
4
|
-
}
|
|
5
1
|
export function normalizeAssistantModel(input) {
|
|
6
2
|
const provider = typeof input.provider === 'string' ? input.provider.trim() : '';
|
|
7
3
|
const model = typeof input.model === 'string' ? input.model.trim() : '';
|
|
@@ -23,10 +19,14 @@ export function normalizeWorkspacePath(input) {
|
|
|
23
19
|
const cwd = input.trim();
|
|
24
20
|
return cwd === '' ? undefined : cwd;
|
|
25
21
|
}
|
|
26
|
-
export function normalizePermission(input) {
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
29
|
-
|
|
22
|
+
export function normalizePermission(input, officialNames) {
|
|
23
|
+
if (typeof input !== 'string')
|
|
24
|
+
return undefined;
|
|
25
|
+
// 兼容 0.1.13 及更早版本保存的旧值,读取后统一迁移到 Chat 标准值。
|
|
26
|
+
const permission = input.trim() === 'full-access' ? 'danger-full-access' : input.trim();
|
|
27
|
+
if (!permission || (officialNames !== undefined && !officialNames.includes(permission)))
|
|
28
|
+
return undefined;
|
|
29
|
+
return permission;
|
|
30
30
|
}
|
|
31
31
|
export function normalizeEffort(input) {
|
|
32
32
|
if (typeof input !== 'string')
|