@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,10 +1,10 @@
|
|
|
1
|
-
export * from "./constants.js";
|
|
2
|
-
export * from "./roots.js";
|
|
3
|
-
export * from "./filters.js";
|
|
4
|
-
export * from "./cards.js";
|
|
5
|
-
export * from "./detail.js";
|
|
6
|
-
export * from "./actions.js";
|
|
7
|
-
export * from "./jobs.js";
|
|
8
|
-
export * from "./scopes.js";
|
|
9
|
-
export * from "./refresh.js";
|
|
10
|
-
export * from "./run-service.js";
|
|
1
|
+
export * from "./constants.js";
|
|
2
|
+
export * from "./roots.js";
|
|
3
|
+
export * from "./filters.js";
|
|
4
|
+
export * from "./cards.js";
|
|
5
|
+
export * from "./detail.js";
|
|
6
|
+
export * from "./actions.js";
|
|
7
|
+
export * from "./jobs.js";
|
|
8
|
+
export * from "./scopes.js";
|
|
9
|
+
export * from "./refresh.js";
|
|
10
|
+
export * from "./run-service.js";
|
|
@@ -1,316 +1,316 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clickNodeCenter,
|
|
3
|
-
DETERMINISTIC_CLICK_OPTIONS,
|
|
4
|
-
getAttributesMap,
|
|
5
|
-
getNodeBox,
|
|
6
|
-
getOuterHTML,
|
|
7
|
-
pressKey,
|
|
8
|
-
querySelectorAll,
|
|
9
|
-
sleep
|
|
10
|
-
} from "../../core/browser/index.js";
|
|
11
|
-
import {
|
|
12
|
-
htmlToText,
|
|
13
|
-
normalizeText
|
|
14
|
-
} from "../../core/screening/index.js";
|
|
15
|
-
|
|
16
|
-
export const RECOMMEND_JOB_SELECTORS = Object.freeze({
|
|
17
|
-
trigger: ".job-selecter-wrap, [class*=\"job-selecter-wrap\"], .ui-dropmenu",
|
|
18
|
-
option: ".job-selecter-options .job-item, .job-list .job-item, .job-item",
|
|
19
|
-
current: ".job-selecter-options .job-item.curr, .job-list .job-item.curr, .job-item.curr"
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
function normalizeJobText(value) {
|
|
23
|
-
return normalizeText(value).replace(/\s+/g, "");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function stripSalaryText(label) {
|
|
27
|
-
return normalizeText(label)
|
|
28
|
-
.replace(/\s*[((]\s*(?:\d+(?:-\d+)?K|面议|\d+-\d+元\/天)\s*[))]\s*$/i, "")
|
|
29
|
-
.replace(/\s+(?:\d+(?:-\d+)?K|面议|\d+-\d+元\/天)\s*$/i, "")
|
|
30
|
-
.trim();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function trimSalarySuffix(label) {
|
|
34
|
-
return stripSalaryText(label);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function jobLabelMatches(optionLabel, targetLabel) {
|
|
38
|
-
const option = normalizeJobText(optionLabel);
|
|
39
|
-
const target = normalizeJobText(targetLabel);
|
|
40
|
-
const optionWithoutSalary = normalizeJobText(stripSalaryText(optionLabel));
|
|
41
|
-
const targetWithoutSalary = normalizeJobText(stripSalaryText(targetLabel));
|
|
42
|
-
if (!option || !target) return false;
|
|
43
|
-
return option === target
|
|
44
|
-
|| option.startsWith(target)
|
|
45
|
-
|| optionWithoutSalary === target
|
|
46
|
-
|| option === targetWithoutSalary
|
|
47
|
-
|| optionWithoutSalary === targetWithoutSalary;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function isVisibleBox(box) {
|
|
51
|
-
return Boolean(box && box.rect.width > 4 && box.rect.height > 4);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function readJobOption(client, nodeId, index) {
|
|
55
|
-
const [attributes, outerHTML] = await Promise.all([
|
|
56
|
-
getAttributesMap(client, nodeId),
|
|
57
|
-
getOuterHTML(client, nodeId)
|
|
58
|
-
]);
|
|
59
|
-
const label = normalizeText(htmlToText(outerHTML));
|
|
60
|
-
let box = null;
|
|
61
|
-
try {
|
|
62
|
-
box = await getNodeBox(client, nodeId);
|
|
63
|
-
} catch {}
|
|
64
|
-
const className = attributes.class || "";
|
|
65
|
-
return {
|
|
66
|
-
node_id: nodeId,
|
|
67
|
-
index,
|
|
68
|
-
label,
|
|
69
|
-
label_without_salary: trimSalarySuffix(label),
|
|
70
|
-
class_name: className,
|
|
71
|
-
current: /\bcurr\b|\bactive\b|\bselected\b/.test(className),
|
|
72
|
-
visible: isVisibleBox(box),
|
|
73
|
-
center: box?.center || null,
|
|
74
|
-
rect: box?.rect || null
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function findRecommendJobTrigger(client, frameNodeId) {
|
|
79
|
-
const nodeIds = await querySelectorAll(client, frameNodeId, RECOMMEND_JOB_SELECTORS.trigger);
|
|
80
|
-
for (const nodeId of nodeIds) {
|
|
81
|
-
try {
|
|
82
|
-
const box = await getNodeBox(client, nodeId);
|
|
83
|
-
if (isVisibleBox(box)) {
|
|
84
|
-
return {
|
|
85
|
-
node_id: nodeId,
|
|
86
|
-
center: box.center,
|
|
87
|
-
rect: box.rect
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
} catch {}
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export async function waitForRecommendJobTrigger(client, frameNodeId, {
|
|
96
|
-
timeoutMs = 8000,
|
|
97
|
-
intervalMs = 250
|
|
98
|
-
} = {}) {
|
|
99
|
-
const started = Date.now();
|
|
100
|
-
while (Date.now() - started <= timeoutMs) {
|
|
101
|
-
const trigger = await findRecommendJobTrigger(client, frameNodeId);
|
|
102
|
-
if (trigger) return trigger;
|
|
103
|
-
await sleep(intervalMs);
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function openRecommendJobDropdown(client, frameNodeId, {
|
|
109
|
-
timeoutMs = 4000,
|
|
110
|
-
triggerTimeoutMs = Math.max(8000, timeoutMs),
|
|
111
|
-
triggerIntervalMs = 250,
|
|
112
|
-
dismissBeforeOpen = true,
|
|
113
|
-
maxAttempts = 3
|
|
114
|
-
} = {}) {
|
|
115
|
-
const trigger = await waitForRecommendJobTrigger(client, frameNodeId, {
|
|
116
|
-
timeoutMs: triggerTimeoutMs,
|
|
117
|
-
intervalMs: triggerIntervalMs
|
|
118
|
-
});
|
|
119
|
-
if (!trigger) {
|
|
120
|
-
throw new Error("Recommend job trigger was not found");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const alreadyOpen = await waitForVisibleRecommendJobOptions(client, frameNodeId, {
|
|
124
|
-
timeoutMs: 300,
|
|
125
|
-
intervalMs: 100
|
|
126
|
-
});
|
|
127
|
-
if (alreadyOpen.visible_options.length) {
|
|
128
|
-
return {
|
|
129
|
-
opened: true,
|
|
130
|
-
already_open: true,
|
|
131
|
-
trigger,
|
|
132
|
-
options: alreadyOpen.options
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const attempts = [];
|
|
137
|
-
const attemptLimit = Math.max(1, Math.floor(Number(maxAttempts) || 1));
|
|
138
|
-
if (dismissBeforeOpen) {
|
|
139
|
-
await closeRecommendJobDropdown(client);
|
|
140
|
-
}
|
|
141
|
-
for (let attempt = 1; attempt <= attemptLimit; attempt += 1) {
|
|
142
|
-
if (attempt > 1) await closeRecommendJobDropdown(client);
|
|
143
|
-
const triggerBox = await clickNodeCenter(client, trigger.node_id, DETERMINISTIC_CLICK_OPTIONS);
|
|
144
|
-
const opened = await waitForVisibleRecommendJobOptions(client, frameNodeId, {
|
|
145
|
-
timeoutMs,
|
|
146
|
-
intervalMs: 200
|
|
147
|
-
});
|
|
148
|
-
attempts.push({
|
|
149
|
-
attempt,
|
|
150
|
-
trigger_box: triggerBox,
|
|
151
|
-
option_count: opened.options.length,
|
|
152
|
-
visible_option_count: opened.visible_options.length
|
|
153
|
-
});
|
|
154
|
-
if (opened.visible_options.length) {
|
|
155
|
-
return {
|
|
156
|
-
opened: true,
|
|
157
|
-
already_open: false,
|
|
158
|
-
trigger,
|
|
159
|
-
options: opened.options,
|
|
160
|
-
attempts
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const error = new Error("Recommend job dropdown did not expose visible options after trigger click");
|
|
165
|
-
error.job_dropdown_attempts = attempts;
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async function waitForVisibleRecommendJobOptions(client, frameNodeId, {
|
|
170
|
-
timeoutMs = 4000,
|
|
171
|
-
intervalMs = 200
|
|
172
|
-
} = {}) {
|
|
173
|
-
const started = Date.now();
|
|
174
|
-
let lastOptions = [];
|
|
175
|
-
while (Date.now() - started <= timeoutMs) {
|
|
176
|
-
lastOptions = await listRecommendJobOptions(client, frameNodeId, { openDropdown: false });
|
|
177
|
-
const visibleOptions = lastOptions.filter((option) => option.visible);
|
|
178
|
-
if (visibleOptions.length) {
|
|
179
|
-
return {
|
|
180
|
-
options: lastOptions,
|
|
181
|
-
visible_options: visibleOptions
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
await sleep(intervalMs);
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
options: lastOptions,
|
|
188
|
-
visible_options: []
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export async function listRecommendJobOptions(client, frameNodeId, {
|
|
193
|
-
openDropdown = true
|
|
194
|
-
} = {}) {
|
|
195
|
-
if (openDropdown) {
|
|
196
|
-
await openRecommendJobDropdown(client, frameNodeId);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const nodeIds = await querySelectorAll(client, frameNodeId, RECOMMEND_JOB_SELECTORS.option);
|
|
200
|
-
const options = [];
|
|
201
|
-
const seen = new Set();
|
|
202
|
-
for (let index = 0; index < nodeIds.length; index += 1) {
|
|
203
|
-
const nodeId = nodeIds[index];
|
|
204
|
-
if (seen.has(nodeId)) continue;
|
|
205
|
-
seen.add(nodeId);
|
|
206
|
-
const option = await readJobOption(client, nodeId, index);
|
|
207
|
-
if (!option.label) continue;
|
|
208
|
-
if (option.label.length > 120) continue;
|
|
209
|
-
options.push(option);
|
|
210
|
-
}
|
|
211
|
-
return options;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export async function closeRecommendJobDropdown(client) {
|
|
215
|
-
if (typeof client?.Input?.dispatchKeyEvent !== "function") {
|
|
216
|
-
return {
|
|
217
|
-
ok: false,
|
|
218
|
-
reason: "dispatch_key_unavailable"
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
await pressKey(client, "Escape", {
|
|
222
|
-
code: "Escape",
|
|
223
|
-
windowsVirtualKeyCode: 27,
|
|
224
|
-
nativeVirtualKeyCode: 27
|
|
225
|
-
});
|
|
226
|
-
await sleep(300);
|
|
227
|
-
return {
|
|
228
|
-
ok: true,
|
|
229
|
-
reason: "escape"
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export async function selectRecommendJob(client, frameNodeId, {
|
|
234
|
-
jobLabel = "",
|
|
235
|
-
settleMs = 6000,
|
|
236
|
-
dropdownTimeoutMs = Math.max(8000, settleMs)
|
|
237
|
-
} = {}) {
|
|
238
|
-
const target = normalizeText(jobLabel);
|
|
239
|
-
if (!target) {
|
|
240
|
-
return {
|
|
241
|
-
requested: "",
|
|
242
|
-
selected: false,
|
|
243
|
-
reason: "no_job_requested",
|
|
244
|
-
options: []
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const opened = await openRecommendJobDropdown(client, frameNodeId, {
|
|
249
|
-
timeoutMs: dropdownTimeoutMs,
|
|
250
|
-
triggerTimeoutMs: dropdownTimeoutMs
|
|
251
|
-
});
|
|
252
|
-
const options = opened.options.length
|
|
253
|
-
? opened.options
|
|
254
|
-
: await listRecommendJobOptions(client, frameNodeId, { openDropdown: false });
|
|
255
|
-
const visibleOptions = options.filter((option) => option.visible);
|
|
256
|
-
const hiddenMatches = options.filter((option) => !option.visible && jobLabelMatches(option.label, target));
|
|
257
|
-
const match = visibleOptions.find((option) => jobLabelMatches(option.label, target));
|
|
258
|
-
|
|
259
|
-
if (!match) {
|
|
260
|
-
await closeRecommendJobDropdown(client);
|
|
261
|
-
if (hiddenMatches.length) {
|
|
262
|
-
const error = new Error(`Matched recommend job has no visible clickable option: ${hiddenMatches[0].label}`);
|
|
263
|
-
error.hidden_job_matches = hiddenMatches.map(compactJobOption);
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
return {
|
|
267
|
-
requested: target,
|
|
268
|
-
selected: false,
|
|
269
|
-
reason: "job_not_found",
|
|
270
|
-
options: options.map(compactJobOption)
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if (match.current) {
|
|
275
|
-
await closeRecommendJobDropdown(client);
|
|
276
|
-
return {
|
|
277
|
-
requested: target,
|
|
278
|
-
selected: true,
|
|
279
|
-
already_current: true,
|
|
280
|
-
selected_option: compactJobOption(match),
|
|
281
|
-
options: options.map(compactJobOption)
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (!match.center) {
|
|
286
|
-
await closeRecommendJobDropdown(client);
|
|
287
|
-
throw new Error(`Matched recommend job has no clickable center: ${match.label}`);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const clickedBox = await clickNodeCenter(client, match.node_id, DETERMINISTIC_CLICK_OPTIONS);
|
|
291
|
-
if (settleMs > 0) await sleep(settleMs);
|
|
292
|
-
return {
|
|
293
|
-
requested: target,
|
|
294
|
-
selected: true,
|
|
295
|
-
already_current: false,
|
|
296
|
-
selected_option: compactJobOption(match),
|
|
297
|
-
click_box: {
|
|
298
|
-
center: clickedBox.center,
|
|
299
|
-
rect: clickedBox.rect
|
|
300
|
-
},
|
|
301
|
-
options: options.map(compactJobOption)
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function compactJobOption(option) {
|
|
306
|
-
return {
|
|
307
|
-
label: option.label,
|
|
308
|
-
label_without_salary: option.label_without_salary,
|
|
309
|
-
current: Boolean(option.current),
|
|
310
|
-
visible: Boolean(option.visible),
|
|
311
|
-
class_name: option.class_name,
|
|
312
|
-
node_id: option.node_id,
|
|
313
|
-
center: option.center,
|
|
314
|
-
rect: option.rect
|
|
315
|
-
};
|
|
316
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
clickNodeCenter,
|
|
3
|
+
DETERMINISTIC_CLICK_OPTIONS,
|
|
4
|
+
getAttributesMap,
|
|
5
|
+
getNodeBox,
|
|
6
|
+
getOuterHTML,
|
|
7
|
+
pressKey,
|
|
8
|
+
querySelectorAll,
|
|
9
|
+
sleep
|
|
10
|
+
} from "../../core/browser/index.js";
|
|
11
|
+
import {
|
|
12
|
+
htmlToText,
|
|
13
|
+
normalizeText
|
|
14
|
+
} from "../../core/screening/index.js";
|
|
15
|
+
|
|
16
|
+
export const RECOMMEND_JOB_SELECTORS = Object.freeze({
|
|
17
|
+
trigger: ".job-selecter-wrap, [class*=\"job-selecter-wrap\"], .ui-dropmenu",
|
|
18
|
+
option: ".job-selecter-options .job-item, .job-list .job-item, .job-item",
|
|
19
|
+
current: ".job-selecter-options .job-item.curr, .job-list .job-item.curr, .job-item.curr"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function normalizeJobText(value) {
|
|
23
|
+
return normalizeText(value).replace(/\s+/g, "");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function stripSalaryText(label) {
|
|
27
|
+
return normalizeText(label)
|
|
28
|
+
.replace(/\s*[((]\s*(?:\d+(?:-\d+)?K|面议|\d+-\d+元\/天)\s*[))]\s*$/i, "")
|
|
29
|
+
.replace(/\s+(?:\d+(?:-\d+)?K|面议|\d+-\d+元\/天)\s*$/i, "")
|
|
30
|
+
.trim();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function trimSalarySuffix(label) {
|
|
34
|
+
return stripSalaryText(label);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function jobLabelMatches(optionLabel, targetLabel) {
|
|
38
|
+
const option = normalizeJobText(optionLabel);
|
|
39
|
+
const target = normalizeJobText(targetLabel);
|
|
40
|
+
const optionWithoutSalary = normalizeJobText(stripSalaryText(optionLabel));
|
|
41
|
+
const targetWithoutSalary = normalizeJobText(stripSalaryText(targetLabel));
|
|
42
|
+
if (!option || !target) return false;
|
|
43
|
+
return option === target
|
|
44
|
+
|| option.startsWith(target)
|
|
45
|
+
|| optionWithoutSalary === target
|
|
46
|
+
|| option === targetWithoutSalary
|
|
47
|
+
|| optionWithoutSalary === targetWithoutSalary;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isVisibleBox(box) {
|
|
51
|
+
return Boolean(box && box.rect.width > 4 && box.rect.height > 4);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function readJobOption(client, nodeId, index) {
|
|
55
|
+
const [attributes, outerHTML] = await Promise.all([
|
|
56
|
+
getAttributesMap(client, nodeId),
|
|
57
|
+
getOuterHTML(client, nodeId)
|
|
58
|
+
]);
|
|
59
|
+
const label = normalizeText(htmlToText(outerHTML));
|
|
60
|
+
let box = null;
|
|
61
|
+
try {
|
|
62
|
+
box = await getNodeBox(client, nodeId);
|
|
63
|
+
} catch {}
|
|
64
|
+
const className = attributes.class || "";
|
|
65
|
+
return {
|
|
66
|
+
node_id: nodeId,
|
|
67
|
+
index,
|
|
68
|
+
label,
|
|
69
|
+
label_without_salary: trimSalarySuffix(label),
|
|
70
|
+
class_name: className,
|
|
71
|
+
current: /\bcurr\b|\bactive\b|\bselected\b/.test(className),
|
|
72
|
+
visible: isVisibleBox(box),
|
|
73
|
+
center: box?.center || null,
|
|
74
|
+
rect: box?.rect || null
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function findRecommendJobTrigger(client, frameNodeId) {
|
|
79
|
+
const nodeIds = await querySelectorAll(client, frameNodeId, RECOMMEND_JOB_SELECTORS.trigger);
|
|
80
|
+
for (const nodeId of nodeIds) {
|
|
81
|
+
try {
|
|
82
|
+
const box = await getNodeBox(client, nodeId);
|
|
83
|
+
if (isVisibleBox(box)) {
|
|
84
|
+
return {
|
|
85
|
+
node_id: nodeId,
|
|
86
|
+
center: box.center,
|
|
87
|
+
rect: box.rect
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
} catch {}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function waitForRecommendJobTrigger(client, frameNodeId, {
|
|
96
|
+
timeoutMs = 8000,
|
|
97
|
+
intervalMs = 250
|
|
98
|
+
} = {}) {
|
|
99
|
+
const started = Date.now();
|
|
100
|
+
while (Date.now() - started <= timeoutMs) {
|
|
101
|
+
const trigger = await findRecommendJobTrigger(client, frameNodeId);
|
|
102
|
+
if (trigger) return trigger;
|
|
103
|
+
await sleep(intervalMs);
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function openRecommendJobDropdown(client, frameNodeId, {
|
|
109
|
+
timeoutMs = 4000,
|
|
110
|
+
triggerTimeoutMs = Math.max(8000, timeoutMs),
|
|
111
|
+
triggerIntervalMs = 250,
|
|
112
|
+
dismissBeforeOpen = true,
|
|
113
|
+
maxAttempts = 3
|
|
114
|
+
} = {}) {
|
|
115
|
+
const trigger = await waitForRecommendJobTrigger(client, frameNodeId, {
|
|
116
|
+
timeoutMs: triggerTimeoutMs,
|
|
117
|
+
intervalMs: triggerIntervalMs
|
|
118
|
+
});
|
|
119
|
+
if (!trigger) {
|
|
120
|
+
throw new Error("Recommend job trigger was not found");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const alreadyOpen = await waitForVisibleRecommendJobOptions(client, frameNodeId, {
|
|
124
|
+
timeoutMs: 300,
|
|
125
|
+
intervalMs: 100
|
|
126
|
+
});
|
|
127
|
+
if (alreadyOpen.visible_options.length) {
|
|
128
|
+
return {
|
|
129
|
+
opened: true,
|
|
130
|
+
already_open: true,
|
|
131
|
+
trigger,
|
|
132
|
+
options: alreadyOpen.options
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const attempts = [];
|
|
137
|
+
const attemptLimit = Math.max(1, Math.floor(Number(maxAttempts) || 1));
|
|
138
|
+
if (dismissBeforeOpen) {
|
|
139
|
+
await closeRecommendJobDropdown(client);
|
|
140
|
+
}
|
|
141
|
+
for (let attempt = 1; attempt <= attemptLimit; attempt += 1) {
|
|
142
|
+
if (attempt > 1) await closeRecommendJobDropdown(client);
|
|
143
|
+
const triggerBox = await clickNodeCenter(client, trigger.node_id, DETERMINISTIC_CLICK_OPTIONS);
|
|
144
|
+
const opened = await waitForVisibleRecommendJobOptions(client, frameNodeId, {
|
|
145
|
+
timeoutMs,
|
|
146
|
+
intervalMs: 200
|
|
147
|
+
});
|
|
148
|
+
attempts.push({
|
|
149
|
+
attempt,
|
|
150
|
+
trigger_box: triggerBox,
|
|
151
|
+
option_count: opened.options.length,
|
|
152
|
+
visible_option_count: opened.visible_options.length
|
|
153
|
+
});
|
|
154
|
+
if (opened.visible_options.length) {
|
|
155
|
+
return {
|
|
156
|
+
opened: true,
|
|
157
|
+
already_open: false,
|
|
158
|
+
trigger,
|
|
159
|
+
options: opened.options,
|
|
160
|
+
attempts
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const error = new Error("Recommend job dropdown did not expose visible options after trigger click");
|
|
165
|
+
error.job_dropdown_attempts = attempts;
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function waitForVisibleRecommendJobOptions(client, frameNodeId, {
|
|
170
|
+
timeoutMs = 4000,
|
|
171
|
+
intervalMs = 200
|
|
172
|
+
} = {}) {
|
|
173
|
+
const started = Date.now();
|
|
174
|
+
let lastOptions = [];
|
|
175
|
+
while (Date.now() - started <= timeoutMs) {
|
|
176
|
+
lastOptions = await listRecommendJobOptions(client, frameNodeId, { openDropdown: false });
|
|
177
|
+
const visibleOptions = lastOptions.filter((option) => option.visible);
|
|
178
|
+
if (visibleOptions.length) {
|
|
179
|
+
return {
|
|
180
|
+
options: lastOptions,
|
|
181
|
+
visible_options: visibleOptions
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
await sleep(intervalMs);
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
options: lastOptions,
|
|
188
|
+
visible_options: []
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export async function listRecommendJobOptions(client, frameNodeId, {
|
|
193
|
+
openDropdown = true
|
|
194
|
+
} = {}) {
|
|
195
|
+
if (openDropdown) {
|
|
196
|
+
await openRecommendJobDropdown(client, frameNodeId);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const nodeIds = await querySelectorAll(client, frameNodeId, RECOMMEND_JOB_SELECTORS.option);
|
|
200
|
+
const options = [];
|
|
201
|
+
const seen = new Set();
|
|
202
|
+
for (let index = 0; index < nodeIds.length; index += 1) {
|
|
203
|
+
const nodeId = nodeIds[index];
|
|
204
|
+
if (seen.has(nodeId)) continue;
|
|
205
|
+
seen.add(nodeId);
|
|
206
|
+
const option = await readJobOption(client, nodeId, index);
|
|
207
|
+
if (!option.label) continue;
|
|
208
|
+
if (option.label.length > 120) continue;
|
|
209
|
+
options.push(option);
|
|
210
|
+
}
|
|
211
|
+
return options;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function closeRecommendJobDropdown(client) {
|
|
215
|
+
if (typeof client?.Input?.dispatchKeyEvent !== "function") {
|
|
216
|
+
return {
|
|
217
|
+
ok: false,
|
|
218
|
+
reason: "dispatch_key_unavailable"
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
await pressKey(client, "Escape", {
|
|
222
|
+
code: "Escape",
|
|
223
|
+
windowsVirtualKeyCode: 27,
|
|
224
|
+
nativeVirtualKeyCode: 27
|
|
225
|
+
});
|
|
226
|
+
await sleep(300);
|
|
227
|
+
return {
|
|
228
|
+
ok: true,
|
|
229
|
+
reason: "escape"
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export async function selectRecommendJob(client, frameNodeId, {
|
|
234
|
+
jobLabel = "",
|
|
235
|
+
settleMs = 6000,
|
|
236
|
+
dropdownTimeoutMs = Math.max(8000, settleMs)
|
|
237
|
+
} = {}) {
|
|
238
|
+
const target = normalizeText(jobLabel);
|
|
239
|
+
if (!target) {
|
|
240
|
+
return {
|
|
241
|
+
requested: "",
|
|
242
|
+
selected: false,
|
|
243
|
+
reason: "no_job_requested",
|
|
244
|
+
options: []
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const opened = await openRecommendJobDropdown(client, frameNodeId, {
|
|
249
|
+
timeoutMs: dropdownTimeoutMs,
|
|
250
|
+
triggerTimeoutMs: dropdownTimeoutMs
|
|
251
|
+
});
|
|
252
|
+
const options = opened.options.length
|
|
253
|
+
? opened.options
|
|
254
|
+
: await listRecommendJobOptions(client, frameNodeId, { openDropdown: false });
|
|
255
|
+
const visibleOptions = options.filter((option) => option.visible);
|
|
256
|
+
const hiddenMatches = options.filter((option) => !option.visible && jobLabelMatches(option.label, target));
|
|
257
|
+
const match = visibleOptions.find((option) => jobLabelMatches(option.label, target));
|
|
258
|
+
|
|
259
|
+
if (!match) {
|
|
260
|
+
await closeRecommendJobDropdown(client);
|
|
261
|
+
if (hiddenMatches.length) {
|
|
262
|
+
const error = new Error(`Matched recommend job has no visible clickable option: ${hiddenMatches[0].label}`);
|
|
263
|
+
error.hidden_job_matches = hiddenMatches.map(compactJobOption);
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
requested: target,
|
|
268
|
+
selected: false,
|
|
269
|
+
reason: "job_not_found",
|
|
270
|
+
options: options.map(compactJobOption)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (match.current) {
|
|
275
|
+
await closeRecommendJobDropdown(client);
|
|
276
|
+
return {
|
|
277
|
+
requested: target,
|
|
278
|
+
selected: true,
|
|
279
|
+
already_current: true,
|
|
280
|
+
selected_option: compactJobOption(match),
|
|
281
|
+
options: options.map(compactJobOption)
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (!match.center) {
|
|
286
|
+
await closeRecommendJobDropdown(client);
|
|
287
|
+
throw new Error(`Matched recommend job has no clickable center: ${match.label}`);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const clickedBox = await clickNodeCenter(client, match.node_id, DETERMINISTIC_CLICK_OPTIONS);
|
|
291
|
+
if (settleMs > 0) await sleep(settleMs);
|
|
292
|
+
return {
|
|
293
|
+
requested: target,
|
|
294
|
+
selected: true,
|
|
295
|
+
already_current: false,
|
|
296
|
+
selected_option: compactJobOption(match),
|
|
297
|
+
click_box: {
|
|
298
|
+
center: clickedBox.center,
|
|
299
|
+
rect: clickedBox.rect
|
|
300
|
+
},
|
|
301
|
+
options: options.map(compactJobOption)
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function compactJobOption(option) {
|
|
306
|
+
return {
|
|
307
|
+
label: option.label,
|
|
308
|
+
label_without_salary: option.label_without_salary,
|
|
309
|
+
current: Boolean(option.current),
|
|
310
|
+
visible: Boolean(option.visible),
|
|
311
|
+
class_name: option.class_name,
|
|
312
|
+
node_id: option.node_id,
|
|
313
|
+
center: option.center,
|
|
314
|
+
rect: option.rect
|
|
315
|
+
};
|
|
316
|
+
}
|