grok-bot-sdk 0.0.0-stage → 0.75.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## 0.75.8
4
+
5
+ Protocol surface matched to the Grok Bot 0.75.8 desktop client. The package stays ESM, with no runtime dependencies.
6
+
7
+ - Default `x-cursor-client-version` is `0.75.8`.
8
+ - Login polling stops on HTTP 403 `{ "error": "sign_in_policy_violation" }` and throws `SIGN_IN_POLICY_VIOLATION`.
9
+ - Roster reads optional `role` and `addedTeamAgentsOnly`, and returns Slack and Teams connection records plus the additional `GrokBotAgent` scalars present in 0.75.8.
10
+ - `sendMessage` accepts `replyToId`, `replyQuote`, `taskId`, `language`, `richText`, and `machineId`. Delivery `4` (`REFUSED`) throws `SEND_REFUSED`.
11
+ - New read methods: `listSessions`, `listTranscript`, `listAgentStatuses`, `getSendStatus`, `listAgentTasks`, `listTasks`, `listSubagents`, `listAgentTodos`, `listAgentSkills`, `listDeletedAgentIds`, `getRuntimeCapabilities`, `getSandBoxRunState`.
12
+ - Watch events add `agent.state`, `computer.actions`, `box.state`, and `page.title.changed`. `bot.state.changed` includes `changedAtMs`.
13
+ - CLI read-only subcommands: `bots`, `sessions`, `transcript`, `tasks`, `capabilities`, `box`.
14
+ - Avatar derivation is unchanged (`grok-bot-0.70.2`). `pumpkin` is accepted as an explicit shape.
15
+
16
+ The checksum, ghost-mode default, and desktop chat enums `source=1`, `initiator=1`, `sendSource=1` are the same values the 0.75.8 client still sends for desktop chat.
17
+
18
+ ## 0.1.0
19
+
20
+ First release, matched to the Grok Bot 0.70.2 desktop client. From 0.75.8 on, the package version follows the Grok Bot version it targets.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RongleCat
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 CHANGED
@@ -1,3 +1,213 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="assets/avatars-row-dark.png" />
4
+ <img src="assets/avatars-row.png" alt="Five Grok Bot avatars. The default black circle is in the middle, with an orange cloud and a violet teardrop on the left, and a green hexagon and a blue squircle on the right." width="680" height="128" />
5
+ </picture>
6
+ </p>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ <h1 align="center">grok-bot-sdk</h1>
9
+
10
+ <p align="center"><strong>Unofficial Node.js SDK for the Grok Bot desktop client protocol</strong></p>
11
+ <p align="center"><em>Browser login · Account and bot roster · Sessions, transcript, and tasks · Normalized avatars · Send · Connect replies forwarded as SSE</em></p>
12
+ <p align="center"><a href="https://ronglecat.github.io/grok-bot-sdk/">https://ronglecat.github.io/grok-bot-sdk/</a></p>
13
+
14
+ <p align="center">
15
+ <a href="./README.md">English</a> ·
16
+ <a href="./README_ZH.md">中文</a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <a href="https://ronglecat.github.io/grok-bot-sdk/"><img src="https://img.shields.io/badge/docs-API%20reference-0ea5e9" alt="API docs" /></a>
21
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License" /></a>
22
+ <a href="https://github.com/RongleCat/grok-bot-sdk/stargazers"><img src="https://img.shields.io/github/stars/RongleCat/grok-bot-sdk?style=social" alt="GitHub stars" /></a>
23
+ <img src="https://img.shields.io/badge/node-%3E%3D22.13-339933?logo=node.js&logoColor=white" alt="Node.js" />
24
+ <img src="https://img.shields.io/badge/client-Grok%20Bot%200.75.8-lightgrey" alt="Grok Bot 0.75.8" />
25
+ <img src="https://img.shields.io/badge/note-unofficial-yellow" alt="Unofficial" />
26
+ </p>
27
+
28
+ <p align="center">
29
+ <a href="https://x.com/cgnot996"><img src="https://img.shields.io/badge/X-铁柱AGI%20%40cgnot996-black?logo=x&logoColor=white" alt="X 铁柱AGI" /></a>
30
+ <img src="https://img.shields.io/badge/WeChat-铁柱AGI-07C160?logo=wechat&logoColor=white" alt="WeChat 铁柱AGI" />
31
+ <a href="https://bot.tiezhu.si/"><img src="https://img.shields.io/badge/learn-bot.tiezhu.si-111111" alt="Grok Bot learning site" /></a>
32
+ </p>
33
+
34
+ <p align="center">
35
+ <img src="assets/wechat/mp-search-scan.png" alt="WeChat Search 铁柱AGI — scan to follow the official account" width="420" />
36
+ &nbsp;&nbsp;
37
+ <img src="assets/wechat/community-group-qr.png" alt="Author WeChat QR — add to join the paid community" width="200" />
38
+ </p>
39
+
40
+ <p align="center"><sub>Left: WeChat official account <strong>铁柱AGI</strong>. Right: the author's personal WeChat. The paid community is invite-only — add this WeChat and ask to join.</sub></p>
41
+
42
+ ---
43
+
44
+ > [!NOTE]
45
+ > **About this SDK.** grok-bot-sdk reproduces the browser login and the read, send, and reply-stream calls used by the Grok Bot **0.75.8** desktop client. It is an independent open-source library by [铁柱AGI](https://x.com/cgnot996). It is **not an xAI product, not a Cursor product, and not the official Grok Bot SDK**.
46
+ >
47
+ > The same author also builds [Grok App](https://github.com/RongleCat/grok-app), a desktop workbench for the local Grok Build CLI. Grok App and this SDK are different programs.
48
+
49
+ ---
50
+
51
+ ## Contents
52
+
53
+ - [Install](#install)
54
+ - [Authorize](#authorize)
55
+ - [Call](#call)
56
+ - [What this release includes](#what-this-release-includes)
57
+ - [Notes you should read](#notes-you-should-read)
58
+ - [Docs](#docs)
59
+ - [Related projects](#related-projects)
60
+ - [Author and community](#author-and-community)
61
+
62
+ ## Install
63
+
64
+ Node.js **22.13 or newer**. ESM only. The runtime has zero npm dependencies.
65
+
66
+ The package is published from this GitHub repository. It is not on the npm registry.
67
+
68
+ ```sh
69
+ npm install github:RongleCat/grok-bot-sdk
70
+ ```
71
+
72
+ ```js
73
+ import { GrokBotClient, createLogin, pollLogin } from 'grok-bot-sdk';
74
+ ```
75
+
76
+ ## Authorize
77
+
78
+ The normal path is a fresh browser login. It creates a session for this SDK and leaves the official client's saved login alone.
79
+
80
+ ```sh
81
+ npx grok-bot-sdk login --out ./credentials.json
82
+ ```
83
+
84
+ On macOS the command opens the system browser. Elsewhere, or with `--no-open`, it prints a `loginUrl`. Finish the login in that page. The command then writes `accessToken`, `refreshToken`, and `selectedTeamId` when the server returns one. The file mode is `0600`. The terminal output says the token is present. It does not print the token.
85
+
86
+ ```js
87
+ import { readFile } from 'node:fs/promises';
88
+ import { GrokBotClient } from 'grok-bot-sdk';
89
+
90
+ const saved = JSON.parse(await readFile('./credentials.json', 'utf8'));
91
+ const client = new GrokBotClient({
92
+ accessToken: saved.accessToken,
93
+ teamId: saved.selectedTeamId,
94
+ });
95
+ ```
96
+
97
+ You can also pass `GROK_BOT_ACCESS_TOKEN` in the environment. Keep that value out of shell history and logs.
98
+
99
+ A second, optional path reads the Grok Bot session already stored on this Mac:
100
+
101
+ ```js
102
+ import { desktopCredentials } from 'grok-bot-sdk/desktop';
103
+ import { GrokBotClient } from 'grok-bot-sdk';
104
+
105
+ const client = new GrokBotClient(await desktopCredentials());
106
+ ```
107
+
108
+ macOS shows the normal Keychain prompt for `Grok Bot Safe Storage`. Approve it yourself. If that stored token is no longer accepted, stop and use `login`.
109
+
110
+ Check the session without printing the account:
111
+
112
+ ```sh
113
+ npx grok-bot-sdk whoami --token-file ./credentials.json
114
+ ```
115
+
116
+ The full sequence, poll responses, headers, and the Mac path are in the [authorization guide](https://ronglecat.github.io/grok-bot-sdk/guide/auth).
117
+
118
+ ## Call
119
+
120
+ ```js
121
+ const me = await client.getMe();
122
+ const { bots, truncated } = await client.listBots();
123
+ const bot = bots[0];
124
+
125
+ const sent = await client.sendMessage({
126
+ botId: bot.id,
127
+ sessionId: bot.sessionId,
128
+ text: 'Summarize the notes I just sent.',
129
+ });
130
+
131
+ for await (const event of client.watchBot({
132
+ botId: bot.id,
133
+ sessionId: bot.sessionId,
134
+ })) {
135
+ if (event.type === 'message') {
136
+ // Replace the bubble for event.data.entryId with event.data.text.
137
+ }
138
+ }
139
+ ```
140
+
141
+ A backend that already authenticates its own user can return the SDK response directly:
142
+
143
+ ```js
144
+ return client.botEventsSSE({
145
+ botId: authorizedBot.id,
146
+ sessionId: authorizedBot.sessionId,
147
+ resumeFrom: request.headers.get('last-event-id') || undefined,
148
+ signal: request.signal,
149
+ });
150
+ ```
151
+
152
+ `Bot.id` is the agent UUID. Every bot includes `avatarShape`, `avatarColor`, and a normalized `avatar` object. When the roster omits a valid shape or color, the SDK derives that field from the agent UUID. The shape and the color are decided separately.
153
+
154
+ `examples/list-bots.mjs` prints the roster summary from a saved credentials file.
155
+
156
+ ## What this release includes
157
+
158
+ Verified against Grok Bot 0.75.8:
159
+
160
+ - One browser login continued into account read and the cloud bot roster.
161
+ - The same read path works with the Mac client's existing session.
162
+ - Roster records come back with one avatar shape, whether the server sent the fields or the SDK derived them. The avatar hash is still `grok-bot-0.70.2`. `pumpkin` is explicit only.
163
+ - `WatchGrokBotTranscripts` connects with Connect JSON, and an existing reply was forwarded through `botEventsSSE`.
164
+ - Read calls: `listSessions`, `listTranscript`, `listAgentStatuses`, `getSendStatus`, `listAgentTasks`, `listTasks`, `listSubagents`, `listAgentTodos`, `listAgentSkills`, `listDeletedAgentIds`, `getRuntimeCapabilities`, and `getSandBoxRunState`.
165
+ - Watch events also include `agent.state`, `computer.actions`, `box.state`, and `page.title.changed`.
166
+ - Offline tests cover login URL shape, avatar vectors, frame parsing, cursors, cancellation, SSE framing, send results, and the new read records.
167
+
168
+ The default client version string is `0.75.8`. Pass `version` when you know the client you are matching. The CLI also has read-only subcommands: `bots`, `sessions`, `transcript`, `tasks`, `capabilities`, and `box`.
169
+
170
+ ## Notes you should read
171
+
172
+ These limits are part of the contract. The [notes page](https://ronglecat.github.io/grok-bot-sdk/guide/notes) lists each one with the behavior to expect.
173
+
174
+ - The access token is an account credential. Store it like a password. The SDK does not refresh it, does not log it out, and does not revoke it when the process exits.
175
+ - `truncated: true` means the roster is incomplete. `includeTeamAgents` can include team records.
176
+ - `sendMessage` returning `accepted-box`, `accepted-temporal`, or `duplicate` means the server accepted delivery. It does not mean the bot has read or answered. `SEND_UNCONFIRMED` means you must not automatically send again.
177
+ - `attachmentPaths` are server references from an upload that already finished. This package does not upload local files and does not wake a cloud computer.
178
+ - Reply events carry the current full text of one transcript entry. Per-token streaming was not verified. The shape is not an OpenAI Chat Completions stream.
179
+ - The SDK does not reconnect, does not fill in omitted entry bodies, and does not render avatar animation.
180
+ - Put the account token on your server. The browser `EventSource` should call your backend.
181
+
182
+ ## Docs
183
+
184
+ The API site is VitePress, deployed with GitHub Pages: [ronglecat.github.io/grok-bot-sdk](https://ronglecat.github.io/grok-bot-sdk/).
185
+
186
+ English and Chinese are both in the site. The reference covers `GrokBotClient`, event types, SSE frames, avatar derivation, error codes, and the HTTP endpoints this SDK calls.
187
+
188
+ ```sh
189
+ npm install
190
+ npm test
191
+ npm run docs:dev
192
+ ```
193
+
194
+ ## Related projects
195
+
196
+ | Project | What it is |
197
+ |---|---|
198
+ | [Grok App](https://github.com/RongleCat/grok-app) | Open-source desktop workbench for the local Grok Build CLI. [grok-app.com](https://grok-app.com) |
199
+ | [awesome-grok-bot](https://github.com/RongleCat/awesome-grok-bot) | Grok Bot community index |
200
+ | [Grok Bot learning site](https://bot.tiezhu.si/) | From zero to a bot team: install, routines, cases, usage |
201
+
202
+ ## Author and community
203
+
204
+ | Channel | Where |
205
+ |---|---|
206
+ | X | [@cgnot996 (铁柱AGI)](https://x.com/cgnot996) |
207
+ | WeChat official account | Search **铁柱AGI**, or scan the left code above |
208
+ | Paid community | Add the author's WeChat with the right code, then ask to join |
209
+ | Learning site | [bot.tiezhu.si](https://bot.tiezhu.si/) |
210
+
211
+ The avatars at the top are the Grok Bot shapes and colors, with the default black circle in the middle. They are not an xAI logo.
212
+
213
+ MIT License. Copyright 2026 RongleCat.
package/README_ZH.md ADDED
@@ -0,0 +1,213 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="assets/avatars-row-dark.png" />
4
+ <img src="assets/avatars-row.png" alt="一排五个 Grok Bot 头像。中间是默认的黑色圆形,左边是橙色云朵和紫色水滴,右边是绿色六边形和蓝色圆角方块。" width="680" height="128" />
5
+ </picture>
6
+ </p>
7
+
8
+ <h1 align="center">grok-bot-sdk</h1>
9
+
10
+ <p align="center"><strong>Grok Bot 桌面客户端协议的非官方 Node.js SDK</strong></p>
11
+ <p align="center"><em>浏览器登录 · 账号与 Bot 名单 · 会话、转录与任务 · 统一头像 · 发送 · Connect 回复转发为 SSE</em></p>
12
+ <p align="center"><a href="https://ronglecat.github.io/grok-bot-sdk/zh/">https://ronglecat.github.io/grok-bot-sdk/zh/</a></p>
13
+
14
+ <p align="center">
15
+ <a href="./README.md">English</a> ·
16
+ <a href="./README_ZH.md">中文</a>
17
+ </p>
18
+
19
+ <p align="center">
20
+ <a href="https://ronglecat.github.io/grok-bot-sdk/zh/"><img src="https://img.shields.io/badge/docs-接口文档-0ea5e9" alt="接口文档" /></a>
21
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License" /></a>
22
+ <a href="https://github.com/RongleCat/grok-bot-sdk/stargazers"><img src="https://img.shields.io/github/stars/RongleCat/grok-bot-sdk?style=social" alt="GitHub stars" /></a>
23
+ <img src="https://img.shields.io/badge/node-%3E%3D22.13-339933?logo=node.js&logoColor=white" alt="Node.js" />
24
+ <img src="https://img.shields.io/badge/client-Grok%20Bot%200.75.8-lightgrey" alt="Grok Bot 0.75.8" />
25
+ <img src="https://img.shields.io/badge/note-unofficial-yellow" alt="非官方" />
26
+ </p>
27
+
28
+ <p align="center">
29
+ <a href="https://x.com/cgnot996"><img src="https://img.shields.io/badge/X-铁柱AGI%20%40cgnot996-black?logo=x&logoColor=white" alt="X 铁柱AGI" /></a>
30
+ <img src="https://img.shields.io/badge/微信公众号-铁柱AGI-07C160?logo=wechat&logoColor=white" alt="微信公众号 铁柱AGI" />
31
+ <a href="https://bot.tiezhu.si/"><img src="https://img.shields.io/badge/学习站-bot.tiezhu.si-111111" alt="Grok Bot 学习站" /></a>
32
+ </p>
33
+
34
+ <p align="center">
35
+ <img src="assets/wechat/mp-search-scan.png" alt="微信搜一搜 铁柱AGI,扫码关注公众号" width="420" />
36
+ &nbsp;&nbsp;
37
+ <img src="assets/wechat/community-group-qr.png" alt="作者个人微信二维码,添加后可申请加入付费交流群" width="200" />
38
+ </p>
39
+
40
+ <p align="center"><sub>左:微信公众号「铁柱AGI」。右:作者个人微信。付费交流群由作者邀请进入,扫码添加微信后说明来意。</sub></p>
41
+
42
+ ---
43
+
44
+ > [!NOTE]
45
+ > **关于这个 SDK。** grok-bot-sdk 复现 Grok Bot **0.75.8** 桌面客户端使用的浏览器登录,以及读取账号、读取名单、发送消息和订阅回复。作者是 [铁柱AGI](https://x.com/cgnot996)。它**不是 xAI 官方产品,不是 Cursor 官方产品,也不是 Grok Bot 官方 SDK**。
46
+ >
47
+ > 同一作者的 [Grok App](https://github.com/RongleCat/grok-app) 是本机 Grok Build CLI 的桌面工作台。Grok App 和这个 SDK 是两个程序。
48
+
49
+ ---
50
+
51
+ ## 目录
52
+
53
+ - [安装](#安装)
54
+ - [授权](#授权)
55
+ - [调用](#调用)
56
+ - [这一版包含什么](#这一版包含什么)
57
+ - [使用前要知道的事](#使用前要知道的事)
58
+ - [接口文档](#接口文档)
59
+ - [相关项目](#相关项目)
60
+ - [作者与社区](#作者与社区)
61
+
62
+ ## 安装
63
+
64
+ 需要 Node.js **22.13 或更高版本**。只提供 ESM。运行时没有 npm 依赖。
65
+
66
+ 包从本 GitHub 仓库安装,尚未发布到 npm registry。
67
+
68
+ ```sh
69
+ npm install github:RongleCat/grok-bot-sdk
70
+ ```
71
+
72
+ ```js
73
+ import { GrokBotClient, createLogin, pollLogin } from 'grok-bot-sdk';
74
+ ```
75
+
76
+ ## 授权
77
+
78
+ 常规路径是一次新的浏览器登录。它为这个 SDK 建立独立会话,不改写官方客户端已经保存的登录。
79
+
80
+ ```sh
81
+ npx grok-bot-sdk login --out ./credentials.json
82
+ ```
83
+
84
+ 在 macOS 上,命令会打开系统浏览器。其他系统,或者加上 `--no-open` 时,终端只打印 `loginUrl`。在页面里完成登录后,命令把 `accessToken`、`refreshToken`,以及服务端返回时的 `selectedTeamId`,写入指定文件。文件权限是 `0600`。终端只说明令牌已经写入,不打印令牌本身。
85
+
86
+ ```js
87
+ import { readFile } from 'node:fs/promises';
88
+ import { GrokBotClient } from 'grok-bot-sdk';
89
+
90
+ const saved = JSON.parse(await readFile('./credentials.json', 'utf8'));
91
+ const client = new GrokBotClient({
92
+ accessToken: saved.accessToken,
93
+ teamId: saved.selectedTeamId,
94
+ });
95
+ ```
96
+
97
+ 也可以把访问令牌放在环境变量 `GROK_BOT_ACCESS_TOKEN` 里。不要把它留在 shell 历史或日志里。
98
+
99
+ 另一条可选路径读取这台 Mac 上 Grok Bot 已经保存的会话:
100
+
101
+ ```js
102
+ import { desktopCredentials } from 'grok-bot-sdk/desktop';
103
+ import { GrokBotClient } from 'grok-bot-sdk';
104
+
105
+ const client = new GrokBotClient(await desktopCredentials());
106
+ ```
107
+
108
+ macOS 会为钥匙串项目 `Grok Bot Safe Storage` 弹出系统授权。由你自己点允许。若这份旧令牌已经被拒绝,停下来,改用 `login`。
109
+
110
+ 检查会话时不打印账号内容:
111
+
112
+ ```sh
113
+ npx grok-bot-sdk whoami --token-file ./credentials.json
114
+ ```
115
+
116
+ 完整顺序、轮询响应、请求头和 Mac 路径见[授权说明](https://ronglecat.github.io/grok-bot-sdk/zh/guide/auth)。
117
+
118
+ ## 调用
119
+
120
+ ```js
121
+ const me = await client.getMe();
122
+ const { bots, truncated } = await client.listBots();
123
+ const bot = bots[0];
124
+
125
+ const sent = await client.sendMessage({
126
+ botId: bot.id,
127
+ sessionId: bot.sessionId,
128
+ text: '总结我刚发过去的笔记。',
129
+ });
130
+
131
+ for await (const event of client.watchBot({
132
+ botId: bot.id,
133
+ sessionId: bot.sessionId,
134
+ })) {
135
+ if (event.type === 'message') {
136
+ // 用 event.data.text 替换 event.data.entryId 对应的那条消息。
137
+ }
138
+ }
139
+ ```
140
+
141
+ 已经认证过自己用户的后端,可以直接返回 SDK 的响应:
142
+
143
+ ```js
144
+ return client.botEventsSSE({
145
+ botId: authorizedBot.id,
146
+ sessionId: authorizedBot.sessionId,
147
+ resumeFrom: request.headers.get('last-event-id') || undefined,
148
+ signal: request.signal,
149
+ });
150
+ ```
151
+
152
+ `Bot.id` 是 Bot 的 UUID。每条记录都有 `avatarShape`、`avatarColor` 和统一的 `avatar` 对象。名单缺少有效形状或颜色时,SDK 用 agent UUID 补上该字段。形状和颜色分开决定。
153
+
154
+ `examples/list-bots.mjs` 用保存的凭据文件打印名单摘要。
155
+
156
+ ## 这一版包含什么
157
+
158
+ 对照 Grok Bot 0.75.8 核对过:
159
+
160
+ - 一次浏览器登录可以接着读账号和云端 Bot 名单。
161
+ - 用 Mac 客户端里已有的会话,可以走同一条读取路径。
162
+ - 名单里的每条记录都带回同一种头像结构。服务端带了字段就用字段,缺了就按 UUID 推算。头像哈希仍是 `grok-bot-0.70.2`。`pumpkin` 只在显式指定时出现。
163
+ - `WatchGrokBotTranscripts` 以 Connect JSON 接通,既有回复可以经 `botEventsSSE` 转发。
164
+ - 只读调用:`listSessions`、`listTranscript`、`listAgentStatuses`、`getSendStatus`、`listAgentTasks`、`listTasks`、`listSubagents`、`listAgentTodos`、`listAgentSkills`、`listDeletedAgentIds`、`getRuntimeCapabilities`、`getSandBoxRunState`。
165
+ - 订阅事件还包含 `agent.state`、`computer.actions`、`box.state` 和 `page.title.changed`。
166
+ - 离线测试覆盖登录 URL、头像向量、帧解析、游标、取消、SSE 帧、发送结果,以及新增的只读记录。
167
+
168
+ 默认客户端版本字符串是 `0.75.8`。你知道自己要匹配的客户端版本时,传入 `version`。CLI 还有只读子命令:`bots`、`sessions`、`transcript`、`tasks`、`capabilities`、`box`。
169
+
170
+ ## 使用前要知道的事
171
+
172
+ 这些边界就是这份 SDK 的约定。[注意事项](https://ronglecat.github.io/grok-bot-sdk/zh/guide/notes)逐条写了会看到的行为。
173
+
174
+ - 访问令牌是账号凭据,按密码保管。SDK 不刷新它,不替你登出,进程退出也不等于服务端撤销。
175
+ - `truncated: true` 表示名单不完整。`includeTeamAgents` 可能带上团队记录。
176
+ - `sendMessage` 返回 `accepted-box`、`accepted-temporal` 或 `duplicate`,只表示服务端接受了投递,不表示 Bot 已经阅读或回复。遇到 `SEND_UNCONFIRMED` 时,不要自动再发一次。
177
+ - `attachmentPaths` 是已经上传完成的服务端引用。这个包不上传本地文件,也不唤醒云电脑。
178
+ - 回复事件给出的是某一条记录当前的完整文本。逐 token 输出尚未验证。它也不是 OpenAI Chat Completions 的流格式。
179
+ - SDK 不自动重连,不补齐被省略的正文,也不渲染头像动画。
180
+ - 账号令牌放在你自己的服务端。浏览器里的 `EventSource` 只访问你的后端。
181
+
182
+ ## 接口文档
183
+
184
+ 文档站使用 VitePress,由 GitHub Pages 发布:[ronglecat.github.io/grok-bot-sdk/zh/](https://ronglecat.github.io/grok-bot-sdk/zh/)。
185
+
186
+ 站点包含中文和英文。参考页写明 `GrokBotClient`、事件类型、SSE 帧、头像推算、错误码,以及这个 SDK 实际调用的 HTTP 接口。
187
+
188
+ ```sh
189
+ npm install
190
+ npm test
191
+ npm run docs:dev
192
+ ```
193
+
194
+ ## 相关项目
195
+
196
+ | 项目 | 是什么 |
197
+ |---|---|
198
+ | [Grok App](https://github.com/RongleCat/grok-app) | 本机 Grok Build CLI 的开源桌面工作台。[grok-app.com](https://grok-app.com) |
199
+ | [awesome-grok-bot](https://github.com/RongleCat/awesome-grok-bot) | Grok Bot 社区索引 |
200
+ | [Grok Bot 学习站](https://bot.tiezhu.si/) | 从装好客户端到带一支 Bot 团队:安装、例程、案例、额度 |
201
+
202
+ ## 作者与社区
203
+
204
+ | 渠道 | 入口 |
205
+ |---|---|
206
+ | X | [@cgnot996(铁柱AGI)](https://x.com/cgnot996) |
207
+ | 微信公众号 | 搜索 **铁柱AGI**,或扫描上方左侧二维码 |
208
+ | 付费交流群 | 扫描上方右侧二维码添加作者微信,再说明要入群 |
209
+ | 学习站 | [bot.tiezhu.si](https://bot.tiezhu.si/) |
210
+
211
+ 页顶是一排 Grok Bot 头像,中间是默认的黑色圆形,左右是另外四种形状和颜色。这不是 xAI 的标志。
212
+
213
+ MIT License。Copyright 2026 RongleCat。
package/avatar.d.mts ADDED
@@ -0,0 +1,37 @@
1
+ export type AvatarSource = 'explicit' | 'id-default';
2
+ export interface CharacterAvatar {
3
+ shape: string;
4
+ color: string;
5
+ baseHex: string;
6
+ lightHex: string;
7
+ darkHex: string;
8
+ }
9
+ export interface ResolvedAvatar {
10
+ algorithmVersion: string;
11
+ kind: 'character' | 'picture';
12
+ character: CharacterAvatar;
13
+ sources: { shape: AvatarSource; color: AvatarSource };
14
+ picture: { url: string | null; version: string | null } | null;
15
+ }
16
+ export interface CloudAvatarRecord {
17
+ agentId: string;
18
+ avatarShape?: string | null;
19
+ avatarColor?: string | null;
20
+ avatarUrl?: string | null;
21
+ avatarDataUrl?: string | null;
22
+ avatarVersion?: string | null;
23
+ [key: string]: unknown;
24
+ }
25
+ export const AVATAR_ALGORITHM_VERSION: string;
26
+ export const DEFAULT_SHAPES: readonly string[];
27
+ export const VALID_SHAPES: readonly string[];
28
+ export const DEFAULT_COLORS: readonly string[];
29
+ export function hashBotId(key: string): number;
30
+ export function deriveDefaultAvatar(key: string): CharacterAvatar & {
31
+ algorithmVersion: string;
32
+ hash: number;
33
+ shapeHash: number;
34
+ shapeIndex: number;
35
+ colorIndex: number;
36
+ };
37
+ export function resolveAgentAvatar(agent: CloudAvatarRecord): ResolvedAvatar;
package/avatar.mjs ADDED
@@ -0,0 +1,69 @@
1
+ // Parameter derivation verified against Grok Bot 0.70.2 and again against 0.75.8.
2
+ // 0.75.8 keeps the same hash, salts, default shapes, and palette. It adds one
3
+ // explicit shape, pumpkin, behind the sand_pumpkin_2026 picker gate. Pumpkin is
4
+ // not part of the default hash set. This module does not load or execute the
5
+ // official renderer or its assets.
6
+ export const AVATAR_ALGORITHM_VERSION='grok-bot-0.70.2';
7
+ export const DEFAULT_SHAPES=Object.freeze(['blob','pebble','squircle','tablet','wedge','hex','cloud','teardrop']);
8
+ export const VALID_SHAPES=Object.freeze(['blob','pebble','bean','egg','squircle','tablet','capsule','cylinder','hex','gem','crystal','wedge','shield','dome','arch','cloud','teardrop','leaf','square','sparkle','clover','flower','heart','house','star','pumpkin']);
9
+ export const DEFAULT_COLORS=Object.freeze(['brown','red','orange','yellow','green','cyan','blue','violet','magenta','gray']);
10
+ const PALETTE=Object.freeze(Object.fromEntries([
11
+ ['black','#000000','#000000','#FFFFFF'],
12
+ ['brown','#936439','#A27952','#855C36'],
13
+ ['red','#FF263C','#FF3E51','#E02135'],
14
+ ['orange','#FF6700','#FF781C','#FF6700'],
15
+ ['yellow','#FF9800','#FFAF38','#FF9800'],
16
+ ['green','#00C972','#00C972','#009957'],
17
+ ['cyan','#00BCA6','#1CC3B0','#00A592'],
18
+ ['blue','#1084FE','#2A92FE','#0E74E0'],
19
+ ['violet','#9159FE','#A97EFE','#804EE0'],
20
+ ['magenta','#FF309B','#FF5EB1','#E02A88'],
21
+ ['gray','#777777','#959595','#777777'],
22
+ ].map(([color,baseHex,lightHex,darkHex])=>[color,Object.freeze({baseHex,lightHex,darkHex})])));
23
+
24
+ export function hashBotId(key){
25
+ if(typeof key!=='string'||!key.length)throw new Error('AVATAR_KEY_REQUIRED');
26
+ let hash=2166136261;
27
+ for(let i=0;i<key.length;i++)hash=Math.imul(hash^key.charCodeAt(i),16777619);
28
+ return hash>>>0;
29
+ }
30
+
31
+ export function deriveDefaultAvatar(key){
32
+ const hash=hashBotId(key);
33
+ let shapeHash=hash|0;
34
+ shapeHash=Math.imul(shapeHash^(shapeHash>>>16),73244475);
35
+ shapeHash=Math.imul(shapeHash^(shapeHash>>>13),3266489909);
36
+ shapeHash=(shapeHash^(shapeHash>>>16))>>>0;
37
+ const shapeIndex=shapeHash%DEFAULT_SHAPES.length;
38
+ // Keep the two independent version salts even though they cancel in 0.70.2.
39
+ const identitySaltVersion=1,paletteSaltVersion=1;
40
+ const identitySeed=(hash^Math.imul(identitySaltVersion,2654435769))>>>0;
41
+ let seed=(identitySeed^Math.imul(paletteSaltVersion,2654435769))>>>0;
42
+ seed=(seed+1831565813)|0;
43
+ let sample=Math.imul(seed^(seed>>>15),1|seed);
44
+ sample=(sample+Math.imul(sample^(sample>>>7),61|sample))^sample;
45
+ const random=((sample^(sample>>>14))>>>0)/4294967296;
46
+ const colorIndex=Math.floor(random*DEFAULT_COLORS.length);
47
+ const shape=DEFAULT_SHAPES[shapeIndex],color=DEFAULT_COLORS[colorIndex];
48
+ return {algorithmVersion:AVATAR_ALGORITHM_VERSION,hash,shapeHash,shapeIndex,colorIndex,shape,color,...PALETTE[color]};
49
+ }
50
+
51
+ // Input is a raw cloud ListGrokBotAgents record: its numeric `id` is not the avatar key.
52
+ export function resolveAgentAvatar(agent){
53
+ if(typeof agent?.agentId!=='string'||!agent.agentId.length)throw new Error('AVATAR_AGENT_ID_REQUIRED');
54
+ const derived=deriveDefaultAvatar(agent.agentId);
55
+ const explicitShape=VALID_SHAPES.includes(agent.avatarShape);
56
+ const explicitColor=typeof agent.avatarColor==='string'&&Object.hasOwn(PALETTE,agent.avatarColor);
57
+ const shape=explicitShape?agent.avatarShape:derived.shape;
58
+ const color=explicitColor?agent.avatarColor:derived.color;
59
+ const nonempty=value=>typeof value==='string'&&value.length>0;
60
+ const url=nonempty(agent.avatarUrl)?agent.avatarUrl:nonempty(agent.avatarDataUrl)?agent.avatarDataUrl:null;
61
+ const version=nonempty(agent.avatarVersion)?agent.avatarVersion:null;
62
+ return {
63
+ algorithmVersion:AVATAR_ALGORITHM_VERSION,
64
+ kind:url||version?'picture':'character',
65
+ character:{shape,color,...PALETTE[color]},
66
+ sources:{shape:explicitShape?'explicit':'id-default',color:explicitColor?'explicit':'id-default'},
67
+ picture:url||version?{url,version}:null,
68
+ };
69
+ }