@reconcrap/boss-recommend-mcp 2.0.47 → 2.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/bin/boss-recommend-mcp.js +4 -4
  2. package/config/screening-config.example.json +27 -27
  3. package/package.json +1 -1
  4. package/scripts/postinstall.cjs +44 -44
  5. package/skills/boss-chat/README.md +39 -39
  6. package/skills/boss-chat/SKILL.md +93 -93
  7. package/skills/boss-recommend-pipeline/README.md +12 -12
  8. package/skills/boss-recommend-pipeline/SKILL.md +180 -180
  9. package/skills/boss-recruit-pipeline/README.md +17 -17
  10. package/skills/boss-recruit-pipeline/SKILL.md +58 -58
  11. package/src/chat-mcp.js +1780 -1780
  12. package/src/chat-runtime-config.js +749 -749
  13. package/src/cli.js +3054 -3054
  14. package/src/core/boss-cards/index.js +199 -199
  15. package/src/core/browser/index.js +1586 -1453
  16. package/src/core/capture/index.js +1201 -1201
  17. package/src/core/cv-acquisition/index.js +238 -238
  18. package/src/core/cv-capture-target/index.js +299 -299
  19. package/src/core/greet-quota/index.js +54 -54
  20. package/src/core/infinite-list/index.js +1326 -1326
  21. package/src/core/reporting/legacy-csv.js +341 -341
  22. package/src/core/run/timing.js +33 -33
  23. package/src/core/self-heal/index.js +973 -973
  24. package/src/core/self-heal/viewport.js +564 -564
  25. package/src/domains/chat/cards.js +137 -137
  26. package/src/domains/chat/constants.js +221 -221
  27. package/src/domains/chat/detail.js +1668 -1668
  28. package/src/domains/chat/index.js +7 -7
  29. package/src/domains/chat/jobs.js +592 -592
  30. package/src/domains/chat/page-guard.js +98 -98
  31. package/src/domains/chat/roots.js +56 -56
  32. package/src/domains/chat/run-service.js +1977 -1977
  33. package/src/domains/recommend/actions.js +457 -457
  34. package/src/domains/recommend/cards.js +243 -243
  35. package/src/domains/recommend/constants.js +165 -165
  36. package/src/domains/recommend/detail.js +1 -1
  37. package/src/domains/recommend/filters.js +610 -610
  38. package/src/domains/recommend/index.js +10 -10
  39. package/src/domains/recommend/jobs.js +378 -316
  40. package/src/domains/recommend/refresh.js +491 -472
  41. package/src/domains/recommend/roots.js +80 -80
  42. package/src/domains/recommend/run-service.js +50 -29
  43. package/src/domains/recommend/scopes.js +246 -246
  44. package/src/domains/recruit/actions.js +277 -277
  45. package/src/domains/recruit/cards.js +74 -74
  46. package/src/domains/recruit/constants.js +167 -167
  47. package/src/domains/recruit/detail.js +461 -461
  48. package/src/domains/recruit/index.js +9 -9
  49. package/src/domains/recruit/instruction-parser.js +451 -451
  50. package/src/domains/recruit/refresh.js +44 -44
  51. package/src/domains/recruit/roots.js +68 -68
  52. package/src/domains/recruit/run-service.js +1207 -1207
  53. package/src/domains/recruit/search.js +1202 -1202
  54. package/src/recommend-mcp.js +22 -22
  55. package/src/recruit-mcp.js +1338 -1338
@@ -1,316 +1,378 @@
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
+ import { isStaleRecommendNodeError } from "./detail.js";
16
+
17
+ export const RECOMMEND_JOB_SELECTORS = Object.freeze({
18
+ trigger: ".job-selecter-wrap, [class*=\"job-selecter-wrap\"], .ui-dropmenu",
19
+ option: ".job-selecter-options .job-item, .job-list .job-item, .job-item",
20
+ current: ".job-selecter-options .job-item.curr, .job-list .job-item.curr, .job-item.curr"
21
+ });
22
+
23
+ function normalizeJobText(value) {
24
+ return normalizeText(value).replace(/\s+/g, "");
25
+ }
26
+
27
+ function stripSalaryText(label) {
28
+ return normalizeText(label)
29
+ .replace(/\s*[((]\s*(?:\d+(?:-\d+)?K|面议|\d+-\d+元\/天)\s*[))]\s*$/i, "")
30
+ .replace(/\s+(?:\d+(?:-\d+)?K|面议|\d+-\d+元\/天)\s*$/i, "")
31
+ .trim();
32
+ }
33
+
34
+ function trimSalarySuffix(label) {
35
+ return stripSalaryText(label);
36
+ }
37
+
38
+ export function jobLabelMatches(optionLabel, targetLabel) {
39
+ const option = normalizeJobText(optionLabel);
40
+ const target = normalizeJobText(targetLabel);
41
+ const optionWithoutSalary = normalizeJobText(stripSalaryText(optionLabel));
42
+ const targetWithoutSalary = normalizeJobText(stripSalaryText(targetLabel));
43
+ if (!option || !target) return false;
44
+ return option === target
45
+ || option.startsWith(target)
46
+ || optionWithoutSalary === target
47
+ || option === targetWithoutSalary
48
+ || optionWithoutSalary === targetWithoutSalary;
49
+ }
50
+
51
+ function isVisibleBox(box) {
52
+ return Boolean(box && box.rect.width > 4 && box.rect.height > 4);
53
+ }
54
+
55
+ async function readJobOption(client, nodeId, index) {
56
+ let attributes = null;
57
+ let outerHTML = "";
58
+ try {
59
+ [attributes, outerHTML] = await Promise.all([
60
+ getAttributesMap(client, nodeId),
61
+ getOuterHTML(client, nodeId)
62
+ ]);
63
+ } catch (error) {
64
+ if (isStaleRecommendNodeError(error)) {
65
+ return null;
66
+ }
67
+ throw error;
68
+ }
69
+ const label = normalizeText(htmlToText(outerHTML));
70
+ let box = null;
71
+ try {
72
+ box = await getNodeBox(client, nodeId);
73
+ } catch (error) {
74
+ if (!isStaleRecommendNodeError(error)) throw error;
75
+ }
76
+ const className = attributes.class || "";
77
+ return {
78
+ node_id: nodeId,
79
+ index,
80
+ label,
81
+ label_without_salary: trimSalarySuffix(label),
82
+ class_name: className,
83
+ current: /\bcurr\b|\bactive\b|\bselected\b/.test(className),
84
+ visible: isVisibleBox(box),
85
+ center: box?.center || null,
86
+ rect: box?.rect || null
87
+ };
88
+ }
89
+
90
+ async function readJobTrigger(client, nodeId) {
91
+ let box = null;
92
+ try {
93
+ box = await getNodeBox(client, nodeId);
94
+ } catch {}
95
+ if (!isVisibleBox(box)) return null;
96
+
97
+ let label = "";
98
+ let className = "";
99
+ try {
100
+ const outerHTML = await getOuterHTML(client, nodeId);
101
+ label = normalizeText(htmlToText(outerHTML));
102
+ } catch {}
103
+ try {
104
+ const attributes = await getAttributesMap(client, nodeId);
105
+ className = attributes.class || "";
106
+ } catch {}
107
+
108
+ return {
109
+ node_id: nodeId,
110
+ center: box.center,
111
+ rect: box.rect,
112
+ label,
113
+ label_without_salary: trimSalarySuffix(label),
114
+ class_name: className,
115
+ visible: true
116
+ };
117
+ }
118
+
119
+ export async function findRecommendJobTrigger(client, frameNodeId) {
120
+ const nodeIds = await querySelectorAll(client, frameNodeId, RECOMMEND_JOB_SELECTORS.trigger);
121
+ for (const nodeId of nodeIds) {
122
+ const trigger = await readJobTrigger(client, nodeId);
123
+ if (trigger) return trigger;
124
+ }
125
+ return null;
126
+ }
127
+
128
+ export async function waitForRecommendJobTrigger(client, frameNodeId, {
129
+ timeoutMs = 8000,
130
+ intervalMs = 250
131
+ } = {}) {
132
+ const started = Date.now();
133
+ while (Date.now() - started <= timeoutMs) {
134
+ const trigger = await findRecommendJobTrigger(client, frameNodeId);
135
+ if (trigger) return trigger;
136
+ await sleep(intervalMs);
137
+ }
138
+ return null;
139
+ }
140
+
141
+ export async function openRecommendJobDropdown(client, frameNodeId, {
142
+ timeoutMs = 4000,
143
+ triggerTimeoutMs = Math.max(8000, timeoutMs),
144
+ triggerIntervalMs = 250,
145
+ dismissBeforeOpen = true,
146
+ maxAttempts = 3
147
+ } = {}) {
148
+ const trigger = await waitForRecommendJobTrigger(client, frameNodeId, {
149
+ timeoutMs: triggerTimeoutMs,
150
+ intervalMs: triggerIntervalMs
151
+ });
152
+ if (!trigger) {
153
+ throw new Error("Recommend job trigger was not found");
154
+ }
155
+
156
+ const alreadyOpen = await waitForVisibleRecommendJobOptions(client, frameNodeId, {
157
+ timeoutMs: 300,
158
+ intervalMs: 100
159
+ });
160
+ if (alreadyOpen.visible_options.length) {
161
+ return {
162
+ opened: true,
163
+ already_open: true,
164
+ trigger,
165
+ options: alreadyOpen.options
166
+ };
167
+ }
168
+
169
+ const attempts = [];
170
+ const attemptLimit = Math.max(1, Math.floor(Number(maxAttempts) || 1));
171
+ if (dismissBeforeOpen) {
172
+ await closeRecommendJobDropdown(client);
173
+ }
174
+ for (let attempt = 1; attempt <= attemptLimit; attempt += 1) {
175
+ if (attempt > 1) await closeRecommendJobDropdown(client);
176
+ const triggerBox = await clickNodeCenter(client, trigger.node_id, DETERMINISTIC_CLICK_OPTIONS);
177
+ const opened = await waitForVisibleRecommendJobOptions(client, frameNodeId, {
178
+ timeoutMs,
179
+ intervalMs: 200
180
+ });
181
+ attempts.push({
182
+ attempt,
183
+ trigger_box: triggerBox,
184
+ option_count: opened.options.length,
185
+ visible_option_count: opened.visible_options.length
186
+ });
187
+ if (opened.visible_options.length) {
188
+ return {
189
+ opened: true,
190
+ already_open: false,
191
+ trigger,
192
+ options: opened.options,
193
+ attempts
194
+ };
195
+ }
196
+ }
197
+ const error = new Error("Recommend job dropdown did not expose visible options after trigger click");
198
+ error.trigger = trigger;
199
+ error.job_dropdown_attempts = attempts;
200
+ throw error;
201
+ }
202
+
203
+ async function waitForVisibleRecommendJobOptions(client, frameNodeId, {
204
+ timeoutMs = 4000,
205
+ intervalMs = 200
206
+ } = {}) {
207
+ const started = Date.now();
208
+ let lastOptions = [];
209
+ while (Date.now() - started <= timeoutMs) {
210
+ lastOptions = await listRecommendJobOptions(client, frameNodeId, { openDropdown: false });
211
+ const visibleOptions = lastOptions.filter((option) => option.visible);
212
+ if (visibleOptions.length) {
213
+ return {
214
+ options: lastOptions,
215
+ visible_options: visibleOptions
216
+ };
217
+ }
218
+ await sleep(intervalMs);
219
+ }
220
+ return {
221
+ options: lastOptions,
222
+ visible_options: []
223
+ };
224
+ }
225
+
226
+ export async function listRecommendJobOptions(client, frameNodeId, {
227
+ openDropdown = true
228
+ } = {}) {
229
+ if (openDropdown) {
230
+ await openRecommendJobDropdown(client, frameNodeId);
231
+ }
232
+
233
+ const nodeIds = await querySelectorAll(client, frameNodeId, RECOMMEND_JOB_SELECTORS.option);
234
+ const options = [];
235
+ const seen = new Set();
236
+ for (let index = 0; index < nodeIds.length; index += 1) {
237
+ const nodeId = nodeIds[index];
238
+ if (seen.has(nodeId)) continue;
239
+ seen.add(nodeId);
240
+ const option = await readJobOption(client, nodeId, index);
241
+ if (!option) continue;
242
+ if (!option.label) continue;
243
+ if (option.label.length > 120) continue;
244
+ options.push(option);
245
+ }
246
+ return options;
247
+ }
248
+
249
+ export async function closeRecommendJobDropdown(client) {
250
+ if (typeof client?.Input?.dispatchKeyEvent !== "function") {
251
+ return {
252
+ ok: false,
253
+ reason: "dispatch_key_unavailable"
254
+ };
255
+ }
256
+ await pressKey(client, "Escape", {
257
+ code: "Escape",
258
+ windowsVirtualKeyCode: 27,
259
+ nativeVirtualKeyCode: 27
260
+ });
261
+ await sleep(300);
262
+ return {
263
+ ok: true,
264
+ reason: "escape"
265
+ };
266
+ }
267
+
268
+ export async function selectRecommendJob(client, frameNodeId, {
269
+ jobLabel = "",
270
+ settleMs = 6000,
271
+ dropdownTimeoutMs = Math.max(8000, settleMs)
272
+ } = {}) {
273
+ const target = normalizeText(jobLabel);
274
+ if (!target) {
275
+ return {
276
+ requested: "",
277
+ selected: false,
278
+ reason: "no_job_requested",
279
+ options: []
280
+ };
281
+ }
282
+
283
+ let opened = null;
284
+ try {
285
+ opened = await openRecommendJobDropdown(client, frameNodeId, {
286
+ timeoutMs: dropdownTimeoutMs,
287
+ triggerTimeoutMs: dropdownTimeoutMs
288
+ });
289
+ } catch (error) {
290
+ const currentOptions = await listRecommendJobOptions(client, frameNodeId, {
291
+ openDropdown: false
292
+ }).catch(() => []);
293
+ const currentMatch = currentOptions.find((option) => (
294
+ option.current && jobLabelMatches(option.label, target)
295
+ ));
296
+ if (currentMatch) {
297
+ await closeRecommendJobDropdown(client);
298
+ return {
299
+ requested: target,
300
+ selected: true,
301
+ already_current: true,
302
+ selected_option: compactJobOption({
303
+ ...currentMatch,
304
+ source: "current_option_without_visible_dropdown"
305
+ }),
306
+ options: currentOptions.map(compactJobOption),
307
+ dropdown_error: error?.message || String(error),
308
+ job_dropdown_attempts: error?.job_dropdown_attempts || []
309
+ };
310
+ }
311
+ throw error;
312
+ }
313
+ const options = opened.options.length
314
+ ? opened.options
315
+ : await listRecommendJobOptions(client, frameNodeId, { openDropdown: false });
316
+ const visibleOptions = options.filter((option) => option.visible);
317
+ const hiddenMatches = options.filter((option) => !option.visible && jobLabelMatches(option.label, target));
318
+ const match = visibleOptions.find((option) => jobLabelMatches(option.label, target));
319
+
320
+ if (!match) {
321
+ await closeRecommendJobDropdown(client);
322
+ if (hiddenMatches.length) {
323
+ const error = new Error(`Matched recommend job has no visible clickable option: ${hiddenMatches[0].label}`);
324
+ error.hidden_job_matches = hiddenMatches.map(compactJobOption);
325
+ throw error;
326
+ }
327
+ return {
328
+ requested: target,
329
+ selected: false,
330
+ reason: "job_not_found",
331
+ options: options.map(compactJobOption)
332
+ };
333
+ }
334
+
335
+ if (match.current) {
336
+ await closeRecommendJobDropdown(client);
337
+ return {
338
+ requested: target,
339
+ selected: true,
340
+ already_current: true,
341
+ selected_option: compactJobOption(match),
342
+ options: options.map(compactJobOption)
343
+ };
344
+ }
345
+
346
+ if (!match.center) {
347
+ await closeRecommendJobDropdown(client);
348
+ throw new Error(`Matched recommend job has no clickable center: ${match.label}`);
349
+ }
350
+
351
+ const clickedBox = await clickNodeCenter(client, match.node_id, DETERMINISTIC_CLICK_OPTIONS);
352
+ if (settleMs > 0) await sleep(settleMs);
353
+ return {
354
+ requested: target,
355
+ selected: true,
356
+ already_current: false,
357
+ selected_option: compactJobOption(match),
358
+ click_box: {
359
+ center: clickedBox.center,
360
+ rect: clickedBox.rect
361
+ },
362
+ options: options.map(compactJobOption)
363
+ };
364
+ }
365
+
366
+ function compactJobOption(option) {
367
+ return {
368
+ label: option.label,
369
+ label_without_salary: option.label_without_salary,
370
+ current: Boolean(option.current),
371
+ visible: Boolean(option.visible),
372
+ class_name: option.class_name,
373
+ node_id: option.node_id,
374
+ center: option.center,
375
+ rect: option.rect,
376
+ source: option.source || null
377
+ };
378
+ }