@chenkai114/dsh-superagent-dingtalk 0.0.2 → 0.0.3

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/cordis.patch.yml CHANGED
@@ -2,8 +2,10 @@
2
2
  # profile supplies the `dsh-superagent` entry's stateDir (see docs/006-deployment.md and examples/profile.cordis.patch.yml); the plugin
3
3
  # refuses to start without stateDir.
4
4
  - insert:
5
+ # 包根:改名后这里若仍写 `dsh-superagent` 就无法解析,整个 orchestrator 起不来,
6
+ # 后续两个 Source 会一直停在 waiting for service: orchestrator。
5
7
  - id: dsh-superagent
6
- name: dsh-superagent
8
+ name: '@chenkai114/dsh-superagent-dingtalk'
7
9
  - id: dsh-superagent-github
8
10
  name: '@chenkai114/dsh-superagent-dingtalk/github-watch'
9
11
  # Optional DingTalk Source; enable it, then set the groups, the dws CLI, and either a Stream robot or a group robot.
package/lib/client.js CHANGED
@@ -514,6 +514,7 @@ window.__ModuleLoader__.load({
514
514
  promptPartEmpty: ["refused", "The “{part}” part cannot be empty; reset it to follow its built-in text"],
515
515
  sourceNotInstalled: ["refused", "The {source} Source kind is not installed"],
516
516
  noLabels: ["refused", "This Source has no names to refresh"],
517
+ noCheck: ["refused", "This Source has no settings probe"],
517
518
  nothingToSync: ["refused", "The {source} Source's part of the Policy has nothing to sync from, or the Source is off or waiting for setup"]
518
519
  };
519
520
  //#endregion
@@ -3569,6 +3570,21 @@ window.__ModuleLoader__.load({
3569
3570
  sourceFilteredLabel: ["被过滤", "Filtered"],
3570
3571
  sourceLatestLabel: ["最近", "Latest"],
3571
3572
  advanced: ["高级", "Advanced"],
3573
+ dingtalkSectionLabel: ["钉钉", "DingTalk"],
3574
+ dingtalkCheckTitle: ["钉钉环境检查", "DingTalk environment check"],
3575
+ dingtalkCheckDws: ["dws 命令行", "dws command line"],
3576
+ dingtalkCheckDwsHint: ["以操作者身份读取群消息、并以机器人身份回帖都依赖它。", "Reads group messages as the operator and posts replies as a bot."],
3577
+ dingtalkCheckStream: ["Stream 机器人凭证", "Stream robot credentials"],
3578
+ dingtalkCheckStreamHint: ["Client ID 与 Client Secret 齐全时,才连得上钉钉的 Stream 长连接。", "A Client ID with its Client Secret is what the Stream connection needs."],
3579
+ dingtalkCheckBots: ["群机器人", "Group bots"],
3580
+ dingtalkCheckBotsHint: ["至少一个群机器人同时有 token 与 *,才有身份可以署名回帖。", "At least one group bot needs both a token and a * to sign a reply."],
3581
+ dingtalkCheckGroups: ["监听的群", "Listened groups"],
3582
+ dingtalkCheckGroupsHint: ["没有群时不会读到任何消息。", "Without a group nothing is read."],
3583
+ checking: ["检查中…", "Checking…"],
3584
+ recheck: ["重新检查", "Check again"],
3585
+ dingtalkMissing: ["钉钉来源未安装。", "The DingTalk Source is not installed."],
3586
+ dingtalkIntro: ["这台机器上的钉钉接入:先看检查结果,再填下面的参数。保存后立即生效。", "The DingTalk connection on this machine: read the checks first, then fill in the settings below. Saving applies at once."],
3587
+ dingtalkPolicyNote: ["谁能发起工作(允许名单)在 dsh-superagent 面板的策略页设置;名单为空时任何请求都不会成为工单。", "Who may originate work — the allowed list — is set on the policy page of the dsh-superagent panel; while it is empty no request becomes a ticket."],
3572
3588
  "sourceState.done": ["运行中", "Running"],
3573
3589
  "sourceState.ongoing": ["启动中", "Starting"],
3574
3590
  "sourceState.warning": ["待处理", "Pending"],
@@ -4121,6 +4137,7 @@ window.__ModuleLoader__.load({
4121
4137
  "userError.promptPartEmpty": ["「{part}」段落不能为空;要沿用内置文本,请恢复此段默认内容。", USER_ERRORS.promptPartEmpty[1]],
4122
4138
  "userError.sourceNotInstalled": ["{source} 来源的插件没有安装。", USER_ERRORS.sourceNotInstalled[1]],
4123
4139
  "userError.noLabels": ["这个来源没有可以刷新的名称。", USER_ERRORS.noLabels[1]],
4140
+ "userError.noCheck": ["这个来源没有可用的检查项。", USER_ERRORS.noCheck[1]],
4124
4141
  "userError.nothingToSync": ["{source} 来源上的策略没有指定从哪里同步,或者这个来源已关闭或在等待部署检查。", USER_ERRORS.nothingToSync[1]],
4125
4142
  "setup.repositoryUnset": ["GitHub 来源没有设置监听的仓库。", SETUP_PROBLEMS.repositoryUnset[1]],
4126
4143
  "setup.foreignFile": ["{file} 不是 dsh-superagent 写入的文件;移走它,或换一个状态目录。", SETUP_PROBLEMS.foreignFile[1]],
@@ -5244,6 +5261,7 @@ window.__ModuleLoader__.load({
5244
5261
  //#endregion
5245
5262
  //#region src/client/source.tsx
5246
5263
  /** Source status view (health, filtered Triggers, dropped replies) and Source settings cards. */
5264
+ /** One Source's settings form: enable switch, status, every field, and the save bar. */
5247
5265
  function SourceCard({ source }) {
5248
5266
  const { t, call } = usePanel();
5249
5267
  const { running } = usePanelData();
@@ -6787,6 +6805,138 @@ window.__ModuleLoader__.load({
6787
6805
  });
6788
6806
  }
6789
6807
  //#endregion
6808
+ //#region src/client/dingtalk-settings.tsx
6809
+ /** DingTalk settings page: a live probe of the tooling this Source needs, then the Source's own form. */
6810
+ /** The label and hint for one probe item; unknown keys fall back to the key itself. */
6811
+ function itemCopy(t, key) {
6812
+ switch (key) {
6813
+ case "dws": return {
6814
+ label: t("dingtalkCheckDws"),
6815
+ hint: t("dingtalkCheckDwsHint")
6816
+ };
6817
+ case "stream": return {
6818
+ label: t("dingtalkCheckStream"),
6819
+ hint: t("dingtalkCheckStreamHint")
6820
+ };
6821
+ case "bots": return {
6822
+ label: t("dingtalkCheckBots"),
6823
+ hint: t("dingtalkCheckBotsHint")
6824
+ };
6825
+ case "groups": return {
6826
+ label: t("dingtalkCheckGroups"),
6827
+ hint: t("dingtalkCheckGroupsHint")
6828
+ };
6829
+ default: return { label: key };
6830
+ }
6831
+ }
6832
+ /**
6833
+ * Probe block: runs the Source's checks on mount and on demand.
6834
+ * @param props.t Localized copy.
6835
+ * @returns The probe result, a re-check button, and the reason an item failed.
6836
+ */
6837
+ function CheckBlock({ t }) {
6838
+ const { call, notify } = usePanel();
6839
+ const [result, setResult] = (0, react.useState)();
6840
+ const [busy, setBusy] = (0, react.useState)(false);
6841
+ const [error, setError] = (0, react.useState)();
6842
+ const run = (0, react.useCallback)(async () => {
6843
+ setBusy(true);
6844
+ setError(void 0);
6845
+ try {
6846
+ setResult(await call("GET sources/:id/check", { id: "dingtalk" }));
6847
+ } catch (failure) {
6848
+ setError(failure);
6849
+ notify(String(failure.message));
6850
+ } finally {
6851
+ setBusy(false);
6852
+ }
6853
+ }, [call, notify]);
6854
+ (0, react.useEffect)(() => {
6855
+ run();
6856
+ }, [run]);
6857
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
6858
+ className: "dt-card",
6859
+ children: [
6860
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6861
+ className: "dt-card-head",
6862
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6863
+ className: "dt-row-main",
6864
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
6865
+ className: "dt-card-title",
6866
+ children: t("dingtalkCheckTitle")
6867
+ })
6868
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
6869
+ type: "button",
6870
+ className: "dt-btn",
6871
+ disabled: busy,
6872
+ onClick: () => void run(),
6873
+ children: busy ? t("checking") : t("recheck")
6874
+ })]
6875
+ }),
6876
+ !result && !error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadState, { loading: true }),
6877
+ result && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
6878
+ className: "dt-check-list",
6879
+ children: result.items.map((item) => {
6880
+ const copy = itemCopy(t, item.key);
6881
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
6882
+ className: "dt-row",
6883
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Dot, { state: item.ok ? "done" : "error" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6884
+ className: "dt-row-main",
6885
+ children: [
6886
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6887
+ className: "dt-row-title",
6888
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: copy.label })
6889
+ }),
6890
+ copy.hint && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6891
+ className: "dt-hint",
6892
+ children: copy.hint
6893
+ }),
6894
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6895
+ className: item.ok ? "dt-mono" : "dt-error",
6896
+ children: item.detail
6897
+ })
6898
+ ]
6899
+ })]
6900
+ }, item.key);
6901
+ })
6902
+ }),
6903
+ error && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6904
+ className: "dt-error",
6905
+ role: "status",
6906
+ children: String(error.message)
6907
+ })
6908
+ ]
6909
+ });
6910
+ }
6911
+ /**
6912
+ * The DingTalk settings section body.
6913
+ * @param props.t Localized copy.
6914
+ * @returns The probe block followed by the DingTalk Source's own form.
6915
+ */
6916
+ function DingtalkPage({ t }) {
6917
+ const { settings } = useSettings();
6918
+ const source = settings.sources.find((item) => item.id === "dingtalk");
6919
+ if (!source) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6920
+ className: "dt-hint",
6921
+ children: t("dingtalkMissing")
6922
+ });
6923
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6924
+ className: "dt-settings-page",
6925
+ children: [
6926
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6927
+ className: "dt-hint",
6928
+ children: t("dingtalkIntro")
6929
+ }),
6930
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckBlock, { t }),
6931
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SourceCard, { source }),
6932
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6933
+ className: "dt-hint",
6934
+ children: t("dingtalkPolicyNote")
6935
+ })
6936
+ ]
6937
+ });
6938
+ }
6939
+ //#endregion
6790
6940
  //#region src/client/index.tsx
6791
6941
  /** Browser plugin entry point registering the sidebar icon, main management panel, and Plugin Manager config view. */
6792
6942
  const NS = "dshSuperagent";
@@ -6836,6 +6986,13 @@ window.__ModuleLoader__.load({
6836
6986
  deploymentForm: form
6837
6987
  });
6838
6988
  }
6989
+ /** The settings shell renders sections outside the management panel, so the page brings its own panel context. */
6990
+ function DingtalkSection({ t }) {
6991
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PanelProvider, {
6992
+ t,
6993
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SettingsProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DingtalkPage, { t }) })
6994
+ });
6995
+ }
6839
6996
  const inject = [
6840
6997
  "slots",
6841
6998
  "locale",
@@ -6874,6 +7031,13 @@ window.__ModuleLoader__.load({
6874
7031
  view: props.view,
6875
7032
  form: props.form
6876
7033
  })));
7034
+ ctx.slots.inject("settings.section", () => ctx.slots.register({
7035
+ name: "settings.section",
7036
+ id: "dingtalk",
7037
+ order: 30,
7038
+ locale: NS,
7039
+ label: () => t("dingtalkSectionLabel")
7040
+ }, () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DingtalkSection, { t })));
6877
7041
  }
6878
7042
  //#endregion
6879
7043
  exports.apply = apply;
@@ -1,5 +1,5 @@
1
1
  import { S as ChannelRef, U as Trigger } from "./intake-Ba9xBNyb.js";
2
- import { n as Health, r as SourceContext, t as SourceKind } from "./kind-BlPO15JX.js";
2
+ import { n as Health, r as SourceContext, t as SourceKind } from "./kind-Dwr9FNbs.js";
3
3
  import { Context } from "@deepseek-ai/cordis";
4
4
  import { z } from "zod";
5
5
  //#region src/sources/dingtalk-config.d.ts
@@ -387,6 +387,74 @@ function dingtalkLink(address, links) {
387
387
  };
388
388
  }
389
389
  //#endregion
390
+ //#region src/sources/dingtalk-check.ts
391
+ /**
392
+ * Reads the version a `dws --version` run prints, which is all a person needs to confirm the CLI is usable.
393
+ * @param output The command's stdout.
394
+ * @returns The version token, or the first non-empty line when the output has no `v` prefix.
395
+ */
396
+ function versionOf(output) {
397
+ return output.match(/v?\d+\.\d+\.\d+[\w.\-+]*/)?.[0] ?? output.trim().split("\n")[0]?.slice(0, 80) ?? "";
398
+ }
399
+ /**
400
+ * Runs every check the DingTalk settings page shows, in the order a person should read them.
401
+ * @param commands The deployment's command runner.
402
+ * @param config The Source's stored configuration.
403
+ * @returns One item per check, plus whether all of them hold.
404
+ */
405
+ async function checkDingtalk(commands, config) {
406
+ const items = [];
407
+ const dws = config.dwsCli?.trim() || "dws";
408
+ try {
409
+ const version = versionOf(await commands.run(dws, ["--version"]));
410
+ items.push({
411
+ key: "dws",
412
+ ok: true,
413
+ detail: version ? `${dws} · ${version}` : dws
414
+ });
415
+ } catch (error) {
416
+ items.push({
417
+ key: "dws",
418
+ ok: false,
419
+ detail: String(error?.message ?? error).slice(0, 200)
420
+ });
421
+ }
422
+ const stream = streamOf(config);
423
+ items.push(stream ? {
424
+ key: "stream",
425
+ ok: true,
426
+ detail: stream.clientId
427
+ } : {
428
+ key: "stream",
429
+ ok: false,
430
+ detail: "Stream robot credentials are incomplete"
431
+ });
432
+ const bots = config.bots.filter((bot) => bot.token && bot.secret);
433
+ items.push(bots.length > 0 ? {
434
+ key: "bots",
435
+ ok: true,
436
+ detail: bots.map((bot) => bot.name || bot.conversationId).join(", ")
437
+ } : {
438
+ key: "bots",
439
+ ok: false,
440
+ detail: "No group bot has both a token and a secret"
441
+ });
442
+ const groups = config.groups.filter((group) => group.conversationId);
443
+ items.push(groups.length > 0 ? {
444
+ key: "groups",
445
+ ok: true,
446
+ detail: `${groups.length}`
447
+ } : {
448
+ key: "groups",
449
+ ok: false,
450
+ detail: "No group is listened to"
451
+ });
452
+ return {
453
+ ok: items.every((item) => item.ok),
454
+ items
455
+ };
456
+ }
457
+ //#endregion
390
458
  //#region src/sources/dingtalk-stream.ts
391
459
  /** Receives DingTalk robot messages over the official Stream long connection. */
392
460
  /**
@@ -1141,7 +1209,8 @@ const dingtalkKind = {
1141
1209
  DSH_SUPERAGENT_DINGTALK_ROBOT: trigger?.source === SOURCE$1 ? String(trigger.meta.robotCode ?? "") : ""
1142
1210
  })
1143
1211
  },
1144
- facts: (deployment) => deployment ? {} : {}
1212
+ facts: (deployment) => deployment ? {} : {},
1213
+ check: ({ commands, config }) => checkDingtalk(commands, config("dingtalk") ?? DingtalkConfigSchema.parse({}))
1145
1214
  };
1146
1215
  const name = "dsh-superagent-dingtalk";
1147
1216
  const inject = ["orchestrator"];
@@ -1,5 +1,5 @@
1
1
  import { F as Thread, U as Trigger } from "./intake-Ba9xBNyb.js";
2
- import { _ as Tally, g as SourceRegistry, r as SourceContext, t as SourceKind } from "./kind-BlPO15JX.js";
2
+ import { _ as Tally, g as SourceRegistry, r as SourceContext, t as SourceKind } from "./kind-Dwr9FNbs.js";
3
3
  import { Context } from "@deepseek-ai/cordis";
4
4
  import { z } from "zod";
5
5
  //#region src/sources/feishu-read.d.ts
@@ -1,2 +1,2 @@
1
- import { a as Retry, c as inject, d as pollRound, f as pollThreads, h as commentTrigger, i as GithubConfig, l as name, m as GithubComment, o as apply, p as pollTicketPulls, s as githubKind, u as pollFailure } from "./kind-BlPO15JX.js";
1
+ import { a as Retry, c as inject, d as pollRound, f as pollThreads, h as commentTrigger, i as GithubConfig, l as name, m as GithubComment, o as apply, p as pollTicketPulls, s as githubKind, u as pollFailure } from "./kind-Dwr9FNbs.js";
2
2
  export { type GithubComment, GithubConfig, Retry, apply, commentTrigger, githubKind, inject, name, pollFailure, pollRound, pollThreads, pollTicketPulls };
package/lib/index.d.ts CHANGED
@@ -287,6 +287,7 @@ declare const USER_ERRORS: {
287
287
  readonly promptPartEmpty: readonly ["refused", "The “{part}” part cannot be empty; reset it to follow its built-in text"];
288
288
  readonly sourceNotInstalled: readonly ["refused", "The {source} Source kind is not installed"];
289
289
  readonly noLabels: readonly ["refused", "This Source has no names to refresh"];
290
+ readonly noCheck: readonly ["refused", "This Source has no settings probe"];
290
291
  readonly nothingToSync: readonly ["refused", "The {source} Source's part of the Policy has nothing to sync from, or the Source is off or waiting for setup"];
291
292
  };
292
293
  type UserErrorCode = keyof typeof USER_ERRORS;
package/lib/index.js CHANGED
@@ -59,6 +59,7 @@ const USER_ERRORS = {
59
59
  promptPartEmpty: ["refused", "The “{part}” part cannot be empty; reset it to follow its built-in text"],
60
60
  sourceNotInstalled: ["refused", "The {source} Source kind is not installed"],
61
61
  noLabels: ["refused", "This Source has no names to refresh"],
62
+ noCheck: ["refused", "This Source has no settings probe"],
62
63
  nothingToSync: ["refused", "The {source} Source's part of the Policy has nothing to sync from, or the Source is off or waiting for setup"]
63
64
  };
64
65
  /**
@@ -8100,6 +8101,23 @@ var Settings = class {
8100
8101
  const after = await kind.refreshLabels(this.host.sourceHost);
8101
8102
  return { added: Object.entries(after).filter(([key]) => !(key in before)).map(([, name]) => name).sort((a, b) => a.localeCompare(b)) };
8102
8103
  }
8104
+ /**
8105
+ * Probes the tooling a Source needs, for the settings page to report on demand.
8106
+ * @param id The Source instance ID.
8107
+ * @returns Whether every check holds, and one item per check.
8108
+ * @throws UserError (`noCheck`) when the Source has no probe.
8109
+ */
8110
+ async check(id) {
8111
+ const { sources } = this.host;
8112
+ const instance = sources.instance(id);
8113
+ const kind = instance && sources.kind(instance.kind);
8114
+ if (!kind?.check) throw new UserError("noCheck");
8115
+ const context = this.host.sourceHost.context(kind);
8116
+ return kind.check({
8117
+ commands: context.commands,
8118
+ config: context.config
8119
+ });
8120
+ }
8103
8121
  };
8104
8122
  //#endregion
8105
8123
  //#region src/app/settings-history.ts
@@ -8644,6 +8662,7 @@ function routes(runtime) {
8644
8662
  "GET sources": () => sourcesStatus(views(runtime), runtime.health, setupState(runtime)),
8645
8663
  "GET settings": () => settingsView(store, runtime.sources, runtime.health, setupState(runtime), runtime.machine.stateDir),
8646
8664
  "POST sources/:id/labels": ({ params }) => runtime.settings.refreshLabels(params.id),
8665
+ "GET sources/:id/check": async ({ params }) => runtime.settings.check(params.id),
8647
8666
  "GET threads": ({ query }) => {
8648
8667
  const { filter, offset, limit } = ThreadsQuery.parse(query);
8649
8668
  return threadList(views(runtime), filter, offset, limit);
@@ -906,6 +906,18 @@ interface TriggerContext {
906
906
  text: string;
907
907
  }, key: string, stateDir: string, signal: AbortSignal): Promise<unknown>;
908
908
  }
909
+ /** One line of a settings-page probe: what was checked, whether it holds, and what was observed. */
910
+ interface SourceCheckItem {
911
+ key: string;
912
+ ok: boolean;
913
+ /** Observation in the operator's words, e.g. a version number or the reason a check failed. */
914
+ detail: string;
915
+ }
916
+ /** Result of probing a kind's surroundings from the settings page, in the order a person should read it. */
917
+ interface SourceCheck {
918
+ ok: boolean;
919
+ items: SourceCheckItem[];
920
+ }
909
921
  /** Pluggable source kind descriptor registered with SourceRegistry. */
910
922
  interface SourceKind<C extends Record<string, unknown> = Record<string, unknown>> {
911
923
  /** Stable ID; a default instance with the same ID exists when none is stored. */
@@ -941,6 +953,8 @@ interface SourceKind<C extends Record<string, unknown> = Record<string, unknown>
941
953
  name?: string;
942
954
  }[];
943
955
  }>;
956
+ /** Probes the tooling this kind needs (a CLI, credentials) so the settings page can report it on demand. */
957
+ check?(host: Pick<SourceContext, 'commands' | 'config'>): Promise<SourceCheck>;
944
958
  /** Rereads display names for row keys (such as chat names), stores the resolved names in `KV.sources.labels(kind)`, and returns them. */
945
959
  refreshLabels?(host: SourceHost, signal?: AbortSignal): Promise<Record<string, string>>;
946
960
  /** Variables the kind registers with the execution environment and how their values are computed. */
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@chenkai114/dsh-superagent-dingtalk",
3
3
  "author": "chenkai2",
4
4
  "license": "MIT",
5
- "version": "0.0.2",
5
+ "version": "0.0.3",
6
6
  "description": "DingTalk source for dsh-superagent: reads configured groups through the official dws CLI, receives messages addressed to an application robot over Stream, and replies as a bot.",
7
7
  "type": "module",
8
8
  "main": "lib/index.js",