@reconcrap/boss-recommend-mcp 1.3.38 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -33
- package/package.json +61 -9
- package/skills/boss-recommend-pipeline/SKILL.md +4 -0
- package/src/chat-mcp.js +1333 -0
- package/src/chat-runtime-config.js +559 -0
- package/src/cli.js +1095 -196
- package/src/core/browser/index.js +378 -0
- package/src/core/capture/index.js +298 -0
- package/src/core/cv-acquisition/index.js +219 -0
- package/src/core/greet-quota/index.js +54 -0
- package/src/core/infinite-list/index.js +459 -0
- package/src/core/reporting/legacy-csv.js +332 -0
- package/src/core/run/index.js +286 -0
- package/src/core/screening/index.js +1166 -0
- package/src/core/self-heal/index.js +848 -0
- package/src/domains/chat/cards.js +129 -0
- package/src/domains/chat/constants.js +183 -0
- package/src/domains/chat/detail.js +1369 -0
- package/src/domains/chat/index.js +7 -0
- package/src/domains/chat/jobs.js +334 -0
- package/src/domains/chat/page-guard.js +88 -0
- package/src/domains/chat/roots.js +56 -0
- package/src/domains/chat/run-service.js +1101 -0
- package/src/domains/recommend/actions.js +457 -0
- package/src/domains/recommend/cards.js +228 -0
- package/src/domains/recommend/constants.js +141 -0
- package/src/domains/recommend/detail.js +341 -0
- package/src/domains/recommend/filters.js +581 -0
- package/src/domains/recommend/index.js +10 -0
- package/src/domains/recommend/jobs.js +232 -0
- package/src/domains/recommend/refresh.js +204 -0
- package/src/domains/recommend/roots.js +78 -0
- package/src/domains/recommend/run-service.js +903 -0
- package/src/domains/recommend/scopes.js +245 -0
- package/src/domains/recruit/actions.js +277 -0
- package/src/domains/recruit/cards.js +67 -0
- package/src/domains/recruit/constants.js +130 -0
- package/src/domains/recruit/detail.js +414 -0
- package/src/domains/recruit/index.js +9 -0
- package/src/domains/recruit/instruction-parser.js +451 -0
- package/src/domains/recruit/refresh.js +40 -0
- package/src/domains/recruit/roots.js +68 -0
- package/src/domains/recruit/run-service.js +580 -0
- package/src/domains/recruit/search.js +1149 -0
- package/src/index.js +578 -419
- package/src/recommend-mcp.js +1257 -0
- package/src/recruit-mcp.js +1035 -0
- package/src/adapters.js +0 -3079
- package/src/boss-chat.js +0 -1037
- package/src/pipeline.js +0 -2249
- package/src/recommend-healing-config.js +0 -131
- package/src/recommend-healing-rules.json +0 -261
- package/src/self-heal.js +0 -2237
- package/src/test-adapters-runtime.js +0 -628
- package/src/test-boss-chat.js +0 -3196
- package/src/test-index-async.js +0 -498
- package/src/test-parser.js +0 -742
- package/src/test-pipeline.js +0 -2703
- package/src/test-run-state.js +0 -152
- package/src/test-self-heal.js +0 -224
- package/vendor/boss-chat-cli/README.md +0 -134
- package/vendor/boss-chat-cli/package.json +0 -53
- package/vendor/boss-chat-cli/src/app.js +0 -1501
- package/vendor/boss-chat-cli/src/browser/chat-page.js +0 -3562
- package/vendor/boss-chat-cli/src/cli.js +0 -1713
- package/vendor/boss-chat-cli/src/mcp/server.js +0 -149
- package/vendor/boss-chat-cli/src/mcp/tool-runtime.js +0 -193
- package/vendor/boss-chat-cli/src/runtime/async-run-state.js +0 -260
- package/vendor/boss-chat-cli/src/runtime/interaction.js +0 -102
- package/vendor/boss-chat-cli/src/runtime/run-control.js +0 -102
- package/vendor/boss-chat-cli/src/services/chrome-client.js +0 -107
- package/vendor/boss-chat-cli/src/services/llm.js +0 -1292
- package/vendor/boss-chat-cli/src/services/llm.test.js +0 -326
- package/vendor/boss-chat-cli/src/services/profile-store.js +0 -173
- package/vendor/boss-chat-cli/src/services/report-store.js +0 -317
- package/vendor/boss-chat-cli/src/services/resume-capture.js +0 -469
- package/vendor/boss-chat-cli/src/services/resume-network.js +0 -727
- package/vendor/boss-chat-cli/src/services/state-store.js +0 -90
- package/vendor/boss-chat-cli/src/utils/customer-key.js +0 -82
- package/vendor/boss-recommend-screen-cli/boss-recommend-screen-cli.cjs +0 -6927
- package/vendor/boss-recommend-screen-cli/scripts/capture-full-resume-canvas.cjs +0 -817
- package/vendor/boss-recommend-screen-cli/scripts/stitch_resume_chunks.py +0 -141
- package/vendor/boss-recommend-screen-cli/test-recoverable-resume-failures.cjs +0 -2294
- package/vendor/boss-recommend-search-cli/src/cli.js +0 -1698
- package/vendor/boss-recommend-search-cli/src/test-job-selection.js +0 -211
|
@@ -0,0 +1,245 @@
|
|
|
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
|
+
RECOMMEND_CARD_SELECTOR,
|
|
15
|
+
RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
16
|
+
RECOMMEND_PAGE_SCOPE_LABELS,
|
|
17
|
+
RECOMMEND_PAGE_SCOPE_STATUS,
|
|
18
|
+
RECOMMEND_PAGE_SCOPE_TAB_SELECTOR
|
|
19
|
+
} from "./constants.js";
|
|
20
|
+
|
|
21
|
+
const SCOPE_ALIASES = Object.freeze({
|
|
22
|
+
recommend: "recommend",
|
|
23
|
+
"推荐": "recommend",
|
|
24
|
+
"推荐页": "recommend",
|
|
25
|
+
"推荐页面": "recommend",
|
|
26
|
+
latest: "latest",
|
|
27
|
+
"最新": "latest",
|
|
28
|
+
"最新页": "latest",
|
|
29
|
+
"最新页面": "latest",
|
|
30
|
+
featured: "featured",
|
|
31
|
+
"精选": "featured",
|
|
32
|
+
"精选页": "featured",
|
|
33
|
+
"精选页面": "featured",
|
|
34
|
+
"精选牛人": "featured"
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const STATUS_TO_SCOPE = Object.freeze(
|
|
38
|
+
Object.fromEntries(
|
|
39
|
+
Object.entries(RECOMMEND_PAGE_SCOPE_STATUS).map(([scope, status]) => [status, scope])
|
|
40
|
+
)
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
function compactTab(tab) {
|
|
44
|
+
return {
|
|
45
|
+
scope: tab.scope,
|
|
46
|
+
label: tab.label,
|
|
47
|
+
title: tab.title,
|
|
48
|
+
status: tab.status,
|
|
49
|
+
current: Boolean(tab.current),
|
|
50
|
+
visible: Boolean(tab.visible),
|
|
51
|
+
class_name: tab.class_name,
|
|
52
|
+
node_id: tab.node_id,
|
|
53
|
+
center: tab.center,
|
|
54
|
+
rect: tab.rect
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function inferScopeFromText(text = "") {
|
|
59
|
+
const normalized = normalizeText(text).replace(/\s+/g, "");
|
|
60
|
+
if (!normalized) return null;
|
|
61
|
+
if (/^推荐/.test(normalized)) return "recommend";
|
|
62
|
+
if (/^精选/.test(normalized)) return "featured";
|
|
63
|
+
if (/^最新/.test(normalized)) return "latest";
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isVisibleBox(box) {
|
|
68
|
+
return Boolean(box && box.rect.width > 4 && box.rect.height > 4);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function normalizeRecommendPageScope(value) {
|
|
72
|
+
const raw = normalizeText(value);
|
|
73
|
+
if (!raw) return null;
|
|
74
|
+
const lower = raw.toLowerCase();
|
|
75
|
+
return SCOPE_ALIASES[lower] || SCOPE_ALIASES[raw] || null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function getRecommendPageScopeStatus(scope) {
|
|
79
|
+
const normalized = normalizeRecommendPageScope(scope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
80
|
+
return RECOMMEND_PAGE_SCOPE_STATUS[normalized] || RECOMMEND_PAGE_SCOPE_STATUS.recommend;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getRecommendPageScopeLabel(scope) {
|
|
84
|
+
const normalized = normalizeRecommendPageScope(scope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
85
|
+
return RECOMMEND_PAGE_SCOPE_LABELS[normalized] || RECOMMEND_PAGE_SCOPE_LABELS.recommend;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function readPageScopeTab(client, nodeId, index) {
|
|
89
|
+
const [attributes, outerHTML] = await Promise.all([
|
|
90
|
+
getAttributesMap(client, nodeId),
|
|
91
|
+
getOuterHTML(client, nodeId)
|
|
92
|
+
]);
|
|
93
|
+
const label = normalizeText(htmlToText(outerHTML));
|
|
94
|
+
const status = attributes["data-status"] || "";
|
|
95
|
+
const title = attributes.title || "";
|
|
96
|
+
const scope = STATUS_TO_SCOPE[status] || inferScopeFromText(`${title} ${label}`);
|
|
97
|
+
let box = null;
|
|
98
|
+
try {
|
|
99
|
+
box = await getNodeBox(client, nodeId);
|
|
100
|
+
} catch {}
|
|
101
|
+
const className = attributes.class || "";
|
|
102
|
+
return {
|
|
103
|
+
node_id: nodeId,
|
|
104
|
+
index,
|
|
105
|
+
scope,
|
|
106
|
+
status,
|
|
107
|
+
label,
|
|
108
|
+
title,
|
|
109
|
+
class_name: className,
|
|
110
|
+
current: /\bcurr\b|\bactive\b|\bselected\b/.test(className),
|
|
111
|
+
visible: isVisibleBox(box),
|
|
112
|
+
center: box?.center || null,
|
|
113
|
+
rect: box?.rect || null
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function listRecommendPageScopeTabs(client, frameNodeId, {
|
|
118
|
+
selector = RECOMMEND_PAGE_SCOPE_TAB_SELECTOR
|
|
119
|
+
} = {}) {
|
|
120
|
+
const nodeIds = await querySelectorAll(client, frameNodeId, selector);
|
|
121
|
+
const tabs = [];
|
|
122
|
+
const seen = new Set();
|
|
123
|
+
for (let index = 0; index < nodeIds.length; index += 1) {
|
|
124
|
+
const nodeId = nodeIds[index];
|
|
125
|
+
if (seen.has(nodeId)) continue;
|
|
126
|
+
seen.add(nodeId);
|
|
127
|
+
const tab = await readPageScopeTab(client, nodeId, index);
|
|
128
|
+
if (!tab.scope) continue;
|
|
129
|
+
tabs.push(tab);
|
|
130
|
+
}
|
|
131
|
+
return tabs;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function getActiveRecommendPageScope(client, frameNodeId) {
|
|
135
|
+
const tabs = await listRecommendPageScopeTabs(client, frameNodeId);
|
|
136
|
+
const current = tabs.find((tab) => tab.current);
|
|
137
|
+
return {
|
|
138
|
+
scope: current?.scope || null,
|
|
139
|
+
tab: current ? compactTab(current) : null,
|
|
140
|
+
tabs: tabs.map(compactTab)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function waitForRecommendPageScope(client, frameNodeId, scope, {
|
|
145
|
+
timeoutMs = 10000,
|
|
146
|
+
intervalMs = 300
|
|
147
|
+
} = {}) {
|
|
148
|
+
const started = Date.now();
|
|
149
|
+
let lastState = null;
|
|
150
|
+
while (Date.now() - started <= timeoutMs) {
|
|
151
|
+
const active = await getActiveRecommendPageScope(client, frameNodeId);
|
|
152
|
+
const cardCount = (await querySelectorAll(client, frameNodeId, RECOMMEND_CARD_SELECTOR)).length;
|
|
153
|
+
lastState = {
|
|
154
|
+
...active,
|
|
155
|
+
card_count: cardCount
|
|
156
|
+
};
|
|
157
|
+
if (active.scope === scope && cardCount > 0) {
|
|
158
|
+
return {
|
|
159
|
+
ok: true,
|
|
160
|
+
elapsed_ms: Date.now() - started,
|
|
161
|
+
...lastState
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
await sleep(intervalMs);
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
ok: false,
|
|
168
|
+
elapsed_ms: Date.now() - started,
|
|
169
|
+
...lastState
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export async function selectRecommendPageScope(client, frameNodeId, {
|
|
174
|
+
pageScope = RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
175
|
+
fallbackScope = RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
176
|
+
settleMs = 1200,
|
|
177
|
+
timeoutMs = 15000
|
|
178
|
+
} = {}) {
|
|
179
|
+
const requested = normalizeRecommendPageScope(pageScope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
180
|
+
const fallback = normalizeRecommendPageScope(fallbackScope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
181
|
+
const tabs = await listRecommendPageScopeTabs(client, frameNodeId);
|
|
182
|
+
const availableScopes = Array.from(new Set(tabs.map((tab) => tab.scope)));
|
|
183
|
+
const requestedTab = tabs.find((tab) => tab.scope === requested && tab.visible)
|
|
184
|
+
|| tabs.find((tab) => tab.scope === requested);
|
|
185
|
+
const fallbackTab = tabs.find((tab) => tab.scope === fallback && tab.visible)
|
|
186
|
+
|| tabs.find((tab) => tab.scope === fallback);
|
|
187
|
+
const targetTab = requestedTab || fallbackTab;
|
|
188
|
+
const effectiveScope = requestedTab ? requested : fallback;
|
|
189
|
+
|
|
190
|
+
if (!targetTab) {
|
|
191
|
+
return {
|
|
192
|
+
requested_scope: requested,
|
|
193
|
+
effective_scope: null,
|
|
194
|
+
fallback_scope: fallback,
|
|
195
|
+
fallback_applied: !requestedTab,
|
|
196
|
+
selected: false,
|
|
197
|
+
reason: "scope_tab_not_found",
|
|
198
|
+
available_scopes: availableScopes,
|
|
199
|
+
tabs: tabs.map(compactTab)
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (targetTab.current) {
|
|
204
|
+
const active = await getActiveRecommendPageScope(client, frameNodeId);
|
|
205
|
+
const cardCount = (await querySelectorAll(client, frameNodeId, RECOMMEND_CARD_SELECTOR)).length;
|
|
206
|
+
return {
|
|
207
|
+
requested_scope: requested,
|
|
208
|
+
effective_scope: effectiveScope,
|
|
209
|
+
fallback_scope: fallback,
|
|
210
|
+
fallback_applied: requested !== effectiveScope,
|
|
211
|
+
selected: true,
|
|
212
|
+
already_current: true,
|
|
213
|
+
selected_tab: compactTab(targetTab),
|
|
214
|
+
available_scopes: availableScopes,
|
|
215
|
+
tabs: tabs.map(compactTab),
|
|
216
|
+
after: {
|
|
217
|
+
...active,
|
|
218
|
+
card_count: cardCount
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const clickBox = await clickNodeCenter(client, targetTab.node_id);
|
|
224
|
+
if (settleMs > 0) await sleep(settleMs);
|
|
225
|
+
const after = await waitForRecommendPageScope(client, frameNodeId, effectiveScope, {
|
|
226
|
+
timeoutMs,
|
|
227
|
+
intervalMs: Math.max(250, Math.min(500, Math.floor(timeoutMs / 30)))
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
requested_scope: requested,
|
|
231
|
+
effective_scope: effectiveScope,
|
|
232
|
+
fallback_scope: fallback,
|
|
233
|
+
fallback_applied: requested !== effectiveScope,
|
|
234
|
+
selected: after.ok,
|
|
235
|
+
already_current: false,
|
|
236
|
+
selected_tab: compactTab(targetTab),
|
|
237
|
+
available_scopes: availableScopes,
|
|
238
|
+
tabs: tabs.map(compactTab),
|
|
239
|
+
click_box: {
|
|
240
|
+
center: clickBox.center,
|
|
241
|
+
rect: clickBox.rect
|
|
242
|
+
},
|
|
243
|
+
after
|
|
244
|
+
};
|
|
245
|
+
}
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAttributesMap,
|
|
3
|
+
getOuterHTML,
|
|
4
|
+
querySelectorAll,
|
|
5
|
+
sleep
|
|
6
|
+
} from "../../core/browser/index.js";
|
|
7
|
+
import { normalizeCandidateFromHtml } from "../../core/screening/index.js";
|
|
8
|
+
import { RECRUIT_CARD_SELECTOR } from "./constants.js";
|
|
9
|
+
|
|
10
|
+
export async function findRecruitCardNodeIds(client, frameNodeId, {
|
|
11
|
+
selector = RECRUIT_CARD_SELECTOR
|
|
12
|
+
} = {}) {
|
|
13
|
+
return querySelectorAll(client, frameNodeId, selector);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function waitForRecruitCardNodeIds(client, frameNodeId, {
|
|
17
|
+
selector = RECRUIT_CARD_SELECTOR,
|
|
18
|
+
timeoutMs = 12000,
|
|
19
|
+
intervalMs = 300
|
|
20
|
+
} = {}) {
|
|
21
|
+
const started = Date.now();
|
|
22
|
+
let nodeIds = [];
|
|
23
|
+
while (Date.now() - started <= timeoutMs) {
|
|
24
|
+
nodeIds = await findRecruitCardNodeIds(client, frameNodeId, { selector });
|
|
25
|
+
if (nodeIds.length) return nodeIds;
|
|
26
|
+
await sleep(intervalMs);
|
|
27
|
+
}
|
|
28
|
+
return nodeIds;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function readRecruitCardCandidate(client, cardNodeId, {
|
|
32
|
+
targetUrl = "",
|
|
33
|
+
source = "recruit-domain-card",
|
|
34
|
+
metadata = {}
|
|
35
|
+
} = {}) {
|
|
36
|
+
const [attributes, outerHTML] = await Promise.all([
|
|
37
|
+
getAttributesMap(client, cardNodeId),
|
|
38
|
+
getOuterHTML(client, cardNodeId)
|
|
39
|
+
]);
|
|
40
|
+
return normalizeCandidateFromHtml({
|
|
41
|
+
domain: "recruit",
|
|
42
|
+
source,
|
|
43
|
+
html: outerHTML,
|
|
44
|
+
attributes,
|
|
45
|
+
metadata: {
|
|
46
|
+
target_url: targetUrl,
|
|
47
|
+
card_node_id: cardNodeId,
|
|
48
|
+
...metadata
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function readFirstRecruitCardCandidate(client, frameNodeId, options = {}) {
|
|
54
|
+
const cardNodeIds = await findRecruitCardNodeIds(client, frameNodeId, options);
|
|
55
|
+
if (!cardNodeIds.length) {
|
|
56
|
+
throw new Error("No recruit/search candidate cards found");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const candidate = await readRecruitCardCandidate(client, cardNodeIds[0], options);
|
|
60
|
+
return {
|
|
61
|
+
card_count: cardNodeIds.length,
|
|
62
|
+
first_card_node_id: cardNodeIds[0],
|
|
63
|
+
card_node_ids: cardNodeIds,
|
|
64
|
+
candidate
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|