@libai168/dsh-tool-google-drive 0.2.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Local developer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # dsh-tool-google-drive
2
+
3
+ [English](README.md) | [中文](README.zh.md)
4
+
5
+ A Cordis tool plugin that gives [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (`dsh`) Google Workspace read capabilities. Agents can verify credentials, search Drive files, inspect file metadata and sharing/revision history, export Google Workspace file content, list Shared Drives, read Google Docs text, and read Google Sheets metadata/values.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @libai168/dsh-tool-google-drive
11
+ ```
12
+
13
+ Requires `@deepseek-ai/cordis` (^4.0.1) and `@deepseek-ai/dsh-tools` (^0.1.0-rc.6) as peer dependencies.
14
+
15
+ ## Configuration
16
+
17
+ ```yaml
18
+ - name: 'github:LJH-snow/dsh-tool-google-drive'
19
+ config:
20
+ accessToken: 'ya29.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
21
+ # or OAuth refresh credentials:
22
+ # clientId: 'xxxxxxxx.apps.googleusercontent.com'
23
+ # clientSecret: 'xxxxxxxxxxxxxxxxxxxx'
24
+ # refreshToken: '1//xxxxxxxxxxxxxxxxxxxxxxxx'
25
+ # baseUrl: 'https://www.googleapis.com/drive/v3'
26
+ # tokenUrl: 'https://oauth2.googleapis.com/token'
27
+ # timeoutMs: 15000
28
+ ```
29
+
30
+ Recommended read-only OAuth scopes:
31
+
32
+ - Drive metadata/search: `https://www.googleapis.com/auth/drive.metadata.readonly`
33
+ - Drive export/content read: `https://www.googleapis.com/auth/drive.readonly`
34
+ - Docs read: `https://www.googleapis.com/auth/documents.readonly`
35
+ - Sheets read: `https://www.googleapis.com/auth/spreadsheets.readonly`
36
+
37
+ ## OAuth helper
38
+
39
+ This package includes a small no-dependency helper that generates a Google OAuth consent URL, captures the loopback callback, exchanges the authorization code, and prints a ready-to-copy Cordis config snippet with a refresh token.
40
+
41
+ 1. In Google Cloud Console, create or select an OAuth client. Add this redirect URI when your client type requires an explicit redirect URI:
42
+
43
+ ```text
44
+ http://127.0.0.1:53682/oauth2callback
45
+ ```
46
+
47
+ 2. Run the helper from this repository or from an installed package checkout:
48
+
49
+ ```sh
50
+ npm run auth:google -- --client-id 'xxxxxxxx.apps.googleusercontent.com' --client-secret 'xxxxxxxxxxxxxxxxxxxx'
51
+ ```
52
+
53
+ If the browser cannot be opened automatically, use `--no-open` and paste the printed URL manually:
54
+
55
+ ```sh
56
+ npm run auth:google -- --client-id 'xxxxxxxx.apps.googleusercontent.com' --client-secret 'xxxxxxxxxxxxxxxxxxxx' --no-open
57
+ ```
58
+
59
+ 3. After approval, copy the printed YAML snippet into your `dsh` / Cordis config.
60
+
61
+ Useful options:
62
+
63
+ - `--print-url` prints the authorization URL without starting the local callback server or making network calls. The URL never includes the client secret.
64
+ - `--redirect-uri` or `--port` changes the callback URL when your OAuth client uses a different loopback URI.
65
+ - `--scope` can be repeated, and `--scopes` accepts a space- or comma-separated scope list when you want narrower authorization.
66
+ - `--code` exchanges a manually copied authorization code without starting the callback server; pass `--code-verifier` too if the code came from a prior `--print-url` run.
67
+
68
+ The helper requests offline access with consent prompting so Google can return a refresh token. Keep the client secret and refresh token private; do not commit them to git.
69
+
70
+ ## Tools
71
+
72
+ | Tool | Description | Write |
73
+ |---|---|---|
74
+ | `gdrive_auth_test` | Verify Google Drive credentials and return token metadata | no |
75
+ | `gdrive_list_files` | List or search Drive files by query and pagination | no |
76
+ | `gdrive_get_file` | Get one Drive file's metadata by file ID | no |
77
+ | `gdrive_list_permissions` | List file/folder/shared-drive sharing permissions with pagination | no |
78
+ | `gdrive_list_revisions` | List a file's revision metadata with pagination | no |
79
+ | `gdrive_export_file` | Export a Google Workspace file to text or base64 for binary MIME types | no |
80
+ | `gdrive_list_shared_drives` | List Shared Drives with pagination and query support | no |
81
+ | `gdrive_get_shared_drive` | Get one Shared Drive metadata record | no |
82
+ | `gdocs_get_document` | Read a Google Docs document structure and extracted text | no |
83
+ | `gsheets_get_spreadsheet` | Read spreadsheet metadata and sheet properties | no |
84
+ | `gsheets_get_values` | Read values from one A1 range | no |
85
+
86
+ ## Drive query examples
87
+
88
+ - `name contains 'report' and trashed = false`
89
+ - `mimeType = 'application/pdf' and modifiedTime > '2026-08-01T00:00:00'`
90
+ - `fullText contains 'quarterly review'`
91
+
92
+ ## Common workflows
93
+
94
+ ```text
95
+ # Search in My Drive or visible Drive items
96
+ gdrive_list_files({ query: "name contains 'roadmap' and trashed = false", orderBy: 'modifiedTime desc' })
97
+
98
+ # Search across Shared Drives
99
+ gdrive_list_shared_drives({ pageSize: 20 })
100
+ gdrive_list_files({ corpora: 'allDrives', includeItemsFromAllDrives: true, supportsAllDrives: true })
101
+
102
+ # Export a Google Doc as plain text
103
+ gdrive_export_file({ fileId: 'doc_file_id', exportMimeType: 'text/plain' })
104
+ gdrive_export_file({ fileId: 'doc_file_id', exportMimeType: 'application/pdf', responseEncoding: 'base64' })
105
+
106
+ # Inspect sharing and revision history
107
+ gdrive_list_permissions({ fileId: 'file_id', pageSize: 50, supportsAllDrives: true })
108
+ gdrive_list_revisions({ fileId: 'file_id', pageSize: 50 })
109
+
110
+ # Read Docs and Sheets directly
111
+ gdocs_get_document({ documentId: 'doc_id' })
112
+ gsheets_get_spreadsheet({ spreadsheetId: 'spreadsheet_id' })
113
+ gsheets_get_values({ spreadsheetId: 'spreadsheet_id', range: 'Sheet1!A1:D20' })
114
+ ```
115
+
116
+ Permission and revision listings return an opaque `nextPageToken`; pass it back as `pageToken` to continue. `gdrive_list_permissions` can include shared-drive and domain-admin flags when the OAuth principal has those permissions. Permission email addresses, revision download URLs, and exported content are returned only by explicitly requested read tools; treat them as sensitive workspace data.
117
+
118
+ ## Development
119
+
120
+ ```sh
121
+ npm install
122
+ npm run typecheck
123
+ npm test
124
+ npm run build
125
+ ```
126
+
127
+ ## License
128
+
129
+ [MIT](LICENSE)
package/README.zh.md ADDED
@@ -0,0 +1,129 @@
1
+ # dsh-tool-google-drive
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 为 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(`dsh`)提供 Google Workspace 只读集成能力的 Cordis 工具插件。Agent 可以验证凭证、搜索 Drive 文件、查看文件元数据与共享/修订历史、导出 Google Workspace 文件内容、列出共享云端硬盘、读取 Google Docs 文本,以及读取 Google Sheets 元数据/单元格值。
6
+
7
+ ## 安装
8
+
9
+ ```sh
10
+ npm install @libai168/dsh-tool-google-drive
11
+ ```
12
+
13
+ 需要 `@deepseek-ai/cordis`(^4.0.1)与 `@deepseek-ai/dsh-tools`(^0.1.0-rc.6)作为 peer 依赖。
14
+
15
+ ## 配置
16
+
17
+ ```yaml
18
+ - name: 'github:LJH-snow/dsh-tool-google-drive'
19
+ config:
20
+ accessToken: 'ya29.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
21
+ # 或者使用 OAuth 刷新凭证:
22
+ # clientId: 'xxxxxxxx.apps.googleusercontent.com'
23
+ # clientSecret: 'xxxxxxxxxxxxxxxxxxxx'
24
+ # refreshToken: '1//xxxxxxxxxxxxxxxxxxxxxxxx'
25
+ # baseUrl: 'https://www.googleapis.com/drive/v3'
26
+ # tokenUrl: 'https://oauth2.googleapis.com/token'
27
+ # timeoutMs: 15000
28
+ ```
29
+
30
+ 推荐的只读 OAuth scopes:
31
+
32
+ - Drive 元数据/搜索:`https://www.googleapis.com/auth/drive.metadata.readonly`
33
+ - Drive 导出/内容读取:`https://www.googleapis.com/auth/drive.readonly`
34
+ - Docs 读取:`https://www.googleapis.com/auth/documents.readonly`
35
+ - Sheets 读取:`https://www.googleapis.com/auth/spreadsheets.readonly`
36
+
37
+ ## OAuth 授权辅助脚本
38
+
39
+ 本包内置一个无额外依赖的辅助脚本:生成 Google OAuth 授权 URL、监听本机回调、用授权码换取 token,并输出可直接复制到 Cordis 配置里的 `refreshToken` 片段。
40
+
41
+ 1. 在 Google Cloud Console 创建或选择 OAuth Client。如果客户端类型需要显式配置回调地址,请加入:
42
+
43
+ ```text
44
+ http://127.0.0.1:53682/oauth2callback
45
+ ```
46
+
47
+ 2. 在本仓库或已安装包的工作目录运行:
48
+
49
+ ```sh
50
+ npm run auth:google -- --client-id 'xxxxxxxx.apps.googleusercontent.com' --client-secret 'xxxxxxxxxxxxxxxxxxxx'
51
+ ```
52
+
53
+ 如果无法自动打开浏览器,使用 `--no-open`,然后手动打开终端里打印的 URL:
54
+
55
+ ```sh
56
+ npm run auth:google -- --client-id 'xxxxxxxx.apps.googleusercontent.com' --client-secret 'xxxxxxxxxxxxxxxxxxxx' --no-open
57
+ ```
58
+
59
+ 3. 授权完成后,把终端输出的 YAML 片段复制到 `dsh` / Cordis 配置中。
60
+
61
+ 常用选项:
62
+
63
+ - `--print-url` 只打印授权 URL,不启动本机回调服务,也不发起网络请求;URL 不会包含 client secret。
64
+ - `--redirect-uri` 或 `--port` 可在 OAuth Client 使用不同 loopback URI 时调整回调地址。
65
+ - `--scope` 可重复传入;`--scopes` 支持空格或逗号分隔的 scope 列表,方便收窄授权范围。
66
+ - `--code` 可直接交换手动复制的授权码,不启动回调服务;如果授权码来自之前的 `--print-url` 输出,请同时传入 `--code-verifier`。
67
+
68
+ 脚本会请求 offline access 并强制 consent prompt,以便 Google 返回 refresh token。请妥善保管 client secret 与 refresh token,不要提交到 git。
69
+
70
+ ## 工具
71
+
72
+ | 工具 | 说明 | 写操作 |
73
+ |---|---|---|
74
+ | `gdrive_auth_test` | 验证 Google Drive 凭证并返回 token 元信息 | 否 |
75
+ | `gdrive_list_files` | 按查询与分页列出或搜索 Drive 文件 | 否 |
76
+ | `gdrive_get_file` | 按文件 ID 获取 Drive 文件元数据 | 否 |
77
+ | `gdrive_list_permissions` | 分页列出文件、文件夹或共享云端硬盘的共享权限 | 否 |
78
+ | `gdrive_list_revisions` | 分页列出文件的修订元数据 | 否 |
79
+ | `gdrive_export_file` | 将 Google Workspace 文件导出为文本,或将二进制 MIME 类型导出为 base64 | 否 |
80
+ | `gdrive_list_shared_drives` | 列出共享云端硬盘,支持分页与查询 | 否 |
81
+ | `gdrive_get_shared_drive` | 获取单个共享云端硬盘元数据 | 否 |
82
+ | `gdocs_get_document` | 读取 Google Docs 文档结构与提取文本 | 否 |
83
+ | `gsheets_get_spreadsheet` | 读取 Google Sheets 表格元数据与工作表属性 | 否 |
84
+ | `gsheets_get_values` | 读取一个 A1 范围内的单元格值 | 否 |
85
+
86
+ ## Drive 查询示例
87
+
88
+ - `name contains 'report' and trashed = false`
89
+ - `mimeType = 'application/pdf' and modifiedTime > '2026-08-01T00:00:00'`
90
+ - `fullText contains 'quarterly review'`
91
+
92
+ ## 常见工作流
93
+
94
+ ```text
95
+ # 搜索 My Drive 或可见文件
96
+ gdrive_list_files({ query: "name contains 'roadmap' and trashed = false", orderBy: 'modifiedTime desc' })
97
+
98
+ # 跨共享云端硬盘搜索
99
+ gdrive_list_shared_drives({ pageSize: 20 })
100
+ gdrive_list_files({ corpora: 'allDrives', includeItemsFromAllDrives: true, supportsAllDrives: true })
101
+
102
+ # 将 Google Docs 导出为纯文本
103
+ gdrive_export_file({ fileId: 'doc_file_id', exportMimeType: 'text/plain' })
104
+ gdrive_export_file({ fileId: 'doc_file_id', exportMimeType: 'application/pdf', responseEncoding: 'base64' })
105
+
106
+ # 查看共享权限和修订历史
107
+ gdrive_list_permissions({ fileId: 'file_id', pageSize: 50, supportsAllDrives: true })
108
+ gdrive_list_revisions({ fileId: 'file_id', pageSize: 50 })
109
+
110
+ # 直接读取 Docs 与 Sheets
111
+ gdocs_get_document({ documentId: 'doc_id' })
112
+ gsheets_get_spreadsheet({ spreadsheetId: 'spreadsheet_id' })
113
+ gsheets_get_values({ spreadsheetId: 'spreadsheet_id', range: 'Sheet1!A1:D20' })
114
+ ```
115
+
116
+ 权限和修订列表会返回不透明的 `nextPageToken`;把它作为 `pageToken` 传回即可继续分页。`gdrive_list_permissions` 支持在 OAuth 主体具备权限时传入共享云端硬盘和域管理员参数。权限邮箱、修订下载 URL 以及导出内容只会由明确调用的只读工具返回,请将它们视为敏感工作区数据。
117
+
118
+ ## 开发
119
+
120
+ ```sh
121
+ npm install
122
+ npm run typecheck
123
+ npm test
124
+ npm run build
125
+ ```
126
+
127
+ ## 许可证
128
+
129
+ [MIT](LICENSE)