@reconcrap/boss-recommend-mcp 2.0.46 → 2.0.47
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/bin/boss-recommend-mcp.js +4 -4
- package/config/screening-config.example.json +27 -27
- package/package.json +1 -1
- package/scripts/postinstall.cjs +44 -44
- package/skills/boss-chat/README.md +39 -39
- package/skills/boss-chat/SKILL.md +93 -93
- package/skills/boss-recommend-pipeline/README.md +12 -12
- package/skills/boss-recommend-pipeline/SKILL.md +180 -180
- package/skills/boss-recruit-pipeline/README.md +17 -17
- package/skills/boss-recruit-pipeline/SKILL.md +58 -58
- package/src/chat-mcp.js +1780 -1780
- package/src/chat-runtime-config.js +749 -749
- package/src/cli.js +3054 -3054
- package/src/core/boss-cards/index.js +199 -199
- package/src/core/browser/index.js +1453 -1453
- package/src/core/capture/index.js +1201 -1201
- package/src/core/cv-acquisition/index.js +238 -238
- package/src/core/cv-capture-target/index.js +299 -299
- package/src/core/greet-quota/index.js +54 -54
- package/src/core/infinite-list/index.js +1326 -1326
- package/src/core/reporting/legacy-csv.js +341 -341
- package/src/core/run/timing.js +33 -33
- package/src/core/screening/index.js +50 -3
- package/src/core/self-heal/index.js +973 -973
- package/src/core/self-heal/viewport.js +564 -564
- package/src/domains/chat/cards.js +137 -137
- package/src/domains/chat/constants.js +221 -221
- package/src/domains/chat/detail.js +1668 -1668
- package/src/domains/chat/index.js +7 -7
- package/src/domains/chat/jobs.js +592 -592
- package/src/domains/chat/page-guard.js +98 -98
- package/src/domains/chat/roots.js +56 -56
- package/src/domains/chat/run-service.js +1977 -1977
- package/src/domains/recommend/actions.js +457 -457
- package/src/domains/recommend/cards.js +243 -243
- package/src/domains/recommend/constants.js +165 -165
- package/src/domains/recommend/detail.js +25 -18
- package/src/domains/recommend/filters.js +610 -610
- package/src/domains/recommend/index.js +10 -10
- package/src/domains/recommend/jobs.js +316 -316
- package/src/domains/recommend/refresh.js +472 -472
- package/src/domains/recommend/roots.js +80 -80
- package/src/domains/recommend/run-service.js +27 -20
- package/src/domains/recommend/scopes.js +246 -246
- package/src/domains/recruit/actions.js +277 -277
- package/src/domains/recruit/cards.js +74 -74
- package/src/domains/recruit/constants.js +167 -167
- package/src/domains/recruit/detail.js +461 -461
- package/src/domains/recruit/index.js +9 -9
- package/src/domains/recruit/instruction-parser.js +451 -451
- package/src/domains/recruit/refresh.js +44 -44
- package/src/domains/recruit/roots.js +68 -68
- package/src/domains/recruit/run-service.js +1207 -1207
- package/src/domains/recruit/search.js +1202 -1202
- package/src/recommend-mcp.js +22 -22
- package/src/recruit-mcp.js +1338 -1338
|
@@ -1,277 +1,277 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clickNodeCenter,
|
|
3
|
-
getAttributesMap,
|
|
4
|
-
getNodeBox,
|
|
5
|
-
getOuterHTML,
|
|
6
|
-
querySelectorAll,
|
|
7
|
-
sleep
|
|
8
|
-
} from "../../core/browser/index.js";
|
|
9
|
-
import {
|
|
10
|
-
htmlToText,
|
|
11
|
-
normalizeText
|
|
12
|
-
} from "../../core/screening/index.js";
|
|
13
|
-
import {
|
|
14
|
-
assertGreetQuotaAvailable,
|
|
15
|
-
parseGreetQuota
|
|
16
|
-
} from "../../core/greet-quota/index.js";
|
|
17
|
-
|
|
18
|
-
const ACTION_SELECTOR = [
|
|
19
|
-
"button",
|
|
20
|
-
'[role="button"]',
|
|
21
|
-
".btn",
|
|
22
|
-
'[class*="btn"]',
|
|
23
|
-
'[class*="chat"]',
|
|
24
|
-
'[class*="greet"]',
|
|
25
|
-
'[ka*="chat"]',
|
|
26
|
-
'[ka*="greet"]',
|
|
27
|
-
'[ka*="contact"]'
|
|
28
|
-
].join(", ");
|
|
29
|
-
|
|
30
|
-
const DISABLED_PATTERN = /\b(disabled|disable|ui-disabled|is-disabled)\b/i;
|
|
31
|
-
const CONTINUE_CHAT_PATTERN = /继续沟通|继续聊天|查看沟通|已沟通/i;
|
|
32
|
-
const GREET_PATTERN = /打招呼|立即沟通|立即聊天|聊一聊|开聊|沟通/i;
|
|
33
|
-
const GREET_LABEL_PATTERN = /^(打招呼|立即沟通|立即聊天|聊一聊|开聊|沟通)(?:[\((]\d+\s*[//]\s*\d+[\))])?$/i;
|
|
34
|
-
const FAVORITE_PATTERN = /收藏|感兴趣/i;
|
|
35
|
-
const FAVORITE_LABEL_PATTERN = /^(收藏|感兴趣)$/i;
|
|
36
|
-
const OPEN_RESUME_KA_PATTERN = /search_click_open_resume|open_resume|resume/i;
|
|
37
|
-
const EXTERNAL_URL_PATTERN = /(?:https?:)?\/\/|github\.com|gitlab\.com|gitee\.com/i;
|
|
38
|
-
const MAX_ACTION_LABEL_LENGTH = 80;
|
|
39
|
-
|
|
40
|
-
function openingTagName(outerHTML = "") {
|
|
41
|
-
const match = String(outerHTML || "").match(/^<\s*([a-z0-9-]+)/i);
|
|
42
|
-
return match ? match[1].toLowerCase() : "";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function isButtonLike(attributes = {}, outerHTML = "") {
|
|
46
|
-
const tagName = openingTagName(outerHTML);
|
|
47
|
-
const className = normalizeText(attributes.class);
|
|
48
|
-
const role = normalizeText(attributes.role).toLowerCase();
|
|
49
|
-
const ka = normalizeText(attributes.ka || attributes["data-ka"]);
|
|
50
|
-
return tagName === "button"
|
|
51
|
-
|| role === "button"
|
|
52
|
-
|| /\bbtn\b|button|chat|greet/i.test(className)
|
|
53
|
-
|| /greet|chat|contact/i.test(ka);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function isUnsafeLinkOrCard(attributes = {}, outerHTML = "") {
|
|
57
|
-
const tagName = openingTagName(outerHTML);
|
|
58
|
-
const href = normalizeText(attributes.href);
|
|
59
|
-
const ka = normalizeText(attributes.ka || attributes["data-ka"]);
|
|
60
|
-
const className = normalizeText(attributes.class);
|
|
61
|
-
const joined = [href, ka, className, String(outerHTML || "").slice(0, 500)].join(" ");
|
|
62
|
-
if (OPEN_RESUME_KA_PATTERN.test(ka)) return true;
|
|
63
|
-
if (tagName === "a" && href && !/^#|^javascript:/i.test(href)) return true;
|
|
64
|
-
if (EXTERNAL_URL_PATTERN.test(joined) && tagName === "a") return true;
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function nodeIsDisabled(attributes = {}, outerHTML = "") {
|
|
69
|
-
const joined = [
|
|
70
|
-
attributes.class,
|
|
71
|
-
attributes.disabled,
|
|
72
|
-
attributes["aria-disabled"],
|
|
73
|
-
attributes["data-disabled"],
|
|
74
|
-
String(outerHTML || "").slice(0, 500)
|
|
75
|
-
].map(normalizeText).join(" ");
|
|
76
|
-
return DISABLED_PATTERN.test(joined)
|
|
77
|
-
|| attributes.disabled !== undefined
|
|
78
|
-
|| normalizeText(attributes["aria-disabled"]).toLowerCase() === "true";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function classifyRecruitAction({ text = "", attributes = {}, outerHTML = "" } = {}) {
|
|
82
|
-
if (isUnsafeLinkOrCard(attributes, outerHTML)) return null;
|
|
83
|
-
const joined = [
|
|
84
|
-
text,
|
|
85
|
-
attributes.class,
|
|
86
|
-
attributes.ka,
|
|
87
|
-
attributes["data-ka"],
|
|
88
|
-
attributes.title,
|
|
89
|
-
attributes["aria-label"]
|
|
90
|
-
].map(normalizeText).join(" ");
|
|
91
|
-
const label = normalizeText(text);
|
|
92
|
-
const buttonLike = isButtonLike(attributes, outerHTML);
|
|
93
|
-
const continueChat = CONTINUE_CHAT_PATTERN.test(joined);
|
|
94
|
-
const greetQuota = parseGreetQuota(label);
|
|
95
|
-
if (continueChat) {
|
|
96
|
-
return {
|
|
97
|
-
kind: "greet",
|
|
98
|
-
continue_chat: true,
|
|
99
|
-
available: false,
|
|
100
|
-
greet_quota: null
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
if (GREET_PATTERN.test(joined) && buttonLike && (label.length <= MAX_ACTION_LABEL_LENGTH || GREET_LABEL_PATTERN.test(label))) {
|
|
104
|
-
return {
|
|
105
|
-
kind: "greet",
|
|
106
|
-
continue_chat: false,
|
|
107
|
-
available: !nodeIsDisabled(attributes, outerHTML),
|
|
108
|
-
greet_quota: greetQuota.found ? greetQuota : null
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (FAVORITE_PATTERN.test(joined) && buttonLike && (label.length <= MAX_ACTION_LABEL_LENGTH || FAVORITE_LABEL_PATTERN.test(label))) {
|
|
112
|
-
return {
|
|
113
|
-
kind: "favorite",
|
|
114
|
-
continue_chat: false,
|
|
115
|
-
available: !nodeIsDisabled(attributes, outerHTML)
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function scoreRecruitAction(control) {
|
|
122
|
-
let score = 0;
|
|
123
|
-
if (control.kind === "greet") score += 100;
|
|
124
|
-
if (control.available) score += 20;
|
|
125
|
-
if (!control.continue_chat) score += 10;
|
|
126
|
-
if (/打招呼/.test(control.label)) score += 10;
|
|
127
|
-
if (/立即沟通|聊一聊|开聊/.test(control.label)) score += 6;
|
|
128
|
-
if (/btn|button/i.test(control.class_name)) score += 3;
|
|
129
|
-
return score;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async function readRecruitActionControl(client, nodeId, {
|
|
133
|
-
selector = "",
|
|
134
|
-
index = 0
|
|
135
|
-
} = {}) {
|
|
136
|
-
let attributes;
|
|
137
|
-
let outerHTML;
|
|
138
|
-
try {
|
|
139
|
-
[attributes, outerHTML] = await Promise.all([
|
|
140
|
-
getAttributesMap(client, nodeId),
|
|
141
|
-
getOuterHTML(client, nodeId)
|
|
142
|
-
]);
|
|
143
|
-
} catch {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
const text = normalizeText(htmlToText(outerHTML));
|
|
147
|
-
const classified = classifyRecruitAction({ text, attributes, outerHTML });
|
|
148
|
-
if (!classified) return null;
|
|
149
|
-
let box = null;
|
|
150
|
-
try {
|
|
151
|
-
box = await getNodeBox(client, nodeId);
|
|
152
|
-
} catch {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
if (!box?.rect || box.rect.width < 4 || box.rect.height < 4) return null;
|
|
156
|
-
const control = {
|
|
157
|
-
node_id: nodeId,
|
|
158
|
-
selector,
|
|
159
|
-
index,
|
|
160
|
-
kind: classified.kind,
|
|
161
|
-
label: text,
|
|
162
|
-
class_name: attributes.class || "",
|
|
163
|
-
attributes: {
|
|
164
|
-
ka: attributes.ka || attributes["data-ka"] || "",
|
|
165
|
-
href: attributes.href || "",
|
|
166
|
-
role: attributes.role || "",
|
|
167
|
-
title: attributes.title || "",
|
|
168
|
-
aria_label: attributes["aria-label"] || ""
|
|
169
|
-
},
|
|
170
|
-
tag_name: openingTagName(outerHTML),
|
|
171
|
-
disabled: nodeIsDisabled(attributes, outerHTML),
|
|
172
|
-
available: Boolean(classified.available),
|
|
173
|
-
continue_chat: Boolean(classified.continue_chat),
|
|
174
|
-
greet_quota: classified.greet_quota || null,
|
|
175
|
-
center: box.center,
|
|
176
|
-
rect: box.rect
|
|
177
|
-
};
|
|
178
|
-
control.score = scoreRecruitAction(control);
|
|
179
|
-
return control;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export async function discoverRecruitDetailActionControls(client, rootNodeIds = []) {
|
|
183
|
-
const controls = [];
|
|
184
|
-
const seen = new Set();
|
|
185
|
-
for (const rootNodeId of rootNodeIds.filter(Boolean)) {
|
|
186
|
-
let nodeIds = [];
|
|
187
|
-
try {
|
|
188
|
-
nodeIds = await querySelectorAll(client, rootNodeId, ACTION_SELECTOR);
|
|
189
|
-
} catch {
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
for (let index = 0; index < nodeIds.length; index += 1) {
|
|
193
|
-
const nodeId = nodeIds[index];
|
|
194
|
-
if (!nodeId || seen.has(nodeId)) continue;
|
|
195
|
-
seen.add(nodeId);
|
|
196
|
-
const control = await readRecruitActionControl(client, nodeId, {
|
|
197
|
-
selector: ACTION_SELECTOR,
|
|
198
|
-
index
|
|
199
|
-
});
|
|
200
|
-
if (control) controls.push(control);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
controls.sort((left, right) => right.score - left.score);
|
|
204
|
-
return controls;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function summarizeRecruitActionControls(controls = []) {
|
|
208
|
-
const greetControls = controls.filter((control) => control.kind === "greet");
|
|
209
|
-
const favoriteControls = controls.filter((control) => control.kind === "favorite");
|
|
210
|
-
const actionableGreet = greetControls.find((control) => control.available && !control.continue_chat) || null;
|
|
211
|
-
const continueGreet = greetControls.find((control) => control.continue_chat) || null;
|
|
212
|
-
const actionableFavorite = favoriteControls.find((control) => control.available) || null;
|
|
213
|
-
return {
|
|
214
|
-
greet: {
|
|
215
|
-
found: Boolean(actionableGreet || continueGreet),
|
|
216
|
-
available: Boolean(actionableGreet),
|
|
217
|
-
continue_chat: Boolean(continueGreet && !actionableGreet),
|
|
218
|
-
greet_quota: actionableGreet?.greet_quota || continueGreet?.greet_quota || null,
|
|
219
|
-
control: actionableGreet || continueGreet
|
|
220
|
-
},
|
|
221
|
-
favorite: {
|
|
222
|
-
found: Boolean(actionableFavorite),
|
|
223
|
-
available: Boolean(actionableFavorite),
|
|
224
|
-
control: actionableFavorite
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export async function waitForRecruitDetailActionControls(client, {
|
|
230
|
-
rootNodeIds = [],
|
|
231
|
-
timeoutMs = 8000,
|
|
232
|
-
intervalMs = 400,
|
|
233
|
-
requireAny = false
|
|
234
|
-
} = {}) {
|
|
235
|
-
const started = Date.now();
|
|
236
|
-
let controls = [];
|
|
237
|
-
while (Date.now() - started <= timeoutMs) {
|
|
238
|
-
controls = await discoverRecruitDetailActionControls(client, rootNodeIds);
|
|
239
|
-
const summary = summarizeRecruitActionControls(controls);
|
|
240
|
-
if (!requireAny || summary.greet.found || summary.favorite.found) {
|
|
241
|
-
return {
|
|
242
|
-
ok: summary.greet.found || summary.favorite.found,
|
|
243
|
-
elapsed_ms: Date.now() - started,
|
|
244
|
-
controls,
|
|
245
|
-
summary
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
await sleep(intervalMs);
|
|
249
|
-
}
|
|
250
|
-
return {
|
|
251
|
-
ok: false,
|
|
252
|
-
elapsed_ms: Date.now() - started,
|
|
253
|
-
controls,
|
|
254
|
-
summary: summarizeRecruitActionControls(controls)
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export async function clickRecruitActionControl(client, control, {
|
|
259
|
-
delayMs = 120
|
|
260
|
-
} = {}) {
|
|
261
|
-
if (!control?.node_id) throw new Error("Recruit action control is missing node_id");
|
|
262
|
-
const greetQuota = control.kind === "greet"
|
|
263
|
-
? assertGreetQuotaAvailable(control.greet_quota || control.label || "")
|
|
264
|
-
: null;
|
|
265
|
-
const box = await clickNodeCenter(client, control.node_id, {
|
|
266
|
-
scrollIntoView: true,
|
|
267
|
-
delayMs
|
|
268
|
-
});
|
|
269
|
-
return {
|
|
270
|
-
clicked: true,
|
|
271
|
-
kind: control.kind,
|
|
272
|
-
label: control.label,
|
|
273
|
-
greet_quota: greetQuota?.found ? greetQuota : null,
|
|
274
|
-
node_id: control.node_id,
|
|
275
|
-
box
|
|
276
|
-
};
|
|
277
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
clickNodeCenter,
|
|
3
|
+
getAttributesMap,
|
|
4
|
+
getNodeBox,
|
|
5
|
+
getOuterHTML,
|
|
6
|
+
querySelectorAll,
|
|
7
|
+
sleep
|
|
8
|
+
} from "../../core/browser/index.js";
|
|
9
|
+
import {
|
|
10
|
+
htmlToText,
|
|
11
|
+
normalizeText
|
|
12
|
+
} from "../../core/screening/index.js";
|
|
13
|
+
import {
|
|
14
|
+
assertGreetQuotaAvailable,
|
|
15
|
+
parseGreetQuota
|
|
16
|
+
} from "../../core/greet-quota/index.js";
|
|
17
|
+
|
|
18
|
+
const ACTION_SELECTOR = [
|
|
19
|
+
"button",
|
|
20
|
+
'[role="button"]',
|
|
21
|
+
".btn",
|
|
22
|
+
'[class*="btn"]',
|
|
23
|
+
'[class*="chat"]',
|
|
24
|
+
'[class*="greet"]',
|
|
25
|
+
'[ka*="chat"]',
|
|
26
|
+
'[ka*="greet"]',
|
|
27
|
+
'[ka*="contact"]'
|
|
28
|
+
].join(", ");
|
|
29
|
+
|
|
30
|
+
const DISABLED_PATTERN = /\b(disabled|disable|ui-disabled|is-disabled)\b/i;
|
|
31
|
+
const CONTINUE_CHAT_PATTERN = /继续沟通|继续聊天|查看沟通|已沟通/i;
|
|
32
|
+
const GREET_PATTERN = /打招呼|立即沟通|立即聊天|聊一聊|开聊|沟通/i;
|
|
33
|
+
const GREET_LABEL_PATTERN = /^(打招呼|立即沟通|立即聊天|聊一聊|开聊|沟通)(?:[\((]\d+\s*[//]\s*\d+[\))])?$/i;
|
|
34
|
+
const FAVORITE_PATTERN = /收藏|感兴趣/i;
|
|
35
|
+
const FAVORITE_LABEL_PATTERN = /^(收藏|感兴趣)$/i;
|
|
36
|
+
const OPEN_RESUME_KA_PATTERN = /search_click_open_resume|open_resume|resume/i;
|
|
37
|
+
const EXTERNAL_URL_PATTERN = /(?:https?:)?\/\/|github\.com|gitlab\.com|gitee\.com/i;
|
|
38
|
+
const MAX_ACTION_LABEL_LENGTH = 80;
|
|
39
|
+
|
|
40
|
+
function openingTagName(outerHTML = "") {
|
|
41
|
+
const match = String(outerHTML || "").match(/^<\s*([a-z0-9-]+)/i);
|
|
42
|
+
return match ? match[1].toLowerCase() : "";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function isButtonLike(attributes = {}, outerHTML = "") {
|
|
46
|
+
const tagName = openingTagName(outerHTML);
|
|
47
|
+
const className = normalizeText(attributes.class);
|
|
48
|
+
const role = normalizeText(attributes.role).toLowerCase();
|
|
49
|
+
const ka = normalizeText(attributes.ka || attributes["data-ka"]);
|
|
50
|
+
return tagName === "button"
|
|
51
|
+
|| role === "button"
|
|
52
|
+
|| /\bbtn\b|button|chat|greet/i.test(className)
|
|
53
|
+
|| /greet|chat|contact/i.test(ka);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isUnsafeLinkOrCard(attributes = {}, outerHTML = "") {
|
|
57
|
+
const tagName = openingTagName(outerHTML);
|
|
58
|
+
const href = normalizeText(attributes.href);
|
|
59
|
+
const ka = normalizeText(attributes.ka || attributes["data-ka"]);
|
|
60
|
+
const className = normalizeText(attributes.class);
|
|
61
|
+
const joined = [href, ka, className, String(outerHTML || "").slice(0, 500)].join(" ");
|
|
62
|
+
if (OPEN_RESUME_KA_PATTERN.test(ka)) return true;
|
|
63
|
+
if (tagName === "a" && href && !/^#|^javascript:/i.test(href)) return true;
|
|
64
|
+
if (EXTERNAL_URL_PATTERN.test(joined) && tagName === "a") return true;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function nodeIsDisabled(attributes = {}, outerHTML = "") {
|
|
69
|
+
const joined = [
|
|
70
|
+
attributes.class,
|
|
71
|
+
attributes.disabled,
|
|
72
|
+
attributes["aria-disabled"],
|
|
73
|
+
attributes["data-disabled"],
|
|
74
|
+
String(outerHTML || "").slice(0, 500)
|
|
75
|
+
].map(normalizeText).join(" ");
|
|
76
|
+
return DISABLED_PATTERN.test(joined)
|
|
77
|
+
|| attributes.disabled !== undefined
|
|
78
|
+
|| normalizeText(attributes["aria-disabled"]).toLowerCase() === "true";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function classifyRecruitAction({ text = "", attributes = {}, outerHTML = "" } = {}) {
|
|
82
|
+
if (isUnsafeLinkOrCard(attributes, outerHTML)) return null;
|
|
83
|
+
const joined = [
|
|
84
|
+
text,
|
|
85
|
+
attributes.class,
|
|
86
|
+
attributes.ka,
|
|
87
|
+
attributes["data-ka"],
|
|
88
|
+
attributes.title,
|
|
89
|
+
attributes["aria-label"]
|
|
90
|
+
].map(normalizeText).join(" ");
|
|
91
|
+
const label = normalizeText(text);
|
|
92
|
+
const buttonLike = isButtonLike(attributes, outerHTML);
|
|
93
|
+
const continueChat = CONTINUE_CHAT_PATTERN.test(joined);
|
|
94
|
+
const greetQuota = parseGreetQuota(label);
|
|
95
|
+
if (continueChat) {
|
|
96
|
+
return {
|
|
97
|
+
kind: "greet",
|
|
98
|
+
continue_chat: true,
|
|
99
|
+
available: false,
|
|
100
|
+
greet_quota: null
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (GREET_PATTERN.test(joined) && buttonLike && (label.length <= MAX_ACTION_LABEL_LENGTH || GREET_LABEL_PATTERN.test(label))) {
|
|
104
|
+
return {
|
|
105
|
+
kind: "greet",
|
|
106
|
+
continue_chat: false,
|
|
107
|
+
available: !nodeIsDisabled(attributes, outerHTML),
|
|
108
|
+
greet_quota: greetQuota.found ? greetQuota : null
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (FAVORITE_PATTERN.test(joined) && buttonLike && (label.length <= MAX_ACTION_LABEL_LENGTH || FAVORITE_LABEL_PATTERN.test(label))) {
|
|
112
|
+
return {
|
|
113
|
+
kind: "favorite",
|
|
114
|
+
continue_chat: false,
|
|
115
|
+
available: !nodeIsDisabled(attributes, outerHTML)
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function scoreRecruitAction(control) {
|
|
122
|
+
let score = 0;
|
|
123
|
+
if (control.kind === "greet") score += 100;
|
|
124
|
+
if (control.available) score += 20;
|
|
125
|
+
if (!control.continue_chat) score += 10;
|
|
126
|
+
if (/打招呼/.test(control.label)) score += 10;
|
|
127
|
+
if (/立即沟通|聊一聊|开聊/.test(control.label)) score += 6;
|
|
128
|
+
if (/btn|button/i.test(control.class_name)) score += 3;
|
|
129
|
+
return score;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function readRecruitActionControl(client, nodeId, {
|
|
133
|
+
selector = "",
|
|
134
|
+
index = 0
|
|
135
|
+
} = {}) {
|
|
136
|
+
let attributes;
|
|
137
|
+
let outerHTML;
|
|
138
|
+
try {
|
|
139
|
+
[attributes, outerHTML] = await Promise.all([
|
|
140
|
+
getAttributesMap(client, nodeId),
|
|
141
|
+
getOuterHTML(client, nodeId)
|
|
142
|
+
]);
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const text = normalizeText(htmlToText(outerHTML));
|
|
147
|
+
const classified = classifyRecruitAction({ text, attributes, outerHTML });
|
|
148
|
+
if (!classified) return null;
|
|
149
|
+
let box = null;
|
|
150
|
+
try {
|
|
151
|
+
box = await getNodeBox(client, nodeId);
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
if (!box?.rect || box.rect.width < 4 || box.rect.height < 4) return null;
|
|
156
|
+
const control = {
|
|
157
|
+
node_id: nodeId,
|
|
158
|
+
selector,
|
|
159
|
+
index,
|
|
160
|
+
kind: classified.kind,
|
|
161
|
+
label: text,
|
|
162
|
+
class_name: attributes.class || "",
|
|
163
|
+
attributes: {
|
|
164
|
+
ka: attributes.ka || attributes["data-ka"] || "",
|
|
165
|
+
href: attributes.href || "",
|
|
166
|
+
role: attributes.role || "",
|
|
167
|
+
title: attributes.title || "",
|
|
168
|
+
aria_label: attributes["aria-label"] || ""
|
|
169
|
+
},
|
|
170
|
+
tag_name: openingTagName(outerHTML),
|
|
171
|
+
disabled: nodeIsDisabled(attributes, outerHTML),
|
|
172
|
+
available: Boolean(classified.available),
|
|
173
|
+
continue_chat: Boolean(classified.continue_chat),
|
|
174
|
+
greet_quota: classified.greet_quota || null,
|
|
175
|
+
center: box.center,
|
|
176
|
+
rect: box.rect
|
|
177
|
+
};
|
|
178
|
+
control.score = scoreRecruitAction(control);
|
|
179
|
+
return control;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function discoverRecruitDetailActionControls(client, rootNodeIds = []) {
|
|
183
|
+
const controls = [];
|
|
184
|
+
const seen = new Set();
|
|
185
|
+
for (const rootNodeId of rootNodeIds.filter(Boolean)) {
|
|
186
|
+
let nodeIds = [];
|
|
187
|
+
try {
|
|
188
|
+
nodeIds = await querySelectorAll(client, rootNodeId, ACTION_SELECTOR);
|
|
189
|
+
} catch {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
for (let index = 0; index < nodeIds.length; index += 1) {
|
|
193
|
+
const nodeId = nodeIds[index];
|
|
194
|
+
if (!nodeId || seen.has(nodeId)) continue;
|
|
195
|
+
seen.add(nodeId);
|
|
196
|
+
const control = await readRecruitActionControl(client, nodeId, {
|
|
197
|
+
selector: ACTION_SELECTOR,
|
|
198
|
+
index
|
|
199
|
+
});
|
|
200
|
+
if (control) controls.push(control);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
controls.sort((left, right) => right.score - left.score);
|
|
204
|
+
return controls;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function summarizeRecruitActionControls(controls = []) {
|
|
208
|
+
const greetControls = controls.filter((control) => control.kind === "greet");
|
|
209
|
+
const favoriteControls = controls.filter((control) => control.kind === "favorite");
|
|
210
|
+
const actionableGreet = greetControls.find((control) => control.available && !control.continue_chat) || null;
|
|
211
|
+
const continueGreet = greetControls.find((control) => control.continue_chat) || null;
|
|
212
|
+
const actionableFavorite = favoriteControls.find((control) => control.available) || null;
|
|
213
|
+
return {
|
|
214
|
+
greet: {
|
|
215
|
+
found: Boolean(actionableGreet || continueGreet),
|
|
216
|
+
available: Boolean(actionableGreet),
|
|
217
|
+
continue_chat: Boolean(continueGreet && !actionableGreet),
|
|
218
|
+
greet_quota: actionableGreet?.greet_quota || continueGreet?.greet_quota || null,
|
|
219
|
+
control: actionableGreet || continueGreet
|
|
220
|
+
},
|
|
221
|
+
favorite: {
|
|
222
|
+
found: Boolean(actionableFavorite),
|
|
223
|
+
available: Boolean(actionableFavorite),
|
|
224
|
+
control: actionableFavorite
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export async function waitForRecruitDetailActionControls(client, {
|
|
230
|
+
rootNodeIds = [],
|
|
231
|
+
timeoutMs = 8000,
|
|
232
|
+
intervalMs = 400,
|
|
233
|
+
requireAny = false
|
|
234
|
+
} = {}) {
|
|
235
|
+
const started = Date.now();
|
|
236
|
+
let controls = [];
|
|
237
|
+
while (Date.now() - started <= timeoutMs) {
|
|
238
|
+
controls = await discoverRecruitDetailActionControls(client, rootNodeIds);
|
|
239
|
+
const summary = summarizeRecruitActionControls(controls);
|
|
240
|
+
if (!requireAny || summary.greet.found || summary.favorite.found) {
|
|
241
|
+
return {
|
|
242
|
+
ok: summary.greet.found || summary.favorite.found,
|
|
243
|
+
elapsed_ms: Date.now() - started,
|
|
244
|
+
controls,
|
|
245
|
+
summary
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
await sleep(intervalMs);
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
ok: false,
|
|
252
|
+
elapsed_ms: Date.now() - started,
|
|
253
|
+
controls,
|
|
254
|
+
summary: summarizeRecruitActionControls(controls)
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export async function clickRecruitActionControl(client, control, {
|
|
259
|
+
delayMs = 120
|
|
260
|
+
} = {}) {
|
|
261
|
+
if (!control?.node_id) throw new Error("Recruit action control is missing node_id");
|
|
262
|
+
const greetQuota = control.kind === "greet"
|
|
263
|
+
? assertGreetQuotaAvailable(control.greet_quota || control.label || "")
|
|
264
|
+
: null;
|
|
265
|
+
const box = await clickNodeCenter(client, control.node_id, {
|
|
266
|
+
scrollIntoView: true,
|
|
267
|
+
delayMs
|
|
268
|
+
});
|
|
269
|
+
return {
|
|
270
|
+
clicked: true,
|
|
271
|
+
kind: control.kind,
|
|
272
|
+
label: control.label,
|
|
273
|
+
greet_quota: greetQuota?.found ? greetQuota : null,
|
|
274
|
+
node_id: control.node_id,
|
|
275
|
+
box
|
|
276
|
+
};
|
|
277
|
+
}
|