dsh-llm-codebuddy-power 1.0.0 → 1.2.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 -22
- package/README.md +85 -66
- package/README.zh.md +85 -66
- package/cordis.patch.yml +7 -7
- package/icon.svg +6 -0
- package/lib/cli-login.js +4 -4
- package/lib/client.js +368 -270
- package/lib/index.js +321 -172
- package/lib/types/adapter.d.ts +7 -1
- package/lib/types/auth-service.d.ts +58 -11
- package/lib/types/client/CodeBuddySection.d.ts +14 -7
- package/lib/types/client/index.d.ts +6 -6
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/store.d.ts +17 -9
- package/lib/types/client/wire.d.ts +18 -1
- package/lib/types/constants.d.ts +8 -0
- package/lib/types/index.d.ts +43 -21
- package/lib/types/prefs.d.ts +17 -13
- package/lib/types/serialize.d.ts +19 -10
- package/lib/types/session.d.ts +3 -3
- package/lib/types/settings.d.ts +10 -7
- package/lib/types/storage.d.ts +2 -2
- package/package.json +37 -30
- package/lib/types/client/UsageIndicator.d.ts +0 -21
- package/lib/types/client/poll.d.ts +0 -19
- package/lib/types/credit-store.d.ts +0 -25
- package/lib/types/selection.d.ts +0 -35
package/lib/types/adapter.d.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { LlmAdapter } from '@deepseek-ai/dsh-llm';
|
|
12
12
|
import type { GenerateOptions, LlmModelInfo, LlmProviderInfo, LlmResolvedModelInfo, StreamChunk } from '@deepseek-ai/dsh-llm';
|
|
13
|
-
import type {
|
|
13
|
+
import type { ImageAttachmentAccess } from '@deepseek-ai/dsh-llm';
|
|
14
|
+
import type { AttachmentStore, ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
|
|
14
15
|
import { DEFAULT_CONTEXT_WINDOW, DEFAULT_MAX_TOKENS } from './constants.ts';
|
|
15
16
|
import type { CodeBuddySession } from './session.ts';
|
|
16
17
|
import type { WireError } from './types.ts';
|
|
@@ -32,6 +33,11 @@ export interface CodeBuddyAdapterOptions {
|
|
|
32
33
|
options: () => CodeBuddyConnectionOptions;
|
|
33
34
|
/** 解析持久化附件服务;缺失时拒绝图像输入。 */
|
|
34
35
|
resolveAttachments: () => AttachmentStore | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* 解析单张图在当前执行世界中的只读路径,随读取提示词交给模型供 `read_image` 读取。
|
|
38
|
+
* 未设置时解析不出路径,用户消息里的图退回内联。
|
|
39
|
+
*/
|
|
40
|
+
resolveImageAccess?: (attachments: AttachmentStore, ref: ImageAttachmentRef) => ImageAttachmentAccess | undefined;
|
|
35
41
|
/** 已设置时,解析用户为单个模型设置的上限(上下文窗口 / 最大输出)。 */
|
|
36
42
|
resolveOverrides?: (modelId: string) => Promise<ModelOverrides | undefined>;
|
|
37
43
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 通过私有 RPC 通道暴露给 Web 客户端的宿主侧 OAuth 服务。
|
|
3
3
|
*
|
|
4
|
-
* 浏览器登录是长时操作(要等待用户完成登录)
|
|
5
|
-
* `startLogin` 生成握手并返回用户必须打开的 URL,`pollLogin`
|
|
4
|
+
* 浏览器登录是长时操作(要等待用户完成登录),因此拆成三个 RPC endpoint:
|
|
5
|
+
* `startLogin` 生成握手并返回用户必须打开的 URL,`pollLogin` 检查该握手是否已完成,
|
|
6
|
+
* `pendingLogin` 报出仍在轮询的握手(浏览器刷新后据此接回);
|
|
6
7
|
* 一次完成的登录会**追加**一个账号,而不是取代已有的。`accounts`、`activate`、
|
|
7
|
-
* `setDefault`、`logout`
|
|
8
|
+
* `setDefault`、`logout` 是配置页与会话账号按钮其余时间驱动的读写组合。
|
|
8
9
|
*
|
|
9
10
|
* @module dsh-llm-codebuddy-power/auth-service
|
|
10
11
|
*/
|
|
@@ -27,6 +28,15 @@ export interface CodeBuddyLoginStart {
|
|
|
27
28
|
authUrl: string;
|
|
28
29
|
/** 握手 id;客户端会把它回传给 `pollLogin`。 */
|
|
29
30
|
state: string;
|
|
31
|
+
/** 握手发起时刻(epoch ms);客户端据此计算截止时间。 */
|
|
32
|
+
startedAt: number;
|
|
33
|
+
}
|
|
34
|
+
/** `pendingLogin` 返回给客户端的结构。 */
|
|
35
|
+
export interface CodeBuddyLoginPending {
|
|
36
|
+
/** 仍在轮询的握手 id。 */
|
|
37
|
+
state: string;
|
|
38
|
+
/** 该握手的发起时刻(epoch ms)。 */
|
|
39
|
+
startedAt: number;
|
|
30
40
|
}
|
|
31
41
|
/** `pollLogin` 返回给客户端的结构。 */
|
|
32
42
|
export interface CodeBuddyLoginPoll {
|
|
@@ -89,13 +99,18 @@ export interface CodeBuddyTurnCreditAccount {
|
|
|
89
99
|
/**
|
|
90
100
|
* CodeBuddy 认证 RPC 服务。
|
|
91
101
|
*
|
|
92
|
-
* 握手由 `startLogin`
|
|
93
|
-
* `CodeBuddySession` 在下一个请求中取用 → 因此通过 UI
|
|
94
|
-
*
|
|
102
|
+
* 握手由 `startLogin` 发起并**脱手**开跑,客户端经 `pollLogin` 反复查问它是否已结算,
|
|
103
|
+
* 其账号由适配器的 `CodeBuddySession` 在下一个请求中取用 → 因此通过 UI 完成的登录
|
|
104
|
+
* 无需重启即可到达运行中的 harness。`logout` 移除指定账号并使会话缓存失效。
|
|
95
105
|
*/
|
|
96
106
|
export declare class CodeBuddyAuthService {
|
|
97
107
|
private readonly session?;
|
|
98
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* 按 state id 索引的握手。
|
|
110
|
+
*
|
|
111
|
+
* 同时存放进行中的与**刚结算、尚在保留窗口内**的条目 —— 后者供客户端取回结果,
|
|
112
|
+
* 由 `settle()` 安排回收,因此本表不是"进行中握手"的集合。
|
|
113
|
+
*/
|
|
99
114
|
private readonly pending;
|
|
100
115
|
constructor(ctx: Context, session?: CodeBuddySession | undefined);
|
|
101
116
|
/** 把一次 RPC endpoint 调用路由到对应的处理器。 */
|
|
@@ -107,15 +122,35 @@ export declare class CodeBuddyAuthService {
|
|
|
107
122
|
accounts(): Promise<CodeBuddyAccountsResult>;
|
|
108
123
|
/**
|
|
109
124
|
* 发起一次浏览器登录握手。
|
|
110
|
-
* @returns 用户必须打开的 URL
|
|
125
|
+
* @returns 用户必须打开的 URL,以及该握手的 id 与发起时刻。
|
|
111
126
|
*/
|
|
112
127
|
startLogin(): Promise<CodeBuddyLoginStart>;
|
|
128
|
+
/**
|
|
129
|
+
* 仍在进行的握手。
|
|
130
|
+
*
|
|
131
|
+
* 客户端的「登录中」状态只活在浏览器内存里,刷新即丢,而本表里的握手仍在轮询,
|
|
132
|
+
* 浏览器重新挂载后据此接回(否则界面显示可再次登录,而宿主那边已有一次握手在等,
|
|
133
|
+
* 用户点了就会平白多出第二次)。
|
|
134
|
+
*
|
|
135
|
+
* **只报尚未结算的握手**:已结算的条目会在表里多留一会儿供客户端取结果,若把它们
|
|
136
|
+
* 也算作"进行中",刷新后接回的就是一次已经结束(甚至已经失败)的登录,界面会重新
|
|
137
|
+
* 显示「登录中…」并空转到截止时间。
|
|
138
|
+
*
|
|
139
|
+
* 同时存在多次时给出最近发起的那次:客户端的轮询、取消与超时都只针对一个握手,
|
|
140
|
+
* 而最晚发起的那次正是用户此刻在等的那次。
|
|
141
|
+
* @returns 该握手;没有进行中的登录时缺省。
|
|
142
|
+
*/
|
|
143
|
+
pendingLogin(): CodeBuddyLoginPending | undefined;
|
|
113
144
|
/**
|
|
114
145
|
* 检查已发起的握手是否完成。
|
|
146
|
+
*
|
|
147
|
+
* **立即返回**,不等待后台握手:`runLogin` 可能还要跑满十分钟,若在这里 await 它,
|
|
148
|
+
* 浏览器的一次请求就会在整个登录窗口内停在待处理,占住一条连接不放;而客户端是
|
|
149
|
+
* 按自己的间隔反复来问的,让它每次都立刻拿到"还没好"才是这条 endpoint 的职责。
|
|
115
150
|
* @param state - 来自 `startLogin` 的握手 id。
|
|
116
151
|
* @returns 登录是否完成、账号是否已持久化。
|
|
117
152
|
*/
|
|
118
|
-
pollLogin(state: string):
|
|
153
|
+
pollLogin(state: string): CodeBuddyLoginPoll;
|
|
119
154
|
/**
|
|
120
155
|
* 某会话此刻生效的账号。
|
|
121
156
|
* @param sessionId - dsh 会话身份;为空时按未选定处理。
|
|
@@ -169,13 +204,25 @@ export declare class CodeBuddyAuthService {
|
|
|
169
204
|
*/
|
|
170
205
|
usage(sessionId: string): Promise<CodeBuddyUsageResult>;
|
|
171
206
|
/**
|
|
172
|
-
*
|
|
207
|
+
* 把一次握手推进到持久化的账号,并把结果写回 {@link pending} 里对应条目。
|
|
173
208
|
*
|
|
174
209
|
* 复用 `buildAccount`,使落盘结构与 CLI 登录完全一致。
|
|
175
|
-
*
|
|
210
|
+
* 任何失败都记为"结算为失败",让客户端的轮询得到 `done: false`,
|
|
176
211
|
* 从而可以从 `startLogin` 重试。
|
|
212
|
+
*
|
|
213
|
+
* 本方法由 `startLogin` **脱手**调用,`pollLogin` 不 await 它;因此它自己不返回
|
|
214
|
+
* 结果,只负责把结果写进条目并安排回收。
|
|
177
215
|
*/
|
|
178
216
|
private runLogin;
|
|
217
|
+
/**
|
|
218
|
+
* 记录一次握手的结局,并在保留窗口之后回收该条目。
|
|
219
|
+
*
|
|
220
|
+
* 回收之所以要延迟:客户端是按自己的间隔来问结果的,一结算就删会让那次本已成功的
|
|
221
|
+
* 登录再也答不出 `done: true`。取消过的握手已不在表里,这里的写入自然丢弃。
|
|
222
|
+
* @param state - 握手 id。
|
|
223
|
+
* @param account - 已落盘的账号;失败或取消时为 `undefined`。
|
|
224
|
+
*/
|
|
225
|
+
private settle;
|
|
179
226
|
/**
|
|
180
227
|
* 供客户端面板使用的增强版 CodeBuddy 目录:应用了促销/等级展示信息与覆盖配置的模型。
|
|
181
228
|
* @param sessionId - 用哪个会话的账号读目录;为空时用默认账号。
|
|
@@ -14,8 +14,8 @@ import type { CodeBuddyPrefs } from '../prefs.ts';
|
|
|
14
14
|
* 设置分区与对话内账号控件共享的、经 RPC 支撑的业务面。每个回调都经 store action
|
|
15
15
|
* 写入;组件自身不接触 wire。
|
|
16
16
|
*
|
|
17
|
-
* 界面偏好走 `hooks` 隔舱:它与对话输入区的控件组是同一份活来源(
|
|
18
|
-
*
|
|
17
|
+
* 界面偏好走 `hooks` 隔舱:它与对话输入区的控件组是同一份活来源(本入口的
|
|
18
|
+
* volatile 配置字段),写入经 `setPref`。
|
|
19
19
|
*/
|
|
20
20
|
export interface CodeBuddySectionInjected {
|
|
21
21
|
hooks: {
|
|
@@ -26,6 +26,11 @@ export interface CodeBuddySectionInjected {
|
|
|
26
26
|
refreshAccounts: () => Promise<void>;
|
|
27
27
|
/** 发起浏览器登录握手(在新标签页打开鉴权 URL);完成后账号被追加到列表。 */
|
|
28
28
|
startLogin: () => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* 接回宿主仍在轮询的握手。浏览器刷新后本地状态已丢而宿主的握手还在等,
|
|
31
|
+
* 挂载时调用一次即可让「登录中」继续显示并恢复轮询。
|
|
32
|
+
*/
|
|
33
|
+
resumeLogin: () => Promise<void>;
|
|
29
34
|
/**
|
|
30
35
|
* 发起一次登录握手并把鉴权 URL 复制到剪贴板(不打开浏览器),用于在别的浏览器或
|
|
31
36
|
* 机器上完成登录。失败时会发布一条页面级错误。
|
|
@@ -34,11 +39,13 @@ export interface CodeBuddySectionInjected {
|
|
|
34
39
|
copyLoginLink: () => Promise<boolean>;
|
|
35
40
|
/**
|
|
36
41
|
* 放弃一次进行中的登录握手,并把界面从“登录中”收回到可再次发起的状态。
|
|
37
|
-
*
|
|
42
|
+
*
|
|
43
|
+
* 调用方不必等它的结果:取消对界面是即刻生效的,而宿主侧的中止即使慢或失败,
|
|
44
|
+
* 该握手也会在宿主自己的截止时间被回收。
|
|
38
45
|
*/
|
|
39
|
-
cancelLogin: (state: string) => Promise<
|
|
46
|
+
cancelLogin: (state: string, signal?: AbortSignal) => Promise<void>;
|
|
40
47
|
/** 按 state id 轮询一次握手;账号持久化后解析为 true。 */
|
|
41
|
-
pollLogin: (state: string) => Promise<boolean>;
|
|
48
|
+
pollLogin: (state: string, signal?: AbortSignal) => Promise<boolean>;
|
|
42
49
|
/** 退出若干账号。 */
|
|
43
50
|
logoutAccounts: (uids: string[]) => Promise<void>;
|
|
44
51
|
/**
|
|
@@ -48,11 +55,11 @@ export interface CodeBuddySectionInjected {
|
|
|
48
55
|
reorderAccounts: (uids: string[]) => Promise<void>;
|
|
49
56
|
/** 指定默认账号;`null` 表示取消默认账号。 */
|
|
50
57
|
setDefault: (uid: string | null) => Promise<void>;
|
|
51
|
-
/**
|
|
58
|
+
/** 写入一个界面偏好字段;该写入持久化到本入口的 profile patch。 */
|
|
52
59
|
setPref: (field: keyof CodeBuddyPrefs, value: boolean | number) => void;
|
|
53
60
|
}
|
|
54
61
|
/** 完整组件 props:runtime 份额 + store 份额 + locale seat + inject face。 */
|
|
55
|
-
export type CodeBuddySectionProps = PropsRuntime<'
|
|
62
|
+
export type CodeBuddySectionProps = PropsRuntime<'plugins.bundle.config'> & PropsStore<ReturnType<typeof createCodeBuddyStore>> & PropsLocale<'settings.codebuddy'> & InjectFace<CodeBuddySectionInjected>;
|
|
56
63
|
/**
|
|
57
64
|
* CodeBuddy 设置分区。
|
|
58
65
|
* @param props - 组合后的 slot props。
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Web 客户端部分:一个 CodeBuddy
|
|
2
|
+
* Web 客户端部分:一个 CodeBuddy 配置页(挂在侧边栏插件面板上),以及对话框输入区的账号控件。
|
|
3
3
|
*
|
|
4
|
-
* 在 `
|
|
5
|
-
*
|
|
6
|
-
* `conversation.input.right` 中注册一个条目,在 CodeBuddy 模型按钮左侧渲染当前
|
|
4
|
+
* 在 `plugins.bundle.config` 中注册一个条目 —— 一个展示全部已登录账号、追加登录、
|
|
5
|
+
* 退出单个或选中账号、指定默认账号的页面,按本包名派发到插件页本插件自己的卡片上 ——
|
|
6
|
+
* 再在 `conversation.input.right` 中注册一个条目,在 CodeBuddy 模型按钮左侧渲染当前
|
|
7
7
|
* 会话的额度圆环与账号切换按钮。
|
|
8
8
|
*
|
|
9
|
-
* 两个条目处在**不同作用域**(
|
|
10
|
-
*
|
|
9
|
+
* 两个条目处在**不同作用域**(配置页 root、输入区 session),而一个 store handle
|
|
10
|
+
* 只能绑一个作用域,因此它们不共用句柄:配置页持有 store,对话控件按会话经 RPC
|
|
11
11
|
* 自取账号集合与用量(见该处的注册注释)。
|
|
12
12
|
*
|
|
13
13
|
* @module dsh-llm-codebuddy-power/client
|
|
@@ -79,7 +79,7 @@ export declare const en: {
|
|
|
79
79
|
export type CodeBuddyKey = keyof typeof en;
|
|
80
80
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
81
81
|
interface LocaleNamespaceMap {
|
|
82
|
-
/** CodeBuddy
|
|
82
|
+
/** CodeBuddy 配置页与对话内账号控件的文案。 */
|
|
83
83
|
'settings.codebuddy': CodeBuddyKey;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CodeBuddy 页面 store
|
|
2
|
+
* CodeBuddy 页面 store:配置页共享的账号快照。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* 客户端插件在配置页条目下挂载本句柄,因此在该页完成的登录、退出或改
|
|
5
5
|
* 默认账号无需跨组件接线即可到达同一页面的各个徽章。
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* 由 `./index.ts` 经 `ctx.
|
|
9
|
-
* 注入面的 `hooks`
|
|
10
|
-
*
|
|
11
|
-
* 读取,导致开关与圆环之间有最多一个轮询周期的延迟。
|
|
7
|
+
* **界面偏好不在这里**:它们是插件自己的 volatile 配置字段(见 `../prefs.ts`),
|
|
8
|
+
* 由 `./index.ts` 经 `ctx.configForms.get()` 读取,并以一个派生的活快照经
|
|
9
|
+
* 注入面的 `hooks` 隔舱同时下发给配置页与对话输入区的控件组 —— 后者处在另一个
|
|
10
|
+
* 作用域,共享不了本句柄。
|
|
12
11
|
*
|
|
13
12
|
* @module dsh-llm-codebuddy-power/client/store
|
|
14
13
|
*/
|
|
@@ -22,7 +21,7 @@ export interface PendingLogin {
|
|
|
22
21
|
state: string;
|
|
23
22
|
/**
|
|
24
23
|
* 发起时刻(epoch ms)。截止时间据此计算并存进 store —— 放在组件的 effect 里会让
|
|
25
|
-
* 每次重新挂载(
|
|
24
|
+
* 每次重新挂载(关闭再打开配置页)都把计时归零,于是反复开关就能把"登录中…"
|
|
26
25
|
* 无限延长。
|
|
27
26
|
*/
|
|
28
27
|
startedAt: number;
|
|
@@ -47,12 +46,21 @@ type CodeBuddyActions = {
|
|
|
47
46
|
setAccounts: (draft: CodeBuddyState, result: CodeBuddyAccountsResult) => void;
|
|
48
47
|
/** 发布页面级失败。 */
|
|
49
48
|
fail: (draft: CodeBuddyState, message: string) => void;
|
|
49
|
+
/** 丢弃页面级失败,回到可再次发起的阶段。 */
|
|
50
|
+
clearError: (draft: CodeBuddyState) => void;
|
|
50
51
|
/** 跟踪进行中的浏览器登录握手(null 表示没有)。 */
|
|
51
52
|
setLoginState: (draft: CodeBuddyState, state: PendingLogin | null) => void;
|
|
53
|
+
/**
|
|
54
|
+
* 采纳宿主报出的握手(仅当本地此刻没有握手时)。
|
|
55
|
+
*
|
|
56
|
+
* 判据放在 action 里而不是调用方:采纳是异步读了一次 RPC 之后才发生的,
|
|
57
|
+
* 期间用户可能刚点了登录;无条件写入会把那次新握手的发起时刻换成宿主的旧时刻。
|
|
58
|
+
*/
|
|
59
|
+
adoptLogin: (draft: CodeBuddyState, state: PendingLogin) => void;
|
|
52
60
|
};
|
|
53
61
|
/**
|
|
54
62
|
* 声明 CodeBuddy 页面状态与写入接口。
|
|
55
|
-
* @returns store 句柄(在 apply
|
|
63
|
+
* @returns store 句柄(在 apply 中挂载于配置页条目下)。
|
|
56
64
|
*/
|
|
57
65
|
export declare function createCodeBuddyStore(): EngineStoreHandle<CodeBuddyState, CodeBuddyActions>;
|
|
58
66
|
export {};
|
|
@@ -36,6 +36,18 @@ export interface CodeBuddyAccountsResult {
|
|
|
36
36
|
export interface CodeBuddyLoginStart {
|
|
37
37
|
authUrl: string;
|
|
38
38
|
state: string;
|
|
39
|
+
/**
|
|
40
|
+
* 握手发起时刻(epoch ms)。按"可能缺失"声明,与 {@link CodeBuddyAccountView} 同理:
|
|
41
|
+
* 旧宿主不返回该字段,客户端据本机当前时刻兜底。
|
|
42
|
+
*/
|
|
43
|
+
startedAt?: number;
|
|
44
|
+
}
|
|
45
|
+
/** `pendingLogin` 的结果结构;没有进行中的登录时缺省。 */
|
|
46
|
+
export interface CodeBuddyLoginPending {
|
|
47
|
+
/** 仍在轮询的握手 id。 */
|
|
48
|
+
state: string;
|
|
49
|
+
/** 该握手的发起时刻(epoch ms)。 */
|
|
50
|
+
startedAt: number;
|
|
39
51
|
}
|
|
40
52
|
/** `pollLogin` 的结果结构。 */
|
|
41
53
|
export interface CodeBuddyLoginPoll {
|
|
@@ -142,6 +154,11 @@ export interface CodeBuddyTurnCreditRecord {
|
|
|
142
154
|
/**
|
|
143
155
|
* 在共享通道上调用一个鉴权 endpoint。该通道调用按设计不做类型约束;
|
|
144
156
|
* endpoint 所记录的 payload 结构在此唯一的 wire 边界处恢复。
|
|
157
|
+
* @param rpc - 当前连接的 RPC 调用器。
|
|
158
|
+
* @param endpoint - 通道下的 endpoint 名。
|
|
159
|
+
* @param payload - endpoint 自己的请求载荷。
|
|
160
|
+
* @param signal - 可选取消;中止后该请求的连接随即释放,而不是等宿主应答。
|
|
161
|
+
* @returns endpoint 自己声明的结果。
|
|
145
162
|
*/
|
|
146
|
-
export declare function authCall<T>(rpc: ClientConnectionRpc, endpoint: string, payload?: unknown): Promise<ConnectionRpcResult<T>>;
|
|
163
|
+
export declare function authCall<T>(rpc: ClientConnectionRpc, endpoint: string, payload?: unknown, signal?: AbortSignal): Promise<ConnectionRpcResult<T>>;
|
|
147
164
|
//# sourceMappingURL=wire.d.ts.map
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -62,6 +62,14 @@ export declare const REQUEST_IMAGE_DIMENSION_LADDER: readonly [1920, 1440, 1080]
|
|
|
62
62
|
export declare const LOGIN_TIMEOUT_MS: number;
|
|
63
63
|
/** 等待浏览器登录完成时的轮询间隔,单位 ms。 */
|
|
64
64
|
export declare const LOGIN_POLL_INTERVAL_MS = 1000;
|
|
65
|
+
/**
|
|
66
|
+
* 握手结算后在宿主表里保留结果的时长,单位 ms。
|
|
67
|
+
*
|
|
68
|
+
* 逾期即回收,但**客户端是过一会儿才来问的**(它按自己的间隔轮询),所以结果不能
|
|
69
|
+
* 一结算就丢:一丢,那次本已成功的登录就再也答不出 `done: true`,客户端只能干等到
|
|
70
|
+
* 十分钟截止。保留窗口只需覆盖一个客户端轮询周期,取一个宽裕值。
|
|
71
|
+
*/
|
|
72
|
+
export declare const LOGIN_RESULT_RETENTION_MS: number;
|
|
65
73
|
/** 含义为“浏览器登录尚未完成”的服务码。 */
|
|
66
74
|
export declare const AUTH_PENDING_CODE = 11217;
|
|
67
75
|
//# sourceMappingURL=constants.d.ts.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
* @module dsh-llm-codebuddy-power
|
|
12
12
|
*/
|
|
13
13
|
import type { Context } from '@deepseek-ai/cordis';
|
|
14
|
+
import z from '@deepseek-ai/schemastery';
|
|
14
15
|
import type { CodeBuddyConnectionOptions } from './adapter.ts';
|
|
15
16
|
import type { CodeBuddyPrefs, CodeBuddyPrefsConfig } from './prefs.ts';
|
|
16
17
|
export { CodeBuddyAdapter, httpErrorCode } from './adapter.ts';
|
|
17
18
|
export type { CodeBuddyAdapterOptions, CodeBuddyConnectionOptions } from './adapter.ts';
|
|
18
19
|
export { CodeBuddyAuthService, CODEBUDDY_AUTH_CHANNEL } from './auth-service.ts';
|
|
19
|
-
export type { CodeBuddyAccountsResult, CodeBuddyLoginStart, CodeBuddyLoginPoll, CodeBuddySessionAccount, CodeBuddyUsageResult, CodeBuddyUsageWindow, } from './auth-service.ts';
|
|
20
|
+
export type { CodeBuddyAccountsResult, CodeBuddyLoginPending, CodeBuddyLoginStart, CodeBuddyLoginPoll, CodeBuddySessionAccount, CodeBuddyUsageResult, CodeBuddyUsageWindow, } from './auth-service.ts';
|
|
20
21
|
export { CodeBuddySession, NotLoggedInError } from './session.ts';
|
|
21
22
|
export type { CodeBuddyAccountInfo, TurnCreditAccount, TurnCreditAccountView, TurnCreditRecord, TurnCreditRecordView, } from './session.ts';
|
|
22
23
|
export { login } from './login.ts';
|
|
@@ -34,17 +35,18 @@ export type * from './types.ts';
|
|
|
34
35
|
export declare const name = "llm-codebuddy-power";
|
|
35
36
|
/**
|
|
36
37
|
* 本插件的激活服务。`llm` 承载适配器路由,`tools` 接受文生图工具注册,
|
|
37
|
-
* `agents` 用于极简模式会话中按 agent
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* `agents` 用于极简模式会话中按 agent 限制画图工具可见性。生成图片经标准附件通道
|
|
39
|
+
* (attachments.saveImage + uiConversation.imageUrl)持久化与展示,工具注册在
|
|
40
|
+
* 附件服务挂载后(`ctx.inject(['attachments'])`)。
|
|
40
41
|
*/
|
|
41
42
|
export declare const inject: string[];
|
|
42
43
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
44
|
+
* 插件配置。连接字段都可选:内置默认值直达公开的 CodeBuddy 服务,且按设计完全
|
|
45
|
+
* 没有凭据字段 → 唯一的进入方式是浏览器登录。
|
|
45
46
|
*
|
|
46
|
-
* 界面偏好字段(`CodeBuddyPrefsConfig`)
|
|
47
|
-
*
|
|
47
|
+
* 界面偏好字段(`CodeBuddyPrefsConfig`)是 volatile 的:设置表单只能读写 volatile
|
|
48
|
+
* 字段,写入落回本入口的 profile patch,而 volatile 引用原地更新,因此宿主每次
|
|
49
|
+
* 读取都拿到当前值、无需重挂插件。
|
|
48
50
|
*/
|
|
49
51
|
export interface Config extends CodeBuddyPrefsConfig {
|
|
50
52
|
/** Chat 端点基址;默认为 CodeBuddy 的 OpenAI 兼容路由。 */
|
|
@@ -57,23 +59,43 @@ export interface Config extends CodeBuddyPrefsConfig {
|
|
|
57
59
|
streamIdleTimeoutMs?: number;
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
60
|
-
*
|
|
62
|
+
* {@link Config} 的运行时 schema。
|
|
61
63
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @returns 解析出的连接事实。
|
|
64
|
+
* 三个界面偏好字段必须是 volatile 才会被设置表单投影,而 volatile 只从
|
|
65
|
+
* schemastery schema 产生;连接字段保持普通字段,因此不在表单里暴露 ——
|
|
66
|
+
* 它们由 profile 的 cordis.patch.yml 配置。
|
|
66
67
|
*/
|
|
67
|
-
export declare
|
|
68
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
69
|
+
baseURL: z<string, string, "plain">;
|
|
70
|
+
defaultContextWindow: z<number, number, "plain">;
|
|
71
|
+
defaultMaxTokens: z<number, number, "plain">;
|
|
72
|
+
streamIdleTimeoutMs: z<number, number, "plain">;
|
|
73
|
+
showUsage: z<boolean, boolean, "volatile-defined">;
|
|
74
|
+
dangerPct: z<number, number, "volatile-defined">;
|
|
75
|
+
drawToolInMinimal: z<boolean, boolean, "volatile-defined">;
|
|
76
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
77
|
+
baseURL: z<string, string, "plain">;
|
|
78
|
+
defaultContextWindow: z<number, number, "plain">;
|
|
79
|
+
defaultMaxTokens: z<number, number, "plain">;
|
|
80
|
+
streamIdleTimeoutMs: z<number, number, "plain">;
|
|
81
|
+
showUsage: z<boolean, boolean, "volatile-defined">;
|
|
82
|
+
dangerPct: z<number, number, "volatile-defined">;
|
|
83
|
+
drawToolInMinimal: z<boolean, boolean, "volatile-defined">;
|
|
84
|
+
}>>, "plain">;
|
|
68
85
|
/**
|
|
69
|
-
*
|
|
86
|
+
* 从配置解析连接事实。
|
|
70
87
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
|
|
88
|
+
* 连接字段在 `Config` 里都是可选的,缺省值即公开的 CodeBuddy 服务。
|
|
89
|
+
* @param config - 入口配置。
|
|
90
|
+
* @returns 解析出的连接事实。
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveConnectionOptions(config: Config): CodeBuddyConnectionOptions;
|
|
93
|
+
/**
|
|
94
|
+
* 读取界面偏好的当前值。
|
|
95
|
+
* @param config - 入口配置。
|
|
96
|
+
* @returns 三个界面偏好。
|
|
75
97
|
*/
|
|
76
|
-
export declare function
|
|
98
|
+
export declare function resolvePrefs(config: Config): CodeBuddyPrefs;
|
|
77
99
|
/** 挂载插件:解析配置,然后注册路由。 */
|
|
78
|
-
export declare function apply(ctx: Context, config
|
|
100
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
79
101
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/types/prefs.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CodeBuddy
|
|
2
|
+
* CodeBuddy 界面偏好的契约,Host 与 Client 两面共享。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* harness
|
|
7
|
-
* `codebuddy-draw`
|
|
4
|
+
* 这些偏好是**插件自己的 volatile 配置字段**:`Config` 里声明为 volatile 后,
|
|
5
|
+
* 设置表单按入口 id 把它们投影成可读写的表单,宿主在每次操作时读取当前值,因此
|
|
6
|
+
* 换浏览器、重启 harness 后仍然生效。其中「极简模式画图工具」还会被宿主读取来
|
|
7
|
+
* 决定 `codebuddy-draw` 对模型是否可见。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 本文件必须保持零运行时依赖:两面都会编译它,而 Client 面若因此引入 schemastery
|
|
10
10
|
* 就会把它打进浏览器产物(校验 schema 是宿主面的事,见 `./settings.ts`)。
|
|
11
|
+
* `Volatile` 是纯类型导入,擦除后不留依赖。
|
|
11
12
|
*
|
|
12
13
|
* @module dsh-llm-codebuddy-power/prefs
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
import type { Volatile } from '@deepseek-ai/cordis';
|
|
16
|
+
/** 本插件的设置入口 id,与插件名一致。 */
|
|
15
17
|
export declare const CODEBUDDY_SETTINGS_NAMESPACE = "llm-codebuddy-power";
|
|
16
18
|
/** 告警百分比的下界(含)。 */
|
|
17
19
|
export declare const DANGER_PCT_MIN = 1;
|
|
18
20
|
/** 告警百分比的上界(含)。 */
|
|
19
21
|
export declare const DANGER_PCT_MAX = 100;
|
|
20
|
-
/**
|
|
22
|
+
/** 本插件的界面偏好;设置表单投影出的就是这个结构。 */
|
|
21
23
|
export interface CodeBuddyPrefs {
|
|
22
24
|
/** 对话输入区是否显示额度圆环。 */
|
|
23
25
|
showUsage: boolean;
|
|
@@ -29,15 +31,17 @@ export interface CodeBuddyPrefs {
|
|
|
29
31
|
/** 未覆盖任何一层时使用的偏好默认值。 */
|
|
30
32
|
export declare const DEFAULT_CODEBUDDY_SETTINGS: CodeBuddyPrefs;
|
|
31
33
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
+
* `Config` 里的界面偏好字段。
|
|
35
|
+
*
|
|
36
|
+
* 三者都声明为 volatile:设置表单只能读写 volatile 字段,而 volatile 引用在原地
|
|
37
|
+
* 更新,所以宿主每次 `.get()` 都拿到当前值,不必重挂插件。
|
|
34
38
|
*/
|
|
35
39
|
export interface CodeBuddyPrefsConfig {
|
|
36
40
|
/** 对话输入区是否显示额度圆环。 */
|
|
37
|
-
showUsage
|
|
41
|
+
showUsage: Volatile<boolean>;
|
|
38
42
|
/** 圆环填充变为告警颜色的已用百分比。 */
|
|
39
|
-
dangerPct
|
|
43
|
+
dangerPct: Volatile<number>;
|
|
40
44
|
/** 极简模式会话是否注入 codebuddy-draw 工具。 */
|
|
41
|
-
drawToolInMinimal
|
|
45
|
+
drawToolInMinimal: Volatile<boolean>;
|
|
42
46
|
}
|
|
43
47
|
//# sourceMappingURL=prefs.d.ts.map
|
package/lib/types/serialize.d.ts
CHANGED
|
@@ -2,28 +2,35 @@
|
|
|
2
2
|
* 把 harness 消息序列化为 CodeBuddy(OpenAI 兼容)chat 请求。
|
|
3
3
|
*
|
|
4
4
|
* 用户文本被拼接,助手文本成为 `content`,工具调用成为
|
|
5
|
-
* `tool_calls
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* `tool_calls`,每个工具结果是一条 `role: 'tool'` 的 harness 消息,直接映射为
|
|
6
|
+
* 同名 wire 条目。对于支持图像的模型,用户消息里的图**不内联**:改为给出一段
|
|
7
|
+
* 引导模型自行用 `read_image` 读取的提示词(附件服务解析出的只读绝对路径);
|
|
8
|
+
* 解析不出路径时退回内联,以免模型既拿不到图也拿不到路径。`read_image` 的工具
|
|
9
|
+
* 结果仍内联图片本身 —— 那是像素交给模型的唯一途径。生成图工具的结果继续走
|
|
10
|
+
* 纯文本信封。
|
|
11
11
|
*
|
|
12
12
|
* @module dsh-llm-codebuddy-power/serialize
|
|
13
13
|
*/
|
|
14
|
-
import type { GenerateOptions,
|
|
14
|
+
import type { GenerateOptions, ImageAttachmentAccessResolver, RequestMessage } from '@deepseek-ai/dsh-llm';
|
|
15
15
|
import type { RequestImageAttachment } from '@deepseek-ai/dsh-attachment';
|
|
16
16
|
import type { WireMessage, WireRequest } from './types.ts';
|
|
17
17
|
/** 请求中每个图像已解析的请求版本,以 attachment id 为键。 */
|
|
18
18
|
export type RequestImages = ReadonlyMap<RequestImageAttachment['attachment']['attachmentId'], RequestImageAttachment>;
|
|
19
19
|
/**
|
|
20
20
|
* 按顺序序列化整个对话。
|
|
21
|
+
*
|
|
22
|
+
* 工具结果在 harness 里是**独立的 `role: 'tool'` 消息**(`ToolResultMessage`),
|
|
23
|
+
* 因此这里逐条映射,而不是按块从 user 消息里筛选。
|
|
24
|
+
* developer 消息由运行时在 `projectToolUpdates` 中剥离(本 adapter 未声明
|
|
25
|
+
* `toolUpdate`),因此不会到达这里;万一到达即明确拒绝,而不是静默丢弃。
|
|
21
26
|
* @param messages - harness 会话。
|
|
22
27
|
* @param supportsImages - 所选模型是否声明支持图像输入。
|
|
23
28
|
* @param images - 请求中每个图像已解析的请求版本。
|
|
24
|
-
* @
|
|
29
|
+
* @param resolveAccess - 解析单张图在当前执行世界中的只读路径。
|
|
30
|
+
* @param route - 本请求的读图形态。
|
|
31
|
+
* @returns wire 消息,工具结果各自成为独立条目。
|
|
25
32
|
*/
|
|
26
|
-
export declare function serializeMessages(messages: readonly
|
|
33
|
+
export declare function serializeMessages(messages: readonly RequestMessage[], supportsImages: boolean, images?: RequestImages, resolveAccess?: ImageAttachmentAccessResolver, route?: 'direct' | 'ptc' | 'none'): WireMessage[];
|
|
27
34
|
/**
|
|
28
35
|
* 构建 chat-completions 请求体。始终流式并上报 usage;
|
|
29
36
|
* 缺省的选项被省略而非以 null 发送,以便应用
|
|
@@ -31,7 +38,9 @@ export declare function serializeMessages(messages: readonly Message[], supports
|
|
|
31
38
|
* @param options - 组装好的 harness 请求。
|
|
32
39
|
* @param supportsImages - 所选模型是否声明支持图像输入。
|
|
33
40
|
* @param images - 请求中每个图像已解析的请求版本。
|
|
41
|
+
* @param resolveAccess - 解析单张图在当前执行世界中的只读路径。
|
|
42
|
+
* @param route - 本请求的读图形态,由工具目录决定;写入前由调用方计算一次。
|
|
34
43
|
* @returns 请求体。
|
|
35
44
|
*/
|
|
36
|
-
export declare function serializeRequest(options: GenerateOptions, supportsImages: boolean, images?: RequestImages): WireRequest;
|
|
45
|
+
export declare function serializeRequest(options: GenerateOptions, supportsImages: boolean, images?: RequestImages, resolveAccess?: ImageAttachmentAccessResolver): WireRequest;
|
|
37
46
|
//# sourceMappingURL=serialize.d.ts.map
|
package/lib/types/session.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ interface Catalog {
|
|
|
30
30
|
promotions: readonly CodeBuddyModelPromotion[];
|
|
31
31
|
tiers: readonly CodeBuddyModelTier[] | undefined;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
33
|
+
/** 配置页与账号切换按钮读取的账号投影。 */
|
|
34
34
|
export interface CodeBuddyAccountInfo {
|
|
35
35
|
uid: string;
|
|
36
36
|
nickname: string;
|
|
@@ -322,7 +322,7 @@ export declare class CodeBuddySession {
|
|
|
322
322
|
*/
|
|
323
323
|
isLoggedIn(): Promise<boolean>;
|
|
324
324
|
/**
|
|
325
|
-
*
|
|
325
|
+
* 已存账号及其默认账号,供配置页与会话切换按钮展示。
|
|
326
326
|
* @returns 账号列表(顺序与磁盘一致)与默认账号 uid;未登录时列表为空。
|
|
327
327
|
*/
|
|
328
328
|
accountList(): Promise<{
|
|
@@ -390,7 +390,7 @@ export declare class CodeBuddySession {
|
|
|
390
390
|
/**
|
|
391
391
|
* 目录;读不到时返回空列表。
|
|
392
392
|
*
|
|
393
|
-
*
|
|
393
|
+
* 列出模型是配置页上的浏览动作,所以失败必须降级为“没有可显示的内容”,
|
|
394
394
|
* 而不是让页面崩掉。请求路径直接使用 {@link models} 并保留真实失败。
|
|
395
395
|
* @param signal - 可选取消信号。
|
|
396
396
|
* @param sessionId - 用哪个会话的账号;缺省时用默认账号。
|
package/lib/types/settings.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 本插件的 `Config` schema —— 连接事实与界面偏好合一。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
6
|
-
*
|
|
4
|
+
* 设置表单只投影**入口自己的 `Config`** 里声明为 `.volatile()` 的字段(入口 id
|
|
5
|
+
* 即命名空间),因此界面偏好字段与连接字段同在 `Config` 中,只有偏好那三个是
|
|
6
|
+
* volatile。
|
|
7
7
|
*
|
|
8
8
|
* 字段的默认值一律取自 `DEFAULT_CODEBUDDY_SETTINGS`,不在此重复字面量 ——
|
|
9
9
|
* 两处各写一份时,改了一处就会出现「宿主默认 90、界面显示 80」这种只有用户
|
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
* @module dsh-llm-codebuddy-power/settings
|
|
13
13
|
*/
|
|
14
14
|
import z from '@deepseek-ai/schemastery';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
/** `Config.showUsage` 的 schema。 */
|
|
16
|
+
export declare const ShowUsageField: z<boolean, boolean, "volatile-defined">;
|
|
17
|
+
/** `Config.dangerPct` 的 schema。 */
|
|
18
|
+
export declare const DangerPctField: z<number, number, "volatile-defined">;
|
|
19
|
+
/** `Config.drawToolInMinimal` 的 schema。 */
|
|
20
|
+
export declare const DrawToolInMinimalField: z<boolean, boolean, "volatile-defined">;
|
|
18
21
|
//# sourceMappingURL=settings.d.ts.map
|
package/lib/types/storage.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* (`$DSH_HOME/data/plugins/llm-codebuddy-power/`,通过 harness 所用的同一个
|
|
6
6
|
* `@deepseek-ai/dsh-home-paths` 解析),而不放在插件包内,因此重装不会让
|
|
7
7
|
* 用户退出登录。写入经 [atomic-file.ts](./atomic-file.ts) 做原子替换并按路径串行化:
|
|
8
|
-
*
|
|
8
|
+
* 多个账号的令牌刷新、配置页的增删与 CLI 的调用都在改同一份文件,不串行化时
|
|
9
9
|
* 两个并发写入会各自基于自己读到的旧内容覆盖对方。残缺文件会让用户手里只有
|
|
10
10
|
* 一份读不出的凭据,还无法与“从未登录过”区分开。
|
|
11
11
|
*
|
|
@@ -80,7 +80,7 @@ export declare function updateStorage(change: (current: CodeBuddyStorage) => Cod
|
|
|
80
80
|
* 插入一个账号,或替换同 uid 账号的凭据。
|
|
81
81
|
*
|
|
82
82
|
* 同 uid 视为重新登录同一个账号:令牌被替换而不是追加成第二个条目,否则
|
|
83
|
-
*
|
|
83
|
+
* 配置页会出现两个同名徽章,退出其中一个还会留下另一个。
|
|
84
84
|
* @param entry - 刚登录得到的账号。
|
|
85
85
|
*/
|
|
86
86
|
export declare function upsertAccount(entry: CodeBuddyStoredAccount): Promise<void>;
|