@linjz/opencode-qqbot 0.3.1 → 0.3.2
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/package.json +1 -1
- package/src/qq/api.ts +6 -1
package/package.json
CHANGED
package/src/qq/api.ts
CHANGED
|
@@ -5,6 +5,11 @@ import type { MessageContext } from "./types.js"
|
|
|
5
5
|
|
|
6
6
|
const API_BASE = "https://api.sgroup.qq.com"
|
|
7
7
|
const TOKEN_URL = "https://bots.qq.com/app/getAppAccessToken"
|
|
8
|
+
// 沙箱模式(QQ_SANDBOX=true):API 底座切沙箱域(QQ 官方文档约定
|
|
9
|
+
// sandbox.api.sgroup.qq.com);token 端点两环境共用 bots.qq.com。
|
|
10
|
+
// 注意:沙箱 bot 在非沙箱场景会被网关以 4914(offline/sandbox-only)拒绝。
|
|
11
|
+
const API_BASE_SANDBOX = "https://sandbox.api.sgroup.qq.com"
|
|
12
|
+
const API_BASE_EFFECTIVE = process.env.QQ_SANDBOX === "true" ? API_BASE_SANDBOX : API_BASE
|
|
8
13
|
|
|
9
14
|
let cachedToken: { token: string; expiresAt: number; appId: string } | null = null
|
|
10
15
|
// Singleflight:防止并发获取 Token 时重复请求
|
|
@@ -152,7 +157,7 @@ export async function apiRequest<T = unknown>(
|
|
|
152
157
|
body?: unknown,
|
|
153
158
|
timeoutMs?: number,
|
|
154
159
|
): Promise<T> {
|
|
155
|
-
const url = `${
|
|
160
|
+
const url = `${API_BASE_EFFECTIVE}${path}`
|
|
156
161
|
const headers: Record<string, string> = {
|
|
157
162
|
Authorization: `QQBot ${accessToken}`,
|
|
158
163
|
"Content-Type": "application/json",
|