@cydm/pie 4.3.0 → 4.3.1
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.
|
@@ -447,10 +447,10 @@ function resolveConfig(cwd, dir) {
|
|
|
447
447
|
for (const file of configPaths(cwd, dir)) {
|
|
448
448
|
const layer = readLayer(file);
|
|
449
449
|
if (Object.keys(layer).length) present = true;
|
|
450
|
-
const legacy = ["chatId", "receiveId", "openId", "larkCli", "allowUsers"].some((key) => key in layer);
|
|
450
|
+
const legacy = ["chatId", "receiveId", "openId", "larkCli", "allowUsers", "groupAccess"].some((key) => key in layer);
|
|
451
451
|
if (legacy && !layer.provider) {
|
|
452
452
|
const previous = providers.feishu ?? {};
|
|
453
|
-
providers.feishu = { ...previous, ...Object.fromEntries(["chatId", "openId", "larkCli", "allowUsers"].filter((key) => key in layer).map((key) => [key, layer[key]])), ...layer.receiveId && !layer.chatId ? { chatId: layer.receiveId } : {} };
|
|
453
|
+
providers.feishu = { ...previous, ...Object.fromEntries(["chatId", "openId", "larkCli", "allowUsers", "groupAccess"].filter((key) => key in layer).map((key) => [key, layer[key]])), ...layer.receiveId && !layer.chatId ? { chatId: layer.receiveId } : {} };
|
|
454
454
|
merged.provider = "feishu";
|
|
455
455
|
}
|
|
456
456
|
if (isRecord(layer.providers)) {
|
|
@@ -1198,10 +1198,17 @@ function loadPersistedAnchor(sessionId, identity) {
|
|
|
1198
1198
|
try {
|
|
1199
1199
|
const raw = fs7.readFileSync(anchorPath(sessionId), "utf8");
|
|
1200
1200
|
const parsed = JSON.parse(raw);
|
|
1201
|
-
if (typeof parsed.anchor?.messageId === "string" && parsed.anchor.messageId && typeof parsed.anchor.at === "number" && parsed.provider === identity.provider &&
|
|
1201
|
+
if (typeof parsed.anchor?.messageId === "string" && parsed.anchor.messageId && typeof parsed.anchor.at === "number" && parsed.provider === identity.provider && // v2 group-home (11-12): the home is the APP'S WHOLE PRESENCE, so an
|
|
1202
|
+
// anchor may live in ANY room — a group chat id differs from the
|
|
1203
|
+
// configured DM target and must NOT invalidate the anchor (the old
|
|
1204
|
+
// equality here silently forked a group-anchored session back to the
|
|
1205
|
+
// DM root on restart). The provider check stays: a re-bound app is a
|
|
1206
|
+
// different home entirely.
|
|
1207
|
+
(parsed.targetId === identity.targetId || typeof parsed.anchor.home === "string")) {
|
|
1202
1208
|
return {
|
|
1203
1209
|
messageId: parsed.anchor.messageId,
|
|
1204
1210
|
...typeof parsed.anchor.threadId === "string" && parsed.anchor.threadId ? { threadId: parsed.anchor.threadId } : {},
|
|
1211
|
+
...typeof parsed.anchor.home === "string" && parsed.anchor.home ? { home: parsed.anchor.home } : {},
|
|
1205
1212
|
at: parsed.anchor.at
|
|
1206
1213
|
};
|
|
1207
1214
|
}
|
|
@@ -1357,11 +1364,12 @@ function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
|
|
|
1357
1364
|
const anchor = replyAnchor.get(sessionId);
|
|
1358
1365
|
return anchor ? { messageId: anchor.messageId, threadId: anchor.threadId } : { threadId: null };
|
|
1359
1366
|
}
|
|
1360
|
-
function persistSessionAnchor(sessionId, messageId, threadId) {
|
|
1367
|
+
function persistSessionAnchor(sessionId, messageId, threadId, home) {
|
|
1361
1368
|
replyAnchor.set(sessionId, { messageId, threadId, at: Date.now() });
|
|
1362
1369
|
savePersistedAnchor(sessionId, anchorIdentity, {
|
|
1363
1370
|
messageId,
|
|
1364
1371
|
...threadId ? { threadId } : {},
|
|
1372
|
+
...home ? { home } : {},
|
|
1365
1373
|
at: Date.now()
|
|
1366
1374
|
});
|
|
1367
1375
|
}
|
|
@@ -1732,7 +1740,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1732
1740
|
}
|
|
1733
1741
|
if (opener) registerRoute(opener, sessionId);
|
|
1734
1742
|
}
|
|
1735
|
-
persistSessionAnchor(sessionId, sent.messageId, threadId);
|
|
1743
|
+
persistSessionAnchor(sessionId, sent.messageId, threadId, cfg.targetId);
|
|
1736
1744
|
if (threadId) {
|
|
1737
1745
|
claimThreadOwnership({ provider: cfg.provider, threadId }, sessionId);
|
|
1738
1746
|
}
|
|
@@ -1942,9 +1950,16 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
|
|
|
1942
1950
|
}
|
|
1943
1951
|
}
|
|
1944
1952
|
async function handleInboundEventInner(event, retry) {
|
|
1945
|
-
const
|
|
1946
|
-
if (
|
|
1947
|
-
|
|
1953
|
+
const isGroup = event.chatType === "group";
|
|
1954
|
+
if (isGroup) {
|
|
1955
|
+
if (cfg.groupAccess === "off") return;
|
|
1956
|
+
if (cfg.groupAccess === "allowUsers" && (!event.sender_id || !cfg.allowUsers?.includes(event.sender_id)))
|
|
1957
|
+
return;
|
|
1958
|
+
} else {
|
|
1959
|
+
const matchesTarget = cfg.targetKind === "user" ? event.sender_id === cfg.targetId && (event.chatType === void 0 || event.chatType === "p2p") : event.chat_id === cfg.targetId || event.chatType === "p2p";
|
|
1960
|
+
if (!matchesTarget) return;
|
|
1961
|
+
}
|
|
1962
|
+
if (!isGroup && cfg.allowUsers && (!event.sender_id || !cfg.allowUsers.includes(event.sender_id)))
|
|
1948
1963
|
return;
|
|
1949
1964
|
const messageId = event.message_id;
|
|
1950
1965
|
if (!messageId) return;
|
|
@@ -2083,7 +2098,10 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
2083
2098
|
persistSessionAnchor(
|
|
2084
2099
|
route.sessionId,
|
|
2085
2100
|
messageId,
|
|
2086
|
-
route.threadId ?? meta.threadId ?? null
|
|
2101
|
+
route.threadId ?? meta.threadId ?? null,
|
|
2102
|
+
// v2 group-home: the room the user spoke in IS the anchor's home —
|
|
2103
|
+
// a group topic keeps living in the group across restarts.
|
|
2104
|
+
event.chat_id
|
|
2087
2105
|
);
|
|
2088
2106
|
claimSessionRoot(cfg.provider, messageId, route.sessionId);
|
|
2089
2107
|
if (route.threadId ?? meta.threadId) {
|
|
@@ -2235,7 +2253,7 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
|
|
|
2235
2253
|
}
|
|
2236
2254
|
let consumerLock;
|
|
2237
2255
|
function bindingKey() {
|
|
2238
|
-
return `${cfg.provider}:${cfg.targetId}`;
|
|
2256
|
+
return `${cfg.provider}:${cfg.appId ?? cfg.targetId}`;
|
|
2239
2257
|
}
|
|
2240
2258
|
function acquireConsumerSlot() {
|
|
2241
2259
|
if (consumerLock) return true;
|
|
@@ -3408,13 +3426,24 @@ function normalizeEvent(line) {
|
|
|
3408
3426
|
if (!isRecord(raw) || raw.type !== "im.message.receive_v1" || typeof raw.event_id !== "string" || typeof raw.chat_id !== "string") return null;
|
|
3409
3427
|
const id = raw.message_id ?? raw.id;
|
|
3410
3428
|
if (typeof id !== "string") return null;
|
|
3429
|
+
const mentions = Array.isArray(raw.mentions) ? raw.mentions.filter((m) => isRecord(m)).map((m) => ({ id: typeof m.id === "string" ? m.id : void 0, name: typeof m.name === "string" ? m.name : void 0 })) : void 0;
|
|
3430
|
+
let text = extractInboundText(raw.content).replace(/\[Image:\s*img_[A-Za-z0-9_-]+\]/g, "").trim();
|
|
3431
|
+
const chatType = raw.chat_type === void 0 ? void 0 : typeof raw.chat_type === "string" ? raw.chat_type : "invalid";
|
|
3432
|
+
if (chatType === "group" && mentions?.length) {
|
|
3433
|
+
const first = mentions[0];
|
|
3434
|
+
if (first?.name) {
|
|
3435
|
+
const esc = first.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3436
|
+
text = text.replace(new RegExp(`^(?:[^\\n]*\\n)?@${esc}\\s*`), "").trim();
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3411
3439
|
return {
|
|
3412
3440
|
event_id: raw.event_id,
|
|
3413
3441
|
message_id: id,
|
|
3414
3442
|
chat_id: raw.chat_id,
|
|
3415
3443
|
sender_id: typeof raw.sender_id === "string" ? raw.sender_id : void 0,
|
|
3416
|
-
chatType
|
|
3417
|
-
|
|
3444
|
+
chatType,
|
|
3445
|
+
mentions: mentions?.length ? mentions : void 0,
|
|
3446
|
+
text,
|
|
3418
3447
|
images: extractImageKeys(raw.content)
|
|
3419
3448
|
};
|
|
3420
3449
|
}
|
|
@@ -3548,7 +3577,8 @@ var feishuProvider = {
|
|
|
3548
3577
|
if (!targetKind) return null;
|
|
3549
3578
|
const allowed = Array.isArray(raw.allowUsers) ? raw.allowUsers.filter((id) => typeof id === "string" && !!id.trim()) : void 0;
|
|
3550
3579
|
const appId = typeof raw.larkCliAppId === "string" && raw.larkCliAppId.trim() ? raw.larkCliAppId.trim() : void 0;
|
|
3551
|
-
|
|
3580
|
+
const groupAccess = raw.groupAccess === "allowUsers" || raw.groupAccess === "members" || raw.groupAccess === "off" ? raw.groupAccess : void 0;
|
|
3581
|
+
return { ...raw, targetId: targetKind === "user" ? openId : chatId, targetKind, allowUsers: allowed?.length ? allowed : void 0, ...appId ? { appId } : {}, ...groupAccess ? { groupAccess } : {} };
|
|
3552
3582
|
},
|
|
3553
3583
|
connect(settings, cwd) {
|
|
3554
3584
|
const binary = resolveLaunchSpec(typeof settings.larkCli === "string" ? settings.larkCli : void 0, cwd);
|
|
@@ -3650,7 +3680,7 @@ function initializeImForward(ctx, providers = implementedProviders) {
|
|
|
3650
3680
|
return () => {
|
|
3651
3681
|
};
|
|
3652
3682
|
};
|
|
3653
|
-
createRuntime(bridge, { enabled: config.enabled, provider: config.provider, label: provider.label, targetId: settings.targetId, targetKind: settings.targetKind, allowUsers: settings.allowUsers, retryBackoffMs: config.retryBackoffMs, ...settings.appId ? { appId: settings.appId } : {}, ...caps.unattended ? { unattended: true } : {} }, connection, () => liveEnabled(config), (next) => {
|
|
3683
|
+
createRuntime(bridge, { enabled: config.enabled, provider: config.provider, label: provider.label, targetId: settings.targetId, targetKind: settings.targetKind, allowUsers: settings.allowUsers, retryBackoffMs: config.retryBackoffMs, ...settings.appId ? { appId: settings.appId } : {}, ...settings.groupAccess ? { groupAccess: settings.groupAccess } : {}, ...caps.unattended ? { unattended: true } : {} }, connection, () => liveEnabled(config), (next) => {
|
|
3654
3684
|
const latest = readLiveConfig(ctx.cwd, dir);
|
|
3655
3685
|
if (latest.problems.length || !latest.config || configurationIdentity(latest.config) !== configurationIdentity(config)) throw new Error("Configuration changed; setup required");
|
|
3656
3686
|
writeConfig(ctx.cwd, dir, { enabled: next });
|