@openclaw/feishu 2026.2.25 → 2026.3.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.
Files changed (73) hide show
  1. package/index.ts +2 -0
  2. package/package.json +2 -1
  3. package/skills/feishu-doc/SKILL.md +109 -3
  4. package/src/accounts.test.ts +161 -0
  5. package/src/accounts.ts +76 -8
  6. package/src/async.ts +62 -0
  7. package/src/bitable.ts +189 -215
  8. package/src/bot.card-action.test.ts +63 -0
  9. package/src/bot.checkBotMentioned.test.ts +56 -1
  10. package/src/bot.test.ts +1271 -56
  11. package/src/bot.ts +499 -215
  12. package/src/card-action.ts +79 -0
  13. package/src/channel.ts +26 -4
  14. package/src/chat-schema.ts +24 -0
  15. package/src/chat.test.ts +89 -0
  16. package/src/chat.ts +130 -0
  17. package/src/client.test.ts +121 -0
  18. package/src/client.ts +13 -0
  19. package/src/config-schema.test.ts +101 -1
  20. package/src/config-schema.ts +66 -11
  21. package/src/dedup.ts +47 -1
  22. package/src/doc-schema.ts +135 -0
  23. package/src/docx-batch-insert.ts +190 -0
  24. package/src/docx-color-text.ts +149 -0
  25. package/src/docx-table-ops.ts +298 -0
  26. package/src/docx.account-selection.test.ts +70 -0
  27. package/src/docx.test.ts +331 -9
  28. package/src/docx.ts +996 -72
  29. package/src/drive.ts +38 -33
  30. package/src/media.test.ts +227 -7
  31. package/src/media.ts +52 -11
  32. package/src/mention.ts +1 -1
  33. package/src/monitor.account.ts +534 -0
  34. package/src/monitor.reaction.test.ts +578 -0
  35. package/src/monitor.startup.test.ts +203 -0
  36. package/src/monitor.startup.ts +51 -0
  37. package/src/monitor.state.defaults.test.ts +46 -0
  38. package/src/monitor.state.ts +152 -0
  39. package/src/monitor.test-mocks.ts +12 -0
  40. package/src/monitor.transport.ts +163 -0
  41. package/src/monitor.ts +44 -346
  42. package/src/monitor.webhook-security.test.ts +53 -10
  43. package/src/onboarding.status.test.ts +25 -0
  44. package/src/onboarding.ts +144 -52
  45. package/src/outbound.test.ts +181 -0
  46. package/src/outbound.ts +94 -7
  47. package/src/perm.ts +37 -30
  48. package/src/policy.test.ts +56 -1
  49. package/src/policy.ts +5 -1
  50. package/src/post.test.ts +105 -0
  51. package/src/post.ts +274 -0
  52. package/src/probe.test.ts +271 -0
  53. package/src/probe.ts +131 -19
  54. package/src/reply-dispatcher.test.ts +300 -0
  55. package/src/reply-dispatcher.ts +159 -46
  56. package/src/secret-input.ts +19 -0
  57. package/src/send-target.test.ts +74 -0
  58. package/src/send-target.ts +6 -2
  59. package/src/send.reply-fallback.test.ts +105 -0
  60. package/src/send.test.ts +168 -0
  61. package/src/send.ts +143 -18
  62. package/src/streaming-card.ts +131 -43
  63. package/src/targets.test.ts +55 -1
  64. package/src/targets.ts +32 -7
  65. package/src/tool-account-routing.test.ts +129 -0
  66. package/src/tool-account.ts +70 -0
  67. package/src/tool-factory-test-harness.ts +76 -0
  68. package/src/tools-config.test.ts +21 -0
  69. package/src/tools-config.ts +2 -1
  70. package/src/types.ts +10 -1
  71. package/src/typing.test.ts +144 -0
  72. package/src/typing.ts +140 -10
  73. package/src/wiki.ts +55 -50
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { FeishuConfigSchema } from "./config-schema.js";
3
+ import { resolveToolsConfig } from "./tools-config.js";
4
+
5
+ describe("feishu tools config", () => {
6
+ it("enables chat tool by default", () => {
7
+ const resolved = resolveToolsConfig(undefined);
8
+ expect(resolved.chat).toBe(true);
9
+ });
10
+
11
+ it("accepts tools.chat in config schema", () => {
12
+ const parsed = FeishuConfigSchema.parse({
13
+ enabled: true,
14
+ tools: {
15
+ chat: false,
16
+ },
17
+ });
18
+
19
+ expect(parsed.tools?.chat).toBe(false);
20
+ });
21
+ });
@@ -2,11 +2,12 @@ import type { FeishuToolsConfig } from "./types.js";
2
2
 
3
3
  /**
4
4
  * Default tool configuration.
5
- * - doc, wiki, drive, scopes: enabled by default
5
+ * - doc, chat, wiki, drive, scopes: enabled by default
6
6
  * - perm: disabled by default (sensitive operation)
7
7
  */
8
8
  export const DEFAULT_TOOLS_CONFIG: Required<FeishuToolsConfig> = {
9
9
  doc: true,
10
+ chat: true,
10
11
  wiki: true,
11
12
  drive: true,
12
13
  perm: false,
package/src/types.ts CHANGED
@@ -14,8 +14,15 @@ export type FeishuAccountConfig = z.infer<typeof FeishuAccountConfigSchema>;
14
14
  export type FeishuDomain = "feishu" | "lark" | (string & {});
15
15
  export type FeishuConnectionMode = "websocket" | "webhook";
16
16
 
17
+ export type FeishuDefaultAccountSelectionSource =
18
+ | "explicit-default"
19
+ | "mapped-default"
20
+ | "fallback";
21
+ export type FeishuAccountSelectionSource = "explicit" | FeishuDefaultAccountSelectionSource;
22
+
17
23
  export type ResolvedFeishuAccount = {
18
24
  accountId: string;
25
+ selectionSource: FeishuAccountSelectionSource;
19
26
  enabled: boolean;
20
27
  configured: boolean;
21
28
  name?: string;
@@ -36,10 +43,11 @@ export type FeishuMessageContext = {
36
43
  senderId: string;
37
44
  senderOpenId: string;
38
45
  senderName?: string;
39
- chatType: "p2p" | "group";
46
+ chatType: "p2p" | "group" | "private";
40
47
  mentionedBot: boolean;
41
48
  rootId?: string;
42
49
  parentId?: string;
50
+ threadId?: string;
43
51
  content: string;
44
52
  contentType: string;
45
53
  /** Mention forward targets (excluding the bot itself) */
@@ -67,6 +75,7 @@ export type FeishuMediaInfo = {
67
75
 
68
76
  export type FeishuToolsConfig = {
69
77
  doc?: boolean;
78
+ chat?: boolean;
70
79
  wiki?: boolean;
71
80
  drive?: boolean;
72
81
  perm?: boolean;
@@ -0,0 +1,144 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { isFeishuBackoffError, getBackoffCodeFromResponse, FeishuBackoffError } from "./typing.js";
3
+
4
+ describe("isFeishuBackoffError", () => {
5
+ it("returns true for HTTP 429 (AxiosError shape)", () => {
6
+ const err = { response: { status: 429, data: {} } };
7
+ expect(isFeishuBackoffError(err)).toBe(true);
8
+ });
9
+
10
+ it("returns true for Feishu quota exceeded code 99991403", () => {
11
+ const err = { response: { status: 200, data: { code: 99991403 } } };
12
+ expect(isFeishuBackoffError(err)).toBe(true);
13
+ });
14
+
15
+ it("returns true for Feishu rate limit code 99991400", () => {
16
+ const err = { response: { status: 200, data: { code: 99991400 } } };
17
+ expect(isFeishuBackoffError(err)).toBe(true);
18
+ });
19
+
20
+ it("returns true for SDK error with code 429", () => {
21
+ const err = { code: 429, message: "too many requests" };
22
+ expect(isFeishuBackoffError(err)).toBe(true);
23
+ });
24
+
25
+ it("returns true for SDK error with top-level code 99991403", () => {
26
+ const err = { code: 99991403, message: "quota exceeded" };
27
+ expect(isFeishuBackoffError(err)).toBe(true);
28
+ });
29
+
30
+ it("returns false for other HTTP errors (e.g. 500)", () => {
31
+ const err = { response: { status: 500, data: {} } };
32
+ expect(isFeishuBackoffError(err)).toBe(false);
33
+ });
34
+
35
+ it("returns false for non-rate-limit Feishu codes", () => {
36
+ const err = { response: { status: 200, data: { code: 99991401 } } };
37
+ expect(isFeishuBackoffError(err)).toBe(false);
38
+ });
39
+
40
+ it("returns false for generic Error", () => {
41
+ expect(isFeishuBackoffError(new Error("network timeout"))).toBe(false);
42
+ });
43
+
44
+ it("returns false for null", () => {
45
+ expect(isFeishuBackoffError(null)).toBe(false);
46
+ });
47
+
48
+ it("returns false for undefined", () => {
49
+ expect(isFeishuBackoffError(undefined)).toBe(false);
50
+ });
51
+
52
+ it("returns false for string", () => {
53
+ expect(isFeishuBackoffError("429")).toBe(false);
54
+ });
55
+
56
+ it("returns true for 429 even without data", () => {
57
+ const err = { response: { status: 429 } };
58
+ expect(isFeishuBackoffError(err)).toBe(true);
59
+ });
60
+ });
61
+
62
+ describe("getBackoffCodeFromResponse", () => {
63
+ it("returns backoff code for response with quota exceeded code", () => {
64
+ const response = { code: 99991403, msg: "quota exceeded", data: null };
65
+ expect(getBackoffCodeFromResponse(response)).toBe(response.code);
66
+ });
67
+
68
+ it("returns backoff code for response with rate limit code", () => {
69
+ const response = { code: 99991400, msg: "rate limit", data: null };
70
+ expect(getBackoffCodeFromResponse(response)).toBe(response.code);
71
+ });
72
+
73
+ it("returns backoff code for response with code 429", () => {
74
+ const response = { code: 429, msg: "too many requests", data: null };
75
+ expect(getBackoffCodeFromResponse(response)).toBe(response.code);
76
+ });
77
+
78
+ it("returns undefined for successful response (code 0)", () => {
79
+ const response = { code: 0, msg: "success", data: { reaction_id: "r1" } };
80
+ expect(getBackoffCodeFromResponse(response)).toBeUndefined();
81
+ });
82
+
83
+ it("returns undefined for other error codes", () => {
84
+ const response = { code: 99991401, msg: "other error", data: null };
85
+ expect(getBackoffCodeFromResponse(response)).toBeUndefined();
86
+ });
87
+
88
+ it("returns undefined for null", () => {
89
+ expect(getBackoffCodeFromResponse(null)).toBeUndefined();
90
+ });
91
+
92
+ it("returns undefined for undefined", () => {
93
+ expect(getBackoffCodeFromResponse(undefined)).toBeUndefined();
94
+ });
95
+
96
+ it("returns undefined for response without code field", () => {
97
+ const response = { data: { reaction_id: "r1" } };
98
+ expect(getBackoffCodeFromResponse(response)).toBeUndefined();
99
+ });
100
+ });
101
+
102
+ describe("FeishuBackoffError", () => {
103
+ it("is detected by isFeishuBackoffError via .code property", () => {
104
+ const err = new FeishuBackoffError(99991403);
105
+ expect(isFeishuBackoffError(err)).toBe(true);
106
+ });
107
+
108
+ it("is detected for rate limit code 99991400", () => {
109
+ const err = new FeishuBackoffError(99991400);
110
+ expect(isFeishuBackoffError(err)).toBe(true);
111
+ });
112
+
113
+ it("has correct name and message", () => {
114
+ const err = new FeishuBackoffError(99991403);
115
+ expect(err.name).toBe("FeishuBackoffError");
116
+ expect(err.message).toBe("Feishu API backoff: code 99991403");
117
+ expect(err.code).toBe(99991403);
118
+ });
119
+
120
+ it("is an instance of Error", () => {
121
+ const err = new FeishuBackoffError(99991403);
122
+ expect(err instanceof Error).toBe(true);
123
+ });
124
+
125
+ it("survives catch-and-rethrow pattern", () => {
126
+ // Simulates the exact pattern in addTypingIndicator/removeTypingIndicator:
127
+ // thrown inside try, caught by catch, isFeishuBackoffError must match
128
+ let caught: unknown;
129
+ try {
130
+ try {
131
+ throw new FeishuBackoffError(99991403);
132
+ } catch (err) {
133
+ if (isFeishuBackoffError(err)) {
134
+ throw err; // re-thrown — this is the fix
135
+ }
136
+ // would be silently swallowed with plain Error
137
+ caught = "swallowed";
138
+ }
139
+ } catch (err) {
140
+ caught = err;
141
+ }
142
+ expect(caught).toBeInstanceOf(FeishuBackoffError);
143
+ });
144
+ });
package/src/typing.ts CHANGED
@@ -1,26 +1,112 @@
1
- import type { ClawdbotConfig } from "openclaw/plugin-sdk";
1
+ import type { ClawdbotConfig, RuntimeEnv } from "openclaw/plugin-sdk";
2
2
  import { resolveFeishuAccount } from "./accounts.js";
3
3
  import { createFeishuClient } from "./client.js";
4
+ import { getFeishuRuntime } from "./runtime.js";
4
5
 
5
6
  // Feishu emoji types for typing indicator
6
7
  // See: https://open.feishu.cn/document/server-docs/im-v1/message-reaction/emojis-introduce
7
8
  // Full list: https://github.com/go-lark/lark/blob/main/emoji.go
8
9
  const TYPING_EMOJI = "Typing"; // Typing indicator emoji
9
10
 
11
+ /**
12
+ * Feishu API error codes that indicate the caller should back off.
13
+ * These must propagate to the typing circuit breaker so the keepalive loop
14
+ * can trip and stop retrying.
15
+ *
16
+ * - 99991400: Rate limit (too many requests per second)
17
+ * - 99991403: Monthly API call quota exceeded
18
+ * - 429: Standard HTTP 429 returned as a Feishu SDK error code
19
+ *
20
+ * @see https://open.feishu.cn/document/server-docs/api-call-guide/generic-error-code
21
+ */
22
+ const FEISHU_BACKOFF_CODES = new Set([99991400, 99991403, 429]);
23
+
24
+ /**
25
+ * Custom error class for Feishu backoff conditions detected from non-throwing
26
+ * SDK responses. Carries a numeric `.code` so that `isFeishuBackoffError()`
27
+ * recognises it when the error is caught downstream.
28
+ */
29
+ export class FeishuBackoffError extends Error {
30
+ code: number;
31
+ constructor(code: number) {
32
+ super(`Feishu API backoff: code ${code}`);
33
+ this.name = "FeishuBackoffError";
34
+ this.code = code;
35
+ }
36
+ }
37
+
10
38
  export type TypingIndicatorState = {
11
39
  messageId: string;
12
40
  reactionId: string | null;
13
41
  };
14
42
 
15
43
  /**
16
- * Add a typing indicator (reaction) to a message
44
+ * Check whether an error represents a rate-limit or quota-exceeded condition
45
+ * from the Feishu API that should stop the typing keepalive loop.
46
+ *
47
+ * Handles two shapes:
48
+ * 1. AxiosError with `response.status` and `response.data.code`
49
+ * 2. Feishu SDK error with a top-level `code` property
50
+ */
51
+ export function isFeishuBackoffError(err: unknown): boolean {
52
+ if (typeof err !== "object" || err === null) {
53
+ return false;
54
+ }
55
+
56
+ // AxiosError shape: err.response.status / err.response.data.code
57
+ const response = (err as { response?: { status?: number; data?: { code?: number } } }).response;
58
+ if (response) {
59
+ if (response.status === 429) {
60
+ return true;
61
+ }
62
+ if (typeof response.data?.code === "number" && FEISHU_BACKOFF_CODES.has(response.data.code)) {
63
+ return true;
64
+ }
65
+ }
66
+
67
+ // Feishu SDK error shape: err.code
68
+ const code = (err as { code?: number }).code;
69
+ if (typeof code === "number" && FEISHU_BACKOFF_CODES.has(code)) {
70
+ return true;
71
+ }
72
+
73
+ return false;
74
+ }
75
+
76
+ /**
77
+ * Check whether a Feishu SDK response object contains a backoff error code.
78
+ *
79
+ * The Feishu SDK sometimes returns a normal response (no throw) with an
80
+ * API-level error code in the response body. This must be detected so the
81
+ * circuit breaker can trip. See codex review on #28157.
82
+ */
83
+ export function getBackoffCodeFromResponse(response: unknown): number | undefined {
84
+ if (typeof response !== "object" || response === null) {
85
+ return undefined;
86
+ }
87
+ const code = (response as { code?: number }).code;
88
+ if (typeof code === "number" && FEISHU_BACKOFF_CODES.has(code)) {
89
+ return code;
90
+ }
91
+ return undefined;
92
+ }
93
+
94
+ /**
95
+ * Add a typing indicator (reaction) to a message.
96
+ *
97
+ * Rate-limit and quota errors are re-thrown so the circuit breaker in
98
+ * `createTypingCallbacks` (typing-start-guard) can trip and stop the
99
+ * keepalive loop. See #28062.
100
+ *
101
+ * Also checks for backoff codes in non-throwing SDK responses (#28157).
17
102
  */
18
103
  export async function addTypingIndicator(params: {
19
104
  cfg: ClawdbotConfig;
20
105
  messageId: string;
21
106
  accountId?: string;
107
+ runtime?: RuntimeEnv;
22
108
  }): Promise<TypingIndicatorState> {
23
- const { cfg, messageId, accountId } = params;
109
+ const { cfg, messageId, accountId, runtime } = params;
24
110
  const account = resolveFeishuAccount({ cfg, accountId });
25
111
  if (!account.configured) {
26
112
  return { messageId, reactionId: null };
@@ -36,25 +122,48 @@ export async function addTypingIndicator(params: {
36
122
  },
37
123
  });
38
124
 
125
+ // Feishu SDK may return a normal response with an API-level error code
126
+ // instead of throwing. Detect backoff codes and throw to trip the breaker.
127
+ const backoffCode = getBackoffCodeFromResponse(response);
128
+ if (backoffCode !== undefined) {
129
+ if (getFeishuRuntime().logging.shouldLogVerbose()) {
130
+ runtime?.log?.(
131
+ `[feishu] typing indicator response contains backoff code ${backoffCode}, stopping keepalive`,
132
+ );
133
+ }
134
+ throw new FeishuBackoffError(backoffCode);
135
+ }
136
+
39
137
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK response type
40
138
  const reactionId = (response as any)?.data?.reaction_id ?? null;
41
139
  return { messageId, reactionId };
42
140
  } catch (err) {
43
- // Silently fail - typing indicator is not critical
44
- console.log(`[feishu] failed to add typing indicator: ${err}`);
141
+ if (isFeishuBackoffError(err)) {
142
+ if (getFeishuRuntime().logging.shouldLogVerbose()) {
143
+ runtime?.log?.("[feishu] typing indicator hit rate-limit/quota, stopping keepalive");
144
+ }
145
+ throw err;
146
+ }
147
+ // Silently fail for other non-critical errors (e.g. message deleted, permission issues)
148
+ if (getFeishuRuntime().logging.shouldLogVerbose()) {
149
+ runtime?.log?.(`[feishu] failed to add typing indicator: ${String(err)}`);
150
+ }
45
151
  return { messageId, reactionId: null };
46
152
  }
47
153
  }
48
154
 
49
155
  /**
50
- * Remove a typing indicator (reaction) from a message
156
+ * Remove a typing indicator (reaction) from a message.
157
+ *
158
+ * Rate-limit and quota errors are re-thrown for the same reason as above.
51
159
  */
52
160
  export async function removeTypingIndicator(params: {
53
161
  cfg: ClawdbotConfig;
54
162
  state: TypingIndicatorState;
55
163
  accountId?: string;
164
+ runtime?: RuntimeEnv;
56
165
  }): Promise<void> {
57
- const { cfg, state, accountId } = params;
166
+ const { cfg, state, accountId, runtime } = params;
58
167
  if (!state.reactionId) {
59
168
  return;
60
169
  }
@@ -67,14 +176,35 @@ export async function removeTypingIndicator(params: {
67
176
  const client = createFeishuClient(account);
68
177
 
69
178
  try {
70
- await client.im.messageReaction.delete({
179
+ const result = await client.im.messageReaction.delete({
71
180
  path: {
72
181
  message_id: state.messageId,
73
182
  reaction_id: state.reactionId,
74
183
  },
75
184
  });
185
+
186
+ // Check for backoff codes in non-throwing SDK responses
187
+ const backoffCode = getBackoffCodeFromResponse(result);
188
+ if (backoffCode !== undefined) {
189
+ if (getFeishuRuntime().logging.shouldLogVerbose()) {
190
+ runtime?.log?.(
191
+ `[feishu] typing indicator removal response contains backoff code ${backoffCode}, stopping keepalive`,
192
+ );
193
+ }
194
+ throw new FeishuBackoffError(backoffCode);
195
+ }
76
196
  } catch (err) {
77
- // Silently fail - cleanup is not critical
78
- console.log(`[feishu] failed to remove typing indicator: ${err}`);
197
+ if (isFeishuBackoffError(err)) {
198
+ if (getFeishuRuntime().logging.shouldLogVerbose()) {
199
+ runtime?.log?.(
200
+ "[feishu] typing indicator removal hit rate-limit/quota, stopping keepalive",
201
+ );
202
+ }
203
+ throw err;
204
+ }
205
+ // Silently fail for other non-critical errors
206
+ if (getFeishuRuntime().logging.shouldLogVerbose()) {
207
+ runtime?.log?.(`[feishu] failed to remove typing indicator: ${String(err)}`);
208
+ }
79
209
  }
80
210
  }
package/src/wiki.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import type * as Lark from "@larksuiteoapi/node-sdk";
2
2
  import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
3
3
  import { listEnabledFeishuAccounts } from "./accounts.js";
4
- import { createFeishuClient } from "./client.js";
5
- import { resolveToolsConfig } from "./tools-config.js";
4
+ import { createFeishuToolClient, resolveAnyEnabledFeishuToolsConfig } from "./tool-account.js";
6
5
  import { FeishuWikiSchema, type FeishuWikiParams } from "./wiki-schema.js";
7
6
 
8
7
  // ============ Helpers ============
@@ -168,62 +167,68 @@ export function registerFeishuWikiTools(api: OpenClawPluginApi) {
168
167
  return;
169
168
  }
170
169
 
171
- const firstAccount = accounts[0];
172
- const toolsCfg = resolveToolsConfig(firstAccount.config.tools);
170
+ const toolsCfg = resolveAnyEnabledFeishuToolsConfig(accounts);
173
171
  if (!toolsCfg.wiki) {
174
172
  api.logger.debug?.("feishu_wiki: wiki tool disabled in config");
175
173
  return;
176
174
  }
177
175
 
178
- const getClient = () => createFeishuClient(firstAccount);
176
+ type FeishuWikiExecuteParams = FeishuWikiParams & { accountId?: string };
179
177
 
180
178
  api.registerTool(
181
- {
182
- name: "feishu_wiki",
183
- label: "Feishu Wiki",
184
- description:
185
- "Feishu knowledge base operations. Actions: spaces, nodes, get, create, move, rename",
186
- parameters: FeishuWikiSchema,
187
- async execute(_toolCallId, params) {
188
- const p = params as FeishuWikiParams;
189
- try {
190
- const client = getClient();
191
- switch (p.action) {
192
- case "spaces":
193
- return json(await listSpaces(client));
194
- case "nodes":
195
- return json(await listNodes(client, p.space_id, p.parent_node_token));
196
- case "get":
197
- return json(await getNode(client, p.token));
198
- case "search":
199
- return json({
200
- error:
201
- "Search is not available. Use feishu_wiki with action: 'nodes' to browse or action: 'get' to lookup by token.",
202
- });
203
- case "create":
204
- return json(
205
- await createNode(client, p.space_id, p.title, p.obj_type, p.parent_node_token),
206
- );
207
- case "move":
208
- return json(
209
- await moveNode(
210
- client,
211
- p.space_id,
212
- p.node_token,
213
- p.target_space_id,
214
- p.target_parent_token,
215
- ),
216
- );
217
- case "rename":
218
- return json(await renameNode(client, p.space_id, p.node_token, p.title));
219
- default:
220
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- exhaustive check fallback
221
- return json({ error: `Unknown action: ${(p as any).action}` });
179
+ (ctx) => {
180
+ const defaultAccountId = ctx.agentAccountId;
181
+ return {
182
+ name: "feishu_wiki",
183
+ label: "Feishu Wiki",
184
+ description:
185
+ "Feishu knowledge base operations. Actions: spaces, nodes, get, create, move, rename",
186
+ parameters: FeishuWikiSchema,
187
+ async execute(_toolCallId, params) {
188
+ const p = params as FeishuWikiExecuteParams;
189
+ try {
190
+ const client = createFeishuToolClient({
191
+ api,
192
+ executeParams: p,
193
+ defaultAccountId,
194
+ });
195
+ switch (p.action) {
196
+ case "spaces":
197
+ return json(await listSpaces(client));
198
+ case "nodes":
199
+ return json(await listNodes(client, p.space_id, p.parent_node_token));
200
+ case "get":
201
+ return json(await getNode(client, p.token));
202
+ case "search":
203
+ return json({
204
+ error:
205
+ "Search is not available. Use feishu_wiki with action: 'nodes' to browse or action: 'get' to lookup by token.",
206
+ });
207
+ case "create":
208
+ return json(
209
+ await createNode(client, p.space_id, p.title, p.obj_type, p.parent_node_token),
210
+ );
211
+ case "move":
212
+ return json(
213
+ await moveNode(
214
+ client,
215
+ p.space_id,
216
+ p.node_token,
217
+ p.target_space_id,
218
+ p.target_parent_token,
219
+ ),
220
+ );
221
+ case "rename":
222
+ return json(await renameNode(client, p.space_id, p.node_token, p.title));
223
+ default:
224
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- exhaustive check fallback
225
+ return json({ error: `Unknown action: ${(p as any).action}` });
226
+ }
227
+ } catch (err) {
228
+ return json({ error: err instanceof Error ? err.message : String(err) });
222
229
  }
223
- } catch (err) {
224
- return json({ error: err instanceof Error ? err.message : String(err) });
225
- }
226
- },
230
+ },
231
+ };
227
232
  },
228
233
  { name: "feishu_wiki" },
229
234
  );