Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Upgrade deep-view to 0.1.2 and make mail send cards editable drafts

Fei2411459ace42b40b
diff --git a/app/package-lock.json b/app/package-lock.json
index aba9736f..05a99c78 100644
--- a/app/package-lock.json
+++ b/app/package-lock.json
@@ -46,7 +46,7 @@
"@deepseek-ai/dsh-util-workspace-path": "0.2.1-rc.5",
"@deepseek-ai/dsh-workflow": "0.2.1-rc.5",
"@deepseek-ai/libreoffice-kit": "0.1.5",
- "deep-view": "0.1.0",
+ "deep-view": "0.1.2",
"ds-bot": "file:../ds-bot",
"electron-updater": "6.8.10",
"js-yaml": "4.3.2",
@@ -10473,9 +10473,9 @@
}
},
"node_modules/deep-view": {
- "version": "0.1.0",
- "resolved": "https://registry.npmjs.org/deep-view/-/deep-view-0.1.0.tgz",
- "integrity": "sha512-INK3vzw/p68GjfIjy06Dgk429VpNRREkzHXTK6BhwrPCeh/3gj7uArBKion7nzBfRQhnoTV6v22Nl0CbVX89Gw==",
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/deep-view/-/deep-view-0.1.2.tgz",
+ "integrity": "sha512-hOOWWAcdqtQ0M1/+Dg7vfE+qDhqaTcrao+3jwsWQskCJjVSl8NN7stfvPLP9pnNK5nrW3fLTxWTNMdK1hiFdcQ==",
"license": "Apache-2.0",
"peerDependencies": {
"@deepseek-ai/cordis": "*",
@@ -10893,6 +10893,18 @@
"node": ">=20"
}
},
+ "node_modules/ds-bot/node_modules/deep-view": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npmjs.org/deep-view/-/deep-view-0.1.0.tgz",
+ "integrity": "sha512-INK3vzw/p68GjfIjy06Dgk429VpNRREkzHXTK6BhwrPCeh/3gj7uArBKion7nzBfRQhnoTV6v22Nl0CbVX89Gw==",
+ "license": "Apache-2.0",
+ "peerDependencies": {
+ "@deepseek-ai/cordis": "*",
+ "@deepseek-ai/dsh-llm": "*",
+ "@deepseek-ai/dsh-tools": "*",
+ "@deepseek-ai/dsh-web": "*"
+ }
+ },
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
diff --git a/app/package.json b/app/package.json
index 3801e5f2..0e8d9f8e 100644
--- a/app/package.json
+++ b/app/package.json
@@ -60,7 +60,7 @@
"@deepseek-ai/dsh-util-workspace-path": "0.2.1-rc.5",
"@deepseek-ai/dsh-workflow": "0.2.1-rc.5",
"@deepseek-ai/libreoffice-kit": "0.1.5",
- "deep-view": "0.1.0",
+ "deep-view": "0.1.2",
"ds-bot": "file:../ds-bot",
"electron-updater": "6.8.10",
"js-yaml": "4.3.2",
diff --git a/docs/plans/2026-10-20-widget-views.md b/docs/plans/2026-10-20-widget-views.md
index 38d32aab..301c9931 100644
--- a/docs/plans/2026-10-20-widget-views.md
+++ b/docs/plans/2026-10-20-widget-views.md
@@ -65,7 +65,7 @@ Bot 的回答现在只有 Markdown 文本。有些回答天生是结构化的:
- `options`:`{ id, options: [{ label, description? }], multi? }`。单选按下即提交;多选切换勾选、出 Submit 按钮(和提问卡一致)。
- `confirm`:`{ id, confirmLabel?, cancelLabel? }`,按下即提交。
-- `form`:`{ id, fields: [{ id, label, placeholder? }], submitLabel? }`,短文本输入框 + 提交按钮。说明里禁止用 form 收集密钥——密钥走 `request_secret`。
+- `form`:`{ id, fields: [{ id, label, placeholder?, value?, multiline?, readOnly? }], submitLabel?, cancelLabel? }`,支持预设初值、单行与多行输入、只读字段,以及可选的取消/丢弃按钮(取消时结算为 `{ canceled: true }`)。说明里禁止用 form 收集密钥——密钥走 `request_secret`。
- `submit`:`{ id, label? }`,把输入控件当前的值发给 Bot(「发给 Bot」)。
标识约束:交互组件和输入的 `id` 在整棵树里唯一;输入的 `id` 必须是公式能引用的名字(字母、数字、下划线,不以数字开头);form 内字段 `id` 在该 form 内唯一;options 的选项以 label 为身份(和提问卡一致);choice 的选项值唯一。
diff --git a/docs/plans/2026-11-04-connectors.md b/docs/plans/2026-11-04-connectors.md
index 73322db0..6584f58f 100644
--- a/docs/plans/2026-11-04-connectors.md
+++ b/docs/plans/2026-11-04-connectors.md
@@ -24,7 +24,7 @@ OAuth 登录的顺序是定的:目录里写的客户端 → CIMD → DCR →
## Bot 工具和卡片
-`list_connectors` 列目录、连接状态和本 Bot 可用性;`request_connector`(id、purpose)在本 Bot 自己的会话里出卡片,按密钥卡同一套规矩:只在私聊、群聊拒绝、只读窗口拒绝、记录 pending 并 `concludeTurn`、连接或取消后回话。`request_secret` 的笔记机制原样复用(`rt.deliver` 带角色标签)。邮箱发送同样出卡片:显示 from/to/cc/bcc/subject/正文/附件名和大小,Send 才发,Cancel 什么都不发;draft 不出卡。
+`list_connectors` 列目录、连接状态和本 Bot 可用性;`request_connector`(id、purpose)在本 Bot 自己的会话里出卡片,按密钥卡同一套规矩:只在私聊、群聊拒绝、只读窗口拒绝、记录 pending 并 `concludeTurn`、连接或取消后回话。`request_secret` 的笔记机制原样复用(`rt.deliver` 带角色标签)。邮箱发送同样复用 `show_view` 的 `form` 卡片:展示可编辑草稿(主题、只读发件人、收件人、抄送、密送、多行正文与附件名和大小),用户可直接修改后点「发送」或「丢弃」。默认每封信都需要确认;左下角规则菜单可设为「允许收件人」「需要批准(默认)」「为此 Bot 关闭草稿」或打开「管理规则」(设置 → 连接器 → 邮箱可查看与移除规则);隐私 Bot 始终需要确认;`mail_draft` 不出卡。
## 邮箱
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 78d931d9..fd5c20a1 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -1319,6 +1319,15 @@ var ZH = {
"No connectors connected": "未连接任何连接器",
"{bot} needs {name}": "{bot} 需要 {name}",
"{bot} wants to send an email": "{bot} 想发送一封邮件",
+ "Mail": "邮件",
+ "Subject": "主题",
+ "Write a message…": "写邮件正文…",
+ "Discard": "丢弃",
+ "Discarded": "已丢弃",
+ "Allow recipient": "允许收件人",
+ "Turn off drafts for this Bot": "为此 Bot 关闭草稿",
+ "Manage rules": "管理规则",
+ "Sending rules": "发信规则",
"From": "发件人",
"To": "收件人",
"Cc": "抄送",
@@ -1953,7 +1962,8 @@ function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cards
connectorRequestCancel: (requestId) => after(call2("connector-request-cancel", { requestId })),
mailAccountAdd: (payload) => after(call2("mail-account-add", payload)),
mailAccountRemove: (id) => after(call2("mail-account-remove", { id })),
- mailSendAnswer: (requestId, choice) => after(call2("mail-send-answer", { requestId, choice })),
+ mailRuleSet: (payload) => after(call2("mail-rule-set", payload)),
+ mailSendAnswer: (requestId, choice, extra = {}) => after(call2("mail-send-answer", { requestId, choice, ...extra })),
mailSignInCode: (payload) => after(call2("mail-sign-in-code", payload)),
saveCapability: (capability) => after(call2("capability-save", capability)),
deleteCapability: (name) => after(call2("capability-delete", { name })),
@@ -5572,9 +5582,10 @@ var PROPS = {
number: ["id", "label", "min", "max", "step", "value", "unit"],
options: ["id", "options", "multi"],
confirm: ["id", "confirmLabel", "cancelLabel"],
- form: ["id", "fields", "submitLabel"],
+ form: ["id", "fields", "submitLabel", "cancelLabel"],
submit: ["id", "label"]
};
+var FIELD_PROPS = ["id", "label", "placeholder", "value", "multiline", "readOnly"];
var MAX_DEPTH = 8;
var MAX_NODES = 64;
var MAX_CHILDREN = 16;
@@ -5599,17 +5610,17 @@ function viewBytes(title, view) {
}
var NUMERIC = ["value", "percent", "min", "max", "step", "height"];
var numeric = (value) => typeof value === "string" && value.trim() !== "" && !Number.isNaN(Number(value)) ? Number(value) : value;
-function normalizeView(value) {
- if (Array.isArray(value)) return value.map(normalizeView);
+function normalizeView(value, inFormFields = false) {
+ if (Array.isArray(value)) return value.map((item) => normalizeView(item, inFormFields));
if (!isRecord(value)) return value;
const keys = Object.keys(value);
if (keys.length === 1 && keys[0] === "item") {
- const inner = normalizeView(value.item);
+ const inner = normalizeView(value.item, inFormFields);
if (Array.isArray(inner)) return inner;
}
const out = {};
- for (const key of keys) Object.defineProperty(out, key, { value: normalizeView(value[key]), writable: true, enumerable: true, configurable: true });
- for (const field of NUMERIC) if (Object.hasOwn(out, field)) out[field] = numeric(out[field]);
+ for (const key of keys) Object.defineProperty(out, key, { value: normalizeView(value[key], inFormFields || key === "fields"), writable: true, enumerable: true, configurable: true });
+ for (const field of NUMERIC) if ((field !== "value" || !inFormFields) && Object.hasOwn(out, field)) out[field] = numeric(out[field]);
if (Array.isArray(out.values)) out.values = out.values.map(numeric);
return out;
}
@@ -5907,6 +5918,7 @@ function checkForm(node, path2, ctx) {
const idError = checkId(node, path2, ctx);
if (idError !== void 0) return idError;
if (node.submitLabel !== void 0 && typeof node.submitLabel !== "string") return `${path2}.submitLabel: expected a string`;
+ if (node.cancelLabel !== void 0 && typeof node.cancelLabel !== "string") return `${path2}.cancelLabel: expected a string`;
if (!Array.isArray(node.fields)) return `${path2}.fields: expected an array of at most ${MAX_FIELDS} fields`;
if (node.fields.length > MAX_FIELDS) return `${path2}.fields: ${node.fields.length} fields exceeds the limit of ${MAX_FIELDS}`;
const seen = /* @__PURE__ */ new Set();
@@ -5915,7 +5927,7 @@ function checkForm(node, path2, ctx) {
const at = `${path2}.fields[${index}]`;
if (!isRecord(field)) return `${at}: expected a field object`;
for (const key of Object.keys(field)) {
- if (key !== "id" && key !== "label" && key !== "placeholder") return `${at}.${key}: unknown property ${quoted(key)}; allowed: id, label, placeholder`;
+ if (!FIELD_PROPS.includes(key)) return `${at}.${key}: unknown property ${quoted(key)}; allowed: ${allowed(FIELD_PROPS)}`;
}
if (typeof field.id !== "string" || field.id === "") return `${at}.id: expected a non-empty string`;
if (field.id === "__proto__") return `${at}.id: "__proto__" cannot be an id`;
@@ -5923,6 +5935,12 @@ function checkForm(node, path2, ctx) {
seen.add(field.id);
if (typeof field.label !== "string") return `${at}.label: expected a string`;
if (field.placeholder !== void 0 && typeof field.placeholder !== "string") return `${at}.placeholder: expected a string`;
+ if (field.value !== void 0) {
+ if (typeof field.value !== "string") return `${at}.value: expected a string`;
+ if (field.value.length > MAX_TEXT) return `${at}.value: ${field.value.length} characters exceeds the limit of ${MAX_TEXT}`;
+ }
+ if (field.multiline !== void 0 && typeof field.multiline !== "boolean") return `${at}.multiline: expected a boolean`;
+ if (field.readOnly !== void 0 && typeof field.readOnly !== "boolean") return `${at}.readOnly: expected a boolean`;
}
return void 0;
}
@@ -6072,7 +6090,7 @@ function componentSummary(node, lookup) {
case "confirm":
return "confirm";
case "form":
- return `form: ${(Array.isArray(node.fields) ? node.fields : []).map((field) => field?.label ?? field?.id).filter(Boolean).join("/")}`;
+ return `form: ${(Array.isArray(node.fields) ? node.fields : []).map((field) => field?.label || field?.id).filter(Boolean).join("/")}`;
case "submit":
return `submit: ${node.label ?? "Send"}`;
default:
@@ -6150,15 +6168,19 @@ function validateConfirm(values) {
return { confirmed: values.confirmed };
}
function validateForm(node, values) {
+ if (values.canceled === true) return { canceled: true };
if (!isRecord(values.fields)) return { error: "values.fields: expected an object of field ids to strings" };
- const declared = (node.fields ?? []).map((field) => field?.id).filter((id) => typeof id === "string");
+ const declaredFields = (node.fields ?? []).filter((field) => typeof field?.id === "string");
+ const declared = declaredFields.map((field) => field.id);
+ const byId = new Map(declaredFields.map((field) => [field.id, field]));
const allowedIds = new Set(declared);
const fields = {};
for (const [key, value] of Object.entries(values.fields)) {
if (!allowedIds.has(key)) return { error: `values.fields.${key}: unknown field; allowed: ${allowed(declared)}` };
if (typeof value !== "string") return { error: `values.fields.${key}: expected a string` };
if (value.length > MAX_TEXT) return { error: `values.fields.${key}: ${value.length} characters exceeds the limit of ${MAX_TEXT}` };
- fields[key] = value;
+ const spec = byId.get(key);
+ fields[key] = spec?.readOnly === true ? spec.value ?? "" : value;
}
return { fields };
}
@@ -6776,11 +6798,12 @@ function SettledOptions({ node, answer }) {
))
);
}
-function ConfirmInput({ node, onSubmit, busy = false }) {
+function ConfirmInput({ node, onSubmit, busy = false, footStart = null }) {
const ui2 = useViewUi();
return (0, import_react13.createElement)(
"div",
{ className: "dv-q-foot" },
+ footStart ? (0, import_react13.createElement)("div", { className: "dv-q-foot-start" }, footStart) : null,
(0, import_react13.createElement)("button", { type: "button", className: "dv-q-btn", disabled: busy, onClick: () => onSubmit?.(node.id, { confirmed: false }) }, node.cancelLabel ?? ui2.t("Cancel")),
(0, import_react13.createElement)("button", { type: "button", className: "dv-q-submit", disabled: busy, onClick: () => onSubmit?.(node.id, { confirmed: true }) }, node.confirmLabel ?? ui2.t("Confirm"))
);
@@ -6799,12 +6822,15 @@ function SettledConfirm({ node, answer }) {
const label = confirmed ? node.confirmLabel ?? ui2.t("Confirm") : node.cancelLabel ?? ui2.t("Cancel");
return (0, import_react13.createElement)("span", { className: "dv-q-badge" }, label);
}
-function FormInput({ node, onSubmit, busy = false }) {
+function FormInput({ node, onSubmit, busy = false, footStart = null }) {
const ui2 = useViewUi();
const fields = fieldsOf(node);
- const [draft, setDraft] = (0, import_react13.useState)({});
+ const [draft, setDraft] = (0, import_react13.useState)(() => Object.fromEntries(fields.map((field) => [field.id, field.value ?? ""])));
const submit = () => {
- if (!busy) onSubmit?.(node.id, { fields: Object.fromEntries(fields.map((field) => [field.id, draft[field.id] ?? ""])) });
+ if (!busy) onSubmit?.(node.id, { fields: Object.fromEntries(fields.map((field) => [field.id, field.readOnly === true ? field.value ?? "" : draft[field.id] ?? ""])) });
+ };
+ const cancel = () => {
+ if (!busy) onSubmit?.(node.id, { canceled: true });
};
return (0, import_react13.createElement)(
"form",
@@ -6815,52 +6841,109 @@ function FormInput({ node, onSubmit, busy = false }) {
submit();
}
},
- fields.map((field) => (0, import_react13.createElement)(
- "label",
- { key: field.id, className: "dv-widget-field" },
- (0, import_react13.createElement)("span", { className: "dv-widget-field-label" }, field.label),
- (0, import_react13.createElement)(
- "span",
- { className: "dv-q-field" },
- (0, import_react13.createElement)("input", {
- className: "dv-q-input",
- type: "text",
- value: draft[field.id] ?? "",
- autoComplete: "off",
- spellCheck: false,
- readOnly: busy,
- "aria-label": field.label,
- placeholder: field.placeholder ?? void 0,
- onChange: (event) => {
- if (!busy) setDraft((current) => ({ ...current, [field.id]: event.target.value }));
- },
- onKeyDown: (event) => {
- if (event.key !== "Enter" || event.nativeEvent.isComposing) return;
- event.preventDefault();
- submit();
- }
- })
- )
- )),
- (0, import_react13.createElement)("div", { className: "dv-q-foot" }, (0, import_react13.createElement)("button", { type: "submit", className: "dv-q-submit", disabled: busy }, node.submitLabel ?? ui2.t("Submit")))
+ fields.map((field) => {
+ const val = field.readOnly === true ? field.value ?? "" : draft[field.id] ?? "";
+ const hasLabel = typeof field.label === "string" && field.label.trim() !== "";
+ const multiline = field.multiline === true;
+ const readOnly = field.readOnly === true;
+ const heading = !multiline && !hasLabel;
+ const labelText = hasLabel ? field.label : field.placeholder ?? field.id;
+ return (0, import_react13.createElement)(
+ "label",
+ {
+ key: field.id,
+ className: "dv-widget-field",
+ "data-inline": !multiline && hasLabel ? "" : void 0,
+ "data-heading": heading ? "" : void 0,
+ "data-multiline": multiline ? "" : void 0,
+ "data-readonly": readOnly ? "" : void 0
+ },
+ hasLabel ? (0, import_react13.createElement)("span", { className: "dv-widget-field-label" }, field.label) : null,
+ (0, import_react13.createElement)(
+ "span",
+ { className: "dv-q-field" },
+ multiline ? (0, import_react13.createElement)("textarea", {
+ className: "dv-q-input dv-q-textarea",
+ rows: Math.min(10, Math.max(3, (val.match(/\n/g)?.length ?? 0) + 1)),
+ value: val,
+ autoComplete: "off",
+ spellCheck: false,
+ readOnly: busy || readOnly,
+ "aria-label": labelText,
+ placeholder: field.placeholder ?? void 0,
+ onChange: (event) => {
+ if (!busy && !readOnly) setDraft((current) => ({ ...current, [field.id]: event.target.value }));
+ },
+ onKeyDown: (event) => {
+ if (event.key !== "Enter" || !event.metaKey && !event.ctrlKey || event.nativeEvent?.isComposing) return;
+ event.preventDefault();
+ submit();
+ }
+ }) : (0, import_react13.createElement)("input", {
+ className: "dv-q-input",
+ type: "text",
+ value: val,
+ autoComplete: "off",
+ spellCheck: false,
+ readOnly: busy || readOnly,
+ "aria-label": labelText,
+ placeholder: field.placeholder ?? void 0,
+ onChange: (event) => {
+ if (!busy && !readOnly) setDraft((current) => ({ ...current, [field.id]: event.target.value }));
+ },
+ onKeyDown: (event) => {
+ if (event.key !== "Enter" || event.nativeEvent?.isComposing) return;
+ event.preventDefault();
+ submit();
+ }
+ })
+ )
+ );
+ }),
+ (0, import_react13.createElement)(
+ "div",
+ { className: "dv-q-foot" },
+ footStart ? (0, import_react13.createElement)("div", { className: "dv-q-foot-start" }, footStart) : null,
+ node.cancelLabel ? (0, import_react13.createElement)("button", { type: "button", className: "dv-q-btn", disabled: busy, onClick: cancel }, node.cancelLabel) : null,
+ (0, import_react13.createElement)("button", { type: "submit", className: "dv-q-submit", disabled: busy }, node.submitLabel ?? ui2.t("Submit"))
+ )
);
}
function SettledForm({ node, answer }) {
- const fields = answerValues(answer, node)?.fields;
+ const ui2 = useViewUi();
+ const ans = answerValues(answer, node);
+ const fields = ans?.fields;
const values = fields !== null && typeof fields === "object" ? fields : {};
+ const canceled = ans?.canceled === true;
+ const badge = canceled ? node.cancelLabel ?? ui2.t("Cancel") : node.cancelLabel !== void 0 && ans !== void 0 ? node.submitLabel ?? ui2.t("Submit") : null;
return (0, import_react13.createElement)(
"div",
{ className: "dv-widget-form" },
- fieldsOf(node).map((field) => (0, import_react13.createElement)(
- "label",
- { key: field.id, className: "dv-widget-field" },
- (0, import_react13.createElement)("span", { className: "dv-widget-field-label" }, field.label),
- (0, import_react13.createElement)(
- "span",
- { className: "dv-q-field" },
- (0, import_react13.createElement)("input", { className: "dv-q-input", type: "text", value: values[field.id] ?? "", disabled: true, readOnly: true, "aria-label": field.label })
- )
- ))
+ fieldsOf(node).map((field) => {
+ const val = values[field.id] ?? field.value ?? "";
+ const hasLabel = typeof field.label === "string" && field.label.trim() !== "";
+ const multiline = field.multiline === true;
+ const heading = !multiline && !hasLabel;
+ const labelText = hasLabel ? field.label : field.placeholder ?? field.id;
+ return (0, import_react13.createElement)(
+ "label",
+ {
+ key: field.id,
+ className: "dv-widget-field",
+ "data-inline": !multiline && hasLabel ? "" : void 0,
+ "data-heading": heading ? "" : void 0,
+ "data-multiline": multiline ? "" : void 0,
+ "data-readonly": field.readOnly === true ? "" : void 0
+ },
+ hasLabel ? (0, import_react13.createElement)("span", { className: "dv-widget-field-label" }, field.label) : null,
+ (0, import_react13.createElement)(
+ "span",
+ { className: "dv-q-field" },
+ multiline ? (0, import_react13.createElement)("textarea", { className: "dv-q-input dv-q-textarea", rows: Math.min(10, Math.max(2, (val.match(/\n/g)?.length ?? 0) + 1)), value: val, disabled: true, readOnly: true, "aria-label": labelText }) : (0, import_react13.createElement)("input", { className: "dv-q-input", type: "text", value: val, disabled: true, readOnly: true, "aria-label": labelText })
+ )
+ );
+ }),
+ badge ? (0, import_react13.createElement)("div", { className: "dv-q-foot" }, (0, import_react13.createElement)("span", { className: "dv-q-badge" }, badge)) : null
);
}
function SubmitInput({ node, ctx }) {
@@ -7113,14 +7196,14 @@ function WidgetNode({ node, ctx }) {
case "options":
return ctx.settled ? (0, import_react13.createElement)(SettledOptions, { node, answer: ctx.answer }) : (0, import_react13.createElement)(OptionsInput, { node, onSubmit: ctx.onSubmit, keys: ctx.keys, busy: ctx.busy });
case "confirm":
- return ctx.settled ? (0, import_react13.createElement)(SettledConfirm, { node, answer: ctx.answer }) : (0, import_react13.createElement)(ConfirmInput, { node, onSubmit: ctx.onSubmit, busy: ctx.busy });
+ return ctx.settled ? (0, import_react13.createElement)(SettledConfirm, { node, answer: ctx.answer }) : (0, import_react13.createElement)(ConfirmInput, { node, onSubmit: ctx.onSubmit, busy: ctx.busy, footStart: ctx.footStart });
case "form":
- return ctx.settled ? (0, import_react13.createElement)(SettledForm, { node, answer: ctx.answer }) : (0, import_react13.createElement)(FormInput, { node, onSubmit: ctx.onSubmit, busy: ctx.busy });
+ return ctx.settled ? (0, import_react13.createElement)(SettledForm, { node, answer: ctx.answer }) : (0, import_react13.createElement)(FormInput, { node, onSubmit: ctx.onSubmit, busy: ctx.busy, footStart: ctx.footStart });
default:
return null;
}
}
-function WidgetView({ view, onSubmit, settled = false, answer = null, busy = false, registerChart, refreshCharts }) {
+function WidgetView({ view, onSubmit, settled = false, answer = null, busy = false, footStart = null, registerChart, refreshCharts }) {
const inputs = viewInputs(view);
const [values, setValues] = (0, import_react13.useState)(() => Object.fromEntries(inputs.map((node) => [node.id, inputDefault(node)])));
const sent = answer?.values?.inputs;
@@ -7131,6 +7214,7 @@ function WidgetView({ view, onSubmit, settled = false, answer = null, busy = fal
settled,
answer,
busy,
+ footStart,
keys: !settled && countType(view, "options") === 1,
lookup: viewScope(view, current),
values: current,
@@ -7211,15 +7295,16 @@ function ViewMenu({ charts }) {
open ? (0, import_react13.createElement)(ViewMenuList, { charts, pick: pick2 }) : null
);
}
-function WidgetCard({ title, view, onSubmit, onDismiss, busy = false, raised = false, settled = false, answer = null }) {
+function WidgetCard({ title, icon: icon2, footStart, view, onSubmit, onDismiss, busy = false, raised = false, settled = false, answer = null }) {
const ui2 = useViewUi();
const titleId = (0, import_react13.useId)();
const { charts, registerChart, refreshCharts } = useChartHandles();
const framed = raised || hasControls(view);
const className = ["dv-view", framed ? "dv-q" : "dv-view-bare", settled ? "dv-q-settled" : "", raised ? "dv-q-raised" : ""].filter(Boolean).join(" ");
- const head = title || onDismiss || countType(view, "chart") > 0 ? (0, import_react13.createElement)(
+ const head = title || icon2 || onDismiss || countType(view, "chart") > 0 ? (0, import_react13.createElement)(
"div",
{ className: "dv-view-head" },
+ icon2 ? (0, import_react13.createElement)("span", { className: "dv-view-icon", "aria-hidden": true }, icon2) : null,
title ? (0, import_react13.createElement)("p", { className: "dv-view-title", id: titleId }, title) : (0, import_react13.createElement)("span", { className: "dv-view-title" }),
countType(view, "chart") > 0 ? (0, import_react13.createElement)(ViewMenu, { charts }) : null,
onDismiss ? (0, import_react13.createElement)("button", { type: "button", className: "dv-q-x", "aria-label": ui2.t("Dismiss view"), title: ui2.t("Dismiss"), onClick: onDismiss, disabled: busy }, (0, import_react13.createElement)(CloseIcon2)) : null
@@ -7234,7 +7319,7 @@ function WidgetCard({ title, view, onSubmit, onDismiss, busy = false, raised = f
"aria-busy": busy || void 0
},
head,
- (0, import_react13.createElement)("div", { className: "dv-view-body" }, (0, import_react13.createElement)(WidgetView, { view, onSubmit, settled, answer, busy, registerChart, refreshCharts }))
+ (0, import_react13.createElement)("div", { className: "dv-view-body" }, (0, import_react13.createElement)(WidgetView, { view, onSubmit, settled, answer, busy, footStart: settled ? null : footStart, registerChart, refreshCharts }))
);
}
function AnsweredView({ node }) {
@@ -7258,7 +7343,9 @@ function AnsweredView({ node }) {
var WIDGET_CSS = `
.dv-view{min-width:0}
.dv-view-bare{display:flex;flex-direction:column;gap:8px;width:100%;color:var(--dv-ink);font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif;animation:dv-veil-in .2s ease-out backwards}
-.dv-view-head{display:flex;align-items:flex-start;gap:8px;min-width:0}
+.dv-view-head{display:flex;align-items:center;gap:8px;min-width:0}
+.dv-view-icon{flex:none;width:22px;height:22px;border-radius:6px;background:var(--dv-hover);color:var(--dv-ink-2);display:inline-flex;align-items:center;justify-content:center}
+.dv-view-icon svg{width:14px;height:14px}
.dv-view-title{flex:1 1 0;min-width:0;margin:0;font-size:13px;line-height:18px;font-weight:500;color:var(--dv-ink);overflow-wrap:anywhere}
.dv-q-settled .dv-view-title{color:var(--dv-ink-2)}
.dv-view-tools{position:relative;flex:none;align-self:flex-start;opacity:0;transition:opacity .12s ease}
@@ -7294,6 +7381,14 @@ var WIDGET_CSS = `
.dv-widget-field{display:flex;flex-direction:column;gap:4px;min-width:0}
.dv-widget-field-label{font-size:12px;line-height:16px;color:var(--dv-ink-2)}
.dv-widget-field .dv-q-field:has(.dv-q-input:disabled){cursor:default;opacity:.75}
+.dv-widget-field[data-inline]{flex-direction:row;align-items:center;gap:12px;padding:7px 0;border-bottom:.5px solid var(--dv-line)}
+.dv-widget-field[data-inline] .dv-widget-field-label{flex:none;min-width:44px;font-size:13px;line-height:20px}
+.dv-widget-field[data-inline] .dv-q-field{border:0;border-radius:0;padding:0;min-height:20px;background:none}
+.dv-widget-field[data-inline][data-readonly] .dv-q-input{color:var(--dv-ink-2);cursor:default}
+.dv-widget-field[data-heading] .dv-q-field{border:0;border-radius:0;padding:2px 0;min-height:24px;background:none}
+.dv-widget-field[data-heading] .dv-q-input{font-size:16px;line-height:22px;font-weight:600}
+.dv-widget-field[data-multiline]:not(:has(.dv-widget-field-label)) .dv-q-field{border:0;border-radius:0;padding:4px 0;background:none}
+.dv-q-textarea{max-height:240px;overflow-y:auto;line-height:22px}
.dv-widget-progress{display:flex;flex-direction:column;gap:5px;min-width:0}
.dv-widget-progress-label{display:flex;justify-content:space-between;gap:8px;font-size:12px;line-height:16px;color:var(--dv-ink-2);font-variant-numeric:tabular-nums}
.dv-widget-progress-name{color:var(--dv-ink);font-weight:500}
@@ -7424,7 +7519,8 @@ button.dv-q-opt:active{background:var(--dv-active)}
.dv-q-submit:disabled{opacity:.4;cursor:default}
.dv-q-btn{background:var(--dv-hover);color:var(--dv-ink)}
.dv-q-btn:hover{background:var(--dv-active)}
-.dv-q-foot{display:flex;justify-content:flex-end;gap:8px}
+.dv-q-foot{display:flex;align-items:center;justify-content:flex-end;gap:8px}
+.dv-q-foot-start{margin-right:auto;display:flex;align-items:center}
.dv-menu{position:fixed;pointer-events:auto;z-index:60;min-width:200px;padding:6px;border-radius:12px;background:var(--dv-main);border:.5px solid var(--dv-line-2);box-shadow:0 10px 20px -3px rgba(0,0,0,.1),0 4px 6px -4px rgba(0,0,0,.1),0 0 0 1px rgba(228,228,228,.04);display:flex;flex-direction:column;gap:2px;transform-origin:var(--dv-origin,top left);animation:dv-veil-in .14s ease-out;font-family:var(--dsw-font-family,-apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif);box-sizing:border-box}
.dv-menu.dv-view-menu{position:absolute;z-index:4}
.dv-menu button{display:flex;align-items:center;gap:4px;width:100%;min-height:30px;text-align:left;border:0;background:none;border-radius:6px;padding:6px 8px;font:inherit;font-size:13px;line-height:18px;color:var(--dv-ink);cursor:pointer;box-sizing:border-box}
@@ -7455,6 +7551,7 @@ var DEEP_VIEW_CSS = THEME_CSS + QUESTION_CSS + WIDGET_CSS;
// node_modules/deep-view/src/core/reply.js
var REPLY_KIND = "user-question-reply";
+var REPLY_SOURCE_KIND = "deep-view-reply";
function viewCardText(args) {
let card = args;
if (typeof card === "string") {
@@ -7509,10 +7606,16 @@ function viewAnswerText(view, answer) {
}
});
parts.push(values.confirmed ? confirmLabel ?? "Confirmed" : cancelLabel ?? "Cancelled");
+ } else if (values.canceled === true) {
+ let cancelLabel;
+ eachNode(view, (node) => {
+ if (node.id === answer.action) cancelLabel = node.cancelLabel;
+ });
+ parts.push(cancelLabel ?? "Cancelled");
} else if (isRecord2(values.fields)) {
const labels = /* @__PURE__ */ new Map();
eachNode(view, (node) => {
- for (const field of Array.isArray(node.fields) ? node.fields : []) labels.set(field?.id, field?.label ?? field?.id);
+ for (const field of Array.isArray(node.fields) ? node.fields : []) labels.set(field?.id, field?.label || field?.id);
});
parts.push(...Object.entries(values.fields).map(([key, value]) => `${labels.get(key) ?? key}: ${value}`));
}
@@ -7548,6 +7651,7 @@ function actionSummary(answer, view) {
let text;
if (Array.isArray(values.selected)) text = `selected: ${values.selected.join(", ")}`;
else if (typeof values.confirmed === "boolean") text = values.confirmed ? "confirmed" : "cancelled";
+ else if (values.canceled === true) text = "cancelled";
else if (isRecord2(values.fields)) text = Object.entries(values.fields).map(([key, value]) => `${key}: ${value}`).join("; ");
else if (inputs !== "") text = "";
else text = typeof answer.action === "string" && answer.action !== "" ? answer.action : "(skipped)";
@@ -10869,13 +10973,69 @@ function MailForm({ mail, actions, mailRun, busy, error, fields, setField, onClo
);
}
var EMPTY_MAIL = { address: "", password: "", provider: "", imapHost: "", smtpHost: "" };
-function MailSection({ mail, actions, run: run2 }) {
+function MailRules({ mail, bots, actions, run: run2 }) {
+ const [recipient, setRecipient] = (0, import_react25.useState)("");
+ const allowed2 = mail?.allowedRecipients ?? [];
+ const noDraft = mail?.noDraftFor ?? [];
+ const add = () => {
+ const addr = recipient.trim();
+ if (!addr.includes("@")) return;
+ void run2(actions.mailRuleSet({ addRecipient: addr }), () => setRecipient(""));
+ };
+ return (0, import_react25.createElement)(
+ "div",
+ { className: "bt-set-row bt-set-paste bt-mail-rules" },
+ (0, import_react25.createElement)("div", { className: "bt-connector-name" }, t("Sending rules")),
+ allowed2.map((addr) => (0, import_react25.createElement)(
+ "div",
+ { key: `r:${addr}`, className: "bt-connector-head" },
+ (0, import_react25.createElement)(
+ "span",
+ { className: "bt-connector-text" },
+ (0, import_react25.createElement)("span", { className: "bt-connector-name" }, addr),
+ (0, import_react25.createElement)("span", { className: "bt-connector-status" }, t("Allow recipient"))
+ ),
+ (0, import_react25.createElement)(
+ "span",
+ { className: "bt-connector-actions" },
+ (0, import_react25.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => void run2(actions.mailRuleSet({ removeRecipient: addr })) }, t("Remove"))
+ )
+ )),
+ noDraft.map((botId) => {
+ const botName = (bots ?? []).find((b) => b.id === botId)?.name ?? botId;
+ return (0, import_react25.createElement)(
+ "div",
+ { key: `b:${botId}`, className: "bt-connector-head" },
+ (0, import_react25.createElement)(
+ "span",
+ { className: "bt-connector-text" },
+ (0, import_react25.createElement)("span", { className: "bt-connector-name" }, botName),
+ (0, import_react25.createElement)("span", { className: "bt-connector-status" }, t("Turn off drafts for this Bot"))
+ ),
+ (0, import_react25.createElement)(
+ "span",
+ { className: "bt-connector-actions" },
+ (0, import_react25.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => void run2(actions.mailRuleSet({ botId, noDraft: false })) }, t("Needs approval"))
+ )
+ );
+ }),
+ (0, import_react25.createElement)(
+ "div",
+ { className: "bt-connector-form-row" },
+ (0, import_react25.createElement)("input", { className: "bt-input", "aria-label": t("Allow recipient"), placeholder: "[email protected]", value: recipient, autoComplete: "off", onChange: (e) => setRecipient(e.target.value) }),
+ (0, import_react25.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: !recipient.includes("@"), onClick: add }, t("Add"))
+ )
+ );
+}
+function MailSection({ mail, bots, actions, run: run2 }) {
const [form, setForm] = (0, import_react25.useState)(false);
+ const [rulesOpen, setRulesOpen] = (0, import_react25.useState)(false);
const [busy, setBusy] = (0, import_react25.useState)(false);
const [error, setError] = (0, import_react25.useState)(null);
const [fields, setFields] = (0, import_react25.useState)(EMPTY_MAIL);
const busyRef = (0, import_react25.useRef)(false);
const accounts = mail?.accounts ?? [];
+ const hasRules = (mail?.allowedRecipients?.length ?? 0) > 0 || (mail?.noDraftFor?.length ?? 0) > 0;
const setField = (key, value) => setFields((current) => ({ ...current, [key]: value }));
const close = () => {
setError(null);
@@ -10905,7 +11065,8 @@ function MailSection({ mail, actions, run: run2 }) {
accounts.length === 0 && !form ? (0, import_react25.createElement)("div", { className: "bt-set-row" }, (0, import_react25.createElement)("span", { className: "bt-set-hint" }, t("No mail accounts yet"))) : null,
accounts.map((account) => (0, import_react25.createElement)(MailAccount, { key: account.id, account, actions, run: run2 })),
(mail?.pending ?? []).map((p) => (0, import_react25.createElement)(MailPending, { key: p.address ?? "google", pending: p })),
- form ? (0, import_react25.createElement)(MailForm, { mail, actions, mailRun, busy, error, fields, setField, onClose: close }) : null
+ form ? (0, import_react25.createElement)(MailForm, { mail, actions, mailRun, busy, error, fields, setField, onClose: close }) : null,
+ hasRules || rulesOpen ? (0, import_react25.createElement)(MailRules, { mail, bots, actions, run: run2 }) : null
),
form ? null : (0, import_react25.createElement)(
"div",
@@ -10914,7 +11075,8 @@ function MailSection({ mail, actions, run: run2 }) {
setError(null);
setForm(true);
} }, t("Add an account")),
- mail?.google ? (0, import_react25.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy, onClick: () => void run2(actions.mailAccountAdd({ google: true })) }, t("Sign in with Google")) : null
+ mail?.google ? (0, import_react25.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", disabled: busy, onClick: () => void run2(actions.mailAccountAdd({ google: true })) }, t("Sign in with Google")) : null,
+ !hasRules && accounts.length > 0 ? (0, import_react25.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => setRulesOpen((v) => !v) }, t("Manage rules")) : null
)
];
}
@@ -11002,7 +11164,7 @@ function ConnectorsPage({ roster, actions }) {
connected.length === 0 ? (0, import_react25.createElement)("div", { className: "bt-set-row" }, (0, import_react25.createElement)("span", { className: "bt-set-hint" }, t("No connectors connected"))) : null,
connected.map((connector) => (0, import_react25.createElement)(ConnectorRow, { key: connector.id, connector, actions }))
),
- (0, import_react25.createElement)(MailSection, { mail: data.mail, actions, run: run2 }),
+ (0, import_react25.createElement)(MailSection, { mail: data.mail, bots: roster?.bots, actions, run: run2 }),
(0, import_react25.createElement)("div", { className: "bt-section-title" }, t("Catalog")),
(0, import_react25.createElement)(
"div",
@@ -11043,29 +11205,31 @@ function BotConnectors({ bot, roster, actions, run: run2 }) {
);
}
var literal = (text) => String(text ?? "").replace(/[\\`*_{}[\]()#+\-.!|<>~&@:]/g, "\\$&");
-var literalBlock = (text) => literal(String(text ?? "").replace(/\r\n?/g, "\n").trim()).split(/\n{2,}/).map((paragraph) => paragraph.replace(/\n/g, "\\\n")).join("\n\n");
-var codeSpan = (text) => {
- const value = String(text ?? "").replace(/\s+/g, " ");
- const fence = "`".repeat(Math.max(0, ...(value.match(/`+/g) ?? []).map((run2) => run2.length)) + 1);
- return `${fence} ${value} ${fence}`;
-};
-function RequestView2({ sessionId, kind, request, actions, inline, title, view, onAnswer, busy = false }) {
+var MailIcon = () => (0, import_react25.createElement)(
+ "svg",
+ { width: 14, height: 14, viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.6, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true },
+ (0, import_react25.createElement)("rect", { x: 2.5, y: 4.5, width: 15, height: 11, rx: 2 }),
+ (0, import_react25.createElement)("path", { d: "M3 5.5l7 5 7-5" })
+);
+function RequestView2({ sessionId, kind, request, actions, inline, title, icon: icon2, footStart, view, onAnswer, busy = false }) {
const hold = useDockHold(sessionId, kind, request.id, actions, inline);
return (0, import_react25.createElement)(
"div",
{ style: { display: "contents" }, onFocusCapture: hold, onPointerDownCapture: hold },
(0, import_react25.createElement)(ViewCard, {
title,
+ icon: icon2,
+ footStart,
view,
busy,
raised: !inline,
onSubmit: (_, values) => {
hold();
- onAnswer(values?.confirmed === true);
+ onAnswer(values);
},
onDismiss: () => {
hold();
- onAnswer(false);
+ onAnswer({ canceled: true });
}
})
);
@@ -11087,8 +11251,8 @@ function ConnectorCard({ sessionId, bot, request, actions, inline = false }) {
inline,
title: t("{bot} needs {name}", { bot: bot.name, name }),
view: connectorView(request),
- onAnswer: (connect) => {
- if (connect) actions.openConnectors();
+ onAnswer: (values) => {
+ if (values?.confirmed === true) actions.openConnectors();
else void actions.connectorRequestCancel(request.id);
}
});
@@ -11125,36 +11289,112 @@ function ConnectorDock({ sessionId, useRoster, useCards, useHeldCards, actions }
if (waiting.length === 0) return null;
return (0, import_react25.createElement)("div", { className: "bt-q-dock bt-secret-dock" }, waiting.map((request) => (0, import_react25.createElement)(ConnectorCard, { key: request.id, sessionId, bot, request, actions })));
}
-function mailView(request, roster, settled = false) {
+var RULE_LABELS = {
+ "allow-recipient": "Allow recipient",
+ "require-approval": "Needs approval",
+ "no-draft": "Turn off drafts for this Bot"
+};
+function MailApprovalMenu({ bot, request, rule, onPick, actions, disabled = false }) {
+ const [open, setOpen] = (0, import_react25.useState)(false);
+ const root = (0, import_react25.useRef)(null);
+ (0, import_react25.useEffect)(() => {
+ if (!open) return void 0;
+ const away = (event) => {
+ if (!root.current?.contains(event.target)) setOpen(false);
+ };
+ const key = (event) => {
+ if (event.key === "Escape") setOpen(false);
+ };
+ document.addEventListener("pointerdown", away, true);
+ document.addEventListener("keydown", key);
+ return () => {
+ document.removeEventListener("pointerdown", away, true);
+ document.removeEventListener("keydown", key);
+ };
+ }, [open]);
+ const choose = (mode) => {
+ setOpen(false);
+ onPick(mode);
+ void Promise.resolve(actions.mailRuleSet?.({
+ mode,
+ botId: bot.id,
+ recipients: [request.to, request.cc, request.bcc].filter(Boolean).join(", ")
+ })).catch(() => {
+ });
+ };
+ return (0, import_react25.createElement)(
+ "div",
+ { ref: root, className: "bt-mail-rule-wrap" },
+ (0, import_react25.createElement)("button", {
+ type: "button",
+ className: "bt-mail-rule-btn",
+ disabled,
+ "aria-haspopup": "menu",
+ "aria-expanded": open,
+ onClick: () => setOpen((v) => !v)
+ }, t(RULE_LABELS[rule] ?? "Needs approval"), (0, import_react25.createElement)(ChevronDownIcon)),
+ open ? (0, import_react25.createElement)(
+ "div",
+ { className: "dv-menu bt-mail-rule-menu", role: "menu" },
+ ["allow-recipient", "require-approval", "no-draft"].map((mode) => (0, import_react25.createElement)("button", {
+ key: mode,
+ type: "button",
+ role: "menuitemradio",
+ "aria-checked": rule === mode,
+ onClick: () => choose(mode)
+ }, (0, import_react25.createElement)("span", { className: "bt-mail-rule-item-text" }, t(RULE_LABELS[mode])), rule === mode ? (0, import_react25.createElement)(CheckIcon) : null)),
+ (0, import_react25.createElement)("div", { className: "dv-menu-sep", role: "separator" }),
+ (0, import_react25.createElement)("button", {
+ type: "button",
+ role: "menuitem",
+ onClick: () => {
+ setOpen(false);
+ actions.openConnectors?.();
+ }
+ }, (0, import_react25.createElement)("span", { className: "bt-mail-rule-item-text" }, t("Manage rules")))
+ ) : null
+ );
+}
+function mailFrom(request, roster) {
const account = (roster?.connectors?.mail?.accounts ?? []).find((entry) => entry.id === request.account);
- const from = account?.address ?? request.account;
- const route = [
- [t("From"), from],
- [t("To"), request.to],
- [t("Cc"), request.cc],
- [t("Bcc"), request.bcc]
- ].filter(([, value]) => value).map(([label, value]) => `${literal(label)} ${codeSpan(value)}`).join("\\\n");
+ return account?.address ?? request.account ?? "";
+}
+function mailView(request, roster, settled = false) {
+ const from = mailFrom(request, roster);
const attachments = request.attachmentDetails?.length ? t("Attachments: {names}", { names: request.attachmentDetails.map((a) => a.size !== void 0 ? `${a.name} (${humanSize(a.size)})` : a.name).join(", ") }) : "";
const done = request.status === "sent" ? t("Sent") : request.status === "failed" ? t("Failed") : t("Send");
+ const fields = [
+ { id: "subject", label: "", value: String(request.subject ?? ""), placeholder: t("Subject") },
+ { id: "from", label: t("From"), value: String(from), readOnly: true },
+ { id: "to", label: t("To"), value: String(request.to ?? ""), placeholder: "[email protected]" },
+ ...settled && !request.cc ? [] : [{ id: "cc", label: t("Cc"), value: String(request.cc ?? ""), placeholder: "[email protected]" }],
+ ...request.bcc ? [{ id: "bcc", label: t("Bcc"), value: String(request.bcc ?? ""), placeholder: "[email protected]" }] : [],
+ { id: "body", label: "", value: String(request.body ?? ""), multiline: true, placeholder: t("Write a message…") }
+ ];
return {
type: "stack",
children: [
- route ? { type: "text", tone: "muted", text: route } : null,
- request.subject ? { type: "text", text: `**${literal(request.subject)}**` } : null,
- String(request.body ?? "").trim() ? { type: "text", text: literalBlock(request.body) } : null,
- attachments ? { type: "text", tone: "muted", text: literal(attachments) } : null,
- { type: "confirm", id: "send", confirmLabel: settled ? done : t("Send"), cancelLabel: settled ? t("Canceled") : t("Cancel") }
+ {
+ type: "form",
+ id: "send",
+ submitLabel: settled ? done : t("Send"),
+ cancelLabel: settled ? t("Discarded") : t("Discard"),
+ fields
+ },
+ attachments ? { type: "text", tone: "muted", text: literal(attachments) } : null
].filter(Boolean)
};
}
function MailSendCard({ sessionId, bot, request, roster, actions, inline = false }) {
const [busy, setBusy] = (0, import_react25.useState)(false);
+ const [rule, setRule] = (0, import_react25.useState)("require-approval");
const busyRef = (0, import_react25.useRef)(false);
- const answer = (send) => {
+ const answer = (values) => {
if (busyRef.current) return;
busyRef.current = true;
setBusy(true);
- void Promise.resolve(actions.mailSendAnswer(request.id, send ? "send" : "cancel")).catch(() => {
+ const send = values?.canceled !== true && values?.fields !== void 0;
+ void Promise.resolve(actions.mailSendAnswer(request.id, send ? "send" : "cancel", send ? { fields: values.fields, rule } : { rule })).catch(() => {
}).finally(() => {
busyRef.current = false;
setBusy(false);
@@ -11167,17 +11407,25 @@ function MailSendCard({ sessionId, bot, request, roster, actions, inline = false
actions,
inline,
busy,
- title: t("{bot} wants to send an email", { bot: bot.name }),
+ title: t("Mail"),
+ icon: (0, import_react25.createElement)(MailIcon),
+ footStart: (0, import_react25.createElement)(MailApprovalMenu, { bot, request, rule, onPick: setRule, actions, disabled: busy }),
view: mailView(request, roster),
onAnswer: answer
});
}
-function SettledMail({ bot, request, roster }) {
+function SettledMail({ request, roster }) {
+ const from = mailFrom(request, roster);
+ const sent = request.status === "sent" || request.status === "failed";
return (0, import_react25.createElement)(ViewCard, {
- title: t("{bot} wants to send an email", { bot: bot.name }),
+ title: t("Mail"),
+ icon: (0, import_react25.createElement)(MailIcon),
view: mailView(request, roster, true),
settled: true,
- answer: { action: "send", values: { confirmed: request.status === "sent" || request.status === "failed" } }
+ answer: {
+ action: "send",
+ values: sent ? { fields: { subject: String(request.subject ?? ""), from: String(from), to: String(request.to ?? ""), cc: String(request.cc ?? ""), bcc: String(request.bcc ?? ""), body: String(request.body ?? "") } } : { canceled: true }
+ }
});
}
function MailToolCell({ sessionId, callId, roster, actions, heldCards = NONE2 }) {
@@ -11218,6 +11466,15 @@ var CONNECTOR_CSS = `
.bt-mail-providers .bt-secret-seg[aria-checked=true]{background:var(--bt-active)}
.bt-connector-bot .bt-set-copy{min-width:0}
.bt-mail-open{text-decoration:none}
+.bt-mail-rule-wrap{position:relative;display:inline-flex;align-items:center}
+.bt-mail-rule-btn{display:inline-flex;align-items:center;gap:4px;height:30px;padding:0 8px;border:0;border-radius:8px;background:none;color:var(--bt-ink-2);font:inherit;font-size:13px;font-weight:500;cursor:pointer;transition:background-color .12s ease,color .12s ease}
+.bt-mail-rule-btn:hover:not(:disabled){background:var(--bt-hover);color:var(--bt-ink)}
+.bt-mail-rule-btn:disabled{opacity:.4;cursor:default}
+.bt-mail-rule-btn svg{width:13px;height:13px;color:var(--bt-ink-2)}
+.dv-menu.bt-mail-rule-menu{position:absolute;left:0;bottom:calc(100% + 6px);z-index:20;min-width:190px;--dv-origin:bottom left}
+.dv-menu.bt-mail-rule-menu button{justify-content:space-between;gap:12px}
+.bt-mail-rule-item-text{flex:1 1 auto;min-width:0}
+.bt-mail-rules{display:flex;flex-direction:column;gap:8px}
`;
// src/client/turn-reasoning.js
diff --git a/ds-bot/package-lock.json b/ds-bot/package-lock.json
index 0273b611..1b394a5f 100644
--- a/ds-bot/package-lock.json
+++ b/ds-bot/package-lock.json
@@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@modelcontextprotocol/client": "2.4.0",
- "deep-view": "0.1.0",
+ "deep-view": "0.1.2",
"imapflow": "2.9.1",
"mailparser": "3.12.4",
"nodemailer": "10.2.1"
@@ -569,9 +569,9 @@
}
},
"node_modules/deep-view": {
- "version": "0.1.0",
- "resolved": "https://registry.npmjs.org/deep-view/-/deep-view-0.1.0.tgz",
- "integrity": "sha512-INK3vzw/p68GjfIjy06Dgk429VpNRREkzHXTK6BhwrPCeh/3gj7uArBKion7nzBfRQhnoTV6v22Nl0CbVX89Gw==",
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/deep-view/-/deep-view-0.1.2.tgz",
+ "integrity": "sha512-hOOWWAcdqtQ0M1/+Dg7vfE+qDhqaTcrao+3jwsWQskCJjVSl8NN7stfvPLP9pnNK5nrW3fLTxWTNMdK1hiFdcQ==",
"license": "Apache-2.0",
"peerDependencies": {
"@deepseek-ai/cordis": "*",
diff --git a/ds-bot/package.json b/ds-bot/package.json
index ce016735..f840050a 100644
--- a/ds-bot/package.json
+++ b/ds-bot/package.json
@@ -69,7 +69,7 @@
},
"dependencies": {
"@modelcontextprotocol/client": "2.4.0",
- "deep-view": "0.1.0",
+ "deep-view": "0.1.2",
"imapflow": "2.9.1",
"mailparser": "3.12.4",
"nodemailer": "10.2.1"
diff --git a/ds-bot/src/client/connectors.js b/ds-bot/src/client/connectors.js
index ee4a6c78..9f6414f1 100644
--- a/ds-bot/src/client/connectors.js
+++ b/ds-bot/src/client/connectors.js
@@ -1,7 +1,7 @@
// Settings → Connectors: connected rows, a catalog with search and categories,
// an Add menu, and the mailbox. One row component draws the mark, name, status
// and the expanding panels (browser sign-in, device code, key/token, client).
-import { createElement as h, useRef, useState } from 'react'
+import { createElement as h, useEffect, useRef, useState } from 'react'
import { useMorph } from './motion.js'
import { MaskedInput } from './secret-card.js'
import { SwitchRow } from './bot-settings.js'
@@ -10,6 +10,7 @@ import { useDockHold } from './card-hold.js'
import { heldCardKey } from './sources.js'
import { CellEmpty } from './cell-empty.js'
import { hostText, t } from './i18n.js'
+import { CheckIcon, ChevronDownIcon } from './icons.js'
import { ViewCard } from './widget-cell.js'
export { GitHubMark } from './connector-marks.js'
@@ -249,13 +250,46 @@ function MailForm({ mail, actions, mailRun, busy, error, fields, setField, onClo
}
const EMPTY_MAIL = { address: '', password: '', provider: '', imapHost: '', smtpHost: '' }
-export function MailSection({ mail, actions, run }) {
+function MailRules({ mail, bots, actions, run }) {
+ const [recipient, setRecipient] = useState('')
+ const allowed = mail?.allowedRecipients ?? []
+ const noDraft = mail?.noDraftFor ?? []
+ const add = () => {
+ const addr = recipient.trim()
+ if (!addr.includes('@')) return
+ void run(actions.mailRuleSet({ addRecipient: addr }), () => setRecipient(''))
+ }
+ return h('div', { className: 'bt-set-row bt-set-paste bt-mail-rules' },
+ h('div', { className: 'bt-connector-name' }, t('Sending rules')),
+ allowed.map(addr => h('div', { key: `r:${addr}`, className: 'bt-connector-head' },
+ h('span', { className: 'bt-connector-text' },
+ h('span', { className: 'bt-connector-name' }, addr),
+ h('span', { className: 'bt-connector-status' }, t('Allow recipient'))),
+ h('span', { className: 'bt-connector-actions' },
+ h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => void run(actions.mailRuleSet({ removeRecipient: addr })) }, t('Remove'))))),
+ noDraft.map((botId) => {
+ const botName = (bots ?? []).find(b => b.id === botId)?.name ?? botId
+ return h('div', { key: `b:${botId}`, className: 'bt-connector-head' },
+ h('span', { className: 'bt-connector-text' },
+ h('span', { className: 'bt-connector-name' }, botName),
+ h('span', { className: 'bt-connector-status' }, t('Turn off drafts for this Bot'))),
+ h('span', { className: 'bt-connector-actions' },
+ h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => void run(actions.mailRuleSet({ botId, noDraft: false })) }, t('Needs approval'))))
+ }),
+ h('div', { className: 'bt-connector-form-row' },
+ h('input', { className: 'bt-input', 'aria-label': t('Allow recipient'), placeholder: '[email protected]', value: recipient, autoComplete: 'off', onChange: e => setRecipient(e.target.value) }),
+ h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: !recipient.includes('@'), onClick: add }, t('Add'))))
+}
+
+export function MailSection({ mail, bots, actions, run }) {
const [form, setForm] = useState(false)
+ const [rulesOpen, setRulesOpen] = useState(false)
const [busy, setBusy] = useState(false)
const [error, setError] = useState(null)
const [fields, setFields] = useState(EMPTY_MAIL)
const busyRef = useRef(false)
const accounts = mail?.accounts ?? []
+ const hasRules = (mail?.allowedRecipients?.length ?? 0) > 0 || (mail?.noDraftFor?.length ?? 0) > 0
const setField = (key, value) => setFields(current => ({ ...current, [key]: value }))
const close = () => { setError(null); setForm(false); setFields(EMPTY_MAIL) }
const mailRun = (task, onDone) => {
@@ -272,10 +306,12 @@ export function MailSection({ mail, actions, run }) {
accounts.length === 0 && !form ? h('div', { className: 'bt-set-row' }, h('span', { className: 'bt-set-hint' }, t('No mail accounts yet'))) : null,
accounts.map(account => h(MailAccount, { key: account.id, account, actions, run })),
(mail?.pending ?? []).map(p => h(MailPending, { key: p.address ?? 'google', pending: p })),
- form ? h(MailForm, { mail, actions, mailRun, busy, error, fields, setField, onClose: close }) : null),
+ form ? h(MailForm, { mail, actions, mailRun, busy, error, fields, setField, onClose: close }) : null,
+ hasRules || rulesOpen ? h(MailRules, { mail, bots, actions, run }) : null),
form ? null : h('div', { key: 'add', className: 'bt-actions' },
h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => { setError(null); setForm(true) } }, t('Add an account')),
- mail?.google ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => void run(actions.mailAccountAdd({ google: true })) }, t('Sign in with Google')) : null),
+ mail?.google ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', disabled: busy, onClick: () => void run(actions.mailAccountAdd({ google: true })) }, t('Sign in with Google')) : null,
+ !hasRules && accounts.length > 0 ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => setRulesOpen(v => !v) }, t('Manage rules')) : null),
]
}
@@ -329,7 +365,7 @@ export function ConnectorsPage({ roster, actions }) {
h('div', { className: 'bt-set-card bt-connectors-card' },
connected.length === 0 ? h('div', { className: 'bt-set-row' }, h('span', { className: 'bt-set-hint' }, t('No connectors connected'))) : null,
connected.map(connector => h(ConnectorRow, { key: connector.id, connector, actions }))),
- h(MailSection, { mail: data.mail, actions, run }),
+ h(MailSection, { mail: data.mail, bots: roster?.bots, actions, run }),
h('div', { className: 'bt-section-title' }, t('Catalog')),
h('div', { className: 'bt-set-card bt-connectors-card' },
h('div', { className: 'bt-connector-search' },
@@ -365,25 +401,21 @@ export function BotConnectors({ bot, roster, actions, run }) {
// and a confirm row. Answered requests settle into the same card, read-only.
// Bot-written text shows exactly as written: Markdown is escaped so nothing in
-// it renders, links, or hides. Blank lines keep paragraphs, single breaks stay.
+// it renders, links, or hides.
const literal = text => String(text ?? '').replace(/[\\`*_{}[\]()#+\-.!|<>~&@:]/g, '\\$&')
-const literalBlock = text => literal(String(text ?? '').replace(/\r\n?/g, '\n').trim())
- .split(/\n{2,}/).map(paragraph => paragraph.replace(/\n/g, '\\\n')).join('\n\n')
-// Addresses go in code spans: the renderer links bare addresses even when escaped.
-const codeSpan = text => {
- const value = String(text ?? '').replace(/\s+/g, ' ')
- const fence = '`'.repeat(Math.max(0, ...(value.match(/`+/g) ?? []).map(run => run.length)) + 1)
- return `${fence} ${value} ${fence}`
-}
+
+const MailIcon = () => h('svg', { width: 14, height: 14, viewBox: '0 0 20 20', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true },
+ h('rect', { x: 2.5, y: 4.5, width: 15, height: 11, rx: 2 }),
+ h('path', { d: 'M3 5.5l7 5 7-5' }))
// A view card that holds the dock while the user works in it.
-function RequestView({ sessionId, kind, request, actions, inline, title, view, onAnswer, busy = false }) {
+function RequestView({ sessionId, kind, request, actions, inline, title, icon, footStart, view, onAnswer, busy = false }) {
const hold = useDockHold(sessionId, kind, request.id, actions, inline)
return h('div', { style: { display: 'contents' }, onFocusCapture: hold, onPointerDownCapture: hold },
h(ViewCard, {
- title, view, busy, raised: !inline,
- onSubmit: (_, values) => { hold(); onAnswer(values?.confirmed === true) },
- onDismiss: () => { hold(); onAnswer(false) },
+ title, icon, footStart, view, busy, raised: !inline,
+ onSubmit: (_, values) => { hold(); onAnswer(values) },
+ onDismiss: () => { hold(); onAnswer({ canceled: true }) },
}))
}
@@ -401,7 +433,7 @@ function ConnectorCard({ sessionId, bot, request, actions, inline = false }) {
sessionId, kind: 'connector', request, actions, inline,
title: t('{bot} needs {name}', { bot: bot.name, name }),
view: connectorView(request),
- onAnswer: connect => { if (connect) actions.openConnectors(); else void actions.connectorRequestCancel(request.id) },
+ onAnswer: values => { if (values?.confirmed === true) actions.openConnectors(); else void actions.connectorRequestCancel(request.id) },
})
}
@@ -443,53 +475,121 @@ export function ConnectorDock({ sessionId, useRoster, useCards, useHeldCards, ac
return h('div', { className: 'bt-q-dock bt-secret-dock' }, waiting.map(request => h(ConnectorCard, { key: request.id, sessionId, bot, request, actions })))
}
-// What the user approves is what goes out: sender, recipients, subject, the
-// whole body, and the attachments, all shown literally.
-function mailView(request, roster, settled = false) {
+const RULE_LABELS = {
+ 'allow-recipient': 'Allow recipient',
+ 'require-approval': 'Needs approval',
+ 'no-draft': 'Turn off drafts for this Bot',
+}
+
+function MailApprovalMenu({ bot, request, rule, onPick, actions, disabled = false }) {
+ const [open, setOpen] = useState(false)
+ const root = useRef(null)
+ useEffect(() => {
+ if (!open) return undefined
+ const away = (event) => { if (!root.current?.contains(event.target)) setOpen(false) }
+ const key = (event) => { if (event.key === 'Escape') setOpen(false) }
+ document.addEventListener('pointerdown', away, true)
+ document.addEventListener('keydown', key)
+ return () => { document.removeEventListener('pointerdown', away, true); document.removeEventListener('keydown', key) }
+ }, [open])
+ const choose = (mode) => {
+ setOpen(false)
+ onPick(mode)
+ void Promise.resolve(actions.mailRuleSet?.({
+ mode,
+ botId: bot.id,
+ recipients: [request.to, request.cc, request.bcc].filter(Boolean).join(', '),
+ })).catch(() => {})
+ }
+ return h('div', { ref: root, className: 'bt-mail-rule-wrap' },
+ h('button', {
+ type: 'button', className: 'bt-mail-rule-btn', disabled,
+ 'aria-haspopup': 'menu', 'aria-expanded': open,
+ onClick: () => setOpen(v => !v),
+ }, t(RULE_LABELS[rule] ?? 'Needs approval'), h(ChevronDownIcon)),
+ open ? h('div', { className: 'dv-menu bt-mail-rule-menu', role: 'menu' },
+ ['allow-recipient', 'require-approval', 'no-draft'].map(mode => h('button', {
+ key: mode, type: 'button', role: 'menuitemradio', 'aria-checked': rule === mode,
+ onClick: () => choose(mode),
+ }, h('span', { className: 'bt-mail-rule-item-text' }, t(RULE_LABELS[mode])), rule === mode ? h(CheckIcon) : null)),
+ h('div', { className: 'dv-menu-sep', role: 'separator' }),
+ h('button', {
+ type: 'button', role: 'menuitem',
+ onClick: () => { setOpen(false); actions.openConnectors?.() },
+ }, h('span', { className: 'bt-mail-rule-item-text' }, t('Manage rules')))) : null)
+}
+
+function mailFrom(request, roster) {
const account = (roster?.connectors?.mail?.accounts ?? []).find(entry => entry.id === request.account)
- const from = account?.address ?? request.account
- const route = [
- [t('From'), from], [t('To'), request.to], [t('Cc'), request.cc], [t('Bcc'), request.bcc],
- ].filter(([, value]) => value).map(([label, value]) => `${literal(label)} ${codeSpan(value)}`).join('\\\n')
+ return account?.address ?? request.account ?? ''
+}
+
+// The mail draft card is a show_view form card: the user can edit the subject,
+// recipients, CC, and body right in the card before pressing Send, or discard it.
+function mailView(request, roster, settled = false) {
+ const from = mailFrom(request, roster)
const attachments = request.attachmentDetails?.length
? t('Attachments: {names}', { names: request.attachmentDetails.map(a => a.size !== undefined ? `${a.name} (${humanSize(a.size)})` : a.name).join(', ') })
: ''
const done = request.status === 'sent' ? t('Sent') : request.status === 'failed' ? t('Failed') : t('Send')
+ const fields = [
+ { id: 'subject', label: '', value: String(request.subject ?? ''), placeholder: t('Subject') },
+ { id: 'from', label: t('From'), value: String(from), readOnly: true },
+ { id: 'to', label: t('To'), value: String(request.to ?? ''), placeholder: '[email protected]' },
+ ...(settled && !request.cc ? [] : [{ id: 'cc', label: t('Cc'), value: String(request.cc ?? ''), placeholder: '[email protected]' }]),
+ ...(request.bcc ? [{ id: 'bcc', label: t('Bcc'), value: String(request.bcc ?? ''), placeholder: '[email protected]' }] : []),
+ { id: 'body', label: '', value: String(request.body ?? ''), multiline: true, placeholder: t('Write a message…') },
+ ]
return {
type: 'stack',
children: [
- route ? { type: 'text', tone: 'muted', text: route } : null,
- request.subject ? { type: 'text', text: `**${literal(request.subject)}**` } : null,
- String(request.body ?? '').trim() ? { type: 'text', text: literalBlock(request.body) } : null,
+ {
+ type: 'form',
+ id: 'send',
+ submitLabel: settled ? done : t('Send'),
+ cancelLabel: settled ? t('Discarded') : t('Discard'),
+ fields,
+ },
attachments ? { type: 'text', tone: 'muted', text: literal(attachments) } : null,
- { type: 'confirm', id: 'send', confirmLabel: settled ? done : t('Send'), cancelLabel: settled ? t('Canceled') : t('Cancel') },
].filter(Boolean),
}
}
export function MailSendCard({ sessionId, bot, request, roster, actions, inline = false }) {
const [busy, setBusy] = useState(false)
+ const [rule, setRule] = useState('require-approval')
const busyRef = useRef(false)
- const answer = (send) => {
+ const answer = (values) => {
if (busyRef.current) return
busyRef.current = true
setBusy(true)
- void Promise.resolve(actions.mailSendAnswer(request.id, send ? 'send' : 'cancel')).catch(() => {}).finally(() => { busyRef.current = false; setBusy(false) })
+ const send = values?.canceled !== true && values?.fields !== undefined
+ void Promise.resolve(actions.mailSendAnswer(request.id, send ? 'send' : 'cancel', send ? { fields: values.fields, rule } : { rule })).catch(() => {}).finally(() => { busyRef.current = false; setBusy(false) })
}
return h(RequestView, {
sessionId, kind: 'mail', request, actions, inline, busy,
- title: t('{bot} wants to send an email', { bot: bot.name }),
+ title: t('Mail'),
+ icon: h(MailIcon),
+ footStart: h(MailApprovalMenu, { bot, request, rule, onPick: setRule, actions, disabled: busy }),
view: mailView(request, roster),
onAnswer: answer,
})
}
-function SettledMail({ bot, request, roster }) {
+function SettledMail({ request, roster }) {
+ const from = mailFrom(request, roster)
+ const sent = request.status === 'sent' || request.status === 'failed'
return h(ViewCard, {
- title: t('{bot} wants to send an email', { bot: bot.name }),
+ title: t('Mail'),
+ icon: h(MailIcon),
view: mailView(request, roster, true),
settled: true,
- answer: { action: 'send', values: { confirmed: request.status === 'sent' || request.status === 'failed' } },
+ answer: {
+ action: 'send',
+ values: sent
+ ? { fields: { subject: String(request.subject ?? ''), from: String(from), to: String(request.to ?? ''), cc: String(request.cc ?? ''), bcc: String(request.bcc ?? ''), body: String(request.body ?? '') } }
+ : { canceled: true },
+ },
})
}
@@ -535,4 +635,13 @@ export const CONNECTOR_CSS = `
.bt-mail-providers .bt-secret-seg[aria-checked=true]{background:var(--bt-active)}
.bt-connector-bot .bt-set-copy{min-width:0}
.bt-mail-open{text-decoration:none}
+.bt-mail-rule-wrap{position:relative;display:inline-flex;align-items:center}
+.bt-mail-rule-btn{display:inline-flex;align-items:center;gap:4px;height:30px;padding:0 8px;border:0;border-radius:8px;background:none;color:var(--bt-ink-2);font:inherit;font-size:13px;font-weight:500;cursor:pointer;transition:background-color .12s ease,color .12s ease}
+.bt-mail-rule-btn:hover:not(:disabled){background:var(--bt-hover);color:var(--bt-ink)}
+.bt-mail-rule-btn:disabled{opacity:.4;cursor:default}
+.bt-mail-rule-btn svg{width:13px;height:13px;color:var(--bt-ink-2)}
+.dv-menu.bt-mail-rule-menu{position:absolute;left:0;bottom:calc(100% + 6px);z-index:20;min-width:190px;--dv-origin:bottom left}
+.dv-menu.bt-mail-rule-menu button{justify-content:space-between;gap:12px}
+.bt-mail-rule-item-text{flex:1 1 auto;min-width:0}
+.bt-mail-rules{display:flex;flex-direction:column;gap:8px}
`
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index 26f2cd54..54081ee1 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -1272,6 +1272,15 @@ const ZH = {
'No connectors connected': '未连接任何连接器',
'{bot} needs {name}': '{bot} 需要 {name}',
'{bot} wants to send an email': '{bot} 想发送一封邮件',
+ 'Mail': '邮件',
+ 'Subject': '主题',
+ 'Write a message…': '写邮件正文…',
+ 'Discard': '丢弃',
+ 'Discarded': '已丢弃',
+ 'Allow recipient': '允许收件人',
+ 'Turn off drafts for this Bot': '为此 Bot 关闭草稿',
+ 'Manage rules': '管理规则',
+ 'Sending rules': '发信规则',
'From': '发件人',
'To': '收件人',
'Cc': '抄送',
diff --git a/ds-bot/src/client/team-actions.js b/ds-bot/src/client/team-actions.js
index 73eb05ec..dcb1f1d3 100644
--- a/ds-bot/src/client/team-actions.js
+++ b/ds-bot/src/client/team-actions.js
@@ -152,7 +152,8 @@ export function teamActions({ call, after, partFor, roster, ui, live, cards, hel
connectorRequestCancel: requestId => after(call('connector-request-cancel', { requestId })),
mailAccountAdd: payload => after(call('mail-account-add', payload)),
mailAccountRemove: id => after(call('mail-account-remove', { id })),
- mailSendAnswer: (requestId, choice) => after(call('mail-send-answer', { requestId, choice })),
+ mailRuleSet: payload => after(call('mail-rule-set', payload)),
+ mailSendAnswer: (requestId, choice, extra = {}) => after(call('mail-send-answer', { requestId, choice, ...extra })),
mailSignInCode: payload => after(call('mail-sign-in-code', payload)),
saveCapability: capability => after(call('capability-save', capability)),
deleteCapability: name => after(call('capability-delete', { name })),
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index 055088db..6fae7f29 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -420,6 +420,7 @@ export function install(rt) {
case 'connector-request-cancel':
case 'mail-account-add':
case 'mail-account-remove':
+ case 'mail-rule-set':
case 'mail-send-answer':
case 'mail-sign-in-code':
await rt.load()
diff --git a/ds-bot/src/host/connectors/mail/index.js b/ds-bot/src/host/connectors/mail/index.js
index 5d32e0fb..07e9bd04 100644
--- a/ds-bot/src/host/connectors/mail/index.js
+++ b/ds-bot/src/host/connectors/mail/index.js
@@ -14,6 +14,31 @@ import { refreshTokens, invalidGrant, discover, beginBrowser, exchange } from '.
const GOOGLE_SCOPES = 'openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/gmail.modify'
const MAX_REQUESTS = 20
+function parseAddresses(raw) {
+ const out = []
+ for (const part of String(raw ?? '').split(/[,;]+/)) {
+ const text = part.trim()
+ if (text === '') continue
+ const angle = text.match(/<([^<>\s@]+@[^<>\s@]+)>/i)
+ const addr = (angle ? angle[1] : text).trim().toLowerCase()
+ if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(addr) && !out.includes(addr)) out.push(addr)
+ }
+ return out
+}
+
+function allAddressesAllowed(to, cc, bcc, allowed) {
+ const set = new Set((Array.isArray(allowed) ? allowed : []).map(a => String(a).toLowerCase()))
+ if (set.size === 0) return false
+ const parts = [to, cc, bcc].flatMap(raw => String(raw ?? '').split(/[,;]+/)).map(s => s.trim()).filter(Boolean)
+ if (parts.length === 0) return false
+ for (const part of parts) {
+ const angle = part.match(/<([^<>\s@]+@[^<>\s@]+)>/i)
+ const addr = (angle ? angle[1] : part).trim().toLowerCase()
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(addr) || !set.has(addr)) return false
+ }
+ return true
+}
+
export function install(rt, host) {
const { state } = rt
const sessions = new Map()
@@ -245,6 +270,21 @@ export function install(rt, host) {
replyTo: args.reply_to ? String(args.reply_to) : undefined,
status: 'pending', askedAt: Date.now(),
}
+ const skipDraft = !bot.private && (
+ (state.connectors?.mail?.noDraftFor ?? []).includes(bot.id)
+ || allAddressesAllowed(request.to, request.cc, request.bcc, state.connectors?.mail?.allowedRecipients)
+ )
+ if (skipDraft) {
+ const session = await connect(account)
+ const attachments = (request.attachments ?? []).map(name => ({ filename: name, path: realpathSync(resolve(dir ?? '', name)) }))
+ await session.send({ to: request.to, cc: request.cc || undefined, bcc: request.bcc || undefined, subject: request.subject, text: request.body, attachments, ...(request.replyTo ? { inReplyTo: request.replyTo } : {}) })
+ request.status = 'sent'
+ request.settledAt = Date.now()
+ list.push(request)
+ while (list.length > MAX_REQUESTS) { const at = list.findIndex(entry => entry.status !== 'pending'); list.splice(at === -1 ? 0 : at, 1) }
+ await rt.save()
+ return `Sent "${request.subject}" to ${request.to} from ${account.address}.`
+ }
for (const old of list) if (old.status === 'pending') { old.status = 'canceled'; old.settledAt = Date.now() }
list.push(request)
while (list.length > MAX_REQUESTS) { const at = list.findIndex(entry => entry.status !== 'pending'); list.splice(at === -1 ? 0 : at, 1) }
@@ -289,14 +329,50 @@ export function install(rt, host) {
await rt.deliver({ toId: botId, role: 'mail', text }).catch(error => rt.warn('ds-bot: mail note to %s failed: %s', botId, error))
}
+ const applyRules = (patch) => {
+ const mail = state.connectors?.mail ?? {}
+ let allowed = [...(mail.allowedRecipients ?? [])]
+ let noDraft = [...(mail.noDraftFor ?? [])]
+ const addAddrs = (raw) => {
+ for (const addr of parseAddresses(Array.isArray(raw) ? raw.join(', ') : raw)) {
+ if (!allowed.includes(addr)) allowed.push(addr)
+ }
+ }
+ const dropAddrs = (raw) => {
+ const drop = new Set(parseAddresses(Array.isArray(raw) ? raw.join(', ') : raw))
+ allowed = allowed.filter(addr => !drop.has(addr))
+ }
+ if (patch.mode === 'allow-recipient') {
+ addAddrs(patch.recipients ?? patch.address ?? '')
+ if (typeof patch.botId === 'string') noDraft = noDraft.filter(id => id !== patch.botId)
+ } else if (patch.mode === 'no-draft') {
+ if (typeof patch.botId === 'string' && rt.botOf(patch.botId) && !noDraft.includes(patch.botId)) noDraft.push(patch.botId)
+ } else if (patch.mode === 'require-approval') {
+ if (typeof patch.botId === 'string') noDraft = noDraft.filter(id => id !== patch.botId)
+ if (patch.recipients || patch.address) dropAddrs(patch.recipients ?? patch.address)
+ }
+ if (patch.addRecipient) addAddrs(patch.addRecipient)
+ if (patch.removeRecipient) dropAddrs(patch.removeRecipient)
+ if (typeof patch.botId === 'string' && typeof patch.noDraft === 'boolean') {
+ noDraft = patch.noDraft
+ ? (rt.botOf(patch.botId) && !noDraft.includes(patch.botId) ? [...noDraft, patch.botId] : noDraft)
+ : noDraft.filter(id => id !== patch.botId)
+ }
+ state.connectors = {
+ ...(state.connectors ?? {}),
+ mail: { ...mail, allowedRecipients: allowed, noDraftFor: noDraft },
+ }
+ }
+
const endpoints = {
async 'mail-account-add'(body) {
const address = String(body.address ?? '').trim().toLowerCase()
- if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(address)) throw new Error('Enter an email address')
if (body.google === true) {
if (!googleReady()) throw new Error('Google sign-in is not available in this build')
+ if (address !== '' && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(address)) throw new Error('Enter an email address')
return beginGoogle(address)
}
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(address)) throw new Error('Enter an email address')
if (adding.has(address)) return adding.get(address)
const pending = (async () => {
const password = String(body.password ?? '').trim()
@@ -355,6 +431,11 @@ export function install(rt, host) {
syncTools()
return mailView()
},
+ async 'mail-rule-set'(body) {
+ applyRules(body ?? {})
+ await rt.save()
+ return mailView()
+ },
async 'mail-send-answer'(body) {
const found = (() => {
for (const [botId, list] of Object.entries(state.mailRequests ?? {})) {
@@ -365,6 +446,16 @@ export function install(rt, host) {
})()
if (found === undefined || found.request.status !== 'pending') throw new Error('This card was already answered')
const { botId, request } = found
+ if (body.fields && typeof body.fields === 'object' && !Array.isArray(body.fields)) {
+ if (typeof body.fields.to === 'string' && body.fields.to.trim() !== '') request.to = body.fields.to.trim()
+ if (typeof body.fields.cc === 'string') request.cc = body.fields.cc.trim()
+ if (typeof body.fields.bcc === 'string') request.bcc = body.fields.bcc.trim()
+ if (typeof body.fields.subject === 'string') request.subject = body.fields.subject.trim()
+ if (typeof body.fields.body === 'string') request.body = body.fields.body
+ }
+ if (typeof body.rule === 'string') {
+ applyRules({ mode: body.rule, botId, recipients: [request.to, request.cc, request.bcc].filter(Boolean).join(', ') })
+ }
if (body.choice !== 'send') {
request.status = 'canceled'; request.settledAt = Date.now()
await rt.save()
@@ -408,7 +499,7 @@ export function install(rt, host) {
async function beginGoogle(address) {
const client = googleClient()
const discovery = await discover('https://accounts.google.com', { originFallback: true, fetch: rt.config.mail?.fetch ?? fetch })
- const pending = { discovery, address }
+ const pending = { discovery, address: address || undefined }
googlePendings.set(address, pending)
const { createServer } = await import('node:http')
const listener = createServer((req, res) => {
@@ -467,6 +558,8 @@ export function install(rt, host) {
...(account.error ? { error: account.error } : {}),
})),
google: googleReady(),
+ allowedRecipients: state.connectors?.mail?.allowedRecipients ?? [],
+ noDraftFor: state.connectors?.mail?.noDraftFor ?? [],
...(googlePendings.size > 0 ? { pending: [...googlePendings.values()].map(p => ({ kind: 'browser', url: p.url, address: p.address })) } : {}),
})
diff --git a/ds-bot/test/connectors-engine.test.js b/ds-bot/test/connectors-engine.test.js
index 5f9c52b9..3a4b500d 100644
--- a/ds-bot/test/connectors-engine.test.js
+++ b/ds-bot/test/connectors-engine.test.js
@@ -633,10 +633,36 @@ test('mail account add verifies before saving; a bad code fails cleanly; send ne
assert.equal(sessions.get(addressAt('163.com')).calls.filter(c => c[0] === 'send').length, 0)
await send.execute({ to: '[email protected]', subject: 'Hi2', body: 'B' }, { agent: { id: 'm1' }, callId: 'call-2', concludeTurn: () => {} })
const request2 = rt.state.mailRequests.m1.at(-1)
- await rt.connectorEndpoint('mail-send-answer', { requestId: request2.id, choice: 'send' })
+ await rt.connectorEndpoint('mail-send-answer', {
+ requestId: request2.id, choice: 'send',
+ fields: { to: '[email protected]', cc: '[email protected]', subject: 'Hi2 edited', body: 'Edited B' },
+ rule: 'allow-recipient',
+ })
const sent = sessions.get(addressAt('163.com')).calls.filter(c => c[0] === 'send')
assert.equal(sent.length, 1)
- assert.equal(sent[0][1].subject, 'Hi2')
+ assert.equal(sent[0][1].to, '[email protected]')
+ assert.equal(sent[0][1].cc, '[email protected]')
+ assert.equal(sent[0][1].subject, 'Hi2 edited')
+ assert.equal(sent[0][1].text, 'Edited B')
+ assert.deepEqual(rt.mailView().allowedRecipients, ['[email protected]', '[email protected]'])
+ // Allowed recipients skip the draft card and send right away; an unknown recipient still requires confirmation.
+ let concludedAllowed = false
+ const autoReply = await send.execute({ to: '[email protected]', subject: 'Auto', body: 'Quick' }, { agent: { id: 'm1' }, callId: 'call-3', concludeTurn: () => { concludedAllowed = true } })
+ assert.match(String(autoReply), /Sent "Auto" to edited@test\.dev/)
+ assert.equal(concludedAllowed, false)
+ assert.equal(sessions.get(addressAt('163.com')).calls.filter(c => c[0] === 'send').length, 2)
+ let concludedMixed = false
+ await send.execute({ to: '[email protected]', cc: '[email protected]', subject: 'Mixed', body: 'Hold' }, { agent: { id: 'm1' }, callId: 'call-4', concludeTurn: () => { concludedMixed = true } })
+ assert.equal(concludedMixed, true, 'any unapproved recipient in cc still requires confirmation')
+ // Turning off drafts for a Bot sends without confirmation; restoring Needs approval brings the card back.
+ await rt.connectorEndpoint('mail-rule-set', { mode: 'no-draft', botId: 'm1' })
+ assert.deepEqual(rt.mailView().noDraftFor, ['m1'])
+ let concludedNoDraft = false
+ await send.execute({ to: '[email protected]', subject: 'NoDraft', body: 'Go' }, { agent: { id: 'm1' }, callId: 'call-5', concludeTurn: () => { concludedNoDraft = true } })
+ assert.equal(concludedNoDraft, false)
+ await rt.connectorEndpoint('mail-rule-set', { botId: 'm1', noDraft: false, removeRecipient: '[email protected], [email protected]' })
+ assert.deepEqual(rt.mailView().noDraftFor, [])
+ assert.deepEqual(rt.mailView().allowedRecipients, [])
// A draft never draws a card.
const before = (rt.state.mailRequests.m1 ?? []).length
assert.match(String(await draft.execute({ to: '[email protected]', subject: 'D', body: 'x' }, exec)), /Draft saved/)
@@ -815,6 +841,29 @@ test('OAuth loopback keeps an error listener after binding, including repeated e
})
})
+test('Google sign-in without an address still reaches the browser flow', async (t) => {
+ const oldId = process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_ID
+ const oldSecret = process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_SECRET
+ process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_ID = 'google-test'
+ process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_SECRET = 'google-test-secret'
+ t.after(() => {
+ if (oldId === undefined) delete process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_ID
+ else process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_ID = oldId
+ if (oldSecret === undefined) delete process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_SECRET
+ else process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_SECRET = oldSecret
+ })
+ const home = teamHome()
+ const ctx = fakeContext()
+ const rt = createRuntime(ctx, { home, github: false, mail: { fetch: async url => {
+ if (String(url).includes('oauth-authorization-server')) return json(AS)
+ return notFound()
+ } } })
+ t.after(async () => { await ctx.dispose(); rmSync(home, { recursive: true, force: true }) })
+ await rt.load()
+ const view = await rt.connectorEndpoint('mail-account-add', { google: true })
+ assert.ok(new URL(view.pending[0].url).searchParams.get('redirect_uri').startsWith('http://127.0.0.1:'))
+})
+
test('Google loopback catches a rejected sign-in callback instead of an unhandled rejection', async (t) => {
const oldId = process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_ID
const oldSecret = process.env.DS_BOT_GOOGLE_OAUTH_CLIENT_SECRET
diff --git a/ds-bot/test/connectors-page.test.js b/ds-bot/test/connectors-page.test.js
index 03878c75..dc27c087 100644
--- a/ds-bot/test/connectors-page.test.js
+++ b/ds-bot/test/connectors-page.test.js
@@ -32,6 +32,8 @@ const expand = (node) => {
if (typeof node.type === 'function') return expand(node.type(node.props))
return { ...node, props: { ...(node.props ?? {}), children: expand(node.props?.children) } }
}
+let active = () => expand(MailSection(props))
+const rerender = () => { idx = 0; concrete = active() }
const react = {
createContext: (initial) => { const ctx = { value: initial }; ctx.Provider = ({ value, children }) => { ctx.value = value; return children }; return ctx },
useContext: ctx => ctx.value,
@@ -43,7 +45,7 @@ const react = {
useState: (init) => {
const i = idx++
if (!(i in slots)) slots[i] = typeof init === 'function' ? init() : init
- return [slots[i], (value) => { slots[i] = typeof value === 'function' ? value(slots[i]) : value; render() }]
+ return [slots[i], (value) => { slots[i] = typeof value === 'function' ? value(slots[i]) : value; rerender() }]
},
useMemo: make => make(), useRef: current => ({ current }), useId: () => 'id',
}
@@ -56,8 +58,8 @@ runInNewContext(outputFiles[0].text, {
require: name => (name === 'react' ? react : name === 'react-dom' ? { createPortal: node => node } : {}),
})
const { MailSection, MailToolCell } = module.exports
-const render = () => { idx = 0; concrete = expand(MailSection(props)) }
-const renderCell = (cellProps) => { slots.length = 0; idx = 0; concrete = expand(MailToolCell(cellProps)) }
+const render = () => { active = () => expand(MailSection(props)); rerender() }
+const renderCell = (cellProps) => { slots.length = 0; active = () => expand(MailToolCell(cellProps)); rerender() }
const flatten = (node, out = []) => {
if (node === null || node === undefined || node === false || node === true) return out
@@ -155,7 +157,7 @@ test('a busy mail add blocks a second click and a good add clears the fields', a
assert.equal(collect(n => n.type === 'input' && n.props?.['aria-label'] === 'SMTP host')[0].props.value, '', 'SMTP host cleared')
})
-test('the mail send card is the show_view card and shows the mail literally', async () => {
+test('the mail send card is an editable show_view form card with the approval rule menu', async () => {
const bot = { id: 'b1', name: 'Chief' }
const body = 'Hi **all**\n<!-- hidden --> [link](https://x.test)\n\nBye'
const roster = {
@@ -166,23 +168,63 @@ test('the mail send card is the show_view card and shows the mail literally', as
},
}
const answers = []
- renderCell({ sessionId: 's1', callId: 'c1', roster, actions: { mailSendAnswer: (...args) => { answers.push(args); return Promise.resolve() } } })
+ const ruleSets = []
+ let opened = false
+ renderCell({
+ sessionId: 's1', callId: 'c1', roster,
+ actions: {
+ mailSendAnswer: (...args) => { answers.push(args); return Promise.resolve() },
+ mailRuleSet: (payload) => { ruleSets.push(payload); return Promise.resolve() },
+ openConnectors: () => { opened = true },
+ },
+ })
const card = collect(n => String(n.props?.className ?? '').split(' ').includes('dv-view'))[0]
assert.ok(card, 'view card root')
assert.ok(card.props.className.split(' ').includes('dv-q'), 'framed like the show_view answer cards')
- assert.equal(collect(n => /\bbt-(mail|secret|learning)/.test(String(n.props?.className ?? ''))).length, 0, 'no bespoke card classes')
- assert.match(flatten(collect(n => n.props?.className === 'dv-view-title')[0]).join(''), /Chief wants to send an email/)
+ assert.equal( flatten(collect(n => n.props?.className === 'dv-view-title')[0]).join(''), 'Mail')
+ assert.ok(collect(n => n.props?.className === 'dv-view-icon')[0], 'mail icon in header')
+ // Prefilled fields: subject, readOnly from, editable to, editable cc, multiline body.
+ const subjectInput = collect(n => n.type === 'input' && n.props?.['aria-label'] === 'Subject')[0]
+ const fromInput = collect(n => n.type === 'input' && n.props?.['aria-label'] === 'From')[0]
+ const toInput = collect(n => n.type === 'input' && n.props?.['aria-label'] === 'To')[0]
+ const ccInput = collect(n => n.type === 'input' && n.props?.['aria-label'] === 'Cc')[0]
+ const bodyArea = collect(n => n.type === 'textarea' && n.props?.['aria-label'] === 'Write a message…')[0]
+ assert.equal(subjectInput.props.value, 'Weekly_1')
+ assert.equal(fromInput.props.value, '[email protected]')
+ assert.equal(fromInput.props.readOnly, true)
+ assert.equal(toInput.props.value, '[email protected]')
+ assert.equal(ccInput.props.value, '')
+ assert.equal(bodyArea.props.value, body, 'body stays literal in textarea')
const texts = collect(n => typeof n.props?.text === 'string' && n.props?.variant === 'compact').map(n => n.props.text)
- assert.ok(texts.some(text => text.includes('From ` [email protected] `') && text.includes('To ` [email protected] `')), 'sender and recipient')
- assert.ok(texts.includes('**Weekly\\_1**'), 'subject, escaped')
- assert.ok(texts.includes('Hi \\*\\*all\\*\\*\\\n\\<\\!\\-\\- hidden \\-\\-\\> \\[link\\]\\(https\\://x\\.test\\)\n\nBye'), 'body shown literally, breaks kept')
assert.ok(texts.some(text => text.includes('report\\.pdf \\(2 KB\\)')), 'attachments')
+ // Approval menu defaults to Needs approval.
+ const ruleBtn = collect(n => n.type === 'button' && n.props?.className === 'bt-mail-rule-btn')[0]
+ assert.equal(flatten(ruleBtn).join(''), 'Needs approval')
+ ruleBtn.props.onClick()
+ click('Allow recipient')
+ await flush()
+ assert.equal(ruleSets.length, 1)
+ assert.equal(ruleSets[0].mode, 'allow-recipient')
+ assert.equal(flatten(collect(n => n.type === 'button' && n.props?.className === 'bt-mail-rule-btn')[0]).join(''), 'Allow recipient')
+ // Manage rules opens Connectors settings.
+ collect(n => n.type === 'button' && n.props?.className === 'bt-mail-rule-btn')[0].props.onClick()
+ click('Manage rules')
+ assert.equal(opened, true)
+ // Edit recipient and body in the card, then press Send.
+ toInput.props.onChange({ target: { value: '[email protected]' } })
+ collect(n => n.type === 'textarea' && n.props?.['aria-label'] === 'Write a message…')[0].props.onChange({ target: { value: 'Edited body' } })
const send = collect(n => n.type === 'button' && n.props?.className === 'dv-q-submit')[0]
assert.equal(flatten(send).join(''), 'Send')
- assert.equal(flatten(collect(n => n.type === 'button' && n.props?.className === 'dv-q-btn')[0]).join(''), 'Cancel')
- send.props.onClick()
+ assert.equal(flatten(collect(n => n.type === 'button' && n.props?.className === 'dv-q-btn')[0]).join(''), 'Discard')
+ const formNode = collect(n => n.type === 'form' && n.props?.className === 'dv-widget-form')[0]
+ formNode.props.onSubmit({ preventDefault() {} })
await flush()
- assert.deepEqual(answers, [['r1', 'send']])
+ assert.equal(answers.length, 1)
+ assert.equal(answers[0][0], 'r1')
+ assert.equal(answers[0][1], 'send')
+ assert.equal(answers[0][2].rule, 'allow-recipient')
+ assert.equal(answers[0][2].fields.to, '[email protected]')
+ assert.equal(answers[0][2].fields.body, 'Edited body')
})
test('a failed mail add shows the host message inside the form', async () => {