@nextclaw/channel-plugin-feishu 0.2.29-beta.0 → 0.2.29-beta.1
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/dist/index.d.ts +23 -0
- package/dist/index.js +45 -0
- package/dist/src/accounts.js +141 -0
- package/dist/src/app-scope-checker.js +36 -0
- package/dist/src/async.js +34 -0
- package/dist/src/auth-errors.js +72 -0
- package/dist/src/bitable.js +495 -0
- package/dist/src/bot.d.ts +35 -0
- package/dist/src/bot.js +941 -0
- package/dist/src/calendar-calendar.js +54 -0
- package/dist/src/calendar-event-attendee.js +98 -0
- package/dist/src/calendar-event.js +193 -0
- package/dist/src/calendar-freebusy.js +40 -0
- package/dist/src/calendar-shared.js +23 -0
- package/dist/src/calendar.js +16 -0
- package/dist/src/card-action.js +49 -0
- package/dist/src/channel.d.ts +7 -0
- package/dist/src/channel.js +413 -0
- package/dist/src/chat-schema.js +25 -0
- package/dist/src/chat.js +87 -0
- package/dist/src/client.d.ts +16 -0
- package/dist/src/client.js +112 -0
- package/dist/src/config-schema.d.ts +357 -0
- package/dist/src/dedup.js +126 -0
- package/dist/src/device-flow.js +109 -0
- package/dist/src/directory.js +101 -0
- package/dist/src/doc-schema.js +148 -0
- package/dist/src/docx-batch-insert.js +104 -0
- package/dist/src/docx-color-text.js +80 -0
- package/dist/src/docx-table-ops.js +197 -0
- package/dist/src/docx.js +858 -0
- package/dist/src/domains.js +14 -0
- package/dist/src/drive-schema.js +41 -0
- package/dist/src/drive.js +126 -0
- package/dist/src/dynamic-agent.js +93 -0
- package/dist/src/external-keys.js +13 -0
- package/dist/src/feishu-fetch.js +12 -0
- package/dist/src/identity.js +92 -0
- package/dist/src/lark-ticket.js +11 -0
- package/dist/src/media.d.ts +75 -0
- package/dist/src/media.js +304 -0
- package/dist/src/mention.d.ts +52 -0
- package/dist/src/mention.js +82 -0
- package/dist/src/monitor.account.d.ts +1 -0
- package/dist/src/monitor.account.js +393 -0
- package/dist/src/monitor.d.ts +11 -0
- package/dist/src/monitor.js +58 -0
- package/dist/src/monitor.startup.js +24 -0
- package/dist/src/monitor.state.d.ts +1 -0
- package/dist/src/monitor.state.js +80 -0
- package/dist/src/monitor.transport.js +167 -0
- package/dist/src/nextclaw-sdk/account-id.js +15 -0
- package/dist/src/nextclaw-sdk/core-channel.js +150 -0
- package/dist/src/nextclaw-sdk/core-pairing.js +151 -0
- package/dist/src/nextclaw-sdk/dedupe.js +164 -0
- package/dist/src/nextclaw-sdk/feishu.d.ts +1 -0
- package/dist/src/nextclaw-sdk/feishu.js +14 -0
- package/dist/src/nextclaw-sdk/history.js +69 -0
- package/dist/src/nextclaw-sdk/network-body.js +180 -0
- package/dist/src/nextclaw-sdk/network-fetch.js +63 -0
- package/dist/src/nextclaw-sdk/network-webhook.js +126 -0
- package/dist/src/nextclaw-sdk/network.js +4 -0
- package/dist/src/nextclaw-sdk/runtime-store.js +21 -0
- package/dist/src/nextclaw-sdk/secrets-config.js +65 -0
- package/dist/src/nextclaw-sdk/secrets-core.d.ts +1 -0
- package/dist/src/nextclaw-sdk/secrets-core.js +68 -0
- package/dist/src/nextclaw-sdk/secrets-prompt.js +193 -0
- package/dist/src/nextclaw-sdk/secrets.d.ts +1 -0
- package/dist/src/nextclaw-sdk/secrets.js +4 -0
- package/dist/src/nextclaw-sdk/types.d.ts +242 -0
- package/dist/src/oauth.js +171 -0
- package/dist/src/onboarding.js +381 -0
- package/dist/src/outbound.js +150 -0
- package/dist/src/perm-schema.js +49 -0
- package/dist/src/perm.js +90 -0
- package/dist/src/policy.js +61 -0
- package/dist/src/post.js +160 -0
- package/dist/src/probe.d.ts +11 -0
- package/dist/src/probe.js +85 -0
- package/dist/src/raw-request.js +24 -0
- package/dist/src/reactions.d.ts +67 -0
- package/dist/src/reactions.js +91 -0
- package/dist/src/reply-dispatcher.js +250 -0
- package/dist/src/runtime.js +5 -0
- package/dist/src/secret-input.js +3 -0
- package/dist/src/send-result.js +12 -0
- package/dist/src/send-target.js +22 -0
- package/dist/src/send.d.ts +51 -0
- package/dist/src/send.js +265 -0
- package/dist/src/sheets-shared.js +193 -0
- package/dist/src/sheets.js +95 -0
- package/dist/src/streaming-card.js +263 -0
- package/dist/src/targets.js +39 -0
- package/dist/src/task-comment.js +76 -0
- package/dist/src/task-shared.js +13 -0
- package/dist/src/task-subtask.js +79 -0
- package/dist/src/task-task.js +144 -0
- package/dist/src/task-tasklist.js +136 -0
- package/dist/src/task.js +16 -0
- package/dist/src/token-store.js +154 -0
- package/dist/src/tool-account.js +65 -0
- package/dist/src/tool-result.js +18 -0
- package/dist/src/tool-scopes.js +62 -0
- package/dist/src/tools-config.js +30 -0
- package/dist/src/types.d.ts +43 -0
- package/dist/src/typing.js +145 -0
- package/dist/src/uat-client.js +102 -0
- package/dist/src/user-tool-client.js +132 -0
- package/dist/src/user-tool-helpers.js +110 -0
- package/dist/src/user-tool-result.js +10 -0
- package/dist/src/wiki-schema.js +45 -0
- package/dist/src/wiki.js +144 -0
- package/package.json +8 -4
- package/index.ts +0 -75
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { createFeishuToolClient } from "./tool-account.js";
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
//#region src/bitable.ts
|
|
4
|
+
function json(data) {
|
|
5
|
+
return {
|
|
6
|
+
content: [{
|
|
7
|
+
type: "text",
|
|
8
|
+
text: JSON.stringify(data, null, 2)
|
|
9
|
+
}],
|
|
10
|
+
details: data
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
var LarkApiError = class extends Error {
|
|
14
|
+
code;
|
|
15
|
+
api;
|
|
16
|
+
context;
|
|
17
|
+
constructor(code, message, api, context) {
|
|
18
|
+
super(`[${api}] code=${code} message=${message}`);
|
|
19
|
+
this.name = "LarkApiError";
|
|
20
|
+
this.code = code;
|
|
21
|
+
this.api = api;
|
|
22
|
+
this.context = context;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function ensureLarkSuccess(res, api, context) {
|
|
26
|
+
if (res.code !== 0) throw new LarkApiError(res.code ?? -1, res.msg ?? "unknown error", api, context);
|
|
27
|
+
}
|
|
28
|
+
/** Field type ID to human-readable name */
|
|
29
|
+
const FIELD_TYPE_NAMES = {
|
|
30
|
+
1: "Text",
|
|
31
|
+
2: "Number",
|
|
32
|
+
3: "SingleSelect",
|
|
33
|
+
4: "MultiSelect",
|
|
34
|
+
5: "DateTime",
|
|
35
|
+
7: "Checkbox",
|
|
36
|
+
11: "User",
|
|
37
|
+
13: "Phone",
|
|
38
|
+
15: "URL",
|
|
39
|
+
17: "Attachment",
|
|
40
|
+
18: "SingleLink",
|
|
41
|
+
19: "Lookup",
|
|
42
|
+
20: "Formula",
|
|
43
|
+
21: "DuplexLink",
|
|
44
|
+
22: "Location",
|
|
45
|
+
23: "GroupChat",
|
|
46
|
+
1001: "CreatedTime",
|
|
47
|
+
1002: "ModifiedTime",
|
|
48
|
+
1003: "CreatedUser",
|
|
49
|
+
1004: "ModifiedUser",
|
|
50
|
+
1005: "AutoNumber"
|
|
51
|
+
};
|
|
52
|
+
/** Parse bitable URL and extract tokens */
|
|
53
|
+
function parseBitableUrl(url) {
|
|
54
|
+
try {
|
|
55
|
+
const u = new URL(url);
|
|
56
|
+
const tableId = u.searchParams.get("table") ?? void 0;
|
|
57
|
+
const wikiMatch = u.pathname.match(/\/wiki\/([A-Za-z0-9]+)/);
|
|
58
|
+
if (wikiMatch) return {
|
|
59
|
+
token: wikiMatch[1],
|
|
60
|
+
tableId,
|
|
61
|
+
isWiki: true
|
|
62
|
+
};
|
|
63
|
+
const baseMatch = u.pathname.match(/\/base\/([A-Za-z0-9]+)/);
|
|
64
|
+
if (baseMatch) return {
|
|
65
|
+
token: baseMatch[1],
|
|
66
|
+
tableId,
|
|
67
|
+
isWiki: false
|
|
68
|
+
};
|
|
69
|
+
return null;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Get app_token from wiki node_token */
|
|
75
|
+
async function getAppTokenFromWiki(client, nodeToken) {
|
|
76
|
+
const res = await client.wiki.space.getNode({ params: { token: nodeToken } });
|
|
77
|
+
ensureLarkSuccess(res, "wiki.space.getNode", { nodeToken });
|
|
78
|
+
const node = res.data?.node;
|
|
79
|
+
if (!node) throw new Error("Node not found");
|
|
80
|
+
if (node.obj_type !== "bitable") throw new Error(`Node is not a bitable (type: ${node.obj_type})`);
|
|
81
|
+
return node.obj_token;
|
|
82
|
+
}
|
|
83
|
+
/** Get bitable metadata from URL (handles both /base/ and /wiki/ URLs) */
|
|
84
|
+
async function getBitableMeta(client, url) {
|
|
85
|
+
const parsed = parseBitableUrl(url);
|
|
86
|
+
if (!parsed) throw new Error("Invalid URL format. Expected /base/XXX or /wiki/XXX URL");
|
|
87
|
+
let appToken;
|
|
88
|
+
if (parsed.isWiki) appToken = await getAppTokenFromWiki(client, parsed.token);
|
|
89
|
+
else appToken = parsed.token;
|
|
90
|
+
const res = await client.bitable.app.get({ path: { app_token: appToken } });
|
|
91
|
+
ensureLarkSuccess(res, "bitable.app.get", { appToken });
|
|
92
|
+
let tables = [];
|
|
93
|
+
if (!parsed.tableId) {
|
|
94
|
+
const tablesRes = await client.bitable.appTable.list({ path: { app_token: appToken } });
|
|
95
|
+
if (tablesRes.code === 0) tables = (tablesRes.data?.items ?? []).map((t) => ({
|
|
96
|
+
table_id: t.table_id,
|
|
97
|
+
name: t.name
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
app_token: appToken,
|
|
102
|
+
table_id: parsed.tableId,
|
|
103
|
+
name: res.data?.app?.name,
|
|
104
|
+
url_type: parsed.isWiki ? "wiki" : "base",
|
|
105
|
+
...tables.length > 0 && { tables },
|
|
106
|
+
hint: parsed.tableId ? `Use app_token="${appToken}" and table_id="${parsed.tableId}" for other bitable tools` : `Use app_token="${appToken}" for other bitable tools. Select a table_id from the tables list.`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async function listFields(client, appToken, tableId) {
|
|
110
|
+
const res = await client.bitable.appTableField.list({ path: {
|
|
111
|
+
app_token: appToken,
|
|
112
|
+
table_id: tableId
|
|
113
|
+
} });
|
|
114
|
+
ensureLarkSuccess(res, "bitable.appTableField.list", {
|
|
115
|
+
appToken,
|
|
116
|
+
tableId
|
|
117
|
+
});
|
|
118
|
+
const fields = res.data?.items ?? [];
|
|
119
|
+
return {
|
|
120
|
+
fields: fields.map((f) => ({
|
|
121
|
+
field_id: f.field_id,
|
|
122
|
+
field_name: f.field_name,
|
|
123
|
+
type: f.type,
|
|
124
|
+
type_name: FIELD_TYPE_NAMES[f.type ?? 0] || `type_${f.type}`,
|
|
125
|
+
is_primary: f.is_primary,
|
|
126
|
+
...f.property && { property: f.property }
|
|
127
|
+
})),
|
|
128
|
+
total: fields.length
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function listRecords(client, appToken, tableId, pageSize, pageToken) {
|
|
132
|
+
const res = await client.bitable.appTableRecord.list({
|
|
133
|
+
path: {
|
|
134
|
+
app_token: appToken,
|
|
135
|
+
table_id: tableId
|
|
136
|
+
},
|
|
137
|
+
params: {
|
|
138
|
+
page_size: pageSize ?? 100,
|
|
139
|
+
...pageToken && { page_token: pageToken }
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
ensureLarkSuccess(res, "bitable.appTableRecord.list", {
|
|
143
|
+
appToken,
|
|
144
|
+
tableId,
|
|
145
|
+
pageSize
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
records: res.data?.items ?? [],
|
|
149
|
+
has_more: res.data?.has_more ?? false,
|
|
150
|
+
page_token: res.data?.page_token,
|
|
151
|
+
total: res.data?.total
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async function getRecord(client, appToken, tableId, recordId) {
|
|
155
|
+
const res = await client.bitable.appTableRecord.get({ path: {
|
|
156
|
+
app_token: appToken,
|
|
157
|
+
table_id: tableId,
|
|
158
|
+
record_id: recordId
|
|
159
|
+
} });
|
|
160
|
+
ensureLarkSuccess(res, "bitable.appTableRecord.get", {
|
|
161
|
+
appToken,
|
|
162
|
+
tableId,
|
|
163
|
+
recordId
|
|
164
|
+
});
|
|
165
|
+
return { record: res.data?.record };
|
|
166
|
+
}
|
|
167
|
+
async function createRecord(client, appToken, tableId, fields) {
|
|
168
|
+
const res = await client.bitable.appTableRecord.create({
|
|
169
|
+
path: {
|
|
170
|
+
app_token: appToken,
|
|
171
|
+
table_id: tableId
|
|
172
|
+
},
|
|
173
|
+
data: { fields }
|
|
174
|
+
});
|
|
175
|
+
ensureLarkSuccess(res, "bitable.appTableRecord.create", {
|
|
176
|
+
appToken,
|
|
177
|
+
tableId
|
|
178
|
+
});
|
|
179
|
+
return { record: res.data?.record };
|
|
180
|
+
}
|
|
181
|
+
/** Default field types created for new Bitable tables (to be cleaned up) */
|
|
182
|
+
const DEFAULT_CLEANUP_FIELD_TYPES = new Set([
|
|
183
|
+
3,
|
|
184
|
+
5,
|
|
185
|
+
17
|
|
186
|
+
]);
|
|
187
|
+
/** Clean up default placeholder rows and fields in a newly created Bitable table */
|
|
188
|
+
async function cleanupNewBitable(client, appToken, tableId, tableName, logger) {
|
|
189
|
+
let cleanedRows = 0;
|
|
190
|
+
let cleanedFields = 0;
|
|
191
|
+
const fieldsRes = await client.bitable.appTableField.list({ path: {
|
|
192
|
+
app_token: appToken,
|
|
193
|
+
table_id: tableId
|
|
194
|
+
} });
|
|
195
|
+
if (fieldsRes.code === 0 && fieldsRes.data?.items) {
|
|
196
|
+
const primaryField = fieldsRes.data.items.find((f) => f.is_primary);
|
|
197
|
+
if (primaryField?.field_id) try {
|
|
198
|
+
const newFieldName = tableName.length <= 20 ? tableName : "Name";
|
|
199
|
+
await client.bitable.appTableField.update({
|
|
200
|
+
path: {
|
|
201
|
+
app_token: appToken,
|
|
202
|
+
table_id: tableId,
|
|
203
|
+
field_id: primaryField.field_id
|
|
204
|
+
},
|
|
205
|
+
data: {
|
|
206
|
+
field_name: newFieldName,
|
|
207
|
+
type: 1
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
cleanedFields++;
|
|
211
|
+
} catch (err) {
|
|
212
|
+
logger.debug(`Failed to rename primary field: ${err}`);
|
|
213
|
+
}
|
|
214
|
+
const defaultFieldsToDelete = fieldsRes.data.items.filter((f) => !f.is_primary && DEFAULT_CLEANUP_FIELD_TYPES.has(f.type ?? 0));
|
|
215
|
+
for (const field of defaultFieldsToDelete) if (field.field_id) try {
|
|
216
|
+
await client.bitable.appTableField.delete({ path: {
|
|
217
|
+
app_token: appToken,
|
|
218
|
+
table_id: tableId,
|
|
219
|
+
field_id: field.field_id
|
|
220
|
+
} });
|
|
221
|
+
cleanedFields++;
|
|
222
|
+
} catch (err) {
|
|
223
|
+
logger.debug(`Failed to delete default field ${field.field_name}: ${err}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const recordsRes = await client.bitable.appTableRecord.list({
|
|
227
|
+
path: {
|
|
228
|
+
app_token: appToken,
|
|
229
|
+
table_id: tableId
|
|
230
|
+
},
|
|
231
|
+
params: { page_size: 100 }
|
|
232
|
+
});
|
|
233
|
+
if (recordsRes.code === 0 && recordsRes.data?.items) {
|
|
234
|
+
const emptyRecordIds = recordsRes.data.items.filter((r) => !r.fields || Object.keys(r.fields).length === 0).map((r) => r.record_id).filter((id) => Boolean(id));
|
|
235
|
+
if (emptyRecordIds.length > 0) try {
|
|
236
|
+
await client.bitable.appTableRecord.batchDelete({
|
|
237
|
+
path: {
|
|
238
|
+
app_token: appToken,
|
|
239
|
+
table_id: tableId
|
|
240
|
+
},
|
|
241
|
+
data: { records: emptyRecordIds }
|
|
242
|
+
});
|
|
243
|
+
cleanedRows = emptyRecordIds.length;
|
|
244
|
+
} catch {
|
|
245
|
+
for (const recordId of emptyRecordIds) try {
|
|
246
|
+
await client.bitable.appTableRecord.delete({ path: {
|
|
247
|
+
app_token: appToken,
|
|
248
|
+
table_id: tableId,
|
|
249
|
+
record_id: recordId
|
|
250
|
+
} });
|
|
251
|
+
cleanedRows++;
|
|
252
|
+
} catch (err) {
|
|
253
|
+
logger.debug(`Failed to delete empty row ${recordId}: ${err}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
cleanedRows,
|
|
259
|
+
cleanedFields
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async function createApp(client, name, folderToken, logger) {
|
|
263
|
+
const res = await client.bitable.app.create({ data: {
|
|
264
|
+
name,
|
|
265
|
+
...folderToken && { folder_token: folderToken }
|
|
266
|
+
} });
|
|
267
|
+
ensureLarkSuccess(res, "bitable.app.create", {
|
|
268
|
+
name,
|
|
269
|
+
folderToken
|
|
270
|
+
});
|
|
271
|
+
const appToken = res.data?.app?.app_token;
|
|
272
|
+
if (!appToken) throw new Error("Failed to create Bitable: no app_token returned");
|
|
273
|
+
const log = logger ?? {
|
|
274
|
+
debug: () => {},
|
|
275
|
+
warn: () => {}
|
|
276
|
+
};
|
|
277
|
+
let tableId;
|
|
278
|
+
let cleanedRows = 0;
|
|
279
|
+
let cleanedFields = 0;
|
|
280
|
+
try {
|
|
281
|
+
const tablesRes = await client.bitable.appTable.list({ path: { app_token: appToken } });
|
|
282
|
+
if (tablesRes.code === 0 && tablesRes.data?.items && tablesRes.data.items.length > 0) {
|
|
283
|
+
tableId = tablesRes.data.items[0].table_id ?? void 0;
|
|
284
|
+
if (tableId) {
|
|
285
|
+
const cleanup = await cleanupNewBitable(client, appToken, tableId, name, log);
|
|
286
|
+
cleanedRows = cleanup.cleanedRows;
|
|
287
|
+
cleanedFields = cleanup.cleanedFields;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} catch (err) {
|
|
291
|
+
log.debug(`Cleanup failed (non-critical): ${err}`);
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
app_token: appToken,
|
|
295
|
+
table_id: tableId,
|
|
296
|
+
name: res.data?.app?.name,
|
|
297
|
+
url: res.data?.app?.url,
|
|
298
|
+
cleaned_placeholder_rows: cleanedRows,
|
|
299
|
+
cleaned_default_fields: cleanedFields,
|
|
300
|
+
hint: tableId ? `Table created. Use app_token="${appToken}" and table_id="${tableId}" for other bitable tools.` : "Table created. Use feishu_bitable_get_meta to get table_id and field details."
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
async function createField(client, appToken, tableId, fieldName, fieldType, property) {
|
|
304
|
+
const res = await client.bitable.appTableField.create({
|
|
305
|
+
path: {
|
|
306
|
+
app_token: appToken,
|
|
307
|
+
table_id: tableId
|
|
308
|
+
},
|
|
309
|
+
data: {
|
|
310
|
+
field_name: fieldName,
|
|
311
|
+
type: fieldType,
|
|
312
|
+
...property && { property }
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
ensureLarkSuccess(res, "bitable.appTableField.create", {
|
|
316
|
+
appToken,
|
|
317
|
+
tableId,
|
|
318
|
+
fieldName,
|
|
319
|
+
fieldType
|
|
320
|
+
});
|
|
321
|
+
return {
|
|
322
|
+
field_id: res.data?.field?.field_id,
|
|
323
|
+
field_name: res.data?.field?.field_name,
|
|
324
|
+
type: res.data?.field?.type,
|
|
325
|
+
type_name: FIELD_TYPE_NAMES[res.data?.field?.type ?? 0] || `type_${res.data?.field?.type}`
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async function updateRecord(client, appToken, tableId, recordId, fields) {
|
|
329
|
+
const res = await client.bitable.appTableRecord.update({
|
|
330
|
+
path: {
|
|
331
|
+
app_token: appToken,
|
|
332
|
+
table_id: tableId,
|
|
333
|
+
record_id: recordId
|
|
334
|
+
},
|
|
335
|
+
data: { fields }
|
|
336
|
+
});
|
|
337
|
+
ensureLarkSuccess(res, "bitable.appTableRecord.update", {
|
|
338
|
+
appToken,
|
|
339
|
+
tableId,
|
|
340
|
+
recordId
|
|
341
|
+
});
|
|
342
|
+
return { record: res.data?.record };
|
|
343
|
+
}
|
|
344
|
+
const GetMetaSchema = Type.Object({ url: Type.String({ description: "Bitable URL. Supports both formats: /base/XXX?table=YYY or /wiki/XXX?table=YYY" }) });
|
|
345
|
+
const ListFieldsSchema = Type.Object({
|
|
346
|
+
app_token: Type.String({ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)" }),
|
|
347
|
+
table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" })
|
|
348
|
+
});
|
|
349
|
+
const ListRecordsSchema = Type.Object({
|
|
350
|
+
app_token: Type.String({ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)" }),
|
|
351
|
+
table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
|
|
352
|
+
page_size: Type.Optional(Type.Number({
|
|
353
|
+
description: "Number of records per page (1-500, default 100)",
|
|
354
|
+
minimum: 1,
|
|
355
|
+
maximum: 500
|
|
356
|
+
})),
|
|
357
|
+
page_token: Type.Optional(Type.String({ description: "Pagination token from previous response" }))
|
|
358
|
+
});
|
|
359
|
+
const GetRecordSchema = Type.Object({
|
|
360
|
+
app_token: Type.String({ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)" }),
|
|
361
|
+
table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
|
|
362
|
+
record_id: Type.String({ description: "Record ID to retrieve" })
|
|
363
|
+
});
|
|
364
|
+
const CreateRecordSchema = Type.Object({
|
|
365
|
+
app_token: Type.String({ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)" }),
|
|
366
|
+
table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
|
|
367
|
+
fields: Type.Record(Type.String(), Type.Any(), { 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://...'}" })
|
|
368
|
+
});
|
|
369
|
+
const CreateAppSchema = Type.Object({
|
|
370
|
+
name: Type.String({ description: "Name for the new Bitable application" }),
|
|
371
|
+
folder_token: Type.Optional(Type.String({ description: "Optional folder token to place the Bitable in a specific folder" }))
|
|
372
|
+
});
|
|
373
|
+
const CreateFieldSchema = Type.Object({
|
|
374
|
+
app_token: Type.String({ description: "Bitable app token (use feishu_bitable_get_meta to get from URL, or feishu_bitable_create_app to create new)" }),
|
|
375
|
+
table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
|
|
376
|
+
field_name: Type.String({ description: "Name for the new field" }),
|
|
377
|
+
field_type: Type.Number({
|
|
378
|
+
description: "Field type ID: 1=Text, 2=Number, 3=SingleSelect, 4=MultiSelect, 5=DateTime, 7=Checkbox, 11=User, 13=Phone, 15=URL, 17=Attachment, 18=SingleLink, 19=Lookup, 20=Formula, 21=DuplexLink, 22=Location, 23=GroupChat, 1001=CreatedTime, 1002=ModifiedTime, 1003=CreatedUser, 1004=ModifiedUser, 1005=AutoNumber",
|
|
379
|
+
minimum: 1
|
|
380
|
+
}),
|
|
381
|
+
property: Type.Optional(Type.Record(Type.String(), Type.Any(), { description: "Field-specific properties (e.g., options for SingleSelect, format for Number)" }))
|
|
382
|
+
});
|
|
383
|
+
const UpdateRecordSchema = Type.Object({
|
|
384
|
+
app_token: Type.String({ description: "Bitable app token (use feishu_bitable_get_meta to get from URL)" }),
|
|
385
|
+
table_id: Type.String({ description: "Table ID (from URL: ?table=YYY)" }),
|
|
386
|
+
record_id: Type.String({ description: "Record ID to update" }),
|
|
387
|
+
fields: Type.Record(Type.String(), Type.Any(), { description: "Field values to update (same format as create_record)" })
|
|
388
|
+
});
|
|
389
|
+
function registerFeishuBitableTools(api) {
|
|
390
|
+
if (!api.config) {
|
|
391
|
+
api.logger.debug?.("feishu_bitable: No config available, skipping bitable tools");
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const getClient = (params, defaultAccountId) => createFeishuToolClient({
|
|
395
|
+
api,
|
|
396
|
+
executeParams: params,
|
|
397
|
+
defaultAccountId
|
|
398
|
+
});
|
|
399
|
+
const registerBitableTool = (params) => {
|
|
400
|
+
api.registerTool((ctx) => ({
|
|
401
|
+
name: params.name,
|
|
402
|
+
label: params.label,
|
|
403
|
+
description: params.description,
|
|
404
|
+
parameters: params.parameters,
|
|
405
|
+
async execute(_toolCallId, rawParams) {
|
|
406
|
+
try {
|
|
407
|
+
return json(await params.execute({
|
|
408
|
+
params: rawParams,
|
|
409
|
+
defaultAccountId: ctx.agentAccountId
|
|
410
|
+
}));
|
|
411
|
+
} catch (err) {
|
|
412
|
+
return json({ error: err instanceof Error ? err.message : String(err) });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}), { name: params.name });
|
|
416
|
+
};
|
|
417
|
+
registerBitableTool({
|
|
418
|
+
name: "feishu_bitable_get_meta",
|
|
419
|
+
label: "Feishu Bitable Get Meta",
|
|
420
|
+
description: "Parse a Bitable URL and get app_token, table_id, and table list. Use this first when given a /wiki/ or /base/ URL.",
|
|
421
|
+
parameters: GetMetaSchema,
|
|
422
|
+
async execute({ params, defaultAccountId }) {
|
|
423
|
+
return getBitableMeta(getClient(params, defaultAccountId), params.url);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
registerBitableTool({
|
|
427
|
+
name: "feishu_bitable_list_fields",
|
|
428
|
+
label: "Feishu Bitable List Fields",
|
|
429
|
+
description: "List all fields (columns) in a Bitable table with their types and properties",
|
|
430
|
+
parameters: ListFieldsSchema,
|
|
431
|
+
async execute({ params, defaultAccountId }) {
|
|
432
|
+
return listFields(getClient(params, defaultAccountId), params.app_token, params.table_id);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
registerBitableTool({
|
|
436
|
+
name: "feishu_bitable_list_records",
|
|
437
|
+
label: "Feishu Bitable List Records",
|
|
438
|
+
description: "List records (rows) from a Bitable table with pagination support",
|
|
439
|
+
parameters: ListRecordsSchema,
|
|
440
|
+
async execute({ params, defaultAccountId }) {
|
|
441
|
+
return listRecords(getClient(params, defaultAccountId), params.app_token, params.table_id, params.page_size, params.page_token);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
registerBitableTool({
|
|
445
|
+
name: "feishu_bitable_get_record",
|
|
446
|
+
label: "Feishu Bitable Get Record",
|
|
447
|
+
description: "Get a single record by ID from a Bitable table",
|
|
448
|
+
parameters: GetRecordSchema,
|
|
449
|
+
async execute({ params, defaultAccountId }) {
|
|
450
|
+
return getRecord(getClient(params, defaultAccountId), params.app_token, params.table_id, params.record_id);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
registerBitableTool({
|
|
454
|
+
name: "feishu_bitable_create_record",
|
|
455
|
+
label: "Feishu Bitable Create Record",
|
|
456
|
+
description: "Create a new record (row) in a Bitable table",
|
|
457
|
+
parameters: CreateRecordSchema,
|
|
458
|
+
async execute({ params, defaultAccountId }) {
|
|
459
|
+
return createRecord(getClient(params, defaultAccountId), params.app_token, params.table_id, params.fields);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
registerBitableTool({
|
|
463
|
+
name: "feishu_bitable_update_record",
|
|
464
|
+
label: "Feishu Bitable Update Record",
|
|
465
|
+
description: "Update an existing record (row) in a Bitable table",
|
|
466
|
+
parameters: UpdateRecordSchema,
|
|
467
|
+
async execute({ params, defaultAccountId }) {
|
|
468
|
+
return updateRecord(getClient(params, defaultAccountId), params.app_token, params.table_id, params.record_id, params.fields);
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
registerBitableTool({
|
|
472
|
+
name: "feishu_bitable_create_app",
|
|
473
|
+
label: "Feishu Bitable Create App",
|
|
474
|
+
description: "Create a new Bitable (multidimensional table) application",
|
|
475
|
+
parameters: CreateAppSchema,
|
|
476
|
+
async execute({ params, defaultAccountId }) {
|
|
477
|
+
return createApp(getClient(params, defaultAccountId), params.name, params.folder_token, {
|
|
478
|
+
debug: (msg) => api.logger.debug?.(msg),
|
|
479
|
+
warn: (msg) => api.logger.warn?.(msg)
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
registerBitableTool({
|
|
484
|
+
name: "feishu_bitable_create_field",
|
|
485
|
+
label: "Feishu Bitable Create Field",
|
|
486
|
+
description: "Create a new field (column) in a Bitable table",
|
|
487
|
+
parameters: CreateFieldSchema,
|
|
488
|
+
async execute({ params, defaultAccountId }) {
|
|
489
|
+
return createField(getClient(params, defaultAccountId), params.app_token, params.table_id, params.field_name, params.field_type, params.property);
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
api.logger.info?.("feishu_bitable: Registered bitable tools");
|
|
493
|
+
}
|
|
494
|
+
//#endregion
|
|
495
|
+
export { registerFeishuBitableTools };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/bot.d.ts
|
|
2
|
+
type FeishuMessageEvent = {
|
|
3
|
+
sender: {
|
|
4
|
+
sender_id: {
|
|
5
|
+
open_id?: string;
|
|
6
|
+
user_id?: string;
|
|
7
|
+
union_id?: string;
|
|
8
|
+
};
|
|
9
|
+
sender_type?: string;
|
|
10
|
+
tenant_key?: string;
|
|
11
|
+
};
|
|
12
|
+
message: {
|
|
13
|
+
message_id: string;
|
|
14
|
+
root_id?: string;
|
|
15
|
+
parent_id?: string;
|
|
16
|
+
thread_id?: string;
|
|
17
|
+
chat_id: string;
|
|
18
|
+
chat_type: "p2p" | "group" | "private";
|
|
19
|
+
message_type: string;
|
|
20
|
+
content: string;
|
|
21
|
+
create_time?: string;
|
|
22
|
+
mentions?: Array<{
|
|
23
|
+
key: string;
|
|
24
|
+
id: {
|
|
25
|
+
open_id?: string;
|
|
26
|
+
user_id?: string;
|
|
27
|
+
union_id?: string;
|
|
28
|
+
};
|
|
29
|
+
name: string;
|
|
30
|
+
tenant_key?: string;
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { FeishuMessageEvent };
|