@actagent/feishu 2026.6.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 +11 -0
- package/actagent.plugin.json +224 -0
- package/api.ts +33 -0
- package/channel-entry.ts +21 -0
- package/channel-plugin-api.ts +2 -0
- package/contract-api.ts +17 -0
- package/index.ts +83 -0
- package/legacy-state-migrations-api.ts +2 -0
- package/npm-shrinkwrap.json +539 -0
- package/package.json +64 -0
- package/runtime-api.ts +58 -0
- package/runtime-setter-api.ts +3 -0
- package/secret-contract-api.ts +6 -0
- package/security-contract-api.ts +2 -0
- package/session-key-api.ts +2 -0
- package/setup-api.ts +4 -0
- package/setup-entry.test.ts +33 -0
- package/setup-entry.ts +25 -0
- package/skills/feishu-doc/SKILL.md +211 -0
- package/skills/feishu-doc/references/block-types.md +103 -0
- package/skills/feishu-drive/SKILL.md +97 -0
- package/skills/feishu-perm/SKILL.md +119 -0
- package/skills/feishu-wiki/SKILL.md +113 -0
- package/src/accounts.test.ts +481 -0
- package/src/accounts.ts +380 -0
- package/src/agent-config.ts +22 -0
- package/src/app-registration.test.ts +62 -0
- package/src/app-registration.ts +355 -0
- package/src/approval-auth.test.ts +25 -0
- package/src/approval-auth.ts +26 -0
- package/src/async.test.ts +68 -0
- package/src/async.ts +109 -0
- package/src/audio-preflight.runtime.ts +10 -0
- package/src/bitable.test.ts +174 -0
- package/src/bitable.ts +781 -0
- package/src/bot-content.ts +488 -0
- package/src/bot-group-name.test.ts +148 -0
- package/src/bot-runtime-api.ts +13 -0
- package/src/bot-sender-name.test.ts +68 -0
- package/src/bot-sender-name.ts +137 -0
- package/src/bot.broadcast.test.ts +643 -0
- package/src/bot.card-action.test.ts +647 -0
- package/src/bot.checkBotMentioned.test.ts +266 -0
- package/src/bot.helpers.test.ts +136 -0
- package/src/bot.stripBotMention.test.ts +127 -0
- package/src/bot.test.ts +3817 -0
- package/src/bot.ts +1788 -0
- package/src/card-action.ts +515 -0
- package/src/card-interaction.test.ts +132 -0
- package/src/card-interaction.ts +160 -0
- package/src/card-test-helpers.ts +55 -0
- package/src/card-ux-approval.ts +66 -0
- package/src/card-ux-launcher.test.ts +126 -0
- package/src/card-ux-launcher.ts +136 -0
- package/src/card-ux-shared.ts +34 -0
- package/src/channel-runtime-api.ts +17 -0
- package/src/channel.runtime.ts +48 -0
- package/src/channel.test.ts +1337 -0
- package/src/channel.ts +1401 -0
- package/src/chat-schema.ts +30 -0
- package/src/chat.test.ts +295 -0
- package/src/chat.ts +198 -0
- package/src/client-timeout.ts +44 -0
- package/src/client.test.ts +463 -0
- package/src/client.ts +263 -0
- package/src/comment-dispatcher-runtime-api.ts +7 -0
- package/src/comment-dispatcher.test.ts +186 -0
- package/src/comment-dispatcher.ts +108 -0
- package/src/comment-handler-runtime-api.ts +4 -0
- package/src/comment-handler.test.ts +588 -0
- package/src/comment-handler.ts +304 -0
- package/src/comment-reaction.test.ts +139 -0
- package/src/comment-reaction.ts +260 -0
- package/src/comment-shared.test.ts +184 -0
- package/src/comment-shared.ts +405 -0
- package/src/comment-target.ts +45 -0
- package/src/config-schema.test.ts +327 -0
- package/src/config-schema.ts +338 -0
- package/src/conversation-id.test.ts +19 -0
- package/src/conversation-id.ts +199 -0
- package/src/dedup-migrations.test.ts +90 -0
- package/src/dedup-migrations.ts +103 -0
- package/src/dedup.test.ts +95 -0
- package/src/dedup.ts +304 -0
- package/src/dedupe-key.ts +68 -0
- package/src/directory.static.ts +62 -0
- package/src/directory.test.ts +142 -0
- package/src/directory.ts +125 -0
- package/src/doc-schema.ts +183 -0
- package/src/doctor.test.ts +382 -0
- package/src/doctor.ts +876 -0
- package/src/docx-batch-insert.test.ts +117 -0
- package/src/docx-batch-insert.ts +223 -0
- package/src/docx-color-text.ts +154 -0
- package/src/docx-table-ops.test.ts +54 -0
- package/src/docx-table-ops.ts +316 -0
- package/src/docx-types.ts +39 -0
- package/src/docx.account-selection.test.ts +96 -0
- package/src/docx.test.ts +706 -0
- package/src/docx.ts +1598 -0
- package/src/drive-schema.ts +93 -0
- package/src/drive.test.ts +1240 -0
- package/src/drive.ts +830 -0
- package/src/dynamic-agent.test.ts +156 -0
- package/src/dynamic-agent.ts +144 -0
- package/src/event-types.ts +46 -0
- package/src/external-keys.test.ts +21 -0
- package/src/external-keys.ts +20 -0
- package/src/lifecycle.test-support.ts +223 -0
- package/src/media.test.ts +956 -0
- package/src/media.ts +1106 -0
- package/src/mention-target.types.ts +6 -0
- package/src/mention.ts +115 -0
- package/src/message-action-contract.ts +14 -0
- package/src/monitor-state-runtime-api.ts +8 -0
- package/src/monitor-transport-runtime-api.ts +11 -0
- package/src/monitor.account.ts +501 -0
- package/src/monitor.acp-init-failure.lifecycle.test-support.ts +215 -0
- package/src/monitor.bot-identity.ts +87 -0
- package/src/monitor.bot-menu-handler.ts +164 -0
- package/src/monitor.bot-menu.lifecycle.test-support.ts +221 -0
- package/src/monitor.bot-menu.test.ts +200 -0
- package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +265 -0
- package/src/monitor.card-action.lifecycle.test-support.ts +418 -0
- package/src/monitor.cleanup.test.ts +384 -0
- package/src/monitor.comment-notice-handler.ts +106 -0
- package/src/monitor.comment.test.ts +968 -0
- package/src/monitor.comment.ts +1386 -0
- package/src/monitor.lifecycle.test.ts +5 -0
- package/src/monitor.message-handler.ts +346 -0
- package/src/monitor.reaction.test.ts +770 -0
- package/src/monitor.startup.test.ts +232 -0
- package/src/monitor.startup.ts +76 -0
- package/src/monitor.state.defaults.test.ts +47 -0
- package/src/monitor.state.ts +171 -0
- package/src/monitor.synthetic-error.ts +19 -0
- package/src/monitor.test-mocks.ts +47 -0
- package/src/monitor.transport.ts +451 -0
- package/src/monitor.ts +104 -0
- package/src/monitor.webhook-e2e.test.ts +284 -0
- package/src/monitor.webhook-security.test.ts +394 -0
- package/src/monitor.webhook.test-helpers.ts +138 -0
- package/src/outbound-runtime-api.ts +2 -0
- package/src/outbound.test.ts +1255 -0
- package/src/outbound.ts +742 -0
- package/src/perm-schema.ts +53 -0
- package/src/perm.ts +171 -0
- package/src/pins.ts +109 -0
- package/src/policy.test.ts +224 -0
- package/src/policy.ts +322 -0
- package/src/post.test.ts +106 -0
- package/src/post.ts +276 -0
- package/src/presentation-card.ts +204 -0
- package/src/probe.test.ts +310 -0
- package/src/probe.ts +181 -0
- package/src/processing-claims.ts +60 -0
- package/src/qr-terminal.ts +2 -0
- package/src/reactions.ts +124 -0
- package/src/reasoning-preview.test.ts +114 -0
- package/src/reasoning-preview.ts +29 -0
- package/src/reply-dispatcher-runtime-api.ts +8 -0
- package/src/reply-dispatcher.test.ts +2009 -0
- package/src/reply-dispatcher.ts +865 -0
- package/src/runtime.ts +10 -0
- package/src/secret-contract.ts +146 -0
- package/src/secret-input.ts +2 -0
- package/src/security-audit-shared.ts +70 -0
- package/src/security-audit.test.ts +60 -0
- package/src/security-audit.ts +2 -0
- package/src/send-result.ts +81 -0
- package/src/send-target.test.ts +87 -0
- package/src/send-target.ts +36 -0
- package/src/send.reply-fallback.test.ts +418 -0
- package/src/send.test.ts +661 -0
- package/src/send.ts +860 -0
- package/src/sequential-key.test.ts +73 -0
- package/src/sequential-key.ts +29 -0
- package/src/sequential-queue.test.ts +184 -0
- package/src/sequential-queue.ts +90 -0
- package/src/session-conversation.ts +42 -0
- package/src/session-route.ts +49 -0
- package/src/setup-core.ts +52 -0
- package/src/setup-surface.test.ts +485 -0
- package/src/setup-surface.ts +620 -0
- package/src/streaming-card.test.ts +549 -0
- package/src/streaming-card.ts +611 -0
- package/src/subagent-hooks.test.ts +632 -0
- package/src/subagent-hooks.ts +414 -0
- package/src/targets.ts +98 -0
- package/src/test-support/lifecycle-test-support.ts +459 -0
- package/src/thread-bindings.test.ts +181 -0
- package/src/thread-bindings.ts +332 -0
- package/src/tool-account-routing.test.ts +419 -0
- package/src/tool-account.test.ts +45 -0
- package/src/tool-account.ts +98 -0
- package/src/tool-factory-test-harness.ts +83 -0
- package/src/tool-result.test.ts +33 -0
- package/src/tool-result.ts +17 -0
- package/src/tools-config.test.ts +52 -0
- package/src/tools-config.ts +29 -0
- package/src/types.ts +111 -0
- package/src/typing.test.ts +145 -0
- package/src/typing.ts +215 -0
- package/src/wiki-schema.ts +70 -0
- package/src/wiki.ts +271 -0
- package/subagent-hooks-api.ts +22 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// Feishu plugin module implements thread bindings behavior.
|
|
2
|
+
import type { ACTAgentConfig } from "actagent/plugin-sdk/config-contracts";
|
|
3
|
+
import {
|
|
4
|
+
resolveThreadBindingIdleTimeoutMsForChannel,
|
|
5
|
+
resolveThreadBindingMaxAgeMsForChannel,
|
|
6
|
+
registerSessionBindingAdapter,
|
|
7
|
+
resolveThreadBindingConversationIdFromBindingId,
|
|
8
|
+
unregisterSessionBindingAdapter,
|
|
9
|
+
type BindingTargetKind,
|
|
10
|
+
type SessionBindingAdapter,
|
|
11
|
+
type SessionBindingRecord,
|
|
12
|
+
} from "actagent/plugin-sdk/conversation-runtime";
|
|
13
|
+
import { normalizeAccountId, resolveAgentIdFromSessionKey } from "actagent/plugin-sdk/routing";
|
|
14
|
+
import { normalizeOptionalString } from "actagent/plugin-sdk/string-coerce-runtime";
|
|
15
|
+
|
|
16
|
+
type FeishuBindingTargetKind = "subagent" | "acp";
|
|
17
|
+
|
|
18
|
+
type FeishuThreadBindingRecord = {
|
|
19
|
+
accountId: string;
|
|
20
|
+
conversationId: string;
|
|
21
|
+
parentConversationId?: string;
|
|
22
|
+
deliveryTo?: string;
|
|
23
|
+
deliveryThreadId?: string;
|
|
24
|
+
targetKind: FeishuBindingTargetKind;
|
|
25
|
+
targetSessionKey: string;
|
|
26
|
+
agentId?: string;
|
|
27
|
+
label?: string;
|
|
28
|
+
boundBy?: string;
|
|
29
|
+
boundAt: number;
|
|
30
|
+
lastActivityAt: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type FeishuThreadBindingManager = {
|
|
34
|
+
accountId: string;
|
|
35
|
+
getByConversationId: (conversationId: string) => FeishuThreadBindingRecord | undefined;
|
|
36
|
+
listBySessionKey: (targetSessionKey: string) => FeishuThreadBindingRecord[];
|
|
37
|
+
bindConversation: (params: {
|
|
38
|
+
conversationId: string;
|
|
39
|
+
parentConversationId?: string;
|
|
40
|
+
targetKind: BindingTargetKind;
|
|
41
|
+
targetSessionKey: string;
|
|
42
|
+
metadata?: Record<string, unknown>;
|
|
43
|
+
}) => FeishuThreadBindingRecord | null;
|
|
44
|
+
touchConversation: (conversationId: string, at?: number) => FeishuThreadBindingRecord | null;
|
|
45
|
+
unbindConversation: (conversationId: string) => FeishuThreadBindingRecord | null;
|
|
46
|
+
unbindBySessionKey: (targetSessionKey: string) => FeishuThreadBindingRecord[];
|
|
47
|
+
stop: () => void;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
type FeishuThreadBindingsState = {
|
|
51
|
+
managersByAccountId: Map<string, FeishuThreadBindingManager>;
|
|
52
|
+
bindingsByAccountConversation: Map<string, FeishuThreadBindingRecord>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const FEISHU_THREAD_BINDINGS_STATE_KEY = Symbol.for("actagent.feishuThreadBindingsState");
|
|
56
|
+
let state: FeishuThreadBindingsState | undefined;
|
|
57
|
+
|
|
58
|
+
function getState(): FeishuThreadBindingsState {
|
|
59
|
+
if (!state) {
|
|
60
|
+
const globalStore = globalThis as Record<PropertyKey, unknown>;
|
|
61
|
+
state = (globalStore[FEISHU_THREAD_BINDINGS_STATE_KEY] as
|
|
62
|
+
| FeishuThreadBindingsState
|
|
63
|
+
| undefined) ?? {
|
|
64
|
+
managersByAccountId: new Map(),
|
|
65
|
+
bindingsByAccountConversation: new Map(),
|
|
66
|
+
};
|
|
67
|
+
globalStore[FEISHU_THREAD_BINDINGS_STATE_KEY] = state;
|
|
68
|
+
}
|
|
69
|
+
return state;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function resolveBindingKey(params: { accountId: string; conversationId: string }): string {
|
|
73
|
+
return `${params.accountId}:${params.conversationId}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function toSessionBindingTargetKind(raw: FeishuBindingTargetKind): BindingTargetKind {
|
|
77
|
+
return raw === "subagent" ? "subagent" : "session";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function toFeishuTargetKind(raw: BindingTargetKind): FeishuBindingTargetKind {
|
|
81
|
+
return raw === "subagent" ? "subagent" : "acp";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function toSessionBindingRecord(
|
|
85
|
+
record: FeishuThreadBindingRecord,
|
|
86
|
+
defaults: { idleTimeoutMs: number; maxAgeMs: number },
|
|
87
|
+
): SessionBindingRecord {
|
|
88
|
+
const idleExpiresAt =
|
|
89
|
+
defaults.idleTimeoutMs > 0 ? record.lastActivityAt + defaults.idleTimeoutMs : undefined;
|
|
90
|
+
const maxAgeExpiresAt = defaults.maxAgeMs > 0 ? record.boundAt + defaults.maxAgeMs : undefined;
|
|
91
|
+
const expiresAt =
|
|
92
|
+
idleExpiresAt != null && maxAgeExpiresAt != null
|
|
93
|
+
? Math.min(idleExpiresAt, maxAgeExpiresAt)
|
|
94
|
+
: (idleExpiresAt ?? maxAgeExpiresAt);
|
|
95
|
+
return {
|
|
96
|
+
bindingId: resolveBindingKey({
|
|
97
|
+
accountId: record.accountId,
|
|
98
|
+
conversationId: record.conversationId,
|
|
99
|
+
}),
|
|
100
|
+
targetSessionKey: record.targetSessionKey,
|
|
101
|
+
targetKind: toSessionBindingTargetKind(record.targetKind),
|
|
102
|
+
conversation: {
|
|
103
|
+
channel: "feishu",
|
|
104
|
+
accountId: record.accountId,
|
|
105
|
+
conversationId: record.conversationId,
|
|
106
|
+
parentConversationId: record.parentConversationId,
|
|
107
|
+
},
|
|
108
|
+
status: "active",
|
|
109
|
+
boundAt: record.boundAt,
|
|
110
|
+
expiresAt,
|
|
111
|
+
metadata: {
|
|
112
|
+
agentId: record.agentId,
|
|
113
|
+
label: record.label,
|
|
114
|
+
boundBy: record.boundBy,
|
|
115
|
+
deliveryTo: record.deliveryTo,
|
|
116
|
+
deliveryThreadId: record.deliveryThreadId,
|
|
117
|
+
lastActivityAt: record.lastActivityAt,
|
|
118
|
+
idleTimeoutMs: defaults.idleTimeoutMs,
|
|
119
|
+
maxAgeMs: defaults.maxAgeMs,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function createFeishuThreadBindingManager(params: {
|
|
125
|
+
accountId?: string;
|
|
126
|
+
cfg: ACTAgentConfig;
|
|
127
|
+
}): FeishuThreadBindingManager {
|
|
128
|
+
const accountId = normalizeAccountId(params.accountId);
|
|
129
|
+
const existing = getState().managersByAccountId.get(accountId);
|
|
130
|
+
if (existing) {
|
|
131
|
+
return existing;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const idleTimeoutMs = resolveThreadBindingIdleTimeoutMsForChannel({
|
|
135
|
+
cfg: params.cfg,
|
|
136
|
+
channel: "feishu",
|
|
137
|
+
accountId,
|
|
138
|
+
});
|
|
139
|
+
const maxAgeMs = resolveThreadBindingMaxAgeMsForChannel({
|
|
140
|
+
cfg: params.cfg,
|
|
141
|
+
channel: "feishu",
|
|
142
|
+
accountId,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const manager: FeishuThreadBindingManager = {
|
|
146
|
+
accountId,
|
|
147
|
+
getByConversationId: (conversationId) =>
|
|
148
|
+
getState().bindingsByAccountConversation.get(
|
|
149
|
+
resolveBindingKey({ accountId, conversationId }),
|
|
150
|
+
),
|
|
151
|
+
listBySessionKey: (targetSessionKey) =>
|
|
152
|
+
[...getState().bindingsByAccountConversation.values()].filter(
|
|
153
|
+
(record) => record.accountId === accountId && record.targetSessionKey === targetSessionKey,
|
|
154
|
+
),
|
|
155
|
+
bindConversation: ({
|
|
156
|
+
conversationId,
|
|
157
|
+
parentConversationId,
|
|
158
|
+
targetKind,
|
|
159
|
+
targetSessionKey,
|
|
160
|
+
metadata,
|
|
161
|
+
}) => {
|
|
162
|
+
const normalizedConversationId = conversationId.trim();
|
|
163
|
+
const normalizedTargetSessionKey = targetSessionKey.trim();
|
|
164
|
+
if (!normalizedConversationId || !normalizedTargetSessionKey) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
const existingLocal = getState().bindingsByAccountConversation.get(
|
|
168
|
+
resolveBindingKey({ accountId, conversationId: normalizedConversationId }),
|
|
169
|
+
);
|
|
170
|
+
const now = Date.now();
|
|
171
|
+
const record: FeishuThreadBindingRecord = {
|
|
172
|
+
accountId,
|
|
173
|
+
conversationId: normalizedConversationId,
|
|
174
|
+
parentConversationId:
|
|
175
|
+
normalizeOptionalString(parentConversationId) ?? existingLocal?.parentConversationId,
|
|
176
|
+
deliveryTo:
|
|
177
|
+
typeof metadata?.deliveryTo === "string" && metadata.deliveryTo.trim()
|
|
178
|
+
? metadata.deliveryTo.trim()
|
|
179
|
+
: existingLocal?.deliveryTo,
|
|
180
|
+
deliveryThreadId:
|
|
181
|
+
typeof metadata?.deliveryThreadId === "string" && metadata.deliveryThreadId.trim()
|
|
182
|
+
? metadata.deliveryThreadId.trim()
|
|
183
|
+
: existingLocal?.deliveryThreadId,
|
|
184
|
+
targetKind: toFeishuTargetKind(targetKind),
|
|
185
|
+
targetSessionKey: normalizedTargetSessionKey,
|
|
186
|
+
agentId:
|
|
187
|
+
typeof metadata?.agentId === "string" && metadata.agentId.trim()
|
|
188
|
+
? metadata.agentId.trim()
|
|
189
|
+
: (existingLocal?.agentId ?? resolveAgentIdFromSessionKey(normalizedTargetSessionKey)),
|
|
190
|
+
label:
|
|
191
|
+
typeof metadata?.label === "string" && metadata.label.trim()
|
|
192
|
+
? metadata.label.trim()
|
|
193
|
+
: existingLocal?.label,
|
|
194
|
+
boundBy:
|
|
195
|
+
typeof metadata?.boundBy === "string" && metadata.boundBy.trim()
|
|
196
|
+
? metadata.boundBy.trim()
|
|
197
|
+
: existingLocal?.boundBy,
|
|
198
|
+
boundAt: now,
|
|
199
|
+
lastActivityAt: now,
|
|
200
|
+
};
|
|
201
|
+
getState().bindingsByAccountConversation.set(
|
|
202
|
+
resolveBindingKey({ accountId, conversationId: normalizedConversationId }),
|
|
203
|
+
record,
|
|
204
|
+
);
|
|
205
|
+
return record;
|
|
206
|
+
},
|
|
207
|
+
touchConversation: (conversationId, at = Date.now()) => {
|
|
208
|
+
const key = resolveBindingKey({ accountId, conversationId });
|
|
209
|
+
const existingRecord = getState().bindingsByAccountConversation.get(key);
|
|
210
|
+
if (!existingRecord) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
const updated = { ...existingRecord, lastActivityAt: at };
|
|
214
|
+
getState().bindingsByAccountConversation.set(key, updated);
|
|
215
|
+
return updated;
|
|
216
|
+
},
|
|
217
|
+
unbindConversation: (conversationId) => {
|
|
218
|
+
const key = resolveBindingKey({ accountId, conversationId });
|
|
219
|
+
const existingRecord = getState().bindingsByAccountConversation.get(key);
|
|
220
|
+
if (!existingRecord) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
getState().bindingsByAccountConversation.delete(key);
|
|
224
|
+
return existingRecord;
|
|
225
|
+
},
|
|
226
|
+
unbindBySessionKey: (targetSessionKey) => {
|
|
227
|
+
const removed: FeishuThreadBindingRecord[] = [];
|
|
228
|
+
for (const record of getState().bindingsByAccountConversation.values()) {
|
|
229
|
+
if (record.accountId !== accountId || record.targetSessionKey !== targetSessionKey) {
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
getState().bindingsByAccountConversation.delete(
|
|
233
|
+
resolveBindingKey({ accountId, conversationId: record.conversationId }),
|
|
234
|
+
);
|
|
235
|
+
removed.push(record);
|
|
236
|
+
}
|
|
237
|
+
return removed;
|
|
238
|
+
},
|
|
239
|
+
stop: () => {
|
|
240
|
+
for (const key of getState().bindingsByAccountConversation.keys()) {
|
|
241
|
+
if (key.startsWith(`${accountId}:`)) {
|
|
242
|
+
getState().bindingsByAccountConversation.delete(key);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
getState().managersByAccountId.delete(accountId);
|
|
246
|
+
unregisterSessionBindingAdapter({
|
|
247
|
+
channel: "feishu",
|
|
248
|
+
accountId,
|
|
249
|
+
adapter: sessionBindingAdapter,
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const sessionBindingAdapter: SessionBindingAdapter = {
|
|
255
|
+
channel: "feishu",
|
|
256
|
+
accountId,
|
|
257
|
+
capabilities: {
|
|
258
|
+
placements: ["current"],
|
|
259
|
+
},
|
|
260
|
+
bind: async (input) => {
|
|
261
|
+
if (input.conversation.channel !== "feishu" || input.placement === "child") {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
const bound = manager.bindConversation({
|
|
265
|
+
conversationId: input.conversation.conversationId,
|
|
266
|
+
parentConversationId: input.conversation.parentConversationId,
|
|
267
|
+
targetKind: input.targetKind,
|
|
268
|
+
targetSessionKey: input.targetSessionKey,
|
|
269
|
+
metadata: input.metadata,
|
|
270
|
+
});
|
|
271
|
+
return bound ? toSessionBindingRecord(bound, { idleTimeoutMs, maxAgeMs }) : null;
|
|
272
|
+
},
|
|
273
|
+
listBySession: (targetSessionKey) =>
|
|
274
|
+
manager
|
|
275
|
+
.listBySessionKey(targetSessionKey)
|
|
276
|
+
.map((entry) => toSessionBindingRecord(entry, { idleTimeoutMs, maxAgeMs })),
|
|
277
|
+
resolveByConversation: (ref) => {
|
|
278
|
+
if (ref.channel !== "feishu") {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
const found = manager.getByConversationId(ref.conversationId);
|
|
282
|
+
return found ? toSessionBindingRecord(found, { idleTimeoutMs, maxAgeMs }) : null;
|
|
283
|
+
},
|
|
284
|
+
touch: (bindingId, at) => {
|
|
285
|
+
const conversationId = resolveThreadBindingConversationIdFromBindingId({
|
|
286
|
+
accountId,
|
|
287
|
+
bindingId,
|
|
288
|
+
});
|
|
289
|
+
if (conversationId) {
|
|
290
|
+
manager.touchConversation(conversationId, at);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
unbind: async (input) => {
|
|
294
|
+
if (input.targetSessionKey?.trim()) {
|
|
295
|
+
return manager
|
|
296
|
+
.unbindBySessionKey(input.targetSessionKey.trim())
|
|
297
|
+
.map((entry) => toSessionBindingRecord(entry, { idleTimeoutMs, maxAgeMs }));
|
|
298
|
+
}
|
|
299
|
+
const conversationId = resolveThreadBindingConversationIdFromBindingId({
|
|
300
|
+
accountId,
|
|
301
|
+
bindingId: input.bindingId,
|
|
302
|
+
});
|
|
303
|
+
if (!conversationId) {
|
|
304
|
+
return [];
|
|
305
|
+
}
|
|
306
|
+
const removed = manager.unbindConversation(conversationId);
|
|
307
|
+
return removed ? [toSessionBindingRecord(removed, { idleTimeoutMs, maxAgeMs })] : [];
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
registerSessionBindingAdapter(sessionBindingAdapter);
|
|
312
|
+
|
|
313
|
+
getState().managersByAccountId.set(accountId, manager);
|
|
314
|
+
return manager;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export function getFeishuThreadBindingManager(
|
|
318
|
+
accountId?: string,
|
|
319
|
+
): FeishuThreadBindingManager | null {
|
|
320
|
+
return getState().managersByAccountId.get(normalizeAccountId(accountId)) ?? null;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export const testing = {
|
|
324
|
+
resetFeishuThreadBindingsForTests() {
|
|
325
|
+
for (const manager of getState().managersByAccountId.values()) {
|
|
326
|
+
manager.stop();
|
|
327
|
+
}
|
|
328
|
+
getState().managersByAccountId.clear();
|
|
329
|
+
getState().bindingsByAccountConversation.clear();
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
export { testing as __testing };
|