dsh-wakatime 1.1.0 → 1.2.1
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/README.en.md +6 -2
- package/README.md +7 -2
- package/lib/tracker.d.ts +27 -0
- package/lib/tracker.js +32 -5
- package/lib/types.d.ts +21 -2
- package/lib/user-agent.d.ts +110 -0
- package/lib/user-agent.js +277 -0
- package/lib/wakatime.js +12 -5
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
[中文](./README.md) | **English**
|
|
8
8
|
|
|
9
|
-
[](https://github.com/dsh-plugin-collection/dsh-wakatime)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
12
12
|
|
|
@@ -39,7 +39,11 @@ All four panels are fed by this plugin:
|
|
|
39
39
|
| **Projects** | Each heartbeat's `project`, inferred from git / `package.json` / directory name |
|
|
40
40
|
| **Categories** | Tool → category mapping (see [Category mapping](#category-mapping)) |
|
|
41
41
|
| **Languages** | Inferred from file extensions |
|
|
42
|
-
| **Editors** | Derived from the heartbeat `User-Agent
|
|
42
|
+
| **Editors** | Derived from the heartbeat `User-Agent`, so "working in DSH" shows up as its own editor |
|
|
43
|
+
| **Operating Systems** | Also from the `User-Agent` parenthesised section `(linux-<kernel>-<arch>)` |
|
|
44
|
+
| **Models** | Also from the model token inside `User-Agent` (e.g. `deepseek/4.1-flash-eco`) — WakaTime has **no** `ai_model` heartbeat field; this panel reads the UA only |
|
|
45
|
+
|
|
46
|
+
> **Why the UA follows the official template**: the Editors, Operating Systems and Models panels are all derived from `User-Agent`. This plugin emits `wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <model?> <editor>`; the model comes from the host message's `message.source.model` and is normalised with the official `aiModelUserAgentToken` rules. A real sample: `wakatime/1.2.1 (linux-6.18.58-x86_64) node/24.22.0 deepseek/4.1-flash-eco dsh/0.2.2-rc.5`. When a model id has no recognisable version segment (`dsh-opendesign-go`), that part is omitted rather than polluting the `user_agents` table.
|
|
43
47
|
|
|
44
48
|
## Install
|
|
45
49
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
**中文** | [English](./README.en.md)
|
|
8
8
|
|
|
9
|
-
[](https://github.com/dsh-plugin-collection/dsh-wakatime)
|
|
10
10
|
[](LICENSE)
|
|
11
11
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
12
12
|
|
|
@@ -39,7 +39,11 @@ DSH 里的活动原本不会出现在 WakaTime 上:[WakaTime](https://wakatime
|
|
|
39
39
|
| **Projects** | 每次心跳的 `project`:自动从 git / `package.json` / 目录名推断 |
|
|
40
40
|
| **Categories** | 工具调用映射(见[类别映射](#类别映射))——`coding` / `browsing` / `researching` 等 |
|
|
41
41
|
| **Languages** | 按文件扩展名推断 |
|
|
42
|
-
| **Editors** | 由心跳的 `User-Agent
|
|
42
|
+
| **Editors** | 由心跳的 `User-Agent` 推出,所以「在 DSH 里干活」在面板上单独成了一类 |
|
|
43
|
+
| **Operating Systems** | 同样来自 `User-Agent` 的括号段 `(linux-<内核>-<arch>)` |
|
|
44
|
+
| **Models** | 同样来自 `User-Agent` 里的模型 token(如 `deepseek/4.1-flash-eco`)——WakaTime **没有** `ai_model` 心跳字段,这个面板只认 UA |
|
|
45
|
+
|
|
46
|
+
> **为什么 UA 要照官方模板拼**:Editors / Operating Systems / Models 三个面板都从 `User-Agent` 解析。本插件按 `wakatime-cli` 的模板 `wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <model?> <editor>` 生成;模型取自宿主消息的 `message.source.model`,并按官方的 `aiModelUserAgentToken` 规则归一化。一条实测样本:`wakatime/1.2.1 (linux-6.18.58-x86_64) node/24.22.0 deepseek/4.1-flash-eco dsh/0.2.2-rc.5`。模型识别不出时该段省略,不会把 `dsh-opendesign-go` 这类没有版本号的 id 硬塞进去污染 `user_agents` 表。
|
|
43
47
|
|
|
44
48
|
## 安装
|
|
45
49
|
|
|
@@ -157,6 +161,7 @@ wc -l ~/.dsh/wakatime/heartbeat-cache.jsonl
|
|
|
157
161
|
- **DSH 侧的 AI token 口径与 IDE 不同**:宿主给的是「未命中 + 缓存命中」两个互斥分量,插件分字段上报,不与 IDE 插件的数字直接可比;
|
|
158
162
|
- **历史数据不可回溯**:`entity` / `category` 的形态一旦改变,按这两个维度做跨版本对比会断裂;
|
|
159
163
|
- **读端点不可用**:WakaTime 自 2026-10 起对插件 key 封锁读端点(详见[开发](#开发)),因此插件无法回读自己的数据做校验。
|
|
164
|
+
- **Models / Operating Systems 面板的显示效果无法本地验证**:服务端解析 UA 的代码不开源。插件只保证「UA 形状与官方 CLI 产出一致」(`user_agents` 写端点已实测确认该 UA 落库),面板是否按预期归类需以实际面板为准。模型名里**没有版本号**的(如 `dsh-opendesign-go`、`deepseek-chat`)按官方规则识别不出 family,这类会话不会出现在 Models 面板。
|
|
160
165
|
|
|
161
166
|
## 开发
|
|
162
167
|
|
package/lib/tracker.d.ts
CHANGED
|
@@ -52,6 +52,17 @@ interface AssistantMessageEvent {
|
|
|
52
52
|
step: number;
|
|
53
53
|
message: {
|
|
54
54
|
content: string;
|
|
55
|
+
/**
|
|
56
|
+
* 消息来源。宿主 `dsh-llm` 的 `ModelMessageSource` 形状为
|
|
57
|
+
* `{ kind: 'model', provider, model }`——模型 id 就在这里。WakaTime 没有
|
|
58
|
+
* `ai_model` 心跳字段,Models 面板靠解析 UA 里的模型 token 得到归属,
|
|
59
|
+
* 归一化见 `user-agent.ts` 的 aiModelToken。
|
|
60
|
+
*/
|
|
61
|
+
source?: {
|
|
62
|
+
kind?: string;
|
|
63
|
+
provider?: string;
|
|
64
|
+
model?: string;
|
|
65
|
+
};
|
|
55
66
|
};
|
|
56
67
|
usage?: TokenUsageLike;
|
|
57
68
|
};
|
|
@@ -79,6 +90,14 @@ export declare class FileTracker {
|
|
|
79
90
|
private inflight;
|
|
80
91
|
/** 最近一条用户消息的字符数,随下一条 assistant 心跳作为 ai_prompt_length 上报。 */
|
|
81
92
|
private lastPromptLength?;
|
|
93
|
+
/**
|
|
94
|
+
* 最近一次模型调用所用的模型 id(`message.source.model`),用于 UA 里的模型 token。
|
|
95
|
+
*
|
|
96
|
+
* 为什么缓存而不是每条去读:user message / tool call 心跳也需要 UA,而那些事件
|
|
97
|
+
* 不携带模型身份;缓存最近一次即可近似「当前会话正在用的模型」。模型切换后
|
|
98
|
+
* 下一条 assistant 心跳即更新。
|
|
99
|
+
*/
|
|
100
|
+
private lastModelId?;
|
|
82
101
|
constructor(session: Session, config: TrackerConfig);
|
|
83
102
|
/** 等待所有在途追踪任务落袋(含等待期间新启动的)。 */
|
|
84
103
|
idle(): Promise<void>;
|
|
@@ -88,6 +107,14 @@ export declare class FileTracker {
|
|
|
88
107
|
/** 登记在途任务;返回原 promise,拒绝语义与直接调用保持一致。 */
|
|
89
108
|
private tracked;
|
|
90
109
|
private trackToolCallInner;
|
|
110
|
+
/**
|
|
111
|
+
* 入队(含 5 秒去重窗口),并在此处统一贴 `user_agent`。
|
|
112
|
+
*
|
|
113
|
+
* 为什么集中打戳:三类心跳(write 工具、用户消息、assistant 消息)都有自己的
|
|
114
|
+
* 构造点,逐个贴容易漏一个;而 `user_agent` 必须**每条**都带——WakaTime 的
|
|
115
|
+
* Editors / Operating Systems / Models 三个面板都从它解析。
|
|
116
|
+
*/
|
|
117
|
+
private enqueue;
|
|
91
118
|
private trackUserMessageInner;
|
|
92
119
|
private trackAssistantMessageInner;
|
|
93
120
|
getPending(): WakaTimeHeartbeat[];
|
package/lib/tracker.js
CHANGED
|
@@ -3,6 +3,7 @@ import { classifyShellCommand } from './category.js';
|
|
|
3
3
|
import { resolveLanguage } from './language.js';
|
|
4
4
|
import { resolveProject, resolveBranch, resolveProjectRootCount, resolveDependencies } from './project.js';
|
|
5
5
|
import { calculateWriteDiff, calculateEditDiff } from './diff.js';
|
|
6
|
+
import { currentUserAgent } from './user-agent.js';
|
|
6
7
|
/** shell 类心跳缺省的 app entity(设置留空时回退到这里)。 */
|
|
7
8
|
export const DEFAULT_APP_ENTITY = 'Terminal';
|
|
8
9
|
export class FileTracker {
|
|
@@ -13,6 +14,14 @@ export class FileTracker {
|
|
|
13
14
|
inflight = new Set();
|
|
14
15
|
/** 最近一条用户消息的字符数,随下一条 assistant 心跳作为 ai_prompt_length 上报。 */
|
|
15
16
|
lastPromptLength;
|
|
17
|
+
/**
|
|
18
|
+
* 最近一次模型调用所用的模型 id(`message.source.model`),用于 UA 里的模型 token。
|
|
19
|
+
*
|
|
20
|
+
* 为什么缓存而不是每条去读:user message / tool call 心跳也需要 UA,而那些事件
|
|
21
|
+
* 不携带模型身份;缓存最近一次即可近似「当前会话正在用的模型」。模型切换后
|
|
22
|
+
* 下一条 assistant 心跳即更新。
|
|
23
|
+
*/
|
|
24
|
+
lastModelId;
|
|
16
25
|
constructor(session, config) {
|
|
17
26
|
this.session = session;
|
|
18
27
|
this.config = config;
|
|
@@ -82,15 +91,28 @@ export class FileTracker {
|
|
|
82
91
|
const diff = await this.calculateDiff(name, args, entity);
|
|
83
92
|
if (diff) {
|
|
84
93
|
heartbeat.lines = diff.lines;
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
// 官方字段是 `ai_line_changes`(GenAI 增删的行数),不是自造的
|
|
95
|
+
// `line_additions` / `line_deletions`——后者在官方心跳结构里不存在,
|
|
96
|
+
// 服务端直接忽略,WakaTime 的 AI 行数统计因此一直是空的。
|
|
97
|
+
heartbeat.ai_line_changes = diff.lineAdditions + diff.lineDeletions;
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
// 同 entity + 同 category 在 5 秒窗口内合并成一条(与 WakaTime 服务端的
|
|
90
101
|
// 去重窗口一致)。缓冲键必须带上 category:shell 心跳现在共用同一个 entity
|
|
91
102
|
// (应用名),若只按 entity 作键,5 秒内先后跑的 `pnpm test` 与 `ls` 会互相
|
|
92
103
|
// 覆盖,最后只剩后一条的类别——一次跑测试的痕迹会被一条浏览抹掉。
|
|
93
|
-
|
|
104
|
+
this.enqueue(heartbeat);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 入队(含 5 秒去重窗口),并在此处统一贴 `user_agent`。
|
|
108
|
+
*
|
|
109
|
+
* 为什么集中打戳:三类心跳(write 工具、用户消息、assistant 消息)都有自己的
|
|
110
|
+
* 构造点,逐个贴容易漏一个;而 `user_agent` 必须**每条**都带——WakaTime 的
|
|
111
|
+
* Editors / Operating Systems / Models 三个面板都从它解析。
|
|
112
|
+
*/
|
|
113
|
+
enqueue(heartbeat) {
|
|
114
|
+
heartbeat.user_agent = currentUserAgent(this.lastModelId);
|
|
115
|
+
const pendingKey = `${heartbeat.entity}\u0000${heartbeat.category ?? ''}`;
|
|
94
116
|
const existing = this.pending.get(pendingKey);
|
|
95
117
|
if (existing && (heartbeat.time - existing.time) < 5) {
|
|
96
118
|
Object.assign(existing, heartbeat);
|
|
@@ -132,9 +154,14 @@ export class FileTracker {
|
|
|
132
154
|
};
|
|
133
155
|
if (project !== undefined)
|
|
134
156
|
heartbeat.project = project;
|
|
135
|
-
this.
|
|
157
|
+
this.enqueue(heartbeat);
|
|
136
158
|
}
|
|
137
159
|
async trackAssistantMessageInner(event) {
|
|
160
|
+
// 模型身份先记下:user message / tool call 心跳不携带模型,靠这个缓存近似
|
|
161
|
+
// 「当前会话正在用的模型」;切换模型后下一条 assistant 心跳即更新。
|
|
162
|
+
const modelId = event?.data?.message?.source?.model;
|
|
163
|
+
if (typeof modelId === 'string' && modelId !== '')
|
|
164
|
+
this.lastModelId = modelId;
|
|
138
165
|
const usage = event?.data?.usage;
|
|
139
166
|
const time = this.eventTime(event);
|
|
140
167
|
const project = await this.legalProject();
|
|
@@ -166,7 +193,7 @@ export class FileTracker {
|
|
|
166
193
|
heartbeat.ai_prompt_length = this.lastPromptLength;
|
|
167
194
|
this.lastPromptLength = undefined;
|
|
168
195
|
}
|
|
169
|
-
this.
|
|
196
|
+
this.enqueue(heartbeat);
|
|
170
197
|
}
|
|
171
198
|
getPending() {
|
|
172
199
|
return Array.from(this.pending.values());
|
package/lib/types.d.ts
CHANGED
|
@@ -12,8 +12,18 @@ export interface WakaTimeHeartbeat {
|
|
|
12
12
|
language?: string;
|
|
13
13
|
dependencies?: string[];
|
|
14
14
|
lines?: number;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* 由 GenAI 增删的行数(官方字段 `ai_line_changes`)。
|
|
17
|
+
*
|
|
18
|
+
* 与 `lines` 语义不同:`lines` 是「文件共有多少行」,`ai_line_changes` 是
|
|
19
|
+
* 「这次 AI 改动增删了多少行」。WakaTime 的 AI 行数统计只认后者。
|
|
20
|
+
* 早前本插件发的是自造的 `line_additions` / `line_deletions`——官方心跳结构里
|
|
21
|
+
* **不存在**这两个字段(`wakatime-cli` 的 Heartbeat 只有 `ai_line_changes`
|
|
22
|
+
* 与 `human_line_changes`),服务端直接忽略,等于白算。
|
|
23
|
+
*/
|
|
24
|
+
ai_line_changes?: number;
|
|
25
|
+
/** 由人工键入增删的行数(官方字段 `human_line_changes`;本插件不采集,故不发)。 */
|
|
26
|
+
human_line_changes?: number;
|
|
17
27
|
is_write?: boolean;
|
|
18
28
|
/** GenAI 指标(WakaTime 心跳可选字段):本次会话 id */
|
|
19
29
|
ai_session?: string;
|
|
@@ -32,6 +42,15 @@ export interface WakaTimeHeartbeat {
|
|
|
32
42
|
ai_output_tokens?: number;
|
|
33
43
|
/** 距上一心跳的用户提示字符数 */
|
|
34
44
|
ai_prompt_length?: number;
|
|
45
|
+
/**
|
|
46
|
+
* 本心跳所属的 User-Agent(官方心跳结构里有这个 JSON 字段)。
|
|
47
|
+
*
|
|
48
|
+
* 为什么必须逐条带:WakaTime 的 **Editors / Operating Systems / Models** 三个
|
|
49
|
+
* 面板都从 UA 解析(服务端解析代码不开源,行为以官方 CLI 为参照)。批量上报时
|
|
50
|
+
* HTTP 头只有一个 UA,服务端是否会把它落到数组里每条心跳上并无保证;显式逐条
|
|
51
|
+
* 带上才是确定行为。构造见 `user-agent.ts`。
|
|
52
|
+
*/
|
|
53
|
+
user_agent?: string;
|
|
35
54
|
}
|
|
36
55
|
/**
|
|
37
56
|
* Diff calculation result
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-Agent 构造与 AI 模型 token 归一化。
|
|
3
|
+
*
|
|
4
|
+
* WakaTime 侧有三个面板**不是**由心跳字段直接驱动的,而是从 `user_agent`
|
|
5
|
+
* 字符串里解析出来的(官方 `wakatime-cli` 的 `pkg/ai/ai.go` 与
|
|
6
|
+
* `pkg/heartbeat/heartbeat.go` 的 `UserAgent`):
|
|
7
|
+
*
|
|
8
|
+
* - **Editors**:括号后的第一个 product token;
|
|
9
|
+
* - **Operating Systems**:`(...)` 括号段里的 `OS-core-platform`;
|
|
10
|
+
* - **Models / AI Coding**:UA 里的**模型 token**(心跳结构里根本没有
|
|
11
|
+
* `ai_model` 字段,只有 `ai_line_changes` 等 7 个 AI 字段)。
|
|
12
|
+
*
|
|
13
|
+
* 早先本插件发的是 `dsh/1.0.0 dsh-wakatime/1.0.0`——没有括号段,也没有模型
|
|
14
|
+
* token,于是 Operating Systems 落到 `Unknown OS`、Models 面板永远空白
|
|
15
|
+
* (Editors 反而正常,因为第一个 product 被当作 editor 了)。
|
|
16
|
+
*
|
|
17
|
+
* 本模块按官方模板补齐:
|
|
18
|
+
*
|
|
19
|
+
* ```
|
|
20
|
+
* wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <editor> [<model-token>]
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* `wakatime/` 前缀是硬要求:官方 `splitUserAgent()` 只在串以 `wakatime/`
|
|
24
|
+
* 开头时才把前半段当 header(含 OS 括号),否则整串都当 products,OS 段
|
|
25
|
+
* 就解析不出来。
|
|
26
|
+
*
|
|
27
|
+
* @module dsh-wakatime/user-agent
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* 模型 token 归一化 —— 逐条移植官方 `aiModelUserAgentToken`。
|
|
31
|
+
*
|
|
32
|
+
* 服务端靠这个 token 把心跳归到某个 model family(`claude/3-5-sonnet-…`、
|
|
33
|
+
* `gpt/4o` 等)。规则比想象的挑剔,例如:
|
|
34
|
+
*
|
|
35
|
+
* - `deepseek-v4.1-flash-eco` → `deepseek/4.1-flash-eco`
|
|
36
|
+
* - `gpt-4o` → `gpt/4o`
|
|
37
|
+
* - `claude-3-5-sonnet-…` → `claude/3-5-sonnet-…`
|
|
38
|
+
* - `dsh-opendesign-go` → `''`(无数字段 → 识别不出,宁可不发)
|
|
39
|
+
*
|
|
40
|
+
* 空串必须**不**拼进 UA:发出一个识别不出的 token 只会污染 user_agents
|
|
41
|
+
* 表,而不会点亮任何面板。
|
|
42
|
+
*
|
|
43
|
+
* @param model - 宿主提供的模型 id(`message.source.model`)。
|
|
44
|
+
* @param complexity - 可选复杂度后缀(本插件不采集,留空)。
|
|
45
|
+
* @returns 归一化后的 token;识别不出时返回空串。
|
|
46
|
+
*/
|
|
47
|
+
export declare function aiModelToken(model: string, complexity?: string): string;
|
|
48
|
+
export declare function detectHostVersion(): string;
|
|
49
|
+
/**
|
|
50
|
+
* 取本插件对外用的 User-Agent(每次调用都重新拼)。
|
|
51
|
+
*
|
|
52
|
+
* UA 里的模型 token 由调用方传入(心跳层持有「最近一次模型」缓存),这里不
|
|
53
|
+
* 自己做状态管理——同一进程里不同会话的模型可能不同,缓存该由会话侧决定。
|
|
54
|
+
*
|
|
55
|
+
* @param model - 当前会话最近一次使用的模型 id;空/未知识别不出时 UA 不含模型段。
|
|
56
|
+
*/
|
|
57
|
+
export declare function currentUserAgent(model?: string): string;
|
|
58
|
+
/** 构造 UA 所需的运行时信息;全部可注入,便于测试。 */
|
|
59
|
+
export interface UserAgentParts {
|
|
60
|
+
/** 宿主版本(`dsh/<ver>` 中的版本);空串表示探测失败,UA 中省略该段。 */
|
|
61
|
+
hostVersion: string;
|
|
62
|
+
/** 本插件版本。 */
|
|
63
|
+
pluginVersion: string;
|
|
64
|
+
/** 模型 id(可为空:识别不出时不拼 token)。 */
|
|
65
|
+
model?: string;
|
|
66
|
+
/** 复杂度后缀(一般留空)。 */
|
|
67
|
+
complexity?: string;
|
|
68
|
+
/** Node 运行时版本,默认取 `process.versions.node`。 */
|
|
69
|
+
nodeVersion?: string;
|
|
70
|
+
/** 平台,默认取 `process.platform`。 */
|
|
71
|
+
platform?: NodeJS.Platform;
|
|
72
|
+
/** CPU 架构,默认取 `process.arch`;会按官方词汇表映射(x64 → x86_64)。 */
|
|
73
|
+
arch?: string;
|
|
74
|
+
/** 内核版本,默认取 `os.release()`。 */
|
|
75
|
+
kernelRelease?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 按官方模板拼 User-Agent。
|
|
79
|
+
*
|
|
80
|
+
* 形状与 `wakatime-cli` 的 `UserAgent()`(以及注入模型后的
|
|
81
|
+
* `aiUserAgentWithModelTokenAndEditor`)输出同构:
|
|
82
|
+
*
|
|
83
|
+
* ```
|
|
84
|
+
* wakatime/<pluginVer> (<OS>-<core>-<platform>) <runtime> <modelToken?> <editorChain>
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* 逐项对齐官方模板 `"wakatime/%s (%s-%s-%s) %s %s"`:
|
|
88
|
+
*
|
|
89
|
+
* - **`wakatime/<本插件版本>`**:这个前缀是硬要求(`splitUserAgent` 靠它切
|
|
90
|
+
* header/products;没有它,含 OS 的括号段会被当 products,OS 就解析不出来)。
|
|
91
|
+
* 填本插件版本而非宿主版本,`user_agents` 里才能反查是哪个插件发的。
|
|
92
|
+
* - **括号段 `OS-core-platform`**:官方三项依次是 OS 名、CPU 核信息、平台架构;
|
|
93
|
+
* 只有 OS 参与面板归类,后两项仅用于区分机器,这里用内核 release 与 Node
|
|
94
|
+
* 版本充当(不引入新的系统信息采集)。
|
|
95
|
+
* - **products 段**:官方是 `<runtime> <plugin 链>`;模型 token 由
|
|
96
|
+
* `userAgentWithPrependedAgent` **前置**到 products 首位,故这里同样放在
|
|
97
|
+
* runtime 之前。识别不出的模型一律不拼——发出一个解析不了的 token 只会
|
|
98
|
+
* 污染 `user_agents` 表,不会点亮任何面板。
|
|
99
|
+
*
|
|
100
|
+
* 关于验证边界:服务端解析 UA 的代码不开源,且 `user_agents` 读端点对本插件
|
|
101
|
+
* 的 key 返回 403,**无法在本机实测「面板是否点亮」**。因此这里只保证「与官方
|
|
102
|
+
* CLI 产出的形状一致」,而不是「已验证服务端会按预期归类」。
|
|
103
|
+
*
|
|
104
|
+
* @param parts - 见 {@link UserAgentParts}。
|
|
105
|
+
* @returns 单行 UA 字符串。
|
|
106
|
+
*/
|
|
107
|
+
export declare function buildUserAgent(parts: UserAgentParts): string;
|
|
108
|
+
/** 取本插件版本:构建期注入值优先,未注入时回退 `0.0.0`(测试环境)。 */
|
|
109
|
+
export declare function pluginVersion(): string;
|
|
110
|
+
//# sourceMappingURL=user-agent.d.ts.map
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-Agent 构造与 AI 模型 token 归一化。
|
|
3
|
+
*
|
|
4
|
+
* WakaTime 侧有三个面板**不是**由心跳字段直接驱动的,而是从 `user_agent`
|
|
5
|
+
* 字符串里解析出来的(官方 `wakatime-cli` 的 `pkg/ai/ai.go` 与
|
|
6
|
+
* `pkg/heartbeat/heartbeat.go` 的 `UserAgent`):
|
|
7
|
+
*
|
|
8
|
+
* - **Editors**:括号后的第一个 product token;
|
|
9
|
+
* - **Operating Systems**:`(...)` 括号段里的 `OS-core-platform`;
|
|
10
|
+
* - **Models / AI Coding**:UA 里的**模型 token**(心跳结构里根本没有
|
|
11
|
+
* `ai_model` 字段,只有 `ai_line_changes` 等 7 个 AI 字段)。
|
|
12
|
+
*
|
|
13
|
+
* 早先本插件发的是 `dsh/1.0.0 dsh-wakatime/1.0.0`——没有括号段,也没有模型
|
|
14
|
+
* token,于是 Operating Systems 落到 `Unknown OS`、Models 面板永远空白
|
|
15
|
+
* (Editors 反而正常,因为第一个 product 被当作 editor 了)。
|
|
16
|
+
*
|
|
17
|
+
* 本模块按官方模板补齐:
|
|
18
|
+
*
|
|
19
|
+
* ```
|
|
20
|
+
* wakatime/<ver> (<OS>-<core>-<platform>) <runtime> <editor> [<model-token>]
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* `wakatime/` 前缀是硬要求:官方 `splitUserAgent()` 只在串以 `wakatime/`
|
|
24
|
+
* 开头时才把前半段当 header(含 OS 括号),否则整串都当 products,OS 段
|
|
25
|
+
* 就解析不出来。
|
|
26
|
+
*
|
|
27
|
+
* @module dsh-wakatime/user-agent
|
|
28
|
+
*/
|
|
29
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
30
|
+
import { dirname, join } from 'node:path';
|
|
31
|
+
import { release } from 'node:os';
|
|
32
|
+
/**
|
|
33
|
+
* 官方 UA 模板里的 OS 名。
|
|
34
|
+
*
|
|
35
|
+
* 取值来自本账号 `user_agents` 端点里 50 条官方 CLI 的真实样本,括号段一律
|
|
36
|
+
* `(linux-<内核>-<arch>)`——**小写**,不是 `Linux`。这一项直接决定 Operating
|
|
37
|
+
* Systems 面板的归类键,大小写不一致会多出一个新条目而不是并入已有归类。
|
|
38
|
+
*/
|
|
39
|
+
function osName(platform) {
|
|
40
|
+
if (platform === 'win32')
|
|
41
|
+
return 'windows';
|
|
42
|
+
if (platform === 'darwin')
|
|
43
|
+
return 'darwin';
|
|
44
|
+
return 'linux';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 官方括号段第三项(platform/arch)的写法。
|
|
48
|
+
*
|
|
49
|
+
* 官方 CLI 写 `x86_64`;Node 的 `process.arch` 是 `x64`,直接塞进去会变成
|
|
50
|
+
* `x64` 这个陌生值,和官方条目分家。这里按官方词汇表映射。
|
|
51
|
+
*/
|
|
52
|
+
function archName(arch) {
|
|
53
|
+
if (arch === 'x64')
|
|
54
|
+
return 'x86_64';
|
|
55
|
+
if (arch === 'arm64')
|
|
56
|
+
return 'aarch64';
|
|
57
|
+
if (arch === 'ia32')
|
|
58
|
+
return 'i686';
|
|
59
|
+
return arch;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 模型 token 归一化 —— 逐条移植官方 `aiModelUserAgentToken`。
|
|
63
|
+
*
|
|
64
|
+
* 服务端靠这个 token 把心跳归到某个 model family(`claude/3-5-sonnet-…`、
|
|
65
|
+
* `gpt/4o` 等)。规则比想象的挑剔,例如:
|
|
66
|
+
*
|
|
67
|
+
* - `deepseek-v4.1-flash-eco` → `deepseek/4.1-flash-eco`
|
|
68
|
+
* - `gpt-4o` → `gpt/4o`
|
|
69
|
+
* - `claude-3-5-sonnet-…` → `claude/3-5-sonnet-…`
|
|
70
|
+
* - `dsh-opendesign-go` → `''`(无数字段 → 识别不出,宁可不发)
|
|
71
|
+
*
|
|
72
|
+
* 空串必须**不**拼进 UA:发出一个识别不出的 token 只会污染 user_agents
|
|
73
|
+
* 表,而不会点亮任何面板。
|
|
74
|
+
*
|
|
75
|
+
* @param model - 宿主提供的模型 id(`message.source.model`)。
|
|
76
|
+
* @param complexity - 可选复杂度后缀(本插件不采集,留空)。
|
|
77
|
+
* @returns 归一化后的 token;识别不出时返回空串。
|
|
78
|
+
*/
|
|
79
|
+
export function aiModelToken(model, complexity = '') {
|
|
80
|
+
let m = model.trim().split(/\s+/).filter((s) => s !== '').join('-');
|
|
81
|
+
m = m.replace(/^\/+|\/+$/g, '');
|
|
82
|
+
if (m === '')
|
|
83
|
+
return '';
|
|
84
|
+
let cx = (complexity ?? '').trim().split(/\s+/).filter((s) => s !== '').join('-');
|
|
85
|
+
cx = cx.replace(/^[-_/.]+|[-_/.]+$/g, '');
|
|
86
|
+
if (cx !== '' && !m.toLowerCase().endsWith(`-${cx.toLowerCase()}`)) {
|
|
87
|
+
m += `-${cx}`;
|
|
88
|
+
}
|
|
89
|
+
// 已经是 `product/version` 形状且 version 以数字开头:原样保留。
|
|
90
|
+
const slash = m.indexOf('/');
|
|
91
|
+
if (slash !== -1) {
|
|
92
|
+
const product = m.slice(0, slash);
|
|
93
|
+
const version = m.slice(slash + 1);
|
|
94
|
+
if (product !== '' && version !== '' && /^[0-9]/.test(version)) {
|
|
95
|
+
return `${product}/${version}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// 否则取最后一个 `/` 之后的部分继续解析。
|
|
99
|
+
if (slash !== -1) {
|
|
100
|
+
const last = m.lastIndexOf('/');
|
|
101
|
+
m = m.slice(last + 1).replace(/^[-_.]+|[-_.]+$/g, '');
|
|
102
|
+
}
|
|
103
|
+
const parts = m.split(/[-_]/).filter((p) => p !== '');
|
|
104
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
105
|
+
const part = parts[i];
|
|
106
|
+
for (let j = 0; j < part.length; j += 1) {
|
|
107
|
+
const ch = part[j];
|
|
108
|
+
if (ch < '0' || ch > '9')
|
|
109
|
+
continue;
|
|
110
|
+
if (j === 0) {
|
|
111
|
+
// 整个 segment 就是一个纯数字:前一个 segment 是 family,从数字起是版本。
|
|
112
|
+
if (i === 0)
|
|
113
|
+
return '';
|
|
114
|
+
return `${parts[i - 1]}/${parts.slice(i).join('-')}`;
|
|
115
|
+
}
|
|
116
|
+
// 数字出现在 segment 中间:数字前是 family(`v` 要回退到上一个 segment),
|
|
117
|
+
// 数字起连同后续 segment 是版本。
|
|
118
|
+
let product = part.slice(0, j);
|
|
119
|
+
if (product.toLowerCase() === 'v' && i > 0)
|
|
120
|
+
product = parts[i - 1];
|
|
121
|
+
let version = part.slice(j);
|
|
122
|
+
if (i + 1 < parts.length)
|
|
123
|
+
version += `-${parts.slice(i + 1).join('-')}`;
|
|
124
|
+
return `${product}/${version}`;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// 全文无数字:官方同样返回空(例如 `dsh-opendesign-go`)。
|
|
128
|
+
return '';
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* 探测宿主(dsh)版本,用于 UA 里的 `dsh/<ver>` 与 `wakatime/<ver>` 无关的那一段。
|
|
132
|
+
*
|
|
133
|
+
* 为什么要专门探测:插件**不能**直接 `require('@deepseek-ai/dsh/package.json')`
|
|
134
|
+
* ——实测从插件运行位置解析该包会 `MODULE_NOT_FOUND`(两侧 node_modules 是
|
|
135
|
+
* 不同的安装树),而解析到的 `dsh-session` 是**插件自己的 devDependency**
|
|
136
|
+
* (0.2.1-rc.2),不是运行中的宿主(0.2.2-rc.5),拿它填 UA 会报错版本。
|
|
137
|
+
*
|
|
138
|
+
* 可靠来源是宿主进程自身的入口路径:`process.argv[1]` 指向 `.bin/dsh`,
|
|
139
|
+
* 其 realpath 落在 `<install>/node_modules/@deepseek-ai/dsh/lib/bin.js`,
|
|
140
|
+
* 向上找最近的 package.json 即宿主清单。取不到就回退空串(UA 里省略该段),
|
|
141
|
+
* 绝不猜一个版本填进去。
|
|
142
|
+
*
|
|
143
|
+
* @returns 宿主版本(如 `0.2.2-rc.5`),探测失败返回空串。
|
|
144
|
+
*/
|
|
145
|
+
let hostVersionCache;
|
|
146
|
+
export function detectHostVersion() {
|
|
147
|
+
if (hostVersionCache !== undefined)
|
|
148
|
+
return hostVersionCache;
|
|
149
|
+
hostVersionCache = detectHostVersionUncached();
|
|
150
|
+
return hostVersionCache;
|
|
151
|
+
}
|
|
152
|
+
function detectHostVersionUncached() {
|
|
153
|
+
try {
|
|
154
|
+
const entry = process.argv[1];
|
|
155
|
+
if (typeof entry !== 'string' || entry === '')
|
|
156
|
+
return '';
|
|
157
|
+
// 本插件是 ESM(package.json `"type": "module"`):这里**不能**写 `require`。
|
|
158
|
+
// 实测踩过——TypeScript 不报错、tsc 原样保留、单测(vite 转译)也能过,
|
|
159
|
+
// 但宿主进程里 `typeof require === 'undefined'`,调用直接抛 ReferenceError,
|
|
160
|
+
// 被外层 catch 吞成空串:活心跳的 UA 里就少了 `dsh/<ver>` 这一段。
|
|
161
|
+
// 顶部的静态 import 在 ESM 下才是有效的。
|
|
162
|
+
let dir = dirname(realpathSync(entry));
|
|
163
|
+
for (let depth = 0; depth < 8; depth += 1) {
|
|
164
|
+
const manifest = join(dir, 'package.json');
|
|
165
|
+
if (existsSync(manifest)) {
|
|
166
|
+
const parsed = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
167
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
168
|
+
const name = parsed.name;
|
|
169
|
+
const version = parsed.version;
|
|
170
|
+
if (typeof version === 'string' && version !== '' && typeof name === 'string' && name.startsWith('@deepseek-ai/dsh')) {
|
|
171
|
+
return version;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const parent = dirname(dir);
|
|
176
|
+
if (parent === dir)
|
|
177
|
+
break;
|
|
178
|
+
dir = parent;
|
|
179
|
+
}
|
|
180
|
+
return '';
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return '';
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 取本插件对外用的 User-Agent(每次调用都重新拼)。
|
|
188
|
+
*
|
|
189
|
+
* UA 里的模型 token 由调用方传入(心跳层持有「最近一次模型」缓存),这里不
|
|
190
|
+
* 自己做状态管理——同一进程里不同会话的模型可能不同,缓存该由会话侧决定。
|
|
191
|
+
*
|
|
192
|
+
* @param model - 当前会话最近一次使用的模型 id;空/未知识别不出时 UA 不含模型段。
|
|
193
|
+
*/
|
|
194
|
+
export function currentUserAgent(model) {
|
|
195
|
+
return buildUserAgent({
|
|
196
|
+
hostVersion: detectHostVersion(),
|
|
197
|
+
pluginVersion: pluginVersion(),
|
|
198
|
+
...(model === undefined ? {} : { model }),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* 按官方模板拼 User-Agent。
|
|
203
|
+
*
|
|
204
|
+
* 形状与 `wakatime-cli` 的 `UserAgent()`(以及注入模型后的
|
|
205
|
+
* `aiUserAgentWithModelTokenAndEditor`)输出同构:
|
|
206
|
+
*
|
|
207
|
+
* ```
|
|
208
|
+
* wakatime/<pluginVer> (<OS>-<core>-<platform>) <runtime> <modelToken?> <editorChain>
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* 逐项对齐官方模板 `"wakatime/%s (%s-%s-%s) %s %s"`:
|
|
212
|
+
*
|
|
213
|
+
* - **`wakatime/<本插件版本>`**:这个前缀是硬要求(`splitUserAgent` 靠它切
|
|
214
|
+
* header/products;没有它,含 OS 的括号段会被当 products,OS 就解析不出来)。
|
|
215
|
+
* 填本插件版本而非宿主版本,`user_agents` 里才能反查是哪个插件发的。
|
|
216
|
+
* - **括号段 `OS-core-platform`**:官方三项依次是 OS 名、CPU 核信息、平台架构;
|
|
217
|
+
* 只有 OS 参与面板归类,后两项仅用于区分机器,这里用内核 release 与 Node
|
|
218
|
+
* 版本充当(不引入新的系统信息采集)。
|
|
219
|
+
* - **products 段**:官方是 `<runtime> <plugin 链>`;模型 token 由
|
|
220
|
+
* `userAgentWithPrependedAgent` **前置**到 products 首位,故这里同样放在
|
|
221
|
+
* runtime 之前。识别不出的模型一律不拼——发出一个解析不了的 token 只会
|
|
222
|
+
* 污染 `user_agents` 表,不会点亮任何面板。
|
|
223
|
+
*
|
|
224
|
+
* 关于验证边界:服务端解析 UA 的代码不开源,且 `user_agents` 读端点对本插件
|
|
225
|
+
* 的 key 返回 403,**无法在本机实测「面板是否点亮」**。因此这里只保证「与官方
|
|
226
|
+
* CLI 产出的形状一致」,而不是「已验证服务端会按预期归类」。
|
|
227
|
+
*
|
|
228
|
+
* @param parts - 见 {@link UserAgentParts}。
|
|
229
|
+
* @returns 单行 UA 字符串。
|
|
230
|
+
*/
|
|
231
|
+
export function buildUserAgent(parts) {
|
|
232
|
+
const platform = parts.platform ?? process.platform;
|
|
233
|
+
const kernel = parts.kernelRelease ?? safeRelease();
|
|
234
|
+
const nodeVersion = parts.nodeVersion ?? process.versions.node;
|
|
235
|
+
const arch = archName(parts.arch ?? process.arch);
|
|
236
|
+
const os = osName(platform);
|
|
237
|
+
// header 段 = `wakatime/<ver> (<OS>-…>) <runtime>`;官方 splitUserAgent 把
|
|
238
|
+
// 括号后第一个空格前的内容归入 header,其余才是 products,所以 runtime 必须
|
|
239
|
+
// 紧跟括号,不能落进 products。
|
|
240
|
+
const header = `wakatime/${parts.pluginVersion} (${os}-${kernel}-${arch}) node/${nodeVersion}`;
|
|
241
|
+
// products = [模型 token?] + editor 链。模型放首位是照官方
|
|
242
|
+
// `userAgentWithPrependedAgent` 的输出顺序(模型 → editor → 其余)。
|
|
243
|
+
// 探测不到宿主版本时省略 `dsh/` 段:宁可少一个 token,也不发一个编出来的版本
|
|
244
|
+
// (Editors 面板此时回退到 `node/…`,仍能归类,不会污染 user_agents 表)。
|
|
245
|
+
const products = [];
|
|
246
|
+
const token = parts.model === undefined ? '' : aiModelToken(parts.model, parts.complexity ?? '');
|
|
247
|
+
if (token !== '')
|
|
248
|
+
products.push(token);
|
|
249
|
+
if (parts.hostVersion !== '')
|
|
250
|
+
products.push(`dsh/${parts.hostVersion}`);
|
|
251
|
+
// products 可能为空(探测不到宿主版本且模型识别不出)——此时不能留尾随空格。
|
|
252
|
+
return products.length === 0 ? header : `${header} ${products.join(' ')}`;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 构建期注入的本插件版本占位。
|
|
256
|
+
*
|
|
257
|
+
* `build.mjs` 在 tsc 之后把这一整行替换成 `package.json` 的真实版本字面量;
|
|
258
|
+
* 源码里**绝不手写版本号**——UA 曾长期停在 `1.0.0`,而包已经发到 `1.1.0`,
|
|
259
|
+
* 就是手写造成的脱钩。未注入时(vitest 直接跑源码)为 undefined。
|
|
260
|
+
*/
|
|
261
|
+
const INJECTED_PLUGIN_VERSION = "1.2.1";
|
|
262
|
+
/** 取本插件版本:构建期注入值优先,未注入时回退 `0.0.0`(测试环境)。 */
|
|
263
|
+
export function pluginVersion() {
|
|
264
|
+
return typeof INJECTED_PLUGIN_VERSION === 'string' && INJECTED_PLUGIN_VERSION !== ''
|
|
265
|
+
? INJECTED_PLUGIN_VERSION
|
|
266
|
+
: '0.0.0';
|
|
267
|
+
}
|
|
268
|
+
/** `os.release()` 在极少数容器里会抛;UA 构造不能因此中断心跳。 */
|
|
269
|
+
function safeRelease() {
|
|
270
|
+
try {
|
|
271
|
+
return release() || 'unknown';
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return 'unknown';
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=user-agent.js.map
|
package/lib/wakatime.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WakaTimeError, WakaTimeAuthError, WakaTimeRateLimitError } from './types.js';
|
|
2
|
+
import { currentUserAgent } from './user-agent.js';
|
|
2
3
|
/** 默认请求超时:挂起的服务端不能让 flush 永不返回、并发请求越积越多。 */
|
|
3
4
|
const DEFAULT_REQUEST_TIMEOUT_MS = 10_000;
|
|
4
5
|
/**
|
|
@@ -223,7 +224,9 @@ export class WakaTimeClient {
|
|
|
223
224
|
constructor(config) {
|
|
224
225
|
this.apiKey = config.api_key;
|
|
225
226
|
this.baseUrl = `${config.api_url}/api/v1`;
|
|
226
|
-
|
|
227
|
+
// HTTP 头只是兜底:真正的归属信息逐条写在心跳的 `user_agent` 字段里
|
|
228
|
+
// (批量上报时一个头无法区分不同会话/不同模型的条目)。构造规则见 user-agent.ts。
|
|
229
|
+
this.userAgent = currentUserAgent();
|
|
227
230
|
const resolved = resolveProxy(process.env, config.cfg_proxy, config.proxy_url);
|
|
228
231
|
this.proxyUrl = resolved.proxy;
|
|
229
232
|
this.noProxy = usableNoProxy(config.no_proxy) ?? process.env.NO_PROXY ?? '';
|
|
@@ -300,10 +303,14 @@ export class WakaTimeClient {
|
|
|
300
303
|
}
|
|
301
304
|
const url = `${this.baseUrl}/users/current/heartbeats.bulk`;
|
|
302
305
|
const body = JSON.stringify(payloads);
|
|
306
|
+
// HTTP 头跟着本批心跳走:client 是插件级单例,构造时还拿不到模型身份,
|
|
307
|
+
// 而 UA 里的模型段是逐会话变化的。优先取本批第一条的 UA(它们同源),
|
|
308
|
+
// 都缺才回退构造时的兜底值。
|
|
309
|
+
const batchUserAgent = payloads.find((hb) => typeof hb.user_agent === 'string' && hb.user_agent !== '')?.user_agent;
|
|
303
310
|
let response;
|
|
304
311
|
const targetHost = new URL(url).hostname;
|
|
305
312
|
if (shouldUseProxy(this.proxyUrl, targetHost, this.noProxy)) {
|
|
306
|
-
response = await this.fetchWithProxy(url, body);
|
|
313
|
+
response = await this.fetchWithProxy(url, body, batchUserAgent ?? this.userAgent);
|
|
307
314
|
}
|
|
308
315
|
else {
|
|
309
316
|
try {
|
|
@@ -312,7 +319,7 @@ export class WakaTimeClient {
|
|
|
312
319
|
headers: {
|
|
313
320
|
'Authorization': `Basic ${btoa(this.apiKey + ':')}`,
|
|
314
321
|
'Content-Type': 'application/json',
|
|
315
|
-
'User-Agent': this.userAgent,
|
|
322
|
+
'User-Agent': batchUserAgent ?? this.userAgent,
|
|
316
323
|
},
|
|
317
324
|
body,
|
|
318
325
|
signal: AbortSignal.timeout(this.requestTimeoutMs),
|
|
@@ -400,7 +407,7 @@ export class WakaTimeClient {
|
|
|
400
407
|
* @param url - 目标绝对地址。
|
|
401
408
|
* @param body - 请求体(心跳批量上报的 JSON)。
|
|
402
409
|
*/
|
|
403
|
-
async fetchWithProxy(url, body) {
|
|
410
|
+
async fetchWithProxy(url, body, userAgent) {
|
|
404
411
|
const parsed = new URL(url);
|
|
405
412
|
const proxyParsed = new URL(this.proxyUrl);
|
|
406
413
|
// Build proxy request
|
|
@@ -464,7 +471,7 @@ export class WakaTimeClient {
|
|
|
464
471
|
'Authorization': `Basic ${btoa(this.apiKey + ':')}`,
|
|
465
472
|
'Content-Type': 'application/json',
|
|
466
473
|
'Content-Length': String(Buffer.byteLength(body)),
|
|
467
|
-
'User-Agent':
|
|
474
|
+
'User-Agent': userAgent,
|
|
468
475
|
'Host': parsed.host,
|
|
469
476
|
},
|
|
470
477
|
socket,
|