@openclaw-cn/feishu 0.1.8

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 (167) hide show
  1. package/README.md +86 -0
  2. package/dist/index.d.ts +37 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +49 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/src/accounts.d.ts +33 -0
  7. package/dist/src/accounts.d.ts.map +1 -0
  8. package/dist/src/accounts.js +110 -0
  9. package/dist/src/accounts.js.map +1 -0
  10. package/dist/src/bitable.d.ts +211 -0
  11. package/dist/src/bitable.d.ts.map +1 -0
  12. package/dist/src/bitable.js +721 -0
  13. package/dist/src/bitable.js.map +1 -0
  14. package/dist/src/bot.d.ts +53 -0
  15. package/dist/src/bot.d.ts.map +1 -0
  16. package/dist/src/bot.js +853 -0
  17. package/dist/src/bot.js.map +1 -0
  18. package/dist/src/calendar-schema.d.ts +18 -0
  19. package/dist/src/calendar-schema.d.ts.map +1 -0
  20. package/dist/src/calendar-schema.js +52 -0
  21. package/dist/src/calendar-schema.js.map +1 -0
  22. package/dist/src/calendar.d.ts +441 -0
  23. package/dist/src/calendar.d.ts.map +1 -0
  24. package/dist/src/calendar.js +257 -0
  25. package/dist/src/calendar.js.map +1 -0
  26. package/dist/src/channel.d.ts +4 -0
  27. package/dist/src/channel.d.ts.map +1 -0
  28. package/dist/src/channel.js +331 -0
  29. package/dist/src/channel.js.map +1 -0
  30. package/dist/src/client.d.ts +35 -0
  31. package/dist/src/client.d.ts.map +1 -0
  32. package/dist/src/client.js +86 -0
  33. package/dist/src/client.js.map +1 -0
  34. package/dist/src/config-schema.d.ts +176 -0
  35. package/dist/src/config-schema.d.ts.map +1 -0
  36. package/dist/src/config-schema.js +56 -0
  37. package/dist/src/config-schema.js.map +1 -0
  38. package/dist/src/directory.d.ts +36 -0
  39. package/dist/src/directory.d.ts.map +1 -0
  40. package/dist/src/directory.js +129 -0
  41. package/dist/src/directory.js.map +1 -0
  42. package/dist/src/doc-schema.d.ts +37 -0
  43. package/dist/src/doc-schema.d.ts.map +1 -0
  44. package/dist/src/doc-schema.js +51 -0
  45. package/dist/src/doc-schema.js.map +1 -0
  46. package/dist/src/docx.d.ts +3 -0
  47. package/dist/src/docx.d.ts.map +1 -0
  48. package/dist/src/docx.js +608 -0
  49. package/dist/src/docx.js.map +1 -0
  50. package/dist/src/drive-schema.d.ts +24 -0
  51. package/dist/src/drive-schema.d.ts.map +1 -0
  52. package/dist/src/drive-schema.js +39 -0
  53. package/dist/src/drive-schema.js.map +1 -0
  54. package/dist/src/drive.d.ts +3 -0
  55. package/dist/src/drive.d.ts.map +1 -0
  56. package/dist/src/drive.js +181 -0
  57. package/dist/src/drive.js.map +1 -0
  58. package/dist/src/dynamic-agent.d.ts +19 -0
  59. package/dist/src/dynamic-agent.d.ts.map +1 -0
  60. package/dist/src/dynamic-agent.js +91 -0
  61. package/dist/src/dynamic-agent.js.map +1 -0
  62. package/dist/src/im-schema.d.ts +38 -0
  63. package/dist/src/im-schema.d.ts.map +1 -0
  64. package/dist/src/im-schema.js +73 -0
  65. package/dist/src/im-schema.js.map +1 -0
  66. package/dist/src/im.d.ts +70 -0
  67. package/dist/src/im.d.ts.map +1 -0
  68. package/dist/src/im.js +328 -0
  69. package/dist/src/im.js.map +1 -0
  70. package/dist/src/media.d.ts +99 -0
  71. package/dist/src/media.d.ts.map +1 -0
  72. package/dist/src/media.js +454 -0
  73. package/dist/src/media.js.map +1 -0
  74. package/dist/src/mention.d.ts +49 -0
  75. package/dist/src/mention.d.ts.map +1 -0
  76. package/dist/src/mention.js +99 -0
  77. package/dist/src/mention.js.map +1 -0
  78. package/dist/src/monitor.d.ts +16 -0
  79. package/dist/src/monitor.d.ts.map +1 -0
  80. package/dist/src/monitor.js +288 -0
  81. package/dist/src/monitor.js.map +1 -0
  82. package/dist/src/onboarding.d.ts +3 -0
  83. package/dist/src/onboarding.d.ts.map +1 -0
  84. package/dist/src/onboarding.js +119 -0
  85. package/dist/src/onboarding.js.map +1 -0
  86. package/dist/src/outbound.d.ts +3 -0
  87. package/dist/src/outbound.d.ts.map +1 -0
  88. package/dist/src/outbound.js +53 -0
  89. package/dist/src/outbound.js.map +1 -0
  90. package/dist/src/perm-schema.d.ts +21 -0
  91. package/dist/src/perm-schema.d.ts.map +1 -0
  92. package/dist/src/perm-schema.js +47 -0
  93. package/dist/src/perm-schema.js.map +1 -0
  94. package/dist/src/perm.d.ts +14 -0
  95. package/dist/src/perm.d.ts.map +1 -0
  96. package/dist/src/perm.js +106 -0
  97. package/dist/src/perm.js.map +1 -0
  98. package/dist/src/policy.d.ts +28 -0
  99. package/dist/src/policy.d.ts.map +1 -0
  100. package/dist/src/policy.js +61 -0
  101. package/dist/src/policy.js.map +1 -0
  102. package/dist/src/probe.d.ts +4 -0
  103. package/dist/src/probe.d.ts.map +1 -0
  104. package/dist/src/probe.js +41 -0
  105. package/dist/src/probe.js.map +1 -0
  106. package/dist/src/reactions.d.ts +66 -0
  107. package/dist/src/reactions.d.ts.map +1 -0
  108. package/dist/src/reactions.js +104 -0
  109. package/dist/src/reactions.js.map +1 -0
  110. package/dist/src/reply-dispatcher.d.ts +41 -0
  111. package/dist/src/reply-dispatcher.d.ts.map +1 -0
  112. package/dist/src/reply-dispatcher.js +249 -0
  113. package/dist/src/reply-dispatcher.js.map +1 -0
  114. package/dist/src/runtime.d.ts +4 -0
  115. package/dist/src/runtime.d.ts.map +1 -0
  116. package/dist/src/runtime.js +11 -0
  117. package/dist/src/runtime.js.map +1 -0
  118. package/dist/src/send.d.ts +76 -0
  119. package/dist/src/send.d.ts.map +1 -0
  120. package/dist/src/send.js +250 -0
  121. package/dist/src/send.js.map +1 -0
  122. package/dist/src/sheets-schema.d.ts +12 -0
  123. package/dist/src/sheets-schema.d.ts.map +1 -0
  124. package/dist/src/sheets-schema.js +35 -0
  125. package/dist/src/sheets-schema.js.map +1 -0
  126. package/dist/src/sheets.d.ts +45 -0
  127. package/dist/src/sheets.d.ts.map +1 -0
  128. package/dist/src/sheets.js +197 -0
  129. package/dist/src/sheets.js.map +1 -0
  130. package/dist/src/streaming-card.d.ts +29 -0
  131. package/dist/src/streaming-card.d.ts.map +1 -0
  132. package/dist/src/streaming-card.js +192 -0
  133. package/dist/src/streaming-card.js.map +1 -0
  134. package/dist/src/targets.d.ts +7 -0
  135. package/dist/src/targets.d.ts.map +1 -0
  136. package/dist/src/targets.js +70 -0
  137. package/dist/src/targets.js.map +1 -0
  138. package/dist/src/task-schema.d.ts +19 -0
  139. package/dist/src/task-schema.d.ts.map +1 -0
  140. package/dist/src/task-schema.js +54 -0
  141. package/dist/src/task-schema.js.map +1 -0
  142. package/dist/src/task.d.ts +1193 -0
  143. package/dist/src/task.d.ts.map +1 -0
  144. package/dist/src/task.js +274 -0
  145. package/dist/src/task.js.map +1 -0
  146. package/dist/src/tools-config.d.ts +12 -0
  147. package/dist/src/tools-config.d.ts.map +1 -0
  148. package/dist/src/tools-config.js +24 -0
  149. package/dist/src/tools-config.js.map +1 -0
  150. package/dist/src/types.d.ts +74 -0
  151. package/dist/src/types.d.ts.map +1 -0
  152. package/dist/src/types.js +2 -0
  153. package/dist/src/types.js.map +1 -0
  154. package/dist/src/typing.d.ts +22 -0
  155. package/dist/src/typing.d.ts.map +1 -0
  156. package/dist/src/typing.js +60 -0
  157. package/dist/src/typing.js.map +1 -0
  158. package/dist/src/wiki-schema.d.ts +34 -0
  159. package/dist/src/wiki-schema.d.ts.map +1 -0
  160. package/dist/src/wiki-schema.js +43 -0
  161. package/dist/src/wiki-schema.js.map +1 -0
  162. package/dist/src/wiki.d.ts +3 -0
  163. package/dist/src/wiki.d.ts.map +1 -0
  164. package/dist/src/wiki.js +176 -0
  165. package/dist/src/wiki.js.map +1 -0
  166. package/openclaw.plugin.json +9 -0
  167. package/package.json +79 -0
@@ -0,0 +1,721 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { createFeishuClient } from "./client.js";
3
+ // ============ Helpers ============
4
+ function json(data) {
5
+ return {
6
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
7
+ details: data,
8
+ };
9
+ }
10
+ /** Field type ID to human-readable name */
11
+ const FIELD_TYPE_NAMES = {
12
+ 1: "Text",
13
+ 2: "Number",
14
+ 3: "SingleSelect",
15
+ 4: "MultiSelect",
16
+ 5: "DateTime",
17
+ 7: "Checkbox",
18
+ 11: "User",
19
+ 13: "Phone",
20
+ 15: "URL",
21
+ 17: "Attachment",
22
+ 18: "SingleLink",
23
+ 19: "Lookup",
24
+ 20: "Formula",
25
+ 21: "DuplexLink",
26
+ 22: "Location",
27
+ 23: "GroupChat",
28
+ 1001: "CreatedTime",
29
+ 1002: "ModifiedTime",
30
+ 1003: "CreatedUser",
31
+ 1004: "ModifiedUser",
32
+ 1005: "AutoNumber",
33
+ };
34
+ // ============ Core Functions ============
35
+ /** Parse bitable URL and extract tokens */
36
+ function parseBitableUrl(url) {
37
+ try {
38
+ const u = new URL(url);
39
+ const tableId = u.searchParams.get("table") ?? undefined;
40
+ // Wiki format: /wiki/XXXXX?table=YYY
41
+ const wikiMatch = u.pathname.match(/\/wiki\/([A-Za-z0-9]+)/);
42
+ if (wikiMatch) {
43
+ return { token: wikiMatch[1], tableId, isWiki: true };
44
+ }
45
+ // Base format: /base/XXXXX?table=YYY
46
+ const baseMatch = u.pathname.match(/\/base\/([A-Za-z0-9]+)/);
47
+ if (baseMatch) {
48
+ return { token: baseMatch[1], tableId, isWiki: false };
49
+ }
50
+ return null;
51
+ }
52
+ catch {
53
+ return null;
54
+ }
55
+ }
56
+ /** Get app_token from wiki node_token */
57
+ async function getAppTokenFromWiki(client, nodeToken) {
58
+ const res = await client.wiki.space.getNode({
59
+ params: { token: nodeToken },
60
+ });
61
+ if (res.code !== 0) {
62
+ throw new Error(res.msg);
63
+ }
64
+ const node = res.data?.node;
65
+ if (!node) {
66
+ throw new Error("Node not found");
67
+ }
68
+ if (node.obj_type !== "bitable") {
69
+ throw new Error(`Node is not a bitable (type: ${node.obj_type})`);
70
+ }
71
+ return node.obj_token;
72
+ }
73
+ /** Get bitable metadata from URL (handles both /base/ and /wiki/ URLs) */
74
+ async function getBitableMeta(client, url) {
75
+ const parsed = parseBitableUrl(url);
76
+ if (!parsed) {
77
+ throw new Error("Invalid URL format. Expected /base/XXX or /wiki/XXX URL");
78
+ }
79
+ let appToken;
80
+ if (parsed.isWiki) {
81
+ appToken = await getAppTokenFromWiki(client, parsed.token);
82
+ }
83
+ else {
84
+ appToken = parsed.token;
85
+ }
86
+ // Get bitable app info
87
+ const res = await client.bitable.app.get({
88
+ path: { app_token: appToken },
89
+ });
90
+ if (res.code !== 0) {
91
+ throw new Error(res.msg);
92
+ }
93
+ // List tables if no table_id specified
94
+ let tables = [];
95
+ if (!parsed.tableId) {
96
+ const tablesRes = await client.bitable.appTable.list({
97
+ path: { app_token: appToken },
98
+ });
99
+ if (tablesRes.code === 0) {
100
+ tables = (tablesRes.data?.items ?? []).map((t) => ({
101
+ table_id: t.table_id,
102
+ name: t.name,
103
+ }));
104
+ }
105
+ }
106
+ return {
107
+ app_token: appToken,
108
+ table_id: parsed.tableId,
109
+ name: res.data?.app?.name,
110
+ url_type: parsed.isWiki ? "wiki" : "base",
111
+ ...(tables.length > 0 && { tables }),
112
+ hint: parsed.tableId
113
+ ? `Use app_token="${appToken}" and table_id="${parsed.tableId}" for other bitable tools`
114
+ : `Use app_token="${appToken}" for other bitable tools. Select a table_id from the tables list.`,
115
+ };
116
+ }
117
+ async function listFields(client, appToken, tableId) {
118
+ const res = await client.bitable.appTableField.list({
119
+ path: { app_token: appToken, table_id: tableId },
120
+ });
121
+ if (res.code !== 0) {
122
+ throw new Error(res.msg);
123
+ }
124
+ const fields = res.data?.items ?? [];
125
+ return {
126
+ fields: fields.map((f) => ({
127
+ field_id: f.field_id,
128
+ field_name: f.field_name,
129
+ type: f.type,
130
+ type_name: FIELD_TYPE_NAMES[f.type ?? 0] || `type_${f.type}`,
131
+ is_primary: f.is_primary,
132
+ ...(f.property && { property: f.property }),
133
+ })),
134
+ total: fields.length,
135
+ };
136
+ }
137
+ async function listRecords(client, appToken, tableId, pageSize, pageToken) {
138
+ const res = await client.bitable.appTableRecord.list({
139
+ path: { app_token: appToken, table_id: tableId },
140
+ params: {
141
+ page_size: pageSize ?? 100,
142
+ ...(pageToken && { page_token: pageToken }),
143
+ },
144
+ });
145
+ if (res.code !== 0) {
146
+ throw new Error(res.msg);
147
+ }
148
+ return {
149
+ records: res.data?.items ?? [],
150
+ has_more: res.data?.has_more ?? false,
151
+ page_token: res.data?.page_token,
152
+ total: res.data?.total,
153
+ };
154
+ }
155
+ async function getRecord(client, appToken, tableId, recordId) {
156
+ const res = await client.bitable.appTableRecord.get({
157
+ path: { app_token: appToken, table_id: tableId, record_id: recordId },
158
+ });
159
+ if (res.code !== 0) {
160
+ throw new Error(res.msg);
161
+ }
162
+ return {
163
+ record: res.data?.record,
164
+ };
165
+ }
166
+ async function createRecord(client, appToken, tableId, fields) {
167
+ const res = await client.bitable.appTableRecord.create({
168
+ path: { app_token: appToken, table_id: tableId },
169
+ // oxlint-disable-next-line typescript/no-explicit-any
170
+ data: { fields: fields },
171
+ });
172
+ if (res.code !== 0) {
173
+ throw new Error(res.msg);
174
+ }
175
+ return {
176
+ record: res.data?.record,
177
+ };
178
+ }
179
+ async function updateRecord(client, appToken, tableId, recordId, fields) {
180
+ const res = await client.bitable.appTableRecord.update({
181
+ path: { app_token: appToken, table_id: tableId, record_id: recordId },
182
+ // oxlint-disable-next-line typescript/no-explicit-any
183
+ data: { fields: fields },
184
+ });
185
+ if (res.code !== 0) {
186
+ throw new Error(res.msg);
187
+ }
188
+ return {
189
+ record: res.data?.record,
190
+ };
191
+ }
192
+ // ============ Schemas ============
193
+ const GetMetaSchema = Type.Object({
194
+ url: Type.String({
195
+ description: "Bitable URL. Supports both formats: /base/XXX?table=YYY or /wiki/XXX?table=YYY",
196
+ }),
197
+ });
198
+ const ListFieldsSchema = Type.Object({
199
+ app_token: Type.String({
200
+ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
201
+ }),
202
+ table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
203
+ });
204
+ const ListRecordsSchema = Type.Object({
205
+ app_token: Type.String({
206
+ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
207
+ }),
208
+ table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
209
+ page_size: Type.Optional(Type.Number({
210
+ description: "Number of records per page (1-500, default 100)",
211
+ minimum: 1,
212
+ maximum: 500,
213
+ })),
214
+ page_token: Type.Optional(Type.String({ description: "Pagination token from previous response" })),
215
+ });
216
+ const GetRecordSchema = Type.Object({
217
+ app_token: Type.String({
218
+ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
219
+ }),
220
+ table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
221
+ record_id: Type.String({ description: "Record ID to retrieve" }),
222
+ });
223
+ const CreateRecordSchema = Type.Object({
224
+ app_token: Type.String({
225
+ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
226
+ }),
227
+ table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
228
+ fields: Type.Record(Type.String(), Type.Any(), {
229
+ description: "Field values keyed by field name. Format by type: Text='string', Number=123, SingleSelect='Option', MultiSelect=['A','B'], DateTime=timestamp_ms, User=[{id:'ou_xxx'}], URL={text:'Display',link:'https://...'}",
230
+ }),
231
+ });
232
+ const UpdateRecordSchema = Type.Object({
233
+ app_token: Type.String({
234
+ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)",
235
+ }),
236
+ table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
237
+ record_id: Type.String({ description: "Record ID to update" }),
238
+ fields: Type.Record(Type.String(), Type.Any(), {
239
+ description: "Field values to update (same format as create_record)",
240
+ }),
241
+ });
242
+ // ============ Tool Registration ============
243
+ export function registerFeishuBitableTools(api) {
244
+ const feishuCfg = api.config?.channels?.feishu;
245
+ if (!feishuCfg?.appId || !feishuCfg?.appSecret) {
246
+ api.logger.debug?.("feishu_bitable: Feishu credentials not configured, skipping bitable tools");
247
+ return;
248
+ }
249
+ const getClient = () => createFeishuClient(feishuCfg);
250
+ // Tool 0: feishu_bitable_get_meta (helper to parse URLs)
251
+ api.registerTool({
252
+ name: "feishu_bitable_get_meta",
253
+ label: "Feishu Bitable Get Meta",
254
+ description: "Parse a Bitable URL and get app_token, table_id, and table list. Use this first when given a /wiki/ or /base/ URL.",
255
+ parameters: GetMetaSchema,
256
+ async execute(_toolCallId, params) {
257
+ const { url } = params;
258
+ try {
259
+ const result = await getBitableMeta(getClient(), url);
260
+ return json(result);
261
+ }
262
+ catch (err) {
263
+ return json({ error: err instanceof Error ? err.message : String(err) });
264
+ }
265
+ },
266
+ }, { name: "feishu_bitable_get_meta" });
267
+ // Tool 1: feishu_bitable_list_fields
268
+ api.registerTool({
269
+ name: "feishu_bitable_list_fields",
270
+ label: "Feishu Bitable List Fields",
271
+ description: "List all fields (columns) in a Bitable table with their types and properties",
272
+ parameters: ListFieldsSchema,
273
+ async execute(_toolCallId, params) {
274
+ const { app_token, table_id } = params;
275
+ try {
276
+ const result = await listFields(getClient(), app_token, table_id);
277
+ return json(result);
278
+ }
279
+ catch (err) {
280
+ return json({ error: err instanceof Error ? err.message : String(err) });
281
+ }
282
+ },
283
+ }, { name: "feishu_bitable_list_fields" });
284
+ // Tool 2: feishu_bitable_list_records
285
+ api.registerTool({
286
+ name: "feishu_bitable_list_records",
287
+ label: "Feishu Bitable List Records",
288
+ description: "List records (rows) from a Bitable table with pagination support",
289
+ parameters: ListRecordsSchema,
290
+ async execute(_toolCallId, params) {
291
+ const { app_token, table_id, page_size, page_token } = params;
292
+ try {
293
+ const result = await listRecords(getClient(), app_token, table_id, page_size, page_token);
294
+ return json(result);
295
+ }
296
+ catch (err) {
297
+ return json({ error: err instanceof Error ? err.message : String(err) });
298
+ }
299
+ },
300
+ }, { name: "feishu_bitable_list_records" });
301
+ // Tool 3: feishu_bitable_get_record
302
+ api.registerTool({
303
+ name: "feishu_bitable_get_record",
304
+ label: "Feishu Bitable Get Record",
305
+ description: "Get a single record by ID from a Bitable table",
306
+ parameters: GetRecordSchema,
307
+ async execute(_toolCallId, params) {
308
+ const { app_token, table_id, record_id } = params;
309
+ try {
310
+ const result = await getRecord(getClient(), app_token, table_id, record_id);
311
+ return json(result);
312
+ }
313
+ catch (err) {
314
+ return json({ error: err instanceof Error ? err.message : String(err) });
315
+ }
316
+ },
317
+ }, { name: "feishu_bitable_get_record" });
318
+ // Tool 4: feishu_bitable_create_record
319
+ api.registerTool({
320
+ name: "feishu_bitable_create_record",
321
+ label: "Feishu Bitable Create Record",
322
+ description: "Create a new record (row) in a Bitable table",
323
+ parameters: CreateRecordSchema,
324
+ async execute(_toolCallId, params) {
325
+ const { app_token, table_id, fields } = params;
326
+ try {
327
+ const result = await createRecord(getClient(), app_token, table_id, fields);
328
+ return json(result);
329
+ }
330
+ catch (err) {
331
+ return json({ error: err instanceof Error ? err.message : String(err) });
332
+ }
333
+ },
334
+ }, { name: "feishu_bitable_create_record" });
335
+ // Tool 5: feishu_bitable_update_record
336
+ api.registerTool({
337
+ name: "feishu_bitable_update_record",
338
+ label: "Feishu Bitable Update Record",
339
+ description: "Update an existing record (row) in a Bitable table",
340
+ parameters: UpdateRecordSchema,
341
+ async execute(_toolCallId, params) {
342
+ const { app_token, table_id, record_id, fields } = params;
343
+ try {
344
+ const result = await updateRecord(getClient(), app_token, table_id, record_id, fields);
345
+ return json(result);
346
+ }
347
+ catch (err) {
348
+ return json({ error: err instanceof Error ? err.message : String(err) });
349
+ }
350
+ },
351
+ }, { name: "feishu_bitable_update_record" });
352
+ api.logger.info?.(`feishu_bitable: Registered 6 bitable tools (original)`);
353
+ // ============ Enhanced Tools (Phase 1B) ============
354
+ // Tool 6: feishu_bitable_search_records
355
+ api.registerTool({
356
+ name: "feishu_bitable_search_records",
357
+ label: "Feishu Bitable Search Records",
358
+ description: "Search/filter records in a Bitable table with conditions. Supports AND/OR filters, sorting, and field selection.",
359
+ parameters: SearchRecordsSchema,
360
+ async execute(_toolCallId, params) {
361
+ const { app_token, table_id, filter, sort, field_names, page_size, page_token } = params;
362
+ try {
363
+ const result = await searchRecords(getClient(), app_token, table_id, filter, sort, field_names, page_size, page_token);
364
+ return json(result);
365
+ }
366
+ catch (err) {
367
+ return json({ error: err instanceof Error ? err.message : String(err) });
368
+ }
369
+ },
370
+ }, { name: "feishu_bitable_search_records" });
371
+ // Tool 7: feishu_bitable_batch_create
372
+ api.registerTool({
373
+ name: "feishu_bitable_batch_create",
374
+ label: "Feishu Bitable Batch Create Records",
375
+ description: "Create multiple records (rows) in a Bitable table at once",
376
+ parameters: BatchCreateRecordsSchema,
377
+ async execute(_toolCallId, params) {
378
+ const { app_token, table_id, records } = params;
379
+ try {
380
+ const result = await batchCreateRecords(getClient(), app_token, table_id, records);
381
+ return json(result);
382
+ }
383
+ catch (err) {
384
+ return json({ error: err instanceof Error ? err.message : String(err) });
385
+ }
386
+ },
387
+ }, { name: "feishu_bitable_batch_create" });
388
+ // Tool 8: feishu_bitable_batch_update
389
+ api.registerTool({
390
+ name: "feishu_bitable_batch_update",
391
+ label: "Feishu Bitable Batch Update Records",
392
+ description: "Update multiple records (rows) in a Bitable table at once",
393
+ parameters: BatchUpdateRecordsSchema,
394
+ async execute(_toolCallId, params) {
395
+ const { app_token, table_id, records } = params;
396
+ try {
397
+ const result = await batchUpdateRecords(getClient(), app_token, table_id, records);
398
+ return json(result);
399
+ }
400
+ catch (err) {
401
+ return json({ error: err instanceof Error ? err.message : String(err) });
402
+ }
403
+ },
404
+ }, { name: "feishu_bitable_batch_update" });
405
+ // Tool 9: feishu_bitable_list_tables
406
+ api.registerTool({
407
+ name: "feishu_bitable_list_tables",
408
+ label: "Feishu Bitable List Tables",
409
+ description: "List all tables in a Bitable app",
410
+ parameters: ListTablesSchema,
411
+ async execute(_toolCallId, params) {
412
+ const { app_token, page_size, page_token } = params;
413
+ try {
414
+ const result = await listBitableTables(getClient(), app_token, page_size, page_token);
415
+ return json(result);
416
+ }
417
+ catch (err) {
418
+ return json({ error: err instanceof Error ? err.message : String(err) });
419
+ }
420
+ },
421
+ }, { name: "feishu_bitable_list_tables" });
422
+ // Tool 10: feishu_bitable_create_table
423
+ api.registerTool({
424
+ name: "feishu_bitable_create_table",
425
+ label: "Feishu Bitable Create Table",
426
+ description: "Create a new table in a Bitable app",
427
+ parameters: CreateTableSchema,
428
+ async execute(_toolCallId, params) {
429
+ const { app_token, name, fields: fieldDefs, } = params;
430
+ try {
431
+ const result = await createBitableTable(getClient(), app_token, name, fieldDefs);
432
+ return json(result);
433
+ }
434
+ catch (err) {
435
+ return json({ error: err instanceof Error ? err.message : String(err) });
436
+ }
437
+ },
438
+ }, { name: "feishu_bitable_create_table" });
439
+ // Tool 11: feishu_bitable_create_field
440
+ api.registerTool({
441
+ name: "feishu_bitable_create_field",
442
+ label: "Feishu Bitable Create Field",
443
+ description: "Create a new field (column) in a Bitable table. Common types: 1=Text, 2=Number, 3=SingleSelect, 4=MultiSelect, 5=DateTime, 7=Checkbox, 11=User, 15=URL",
444
+ parameters: CreateFieldSchema,
445
+ async execute(_toolCallId, params) {
446
+ const { app_token, table_id, field_name, type, property } = params;
447
+ try {
448
+ const result = await createBitableField(getClient(), app_token, table_id, field_name, type, property);
449
+ return json(result);
450
+ }
451
+ catch (err) {
452
+ return json({ error: err instanceof Error ? err.message : String(err) });
453
+ }
454
+ },
455
+ }, { name: "feishu_bitable_create_field" });
456
+ // Tool 12: feishu_bitable_create_view
457
+ api.registerTool({
458
+ name: "feishu_bitable_create_view",
459
+ label: "Feishu Bitable Create View",
460
+ description: "Create a new view for a Bitable table. View types: grid(table), kanban, gallery, form, gantt",
461
+ parameters: CreateViewSchema,
462
+ async execute(_toolCallId, params) {
463
+ const { app_token, table_id, view_name, view_type } = params;
464
+ try {
465
+ const result = await createBitableView(getClient(), app_token, table_id, view_name, view_type);
466
+ return json(result);
467
+ }
468
+ catch (err) {
469
+ return json({ error: err instanceof Error ? err.message : String(err) });
470
+ }
471
+ },
472
+ }, { name: "feishu_bitable_create_view" });
473
+ // Tool 13: feishu_bitable_list_dashboards
474
+ api.registerTool({
475
+ name: "feishu_bitable_list_dashboards",
476
+ label: "Feishu Bitable List Dashboards",
477
+ description: "List all dashboards in a Bitable app",
478
+ parameters: ListDashboardsSchema,
479
+ async execute(_toolCallId, params) {
480
+ const { app_token, page_size, page_token } = params;
481
+ try {
482
+ const result = await listBitableDashboards(getClient(), app_token, page_size, page_token);
483
+ return json(result);
484
+ }
485
+ catch (err) {
486
+ return json({ error: err instanceof Error ? err.message : String(err) });
487
+ }
488
+ },
489
+ }, { name: "feishu_bitable_list_dashboards" });
490
+ api.logger.info?.(`feishu_bitable: Registered 14 bitable tools total`);
491
+ }
492
+ // ============ Enhanced Core Functions (Phase 1B) ============
493
+ /** Search records with filter conditions */
494
+ export async function searchRecords(client, appToken, tableId, filter, sort, fieldNames, pageSize, pageToken) {
495
+ const res = await client.bitable.appTableRecord.search({
496
+ path: { app_token: appToken, table_id: tableId },
497
+ data: {
498
+ ...(filter && { filter }),
499
+ ...(sort && { sort }),
500
+ ...(fieldNames && { field_names: fieldNames }),
501
+ ...(pageSize && { page_size: pageSize }),
502
+ ...(pageToken && { page_token: pageToken }),
503
+ // oxlint-disable-next-line typescript/no-explicit-any
504
+ },
505
+ });
506
+ if (res.code !== 0) {
507
+ throw new Error(res.msg);
508
+ }
509
+ return {
510
+ records: res.data?.items ?? [],
511
+ has_more: res.data?.has_more ?? false,
512
+ page_token: res.data?.page_token,
513
+ total: res.data?.total,
514
+ };
515
+ }
516
+ /** Batch create records */
517
+ export async function batchCreateRecords(client, appToken, tableId, records) {
518
+ const res = await client.bitable.appTableRecord.batchCreate({
519
+ path: { app_token: appToken, table_id: tableId },
520
+ // oxlint-disable-next-line typescript/no-explicit-any
521
+ data: { records: records },
522
+ });
523
+ if (res.code !== 0) {
524
+ throw new Error(res.msg);
525
+ }
526
+ return {
527
+ records: res.data?.records ?? [],
528
+ total: (res.data?.records ?? []).length,
529
+ };
530
+ }
531
+ /** Batch update records */
532
+ export async function batchUpdateRecords(client, appToken, tableId, records) {
533
+ const res = await client.bitable.appTableRecord.batchUpdate({
534
+ path: { app_token: appToken, table_id: tableId },
535
+ // oxlint-disable-next-line typescript/no-explicit-any
536
+ data: { records: records },
537
+ });
538
+ if (res.code !== 0) {
539
+ throw new Error(res.msg);
540
+ }
541
+ return {
542
+ records: res.data?.records ?? [],
543
+ total: (res.data?.records ?? []).length,
544
+ };
545
+ }
546
+ /** List all tables in a Bitable app */
547
+ export async function listBitableTables(client, appToken, pageSize, pageToken) {
548
+ const res = await client.bitable.appTable.list({
549
+ path: { app_token: appToken },
550
+ params: {
551
+ ...(pageSize && { page_size: pageSize }),
552
+ ...(pageToken && { page_token: pageToken }),
553
+ },
554
+ });
555
+ if (res.code !== 0) {
556
+ throw new Error(res.msg);
557
+ }
558
+ return {
559
+ tables: (res.data?.items ?? []).map((t) => ({
560
+ table_id: t.table_id,
561
+ name: t.name,
562
+ revision: t.revision,
563
+ })),
564
+ has_more: res.data?.has_more ?? false,
565
+ page_token: res.data?.page_token,
566
+ total: res.data?.total,
567
+ };
568
+ }
569
+ /** Create a new table in a Bitable app */
570
+ export async function createBitableTable(client, appToken, name, fields) {
571
+ const table = {
572
+ name,
573
+ ...(fields &&
574
+ fields.length > 0 && {
575
+ fields: fields.map((f) => ({
576
+ field_name: f.field_name,
577
+ type: f.type,
578
+ })),
579
+ }),
580
+ };
581
+ const res = await client.bitable.appTable.create({
582
+ path: { app_token: appToken },
583
+ // oxlint-disable-next-line typescript/no-explicit-any
584
+ data: { table },
585
+ });
586
+ if (res.code !== 0) {
587
+ throw new Error(res.msg);
588
+ }
589
+ return {
590
+ table_id: res.data?.table_id,
591
+ name,
592
+ };
593
+ }
594
+ /** Create a new field in a Bitable table */
595
+ export async function createBitableField(client, appToken, tableId, fieldName, type, property) {
596
+ const res = await client.bitable.appTableField.create({
597
+ path: { app_token: appToken, table_id: tableId },
598
+ data: {
599
+ field_name: fieldName,
600
+ type,
601
+ ...(property && { property }),
602
+ // oxlint-disable-next-line typescript/no-explicit-any
603
+ },
604
+ });
605
+ if (res.code !== 0) {
606
+ throw new Error(res.msg);
607
+ }
608
+ return {
609
+ field_id: res.data?.field?.field_id,
610
+ field_name: res.data?.field?.field_name,
611
+ type: res.data?.field?.type,
612
+ type_name: FIELD_TYPE_NAMES[res.data?.field?.type ?? 0] || `type_${res.data?.field?.type}`,
613
+ };
614
+ }
615
+ /** Create a new view for a Bitable table */
616
+ export async function createBitableView(client, appToken, tableId, viewName, viewType) {
617
+ const res = await client.bitable.appTableView.create({
618
+ path: { app_token: appToken, table_id: tableId },
619
+ data: {
620
+ view_name: viewName,
621
+ view_type: (viewType || "grid"),
622
+ },
623
+ });
624
+ if (res.code !== 0) {
625
+ throw new Error(res.msg);
626
+ }
627
+ return {
628
+ view_id: res.data?.view?.view_id,
629
+ view_name: res.data?.view?.view_name,
630
+ view_type: res.data?.view?.view_type,
631
+ };
632
+ }
633
+ /** List all dashboards in a Bitable app */
634
+ export async function listBitableDashboards(client, appToken, pageSize, pageToken) {
635
+ const res = await client.bitable.appDashboard.list({
636
+ path: { app_token: appToken },
637
+ params: {
638
+ ...(pageSize && { page_size: pageSize }),
639
+ ...(pageToken && { page_token: pageToken }),
640
+ },
641
+ });
642
+ if (res.code !== 0) {
643
+ throw new Error(res.msg);
644
+ }
645
+ const data = res.data;
646
+ return {
647
+ dashboards: (data?.dashboards ?? data?.items ?? []).map((d) => ({
648
+ dashboard_id: d.block_id,
649
+ name: d.name,
650
+ })),
651
+ has_more: data?.has_more ?? false,
652
+ page_token: data?.page_token,
653
+ };
654
+ }
655
+ // ============ Enhanced Schemas (Phase 1B) ============
656
+ const SearchRecordsSchema = Type.Object({
657
+ app_token: Type.String({ description: "Bitable app token" }),
658
+ table_id: Type.String({ description: "Table ID" }),
659
+ filter: Type.Optional(Type.Any({
660
+ description: 'Filter conditions. Example: {"conjunction":"and","conditions":[{"field_name":"Status","operator":"is","value":["Done"]}]}',
661
+ })),
662
+ sort: Type.Optional(Type.Any({
663
+ description: 'Sort conditions. Example: [{"field_name":"Created","desc":true}]',
664
+ })),
665
+ field_names: Type.Optional(Type.Array(Type.String(), { description: "Specific field names to return (reduces data)" })),
666
+ page_size: Type.Optional(Type.Number({ description: "Records per page (1-500, default 100)", minimum: 1, maximum: 500 })),
667
+ page_token: Type.Optional(Type.String({ description: "Pagination token" })),
668
+ });
669
+ const BatchCreateRecordsSchema = Type.Object({
670
+ app_token: Type.String({ description: "Bitable app token" }),
671
+ table_id: Type.String({ description: "Table ID" }),
672
+ records: Type.Array(Type.Object({
673
+ fields: Type.Record(Type.String(), Type.Any(), { description: "Field values" }),
674
+ }), { description: "Array of records to create (max 500)" }),
675
+ });
676
+ const BatchUpdateRecordsSchema = Type.Object({
677
+ app_token: Type.String({ description: "Bitable app token" }),
678
+ table_id: Type.String({ description: "Table ID" }),
679
+ records: Type.Array(Type.Object({
680
+ record_id: Type.String({ description: "Record ID to update" }),
681
+ fields: Type.Record(Type.String(), Type.Any(), { description: "Field values to update" }),
682
+ }), { description: "Array of records to update (max 500)" }),
683
+ });
684
+ const ListTablesSchema = Type.Object({
685
+ app_token: Type.String({ description: "Bitable app token" }),
686
+ page_size: Type.Optional(Type.Number({ description: "Tables per page (default 20)", minimum: 1, maximum: 100 })),
687
+ page_token: Type.Optional(Type.String({ description: "Pagination token" })),
688
+ });
689
+ const CreateTableSchema = Type.Object({
690
+ app_token: Type.String({ description: "Bitable app token" }),
691
+ name: Type.String({ description: "Table name" }),
692
+ fields: Type.Optional(Type.Array(Type.Object({
693
+ field_name: Type.String({ description: "Field name" }),
694
+ type: Type.Number({
695
+ description: "Field type: 1=Text, 2=Number, 3=SingleSelect, 4=MultiSelect, 5=DateTime",
696
+ }),
697
+ }), { description: "Initial fields to create with the table" })),
698
+ });
699
+ const CreateFieldSchema = Type.Object({
700
+ app_token: Type.String({ description: "Bitable app token" }),
701
+ table_id: Type.String({ description: "Table ID" }),
702
+ field_name: Type.String({ description: "Field name" }),
703
+ type: Type.Number({
704
+ description: "Field type: 1=Text, 2=Number, 3=SingleSelect, 4=MultiSelect, 5=DateTime, 7=Checkbox, 11=User, 15=URL",
705
+ }),
706
+ property: Type.Optional(Type.Any({
707
+ description: 'Field properties. E.g. for SingleSelect: {"options":[{"name":"Option A"}]}',
708
+ })),
709
+ });
710
+ const CreateViewSchema = Type.Object({
711
+ app_token: Type.String({ description: "Bitable app token" }),
712
+ table_id: Type.String({ description: "Table ID" }),
713
+ view_name: Type.String({ description: "View name" }),
714
+ view_type: Type.Optional(Type.String({ description: "View type: grid, kanban, gallery, form, gantt. Default: grid" })),
715
+ });
716
+ const ListDashboardsSchema = Type.Object({
717
+ app_token: Type.String({ description: "Bitable app token" }),
718
+ page_size: Type.Optional(Type.Number({ description: "Dashboards per page", minimum: 1, maximum: 100 })),
719
+ page_token: Type.Optional(Type.String({ description: "Pagination token" })),
720
+ });
721
+ //# sourceMappingURL=bitable.js.map