dsh-llm-codebuddy-power 1.0.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 +22 -0
- package/README.md +66 -0
- package/README.zh.md +66 -0
- package/cordis.patch.yml +32 -0
- package/lib/cli-login.js +2099 -0
- package/lib/client.js +2814 -0
- package/lib/index.js +3957 -0
- package/lib/types/adapter.d.ts +58 -0
- package/lib/types/atomic-file.d.ts +43 -0
- package/lib/types/auth-service.d.ts +195 -0
- package/lib/types/cli/login.d.ts +23 -0
- package/lib/types/client/AccountSwitcher.d.ts +53 -0
- package/lib/types/client/CodeBuddySection.d.ts +62 -0
- package/lib/types/client/ComposerControls.d.ts +29 -0
- package/lib/types/client/DrawToolCard.d.ts +24 -0
- package/lib/types/client/ModelPanel.d.ts +77 -0
- package/lib/types/client/TurnCreditPill.d.ts +33 -0
- package/lib/types/client/UsageIndicator.d.ts +21 -0
- package/lib/types/client/icons.d.ts +24 -0
- package/lib/types/client/index.d.ts +34 -0
- package/lib/types/client/locales.d.ts +90 -0
- package/lib/types/client/poll.d.ts +19 -0
- package/lib/types/client/store.d.ts +59 -0
- package/lib/types/client/wire.d.ts +147 -0
- package/lib/types/codebuddy.d.ts +187 -0
- package/lib/types/constants.d.ts +67 -0
- package/lib/types/credit-store.d.ts +25 -0
- package/lib/types/image-tool.d.ts +34 -0
- package/lib/types/index.d.ts +79 -0
- package/lib/types/login.d.ts +43 -0
- package/lib/types/model-enrich.d.ts +125 -0
- package/lib/types/prefs.d.ts +43 -0
- package/lib/types/rpc-route.d.ts +25 -0
- package/lib/types/selection.d.ts +35 -0
- package/lib/types/serialize.d.ts +37 -0
- package/lib/types/session-store.d.ts +63 -0
- package/lib/types/session.d.ts +415 -0
- package/lib/types/settings.d.ts +18 -0
- package/lib/types/sse.d.ts +22 -0
- package/lib/types/storage.d.ts +118 -0
- package/lib/types/translate.d.ts +61 -0
- package/lib/types/types.d.ts +345 -0
- package/lib/types/usage.d.ts +109 -0
- package/package.json +119 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本插件读取的 wire 结构,分属两套互不相关的协议。
|
|
3
|
+
*
|
|
4
|
+
* CodeBuddy 控制平面(`/v2/plugin/auth/*`、`/v3/config`)把每个回复包在
|
|
5
|
+
* `{code, msg, requestId, data}` 中,且不兼容 OpenAI——这正是本插件存在、
|
|
6
|
+
* 而不使用普通 OpenAI 兼容路由的原因。对话平面(`/v2/chat/completions`)
|
|
7
|
+
* 兼容 OpenAI,其 chunk 结构即常见结构。
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-llm-codebuddy-power/types
|
|
10
|
+
*/
|
|
11
|
+
/** 每个 CodeBuddy 控制平面回复都携带的信封。 */
|
|
12
|
+
export interface ResponseBase {
|
|
13
|
+
code: number;
|
|
14
|
+
msg: string;
|
|
15
|
+
requestId: string;
|
|
16
|
+
}
|
|
17
|
+
/** 已发起的浏览器登录握手。 */
|
|
18
|
+
export interface AuthState {
|
|
19
|
+
/** 不透明的握手 id;把浏览器会话与令牌轮询关联起来。 */
|
|
20
|
+
state: string;
|
|
21
|
+
/** 用户打开以登录的 URL。 */
|
|
22
|
+
authUrl: string;
|
|
23
|
+
}
|
|
24
|
+
/** 携带已发起握手的 `/v2/plugin/auth/state` 回复。 */
|
|
25
|
+
export interface AuthStateResponse extends ResponseBase {
|
|
26
|
+
data?: AuthState;
|
|
27
|
+
}
|
|
28
|
+
/** 浏览器登录完成后签发的令牌。 */
|
|
29
|
+
export interface AuthToken {
|
|
30
|
+
accessToken: string;
|
|
31
|
+
/** 访问令牌有效期,单位秒。 */
|
|
32
|
+
expiresIn: number;
|
|
33
|
+
refreshToken: string;
|
|
34
|
+
/** 刷新令牌有效期,单位秒。 */
|
|
35
|
+
refreshExpiresIn: number;
|
|
36
|
+
/** 后续每个请求都必须回带的租户域名。 */
|
|
37
|
+
domain: string;
|
|
38
|
+
}
|
|
39
|
+
/** 携带已签发或已刷新令牌的 `/v2/plugin/auth/token` 回复。 */
|
|
40
|
+
export interface AuthTokenResponse extends ResponseBase {
|
|
41
|
+
data?: AuthToken;
|
|
42
|
+
}
|
|
43
|
+
/** 已登录身份;其字段会成为必需的请求头。 */
|
|
44
|
+
export interface Account {
|
|
45
|
+
uid: string;
|
|
46
|
+
nickname: string;
|
|
47
|
+
/** 腾讯用户身份号(如 QQ openid),当账号披露该字段时。 */
|
|
48
|
+
uin?: string;
|
|
49
|
+
enterpriseId?: string;
|
|
50
|
+
/** 企业显示名,当账号属于企业租户时。 */
|
|
51
|
+
enterpriseName?: string;
|
|
52
|
+
/** 企业用户名(账号在租户内的名字)。 */
|
|
53
|
+
enterpriseUserName?: string;
|
|
54
|
+
departmentFullName?: string;
|
|
55
|
+
}
|
|
56
|
+
/** 携带已登录身份的 `/v2/plugin/login/account` 回复。 */
|
|
57
|
+
export interface AccountResponse extends ResponseBase {
|
|
58
|
+
data?: Account;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* CodeBuddy 为单个模型披露的推理元数据。effort id 是 provider 自己的词汇
|
|
62
|
+
* (“low”“high”“xhigh”“max”);它们被原样透传而不做映射,因此目录日后
|
|
63
|
+
* 新增的级别无需改代码。
|
|
64
|
+
*
|
|
65
|
+
* `supportedEfforts` 确实可选:`auto` 会带一个声明了生效 `effort`、却完全
|
|
66
|
+
* 没有可选列表的推理块。
|
|
67
|
+
*/
|
|
68
|
+
export interface CodeBuddyReasoning {
|
|
69
|
+
/** 可选级别,当该模型披露了可选项时。 */
|
|
70
|
+
supportedEfforts?: string[];
|
|
71
|
+
/** 调用方未选择时应用的级别。 */
|
|
72
|
+
defaultEffort?: string;
|
|
73
|
+
/** 服务端当前生效的级别;一个可回退的默认值来源。 */
|
|
74
|
+
effort?: string;
|
|
75
|
+
/** 思考是否可以完全关闭。 */
|
|
76
|
+
canDisableThinking?: boolean;
|
|
77
|
+
summary?: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* CodeBuddy 所描述的单个模型。这是非 OpenAI 的目录结构:能力开关与尺寸
|
|
81
|
+
* 在此披露,而 OpenAI 的 `GET /models` 列表不会报告这些内容。
|
|
82
|
+
*/
|
|
83
|
+
export interface CodeBuddyModel {
|
|
84
|
+
id: string;
|
|
85
|
+
name: string;
|
|
86
|
+
/** CodeBuddy 在模型名旁展示的积分/额度标签。 */
|
|
87
|
+
credits?: string;
|
|
88
|
+
/** 请求/响应合计的上下文容量。 */
|
|
89
|
+
maxAllowedSize?: number;
|
|
90
|
+
maxOutputTokens?: number;
|
|
91
|
+
supportsImages?: boolean;
|
|
92
|
+
supportsToolCall?: boolean;
|
|
93
|
+
supportsReasoning?: boolean;
|
|
94
|
+
/** 可选思考级别,当披露时。 */
|
|
95
|
+
reasoning?: CodeBuddyReasoning;
|
|
96
|
+
/** 各语言描述,当披露时。 */
|
|
97
|
+
descriptionZh?: string;
|
|
98
|
+
descriptionEn?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 一个有排期的 CodeBuddy 模型活动:挂在模型上的徽标与悬浮信息,可选带一个
|
|
102
|
+
* 改变所展示积分倍率的折扣。
|
|
103
|
+
*/
|
|
104
|
+
export interface CodeBuddyModelPromotion {
|
|
105
|
+
/** 活动标识;唯一,用作展示 hook 的键。 */
|
|
106
|
+
id: string;
|
|
107
|
+
/** 活动是否启用。 */
|
|
108
|
+
enabled?: boolean;
|
|
109
|
+
/** 折扣/活动类型;观察到的唯一取值为 “discount”。 */
|
|
110
|
+
kind?: string;
|
|
111
|
+
/** 该活动适用的模型。 */
|
|
112
|
+
modelIds?: string[];
|
|
113
|
+
/** 覆盖同一模型的多个活动之间的优先级;最高者生效。 */
|
|
114
|
+
priority?: number;
|
|
115
|
+
/** 展示在模型行与悬浮提示中的徽标。 */
|
|
116
|
+
badge?: {
|
|
117
|
+
/** 徽标文本,如 “错峰使用”“夜间折扣”“限时免费”。 */
|
|
118
|
+
label?: string;
|
|
119
|
+
/** 徽标底色(十六进制)。 */
|
|
120
|
+
color?: string;
|
|
121
|
+
/** “activeOnly” 会在活动生效窗口之外隐藏徽标。 */
|
|
122
|
+
display?: string;
|
|
123
|
+
};
|
|
124
|
+
/** 生效期间应用的折扣,会改变积分倍率。 */
|
|
125
|
+
discount?: {
|
|
126
|
+
/** 折扣后的倍率标签,如 “0.50x”“0x”。 */
|
|
127
|
+
discountedCredits?: string;
|
|
128
|
+
/** “replace” 只展示折扣后倍率;“strikethrough” 两者都列出。 */
|
|
129
|
+
displayMode?: string;
|
|
130
|
+
/** 作用于标价积分倍率的乘数(0.5 = 半价)。 */
|
|
131
|
+
factor?: number;
|
|
132
|
+
};
|
|
133
|
+
/** 悬浮提示信息:文本加一个可选的操作按钮。 */
|
|
134
|
+
hover?: {
|
|
135
|
+
/** 各语言活动文案。 */
|
|
136
|
+
textZh?: string;
|
|
137
|
+
textEn?: string;
|
|
138
|
+
/** 提示按钮点击时执行的操作。 */
|
|
139
|
+
action?: {
|
|
140
|
+
type?: string;
|
|
141
|
+
labelZh?: string;
|
|
142
|
+
labelEn?: string;
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
/** 活动生效的时间窗口。 */
|
|
146
|
+
schedule?: {
|
|
147
|
+
/** 每日 [start, end) 窗口。 */
|
|
148
|
+
daily?: {
|
|
149
|
+
start?: string;
|
|
150
|
+
end?: string;
|
|
151
|
+
}[];
|
|
152
|
+
/** 排期所依据的 IANA 时区。 */
|
|
153
|
+
timezone?: string;
|
|
154
|
+
/** 绝对有效期边界。 */
|
|
155
|
+
validFrom?: string;
|
|
156
|
+
validUntil?: string;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 模型档位(订阅等级),用徽标加悬浮文案标记模型,例如标准档订阅者的
|
|
161
|
+
* “订阅优先”。
|
|
162
|
+
*/
|
|
163
|
+
export interface CodeBuddyModelTier {
|
|
164
|
+
/** 档位标识。 */
|
|
165
|
+
id: string;
|
|
166
|
+
/** 档位类别(如 “standard”)。 */
|
|
167
|
+
tier?: string;
|
|
168
|
+
/** 档位标记是否启用。 */
|
|
169
|
+
enabled?: boolean;
|
|
170
|
+
/** 展示在模型行 / 悬浮提示中的徽标。 */
|
|
171
|
+
badge?: {
|
|
172
|
+
label?: string;
|
|
173
|
+
};
|
|
174
|
+
/** 悬浮文案与可选操作(“去升级”)。 */
|
|
175
|
+
hover?: {
|
|
176
|
+
textZh?: string;
|
|
177
|
+
textEn?: string;
|
|
178
|
+
action?: {
|
|
179
|
+
type?: string;
|
|
180
|
+
labelZh?: string;
|
|
181
|
+
labelEn?: string;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
/** 带有该档位的模型。 */
|
|
185
|
+
modelIds?: string[];
|
|
186
|
+
/** 各档位之间的优先级;最高者生效。 */
|
|
187
|
+
priority?: number;
|
|
188
|
+
/** 该档位生效所需的订阅者类别。 */
|
|
189
|
+
requiredUserType?: string;
|
|
190
|
+
}
|
|
191
|
+
/** `/v3/config` 目录:模型及其附带的活动与档位。 */
|
|
192
|
+
export interface CodeBuddyConfig {
|
|
193
|
+
models: CodeBuddyModel[];
|
|
194
|
+
/** 有排期的活动;没有生效活动时缺省。 */
|
|
195
|
+
modelPromotions?: CodeBuddyModelPromotion[];
|
|
196
|
+
/** 模型档位(订阅等级);没有适用档位时缺省。 */
|
|
197
|
+
modelTiers?: CodeBuddyModelTier[];
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 目录是否披露了 harness 所需的容量。
|
|
201
|
+
*
|
|
202
|
+
* harness 要求它提供的每个模型都有正的 `contextWindow` 与输出上限,而
|
|
203
|
+
* CodeBuddy 对非对话模型的条目(补全、改写/跳转、图片生成)两者都不给。
|
|
204
|
+
* 为这些条目编造数字会把不可用的模型以猜测的尺寸放进选择器,因此调用方
|
|
205
|
+
* 改为丢弃它们。放在这里、紧邻 wire 类型,使列表与解析路径不会对哪些条目
|
|
206
|
+
* 可提供产生分歧。
|
|
207
|
+
* @param model - 一个目录条目。
|
|
208
|
+
* @returns 两个容量都存在且为正时返回 true。
|
|
209
|
+
*/
|
|
210
|
+
export declare function hasDisclosedCapacity(model: CodeBuddyModel): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* 插件有意不提供的模型 id,即使目录把它们描述为完全支持对话。
|
|
213
|
+
*
|
|
214
|
+
* CodeBuddy 的目录会列出并非真实模型的默认/别名条目:它们的请求在用量记录
|
|
215
|
+
* 中会落成另一个模型(`default` 别名解析为 `deepseek-v4-flash`),而选择器
|
|
216
|
+
* 会把它显示为独立选项,因此提供它们会误导用户。被屏蔽的 id 只在列表中
|
|
217
|
+
* 滤除;显式指名的 id 仍会走通(服务以 "The requested model is not
|
|
218
|
+
* available" 拒绝),与选择器隐藏服务无法提供选项的做法一致。
|
|
219
|
+
*/
|
|
220
|
+
export declare const BLOCKED_MODEL_IDS: ReadonlySet<string>;
|
|
221
|
+
/**
|
|
222
|
+
* 某个目录条目 id 是否在屏蔽列表中。
|
|
223
|
+
* @param id - 目录条目 id。
|
|
224
|
+
* @returns 插件不得提供该模型时返回 true。
|
|
225
|
+
*/
|
|
226
|
+
export declare function isBlockedModelId(id: string): boolean;
|
|
227
|
+
/** 包着 {@link CodeBuddyConfig} 的 `/v3/config` 回复信封。 */
|
|
228
|
+
export interface ConfigResponse extends ResponseBase {
|
|
229
|
+
data?: CodeBuddyConfig;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 非 2xx 对话回复携带的错误体:兼容 OpenAI 的 `error` 结构,或当网关层
|
|
233
|
+
* 先于模型平面拒绝请求时,CodeBuddy 自己的控制平面信封
|
|
234
|
+
* (`{code, msg, displayMsg}`)。
|
|
235
|
+
*/
|
|
236
|
+
export interface WireError {
|
|
237
|
+
error?: {
|
|
238
|
+
message?: string;
|
|
239
|
+
type?: string;
|
|
240
|
+
code?: string;
|
|
241
|
+
};
|
|
242
|
+
/** CodeBuddy 信封的失败码(如 11128 = 被安全策略拦截)。 */
|
|
243
|
+
code?: number;
|
|
244
|
+
/** CodeBuddy 信封的失败摘要。 */
|
|
245
|
+
msg?: string;
|
|
246
|
+
/** 本地化失败文本,当信封携带时。 */
|
|
247
|
+
displayMsg?: {
|
|
248
|
+
en?: string;
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/** 兼容 OpenAI 的流式响应中的 usage 块。 */
|
|
252
|
+
export interface WireUsage {
|
|
253
|
+
prompt_tokens?: number;
|
|
254
|
+
completion_tokens?: number;
|
|
255
|
+
prompt_cache_hit_tokens?: number;
|
|
256
|
+
prompt_tokens_details?: {
|
|
257
|
+
cached_tokens?: number;
|
|
258
|
+
};
|
|
259
|
+
completion_tokens_details?: {
|
|
260
|
+
reasoning_tokens?: number;
|
|
261
|
+
};
|
|
262
|
+
/** 本次请求扣除的积分,当服务上报时。 */
|
|
263
|
+
credit?: number;
|
|
264
|
+
}
|
|
265
|
+
/** 一个流式 tool call 片段。 */
|
|
266
|
+
export interface WireToolCall {
|
|
267
|
+
index: number;
|
|
268
|
+
id?: string;
|
|
269
|
+
function?: {
|
|
270
|
+
name?: string;
|
|
271
|
+
arguments?: string;
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/** 多模态用户内容数组中的文本部分。 */
|
|
275
|
+
export interface WireTextContentPart {
|
|
276
|
+
type: 'text';
|
|
277
|
+
text: string;
|
|
278
|
+
}
|
|
279
|
+
/** 多模态用户内容数组中的内联 base64 图片部分。 */
|
|
280
|
+
export interface WireImageUrlContentPart {
|
|
281
|
+
type: 'image_url';
|
|
282
|
+
image_url: {
|
|
283
|
+
url: string;
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/** 多模态消息内容数组中的一个部分。 */
|
|
287
|
+
export type WireContentPart = WireTextContentPart | WireImageUrlContentPart;
|
|
288
|
+
/** 一个兼容 OpenAI 的流式 chunk。 */
|
|
289
|
+
export interface WireChunk {
|
|
290
|
+
choices?: {
|
|
291
|
+
delta?: {
|
|
292
|
+
content?: string | null;
|
|
293
|
+
reasoning_content?: string | null;
|
|
294
|
+
reasoning?: string | null;
|
|
295
|
+
tool_calls?: WireToolCall[] | null;
|
|
296
|
+
} | null;
|
|
297
|
+
finish_reason?: string | null;
|
|
298
|
+
}[] | null;
|
|
299
|
+
/**
|
|
300
|
+
* 每个非最终 chunk 都存在但显式为 `null`,因此消费方必须判断 null,
|
|
301
|
+
* 而不能只判断 `undefined`。
|
|
302
|
+
*/
|
|
303
|
+
usage?: WireUsage | null;
|
|
304
|
+
}
|
|
305
|
+
/** 发送到对话 endpoint 的一条 wire 消息。 */
|
|
306
|
+
export interface WireMessage {
|
|
307
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
308
|
+
/** 文本;当消息携带图片时,为有序的兼容 OpenAI 内容部分。 */
|
|
309
|
+
content: string | WireContentPart[];
|
|
310
|
+
reasoning_content?: string;
|
|
311
|
+
tool_call_id?: string;
|
|
312
|
+
tool_calls?: {
|
|
313
|
+
id: string;
|
|
314
|
+
type: 'function';
|
|
315
|
+
function: {
|
|
316
|
+
name: string;
|
|
317
|
+
arguments: string;
|
|
318
|
+
};
|
|
319
|
+
}[];
|
|
320
|
+
}
|
|
321
|
+
/** 发送到对话 endpoint 的一个 tool schema。 */
|
|
322
|
+
export interface WireTool {
|
|
323
|
+
type: 'function';
|
|
324
|
+
function: {
|
|
325
|
+
name: string;
|
|
326
|
+
description: string;
|
|
327
|
+
parameters: Record<string, unknown>;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/** chat-completions 请求体。 */
|
|
331
|
+
export interface WireRequest {
|
|
332
|
+
model: string;
|
|
333
|
+
messages: WireMessage[];
|
|
334
|
+
stream: true;
|
|
335
|
+
stream_options?: {
|
|
336
|
+
include_usage: boolean;
|
|
337
|
+
};
|
|
338
|
+
tools?: WireTool[];
|
|
339
|
+
temperature?: number;
|
|
340
|
+
max_tokens?: number;
|
|
341
|
+
stop?: string[];
|
|
342
|
+
/** 兼容 OpenAI 的思考级别;CodeBuddy 自己的 effort 词汇。 */
|
|
343
|
+
reasoning_effort?: string;
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CodeBuddy 配额/用量计量器:获取并解析剩余额度。
|
|
3
|
+
*
|
|
4
|
+
* CodeBuddy 对计费面的拆分方式与 gproxy 参考实现相同:企业租户回应
|
|
5
|
+
* `get-enterprise-user-usage`(单个 limit/credit 对),而个人账户回应
|
|
6
|
+
* `get-user-resource`(每个生效套餐一个窗口)。两种结构除了每个 CodeBuddy
|
|
7
|
+
* 请求都携带的认证头之外没有任何共同点,因此传输与解析路径只在已登录账户是否
|
|
8
|
+
* 披露了 `enterpriseId` 这一点上分叉一次。
|
|
9
|
+
*
|
|
10
|
+
* 每个进入 Web 客户端的值都是普通 number/string,因此这里返回的
|
|
11
|
+
* {@link UsageSnapshot} 是自有数据 → 不会有活的会话对象逃出本模块。
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-llm-codebuddy-power/usage
|
|
14
|
+
*/
|
|
15
|
+
import type { CodeBuddyIdentity } from './codebuddy.ts';
|
|
16
|
+
/** 一个计量窗口:一个有名字的额度以及其中已花费多少。 */
|
|
17
|
+
export interface UsageWindow {
|
|
18
|
+
/** 人类可读的套餐名,当目录披露了它时。 */
|
|
19
|
+
name: string;
|
|
20
|
+
/** 已消耗的数量;当计费面未上报它时为 `undefined`。 */
|
|
21
|
+
used?: number;
|
|
22
|
+
/** 此窗口的总额度;容量未披露或非正数时为 `undefined`。 */
|
|
23
|
+
limit?: number;
|
|
24
|
+
/** 窗口重置时刻的 ISO 风格时间戳,当披露了它时。 */
|
|
25
|
+
resetsAt?: string;
|
|
26
|
+
}
|
|
27
|
+
/** 设置界面所渲染的已解析用量。 */
|
|
28
|
+
export interface UsageSnapshot {
|
|
29
|
+
/** 计费面上报的每个计量窗口对应一项;失败时为空。 */
|
|
30
|
+
windows: UsageWindow[];
|
|
31
|
+
/**
|
|
32
|
+
* 首个窗口的重置时刻,与主池的数值一起出现在同一行提示里。
|
|
33
|
+
*
|
|
34
|
+
* 企业租户恰好上报一个窗口,而个人账户的首个生效套餐正是一眼概览应当反映的那个;
|
|
35
|
+
* 进度条自身的数值取自 {@link main}。
|
|
36
|
+
*/
|
|
37
|
+
primaryResetsAt?: string;
|
|
38
|
+
/**
|
|
39
|
+
* 可续期的主池(例如每月 "CodeBuddy个人体验版"):用户自定义上限与危险阈值
|
|
40
|
+
* 所作用的进度条。
|
|
41
|
+
*/
|
|
42
|
+
main?: UsagePool;
|
|
43
|
+
/**
|
|
44
|
+
* 一次性赠送池(推荐/裂变套餐):它自己的聚合进度条,其提示框列出最早过期的
|
|
45
|
+
* 有效赠送。
|
|
46
|
+
*/
|
|
47
|
+
gift?: GiftUsage;
|
|
48
|
+
}
|
|
49
|
+
/** 一个聚合额度池:对匹配窗口的 used/limit 求和。 */
|
|
50
|
+
export interface UsagePool {
|
|
51
|
+
used: number;
|
|
52
|
+
limit: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 赠送额度的汇总,加上提示框的逐套餐明细。
|
|
56
|
+
*
|
|
57
|
+
* 赠送套餐是一次性的:已完全耗尽的窗口会退出汇总,因此百分比只反映仍可花费的
|
|
58
|
+
* 部分(把已耗尽的套餐同时加到两边会让进度条永远被拖向 100%)。
|
|
59
|
+
*/
|
|
60
|
+
export interface GiftUsage extends UsagePool {
|
|
61
|
+
/** 有效的赠送窗口,最早过期者在前,最多 5 个。 */
|
|
62
|
+
soonest: UsageWindow[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 把一次计量响应解析为快照。
|
|
66
|
+
*
|
|
67
|
+
* gproxy 参考实现会在其已被观察到使用的每个指针根下尝试个人 `Accounts`
|
|
68
|
+
* 数组,只有在没有任何数组匹配时才回退到企业单窗口解析 → 与发出的请求路径
|
|
69
|
+
* 无关。沿用这一顺序,可以让恰好携带 `enterpriseId` 的个人账户(或反之)
|
|
70
|
+
* 按它实际回应的结构解析,而不是按其凭据暗示的结构解析。
|
|
71
|
+
* @param raw - 已解析的响应体。
|
|
72
|
+
* @returns 组装好的快照,或响应体不含任何可解析内容时为 `undefined`。
|
|
73
|
+
*/
|
|
74
|
+
export declare function parseUsage(raw: unknown): UsageSnapshot | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* 获取个人账户的用量:每个生效套餐一个窗口。
|
|
77
|
+
*
|
|
78
|
+
* 请求体与官方 IDE 的 `getPersonalUsage` 完全一致(线上抓取):
|
|
79
|
+
* `PageNumber:1, PageSize:100, ProductCode:"p_tcaca", Status:[0,3]`
|
|
80
|
+
* 以及从当前时刻起 101 年的 `PackageEndTimeRange` 窗口 — 起点是“现在”,
|
|
81
|
+
* 终点是 101 年后,依据 `main.js`(`s = new Date`,
|
|
82
|
+
* `n = s + 101*365*24*60*60*1000`)。
|
|
83
|
+
* @param identity - 已登录的身份,由会话刷新。
|
|
84
|
+
* @param signal - 可选的取消信号。
|
|
85
|
+
* @returns 已解析的快照,或计费面不可达时为 `undefined`。
|
|
86
|
+
*/
|
|
87
|
+
export declare function fetchPersonalUsage(identity: CodeBuddyIdentity, signal?: AbortSignal): Promise<UsageSnapshot | undefined>;
|
|
88
|
+
/**
|
|
89
|
+
* 获取企业租户的用量:单个 `limitNum`/`credit` 对。
|
|
90
|
+
*
|
|
91
|
+
* 企业计费面接受空请求体并在 `data` 下回应,因此该请求就是一次带认证的 POST。
|
|
92
|
+
* @param identity - 已登录的身份,由会话刷新。
|
|
93
|
+
* @param signal - 可选的取消信号。
|
|
94
|
+
* @returns 已解析的快照,或计费面不可达时为 `undefined`。
|
|
95
|
+
*/
|
|
96
|
+
export declare function fetchEnterpriseUsage(identity: CodeBuddyIdentity, signal?: AbortSignal): Promise<UsageSnapshot | undefined>;
|
|
97
|
+
/**
|
|
98
|
+
* 获取并解析 CodeBuddy 用量快照,按账户类型分叉。
|
|
99
|
+
*
|
|
100
|
+
* 视已登录身份是否披露了 `enterpriseId`,委托给 {@link fetchPersonalUsage}
|
|
101
|
+
* 或 {@link fetchEnterpriseUsage}。所有失败模式都解析为 `undefined` 而不抛出;
|
|
102
|
+
* 是否重试由调用方决定。
|
|
103
|
+
* @param identity - 已登录的身份,由会话刷新。
|
|
104
|
+
* @param signal - 可选的取消信号。
|
|
105
|
+
* @returns 已解析的快照,或计费面不可达、回应了不可用响应体时为
|
|
106
|
+
* `undefined`。
|
|
107
|
+
*/
|
|
108
|
+
export declare function fetchUsage(identity: CodeBuddyIdentity, signal?: AbortSignal): Promise<UsageSnapshot | undefined>;
|
|
109
|
+
//# sourceMappingURL=usage.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-llm-codebuddy-power",
|
|
3
|
+
"description": "Tencent CodeBuddy plugin for DeepSeek Harness (dsh).",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"contributors": [
|
|
7
|
+
"pgnqukezrdxmhjso"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/pgnqukezrdxmhjso/dsh-llm-codebuddy-power",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/pgnqukezrdxmhjso/dsh-llm-codebuddy-power.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/pgnqukezrdxmhjso/dsh-llm-codebuddy-power/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"deepseek-harness",
|
|
19
|
+
"dsh-plugin",
|
|
20
|
+
"cordis",
|
|
21
|
+
"llm",
|
|
22
|
+
"codebuddy"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "lib/index.js",
|
|
26
|
+
"types": "lib/types/index.d.ts",
|
|
27
|
+
"bin": {
|
|
28
|
+
"codebuddy-power": "./lib/cli-login.js"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./lib/types/index.d.ts",
|
|
33
|
+
"default": "./lib/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./client": {
|
|
36
|
+
"types": "./lib/types/client/index.d.ts",
|
|
37
|
+
"default": "./lib/client.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"cordis.patch.yml",
|
|
43
|
+
"lib/index.js",
|
|
44
|
+
"lib/client.js",
|
|
45
|
+
"lib/cli-login.js",
|
|
46
|
+
"lib/types/**/*.d.ts",
|
|
47
|
+
"README.md",
|
|
48
|
+
"README.zh.md",
|
|
49
|
+
"LICENSE"
|
|
50
|
+
],
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@deepseek-ai/dsh-home-paths": "^0.1.5-rc.2",
|
|
53
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
54
|
+
"@deepseek-ai/dsh-tools": "^0.1.5-rc.2",
|
|
55
|
+
"@deepseek-ai/dsh-llm": "^0.1.5-rc.2",
|
|
56
|
+
"@deepseek-ai/schemastery": "^3.18.2"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/node": "^22.15.0",
|
|
60
|
+
"@types/react": "~18.3.1",
|
|
61
|
+
"@types/react-dom": "~18.3.0",
|
|
62
|
+
"react": "^18.2.0",
|
|
63
|
+
"react-dom": "^18.2.0",
|
|
64
|
+
"typescript": "^6.0.3",
|
|
65
|
+
"@deepseek-ai/dsh-agent": "^0.1.5-rc.2",
|
|
66
|
+
"@deepseek-ai/dsh-client-connection": "^0.1.5-rc.2",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-conversation": "^0.1.5-rc.2",
|
|
68
|
+
"@deepseek-ai/dsh-client-locale": "^0.1.5-rc.2",
|
|
69
|
+
"@deepseek-ai/cordis": "^4.0.2",
|
|
70
|
+
"@deepseek-ai/dsh-api-remotes": "^0.1.5-rc.2",
|
|
71
|
+
"@deepseek-ai/dsh-client-ui-chat": "^0.1.5-rc.2",
|
|
72
|
+
"@deepseek-ai/dsh-client-store": "^0.1.5-rc.2",
|
|
73
|
+
"@deepseek-ai/dsh-attachment": "^0.1.5-rc.2",
|
|
74
|
+
"@deepseek-ai/dsh-client-ui-renderer": "^0.1.5-rc.2",
|
|
75
|
+
"@deepseek-ai/dsh-client-ui-model-selection": "^0.1.5-rc.2",
|
|
76
|
+
"@deepseek-ai/dsh-client-ui-primitives": "^0.1.5-rc.2",
|
|
77
|
+
"@deepseek-ai/dsh-client-ui-tool": "^0.1.5-rc.2",
|
|
78
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.1.5-rc.2",
|
|
79
|
+
"@deepseek-ai/dsh-home-paths": "^0.1.5-rc.2",
|
|
80
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.1.5-rc.2",
|
|
81
|
+
"@deepseek-ai/dsh-host-webserver": "^0.1.5-rc.2",
|
|
82
|
+
"@deepseek-ai/dsh-llm": "^0.1.5-rc.2",
|
|
83
|
+
"@deepseek-ai/dsh-settings": "^0.1.5-rc.2",
|
|
84
|
+
"@deepseek-ai/dsh-session": "^0.1.5-rc.2",
|
|
85
|
+
"@deepseek-ai/dsh-tools": "^0.1.5-rc.2",
|
|
86
|
+
"@deepseek-ai/schemastery": "^3.18.2"
|
|
87
|
+
},
|
|
88
|
+
"dependencies": {
|
|
89
|
+
"eventsource-parser": "^3.1.0"
|
|
90
|
+
},
|
|
91
|
+
"dsh": {
|
|
92
|
+
"bundle": {
|
|
93
|
+
"patch": "./cordis.patch.yml"
|
|
94
|
+
},
|
|
95
|
+
"client": {
|
|
96
|
+
"platform": "web",
|
|
97
|
+
"inject": [
|
|
98
|
+
"@deepseek-ai/dsh-api-remotes",
|
|
99
|
+
"@deepseek-ai/dsh-client-connection",
|
|
100
|
+
"@deepseek-ai/dsh-client-locale",
|
|
101
|
+
"@deepseek-ai/dsh-client-ui-model-selection",
|
|
102
|
+
"@deepseek-ai/dsh-client-ui-settings",
|
|
103
|
+
"@deepseek-ai/dsh-client-ui-renderer"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
"scripts": {
|
|
108
|
+
"build": "tsc -b && tsdown",
|
|
109
|
+
"watch": "tsdown --watch",
|
|
110
|
+
"verify": "node ../dsh-pgnqukezrdxmhjso-base/verify.mjs",
|
|
111
|
+
"pub": "pnpm run build && pnpm login --registry=https://registry.npmjs.org && pnpm publish --registry=https://registry.npmjs.org --no-git-checks",
|
|
112
|
+
"pack": "pnpm run build && pnpm pack --pack-destination lib",
|
|
113
|
+
"pack-test-i": "pnpm run pack && (pnpm dsh plugin --profile pkgtest remove %npm_package_name% & pnpm dsh plugin --profile pkgtest add ./lib/%npm_package_name%-%npm_package_version%.tgz)",
|
|
114
|
+
"npm-test-i": "pnpm dsh plugin --profile pkgtest remove %npm_package_name% & pnpm dsh plugin --profile pkgtest add --registry=https://registry.npmjs.org %npm_package_name%@%npm_package_version%",
|
|
115
|
+
"test-create": "pnpm dsh --profile pkgtest --from-default-profile web",
|
|
116
|
+
"test-start": "pnpm dsh --profile pkgtest --port 3081 --no-open",
|
|
117
|
+
"login": "node lib/cli-login.js"
|
|
118
|
+
}
|
|
119
|
+
}
|