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
|
@@ -2,11 +2,14 @@ import {
|
|
|
2
2
|
SERPBASE_MODES,
|
|
3
3
|
serpbaseProvider,
|
|
4
4
|
validateOptions
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-EBKQHHCO.js";
|
|
6
6
|
import {
|
|
7
|
+
asRecord,
|
|
8
|
+
readNonEmptyString,
|
|
9
|
+
requireApiKey,
|
|
7
10
|
trimSnippet
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-U4I3X7IN.js";
|
|
12
|
+
import "./chunk-46OIVYHW.js";
|
|
10
13
|
import {
|
|
11
14
|
WebfoxError,
|
|
12
15
|
httpError
|
|
@@ -31,8 +34,7 @@ var adapter = {
|
|
|
31
34
|
"SerpBase maps-detail requires a feature_id (0x...:0x...) in each queries entry. First use mode maps and copy the returned feature_id; names, place_id, CID, and Maps URLs are not accepted."
|
|
32
35
|
);
|
|
33
36
|
}
|
|
34
|
-
const apiKey = config
|
|
35
|
-
if (!apiKey) throw new Error("SerpBase search is missing an API key");
|
|
37
|
+
const apiKey = requireApiKey(config, "api", "SerpBase search");
|
|
36
38
|
const response = await fetch(
|
|
37
39
|
`${(config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "")}/google/${endpoint.path}`,
|
|
38
40
|
{
|
|
@@ -58,7 +60,7 @@ var adapter = {
|
|
|
58
60
|
const status = payload?.status;
|
|
59
61
|
const apiFailure = typeof status === "number" && status !== 0;
|
|
60
62
|
if (!response.ok || apiFailure) {
|
|
61
|
-
const detail = (
|
|
63
|
+
const detail = (readNonEmptyString(payload?.error) ?? body.trim()).slice(0, 500);
|
|
62
64
|
const message = `SerpBase ${mode} request failed (HTTP ${response.status}${apiFailure ? `, status ${status}` : ""})${detail ? `: ${detail}` : "."}`;
|
|
63
65
|
if (apiFailure) {
|
|
64
66
|
throw new WebfoxError("PROVIDER_FAILURE", message, {
|
|
@@ -81,7 +83,6 @@ var adapter = {
|
|
|
81
83
|
const entries = mode === "maps-detail" ? collection === void 0 ? [] : [collection] : collection ?? [];
|
|
82
84
|
const results = entries.map((entry) => toSearchResult(entry, searchContext, mode)).filter((result) => result !== void 0);
|
|
83
85
|
return {
|
|
84
|
-
provider: "serpbase",
|
|
85
86
|
// No upstream count parameter or automatic pagination: one page or place.
|
|
86
87
|
results: results.slice(
|
|
87
88
|
0,
|
|
@@ -95,12 +96,12 @@ function toSearchResult(entry, searchContext, mode) {
|
|
|
95
96
|
if (!record || mode === "images" && isNavigationImage(record))
|
|
96
97
|
return void 0;
|
|
97
98
|
const isPlace = mode === "maps" || mode === "maps-detail";
|
|
98
|
-
const featureId =
|
|
99
|
-
const url = isPlace ?
|
|
99
|
+
const featureId = readNonEmptyString(record.feature_id);
|
|
100
|
+
const url = isPlace ? readNonEmptyString(record.google_maps_url) ?? readNonEmptyString(record.url) ?? readNonEmptyString(record.website) ?? (featureId && FEATURE_ID.test(featureId) ? `https://www.google.com/maps?ftid=${encodeURIComponent(featureId)}` : void 0) : readNonEmptyString(record.link) ?? readNonEmptyString(record.url) ?? (mode === "images" ? readNonEmptyString(record.image_url) : void 0);
|
|
100
101
|
if (!url) return void 0;
|
|
101
102
|
const { title, link: _link, url: _url, snippet, ...metadata } = record;
|
|
102
103
|
return {
|
|
103
|
-
title:
|
|
104
|
+
title: readNonEmptyString(title) ?? readNonEmptyString(record.name),
|
|
104
105
|
url,
|
|
105
106
|
snippet: resultSnippet(record, mode),
|
|
106
107
|
metadata: { ...metadata, mode, searchContext }
|
|
@@ -108,13 +109,13 @@ function toSearchResult(entry, searchContext, mode) {
|
|
|
108
109
|
}
|
|
109
110
|
function resultSnippet(record, mode) {
|
|
110
111
|
const lines = [];
|
|
111
|
-
const excerpt =
|
|
112
|
+
const excerpt = readNonEmptyString(record.snippet) ?? readNonEmptyString(record.short_description) ?? readNonEmptyString(record.description);
|
|
112
113
|
if (excerpt && !(mode === "videos" && /^\s*Duration:\s*Posted:\s*$/i.test(excerpt)))
|
|
113
114
|
lines.push(trimSnippet(excerpt));
|
|
114
115
|
const add = (label, value, limit = 600) => {
|
|
115
116
|
if (typeof value === "number" && Number.isFinite(value))
|
|
116
117
|
value = String(value);
|
|
117
|
-
if (
|
|
118
|
+
if (readNonEmptyString(value))
|
|
118
119
|
lines.push(`${label}: ${trimSnippet(value, limit)}`);
|
|
119
120
|
};
|
|
120
121
|
const json = (label, value) => {
|
|
@@ -123,16 +124,16 @@ function resultSnippet(record, mode) {
|
|
|
123
124
|
};
|
|
124
125
|
if (mode === "images") {
|
|
125
126
|
add("Image URL", record.image_url, Infinity);
|
|
126
|
-
add("Source page",
|
|
127
|
+
add("Source page", readNonEmptyString(record.link) ?? readNonEmptyString(record.url), Infinity);
|
|
127
128
|
add(
|
|
128
129
|
"Thumbnail",
|
|
129
|
-
|
|
130
|
+
readNonEmptyString(record.thumbnail_url) ?? readNonEmptyString(record.thumbnail),
|
|
130
131
|
Infinity
|
|
131
132
|
);
|
|
132
|
-
add("Source",
|
|
133
|
+
add("Source", readNonEmptyString(record.source) ?? readNonEmptyString(record.domain));
|
|
133
134
|
} else if (mode === "news" || mode === "videos") {
|
|
134
135
|
add("Source", record.source);
|
|
135
|
-
const published =
|
|
136
|
+
const published = readNonEmptyString(record.published_at) ?? readNonEmptyString(record.time);
|
|
136
137
|
add(
|
|
137
138
|
published && /^\d{1,3}:\d{2}(?::\d{2})?$/.test(published.trim()) ? "Time (upstream)" : "Published",
|
|
138
139
|
published
|
|
@@ -140,7 +141,7 @@ function resultSnippet(record, mode) {
|
|
|
140
141
|
if (mode === "videos") add("Duration", record.duration);
|
|
141
142
|
add(
|
|
142
143
|
"Thumbnail",
|
|
143
|
-
|
|
144
|
+
readNonEmptyString(record.thumbnail_url) ?? readNonEmptyString(record.thumbnail),
|
|
144
145
|
Infinity
|
|
145
146
|
);
|
|
146
147
|
} else if (mode === "maps" || mode === "maps-detail") {
|
|
@@ -148,7 +149,7 @@ function resultSnippet(record, mode) {
|
|
|
148
149
|
add("Address", record.address);
|
|
149
150
|
add("Rating", record.rating);
|
|
150
151
|
add("Reviews", record.review_count);
|
|
151
|
-
add("Phone",
|
|
152
|
+
add("Phone", readNonEmptyString(record.phone_international) ?? readNonEmptyString(record.phone));
|
|
152
153
|
add("Website", record.website, Infinity);
|
|
153
154
|
if (typeof record.latitude === "number" && typeof record.longitude === "number")
|
|
154
155
|
add("Coordinates", `${record.latitude}, ${record.longitude}`);
|
|
@@ -172,12 +173,6 @@ function isNavigationImage(record) {
|
|
|
172
173
|
return false;
|
|
173
174
|
}
|
|
174
175
|
}
|
|
175
|
-
function asRecord(value) {
|
|
176
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
177
|
-
}
|
|
178
|
-
function text(value) {
|
|
179
|
-
return typeof value === "string" && value.trim() ? value : void 0;
|
|
180
|
-
}
|
|
181
176
|
export {
|
|
182
177
|
adapter
|
|
183
178
|
};
|
|
@@ -1,15 +1,23 @@
|
|
|
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
|
+
describeHttpError,
|
|
7
|
+
joinUrl,
|
|
8
|
+
readInteger,
|
|
9
|
+
readNonEmptyString,
|
|
10
|
+
readPositiveInteger,
|
|
11
|
+
readStringArray,
|
|
12
|
+
readStringUnion,
|
|
13
|
+
requestJson,
|
|
14
|
+
requireApiKey,
|
|
7
15
|
trimSnippet
|
|
8
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-U4I3X7IN.js";
|
|
9
17
|
import "./chunk-U4BLULLV.js";
|
|
10
18
|
|
|
11
19
|
// src/providers/openai/adapter.ts
|
|
12
|
-
|
|
20
|
+
var DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
13
21
|
var DEFAULT_SEARCH_MODEL = "gpt-4.1";
|
|
14
22
|
var DEFAULT_ANSWER_MODEL = "gpt-4.1";
|
|
15
23
|
var DEFAULT_RESEARCH_MODEL = "o4-mini-deep-research";
|
|
@@ -33,94 +41,106 @@ var searchResultSchema = {
|
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
43
|
};
|
|
36
|
-
var
|
|
37
|
-
async search(
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
var adapter = {
|
|
45
|
+
async search(request, config, context) {
|
|
46
|
+
const response = await openaiRequest(
|
|
47
|
+
config,
|
|
48
|
+
context,
|
|
49
|
+
"/responses",
|
|
50
|
+
buildOpenAISearchRequest(
|
|
51
|
+
request.query,
|
|
52
|
+
request.maxResults,
|
|
53
|
+
request.options
|
|
54
|
+
),
|
|
55
|
+
context.idempotencyKey
|
|
42
56
|
);
|
|
43
|
-
return parseSearchResponse(response, maxResults);
|
|
57
|
+
return parseSearchResponse(response, request.maxResults);
|
|
44
58
|
},
|
|
45
|
-
async answer(
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
async answer(request, config, context) {
|
|
60
|
+
const response = await openaiRequest(
|
|
61
|
+
config,
|
|
62
|
+
context,
|
|
63
|
+
"/responses",
|
|
64
|
+
buildOpenAIAnswerRequest(request.query, request.options),
|
|
65
|
+
context.idempotencyKey
|
|
50
66
|
);
|
|
51
67
|
return ensureCompletedResponse(response, "answer");
|
|
52
68
|
},
|
|
53
|
-
async research(
|
|
69
|
+
async research(request, config, context) {
|
|
54
70
|
return await executeAsyncResearch({
|
|
55
71
|
providerLabel: "OpenAI",
|
|
56
|
-
providerId: "openai",
|
|
57
72
|
context,
|
|
58
|
-
start: (researchContext) =>
|
|
59
|
-
|
|
60
|
-
config,
|
|
61
|
-
researchContext,
|
|
62
|
-
options
|
|
63
|
-
),
|
|
64
|
-
poll: (id, researchContext) => openaiImplementation.pollResearch(id, config, researchContext, options)
|
|
73
|
+
start: (researchContext) => startResearch(request.input, config, researchContext, request.options),
|
|
74
|
+
poll: (id, researchContext) => pollResearch(id, config, researchContext)
|
|
65
75
|
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
output: formatResponseOutput(response, "research")
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
if (status === "failed") {
|
|
90
|
-
return {
|
|
91
|
-
status: "failed",
|
|
92
|
-
error: response.error?.message ?? "research failed"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
if (status === "cancelled") {
|
|
96
|
-
return {
|
|
97
|
-
status: "cancelled",
|
|
98
|
-
error: "research was canceled"
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
if (status === "incomplete") {
|
|
102
|
-
return {
|
|
103
|
-
status: "failed",
|
|
104
|
-
error: formatIncompleteError(response, "research")
|
|
105
|
-
};
|
|
106
|
-
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
async function startResearch(input, config, context, options) {
|
|
79
|
+
const response = await openaiRequest(
|
|
80
|
+
config,
|
|
81
|
+
context,
|
|
82
|
+
"/responses",
|
|
83
|
+
buildOpenAIResearchRequest(input, options),
|
|
84
|
+
context.idempotencyKey
|
|
85
|
+
);
|
|
86
|
+
return { id: response.id };
|
|
87
|
+
}
|
|
88
|
+
async function pollResearch(id, config, context) {
|
|
89
|
+
const response = await openaiRequest(
|
|
90
|
+
config,
|
|
91
|
+
context,
|
|
92
|
+
`/responses/${encodeURIComponent(id)}`
|
|
93
|
+
);
|
|
94
|
+
const status = response.status ?? "completed";
|
|
95
|
+
if (status === "completed") {
|
|
107
96
|
return {
|
|
108
|
-
status: "
|
|
109
|
-
|
|
97
|
+
status: "completed",
|
|
98
|
+
output: formatResponseOutput(response)
|
|
110
99
|
};
|
|
111
100
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
if (status === "failed") {
|
|
102
|
+
return {
|
|
103
|
+
status: "failed",
|
|
104
|
+
error: response.error?.message ?? "research failed"
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (status === "cancelled") {
|
|
108
|
+
return {
|
|
109
|
+
status: "cancelled",
|
|
110
|
+
error: "research was canceled"
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (status === "incomplete") {
|
|
114
|
+
return {
|
|
115
|
+
status: "failed",
|
|
116
|
+
error: formatIncompleteError(response, "research")
|
|
117
|
+
};
|
|
117
118
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
return {
|
|
120
|
+
status: "in_progress",
|
|
121
|
+
statusText: status
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async function openaiRequest(config, context, path, body, idempotencyKey) {
|
|
125
|
+
const apiKey = requireApiKey(config);
|
|
126
|
+
const env = context.env ?? process.env;
|
|
127
|
+
const baseUrl = config.baseUrl?.trim() || env.OPENAI_BASE_URL?.trim() || DEFAULT_BASE_URL;
|
|
128
|
+
const organization = env.OPENAI_ORG_ID?.trim();
|
|
129
|
+
const project = env.OPENAI_PROJECT_ID?.trim();
|
|
130
|
+
return await requestJson(
|
|
131
|
+
joinUrl(baseUrl, path),
|
|
132
|
+
{
|
|
133
|
+
headers: {
|
|
134
|
+
Authorization: `Bearer ${apiKey}`,
|
|
135
|
+
...organization ? { "OpenAI-Organization": organization } : {},
|
|
136
|
+
...project ? { "OpenAI-Project": project } : {},
|
|
137
|
+
...idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}
|
|
138
|
+
},
|
|
139
|
+
...body === void 0 ? {} : { body },
|
|
140
|
+
signal: context.signal
|
|
141
|
+
},
|
|
142
|
+
(payload, response) => describeHttpError("OpenAI", payload, response)
|
|
143
|
+
);
|
|
124
144
|
}
|
|
125
145
|
function generationControls(options) {
|
|
126
146
|
const reasoning = options?.reasoning;
|
|
@@ -265,14 +285,20 @@ function resolveOpenAIResearchOptions(options) {
|
|
|
265
285
|
...resolveOpenAIWebSearchToolOptions(mergedOptions)
|
|
266
286
|
};
|
|
267
287
|
}
|
|
268
|
-
function
|
|
269
|
-
if (
|
|
270
|
-
return
|
|
288
|
+
function resolveOutputText(response) {
|
|
289
|
+
if (typeof response.output_text === "string") {
|
|
290
|
+
return response.output_text;
|
|
271
291
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
292
|
+
const texts = [];
|
|
293
|
+
for (const item of response.output ?? []) {
|
|
294
|
+
if (item.type !== "message" || !item.content) continue;
|
|
295
|
+
for (const content of item.content) {
|
|
296
|
+
if (content.type === "output_text" && typeof content.text === "string") {
|
|
297
|
+
texts.push(content.text);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return texts.join("");
|
|
276
302
|
}
|
|
277
303
|
function parseSearchResponse(response, maxResults) {
|
|
278
304
|
const status = response.status ?? "completed";
|
|
@@ -288,9 +314,8 @@ function parseSearchResponse(response, maxResults) {
|
|
|
288
314
|
if (status !== "completed") {
|
|
289
315
|
throw new Error(`search did not complete (status: ${status})`);
|
|
290
316
|
}
|
|
291
|
-
const payload = parseSearchPayload(response
|
|
317
|
+
const payload = parseSearchPayload(resolveOutputText(response));
|
|
292
318
|
return {
|
|
293
|
-
provider: "openai",
|
|
294
319
|
results: payload.sources.slice(0, maxResults).map((source) => ({
|
|
295
320
|
title: source.title.trim(),
|
|
296
321
|
url: source.url.trim(),
|
|
@@ -301,7 +326,7 @@ function parseSearchResponse(response, maxResults) {
|
|
|
301
326
|
function ensureCompletedResponse(response, operation) {
|
|
302
327
|
const status = response.status ?? "completed";
|
|
303
328
|
if (status === "completed") {
|
|
304
|
-
return formatResponseOutput(response
|
|
329
|
+
return formatResponseOutput(response);
|
|
305
330
|
}
|
|
306
331
|
if (status === "failed") {
|
|
307
332
|
throw new Error(response.error?.message ?? `${operation} failed`);
|
|
@@ -314,11 +339,10 @@ function ensureCompletedResponse(response, operation) {
|
|
|
314
339
|
}
|
|
315
340
|
throw new Error(`${operation} did not complete (status: ${status})`);
|
|
316
341
|
}
|
|
317
|
-
function formatResponseOutput(response
|
|
342
|
+
function formatResponseOutput(response) {
|
|
318
343
|
const citations = extractUrlCitations(response);
|
|
319
344
|
return {
|
|
320
|
-
|
|
321
|
-
text: response.output_text ?? "",
|
|
345
|
+
text: resolveOutputText(response),
|
|
322
346
|
sources: citations.map(({ title, url }) => ({ title, url })),
|
|
323
347
|
metadata: {
|
|
324
348
|
responseId: response.id,
|
|
@@ -330,7 +354,7 @@ function formatResponseOutput(response, operation) {
|
|
|
330
354
|
function extractUrlCitations(response) {
|
|
331
355
|
const citations = [];
|
|
332
356
|
const seen = /* @__PURE__ */ new Set();
|
|
333
|
-
for (const item of response.output) {
|
|
357
|
+
for (const item of response.output ?? []) {
|
|
334
358
|
if (item.type !== "message" || !item.content) {
|
|
335
359
|
continue;
|
|
336
360
|
}
|
|
@@ -412,21 +436,6 @@ function formatIncompleteError(response, operation) {
|
|
|
412
436
|
}
|
|
413
437
|
return `${operation} ended incomplete`;
|
|
414
438
|
}
|
|
415
|
-
function readNonEmptyString(value) {
|
|
416
|
-
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
417
|
-
}
|
|
418
|
-
function readStringArray(value) {
|
|
419
|
-
if (!Array.isArray(value)) {
|
|
420
|
-
return void 0;
|
|
421
|
-
}
|
|
422
|
-
const strings = value.filter(
|
|
423
|
-
(item) => typeof item === "string" && item.trim() !== ""
|
|
424
|
-
);
|
|
425
|
-
return strings.length > 0 ? strings : void 0;
|
|
426
|
-
}
|
|
427
|
-
function readStringUnion(value, values) {
|
|
428
|
-
return typeof value === "string" && values.includes(value) ? value : void 0;
|
|
429
|
-
}
|
|
430
439
|
function readUserLocation(value) {
|
|
431
440
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
432
441
|
return void 0;
|
|
@@ -444,39 +453,6 @@ function readUserLocation(value) {
|
|
|
444
453
|
};
|
|
445
454
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
446
455
|
}
|
|
447
|
-
function readPositiveInteger(value) {
|
|
448
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
|
|
449
|
-
}
|
|
450
|
-
function readInteger(value) {
|
|
451
|
-
return typeof value === "number" && Number.isInteger(value) ? value : void 0;
|
|
452
|
-
}
|
|
453
|
-
var adapter = {
|
|
454
|
-
async search(input, config, context) {
|
|
455
|
-
return await openaiImplementation.search(
|
|
456
|
-
input.query,
|
|
457
|
-
input.maxResults,
|
|
458
|
-
config,
|
|
459
|
-
context,
|
|
460
|
-
input.options
|
|
461
|
-
);
|
|
462
|
-
},
|
|
463
|
-
async answer(input, config, context) {
|
|
464
|
-
return await openaiImplementation.answer(
|
|
465
|
-
input.query,
|
|
466
|
-
config,
|
|
467
|
-
context,
|
|
468
|
-
input.options
|
|
469
|
-
);
|
|
470
|
-
},
|
|
471
|
-
async research(input, config, context) {
|
|
472
|
-
return await openaiImplementation.research(
|
|
473
|
-
input.input,
|
|
474
|
-
config,
|
|
475
|
-
context,
|
|
476
|
-
input.options
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
456
|
export {
|
|
481
457
|
adapter
|
|
482
458
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
+
readString,
|
|
3
|
+
requireApiKey,
|
|
2
4
|
trimSnippet
|
|
3
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-U4I3X7IN.js";
|
|
4
6
|
import {
|
|
5
7
|
httpError
|
|
6
8
|
} from "./chunk-U4BLULLV.js";
|
|
@@ -9,8 +11,7 @@ import {
|
|
|
9
11
|
var DEFAULT_BASE_URL = "https://ydc-index.io";
|
|
10
12
|
var adapter = {
|
|
11
13
|
async search(request, config, context) {
|
|
12
|
-
const apiKey = config.
|
|
13
|
-
if (!apiKey) throw new Error("You.com search is missing an API key");
|
|
14
|
+
const apiKey = requireApiKey(config, "api", "You.com search");
|
|
14
15
|
const options = asRecord(request.options);
|
|
15
16
|
const response = await fetch(joinUrl(config.baseUrl), {
|
|
16
17
|
method: "POST",
|
|
@@ -56,7 +57,6 @@ var adapter = {
|
|
|
56
57
|
if (news[index]) results.push(news[index]);
|
|
57
58
|
}
|
|
58
59
|
return {
|
|
59
|
-
provider: "youcom",
|
|
60
60
|
results: results.slice(0, clamp(request.maxResults, 100))
|
|
61
61
|
};
|
|
62
62
|
}
|
|
@@ -66,8 +66,8 @@ function joinUrl(baseUrl) {
|
|
|
66
66
|
}
|
|
67
67
|
function collectResults(results, section, searchMetadata) {
|
|
68
68
|
return array(results).map((entry) => asRecord(entry)).filter((entry) => Object.keys(entry).length > 0).map((entry) => {
|
|
69
|
-
const url =
|
|
70
|
-
const title =
|
|
69
|
+
const url = readString(entry.url) ?? "";
|
|
70
|
+
const title = readString(entry.title) ?? readString(entry.name);
|
|
71
71
|
return {
|
|
72
72
|
title,
|
|
73
73
|
url,
|
|
@@ -80,7 +80,7 @@ function buildSnippet(entry, section) {
|
|
|
80
80
|
const contents = asRecord(entry.contents);
|
|
81
81
|
const snippets = arrayOfStrings(entry.snippets);
|
|
82
82
|
if (snippets.length > 0) return trimSnippet(snippets.join("\n\n"), 1200);
|
|
83
|
-
const text =
|
|
83
|
+
const text = readString(entry.description) ?? readString(contents.markdown) ?? readString(contents.html) ?? (section === "news" ? readString(entry.page_age) : void 0) ?? "";
|
|
84
84
|
return trimSnippet(text);
|
|
85
85
|
}
|
|
86
86
|
function buildMetadata(entry, section, searchMetadata) {
|
|
@@ -112,9 +112,6 @@ function arrayOfStrings(value) {
|
|
|
112
112
|
function asRecord(value) {
|
|
113
113
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
114
114
|
}
|
|
115
|
-
function string(value) {
|
|
116
|
-
return typeof value === "string" ? value : void 0;
|
|
117
|
-
}
|
|
118
115
|
async function buildHttpError(response) {
|
|
119
116
|
const body = (await response.text()).trim();
|
|
120
117
|
return `You.com search request failed (${response.status}${response.statusText ? ` ${response.statusText}` : ""})${body ? `: ${body}` : "."}`;
|