dsh-lcx-codex 0.4.2 → 0.4.3-pre.2
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 +116 -202
- package/cordis.patch.yml +3 -20
- package/lib/client.js +273 -146
- package/lib/compact-v2.js +218 -199
- package/lib/dsh-compat.js +227 -100
- package/lib/dsh-responses.js +445 -277
- package/lib/index.js +851 -757
- package/lib/json-store.js +50 -31
- package/lib/native-checkpoint.js +520 -194
- package/lib/responses-request.js +106 -121
- package/lib/responses-stream.js +972 -443
- package/lib/route.js +229 -355
- package/lib/service-mutex.js +73 -64
- package/lib/token-budget.js +176 -108
- package/lib/transport.js +277 -67
- package/lib/types/client/index.d.ts +6 -0
- package/lib/types/compact-v2.d.ts +104 -0
- package/lib/types/dsh-compat.d.ts +78 -0
- package/lib/types/dsh-responses.d.ts +82 -0
- package/lib/types/index.d.ts +83 -0
- package/lib/types/json-store.d.ts +10 -0
- package/lib/types/native-checkpoint.d.ts +213 -0
- package/lib/types/responses-request.d.ts +58 -0
- package/lib/types/responses-stream.d.ts +51 -0
- package/lib/types/route.d.ts +132 -0
- package/lib/types/service-mutex.d.ts +14 -0
- package/lib/types/token-budget.d.ts +50 -0
- package/lib/types/transport.d.ts +20 -0
- package/lib/types/web-run-output.d.ts +29 -0
- package/lib/types/web-search-alpha.d.ts +286 -0
- package/lib/types/web-search-capability.d.ts +26 -0
- package/lib/types/web-search-hosted.d.ts +246 -0
- package/lib/types/web-search-ref-store.d.ts +22 -0
- package/lib/web-run-output.js +167 -18
- package/lib/web-search-alpha.js +865 -163
- package/lib/web-search-capability.js +55 -65
- package/lib/web-search-hosted.js +210 -32
- package/lib/web-search-ref-store.js +63 -59
- package/package.json +79 -27
- package/ARCHITECTURE.md +0 -117
- package/CHANGELOG.md +0 -224
- package/README_EN.md +0 -277
- package/assets/dsh-lcx-codex-banner.jpg +0 -0
- package/lib/legacy-v3.js +0 -20
- package/lib/responses-replay.js +0 -68
- package/scripts/probe-alpha.mjs +0 -43
- package/scripts/validate-dsh-schema.mjs +0 -31
package/lib/web-search-alpha.js
CHANGED
|
@@ -1,173 +1,875 @@
|
|
|
1
|
-
import { createHash } from
|
|
2
|
-
import { isIP } from
|
|
3
|
-
import { outputDomains, outputLineRange, outputLinks, outputPdfRefs, parseWebRunOutput } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { isIP } from "node:net";
|
|
3
|
+
import { outputDomains, outputLineRange, outputLinks, outputPdfRefs, parseWebRunOutput, } from "./web-run-output.js";
|
|
4
|
+
export const ALPHA_ACTIONS = [
|
|
5
|
+
"search_query",
|
|
6
|
+
"image_query",
|
|
7
|
+
"open",
|
|
8
|
+
"find",
|
|
9
|
+
"click",
|
|
10
|
+
"screenshot",
|
|
11
|
+
"finance",
|
|
12
|
+
"weather",
|
|
13
|
+
"sports",
|
|
14
|
+
"time",
|
|
15
|
+
];
|
|
16
|
+
const LEAGUES = [
|
|
17
|
+
"nba",
|
|
18
|
+
"wnba",
|
|
19
|
+
"nfl",
|
|
20
|
+
"nhl",
|
|
21
|
+
"mlb",
|
|
22
|
+
"epl",
|
|
23
|
+
"ncaamb",
|
|
24
|
+
"ncaawb",
|
|
25
|
+
"ipl",
|
|
26
|
+
];
|
|
27
|
+
const ASSET_TYPES = ["equity", "fund", "crypto", "index"];
|
|
28
|
+
const RESPONSE_LENGTHS = ["short", "medium", "long"];
|
|
29
|
+
export const ALPHA_SEARCH_PARAMETERS = {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
action: { type: "string", enum: ALPHA_ACTIONS },
|
|
33
|
+
query: { type: "string" },
|
|
34
|
+
domains: { type: "array", items: { type: "string" } },
|
|
35
|
+
recency: { type: "integer" },
|
|
36
|
+
refId: { type: "string" },
|
|
37
|
+
lineNumber: { type: "integer" },
|
|
38
|
+
linkId: { type: "integer" },
|
|
39
|
+
pattern: { type: "string" },
|
|
40
|
+
pageNumber: { type: "integer" },
|
|
41
|
+
ticker: { type: "string" },
|
|
42
|
+
assetType: { type: "string", enum: ASSET_TYPES },
|
|
43
|
+
market: { type: "string" },
|
|
44
|
+
location: { type: "string" },
|
|
45
|
+
start: { type: "string" },
|
|
46
|
+
duration: { type: "integer" },
|
|
47
|
+
fn: { type: "string", enum: ["schedule", "standings"] },
|
|
48
|
+
league: { type: "string", enum: LEAGUES },
|
|
49
|
+
team: { type: "string" },
|
|
50
|
+
opponent: { type: "string" },
|
|
51
|
+
dateFrom: { type: "string" },
|
|
52
|
+
dateTo: { type: "string" },
|
|
53
|
+
numberOfGames: { type: "integer" },
|
|
54
|
+
locale: { type: "string" },
|
|
55
|
+
utcOffset: { type: "string" },
|
|
56
|
+
responseLength: { type: "string", enum: RESPONSE_LENGTHS },
|
|
57
|
+
},
|
|
58
|
+
required: ["action"],
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
};
|
|
61
|
+
export const ALPHA_SEARCH_OUTPUT = {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
mode: { type: "string" },
|
|
65
|
+
action: { type: "string" },
|
|
66
|
+
capability: { type: "string" },
|
|
67
|
+
emulation: { type: "string" },
|
|
68
|
+
content: { type: "string" },
|
|
69
|
+
results: { type: "array", items: { type: "object" } },
|
|
70
|
+
refs: { type: "array", items: { type: "string" } },
|
|
71
|
+
sources: { type: "array", items: { type: "object" } },
|
|
72
|
+
citations: { type: "array", items: { type: "object" } },
|
|
73
|
+
outputBlocks: { type: "array", items: { type: "object" } },
|
|
74
|
+
links: { type: "array", items: { type: "object" } },
|
|
75
|
+
pdfRefs: { type: "array", items: { type: "string" } },
|
|
76
|
+
domains: { type: "array", items: { type: "string" } },
|
|
77
|
+
lineRange: { type: "object" },
|
|
78
|
+
requestId: { type: "string" },
|
|
79
|
+
responseId: { type: "string" },
|
|
80
|
+
retrievedAt: { type: "string" },
|
|
81
|
+
warnings: { type: "array", items: { type: "string" } },
|
|
82
|
+
},
|
|
83
|
+
required: [
|
|
84
|
+
"mode",
|
|
85
|
+
"action",
|
|
86
|
+
"capability",
|
|
87
|
+
"emulation",
|
|
88
|
+
"content",
|
|
89
|
+
"results",
|
|
90
|
+
"refs",
|
|
91
|
+
"sources",
|
|
92
|
+
"citations",
|
|
93
|
+
"outputBlocks",
|
|
94
|
+
"links",
|
|
95
|
+
"pdfRefs",
|
|
96
|
+
"domains",
|
|
97
|
+
"requestId",
|
|
98
|
+
"retrievedAt",
|
|
99
|
+
"warnings",
|
|
100
|
+
],
|
|
101
|
+
additionalProperties: false,
|
|
102
|
+
};
|
|
103
|
+
export const ALPHA_SCHEMA_FINGERPRINT = createHash("sha256")
|
|
104
|
+
.update(JSON.stringify(ALPHA_SEARCH_PARAMETERS))
|
|
105
|
+
.digest("hex");
|
|
106
|
+
export const ALPHA_PROBE_VERSION = 12;
|
|
107
|
+
function failure(message, code = "WEB_INVALID_REQUEST") {
|
|
108
|
+
return Object.assign(new Error(message), { code });
|
|
109
|
+
}
|
|
110
|
+
function isObject(v) {
|
|
111
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
112
|
+
}
|
|
113
|
+
function text(value, field, max = 1000) {
|
|
114
|
+
if (typeof value !== "string" || !value.trim() || value.trim().length > max)
|
|
115
|
+
throw failure(`websearch_alpha.${field} is invalid`);
|
|
116
|
+
return value.trim();
|
|
117
|
+
}
|
|
118
|
+
function integer(value, field, min = 0, max = 10000) {
|
|
119
|
+
if (typeof value !== "number" ||
|
|
120
|
+
!Number.isSafeInteger(value) ||
|
|
121
|
+
value < min ||
|
|
122
|
+
value > max)
|
|
123
|
+
throw failure(`websearch_alpha.${field} is invalid`);
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
function date(value, field) {
|
|
127
|
+
const normalized = text(value, field, 10);
|
|
128
|
+
if (!/^\d{4}-\d{2}-\d{2}$/u.test(normalized) ||
|
|
129
|
+
Number.isNaN(Date.parse(`${normalized}T00:00:00Z`)))
|
|
130
|
+
throw failure(`websearch_alpha.${field} must use YYYY-MM-DD`);
|
|
131
|
+
return normalized;
|
|
132
|
+
}
|
|
133
|
+
function normalizeDomains(value) {
|
|
134
|
+
if (!Array.isArray(value) || !value.length || value.length > 100)
|
|
135
|
+
throw failure("websearch_alpha.domains is invalid");
|
|
136
|
+
return value.map((item) => {
|
|
137
|
+
const d = text(item, "domains", 253).toLowerCase();
|
|
138
|
+
if (d.includes("/") || d.includes(":") || !d.includes("."))
|
|
139
|
+
throw failure("websearch_alpha.domains contains an invalid domain");
|
|
140
|
+
return d;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const FIELDS = {
|
|
144
|
+
search_query: ["query", "domains", "recency"],
|
|
145
|
+
image_query: ["query", "domains", "recency"],
|
|
146
|
+
open: ["refId", "lineNumber"],
|
|
147
|
+
find: ["refId", "pattern"],
|
|
148
|
+
click: ["refId", "linkId"],
|
|
149
|
+
screenshot: ["refId", "pageNumber"],
|
|
150
|
+
finance: ["ticker", "assetType", "market"],
|
|
151
|
+
weather: ["location", "start", "duration"],
|
|
152
|
+
sports: [
|
|
153
|
+
"fn",
|
|
154
|
+
"league",
|
|
155
|
+
"team",
|
|
156
|
+
"opponent",
|
|
157
|
+
"dateFrom",
|
|
158
|
+
"dateTo",
|
|
159
|
+
"numberOfGames",
|
|
160
|
+
"locale",
|
|
161
|
+
],
|
|
162
|
+
time: ["utcOffset"],
|
|
163
|
+
};
|
|
164
|
+
function isAlphaAction(value) {
|
|
165
|
+
return typeof value === "string" && ALPHA_ACTIONS.includes(value);
|
|
166
|
+
}
|
|
167
|
+
export function normalizeAlphaSearchArgs(args) {
|
|
168
|
+
if (!isObject(args) || !isAlphaAction(args.action))
|
|
169
|
+
throw failure("websearch_alpha.action is invalid");
|
|
170
|
+
const allowed = new Set(["action", "responseLength", ...FIELDS[args.action]]);
|
|
171
|
+
if (Object.keys(args).some((k) => !allowed.has(k)))
|
|
172
|
+
throw failure(`websearch_alpha.${args.action} received an unrelated field`);
|
|
173
|
+
const result = { action: args.action };
|
|
174
|
+
if (args.responseLength !== undefined) {
|
|
175
|
+
if (typeof args.responseLength !== "string" ||
|
|
176
|
+
!RESPONSE_LENGTHS.includes(args.responseLength))
|
|
177
|
+
throw failure("websearch_alpha.responseLength is invalid");
|
|
178
|
+
result.responseLength = args.responseLength;
|
|
179
|
+
}
|
|
180
|
+
switch (args.action) {
|
|
181
|
+
case "search_query":
|
|
182
|
+
case "image_query":
|
|
183
|
+
result.query = text(args.query, "query", 16000);
|
|
184
|
+
if (args.domains !== undefined)
|
|
185
|
+
result.domains = normalizeDomains(args.domains);
|
|
186
|
+
if (args.recency !== undefined)
|
|
187
|
+
result.recency = integer(args.recency, "recency", 0, 3650);
|
|
188
|
+
break;
|
|
189
|
+
case "open":
|
|
190
|
+
result.refId = text(args.refId, "refId");
|
|
191
|
+
if (args.lineNumber !== undefined)
|
|
192
|
+
result.lineNumber = integer(args.lineNumber, "lineNumber");
|
|
193
|
+
break;
|
|
194
|
+
case "find":
|
|
195
|
+
result.refId = text(args.refId, "refId");
|
|
196
|
+
result.pattern = text(args.pattern, "pattern");
|
|
197
|
+
break;
|
|
198
|
+
case "click":
|
|
199
|
+
result.refId = text(args.refId, "refId");
|
|
200
|
+
if (isAlphaHttpUrl(result.refId))
|
|
201
|
+
throw failure("websearch_alpha.click requires an opaque stored ref", "LCX_ALPHA_REF_REQUIRED");
|
|
202
|
+
result.linkId = integer(args.linkId, "linkId");
|
|
203
|
+
break;
|
|
204
|
+
case "screenshot":
|
|
205
|
+
result.refId = text(args.refId, "refId");
|
|
206
|
+
result.pageNumber = integer(args.pageNumber, "pageNumber");
|
|
207
|
+
break;
|
|
208
|
+
case "finance":
|
|
209
|
+
result.ticker = text(args.ticker, "ticker", 40);
|
|
210
|
+
if (typeof args.assetType !== "string" ||
|
|
211
|
+
!ASSET_TYPES.includes(args.assetType))
|
|
212
|
+
throw failure("websearch_alpha.assetType is invalid");
|
|
213
|
+
result.assetType = args.assetType;
|
|
214
|
+
if (args.market !== undefined)
|
|
215
|
+
result.market = text(args.market, "market", 20);
|
|
216
|
+
break;
|
|
217
|
+
case "weather":
|
|
218
|
+
result.location = text(args.location, "location", 500);
|
|
219
|
+
if (args.start !== undefined)
|
|
220
|
+
result.start = date(args.start, "start");
|
|
221
|
+
if (args.duration !== undefined)
|
|
222
|
+
result.duration = integer(args.duration, "duration", 1, 14);
|
|
223
|
+
break;
|
|
224
|
+
case "sports":
|
|
225
|
+
if (typeof args.fn !== "string" ||
|
|
226
|
+
!["schedule", "standings"].includes(args.fn) ||
|
|
227
|
+
typeof args.league !== "string" ||
|
|
228
|
+
!LEAGUES.includes(args.league))
|
|
229
|
+
throw failure("websearch_alpha sports args are invalid");
|
|
230
|
+
result.fn = args.fn;
|
|
231
|
+
result.league = args.league;
|
|
232
|
+
for (const f of ["team", "opponent", "locale"])
|
|
233
|
+
if (args[f] !== undefined)
|
|
234
|
+
result[f] = text(args[f], f, 100);
|
|
235
|
+
if (args.dateFrom !== undefined)
|
|
236
|
+
result.dateFrom = date(args.dateFrom, "dateFrom");
|
|
237
|
+
if (args.dateTo !== undefined)
|
|
238
|
+
result.dateTo = date(args.dateTo, "dateTo");
|
|
239
|
+
if (args.numberOfGames !== undefined)
|
|
240
|
+
result.numberOfGames = integer(args.numberOfGames, "numberOfGames", 1, 100);
|
|
241
|
+
break;
|
|
242
|
+
case "time": {
|
|
243
|
+
const utcOffset = text(args.utcOffset, "utcOffset", 6);
|
|
244
|
+
result.utcOffset = utcOffset;
|
|
245
|
+
if (!/^[+-](?:0\d|1\d|2[0-3]):[0-5]\d$/u.test(utcOffset))
|
|
246
|
+
throw failure("websearch_alpha.utcOffset is invalid");
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
export function alphaActionCommand(args) {
|
|
253
|
+
let value;
|
|
254
|
+
switch (args.action) {
|
|
255
|
+
case "search_query":
|
|
256
|
+
case "image_query":
|
|
257
|
+
value = {
|
|
258
|
+
q: args.query,
|
|
259
|
+
...(args.recency !== undefined ? { recency: args.recency } : {}),
|
|
260
|
+
...(args.domains ? { domains: args.domains } : {}),
|
|
261
|
+
};
|
|
262
|
+
break;
|
|
263
|
+
case "open":
|
|
264
|
+
value = {
|
|
265
|
+
ref_id: args.refId,
|
|
266
|
+
...(args.lineNumber !== undefined ? { lineno: args.lineNumber } : {}),
|
|
267
|
+
};
|
|
268
|
+
break;
|
|
269
|
+
case "find":
|
|
270
|
+
value = { ref_id: args.refId, pattern: args.pattern };
|
|
271
|
+
break;
|
|
272
|
+
case "click":
|
|
273
|
+
if (isAlphaHttpUrl(args.refId))
|
|
274
|
+
throw failure("websearch_alpha.click requires an opaque stored ref", "LCX_ALPHA_REF_REQUIRED");
|
|
275
|
+
value = { ref_id: args.refId, id: args.linkId };
|
|
276
|
+
break;
|
|
277
|
+
case "screenshot":
|
|
278
|
+
value = { ref_id: args.refId, pageno: args.pageNumber };
|
|
279
|
+
break;
|
|
280
|
+
case "finance":
|
|
281
|
+
value = {
|
|
282
|
+
ticker: args.ticker,
|
|
283
|
+
type: args.assetType,
|
|
284
|
+
...(args.market ? { market: args.market } : {}),
|
|
285
|
+
};
|
|
286
|
+
break;
|
|
287
|
+
case "weather":
|
|
288
|
+
value = {
|
|
289
|
+
location: args.location,
|
|
290
|
+
...(args.start ? { start: args.start } : {}),
|
|
291
|
+
...(args.duration !== undefined ? { duration: args.duration } : {}),
|
|
292
|
+
};
|
|
293
|
+
break;
|
|
294
|
+
case "sports":
|
|
295
|
+
value = {
|
|
296
|
+
tool: "sports",
|
|
297
|
+
fn: args.fn,
|
|
298
|
+
league: args.league,
|
|
299
|
+
...(args.team ? { team: args.team } : {}),
|
|
300
|
+
...(args.opponent ? { opponent: args.opponent } : {}),
|
|
301
|
+
...(args.dateFrom ? { date_from: args.dateFrom } : {}),
|
|
302
|
+
...(args.dateTo ? { date_to: args.dateTo } : {}),
|
|
303
|
+
...(args.numberOfGames !== undefined
|
|
304
|
+
? { num_games: args.numberOfGames }
|
|
305
|
+
: {}),
|
|
306
|
+
...(args.locale ? { locale: args.locale } : {}),
|
|
307
|
+
};
|
|
308
|
+
break;
|
|
309
|
+
case "time":
|
|
310
|
+
value = { utc_offset: args.utcOffset };
|
|
311
|
+
break;
|
|
312
|
+
default:
|
|
313
|
+
throw failure("websearch_alpha.action is invalid");
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
[args.action]: [value],
|
|
317
|
+
...(args.responseLength ? { response_length: args.responseLength } : {}),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function actionInput(args) {
|
|
321
|
+
return String(args.query ??
|
|
322
|
+
(args.refId
|
|
323
|
+
? `${args.action}: ${args.refId}`
|
|
324
|
+
: args.ticker
|
|
325
|
+
? `${args.action}: ${args.ticker}`
|
|
326
|
+
: args.location
|
|
327
|
+
? `${args.action}: ${args.location}`
|
|
328
|
+
: args.utcOffset
|
|
329
|
+
? `${args.action}: ${args.utcOffset}`
|
|
330
|
+
: `${args.action}: ${args.league ?? ""}`.trim()));
|
|
331
|
+
}
|
|
332
|
+
export function buildAlphaSearchBody(args, model, sessionId, externalWebAccess = true, maxOutputTokens = 2500) {
|
|
333
|
+
if (typeof sessionId !== "string" || !sessionId)
|
|
334
|
+
throw failure("websearch_alpha requires a DSH session", "LCX_ALPHA_SESSION_REQUIRED");
|
|
335
|
+
return {
|
|
336
|
+
id: sessionId,
|
|
337
|
+
model,
|
|
338
|
+
input: [
|
|
339
|
+
{
|
|
340
|
+
role: "user",
|
|
341
|
+
content: [{ type: "input_text", text: actionInput(args) }],
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
commands: alphaActionCommand(args),
|
|
345
|
+
settings: {
|
|
346
|
+
allowed_callers: ["direct"],
|
|
347
|
+
external_web_access: externalWebAccess,
|
|
348
|
+
},
|
|
349
|
+
max_output_tokens: maxOutputTokens,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
24
352
|
function ipv4Octets(hostname) {
|
|
25
|
-
|
|
26
|
-
|
|
353
|
+
const octets = hostname.split(".").map((part) => Number(part));
|
|
354
|
+
return octets.length === 4 &&
|
|
355
|
+
octets.every((part) => Number.isInteger(part) && part >= 0 && part <= 255)
|
|
356
|
+
? octets
|
|
357
|
+
: undefined;
|
|
27
358
|
}
|
|
28
|
-
|
|
29
359
|
function isPublicIpv4(hostname) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
360
|
+
const octets = ipv4Octets(hostname);
|
|
361
|
+
if (!octets)
|
|
362
|
+
return false;
|
|
363
|
+
const [first, second, third] = octets;
|
|
364
|
+
return (first !== 0 &&
|
|
365
|
+
first !== 10 &&
|
|
366
|
+
first !== 127 &&
|
|
367
|
+
!(first === 100 && second >= 64 && second <= 127) &&
|
|
368
|
+
!(first === 169 && second === 254) &&
|
|
369
|
+
!(first === 172 && second >= 16 && second <= 31) &&
|
|
370
|
+
!(first === 192 && second === 0 && third === 0) &&
|
|
371
|
+
!(first === 192 && second === 0 && third === 2) &&
|
|
372
|
+
!(first === 192 && second === 88 && third === 99) &&
|
|
373
|
+
!(first === 192 && second === 168) &&
|
|
374
|
+
!(first === 198 && second >= 18 && second <= 19) &&
|
|
375
|
+
!(first === 198 && second === 51 && third === 100) &&
|
|
376
|
+
!(first === 203 && second === 0 && third === 113) &&
|
|
377
|
+
first < 224);
|
|
378
|
+
}
|
|
47
379
|
function ipv6Groups(hostname) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
380
|
+
const segments = hostname
|
|
381
|
+
.replace(/^\[|\]$/gu, "")
|
|
382
|
+
.toLowerCase()
|
|
383
|
+
.split("::");
|
|
384
|
+
if (segments.length > 2)
|
|
385
|
+
return undefined;
|
|
386
|
+
const left = segments[0] ? segments[0].split(":") : [];
|
|
387
|
+
const right = segments.length === 2 && segments[1] ? segments[1].split(":") : [];
|
|
388
|
+
const missing = segments.length === 2 ? 8 - left.length - right.length : 0;
|
|
389
|
+
const values = [...left, ...Array(Math.max(0, missing)).fill("0"), ...right];
|
|
390
|
+
if (values.length !== 8 ||
|
|
391
|
+
(segments.length === 2 && missing < 1) ||
|
|
392
|
+
values.some((part) => !/^[0-9a-f]{1,4}$/u.test(part)))
|
|
393
|
+
return undefined;
|
|
394
|
+
return values.map((part) => Number.parseInt(part, 16));
|
|
395
|
+
}
|
|
58
396
|
function isPublicIpv6(hostname) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
397
|
+
const groups = ipv6Groups(hostname);
|
|
398
|
+
if (!groups)
|
|
399
|
+
return false;
|
|
400
|
+
const [first, second] = groups;
|
|
401
|
+
if ((first & 0xe000) !== 0x2000)
|
|
402
|
+
return false;
|
|
403
|
+
if (first === 0x3fff && (second & 0xf000) === 0)
|
|
404
|
+
return false;
|
|
405
|
+
if (first === 0x0100 && second === 0)
|
|
406
|
+
return false;
|
|
407
|
+
if ((first & 0xfe00) === 0xfc00 ||
|
|
408
|
+
(first & 0xffc0) === 0xfe80 ||
|
|
409
|
+
(first & 0xffc0) === 0xfec0 ||
|
|
410
|
+
(first & 0xff00) === 0xff00)
|
|
411
|
+
return false;
|
|
412
|
+
if (first === 0x2001 &&
|
|
413
|
+
(second === 0 ||
|
|
414
|
+
second === 0x0002 ||
|
|
415
|
+
(second >= 0x0010 && second <= 0x002f) ||
|
|
416
|
+
second === 0x0db8))
|
|
417
|
+
return false;
|
|
418
|
+
if (first === 0x0064 && second === 0xff9b && groups[2] === 0x0001)
|
|
419
|
+
return false;
|
|
420
|
+
return first !== 0x2002;
|
|
421
|
+
}
|
|
422
|
+
const RESERVED_HOSTNAME_SUFFIXES = [
|
|
423
|
+
".localhost",
|
|
424
|
+
".local",
|
|
425
|
+
".home.arpa",
|
|
426
|
+
".internal",
|
|
427
|
+
".test",
|
|
428
|
+
".example",
|
|
429
|
+
".invalid",
|
|
430
|
+
".onion",
|
|
431
|
+
".alt",
|
|
432
|
+
];
|
|
433
|
+
const RESERVED_DNS_SUFFIXES = ["ipv4only.arpa", "in-addr.arpa", "ip6.arpa"];
|
|
74
434
|
function isPublicHostname(hostname) {
|
|
75
|
-
|
|
435
|
+
return (hostname.includes(".") &&
|
|
436
|
+
!RESERVED_HOSTNAME_SUFFIXES.some((suffix) => hostname.endsWith(suffix)) &&
|
|
437
|
+
!RESERVED_DNS_SUFFIXES.some((suffix) => hostname === suffix || hostname.endsWith(`.${suffix}`)));
|
|
76
438
|
}
|
|
77
|
-
|
|
78
439
|
export function isPublicAlphaTarget(url) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
440
|
+
const hostname = String(url?.hostname ?? "")
|
|
441
|
+
.replace(/^\[|\]$/gu, "")
|
|
442
|
+
.replace(/\.$/u, "")
|
|
443
|
+
.toLowerCase();
|
|
444
|
+
if (!hostname)
|
|
445
|
+
return false;
|
|
446
|
+
const family = isIP(hostname);
|
|
447
|
+
if (family === 4)
|
|
448
|
+
return isPublicIpv4(hostname);
|
|
449
|
+
if (family === 6)
|
|
450
|
+
return isPublicIpv6(hostname);
|
|
451
|
+
return isPublicHostname(hostname);
|
|
452
|
+
}
|
|
87
453
|
export function isAlphaHttpUrl(value) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
454
|
+
if (typeof value !== "string" || !value.trim())
|
|
455
|
+
return false;
|
|
456
|
+
try {
|
|
457
|
+
const url = new URL(value);
|
|
458
|
+
return ["http:", "https:"].includes(url.protocol) && Boolean(url.hostname);
|
|
459
|
+
}
|
|
460
|
+
catch {
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
export function isAlphaContinuationUrl(value) {
|
|
465
|
+
if (typeof value !== "string" || !value.trim() || value !== value.trim())
|
|
466
|
+
return false;
|
|
467
|
+
try {
|
|
468
|
+
const url = new URL(value);
|
|
469
|
+
return (["http:", "https:"].includes(url.protocol) &&
|
|
470
|
+
Boolean(url.hostname) &&
|
|
471
|
+
!url.username &&
|
|
472
|
+
!url.password &&
|
|
473
|
+
isPublicAlphaTarget(url));
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
export function alphaRefRequiresStore(action, refId) {
|
|
480
|
+
return (action === "click" ||
|
|
481
|
+
(["open", "find", "screenshot"].includes(action) &&
|
|
482
|
+
!isAlphaContinuationUrl(refId)));
|
|
483
|
+
}
|
|
484
|
+
function httpUrl(value) {
|
|
485
|
+
return isAlphaContinuationUrl(value) ? new URL(value).toString() : undefined;
|
|
486
|
+
}
|
|
487
|
+
function safeResult(value, seen = new Set()) {
|
|
488
|
+
if (value === null || typeof value !== "object")
|
|
489
|
+
return value;
|
|
490
|
+
if (seen.has(value))
|
|
491
|
+
return undefined;
|
|
492
|
+
seen.add(value);
|
|
493
|
+
if (Array.isArray(value))
|
|
494
|
+
return value.map((x) => safeResult(x, seen)).filter((x) => x !== undefined);
|
|
495
|
+
const result = {};
|
|
496
|
+
for (const [key, item] of Object.entries(value)) {
|
|
497
|
+
if (key === "encrypted_output" || key === "encrypted_content")
|
|
498
|
+
continue;
|
|
499
|
+
if ([
|
|
500
|
+
"url",
|
|
501
|
+
"source_url",
|
|
502
|
+
"source_website_url",
|
|
503
|
+
"image_url",
|
|
504
|
+
"thumbnail_url",
|
|
505
|
+
].includes(key)) {
|
|
506
|
+
const u = httpUrl(item);
|
|
507
|
+
if (u)
|
|
508
|
+
result[key] = u;
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
const safe = safeResult(item, seen);
|
|
512
|
+
if (safe !== undefined)
|
|
513
|
+
result[key] = safe;
|
|
514
|
+
}
|
|
515
|
+
return result;
|
|
516
|
+
}
|
|
517
|
+
function artifacts(results) {
|
|
518
|
+
const refs = [], refRecords = [], sources = [], seenRefs = new Set(), seenSources = new Set();
|
|
519
|
+
const visit = (value) => {
|
|
520
|
+
if (!isObject(value) && !Array.isArray(value))
|
|
521
|
+
return;
|
|
522
|
+
if (Array.isArray(value)) {
|
|
523
|
+
value.forEach(visit);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
const candidate = typeof value.ref_id === "string" && value.ref_id
|
|
527
|
+
? value.ref_id
|
|
528
|
+
: typeof value.id === "string" && /^turn[\w-]+$/u.test(value.id)
|
|
529
|
+
? value.id
|
|
530
|
+
: undefined;
|
|
531
|
+
const refId = isAlphaHttpUrl(candidate) ? undefined : candidate;
|
|
532
|
+
const url = httpUrl(value.url ?? value.source_url ?? value.source_website_url ?? candidate);
|
|
533
|
+
if (refId && !seenRefs.has(refId)) {
|
|
534
|
+
seenRefs.add(refId);
|
|
535
|
+
refs.push(refId);
|
|
536
|
+
refRecords.push({ refId, ...(url ? { url } : {}) });
|
|
537
|
+
}
|
|
538
|
+
if (url && !seenSources.has(url)) {
|
|
539
|
+
seenSources.add(url);
|
|
540
|
+
sources.push({
|
|
541
|
+
url,
|
|
542
|
+
...(typeof value.title === "string" ? { title: value.title } : {}),
|
|
543
|
+
...(typeof value.snippet === "string"
|
|
544
|
+
? { snippet: value.snippet }
|
|
545
|
+
: {}),
|
|
546
|
+
...(refId ? { refId } : {}),
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
Object.values(value).forEach(visit);
|
|
550
|
+
};
|
|
551
|
+
visit(results);
|
|
552
|
+
return { refs, refRecords, sources };
|
|
553
|
+
}
|
|
554
|
+
const ACTION_ERROR = /^\s*(?:Error parsing function call\b|Invalid function_name=|Invalid function call\b)/iu;
|
|
555
|
+
const ALPHA_SEMANTIC_FAILURE = /^\s*(?:reference(?: id)?\s+(?:is\s+)?(?:invalid|unavailable)\b|unable to access requested content\b|service unavailable\b)/iu;
|
|
556
|
+
const ALPHA_COMMAND_ERROR_ENVELOPE = /^\s*Internal Error\s*\([^\r\n)]*\)\s*(?:\r?\n[ \t]*)+(?:\uE200cite\uE202[^\uE201\r\n]+\uE201[ \t]*(?:\[wordlim:\s*\d+\][ \t]*)?)?Unable to resolve (open|find|click|screenshot) call\s*:/iu;
|
|
557
|
+
const ALPHA_REFERENCE_ERROR_ENVELOPE = /^\s*(?:\*\*Result:\*\*[ \t]*)?Unable to (?:execute[ \t]+)?`?(open|find|click|screenshot)`?(?=[\s:])([^\r\n]*)/iu;
|
|
558
|
+
function alphaCommandErrorEnvelope(output, action) {
|
|
559
|
+
const match = String(output ?? "").match(ALPHA_COMMAND_ERROR_ENVELOPE);
|
|
560
|
+
if (match && match[1].toLowerCase() === action)
|
|
561
|
+
return true;
|
|
562
|
+
// Match the action failure header, never error phrases quoted inside a page.
|
|
563
|
+
const reference = String(output ?? "").match(ALPHA_REFERENCE_ERROR_ENVELOPE);
|
|
564
|
+
return Boolean(reference &&
|
|
565
|
+
reference[1].toLowerCase() === action &&
|
|
566
|
+
/\b(?:reference(?: id)?|turn[\w-]+)\b/iu.test(reference[2]) &&
|
|
567
|
+
/\b(?:invalid|unavailable|not available|unresolved)\b/iu.test(reference[2]));
|
|
568
|
+
}
|
|
569
|
+
export function parseAlphaSearchResponse(response, options) {
|
|
570
|
+
if (!isObject(response) ||
|
|
571
|
+
typeof response.output !== "string" ||
|
|
572
|
+
(response.results !== undefined && !Array.isArray(response.results)))
|
|
573
|
+
throw failure("LCX Alpha Web Search returned an invalid response", "LCX_ALPHA_INVALID_RESPONSE");
|
|
574
|
+
const action = typeof options.action === "string" ? options.action : undefined;
|
|
575
|
+
if (ACTION_ERROR.test(response.output) ||
|
|
576
|
+
(["open", "find", "click", "screenshot"].includes(action ?? "") &&
|
|
577
|
+
(ALPHA_SEMANTIC_FAILURE.test(response.output) ||
|
|
578
|
+
alphaCommandErrorEnvelope(response.output, action))))
|
|
579
|
+
throw failure("LCX Alpha Web Search could not execute the requested action", "LCX_ALPHA_ACTION_FAILED");
|
|
580
|
+
const results = safeResult(response.results ?? []);
|
|
581
|
+
const a = artifacts(results);
|
|
582
|
+
const outputBlocks = parseWebRunOutput(response.output);
|
|
583
|
+
for (const block of outputBlocks)
|
|
584
|
+
if (block.url) {
|
|
585
|
+
const url = httpUrl(block.url);
|
|
586
|
+
if (url)
|
|
587
|
+
block.url = url;
|
|
588
|
+
else
|
|
589
|
+
delete block.url;
|
|
590
|
+
}
|
|
591
|
+
for (const block of outputBlocks)
|
|
592
|
+
for (const ref of block.references ?? []) {
|
|
593
|
+
if (isAlphaHttpUrl(ref))
|
|
594
|
+
continue;
|
|
595
|
+
if (!a.refs.includes(ref))
|
|
596
|
+
a.refs.push(ref);
|
|
597
|
+
if (!a.refRecords.some((item) => item.refId === ref))
|
|
598
|
+
a.refRecords.push({
|
|
599
|
+
refId: ref,
|
|
600
|
+
...(block.url ? { url: block.url } : {}),
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
for (const source of outputBlocks.flatMap((b) => b.url ? [{ url: b.url, ...(b.title ? { title: b.title } : {}) }] : []))
|
|
604
|
+
if (!a.sources.some((x) => x.url === source.url))
|
|
605
|
+
a.sources.push(source);
|
|
606
|
+
return {
|
|
607
|
+
mode: "alpha",
|
|
608
|
+
action: options.action,
|
|
609
|
+
capability: options.capability,
|
|
610
|
+
emulation: options.capability === "native" ? "native" : "unknown",
|
|
611
|
+
content: response.output,
|
|
612
|
+
results,
|
|
613
|
+
refs: a.refs,
|
|
614
|
+
sources: a.sources,
|
|
615
|
+
citations: a.sources.map((s) => ({ ...s })),
|
|
616
|
+
outputBlocks,
|
|
617
|
+
links: outputLinks(outputBlocks),
|
|
618
|
+
pdfRefs: outputPdfRefs(outputBlocks),
|
|
619
|
+
domains: outputDomains(outputBlocks),
|
|
620
|
+
...(outputLineRange(outputBlocks)
|
|
621
|
+
? { lineRange: outputLineRange(outputBlocks) }
|
|
622
|
+
: {}),
|
|
623
|
+
requestId: options.requestId,
|
|
624
|
+
...(typeof response.id === "string" && response.id
|
|
625
|
+
? { responseId: response.id }
|
|
626
|
+
: {}),
|
|
627
|
+
retrievedAt: options.retrievedAt ?? new Date().toISOString(),
|
|
628
|
+
warnings: options.capability === "command-capable"
|
|
629
|
+
? [
|
|
630
|
+
"Alpha command behavior is verified, but trusted native backend provenance is unavailable.",
|
|
631
|
+
]
|
|
632
|
+
: [],
|
|
633
|
+
refRecords: a.refRecords,
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
export function renderAlphaSearchResult(value) {
|
|
637
|
+
const data = isObject(value) ? value : {};
|
|
638
|
+
const parts = [];
|
|
639
|
+
if (typeof data.content === "string")
|
|
640
|
+
parts.push(data.content);
|
|
641
|
+
if (Array.isArray(data.sources) && data.sources.length)
|
|
642
|
+
parts.push(`来源:\n${data.sources.filter(isObject).map((source) => `- [${String(source.title ?? source.url ?? "")}](${String(source.url ?? "")})`).join("\n")}`);
|
|
643
|
+
if (Array.isArray(data.warnings) && data.warnings.length)
|
|
644
|
+
parts.push(data.warnings.map((warning) => `警告:${String(warning)}`).join("\n"));
|
|
645
|
+
parts.push(`检索时间:${String(data.retrievedAt ?? "")}`);
|
|
646
|
+
return [{ type: "text", text: parts.filter(Boolean).join("\n\n") }];
|
|
647
|
+
}
|
|
648
|
+
function probeFailureState(error) {
|
|
649
|
+
const detail = isObject(error) ? error : {};
|
|
650
|
+
if ([404, 405].includes(detail.status) ||
|
|
651
|
+
["LCX_ALPHA_ACTION_UNAVAILABLE", "LCX_ALPHA_ACTION_FAILED"].includes(String(detail.code ?? "")) ||
|
|
652
|
+
/channel does not support|unsupported action|not implemented/iu.test(String(detail.message ?? "")))
|
|
653
|
+
return "unsupported";
|
|
654
|
+
return "unknown";
|
|
655
|
+
}
|
|
656
|
+
function alphaProbeStructuredResult(value, seen = new Set()) {
|
|
657
|
+
if (!value || typeof value !== "object" || seen.has(value))
|
|
658
|
+
return false;
|
|
659
|
+
seen.add(value);
|
|
660
|
+
if (Array.isArray(value))
|
|
661
|
+
return value.some((item) => alphaProbeStructuredResult(item, seen));
|
|
662
|
+
if (!isObject(value))
|
|
663
|
+
return false;
|
|
664
|
+
const refId = typeof value.ref_id === "string" && value.ref_id
|
|
665
|
+
? value.ref_id
|
|
666
|
+
: typeof value.id === "string" && /^turn[\w-]+$/u.test(value.id)
|
|
667
|
+
? value.id
|
|
668
|
+
: undefined;
|
|
669
|
+
if (refId && !isAlphaHttpUrl(refId))
|
|
670
|
+
return true;
|
|
671
|
+
if (["line", "line_number", "page", "page_number", "pageno"].some((field) => Number.isSafeInteger(value[field])))
|
|
672
|
+
return true;
|
|
673
|
+
return Object.values(value).some((item) => alphaProbeStructuredResult(item, seen));
|
|
674
|
+
}
|
|
675
|
+
function alphaProbeStructuredBlock(block) {
|
|
676
|
+
if (!isObject(block))
|
|
677
|
+
return false;
|
|
678
|
+
const references = Array.isArray(block.references) ? block.references : [];
|
|
679
|
+
const links = Array.isArray(block.links) ? block.links : [];
|
|
680
|
+
const metadata = Array.isArray(block.metadata) ? block.metadata : [];
|
|
681
|
+
const lines = Array.isArray(block.lines) ? block.lines : [];
|
|
682
|
+
if (references.some((ref) => typeof ref === "string" && ref && !isAlphaHttpUrl(ref)))
|
|
683
|
+
return true;
|
|
684
|
+
if (links.some((link) => isObject(link) && Number.isSafeInteger(link.id)))
|
|
685
|
+
return true;
|
|
686
|
+
if (metadata.some((item) => item === "HTML" || item === "PDF" || /^\d+ (?:lines|pages)$/u.test(String(item))))
|
|
687
|
+
return true;
|
|
688
|
+
return lines.some((line) => isObject(line) && (Number.isSafeInteger(line.line) || Number.isSafeInteger(line.page)));
|
|
689
|
+
}
|
|
690
|
+
const ALPHA_PROBE_SEMANTIC_FAILURE = /\breference(?: id)?\s+(?:is\s+)?(?:invalid|unavailable)\b/iu;
|
|
691
|
+
function alphaProbeResultHasEvidence(action, value) {
|
|
692
|
+
const data = isObject(value) ? value : {};
|
|
693
|
+
if (alphaCommandErrorEnvelope(data.content, action))
|
|
694
|
+
return false;
|
|
695
|
+
if (ALPHA_PROBE_SEMANTIC_FAILURE.test(String(data.content ?? "")) &&
|
|
696
|
+
!(Array.isArray(data.results) && data.results.length))
|
|
697
|
+
return false;
|
|
698
|
+
const refs = Array.isArray(data.refs) &&
|
|
699
|
+
data.refs.some((ref) => typeof ref === "string" && ref && !isAlphaHttpUrl(ref));
|
|
700
|
+
const links = Array.isArray(data.links) &&
|
|
701
|
+
data.links.some((link) => isObject(link) && Number.isSafeInteger(link.id));
|
|
702
|
+
const pdfRefs = Array.isArray(data.pdfRefs) &&
|
|
703
|
+
data.pdfRefs.some((ref) => typeof ref === "string" && ref && !isAlphaHttpUrl(ref));
|
|
704
|
+
const structuredResults = Array.isArray(data.results) &&
|
|
705
|
+
data.results.some((item) => alphaProbeStructuredResult(item));
|
|
706
|
+
const structuredBlocks = Array.isArray(data.outputBlocks) &&
|
|
707
|
+
data.outputBlocks.some((block) => alphaProbeStructuredBlock(block));
|
|
708
|
+
if (action === "find")
|
|
709
|
+
return Boolean(refs || structuredResults || structuredBlocks);
|
|
710
|
+
if (action === "click" || action === "screenshot")
|
|
711
|
+
return Boolean(refs || pdfRefs || structuredResults || structuredBlocks);
|
|
712
|
+
return Boolean(refs || links || pdfRefs || structuredResults || structuredBlocks);
|
|
713
|
+
}
|
|
714
|
+
export async function probeAlphaCapabilities({ invoke, schemaFingerprint, trustedNativeProvenance = false, actionProbes = {}, clickProbeRef, screenshotProbeRef, }) {
|
|
715
|
+
const actions = Object.fromEntries(ALPHA_ACTIONS.map((action) => [action, "unknown"]));
|
|
716
|
+
const result = {
|
|
717
|
+
classification: "unsupported",
|
|
718
|
+
actions,
|
|
719
|
+
probedAt: new Date().toISOString(),
|
|
720
|
+
schemaFingerprint,
|
|
721
|
+
probeVersion: ALPHA_PROBE_VERSION,
|
|
722
|
+
provenance: trustedNativeProvenance ? "trusted-native" : "unavailable",
|
|
723
|
+
};
|
|
724
|
+
let search;
|
|
725
|
+
try {
|
|
726
|
+
search = await invoke({
|
|
727
|
+
action: "search_query",
|
|
728
|
+
query: "OpenAI official documentation",
|
|
729
|
+
responseLength: "short",
|
|
730
|
+
});
|
|
731
|
+
actions.search_query = "supported";
|
|
732
|
+
}
|
|
733
|
+
catch (error) {
|
|
734
|
+
actions.search_query = probeFailureState(error);
|
|
735
|
+
result.classification =
|
|
736
|
+
actions.search_query === "unsupported" ? "unsupported" : "unknown";
|
|
737
|
+
return result;
|
|
738
|
+
}
|
|
739
|
+
const searchSources = Array.isArray(search.sources) ? search.sources : [];
|
|
740
|
+
const searchUrl = searchSources
|
|
741
|
+
.map((source) => isObject(source) ? httpUrl(source.url) : undefined)
|
|
742
|
+
.find((value) => value !== undefined);
|
|
743
|
+
const searchRefs = Array.isArray(search.refs) ? search.refs : [];
|
|
744
|
+
const searchRef = searchRefs[0];
|
|
745
|
+
const continuationTarget = searchUrl ?? searchRef;
|
|
746
|
+
if (!continuationTarget) {
|
|
747
|
+
result.classification = "emulated-search-only";
|
|
748
|
+
actions.open = "unsupported";
|
|
749
|
+
actions.find = "unsupported";
|
|
750
|
+
actions.click = "unsupported";
|
|
751
|
+
return result;
|
|
752
|
+
}
|
|
753
|
+
let opened;
|
|
754
|
+
try {
|
|
755
|
+
opened = await invoke({
|
|
756
|
+
action: "open",
|
|
757
|
+
refId: continuationTarget,
|
|
758
|
+
responseLength: "short",
|
|
759
|
+
});
|
|
760
|
+
if (!alphaProbeResultHasEvidence("open", opened)) {
|
|
761
|
+
actions.open = "unsupported";
|
|
762
|
+
result.classification = "emulated-search-only";
|
|
763
|
+
return result;
|
|
764
|
+
}
|
|
765
|
+
actions.open = "supported";
|
|
766
|
+
}
|
|
767
|
+
catch (error) {
|
|
768
|
+
actions.open = probeFailureState(error);
|
|
769
|
+
result.classification =
|
|
770
|
+
actions.open === "unsupported" ? "emulated-search-only" : "unknown";
|
|
771
|
+
return result;
|
|
772
|
+
}
|
|
773
|
+
const openedSources = opened && Array.isArray(opened.sources) ? opened.sources : [];
|
|
774
|
+
const openedUrl = openedSources
|
|
775
|
+
.map((source) => isObject(source) ? httpUrl(source.url) : undefined)
|
|
776
|
+
.find((value) => value !== undefined);
|
|
777
|
+
const openedRefs = opened && Array.isArray(opened.refs) ? opened.refs : [];
|
|
778
|
+
const findTarget = searchUrl ?? openedUrl ?? openedRefs[0] ?? continuationTarget;
|
|
779
|
+
try {
|
|
780
|
+
const found = await invoke({
|
|
781
|
+
action: "find",
|
|
782
|
+
refId: findTarget,
|
|
783
|
+
pattern: "OpenAI",
|
|
784
|
+
responseLength: "short",
|
|
785
|
+
});
|
|
786
|
+
actions.find = alphaProbeResultHasEvidence("find", found)
|
|
787
|
+
? "supported"
|
|
788
|
+
: "unsupported";
|
|
789
|
+
}
|
|
790
|
+
catch (error) {
|
|
791
|
+
actions.find = probeFailureState(error);
|
|
792
|
+
}
|
|
793
|
+
let clickPage = opened, clickProbeUsed = false;
|
|
794
|
+
if (!(clickPage && Array.isArray(clickPage.links) && clickPage.links.length > 0) && clickProbeRef) {
|
|
795
|
+
clickProbeUsed = true;
|
|
796
|
+
try {
|
|
797
|
+
clickPage = await invoke({
|
|
798
|
+
action: "open",
|
|
799
|
+
refId: clickProbeRef,
|
|
800
|
+
responseLength: "short",
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
catch (error) {
|
|
804
|
+
actions.click = probeFailureState(error);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
const clickRefs = clickPage && Array.isArray(clickPage.refs) ? clickPage.refs : [];
|
|
808
|
+
const clickLinks = clickPage && Array.isArray(clickPage.links) ? clickPage.links : [];
|
|
809
|
+
const clickRef = clickRefs[0];
|
|
810
|
+
const linkId = isObject(clickLinks[0]) ? clickLinks[0].id : undefined;
|
|
811
|
+
if (clickRef && Number.isSafeInteger(linkId)) {
|
|
812
|
+
try {
|
|
813
|
+
const clicked = await invoke({
|
|
814
|
+
action: "click",
|
|
815
|
+
refId: clickRef,
|
|
816
|
+
linkId,
|
|
817
|
+
responseLength: "short",
|
|
818
|
+
});
|
|
819
|
+
actions.click = alphaProbeResultHasEvidence("click", clicked)
|
|
820
|
+
? "supported"
|
|
821
|
+
: "unsupported";
|
|
822
|
+
}
|
|
823
|
+
catch (error) {
|
|
824
|
+
actions.click = probeFailureState(error);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
if (actions.find === "supported" ||
|
|
828
|
+
(actions.click === "supported" && !clickProbeUsed))
|
|
829
|
+
result.classification = trustedNativeProvenance
|
|
830
|
+
? "native"
|
|
831
|
+
: "command-capable";
|
|
832
|
+
else if (actions.find === "unsupported" && actions.click === "unsupported")
|
|
833
|
+
result.classification = "emulated-search-only";
|
|
834
|
+
else
|
|
835
|
+
result.classification = "unknown";
|
|
836
|
+
if (screenshotProbeRef) {
|
|
837
|
+
try {
|
|
838
|
+
const pdf = await invoke({
|
|
839
|
+
action: "open",
|
|
840
|
+
refId: screenshotProbeRef,
|
|
841
|
+
responseLength: "short",
|
|
842
|
+
});
|
|
843
|
+
const pdfRefs = Array.isArray(pdf.pdfRefs) ? pdf.pdfRefs : [];
|
|
844
|
+
const pdfRef = pdfRefs[0];
|
|
845
|
+
if (pdfRef) {
|
|
846
|
+
const shot = await invoke({
|
|
847
|
+
action: "screenshot",
|
|
848
|
+
refId: pdfRef,
|
|
849
|
+
pageNumber: 0,
|
|
850
|
+
responseLength: "short",
|
|
851
|
+
});
|
|
852
|
+
actions.screenshot = alphaProbeResultHasEvidence("screenshot", shot)
|
|
853
|
+
? "supported"
|
|
854
|
+
: "unsupported";
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
catch (error) {
|
|
858
|
+
actions.screenshot = probeFailureState(error);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
for (const [action, args] of Object.entries(actionProbes)) {
|
|
862
|
+
if (!["image_query", "finance", "weather", "sports", "time"].includes(action))
|
|
863
|
+
continue;
|
|
864
|
+
try {
|
|
865
|
+
const value = await invoke({ action, ...args, responseLength: "short" });
|
|
866
|
+
actions[action] = alphaProbeResultHasEvidence(action, value)
|
|
867
|
+
? "supported"
|
|
868
|
+
: "unknown";
|
|
869
|
+
}
|
|
870
|
+
catch (error) {
|
|
871
|
+
actions[action] = probeFailureState(error);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return result;
|
|
173
875
|
}
|