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
package/README.md
CHANGED
|
@@ -141,6 +141,7 @@ Use different providers for different tasks:
|
|
|
141
141
|
| [SerpBase] | ✔︎ | | | |
|
|
142
142
|
| [Serper] | ✔︎ | | | |
|
|
143
143
|
| [Sofya] | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
|
|
144
|
+
| [Tapline] | ✔︎ | | | |
|
|
144
145
|
| [Tavily] | ✔︎ | ✔︎ | | |
|
|
145
146
|
| [Valyu] | ✔︎ | ✔︎ | ✔︎ | ✔︎ |
|
|
146
147
|
| [You.com] | ✔︎ | | | |
|
|
@@ -160,6 +161,7 @@ Use different providers for different tasks:
|
|
|
160
161
|
[SerpBase]: ./docs/provider.md#serpbase
|
|
161
162
|
[Serper]: ./docs/provider.md#serper
|
|
162
163
|
[Sofya]: ./docs/provider.md#sofya
|
|
164
|
+
[Tapline]: ./docs/provider.md#tapline
|
|
163
165
|
[Tavily]: ./docs/provider.md#tavily
|
|
164
166
|
[Valyu]: ./docs/provider.md#valyu
|
|
165
167
|
[You.com]: ./docs/provider.md#youcom
|
|
@@ -363,8 +365,9 @@ and preserves partial failures. Large text results are saved to private files.
|
|
|
363
365
|
Interrupted requests are not replayed automatically, since providers may charge
|
|
364
366
|
for them. Cancelling a request may not cancel a provider's already-running job.
|
|
365
367
|
|
|
366
|
-
The adapter requires Pi Durable 1.
|
|
367
|
-
|
|
368
|
+
The adapter requires Pi Durable 1.6. It declares the `web` namespace and
|
|
369
|
+
structured result schemas for codemode, but does not install a CLI or register
|
|
370
|
+
standard Pi renderers.
|
|
368
371
|
|
|
369
372
|
## 🩺 Troubleshooting
|
|
370
373
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ambiguousContentsError,
|
|
3
|
+
asRecord,
|
|
4
|
+
describeHttpError,
|
|
5
|
+
formatJson,
|
|
6
|
+
joinUrl,
|
|
7
|
+
omittedContentsError,
|
|
8
|
+
pickSingleUrlOutcome,
|
|
9
|
+
requestJson,
|
|
10
|
+
requireApiKey,
|
|
11
|
+
trimSnippet
|
|
12
|
+
} from "./chunk-U4I3X7IN.js";
|
|
13
|
+
import {
|
|
14
|
+
WebfoxError
|
|
15
|
+
} from "./chunk-U4BLULLV.js";
|
|
16
|
+
|
|
17
|
+
// src/providers/parallel/adapter.ts
|
|
18
|
+
var DEFAULT_BASE_URL = "https://api.parallel.ai";
|
|
19
|
+
var adapter = {
|
|
20
|
+
async search(request, config, context) {
|
|
21
|
+
const response = await parallelRequest(
|
|
22
|
+
config,
|
|
23
|
+
context,
|
|
24
|
+
"/v1/search",
|
|
25
|
+
buildParallelSearchParams(request.query, request.maxResults, {
|
|
26
|
+
...request.options ?? {}
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
if (!Array.isArray(response.results)) {
|
|
30
|
+
throw new WebfoxError(
|
|
31
|
+
"PROVIDER_FAILURE",
|
|
32
|
+
"Parallel returned an invalid search response."
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
results: response.results.slice(0, request.maxResults).map((result) => ({
|
|
37
|
+
title: result.title ?? result.url,
|
|
38
|
+
url: result.url,
|
|
39
|
+
snippet: trimSnippet(result.excerpts?.join(" ") ?? "")
|
|
40
|
+
}))
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
async contents(request, config, context) {
|
|
44
|
+
const response = await parallelRequest(
|
|
45
|
+
config,
|
|
46
|
+
context,
|
|
47
|
+
"/v1/extract",
|
|
48
|
+
buildParallelExtractParams([request.url], {
|
|
49
|
+
...request.options ?? {}
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
const outcome = pickSingleUrlOutcome(
|
|
53
|
+
request.url,
|
|
54
|
+
response.results ?? [],
|
|
55
|
+
response.errors ?? []
|
|
56
|
+
);
|
|
57
|
+
if (outcome.kind === "result") {
|
|
58
|
+
const result = outcome.value;
|
|
59
|
+
return {
|
|
60
|
+
url: result.url,
|
|
61
|
+
content: result.full_content ?? result.excerpts?.join("\n\n") ?? void 0,
|
|
62
|
+
metadata: result
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (outcome.kind === "error") {
|
|
66
|
+
throw new WebfoxError("PROVIDER_FAILURE", formatJson(outcome.value));
|
|
67
|
+
}
|
|
68
|
+
if (outcome.kind === "ambiguous") {
|
|
69
|
+
throw ambiguousContentsError();
|
|
70
|
+
}
|
|
71
|
+
throw omittedContentsError();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
async function parallelRequest(config, context, path, body) {
|
|
75
|
+
const apiKey = requireApiKey(config);
|
|
76
|
+
const env = context.env ?? process.env;
|
|
77
|
+
const baseUrl = config.baseUrl?.trim() || env.PARALLEL_BASE_URL?.trim() || DEFAULT_BASE_URL;
|
|
78
|
+
return await requestJson(
|
|
79
|
+
joinUrl(baseUrl, path),
|
|
80
|
+
{
|
|
81
|
+
headers: { "x-api-key": apiKey },
|
|
82
|
+
body,
|
|
83
|
+
signal: context.signal
|
|
84
|
+
},
|
|
85
|
+
(payload, response) => describeHttpError("Parallel", payload, response)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
function buildParallelSearchParams(query, maxResults, options) {
|
|
89
|
+
const {
|
|
90
|
+
advanced_settings: advancedSettingsValue,
|
|
91
|
+
max_results: _legacyMaxResults,
|
|
92
|
+
mode: modeValue,
|
|
93
|
+
objective: objectiveValue,
|
|
94
|
+
search_queries: _searchQueries,
|
|
95
|
+
...rest
|
|
96
|
+
} = options;
|
|
97
|
+
const advancedSettings = { ...asRecord(advancedSettingsValue) ?? {} };
|
|
98
|
+
const mode = normalizeParallelSearchMode(modeValue);
|
|
99
|
+
const objective = typeof objectiveValue === "string" && objectiveValue.trim() ? objectiveValue.trim() : query;
|
|
100
|
+
return {
|
|
101
|
+
...rest,
|
|
102
|
+
search_queries: [query],
|
|
103
|
+
objective,
|
|
104
|
+
...mode ? { mode } : {},
|
|
105
|
+
advanced_settings: {
|
|
106
|
+
...advancedSettings,
|
|
107
|
+
max_results: maxResults
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function buildParallelExtractParams(urls, options) {
|
|
112
|
+
const {
|
|
113
|
+
advanced_settings: advancedSettingsValue,
|
|
114
|
+
excerpts: excerptsValue,
|
|
115
|
+
full_content: fullContentValue,
|
|
116
|
+
...rest
|
|
117
|
+
} = options;
|
|
118
|
+
const advancedSettings = { ...asRecord(advancedSettingsValue) ?? {} };
|
|
119
|
+
if (typeof fullContentValue === "boolean") {
|
|
120
|
+
advancedSettings.full_content = fullContentValue;
|
|
121
|
+
}
|
|
122
|
+
if (typeof excerptsValue === "boolean" && advancedSettings.excerpt_settings === void 0) {
|
|
123
|
+
advancedSettings.excerpt_settings = excerptsValue ? {} : { max_chars_per_result: 0 };
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
...rest,
|
|
127
|
+
urls,
|
|
128
|
+
advanced_settings: advancedSettings
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function normalizeParallelSearchMode(value) {
|
|
132
|
+
switch (value) {
|
|
133
|
+
case "advanced":
|
|
134
|
+
case "basic":
|
|
135
|
+
case "fast":
|
|
136
|
+
case "turbo":
|
|
137
|
+
return value;
|
|
138
|
+
default:
|
|
139
|
+
return void 0;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
export {
|
|
143
|
+
adapter
|
|
144
|
+
};
|
|
@@ -1,120 +1,97 @@
|
|
|
1
1
|
import {
|
|
2
2
|
executeAsyncResearch
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-WCTOYZVB.js";
|
|
3
|
+
} from "./chunk-I4HLGP7F.js";
|
|
4
|
+
import "./chunk-6UC3ZBNK.js";
|
|
6
5
|
import {
|
|
6
|
+
asRecord,
|
|
7
7
|
expectJsonBody,
|
|
8
8
|
formatJson,
|
|
9
9
|
joinUrl,
|
|
10
10
|
readResponseBody,
|
|
11
|
+
readString,
|
|
12
|
+
requireApiKey,
|
|
11
13
|
trimSnippet
|
|
12
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-U4I3X7IN.js";
|
|
13
15
|
import {
|
|
14
|
-
|
|
15
|
-
} from "./chunk-TYJ6RHKB.js";
|
|
16
|
-
import {
|
|
17
|
-
WebfoxError,
|
|
18
|
-
asWebfoxError
|
|
16
|
+
WebfoxError
|
|
19
17
|
} from "./chunk-U4BLULLV.js";
|
|
20
18
|
|
|
21
19
|
// src/providers/linkup/adapter.ts
|
|
22
20
|
var DEFAULT_BASE_URL = "https://api.linkup.so/v1";
|
|
23
|
-
var
|
|
24
|
-
async search(
|
|
21
|
+
var adapter = {
|
|
22
|
+
async search(request, config, context) {
|
|
25
23
|
const response = await linkupRequest(config, context, "/search", {
|
|
26
|
-
body: buildSearchParams(query, maxResults, {
|
|
27
|
-
...options ?? {}
|
|
24
|
+
body: buildSearchParams(request.query, request.maxResults, {
|
|
25
|
+
...request.options ?? {}
|
|
28
26
|
})
|
|
29
27
|
});
|
|
30
28
|
return {
|
|
31
|
-
|
|
32
|
-
results: (response.results ?? []).map(toSearchResult).filter((result) => result !== null).slice(0, maxResults)
|
|
29
|
+
results: (response.results ?? []).map(toSearchResult).filter((result) => result !== null).slice(0, request.maxResults)
|
|
33
30
|
};
|
|
34
31
|
},
|
|
35
|
-
async contents(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"rawHtml",
|
|
51
|
-
"contentType",
|
|
52
|
-
"images",
|
|
53
|
-
"favicon"
|
|
54
|
-
].includes(key) && value !== void 0
|
|
55
|
-
)
|
|
56
|
-
);
|
|
57
|
-
return {
|
|
58
|
-
url,
|
|
59
|
-
...response.markdown ? { content: response.markdown } : {},
|
|
60
|
-
...Object.keys(metadata).length ? { metadata } : {}
|
|
61
|
-
};
|
|
62
|
-
} catch (error) {
|
|
63
|
-
return {
|
|
64
|
-
url,
|
|
65
|
-
error: asWebfoxError(error).toJSON()
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
})
|
|
32
|
+
async contents(request, config, context) {
|
|
33
|
+
const response = await linkupRequest(config, context, "/fetch", {
|
|
34
|
+
body: buildFetchParams(request.url, {
|
|
35
|
+
...request.options ?? {}
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
const metadata = Object.fromEntries(
|
|
39
|
+
Object.entries(response).filter(
|
|
40
|
+
([key, value]) => [
|
|
41
|
+
"rawContent",
|
|
42
|
+
"rawHtml",
|
|
43
|
+
"contentType",
|
|
44
|
+
"images",
|
|
45
|
+
"favicon"
|
|
46
|
+
].includes(key) && value !== void 0
|
|
69
47
|
)
|
|
48
|
+
);
|
|
49
|
+
return {
|
|
50
|
+
url: request.url,
|
|
51
|
+
...response.markdown ? { content: response.markdown } : {},
|
|
52
|
+
...Object.keys(metadata).length ? { metadata } : {}
|
|
70
53
|
};
|
|
71
54
|
},
|
|
72
|
-
async research(
|
|
55
|
+
async research(request, config, context) {
|
|
73
56
|
return await executeAsyncResearch({
|
|
74
57
|
providerLabel: "Linkup",
|
|
75
|
-
providerId: "linkup",
|
|
76
58
|
context,
|
|
77
|
-
start: (researchContext) =>
|
|
78
|
-
|
|
79
|
-
config,
|
|
80
|
-
researchContext,
|
|
81
|
-
options
|
|
82
|
-
),
|
|
83
|
-
poll: (id, researchContext) => linkupImplementation.pollResearch(id, config, researchContext)
|
|
59
|
+
start: (researchContext) => startResearch(request.input, config, researchContext, request.options),
|
|
60
|
+
poll: (id, researchContext) => pollResearch(id, config, researchContext)
|
|
84
61
|
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
status: "completed",
|
|
103
|
-
output: formatResearchTaskOutput(task)
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
if (task.status === "failed") {
|
|
107
|
-
return {
|
|
108
|
-
status: "failed",
|
|
109
|
-
error: task.error ?? "research failed"
|
|
110
|
-
};
|
|
111
|
-
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
async function startResearch(input, config, context, options) {
|
|
65
|
+
const task = await linkupRequest(config, context, "/research", {
|
|
66
|
+
body: buildResearchParams(input, {
|
|
67
|
+
...options ?? {}
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
return { id: task.id };
|
|
71
|
+
}
|
|
72
|
+
async function pollResearch(id, config, context) {
|
|
73
|
+
const task = await linkupRequest(
|
|
74
|
+
config,
|
|
75
|
+
context,
|
|
76
|
+
`/research/${encodeURIComponent(id)}`
|
|
77
|
+
);
|
|
78
|
+
if (task.status === "completed") {
|
|
112
79
|
return {
|
|
113
|
-
status: "
|
|
114
|
-
|
|
80
|
+
status: "completed",
|
|
81
|
+
output: formatResearchTaskOutput(task)
|
|
115
82
|
};
|
|
116
83
|
}
|
|
117
|
-
|
|
84
|
+
if (task.status === "failed") {
|
|
85
|
+
return {
|
|
86
|
+
status: "failed",
|
|
87
|
+
error: task.error ?? "research failed"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
status: "in_progress",
|
|
92
|
+
statusText: task.status
|
|
93
|
+
};
|
|
94
|
+
}
|
|
118
95
|
function buildSearchParams(query, maxResults, options) {
|
|
119
96
|
const searchOptions = options;
|
|
120
97
|
if (searchOptions.query !== void 0) {
|
|
@@ -204,10 +181,7 @@ function serializeSchema(schema) {
|
|
|
204
181
|
return typeof schema === "string" ? schema : JSON.stringify(schema);
|
|
205
182
|
}
|
|
206
183
|
async function linkupRequest(config, context, path, init = {}) {
|
|
207
|
-
const apiKey = config
|
|
208
|
-
if (!apiKey) {
|
|
209
|
-
throw new Error("is missing an API key");
|
|
210
|
-
}
|
|
184
|
+
const apiKey = requireApiKey(config);
|
|
211
185
|
const response = await fetch(
|
|
212
186
|
joinUrl(config.baseUrl ?? DEFAULT_BASE_URL, path),
|
|
213
187
|
{
|
|
@@ -248,17 +222,16 @@ function linkupError(response, payload) {
|
|
|
248
222
|
}
|
|
249
223
|
function formatResearchTaskOutput(task) {
|
|
250
224
|
const output = task.output;
|
|
251
|
-
if (output == null) return {
|
|
252
|
-
if (typeof output === "string") return {
|
|
225
|
+
if (output == null) return { text: "" };
|
|
226
|
+
if (typeof output === "string") return { text: output };
|
|
253
227
|
const outputType = readString(asRecord(task.input)?.outputType);
|
|
254
228
|
const record = asRecord(output);
|
|
255
229
|
if (outputType !== "structured" && record && ("answer" in record || "sources" in record))
|
|
256
230
|
return {
|
|
257
|
-
provider: "linkup",
|
|
258
231
|
text: readString(record.answer) ?? "",
|
|
259
232
|
sources: readSources(record.sources)
|
|
260
233
|
};
|
|
261
|
-
return {
|
|
234
|
+
return { text: formatJson(output) };
|
|
262
235
|
}
|
|
263
236
|
function toSearchResult(value) {
|
|
264
237
|
const entry = asRecord(value);
|
|
@@ -302,12 +275,6 @@ function readSources(value) {
|
|
|
302
275
|
];
|
|
303
276
|
});
|
|
304
277
|
}
|
|
305
|
-
function asRecord(value) {
|
|
306
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
307
|
-
}
|
|
308
|
-
function readString(value) {
|
|
309
|
-
return typeof value === "string" ? value : void 0;
|
|
310
|
-
}
|
|
311
278
|
function toDate(value, name) {
|
|
312
279
|
const date = value instanceof Date ? value : new Date(value);
|
|
313
280
|
if (Number.isNaN(date.getTime())) {
|
|
@@ -317,35 +284,6 @@ function toDate(value, name) {
|
|
|
317
284
|
}
|
|
318
285
|
return date.toISOString().slice(0, 10);
|
|
319
286
|
}
|
|
320
|
-
var adapter = {
|
|
321
|
-
async search(input, config, context) {
|
|
322
|
-
return await linkupImplementation.search(
|
|
323
|
-
input.query,
|
|
324
|
-
input.maxResults,
|
|
325
|
-
config,
|
|
326
|
-
context,
|
|
327
|
-
input.options
|
|
328
|
-
);
|
|
329
|
-
},
|
|
330
|
-
async contents(input, config, context) {
|
|
331
|
-
return orderedContents(
|
|
332
|
-
await linkupImplementation.contents(
|
|
333
|
-
input.urls,
|
|
334
|
-
config,
|
|
335
|
-
context,
|
|
336
|
-
input.options
|
|
337
|
-
)
|
|
338
|
-
);
|
|
339
|
-
},
|
|
340
|
-
async research(input, config, context) {
|
|
341
|
-
return await linkupImplementation.research(
|
|
342
|
-
input.input,
|
|
343
|
-
config,
|
|
344
|
-
context,
|
|
345
|
-
input.options
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
287
|
export {
|
|
350
288
|
adapter
|
|
351
289
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
asRecord,
|
|
2
3
|
joinUrl,
|
|
4
|
+
readNonEmptyString,
|
|
3
5
|
requestJson,
|
|
6
|
+
requireApiKey,
|
|
4
7
|
trimSnippet
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-U4I3X7IN.js";
|
|
6
9
|
import {
|
|
7
10
|
WebfoxError
|
|
8
11
|
} from "./chunk-U4BLULLV.js";
|
|
@@ -22,8 +25,7 @@ var FORWARDED_OPTIONS = [
|
|
|
22
25
|
];
|
|
23
26
|
var adapter = {
|
|
24
27
|
async search(request, config, context) {
|
|
25
|
-
const apiKey = config
|
|
26
|
-
if (!apiKey) throw new Error("Keenable search is missing an API key");
|
|
28
|
+
const apiKey = requireApiKey(config, "api", "Keenable search");
|
|
27
29
|
const maxResults = Math.max(
|
|
28
30
|
1,
|
|
29
31
|
Math.min(MAX_RESULTS, Math.trunc(request.maxResults || 0))
|
|
@@ -58,34 +60,28 @@ var adapter = {
|
|
|
58
60
|
);
|
|
59
61
|
}
|
|
60
62
|
const results = entries.map(toSearchResult).filter((result) => result !== void 0);
|
|
61
|
-
return {
|
|
63
|
+
return { results: results.slice(0, maxResults) };
|
|
62
64
|
}
|
|
63
65
|
};
|
|
64
66
|
function describeError(payload, response) {
|
|
65
67
|
const record = asRecord(payload);
|
|
66
|
-
const detail =
|
|
68
|
+
const detail = readNonEmptyString(record?.detail) ?? readNonEmptyString(record?.error) ?? readNonEmptyString(record?.message) ?? (typeof payload === "string" ? readNonEmptyString(payload) : void 0) ?? (record ? JSON.stringify(record) : void 0);
|
|
67
69
|
const trimmed = detail?.trim().slice(0, 500);
|
|
68
70
|
return `Keenable search failed (HTTP ${response.status})${trimmed ? `: ${trimmed}` : "."}`;
|
|
69
71
|
}
|
|
70
72
|
function toSearchResult(entry) {
|
|
71
73
|
const record = asRecord(entry);
|
|
72
|
-
const url =
|
|
74
|
+
const url = readNonEmptyString(record?.url);
|
|
73
75
|
if (!record || !url) return void 0;
|
|
74
76
|
const { title, url: _url, description, snippet, ...metadata } = record;
|
|
75
|
-
const excerpt =
|
|
77
|
+
const excerpt = readNonEmptyString(snippet) ?? readNonEmptyString(description);
|
|
76
78
|
return {
|
|
77
|
-
title:
|
|
79
|
+
title: readNonEmptyString(title),
|
|
78
80
|
url,
|
|
79
81
|
snippet: excerpt ? trimSnippet(excerpt) : "",
|
|
80
82
|
...Object.keys(metadata).length > 0 ? { metadata } : {}
|
|
81
83
|
};
|
|
82
84
|
}
|
|
83
|
-
function asRecord(value) {
|
|
84
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
85
|
-
}
|
|
86
|
-
function text(value) {
|
|
87
|
-
return typeof value === "string" && value.trim() ? value : void 0;
|
|
88
|
-
}
|
|
89
85
|
export {
|
|
90
86
|
adapter
|
|
91
87
|
};
|