@kodelyth/feishu 2026.5.42 → 2026.6.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.
Files changed (192) hide show
  1. package/klaw.plugin.json +1712 -47
  2. package/package.json +17 -4
  3. package/api.ts +0 -32
  4. package/channel-entry.ts +0 -20
  5. package/channel-plugin-api.ts +0 -1
  6. package/contract-api.ts +0 -16
  7. package/index.ts +0 -82
  8. package/runtime-api.ts +0 -52
  9. package/secret-contract-api.ts +0 -5
  10. package/security-contract-api.ts +0 -1
  11. package/session-key-api.ts +0 -1
  12. package/setup-api.ts +0 -3
  13. package/setup-entry.test.ts +0 -19
  14. package/setup-entry.ts +0 -13
  15. package/src/accounts.test.ts +0 -480
  16. package/src/accounts.ts +0 -333
  17. package/src/agent-config.ts +0 -21
  18. package/src/app-registration.ts +0 -331
  19. package/src/approval-auth.test.ts +0 -24
  20. package/src/approval-auth.ts +0 -25
  21. package/src/async.test.ts +0 -35
  22. package/src/async.ts +0 -104
  23. package/src/audio-preflight.runtime.ts +0 -9
  24. package/src/bitable.test.ts +0 -136
  25. package/src/bitable.ts +0 -762
  26. package/src/bot-content.ts +0 -485
  27. package/src/bot-group-name.test.ts +0 -116
  28. package/src/bot-runtime-api.ts +0 -12
  29. package/src/bot-sender-name.ts +0 -125
  30. package/src/bot.broadcast.test.ts +0 -523
  31. package/src/bot.card-action.test.ts +0 -552
  32. package/src/bot.checkBotMentioned.test.ts +0 -265
  33. package/src/bot.helpers.test.ts +0 -135
  34. package/src/bot.stripBotMention.test.ts +0 -126
  35. package/src/bot.test.ts +0 -3671
  36. package/src/bot.ts +0 -1703
  37. package/src/card-action.ts +0 -447
  38. package/src/card-interaction.test.ts +0 -131
  39. package/src/card-interaction.ts +0 -159
  40. package/src/card-test-helpers.ts +0 -54
  41. package/src/card-ux-approval.ts +0 -65
  42. package/src/card-ux-launcher.test.ts +0 -106
  43. package/src/card-ux-launcher.ts +0 -121
  44. package/src/card-ux-shared.ts +0 -33
  45. package/src/channel-runtime-api.ts +0 -16
  46. package/src/channel.runtime.ts +0 -47
  47. package/src/channel.test.ts +0 -1151
  48. package/src/channel.ts +0 -1423
  49. package/src/chat-schema.ts +0 -25
  50. package/src/chat.test.ts +0 -240
  51. package/src/chat.ts +0 -188
  52. package/src/client-timeout.ts +0 -42
  53. package/src/client.test.ts +0 -447
  54. package/src/client.ts +0 -262
  55. package/src/comment-dispatcher-runtime-api.ts +0 -6
  56. package/src/comment-dispatcher.test.ts +0 -185
  57. package/src/comment-dispatcher.ts +0 -107
  58. package/src/comment-handler-runtime-api.ts +0 -3
  59. package/src/comment-handler.test.ts +0 -592
  60. package/src/comment-handler.ts +0 -303
  61. package/src/comment-reaction.test.ts +0 -138
  62. package/src/comment-reaction.ts +0 -259
  63. package/src/comment-shared.test.ts +0 -183
  64. package/src/comment-shared.ts +0 -406
  65. package/src/comment-target.ts +0 -44
  66. package/src/config-schema.test.ts +0 -326
  67. package/src/config-schema.ts +0 -335
  68. package/src/conversation-id.test.ts +0 -18
  69. package/src/conversation-id.ts +0 -199
  70. package/src/dedup-runtime-api.ts +0 -1
  71. package/src/dedup.ts +0 -141
  72. package/src/dedupe-key.ts +0 -72
  73. package/src/directory.static.ts +0 -61
  74. package/src/directory.test.ts +0 -141
  75. package/src/directory.ts +0 -124
  76. package/src/doc-schema.ts +0 -182
  77. package/src/docx-batch-insert.test.ts +0 -116
  78. package/src/docx-batch-insert.ts +0 -223
  79. package/src/docx-color-text.ts +0 -154
  80. package/src/docx-table-ops.test.ts +0 -53
  81. package/src/docx-table-ops.ts +0 -316
  82. package/src/docx-types.ts +0 -38
  83. package/src/docx.account-selection.test.ts +0 -95
  84. package/src/docx.test.ts +0 -701
  85. package/src/docx.ts +0 -1596
  86. package/src/drive-schema.ts +0 -92
  87. package/src/drive.test.ts +0 -1237
  88. package/src/drive.ts +0 -829
  89. package/src/dynamic-agent.test.ts +0 -155
  90. package/src/dynamic-agent.ts +0 -143
  91. package/src/event-types.ts +0 -45
  92. package/src/external-keys.test.ts +0 -20
  93. package/src/external-keys.ts +0 -19
  94. package/src/lifecycle.test-support.ts +0 -220
  95. package/src/media.test.ts +0 -955
  96. package/src/media.ts +0 -1105
  97. package/src/mention-target.types.ts +0 -5
  98. package/src/mention.ts +0 -114
  99. package/src/message-action-contract.ts +0 -13
  100. package/src/monitor-state-runtime-api.ts +0 -7
  101. package/src/monitor-transport-runtime-api.ts +0 -10
  102. package/src/monitor.account.ts +0 -492
  103. package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
  104. package/src/monitor.bot-identity.ts +0 -86
  105. package/src/monitor.bot-menu-handler.ts +0 -165
  106. package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
  107. package/src/monitor.bot-menu.test.ts +0 -188
  108. package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
  109. package/src/monitor.card-action.lifecycle.test-support.ts +0 -421
  110. package/src/monitor.cleanup.test.ts +0 -383
  111. package/src/monitor.comment-notice-handler.ts +0 -105
  112. package/src/monitor.comment.test.ts +0 -967
  113. package/src/monitor.comment.ts +0 -1386
  114. package/src/monitor.lifecycle.test.ts +0 -4
  115. package/src/monitor.message-handler.ts +0 -350
  116. package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
  117. package/src/monitor.reaction.test.ts +0 -739
  118. package/src/monitor.startup.test.ts +0 -213
  119. package/src/monitor.startup.ts +0 -74
  120. package/src/monitor.state.defaults.test.ts +0 -46
  121. package/src/monitor.state.ts +0 -170
  122. package/src/monitor.synthetic-error.ts +0 -18
  123. package/src/monitor.test-mocks.ts +0 -46
  124. package/src/monitor.transport.ts +0 -451
  125. package/src/monitor.ts +0 -100
  126. package/src/monitor.webhook-e2e.test.ts +0 -279
  127. package/src/monitor.webhook-security.test.ts +0 -389
  128. package/src/monitor.webhook.test-helpers.ts +0 -116
  129. package/src/outbound-runtime-api.ts +0 -1
  130. package/src/outbound.test.ts +0 -1118
  131. package/src/outbound.ts +0 -785
  132. package/src/perm-schema.ts +0 -52
  133. package/src/perm.ts +0 -170
  134. package/src/pins.ts +0 -108
  135. package/src/policy.test.ts +0 -223
  136. package/src/policy.ts +0 -318
  137. package/src/post.test.ts +0 -105
  138. package/src/post.ts +0 -275
  139. package/src/probe.test.ts +0 -283
  140. package/src/probe.ts +0 -166
  141. package/src/processing-claims.ts +0 -59
  142. package/src/qr-terminal.ts +0 -1
  143. package/src/reactions.ts +0 -123
  144. package/src/reasoning-preview.test.ts +0 -113
  145. package/src/reasoning-preview.ts +0 -28
  146. package/src/reply-dispatcher-runtime-api.ts +0 -7
  147. package/src/reply-dispatcher.test.ts +0 -1513
  148. package/src/reply-dispatcher.ts +0 -748
  149. package/src/runtime.ts +0 -9
  150. package/src/secret-contract.ts +0 -145
  151. package/src/secret-input.ts +0 -1
  152. package/src/security-audit-shared.ts +0 -69
  153. package/src/security-audit.test.ts +0 -59
  154. package/src/security-audit.ts +0 -1
  155. package/src/send-result.ts +0 -80
  156. package/src/send-target.test.ts +0 -86
  157. package/src/send-target.ts +0 -35
  158. package/src/send.reply-fallback.test.ts +0 -417
  159. package/src/send.test.ts +0 -621
  160. package/src/send.ts +0 -861
  161. package/src/sequential-key.test.ts +0 -72
  162. package/src/sequential-key.ts +0 -25
  163. package/src/sequential-queue.test.ts +0 -165
  164. package/src/sequential-queue.ts +0 -86
  165. package/src/session-conversation.ts +0 -42
  166. package/src/session-route.ts +0 -48
  167. package/src/setup-core.ts +0 -51
  168. package/src/setup-surface.test.ts +0 -484
  169. package/src/setup-surface.ts +0 -618
  170. package/src/streaming-card.test.ts +0 -397
  171. package/src/streaming-card.ts +0 -571
  172. package/src/subagent-hooks.test.ts +0 -627
  173. package/src/subagent-hooks.ts +0 -413
  174. package/src/targets.ts +0 -97
  175. package/src/test-support/lifecycle-test-support.ts +0 -454
  176. package/src/thread-bindings.test.ts +0 -180
  177. package/src/thread-bindings.ts +0 -331
  178. package/src/tool-account-routing.test.ts +0 -250
  179. package/src/tool-account.test.ts +0 -44
  180. package/src/tool-account.ts +0 -93
  181. package/src/tool-factory-test-harness.ts +0 -79
  182. package/src/tool-result.test.ts +0 -32
  183. package/src/tool-result.ts +0 -16
  184. package/src/tools-config.test.ts +0 -21
  185. package/src/tools-config.ts +0 -22
  186. package/src/types.ts +0 -106
  187. package/src/typing.test.ts +0 -144
  188. package/src/typing.ts +0 -214
  189. package/src/wiki-schema.ts +0 -69
  190. package/src/wiki.ts +0 -270
  191. package/subagent-hooks-api.ts +0 -31
  192. package/tsconfig.json +0 -16
@@ -1,72 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { FeishuMessageEvent } from "./bot.js";
3
- import { getFeishuSequentialKey } from "./sequential-key.js";
4
-
5
- function createTextEvent(params: {
6
- text: string;
7
- messageId?: string;
8
- chatId?: string;
9
- }): FeishuMessageEvent {
10
- return {
11
- sender: {
12
- sender_id: {
13
- open_id: "ou_sender_1",
14
- user_id: "ou_user_1",
15
- },
16
- sender_type: "user",
17
- },
18
- message: {
19
- message_id: params.messageId ?? "om_message_1",
20
- chat_id: params.chatId ?? "oc_dm_chat",
21
- chat_type: "p2p",
22
- message_type: "text",
23
- content: JSON.stringify({ text: params.text }),
24
- },
25
- } as FeishuMessageEvent;
26
- }
27
-
28
- describe("getFeishuSequentialKey", () => {
29
- it.each([
30
- [createTextEvent({ text: "hello" }), "feishu:default:oc_dm_chat"],
31
- [createTextEvent({ text: "/status" }), "feishu:default:oc_dm_chat"],
32
- [createTextEvent({ text: "/stop" }), "feishu:default:oc_dm_chat:control"],
33
- [createTextEvent({ text: "/btw what changed?" }), "feishu:default:oc_dm_chat:btw"],
34
- ])("resolves sequential key %#", (event, expected) => {
35
- expect(
36
- getFeishuSequentialKey({
37
- accountId: "default",
38
- event,
39
- }),
40
- ).toBe(expected);
41
- });
42
-
43
- it("keeps /btw on a stable per-chat lane across different message ids", () => {
44
- const first = createTextEvent({ text: "/btw one", messageId: "om_message_1" });
45
- const second = createTextEvent({ text: "/btw two", messageId: "om_message_2" });
46
-
47
- expect(
48
- getFeishuSequentialKey({
49
- accountId: "default",
50
- event: first,
51
- }),
52
- ).toBe("feishu:default:oc_dm_chat:btw");
53
- expect(
54
- getFeishuSequentialKey({
55
- accountId: "default",
56
- event: second,
57
- }),
58
- ).toBe("feishu:default:oc_dm_chat:btw");
59
- });
60
-
61
- it("falls back to a stable btw lane when the message id is unavailable", () => {
62
- const event = createTextEvent({ text: "/btw what changed?" });
63
- delete (event.message as { message_id?: string }).message_id;
64
-
65
- expect(
66
- getFeishuSequentialKey({
67
- accountId: "default",
68
- event,
69
- }),
70
- ).toBe("feishu:default:oc_dm_chat:btw");
71
- });
72
- });
@@ -1,25 +0,0 @@
1
- import { isAbortRequestText, isBtwRequestText } from "klaw/plugin-sdk/command-primitives-runtime";
2
- import { parseFeishuMessageEvent, type FeishuMessageEvent } from "./bot.js";
3
-
4
- export function getFeishuSequentialKey(params: {
5
- accountId: string;
6
- event: FeishuMessageEvent;
7
- botOpenId?: string;
8
- botName?: string;
9
- }): string {
10
- const { accountId, event, botOpenId, botName } = params;
11
- const chatId = event.message.chat_id?.trim() || "unknown";
12
- const baseKey = `feishu:${accountId}:${chatId}`;
13
- const parsed = parseFeishuMessageEvent(event, botOpenId, botName);
14
- const text = parsed.content.trim();
15
-
16
- if (isAbortRequestText(text)) {
17
- return `${baseKey}:control`;
18
- }
19
-
20
- if (isBtwRequestText(text)) {
21
- return `${baseKey}:btw`;
22
- }
23
-
24
- return baseKey;
25
- }
@@ -1,165 +0,0 @@
1
- import { afterEach, describe, expect, it, vi } from "vitest";
2
- import { createSequentialQueue } from "./sequential-queue.js";
3
-
4
- function createDeferred() {
5
- let resolve: (() => void) | undefined;
6
- const promise = new Promise<void>((res) => {
7
- resolve = res;
8
- });
9
- if (!resolve) {
10
- throw new Error("Expected deferred resolver to be initialized");
11
- }
12
- return { promise, resolve };
13
- }
14
-
15
- describe("createSequentialQueue", () => {
16
- afterEach(() => {
17
- vi.useRealTimers();
18
- });
19
-
20
- it("serializes tasks for the same key", async () => {
21
- const enqueue = createSequentialQueue();
22
- const gate = createDeferred();
23
- const order: string[] = [];
24
-
25
- const first = enqueue("feishu:default:chat-1", async () => {
26
- order.push("first:start");
27
- await gate.promise;
28
- order.push("first:end");
29
- });
30
- const second = enqueue("feishu:default:chat-1", async () => {
31
- order.push("second:start");
32
- order.push("second:end");
33
- });
34
-
35
- await Promise.resolve();
36
- expect(order).toEqual(["first:start"]);
37
-
38
- gate.resolve();
39
- await Promise.all([first, second]);
40
-
41
- expect(order).toEqual(["first:start", "first:end", "second:start", "second:end"]);
42
- });
43
-
44
- it("allows different keys to run concurrently", async () => {
45
- const enqueue = createSequentialQueue();
46
- const gateA = createDeferred();
47
- const gateB = createDeferred();
48
- const order: string[] = [];
49
-
50
- const first = enqueue("feishu:default:chat-1", async () => {
51
- order.push("chat-1:start");
52
- await gateA.promise;
53
- order.push("chat-1:end");
54
- });
55
- const second = enqueue("feishu:default:chat-1:btw:om_2", async () => {
56
- order.push("btw:start");
57
- await gateB.promise;
58
- order.push("btw:end");
59
- });
60
-
61
- await Promise.resolve();
62
- expect(order).toEqual(["chat-1:start", "btw:start"]);
63
-
64
- gateA.resolve();
65
- gateB.resolve();
66
- await Promise.all([first, second]);
67
-
68
- expect(order).toContain("chat-1:end");
69
- expect(order).toContain("btw:end");
70
- });
71
-
72
- it("does not leak unhandled rejections when a queued task fails", async () => {
73
- const enqueue = createSequentialQueue();
74
- const unhandled: unknown[] = [];
75
- const onUnhandledRejection = (reason: unknown) => {
76
- unhandled.push(reason);
77
- };
78
- process.on("unhandledRejection", onUnhandledRejection);
79
-
80
- try {
81
- await expect(
82
- enqueue("feishu:default:chat-1", async () => {
83
- throw new Error("boom");
84
- }),
85
- ).rejects.toThrow("boom");
86
-
87
- await new Promise<void>((resolve) => setImmediate(resolve));
88
- expect(unhandled).toStrictEqual([]);
89
-
90
- await expect(
91
- enqueue("feishu:default:chat-1", async () => {
92
- return;
93
- }),
94
- ).resolves.toBeUndefined();
95
- } finally {
96
- process.off("unhandledRejection", onUnhandledRejection);
97
- }
98
- });
99
-
100
- it("evicts a stuck task after taskTimeoutMs so newer same-key work proceeds", async () => {
101
- vi.useFakeTimers();
102
- const timeouts: Array<{ key: string; timeoutMs: number }> = [];
103
- const enqueue = createSequentialQueue({
104
- taskTimeoutMs: 25,
105
- onTaskTimeout: (key, timeoutMs) => {
106
- timeouts.push({ key, timeoutMs });
107
- },
108
- });
109
- const order: string[] = [];
110
-
111
- // Stuck task — never resolves until the test cleans up.
112
- const stuckGate = createDeferred();
113
- const stuck = enqueue("feishu:default:chat-stuck", async () => {
114
- order.push("stuck:start");
115
- await stuckGate.promise;
116
- order.push("stuck:end");
117
- });
118
-
119
- // Second same-key task — would be starved indefinitely without the cap.
120
- const followUp = enqueue("feishu:default:chat-stuck", async () => {
121
- order.push("follow-up:ran");
122
- });
123
-
124
- await vi.advanceTimersByTimeAsync(25);
125
- await followUp;
126
-
127
- expect(order).toEqual(["stuck:start", "follow-up:ran"]);
128
- expect(timeouts).toEqual([{ key: "feishu:default:chat-stuck", timeoutMs: 25 }]);
129
-
130
- // Drain the leaked stuck task so it doesn't trip the unhandled-rejection guard.
131
- stuckGate.resolve();
132
- await stuck;
133
- });
134
-
135
- it("disables the timeout cap when taskTimeoutMs is 0 (legacy behavior)", async () => {
136
- vi.useFakeTimers();
137
- const timeouts: Array<{ key: string; timeoutMs: number }> = [];
138
- const enqueue = createSequentialQueue({
139
- taskTimeoutMs: 0,
140
- onTaskTimeout: (key, timeoutMs) => {
141
- timeouts.push({ key, timeoutMs });
142
- },
143
- });
144
- const gate = createDeferred();
145
- const order: string[] = [];
146
-
147
- const first = enqueue("feishu:default:chat-1", async () => {
148
- order.push("first:start");
149
- await gate.promise;
150
- order.push("first:end");
151
- });
152
- const second = enqueue("feishu:default:chat-1", async () => {
153
- order.push("second:ran");
154
- });
155
-
156
- // Wait long enough that a timeout would have fired if it were active.
157
- await vi.advanceTimersByTimeAsync(30);
158
- expect(order).toEqual(["first:start"]);
159
- expect(timeouts).toStrictEqual([]);
160
-
161
- gate.resolve();
162
- await Promise.all([first, second]);
163
- expect(order).toEqual(["first:start", "first:end", "second:ran"]);
164
- });
165
- });
@@ -1,86 +0,0 @@
1
- /**
2
- * Per-key serial task queue for Feishu inbound message handling.
3
- *
4
- * Tasks enqueued under the same key run in FIFO order. Different keys run
5
- * concurrently. This preserves the channel's same-chat ordering contract
6
- * (see #64324) while letting cross-chat work proceed in parallel.
7
- *
8
- * `taskTimeoutMs` bounds how long the queue will block subsequent same-key
9
- * tasks behind a single in-flight task. After the cap, the in-flight task
10
- * is evicted from the blocking chain so newer messages for the same key
11
- * can proceed. The original task is NOT aborted — it continues running in
12
- * the background; it just stops starving the queue.
13
- *
14
- * Without this cap, a single hung dispatch (e.g. an agent call that never
15
- * resolves) keeps later same-chat messages in `queued` state until the
16
- * gateway is restarted. See #70133.
17
- */
18
-
19
- const DEFAULT_TASK_TIMEOUT_MS = 5 * 60 * 1000;
20
-
21
- export interface SequentialQueueOptions {
22
- /**
23
- * Maximum time (ms) to block subsequent same-key tasks behind a single
24
- * in-flight task. Pass 0 (or a non-finite value) to disable the cap and
25
- * restore unbounded legacy behavior.
26
- *
27
- * Default: 5 minutes.
28
- */
29
- taskTimeoutMs?: number;
30
-
31
- /**
32
- * Optional callback fired when a task exceeds `taskTimeoutMs`. The task
33
- * itself is not awaited further; this callback is the only signal the
34
- * caller gets that the queue moved on without it.
35
- */
36
- onTaskTimeout?: (key: string, timeoutMs: number) => void;
37
- }
38
-
39
- export function createSequentialQueue(options: SequentialQueueOptions = {}) {
40
- const queues = new Map<string, Promise<void>>();
41
- const taskTimeoutMs = options.taskTimeoutMs ?? DEFAULT_TASK_TIMEOUT_MS;
42
- const onTaskTimeout = options.onTaskTimeout;
43
-
44
- return (key: string, task: () => Promise<void>): Promise<void> => {
45
- const previous = queues.get(key) ?? Promise.resolve();
46
- const wrapped = () => boundedRun(key, task, taskTimeoutMs, onTaskTimeout);
47
- const next = previous.then(wrapped, wrapped);
48
- queues.set(key, next);
49
- const cleanup = () => {
50
- if (queues.get(key) === next) {
51
- queues.delete(key);
52
- }
53
- };
54
- next.then(cleanup, cleanup);
55
- return next;
56
- };
57
- }
58
-
59
- async function boundedRun(
60
- key: string,
61
- task: () => Promise<void>,
62
- timeoutMs: number,
63
- onTaskTimeout: ((key: string, timeoutMs: number) => void) | undefined,
64
- ): Promise<void> {
65
- if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
66
- return task();
67
- }
68
- let timeoutHandle: ReturnType<typeof setTimeout> | undefined;
69
- const timeoutPromise = new Promise<void>((resolve) => {
70
- timeoutHandle = setTimeout(() => {
71
- try {
72
- onTaskTimeout?.(key, timeoutMs);
73
- } catch {
74
- // Swallow logging errors so they cannot poison the queue chain.
75
- }
76
- resolve();
77
- }, timeoutMs);
78
- });
79
- try {
80
- await Promise.race([task(), timeoutPromise]);
81
- } finally {
82
- if (timeoutHandle) {
83
- clearTimeout(timeoutHandle);
84
- }
85
- }
86
- }
@@ -1,42 +0,0 @@
1
- import { buildFeishuConversationId, parseFeishuConversationId } from "./conversation-id.js";
2
-
3
- function resolveFeishuParentConversationCandidates(rawId: string): string[] {
4
- const parsed = parseFeishuConversationId({ conversationId: rawId });
5
- if (!parsed) {
6
- return [];
7
- }
8
- switch (parsed.scope) {
9
- case "group_topic_sender":
10
- return [
11
- buildFeishuConversationId({
12
- chatId: parsed.chatId,
13
- scope: "group_topic",
14
- topicId: parsed.topicId,
15
- }),
16
- parsed.chatId,
17
- ];
18
- case "group_topic":
19
- case "group_sender":
20
- return [parsed.chatId];
21
- case "group":
22
- default:
23
- return [];
24
- }
25
- }
26
-
27
- export function resolveFeishuSessionConversation(params: {
28
- kind: "group" | "channel";
29
- rawId: string;
30
- }) {
31
- const parsed = parseFeishuConversationId({ conversationId: params.rawId });
32
- if (!parsed) {
33
- return null;
34
- }
35
- return {
36
- id: parsed.canonicalConversationId,
37
- baseConversationId: parsed.chatId,
38
- parentConversationCandidates: resolveFeishuParentConversationCandidates(
39
- parsed.canonicalConversationId,
40
- ),
41
- };
42
- }
@@ -1,48 +0,0 @@
1
- import {
2
- buildChannelOutboundSessionRoute,
3
- stripChannelTargetPrefix,
4
- type ChannelOutboundSessionRouteParams,
5
- } from "klaw/plugin-sdk/channel-core";
6
- import { normalizeLowercaseStringOrEmpty } from "klaw/plugin-sdk/string-coerce-runtime";
7
-
8
- export function resolveFeishuOutboundSessionRoute(params: ChannelOutboundSessionRouteParams) {
9
- let trimmed = stripChannelTargetPrefix(params.target, "feishu", "lark");
10
- if (!trimmed) {
11
- return null;
12
- }
13
-
14
- const lower = normalizeLowercaseStringOrEmpty(trimmed);
15
- let isGroup = false;
16
- let typeExplicit = false;
17
-
18
- if (lower.startsWith("group:") || lower.startsWith("chat:") || lower.startsWith("channel:")) {
19
- trimmed = trimmed.replace(/^(group|chat|channel):/i, "").trim();
20
- isGroup = true;
21
- typeExplicit = true;
22
- } else if (lower.startsWith("user:") || lower.startsWith("dm:")) {
23
- trimmed = trimmed.replace(/^(user|dm):/i, "").trim();
24
- isGroup = false;
25
- typeExplicit = true;
26
- }
27
-
28
- if (!typeExplicit) {
29
- const idLower = normalizeLowercaseStringOrEmpty(trimmed);
30
- if (idLower.startsWith("ou_") || idLower.startsWith("on_")) {
31
- isGroup = false;
32
- }
33
- }
34
-
35
- return buildChannelOutboundSessionRoute({
36
- cfg: params.cfg,
37
- agentId: params.agentId,
38
- channel: "feishu",
39
- accountId: params.accountId,
40
- peer: {
41
- kind: isGroup ? "group" : "direct",
42
- id: trimmed,
43
- },
44
- chatType: isGroup ? "group" : "direct",
45
- from: isGroup ? `feishu:group:${trimmed}` : `feishu:${trimmed}`,
46
- to: trimmed,
47
- });
48
- }
package/src/setup-core.ts DELETED
@@ -1,51 +0,0 @@
1
- import {
2
- DEFAULT_ACCOUNT_ID,
3
- type ChannelSetupAdapter,
4
- type KlawConfig,
5
- } from "klaw/plugin-sdk/setup";
6
- import { resolveDefaultFeishuAccountId } from "./accounts.js";
7
- import type { FeishuConfig } from "./types.js";
8
-
9
- export function setFeishuNamedAccountEnabled(
10
- cfg: KlawConfig,
11
- accountId: string,
12
- enabled: boolean,
13
- ): KlawConfig {
14
- const feishuCfg = cfg.channels?.feishu as FeishuConfig | undefined;
15
- return {
16
- ...cfg,
17
- channels: {
18
- ...cfg.channels,
19
- feishu: {
20
- ...feishuCfg,
21
- accounts: {
22
- ...feishuCfg?.accounts,
23
- [accountId]: {
24
- ...feishuCfg?.accounts?.[accountId],
25
- enabled,
26
- },
27
- },
28
- },
29
- },
30
- };
31
- }
32
-
33
- export const feishuSetupAdapter: ChannelSetupAdapter = {
34
- resolveAccountId: ({ cfg, accountId }) => accountId?.trim() || resolveDefaultFeishuAccountId(cfg),
35
- applyAccountConfig: ({ cfg, accountId }) => {
36
- const isDefault = !accountId || accountId === DEFAULT_ACCOUNT_ID;
37
- if (isDefault) {
38
- return {
39
- ...cfg,
40
- channels: {
41
- ...cfg.channels,
42
- feishu: {
43
- ...cfg.channels?.feishu,
44
- enabled: true,
45
- },
46
- },
47
- };
48
- }
49
- return setFeishuNamedAccountEnabled(cfg, accountId, true);
50
- },
51
- };