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.
Files changed (95) hide show
  1. package/README.md +5 -2
  2. package/dist/adapter-2HWVV4H7.js +144 -0
  3. package/dist/{adapter-QQZFHUOP.js → adapter-2V73476L.js} +69 -131
  4. package/dist/{adapter-SZMVKAMC.js → adapter-3V4OZDZZ.js} +10 -14
  5. package/dist/adapter-64462GL3.js +247 -0
  6. package/dist/{adapter-WXEVTCM3.js → adapter-BCZ4UE7S.js} +38 -81
  7. package/dist/{adapter-YVZ4YBK5.js → adapter-BHDA6JOK.js} +40 -56
  8. package/dist/adapter-EQ3LZTZ4.js +152 -0
  9. package/dist/adapter-EQSFB26L.js +58 -0
  10. package/dist/{adapter-ODDFBGJG.js → adapter-EXDS6465.js} +36 -57
  11. package/dist/adapter-IWGMWJ5A.js +121 -0
  12. package/dist/{adapter-XSQX3GAI.js → adapter-JQNYUBYZ.js} +33 -23
  13. package/dist/{adapter-VXT4C6RZ.js → adapter-OTMS6OEU.js} +81 -102
  14. package/dist/{adapter-MZ7USB6Q.js → adapter-PW4UL2DR.js} +12 -32
  15. package/dist/adapter-RBSOVQCV.js +84 -0
  16. package/dist/{adapter-GFXYSHKP.js → adapter-RJ334ZU5.js} +28 -76
  17. package/dist/{adapter-XU2APKPC.js → adapter-T6UEERC7.js} +19 -24
  18. package/dist/{adapter-BZO5UEI6.js → adapter-VVWNAGWI.js} +118 -142
  19. package/dist/{adapter-GJOUFE2U.js → adapter-XMEXVEMQ.js} +7 -10
  20. package/dist/adapter-ZLS55DG2.js +341 -0
  21. package/dist/{chunk-NENL6L6N.js → chunk-46OIVYHW.js} +1 -0
  22. package/dist/{chunk-WCTOYZVB.js → chunk-6UC3ZBNK.js} +15 -5
  23. package/dist/{chunk-YILOS4E7.js → chunk-7NTO6AQX.js} +110 -72
  24. package/dist/{chunk-PVNWACMT.js → chunk-EBKQHHCO.js} +199 -20
  25. package/dist/chunk-HZVTFUBC.js +139 -0
  26. package/dist/{chunk-LDVDVA4Z.js → chunk-I4HLGP7F.js} +3 -7
  27. package/dist/chunk-U4I3X7IN.js +267 -0
  28. package/dist/chunk-V4SQCDI3.js +336 -0
  29. package/dist/chunk-VMIDLDYP.js +111 -0
  30. package/dist/cli.js +9 -9
  31. package/dist/config.schema.json +222 -1
  32. package/dist/document-schema.d.ts +4 -4
  33. package/dist/domain.d.ts +1 -1
  34. package/dist/durable.js +73 -65
  35. package/dist/index.js +8 -7
  36. package/dist/pi-render.d.ts +3 -2
  37. package/dist/pi-shared.d.ts +39 -0
  38. package/dist/pi.js +87 -191
  39. package/dist/providers/brave/adapter.d.ts +4 -5
  40. package/dist/providers/cloudflare/adapter.d.ts +3 -2
  41. package/dist/providers/contract.d.ts +20 -19
  42. package/dist/providers/custom/adapter.d.ts +2 -2
  43. package/dist/providers/exa/adapter.d.ts +6 -6
  44. package/dist/providers/firecrawl/adapter.d.ts +5 -5
  45. package/dist/providers/gemini/adapter.d.ts +5 -10
  46. package/dist/providers/keenable/adapter.d.ts +2 -3
  47. package/dist/providers/linkup/adapter.d.ts +5 -5
  48. package/dist/providers/ollama/adapter.d.ts +4 -4
  49. package/dist/providers/openai/adapter.d.ts +4 -4
  50. package/dist/providers/openai/types.d.ts +2 -4
  51. package/dist/providers/parallel/adapter.d.ts +4 -4
  52. package/dist/providers/perplexity/adapter.d.ts +4 -5
  53. package/dist/providers/registry.d.ts +1 -0
  54. package/dist/providers/serpbase/types.d.ts +2 -4
  55. package/dist/providers/serper/adapter.d.ts +2 -2
  56. package/dist/providers/serper/types.d.ts +2 -4
  57. package/dist/providers/shared.d.ts +50 -0
  58. package/dist/providers/sofya/adapter.d.ts +6 -6
  59. package/dist/providers/tapline/adapter.d.ts +4 -0
  60. package/dist/providers/tapline/definition.d.ts +1 -0
  61. package/dist/providers/tavily/adapter.d.ts +4 -4
  62. package/dist/providers/valyu/adapter.d.ts +6 -6
  63. package/dist/providers/youcom/adapter.d.ts +2 -3
  64. package/dist/runtime/duration.d.ts +2 -0
  65. package/dist/runtime/execute.d.ts +3 -1
  66. package/dist/runtime/lifecycle.d.ts +0 -1
  67. package/dist/runtime/outward.d.ts +6 -1
  68. package/dist/runtime/polling.d.ts +2 -3
  69. package/docs/provider.md +29 -0
  70. package/package.json +14 -20
  71. package/dist/adapter-44ZBIK47.js +0 -121
  72. package/dist/adapter-57MELLYI.js +0 -160
  73. package/dist/adapter-D4EXZEDL.js +0 -213
  74. package/dist/adapter-DJCTEEOA.js +0 -159
  75. package/dist/adapter-DLNMW34W.js +0 -214
  76. package/dist/adapter-RR55EZAW.js +0 -73
  77. package/dist/chunk-FSTCLBSF.js +0 -76
  78. package/dist/chunk-I2UIACY3.js +0 -12
  79. package/dist/chunk-KMUCUJVN.js +0 -251
  80. package/dist/chunk-TYJ6RHKB.js +0 -31
  81. package/dist/chunk-VVOQKYOP.js +0 -112
  82. package/dist/contents.d.ts +0 -24
  83. package/dist/providers/brave/types.d.ts +0 -4
  84. package/dist/providers/exa/types.d.ts +0 -4
  85. package/dist/providers/firecrawl/types.d.ts +0 -4
  86. package/dist/providers/gemini/types.d.ts +0 -3
  87. package/dist/providers/keenable/types.d.ts +0 -4
  88. package/dist/providers/linkup/types.d.ts +0 -4
  89. package/dist/providers/ollama/types.d.ts +0 -4
  90. package/dist/providers/parallel/types.d.ts +0 -4
  91. package/dist/providers/perplexity/types.d.ts +0 -4
  92. package/dist/providers/sofya/types.d.ts +0 -4
  93. package/dist/providers/tavily/types.d.ts +0 -4
  94. package/dist/providers/valyu/types.d.ts +0 -4
  95. package/dist/providers/youcom/types.d.ts +0 -4
@@ -1,213 +0,0 @@
1
- import {
2
- trimSnippet
3
- } from "./chunk-FSTCLBSF.js";
4
- import "./chunk-U4BLULLV.js";
5
-
6
- // src/providers/perplexity/adapter.ts
7
- import PerplexityClient from "@perplexity-ai/perplexity_ai";
8
- var DEFAULT_ANSWER_MODEL = "sonar";
9
- var DEFAULT_RESEARCH_MODEL = "sonar-deep-research";
10
- var perplexityImplementation = {
11
- async search(query, maxResults, config, context, options) {
12
- const client = createClient(config);
13
- const request = {
14
- ...options ?? {},
15
- query,
16
- max_results: maxResults
17
- };
18
- const response = await client.search.create(
19
- request,
20
- buildRequestOptions(context)
21
- );
22
- return {
23
- provider: "perplexity",
24
- results: response.results.slice(0, maxResults).map((result) => ({
25
- title: result.title,
26
- url: result.url,
27
- snippet: trimSnippet(result.snippet),
28
- metadata: result.date || result.last_updated ? {
29
- ...result.date ? { date: result.date } : {},
30
- ...result.last_updated ? { last_updated: result.last_updated } : {}
31
- } : void 0
32
- }))
33
- };
34
- },
35
- async answer(query, config, context, options) {
36
- return runSilentForegroundChatTool(
37
- query,
38
- config,
39
- context,
40
- DEFAULT_ANSWER_MODEL,
41
- options
42
- );
43
- },
44
- async research(input, config, context, options) {
45
- return runStreamingForegroundChatTool(
46
- input,
47
- config,
48
- context,
49
- DEFAULT_RESEARCH_MODEL,
50
- options
51
- );
52
- }
53
- };
54
- async function runSilentForegroundChatTool(input, config, context, fallbackModel, options) {
55
- const client = createClient(config);
56
- const request = {
57
- ...options ?? {},
58
- messages: [{ role: "user", content: input }],
59
- model: resolveModel(options?.model, fallbackModel),
60
- stream: false
61
- };
62
- const response = await client.chat.completions.create(
63
- request,
64
- buildRequestOptions(context)
65
- );
66
- const content = extractMessageText(response.choices[0]?.message?.content);
67
- const sources = dedupeSources(extractSources(response));
68
- return {
69
- provider: "perplexity",
70
- text: content,
71
- sources
72
- };
73
- }
74
- async function runStreamingForegroundChatTool(input, config, context, fallbackModel, options) {
75
- const client = createClient(config);
76
- const request = {
77
- ...options ?? {},
78
- messages: [{ role: "user", content: input }],
79
- model: resolveModel(options?.model, fallbackModel),
80
- stream: true
81
- };
82
- const stream = await client.chat.completions.create(
83
- request,
84
- buildRequestOptions(context)
85
- );
86
- let partialText = "";
87
- let lastChunk;
88
- const sources = [];
89
- for await (const chunk of stream) {
90
- lastChunk = chunk;
91
- const deltaText = extractDeltaText(chunk.choices[0]?.delta?.content);
92
- if (deltaText) {
93
- partialText = `${partialText}${deltaText}`;
94
- }
95
- sources.push(...extractSources(chunk));
96
- }
97
- const finalText = partialText.trim() || extractMessageText(lastChunk?.choices?.[0]?.message?.content);
98
- return {
99
- provider: "perplexity",
100
- text: finalText,
101
- sources: dedupeSources(sources)
102
- };
103
- }
104
- function createClient(config) {
105
- const apiKey = config.credentials?.api;
106
- if (!apiKey) {
107
- throw new Error("is missing an API key");
108
- }
109
- return new PerplexityClient({
110
- maxRetries: 0,
111
- apiKey,
112
- baseURL: config.baseUrl,
113
- ...shouldSendIntegrationHeader(config.baseUrl) ? { defaultHeaders: { "X-Pplx-Integration": "webfox" } } : {}
114
- });
115
- }
116
- function shouldSendIntegrationHeader(baseUrl) {
117
- const customHeaders = process.env.PERPLEXITY_CUSTOM_HEADERS ?? "";
118
- if (/^\s*x-pplx-integration\s*:/im.test(customHeaders)) return false;
119
- const url = baseUrl ?? process.env.PERPLEXITY_BASE_URL?.trim();
120
- if (!url) return true;
121
- try {
122
- return new URL(url).hostname === "api.perplexity.ai";
123
- } catch {
124
- return false;
125
- }
126
- }
127
- function resolveModel(optionModel, fallbackModel) {
128
- if (typeof optionModel === "string" && optionModel.trim().length > 0) {
129
- return optionModel;
130
- }
131
- return fallbackModel;
132
- }
133
- function extractMessageText(content) {
134
- if (typeof content === "string") {
135
- return content.trim();
136
- }
137
- if (!Array.isArray(content)) {
138
- return "";
139
- }
140
- return content.flatMap((chunk) => {
141
- if (typeof chunk === "object" && chunk !== null && "type" in chunk && chunk.type === "text" && "text" in chunk && typeof chunk.text === "string") {
142
- return [chunk.text.trim()];
143
- }
144
- return [];
145
- }).filter((text) => text.length > 0).join("\n\n").trim();
146
- }
147
- function extractDeltaText(content) {
148
- if (typeof content === "string") {
149
- return content;
150
- }
151
- if (!Array.isArray(content)) {
152
- return "";
153
- }
154
- return content.flatMap((chunk) => {
155
- if (typeof chunk === "object" && chunk !== null && "type" in chunk && chunk.type === "text" && "text" in chunk && typeof chunk.text === "string") {
156
- return [chunk.text];
157
- }
158
- return [];
159
- }).join("");
160
- }
161
- function dedupeSources(sources) {
162
- const seen = /* @__PURE__ */ new Set();
163
- return sources.filter((source) => {
164
- const key = `${source.title?.trim().toLowerCase() ?? ""}::${source.url?.trim().toLowerCase()}`;
165
- if (seen.has(key)) return false;
166
- seen.add(key);
167
- return true;
168
- });
169
- }
170
- function extractSources(response) {
171
- const searchResults = response.search_results?.flatMap(
172
- (result) => result.url?.trim() ? [{ title: result.title ?? void 0, url: result.url }] : []
173
- ) ?? [];
174
- if (searchResults.length > 0) {
175
- return searchResults;
176
- }
177
- return response.citations?.flatMap((citation) => {
178
- return citation?.trim() ? [{ url: citation }] : [];
179
- }) ?? [];
180
- }
181
- function buildRequestOptions(context) {
182
- return context.signal ? { signal: context.signal } : void 0;
183
- }
184
- var adapter = {
185
- async search(input, config, context) {
186
- return await perplexityImplementation.search(
187
- input.query,
188
- input.maxResults,
189
- config,
190
- context,
191
- input.options
192
- );
193
- },
194
- async answer(input, config, context) {
195
- return await perplexityImplementation.answer(
196
- input.query,
197
- config,
198
- context,
199
- input.options
200
- );
201
- },
202
- async research(input, config, context) {
203
- return await perplexityImplementation.research(
204
- input.input,
205
- config,
206
- context,
207
- input.options
208
- );
209
- }
210
- };
211
- export {
212
- adapter
213
- };
@@ -1,159 +0,0 @@
1
- import {
2
- formatJson,
3
- trimSnippet
4
- } from "./chunk-FSTCLBSF.js";
5
- import {
6
- omittedContents,
7
- orderedContents
8
- } from "./chunk-TYJ6RHKB.js";
9
- import "./chunk-U4BLULLV.js";
10
-
11
- // src/providers/parallel/adapter.ts
12
- import ParallelClient from "parallel-web";
13
- var parallelImplementation = {
14
- async search(query, maxResults, config, context, options) {
15
- const client = createClient(config);
16
- const response = await client.search(
17
- buildParallelSearchParams(query, maxResults, {
18
- ...options ?? {}
19
- }),
20
- buildRequestOptions(context)
21
- );
22
- return {
23
- provider: "parallel",
24
- results: response.results.slice(0, maxResults).map((result) => ({
25
- title: result.title ?? result.url,
26
- url: result.url,
27
- snippet: trimSnippet(result.excerpts?.join(" ") ?? "")
28
- }))
29
- };
30
- },
31
- async contents(urls, config, context, options) {
32
- const client = createClient(config);
33
- const response = await client.extract(
34
- buildParallelExtractParams(urls, {
35
- ...options ?? {}
36
- }),
37
- buildRequestOptions(context)
38
- );
39
- const resultsByUrl = new Map(
40
- response.results.map((result) => [result.url, result])
41
- );
42
- const errorsByUrl = new Map(
43
- response.errors.map((error) => [error.url, error])
44
- );
45
- return {
46
- provider: "parallel",
47
- answers: urls.map((url) => {
48
- const result = resultsByUrl.get(url) ?? (urls.length === 1 && response.results.length === 1 ? response.results[0] : void 0);
49
- if (result) {
50
- return {
51
- url: result.url,
52
- content: result.full_content ?? result.excerpts?.join("\n\n") ?? void 0,
53
- metadata: result
54
- };
55
- }
56
- const error = errorsByUrl.get(url) ?? (urls.length === 1 && response.errors.length === 1 ? response.errors[0] : void 0);
57
- return error ? {
58
- url,
59
- error: formatJson(error)
60
- } : omittedContents(url);
61
- })
62
- };
63
- }
64
- };
65
- function buildParallelSearchParams(query, maxResults, options) {
66
- const {
67
- advanced_settings: advancedSettingsValue,
68
- max_results: _legacyMaxResults,
69
- mode: modeValue,
70
- objective: objectiveValue,
71
- search_queries: _searchQueries,
72
- ...rest
73
- } = options;
74
- const advancedSettings = readObjectOption(advancedSettingsValue);
75
- const mode = normalizeParallelSearchMode(modeValue);
76
- const objective = typeof objectiveValue === "string" && objectiveValue.trim() ? objectiveValue.trim() : query;
77
- return {
78
- ...rest,
79
- search_queries: [query],
80
- objective,
81
- ...mode ? { mode } : {},
82
- advanced_settings: {
83
- ...advancedSettings,
84
- max_results: maxResults
85
- }
86
- };
87
- }
88
- function buildParallelExtractParams(urls, options) {
89
- const {
90
- advanced_settings: advancedSettingsValue,
91
- excerpts: excerptsValue,
92
- full_content: fullContentValue,
93
- ...rest
94
- } = options;
95
- const advancedSettings = readObjectOption(advancedSettingsValue);
96
- if (typeof fullContentValue === "boolean") {
97
- advancedSettings.full_content = fullContentValue;
98
- }
99
- if (typeof excerptsValue === "boolean" && advancedSettings.excerpt_settings === void 0) {
100
- advancedSettings.excerpt_settings = excerptsValue ? {} : { max_chars_per_result: 0 };
101
- }
102
- return {
103
- ...rest,
104
- urls,
105
- advanced_settings: advancedSettings
106
- };
107
- }
108
- function normalizeParallelSearchMode(value) {
109
- switch (value) {
110
- case "advanced":
111
- case "basic":
112
- case "fast":
113
- case "turbo":
114
- return value;
115
- default:
116
- return void 0;
117
- }
118
- }
119
- function readObjectOption(value) {
120
- return typeof value === "object" && value !== null && !Array.isArray(value) ? { ...value } : {};
121
- }
122
- function createClient(config) {
123
- const apiKey = config.credentials?.api;
124
- if (!apiKey) {
125
- throw new Error("is missing an API key");
126
- }
127
- return new ParallelClient({
128
- maxRetries: 0,
129
- apiKey,
130
- baseURL: config.baseUrl
131
- });
132
- }
133
- function buildRequestOptions(context) {
134
- return context.signal ? { signal: context.signal } : void 0;
135
- }
136
- var adapter = {
137
- async search(input, config, context) {
138
- return await parallelImplementation.search(
139
- input.query,
140
- input.maxResults,
141
- config,
142
- context,
143
- input.options
144
- );
145
- },
146
- async contents(input, config, context) {
147
- return orderedContents(
148
- await parallelImplementation.contents(
149
- input.urls,
150
- config,
151
- context,
152
- input.options
153
- )
154
- );
155
- }
156
- };
157
- export {
158
- adapter
159
- };
@@ -1,214 +0,0 @@
1
- import {
2
- executeAsyncResearch
3
- } from "./chunk-LDVDVA4Z.js";
4
- import "./chunk-I2UIACY3.js";
5
- import {
6
- sleep,
7
- withSignal
8
- } from "./chunk-WCTOYZVB.js";
9
- import {
10
- formatJson,
11
- trimSnippet
12
- } from "./chunk-FSTCLBSF.js";
13
- import {
14
- omittedContents,
15
- orderedContents
16
- } from "./chunk-TYJ6RHKB.js";
17
- import "./chunk-U4BLULLV.js";
18
-
19
- // src/providers/valyu/adapter.ts
20
- import { Valyu as ValyuClient } from "valyu-js";
21
- var valyuImplementation = {
22
- async search(query, maxResults, config, _context, searchOptions) {
23
- const client = createClient(config);
24
- const options = {
25
- ...searchOptions ?? {},
26
- maxNumResults: maxResults
27
- };
28
- const response = await client.search(query, options);
29
- if (!response.success) {
30
- throw new Error(response.error || "search failed");
31
- }
32
- return {
33
- provider: "valyu",
34
- results: (response.results ?? []).slice(0, maxResults).map((result) => ({
35
- title: result.title,
36
- url: result.url,
37
- snippet: trimSnippet(
38
- result.description ?? (typeof result.content === "string" ? result.content : "")
39
- ),
40
- score: result.relevance_score
41
- }))
42
- };
43
- },
44
- async contents(urls, config, context, options) {
45
- const client = createClient(config);
46
- const response = await client.contents(urls, {
47
- ...options ?? {}
48
- });
49
- let finalResponse;
50
- if ("jobId" in response) {
51
- while (true) {
52
- context.signal?.throwIfAborted();
53
- const status = await withSignal(
54
- client.getContentsJob(response.jobId),
55
- context.signal
56
- );
57
- if (!status.success || ["completed", "partial", "failed"].includes(status.status)) {
58
- finalResponse = status;
59
- break;
60
- }
61
- await sleep(3e3, context.signal);
62
- }
63
- } else finalResponse = response;
64
- if (!finalResponse.success) {
65
- throw new Error(finalResponse.error || "contents failed");
66
- }
67
- const resultsByUrl = new Map(
68
- (finalResponse.results ?? []).map(
69
- (result) => [result.url, result]
70
- )
71
- );
72
- return {
73
- provider: "valyu",
74
- answers: urls.map((url) => {
75
- const result = resultsByUrl.get(url) ?? (urls.length === 1 && finalResponse.results?.length === 1 ? finalResponse.results[0] : void 0);
76
- if (!result) {
77
- return omittedContents(url);
78
- }
79
- if (result.status === "failed" || result.status === "not_found") {
80
- return {
81
- url,
82
- error: result.error ?? formatJson(result)
83
- };
84
- }
85
- const page = result;
86
- return {
87
- url: page.url,
88
- ...typeof page.content === "string" || typeof page.content === "number" ? { content: String(page.content) } : {},
89
- ...page.summary !== void 0 ? { summary: page.summary } : {},
90
- metadata: page
91
- };
92
- })
93
- };
94
- },
95
- async answer(query, config, _context, options) {
96
- const client = createClient(config);
97
- const response = await client.answer(query, {
98
- ...options ?? {},
99
- streaming: false
100
- });
101
- if (!("success" in response) || !response.success) {
102
- throw new Error(
103
- "error" in response && typeof response.error === "string" ? response.error : "answer failed"
104
- );
105
- }
106
- return {
107
- provider: "valyu",
108
- text: typeof response.contents === "string" ? response.contents : response.contents == null ? "" : formatJson(response.contents),
109
- sources: response.search_results ?? []
110
- };
111
- },
112
- async research(input, config, context, options) {
113
- return await executeAsyncResearch({
114
- providerLabel: "Valyu",
115
- providerId: "valyu",
116
- context,
117
- start: (researchContext) => valyuImplementation.startResearch(
118
- input,
119
- config,
120
- researchContext,
121
- options
122
- ),
123
- poll: (id, researchContext) => valyuImplementation.pollResearch(id, config, researchContext, options)
124
- });
125
- },
126
- async startResearch(input, config, _context, options) {
127
- const client = createClient(config);
128
- const task = await client.deepresearch.create({
129
- input,
130
- ...options ?? {}
131
- });
132
- if (!task.success || !task.deepresearch_id) {
133
- throw new Error(task.error || "deep research creation failed");
134
- }
135
- return { id: task.deepresearch_id };
136
- },
137
- async pollResearch(id, config, _context, _options) {
138
- const client = createClient(config);
139
- const result = await client.deepresearch.status(id);
140
- if (!result.success) {
141
- throw new Error(result.error || "deep research failed");
142
- }
143
- if (result.status === "completed") {
144
- return {
145
- status: "completed",
146
- output: {
147
- provider: "valyu",
148
- text: typeof result.output === "string" ? result.output : result.output ? formatJson(result.output) : "",
149
- sources: result.sources ?? []
150
- }
151
- };
152
- }
153
- if (result.status === "failed") {
154
- return {
155
- status: "failed",
156
- error: result.error || "research failed"
157
- };
158
- }
159
- if (result.status === "cancelled") {
160
- return {
161
- status: "cancelled",
162
- error: result.error || "research was canceled"
163
- };
164
- }
165
- return { status: "in_progress" };
166
- }
167
- };
168
- function createClient(config) {
169
- const apiKey = config.credentials?.api;
170
- if (!apiKey) {
171
- throw new Error("is missing an API key");
172
- }
173
- return new ValyuClient(apiKey, config.baseUrl);
174
- }
175
- var adapter = {
176
- async search(input, config, context) {
177
- return await valyuImplementation.search(
178
- input.query,
179
- input.maxResults,
180
- config,
181
- context,
182
- input.options
183
- );
184
- },
185
- async contents(input, config, context) {
186
- return orderedContents(
187
- await valyuImplementation.contents(
188
- input.urls,
189
- config,
190
- context,
191
- input.options
192
- )
193
- );
194
- },
195
- async answer(input, config, context) {
196
- return await valyuImplementation.answer(
197
- input.query,
198
- config,
199
- context,
200
- input.options
201
- );
202
- },
203
- async research(input, config, context) {
204
- return await valyuImplementation.research(
205
- input.input,
206
- config,
207
- context,
208
- input.options
209
- );
210
- }
211
- };
212
- export {
213
- adapter
214
- };
@@ -1,73 +0,0 @@
1
- import {
2
- orderedContents
3
- } from "./chunk-TYJ6RHKB.js";
4
- import {
5
- asWebfoxError
6
- } from "./chunk-U4BLULLV.js";
7
-
8
- // src/providers/cloudflare/adapter.ts
9
- import CloudflareClient from "cloudflare";
10
- var cloudflareImplementation = {
11
- async contents(urls, config, context, options) {
12
- const client = createClient(config);
13
- const accountId = config.accountId;
14
- if (!accountId) {
15
- throw new Error("is missing an account ID");
16
- }
17
- const answers = await Promise.all(
18
- urls.map(async (url) => {
19
- try {
20
- const markdown = await client.browserRendering.markdown.create(
21
- {
22
- ...options ?? {},
23
- account_id: accountId,
24
- url
25
- },
26
- buildRequestOptions(context)
27
- );
28
- return {
29
- url,
30
- content: markdown
31
- };
32
- } catch (error) {
33
- return {
34
- url,
35
- error: asWebfoxError(error).toJSON()
36
- };
37
- }
38
- })
39
- );
40
- return {
41
- provider: "cloudflare",
42
- answers
43
- };
44
- }
45
- };
46
- function createClient(config) {
47
- const apiToken = config.credentials?.api;
48
- if (!apiToken) {
49
- throw new Error("is missing an API token");
50
- }
51
- return new CloudflareClient({
52
- maxRetries: 0,
53
- apiToken
54
- });
55
- }
56
- function buildRequestOptions(context) {
57
- return context.signal ? { signal: context.signal } : void 0;
58
- }
59
- var adapter = {
60
- async contents(input, config, context) {
61
- return orderedContents(
62
- await cloudflareImplementation.contents(
63
- input.urls,
64
- config,
65
- context,
66
- input.options
67
- )
68
- );
69
- }
70
- };
71
- export {
72
- adapter
73
- };