IronClaw google-drive 扩展:12 个 Google Drive 工具包的清单、认证与 WASM 实现解析
人工智能AI 应用交互助手AI Agent【免费下载链接】ironclawIronClaw is an Agent OS focused on privacy, security and extensibility项目地址https://gitcode.com/gh_mirrors/iro/ironclaw点击查看免费下载本指南围绕 IronClaw 的google-drive扩展包展开它是一个纯数据包data-only package以 WASM 访客guest形式提供 12 个文件管理工具覆盖 Google Drive 的搜索、读取、上传、更新、分享与共享云端硬盘操作并与 Gmail 等google-*系列扩展共用一套 Google OAuth 凭证。读完本文你将掌握该扩展的目录结构、清单声明方式、OAuth 凭证注入与作用域分级、每个工具的入参契约以及底层 WASM 访客如何通过宿主 HTTP 能力调用 Drive API v3。包概览一个清单驱动的自包含目录在crates/extensions/packages/下每个可安装扩展都是自包含目录。google-drive扩展的核心身份信息记录在 crates/extensions/packages/google-drive/README.md扩展 idgoogle-drive表面Surfaces12 个工具google-drive.list_files…google-drive.list_shared_drives[auth.google]认证段凭证权威Vendorgoogle与 gmail 及其他google-*扩展共享运行时wasm提交产物在wasm/访客源码在wasm-src/内容manifest.toml、prompts/、schemas/、wasm/、wasm-src/由ironclaw_extension_support::packages::gsuite内嵌embed到宿主二进制测试/检查清单投影由cargo test -p ironclaw_extension_registry验证WASM 产物新鲜度由python3 scripts/ci/check-wasm-artifact-freshness.py校验从 crates/extensions/AGENTS.md 的包目录规则可知纯数据包没有自己的 crate只有实现 channel 适配器或 provider 表面的包才需要独立 crate。google-drive属于仅含 manifest 与资产数据、无 crate的一类其工具逻辑以 WASM 访客形式交付构建产物wasm/google_drive_tool.wasm被提交进仓库并由ironclaw_extension_support的PACKAGES清单注册见 crates/extensions/ironclaw_extension_support/src/packages/mod.rs 中的(gsuite::DRIVE_ID, gsuite::google_drive_bundle)与 crates/extensions/ironclaw_extension_support/src/packages/gsuite.rs。目录完整结构如下crates/extensions/packages/google-drive/ ├── manifest.toml # 扩展清单v3 架构 ├── prompts/google-drive/ # 12 个工具给模型看的操作说明 ├── schemas/google-drive/ # 12 个工具入参 JSON Schema raw_output.v1.json ├── wasm/google_drive_tool.wasm # 已提交的 WASM 编译产物 └── wasm-src/ # 访客源码Rust独立于工作区构建 ├── Cargo.toml └── src/{lib.rs, api.rs, types.rs}manifest.toml扩展清单声明了什么manifest.toml 采用schema_version reborn.extension_manifest.v3一次安装即被编译为解析后的、带摘要的记录生产环境投影只读解析记录、不重复解析 TOML。关键字段如下字段值说明id/name/versiongoogle-drive/Google Drive/0.1.0扩展身份与版本trustfirst_party_requested第一方请求信任级别[runtime]kind wasm,module wasm/google_drive_tool.wasm声明运行时类型与模块路径[admin_configuration]group_id vendor.google部署期 OAuth 客户端凭证与 Google 系列扩展共享部署期管理员配置[admin_configuration] group_id vendor.google display_name Google OAuth client credentials description Deployment OAuth client credentials shared by Google extensions. fields [ { handle google_oauth_client_id, label Google OAuth client ID, secret false, required true }, { handle google_oauth_client_secret, label Google OAuth client secret, secret true, required true }, ]两个字段google_oauth_client_id/google_oauth_client_secret是所有 Google 扩展共享的部署凭证句柄client secret 标记为secret true。它们被[auth.google]段的client_credentials引用。12 个工具的统一声明模板每个[[tools]]条目都声明origin_gate_matrix来源门控、effects效果声明、default_permission、visibility、输入 Schema 与提示文档引用以及凭证段[[tools.credentials]]。以list_files为例[[tools]] origin_gate_matrix { loop_run gated_unless_granted, product forbidden, automation forbidden } id google-drive.list_files description Search or list files and folders, including Google Sheets/spreadsheets by name or title. effects [network, use_secret] default_permission ask visibility model input_schema_ref schemas/google-drive/list_files.input.v1.json prompt_doc_ref prompts/google-drive/list_files.md [[tools.credentials]] handle google_runtime_token vendor google scopes [https://www.googleapis.com/auth/drive.readonly] audience { scheme https, host www.googleapis.com } injection { type header, name authorization, prefix Bearer }值得注意的治理细节来源门控三个来源中loop_run为gated_unless_granted循环运行中默认被门控除非已授权product与automation一律forbidden——即该扩展的工具不允许出现在产品界面与自动化调用路径上。默认权限全部 12 个工具均为default_permission ask每次调用需要显式授权。效果声明读操作声明[network, use_secret]写操作额外声明[external_write]如 upload、update、create、delete、trash、share、remove_permission。凭证注入每个工具声明handle google_runtime_token由宿主在发送时以Authorization: Bearer token头注入WASM 访客永远看不到原始 OAuth token见api.rs模块注释All API calls go through the hosts HTTP capability... The WASM tool never sees the actual OAuth token.。作用域Scope分级清单严格区分读写作用域工具Scopelist_files、get_file、download_file、list_permissions、list_shared_driveshttps://www.googleapis.com/auth/drive.readonlyupload_file、update_file、create_folder、delete_file、trash_file、share_file、remove_permissionhttps://www.googleapis.com/auth/drive这与工具的effects声明保持一致只读工具不声明external_write。认证模型[auth.google] 与 OAuth 2.0 授权码流程清单末尾的[auth.google]段声明了完整的 OAuth 2.0 授权码authorization code流程参数[auth.google] method oauth2_code display_name Google account authorization_endpoint https://accounts.google.com/o/oauth2/v2/auth token_endpoint https://oauth2.googleapis.com/token pkce s256 scopes [https://www.googleapis.com/auth/drive.readonly, https://www.googleapis.com/auth/drive] extra_authorize_params { access_type offline, include_granted_scopes true, prompt consent } client_credentials { client_id_handle google_oauth_client_id, client_secret_handle google_oauth_client_secret } [auth.google.refresh] # Google refresh tokens for apps in testing publishing status expire after # 7 days of inactivity; the host auth engines keepalive sweep proactively # refreshes idle accounts well before this vendor lifetime. keepalive_idle_seconds 604800 [auth.google.token_response] access_token /access_token refresh_token /refresh_token expires_in /expires_in scope { path /scope }要点使用PKCES256增强授权码流程access_type offline换取 refresh tokenprompt consent强制每次授权弹窗。token_response用 JSONPath 式路径声明 token 响应字段的解析位置。keepalive 说明604800 秒 7 天Google 对处于 testing 发布状态的 apprefresh token 在闲置 7 天后过期。IronClaw 宿主认证引擎的 keepalive 扫描会在 vendor 生命周期到期之前主动刷新闲置账户。这一设计直接回答了为什么 7 天这个数字——它是对 Google 平台规则的主动防御而不是随意取值。12 个工具逐一解析从 wasm-src/src/lib.rs 的模块注释与types.rs的GoogleDriveAction枚举可以完整还原 12 个工具的语义。按能力分组如下分类工具 id功能关键入参搜索/读取google-drive.list_files用 Drive 查询语法搜索文件含按标题找 Sheet/Doc/Slidesquery、page_size、order_by、corpora、drive_id、page_token读取google-drive.get_file获取文件元数据file_id读取google-drive.download_file下载文本内容 / 导出 Workspace 文件 / 提取二进制文档文本file_id、export_mime_type写入google-drive.upload_file上传新文本文件multipartname、content、mime_type、parent_id、description写入google-drive.update_file重命名、移动、加星、改描述file_id、name、description、move_to_parent、starred写入google-drive.create_folder新建文件夹name、parent_id、description写入google-drive.delete_file永久删除file_id写入google-drive.trash_file移入回收站file_id共享google-drive.share_file与某人分享file_id、email、role、message共享google-drive.list_permissions查看共享权限file_id共享google-drive.remove_permission撤销权限file_id、permission_id共享盘google-drive.list_shared_drives列出共享云端硬盘page_size常用参数默认值来自 types.rspage_size默认25Drive API 上限 1000corpora默认user个人空间可选drive指定共享盘需配drive_id、domain组织范围、allDrives所有可访问mime_type上传默认text/plainrole分享默认reader可选commenter、writer、organizer来自 lib.rs 的官方调用示例{action: list_files, query: name contains report and mimeType application/pdf} {action: list_files, query: name spreadsheet title and mimeType application/vnd.google-apps.spreadsheet and trashed false} {action: list_files, corpora: drive, drive_id: 0ABcd..., query: trashed false} {action: share_file, file_id: abc123, email: alicecompany.com, role: writer}注意清单与提示文档中的约定宿主从 capability id 选择操作模型只提供 Schema 声明的参数不要包含action字段。例如 prompts/google-drive/list_files.md 明确写道The host selects this operation from the capability id. Provide only the parameters described by the input schema; do not include an action field. 访客端params_with_action会校验参数中不得出现action键否则返回invalid_parameters错误见 lib.rs。WASM 访客实现从 WIT 世界到 Drive API v3google-drive的访客是一个 WASM 组件通过wit-bindgen绑定sandboxed-tool世界WIT 定义在 crates/lanes/ironclaw_wasm/wit/tool.wit实现exports::near::agent::tool::Guesttrait。构建配置见 wasm-src/Cargo.tomlcrate-type [cdylib]release 开启opt-level s、lto、strip、codegen-units 1以缩小产物。执行分发action 从上下文解析execute入口调用execute_inner先从调用上下文ToolContext.capability_id解析出 action 名action_from_context再将 action 注入参数 JSONparams_with_action最后用 serde 反序列化到带标签的GoogleDriveAction枚举并按变体分发到api.rs的对应函数见 lib.rs。不支持的 capability id 会得到稳定的unsupported_google_drive_capability输入错误。自动派生 JSON Schema杜绝字段可选的幻觉types.rs中的GoogleDriveAction是#[serde(tag action, rename_all snake_case)]的带标签枚举并派生schemars::JsonSchema。访客的schema()函数用schemars::schema_for!从该枚举生成 JSON Schema每个枚举变体成为oneOf条目带自己的required数组因此模型看到action get_file时file_id是必填。这一设计的动机在 types.rs 与单元测试中有明确记载此前手写扁平 Schema 把所有字段标为可选导致 LLM 频繁漏传必填字段运行时才报missing field file_id。现在 Schema 与 serde 契约同源永不错位。types.rs的测试直接验证了这一契约cargo test在 wasm-src 内运行get_file_requires_file_id_at_serde_layerserde 必须拒绝缺file_id的get_fileschema_marks_file_id_required_for_get_fileSchema 中get_file分支的required必须含file_id与actionschema_does_not_require_file_id_for_list_fileslist_files分支只要求action不得出现file_idapi.rsGoogle Drive API v3 的直接实现api.rs 定义了常量const DRIVE_API_BASE: str https://www.googleapis.com/drive/v3; const UPLOAD_API_BASE: str https://www.googleapis.com/upload/drive/v3; const MAX_DOWNLOAD_TEXT_BYTES: usize 1_000_000; // 内联读取上限 1MB const GOOGLE_API_AUTH_REQUIRED_ERROR: str google_api_error_status_401;所有请求经宿主host::http_request发出宿主负责凭证注入与限流。关键实现点list_files固定带上supportsAllDrivestrue与includeItemsFromAllDrivestrue按需拼接q、orderBy、driveId、pageToken字段投影使用FILE_FIELDSid、name、mimeType、description、size、createdTime、modifiedTime、webViewLink、parents、shared、starred、trashed、ownedByMe、driveId、owners。download_file先get_file取元数据。Google Workspace 文件走/export?mimeType导出默认映射Docs→text/plain、Sheets→text/csv、Slides→text/plain、Drawings→image/svgxml普通文件走?altmedia。文本可直接内联返回二进制PDF/PPTX/DOCX/XLSX以 base64 编码到content_base64返回由宿主运行时解码并运行文档文本提取器把提取出的文本替换回content字段后才到达模型见DownloadResult文档注释。content与content_base64二选一。大小守卫内联上限 1MB。超过声明大小或下载后实际字节数时不是返回晦涩错误而是返回一条模型可见的说明消息[File too large to read inline: X.X MB exceeds the 1 MB limit... Ask the user to share a smaller file or paste the relevant excerpt.] 且用u64解析声明大小避免 wasm32 上usize32 位溢出绕过守卫测试覆盖了 5GB 声明大小。upload_filemultipart/related 上传到UPLOAD_API_BASE/files?uploadTypemultipart边界串由multipart_boundary基于元数据与内容哈希生成并确保不出现在两段内容中有对应测试。update_filePATCH 合并补丁移动文件时先get_file取当前 parents再组合addParents与removeParents参数。delete/trash 的差异delete_file直接DELETE files/{id}永久删除trash_file用PATCH {trashed: true}进回收站。错误语义HTTP 401 映射为ErrorKind::AuthRequired 稳定码google_api_error_status_401宿主可据此触发重新授权其他非 2xx 映射为ErrorKind::Clientapi_status_{status}消息统一经bounded_message截断到 512 字符。api.rs的单元测试覆盖了 401/429 的错误映射、multipart 边界隔离、大小上限消息的诚实措辞too large to read inline 且包含实际大小等行为。输入 Schema 与提示文档模型可读的契约schemas/google-drive/下每个工具一个*.input.v1.jsonDraft-07另有raw_output.v1.json。以 list_files.input.v1.json 为例它声明了query、page_size默认 25、order_by、corpora默认 user、drive_id、page_token六个字段且additionalProperties: false——不允许清单与 Schema 之外的字段。上传类 Schema如 upload_file.input.v1.json则用required: [name, content]声明必填项。prompts/google-drive/下 12 个 Markdown 是给模型的操作手册交代该工具的适用场景。例如 download_file.md 强调读取、总结、分析任何 Drive 文件都用它——文本与 Docs/Sheets/Slides 直接返回文本二进制办公文档与 PDF 自动转为提取文本You do not need a shell, a downloader, or any other tool first。构建、产物新鲜度与测试由于访客 crate 被排除在工作区构建图之外WASM 产物是带外构建并提交进仓库的。构建与校验链路见 crates/extensions/AGENTS.md用./scripts/build-wasm-extensions.sh --first-party从wasm-src/构建wasm/*.wasmCI 脚本 scripts/ci/check-wasm-artifact-freshness.py 将每个提交产物与wasm-src/目录树的摘要记录在 scripts/ci/wasm-src-digests.toml比对——只改wasm-src/而不重新构建、重新记录摘要CI 会失败清单投影manifest projection由cargo test -p ironclaw_extension_registry验证确保 12 个工具声明、凭证段、Schema 引用等被正确投影到解析记录中。运行时ironclaw_extension_support通过include_str!/include_bytes!将整个包目录manifest prompts schemas wasm内嵌进宿主二进制见 gsuite.rs 的google_drive_bundle()因此部署无需额外分发扩展文件。总结google-drive是 IronClaw 扩展体系中纯数据包 WASM 访客范式的典型样本清单manifest.toml声明了 12 个工具、来源门控、权限效果与凭证注入方式[auth.google]段以数据而非代码的方式描述了完整的 OAuth 授权码流程与 7 天 keepalive 策略WASM 访客借助wit-bindgen接入宿主的沙箱化 HTTP 能力用带标签枚举 schemars自动派生 Schema从源头消除了Schema 说可选、代码说必填的错位下载大文件时的诚实提示、二进制文档的 base64 回传提取、u64大小解析等细节则体现了面向 LLM 调用场景的工程取舍。想要把整套流程跑通并继续深入可依次阅读 crates/extensions/packages/google-drive/manifest.toml、wasm-src/src/lib.rs、wasm-src/src/api.rs并以 crates/extensions/AGENTS.md 的包目录规则与架构门控作为上下文。赞分享人工智能AI 应用交互助手AI Agent【免费下载链接】ironclawIronClaw is an Agent OS focused on privacy, security and extensibility项目地址https://gitcode.com/gh_mirrors/iro/ironclaw点击查看免费下载相关推荐IronClaw Google Drive 权限清单list_permissions 工具的参数、Schema 与 WASM 实现解析IronClaw Google Drive 权限清单list_permissions 工具的参数、Schema 与 WASM 实现解析 IronClaw 以「人工智能AI 应用交互助手AI AgentIronClaw Google Drive 扩展remove_permission 工具的安全权限撤销实战指南IronClaw Google Drive 扩展remove_permission 工具的安全权限撤销实战指南 本文基于 IronClaw 开源仓库中的 Go人工智能AI 应用交互助手AI AgentIronClaw Google Drive 扩展download_file 文件内容读取能力全解析IronClaw Google Drive 扩展download_file 文件内容读取能力全解析 导读 google drive.download_file人工智能AI 应用交互助手AI Agent创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考