Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(feishu): ctr 会话命名对齐渠道会话 + 带入 thread 前群主流上下文

Lizi44ce5fe150dc
diff --git a/apps/desktop/src/main/im/feishu/__tests__/feishuAdapter.test.ts b/apps/desktop/src/main/im/feishu/__tests__/feishuAdapter.test.ts
index b46de60df1..52f145c5c8 100644
--- a/apps/desktop/src/main/im/feishu/__tests__/feishuAdapter.test.ts
+++ b/apps/desktop/src/main/im/feishu/__tests__/feishuAdapter.test.ts
@@ -63,7 +63,7 @@ const fetchChatHistoryPage = vi.fn<
>(async () => ({ messages: [], nextPageToken: null }));
const downloadMessageAttachments = vi.fn(async () => ({ attachments: [], unsupported: [] }));
const getOwnerOpenId = vi.fn(() => 'ou_owner');
-const sendMarkdownText = vi.fn(async (_userId: string, _text: string) => ({ messageId: 'om_notice' }));
+const sendMarkdownText = vi.fn(async () => ({ messageId: 'om_notice' }));
const getChatName = vi.fn<(chatId: string) => Promise<string | null>>(async () => null);
const getStatus = vi.fn<() => IMStatus>(() => ({ kind: 'connected', appId: 'cli_abc' }));
const fakeIm = {
@@ -234,7 +234,7 @@ describe('feishu group lane adapter hooks', () => {
).toBe('[飞书·产品交流群·周进度总结] 9ce6ab');
});
- it('composeGeneratedTitle: 群名未知退化为 [飞书·话题·{简介}]; DM/群主流 lane 返回 null 回落', async () => {
+ it('composeGeneratedTitle: 群名未知退化为 [飞书·话题·{简介}]; DM 返回 null 回落', async () => {
getChatName.mockResolvedValueOnce(null);
expect(
await adapter.sessions.composeGeneratedTitle?.('g/oc_chat6/omt_t2', undefined, '简介', 's1'),
@@ -242,9 +242,19 @@ describe('feishu group lane adapter hooks', () => {
expect(
await adapter.sessions.composeGeneratedTitle?.('ou_owner', undefined, 'x', 's1'),
).toBeNull();
+ });
+
+ it('composeGeneratedTitle: 群主流 lane 拼 [飞书·群] {群名|chatId 后 6 位}(/ctr 接管会话命名对齐群会话族)', async () => {
+ // 非 ctr 群主流会话不参与 oneshot(skipOneshotTitleFor), 只有 /ctr 新建的
+ // 接管会话走到这里 — 固定名与 defaultTitle/resolveSessionTitle 同族。
+ getChatName.mockResolvedValueOnce('产品交流群');
expect(
- await adapter.sessions.composeGeneratedTitle?.('g/oc_chat6', undefined, 'x', 's1'),
- ).toBeNull();
+ await adapter.sessions.composeGeneratedTitle?.('g/oc_chat7', undefined, 'x', 's1'),
+ ).toBe('[飞书·群] 产品交流群');
+ getChatName.mockResolvedValueOnce(null);
+ expect(
+ await adapter.sessions.composeGeneratedTitle?.('g/oc_1234567890', undefined, 'x', 's1'),
+ ).toBe('[飞书·群] 567890');
});
it('群轮次(speaker 存在)挂 channel 强确认策略; DM 不挂', () => {
@@ -297,6 +307,70 @@ describe('feishu group lane adapter hooks', () => {
expect(result?.agentText).toContain('群主流背景');
});
+ it('prepareAgentTurnText: /ctr 开话题事件记忆的群主流取数 lane 被话题首条消息领走(一次性)', async () => {
+ // 群主流 @ "/ctr" 开新话题: slash 不经过 prepareAgentTurnText, 取数 lane
+ // 由 onSlashCommandEvent 记住; 流程结束后话题里第一条 agent 消息按群主流
+ // 拉历史(thread 创建前的上下文), 第二条起回到话题容器。
+ adapter.onSlashCommandEvent?.(
+ groupEvent({
+ senderId: 'g/oc_chat9/omt_ctr1',
+ groupContextLane: { chatId: 'oc_chat9', threadId: '' },
+ }),
+ );
+ fetchChatHistoryPage.mockResolvedValueOnce(
+ historyPage([historyEntry({ messageId: 'om_h1', threadId: '', text: '群主流背景' })]),
+ );
+ const first = await adapter.prepareAgentTurnText?.(
+ groupEvent({ senderId: 'g/oc_chat9/omt_ctr1' }),
+ );
+ expect(fetchChatHistoryPage).toHaveBeenCalledWith(
+ expect.objectContaining({ chatId: 'oc_chat9' }),
+ );
+ expect(fetchChatHistoryPage).not.toHaveBeenCalledWith(
+ expect.objectContaining({ threadId: 'omt_ctr1' }),
+ );
+ expect(first?.agentText).toContain('群主流背景');
+
+ // 一次性: 第二条消息回到话题容器。
+ fetchChatHistoryPage.mockResolvedValueOnce(
+ historyPage([historyEntry({ messageId: 'om_h2', threadId: 'omt_ctr1', text: '话题内消息' })]),
+ );
+ const second = await adapter.prepareAgentTurnText?.(
+ groupEvent({ senderId: 'g/oc_chat9/omt_ctr1' }),
+ );
+ expect(fetchChatHistoryPage).toHaveBeenLastCalledWith(
+ expect.objectContaining({ chatId: 'oc_chat9', threadId: 'omt_ctr1' }),
+ );
+ expect(second?.agentText).toContain('话题内消息');
+ expect(second?.agentText).not.toContain('群主流背景');
+ });
+
+ it('prepareAgentTurnText: 话题内 slash 事件无 groupContextLane, 不建立记忆(走话题容器)', async () => {
+ adapter.onSlashCommandEvent?.(groupEvent({ senderId: 'g/oc_chat10/omt_ctr2' }));
+ fetchChatHistoryPage.mockResolvedValueOnce(
+ historyPage([historyEntry({ messageId: 'om_h1', threadId: 'omt_ctr2', text: '话题内消息' })]),
+ );
+ const result = await adapter.prepareAgentTurnText?.(
+ groupEvent({ senderId: 'g/oc_chat10/omt_ctr2' }),
+ );
+ expect(fetchChatHistoryPage).toHaveBeenCalledWith(
+ expect.objectContaining({ chatId: 'oc_chat10', threadId: 'omt_ctr2' }),
+ );
+ expect(result?.agentText).toContain('话题内消息');
+ });
+
+ it('prepareAgentTurnText: DM slash 事件不受记忆机制影响', async () => {
+ adapter.onSlashCommandEvent?.(
+ groupEvent({ senderId: 'ou_owner', groupContextLane: { chatId: 'oc_chat11', threadId: '' } }),
+ );
+ fetchChatHistoryPage.mockClear();
+ const result = await adapter.prepareAgentTurnText?.(
+ groupEvent({ senderId: 'ou_owner', speaker: undefined }),
+ );
+ expect(result).toBeNull();
+ expect(fetchChatHistoryPage).not.toHaveBeenCalled();
+ });
+
it('prepareAgentTurnText: 话题 lane 按 thread 容器拉取, 只取本话题的消息', async () => {
fetchChatHistoryPage.mockResolvedValueOnce(
historyPage([
diff --git a/apps/desktop/src/main/im/feishu/adapter.ts b/apps/desktop/src/main/im/feishu/adapter.ts
index 91a8948d42..42fda5b4ea 100644
--- a/apps/desktop/src/main/im/feishu/adapter.ts
+++ b/apps/desktop/src/main/im/feishu/adapter.ts
@@ -173,6 +173,44 @@ async function resolveChatName(feishuIm: FeishuIM, chatId: string): Promise<stri
return name;
}
+// ── 群主流 @ 开话题的「thread 前上下文」取数 lane 记忆 ────────────────────────
+// 开话题事件(groupContextLane)若是 slash(如 /ctr), prepareAgentTurnText 不会
+// 被调用, 群主流上下文取数 lane 随之丢失;记下来, 由话题里第一条 agent 消息
+// 领走(take 后即删, 只补一次 — 与开话题事件「只有首条消息看群主流」的口径
+// 一致)。TTL + 上限兜底, 防用户开话题后永不发消息造成的无界增长。
+
+const MAIN_FLOW_CONTEXT_TTL_MS = 24 * 60 * 60 * 1000;
+const MAIN_FLOW_CONTEXT_MAX_ENTRIES = 64;
+const mainFlowContextLanes = new Map<string, { ts: number; lane: FeishuLane }>();
+
+function rememberMainFlowContextLane(topicLaneUserId: string, mainFlowLane: FeishuLane): void {
+ const now = Date.now();
+ for (const [laneId, entry] of mainFlowContextLanes) {
+ if (now - entry.ts > MAIN_FLOW_CONTEXT_TTL_MS) mainFlowContextLanes.delete(laneId);
+ }
+ while (mainFlowContextLanes.size > MAIN_FLOW_CONTEXT_MAX_ENTRIES) {
+ let oldestKey: string | undefined;
+ let oldestTs = Number.POSITIVE_INFINITY;
+ for (const [laneId, entry] of mainFlowContextLanes) {
+ if (entry.ts < oldestTs) {
+ oldestTs = entry.ts;
+ oldestKey = laneId;
+ }
+ }
+ if (oldestKey === undefined) break;
+ mainFlowContextLanes.delete(oldestKey);
+ }
+ mainFlowContextLanes.set(topicLaneUserId, { ts: now, lane: mainFlowLane });
+}
+
+/** 领取话题 lane 记忆的群主流取数 lane(一次性, 领完即删);无则返回 undefined。 */
+function takeMainFlowContextLane(topicLaneUserId: string): FeishuLane | undefined {
+ const entry = mainFlowContextLanes.get(topicLaneUserId);
+ if (!entry) return undefined;
+ mainFlowContextLanes.delete(topicLaneUserId);
+ return entry.lane;
+}
+
export function buildFeishuAdapter(
feishuIm: FeishuIM,
config: ImOrchestratorConfig,
@@ -239,19 +277,43 @@ export function buildFeishuAdapter(
return lane !== null && lane.threadId === '';
},
// 话题 lane 的 oneshot 标题拼装: [飞书·{群名}·{话题简介}] {threadId 后 6 位}
- // — 群名拉不到时退化为 [飞书·话题·{简介}]。DM/群主流 lane 返回 null,
- // 回落默认 generatedTitlePrefix 路径(DM → [飞书·DM] {简介})。
+ // — 群名拉不到时退化为 [飞书·话题·{简介}]。DM 返回 null, 回落默认
+ // generatedTitlePrefix 路径(DM → [飞书·DM] {简介})。
+ // 群主流 lane 拼固定名 [飞书·群] {群名|chatId 后 6 位}, 与 defaultTitle /
+ // resolveSessionTitle 同族 — 非 ctr 群主流会话不参与 oneshot
+ // (skipOneshotTitleFor), 只有 /ctr 新建的接管会话走到这里, 命名与
+ // 群会话族对齐(oneshot 文本用不上, 有意忽略)。
composeGeneratedTitle: async (userId, _scopeKey, generated) => {
const lane = decodeFeishuLaneUserId(userId);
- if (!lane || !lane.threadId) return null;
- const name = await resolveChatName(feishuIm, lane.chatId);
+ if (!lane) return null;
const label = isLark() ? 'Lark' : '飞书';
+ if (!lane.threadId) {
+ const name = await resolveChatName(feishuIm, lane.chatId);
+ return `[${label}·群] ${name ?? lane.chatId.slice(-6)}`;
+ }
+ const name = await resolveChatName(feishuIm, lane.chatId);
const mid = name ? `${label}·${name}·${generated}` : `${label}·话题·${generated}`;
return `[${mid}] ${lane.threadId.slice(-6)}`;
},
},
processingEmoji: REACTION_PROCESSING,
buildVendorOptions: (userId) => ({ feishuChatId: userId, source: 'feishu' }),
+
+ // ── /ctr 流程的「thread 前上下文」记忆 ─────────────────────────────────
+ // 群主流 @ 开新话题时, 触发事件带 groupContextLane(群主流取数 lane)——
+ // 但 /ctr 是 slash 命令, 不走 prepareAgentTurnText, 开话题那条事件攒下的
+ // 上下文取数 lane 直接浪费; 流程结束后话题里的第一条消息只按话题容器拉
+ // 历史, thread 创建前的群主流讨论就此丢失。这里在 slash 事件时记住
+ // 「话题 lane → 群主流 lane」, 话题里的第一条 agent 消息把它领走
+ // (take, 一次性)当取数 lane 用 — 与开话题事件的 groupContextLane 同语义。
+ // 只记话题 lane(群主流降级 lane 的话题消息本就按群主流取数, 无需补);
+ // TTL + 上限防泄漏。DM 事件无 groupContextLane, 不受影响。
+ onSlashCommandEvent: (event) => {
+ if (!event.groupContextLane) return;
+ const lane = decodeFeishuLaneUserId(event.senderId);
+ if (!lane || !lane.threadId) return;
+ rememberMainFlowContextLane(event.senderId, event.groupContextLane);
+ },
// 群轮次(speaker 存在)统一挂强确认策略 — 群历史前缀携带成员可控文本,
// 注入可借 owner 轮次的宽松档执行危险操作; 确认卡经 deliverToOwnerDm
// 改投 owner 私聊, 点击也只认 owner。DM 不挂, owner 私聊保持全速。
@@ -264,7 +326,10 @@ export function buildFeishuAdapter(
// 群主流 @ 开新话题: 上下文取数 lane 与路由 lane 分离(见
// IMMessageEvent.groupContextLane) — 新话题是空的, 群历史仍按群主流
// 拉取, 「总结上面」等依赖上文的消息才能拿到上下文。
- const contextLane = event.groupContextLane ?? lane;
+ // 开话题事件本身是 slash(如 /ctr)时不经过这里: 取数 lane 由
+ // onSlashCommandEvent 记住, 话题里第一条 agent 消息来此领走。
+ const contextLane =
+ event.groupContextLane ?? takeMainFlowContextLane(event.senderId) ?? lane;
const built = await buildFeishuGroupContext({
lane: contextLane,
triggerMessageId: event.messageId,
@@ -276,7 +341,7 @@ export function buildFeishuAdapter(
judgePageRelevant: judgeHistoryPageRelevant,
scanInjection: scanHistoryInjection,
notifyFetchFailure: (errMsg) =>
- notifyContextFetchFailure(feishuIm, lane, errMsg, isLark()),
+ notifyContextFetchFailure(feishuIm, contextLane, errMsg, isLark()),
log,
},
});
diff --git a/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts
index 9b3d342da9..a0d5fe2b21 100644
--- a/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts
@@ -405,4 +405,56 @@ describe('messageHandler !stop routing', () => {
);
expect(runAgentTurn).not.toHaveBeenCalled();
});
+
+ it('calls adapter.onSlashCommandEvent before slash dispatch; hook throw does not block the command', async () => {
+ const hook = vi.fn<(event: IMMessageEvent) => void>();
+ // 重建一份带钩子的 adapter — 钩子先于 handleSlashCommand 执行(飞书靠它
+ // 记住开话题 slash 的群主流取数 lane)。
+ const im = {
+ onMessage(handler: (event: IMMessageEvent) => void) {
+ deliver = handler;
+ return () => undefined;
+ },
+ sendMarkdownText,
+ sendText,
+ } as unknown as ChannelIM;
+ const adapter = {
+ channel: 'slack',
+ im,
+ ui: slackUi,
+ threadScoped: true,
+ onSlashCommandEvent: hook,
+ } as unknown as ImChannelAdapter;
+ createMessageHandler(
+ adapter,
+ { handleSlashCommand } as unknown as ImSlashHandlers,
+ { stopActiveTurn, runAgentTurn } as unknown as ImTurnRunner,
+ )(im);
+
+ const slashEvent = makeEvent({ text: '/ctr' });
+ const order: string[] = [];
+ hook.mockImplementation(() => {
+ order.push('hook');
+ });
+ handleSlashCommand.mockImplementation(async () => {
+ order.push('slash');
+ return true;
+ });
+ deliver(slashEvent);
+ await flushMicrotasks();
+ expect(order).toEqual(['hook', 'slash']);
+ expect(hook).toHaveBeenCalledWith(slashEvent);
+
+ // 钩子抛错只记 warn, 命令照常派发。
+ hook.mockImplementation(() => {
+ throw new Error('hook exploded');
+ });
+ const second = makeEvent({ text: '/model', messageId: 'msg-2' });
+ deliver(second);
+ await flushMicrotasks();
+ expect(handleSlashCommand).toHaveBeenCalledWith('/model', {
+ botContextId: 'bot-ctx',
+ userId: 'U123456789',
+ });
+ });
});
diff --git a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
index 895009bfbf..43cf6d6ccf 100644
--- a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
@@ -522,21 +522,23 @@ describe('turnRunner thread = session 路由(slack threadScoped)', () => {
}),
}),
});
- mocks.generateAndPersistFbotTitle.mockResolvedValue('FBot · 新功能');
+ mocks.generateAndPersistFbotTitle.mockResolvedValue('Slack · 新功能');
await runTurn('400.4', '帮我做个新功能');
await vi.waitFor(() => {
expect(mocks.slackIm.updateInteractiveCard).toHaveBeenCalledWith(
'C1|anchor',
expect.objectContaining({
- title: slackUi.thread!.takeoverCard('FBot · 新功能', 'desktop-wd').title,
+ title: slackUi.thread!.takeoverCard('Slack · 新功能', 'desktop-wd').title,
buttons: [expect.objectContaining({ id: 'control:thread-exit' })],
}),
);
});
- // 接管路径不带渠道前缀(沿用 FBot 默认)
+ // 接管路径与渠道默认会话同名族: 无渠道拼装(slack)时透传渠道前缀,
+ // 与「标题生成后: 名片卡升级」用例的 'Slack · ' 前缀一致。
expect(mocks.generateAndPersistFbotTitle).toHaveBeenCalledWith(
'desktop-new-1',
'帮我做个新功能',
+ 'Slack · ',
);
});
});
diff --git a/apps/desktop/src/main/im/shared/fbotTitle.ts b/apps/desktop/src/main/im/shared/fbotTitle.ts
index 5b9c2fca2c..c05008ffa1 100644
--- a/apps/desktop/src/main/im/shared/fbotTitle.ts
+++ b/apps/desktop/src/main/im/shared/fbotTitle.ts
@@ -5,7 +5,10 @@
* 抽到独立模块避免反向 import (cardActionHandler 已经 import runAgentTurn)。
*
* 命名约定:
- * - prefix 'FBot · ' 给所有飞书 bot 接管/新建出来的 session 打标
+ * - prefix 'FBot · ' 是接管 session 标题的兜底前缀(无渠道命名约定的渠道);
+ * feishu 接管 session 与渠道默认会话对齐 — 话题 lane 走 composeGeneratedTitle
+ * ([飞书·{群名}·{话题简介}] {threadId}), DM 走 generatedTitlePrefix
+ * ([飞书·DM] {简介}), 见 turnRunner.composeOrGenerateTitle
* - 草稿态 title = 'FBot · New', 跟 desktop 'New Maker' 占位 title 同语义:
* 表示用户还没发第一条消息, 等首条消息到达后由 oneshot 生成正式 title
*
diff --git a/apps/desktop/src/main/im/shared/messageHandler.ts b/apps/desktop/src/main/im/shared/messageHandler.ts
index 387277769f..4b50d0078b 100644
--- a/apps/desktop/src/main/im/shared/messageHandler.ts
+++ b/apps/desktop/src/main/im/shared/messageHandler.ts
@@ -147,6 +147,14 @@ export function createMessageHandler(
// ── slash command (only on plain text: no attachments, no unsupported) ──
if (pureTextCommandInput && looksLikeSlashCommand(event.text)) {
+ // 渠道钩子先于命令处理 — 飞书靠它记住开话题 slash 事件的群主流取数
+ // lane(thread 前上下文), 供流程结束后话题里的第一条 agent 消息使用。
+ try {
+ adapter.onSlashCommandEvent?.(event);
+ } catch (err) {
+ const msg = err instanceof Error ? err.message : String(err);
+ log.warn(`onSlashCommandEvent threw (non-fatal): ${msg}`);
+ }
try {
await slash.handleSlashCommand(event.text, {
botContextId: event.contextId,
diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.ts
index 8e87a0c5d2..a800b674aa 100644
--- a/apps/desktop/src/main/im/shared/turnRunner.ts
+++ b/apps/desktop/src/main/im/shared/turnRunner.ts
@@ -123,6 +123,7 @@ import {
} from './authCheck';
import {
FBOT_DRAFT_TITLE,
+ FBOT_TITLE_PREFIX,
generateAndPersistFbotTitle,
generateImSessionTitleText,
persistGeneratedSessionTitle,
@@ -1639,10 +1640,40 @@ export function createTurnRunner(
}
}
+ /**
+ * 标题拼装的公共路径: 渠道自定义拼装优先(飞书话题 lane → [飞书·{群名}·
+ * {话题简介}] {threadId}), 拼装不适用(飞书 DM)回落 fallbackPrefix +
+ * oneshot 简介。没有渠道拼装的渠道直接走 fallbackPrefix。
+ */
+ async function composeOrGenerateTitle(
+ sessionId: string,
+ userId: string,
+ scopeKey: string | undefined,
+ text: string,
+ fallbackPrefix: string,
+ ): Promise<string | null> {
+ const composeTitle = adapter.sessions.composeGeneratedTitle;
+ if (!composeTitle) {
+ return generateAndPersistFbotTitle(sessionId, text, fallbackPrefix);
+ }
+ const generated = await generateImSessionTitleText(sessionId, text);
+ if (!generated) return null;
+ const title = await composeTitle(userId, scopeKey, generated, sessionId);
+ if (title) {
+ await persistGeneratedSessionTitle(sessionId, title);
+ return title;
+ }
+ return generateAndPersistFbotTitle(sessionId, text, fallbackPrefix);
+ }
+
/**
* 接管 session 首条消息触发的 title 生成 — 仅当当前 title 还是 'FBot · New'
* 草稿占位时执行, 否则 noop (说明已经生成过了)。
*
+ * 命名与渠道默认会话对齐: 有 composeGeneratedTitle 的渠道(feishu)走同一条
+ * 拼装路径(话题 lane 与普通话题会话同名族), compose 不适用(DM)回落渠道
+ * generatedTitlePrefix([飞书·DM] {简介}); 其它渠道保持 'FBot · {简介}'。
+ *
* 用 drizzle 查 title 而不是从 row 里带 — row 来自 resolveRouteTarget 早一步,
* 几十毫秒内 title 不会变, 但显式查一次更稳 (避免读到已被并发更新的旧值, 虽然
* messageHandler 的 per-user lock 已经避免了并发, 这里再加一道防御)。
@@ -1667,7 +1698,18 @@ export function createTurnRunner(
.where(eq(sessionsTable.id, sessionId))
.limit(1);
if (rows[0]?.title !== FBOT_DRAFT_TITLE) return;
- const title = await generateAndPersistFbotTitle(sessionId, text);
+ const configuredPrefix = adapter.sessions.generatedTitlePrefix;
+ const fallbackPrefix =
+ typeof configuredPrefix === 'function' ? configuredPrefix() : configuredPrefix;
+ const title = ctx
+ ? await composeOrGenerateTitle(
+ sessionId,
+ ctx.userId,
+ ctx.scopeKey,
+ text,
+ fallbackPrefix ?? FBOT_TITLE_PREFIX,
+ )
+ : await generateAndPersistFbotTitle(sessionId, text);
// thread 模型的"新建+接管": 标题生成后把锚点/root 卡也升级成正式标题
// (此前是「新会话(刚建好)」占位), 顶层一眼能看出 thread 对应哪条会话。
@@ -1726,22 +1768,16 @@ export function createTurnRunner(
return;
const prefix = typeof configuredPrefix === 'function' ? configuredPrefix() : configuredPrefix;
try {
- let title: string | null;
- if (composeTitle) {
- // 渠道自定义拼装(飞书话题 lane → [飞书·{群名}·{简介}] {threadId 后 6 位}):
- // oneshot 只负责出「话题简介」文本, 完整标题由渠道按 lane 拼; 返回 null
- // (该 lane 不适用, 如 DM)回落默认 prefix 路径。
- const generated = await generateImSessionTitleText(sessionId, text);
- if (!generated) return;
- title = await composeTitle(userId, scopeKey, generated, sessionId);
- if (title) {
- await persistGeneratedSessionTitle(sessionId, title);
- } else {
- title = await generateAndPersistFbotTitle(sessionId, text, prefix);
- }
- } else {
- title = await generateAndPersistFbotTitle(sessionId, text, prefix);
- }
+ // 渠道自定义拼装(feishu 话题 lane → [飞书·{群名}·{简介}] {threadId 后 6 位}):
+ // oneshot 只负责出「话题简介」文本, 完整标题由渠道按 lane 拼; compose
+ // 不适用(feishu DM)回落渠道前缀。无 compose 的渠道直接前缀 + 简介。
+ const title = await composeOrGenerateTitle(
+ sessionId,
+ userId,
+ scopeKey,
+ text,
+ prefix ?? FBOT_TITLE_PREFIX,
+ );
if (!richIm || !title || !headerCardId || !threadUiPack) return;
await richIm.updateInteractiveCard(headerCardId, {
...threadUiPack.sessionHeaderTitled(title),
diff --git a/apps/desktop/src/main/im/shared/types.ts b/apps/desktop/src/main/im/shared/types.ts
index a1de043a7a..cf142f68db 100644
--- a/apps/desktop/src/main/im/shared/types.ts
+++ b/apps/desktop/src/main/im/shared/types.ts
@@ -216,6 +216,14 @@ export interface ImChannelAdapter {
turnPermissionPolicyFor?(event: IMMessageEvent): TurnPermissionPolicy | undefined;
/** Telegram 每轮的群历史检索授权;其它渠道不实现即 fail closed。 */
groupHistoryAccessFor?(event: IMMessageEvent): GroupHistoryAccessScope | undefined;
+ /**
+ * slash 命令事件的渠道钩子 — 在 handleSlashCommand 之前调用。飞书用它记住
+ * 「群主流 @ 开话题」事件带的群主流取数 lane(groupContextLane): /ctr 等
+ * slash 不经过 prepareAgentTurnText, 开话题那条事件攒下的 thread 前上下文
+ * 会丢失; 记住后由话题里第一条 agent 消息领走(见 adapter 实现)。
+ * 其它渠道不实现即 no-op。
+ */
+ onSlashCommandEvent?(event: IMMessageEvent): void;
}
// ── UI 文案包 ─────────────────────────────────────────────────────────────────