@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/drive.test.ts
DELETED
|
@@ -1,1237 +0,0 @@
|
|
|
1
|
-
import { createTestPluginApi } from "klaw/plugin-sdk/plugin-test-api";
|
|
2
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import type { KlawPluginApi, PluginRuntime } from "../runtime-api.js";
|
|
4
|
-
|
|
5
|
-
const createFeishuToolClientMock = vi.hoisted(() => vi.fn());
|
|
6
|
-
const resolveAnyEnabledFeishuToolsConfigMock = vi.hoisted(() => vi.fn());
|
|
7
|
-
const cleanupAmbientCommentTypingReactionMock = vi.hoisted(() => vi.fn(async () => false));
|
|
8
|
-
|
|
9
|
-
vi.mock("./tool-account.js", () => ({
|
|
10
|
-
createFeishuToolClient: createFeishuToolClientMock,
|
|
11
|
-
resolveAnyEnabledFeishuToolsConfig: resolveAnyEnabledFeishuToolsConfigMock,
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
vi.mock("./comment-reaction.js", () => ({
|
|
15
|
-
cleanupAmbientCommentTypingReaction: cleanupAmbientCommentTypingReactionMock,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
let registerFeishuDriveTools: typeof import("./drive.js").registerFeishuDriveTools;
|
|
19
|
-
|
|
20
|
-
function createFeishuToolRuntime(): PluginRuntime {
|
|
21
|
-
return {} as PluginRuntime;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function raceWithNextMacrotask<T>(promise: Promise<T>): Promise<T | "pending"> {
|
|
25
|
-
return await Promise.race([
|
|
26
|
-
promise,
|
|
27
|
-
new Promise<"pending">((resolve) => {
|
|
28
|
-
setImmediate(() => resolve("pending"));
|
|
29
|
-
}),
|
|
30
|
-
]);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function createDriveToolApi(params: {
|
|
34
|
-
config: KlawPluginApi["config"];
|
|
35
|
-
registerTool: KlawPluginApi["registerTool"];
|
|
36
|
-
}): KlawPluginApi {
|
|
37
|
-
return createTestPluginApi({
|
|
38
|
-
id: "feishu-test",
|
|
39
|
-
name: "Feishu Test",
|
|
40
|
-
source: "local",
|
|
41
|
-
config: params.config,
|
|
42
|
-
runtime: createFeishuToolRuntime(),
|
|
43
|
-
logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
44
|
-
registerTool: params.registerTool,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function mockCallArg<T>(
|
|
49
|
-
mock: { mock: { calls: unknown[][] } },
|
|
50
|
-
callIndex: number,
|
|
51
|
-
argIndex: number,
|
|
52
|
-
_type?: (value: unknown) => value is T,
|
|
53
|
-
): T {
|
|
54
|
-
const call = mock.mock.calls.at(callIndex);
|
|
55
|
-
if (!call) {
|
|
56
|
-
throw new Error(`Expected mock call at index ${callIndex}`);
|
|
57
|
-
}
|
|
58
|
-
return call[argIndex] as T;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
type FeishuDriveTool = {
|
|
62
|
-
execute: (callId: string, input: Record<string, unknown>) => Promise<{ details?: unknown }>;
|
|
63
|
-
name?: string;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
type FeishuDriveToolFactory = (context: {
|
|
67
|
-
agentAccountId?: string;
|
|
68
|
-
deliveryContext?: unknown;
|
|
69
|
-
}) => FeishuDriveTool;
|
|
70
|
-
|
|
71
|
-
function firstToolFactory(mock: { mock: { calls: unknown[][] } }): FeishuDriveToolFactory {
|
|
72
|
-
return mockCallArg<FeishuDriveToolFactory>(mock, 0, 0);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function firstLogMessage(mock: { mock: { calls: unknown[][] } }): string {
|
|
76
|
-
return String(mockCallArg<unknown>(mock, 0, 0));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type FeishuDriveRequest = {
|
|
80
|
-
data?: unknown;
|
|
81
|
-
method?: string;
|
|
82
|
-
params?: unknown;
|
|
83
|
-
url?: string;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
function requestCall(
|
|
87
|
-
mock: { mock: { calls: unknown[][] } },
|
|
88
|
-
callIndex: number,
|
|
89
|
-
): FeishuDriveRequest {
|
|
90
|
-
return mockCallArg<FeishuDriveRequest>(mock, callIndex, 0);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function expectRequestCall(
|
|
94
|
-
mock: { mock: { calls: unknown[][] } },
|
|
95
|
-
callIndex: number,
|
|
96
|
-
expected: FeishuDriveRequest,
|
|
97
|
-
): void {
|
|
98
|
-
const request = requestCall(mock, callIndex);
|
|
99
|
-
expect(request.method).toBe(expected.method);
|
|
100
|
-
expect(request.url).toBe(expected.url);
|
|
101
|
-
if ("data" in expected) {
|
|
102
|
-
expect(request.data).toEqual(expected.data);
|
|
103
|
-
}
|
|
104
|
-
if ("params" in expected) {
|
|
105
|
-
expect(request.params).toEqual(expected.params);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
describe("registerFeishuDriveTools", () => {
|
|
110
|
-
const requestMock = vi.fn();
|
|
111
|
-
|
|
112
|
-
beforeAll(async () => {
|
|
113
|
-
({ registerFeishuDriveTools } = await import("./drive.js"));
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
afterAll(() => {
|
|
117
|
-
vi.doUnmock("./tool-account.js");
|
|
118
|
-
vi.doUnmock("./comment-reaction.js");
|
|
119
|
-
vi.resetModules();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
afterEach(() => {
|
|
123
|
-
vi.restoreAllMocks();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
beforeEach(() => {
|
|
127
|
-
vi.clearAllMocks();
|
|
128
|
-
resolveAnyEnabledFeishuToolsConfigMock.mockReturnValue({
|
|
129
|
-
doc: false,
|
|
130
|
-
chat: false,
|
|
131
|
-
wiki: false,
|
|
132
|
-
drive: true,
|
|
133
|
-
perm: false,
|
|
134
|
-
scopes: false,
|
|
135
|
-
});
|
|
136
|
-
createFeishuToolClientMock.mockReturnValue({
|
|
137
|
-
request: requestMock,
|
|
138
|
-
});
|
|
139
|
-
cleanupAmbientCommentTypingReactionMock.mockResolvedValue(false);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("registers feishu_drive and handles comment actions", async () => {
|
|
143
|
-
const registerTool = vi.fn();
|
|
144
|
-
registerFeishuDriveTools(
|
|
145
|
-
createDriveToolApi({
|
|
146
|
-
config: {
|
|
147
|
-
channels: {
|
|
148
|
-
feishu: {
|
|
149
|
-
enabled: true,
|
|
150
|
-
appId: "app_id",
|
|
151
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
152
|
-
tools: { drive: true },
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
registerTool,
|
|
157
|
-
}),
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
expect(registerTool).toHaveBeenCalledTimes(1);
|
|
161
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
162
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
163
|
-
expect(tool?.name).toBe("feishu_drive");
|
|
164
|
-
|
|
165
|
-
requestMock.mockResolvedValueOnce({
|
|
166
|
-
code: 0,
|
|
167
|
-
data: {
|
|
168
|
-
has_more: false,
|
|
169
|
-
page_token: "0",
|
|
170
|
-
items: [
|
|
171
|
-
{
|
|
172
|
-
comment_id: "c1",
|
|
173
|
-
quote: "quoted text",
|
|
174
|
-
reply_list: {
|
|
175
|
-
replies: [
|
|
176
|
-
{
|
|
177
|
-
reply_id: "r1",
|
|
178
|
-
user_id: "ou_author",
|
|
179
|
-
content: {
|
|
180
|
-
elements: [
|
|
181
|
-
{
|
|
182
|
-
type: "text_run",
|
|
183
|
-
text_run: { text: "root comment" },
|
|
184
|
-
},
|
|
185
|
-
],
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
reply_id: "r2",
|
|
190
|
-
user_id: "ou_reply",
|
|
191
|
-
content: {
|
|
192
|
-
elements: [
|
|
193
|
-
{
|
|
194
|
-
type: "text_run",
|
|
195
|
-
text_run: { text: "reply text" },
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
],
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
const listResult = await tool.execute("call-1", {
|
|
207
|
-
action: "list_comments",
|
|
208
|
-
file_token: "doc_1",
|
|
209
|
-
file_type: "docx",
|
|
210
|
-
});
|
|
211
|
-
const listRequest = mockCallArg<{ method?: string; url?: string }>(requestMock, 0, 0);
|
|
212
|
-
expect(listRequest.method).toBe("GET");
|
|
213
|
-
expect(listRequest.url).toBe(
|
|
214
|
-
"/open-apis/drive/v1/files/doc_1/comments?file_type=docx&user_id_type=open_id",
|
|
215
|
-
);
|
|
216
|
-
const listDetails = listResult.details as
|
|
217
|
-
| {
|
|
218
|
-
comments?: Array<{
|
|
219
|
-
comment_id?: string;
|
|
220
|
-
quote?: string;
|
|
221
|
-
replies?: Array<{ reply_id?: string; text?: string }>;
|
|
222
|
-
text?: string;
|
|
223
|
-
}>;
|
|
224
|
-
}
|
|
225
|
-
| undefined;
|
|
226
|
-
expect(listDetails?.comments).toHaveLength(1);
|
|
227
|
-
expect(listDetails?.comments?.[0]?.comment_id).toBe("c1");
|
|
228
|
-
expect(listDetails?.comments?.[0]?.text).toBe("root comment");
|
|
229
|
-
expect(listDetails?.comments?.[0]?.quote).toBe("quoted text");
|
|
230
|
-
expect(listDetails?.comments?.[0]?.replies).toHaveLength(1);
|
|
231
|
-
expect(listDetails?.comments?.[0]?.replies?.[0]?.reply_id).toBe("r2");
|
|
232
|
-
expect(listDetails?.comments?.[0]?.replies?.[0]?.text).toBe("reply text");
|
|
233
|
-
|
|
234
|
-
requestMock.mockResolvedValueOnce({
|
|
235
|
-
code: 0,
|
|
236
|
-
data: {
|
|
237
|
-
has_more: false,
|
|
238
|
-
page_token: "0",
|
|
239
|
-
items: [
|
|
240
|
-
{
|
|
241
|
-
reply_id: "r3",
|
|
242
|
-
user_id: "ou_reply_2",
|
|
243
|
-
content: {
|
|
244
|
-
elements: [
|
|
245
|
-
{
|
|
246
|
-
type: "text_run",
|
|
247
|
-
text_run: { content: "reply from api" },
|
|
248
|
-
},
|
|
249
|
-
],
|
|
250
|
-
},
|
|
251
|
-
},
|
|
252
|
-
],
|
|
253
|
-
},
|
|
254
|
-
});
|
|
255
|
-
const repliesResult = await tool.execute("call-2", {
|
|
256
|
-
action: "list_comment_replies",
|
|
257
|
-
file_token: "doc_1",
|
|
258
|
-
file_type: "docx",
|
|
259
|
-
comment_id: "c1",
|
|
260
|
-
});
|
|
261
|
-
const repliesRequest = mockCallArg<{ method?: string; url?: string }>(requestMock, 1, 0);
|
|
262
|
-
expect(repliesRequest.method).toBe("GET");
|
|
263
|
-
expect(repliesRequest.url).toBe(
|
|
264
|
-
"/open-apis/drive/v1/files/doc_1/comments/c1/replies?file_type=docx&user_id_type=open_id",
|
|
265
|
-
);
|
|
266
|
-
const repliesDetails = repliesResult.details as
|
|
267
|
-
| { replies?: Array<{ reply_id?: string; text?: string }> }
|
|
268
|
-
| undefined;
|
|
269
|
-
expect(repliesDetails?.replies).toHaveLength(1);
|
|
270
|
-
expect(repliesDetails?.replies?.[0]?.reply_id).toBe("r3");
|
|
271
|
-
expect(repliesDetails?.replies?.[0]?.text).toBe("reply from api");
|
|
272
|
-
|
|
273
|
-
requestMock.mockResolvedValueOnce({
|
|
274
|
-
code: 0,
|
|
275
|
-
data: { comment_id: "c2" },
|
|
276
|
-
});
|
|
277
|
-
const addCommentResult = await tool.execute("call-3", {
|
|
278
|
-
action: "add_comment",
|
|
279
|
-
file_token: "doc_1",
|
|
280
|
-
file_type: "docx",
|
|
281
|
-
block_id: "blk_1",
|
|
282
|
-
content: "please update this section",
|
|
283
|
-
});
|
|
284
|
-
const addRequest = mockCallArg<{
|
|
285
|
-
data?: {
|
|
286
|
-
anchor?: { block_id?: string };
|
|
287
|
-
file_type?: string;
|
|
288
|
-
reply_elements?: Array<{ text?: string; type?: string }>;
|
|
289
|
-
};
|
|
290
|
-
method?: string;
|
|
291
|
-
url?: string;
|
|
292
|
-
}>(requestMock, 2, 0);
|
|
293
|
-
expect(addRequest.method).toBe("POST");
|
|
294
|
-
expect(addRequest.url).toBe("/open-apis/drive/v1/files/doc_1/new_comments");
|
|
295
|
-
expect(addRequest.data).toEqual({
|
|
296
|
-
file_type: "docx",
|
|
297
|
-
reply_elements: [{ type: "text", text: "please update this section" }],
|
|
298
|
-
anchor: { block_id: "blk_1" },
|
|
299
|
-
});
|
|
300
|
-
expect((addCommentResult.details as { comment_id?: string; success?: boolean }).success).toBe(
|
|
301
|
-
true,
|
|
302
|
-
);
|
|
303
|
-
expect((addCommentResult.details as { comment_id?: string }).comment_id).toBe("c2");
|
|
304
|
-
|
|
305
|
-
requestMock
|
|
306
|
-
.mockResolvedValueOnce({
|
|
307
|
-
code: 0,
|
|
308
|
-
data: {
|
|
309
|
-
items: [{ comment_id: "c1", is_whole: false }],
|
|
310
|
-
},
|
|
311
|
-
})
|
|
312
|
-
.mockResolvedValueOnce({
|
|
313
|
-
code: 0,
|
|
314
|
-
data: { reply_id: "r4" },
|
|
315
|
-
});
|
|
316
|
-
const replyCommentResult = await tool.execute("call-4", {
|
|
317
|
-
action: "reply_comment",
|
|
318
|
-
file_token: "doc_1",
|
|
319
|
-
file_type: "docx",
|
|
320
|
-
comment_id: "c1",
|
|
321
|
-
content: "handled",
|
|
322
|
-
});
|
|
323
|
-
const batchRequest = mockCallArg<{
|
|
324
|
-
data?: { comment_ids?: string[] };
|
|
325
|
-
method?: string;
|
|
326
|
-
url?: string;
|
|
327
|
-
}>(requestMock, 3, 0);
|
|
328
|
-
expect(batchRequest.method).toBe("POST");
|
|
329
|
-
expect(batchRequest.url).toBe(
|
|
330
|
-
"/open-apis/drive/v1/files/doc_1/comments/batch_query?file_type=docx&user_id_type=open_id",
|
|
331
|
-
);
|
|
332
|
-
expect(batchRequest.data).toEqual({ comment_ids: ["c1"] });
|
|
333
|
-
const replyRequest = mockCallArg<{
|
|
334
|
-
data?: { content?: { elements?: Array<{ text_run?: { text?: string }; type?: string }> } };
|
|
335
|
-
method?: string;
|
|
336
|
-
params?: { file_type?: string };
|
|
337
|
-
url?: string;
|
|
338
|
-
}>(requestMock, 4, 0);
|
|
339
|
-
expect(replyRequest.method).toBe("POST");
|
|
340
|
-
expect(replyRequest.url).toBe("/open-apis/drive/v1/files/doc_1/comments/c1/replies");
|
|
341
|
-
expect(replyRequest.params).toEqual({ file_type: "docx" });
|
|
342
|
-
expect(replyRequest.data).toEqual({
|
|
343
|
-
content: {
|
|
344
|
-
elements: [
|
|
345
|
-
{
|
|
346
|
-
type: "text_run",
|
|
347
|
-
text_run: {
|
|
348
|
-
text: "handled",
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
],
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
expect((replyCommentResult.details as { reply_id?: string; success?: boolean }).success).toBe(
|
|
355
|
-
true,
|
|
356
|
-
);
|
|
357
|
-
expect((replyCommentResult.details as { reply_id?: string }).reply_id).toBe("r4");
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it("defaults add_comment file_type to docx when omitted", async () => {
|
|
361
|
-
const registerTool = vi.fn();
|
|
362
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
363
|
-
registerFeishuDriveTools(
|
|
364
|
-
createDriveToolApi({
|
|
365
|
-
config: {
|
|
366
|
-
channels: {
|
|
367
|
-
feishu: {
|
|
368
|
-
enabled: true,
|
|
369
|
-
appId: "app_id",
|
|
370
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
371
|
-
tools: { drive: true },
|
|
372
|
-
},
|
|
373
|
-
},
|
|
374
|
-
},
|
|
375
|
-
registerTool,
|
|
376
|
-
}),
|
|
377
|
-
);
|
|
378
|
-
|
|
379
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
380
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
381
|
-
|
|
382
|
-
requestMock.mockResolvedValueOnce({
|
|
383
|
-
code: 0,
|
|
384
|
-
data: { comment_id: "c-default-docx" },
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
const result = await tool.execute("call-default-docx", {
|
|
388
|
-
action: "add_comment",
|
|
389
|
-
file_token: "doc_1",
|
|
390
|
-
content: "defaulted file type",
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
const request = requestCall(requestMock, 0);
|
|
394
|
-
expect(request.method).toBe("POST");
|
|
395
|
-
expect(request.url).toBe("/open-apis/drive/v1/files/doc_1/new_comments");
|
|
396
|
-
expect(request.data).toEqual({
|
|
397
|
-
file_type: "docx",
|
|
398
|
-
reply_elements: [{ type: "text", text: "defaulted file type" }],
|
|
399
|
-
});
|
|
400
|
-
expect(firstLogMessage(infoSpy)).toContain("add_comment missing file_type; defaulting to docx");
|
|
401
|
-
expect((result.details as { comment_id?: string; success?: boolean }).success).toBe(true);
|
|
402
|
-
expect((result.details as { comment_id?: string }).comment_id).toBe("c-default-docx");
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it("defaults list_comments file_type to docx when omitted", async () => {
|
|
406
|
-
const registerTool = vi.fn();
|
|
407
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
408
|
-
registerFeishuDriveTools(
|
|
409
|
-
createDriveToolApi({
|
|
410
|
-
config: {
|
|
411
|
-
channels: {
|
|
412
|
-
feishu: {
|
|
413
|
-
enabled: true,
|
|
414
|
-
appId: "app_id",
|
|
415
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
416
|
-
tools: { drive: true },
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
},
|
|
420
|
-
registerTool,
|
|
421
|
-
}),
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
425
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
426
|
-
|
|
427
|
-
requestMock.mockResolvedValueOnce({
|
|
428
|
-
code: 0,
|
|
429
|
-
data: { has_more: false, items: [] },
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
await tool.execute("call-list-default-docx", {
|
|
433
|
-
action: "list_comments",
|
|
434
|
-
file_token: "doc_1",
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
const request = requestCall(requestMock, 0);
|
|
438
|
-
expect(request.method).toBe("GET");
|
|
439
|
-
expect(request.url).toBe(
|
|
440
|
-
"/open-apis/drive/v1/files/doc_1/comments?file_type=docx&user_id_type=open_id",
|
|
441
|
-
);
|
|
442
|
-
expect(firstLogMessage(infoSpy)).toContain(
|
|
443
|
-
"list_comments missing file_type; defaulting to docx",
|
|
444
|
-
);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
it("defaults list_comment_replies file_type to docx when omitted", async () => {
|
|
448
|
-
const registerTool = vi.fn();
|
|
449
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
450
|
-
registerFeishuDriveTools(
|
|
451
|
-
createDriveToolApi({
|
|
452
|
-
config: {
|
|
453
|
-
channels: {
|
|
454
|
-
feishu: {
|
|
455
|
-
enabled: true,
|
|
456
|
-
appId: "app_id",
|
|
457
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
458
|
-
tools: { drive: true },
|
|
459
|
-
},
|
|
460
|
-
},
|
|
461
|
-
},
|
|
462
|
-
registerTool,
|
|
463
|
-
}),
|
|
464
|
-
);
|
|
465
|
-
|
|
466
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
467
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
468
|
-
|
|
469
|
-
requestMock.mockResolvedValueOnce({
|
|
470
|
-
code: 0,
|
|
471
|
-
data: { has_more: false, items: [] },
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
await tool.execute("call-replies-default-docx", {
|
|
475
|
-
action: "list_comment_replies",
|
|
476
|
-
file_token: "doc_1",
|
|
477
|
-
comment_id: "c1",
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
const request = requestCall(requestMock, 0);
|
|
481
|
-
expect(request.method).toBe("GET");
|
|
482
|
-
expect(request.url).toBe(
|
|
483
|
-
"/open-apis/drive/v1/files/doc_1/comments/c1/replies?file_type=docx&user_id_type=open_id",
|
|
484
|
-
);
|
|
485
|
-
expect(firstLogMessage(infoSpy)).toContain(
|
|
486
|
-
"list_comment_replies missing file_type; defaulting to docx",
|
|
487
|
-
);
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
it("surfaces reply_comment HTTP errors when the single supported body fails", async () => {
|
|
491
|
-
const registerTool = vi.fn();
|
|
492
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
493
|
-
registerFeishuDriveTools(
|
|
494
|
-
createDriveToolApi({
|
|
495
|
-
config: {
|
|
496
|
-
channels: {
|
|
497
|
-
feishu: {
|
|
498
|
-
enabled: true,
|
|
499
|
-
appId: "app_id",
|
|
500
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
501
|
-
tools: { drive: true },
|
|
502
|
-
},
|
|
503
|
-
},
|
|
504
|
-
},
|
|
505
|
-
registerTool,
|
|
506
|
-
}),
|
|
507
|
-
);
|
|
508
|
-
|
|
509
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
510
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
511
|
-
|
|
512
|
-
requestMock
|
|
513
|
-
.mockResolvedValueOnce({
|
|
514
|
-
code: 0,
|
|
515
|
-
data: {
|
|
516
|
-
items: [{ comment_id: "c1", is_whole: false }],
|
|
517
|
-
},
|
|
518
|
-
})
|
|
519
|
-
.mockRejectedValueOnce({
|
|
520
|
-
message: "Request failed with status code 400",
|
|
521
|
-
code: "ERR_BAD_REQUEST",
|
|
522
|
-
config: {
|
|
523
|
-
method: "post",
|
|
524
|
-
url: "https://open.feishu.cn/open-apis/drive/v1/files/doc_1/comments/c1/replies",
|
|
525
|
-
params: { file_type: "docx" },
|
|
526
|
-
},
|
|
527
|
-
response: {
|
|
528
|
-
status: 400,
|
|
529
|
-
data: {
|
|
530
|
-
code: 99992402,
|
|
531
|
-
msg: "field validation failed",
|
|
532
|
-
log_id: "log_legacy_400",
|
|
533
|
-
},
|
|
534
|
-
},
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
const replyCommentResult = await tool.execute("call-throw", {
|
|
538
|
-
action: "reply_comment",
|
|
539
|
-
file_token: "doc_1",
|
|
540
|
-
file_type: "docx",
|
|
541
|
-
comment_id: "c1",
|
|
542
|
-
content: "inserted successfully",
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
const batchRequest = requestCall(requestMock, 0);
|
|
546
|
-
expect(batchRequest.method).toBe("POST");
|
|
547
|
-
expect(batchRequest.url).toBe(
|
|
548
|
-
"/open-apis/drive/v1/files/doc_1/comments/batch_query?file_type=docx&user_id_type=open_id",
|
|
549
|
-
);
|
|
550
|
-
expect(batchRequest.data).toEqual({ comment_ids: ["c1"] });
|
|
551
|
-
const replyRequest = requestCall(requestMock, 1);
|
|
552
|
-
expect(replyRequest.method).toBe("POST");
|
|
553
|
-
expect(replyRequest.url).toBe("/open-apis/drive/v1/files/doc_1/comments/c1/replies");
|
|
554
|
-
expect(replyRequest.params).toEqual({ file_type: "docx" });
|
|
555
|
-
expect(replyRequest.data).toEqual({
|
|
556
|
-
content: {
|
|
557
|
-
elements: [
|
|
558
|
-
{
|
|
559
|
-
type: "text_run",
|
|
560
|
-
text_run: {
|
|
561
|
-
text: "inserted successfully",
|
|
562
|
-
},
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
},
|
|
566
|
-
});
|
|
567
|
-
expect(firstLogMessage(warnSpy)).toContain("replyComment threw");
|
|
568
|
-
expect((replyCommentResult.details as { error?: string }).error).toBe(
|
|
569
|
-
"Request failed with status code 400",
|
|
570
|
-
);
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
it("does not wait for ambient typing cleanup before reply_comment sends visible output", async () => {
|
|
574
|
-
const registerTool = vi.fn();
|
|
575
|
-
registerFeishuDriveTools(
|
|
576
|
-
createDriveToolApi({
|
|
577
|
-
config: {
|
|
578
|
-
channels: {
|
|
579
|
-
feishu: {
|
|
580
|
-
enabled: true,
|
|
581
|
-
appId: "app_id",
|
|
582
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
583
|
-
tools: { drive: true },
|
|
584
|
-
},
|
|
585
|
-
},
|
|
586
|
-
},
|
|
587
|
-
registerTool,
|
|
588
|
-
}),
|
|
589
|
-
);
|
|
590
|
-
|
|
591
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
592
|
-
const tool = toolFactory({
|
|
593
|
-
agentAccountId: undefined,
|
|
594
|
-
deliveryContext: {
|
|
595
|
-
channel: "feishu",
|
|
596
|
-
to: "comment:docx:doc_1:c1",
|
|
597
|
-
threadId: "reply_ambient_1",
|
|
598
|
-
},
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
requestMock
|
|
602
|
-
.mockResolvedValueOnce({
|
|
603
|
-
code: 0,
|
|
604
|
-
data: {
|
|
605
|
-
items: [{ comment_id: "c1", is_whole: false }],
|
|
606
|
-
},
|
|
607
|
-
})
|
|
608
|
-
.mockResolvedValueOnce({
|
|
609
|
-
code: 0,
|
|
610
|
-
data: { reply_id: "r6" },
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
let resolveCleanup: ((value: boolean) => void) | undefined;
|
|
614
|
-
cleanupAmbientCommentTypingReactionMock.mockImplementationOnce(
|
|
615
|
-
() =>
|
|
616
|
-
new Promise<boolean>((resolve) => {
|
|
617
|
-
resolveCleanup = resolve;
|
|
618
|
-
}),
|
|
619
|
-
);
|
|
620
|
-
|
|
621
|
-
const replyCommentPromise = tool.execute("call-ambient", {
|
|
622
|
-
action: "reply_comment",
|
|
623
|
-
content: "ambient success",
|
|
624
|
-
});
|
|
625
|
-
const status = await raceWithNextMacrotask(replyCommentPromise.then(() => "done"));
|
|
626
|
-
|
|
627
|
-
expect(status).toBe("done");
|
|
628
|
-
const batchRequest = requestCall(requestMock, 0);
|
|
629
|
-
expect(batchRequest.method).toBe("POST");
|
|
630
|
-
expect(batchRequest.url).toBe(
|
|
631
|
-
"/open-apis/drive/v1/files/doc_1/comments/batch_query?file_type=docx&user_id_type=open_id",
|
|
632
|
-
);
|
|
633
|
-
expect(batchRequest.data).toEqual({ comment_ids: ["c1"] });
|
|
634
|
-
const replyRequest = requestCall(requestMock, 1);
|
|
635
|
-
expect(replyRequest.method).toBe("POST");
|
|
636
|
-
expect(replyRequest.url).toBe("/open-apis/drive/v1/files/doc_1/comments/c1/replies");
|
|
637
|
-
expect(replyRequest.params).toEqual({ file_type: "docx" });
|
|
638
|
-
expect(replyRequest.data).toEqual({
|
|
639
|
-
content: {
|
|
640
|
-
elements: [
|
|
641
|
-
{
|
|
642
|
-
type: "text_run",
|
|
643
|
-
text_run: {
|
|
644
|
-
text: "ambient success",
|
|
645
|
-
},
|
|
646
|
-
},
|
|
647
|
-
],
|
|
648
|
-
},
|
|
649
|
-
});
|
|
650
|
-
const cleanupRequest = mockCallArg<{
|
|
651
|
-
client?: unknown;
|
|
652
|
-
deliveryContext?: { channel?: string; threadId?: string; to?: string };
|
|
653
|
-
}>(cleanupAmbientCommentTypingReactionMock, 0, 0);
|
|
654
|
-
if (!cleanupRequest.client) {
|
|
655
|
-
throw new Error("Expected cleanup request client");
|
|
656
|
-
}
|
|
657
|
-
expect(cleanupRequest.deliveryContext).toEqual({
|
|
658
|
-
channel: "feishu",
|
|
659
|
-
to: "comment:docx:doc_1:c1",
|
|
660
|
-
threadId: "reply_ambient_1",
|
|
661
|
-
});
|
|
662
|
-
const replyCommentResult = await replyCommentPromise;
|
|
663
|
-
expect((replyCommentResult.details as { reply_id?: string; success?: boolean }).success).toBe(
|
|
664
|
-
true,
|
|
665
|
-
);
|
|
666
|
-
expect((replyCommentResult.details as { reply_id?: string }).reply_id).toBe("r6");
|
|
667
|
-
|
|
668
|
-
resolveCleanup?.(false);
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
it("does not wait for ambient typing cleanup before add_comment sends visible output", async () => {
|
|
672
|
-
const registerTool = vi.fn();
|
|
673
|
-
registerFeishuDriveTools(
|
|
674
|
-
createDriveToolApi({
|
|
675
|
-
config: {
|
|
676
|
-
channels: {
|
|
677
|
-
feishu: {
|
|
678
|
-
enabled: true,
|
|
679
|
-
appId: "app_id",
|
|
680
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
681
|
-
tools: { drive: true },
|
|
682
|
-
},
|
|
683
|
-
},
|
|
684
|
-
},
|
|
685
|
-
registerTool,
|
|
686
|
-
}),
|
|
687
|
-
);
|
|
688
|
-
|
|
689
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
690
|
-
const tool = toolFactory({
|
|
691
|
-
agentAccountId: undefined,
|
|
692
|
-
deliveryContext: {
|
|
693
|
-
channel: "feishu",
|
|
694
|
-
to: "comment:docx:doc_1:c1",
|
|
695
|
-
threadId: "reply_ambient_1",
|
|
696
|
-
},
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
requestMock.mockResolvedValueOnce({
|
|
700
|
-
code: 0,
|
|
701
|
-
data: { comment_id: "c_add" },
|
|
702
|
-
});
|
|
703
|
-
|
|
704
|
-
let resolveCleanup: ((value: boolean) => void) | undefined;
|
|
705
|
-
cleanupAmbientCommentTypingReactionMock.mockImplementationOnce(
|
|
706
|
-
() =>
|
|
707
|
-
new Promise<boolean>((resolve) => {
|
|
708
|
-
resolveCleanup = resolve;
|
|
709
|
-
}),
|
|
710
|
-
);
|
|
711
|
-
|
|
712
|
-
const addCommentPromise = tool.execute("call-add-ambient", {
|
|
713
|
-
action: "add_comment",
|
|
714
|
-
content: "ambient top-level comment",
|
|
715
|
-
});
|
|
716
|
-
const status = await raceWithNextMacrotask(addCommentPromise.then(() => "done"));
|
|
717
|
-
|
|
718
|
-
expect(status).toBe("done");
|
|
719
|
-
const request = requestCall(requestMock, 0);
|
|
720
|
-
expect(request.method).toBe("POST");
|
|
721
|
-
expect(request.url).toBe("/open-apis/drive/v1/files/doc_1/new_comments");
|
|
722
|
-
expect(request.data).toEqual({
|
|
723
|
-
file_type: "docx",
|
|
724
|
-
reply_elements: [{ type: "text", text: "ambient top-level comment" }],
|
|
725
|
-
});
|
|
726
|
-
const cleanupRequest = mockCallArg<{
|
|
727
|
-
client?: unknown;
|
|
728
|
-
deliveryContext?: { channel?: string; threadId?: string; to?: string };
|
|
729
|
-
}>(cleanupAmbientCommentTypingReactionMock, 0, 0);
|
|
730
|
-
if (!cleanupRequest.client) {
|
|
731
|
-
throw new Error("Expected cleanup request client");
|
|
732
|
-
}
|
|
733
|
-
expect(cleanupRequest.deliveryContext).toEqual({
|
|
734
|
-
channel: "feishu",
|
|
735
|
-
to: "comment:docx:doc_1:c1",
|
|
736
|
-
threadId: "reply_ambient_1",
|
|
737
|
-
});
|
|
738
|
-
const addCommentResult = await addCommentPromise;
|
|
739
|
-
expect((addCommentResult.details as { comment_id?: string; success?: boolean }).success).toBe(
|
|
740
|
-
true,
|
|
741
|
-
);
|
|
742
|
-
expect((addCommentResult.details as { comment_id?: string }).comment_id).toBe("c_add");
|
|
743
|
-
|
|
744
|
-
resolveCleanup?.(false);
|
|
745
|
-
});
|
|
746
|
-
|
|
747
|
-
it("does not inherit non-doc ambient file types for add_comment", async () => {
|
|
748
|
-
const registerTool = vi.fn();
|
|
749
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
750
|
-
registerFeishuDriveTools(
|
|
751
|
-
createDriveToolApi({
|
|
752
|
-
config: {
|
|
753
|
-
channels: {
|
|
754
|
-
feishu: {
|
|
755
|
-
enabled: true,
|
|
756
|
-
appId: "app_id",
|
|
757
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
758
|
-
tools: { drive: true },
|
|
759
|
-
},
|
|
760
|
-
},
|
|
761
|
-
},
|
|
762
|
-
registerTool,
|
|
763
|
-
}),
|
|
764
|
-
);
|
|
765
|
-
|
|
766
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
767
|
-
const tool = toolFactory({
|
|
768
|
-
agentAccountId: undefined,
|
|
769
|
-
deliveryContext: {
|
|
770
|
-
channel: "feishu",
|
|
771
|
-
to: "comment:sheet:sheet_1:c1",
|
|
772
|
-
},
|
|
773
|
-
});
|
|
774
|
-
|
|
775
|
-
requestMock.mockResolvedValueOnce({
|
|
776
|
-
code: 0,
|
|
777
|
-
data: { comment_id: "c-add-docx" },
|
|
778
|
-
});
|
|
779
|
-
|
|
780
|
-
const result = await tool.execute("call-add-ignore-sheet-ambient", {
|
|
781
|
-
action: "add_comment",
|
|
782
|
-
file_token: "doc_1",
|
|
783
|
-
content: "default add comment",
|
|
784
|
-
});
|
|
785
|
-
|
|
786
|
-
const request = requestCall(requestMock, 0);
|
|
787
|
-
expect(request.method).toBe("POST");
|
|
788
|
-
expect(request.url).toBe("/open-apis/drive/v1/files/doc_1/new_comments");
|
|
789
|
-
expect(request.data).toEqual({
|
|
790
|
-
file_type: "docx",
|
|
791
|
-
reply_elements: [{ type: "text", text: "default add comment" }],
|
|
792
|
-
});
|
|
793
|
-
expect(firstLogMessage(infoSpy)).toContain("add_comment missing file_type; defaulting to docx");
|
|
794
|
-
expect((result.details as { comment_id?: string; success?: boolean }).success).toBe(true);
|
|
795
|
-
expect((result.details as { comment_id?: string }).comment_id).toBe("c-add-docx");
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
it("defaults reply_comment file_type to docx when omitted", async () => {
|
|
799
|
-
const registerTool = vi.fn();
|
|
800
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
801
|
-
registerFeishuDriveTools(
|
|
802
|
-
createDriveToolApi({
|
|
803
|
-
config: {
|
|
804
|
-
channels: {
|
|
805
|
-
feishu: {
|
|
806
|
-
enabled: true,
|
|
807
|
-
appId: "app_id",
|
|
808
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
809
|
-
tools: { drive: true },
|
|
810
|
-
},
|
|
811
|
-
},
|
|
812
|
-
},
|
|
813
|
-
registerTool,
|
|
814
|
-
}),
|
|
815
|
-
);
|
|
816
|
-
|
|
817
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
818
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
819
|
-
|
|
820
|
-
requestMock
|
|
821
|
-
.mockResolvedValueOnce({
|
|
822
|
-
code: 0,
|
|
823
|
-
data: {
|
|
824
|
-
items: [{ comment_id: "c1", is_whole: false }],
|
|
825
|
-
},
|
|
826
|
-
})
|
|
827
|
-
.mockResolvedValueOnce({
|
|
828
|
-
code: 0,
|
|
829
|
-
data: { reply_id: "r-default-docx" },
|
|
830
|
-
});
|
|
831
|
-
|
|
832
|
-
const result = await tool.execute("call-reply-default-docx", {
|
|
833
|
-
action: "reply_comment",
|
|
834
|
-
file_token: "doc_1",
|
|
835
|
-
comment_id: "c1",
|
|
836
|
-
content: "default reply docx",
|
|
837
|
-
});
|
|
838
|
-
|
|
839
|
-
expectRequestCall(requestMock, 0, {
|
|
840
|
-
method: "POST",
|
|
841
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/batch_query?file_type=docx&user_id_type=open_id",
|
|
842
|
-
data: { comment_ids: ["c1"] },
|
|
843
|
-
});
|
|
844
|
-
expectRequestCall(requestMock, 1, {
|
|
845
|
-
method: "POST",
|
|
846
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/c1/replies",
|
|
847
|
-
params: { file_type: "docx" },
|
|
848
|
-
data: {
|
|
849
|
-
content: {
|
|
850
|
-
elements: [
|
|
851
|
-
{
|
|
852
|
-
type: "text_run",
|
|
853
|
-
text_run: {
|
|
854
|
-
text: "default reply docx",
|
|
855
|
-
},
|
|
856
|
-
},
|
|
857
|
-
],
|
|
858
|
-
},
|
|
859
|
-
},
|
|
860
|
-
});
|
|
861
|
-
expect(firstLogMessage(infoSpy)).toContain(
|
|
862
|
-
"reply_comment missing file_type; defaulting to docx",
|
|
863
|
-
);
|
|
864
|
-
expect((result.details as { reply_id?: string; success?: boolean }).success).toBe(true);
|
|
865
|
-
expect((result.details as { reply_id?: string }).reply_id).toBe("r-default-docx");
|
|
866
|
-
});
|
|
867
|
-
|
|
868
|
-
it("routes whole-document reply_comment requests through add_comment compatibility", async () => {
|
|
869
|
-
const registerTool = vi.fn();
|
|
870
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
871
|
-
registerFeishuDriveTools(
|
|
872
|
-
createDriveToolApi({
|
|
873
|
-
config: {
|
|
874
|
-
channels: {
|
|
875
|
-
feishu: {
|
|
876
|
-
enabled: true,
|
|
877
|
-
appId: "app_id",
|
|
878
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
879
|
-
tools: { drive: true },
|
|
880
|
-
},
|
|
881
|
-
},
|
|
882
|
-
},
|
|
883
|
-
registerTool,
|
|
884
|
-
}),
|
|
885
|
-
);
|
|
886
|
-
|
|
887
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
888
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
889
|
-
|
|
890
|
-
requestMock
|
|
891
|
-
.mockResolvedValueOnce({
|
|
892
|
-
code: 0,
|
|
893
|
-
data: {
|
|
894
|
-
items: [{ comment_id: "c1", is_whole: true }],
|
|
895
|
-
},
|
|
896
|
-
})
|
|
897
|
-
.mockResolvedValueOnce({
|
|
898
|
-
code: 0,
|
|
899
|
-
data: { comment_id: "c2" },
|
|
900
|
-
});
|
|
901
|
-
|
|
902
|
-
const result = await tool.execute("call-whole", {
|
|
903
|
-
action: "reply_comment",
|
|
904
|
-
file_token: "doc_1",
|
|
905
|
-
file_type: "docx",
|
|
906
|
-
comment_id: "c1",
|
|
907
|
-
content: "whole comment follow-up",
|
|
908
|
-
});
|
|
909
|
-
|
|
910
|
-
expectRequestCall(requestMock, 0, {
|
|
911
|
-
method: "POST",
|
|
912
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/batch_query?file_type=docx&user_id_type=open_id",
|
|
913
|
-
data: { comment_ids: ["c1"] },
|
|
914
|
-
});
|
|
915
|
-
expectRequestCall(requestMock, 1, {
|
|
916
|
-
method: "POST",
|
|
917
|
-
url: "/open-apis/drive/v1/files/doc_1/new_comments",
|
|
918
|
-
data: {
|
|
919
|
-
file_type: "docx",
|
|
920
|
-
reply_elements: [{ type: "text", text: "whole comment follow-up" }],
|
|
921
|
-
},
|
|
922
|
-
});
|
|
923
|
-
expect(firstLogMessage(infoSpy)).toContain("whole-comment compatibility path");
|
|
924
|
-
const details = result.details as {
|
|
925
|
-
comment_id?: string;
|
|
926
|
-
delivery_mode?: string;
|
|
927
|
-
success?: boolean;
|
|
928
|
-
};
|
|
929
|
-
expect(details.success).toBe(true);
|
|
930
|
-
expect(details.comment_id).toBe("c2");
|
|
931
|
-
expect(details.delivery_mode).toBe("add_comment");
|
|
932
|
-
});
|
|
933
|
-
|
|
934
|
-
it("continues with reply_comment when comment metadata preflight fails", async () => {
|
|
935
|
-
const registerTool = vi.fn();
|
|
936
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
937
|
-
registerFeishuDriveTools(
|
|
938
|
-
createDriveToolApi({
|
|
939
|
-
config: {
|
|
940
|
-
channels: {
|
|
941
|
-
feishu: {
|
|
942
|
-
enabled: true,
|
|
943
|
-
appId: "app_id",
|
|
944
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
945
|
-
tools: { drive: true },
|
|
946
|
-
},
|
|
947
|
-
},
|
|
948
|
-
},
|
|
949
|
-
registerTool,
|
|
950
|
-
}),
|
|
951
|
-
);
|
|
952
|
-
|
|
953
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
954
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
955
|
-
|
|
956
|
-
requestMock.mockRejectedValueOnce(new Error("preflight unavailable")).mockResolvedValueOnce({
|
|
957
|
-
code: 0,
|
|
958
|
-
data: { reply_id: "r-preflight-fallback" },
|
|
959
|
-
});
|
|
960
|
-
|
|
961
|
-
const result = await tool.execute("call-preflight-fallback", {
|
|
962
|
-
action: "reply_comment",
|
|
963
|
-
file_token: "doc_1",
|
|
964
|
-
file_type: "docx",
|
|
965
|
-
comment_id: "c1",
|
|
966
|
-
content: "preflight fallback reply",
|
|
967
|
-
});
|
|
968
|
-
|
|
969
|
-
expectRequestCall(requestMock, 0, {
|
|
970
|
-
method: "POST",
|
|
971
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/batch_query?file_type=docx&user_id_type=open_id",
|
|
972
|
-
data: { comment_ids: ["c1"] },
|
|
973
|
-
});
|
|
974
|
-
expectRequestCall(requestMock, 1, {
|
|
975
|
-
method: "POST",
|
|
976
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/c1/replies",
|
|
977
|
-
params: { file_type: "docx" },
|
|
978
|
-
data: {
|
|
979
|
-
content: {
|
|
980
|
-
elements: [
|
|
981
|
-
{
|
|
982
|
-
type: "text_run",
|
|
983
|
-
text_run: {
|
|
984
|
-
text: "preflight fallback reply",
|
|
985
|
-
},
|
|
986
|
-
},
|
|
987
|
-
],
|
|
988
|
-
},
|
|
989
|
-
},
|
|
990
|
-
});
|
|
991
|
-
expect(firstLogMessage(warnSpy)).toContain("comment metadata preflight failed");
|
|
992
|
-
const details = result.details as {
|
|
993
|
-
delivery_mode?: string;
|
|
994
|
-
reply_id?: string;
|
|
995
|
-
success?: boolean;
|
|
996
|
-
};
|
|
997
|
-
expect(details.success).toBe(true);
|
|
998
|
-
expect(details.reply_id).toBe("r-preflight-fallback");
|
|
999
|
-
expect(details.delivery_mode).toBe("reply_comment");
|
|
1000
|
-
});
|
|
1001
|
-
|
|
1002
|
-
it("continues with reply_comment when batch_query returns no exact comment match", async () => {
|
|
1003
|
-
const registerTool = vi.fn();
|
|
1004
|
-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
1005
|
-
registerFeishuDriveTools(
|
|
1006
|
-
createDriveToolApi({
|
|
1007
|
-
config: {
|
|
1008
|
-
channels: {
|
|
1009
|
-
feishu: {
|
|
1010
|
-
enabled: true,
|
|
1011
|
-
appId: "app_id",
|
|
1012
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
1013
|
-
tools: { drive: true },
|
|
1014
|
-
},
|
|
1015
|
-
},
|
|
1016
|
-
},
|
|
1017
|
-
registerTool,
|
|
1018
|
-
}),
|
|
1019
|
-
);
|
|
1020
|
-
|
|
1021
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
1022
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
1023
|
-
|
|
1024
|
-
requestMock
|
|
1025
|
-
.mockResolvedValueOnce({
|
|
1026
|
-
code: 0,
|
|
1027
|
-
data: {
|
|
1028
|
-
items: [{ comment_id: "different_comment", is_whole: true }],
|
|
1029
|
-
},
|
|
1030
|
-
})
|
|
1031
|
-
.mockResolvedValueOnce({
|
|
1032
|
-
code: 0,
|
|
1033
|
-
data: { reply_id: "r-no-exact-match" },
|
|
1034
|
-
});
|
|
1035
|
-
|
|
1036
|
-
const result = await tool.execute("call-preflight-no-exact-match", {
|
|
1037
|
-
action: "reply_comment",
|
|
1038
|
-
file_token: "doc_1",
|
|
1039
|
-
file_type: "docx",
|
|
1040
|
-
comment_id: "c1",
|
|
1041
|
-
content: "fallback on exact match miss",
|
|
1042
|
-
});
|
|
1043
|
-
|
|
1044
|
-
expectRequestCall(requestMock, 0, {
|
|
1045
|
-
method: "POST",
|
|
1046
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/batch_query?file_type=docx&user_id_type=open_id",
|
|
1047
|
-
data: { comment_ids: ["c1"] },
|
|
1048
|
-
});
|
|
1049
|
-
expectRequestCall(requestMock, 1, {
|
|
1050
|
-
method: "POST",
|
|
1051
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/c1/replies",
|
|
1052
|
-
params: { file_type: "docx" },
|
|
1053
|
-
data: {
|
|
1054
|
-
content: {
|
|
1055
|
-
elements: [
|
|
1056
|
-
{
|
|
1057
|
-
type: "text_run",
|
|
1058
|
-
text_run: {
|
|
1059
|
-
text: "fallback on exact match miss",
|
|
1060
|
-
},
|
|
1061
|
-
},
|
|
1062
|
-
],
|
|
1063
|
-
},
|
|
1064
|
-
},
|
|
1065
|
-
});
|
|
1066
|
-
expect(
|
|
1067
|
-
warnSpy.mock.calls.some((call) =>
|
|
1068
|
-
String(call[0]).includes("whole-comment compatibility path"),
|
|
1069
|
-
),
|
|
1070
|
-
).toBe(false);
|
|
1071
|
-
const details = result.details as {
|
|
1072
|
-
delivery_mode?: string;
|
|
1073
|
-
reply_id?: string;
|
|
1074
|
-
success?: boolean;
|
|
1075
|
-
};
|
|
1076
|
-
expect(details.success).toBe(true);
|
|
1077
|
-
expect(details.reply_id).toBe("r-no-exact-match");
|
|
1078
|
-
expect(details.delivery_mode).toBe("reply_comment");
|
|
1079
|
-
});
|
|
1080
|
-
|
|
1081
|
-
it("falls back to add_comment when reply_comment returns compatibility code 1069302 even without is_whole metadata", async () => {
|
|
1082
|
-
const registerTool = vi.fn();
|
|
1083
|
-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
|
1084
|
-
registerFeishuDriveTools(
|
|
1085
|
-
createDriveToolApi({
|
|
1086
|
-
config: {
|
|
1087
|
-
channels: {
|
|
1088
|
-
feishu: {
|
|
1089
|
-
enabled: true,
|
|
1090
|
-
appId: "app_id",
|
|
1091
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
1092
|
-
tools: { drive: true },
|
|
1093
|
-
},
|
|
1094
|
-
},
|
|
1095
|
-
},
|
|
1096
|
-
registerTool,
|
|
1097
|
-
}),
|
|
1098
|
-
);
|
|
1099
|
-
|
|
1100
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
1101
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
1102
|
-
|
|
1103
|
-
requestMock
|
|
1104
|
-
.mockResolvedValueOnce({
|
|
1105
|
-
code: 0,
|
|
1106
|
-
data: {
|
|
1107
|
-
items: [{ comment_id: "c1", is_whole: false }],
|
|
1108
|
-
},
|
|
1109
|
-
})
|
|
1110
|
-
.mockRejectedValueOnce({
|
|
1111
|
-
message: "Request failed with status code 400",
|
|
1112
|
-
code: "ERR_BAD_REQUEST",
|
|
1113
|
-
config: {
|
|
1114
|
-
method: "post",
|
|
1115
|
-
url: "https://open.feishu.cn/open-apis/drive/v1/files/doc_1/comments/c1/replies",
|
|
1116
|
-
params: { file_type: "docx" },
|
|
1117
|
-
},
|
|
1118
|
-
response: {
|
|
1119
|
-
status: 400,
|
|
1120
|
-
data: {
|
|
1121
|
-
code: 1069302,
|
|
1122
|
-
msg: "param error",
|
|
1123
|
-
log_id: "log_reply_forbidden",
|
|
1124
|
-
},
|
|
1125
|
-
},
|
|
1126
|
-
})
|
|
1127
|
-
.mockResolvedValueOnce({
|
|
1128
|
-
code: 0,
|
|
1129
|
-
data: { comment_id: "c3" },
|
|
1130
|
-
});
|
|
1131
|
-
|
|
1132
|
-
const result = await tool.execute("call-reply-forbidden", {
|
|
1133
|
-
action: "reply_comment",
|
|
1134
|
-
file_token: "doc_1",
|
|
1135
|
-
file_type: "docx",
|
|
1136
|
-
comment_id: "c1",
|
|
1137
|
-
content: "compat follow-up",
|
|
1138
|
-
});
|
|
1139
|
-
|
|
1140
|
-
expectRequestCall(requestMock, 2, {
|
|
1141
|
-
method: "POST",
|
|
1142
|
-
url: "/open-apis/drive/v1/files/doc_1/new_comments",
|
|
1143
|
-
data: {
|
|
1144
|
-
file_type: "docx",
|
|
1145
|
-
reply_elements: [{ type: "text", text: "compat follow-up" }],
|
|
1146
|
-
},
|
|
1147
|
-
});
|
|
1148
|
-
expect(firstLogMessage(infoSpy)).toContain("reply-not-allowed compatibility path");
|
|
1149
|
-
const details = result.details as {
|
|
1150
|
-
comment_id?: string;
|
|
1151
|
-
delivery_mode?: string;
|
|
1152
|
-
success?: boolean;
|
|
1153
|
-
};
|
|
1154
|
-
expect(details.success).toBe(true);
|
|
1155
|
-
expect(details.comment_id).toBe("c3");
|
|
1156
|
-
expect(details.delivery_mode).toBe("add_comment");
|
|
1157
|
-
});
|
|
1158
|
-
|
|
1159
|
-
it("clamps comment list page sizes to the Feishu API maximum", async () => {
|
|
1160
|
-
const registerTool = vi.fn();
|
|
1161
|
-
registerFeishuDriveTools(
|
|
1162
|
-
createDriveToolApi({
|
|
1163
|
-
config: {
|
|
1164
|
-
channels: {
|
|
1165
|
-
feishu: {
|
|
1166
|
-
enabled: true,
|
|
1167
|
-
appId: "app_id",
|
|
1168
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
1169
|
-
tools: { drive: true },
|
|
1170
|
-
},
|
|
1171
|
-
},
|
|
1172
|
-
},
|
|
1173
|
-
registerTool,
|
|
1174
|
-
}),
|
|
1175
|
-
);
|
|
1176
|
-
|
|
1177
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
1178
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
1179
|
-
|
|
1180
|
-
requestMock.mockResolvedValueOnce({ code: 0, data: { has_more: false, items: [] } });
|
|
1181
|
-
await tool.execute("call-list", {
|
|
1182
|
-
action: "list_comments",
|
|
1183
|
-
file_token: "doc_1",
|
|
1184
|
-
file_type: "docx",
|
|
1185
|
-
page_size: 200,
|
|
1186
|
-
});
|
|
1187
|
-
expectRequestCall(requestMock, 0, {
|
|
1188
|
-
method: "GET",
|
|
1189
|
-
url: "/open-apis/drive/v1/files/doc_1/comments?file_type=docx&page_size=100&user_id_type=open_id",
|
|
1190
|
-
});
|
|
1191
|
-
|
|
1192
|
-
requestMock.mockResolvedValueOnce({ code: 0, data: { has_more: false, items: [] } });
|
|
1193
|
-
await tool.execute("call-replies", {
|
|
1194
|
-
action: "list_comment_replies",
|
|
1195
|
-
file_token: "doc_1",
|
|
1196
|
-
file_type: "docx",
|
|
1197
|
-
comment_id: "c1",
|
|
1198
|
-
page_size: 200,
|
|
1199
|
-
});
|
|
1200
|
-
expectRequestCall(requestMock, 1, {
|
|
1201
|
-
method: "GET",
|
|
1202
|
-
url: "/open-apis/drive/v1/files/doc_1/comments/c1/replies?file_type=docx&page_size=100&user_id_type=open_id",
|
|
1203
|
-
});
|
|
1204
|
-
});
|
|
1205
|
-
|
|
1206
|
-
it("rejects block-scoped comments for non-docx files", async () => {
|
|
1207
|
-
const registerTool = vi.fn();
|
|
1208
|
-
registerFeishuDriveTools(
|
|
1209
|
-
createDriveToolApi({
|
|
1210
|
-
config: {
|
|
1211
|
-
channels: {
|
|
1212
|
-
feishu: {
|
|
1213
|
-
enabled: true,
|
|
1214
|
-
appId: "app_id",
|
|
1215
|
-
appSecret: "app_secret", // pragma: allowlist secret
|
|
1216
|
-
tools: { drive: true },
|
|
1217
|
-
},
|
|
1218
|
-
},
|
|
1219
|
-
},
|
|
1220
|
-
registerTool,
|
|
1221
|
-
}),
|
|
1222
|
-
);
|
|
1223
|
-
|
|
1224
|
-
const toolFactory = firstToolFactory(registerTool);
|
|
1225
|
-
const tool = toolFactory({ agentAccountId: undefined });
|
|
1226
|
-
const result = await tool.execute("call-5", {
|
|
1227
|
-
action: "add_comment",
|
|
1228
|
-
file_token: "doc_1",
|
|
1229
|
-
file_type: "doc",
|
|
1230
|
-
block_id: "blk_1",
|
|
1231
|
-
content: "invalid",
|
|
1232
|
-
});
|
|
1233
|
-
expect((result.details as { error?: string }).error).toBe(
|
|
1234
|
-
"block_id is only supported for docx comments",
|
|
1235
|
-
);
|
|
1236
|
-
});
|
|
1237
|
-
});
|