dsh-im-lark 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -109,7 +109,7 @@ dsh plugin --profile web add file:/绝对路径/dsh-im-lark
109
109
  failureReminders: true # 独立模式:回合失败或被外部中止时立刻提醒
110
110
  ```
111
111
 
112
- 面板能改的项会落到 `$DSH_HOME/.dsh-im-lark/config.json`,卸载重装后沿用。凭据单独存 `credentials.json`,目录 0700、文件 0600,日志与面板快照里只出现 App ID 尾号。
112
+ 面板能改的项会落到 `$DSH_HOME/.dsh-im-lark/config.json`,卸载重装后沿用。凭据单独存 `credentials.json`,目录 0700、文件 0600,日志与错误信息里只出现 App ID 尾号;面板显示完整 App ID 与绑定时间,Secret 不回显。
113
113
 
114
114
  ## 独立会话命令
115
115
 
package/lib/client.js CHANGED
@@ -74,7 +74,6 @@ var en_default = {
74
74
  "panel.refresh": "Refresh",
75
75
  "panel.retry": "Retry",
76
76
  "status.title": "Connection",
77
- "status.connection": "Long connection",
78
77
  "status.appId": "App ID",
79
78
  "status.domain": "Platform",
80
79
  "status.enabled": "Connect Lark",
@@ -91,7 +90,8 @@ var en_default = {
91
90
  "state.failed": "Failed",
92
91
  "credentials.title": "App credentials",
93
92
  "credentials.hint": "From the Lark developer console. Stored locally; the secret is never echoed.",
94
- "credentials.configured": "App ID ends with {appId} \xB7 {domain}",
93
+ "credentials.configured": "Bound to {appId} \xB7 {domain}",
94
+ "credentials.boundAt": "Bound since {boundAt}",
95
95
  "credentials.manual": "Enter credentials manually",
96
96
  "credentials.appId": "App ID",
97
97
  "credentials.appSecret": "App Secret",
@@ -105,7 +105,7 @@ var en_default = {
105
105
  "credentials.probing": "Testing\u2026",
106
106
  "credentials.clear": "Clear credentials",
107
107
  "credentials.clearTitle": "Clear credentials?",
108
- "credentials.clearHint": "This removes the credentials for the app whose ID ends with {appId} (App ID and App Secret).",
108
+ "credentials.clearHint": "This removes the credentials for {appId} (App ID and App Secret).",
109
109
  "credentials.clearWarning": "The long connection closes immediately; reconnecting requires entering them again.",
110
110
  "credentials.clearConfirm": "Clear",
111
111
  "credentials.cleared": "Credentials cleared",
@@ -186,7 +186,6 @@ var zh_default = {
186
186
  "panel.refresh": "\u5237\u65B0",
187
187
  "panel.retry": "\u91CD\u8BD5",
188
188
  "status.title": "\u8FDE\u63A5\u72B6\u6001",
189
- "status.connection": "\u957F\u8FDE\u63A5",
190
189
  "status.appId": "App ID",
191
190
  "status.domain": "\u5E73\u53F0",
192
191
  "status.enabled": "\u63A5\u5165\u98DE\u4E66",
@@ -203,7 +202,8 @@ var zh_default = {
203
202
  "state.failed": "\u8FDE\u63A5\u5931\u8D25",
204
203
  "credentials.title": "\u5E94\u7528\u51ED\u636E",
205
204
  "credentials.hint": "\u5728\u98DE\u4E66\u5F00\u653E\u5E73\u53F0\u300C\u51ED\u8BC1\u4E0E\u57FA\u7840\u4FE1\u606F\u300D\u91CC\u83B7\u53D6\u3002\u53EA\u4FDD\u5B58\u5728\u672C\u673A\uFF0C\u9762\u677F\u4E0D\u4F1A\u56DE\u663E Secret\u3002",
206
- "credentials.configured": "\u5DF2\u914D\u7F6E App ID \u5C3E\u53F7 {appId} \xB7 {domain}",
205
+ "credentials.configured": "\u5DF2\u7ED1\u5B9A {appId} \xB7 {domain}",
206
+ "credentials.boundAt": "\u7ED1\u5B9A\u4E8E {boundAt}",
207
207
  "credentials.manual": "\u624B\u52A8\u586B\u5199\u51ED\u636E",
208
208
  "credentials.appId": "App ID",
209
209
  "credentials.appSecret": "App Secret",
@@ -217,7 +217,7 @@ var zh_default = {
217
217
  "credentials.probing": "\u6B63\u5728\u81EA\u68C0\u2026",
218
218
  "credentials.clear": "\u6E05\u9664\u51ED\u636E",
219
219
  "credentials.clearTitle": "\u6E05\u9664\u51ED\u636E\uFF1F",
220
- "credentials.clearHint": "\u5C06\u6E05\u9664\u5C3E\u53F7 {appId} \u7684\u5E94\u7528\u51ED\u636E\uFF08App ID \u4E0E App Secret\uFF09\u3002",
220
+ "credentials.clearHint": "\u5C06\u6E05\u9664 {appId} \u7684\u5E94\u7528\u51ED\u636E\uFF08App ID \u4E0E App Secret\uFF09\u3002",
221
221
  "credentials.clearWarning": "\u6E05\u9664\u540E\u957F\u8FDE\u63A5\u7ACB\u5373\u65AD\u5F00\uFF0C\u91CD\u65B0\u63A5\u5165\u9700\u8981\u518D\u586B\u4E00\u6B21\u51ED\u636E\u3002",
222
222
  "credentials.clearConfirm": "\u6E05\u9664",
223
223
  "credentials.cleared": "\u51ED\u636E\u5DF2\u6E05\u9664",
@@ -744,6 +744,7 @@ function LarkSettingsPanel(props) {
744
744
  const [error, setError] = useState("");
745
745
  const [notice, setNotice] = useState("");
746
746
  const [appId, setAppId] = useState("");
747
+ const appIdPrefilled = useRef(false);
747
748
  const [appSecret, setAppSecret] = useState("");
748
749
  const [domain, setDomain] = useState("feishu");
749
750
  const [registration, setRegistration] = useState(null);
@@ -758,6 +759,11 @@ function LarkSettingsPanel(props) {
758
759
  const applySnapshot = useCallback((next) => {
759
760
  setSnapshot(next);
760
761
  setDomain((current) => current === "" ? next.status.domain : current);
762
+ const bound = next.status.appId;
763
+ if (!appIdPrefilled.current && bound !== null && bound !== "") {
764
+ appIdPrefilled.current = true;
765
+ setAppId((current) => current === "" ? bound : current);
766
+ }
761
767
  }, []);
762
768
  const refresh = useCallback(async (quiet = false) => {
763
769
  try {
@@ -1014,8 +1020,10 @@ function LarkSettingsPanel(props) {
1014
1020
  h(
1015
1021
  "div",
1016
1022
  { className: "lark-rows" },
1017
- row(t("status.connection"), h(Pill, { tone: toneOf(state), dot: true }, t(stateKey(state)))),
1018
- row(t("status.appId"), h("span", { className: "lark-mono" }, status?.appIdTail === null ? t("status.notConfigured") : `\u2026${status?.appIdTail ?? ""}`)),
1023
+ row(
1024
+ t("status.appId"),
1025
+ status?.appId === null || status?.appId === void 0 ? t("status.notConfigured") : h("span", { className: "lark-mono" }, status.appId)
1026
+ ),
1019
1027
  row(t("status.domain"), domainLabel)
1020
1028
  ),
1021
1029
  toggleRow(h(Switch, { checked: settings?.enabled === true, onChange: (value) => toggle("enabled", value), label: t("status.enabled") }), t("status.enabled"), t("status.enabledHint")),
@@ -1040,7 +1048,8 @@ function LarkSettingsPanel(props) {
1040
1048
  "div",
1041
1049
  { className: "lark-card-heading" },
1042
1050
  h("div", { className: "lark-card-title" }, t("credentials.title")),
1043
- !credentialsOpen && credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.configured", { appId: status?.appIdTail ?? "", domain: domainLabel })) : null
1051
+ !credentialsOpen && credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.configured", { appId: status?.appId ?? "", domain: domainLabel })) : null,
1052
+ !credentialsOpen && credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.boundAt", { boundAt: formatBoundAt(status?.boundAt) })) : null
1044
1053
  ),
1045
1054
  h(
1046
1055
  Button,
@@ -1067,7 +1076,7 @@ function LarkSettingsPanel(props) {
1067
1076
  h(ConfirmDialog, {
1068
1077
  open: clearOpen,
1069
1078
  title: t("credentials.clearTitle"),
1070
- lines: [t("credentials.clearHint", { appId: status?.appIdTail ?? "" }), t("credentials.clearWarning")],
1079
+ lines: [t("credentials.clearHint", { appId: status?.appId ?? "" }), t("credentials.clearWarning")],
1071
1080
  cancelLabel: t("common.cancel"),
1072
1081
  confirmLabel: t("credentials.clearConfirm"),
1073
1082
  closeLabel: t("common.close"),
@@ -1077,6 +1086,8 @@ function LarkSettingsPanel(props) {
1077
1086
  credentialsOpen ? h(
1078
1087
  "div",
1079
1088
  { id: "lark-credentials-body", className: "lark-card-body" },
1089
+ credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.configured", { appId: status?.appId ?? "", domain: domainLabel })) : null,
1090
+ credentialsConfigured ? h("div", { className: "lark-card-hint" }, t("credentials.boundAt", { boundAt: formatBoundAt(status?.boundAt) })) : null,
1080
1091
  h("div", { className: "lark-card-hint" }, t("credentials.hint")),
1081
1092
  h(
1082
1093
  "div",
@@ -1322,6 +1333,12 @@ function workspaceOptions(catalog, current, t) {
1322
1333
  function row(label, value) {
1323
1334
  return h("div", { className: "lark-row" }, h("span", { className: "lark-row-label" }, label), h("span", { className: "lark-row-value" }, value));
1324
1335
  }
1336
+ function formatBoundAt(boundAt) {
1337
+ if (boundAt === void 0 || boundAt === null) return "\u2014";
1338
+ const at = new Date(boundAt);
1339
+ const pad = (value) => String(value).padStart(2, "0");
1340
+ return `${at.getFullYear()}-${pad(at.getMonth() + 1)}-${pad(at.getDate())} ${pad(at.getHours())}:${pad(at.getMinutes())}:${pad(at.getSeconds())}`;
1341
+ }
1325
1342
  function fieldRow(label, control) {
1326
1343
  return h(
1327
1344
  "div",
@@ -9,7 +9,7 @@
9
9
  * 出来就回 `invalid-config`。浏览器发来的 JSON 是不可信输入,不把它直接塞进
10
10
  * 运行期,也不把内部错误原文透给页面(可能带本机路径)。
11
11
  *
12
- * 凭据只在保存时经过这里;读取只回 App ID 尾号(`RuntimeStatus.appIdTail`)。
12
+ * 凭据只在保存时经过这里;读取回完整 App ID 与绑定时间(Secret 不出边界)。
13
13
  */
14
14
  import { PANEL_CONTRACT, PLUGIN_VERSION, RPC_CHANNEL, RPC_ENDPOINT, RPC_PREFIX } from "../shared/version.js";
15
15
  import { normalizeQuestionDelayMinutes } from "./config.js";
@@ -74,7 +74,9 @@ export function snapshotOf(deps) {
74
74
  maxText: deps.config.maxText,
75
75
  rpcChannel: RPC_CHANNEL,
76
76
  },
77
+ appId: status.appId,
77
78
  appIdTail: status.appIdTail,
79
+ boundAt: status.boundAt,
78
80
  };
79
81
  }
80
82
  export async function handleEndpoint(deps, endpoint, payload) {
@@ -83,7 +83,9 @@ export class LarkRuntime {
83
83
  status() {
84
84
  const connection = this.#connection?.status() ?? { state: 'idle', since: Date.now(), reconnectAttempts: 0 };
85
85
  return {
86
+ appId: this.#credentials === null ? null : this.#credentials.appId,
86
87
  appIdTail: this.#credentials === null ? null : tailOf(this.#credentials.appId),
88
+ boundAt: this.#credentials?.boundAt ?? null,
87
89
  domain: this.#credentials?.domain ?? this.#deps.config.domain,
88
90
  enabled: this.#settings?.enabled ?? this.#deps.config.enabled,
89
91
  superagent: this.#settings?.superagent ?? this.#deps.config.superagent,
@@ -198,7 +200,7 @@ export class LarkRuntime {
198
200
  }
199
201
  }
200
202
  }
201
- /** App ID 尾号:面板只显示它。 */
203
+ /** App ID 尾号:日志与错误信息用(面板显示完整 App ID)。 */
202
204
  function tailOf(appId) {
203
205
  return appId.length > 6 ? appId.slice(-6) : appId;
204
206
  }
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * 凭据存储与自检。
3
3
  *
4
- * 凭据只落本机状态文件(`0700` 目录、`0600` 文件、原子写),**不进日志、不进面板
5
- * 快照、不随包发布**。面板能看到的只有 App ID 与尾号。
4
+ * 凭据只落本机状态文件(`0700` 目录、`0600` 文件、原子写),**不进日志、不随包
5
+ * 发布**。面板可以显示完整 App ID 与绑定时间(App ID 不是密钥),App Secret 永远
6
+ * 不出这个边界。
6
7
  *
7
8
  * 自检走两条独立的最小请求:先换 `tenant_access_token`(验 app_id/app_secret),
8
9
  * 再查机器人信息(验机器人能力是否开启)。两件事分开报错,面板才能给出
9
10
  * 「密钥不对」和「机器人能力没开」两种不同的提示。
10
11
  */
12
+ import { stat } from 'node:fs/promises';
11
13
  import { join } from 'node:path';
12
14
  import { baseUrlOf } from "../lark/api.js";
13
15
  import { readJsonIfPresent, writePrivateFile } from "./files.js";
@@ -16,9 +18,9 @@ const CREDENTIALS_FILE = 'credentials.json';
16
18
  /** App ID 尾号长度:面板只显示这么多,够区分不同应用就够了。 */
17
19
  const TAIL_LENGTH = 6;
18
20
  /** 面板能看到的凭据摘要。 */
19
- export function summarize(appId, domain) {
21
+ export function summarize(appId, domain, boundAt) {
20
22
  const tail = appId.length > TAIL_LENGTH ? appId.slice(-TAIL_LENGTH) : appId;
21
- return { appIdTail: tail, domain };
23
+ return { appId, appIdTail: tail, domain, ...(boundAt === undefined ? {} : { boundAt }) };
22
24
  }
23
25
  /** 收窄磁盘上的凭据:形状不对就当没配置。 */
24
26
  function normalizeStored(raw) {
@@ -30,15 +32,20 @@ function normalizeStored(raw) {
30
32
  const domain = input.domain === 'lark' ? 'lark' : 'feishu';
31
33
  if (appId === '' || appSecret === '')
32
34
  return undefined;
33
- return { appId, appSecret, domain };
35
+ const boundAt = typeof input.boundAt === 'number' && Number.isFinite(input.boundAt) && input.boundAt > 0
36
+ ? input.boundAt
37
+ : undefined;
38
+ return { appId, appSecret, domain, ...(boundAt === undefined ? {} : { boundAt }) };
34
39
  }
35
40
  export class CredentialStore {
36
41
  #path;
37
42
  #logger;
43
+ #now;
38
44
  #cached;
39
45
  constructor(options) {
40
46
  this.#path = join(options.dataDir, CREDENTIALS_FILE);
41
47
  this.#logger = options.logger ?? {};
48
+ this.#now = options.now ?? Date.now;
42
49
  }
43
50
  /** 读凭据;没有或损坏返回 null。 */
44
51
  async load() {
@@ -49,9 +56,25 @@ export class CredentialStore {
49
56
  if (raw !== undefined && parsed === undefined) {
50
57
  this.#logger.warn?.('凭据文件存在但内容不完整,按未配置处理');
51
58
  }
52
- this.#cached = parsed ?? null;
59
+ this.#cached = parsed === undefined ? null : await this.#withFileTime(parsed);
53
60
  return this.#cached;
54
61
  }
62
+ /**
63
+ * 老凭据没有绑定时间:用文件修改时间兜底(≈ 上次保存凭据的时间)。
64
+ *
65
+ * 只补在内存里,不写盘——写盘会把「猜出来的时间」固化成事实。
66
+ */
67
+ async #withFileTime(app) {
68
+ if (app.boundAt !== undefined)
69
+ return app;
70
+ try {
71
+ const info = await stat(this.#path);
72
+ return { ...app, boundAt: Math.round(info.mtimeMs) };
73
+ }
74
+ catch {
75
+ return app;
76
+ }
77
+ }
55
78
  /** 覆盖保存;返回可以展示的摘要。 */
56
79
  async save(input) {
57
80
  const appId = input.appId.trim();
@@ -60,10 +83,13 @@ export class CredentialStore {
60
83
  throw new Error('App ID 不能为空');
61
84
  if (appSecret === '')
62
85
  throw new Error('App Secret 不能为空');
63
- const payload = { appId, appSecret, domain: input.domain };
86
+ // 绑定时间跟着 App ID 走:同一个应用重复保存(哪怕换了 Secret)保留首次时间。
87
+ const previous = await this.load();
88
+ const boundAt = previous !== null && previous.appId === appId && previous.boundAt !== undefined ? previous.boundAt : this.#now();
89
+ const payload = { appId, appSecret, domain: input.domain, boundAt };
64
90
  await writePrivateFile(this.#path, `${JSON.stringify(payload, null, 2)}\n`);
65
91
  this.#cached = payload;
66
- return summarize(appId, input.domain);
92
+ return summarize(appId, input.domain, boundAt);
67
93
  }
68
94
  /** 清空凭据(卸载应用或换应用时用)。 */
69
95
  async clear() {
@@ -73,7 +99,7 @@ export class CredentialStore {
73
99
  /** 已配置时的摘要;未配置返回 null。 */
74
100
  async summary() {
75
101
  const app = await this.load();
76
- return app ? summarize(app.appId, app.domain) : null;
102
+ return app ? summarize(app.appId, app.domain, app.boundAt) : null;
77
103
  }
78
104
  }
79
105
  /**
@@ -5,7 +5,7 @@
5
5
  * 发布时三处同步——package.json、锁文件(`npm version --no-git-tag-version`)、
6
6
  * 这里。
7
7
  */
8
- export const PLUGIN_VERSION = '0.1.1';
8
+ export const PLUGIN_VERSION = '0.1.2';
9
9
  /** 传输层实现版本:协议客户端行为变化时递增,与插件版本解耦。 */
10
10
  export const CHANNEL_VERSION = '1';
11
11
  /**
package/locale/en.json CHANGED
@@ -5,7 +5,6 @@
5
5
  "panel.refresh": "Refresh",
6
6
  "panel.retry": "Retry",
7
7
  "status.title": "Connection",
8
- "status.connection": "Long connection",
9
8
  "status.appId": "App ID",
10
9
  "status.domain": "Platform",
11
10
  "status.enabled": "Connect Lark",
@@ -22,7 +21,8 @@
22
21
  "state.failed": "Failed",
23
22
  "credentials.title": "App credentials",
24
23
  "credentials.hint": "From the Lark developer console. Stored locally; the secret is never echoed.",
25
- "credentials.configured": "App ID ends with {appId} · {domain}",
24
+ "credentials.configured": "Bound to {appId} · {domain}",
25
+ "credentials.boundAt": "Bound since {boundAt}",
26
26
  "credentials.manual": "Enter credentials manually",
27
27
  "credentials.appId": "App ID",
28
28
  "credentials.appSecret": "App Secret",
@@ -36,7 +36,7 @@
36
36
  "credentials.probing": "Testing…",
37
37
  "credentials.clear": "Clear credentials",
38
38
  "credentials.clearTitle": "Clear credentials?",
39
- "credentials.clearHint": "This removes the credentials for the app whose ID ends with {appId} (App ID and App Secret).",
39
+ "credentials.clearHint": "This removes the credentials for {appId} (App ID and App Secret).",
40
40
  "credentials.clearWarning": "The long connection closes immediately; reconnecting requires entering them again.",
41
41
  "credentials.clearConfirm": "Clear",
42
42
  "credentials.cleared": "Credentials cleared",
package/locale/zh.json CHANGED
@@ -5,7 +5,6 @@
5
5
  "panel.refresh": "刷新",
6
6
  "panel.retry": "重试",
7
7
  "status.title": "连接状态",
8
- "status.connection": "长连接",
9
8
  "status.appId": "App ID",
10
9
  "status.domain": "平台",
11
10
  "status.enabled": "接入飞书",
@@ -22,7 +21,8 @@
22
21
  "state.failed": "连接失败",
23
22
  "credentials.title": "应用凭据",
24
23
  "credentials.hint": "在飞书开放平台「凭证与基础信息」里获取。只保存在本机,面板不会回显 Secret。",
25
- "credentials.configured": "已配置 App ID 尾号 {appId} · {domain}",
24
+ "credentials.configured": "已绑定 {appId} · {domain}",
25
+ "credentials.boundAt": "绑定于 {boundAt}",
26
26
  "credentials.manual": "手动填写凭据",
27
27
  "credentials.appId": "App ID",
28
28
  "credentials.appSecret": "App Secret",
@@ -36,7 +36,7 @@
36
36
  "credentials.probing": "正在自检…",
37
37
  "credentials.clear": "清除凭据",
38
38
  "credentials.clearTitle": "清除凭据?",
39
- "credentials.clearHint": "将清除尾号 {appId} 的应用凭据(App ID 与 App Secret)。",
39
+ "credentials.clearHint": "将清除 {appId} 的应用凭据(App ID 与 App Secret)。",
40
40
  "credentials.clearWarning": "清除后长连接立即断开,重新接入需要再填一次凭据。",
41
41
  "credentials.clearConfirm": "清除",
42
42
  "credentials.cleared": "凭据已清除",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-im-lark",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "把飞书(Lark)接入 DeepSeek Harness 的 IM 桥插件",
6
6
  "license": "MIT",