dsh-agent-sdk-bridge 1.1.1 → 1.1.3
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/FAQ.md +5 -0
- package/client.js +30 -4
- package/lib/index.js +23 -0
- package/lib/types/codebuddy.d.ts +12 -0
- package/package.json +1 -1
- package/src/codebuddy.ts +33 -0
package/FAQ.md
CHANGED
|
@@ -107,6 +107,11 @@ subscription` 拒绝,此时卡片只显示积分,不虚构窗口。额度读
|
|
|
107
107
|
已读到的账号并给出原因;点击「刷新额度」可重试。凭据过期时先启动一次带该凭据的会话(或重新
|
|
108
108
|
登录),CLI 会自动续期。
|
|
109
109
|
|
|
110
|
+
**MiniMax 卡片上的「凭据到期」为什么总是今天?** 那一行显示的不是账号或套餐到期日,而是 mcode
|
|
111
|
+
的 OAuth **访问令牌**有效期,它只有约 1 小时:无论什么时候打开页面,绝对日期都会落在今天,看起来
|
|
112
|
+
像「今天到期」。现在这一行改成倒计时(「访问令牌剩余 58 分钟」,超过一小时改用小时),并注明 CLI
|
|
113
|
+
会在下次调用时自动续期、无需重新登录;套餐自己的到期日仍单独显示为「套餐到期」。
|
|
114
|
+
|
|
110
115
|
**MiniMax 回复到一半切到别的对话,再切回来报 `failed to project session`,提示
|
|
111
116
|
`uncachedInputTokens` / `outputTokens` 需要整数?** 已修复。此前 MiniMax 的用量直接上报了
|
|
112
117
|
按字符估算出的**小数**(例如 `1399.5`),流式时看不出问题,但 DSH 的用量投影用
|
package/client.js
CHANGED
|
@@ -181,7 +181,11 @@ window.__ModuleLoader__.load({
|
|
|
181
181
|
minimaxHideOutput: '收起输出',
|
|
182
182
|
minimaxNoUsage: '登录后会显示账号、套餐与剩余额度。',
|
|
183
183
|
minimaxCliRequired: '请先安装 MiniMax Code CLI,再登录。',
|
|
184
|
-
|
|
184
|
+
minimaxPlanExpires: '套餐到期',
|
|
185
|
+
minimaxTokenRemaining: '访问令牌剩余 {n} 分钟',
|
|
186
|
+
minimaxTokenRemainingHours: '访问令牌剩余 {n} 小时',
|
|
187
|
+
minimaxTokenExpired: '访问令牌已过期',
|
|
188
|
+
minimaxTokenRenew: 'CLI 会在下次调用时自动续期,无需重新登录',
|
|
185
189
|
minimaxAccount: '账号',
|
|
186
190
|
minimaxAccountUnknown: '未知账号',
|
|
187
191
|
minimaxPlan: '当前套餐',
|
|
@@ -362,7 +366,11 @@ window.__ModuleLoader__.load({
|
|
|
362
366
|
minimaxHideOutput: 'Hide output',
|
|
363
367
|
minimaxNoUsage: 'Sign in to see the account, plan and remaining quota.',
|
|
364
368
|
minimaxCliRequired: 'Install the MiniMax Code CLI before signing in.',
|
|
365
|
-
|
|
369
|
+
minimaxPlanExpires: 'Plan expires',
|
|
370
|
+
minimaxTokenRemaining: 'Access token: {n} min left',
|
|
371
|
+
minimaxTokenRemainingHours: 'Access token: {n} h left',
|
|
372
|
+
minimaxTokenExpired: 'Access token expired',
|
|
373
|
+
minimaxTokenRenew: 'the CLI renews it automatically on the next call; no re-login needed',
|
|
366
374
|
minimaxAccount: 'Account',
|
|
367
375
|
minimaxAccountUnknown: 'Unknown account',
|
|
368
376
|
minimaxPlan: 'Plan',
|
|
@@ -698,6 +706,22 @@ window.__ModuleLoader__.load({
|
|
|
698
706
|
try { return new Date(ms).toLocaleDateString('zh-CN') } catch { return String(ms) }
|
|
699
707
|
}
|
|
700
708
|
|
|
709
|
+
/**
|
|
710
|
+
* How long a short-lived credential still has, phrased as a countdown.
|
|
711
|
+
*
|
|
712
|
+
* The MiniMax CLI's OAuth access token lives about an hour and the CLI
|
|
713
|
+
* renews it on its next call, so an absolute date is always "today" and
|
|
714
|
+
* reads like a problem that does not exist. A countdown carries the
|
|
715
|
+
* information the date pretended to give.
|
|
716
|
+
*/
|
|
717
|
+
function tokenExpiryText(t, ms, now = Date.now()) {
|
|
718
|
+
if (typeof ms !== 'number' || !Number.isFinite(ms) || ms <= 0) return t('minimaxTokenExpired')
|
|
719
|
+
const minutes = Math.round((ms - now) / 60_000)
|
|
720
|
+
if (minutes <= 0) return t('minimaxTokenExpired')
|
|
721
|
+
if (minutes < 60) return t('minimaxTokenRemaining').replace('{n}', String(minutes))
|
|
722
|
+
return t('minimaxTokenRemainingHours').replace('{n}', String(Math.floor(minutes / 60)))
|
|
723
|
+
}
|
|
724
|
+
|
|
701
725
|
/**
|
|
702
726
|
* One quota bucket as a line: label, `remaining / total`, percentage.
|
|
703
727
|
*
|
|
@@ -1414,7 +1438,7 @@ window.__ModuleLoader__.load({
|
|
|
1414
1438
|
plan.hasTokenPlan === true ? h('span', { style: { ...css.tag, marginLeft: '6px' } }, t('minimaxPlanTokenPlan')) : null,
|
|
1415
1439
|
plan.expiresAt === undefined
|
|
1416
1440
|
? null
|
|
1417
|
-
: h('span', { style: css.note }, `${t('
|
|
1441
|
+
: h('span', { style: css.note }, `${t('minimaxPlanExpires')} ${dateLabel(plan.expiresAt)}`),
|
|
1418
1442
|
),
|
|
1419
1443
|
credits === undefined
|
|
1420
1444
|
? null
|
|
@@ -1492,7 +1516,8 @@ window.__ModuleLoader__.load({
|
|
|
1492
1516
|
quotaBlock,
|
|
1493
1517
|
typeof auth?.expiresAt === 'number' && !blocked
|
|
1494
1518
|
? h('div', { style: css.usageFoot },
|
|
1495
|
-
h('span', null,
|
|
1519
|
+
h('span', null, tokenExpiryText(t, auth.expiresAt)),
|
|
1520
|
+
h('span', { style: css.note }, t('minimaxTokenRenew')),
|
|
1496
1521
|
)
|
|
1497
1522
|
: null,
|
|
1498
1523
|
typeof auth?.url === 'string' && signingIn
|
|
@@ -2404,6 +2429,7 @@ window.__ModuleLoader__.load({
|
|
|
2404
2429
|
exports.__test = {
|
|
2405
2430
|
windowLabel, priceSuffix, ADVANCED, BRANDS, zh, en,
|
|
2406
2431
|
SettingsPage, BundleSettings, UsageCard, CodeBuddyCard, QuotaLine, creditsOf, neverExpires,
|
|
2432
|
+
dateLabel, tokenExpiryText,
|
|
2407
2433
|
readCache, writeCache,
|
|
2408
2434
|
}
|
|
2409
2435
|
return module.exports
|
package/lib/index.js
CHANGED
|
@@ -4032,6 +4032,16 @@ var CodeBuddySession = class {
|
|
|
4032
4032
|
callNonce = randomUUID().slice(0, 8);
|
|
4033
4033
|
lastUsage;
|
|
4034
4034
|
resultUsage;
|
|
4035
|
+
/**
|
|
4036
|
+
* Ids of assistant messages whose streaming events this session consumed.
|
|
4037
|
+
*
|
|
4038
|
+
* Kept across turns, not reset with the turn: the echo of a tool round is
|
|
4039
|
+
* delivered on the next stream(), so the previous turn's id is exactly the
|
|
4040
|
+
* one that has to be recognised. Only the last few ids matter, and bounding
|
|
4041
|
+
* the list keeps a long-lived session from growing without limit.
|
|
4042
|
+
*/
|
|
4043
|
+
streamedMessageIds = /* @__PURE__ */ new Set();
|
|
4044
|
+
streamedMessageOrder = [];
|
|
4035
4045
|
output = new TurnOutputAccounting();
|
|
4036
4046
|
inputChars = 0;
|
|
4037
4047
|
toolResultTimeoutMs;
|
|
@@ -4244,6 +4254,7 @@ var CodeBuddySession = class {
|
|
|
4244
4254
|
if (event.type === "message_start") {
|
|
4245
4255
|
const usage = event.message.usage;
|
|
4246
4256
|
if (usage !== void 0) this.lastUsage = usage;
|
|
4257
|
+
this.rememberStreamedMessage(event.message.id);
|
|
4247
4258
|
return;
|
|
4248
4259
|
}
|
|
4249
4260
|
if (event.type === "content_block_start") {
|
|
@@ -4358,6 +4369,8 @@ var CodeBuddySession = class {
|
|
|
4358
4369
|
return;
|
|
4359
4370
|
}
|
|
4360
4371
|
if (message.type === "assistant") {
|
|
4372
|
+
const echoOf = message.message.id;
|
|
4373
|
+
if (typeof echoOf === "string" && this.streamedMessageIds.has(echoOf)) return;
|
|
4361
4374
|
if (this.textBlock === void 0 && this.tools.length === 0) {
|
|
4362
4375
|
for (const block of message.message.content) if (block.type === "tool_use") {
|
|
4363
4376
|
this.countOutput(block.name);
|
|
@@ -4424,6 +4437,16 @@ var CodeBuddySession = class {
|
|
|
4424
4437
|
this.endTurn({ kind: "stop" });
|
|
4425
4438
|
}
|
|
4426
4439
|
}
|
|
4440
|
+
/** Record that one assistant message reached the host as streaming events. */
|
|
4441
|
+
rememberStreamedMessage(id) {
|
|
4442
|
+
if (typeof id !== "string" || id.length === 0 || this.streamedMessageIds.has(id)) return;
|
|
4443
|
+
this.streamedMessageIds.add(id);
|
|
4444
|
+
this.streamedMessageOrder.push(id);
|
|
4445
|
+
if (this.streamedMessageOrder.length > 32) {
|
|
4446
|
+
const oldest = this.streamedMessageOrder.shift();
|
|
4447
|
+
if (oldest !== void 0) this.streamedMessageIds.delete(oldest);
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4427
4450
|
resetTurnState() {
|
|
4428
4451
|
this.blockIndex = 0;
|
|
4429
4452
|
this.textBlock = void 0;
|
package/lib/types/codebuddy.d.ts
CHANGED
|
@@ -209,6 +209,16 @@ export declare class CodeBuddySession {
|
|
|
209
209
|
private readonly callNonce;
|
|
210
210
|
private lastUsage;
|
|
211
211
|
private resultUsage;
|
|
212
|
+
/**
|
|
213
|
+
* Ids of assistant messages whose streaming events this session consumed.
|
|
214
|
+
*
|
|
215
|
+
* Kept across turns, not reset with the turn: the echo of a tool round is
|
|
216
|
+
* delivered on the next stream(), so the previous turn's id is exactly the
|
|
217
|
+
* one that has to be recognised. Only the last few ids matter, and bounding
|
|
218
|
+
* the list keeps a long-lived session from growing without limit.
|
|
219
|
+
*/
|
|
220
|
+
private readonly streamedMessageIds;
|
|
221
|
+
private readonly streamedMessageOrder;
|
|
212
222
|
private readonly output;
|
|
213
223
|
private inputChars;
|
|
214
224
|
private readonly toolResultTimeoutMs;
|
|
@@ -263,6 +273,8 @@ export declare class CodeBuddySession {
|
|
|
263
273
|
private canUseTool;
|
|
264
274
|
private consume;
|
|
265
275
|
private handle;
|
|
276
|
+
/** Record that one assistant message reached the host as streaming events. */
|
|
277
|
+
private rememberStreamedMessage;
|
|
266
278
|
private resetTurnState;
|
|
267
279
|
private emit;
|
|
268
280
|
private countOutput;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "dsh-agent-sdk-bridge",
|
|
3
3
|
"displayName": "Agent SDK Bridge",
|
|
4
4
|
"description": "DeepSeek Harness LLM adapter bridge for Qoder CN, Qoder International, Tencent CodeBuddy and MiniMax Code subscriptions. It reuses each provider's own SDK or official ACP server and CLI login, shows available quota, and exposes per-provider settings pages with independent international and mainland login regions.",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.3",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "k1-h2",
|
package/src/codebuddy.ts
CHANGED
|
@@ -851,6 +851,16 @@ export class CodeBuddySession {
|
|
|
851
851
|
private readonly callNonce = randomUUID().slice(0, 8)
|
|
852
852
|
private lastUsage: TurnUsage | undefined
|
|
853
853
|
private resultUsage: TurnUsage | undefined
|
|
854
|
+
/**
|
|
855
|
+
* Ids of assistant messages whose streaming events this session consumed.
|
|
856
|
+
*
|
|
857
|
+
* Kept across turns, not reset with the turn: the echo of a tool round is
|
|
858
|
+
* delivered on the next stream(), so the previous turn's id is exactly the
|
|
859
|
+
* one that has to be recognised. Only the last few ids matter, and bounding
|
|
860
|
+
* the list keeps a long-lived session from growing without limit.
|
|
861
|
+
*/
|
|
862
|
+
private readonly streamedMessageIds = new Set<string>()
|
|
863
|
+
private readonly streamedMessageOrder: string[] = []
|
|
854
864
|
private readonly output = new TurnOutputAccounting()
|
|
855
865
|
private inputChars = 0
|
|
856
866
|
private readonly toolResultTimeoutMs: number
|
|
@@ -1057,6 +1067,12 @@ export class CodeBuddySession {
|
|
|
1057
1067
|
if (event.type === 'message_start') {
|
|
1058
1068
|
const usage = (event.message as { usage?: TurnUsage }).usage
|
|
1059
1069
|
if (usage !== undefined) this.lastUsage = usage
|
|
1070
|
+
// Remember which message this stream belongs to. A tool round ends the
|
|
1071
|
+
// host turn at `message_stop` (waiting for `result` would deadlock:
|
|
1072
|
+
// the CLI only finishes after the host returns the tool result), so
|
|
1073
|
+
// the CLI's `assistant` echo of this message is still buffered and is
|
|
1074
|
+
// delivered on the NEXT stream() — where it must not be re-emitted.
|
|
1075
|
+
this.rememberStreamedMessage((event.message as { id?: unknown }).id)
|
|
1060
1076
|
return
|
|
1061
1077
|
}
|
|
1062
1078
|
if (event.type === 'content_block_start') {
|
|
@@ -1132,6 +1148,12 @@ export class CodeBuddySession {
|
|
|
1132
1148
|
return
|
|
1133
1149
|
}
|
|
1134
1150
|
if (message.type === 'assistant') {
|
|
1151
|
+
// The CLI sends the assembled message after its streaming events. When
|
|
1152
|
+
// those events already reached the host, this is an echo, not new
|
|
1153
|
+
// content; a replayed echo would print the same reply a second time
|
|
1154
|
+
// (and count its tokens twice).
|
|
1155
|
+
const echoOf = (message.message as { id?: unknown }).id
|
|
1156
|
+
if (typeof echoOf === 'string' && this.streamedMessageIds.has(echoOf)) return
|
|
1135
1157
|
if (this.textBlock === undefined && this.tools.length === 0) {
|
|
1136
1158
|
for (const block of message.message.content) {
|
|
1137
1159
|
if (block.type === 'tool_use') {
|
|
@@ -1172,6 +1194,17 @@ export class CodeBuddySession {
|
|
|
1172
1194
|
}
|
|
1173
1195
|
}
|
|
1174
1196
|
|
|
1197
|
+
/** Record that one assistant message reached the host as streaming events. */
|
|
1198
|
+
private rememberStreamedMessage(id: unknown): void {
|
|
1199
|
+
if (typeof id !== 'string' || id.length === 0 || this.streamedMessageIds.has(id)) return
|
|
1200
|
+
this.streamedMessageIds.add(id)
|
|
1201
|
+
this.streamedMessageOrder.push(id)
|
|
1202
|
+
if (this.streamedMessageOrder.length > 32) {
|
|
1203
|
+
const oldest = this.streamedMessageOrder.shift()
|
|
1204
|
+
if (oldest !== undefined) this.streamedMessageIds.delete(oldest)
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1175
1208
|
private resetTurnState(): void {
|
|
1176
1209
|
this.blockIndex = 0
|
|
1177
1210
|
this.textBlock = undefined
|