@xgjktech/xg_cwork_im 1.10.3 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xgjktech/xg_cwork_im",
3
- "version": "1.10.3",
3
+ "version": "1.11.0",
4
4
  "description": "XG CWork IM channel plugin for OpenClaw",
5
5
  "keywords": [
6
6
  "bot",
@@ -21,7 +21,8 @@
21
21
  "scripts": {
22
22
  "type-check": "tsc -p tsconfig.json --noEmit",
23
23
  "lint": "tsc -p tsconfig.json --noEmit",
24
- "install:prod": "npm install --omit=dev"
24
+ "install:prod": "npm install --omit=dev",
25
+ "prepublishOnly": "npm run type-check"
25
26
  },
26
27
  "dependencies": {
27
28
  "@sinclair/typebox": "^0.32.0",
package/src/channel.ts CHANGED
@@ -57,6 +57,7 @@ const XgImAccountConfigSchema = z.object({
57
57
  inboundMediaWorkspaceSubdir: z.string().optional(),
58
58
  inboundMediaOpenClawPath: z.enum(["workspaceRelative", "absoluteFileUrl"]).optional(),
59
59
  inboundMediaSandboxRootPrefix: z.string().optional(),
60
+ systemPrompt: z.string().optional(),
60
61
  });
61
62
 
62
63
  const XgImConfigSchema = z.object({
@@ -83,6 +84,8 @@ const XgImConfigSchema = z.object({
83
84
  inboundMediaOpenClawPath: z.enum(["workspaceRelative", "absoluteFileUrl"]).optional(),
84
85
  /** 沙箱内 workspace 挂载根,如 `/workspace`;与 workspaceRelative 组合生成绝对引用 */
85
86
  inboundMediaSandboxRootPrefix: z.string().optional(),
87
+ /** 群聊入站时写入 OpenClaw `GroupSystemPrompt`(与 accounts 内字段合并规则见 getXgImConfig) */
88
+ systemPrompt: z.string().optional(),
86
89
  // 多账户:对象 map(key 为 accountId)
87
90
  accounts: z.record(z.string(), XgImAccountConfigSchema).optional(),
88
91
  }).superRefine((val, ctx) => {
@@ -171,6 +174,31 @@ function getXgImConfig(cfg: OpenClawConfig, accountId?: string | null): XgImConf
171
174
  return raw;
172
175
  }
173
176
 
177
+ /**
178
+ * 合并 `channels.xg_cwork_im` 顶层、`accounts.default`、以及 `accounts.<accountId>` 后的 `systemPrompt`,
179
+ * 写入 OpenClaw 入站 `GroupSystemPrompt`(与 getXgImConfig 的非 default 账户合并方式一致;对 default 账户会合并 default 片段)。
180
+ */
181
+ function resolveXgImGroupSystemPrompt(cfg: OpenClawConfig, accountId: string): string | undefined {
182
+ try {
183
+ const raw = (cfg as Record<string, Record<string, unknown>>)?.channels?.xg_cwork_im as XgImConfig | undefined;
184
+ if (!raw) return undefined;
185
+ const accountMap =
186
+ raw.accounts && typeof raw.accounts === "object" && !Array.isArray(raw.accounts)
187
+ ? (raw.accounts as Record<string, Partial<XgImConfig> | undefined>)
188
+ : undefined;
189
+ const defaults = accountMap?.default ? { ...accountMap.default } : {};
190
+ const base: XgImConfig = { ...raw, ...defaults };
191
+ let merged: XgImConfig = base;
192
+ if (accountId && accountId !== "default" && accountMap?.[accountId]) {
193
+ merged = { ...base, ...accountMap[accountId] };
194
+ }
195
+ const t = merged.systemPrompt?.trim();
196
+ return t || undefined;
197
+ } catch {
198
+ return undefined;
199
+ }
200
+ }
201
+
174
202
  function isConfigured(cfg: OpenClawConfig): boolean {
175
203
  try {
176
204
  const c = getXgImConfig(cfg);
@@ -759,6 +787,16 @@ export const xgCworkImChannelPlugin: XgImChannelPlugin = {
759
787
  config,
760
788
  });
761
789
 
790
+ const groupSystemPromptResolved = resolveXgImGroupSystemPrompt(ctx.cfg, account.accountId);
791
+ if (config.debug) {
792
+ log.info(
793
+ `${logPrefix} [GroupSystemPrompt] ` +
794
+ (groupSystemPromptResolved
795
+ ? `active len=${groupSystemPromptResolved.length} preview=${JSON.stringify(groupSystemPromptResolved.slice(0, 96))}`
796
+ : "(empty — 若已配置 systemPrompt:检查网关是否加载了含本字段的插件构建,或把 systemPrompt 写到 accounts.<id> 再试)"),
797
+ );
798
+ }
799
+
762
800
  const inboundCtx = rt.channel.reply.finalizeInboundContext({
763
801
  Body: body,
764
802
  RawBody: text,
@@ -771,6 +809,7 @@ export const xgCworkImChannelPlugin: XgImChannelPlugin = {
771
809
  ChatType: "group",
772
810
  ConversationLabel: fromLabel,
773
811
  GroupSubject: params.groupId,
812
+ GroupSystemPrompt: groupSystemPromptResolved,
774
813
  SenderName: senderName,
775
814
  SenderId: senderId ?? "",
776
815
  Provider: "xg_cwork_im",
package/src/types.ts CHANGED
@@ -54,6 +54,11 @@ export interface XgImAccountConfig {
54
54
  * `{inboundMediaSandboxRootPrefix}/xg_im_inbound/...`,避免 `./` 被工具按 cwd 解析而报「不可访问」。
55
55
  */
56
56
  inboundMediaSandboxRootPrefix?: string;
57
+ /**
58
+ * 可选:本账户在群聊中追加给 Agent 的补充说明(映射为 OpenClaw 入站 `GroupSystemPrompt`)。
59
+ * 与顶层 `systemPrompt` 的合并规则见 `getXgImConfig`(`accounts.default` 与具体账户覆盖)。
60
+ */
61
+ systemPrompt?: string;
57
62
  }
58
63
 
59
64
  export interface XgImConfig extends OpenClawConfig {
@@ -115,6 +120,11 @@ export interface XgImConfig extends OpenClawConfig {
115
120
  inboundMediaOpenClawPath?: "workspaceRelative" | "absoluteFileUrl";
116
121
  /** 见 {@link XgImAccountConfig.inboundMediaSandboxRootPrefix} */
117
122
  inboundMediaSandboxRootPrefix?: string;
123
+ /**
124
+ * 可选:本通道在群聊中追加给 Agent 的补充说明(映射为 OpenClaw 入站 `GroupSystemPrompt`)。
125
+ * 多账户时可与 `accounts.<id>.systemPrompt` 及 `accounts.default.systemPrompt` 组合覆盖,见插件内 `getXgImConfig`。
126
+ */
127
+ systemPrompt?: string;
118
128
  }
119
129
 
120
130
  // ─── IM 接口 Request / Response ─────────────────────────────────────────────