@openclaw/feishu 2026.5.2 → 2026.5.3-beta.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 (224) hide show
  1. package/dist/accounts-Ba3-WP1z.js +423 -0
  2. package/dist/api.js +2280 -0
  3. package/dist/app-registration-B8qc1MCM.js +184 -0
  4. package/dist/audio-preflight.runtime-BPlzkO3l.js +7 -0
  5. package/dist/card-interaction-BfRLgvw_.js +96 -0
  6. package/dist/channel-CSD_Jt8I.js +1668 -0
  7. package/dist/channel-entry.js +22 -0
  8. package/dist/channel-plugin-api.js +2 -0
  9. package/dist/channel.runtime-DYsXcD36.js +700 -0
  10. package/dist/client-DBVoQL5w.js +157 -0
  11. package/dist/contract-api.js +9 -0
  12. package/dist/conversation-id-DWS3Ep2A.js +139 -0
  13. package/dist/directory.static-f3EeoRJd.js +44 -0
  14. package/dist/drive-C5eJLJr7.js +883 -0
  15. package/dist/index.js +68 -0
  16. package/dist/monitor-CT189QfR.js +60 -0
  17. package/dist/monitor.account-dJV2jO8C.js +4990 -0
  18. package/dist/monitor.state-DYM02ipp.js +100 -0
  19. package/dist/policy-D6c-wMPl.js +118 -0
  20. package/dist/probe-BNzzU_uR.js +149 -0
  21. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  22. package/dist/runtime-CG0DuRCy.js +8 -0
  23. package/dist/runtime-api.js +14 -0
  24. package/dist/secret-contract-Dm4Z_zQN.js +119 -0
  25. package/dist/secret-contract-api.js +2 -0
  26. package/dist/security-audit-DqJdocrN.js +11 -0
  27. package/dist/security-audit-shared-ByuMx9cJ.js +38 -0
  28. package/dist/security-contract-api.js +2 -0
  29. package/dist/send-DowxxbpH.js +1218 -0
  30. package/dist/session-conversation-B4nrW-vo.js +27 -0
  31. package/dist/session-key-api.js +2 -0
  32. package/dist/setup-api.js +2 -0
  33. package/dist/setup-entry.js +15 -0
  34. package/dist/subagent-hooks-C3UhPVLV.js +227 -0
  35. package/dist/subagent-hooks-api.js +23 -0
  36. package/dist/targets-JMFJRKSe.js +48 -0
  37. package/dist/thread-bindings-BmS6TLes.js +222 -0
  38. package/package.json +15 -6
  39. package/api.ts +0 -31
  40. package/channel-entry.ts +0 -20
  41. package/channel-plugin-api.ts +0 -1
  42. package/contract-api.ts +0 -16
  43. package/index.ts +0 -82
  44. package/runtime-api.ts +0 -55
  45. package/secret-contract-api.ts +0 -5
  46. package/security-contract-api.ts +0 -1
  47. package/session-key-api.ts +0 -1
  48. package/setup-api.ts +0 -3
  49. package/setup-entry.test.ts +0 -14
  50. package/setup-entry.ts +0 -13
  51. package/src/accounts.test.ts +0 -459
  52. package/src/accounts.ts +0 -326
  53. package/src/app-registration.ts +0 -331
  54. package/src/approval-auth.test.ts +0 -24
  55. package/src/approval-auth.ts +0 -25
  56. package/src/async.test.ts +0 -35
  57. package/src/async.ts +0 -104
  58. package/src/audio-preflight.runtime.ts +0 -9
  59. package/src/bitable.test.ts +0 -131
  60. package/src/bitable.ts +0 -762
  61. package/src/bot-content.ts +0 -474
  62. package/src/bot-group-name.test.ts +0 -108
  63. package/src/bot-runtime-api.ts +0 -12
  64. package/src/bot-sender-name.ts +0 -125
  65. package/src/bot.broadcast.test.ts +0 -463
  66. package/src/bot.card-action.test.ts +0 -577
  67. package/src/bot.checkBotMentioned.test.ts +0 -265
  68. package/src/bot.helpers.test.ts +0 -118
  69. package/src/bot.stripBotMention.test.ts +0 -126
  70. package/src/bot.test.ts +0 -3040
  71. package/src/bot.ts +0 -1559
  72. package/src/card-action.ts +0 -447
  73. package/src/card-interaction.test.ts +0 -129
  74. package/src/card-interaction.ts +0 -159
  75. package/src/card-test-helpers.ts +0 -47
  76. package/src/card-ux-approval.ts +0 -65
  77. package/src/card-ux-launcher.test.ts +0 -99
  78. package/src/card-ux-launcher.ts +0 -121
  79. package/src/card-ux-shared.ts +0 -33
  80. package/src/channel-runtime-api.ts +0 -16
  81. package/src/channel.runtime.ts +0 -47
  82. package/src/channel.test.ts +0 -959
  83. package/src/channel.ts +0 -1313
  84. package/src/chat-schema.ts +0 -25
  85. package/src/chat.test.ts +0 -196
  86. package/src/chat.ts +0 -188
  87. package/src/client.test.ts +0 -433
  88. package/src/client.ts +0 -290
  89. package/src/comment-dispatcher-runtime-api.ts +0 -6
  90. package/src/comment-dispatcher.test.ts +0 -169
  91. package/src/comment-dispatcher.ts +0 -107
  92. package/src/comment-handler-runtime-api.ts +0 -3
  93. package/src/comment-handler.test.ts +0 -486
  94. package/src/comment-handler.ts +0 -309
  95. package/src/comment-reaction.test.ts +0 -166
  96. package/src/comment-reaction.ts +0 -259
  97. package/src/comment-shared.test.ts +0 -182
  98. package/src/comment-shared.ts +0 -406
  99. package/src/comment-target.ts +0 -44
  100. package/src/config-schema.test.ts +0 -309
  101. package/src/config-schema.ts +0 -333
  102. package/src/conversation-id.test.ts +0 -18
  103. package/src/conversation-id.ts +0 -199
  104. package/src/dedup-runtime-api.ts +0 -1
  105. package/src/dedup.ts +0 -141
  106. package/src/directory.static.ts +0 -61
  107. package/src/directory.test.ts +0 -136
  108. package/src/directory.ts +0 -124
  109. package/src/doc-schema.ts +0 -182
  110. package/src/docx-batch-insert.test.ts +0 -91
  111. package/src/docx-batch-insert.ts +0 -223
  112. package/src/docx-color-text.ts +0 -154
  113. package/src/docx-table-ops.test.ts +0 -53
  114. package/src/docx-table-ops.ts +0 -316
  115. package/src/docx-types.ts +0 -38
  116. package/src/docx.account-selection.test.ts +0 -79
  117. package/src/docx.test.ts +0 -685
  118. package/src/docx.ts +0 -1616
  119. package/src/drive-schema.ts +0 -92
  120. package/src/drive.test.ts +0 -1219
  121. package/src/drive.ts +0 -829
  122. package/src/dynamic-agent.ts +0 -137
  123. package/src/event-types.ts +0 -45
  124. package/src/external-keys.test.ts +0 -20
  125. package/src/external-keys.ts +0 -19
  126. package/src/lifecycle.test-support.ts +0 -220
  127. package/src/media.test.ts +0 -900
  128. package/src/media.ts +0 -861
  129. package/src/mention-target.types.ts +0 -5
  130. package/src/mention.ts +0 -114
  131. package/src/message-action-contract.ts +0 -13
  132. package/src/monitor-state-runtime-api.ts +0 -7
  133. package/src/monitor-transport-runtime-api.ts +0 -7
  134. package/src/monitor.account.ts +0 -468
  135. package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
  136. package/src/monitor.bot-identity.ts +0 -86
  137. package/src/monitor.bot-menu-handler.ts +0 -165
  138. package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
  139. package/src/monitor.bot-menu.test.ts +0 -178
  140. package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
  141. package/src/monitor.card-action.lifecycle.test-support.ts +0 -373
  142. package/src/monitor.cleanup.test.ts +0 -376
  143. package/src/monitor.comment-notice-handler.ts +0 -105
  144. package/src/monitor.comment.test.ts +0 -937
  145. package/src/monitor.comment.ts +0 -1386
  146. package/src/monitor.lifecycle.test.ts +0 -4
  147. package/src/monitor.message-handler.ts +0 -339
  148. package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
  149. package/src/monitor.reaction.test.ts +0 -713
  150. package/src/monitor.startup.test.ts +0 -192
  151. package/src/monitor.startup.ts +0 -74
  152. package/src/monitor.state.defaults.test.ts +0 -46
  153. package/src/monitor.state.ts +0 -170
  154. package/src/monitor.synthetic-error.ts +0 -18
  155. package/src/monitor.test-mocks.ts +0 -45
  156. package/src/monitor.transport.ts +0 -424
  157. package/src/monitor.ts +0 -100
  158. package/src/monitor.webhook-e2e.test.ts +0 -272
  159. package/src/monitor.webhook-security.test.ts +0 -264
  160. package/src/monitor.webhook.test-helpers.ts +0 -116
  161. package/src/outbound-runtime-api.ts +0 -1
  162. package/src/outbound.test.ts +0 -935
  163. package/src/outbound.ts +0 -718
  164. package/src/perm-schema.ts +0 -52
  165. package/src/perm.ts +0 -170
  166. package/src/pins.ts +0 -108
  167. package/src/policy.test.ts +0 -334
  168. package/src/policy.ts +0 -236
  169. package/src/post.test.ts +0 -105
  170. package/src/post.ts +0 -275
  171. package/src/probe.test.ts +0 -275
  172. package/src/probe.ts +0 -166
  173. package/src/processing-claims.ts +0 -59
  174. package/src/qr-terminal.ts +0 -1
  175. package/src/reactions.ts +0 -123
  176. package/src/reasoning-preview.test.ts +0 -59
  177. package/src/reasoning-preview.ts +0 -20
  178. package/src/reply-dispatcher-runtime-api.ts +0 -7
  179. package/src/reply-dispatcher.test.ts +0 -1144
  180. package/src/reply-dispatcher.ts +0 -650
  181. package/src/runtime.ts +0 -9
  182. package/src/secret-contract.ts +0 -145
  183. package/src/secret-input.ts +0 -1
  184. package/src/security-audit-shared.ts +0 -69
  185. package/src/security-audit.test.ts +0 -61
  186. package/src/security-audit.ts +0 -1
  187. package/src/send-result.ts +0 -29
  188. package/src/send-target.test.ts +0 -80
  189. package/src/send-target.ts +0 -35
  190. package/src/send.reply-fallback.test.ts +0 -292
  191. package/src/send.test.ts +0 -550
  192. package/src/send.ts +0 -800
  193. package/src/sequential-key.test.ts +0 -72
  194. package/src/sequential-key.ts +0 -28
  195. package/src/sequential-queue.test.ts +0 -92
  196. package/src/sequential-queue.ts +0 -16
  197. package/src/session-conversation.ts +0 -42
  198. package/src/session-route.ts +0 -48
  199. package/src/setup-core.ts +0 -51
  200. package/src/setup-surface.test.ts +0 -174
  201. package/src/setup-surface.ts +0 -581
  202. package/src/streaming-card.test.ts +0 -190
  203. package/src/streaming-card.ts +0 -490
  204. package/src/subagent-hooks.test.ts +0 -603
  205. package/src/subagent-hooks.ts +0 -397
  206. package/src/targets.ts +0 -97
  207. package/src/test-support/lifecycle-test-support.ts +0 -453
  208. package/src/thread-bindings.test.ts +0 -143
  209. package/src/thread-bindings.ts +0 -330
  210. package/src/tool-account-routing.test.ts +0 -187
  211. package/src/tool-account.test.ts +0 -44
  212. package/src/tool-account.ts +0 -93
  213. package/src/tool-factory-test-harness.ts +0 -79
  214. package/src/tool-result.test.ts +0 -32
  215. package/src/tool-result.ts +0 -16
  216. package/src/tools-config.test.ts +0 -21
  217. package/src/tools-config.ts +0 -22
  218. package/src/types.ts +0 -104
  219. package/src/typing.test.ts +0 -144
  220. package/src/typing.ts +0 -214
  221. package/src/wiki-schema.ts +0 -55
  222. package/src/wiki.ts +0 -227
  223. package/subagent-hooks-api.ts +0 -31
  224. package/tsconfig.json +0 -16
@@ -1,79 +0,0 @@
1
- import type { OpenClawPluginApi } from "../runtime-api.js";
2
-
3
- type ToolContextLike = {
4
- agentAccountId?: string;
5
- };
6
-
7
- export type ToolLike = {
8
- name: string;
9
- execute: (
10
- toolCallId: string,
11
- params: unknown,
12
- ) => Promise<{ details: Record<string, unknown> }> | { details: Record<string, unknown> };
13
- };
14
-
15
- type RegisteredTool = {
16
- tool: unknown;
17
- opts?: { name?: string };
18
- };
19
-
20
- function toToolList(value: unknown): unknown[] {
21
- if (!value) {
22
- return [];
23
- }
24
- return Array.isArray(value) ? value : [value];
25
- }
26
-
27
- function asToolLike(tool: unknown, fallbackName?: string): ToolLike {
28
- const candidate = tool as Partial<ToolLike>;
29
- const name = candidate.name ?? fallbackName;
30
- const execute = candidate.execute;
31
- if (!name || typeof execute !== "function") {
32
- throw new Error(`Resolved tool is missing required fields (name=${String(name)})`);
33
- }
34
- return {
35
- name,
36
- execute: (toolCallId, params) => execute(toolCallId, params),
37
- };
38
- }
39
-
40
- export function createToolFactoryHarness(cfg: OpenClawPluginApi["config"]) {
41
- const registered: RegisteredTool[] = [];
42
-
43
- const api: Pick<OpenClawPluginApi, "config" | "logger" | "registerTool"> = {
44
- config: cfg,
45
- logger: {
46
- info: () => {},
47
- warn: () => {},
48
- error: () => {},
49
- debug: () => {},
50
- },
51
- registerTool: (tool, opts) => {
52
- registered.push({ tool, opts });
53
- },
54
- };
55
-
56
- const resolveTool = (name: string, ctx: ToolContextLike = {}): ToolLike => {
57
- for (const entry of registered) {
58
- if (entry.opts?.name === name && typeof entry.tool !== "function") {
59
- return asToolLike(entry.tool, name);
60
- }
61
-
62
- if (typeof entry.tool === "function") {
63
- const builtTools = toToolList(entry.tool(ctx));
64
- const hit = builtTools.find((tool) => (tool as { name?: string }).name === name);
65
- if (hit) {
66
- return asToolLike(hit, name);
67
- }
68
- } else if ((entry.tool as { name?: string }).name === name) {
69
- return asToolLike(entry.tool, name);
70
- }
71
- }
72
- throw new Error(`Tool not registered: ${name}`);
73
- };
74
-
75
- return {
76
- api: api as OpenClawPluginApi,
77
- resolveTool,
78
- };
79
- }
@@ -1,32 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import {
3
- jsonToolResult,
4
- toolExecutionErrorResult,
5
- unknownToolActionResult,
6
- } from "./tool-result.js";
7
-
8
- describe("jsonToolResult", () => {
9
- it("formats tool result with text content and details", () => {
10
- const payload = { ok: true, id: "abc" };
11
- expect(jsonToolResult(payload)).toEqual({
12
- content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
13
- details: payload,
14
- });
15
- });
16
-
17
- it("formats unknown action errors", () => {
18
- expect(unknownToolActionResult("create")).toEqual({
19
- content: [
20
- { type: "text", text: JSON.stringify({ error: "Unknown action: create" }, null, 2) },
21
- ],
22
- details: { error: "Unknown action: create" },
23
- });
24
- });
25
-
26
- it("formats execution errors", () => {
27
- expect(toolExecutionErrorResult(new Error("boom"))).toEqual({
28
- content: [{ type: "text", text: JSON.stringify({ error: "boom" }, null, 2) }],
29
- details: { error: "boom" },
30
- });
31
- });
32
- });
@@ -1,16 +0,0 @@
1
- import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
2
-
3
- export function jsonToolResult(data: unknown) {
4
- return {
5
- content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
6
- details: data,
7
- };
8
- }
9
-
10
- export function unknownToolActionResult(action: unknown) {
11
- return jsonToolResult({ error: `Unknown action: ${String(action)}` });
12
- }
13
-
14
- export function toolExecutionErrorResult(error: unknown) {
15
- return jsonToolResult({ error: formatErrorMessage(error) });
16
- }
@@ -1,21 +0,0 @@
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
- });
@@ -1,22 +0,0 @@
1
- import type { FeishuToolsConfig } from "./types.js";
2
-
3
- /**
4
- * Default tool configuration.
5
- * - doc, chat, wiki, drive, scopes: enabled by default
6
- * - perm: disabled by default (sensitive operation)
7
- */
8
- const DEFAULT_TOOLS_CONFIG: Required<FeishuToolsConfig> = {
9
- doc: true,
10
- chat: true,
11
- wiki: true,
12
- drive: true,
13
- perm: false,
14
- scopes: true,
15
- };
16
-
17
- /**
18
- * Resolve tools config with defaults.
19
- */
20
- export function resolveToolsConfig(cfg?: FeishuToolsConfig): Required<FeishuToolsConfig> {
21
- return { ...DEFAULT_TOOLS_CONFIG, ...cfg };
22
- }
package/src/types.ts DELETED
@@ -1,104 +0,0 @@
1
- import type { BaseProbeResult } from "openclaw/plugin-sdk/core";
2
- import type { FeishuConfigSchema, FeishuAccountConfigSchema, z } from "./config-schema.js";
3
- import type { MentionTarget } from "./mention-target.types.js";
4
-
5
- export type FeishuConfig = z.infer<typeof FeishuConfigSchema>;
6
- export type FeishuAccountConfig = z.infer<typeof FeishuAccountConfigSchema>;
7
-
8
- export type FeishuDomain = "feishu" | "lark" | (string & {});
9
-
10
- export type FeishuDefaultAccountSelectionSource =
11
- | "explicit-default"
12
- | "mapped-default"
13
- | "fallback";
14
- type FeishuAccountSelectionSource = "explicit" | FeishuDefaultAccountSelectionSource;
15
-
16
- export type ResolvedFeishuAccount = {
17
- accountId: string;
18
- selectionSource: FeishuAccountSelectionSource;
19
- enabled: boolean;
20
- configured: boolean;
21
- name?: string;
22
- appId?: string;
23
- appSecret?: string;
24
- encryptKey?: string;
25
- verificationToken?: string;
26
- domain: FeishuDomain;
27
- /** Merged config (top-level defaults + account-specific overrides) */
28
- config: FeishuConfig;
29
- };
30
-
31
- export type FeishuIdType = "open_id" | "user_id" | "union_id" | "chat_id";
32
-
33
- export type FeishuMessageContext = {
34
- chatId: string;
35
- messageId: string;
36
- replyTargetMessageId?: string;
37
- suppressReplyTarget?: boolean;
38
- senderId: string;
39
- senderOpenId: string;
40
- senderName?: string;
41
- chatType: FeishuChatType;
42
- mentionedBot: boolean;
43
- hasAnyMention?: boolean;
44
- rootId?: string;
45
- parentId?: string;
46
- threadId?: string;
47
- content: string;
48
- contentType: string;
49
- /** Mention forward targets (excluding the bot itself) */
50
- mentionTargets?: MentionTarget[];
51
- };
52
-
53
- export type FeishuSendResult = {
54
- messageId: string;
55
- chatId: string;
56
- };
57
-
58
- export type FeishuChatType = "p2p" | "group" | "topic_group" | "private";
59
-
60
- export function isFeishuGroupChatType(chatType: FeishuChatType | undefined): boolean {
61
- return chatType === "group" || chatType === "topic_group";
62
- }
63
-
64
- export type FeishuMessageInfo = {
65
- messageId: string;
66
- chatId: string;
67
- chatType?: FeishuChatType;
68
- senderId?: string;
69
- senderOpenId?: string;
70
- senderType?: string;
71
- content: string;
72
- contentType: string;
73
- createTime?: number;
74
- /** Feishu thread ID (omt_xxx) — present when the message belongs to a topic thread. */
75
- threadId?: string;
76
- };
77
-
78
- export interface FeishuProbeResult extends BaseProbeResult {
79
- appId?: string;
80
- botName?: string;
81
- botOpenId?: string;
82
- }
83
-
84
- export type FeishuMediaInfo = {
85
- path: string;
86
- contentType?: string;
87
- placeholder: string;
88
- };
89
-
90
- export type FeishuToolsConfig = {
91
- doc?: boolean;
92
- chat?: boolean;
93
- wiki?: boolean;
94
- drive?: boolean;
95
- perm?: boolean;
96
- scopes?: boolean;
97
- };
98
-
99
- export type DynamicAgentCreationConfig = {
100
- enabled?: boolean;
101
- workspaceTemplate?: string;
102
- agentDirTemplate?: string;
103
- maxAgents?: number;
104
- };
@@ -1,144 +0,0 @@
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 DELETED
@@ -1,214 +0,0 @@
1
- import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
2
- import { resolveFeishuRuntimeAccount } from "./accounts.js";
3
- import { createFeishuClient } from "./client.js";
4
- import { getFeishuRuntime } from "./runtime.js";
5
-
6
- // Feishu emoji types for typing indicator
7
- // See: https://open.feishu.cn/document/server-docs/im-v1/message-reaction/emojis-introduce
8
- // Full list: https://github.com/go-lark/lark/blob/main/emoji.go
9
- const TYPING_EMOJI = "Typing"; // Typing indicator emoji
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
-
38
- export type TypingIndicatorState = {
39
- messageId: string;
40
- reactionId: string | null;
41
- };
42
-
43
- type FeishuMessageReactionCreateResponse = Awaited<
44
- ReturnType<ReturnType<typeof createFeishuClient>["im"]["messageReaction"]["create"]>
45
- >;
46
-
47
- /**
48
- * Check whether an error represents a rate-limit or quota-exceeded condition
49
- * from the Feishu API that should stop the typing keepalive loop.
50
- *
51
- * Handles two shapes:
52
- * 1. AxiosError with `response.status` and `response.data.code`
53
- * 2. Feishu SDK error with a top-level `code` property
54
- */
55
- export function isFeishuBackoffError(err: unknown): boolean {
56
- if (typeof err !== "object" || err === null) {
57
- return false;
58
- }
59
-
60
- // AxiosError shape: err.response.status / err.response.data.code
61
- const response = (err as { response?: { status?: number; data?: { code?: number } } }).response;
62
- if (response) {
63
- if (response.status === 429) {
64
- return true;
65
- }
66
- if (typeof response.data?.code === "number" && FEISHU_BACKOFF_CODES.has(response.data.code)) {
67
- return true;
68
- }
69
- }
70
-
71
- // Feishu SDK error shape: err.code
72
- const code = (err as { code?: number }).code;
73
- if (typeof code === "number" && FEISHU_BACKOFF_CODES.has(code)) {
74
- return true;
75
- }
76
-
77
- return false;
78
- }
79
-
80
- /**
81
- * Check whether a Feishu SDK response object contains a backoff error code.
82
- *
83
- * The Feishu SDK sometimes returns a normal response (no throw) with an
84
- * API-level error code in the response body. This must be detected so the
85
- * circuit breaker can trip. See codex review on #28157.
86
- */
87
- export function getBackoffCodeFromResponse(response: unknown): number | undefined {
88
- if (typeof response !== "object" || response === null) {
89
- return undefined;
90
- }
91
- const code = (response as { code?: number }).code;
92
- if (typeof code === "number" && FEISHU_BACKOFF_CODES.has(code)) {
93
- return code;
94
- }
95
- return undefined;
96
- }
97
-
98
- /**
99
- * Add a typing indicator (reaction) to a message.
100
- *
101
- * Rate-limit and quota errors are re-thrown so the circuit breaker in
102
- * `createTypingCallbacks` (typing-start-guard) can trip and stop the
103
- * keepalive loop. See #28062.
104
- *
105
- * Also checks for backoff codes in non-throwing SDK responses (#28157).
106
- */
107
- export async function addTypingIndicator(params: {
108
- cfg: ClawdbotConfig;
109
- messageId: string;
110
- accountId?: string;
111
- runtime?: RuntimeEnv;
112
- }): Promise<TypingIndicatorState> {
113
- const { cfg, messageId, accountId, runtime } = params;
114
- const account = resolveFeishuRuntimeAccount({ cfg, accountId });
115
- if (!account.configured) {
116
- return { messageId, reactionId: null };
117
- }
118
-
119
- const client = createFeishuClient(account);
120
-
121
- try {
122
- const response = await client.im.messageReaction.create({
123
- path: { message_id: messageId },
124
- data: {
125
- reaction_type: { emoji_type: TYPING_EMOJI },
126
- },
127
- });
128
-
129
- // Feishu SDK may return a normal response with an API-level error code
130
- // instead of throwing. Detect backoff codes and throw to trip the breaker.
131
- const backoffCode = getBackoffCodeFromResponse(response);
132
- if (backoffCode !== undefined) {
133
- if (getFeishuRuntime().logging.shouldLogVerbose()) {
134
- runtime?.log?.(
135
- `[feishu] typing indicator response contains backoff code ${backoffCode}, stopping keepalive`,
136
- );
137
- }
138
- throw new FeishuBackoffError(backoffCode);
139
- }
140
-
141
- const typedResponse: FeishuMessageReactionCreateResponse = response;
142
- const reactionId = typedResponse.data?.reaction_id ?? null;
143
- return { messageId, reactionId };
144
- } catch (err) {
145
- if (isFeishuBackoffError(err)) {
146
- if (getFeishuRuntime().logging.shouldLogVerbose()) {
147
- runtime?.log?.("[feishu] typing indicator hit rate-limit/quota, stopping keepalive");
148
- }
149
- throw err;
150
- }
151
- // Silently fail for other non-critical errors (e.g. message deleted, permission issues)
152
- if (getFeishuRuntime().logging.shouldLogVerbose()) {
153
- runtime?.log?.(`[feishu] failed to add typing indicator: ${String(err)}`);
154
- }
155
- return { messageId, reactionId: null };
156
- }
157
- }
158
-
159
- /**
160
- * Remove a typing indicator (reaction) from a message.
161
- *
162
- * Rate-limit and quota errors are re-thrown for the same reason as above.
163
- */
164
- export async function removeTypingIndicator(params: {
165
- cfg: ClawdbotConfig;
166
- state: TypingIndicatorState;
167
- accountId?: string;
168
- runtime?: RuntimeEnv;
169
- }): Promise<void> {
170
- const { cfg, state, accountId, runtime } = params;
171
- if (!state.reactionId) {
172
- return;
173
- }
174
-
175
- const account = resolveFeishuRuntimeAccount({ cfg, accountId });
176
- if (!account.configured) {
177
- return;
178
- }
179
-
180
- const client = createFeishuClient(account);
181
-
182
- try {
183
- const result = await client.im.messageReaction.delete({
184
- path: {
185
- message_id: state.messageId,
186
- reaction_id: state.reactionId,
187
- },
188
- });
189
-
190
- // Check for backoff codes in non-throwing SDK responses
191
- const backoffCode = getBackoffCodeFromResponse(result);
192
- if (backoffCode !== undefined) {
193
- if (getFeishuRuntime().logging.shouldLogVerbose()) {
194
- runtime?.log?.(
195
- `[feishu] typing indicator removal response contains backoff code ${backoffCode}, stopping keepalive`,
196
- );
197
- }
198
- throw new FeishuBackoffError(backoffCode);
199
- }
200
- } catch (err) {
201
- if (isFeishuBackoffError(err)) {
202
- if (getFeishuRuntime().logging.shouldLogVerbose()) {
203
- runtime?.log?.(
204
- "[feishu] typing indicator removal hit rate-limit/quota, stopping keepalive",
205
- );
206
- }
207
- throw err;
208
- }
209
- // Silently fail for other non-critical errors
210
- if (getFeishuRuntime().logging.shouldLogVerbose()) {
211
- runtime?.log?.(`[feishu] failed to remove typing indicator: ${String(err)}`);
212
- }
213
- }
214
- }
@@ -1,55 +0,0 @@
1
- import { Type, type Static } from "typebox";
2
-
3
- export const FeishuWikiSchema = Type.Union([
4
- Type.Object({
5
- action: Type.Literal("spaces"),
6
- }),
7
- Type.Object({
8
- action: Type.Literal("nodes"),
9
- space_id: Type.String({ description: "Knowledge space ID" }),
10
- parent_node_token: Type.Optional(
11
- Type.String({ description: "Parent node token (optional, omit for root)" }),
12
- ),
13
- }),
14
- Type.Object({
15
- action: Type.Literal("get"),
16
- token: Type.String({ description: "Wiki node token (from URL /wiki/XXX)" }),
17
- }),
18
- Type.Object({
19
- action: Type.Literal("search"),
20
- query: Type.String({ description: "Search query" }),
21
- space_id: Type.Optional(Type.String({ description: "Limit search to this space (optional)" })),
22
- }),
23
- Type.Object({
24
- action: Type.Literal("create"),
25
- space_id: Type.String({ description: "Knowledge space ID" }),
26
- title: Type.String({ description: "Node title" }),
27
- obj_type: Type.Optional(
28
- Type.Union([Type.Literal("docx"), Type.Literal("sheet"), Type.Literal("bitable")], {
29
- description: "Object type (default: docx)",
30
- }),
31
- ),
32
- parent_node_token: Type.Optional(
33
- Type.String({ description: "Parent node token (optional, omit for root)" }),
34
- ),
35
- }),
36
- Type.Object({
37
- action: Type.Literal("move"),
38
- space_id: Type.String({ description: "Source knowledge space ID" }),
39
- node_token: Type.String({ description: "Node token to move" }),
40
- target_space_id: Type.Optional(
41
- Type.String({ description: "Target space ID (optional, same space if omitted)" }),
42
- ),
43
- target_parent_token: Type.Optional(
44
- Type.String({ description: "Target parent node token (optional, root if omitted)" }),
45
- ),
46
- }),
47
- Type.Object({
48
- action: Type.Literal("rename"),
49
- space_id: Type.String({ description: "Knowledge space ID" }),
50
- node_token: Type.String({ description: "Node token to rename" }),
51
- title: Type.String({ description: "New title" }),
52
- }),
53
- ]);
54
-
55
- export type FeishuWikiParams = Static<typeof FeishuWikiSchema>;