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.
Files changed (44) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +66 -0
  3. package/README.zh.md +66 -0
  4. package/cordis.patch.yml +32 -0
  5. package/lib/cli-login.js +2099 -0
  6. package/lib/client.js +2814 -0
  7. package/lib/index.js +3957 -0
  8. package/lib/types/adapter.d.ts +58 -0
  9. package/lib/types/atomic-file.d.ts +43 -0
  10. package/lib/types/auth-service.d.ts +195 -0
  11. package/lib/types/cli/login.d.ts +23 -0
  12. package/lib/types/client/AccountSwitcher.d.ts +53 -0
  13. package/lib/types/client/CodeBuddySection.d.ts +62 -0
  14. package/lib/types/client/ComposerControls.d.ts +29 -0
  15. package/lib/types/client/DrawToolCard.d.ts +24 -0
  16. package/lib/types/client/ModelPanel.d.ts +77 -0
  17. package/lib/types/client/TurnCreditPill.d.ts +33 -0
  18. package/lib/types/client/UsageIndicator.d.ts +21 -0
  19. package/lib/types/client/icons.d.ts +24 -0
  20. package/lib/types/client/index.d.ts +34 -0
  21. package/lib/types/client/locales.d.ts +90 -0
  22. package/lib/types/client/poll.d.ts +19 -0
  23. package/lib/types/client/store.d.ts +59 -0
  24. package/lib/types/client/wire.d.ts +147 -0
  25. package/lib/types/codebuddy.d.ts +187 -0
  26. package/lib/types/constants.d.ts +67 -0
  27. package/lib/types/credit-store.d.ts +25 -0
  28. package/lib/types/image-tool.d.ts +34 -0
  29. package/lib/types/index.d.ts +79 -0
  30. package/lib/types/login.d.ts +43 -0
  31. package/lib/types/model-enrich.d.ts +125 -0
  32. package/lib/types/prefs.d.ts +43 -0
  33. package/lib/types/rpc-route.d.ts +25 -0
  34. package/lib/types/selection.d.ts +35 -0
  35. package/lib/types/serialize.d.ts +37 -0
  36. package/lib/types/session-store.d.ts +63 -0
  37. package/lib/types/session.d.ts +415 -0
  38. package/lib/types/settings.d.ts +18 -0
  39. package/lib/types/sse.d.ts +22 -0
  40. package/lib/types/storage.d.ts +118 -0
  41. package/lib/types/translate.d.ts +61 -0
  42. package/lib/types/types.d.ts +345 -0
  43. package/lib/types/usage.d.ts +109 -0
  44. package/package.json +119 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Web 客户端部分:一个 CodeBuddy 设置页,以及对话框输入区的账号控件。
3
+ *
4
+ * 在 `settings.section` 中注册一个条目 —— 一个展示全部已登录账号、追加登录、
5
+ * 退出单个或选中账号、指定默认账号的 “CodeBuddy” 页面 —— 再在
6
+ * `conversation.input.right` 中注册一个条目,在 CodeBuddy 模型按钮左侧渲染当前
7
+ * 会话的额度圆环与账号切换按钮。
8
+ *
9
+ * 两个条目处在**不同作用域**(设置页 root、输入区 session),而一个 store handle
10
+ * 只能绑一个作用域,因此它们不共用句柄:设置页持有 store,对话控件按会话经 RPC
11
+ * 自取账号集合与用量(见该处的注册注释)。
12
+ *
13
+ * @module dsh-llm-codebuddy-power/client
14
+ */
15
+ import type { Context } from '@deepseek-ai/cordis';
16
+ export type { CodeBuddySectionInjected, CodeBuddySectionProps, } from './CodeBuddySection.tsx';
17
+ export type { ComposerControlsProps, CodeBuddyComposerControlsProps } from './ComposerControls.tsx';
18
+ export type { AccountSwitcherInjected } from './AccountSwitcher.tsx';
19
+ export type { CodeBuddyKey } from './locales.ts';
20
+ export type { CodeBuddyPrefs } from '../prefs.ts';
21
+ /** 必需服务:插槽注册表、locale 服务、wire、共享模型目录服务(该面板读取
22
+ * 与官方选择器相同的 store)、uiConversation(附件图片 URL),以及设置作用域
23
+ * (界面偏好所在的命名空间)。
24
+ *
25
+ * 声明 `sessions`/`remote`/`remote.session` 是因为
26
+ * `modelDirectories.directoryFor()` 在本插件的 Context 下运行,并在构建
27
+ * 会话目录时读取这些服务。 */
28
+ export declare const inject: string[];
29
+ /**
30
+ * 在插槽声明后注册 CodeBuddy 设置分区与对话内账号控件。
31
+ * @param ctx - 客户端根 context。
32
+ */
33
+ export declare function apply(ctx: Context): void;
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,90 @@
1
+ /** CodeBuddy 设置分区与对话内账号控件的文案字典。 */
2
+ /** 英文字符串(zh/en 键集合的事实来源)。 */
3
+ export declare const en: {
4
+ nav: string;
5
+ intro: string;
6
+ loading: string;
7
+ notSignedIn: string;
8
+ waiting: string;
9
+ signIn: string;
10
+ signingIn: string;
11
+ copyLoginLink: string;
12
+ copyLoginLinkFailed: string;
13
+ copied: string;
14
+ cancelLogin: string;
15
+ timeout: string;
16
+ multiSelect: string;
17
+ multiSelectDone: string;
18
+ selectAccount: string;
19
+ logoutSelectedTip: string;
20
+ logoutTitle: string;
21
+ logoutSelectedTitle: string;
22
+ logoutDesc: string;
23
+ logoutSelectedDesc: string;
24
+ logoutConfirm: string;
25
+ cancel: string;
26
+ chooseDefault: string;
27
+ clearDefault: string;
28
+ defaultTag: string;
29
+ nickname: string;
30
+ uid: string;
31
+ loginExpires: string;
32
+ uin: string;
33
+ enterprise: string;
34
+ enterpriseId: string;
35
+ enterpriseUser: string;
36
+ department: string;
37
+ switchAccount: string;
38
+ showUsage: string;
39
+ showUsageDesc: string;
40
+ drawToolMinimal: string;
41
+ drawToolMinimalDesc: string;
42
+ dangerPct: string;
43
+ dangerPctDesc: string;
44
+ usageUsed: string;
45
+ usageMain: string;
46
+ usageGift: string;
47
+ usageResets: string;
48
+ drawGenerating: string;
49
+ drawGenerated: string;
50
+ drawImageLoading: string;
51
+ drawImageAlt: string;
52
+ drawImageOpen: string;
53
+ drawImagePreviewTitle: string;
54
+ drawImagePreviewClose: string;
55
+ turnCredit: string;
56
+ turnCreditTip: string;
57
+ turnCreditAccount: string;
58
+ modelPanelTrigger: string;
59
+ modelPanelTitle: string;
60
+ modelPanelEmpty: string;
61
+ modelPanelSelectError: string;
62
+ modelPanelContextWindow: string;
63
+ modelPanelMaxOutput: string;
64
+ modelPanelFeatures: string;
65
+ modelPanelSpendRate: string;
66
+ modelPanelUse: string;
67
+ modelPanelUpgrade: string;
68
+ modelPanelEdit: string;
69
+ modelPanelDescriptionMissing: string;
70
+ modelPanelSave: string;
71
+ modelPanelSaving: string;
72
+ modelPanelRestoreDefault: string;
73
+ modelPanelEffort: string;
74
+ modelPanelEffortDefault: string;
75
+ modelPanelFeatureImage: string;
76
+ modelPanelFeatureReasoning: string;
77
+ };
78
+ /** settings.codebuddy 命名空间的键联合。 */
79
+ export type CodeBuddyKey = keyof typeof en;
80
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
81
+ interface LocaleNamespaceMap {
82
+ /** CodeBuddy 设置页与对话内账号控件的文案。 */
83
+ 'settings.codebuddy': CodeBuddyKey;
84
+ }
85
+ }
86
+ /** 中文字符串(键与 {@link en} 相同)。 */
87
+ export declare const zh: {
88
+ [Key in keyof typeof en]: string;
89
+ };
90
+ //# sourceMappingURL=locales.d.ts.map
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 参数化的轮询钩子:入参说明「查什么数据」「多久查一次」「这里是否需要它」。
3
+ *
4
+ * 抽成共享钩子而不是各组件自建定时器,是为了让计时器的建立与清理只写一次;节奏仍由
5
+ * 每个消费方按自己那份数据的更新速度给出 —— 两份数据的更新速度不同,不该被迫取同一个值。
6
+ *
7
+ * @module dsh-llm-codebuddy-power/client/poll
8
+ */
9
+ /**
10
+ * 启用时立即读取一次数据源,其后每 `intervalMs` 重复;停用时不读取也不计时。
11
+ *
12
+ * `read` 经 ref 持有,因此调用方可以传内联闭包:轮询节奏只由 `intervalMs` 与
13
+ * `active` 决定,不会因为闭包每次渲染都是新身份而反复重建计时器。
14
+ * @param read - 每次轮询要读取的数据。
15
+ * @param intervalMs - 两次读取之间的间隔,单位 ms;由该数据自身的更新速度决定。
16
+ * @param active - 这里是否需要这份数据;为假时不读取也不轮询,由假转真会立即读取一次。
17
+ */
18
+ export declare function usePolledRead(read: () => void, intervalMs: number, active: boolean): void;
19
+ //# sourceMappingURL=poll.d.ts.map
@@ -0,0 +1,59 @@
1
+ /**
2
+ * CodeBuddy 页面 store:设置分区共享的账号快照。
3
+ *
4
+ * 客户端插件在设置页条目下挂载本句柄,因此在设置分区里完成的登录、退出或改
5
+ * 默认账号无需跨组件接线即可到达同一页面的各个徽章。
6
+ *
7
+ * **界面偏好不在这里**:它们是 harness 用户设置文档里的一段(见 `../prefs.ts`),
8
+ * 由 `./index.ts` 经 `ctx.settingsScope.bind()` 读取,并以一个派生的活快照经
9
+ * 注入面的 `hooks` 隔舱同时下发给设置页与对话输入区的控件组 —— 后者处在另一个
10
+ * 作用域,共享不了本句柄。偏好此前存在 `localStorage` 并由输入区按 5 秒轮询
11
+ * 读取,导致开关与圆环之间有最多一个轮询周期的延迟。
12
+ *
13
+ * @module dsh-llm-codebuddy-power/client/store
14
+ */
15
+ import { type EngineStoreHandle } from '@deepseek-ai/dsh-client-store';
16
+ import type { CodeBuddyAccountView, CodeBuddyAccountsResult } from './wire.ts';
17
+ /** 该分区循环经历的 UI 阶段。 */
18
+ export type CodeBuddyPhase = 'loading' | 'idle' | 'error';
19
+ /** 一次进行中的浏览器登录握手。 */
20
+ export interface PendingLogin {
21
+ /** 宿主发起的握手 id,轮询时回传。 */
22
+ state: string;
23
+ /**
24
+ * 发起时刻(epoch ms)。截止时间据此计算并存进 store —— 放在组件的 effect 里会让
25
+ * 每次重新挂载(关闭再打开设置页)都把计时归零,于是反复开关就能把"登录中…"
26
+ * 无限延长。
27
+ */
28
+ startedAt: number;
29
+ }
30
+ /** 设置分区共享的页面快照。 */
31
+ export interface CodeBuddyState {
32
+ phase: CodeBuddyPhase;
33
+ /** 整页失败文案;行级 RPC 失败留在调用方。 */
34
+ error: string | null;
35
+ /** 已存账号;加载中或未登录时为空数组。 */
36
+ accounts: CodeBuddyAccountView[];
37
+ /** 用户显式指定的默认账号 uid;未指定时为 null。 */
38
+ defaultUid: string | null;
39
+ /** 正在轮询浏览器登录握手时非 null。 */
40
+ loginState: PendingLogin | null;
41
+ }
42
+ /** 声明的 action 结构,为导出的工厂提供稳定的返回类型。 */
43
+ type CodeBuddyActions = {
44
+ /** 进入加载阶段并丢弃先前的状态/错误。 */
45
+ start: (draft: CodeBuddyState) => void;
46
+ /** 发布账号集合与默认账号,并离开加载阶段。 */
47
+ setAccounts: (draft: CodeBuddyState, result: CodeBuddyAccountsResult) => void;
48
+ /** 发布页面级失败。 */
49
+ fail: (draft: CodeBuddyState, message: string) => void;
50
+ /** 跟踪进行中的浏览器登录握手(null 表示没有)。 */
51
+ setLoginState: (draft: CodeBuddyState, state: PendingLogin | null) => void;
52
+ };
53
+ /**
54
+ * 声明 CodeBuddy 页面状态与写入接口。
55
+ * @returns store 句柄(在 apply 中挂载于设置页条目下)。
56
+ */
57
+ export declare function createCodeBuddyStore(): EngineStoreHandle<CodeBuddyState, CodeBuddyActions>;
58
+ export {};
59
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1,147 @@
1
+ /**
2
+ * CodeBuddy 鉴权 RPC 通道的客户端 wire 契约。
3
+ *
4
+ * host 的 `CodeBuddyAuthService` 在 Connection 通道 `/codebuddy` 上注册这些
5
+ * endpoint;此处的 payload 结构是 host 自身应答类型的客户端投影。仅纯 JSON
6
+ * 数据 —— 浏览器标签页可以调用它们,但永远看不到 host 对象。
7
+ */
8
+ import type { ClientConnectionRpc, ConnectionRpcResult } from '@deepseek-ai/dsh-client-connection/client';
9
+ /** host 鉴权服务监听的 RPC 通道(与 host 常量保持一致)。 */
10
+ export declare const AUTH_CHANNEL = "/codebuddy";
11
+ /**
12
+ * host `accounts` endpoint 上报的一个账号。
13
+ *
14
+ * 字段按"可能缺失"声明,尽管宿主侧同名字段是必填:两个编译面**不是**原子部署的 ——
15
+ * 客户端插件可以经 HMR 单独重载,而宿主仍在跑旧的 `lib/index.js`。旧宿主不带新字段,
16
+ * 按必填声明会让缺失悄悄变成 `Invalid Date` 而不是一处类型错误。
17
+ */
18
+ export interface CodeBuddyAccountView {
19
+ uid: string;
20
+ nickname: string;
21
+ /** 刷新令牌的绝对过期时刻(epoch ms);旧宿主不提供时缺省。 */
22
+ loginExpiresAt?: number;
23
+ uin?: string;
24
+ enterpriseId?: string;
25
+ enterpriseName?: string;
26
+ enterpriseUserName?: string;
27
+ departmentFullName?: string;
28
+ }
29
+ /** host `accounts` endpoint 返回的结构。 */
30
+ export interface CodeBuddyAccountsResult {
31
+ accounts: CodeBuddyAccountView[];
32
+ /** 用户显式指定的默认账号;未指定时缺省。 */
33
+ defaultUid?: string;
34
+ }
35
+ /** `startLogin` 的结果结构。 */
36
+ export interface CodeBuddyLoginStart {
37
+ authUrl: string;
38
+ state: string;
39
+ }
40
+ /** `pollLogin` 的结果结构。 */
41
+ export interface CodeBuddyLoginPoll {
42
+ done: boolean;
43
+ nickname?: string;
44
+ }
45
+ /** `sessionAccount` 的结果结构。 */
46
+ export interface CodeBuddySessionAccount {
47
+ /** 该会话此刻生效的账号 uid;一个账号也没有时缺省。 */
48
+ uid?: string;
49
+ }
50
+ /** host `usage` endpoint 上报的一个计量窗口。 */
51
+ export interface CodeBuddyUsageWindow {
52
+ name: string;
53
+ used?: number;
54
+ limit?: number;
55
+ resetsAt?: string;
56
+ }
57
+ /** 一个聚合后的额度池。 */
58
+ export interface CodeBuddyUsagePool {
59
+ used: number;
60
+ limit: number;
61
+ }
62
+ /** 赠送额度的汇总,以及其提示框中最快到期部分的明细。 */
63
+ export interface CodeBuddyUsageGift extends CodeBuddyUsagePool {
64
+ /** 生效中的赠送窗口,按最快到期排序,最多 5 个。 */
65
+ soonest: CodeBuddyUsageWindow[];
66
+ }
67
+ /** host `usage` endpoint 返回的用量结果结构。 */
68
+ export interface CodeBuddyUsageResult {
69
+ loggedIn: boolean;
70
+ /** 首个计量窗口的重置时刻;圆环的提示把它与额度数值显示在一起。 */
71
+ primaryResetsAt?: string;
72
+ /** 可续期的主额度池。 */
73
+ main?: CodeBuddyUsagePool;
74
+ /** 一次性的赠送额度池及其最快到期明细。 */
75
+ gift?: CodeBuddyUsageGift;
76
+ }
77
+ /** 一条促销的面向前端展示信息(与 host 投影保持一致)。 */
78
+ export interface CodeBuddyPromotionView {
79
+ label: string;
80
+ color: string;
81
+ discountedCredits?: string;
82
+ displayMode?: string;
83
+ textZh?: string;
84
+ textEn?: string;
85
+ action?: {
86
+ type?: string;
87
+ labelZh?: string;
88
+ labelEn?: string;
89
+ };
90
+ }
91
+ /** 一个模型档位的面向前端展示信息。 */
92
+ export interface CodeBuddyTierView {
93
+ label: string;
94
+ textZh?: string;
95
+ textEn?: string;
96
+ action?: {
97
+ type?: string;
98
+ labelZh?: string;
99
+ labelEn?: string;
100
+ };
101
+ }
102
+ /** 供面板使用的一条增强后的 CodeBuddy 模型记录。 */
103
+ export interface CodeBuddyModelRow {
104
+ id: string;
105
+ name: string;
106
+ credits?: string;
107
+ promotion?: CodeBuddyPromotionView;
108
+ tier?: CodeBuddyTierView;
109
+ supportsImages?: boolean;
110
+ supportsReasoning?: boolean;
111
+ supportsToolCall?: boolean;
112
+ contextWindow?: number;
113
+ maxOutputTokens?: number;
114
+ /** 目录公布的容量上限,不受用户覆写影响;编辑时用它限制可输入的上限。 */
115
+ contextWindowCap?: number;
116
+ /** 目录公布的最大输出上限;与 `contextWindowCap` 同理。 */
117
+ maxOutputTokensCap?: number;
118
+ descriptionZh?: string;
119
+ descriptionEn?: string;
120
+ }
121
+ /** `models` 返回给客户端的结构。 */
122
+ export interface CodeBuddyModelsResult {
123
+ models: CodeBuddyModelRow[];
124
+ }
125
+ /** 按模型的用户上限,与 host 覆写表条目保持一致。 */
126
+ export interface CodeBuddyModelOverrides {
127
+ contextWindow?: number;
128
+ maxOutputTokens?: number;
129
+ }
130
+ /** `creditOf` 上报的一个账号。 */
131
+ export interface CodeBuddyTurnCreditAccountView {
132
+ nickname: string;
133
+ /** 账号 uid 的前段,只用于区分同名账号。 */
134
+ uidPrefix: string;
135
+ }
136
+ /** `creditOf` 返回的每轮积分记录;该轮没有记录时缺省。 */
137
+ export interface CodeBuddyTurnCreditRecord {
138
+ credit: number;
139
+ /** 本轮扣分用过的账号,按首次使用排序;一轮里切换过账号时会有多个。 */
140
+ accounts: CodeBuddyTurnCreditAccountView[];
141
+ }
142
+ /**
143
+ * 在共享通道上调用一个鉴权 endpoint。该通道调用按设计不做类型约束;
144
+ * endpoint 所记录的 payload 结构在此唯一的 wire 边界处恢复。
145
+ */
146
+ export declare function authCall<T>(rpc: ClientConnectionRpc, endpoint: string, payload?: unknown): Promise<ConnectionRpcResult<T>>;
147
+ //# sourceMappingURL=wire.d.ts.map
@@ -0,0 +1,187 @@
1
+ /**
2
+ * CodeBuddy 控制面客户端:浏览器 OAuth 握手、令牌刷新,
3
+ * 以及非 OpenAI 模型目录。
4
+ *
5
+ * 这里的每次调用都以 `{code, msg, data}` 信封而非仅 HTTP 状态码
6
+ * 表达结果,因此返回 200 却带有非零 `code` 即为失败,并
7
+ * 按失败上报。本模块只负责传输:不持有状态,也不做
8
+ * 策略决策,因此登录流程、适配器与 CLI 得以共用
9
+ * 同一份实现。
10
+ *
11
+ * @module dsh-llm-codebuddy-power/codebuddy
12
+ */
13
+ import type { Account, AuthState, AuthToken, CodeBuddyConfig } from './types.ts';
14
+ /** CodeBuddy 在每个已认证请求上要求的身份信息。 */
15
+ export interface CodeBuddyIdentity {
16
+ accessToken: string;
17
+ domain: string;
18
+ uid: string;
19
+ enterpriseId?: string;
20
+ departmentFullName?: string;
21
+ }
22
+ /**
23
+ * 官方 CodeBuddy CN 4.11.3 客户端在其 CustomFetch 面(chat、catalog)上
24
+ * 发送的组合 IDE `User-Agent`。实测抓包为 `CodeBuddyIDE/4.11.3 CodeBuddy/4.11.3`。
25
+ * @returns IDE user-agent 字符串。
26
+ */
27
+ export declare function ideUserAgent(): string;
28
+ /**
29
+ * 官方 IDE 主进程的认证/计费客户端发送的 `User-Agent`。
30
+ *
31
+ * `main.js` 在一个裸 axios 实例上发起登录与计量请求(无拦截器
32
+ * 链),因此它们携带 axios 默认 UA —— 实测在 `/v2/plugin/auth/*` 与
33
+ * `/v2/billing/meter/*` 上抓到的值为 `axios/1.15.0`。
34
+ * @returns axios user-agent 字符串。
35
+ */
36
+ export declare function axiosUserAgent(): string;
37
+ /**
38
+ * 登录握手与计量共用的 axios 面请求头:
39
+ * axios 默认的 `Accept` 与 `User-Agent`,外加每次调用各自的头。
40
+ *
41
+ * 在官方 IDE 中这两个面运行在同一个裸 axios 客户端上,
42
+ * 因此尽管各自的额外头不同,帧结构仍相同。
43
+ * @param extra - 请求专属头(`X-No-*`、`Authorization` 等)。
44
+ * @returns 请求头。
45
+ */
46
+ export declare function axiosRequestHeaders(extra: Record<string, string>): Record<string, string>;
47
+ /**
48
+ * 发起一次浏览器登录握手。
49
+ * @param signal - 可选取消。
50
+ * @returns 握手状态,以及用户必须打开的 URL。
51
+ * @throws Error 服务拒绝或返回不可用的响应体时。
52
+ */
53
+ export declare function requestAuthState(signal?: AbortSignal): Promise<AuthState>;
54
+ /**
55
+ * 轮询,直到用户在浏览器中完成登录。
56
+ *
57
+ * 服务用 code {@link AUTH_PENDING_CODE} 表示“尚未完成”,
58
+ * 它是唯一让循环继续的 code;其他任何 code 都是已决结果,循环
59
+ * 就此结束。传输错误同样结束循环,因为状态可能已被消耗的
60
+ * 握手不得静默重试。
61
+ * @param state - 来自 {@link requestAuthState} 的握手 id。
62
+ * @param signal - 可选取消。
63
+ * @returns 签发的令牌;登录失败或超时时为 `undefined`。
64
+ */
65
+ export declare function pollAuthToken(state: string, signal?: AbortSignal): Promise<AuthToken | undefined>;
66
+ /**
67
+ * 读取已登录账号,其 uid 与企业 id 会成为之后每个请求的必需
68
+ * 请求头。
69
+ * @param state - 令牌所对应的握手 id。
70
+ * @param accessToken - 刚签发的 access token。
71
+ * @param domain - 令牌所对应的租户 domain。
72
+ * @returns 账号信息。
73
+ * @throws Error 服务拒绝或返回不可用的响应体时。
74
+ */
75
+ export declare function getLoginAccount(state: string, accessToken: string, domain: string): Promise<Account>;
76
+ /**
77
+ * 用 refresh token 换取新的 access token。
78
+ * @param identity - 当前身份,包含正被替换的 access token。
79
+ * @param refreshToken - 要使用的 refresh token。
80
+ * @returns 新令牌;刷新被拒绝时为 `undefined`。
81
+ */
82
+ export declare function refreshAccessToken(identity: CodeBuddyIdentity, refreshToken: string): Promise<AuthToken | undefined>;
83
+ /**
84
+ * 一个新的无连字符 uuid;CodeBuddy 各面用作请求 id 与
85
+ * 会话 id 的紧凑形式。
86
+ * @returns 32 个十六进制字符的 id。
87
+ */
88
+ export declare function compactUuid(): string;
89
+ /**
90
+ * 一个新的 trace id:32 个小写十六进制字符,即官方客户端的
91
+ * OpenTelemetry span 为 `x-trace-id` / `x-b3-traceid` 生成的形态
92
+ * (16 个随机字节的十六进制)。
93
+ * @returns 32 个十六进制字符的 trace id。
94
+ */
95
+ export declare function traceId(): string;
96
+ /**
97
+ * 一个新的 span id:16 个小写十六进制字符,即官方客户端的
98
+ * OpenTelemetry span 为 `x-b3-spanid` / 父 id 生成的形态
99
+ * (8 个随机字节的十六进制)。
100
+ * @returns 16 个十六进制字符的 span id。
101
+ */
102
+ export declare function spanId(): string;
103
+ /**
104
+ * 每个 CustomFetch 面请求(chat、catalog)都携带的共享客户端身份
105
+ * 头,与官方 IDE 4.11.3 的抓包一致:
106
+ * IDE user-agent、SaaS 产品标记、XMLHttpRequest 来源,以及
107
+ * 每个请求一个新生成的紧凑 `X-Request-ID`。
108
+ *
109
+ * CodeBuddy 的安全策略会拒绝任何它不认作自家客户端的 User-Agent
110
+ * (实测:带 harness 标识的 User-Agent 会被以 HTTP 400 / code 11128
111
+ * 拒绝)。提供方自身的产品身份是唯一被接受的载体,因此本函数是
112
+ * chat 与 catalog 两条传输上该身份的唯一来源。
113
+ * @returns 共享身份头,其中 request id 为新生成。
114
+ */
115
+ export declare function clientIdentityHeaders(): Record<string, string>;
116
+ /**
117
+ * 一次 chat 请求的 b3 / X-B3 trace 头,外加 CustomFetch 面同步
118
+ * 的原始 trace id 头。所有 id 每次调用都重新生成,
119
+ * 与官方客户端的每请求 span 一致。
120
+ * @returns trace 头,其中 trace/span id 为新生成。
121
+ */
122
+ export declare function traceHeaders(): Record<string, string>;
123
+ /**
124
+ * 一次图像生成请求的参数,与官方 IDE 的 `image_gen`
125
+ * 工具所接受的一致。
126
+ */
127
+ export interface ImageGenArgs {
128
+ /** 要生成图像的文字描述。 */
129
+ prompt: string;
130
+ /** 输出尺寸;省略时 wire 上默认为 `1024x1024`。 */
131
+ size?: string;
132
+ /** 质量提示(`low`/`medium`/`high`);原样透传。 */
133
+ quality?: string;
134
+ /** 风格提示;原样透传。 */
135
+ style?: string;
136
+ /** 图像数量;服务最多只接受模型每次调用的上限。 */
137
+ n?: number;
138
+ }
139
+ /** 图像生成响应中有用的部分。 */
140
+ export interface GeneratedImage {
141
+ /** 携带 PNG 字节的签名对象存储 URL(schema 允许为 null)。 */
142
+ url?: string;
143
+ /** 服务返回 base64 而非 URL 时的图像数据。 */
144
+ b64_json?: string;
145
+ }
146
+ /** 解析后的图像生成结果:图像以及计费的 credits。 */
147
+ export interface ImageGenResult {
148
+ images: GeneratedImage[];
149
+ /** 本批次服务计费的 credits(`usage.credit`)。 */
150
+ usedCredits: number;
151
+ }
152
+ /**
153
+ * 通过 CodeBuddy 的图像模型生成图像。
154
+ *
155
+ * 复刻官方 IDE 的 `ImageGenTool` wire 调用(`POST
156
+ * /v2/images/generations`,模型 `hunyuan-image-alpha`),并发送完整的
157
+ * IDE 身份头,从而让计费控制台按给定的会话 id 将调用方
158
+ * 记为 IDE 客户端。服务收取的 credits 通过 `usage.credit` 带出。
159
+ * @param identityHeaders - 已认证的身份头(`requestIdentity`)。
160
+ * @param model - 文生图模型 id,例如 `hunyuan-image-alpha`。
161
+ * @param args - 生成提示词与选项。
162
+ * @param conversationIds - 为本次请求生成的会话/轮次/消息 id
163
+ * (`X-Conversation-ID`、`X-Conversation-Request-ID`、
164
+ * `X-Conversation-Message-ID`)。
165
+ * @param signal - 可选取消。
166
+ * @returns 生成的图像与计费的 credits。
167
+ * @throws Error 服务拒绝或返回不可用的响应体时。
168
+ */
169
+ export declare function generateImage(identityHeaders: Record<string, string>, model: string, args: ImageGenArgs, conversationIds: {
170
+ conversationId: string;
171
+ requestId: string;
172
+ messageId: string;
173
+ }, signal?: AbortSignal): Promise<ImageGenResult>;
174
+ /**
175
+ * 读取 CodeBuddy 模型目录。
176
+ *
177
+ * 这是该服务中非 OpenAI 兼容的那一半,也是本插件无法被通用
178
+ * OpenAI 兼容路由取代的原因:该响应会披露每个模型的能力标记与
179
+ * 尺寸,而 `GET /models` 列表不会。
180
+ * @param identityHeaders - 已认证的身份头,由会话构建一次
181
+ * (`requestIdentity()`),使 chat 与目录共用同一套。
182
+ * @param signal - 可选取消。
183
+ * @returns 目录。
184
+ * @throws Error 服务拒绝或返回不可用的响应体时。
185
+ */
186
+ export declare function getConfig(identityHeaders: Record<string, string>, signal?: AbortSignal): Promise<CodeBuddyConfig>;
187
+ //# sourceMappingURL=codebuddy.d.ts.map
@@ -0,0 +1,67 @@
1
+ /**
2
+ * CodeBuddy 服务的固定事实。
3
+ *
4
+ * 这些是协议常量而非用户配置:endpoint 同时承载 OAuth 握手与模型目录,
5
+ * 版本字符串则是服务期望插件客户端用于表明自身身份的内容。
6
+ *
7
+ * @module dsh-llm-codebuddy-power/constants
8
+ */
9
+ /** 本插件在 `ctx.llm` 上注册的 provider 路由。 */
10
+ export declare const CODEBUDDY_PROVIDER = "codebuddy";
11
+ /** 在模型选择器与设置界面中展示的显示名。 */
12
+ export declare const CODEBUDDY_DISPLAY_NAME = "CodeBuddy";
13
+ /** CodeBuddy 服务根地址;认证握手与 `/v3/config` 都在此处。 */
14
+ export declare const CODEBUDDY_ENDPOINT = "https://copilot.tencent.com";
15
+ /**
16
+ * 兼容 OpenAI 的对话基础地址。只有对话 wire 路由兼容;`/v3/config` 处的
17
+ * 模型目录并不兼容,这就是本插件自带目录读取器、而不使用 OpenAI
18
+ * `GET /models` 列表的原因。
19
+ */
20
+ export declare const CODEBUDDY_CHAT_BASE = "https://copilot.tencent.com/v2";
21
+ /** 在对话与模型目录请求中上报的 IDE 版本,与官方 CodeBuddy CN 4.11.3 客户端一致。 */
22
+ export declare const CODEBUDDY_IDE_VERSION = "4.11.3";
23
+ /** 官方 IDE 的产品段名称,用于拼接后的 `User-Agent`。 */
24
+ export declare const CODEBUDDY_PRODUCT_NAME = "CodeBuddy";
25
+ /**
26
+ * 官方 IDE 主进程 auth/billing 客户端发送的 User-Agent。
27
+ *
28
+ * 登录与计量请求在 `main.js` 中使用裸 axios 实例(没有拦截器链),因此携带
29
+ * 的是 axios 默认 UA,而不是 CustomFetch 平面使用的 IDE 身份 UA。
30
+ * 实测抓包:`/v2/plugin/auth/*` 与 `/v2/billing/meter/*` 都发送 `axios/1.15.0`。
31
+ */
32
+ export declare const CODEBUDDY_AXIOS_USER_AGENT = "axios/1.15.0";
33
+ /**
34
+ * 目录完全未描述的模型所假定的上下文容量。
35
+ *
36
+ * 这是约定值,不是 CodeBuddy 提供的数字:服务按模型披露 `maxAllowedSize`,
37
+ * 不提供可回退的全局默认值。因此已列出的模型绝不会按此定尺寸——隐去容量的
38
+ * 条目会直接从头列表中丢弃。它只适用于目录未列出、却被显式指名的 id,
39
+ * 此时必须有假定值才能解析出路由。
40
+ */
41
+ export declare const DEFAULT_CONTEXT_WINDOW = 128000;
42
+ /** 未列出模型所假定的输出上限;同上的约定值。 */
43
+ export declare const DEFAULT_MAX_TOKENS = 8192;
44
+ /** 有一次流读取尚未完成时,provider 的默认最大空闲时间。 */
45
+ export declare const DEFAULT_STREAM_IDLE_TIMEOUT_MS = 300000;
46
+ /**
47
+ * 单张请求图片在 base64 膨胀前的编码字节目标。
48
+ *
49
+ * 这是本插件对请求图片的唯一硬性约束:源图未超过它就不做任何转换。取值与
50
+ * 官方 CodeBuddy IDE 的拖放路径一致(`TARGET_SIZE_MB = 1`)。
51
+ */
52
+ export declare const REQUEST_IMAGE_MAX_BYTES: number;
53
+ /**
54
+ * 源图超过字节目标时逐档收紧的长边档位。
55
+ *
56
+ * 档位取自官方 CodeBuddy IDE 拖放路径的 `COMPRESS_ATTEMPTS`(1920、1440、1080)。
57
+ * 需要逐档重试是因为附件服务的编码阶梯只降质量、不再降尺寸,单靠一档无法保证
58
+ * 落到字节目标。
59
+ */
60
+ export declare const REQUEST_IMAGE_DIMENSION_LADDER: readonly [1920, 1440, 1080];
61
+ /** 浏览器登录流程等待用户完成的时长,单位 ms。 */
62
+ export declare const LOGIN_TIMEOUT_MS: number;
63
+ /** 等待浏览器登录完成时的轮询间隔,单位 ms。 */
64
+ export declare const LOGIN_POLL_INTERVAL_MS = 1000;
65
+ /** 含义为“浏览器登录尚未完成”的服务码。 */
66
+ export declare const AUTH_PENDING_CODE = 11217;
67
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 插件自有的每轮积分持久化:按会话存到独立文件,绕过 dsh 会话日志白名单。
3
+ *
4
+ * 每会话一个 JSON 文件,内容为 `{ [turn]: { credit } }`(轮次号 → 该轮扣分)。
5
+ * 文件是纯增量记录:缺文件等价于空记录,写入是合并回写(原子替换)。模型不存
6
+ * ——dsh 用量自带。文件只增不删:会话被销毁(一次性子代理跑完即如此)不等于
7
+ * 用户删除了会话,此时删除会让那一轮的扣分永远查不到。
8
+ *
9
+ * @module dsh-llm-codebuddy-power/credit-store
10
+ */
11
+ import type { TurnCreditRecord } from './session.ts';
12
+ /**
13
+ * 读取一个会话的全部积分记录。
14
+ * @param sessionId - dsh 会话 id。
15
+ * @returns 轮次号 → 记录的映射;缺文件或损坏返回空对象(纯增量记录,无文件=无记录)。
16
+ */
17
+ export declare function loadCredits(sessionId: string): Promise<Record<string, TurnCreditRecord>>;
18
+ /**
19
+ * 合并写入一个会话某轮的积分(原子替换,文件不存在则新建)。
20
+ * @param sessionId - dsh 会话 id。
21
+ * @param turn - 轮次号。
22
+ * @param record - 该轮消耗的积分。
23
+ */
24
+ export declare function saveCredit(sessionId: string, turn: number, record: TurnCreditRecord): Promise<void>;
25
+ //# sourceMappingURL=credit-store.d.ts.map
@@ -0,0 +1,34 @@
1
+ /**
2
+ * codebuddy-draw 工具:调用 CodeBuddy 文生图模型生成图片,通过标准附件服务
3
+ * 持久化,并在对话中内联展示。
4
+ *
5
+ * 与官方 IDE 的 image_gen 工具一致:聊天模型用提示词调用它,请求携带全套 IDE
6
+ * 身份头(后台计费按 IDE 客户端与会话请求 id 记录)。生成的字节走
7
+ * attachments.saveImage 提交到标准附件仓库(content-addressed、归一化、
8
+ * 回放安全),轨迹/详情按标准 ImageBlock 渲染;对话卡片由浏览器半的
9
+ * DrawToolCard 经 uiConversation.imageUrl 标准附件通道读取展示。
10
+ *
11
+ * @module dsh-llm-codebuddy-power/image-tool
12
+ */
13
+ import type { Context } from '@deepseek-ai/cordis';
14
+ import type { AttachmentStore, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
15
+ import type { CodeBuddySession } from './session.ts';
16
+ /** 工具名;注册前检查唯一性。 */
17
+ export declare const CODEBUDDY_DRAW_TOOL = "codebuddy-draw";
18
+ /**
19
+ * 工具的标准输出:持久化图片引用 + 实际扣分 + 提示词。浏览器卡片按
20
+ * attachment 渲染,回放无需外部存储。
21
+ */
22
+ export interface CodeBuddyDrawValue {
23
+ prompt: string;
24
+ usedCredits: number;
25
+ images: ImageAttachmentRef[];
26
+ }
27
+ /**
28
+ * 注册 codebuddy-draw 工具。
29
+ * @param ctx - 注册作用域;执行时使用 session 与 attachments。
30
+ * @param session - 已登录的 CodeBuddy 会话(身份头 + 会话 id)。
31
+ * @param attachments - 图片持久化所用的标准附件仓库。
32
+ */
33
+ export declare function applyImageTool(ctx: Context, session: CodeBuddySession, attachments: AttachmentStore): void;
34
+ //# sourceMappingURL=image-tool.d.ts.map