@kodelyth/feishu 2026.5.42 → 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/klaw.plugin.json +1712 -47
- package/package.json +19 -6
- package/api.ts +0 -32
- package/channel-entry.ts +0 -20
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -16
- package/index.ts +0 -82
- package/runtime-api.ts +0 -52
- package/secret-contract-api.ts +0 -5
- package/security-contract-api.ts +0 -1
- package/session-key-api.ts +0 -1
- package/setup-api.ts +0 -3
- package/setup-entry.test.ts +0 -19
- package/setup-entry.ts +0 -13
- package/src/accounts.test.ts +0 -480
- package/src/accounts.ts +0 -333
- package/src/agent-config.ts +0 -21
- package/src/app-registration.ts +0 -331
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -25
- package/src/async.test.ts +0 -35
- package/src/async.ts +0 -104
- package/src/audio-preflight.runtime.ts +0 -9
- package/src/bitable.test.ts +0 -136
- package/src/bitable.ts +0 -762
- package/src/bot-content.ts +0 -485
- package/src/bot-group-name.test.ts +0 -116
- package/src/bot-runtime-api.ts +0 -12
- package/src/bot-sender-name.ts +0 -125
- package/src/bot.broadcast.test.ts +0 -523
- package/src/bot.card-action.test.ts +0 -552
- package/src/bot.checkBotMentioned.test.ts +0 -265
- package/src/bot.helpers.test.ts +0 -135
- package/src/bot.stripBotMention.test.ts +0 -126
- package/src/bot.test.ts +0 -3671
- package/src/bot.ts +0 -1703
- package/src/card-action.ts +0 -447
- package/src/card-interaction.test.ts +0 -131
- package/src/card-interaction.ts +0 -159
- package/src/card-test-helpers.ts +0 -54
- package/src/card-ux-approval.ts +0 -65
- package/src/card-ux-launcher.test.ts +0 -106
- package/src/card-ux-launcher.ts +0 -121
- package/src/card-ux-shared.ts +0 -33
- package/src/channel-runtime-api.ts +0 -16
- package/src/channel.runtime.ts +0 -47
- package/src/channel.test.ts +0 -1151
- package/src/channel.ts +0 -1423
- package/src/chat-schema.ts +0 -25
- package/src/chat.test.ts +0 -240
- package/src/chat.ts +0 -188
- package/src/client-timeout.ts +0 -42
- package/src/client.test.ts +0 -447
- package/src/client.ts +0 -262
- package/src/comment-dispatcher-runtime-api.ts +0 -6
- package/src/comment-dispatcher.test.ts +0 -185
- package/src/comment-dispatcher.ts +0 -107
- package/src/comment-handler-runtime-api.ts +0 -3
- package/src/comment-handler.test.ts +0 -592
- package/src/comment-handler.ts +0 -303
- package/src/comment-reaction.test.ts +0 -138
- package/src/comment-reaction.ts +0 -259
- package/src/comment-shared.test.ts +0 -183
- package/src/comment-shared.ts +0 -406
- package/src/comment-target.ts +0 -44
- package/src/config-schema.test.ts +0 -326
- package/src/config-schema.ts +0 -335
- package/src/conversation-id.test.ts +0 -18
- package/src/conversation-id.ts +0 -199
- package/src/dedup-runtime-api.ts +0 -1
- package/src/dedup.ts +0 -141
- package/src/dedupe-key.ts +0 -72
- package/src/directory.static.ts +0 -61
- package/src/directory.test.ts +0 -141
- package/src/directory.ts +0 -124
- package/src/doc-schema.ts +0 -182
- package/src/docx-batch-insert.test.ts +0 -116
- package/src/docx-batch-insert.ts +0 -223
- package/src/docx-color-text.ts +0 -154
- package/src/docx-table-ops.test.ts +0 -53
- package/src/docx-table-ops.ts +0 -316
- package/src/docx-types.ts +0 -38
- package/src/docx.account-selection.test.ts +0 -95
- package/src/docx.test.ts +0 -701
- package/src/docx.ts +0 -1596
- package/src/drive-schema.ts +0 -92
- package/src/drive.test.ts +0 -1237
- package/src/drive.ts +0 -829
- package/src/dynamic-agent.test.ts +0 -155
- package/src/dynamic-agent.ts +0 -143
- package/src/event-types.ts +0 -45
- package/src/external-keys.test.ts +0 -20
- package/src/external-keys.ts +0 -19
- package/src/lifecycle.test-support.ts +0 -220
- package/src/media.test.ts +0 -955
- package/src/media.ts +0 -1105
- package/src/mention-target.types.ts +0 -5
- package/src/mention.ts +0 -114
- package/src/message-action-contract.ts +0 -13
- package/src/monitor-state-runtime-api.ts +0 -7
- package/src/monitor-transport-runtime-api.ts +0 -10
- package/src/monitor.account.ts +0 -492
- package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
- package/src/monitor.bot-identity.ts +0 -86
- package/src/monitor.bot-menu-handler.ts +0 -165
- package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
- package/src/monitor.bot-menu.test.ts +0 -188
- package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
- package/src/monitor.card-action.lifecycle.test-support.ts +0 -421
- package/src/monitor.cleanup.test.ts +0 -383
- package/src/monitor.comment-notice-handler.ts +0 -105
- package/src/monitor.comment.test.ts +0 -967
- package/src/monitor.comment.ts +0 -1386
- package/src/monitor.lifecycle.test.ts +0 -4
- package/src/monitor.message-handler.ts +0 -350
- package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
- package/src/monitor.reaction.test.ts +0 -739
- package/src/monitor.startup.test.ts +0 -213
- package/src/monitor.startup.ts +0 -74
- package/src/monitor.state.defaults.test.ts +0 -46
- package/src/monitor.state.ts +0 -170
- package/src/monitor.synthetic-error.ts +0 -18
- package/src/monitor.test-mocks.ts +0 -46
- package/src/monitor.transport.ts +0 -451
- package/src/monitor.ts +0 -100
- package/src/monitor.webhook-e2e.test.ts +0 -279
- package/src/monitor.webhook-security.test.ts +0 -389
- package/src/monitor.webhook.test-helpers.ts +0 -116
- package/src/outbound-runtime-api.ts +0 -1
- package/src/outbound.test.ts +0 -1118
- package/src/outbound.ts +0 -785
- package/src/perm-schema.ts +0 -52
- package/src/perm.ts +0 -170
- package/src/pins.ts +0 -108
- package/src/policy.test.ts +0 -223
- package/src/policy.ts +0 -318
- package/src/post.test.ts +0 -105
- package/src/post.ts +0 -275
- package/src/probe.test.ts +0 -283
- package/src/probe.ts +0 -166
- package/src/processing-claims.ts +0 -59
- package/src/qr-terminal.ts +0 -1
- package/src/reactions.ts +0 -123
- package/src/reasoning-preview.test.ts +0 -113
- package/src/reasoning-preview.ts +0 -28
- package/src/reply-dispatcher-runtime-api.ts +0 -7
- package/src/reply-dispatcher.test.ts +0 -1513
- package/src/reply-dispatcher.ts +0 -748
- package/src/runtime.ts +0 -9
- package/src/secret-contract.ts +0 -145
- package/src/secret-input.ts +0 -1
- package/src/security-audit-shared.ts +0 -69
- package/src/security-audit.test.ts +0 -59
- package/src/security-audit.ts +0 -1
- package/src/send-result.ts +0 -80
- package/src/send-target.test.ts +0 -86
- package/src/send-target.ts +0 -35
- package/src/send.reply-fallback.test.ts +0 -417
- package/src/send.test.ts +0 -621
- package/src/send.ts +0 -861
- package/src/sequential-key.test.ts +0 -72
- package/src/sequential-key.ts +0 -25
- package/src/sequential-queue.test.ts +0 -165
- package/src/sequential-queue.ts +0 -86
- package/src/session-conversation.ts +0 -42
- package/src/session-route.ts +0 -48
- package/src/setup-core.ts +0 -51
- package/src/setup-surface.test.ts +0 -484
- package/src/setup-surface.ts +0 -618
- package/src/streaming-card.test.ts +0 -397
- package/src/streaming-card.ts +0 -571
- package/src/subagent-hooks.test.ts +0 -627
- package/src/subagent-hooks.ts +0 -413
- package/src/targets.ts +0 -97
- package/src/test-support/lifecycle-test-support.ts +0 -454
- package/src/thread-bindings.test.ts +0 -180
- package/src/thread-bindings.ts +0 -331
- package/src/tool-account-routing.test.ts +0 -250
- package/src/tool-account.test.ts +0 -44
- package/src/tool-account.ts +0 -93
- package/src/tool-factory-test-harness.ts +0 -79
- package/src/tool-result.test.ts +0 -32
- package/src/tool-result.ts +0 -16
- package/src/tools-config.test.ts +0 -21
- package/src/tools-config.ts +0 -22
- package/src/types.ts +0 -106
- package/src/typing.test.ts +0 -144
- package/src/typing.ts +0 -214
- package/src/wiki-schema.ts +0 -69
- package/src/wiki.ts +0 -270
- package/subagent-hooks-api.ts +0 -31
- package/tsconfig.json +0 -16
package/src/chat-schema.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Type, type Static } from "typebox";
|
|
2
|
-
|
|
3
|
-
const CHAT_ACTION_VALUES = ["members", "info", "member_info"] as const;
|
|
4
|
-
const MEMBER_ID_TYPE_VALUES = ["open_id", "user_id", "union_id"] as const;
|
|
5
|
-
|
|
6
|
-
export const FeishuChatSchema = Type.Object({
|
|
7
|
-
action: Type.Unsafe<(typeof CHAT_ACTION_VALUES)[number]>({
|
|
8
|
-
type: "string",
|
|
9
|
-
enum: [...CHAT_ACTION_VALUES],
|
|
10
|
-
description: "Action to run: members | info | member_info",
|
|
11
|
-
}),
|
|
12
|
-
chat_id: Type.Optional(Type.String({ description: "Chat ID (from URL or event payload)" })),
|
|
13
|
-
member_id: Type.Optional(Type.String({ description: "Member ID for member_info lookups" })),
|
|
14
|
-
page_size: Type.Optional(Type.Number({ description: "Page size (1-100, default 50)" })),
|
|
15
|
-
page_token: Type.Optional(Type.String({ description: "Pagination token" })),
|
|
16
|
-
member_id_type: Type.Optional(
|
|
17
|
-
Type.Unsafe<(typeof MEMBER_ID_TYPE_VALUES)[number]>({
|
|
18
|
-
type: "string",
|
|
19
|
-
enum: [...MEMBER_ID_TYPE_VALUES],
|
|
20
|
-
description: "Member ID type (default: open_id)",
|
|
21
|
-
}),
|
|
22
|
-
),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export type FeishuChatParams = Static<typeof FeishuChatSchema>;
|
package/src/chat.test.ts
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { createTestPluginApi } from "klaw/plugin-sdk/plugin-test-api";
|
|
2
|
-
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import type { KlawPluginApi, PluginRuntime } from "../runtime-api.js";
|
|
4
|
-
|
|
5
|
-
const createFeishuClientMock = vi.hoisted(() => vi.fn());
|
|
6
|
-
const chatGetMock = vi.hoisted(() => vi.fn());
|
|
7
|
-
const chatMembersGetMock = vi.hoisted(() => vi.fn());
|
|
8
|
-
const contactUserGetMock = vi.hoisted(() => vi.fn());
|
|
9
|
-
|
|
10
|
-
vi.mock("./client.js", () => ({
|
|
11
|
-
createFeishuClient: createFeishuClientMock,
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
let registerFeishuChatTools: typeof import("./chat.js").registerFeishuChatTools;
|
|
15
|
-
|
|
16
|
-
function createFeishuToolRuntime(): PluginRuntime {
|
|
17
|
-
return {} as PluginRuntime;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
describe("registerFeishuChatTools", () => {
|
|
21
|
-
function createChatToolApi(params: {
|
|
22
|
-
config: KlawPluginApi["config"];
|
|
23
|
-
registerTool: KlawPluginApi["registerTool"];
|
|
24
|
-
}): KlawPluginApi {
|
|
25
|
-
return createTestPluginApi({
|
|
26
|
-
id: "feishu-test",
|
|
27
|
-
name: "Feishu Test",
|
|
28
|
-
source: "local",
|
|
29
|
-
config: params.config,
|
|
30
|
-
runtime: createFeishuToolRuntime(),
|
|
31
|
-
logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
32
|
-
registerTool: params.registerTool,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
beforeAll(async () => {
|
|
37
|
-
({ registerFeishuChatTools } = await import("./chat.js"));
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
afterAll(() => {
|
|
41
|
-
vi.doUnmock("./client.js");
|
|
42
|
-
vi.resetModules();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
vi.clearAllMocks();
|
|
47
|
-
createFeishuClientMock.mockReturnValue({
|
|
48
|
-
im: {
|
|
49
|
-
chat: { get: chatGetMock },
|
|
50
|
-
chatMembers: { get: chatMembersGetMock },
|
|
51
|
-
},
|
|
52
|
-
contact: {
|
|
53
|
-
user: { get: contactUserGetMock },
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("registers feishu_chat and handles info/members actions", async () => {
|
|
59
|
-
const registerTool = vi.fn();
|
|
60
|
-
registerFeishuChatTools(
|
|
61
|
-
createChatToolApi({
|
|
62
|
-
config: {
|
|
63
|
-
channels: {
|
|
64
|
-
feishu: {
|
|
65
|
-
enabled: true,
|
|
66
|
-
appId: "app_id",
|
|
67
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
68
|
-
tools: { chat: true },
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
registerTool,
|
|
73
|
-
}),
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
expect(registerTool).toHaveBeenCalledTimes(1);
|
|
77
|
-
const tool = registerTool.mock.calls[0]?.[0];
|
|
78
|
-
expect(tool?.name).toBe("feishu_chat");
|
|
79
|
-
|
|
80
|
-
chatGetMock.mockResolvedValueOnce({
|
|
81
|
-
code: 0,
|
|
82
|
-
data: { name: "group name", user_count: 3 },
|
|
83
|
-
});
|
|
84
|
-
const infoResult = await tool.execute("tc_1", { action: "info", chat_id: "oc_1" });
|
|
85
|
-
expect(infoResult.details).toEqual({
|
|
86
|
-
chat_id: "oc_1",
|
|
87
|
-
name: "group name",
|
|
88
|
-
description: undefined,
|
|
89
|
-
owner_id: undefined,
|
|
90
|
-
tenant_key: undefined,
|
|
91
|
-
user_count: 3,
|
|
92
|
-
chat_mode: undefined,
|
|
93
|
-
chat_type: undefined,
|
|
94
|
-
join_message_visibility: undefined,
|
|
95
|
-
leave_message_visibility: undefined,
|
|
96
|
-
membership_approval: undefined,
|
|
97
|
-
moderation_permission: undefined,
|
|
98
|
-
avatar: undefined,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
chatMembersGetMock.mockResolvedValueOnce({
|
|
102
|
-
code: 0,
|
|
103
|
-
data: {
|
|
104
|
-
has_more: false,
|
|
105
|
-
page_token: "",
|
|
106
|
-
items: [{ member_id: "ou_1", name: "member1", member_id_type: "open_id" }],
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
const membersResult = await tool.execute("tc_2", { action: "members", chat_id: "oc_1" });
|
|
110
|
-
expect(membersResult.details).toEqual({
|
|
111
|
-
chat_id: "oc_1",
|
|
112
|
-
has_more: false,
|
|
113
|
-
page_token: "",
|
|
114
|
-
members: [
|
|
115
|
-
{
|
|
116
|
-
member_id: "ou_1",
|
|
117
|
-
name: "member1",
|
|
118
|
-
tenant_key: undefined,
|
|
119
|
-
member_id_type: "open_id",
|
|
120
|
-
},
|
|
121
|
-
],
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
contactUserGetMock.mockResolvedValueOnce({
|
|
125
|
-
code: 0,
|
|
126
|
-
data: {
|
|
127
|
-
user: {
|
|
128
|
-
open_id: "ou_1",
|
|
129
|
-
name: "member1",
|
|
130
|
-
email: "member1@example.com",
|
|
131
|
-
department_ids: ["od_1"],
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
const memberInfoResult = await tool.execute("tc_3", {
|
|
136
|
-
action: "member_info",
|
|
137
|
-
member_id: "ou_1",
|
|
138
|
-
});
|
|
139
|
-
expect(memberInfoResult.details).toEqual({
|
|
140
|
-
member_id: "ou_1",
|
|
141
|
-
member_id_type: "open_id",
|
|
142
|
-
open_id: "ou_1",
|
|
143
|
-
user_id: undefined,
|
|
144
|
-
union_id: undefined,
|
|
145
|
-
name: "member1",
|
|
146
|
-
en_name: undefined,
|
|
147
|
-
nickname: undefined,
|
|
148
|
-
email: "member1@example.com",
|
|
149
|
-
enterprise_email: undefined,
|
|
150
|
-
mobile: undefined,
|
|
151
|
-
mobile_visible: undefined,
|
|
152
|
-
status: undefined,
|
|
153
|
-
avatar: undefined,
|
|
154
|
-
department_ids: ["od_1"],
|
|
155
|
-
department_path: undefined,
|
|
156
|
-
leader_user_id: undefined,
|
|
157
|
-
city: undefined,
|
|
158
|
-
country: undefined,
|
|
159
|
-
work_station: undefined,
|
|
160
|
-
join_time: undefined,
|
|
161
|
-
is_tenant_manager: undefined,
|
|
162
|
-
employee_no: undefined,
|
|
163
|
-
employee_type: undefined,
|
|
164
|
-
description: undefined,
|
|
165
|
-
job_title: undefined,
|
|
166
|
-
geo: undefined,
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("skips registration when chat tool is disabled", () => {
|
|
171
|
-
const registerTool = vi.fn();
|
|
172
|
-
registerFeishuChatTools(
|
|
173
|
-
createChatToolApi({
|
|
174
|
-
config: {
|
|
175
|
-
channels: {
|
|
176
|
-
feishu: {
|
|
177
|
-
enabled: true,
|
|
178
|
-
appId: "app_id",
|
|
179
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
180
|
-
tools: { chat: false },
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
registerTool,
|
|
185
|
-
}),
|
|
186
|
-
);
|
|
187
|
-
expect(registerTool).not.toHaveBeenCalled();
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("preserves Feishu diagnostics from rejected member lookups", async () => {
|
|
191
|
-
const registerTool = vi.fn();
|
|
192
|
-
registerFeishuChatTools(
|
|
193
|
-
createChatToolApi({
|
|
194
|
-
config: {
|
|
195
|
-
channels: {
|
|
196
|
-
feishu: {
|
|
197
|
-
enabled: true,
|
|
198
|
-
appId: "app_id",
|
|
199
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
200
|
-
tools: { chat: true },
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
registerTool,
|
|
205
|
-
}),
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
const tool = registerTool.mock.calls[0]?.[0];
|
|
209
|
-
contactUserGetMock.mockRejectedValueOnce(
|
|
210
|
-
Object.assign(new Error("Request failed with status code 400"), {
|
|
211
|
-
response: {
|
|
212
|
-
status: 400,
|
|
213
|
-
data: {
|
|
214
|
-
code: 99992360,
|
|
215
|
-
msg: "The request you send is not a valid {user_id} or not exists",
|
|
216
|
-
error: {
|
|
217
|
-
log_id: "20260429124800CHAT",
|
|
218
|
-
troubleshooter: "https://open.feishu.cn/search?log_id=20260429124800CHAT",
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
}),
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
const result = await tool.execute("tc_4", {
|
|
226
|
-
action: "member_info",
|
|
227
|
-
member_id: "ou_1",
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
expect(result.details.error).toContain('"http_status":400');
|
|
231
|
-
expect(result.details.error).toContain('"feishu_code":99992360');
|
|
232
|
-
expect(result.details.error).toContain(
|
|
233
|
-
'"feishu_msg":"The request you send is not a valid {user_id} or not exists"',
|
|
234
|
-
);
|
|
235
|
-
expect(result.details.error).toContain('"feishu_log_id":"20260429124800CHAT"');
|
|
236
|
-
expect(result.details.error).toContain(
|
|
237
|
-
'"feishu_troubleshooter":"https://open.feishu.cn/search?log_id=20260429124800CHAT"',
|
|
238
|
-
);
|
|
239
|
-
});
|
|
240
|
-
});
|
package/src/chat.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
import type * as Lark from "@larksuiteoapi/node-sdk";
|
|
2
|
-
import type { KlawPluginApi } from "../runtime-api.js";
|
|
3
|
-
import { listEnabledFeishuAccounts } from "./accounts.js";
|
|
4
|
-
import { FeishuChatSchema, type FeishuChatParams } from "./chat-schema.js";
|
|
5
|
-
import { createFeishuClient } from "./client.js";
|
|
6
|
-
import { formatFeishuApiError } from "./comment-shared.js";
|
|
7
|
-
import { resolveToolsConfig } from "./tools-config.js";
|
|
8
|
-
|
|
9
|
-
function json(data: unknown) {
|
|
10
|
-
return {
|
|
11
|
-
content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
|
|
12
|
-
details: data,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function getChatInfo(client: Lark.Client, chatId: string) {
|
|
17
|
-
const res = await client.im.chat.get({ path: { chat_id: chatId } });
|
|
18
|
-
if (res.code !== 0) {
|
|
19
|
-
throw new Error(res.msg);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const chat = res.data;
|
|
23
|
-
return {
|
|
24
|
-
chat_id: chatId,
|
|
25
|
-
name: chat?.name,
|
|
26
|
-
description: chat?.description,
|
|
27
|
-
owner_id: chat?.owner_id,
|
|
28
|
-
tenant_key: chat?.tenant_key,
|
|
29
|
-
user_count: chat?.user_count,
|
|
30
|
-
chat_mode: chat?.chat_mode,
|
|
31
|
-
chat_type: chat?.chat_type,
|
|
32
|
-
join_message_visibility: chat?.join_message_visibility,
|
|
33
|
-
leave_message_visibility: chat?.leave_message_visibility,
|
|
34
|
-
membership_approval: chat?.membership_approval,
|
|
35
|
-
moderation_permission: chat?.moderation_permission,
|
|
36
|
-
avatar: chat?.avatar,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function getChatMembers(
|
|
41
|
-
client: Lark.Client,
|
|
42
|
-
chatId: string,
|
|
43
|
-
pageSize?: number,
|
|
44
|
-
pageToken?: string,
|
|
45
|
-
memberIdType?: "open_id" | "user_id" | "union_id",
|
|
46
|
-
) {
|
|
47
|
-
const page_size = pageSize ? Math.max(1, Math.min(100, pageSize)) : 50;
|
|
48
|
-
const res = await client.im.chatMembers.get({
|
|
49
|
-
path: { chat_id: chatId },
|
|
50
|
-
params: {
|
|
51
|
-
page_size,
|
|
52
|
-
page_token: pageToken,
|
|
53
|
-
member_id_type: memberIdType ?? "open_id",
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
if (res.code !== 0) {
|
|
58
|
-
throw new Error(res.msg);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
chat_id: chatId,
|
|
63
|
-
has_more: res.data?.has_more,
|
|
64
|
-
page_token: res.data?.page_token,
|
|
65
|
-
members:
|
|
66
|
-
res.data?.items?.map((item) => ({
|
|
67
|
-
member_id: item.member_id,
|
|
68
|
-
name: item.name,
|
|
69
|
-
tenant_key: item.tenant_key,
|
|
70
|
-
member_id_type: item.member_id_type,
|
|
71
|
-
})) ?? [],
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function getFeishuMemberInfo(
|
|
76
|
-
client: Lark.Client,
|
|
77
|
-
memberId: string,
|
|
78
|
-
memberIdType: "open_id" | "user_id" | "union_id" = "open_id",
|
|
79
|
-
) {
|
|
80
|
-
const res = await client.contact.user.get({
|
|
81
|
-
path: { user_id: memberId },
|
|
82
|
-
params: {
|
|
83
|
-
user_id_type: memberIdType,
|
|
84
|
-
department_id_type: "open_department_id",
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (res.code !== 0) {
|
|
89
|
-
throw new Error(res.msg);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const user = res.data?.user;
|
|
93
|
-
return {
|
|
94
|
-
member_id: memberId,
|
|
95
|
-
member_id_type: memberIdType,
|
|
96
|
-
open_id: user?.open_id,
|
|
97
|
-
user_id: user?.user_id,
|
|
98
|
-
union_id: user?.union_id,
|
|
99
|
-
name: user?.name,
|
|
100
|
-
en_name: user?.en_name,
|
|
101
|
-
nickname: user?.nickname,
|
|
102
|
-
email: user?.email,
|
|
103
|
-
enterprise_email: user?.enterprise_email,
|
|
104
|
-
mobile: user?.mobile,
|
|
105
|
-
mobile_visible: user?.mobile_visible,
|
|
106
|
-
status: user?.status,
|
|
107
|
-
avatar: user?.avatar,
|
|
108
|
-
department_ids: user?.department_ids,
|
|
109
|
-
department_path: user?.department_path,
|
|
110
|
-
leader_user_id: user?.leader_user_id,
|
|
111
|
-
city: user?.city,
|
|
112
|
-
country: user?.country,
|
|
113
|
-
work_station: user?.work_station,
|
|
114
|
-
join_time: user?.join_time,
|
|
115
|
-
is_tenant_manager: user?.is_tenant_manager,
|
|
116
|
-
employee_no: user?.employee_no,
|
|
117
|
-
employee_type: user?.employee_type,
|
|
118
|
-
description: user?.description,
|
|
119
|
-
job_title: user?.job_title,
|
|
120
|
-
geo: user?.geo,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function registerFeishuChatTools(api: KlawPluginApi) {
|
|
125
|
-
if (!api.config) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const accounts = listEnabledFeishuAccounts(api.config);
|
|
130
|
-
if (accounts.length === 0) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const firstAccount = accounts[0];
|
|
135
|
-
const toolsCfg = resolveToolsConfig(firstAccount.config.tools);
|
|
136
|
-
if (!toolsCfg.chat) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const getClient = () => createFeishuClient(firstAccount);
|
|
141
|
-
|
|
142
|
-
api.registerTool(
|
|
143
|
-
{
|
|
144
|
-
name: "feishu_chat",
|
|
145
|
-
label: "Feishu Chat",
|
|
146
|
-
description: "Feishu chat operations. Actions: members, info, member_info",
|
|
147
|
-
parameters: FeishuChatSchema,
|
|
148
|
-
async execute(_toolCallId, params) {
|
|
149
|
-
const p = params as FeishuChatParams;
|
|
150
|
-
try {
|
|
151
|
-
const client = getClient();
|
|
152
|
-
switch (p.action) {
|
|
153
|
-
case "members":
|
|
154
|
-
if (!p.chat_id) {
|
|
155
|
-
return json({ error: "chat_id is required for action members" });
|
|
156
|
-
}
|
|
157
|
-
return json(
|
|
158
|
-
await getChatMembers(
|
|
159
|
-
client,
|
|
160
|
-
p.chat_id,
|
|
161
|
-
p.page_size,
|
|
162
|
-
p.page_token,
|
|
163
|
-
p.member_id_type,
|
|
164
|
-
),
|
|
165
|
-
);
|
|
166
|
-
case "info":
|
|
167
|
-
if (!p.chat_id) {
|
|
168
|
-
return json({ error: "chat_id is required for action info" });
|
|
169
|
-
}
|
|
170
|
-
return json(await getChatInfo(client, p.chat_id));
|
|
171
|
-
case "member_info":
|
|
172
|
-
if (!p.member_id) {
|
|
173
|
-
return json({ error: "member_id is required for action member_info" });
|
|
174
|
-
}
|
|
175
|
-
return json(
|
|
176
|
-
await getFeishuMemberInfo(client, p.member_id, p.member_id_type ?? "open_id"),
|
|
177
|
-
);
|
|
178
|
-
default:
|
|
179
|
-
return json({ error: `Unknown action: ${String(p.action)}` });
|
|
180
|
-
}
|
|
181
|
-
} catch (err) {
|
|
182
|
-
return json({ error: formatFeishuApiError(err, { includeNestedErrorLogId: true }) });
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
{ name: "feishu_chat" },
|
|
187
|
-
);
|
|
188
|
-
}
|
package/src/client-timeout.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { FeishuConfig } from "./types.js";
|
|
2
|
-
|
|
3
|
-
/** Default HTTP timeout for Feishu API requests (30 seconds). */
|
|
4
|
-
export const FEISHU_HTTP_TIMEOUT_MS = 30_000;
|
|
5
|
-
export const FEISHU_HTTP_TIMEOUT_MAX_MS = 300_000;
|
|
6
|
-
export const FEISHU_HTTP_TIMEOUT_ENV_VAR = "KLAW_FEISHU_HTTP_TIMEOUT_MS";
|
|
7
|
-
|
|
8
|
-
export type FeishuClientTimeoutConfig = {
|
|
9
|
-
httpTimeoutMs?: number;
|
|
10
|
-
config?: Pick<FeishuConfig, "httpTimeoutMs">;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function resolveConfiguredHttpTimeoutMs(creds: FeishuClientTimeoutConfig): number {
|
|
14
|
-
const clampTimeout = (value: number): number => {
|
|
15
|
-
const rounded = Math.floor(value);
|
|
16
|
-
return Math.min(Math.max(rounded, 1), FEISHU_HTTP_TIMEOUT_MAX_MS);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const fromDirectField = creds.httpTimeoutMs;
|
|
20
|
-
if (
|
|
21
|
-
typeof fromDirectField === "number" &&
|
|
22
|
-
Number.isFinite(fromDirectField) &&
|
|
23
|
-
fromDirectField > 0
|
|
24
|
-
) {
|
|
25
|
-
return clampTimeout(fromDirectField);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const envRaw = process.env[FEISHU_HTTP_TIMEOUT_ENV_VAR];
|
|
29
|
-
if (envRaw) {
|
|
30
|
-
const envValue = Number(envRaw);
|
|
31
|
-
if (Number.isFinite(envValue) && envValue > 0) {
|
|
32
|
-
return clampTimeout(envValue);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const fromConfig = creds.config?.httpTimeoutMs;
|
|
37
|
-
const timeout = fromConfig;
|
|
38
|
-
if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0) {
|
|
39
|
-
return FEISHU_HTTP_TIMEOUT_MS;
|
|
40
|
-
}
|
|
41
|
-
return clampTimeout(timeout);
|
|
42
|
-
}
|