webfox 4.11.0 → 4.13.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 +5 -2
- package/dist/adapter-2HWVV4H7.js +144 -0
- package/dist/{adapter-QQZFHUOP.js → adapter-2V73476L.js} +69 -131
- package/dist/{adapter-SZMVKAMC.js → adapter-3V4OZDZZ.js} +10 -14
- package/dist/adapter-64462GL3.js +247 -0
- package/dist/{adapter-WXEVTCM3.js → adapter-BCZ4UE7S.js} +38 -81
- package/dist/{adapter-YVZ4YBK5.js → adapter-BHDA6JOK.js} +40 -56
- package/dist/adapter-EQ3LZTZ4.js +152 -0
- package/dist/adapter-EQSFB26L.js +58 -0
- package/dist/{adapter-ODDFBGJG.js → adapter-EXDS6465.js} +36 -57
- package/dist/adapter-IWGMWJ5A.js +121 -0
- package/dist/{adapter-XSQX3GAI.js → adapter-JQNYUBYZ.js} +33 -23
- package/dist/{adapter-VXT4C6RZ.js → adapter-OTMS6OEU.js} +81 -102
- package/dist/{adapter-MZ7USB6Q.js → adapter-PW4UL2DR.js} +12 -32
- package/dist/adapter-RBSOVQCV.js +84 -0
- package/dist/{adapter-GFXYSHKP.js → adapter-RJ334ZU5.js} +28 -76
- package/dist/{adapter-XU2APKPC.js → adapter-T6UEERC7.js} +19 -24
- package/dist/{adapter-BZO5UEI6.js → adapter-VVWNAGWI.js} +118 -142
- package/dist/{adapter-GJOUFE2U.js → adapter-XMEXVEMQ.js} +7 -10
- package/dist/adapter-ZLS55DG2.js +341 -0
- package/dist/{chunk-NENL6L6N.js → chunk-46OIVYHW.js} +1 -0
- package/dist/{chunk-WCTOYZVB.js → chunk-6UC3ZBNK.js} +15 -5
- package/dist/{chunk-YILOS4E7.js → chunk-7NTO6AQX.js} +110 -72
- package/dist/{chunk-PVNWACMT.js → chunk-EBKQHHCO.js} +199 -20
- package/dist/chunk-HZVTFUBC.js +139 -0
- package/dist/{chunk-LDVDVA4Z.js → chunk-I4HLGP7F.js} +3 -7
- package/dist/chunk-U4I3X7IN.js +267 -0
- package/dist/chunk-V4SQCDI3.js +336 -0
- package/dist/chunk-VMIDLDYP.js +111 -0
- package/dist/cli.js +9 -9
- package/dist/config.schema.json +222 -1
- package/dist/document-schema.d.ts +4 -4
- package/dist/domain.d.ts +1 -1
- package/dist/durable.js +73 -65
- package/dist/index.js +8 -7
- package/dist/pi-render.d.ts +3 -2
- package/dist/pi-shared.d.ts +39 -0
- package/dist/pi.js +87 -191
- package/dist/providers/brave/adapter.d.ts +4 -5
- package/dist/providers/cloudflare/adapter.d.ts +3 -2
- package/dist/providers/contract.d.ts +20 -19
- package/dist/providers/custom/adapter.d.ts +2 -2
- package/dist/providers/exa/adapter.d.ts +6 -6
- package/dist/providers/firecrawl/adapter.d.ts +5 -5
- package/dist/providers/gemini/adapter.d.ts +5 -10
- package/dist/providers/keenable/adapter.d.ts +2 -3
- package/dist/providers/linkup/adapter.d.ts +5 -5
- package/dist/providers/ollama/adapter.d.ts +4 -4
- package/dist/providers/openai/adapter.d.ts +4 -4
- package/dist/providers/openai/types.d.ts +2 -4
- package/dist/providers/parallel/adapter.d.ts +4 -4
- package/dist/providers/perplexity/adapter.d.ts +4 -5
- package/dist/providers/registry.d.ts +1 -0
- package/dist/providers/serpbase/types.d.ts +2 -4
- package/dist/providers/serper/adapter.d.ts +2 -2
- package/dist/providers/serper/types.d.ts +2 -4
- package/dist/providers/shared.d.ts +50 -0
- package/dist/providers/sofya/adapter.d.ts +6 -6
- package/dist/providers/tapline/adapter.d.ts +4 -0
- package/dist/providers/tapline/definition.d.ts +1 -0
- package/dist/providers/tavily/adapter.d.ts +4 -4
- package/dist/providers/valyu/adapter.d.ts +6 -6
- package/dist/providers/youcom/adapter.d.ts +2 -3
- package/dist/runtime/duration.d.ts +2 -0
- package/dist/runtime/execute.d.ts +3 -1
- package/dist/runtime/lifecycle.d.ts +0 -1
- package/dist/runtime/outward.d.ts +6 -1
- package/dist/runtime/polling.d.ts +2 -3
- package/docs/provider.md +29 -0
- package/package.json +14 -20
- package/dist/adapter-44ZBIK47.js +0 -121
- package/dist/adapter-57MELLYI.js +0 -160
- package/dist/adapter-D4EXZEDL.js +0 -213
- package/dist/adapter-DJCTEEOA.js +0 -159
- package/dist/adapter-DLNMW34W.js +0 -214
- package/dist/adapter-RR55EZAW.js +0 -73
- package/dist/chunk-FSTCLBSF.js +0 -76
- package/dist/chunk-I2UIACY3.js +0 -12
- package/dist/chunk-KMUCUJVN.js +0 -251
- package/dist/chunk-TYJ6RHKB.js +0 -31
- package/dist/chunk-VVOQKYOP.js +0 -112
- package/dist/contents.d.ts +0 -24
- package/dist/providers/brave/types.d.ts +0 -4
- package/dist/providers/exa/types.d.ts +0 -4
- package/dist/providers/firecrawl/types.d.ts +0 -4
- package/dist/providers/gemini/types.d.ts +0 -3
- package/dist/providers/keenable/types.d.ts +0 -4
- package/dist/providers/linkup/types.d.ts +0 -4
- package/dist/providers/ollama/types.d.ts +0 -4
- package/dist/providers/parallel/types.d.ts +0 -4
- package/dist/providers/perplexity/types.d.ts +0 -4
- package/dist/providers/sofya/types.d.ts +0 -4
- package/dist/providers/tavily/types.d.ts +0 -4
- package/dist/providers/valyu/types.d.ts +0 -4
- package/dist/providers/youcom/types.d.ts +0 -4
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeAsyncResearch
|
|
3
|
+
} from "./chunk-I4HLGP7F.js";
|
|
4
|
+
import {
|
|
5
|
+
sleep
|
|
6
|
+
} from "./chunk-6UC3ZBNK.js";
|
|
7
|
+
import {
|
|
8
|
+
ambiguousContentsError,
|
|
9
|
+
asRecord,
|
|
10
|
+
describeHttpError,
|
|
11
|
+
formatJson,
|
|
12
|
+
joinUrl,
|
|
13
|
+
omittedContentsError,
|
|
14
|
+
pickSingleUrlOutcome,
|
|
15
|
+
readNonEmptyString,
|
|
16
|
+
readResponseBody,
|
|
17
|
+
readSseJson,
|
|
18
|
+
readString,
|
|
19
|
+
requestJson,
|
|
20
|
+
requireApiKey,
|
|
21
|
+
trimSnippet
|
|
22
|
+
} from "./chunk-U4I3X7IN.js";
|
|
23
|
+
import {
|
|
24
|
+
WebfoxError,
|
|
25
|
+
httpError
|
|
26
|
+
} from "./chunk-U4BLULLV.js";
|
|
27
|
+
|
|
28
|
+
// src/providers/valyu/adapter.ts
|
|
29
|
+
var DEFAULT_BASE_URL = "https://api.valyu.ai/v1";
|
|
30
|
+
var adapter = {
|
|
31
|
+
async search(request, config, context) {
|
|
32
|
+
const response = await valyuRequest(
|
|
33
|
+
config,
|
|
34
|
+
context,
|
|
35
|
+
"/search",
|
|
36
|
+
buildSearchPayload(request.query, request.maxResults, request.options)
|
|
37
|
+
);
|
|
38
|
+
if (response.success === false) {
|
|
39
|
+
throw new Error(response.error || "search failed");
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
results: (response.results ?? []).slice(0, request.maxResults).map((result) => ({
|
|
43
|
+
title: result.title,
|
|
44
|
+
url: result.url,
|
|
45
|
+
snippet: trimSnippet(
|
|
46
|
+
result.description ?? (typeof result.content === "string" ? result.content : "")
|
|
47
|
+
),
|
|
48
|
+
score: result.relevance_score
|
|
49
|
+
}))
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
async contents(request, config, context) {
|
|
53
|
+
const response = await valyuRequest(
|
|
54
|
+
config,
|
|
55
|
+
context,
|
|
56
|
+
"/contents",
|
|
57
|
+
buildContentsPayload(request.url, request.options)
|
|
58
|
+
);
|
|
59
|
+
let finalResponse = response;
|
|
60
|
+
const jobId = readNonEmptyString(response.job_id ?? response.jobId);
|
|
61
|
+
if (jobId) {
|
|
62
|
+
while (true) {
|
|
63
|
+
context.signal?.throwIfAborted();
|
|
64
|
+
const status = await valyuRequest(
|
|
65
|
+
config,
|
|
66
|
+
context,
|
|
67
|
+
`/contents/jobs/${encodeURIComponent(jobId)}`
|
|
68
|
+
);
|
|
69
|
+
if (status.success === false || status.status !== void 0 && ["completed", "partial", "failed"].includes(status.status)) {
|
|
70
|
+
finalResponse = status;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
await sleep(3e3, context.signal);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (finalResponse.success === false) {
|
|
77
|
+
throw new Error(finalResponse.error || "contents failed");
|
|
78
|
+
}
|
|
79
|
+
const outcome = pickSingleUrlOutcome(
|
|
80
|
+
request.url,
|
|
81
|
+
finalResponse.results ?? []
|
|
82
|
+
);
|
|
83
|
+
if (outcome.kind === "omitted") throw omittedContentsError();
|
|
84
|
+
if (outcome.kind === "ambiguous") throw ambiguousContentsError();
|
|
85
|
+
const result = outcome.value;
|
|
86
|
+
if (result.status === "failed" || result.status === "not_found") {
|
|
87
|
+
throw new WebfoxError(
|
|
88
|
+
"PROVIDER_FAILURE",
|
|
89
|
+
result.error ?? formatJson(result)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
url: result.url,
|
|
94
|
+
...typeof result.content === "string" || typeof result.content === "number" ? { content: String(result.content) } : {},
|
|
95
|
+
...result.summary !== void 0 ? { summary: result.summary } : {},
|
|
96
|
+
metadata: result
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
async answer(request, config, context) {
|
|
100
|
+
const apiKey = requireApiKey(config);
|
|
101
|
+
const response = await fetch(
|
|
102
|
+
joinUrl(config.baseUrl ?? DEFAULT_BASE_URL, "/answer"),
|
|
103
|
+
{
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: {
|
|
106
|
+
Accept: "text/event-stream",
|
|
107
|
+
"Content-Type": "application/json",
|
|
108
|
+
"x-api-key": apiKey
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify(
|
|
111
|
+
buildAnswerPayload(request.query, request.options)
|
|
112
|
+
),
|
|
113
|
+
signal: context.signal
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
const payload = await readResponseBody(response);
|
|
118
|
+
throw httpError(response, describeHttpError("Valyu", payload, response));
|
|
119
|
+
}
|
|
120
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
121
|
+
if (contentType.includes("application/json")) {
|
|
122
|
+
const data = asRecord(await readResponseBody(response));
|
|
123
|
+
if (!data || data.success === false) {
|
|
124
|
+
throw new Error(readString(data?.error) || "answer failed");
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
text: formatAnswerContent(data.contents),
|
|
128
|
+
sources: Array.isArray(data.search_results) ? data.search_results : []
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
let fullContent = "";
|
|
132
|
+
let searchResults = [];
|
|
133
|
+
let finalMetadata;
|
|
134
|
+
await readSseJson(response, ({ event, data }) => {
|
|
135
|
+
const parsed = asRecord(data);
|
|
136
|
+
if (!parsed) return;
|
|
137
|
+
if (event === "error" || parsed.success === false) {
|
|
138
|
+
throw new WebfoxError(
|
|
139
|
+
"PROVIDER_FAILURE",
|
|
140
|
+
readNonEmptyString(parsed.error) ?? readNonEmptyString(parsed.message) ?? "answer failed"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (Array.isArray(parsed.search_results) && parsed.success === void 0) {
|
|
144
|
+
searchResults = [
|
|
145
|
+
...searchResults,
|
|
146
|
+
...parsed.search_results
|
|
147
|
+
];
|
|
148
|
+
} else if (Array.isArray(parsed.choices)) {
|
|
149
|
+
const delta = asRecord(asRecord(parsed.choices[0])?.delta);
|
|
150
|
+
const content = readString(delta?.content);
|
|
151
|
+
if (content) fullContent += content;
|
|
152
|
+
} else if (parsed.success !== void 0) {
|
|
153
|
+
finalMetadata = parsed;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
if (finalMetadata?.success === false) {
|
|
157
|
+
throw new Error(readString(finalMetadata.error) || "answer failed");
|
|
158
|
+
}
|
|
159
|
+
const contents = finalMetadata?.contents ?? fullContent;
|
|
160
|
+
const sources = Array.isArray(finalMetadata?.search_results) ? finalMetadata.search_results : searchResults;
|
|
161
|
+
return {
|
|
162
|
+
text: formatAnswerContent(contents),
|
|
163
|
+
sources
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
async research(request, config, context) {
|
|
167
|
+
return await executeAsyncResearch({
|
|
168
|
+
providerLabel: "Valyu",
|
|
169
|
+
context,
|
|
170
|
+
start: (researchContext) => startResearch(request.input, config, researchContext, request.options),
|
|
171
|
+
poll: (id, researchContext) => pollResearch(id, config, researchContext)
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
async function startResearch(input, config, context, options) {
|
|
176
|
+
const task = await valyuRequest(
|
|
177
|
+
config,
|
|
178
|
+
context,
|
|
179
|
+
"/deepresearch/tasks",
|
|
180
|
+
buildDeepResearchPayload(input, options)
|
|
181
|
+
);
|
|
182
|
+
if (task.success === false || !task.deepresearch_id) {
|
|
183
|
+
throw new Error(task.error || "deep research creation failed");
|
|
184
|
+
}
|
|
185
|
+
return { id: task.deepresearch_id };
|
|
186
|
+
}
|
|
187
|
+
async function pollResearch(id, config, context) {
|
|
188
|
+
const result = await valyuRequest(
|
|
189
|
+
config,
|
|
190
|
+
context,
|
|
191
|
+
`/deepresearch/tasks/${encodeURIComponent(id)}/status`
|
|
192
|
+
);
|
|
193
|
+
if (result.success === false) {
|
|
194
|
+
throw new Error(result.error || "deep research failed");
|
|
195
|
+
}
|
|
196
|
+
if (result.status === "completed") {
|
|
197
|
+
return {
|
|
198
|
+
status: "completed",
|
|
199
|
+
output: {
|
|
200
|
+
text: typeof result.output === "string" ? result.output : result.output ? formatJson(result.output) : "",
|
|
201
|
+
sources: result.sources ?? []
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (result.status === "failed") {
|
|
206
|
+
return {
|
|
207
|
+
status: "failed",
|
|
208
|
+
error: result.error || "research failed"
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (result.status === "cancelled") {
|
|
212
|
+
return {
|
|
213
|
+
status: "cancelled",
|
|
214
|
+
error: result.error || "research was canceled"
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
return { status: "in_progress" };
|
|
218
|
+
}
|
|
219
|
+
async function valyuRequest(config, context, path, body) {
|
|
220
|
+
const apiKey = requireApiKey(config);
|
|
221
|
+
return await requestJson(
|
|
222
|
+
joinUrl(config.baseUrl ?? DEFAULT_BASE_URL, path),
|
|
223
|
+
{
|
|
224
|
+
headers: { "x-api-key": apiKey },
|
|
225
|
+
...body === void 0 ? {} : { body },
|
|
226
|
+
signal: context.signal
|
|
227
|
+
},
|
|
228
|
+
(payload, response) => describeHttpError("Valyu", payload, response)
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
function buildSearchPayload(query, maxResults, options = {}) {
|
|
232
|
+
const payload = {
|
|
233
|
+
query,
|
|
234
|
+
search_type: typeof options.searchType === "string" ? options.searchType.toLowerCase() : "all",
|
|
235
|
+
max_num_results: maxResults,
|
|
236
|
+
is_tool_call: options.isToolCall ?? true,
|
|
237
|
+
relevance_threshold: options.relevanceThreshold ?? 0.5
|
|
238
|
+
};
|
|
239
|
+
const fieldMap = [
|
|
240
|
+
["maxPrice", "max_price"],
|
|
241
|
+
["includedSources", "included_sources"],
|
|
242
|
+
["excludeSources", "excluded_sources"],
|
|
243
|
+
["sourceBiases", "source_biases"],
|
|
244
|
+
["category", "category"],
|
|
245
|
+
["startDate", "start_date"],
|
|
246
|
+
["endDate", "end_date"],
|
|
247
|
+
["historicalCache", "historical_cache"],
|
|
248
|
+
["countryCode", "country_code"],
|
|
249
|
+
["responseLength", "response_length"],
|
|
250
|
+
["fastMode", "fast_mode"],
|
|
251
|
+
["urlOnly", "url_only"],
|
|
252
|
+
["instructions", "instructions"]
|
|
253
|
+
];
|
|
254
|
+
for (const [sourceKey, wireKey] of fieldMap) {
|
|
255
|
+
if (options[sourceKey] !== void 0) {
|
|
256
|
+
payload[wireKey] = options[sourceKey];
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return payload;
|
|
260
|
+
}
|
|
261
|
+
function buildContentsPayload(url, options = {}) {
|
|
262
|
+
const payload = { urls: [url] };
|
|
263
|
+
const fieldMap = [
|
|
264
|
+
["summary", "summary"],
|
|
265
|
+
["extractEffort", "extract_effort"],
|
|
266
|
+
["responseLength", "response_length"],
|
|
267
|
+
["maxPriceDollars", "max_price_dollars"],
|
|
268
|
+
["screenshot", "screenshot"],
|
|
269
|
+
["startDate", "start_date"],
|
|
270
|
+
["endDate", "end_date"],
|
|
271
|
+
["historicalCache", "historical_cache"]
|
|
272
|
+
];
|
|
273
|
+
for (const [sourceKey, wireKey] of fieldMap) {
|
|
274
|
+
if (options[sourceKey] !== void 0) {
|
|
275
|
+
payload[wireKey] = options[sourceKey];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return payload;
|
|
279
|
+
}
|
|
280
|
+
function buildAnswerPayload(query, options = {}) {
|
|
281
|
+
const payload = {
|
|
282
|
+
query: query.trim(),
|
|
283
|
+
search_type: typeof options.searchType === "string" ? options.searchType.toLowerCase() : "all"
|
|
284
|
+
};
|
|
285
|
+
const fieldMap = [
|
|
286
|
+
["dataMaxPrice", "data_max_price"],
|
|
287
|
+
["structuredOutput", "structured_output"],
|
|
288
|
+
["systemInstructions", "system_instructions"],
|
|
289
|
+
["countryCode", "country_code"],
|
|
290
|
+
["includedSources", "included_sources"],
|
|
291
|
+
["excludedSources", "excluded_sources"],
|
|
292
|
+
["startDate", "start_date"],
|
|
293
|
+
["endDate", "end_date"],
|
|
294
|
+
["fastMode", "fast_mode"]
|
|
295
|
+
];
|
|
296
|
+
for (const [sourceKey, wireKey] of fieldMap) {
|
|
297
|
+
if (options[sourceKey] !== void 0) {
|
|
298
|
+
payload[wireKey] = sourceKey === "systemInstructions" && typeof options[sourceKey] === "string" ? options[sourceKey].trim() : options[sourceKey];
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return payload;
|
|
302
|
+
}
|
|
303
|
+
function buildDeepResearchPayload(input, options = {}) {
|
|
304
|
+
const rawMode = readString(options.mode);
|
|
305
|
+
const mode = rawMode === "lite" ? "standard" : rawMode ?? "fast";
|
|
306
|
+
const payload = {
|
|
307
|
+
query: input,
|
|
308
|
+
mode,
|
|
309
|
+
output_formats: options.outputFormats ?? ["markdown"]
|
|
310
|
+
};
|
|
311
|
+
if (options.skills !== void 0) payload.skills = options.skills;
|
|
312
|
+
if (options.tools !== void 0) payload.tools = options.tools;
|
|
313
|
+
const searchOption = asRecord(options.search);
|
|
314
|
+
if (searchOption) {
|
|
315
|
+
const search = {};
|
|
316
|
+
const searchMap = [
|
|
317
|
+
["searchType", "search_type"],
|
|
318
|
+
["includedSources", "included_sources"],
|
|
319
|
+
["excludedSources", "excluded_sources"],
|
|
320
|
+
["sourceBiases", "source_biases"],
|
|
321
|
+
["startDate", "start_date"],
|
|
322
|
+
["endDate", "end_date"],
|
|
323
|
+
["historicalCache", "historical_cache"],
|
|
324
|
+
["category", "category"],
|
|
325
|
+
["countryCode", "country_code"]
|
|
326
|
+
];
|
|
327
|
+
for (const [sourceKey, wireKey] of searchMap) {
|
|
328
|
+
if (searchOption[sourceKey] !== void 0) {
|
|
329
|
+
search[wireKey] = searchOption[sourceKey];
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
payload.search = search;
|
|
333
|
+
}
|
|
334
|
+
return payload;
|
|
335
|
+
}
|
|
336
|
+
function formatAnswerContent(contents) {
|
|
337
|
+
return typeof contents === "string" ? contents : contents == null ? "" : formatJson(contents);
|
|
338
|
+
}
|
|
339
|
+
export {
|
|
340
|
+
adapter
|
|
341
|
+
};
|
|
@@ -2,6 +2,19 @@ import {
|
|
|
2
2
|
WebfoxError
|
|
3
3
|
} from "./chunk-U4BLULLV.js";
|
|
4
4
|
|
|
5
|
+
// src/runtime/duration.ts
|
|
6
|
+
function formatDuration(milliseconds) {
|
|
7
|
+
const seconds = Math.max(0, Math.floor(milliseconds / 1e3));
|
|
8
|
+
if (seconds < 60) return `${seconds}s`;
|
|
9
|
+
const minutes = Math.floor(seconds / 60);
|
|
10
|
+
if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
|
|
11
|
+
return `${Math.floor(minutes / 60)}h ${minutes % 60}m ${seconds % 60}s`;
|
|
12
|
+
}
|
|
13
|
+
function formatDeadline(ms) {
|
|
14
|
+
const [unit, divisor] = ms >= 36e5 ? ["h", 36e5] : ms >= 6e4 ? ["m", 6e4] : ms >= 1e3 ? ["s", 1e3] : ["ms", 1];
|
|
15
|
+
return `${Number((ms / divisor).toFixed(3))}${unit}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
5
18
|
// src/runtime/lifecycle.ts
|
|
6
19
|
function deadline(timeoutMs, parent) {
|
|
7
20
|
const controller = new AbortController();
|
|
@@ -12,7 +25,7 @@ function deadline(timeoutMs, parent) {
|
|
|
12
25
|
() => controller.abort(
|
|
13
26
|
new WebfoxError(
|
|
14
27
|
"TIMEOUT",
|
|
15
|
-
`Operation exceeded its ${
|
|
28
|
+
`Operation exceeded its ${formatDeadline(timeoutMs)} overall deadline.`
|
|
16
29
|
)
|
|
17
30
|
),
|
|
18
31
|
timeoutMs
|
|
@@ -25,10 +38,6 @@ function deadline(timeoutMs, parent) {
|
|
|
25
38
|
}
|
|
26
39
|
};
|
|
27
40
|
}
|
|
28
|
-
function formatDuration(ms) {
|
|
29
|
-
const [unit, divisor] = ms >= 36e5 ? ["h", 36e5] : ms >= 6e4 ? ["m", 6e4] : ms >= 1e3 ? ["s", 1e3] : ["ms", 1];
|
|
30
|
-
return `${Number((ms / divisor).toFixed(3))}${unit}`;
|
|
31
|
-
}
|
|
32
41
|
async function withSignal(promise, signal) {
|
|
33
42
|
if (!signal) return promise;
|
|
34
43
|
return new Promise((resolve, reject) => {
|
|
@@ -78,6 +87,7 @@ async function orderedMap(items, concurrency, work) {
|
|
|
78
87
|
}
|
|
79
88
|
|
|
80
89
|
export {
|
|
90
|
+
formatDuration,
|
|
81
91
|
deadline,
|
|
82
92
|
withSignal,
|
|
83
93
|
sleep,
|