@colinlu50/openclaw-lark-stream 2026.3.17
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/LICENSE +21 -0
- package/README.md +141 -0
- package/README.zh.md +70 -0
- package/bin/openclaw-lark.js +48 -0
- package/index.d.ts +36 -0
- package/index.js +118 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +66 -0
- package/skills/feishu-bitable/SKILL.md +248 -0
- package/skills/feishu-bitable/references/examples.md +813 -0
- package/skills/feishu-bitable/references/field-properties.md +763 -0
- package/skills/feishu-bitable/references/record-values.md +911 -0
- package/skills/feishu-calendar/SKILL.md +244 -0
- package/skills/feishu-channel-rules/SKILL.md +24 -0
- package/skills/feishu-channel-rules/references/markdown-syntax.md +138 -0
- package/skills/feishu-create-doc/SKILL.md +719 -0
- package/skills/feishu-fetch-doc/SKILL.md +93 -0
- package/skills/feishu-im-read/SKILL.md +163 -0
- package/skills/feishu-task/SKILL.md +293 -0
- package/skills/feishu-troubleshoot/SKILL.md +70 -0
- package/skills/feishu-update-doc/SKILL.md +285 -0
- package/src/card/builder.d.ts +106 -0
- package/src/card/builder.js +443 -0
- package/src/card/cardkit.d.ts +90 -0
- package/src/card/cardkit.js +181 -0
- package/src/card/flush-controller.d.ts +45 -0
- package/src/card/flush-controller.js +134 -0
- package/src/card/image-resolver.d.ts +45 -0
- package/src/card/image-resolver.js +112 -0
- package/src/card/markdown-style.d.ts +16 -0
- package/src/card/markdown-style.js +97 -0
- package/src/card/reply-dispatcher-types.d.ts +120 -0
- package/src/card/reply-dispatcher-types.js +57 -0
- package/src/card/reply-dispatcher.d.ts +15 -0
- package/src/card/reply-dispatcher.js +299 -0
- package/src/card/reply-mode.d.ts +38 -0
- package/src/card/reply-mode.js +65 -0
- package/src/card/streaming-card-controller.d.ts +101 -0
- package/src/card/streaming-card-controller.js +810 -0
- package/src/card/unavailable-guard.d.ts +35 -0
- package/src/card/unavailable-guard.js +83 -0
- package/src/channel/abort-detect.d.ts +34 -0
- package/src/channel/abort-detect.js +124 -0
- package/src/channel/chat-queue.d.ts +41 -0
- package/src/channel/chat-queue.js +58 -0
- package/src/channel/config-adapter.d.ts +23 -0
- package/src/channel/config-adapter.js +101 -0
- package/src/channel/directory.d.ts +57 -0
- package/src/channel/directory.js +191 -0
- package/src/channel/event-handlers.d.ts +15 -0
- package/src/channel/event-handlers.js +221 -0
- package/src/channel/monitor.d.ts +17 -0
- package/src/channel/monitor.js +129 -0
- package/src/channel/onboarding-config.d.ts +17 -0
- package/src/channel/onboarding-config.js +88 -0
- package/src/channel/onboarding-migrate.d.ts +25 -0
- package/src/channel/onboarding-migrate.js +67 -0
- package/src/channel/onboarding.d.ts +12 -0
- package/src/channel/onboarding.js +296 -0
- package/src/channel/plugin.d.ts +13 -0
- package/src/channel/plugin.js +278 -0
- package/src/channel/probe.d.ts +14 -0
- package/src/channel/probe.js +21 -0
- package/src/channel/types.d.ts +36 -0
- package/src/channel/types.js +7 -0
- package/src/commands/auth.d.ts +21 -0
- package/src/commands/auth.js +161 -0
- package/src/commands/diagnose.d.ts +69 -0
- package/src/commands/diagnose.js +807 -0
- package/src/commands/doctor.d.ts +26 -0
- package/src/commands/doctor.js +584 -0
- package/src/commands/index.d.ts +25 -0
- package/src/commands/index.js +212 -0
- package/src/commands/locale.d.ts +7 -0
- package/src/commands/locale.js +7 -0
- package/src/core/accounts.d.ts +37 -0
- package/src/core/accounts.js +163 -0
- package/src/core/agent-config.d.ts +100 -0
- package/src/core/agent-config.js +139 -0
- package/src/core/api-error.d.ts +48 -0
- package/src/core/api-error.js +112 -0
- package/src/core/app-owner-fallback.d.ts +21 -0
- package/src/core/app-owner-fallback.js +38 -0
- package/src/core/app-scope-checker.d.ts +87 -0
- package/src/core/app-scope-checker.js +190 -0
- package/src/core/auth-errors.d.ts +144 -0
- package/src/core/auth-errors.js +154 -0
- package/src/core/chat-info-cache.d.ts +57 -0
- package/src/core/chat-info-cache.js +152 -0
- package/src/core/config-schema.d.ts +448 -0
- package/src/core/config-schema.js +200 -0
- package/src/core/device-flow.d.ts +77 -0
- package/src/core/device-flow.js +212 -0
- package/src/core/domains.d.ts +18 -0
- package/src/core/domains.js +28 -0
- package/src/core/feishu-fetch.d.ts +18 -0
- package/src/core/feishu-fetch.js +25 -0
- package/src/core/footer-config.d.ts +24 -0
- package/src/core/footer-config.js +39 -0
- package/src/core/lark-client.d.ts +108 -0
- package/src/core/lark-client.js +353 -0
- package/src/core/lark-logger.d.ts +23 -0
- package/src/core/lark-logger.js +154 -0
- package/src/core/lark-ticket.d.ts +29 -0
- package/src/core/lark-ticket.js +35 -0
- package/src/core/message-unavailable.d.ts +53 -0
- package/src/core/message-unavailable.js +130 -0
- package/src/core/owner-policy.d.ts +31 -0
- package/src/core/owner-policy.js +52 -0
- package/src/core/permission-url.d.ts +22 -0
- package/src/core/permission-url.js +72 -0
- package/src/core/raw-request.d.ts +27 -0
- package/src/core/raw-request.js +62 -0
- package/src/core/scope-manager.d.ts +168 -0
- package/src/core/scope-manager.js +213 -0
- package/src/core/security-check.d.ts +72 -0
- package/src/core/security-check.js +174 -0
- package/src/core/shutdown-hooks.d.ts +22 -0
- package/src/core/shutdown-hooks.js +56 -0
- package/src/core/targets.d.ts +60 -0
- package/src/core/targets.js +164 -0
- package/src/core/token-store.d.ts +54 -0
- package/src/core/token-store.js +314 -0
- package/src/core/tool-client.d.ts +176 -0
- package/src/core/tool-client.js +380 -0
- package/src/core/tool-scopes.d.ts +153 -0
- package/src/core/tool-scopes.js +326 -0
- package/src/core/tools-config.d.ts +55 -0
- package/src/core/tools-config.js +137 -0
- package/src/core/types.d.ts +87 -0
- package/src/core/types.js +11 -0
- package/src/core/uat-client.d.ts +46 -0
- package/src/core/uat-client.js +187 -0
- package/src/core/version.d.ts +25 -0
- package/src/core/version.js +49 -0
- package/src/messaging/converters/audio.d.ts +8 -0
- package/src/messaging/converters/audio.js +21 -0
- package/src/messaging/converters/calendar.d.ts +13 -0
- package/src/messaging/converters/calendar.js +50 -0
- package/src/messaging/converters/content-converter.d.ts +41 -0
- package/src/messaging/converters/content-converter.js +106 -0
- package/src/messaging/converters/file.d.ts +8 -0
- package/src/messaging/converters/file.js +20 -0
- package/src/messaging/converters/folder.d.ts +8 -0
- package/src/messaging/converters/folder.js +20 -0
- package/src/messaging/converters/hongbao.d.ts +8 -0
- package/src/messaging/converters/hongbao.js +16 -0
- package/src/messaging/converters/image.d.ts +8 -0
- package/src/messaging/converters/image.js +18 -0
- package/src/messaging/converters/index.d.ts +8 -0
- package/src/messaging/converters/index.js +50 -0
- package/src/messaging/converters/interactive/card-converter.d.ts +76 -0
- package/src/messaging/converters/interactive/card-converter.js +1173 -0
- package/src/messaging/converters/interactive/card-utils.d.ts +9 -0
- package/src/messaging/converters/interactive/card-utils.js +42 -0
- package/src/messaging/converters/interactive/index.d.ts +8 -0
- package/src/messaging/converters/interactive/index.js +21 -0
- package/src/messaging/converters/interactive/legacy.d.ts +11 -0
- package/src/messaging/converters/interactive/legacy.js +57 -0
- package/src/messaging/converters/interactive/types.d.ts +23 -0
- package/src/messaging/converters/interactive/types.js +24 -0
- package/src/messaging/converters/location.d.ts +8 -0
- package/src/messaging/converters/location.js +19 -0
- package/src/messaging/converters/merge-forward.d.ts +32 -0
- package/src/messaging/converters/merge-forward.js +225 -0
- package/src/messaging/converters/post.d.ts +11 -0
- package/src/messaging/converters/post.js +135 -0
- package/src/messaging/converters/share.d.ts +9 -0
- package/src/messaging/converters/share.js +23 -0
- package/src/messaging/converters/sticker.d.ts +8 -0
- package/src/messaging/converters/sticker.js +18 -0
- package/src/messaging/converters/system.d.ts +12 -0
- package/src/messaging/converters/system.js +32 -0
- package/src/messaging/converters/text.d.ts +8 -0
- package/src/messaging/converters/text.js +14 -0
- package/src/messaging/converters/todo.d.ts +8 -0
- package/src/messaging/converters/todo.js +41 -0
- package/src/messaging/converters/types.d.ts +107 -0
- package/src/messaging/converters/types.js +7 -0
- package/src/messaging/converters/unknown.d.ts +8 -0
- package/src/messaging/converters/unknown.js +16 -0
- package/src/messaging/converters/utils.d.ts +22 -0
- package/src/messaging/converters/utils.js +51 -0
- package/src/messaging/converters/video-chat.d.ts +8 -0
- package/src/messaging/converters/video-chat.js +23 -0
- package/src/messaging/converters/video.d.ts +8 -0
- package/src/messaging/converters/video.js +32 -0
- package/src/messaging/converters/vote.d.ts +8 -0
- package/src/messaging/converters/vote.js +24 -0
- package/src/messaging/inbound/dedup.d.ts +59 -0
- package/src/messaging/inbound/dedup.js +116 -0
- package/src/messaging/inbound/dispatch-builders.d.ts +84 -0
- package/src/messaging/inbound/dispatch-builders.js +152 -0
- package/src/messaging/inbound/dispatch-commands.d.ts +27 -0
- package/src/messaging/inbound/dispatch-commands.js +112 -0
- package/src/messaging/inbound/dispatch-context.d.ts +67 -0
- package/src/messaging/inbound/dispatch-context.js +136 -0
- package/src/messaging/inbound/dispatch.d.ts +47 -0
- package/src/messaging/inbound/dispatch.js +264 -0
- package/src/messaging/inbound/enrich.d.ts +102 -0
- package/src/messaging/inbound/enrich.js +227 -0
- package/src/messaging/inbound/gate-effects.d.ts +23 -0
- package/src/messaging/inbound/gate-effects.js +43 -0
- package/src/messaging/inbound/gate.d.ts +60 -0
- package/src/messaging/inbound/gate.js +233 -0
- package/src/messaging/inbound/handler.d.ts +35 -0
- package/src/messaging/inbound/handler.js +173 -0
- package/src/messaging/inbound/media-resolver.d.ts +32 -0
- package/src/messaging/inbound/media-resolver.js +87 -0
- package/src/messaging/inbound/mention.d.ts +39 -0
- package/src/messaging/inbound/mention.js +81 -0
- package/src/messaging/inbound/parse-io.d.ts +50 -0
- package/src/messaging/inbound/parse-io.js +81 -0
- package/src/messaging/inbound/parse.d.ts +28 -0
- package/src/messaging/inbound/parse.js +106 -0
- package/src/messaging/inbound/permission.d.ts +17 -0
- package/src/messaging/inbound/permission.js +40 -0
- package/src/messaging/inbound/policy.d.ts +94 -0
- package/src/messaging/inbound/policy.js +160 -0
- package/src/messaging/inbound/reaction-handler.d.ts +61 -0
- package/src/messaging/inbound/reaction-handler.js +221 -0
- package/src/messaging/inbound/user-name-cache.d.ts +82 -0
- package/src/messaging/inbound/user-name-cache.js +241 -0
- package/src/messaging/outbound/actions.d.ts +16 -0
- package/src/messaging/outbound/actions.js +309 -0
- package/src/messaging/outbound/chat-manage.d.ts +64 -0
- package/src/messaging/outbound/chat-manage.js +111 -0
- package/src/messaging/outbound/deliver.d.ts +155 -0
- package/src/messaging/outbound/deliver.js +298 -0
- package/src/messaging/outbound/fetch.d.ts +12 -0
- package/src/messaging/outbound/fetch.js +12 -0
- package/src/messaging/outbound/forward.d.ts +26 -0
- package/src/messaging/outbound/forward.js +48 -0
- package/src/messaging/outbound/media-url-utils.d.ts +29 -0
- package/src/messaging/outbound/media-url-utils.js +130 -0
- package/src/messaging/outbound/media.d.ts +260 -0
- package/src/messaging/outbound/media.js +758 -0
- package/src/messaging/outbound/outbound.d.ts +89 -0
- package/src/messaging/outbound/outbound.js +121 -0
- package/src/messaging/outbound/reactions.d.ts +124 -0
- package/src/messaging/outbound/reactions.js +378 -0
- package/src/messaging/outbound/send.d.ts +152 -0
- package/src/messaging/outbound/send.js +355 -0
- package/src/messaging/outbound/typing.d.ts +71 -0
- package/src/messaging/outbound/typing.js +179 -0
- package/src/messaging/shared/message-lookup.d.ts +54 -0
- package/src/messaging/shared/message-lookup.js +117 -0
- package/src/messaging/types.d.ts +176 -0
- package/src/messaging/types.js +10 -0
- package/src/tools/auto-auth.d.ts +56 -0
- package/src/tools/auto-auth.js +919 -0
- package/src/tools/helpers.d.ts +260 -0
- package/src/tools/helpers.js +364 -0
- package/src/tools/mcp/doc/create.d.ts +12 -0
- package/src/tools/mcp/doc/create.js +44 -0
- package/src/tools/mcp/doc/fetch.d.ts +12 -0
- package/src/tools/mcp/doc/fetch.js +36 -0
- package/src/tools/mcp/doc/index.d.ts +12 -0
- package/src/tools/mcp/doc/index.js +41 -0
- package/src/tools/mcp/doc/update.d.ts +12 -0
- package/src/tools/mcp/doc/update.js +61 -0
- package/src/tools/mcp/shared.d.ts +59 -0
- package/src/tools/mcp/shared.js +226 -0
- package/src/tools/oapi/bitable/app-table-field.d.ts +16 -0
- package/src/tools/oapi/bitable/app-table-field.js +222 -0
- package/src/tools/oapi/bitable/app-table-record.d.ts +20 -0
- package/src/tools/oapi/bitable/app-table-record.js +436 -0
- package/src/tools/oapi/bitable/app-table-view.d.ts +17 -0
- package/src/tools/oapi/bitable/app-table-view.js +195 -0
- package/src/tools/oapi/bitable/app-table.d.ts +19 -0
- package/src/tools/oapi/bitable/app-table.js +247 -0
- package/src/tools/oapi/bitable/app.d.ts +18 -0
- package/src/tools/oapi/bitable/app.js +186 -0
- package/src/tools/oapi/bitable/index.d.ts +9 -0
- package/src/tools/oapi/bitable/index.js +9 -0
- package/src/tools/oapi/calendar/calendar.d.ts +15 -0
- package/src/tools/oapi/calendar/calendar.js +122 -0
- package/src/tools/oapi/calendar/event-attendee.d.ts +16 -0
- package/src/tools/oapi/calendar/event-attendee.js +263 -0
- package/src/tools/oapi/calendar/event.d.ts +16 -0
- package/src/tools/oapi/calendar/event.js +709 -0
- package/src/tools/oapi/calendar/freebusy.d.ts +13 -0
- package/src/tools/oapi/calendar/freebusy.js +111 -0
- package/src/tools/oapi/calendar/index.d.ts +8 -0
- package/src/tools/oapi/calendar/index.js +8 -0
- package/src/tools/oapi/chat/chat.d.ts +16 -0
- package/src/tools/oapi/chat/chat.js +124 -0
- package/src/tools/oapi/chat/index.d.ts +10 -0
- package/src/tools/oapi/chat/index.js +15 -0
- package/src/tools/oapi/chat/members.d.ts +11 -0
- package/src/tools/oapi/chat/members.js +81 -0
- package/src/tools/oapi/common/get-user.d.ts +12 -0
- package/src/tools/oapi/common/get-user.js +106 -0
- package/src/tools/oapi/common/index.d.ts +6 -0
- package/src/tools/oapi/common/index.js +6 -0
- package/src/tools/oapi/common/search-user.d.ts +11 -0
- package/src/tools/oapi/common/search-user.js +73 -0
- package/src/tools/oapi/drive/doc-comments.d.ts +15 -0
- package/src/tools/oapi/drive/doc-comments.js +279 -0
- package/src/tools/oapi/drive/doc-media.d.ts +19 -0
- package/src/tools/oapi/drive/doc-media.js +335 -0
- package/src/tools/oapi/drive/file.d.ts +19 -0
- package/src/tools/oapi/drive/file.js +483 -0
- package/src/tools/oapi/drive/index.d.ts +12 -0
- package/src/tools/oapi/drive/index.js +36 -0
- package/src/tools/oapi/helpers.d.ts +182 -0
- package/src/tools/oapi/helpers.js +354 -0
- package/src/tools/oapi/im/format-messages.d.ts +50 -0
- package/src/tools/oapi/im/format-messages.js +165 -0
- package/src/tools/oapi/im/index.d.ts +10 -0
- package/src/tools/oapi/im/index.js +17 -0
- package/src/tools/oapi/im/message-read.d.ts +13 -0
- package/src/tools/oapi/im/message-read.js +411 -0
- package/src/tools/oapi/im/message.d.ts +16 -0
- package/src/tools/oapi/im/message.js +149 -0
- package/src/tools/oapi/im/resource.d.ts +13 -0
- package/src/tools/oapi/im/resource.js +150 -0
- package/src/tools/oapi/im/time-utils.d.ts +46 -0
- package/src/tools/oapi/im/time-utils.js +201 -0
- package/src/tools/oapi/im/user-name-uat.d.ts +26 -0
- package/src/tools/oapi/im/user-name-uat.js +140 -0
- package/src/tools/oapi/index.d.ts +11 -0
- package/src/tools/oapi/index.js +58 -0
- package/src/tools/oapi/sdk-types.d.ts +96 -0
- package/src/tools/oapi/sdk-types.js +12 -0
- package/src/tools/oapi/search/doc-search.d.ts +13 -0
- package/src/tools/oapi/search/doc-search.js +191 -0
- package/src/tools/oapi/search/index.d.ts +12 -0
- package/src/tools/oapi/search/index.js +33 -0
- package/src/tools/oapi/sheets/index.d.ts +12 -0
- package/src/tools/oapi/sheets/index.js +31 -0
- package/src/tools/oapi/sheets/sheet.d.ts +16 -0
- package/src/tools/oapi/sheets/sheet.js +652 -0
- package/src/tools/oapi/task/comment.d.ts +15 -0
- package/src/tools/oapi/task/comment.js +140 -0
- package/src/tools/oapi/task/index.d.ts +8 -0
- package/src/tools/oapi/task/index.js +8 -0
- package/src/tools/oapi/task/subtask.d.ts +14 -0
- package/src/tools/oapi/task/subtask.js +162 -0
- package/src/tools/oapi/task/task.d.ts +16 -0
- package/src/tools/oapi/task/task.js +344 -0
- package/src/tools/oapi/task/tasklist.d.ts +21 -0
- package/src/tools/oapi/task/tasklist.js +321 -0
- package/src/tools/oapi/wiki/index.d.ts +12 -0
- package/src/tools/oapi/wiki/index.js +34 -0
- package/src/tools/oapi/wiki/space-node.d.ts +17 -0
- package/src/tools/oapi/wiki/space-node.js +230 -0
- package/src/tools/oapi/wiki/space.d.ts +15 -0
- package/src/tools/oapi/wiki/space.js +130 -0
- package/src/tools/oauth-batch-auth.d.ts +11 -0
- package/src/tools/oauth-batch-auth.js +142 -0
- package/src/tools/oauth-cards.d.ts +39 -0
- package/src/tools/oauth-cards.js +315 -0
- package/src/tools/oauth.d.ts +47 -0
- package/src/tools/oauth.js +620 -0
- package/src/tools/onboarding-auth.d.ts +27 -0
- package/src/tools/onboarding-auth.js +130 -0
- package/src/tools/tat/im/index.d.ts +15 -0
- package/src/tools/tat/im/index.js +18 -0
- package/src/tools/tat/im/resource.d.ts +15 -0
- package/src/tools/tat/im/resource.js +157 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* feishu_drive_file tool -- Manage Feishu Drive files.
|
|
6
|
+
*
|
|
7
|
+
* Actions: list, get_meta, copy, move, delete, upload, download
|
|
8
|
+
*
|
|
9
|
+
* Uses the Feishu Drive API:
|
|
10
|
+
* - list: GET /open-apis/drive/v1/files
|
|
11
|
+
* - get_meta: POST /open-apis/drive/v1/metas/batch_query
|
|
12
|
+
* - copy: POST /open-apis/drive/v1/files/:file_token/copy
|
|
13
|
+
* - move: POST /open-apis/drive/v1/files/:file_token/move
|
|
14
|
+
* - delete: DELETE /open-apis/drive/v1/files/:file_token
|
|
15
|
+
* - upload: POST /open-apis/drive/v1/files/upload_all
|
|
16
|
+
* - download: GET /open-apis/drive/v1/files/:file_token/download
|
|
17
|
+
*/
|
|
18
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
19
|
+
import { Type } from '@sinclair/typebox';
|
|
20
|
+
import { json, createToolContext, assertLarkOk, handleInvokeErrorWithAutoAuth, registerTool, StringEnum, } from '../helpers';
|
|
21
|
+
import * as fs from 'fs/promises';
|
|
22
|
+
import * as path from 'path';
|
|
23
|
+
// 分片上传配置
|
|
24
|
+
const SMALL_FILE_THRESHOLD = 15 * 1024 * 1024; // 15MB,小于此大小使用一次上传
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Schema
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
const FeishuDriveFileSchema = Type.Union([
|
|
29
|
+
// LIST FILES
|
|
30
|
+
Type.Object({
|
|
31
|
+
action: Type.Literal('list'),
|
|
32
|
+
folder_token: Type.Optional(Type.String({
|
|
33
|
+
description: '文件夹 token(可选)。不填写或填空字符串时,获取用户云空间根目录下的清单(注意:根目录模式不支持分页和返回快捷方式)',
|
|
34
|
+
})),
|
|
35
|
+
page_size: Type.Optional(Type.Integer({
|
|
36
|
+
description: '分页大小(默认 200,最大 200)',
|
|
37
|
+
minimum: 1,
|
|
38
|
+
maximum: 200,
|
|
39
|
+
})),
|
|
40
|
+
page_token: Type.Optional(Type.String({
|
|
41
|
+
description: '分页标记。首次请求无需填写',
|
|
42
|
+
})),
|
|
43
|
+
order_by: Type.Optional(StringEnum(['EditedTime', 'CreatedTime'], {
|
|
44
|
+
description: '排序方式:EditedTime(编辑时间)、CreatedTime(创建时间)',
|
|
45
|
+
})),
|
|
46
|
+
direction: Type.Optional(StringEnum(['ASC', 'DESC'], {
|
|
47
|
+
description: '排序方向:ASC(升序)、DESC(降序)',
|
|
48
|
+
})),
|
|
49
|
+
}),
|
|
50
|
+
// GET META
|
|
51
|
+
Type.Object({
|
|
52
|
+
action: Type.Literal('get_meta'),
|
|
53
|
+
request_docs: Type.Array(Type.Object({
|
|
54
|
+
doc_token: Type.String({
|
|
55
|
+
description: '文档 token(从浏览器 URL 中获取,如 spreadsheet_token、doc_token 等)',
|
|
56
|
+
}),
|
|
57
|
+
doc_type: Type.Union([
|
|
58
|
+
Type.Literal('doc'),
|
|
59
|
+
Type.Literal('sheet'),
|
|
60
|
+
Type.Literal('file'),
|
|
61
|
+
Type.Literal('bitable'),
|
|
62
|
+
Type.Literal('docx'),
|
|
63
|
+
Type.Literal('folder'),
|
|
64
|
+
Type.Literal('mindnote'),
|
|
65
|
+
Type.Literal('slides'),
|
|
66
|
+
], {
|
|
67
|
+
description: '文档类型:doc、sheet、file、bitable、docx、folder、mindnote、slides',
|
|
68
|
+
}),
|
|
69
|
+
}), {
|
|
70
|
+
description: "要查询的文档列表(批量查询,最多 50 个)。示例:[{doc_token: 'Z1FjxxxxxxxxxxxxxxxxxxxtnAc', doc_type: 'sheet'}]",
|
|
71
|
+
minItems: 1,
|
|
72
|
+
maxItems: 50,
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
// COPY FILE
|
|
76
|
+
Type.Object({
|
|
77
|
+
action: Type.Literal('copy'),
|
|
78
|
+
file_token: Type.String({
|
|
79
|
+
description: '文件 token(必填)',
|
|
80
|
+
}),
|
|
81
|
+
name: Type.String({
|
|
82
|
+
description: '目标文件名(必填)',
|
|
83
|
+
}),
|
|
84
|
+
type: Type.Union([
|
|
85
|
+
Type.Literal('doc'),
|
|
86
|
+
Type.Literal('sheet'),
|
|
87
|
+
Type.Literal('file'),
|
|
88
|
+
Type.Literal('bitable'),
|
|
89
|
+
Type.Literal('docx'),
|
|
90
|
+
Type.Literal('folder'),
|
|
91
|
+
Type.Literal('mindnote'),
|
|
92
|
+
Type.Literal('slides'),
|
|
93
|
+
], {
|
|
94
|
+
description: '文档类型(必填)',
|
|
95
|
+
}),
|
|
96
|
+
folder_token: Type.Optional(Type.String({
|
|
97
|
+
description: '目标文件夹 token。不传则复制到「我的空间」根目录',
|
|
98
|
+
})),
|
|
99
|
+
parent_node: Type.Optional(Type.String({
|
|
100
|
+
description: '【folder_token 的别名】目标文件夹 token(为兼容性保留,建议使用 folder_token)',
|
|
101
|
+
})),
|
|
102
|
+
}),
|
|
103
|
+
// MOVE FILE
|
|
104
|
+
Type.Object({
|
|
105
|
+
action: Type.Literal('move'),
|
|
106
|
+
file_token: Type.String({
|
|
107
|
+
description: '文件 token(必填)',
|
|
108
|
+
}),
|
|
109
|
+
type: Type.Union([
|
|
110
|
+
Type.Literal('doc'),
|
|
111
|
+
Type.Literal('sheet'),
|
|
112
|
+
Type.Literal('file'),
|
|
113
|
+
Type.Literal('bitable'),
|
|
114
|
+
Type.Literal('docx'),
|
|
115
|
+
Type.Literal('folder'),
|
|
116
|
+
Type.Literal('mindnote'),
|
|
117
|
+
Type.Literal('slides'),
|
|
118
|
+
], {
|
|
119
|
+
description: '文档类型(必填)',
|
|
120
|
+
}),
|
|
121
|
+
folder_token: Type.String({
|
|
122
|
+
description: '目标文件夹 token(必填)',
|
|
123
|
+
}),
|
|
124
|
+
}),
|
|
125
|
+
// DELETE FILE
|
|
126
|
+
Type.Object({
|
|
127
|
+
action: Type.Literal('delete'),
|
|
128
|
+
file_token: Type.String({
|
|
129
|
+
description: '文件 token(必填)',
|
|
130
|
+
}),
|
|
131
|
+
type: Type.Union([
|
|
132
|
+
Type.Literal('doc'),
|
|
133
|
+
Type.Literal('sheet'),
|
|
134
|
+
Type.Literal('file'),
|
|
135
|
+
Type.Literal('bitable'),
|
|
136
|
+
Type.Literal('docx'),
|
|
137
|
+
Type.Literal('folder'),
|
|
138
|
+
Type.Literal('mindnote'),
|
|
139
|
+
Type.Literal('slides'),
|
|
140
|
+
], {
|
|
141
|
+
description: '文档类型(必填)',
|
|
142
|
+
}),
|
|
143
|
+
}),
|
|
144
|
+
// UPLOAD FILE
|
|
145
|
+
Type.Object({
|
|
146
|
+
action: Type.Literal('upload'),
|
|
147
|
+
parent_node: Type.Optional(Type.String({
|
|
148
|
+
description: '父节点 token(可选)。explorer 类型填文件夹 token,bitable 类型填 app_token。不填写或填空字符串时,上传到云空间根目录',
|
|
149
|
+
})),
|
|
150
|
+
file_path: Type.Optional(Type.String({
|
|
151
|
+
description: '本地文件路径(与 file_content_base64 二选一)。优先使用此参数,会自动读取文件内容、计算大小、提取文件名。',
|
|
152
|
+
})),
|
|
153
|
+
file_content_base64: Type.Optional(Type.String({
|
|
154
|
+
description: '文件内容的 Base64 编码(与 file_path 二选一)。当不提供 file_path 时使用。',
|
|
155
|
+
})),
|
|
156
|
+
file_name: Type.Optional(Type.String({
|
|
157
|
+
description: '文件名(可选)。如果提供了 file_path,会自动从路径中提取文件名;如果使用 file_content_base64,则必须提供此参数。',
|
|
158
|
+
})),
|
|
159
|
+
size: Type.Optional(Type.Integer({
|
|
160
|
+
description: '文件大小(字节,可选)。如果提供了 file_path,会自动计算;如果使用 file_content_base64,则必须提供此参数。',
|
|
161
|
+
})),
|
|
162
|
+
}),
|
|
163
|
+
// DOWNLOAD FILE
|
|
164
|
+
Type.Object({
|
|
165
|
+
action: Type.Literal('download'),
|
|
166
|
+
file_token: Type.String({
|
|
167
|
+
description: '文件 token(必填)',
|
|
168
|
+
}),
|
|
169
|
+
output_path: Type.Optional(Type.String({
|
|
170
|
+
description: "本地保存的完整文件路径(可选)。必须包含文件名和扩展名,例如 '/tmp/file.pdf'。如果不提供,则返回 Base64 编码的文件内容。",
|
|
171
|
+
})),
|
|
172
|
+
}),
|
|
173
|
+
]);
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// Registration
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
export function registerFeishuDriveFileTool(api) {
|
|
178
|
+
if (!api.config)
|
|
179
|
+
return;
|
|
180
|
+
const cfg = api.config;
|
|
181
|
+
const { toolClient, log } = createToolContext(api, 'feishu_drive_file');
|
|
182
|
+
registerTool(api, {
|
|
183
|
+
name: 'feishu_drive_file',
|
|
184
|
+
label: 'Feishu Drive Files',
|
|
185
|
+
description: '【以用户身份】飞书云空间文件管理工具。当用户要求查看云空间(云盘)中的文件列表、获取文件信息、复制/移动/删除文件、上传/下载文件时使用。消息中的文件读写**禁止**使用该工具!' +
|
|
186
|
+
'\n\nActions:' +
|
|
187
|
+
'\n- list(列出文件):列出文件夹下的文件。不提供 folder_token 时获取根目录清单' +
|
|
188
|
+
"\n- get_meta(批量获取元数据):批量查询文档元信息,使用 request_docs 数组参数,格式:[{doc_token: '...', doc_type: 'sheet'}]" +
|
|
189
|
+
'\n- copy(复制文件):复制文件到指定位置' +
|
|
190
|
+
'\n- move(移动文件):移动文件到指定文件夹' +
|
|
191
|
+
'\n- delete(删除文件):删除文件' +
|
|
192
|
+
'\n- upload(上传文件):上传本地文件到云空间。提供 file_path(本地文件路径)或 file_content_base64(Base64 编码)' +
|
|
193
|
+
'\n- download(下载文件):下载文件到本地。提供 output_path(本地保存路径)则保存到本地,否则返回 Base64 编码' +
|
|
194
|
+
'\n\n【重要】copy/move/delete 操作需要 file_token 和 type 参数。get_meta 使用 request_docs 数组参数。' +
|
|
195
|
+
'\n【重要】upload 优先使用 file_path(自动读取文件、提取文件名和大小),也支持 file_content_base64(需手动提供 file_name 和 size)。' +
|
|
196
|
+
'\n【重要】download 提供 output_path 时保存到本地(可以是文件路径或文件夹路径+file_name),不提供则返回 Base64。',
|
|
197
|
+
parameters: FeishuDriveFileSchema,
|
|
198
|
+
async execute(_toolCallId, params) {
|
|
199
|
+
const p = params;
|
|
200
|
+
try {
|
|
201
|
+
const client = toolClient();
|
|
202
|
+
switch (p.action) {
|
|
203
|
+
// -----------------------------------------------------------------
|
|
204
|
+
// LIST FILES
|
|
205
|
+
// -----------------------------------------------------------------
|
|
206
|
+
case 'list': {
|
|
207
|
+
log.info(`list: folder_token=${p.folder_token || '(root)'}, page_size=${p.page_size ?? 200}`);
|
|
208
|
+
const res = await client.invoke('feishu_drive_file.list', (sdk, opts) => sdk.drive.file.list({
|
|
209
|
+
params: {
|
|
210
|
+
folder_token: p.folder_token,
|
|
211
|
+
page_size: p.page_size,
|
|
212
|
+
page_token: p.page_token,
|
|
213
|
+
order_by: p.order_by,
|
|
214
|
+
direction: p.direction,
|
|
215
|
+
},
|
|
216
|
+
}, opts), { as: 'user' });
|
|
217
|
+
assertLarkOk(res);
|
|
218
|
+
log.info(`list: returned ${res.data?.files?.length ?? 0} files`);
|
|
219
|
+
const data = res.data;
|
|
220
|
+
return json({
|
|
221
|
+
files: data?.files,
|
|
222
|
+
has_more: data?.has_more,
|
|
223
|
+
page_token: data?.next_page_token,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
// -----------------------------------------------------------------
|
|
227
|
+
// GET META
|
|
228
|
+
// -----------------------------------------------------------------
|
|
229
|
+
case 'get_meta': {
|
|
230
|
+
if (!p.request_docs || !Array.isArray(p.request_docs) || p.request_docs.length === 0) {
|
|
231
|
+
return json({
|
|
232
|
+
error: "request_docs must be a non-empty array. Correct format: {action: 'get_meta', request_docs: [{doc_token: '...', doc_type: 'sheet'}]}",
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
log.info(`get_meta: querying ${p.request_docs.length} documents`);
|
|
236
|
+
const res = await client.invoke('feishu_drive_file.get_meta', (sdk, opts) => sdk.drive.meta.batchQuery({
|
|
237
|
+
data: {
|
|
238
|
+
request_docs: p.request_docs,
|
|
239
|
+
},
|
|
240
|
+
}, opts), { as: 'user' });
|
|
241
|
+
assertLarkOk(res);
|
|
242
|
+
log.info(`get_meta: returned ${res.data?.metas?.length ?? 0} metas`);
|
|
243
|
+
return json({
|
|
244
|
+
metas: res.data?.metas ?? [],
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// -----------------------------------------------------------------
|
|
248
|
+
// COPY FILE
|
|
249
|
+
// -----------------------------------------------------------------
|
|
250
|
+
case 'copy': {
|
|
251
|
+
// 兼容处理:parent_node 作为 folder_token 的别名
|
|
252
|
+
const targetFolderToken = p.folder_token || p.parent_node;
|
|
253
|
+
log.info(`copy: file_token=${p.file_token}, name=${p.name}, type=${p.type}, folder_token=${targetFolderToken ?? '(root)'}`);
|
|
254
|
+
const res = await client.invoke('feishu_drive_file.copy', (sdk, opts) => sdk.drive.file.copy({
|
|
255
|
+
path: { file_token: p.file_token },
|
|
256
|
+
data: {
|
|
257
|
+
name: p.name,
|
|
258
|
+
type: p.type,
|
|
259
|
+
folder_token: targetFolderToken,
|
|
260
|
+
},
|
|
261
|
+
}, opts), { as: 'user' });
|
|
262
|
+
assertLarkOk(res);
|
|
263
|
+
const data = res.data;
|
|
264
|
+
log.info(`copy: new file_token=${data?.file?.token ?? 'unknown'}`);
|
|
265
|
+
return json({
|
|
266
|
+
file: data?.file,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
// -----------------------------------------------------------------
|
|
270
|
+
// MOVE FILE
|
|
271
|
+
// -----------------------------------------------------------------
|
|
272
|
+
case 'move': {
|
|
273
|
+
log.info(`move: file_token=${p.file_token}, type=${p.type}, folder_token=${p.folder_token}`);
|
|
274
|
+
const res = await client.invoke('feishu_drive_file.move', (sdk, opts) => sdk.drive.file.move({
|
|
275
|
+
path: { file_token: p.file_token },
|
|
276
|
+
data: {
|
|
277
|
+
type: p.type,
|
|
278
|
+
folder_token: p.folder_token,
|
|
279
|
+
},
|
|
280
|
+
}, opts), { as: 'user' });
|
|
281
|
+
assertLarkOk(res);
|
|
282
|
+
const data = res.data;
|
|
283
|
+
log.info(`move: task_id=${data?.task_id}`);
|
|
284
|
+
return json({
|
|
285
|
+
success: true,
|
|
286
|
+
task_id: data?.task_id,
|
|
287
|
+
file_token: p.file_token,
|
|
288
|
+
target_folder_token: p.folder_token,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
// -----------------------------------------------------------------
|
|
292
|
+
// DELETE FILE
|
|
293
|
+
// -----------------------------------------------------------------
|
|
294
|
+
case 'delete': {
|
|
295
|
+
log.info(`delete: file_token=${p.file_token}, type=${p.type}`);
|
|
296
|
+
const res = await client.invoke('feishu_drive_file.delete', (sdk, opts) => sdk.drive.file.delete({
|
|
297
|
+
path: { file_token: p.file_token },
|
|
298
|
+
params: {
|
|
299
|
+
type: p.type,
|
|
300
|
+
},
|
|
301
|
+
}, opts), { as: 'user' });
|
|
302
|
+
assertLarkOk(res);
|
|
303
|
+
const data = res.data;
|
|
304
|
+
log.info(`delete: task_id=${data?.task_id}`);
|
|
305
|
+
return json({
|
|
306
|
+
success: true,
|
|
307
|
+
task_id: data?.task_id,
|
|
308
|
+
file_token: p.file_token,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
// -----------------------------------------------------------------
|
|
312
|
+
// UPLOAD FILE
|
|
313
|
+
// -----------------------------------------------------------------
|
|
314
|
+
case 'upload': {
|
|
315
|
+
let fileBuffer;
|
|
316
|
+
let fileName;
|
|
317
|
+
let fileSize;
|
|
318
|
+
// 优先使用 file_path
|
|
319
|
+
if (p.file_path) {
|
|
320
|
+
log.info(`upload: reading from local file: ${p.file_path}`);
|
|
321
|
+
try {
|
|
322
|
+
// 读取文件内容
|
|
323
|
+
fileBuffer = await fs.readFile(p.file_path);
|
|
324
|
+
// 提取文件名(如果未提供)
|
|
325
|
+
fileName = p.file_name || path.basename(p.file_path);
|
|
326
|
+
// 计算文件大小(如果未提供)
|
|
327
|
+
fileSize = p.size || fileBuffer.length;
|
|
328
|
+
log.info(`upload: file_name=${fileName}, size=${fileSize}, parent=${p.parent_node || '(root)'}`);
|
|
329
|
+
}
|
|
330
|
+
catch (err) {
|
|
331
|
+
return json({
|
|
332
|
+
error: `failed to read local file: ${err instanceof Error ? err.message : String(err)}`,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
else if (p.file_content_base64) {
|
|
337
|
+
// 使用 base64 内容
|
|
338
|
+
if (!p.file_name || !p.size) {
|
|
339
|
+
return json({
|
|
340
|
+
error: 'file_name and size are required when using file_content_base64',
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
log.info(`upload: using base64 content, file_name=${p.file_name}, size=${p.size}, parent=${p.parent_node}`);
|
|
344
|
+
// Decode base64 to buffer
|
|
345
|
+
fileBuffer = Buffer.from(p.file_content_base64, 'base64');
|
|
346
|
+
fileName = p.file_name;
|
|
347
|
+
fileSize = p.size;
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
return json({
|
|
351
|
+
error: 'either file_path or file_content_base64 is required',
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
// 根据文件大小选择上传方式
|
|
355
|
+
if (fileSize <= SMALL_FILE_THRESHOLD) {
|
|
356
|
+
// 小文件:使用一次上传
|
|
357
|
+
log.info(`upload: using upload_all (file size ${fileSize} <= 15MB)`);
|
|
358
|
+
const res = await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadAll({
|
|
359
|
+
data: {
|
|
360
|
+
file_name: fileName,
|
|
361
|
+
parent_type: 'explorer',
|
|
362
|
+
parent_node: p.parent_node || '',
|
|
363
|
+
size: fileSize,
|
|
364
|
+
file: fileBuffer,
|
|
365
|
+
},
|
|
366
|
+
}, opts), { as: 'user' });
|
|
367
|
+
assertLarkOk(res);
|
|
368
|
+
log.info(`upload: file_token=${res.data?.file_token}`);
|
|
369
|
+
return json({
|
|
370
|
+
file_token: res.data?.file_token,
|
|
371
|
+
file_name: fileName,
|
|
372
|
+
size: fileSize,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
// 大文件:使用分片上传
|
|
377
|
+
log.info(`upload: using chunked upload (file size ${fileSize} > 15MB)`);
|
|
378
|
+
// 1. 预上传
|
|
379
|
+
log.info(`upload: step 1 - prepare upload`);
|
|
380
|
+
const prepareRes = await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadPrepare({
|
|
381
|
+
data: {
|
|
382
|
+
file_name: fileName,
|
|
383
|
+
parent_type: 'explorer',
|
|
384
|
+
parent_node: p.parent_node || '',
|
|
385
|
+
size: fileSize,
|
|
386
|
+
},
|
|
387
|
+
}, opts), { as: 'user' });
|
|
388
|
+
log.info(`upload: prepareRes = ${JSON.stringify(prepareRes)}`);
|
|
389
|
+
if (!prepareRes) {
|
|
390
|
+
return json({ error: 'pre-upload failed: empty response' });
|
|
391
|
+
}
|
|
392
|
+
assertLarkOk(prepareRes);
|
|
393
|
+
const { upload_id, block_size, block_num } = prepareRes.data;
|
|
394
|
+
log.info(`upload: got upload_id=${upload_id}, block_num=${block_num}, block_size=${block_size}`);
|
|
395
|
+
// 2. 上传分片
|
|
396
|
+
log.info(`upload: step 2 - uploading ${block_num} chunks`);
|
|
397
|
+
for (let seq = 0; seq < block_num; seq++) {
|
|
398
|
+
const start = seq * block_size;
|
|
399
|
+
const end = Math.min(start + block_size, fileSize);
|
|
400
|
+
const chunkBuffer = fileBuffer.subarray(start, end);
|
|
401
|
+
log.info(`upload: uploading chunk ${seq + 1}/${block_num} (${chunkBuffer.length} bytes)`);
|
|
402
|
+
await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadPart({
|
|
403
|
+
data: {
|
|
404
|
+
upload_id: String(upload_id),
|
|
405
|
+
seq: Number(seq),
|
|
406
|
+
size: Number(chunkBuffer.length),
|
|
407
|
+
file: chunkBuffer,
|
|
408
|
+
},
|
|
409
|
+
}, opts), { as: 'user' });
|
|
410
|
+
log.info(`upload: chunk ${seq + 1}/${block_num} uploaded successfully`);
|
|
411
|
+
}
|
|
412
|
+
// 3. 完成上传
|
|
413
|
+
log.info(`upload: step 3 - finish upload`);
|
|
414
|
+
const finishRes = await client.invoke('feishu_drive_file.upload', (sdk, opts) => sdk.drive.file.uploadFinish({
|
|
415
|
+
data: {
|
|
416
|
+
upload_id,
|
|
417
|
+
block_num,
|
|
418
|
+
},
|
|
419
|
+
}, opts), { as: 'user' });
|
|
420
|
+
assertLarkOk(finishRes);
|
|
421
|
+
log.info(`upload: file_token=${finishRes.data?.file_token}`);
|
|
422
|
+
return json({
|
|
423
|
+
file_token: finishRes.data?.file_token,
|
|
424
|
+
file_name: fileName,
|
|
425
|
+
size: fileSize,
|
|
426
|
+
upload_method: 'chunked',
|
|
427
|
+
chunks_uploaded: block_num,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
// -----------------------------------------------------------------
|
|
432
|
+
// DOWNLOAD FILE
|
|
433
|
+
// -----------------------------------------------------------------
|
|
434
|
+
case 'download': {
|
|
435
|
+
log.info(`download: file_token=${p.file_token}`);
|
|
436
|
+
const res = await client.invoke('feishu_drive_file.download', (sdk, opts) => sdk.drive.file.download({
|
|
437
|
+
path: { file_token: p.file_token },
|
|
438
|
+
}, opts), { as: 'user' });
|
|
439
|
+
// File download returns Buffer through getReadableStream
|
|
440
|
+
const stream = res.getReadableStream();
|
|
441
|
+
const chunks = [];
|
|
442
|
+
for await (const chunk of stream) {
|
|
443
|
+
chunks.push(chunk);
|
|
444
|
+
}
|
|
445
|
+
const fileBuffer = Buffer.concat(chunks);
|
|
446
|
+
log.info(`download: file size=${fileBuffer.length} bytes`);
|
|
447
|
+
// 如果提供了 output_path,保存到本地文件
|
|
448
|
+
if (p.output_path) {
|
|
449
|
+
try {
|
|
450
|
+
// output_path 必须是完整文件路径
|
|
451
|
+
// 确保父目录存在
|
|
452
|
+
await fs.mkdir(path.dirname(p.output_path), { recursive: true });
|
|
453
|
+
// 写入文件
|
|
454
|
+
await fs.writeFile(p.output_path, fileBuffer);
|
|
455
|
+
log.info(`download: saved to ${p.output_path}`);
|
|
456
|
+
return json({
|
|
457
|
+
saved_path: p.output_path,
|
|
458
|
+
size: fileBuffer.length,
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
catch (err) {
|
|
462
|
+
return json({
|
|
463
|
+
error: `failed to save file: ${err instanceof Error ? err.message : String(err)}`,
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
// 没有提供 output_path,返回 base64
|
|
469
|
+
const base64Content = fileBuffer.toString('base64');
|
|
470
|
+
return json({
|
|
471
|
+
file_content_base64: base64Content,
|
|
472
|
+
size: fileBuffer.length,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
catch (err) {
|
|
479
|
+
return await handleInvokeErrorWithAutoAuth(err, cfg);
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
}, { name: 'feishu_drive_file' });
|
|
483
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Drive 工具集
|
|
6
|
+
* 统一导出所有云空间相关工具的注册函数
|
|
7
|
+
*/
|
|
8
|
+
import type { OpenClawPluginApi } from 'openclaw/plugin-sdk';
|
|
9
|
+
/**
|
|
10
|
+
* 注册所有 Drive 工具
|
|
11
|
+
*/
|
|
12
|
+
export declare function registerFeishuDriveTools(api: OpenClawPluginApi): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 ByteDance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* Drive 工具集
|
|
6
|
+
* 统一导出所有云空间相关工具的注册函数
|
|
7
|
+
*/
|
|
8
|
+
import { getEnabledLarkAccounts } from '../../../core/accounts';
|
|
9
|
+
import { resolveAnyEnabledToolsConfig } from '../../../core/tools-config';
|
|
10
|
+
import { registerFeishuDriveFileTool } from './file';
|
|
11
|
+
import { registerDocCommentsTool } from './doc-comments';
|
|
12
|
+
import { registerDocMediaTool } from './doc-media';
|
|
13
|
+
/**
|
|
14
|
+
* 注册所有 Drive 工具
|
|
15
|
+
*/
|
|
16
|
+
export function registerFeishuDriveTools(api) {
|
|
17
|
+
if (!api.config) {
|
|
18
|
+
api.logger.debug?.('feishu_drive: No config available, skipping');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const accounts = getEnabledLarkAccounts(api.config);
|
|
22
|
+
if (accounts.length === 0) {
|
|
23
|
+
api.logger.debug?.('feishu_drive: No Feishu accounts configured, skipping');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const toolsCfg = resolveAnyEnabledToolsConfig(accounts);
|
|
27
|
+
if (!toolsCfg.drive) {
|
|
28
|
+
api.logger.debug?.('feishu_drive: drive tool disabled in all accounts');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// 注册所有工具
|
|
32
|
+
registerFeishuDriveFileTool(api);
|
|
33
|
+
registerDocCommentsTool(api);
|
|
34
|
+
registerDocMediaTool(api);
|
|
35
|
+
api.logger.info?.('feishu_drive: Registered feishu_drive_file, feishu_doc_comments, feishu_doc_media');
|
|
36
|
+
}
|