@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,246 +1,246 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clickNodeCenter,
|
|
3
|
-
DETERMINISTIC_CLICK_OPTIONS,
|
|
4
|
-
getAttributesMap,
|
|
5
|
-
getNodeBox,
|
|
6
|
-
getOuterHTML,
|
|
7
|
-
querySelectorAll,
|
|
8
|
-
sleep
|
|
9
|
-
} from "../../core/browser/index.js";
|
|
10
|
-
import {
|
|
11
|
-
htmlToText,
|
|
12
|
-
normalizeText
|
|
13
|
-
} from "../../core/screening/index.js";
|
|
14
|
-
import {
|
|
15
|
-
RECOMMEND_CARD_SELECTOR,
|
|
16
|
-
RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
17
|
-
RECOMMEND_PAGE_SCOPE_LABELS,
|
|
18
|
-
RECOMMEND_PAGE_SCOPE_STATUS,
|
|
19
|
-
RECOMMEND_PAGE_SCOPE_TAB_SELECTOR
|
|
20
|
-
} from "./constants.js";
|
|
21
|
-
|
|
22
|
-
const SCOPE_ALIASES = Object.freeze({
|
|
23
|
-
recommend: "recommend",
|
|
24
|
-
"推荐": "recommend",
|
|
25
|
-
"推荐页": "recommend",
|
|
26
|
-
"推荐页面": "recommend",
|
|
27
|
-
latest: "latest",
|
|
28
|
-
"最新": "latest",
|
|
29
|
-
"最新页": "latest",
|
|
30
|
-
"最新页面": "latest",
|
|
31
|
-
featured: "featured",
|
|
32
|
-
"精选": "featured",
|
|
33
|
-
"精选页": "featured",
|
|
34
|
-
"精选页面": "featured",
|
|
35
|
-
"精选牛人": "featured"
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const STATUS_TO_SCOPE = Object.freeze(
|
|
39
|
-
Object.fromEntries(
|
|
40
|
-
Object.entries(RECOMMEND_PAGE_SCOPE_STATUS).map(([scope, status]) => [status, scope])
|
|
41
|
-
)
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
function compactTab(tab) {
|
|
45
|
-
return {
|
|
46
|
-
scope: tab.scope,
|
|
47
|
-
label: tab.label,
|
|
48
|
-
title: tab.title,
|
|
49
|
-
status: tab.status,
|
|
50
|
-
current: Boolean(tab.current),
|
|
51
|
-
visible: Boolean(tab.visible),
|
|
52
|
-
class_name: tab.class_name,
|
|
53
|
-
node_id: tab.node_id,
|
|
54
|
-
center: tab.center,
|
|
55
|
-
rect: tab.rect
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function inferScopeFromText(text = "") {
|
|
60
|
-
const normalized = normalizeText(text).replace(/\s+/g, "");
|
|
61
|
-
if (!normalized) return null;
|
|
62
|
-
if (/^推荐/.test(normalized)) return "recommend";
|
|
63
|
-
if (/^精选/.test(normalized)) return "featured";
|
|
64
|
-
if (/^最新/.test(normalized)) return "latest";
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function isVisibleBox(box) {
|
|
69
|
-
return Boolean(box && box.rect.width > 4 && box.rect.height > 4);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function normalizeRecommendPageScope(value) {
|
|
73
|
-
const raw = normalizeText(value);
|
|
74
|
-
if (!raw) return null;
|
|
75
|
-
const lower = raw.toLowerCase();
|
|
76
|
-
return SCOPE_ALIASES[lower] || SCOPE_ALIASES[raw] || null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function getRecommendPageScopeStatus(scope) {
|
|
80
|
-
const normalized = normalizeRecommendPageScope(scope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
81
|
-
return RECOMMEND_PAGE_SCOPE_STATUS[normalized] || RECOMMEND_PAGE_SCOPE_STATUS.recommend;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function getRecommendPageScopeLabel(scope) {
|
|
85
|
-
const normalized = normalizeRecommendPageScope(scope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
86
|
-
return RECOMMEND_PAGE_SCOPE_LABELS[normalized] || RECOMMEND_PAGE_SCOPE_LABELS.recommend;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function readPageScopeTab(client, nodeId, index) {
|
|
90
|
-
const [attributes, outerHTML] = await Promise.all([
|
|
91
|
-
getAttributesMap(client, nodeId),
|
|
92
|
-
getOuterHTML(client, nodeId)
|
|
93
|
-
]);
|
|
94
|
-
const label = normalizeText(htmlToText(outerHTML));
|
|
95
|
-
const status = attributes["data-status"] || "";
|
|
96
|
-
const title = attributes.title || "";
|
|
97
|
-
const scope = STATUS_TO_SCOPE[status] || inferScopeFromText(`${title} ${label}`);
|
|
98
|
-
let box = null;
|
|
99
|
-
try {
|
|
100
|
-
box = await getNodeBox(client, nodeId);
|
|
101
|
-
} catch {}
|
|
102
|
-
const className = attributes.class || "";
|
|
103
|
-
return {
|
|
104
|
-
node_id: nodeId,
|
|
105
|
-
index,
|
|
106
|
-
scope,
|
|
107
|
-
status,
|
|
108
|
-
label,
|
|
109
|
-
title,
|
|
110
|
-
class_name: className,
|
|
111
|
-
current: /\bcurr\b|\bactive\b|\bselected\b/.test(className),
|
|
112
|
-
visible: isVisibleBox(box),
|
|
113
|
-
center: box?.center || null,
|
|
114
|
-
rect: box?.rect || null
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export async function listRecommendPageScopeTabs(client, frameNodeId, {
|
|
119
|
-
selector = RECOMMEND_PAGE_SCOPE_TAB_SELECTOR
|
|
120
|
-
} = {}) {
|
|
121
|
-
const nodeIds = await querySelectorAll(client, frameNodeId, selector);
|
|
122
|
-
const tabs = [];
|
|
123
|
-
const seen = new Set();
|
|
124
|
-
for (let index = 0; index < nodeIds.length; index += 1) {
|
|
125
|
-
const nodeId = nodeIds[index];
|
|
126
|
-
if (seen.has(nodeId)) continue;
|
|
127
|
-
seen.add(nodeId);
|
|
128
|
-
const tab = await readPageScopeTab(client, nodeId, index);
|
|
129
|
-
if (!tab.scope) continue;
|
|
130
|
-
tabs.push(tab);
|
|
131
|
-
}
|
|
132
|
-
return tabs;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export async function getActiveRecommendPageScope(client, frameNodeId) {
|
|
136
|
-
const tabs = await listRecommendPageScopeTabs(client, frameNodeId);
|
|
137
|
-
const current = tabs.find((tab) => tab.current);
|
|
138
|
-
return {
|
|
139
|
-
scope: current?.scope || null,
|
|
140
|
-
tab: current ? compactTab(current) : null,
|
|
141
|
-
tabs: tabs.map(compactTab)
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async function waitForRecommendPageScope(client, frameNodeId, scope, {
|
|
146
|
-
timeoutMs = 10000,
|
|
147
|
-
intervalMs = 300
|
|
148
|
-
} = {}) {
|
|
149
|
-
const started = Date.now();
|
|
150
|
-
let lastState = null;
|
|
151
|
-
while (Date.now() - started <= timeoutMs) {
|
|
152
|
-
const active = await getActiveRecommendPageScope(client, frameNodeId);
|
|
153
|
-
const cardCount = (await querySelectorAll(client, frameNodeId, RECOMMEND_CARD_SELECTOR)).length;
|
|
154
|
-
lastState = {
|
|
155
|
-
...active,
|
|
156
|
-
card_count: cardCount
|
|
157
|
-
};
|
|
158
|
-
if (active.scope === scope && cardCount > 0) {
|
|
159
|
-
return {
|
|
160
|
-
ok: true,
|
|
161
|
-
elapsed_ms: Date.now() - started,
|
|
162
|
-
...lastState
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
await sleep(intervalMs);
|
|
166
|
-
}
|
|
167
|
-
return {
|
|
168
|
-
ok: false,
|
|
169
|
-
elapsed_ms: Date.now() - started,
|
|
170
|
-
...lastState
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export async function selectRecommendPageScope(client, frameNodeId, {
|
|
175
|
-
pageScope = RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
176
|
-
fallbackScope = RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
177
|
-
settleMs = 1200,
|
|
178
|
-
timeoutMs = 15000
|
|
179
|
-
} = {}) {
|
|
180
|
-
const requested = normalizeRecommendPageScope(pageScope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
181
|
-
const fallback = normalizeRecommendPageScope(fallbackScope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
182
|
-
const tabs = await listRecommendPageScopeTabs(client, frameNodeId);
|
|
183
|
-
const availableScopes = Array.from(new Set(tabs.map((tab) => tab.scope)));
|
|
184
|
-
const requestedTab = tabs.find((tab) => tab.scope === requested && tab.visible)
|
|
185
|
-
|| tabs.find((tab) => tab.scope === requested);
|
|
186
|
-
const fallbackTab = tabs.find((tab) => tab.scope === fallback && tab.visible)
|
|
187
|
-
|| tabs.find((tab) => tab.scope === fallback);
|
|
188
|
-
const targetTab = requestedTab || fallbackTab;
|
|
189
|
-
const effectiveScope = requestedTab ? requested : fallback;
|
|
190
|
-
|
|
191
|
-
if (!targetTab) {
|
|
192
|
-
return {
|
|
193
|
-
requested_scope: requested,
|
|
194
|
-
effective_scope: null,
|
|
195
|
-
fallback_scope: fallback,
|
|
196
|
-
fallback_applied: !requestedTab,
|
|
197
|
-
selected: false,
|
|
198
|
-
reason: "scope_tab_not_found",
|
|
199
|
-
available_scopes: availableScopes,
|
|
200
|
-
tabs: tabs.map(compactTab)
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (targetTab.current) {
|
|
205
|
-
const active = await getActiveRecommendPageScope(client, frameNodeId);
|
|
206
|
-
const cardCount = (await querySelectorAll(client, frameNodeId, RECOMMEND_CARD_SELECTOR)).length;
|
|
207
|
-
return {
|
|
208
|
-
requested_scope: requested,
|
|
209
|
-
effective_scope: effectiveScope,
|
|
210
|
-
fallback_scope: fallback,
|
|
211
|
-
fallback_applied: requested !== effectiveScope,
|
|
212
|
-
selected: true,
|
|
213
|
-
already_current: true,
|
|
214
|
-
selected_tab: compactTab(targetTab),
|
|
215
|
-
available_scopes: availableScopes,
|
|
216
|
-
tabs: tabs.map(compactTab),
|
|
217
|
-
after: {
|
|
218
|
-
...active,
|
|
219
|
-
card_count: cardCount
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
const clickBox = await clickNodeCenter(client, targetTab.node_id, DETERMINISTIC_CLICK_OPTIONS);
|
|
225
|
-
if (settleMs > 0) await sleep(settleMs);
|
|
226
|
-
const after = await waitForRecommendPageScope(client, frameNodeId, effectiveScope, {
|
|
227
|
-
timeoutMs,
|
|
228
|
-
intervalMs: Math.max(250, Math.min(500, Math.floor(timeoutMs / 30)))
|
|
229
|
-
});
|
|
230
|
-
return {
|
|
231
|
-
requested_scope: requested,
|
|
232
|
-
effective_scope: effectiveScope,
|
|
233
|
-
fallback_scope: fallback,
|
|
234
|
-
fallback_applied: requested !== effectiveScope,
|
|
235
|
-
selected: after.ok,
|
|
236
|
-
already_current: false,
|
|
237
|
-
selected_tab: compactTab(targetTab),
|
|
238
|
-
available_scopes: availableScopes,
|
|
239
|
-
tabs: tabs.map(compactTab),
|
|
240
|
-
click_box: {
|
|
241
|
-
center: clickBox.center,
|
|
242
|
-
rect: clickBox.rect
|
|
243
|
-
},
|
|
244
|
-
after
|
|
245
|
-
};
|
|
246
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
clickNodeCenter,
|
|
3
|
+
DETERMINISTIC_CLICK_OPTIONS,
|
|
4
|
+
getAttributesMap,
|
|
5
|
+
getNodeBox,
|
|
6
|
+
getOuterHTML,
|
|
7
|
+
querySelectorAll,
|
|
8
|
+
sleep
|
|
9
|
+
} from "../../core/browser/index.js";
|
|
10
|
+
import {
|
|
11
|
+
htmlToText,
|
|
12
|
+
normalizeText
|
|
13
|
+
} from "../../core/screening/index.js";
|
|
14
|
+
import {
|
|
15
|
+
RECOMMEND_CARD_SELECTOR,
|
|
16
|
+
RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
17
|
+
RECOMMEND_PAGE_SCOPE_LABELS,
|
|
18
|
+
RECOMMEND_PAGE_SCOPE_STATUS,
|
|
19
|
+
RECOMMEND_PAGE_SCOPE_TAB_SELECTOR
|
|
20
|
+
} from "./constants.js";
|
|
21
|
+
|
|
22
|
+
const SCOPE_ALIASES = Object.freeze({
|
|
23
|
+
recommend: "recommend",
|
|
24
|
+
"推荐": "recommend",
|
|
25
|
+
"推荐页": "recommend",
|
|
26
|
+
"推荐页面": "recommend",
|
|
27
|
+
latest: "latest",
|
|
28
|
+
"最新": "latest",
|
|
29
|
+
"最新页": "latest",
|
|
30
|
+
"最新页面": "latest",
|
|
31
|
+
featured: "featured",
|
|
32
|
+
"精选": "featured",
|
|
33
|
+
"精选页": "featured",
|
|
34
|
+
"精选页面": "featured",
|
|
35
|
+
"精选牛人": "featured"
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const STATUS_TO_SCOPE = Object.freeze(
|
|
39
|
+
Object.fromEntries(
|
|
40
|
+
Object.entries(RECOMMEND_PAGE_SCOPE_STATUS).map(([scope, status]) => [status, scope])
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
function compactTab(tab) {
|
|
45
|
+
return {
|
|
46
|
+
scope: tab.scope,
|
|
47
|
+
label: tab.label,
|
|
48
|
+
title: tab.title,
|
|
49
|
+
status: tab.status,
|
|
50
|
+
current: Boolean(tab.current),
|
|
51
|
+
visible: Boolean(tab.visible),
|
|
52
|
+
class_name: tab.class_name,
|
|
53
|
+
node_id: tab.node_id,
|
|
54
|
+
center: tab.center,
|
|
55
|
+
rect: tab.rect
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function inferScopeFromText(text = "") {
|
|
60
|
+
const normalized = normalizeText(text).replace(/\s+/g, "");
|
|
61
|
+
if (!normalized) return null;
|
|
62
|
+
if (/^推荐/.test(normalized)) return "recommend";
|
|
63
|
+
if (/^精选/.test(normalized)) return "featured";
|
|
64
|
+
if (/^最新/.test(normalized)) return "latest";
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isVisibleBox(box) {
|
|
69
|
+
return Boolean(box && box.rect.width > 4 && box.rect.height > 4);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function normalizeRecommendPageScope(value) {
|
|
73
|
+
const raw = normalizeText(value);
|
|
74
|
+
if (!raw) return null;
|
|
75
|
+
const lower = raw.toLowerCase();
|
|
76
|
+
return SCOPE_ALIASES[lower] || SCOPE_ALIASES[raw] || null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getRecommendPageScopeStatus(scope) {
|
|
80
|
+
const normalized = normalizeRecommendPageScope(scope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
81
|
+
return RECOMMEND_PAGE_SCOPE_STATUS[normalized] || RECOMMEND_PAGE_SCOPE_STATUS.recommend;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getRecommendPageScopeLabel(scope) {
|
|
85
|
+
const normalized = normalizeRecommendPageScope(scope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
86
|
+
return RECOMMEND_PAGE_SCOPE_LABELS[normalized] || RECOMMEND_PAGE_SCOPE_LABELS.recommend;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function readPageScopeTab(client, nodeId, index) {
|
|
90
|
+
const [attributes, outerHTML] = await Promise.all([
|
|
91
|
+
getAttributesMap(client, nodeId),
|
|
92
|
+
getOuterHTML(client, nodeId)
|
|
93
|
+
]);
|
|
94
|
+
const label = normalizeText(htmlToText(outerHTML));
|
|
95
|
+
const status = attributes["data-status"] || "";
|
|
96
|
+
const title = attributes.title || "";
|
|
97
|
+
const scope = STATUS_TO_SCOPE[status] || inferScopeFromText(`${title} ${label}`);
|
|
98
|
+
let box = null;
|
|
99
|
+
try {
|
|
100
|
+
box = await getNodeBox(client, nodeId);
|
|
101
|
+
} catch {}
|
|
102
|
+
const className = attributes.class || "";
|
|
103
|
+
return {
|
|
104
|
+
node_id: nodeId,
|
|
105
|
+
index,
|
|
106
|
+
scope,
|
|
107
|
+
status,
|
|
108
|
+
label,
|
|
109
|
+
title,
|
|
110
|
+
class_name: className,
|
|
111
|
+
current: /\bcurr\b|\bactive\b|\bselected\b/.test(className),
|
|
112
|
+
visible: isVisibleBox(box),
|
|
113
|
+
center: box?.center || null,
|
|
114
|
+
rect: box?.rect || null
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function listRecommendPageScopeTabs(client, frameNodeId, {
|
|
119
|
+
selector = RECOMMEND_PAGE_SCOPE_TAB_SELECTOR
|
|
120
|
+
} = {}) {
|
|
121
|
+
const nodeIds = await querySelectorAll(client, frameNodeId, selector);
|
|
122
|
+
const tabs = [];
|
|
123
|
+
const seen = new Set();
|
|
124
|
+
for (let index = 0; index < nodeIds.length; index += 1) {
|
|
125
|
+
const nodeId = nodeIds[index];
|
|
126
|
+
if (seen.has(nodeId)) continue;
|
|
127
|
+
seen.add(nodeId);
|
|
128
|
+
const tab = await readPageScopeTab(client, nodeId, index);
|
|
129
|
+
if (!tab.scope) continue;
|
|
130
|
+
tabs.push(tab);
|
|
131
|
+
}
|
|
132
|
+
return tabs;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function getActiveRecommendPageScope(client, frameNodeId) {
|
|
136
|
+
const tabs = await listRecommendPageScopeTabs(client, frameNodeId);
|
|
137
|
+
const current = tabs.find((tab) => tab.current);
|
|
138
|
+
return {
|
|
139
|
+
scope: current?.scope || null,
|
|
140
|
+
tab: current ? compactTab(current) : null,
|
|
141
|
+
tabs: tabs.map(compactTab)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function waitForRecommendPageScope(client, frameNodeId, scope, {
|
|
146
|
+
timeoutMs = 10000,
|
|
147
|
+
intervalMs = 300
|
|
148
|
+
} = {}) {
|
|
149
|
+
const started = Date.now();
|
|
150
|
+
let lastState = null;
|
|
151
|
+
while (Date.now() - started <= timeoutMs) {
|
|
152
|
+
const active = await getActiveRecommendPageScope(client, frameNodeId);
|
|
153
|
+
const cardCount = (await querySelectorAll(client, frameNodeId, RECOMMEND_CARD_SELECTOR)).length;
|
|
154
|
+
lastState = {
|
|
155
|
+
...active,
|
|
156
|
+
card_count: cardCount
|
|
157
|
+
};
|
|
158
|
+
if (active.scope === scope && cardCount > 0) {
|
|
159
|
+
return {
|
|
160
|
+
ok: true,
|
|
161
|
+
elapsed_ms: Date.now() - started,
|
|
162
|
+
...lastState
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
await sleep(intervalMs);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
elapsed_ms: Date.now() - started,
|
|
170
|
+
...lastState
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export async function selectRecommendPageScope(client, frameNodeId, {
|
|
175
|
+
pageScope = RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
176
|
+
fallbackScope = RECOMMEND_PAGE_SCOPE_DEFAULT,
|
|
177
|
+
settleMs = 1200,
|
|
178
|
+
timeoutMs = 15000
|
|
179
|
+
} = {}) {
|
|
180
|
+
const requested = normalizeRecommendPageScope(pageScope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
181
|
+
const fallback = normalizeRecommendPageScope(fallbackScope) || RECOMMEND_PAGE_SCOPE_DEFAULT;
|
|
182
|
+
const tabs = await listRecommendPageScopeTabs(client, frameNodeId);
|
|
183
|
+
const availableScopes = Array.from(new Set(tabs.map((tab) => tab.scope)));
|
|
184
|
+
const requestedTab = tabs.find((tab) => tab.scope === requested && tab.visible)
|
|
185
|
+
|| tabs.find((tab) => tab.scope === requested);
|
|
186
|
+
const fallbackTab = tabs.find((tab) => tab.scope === fallback && tab.visible)
|
|
187
|
+
|| tabs.find((tab) => tab.scope === fallback);
|
|
188
|
+
const targetTab = requestedTab || fallbackTab;
|
|
189
|
+
const effectiveScope = requestedTab ? requested : fallback;
|
|
190
|
+
|
|
191
|
+
if (!targetTab) {
|
|
192
|
+
return {
|
|
193
|
+
requested_scope: requested,
|
|
194
|
+
effective_scope: null,
|
|
195
|
+
fallback_scope: fallback,
|
|
196
|
+
fallback_applied: !requestedTab,
|
|
197
|
+
selected: false,
|
|
198
|
+
reason: "scope_tab_not_found",
|
|
199
|
+
available_scopes: availableScopes,
|
|
200
|
+
tabs: tabs.map(compactTab)
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (targetTab.current) {
|
|
205
|
+
const active = await getActiveRecommendPageScope(client, frameNodeId);
|
|
206
|
+
const cardCount = (await querySelectorAll(client, frameNodeId, RECOMMEND_CARD_SELECTOR)).length;
|
|
207
|
+
return {
|
|
208
|
+
requested_scope: requested,
|
|
209
|
+
effective_scope: effectiveScope,
|
|
210
|
+
fallback_scope: fallback,
|
|
211
|
+
fallback_applied: requested !== effectiveScope,
|
|
212
|
+
selected: true,
|
|
213
|
+
already_current: true,
|
|
214
|
+
selected_tab: compactTab(targetTab),
|
|
215
|
+
available_scopes: availableScopes,
|
|
216
|
+
tabs: tabs.map(compactTab),
|
|
217
|
+
after: {
|
|
218
|
+
...active,
|
|
219
|
+
card_count: cardCount
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const clickBox = await clickNodeCenter(client, targetTab.node_id, DETERMINISTIC_CLICK_OPTIONS);
|
|
225
|
+
if (settleMs > 0) await sleep(settleMs);
|
|
226
|
+
const after = await waitForRecommendPageScope(client, frameNodeId, effectiveScope, {
|
|
227
|
+
timeoutMs,
|
|
228
|
+
intervalMs: Math.max(250, Math.min(500, Math.floor(timeoutMs / 30)))
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
requested_scope: requested,
|
|
232
|
+
effective_scope: effectiveScope,
|
|
233
|
+
fallback_scope: fallback,
|
|
234
|
+
fallback_applied: requested !== effectiveScope,
|
|
235
|
+
selected: after.ok,
|
|
236
|
+
already_current: false,
|
|
237
|
+
selected_tab: compactTab(targetTab),
|
|
238
|
+
available_scopes: availableScopes,
|
|
239
|
+
tabs: tabs.map(compactTab),
|
|
240
|
+
click_box: {
|
|
241
|
+
center: clickBox.center,
|
|
242
|
+
rect: clickBox.rect
|
|
243
|
+
},
|
|
244
|
+
after
|
|
245
|
+
};
|
|
246
|
+
}
|