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/dist/chunk-FSTCLBSF.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WebfoxError,
|
|
3
|
-
httpError
|
|
4
|
-
} from "./chunk-U4BLULLV.js";
|
|
5
|
-
|
|
6
|
-
// src/providers/shared.ts
|
|
7
|
-
function trimSnippet(input, maxLength = 300) {
|
|
8
|
-
const text = (input ?? "").replace(/\s+/g, " ").trim();
|
|
9
|
-
return text.length <= maxLength ? text : `${text.slice(0, maxLength - 1)}\u2026`;
|
|
10
|
-
}
|
|
11
|
-
function normalizeContentText(input) {
|
|
12
|
-
return (input ?? "").replace(/\r/g, "").trim().split("\n").map((line) => line.replace(/[ \t]+$/g, "")).join("\n").replace(/\n{3,}/g, "\n\n");
|
|
13
|
-
}
|
|
14
|
-
function asJsonObject(value) {
|
|
15
|
-
return value ? { ...value } : {};
|
|
16
|
-
}
|
|
17
|
-
function formatJson(value) {
|
|
18
|
-
return JSON.stringify(value, null, 2);
|
|
19
|
-
}
|
|
20
|
-
function joinUrl(baseUrl, path) {
|
|
21
|
-
return `${baseUrl.replace(/\/+$/g, "")}/${path.replace(/^\/+/g, "")}`;
|
|
22
|
-
}
|
|
23
|
-
async function readResponseBody(response) {
|
|
24
|
-
const text = await response.text();
|
|
25
|
-
if (!text) return void 0;
|
|
26
|
-
try {
|
|
27
|
-
return JSON.parse(text);
|
|
28
|
-
} catch {
|
|
29
|
-
return text;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function expectJsonBody(payload, response) {
|
|
33
|
-
if (payload === void 0) {
|
|
34
|
-
throw new WebfoxError(
|
|
35
|
-
"PROVIDER_FAILURE",
|
|
36
|
-
`Expected a JSON response but received an empty body (status ${response.status}).`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
if (typeof payload === "string") {
|
|
40
|
-
const snippet = payload.trim().replace(/\s+/g, " ").slice(0, 200);
|
|
41
|
-
throw new WebfoxError(
|
|
42
|
-
"PROVIDER_FAILURE",
|
|
43
|
-
`Expected a JSON response but received a non-JSON body (status ${response.status}): ${snippet}`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return payload;
|
|
47
|
-
}
|
|
48
|
-
async function requestJson(url, init, describeError) {
|
|
49
|
-
const method = init.method ?? (init.body === void 0 ? "GET" : "POST");
|
|
50
|
-
const response = await fetch(url, {
|
|
51
|
-
method,
|
|
52
|
-
headers: {
|
|
53
|
-
Accept: "application/json",
|
|
54
|
-
...init.body === void 0 ? {} : { "Content-Type": "application/json" },
|
|
55
|
-
...init.headers
|
|
56
|
-
},
|
|
57
|
-
...init.body === void 0 ? {} : { body: JSON.stringify(init.body) },
|
|
58
|
-
signal: init.signal
|
|
59
|
-
});
|
|
60
|
-
const payload = await readResponseBody(response);
|
|
61
|
-
if (!response.ok) {
|
|
62
|
-
throw httpError(response, describeError(payload, response));
|
|
63
|
-
}
|
|
64
|
-
return expectJsonBody(payload, response);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
trimSnippet,
|
|
69
|
-
normalizeContentText,
|
|
70
|
-
asJsonObject,
|
|
71
|
-
formatJson,
|
|
72
|
-
joinUrl,
|
|
73
|
-
readResponseBody,
|
|
74
|
-
expectJsonBody,
|
|
75
|
-
requestJson
|
|
76
|
-
};
|
package/dist/chunk-I2UIACY3.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// src/runtime/duration.ts
|
|
2
|
-
function formatDuration(milliseconds) {
|
|
3
|
-
const seconds = Math.max(0, Math.floor(milliseconds / 1e3));
|
|
4
|
-
if (seconds < 60) return `${seconds}s`;
|
|
5
|
-
const minutes = Math.floor(seconds / 60);
|
|
6
|
-
if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
|
|
7
|
-
return `${Math.floor(minutes / 60)}h ${minutes % 60}m ${seconds % 60}s`;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
formatDuration
|
|
12
|
-
};
|
package/dist/chunk-KMUCUJVN.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
optionSchema,
|
|
3
|
-
providers
|
|
4
|
-
} from "./chunk-PVNWACMT.js";
|
|
5
|
-
import {
|
|
6
|
-
CAPABILITIES
|
|
7
|
-
} from "./chunk-NENL6L6N.js";
|
|
8
|
-
|
|
9
|
-
// package.json
|
|
10
|
-
var package_default = {
|
|
11
|
-
name: "webfox",
|
|
12
|
-
version: "4.11.0",
|
|
13
|
-
description: "Search the web, extract pages, get grounded answers, and run deep research with the web CLI, a TypeScript library, and a pi extension. Bring your own providers and API keys.",
|
|
14
|
-
type: "module",
|
|
15
|
-
files: [
|
|
16
|
-
"dist",
|
|
17
|
-
"README.md",
|
|
18
|
-
"assets/webfox-lockup.png",
|
|
19
|
-
"assets/webfox-lockup-dark.png",
|
|
20
|
-
"docs/cli-experience.md",
|
|
21
|
-
"docs/provider.md",
|
|
22
|
-
"docs/reference.md",
|
|
23
|
-
"LICENSE",
|
|
24
|
-
"example-config.yaml",
|
|
25
|
-
"examples"
|
|
26
|
-
],
|
|
27
|
-
keywords: [
|
|
28
|
-
"webfox",
|
|
29
|
-
"web-cli",
|
|
30
|
-
"typescript-library",
|
|
31
|
-
"pi-package",
|
|
32
|
-
"pi-extension",
|
|
33
|
-
"coding-agent",
|
|
34
|
-
"web-search",
|
|
35
|
-
"web-contents",
|
|
36
|
-
"web-answer",
|
|
37
|
-
"web-research",
|
|
38
|
-
"provider-routing",
|
|
39
|
-
"brave",
|
|
40
|
-
"cloudflare",
|
|
41
|
-
"custom",
|
|
42
|
-
"exa",
|
|
43
|
-
"firecrawl",
|
|
44
|
-
"gemini",
|
|
45
|
-
"linkup",
|
|
46
|
-
"ollama",
|
|
47
|
-
"openai",
|
|
48
|
-
"parallel",
|
|
49
|
-
"perplexity",
|
|
50
|
-
"serper",
|
|
51
|
-
"tavily",
|
|
52
|
-
"valyu"
|
|
53
|
-
],
|
|
54
|
-
author: "mavam",
|
|
55
|
-
license: "MIT",
|
|
56
|
-
repository: {
|
|
57
|
-
type: "git",
|
|
58
|
-
url: "git+https://github.com/mavam/webfox.git"
|
|
59
|
-
},
|
|
60
|
-
engines: {
|
|
61
|
-
node: ">=22.0.0"
|
|
62
|
-
},
|
|
63
|
-
publishConfig: {
|
|
64
|
-
access: "public"
|
|
65
|
-
},
|
|
66
|
-
pi: {
|
|
67
|
-
extensions: [
|
|
68
|
-
"./dist/pi.js"
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
bin: {
|
|
72
|
-
web: "./dist/cli.js"
|
|
73
|
-
},
|
|
74
|
-
main: "./dist/index.js",
|
|
75
|
-
types: "./dist/index.d.ts",
|
|
76
|
-
exports: {
|
|
77
|
-
".": {
|
|
78
|
-
types: "./dist/index.d.ts",
|
|
79
|
-
import: "./dist/index.js"
|
|
80
|
-
},
|
|
81
|
-
"./pi": {
|
|
82
|
-
types: "./dist/pi.d.ts",
|
|
83
|
-
import: "./dist/pi.js"
|
|
84
|
-
},
|
|
85
|
-
"./durable": {
|
|
86
|
-
types: "./dist/durable.d.ts",
|
|
87
|
-
import: "./dist/durable.js"
|
|
88
|
-
},
|
|
89
|
-
"./config.schema.json": "./dist/config.schema.json"
|
|
90
|
-
},
|
|
91
|
-
scripts: {
|
|
92
|
-
build: "rm -rf dist && esbuild index=src/index.ts cli=src/cli.ts pi=src/pi.ts durable=src/durable.ts generate-schema=scripts/generate-schema.ts --bundle --splitting --format=esm --platform=node --target=node22 --packages=external --outdir=dist && node dist/generate-schema.js && biome format --write src/config.schema.json >&2 && rm dist/generate-schema.js && tsc --project tsconfig.build.json && cp src/config.schema.json dist/config.schema.json && chmod +x dist/cli.js",
|
|
93
|
-
prepare: "npm run build",
|
|
94
|
-
prepack: "npm run build",
|
|
95
|
-
check: "tsc --noEmit",
|
|
96
|
-
format: "biome format --write .",
|
|
97
|
-
"format:check": "biome format .",
|
|
98
|
-
"smoke:live": "npm run build && node scripts/live-smoke.mjs",
|
|
99
|
-
"smoke:package": "node scripts/package-smoke.mjs",
|
|
100
|
-
test: "vitest run",
|
|
101
|
-
"test:watch": "vitest"
|
|
102
|
-
},
|
|
103
|
-
dependencies: {
|
|
104
|
-
"@perplexity-ai/perplexity_ai": "^0.41.0",
|
|
105
|
-
"@tavily/core": "^0.7.14",
|
|
106
|
-
cloudflare: "^7.3.0",
|
|
107
|
-
commander: "^14.0.3",
|
|
108
|
-
openai: "^7.47.0",
|
|
109
|
-
"parallel-web": "^1.3.7",
|
|
110
|
-
picocolors: "^1.1.1",
|
|
111
|
-
"valyu-js": "^2.11.5",
|
|
112
|
-
yaml: "^2.9.0"
|
|
113
|
-
},
|
|
114
|
-
devDependencies: {
|
|
115
|
-
"@biomejs/biome": "^2.5.4",
|
|
116
|
-
"@earendil-works/chord": "^1.0.0",
|
|
117
|
-
"@earendil-works/pi-ai": "^1.0.0",
|
|
118
|
-
"@earendil-works/pi-coding-agent": "^1.0.0",
|
|
119
|
-
"@earendil-works/pi-durable": "^1.0.0",
|
|
120
|
-
"@earendil-works/pi-tui": "^1.0.0",
|
|
121
|
-
"@types/node": "^26.1.1",
|
|
122
|
-
esbuild: "^0.28.1",
|
|
123
|
-
typescript: "^7.0.2",
|
|
124
|
-
vitest: "^4.1.10"
|
|
125
|
-
},
|
|
126
|
-
peerDependencies: {
|
|
127
|
-
"@earendil-works/pi-durable": "^1.0.0",
|
|
128
|
-
"@earendil-works/pi-coding-agent": "*",
|
|
129
|
-
"@earendil-works/pi-tui": "*",
|
|
130
|
-
typebox: "*"
|
|
131
|
-
},
|
|
132
|
-
peerDependenciesMeta: {
|
|
133
|
-
"@earendil-works/pi-durable": {
|
|
134
|
-
optional: true
|
|
135
|
-
},
|
|
136
|
-
"@earendil-works/pi-coding-agent": {
|
|
137
|
-
optional: true
|
|
138
|
-
},
|
|
139
|
-
"@earendil-works/pi-tui": {
|
|
140
|
-
optional: true
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// src/package-metadata.ts
|
|
146
|
-
var PACKAGE_NAME = package_default.name;
|
|
147
|
-
var PACKAGE_VERSION = package_default.version;
|
|
148
|
-
var CONFIG_SCHEMA_URL = `https://unpkg.com/${PACKAGE_NAME}@latest/dist/config.schema.json`;
|
|
149
|
-
|
|
150
|
-
// src/configuration/schema.ts
|
|
151
|
-
var text = { type: "string", minLength: 1 };
|
|
152
|
-
var object = (properties) => ({
|
|
153
|
-
type: "object",
|
|
154
|
-
additionalProperties: false,
|
|
155
|
-
properties
|
|
156
|
-
});
|
|
157
|
-
var source = {
|
|
158
|
-
oneOf: ["env", "value", "command"].map((key) => ({
|
|
159
|
-
...object({
|
|
160
|
-
[key]: key === "command" ? { type: "array", minItems: 1, items: text } : text
|
|
161
|
-
}),
|
|
162
|
-
required: [key]
|
|
163
|
-
}))
|
|
164
|
-
};
|
|
165
|
-
var sourceMap = { type: "object", additionalProperties: source };
|
|
166
|
-
var command = {
|
|
167
|
-
...object({
|
|
168
|
-
argv: { type: "array", minItems: 1, items: text },
|
|
169
|
-
cwd: text,
|
|
170
|
-
env: sourceMap
|
|
171
|
-
}),
|
|
172
|
-
required: ["argv"]
|
|
173
|
-
};
|
|
174
|
-
var positive = { type: "integer", minimum: 1 };
|
|
175
|
-
var timeout = { ...positive, maximum: 2147483647 };
|
|
176
|
-
var fields = {
|
|
177
|
-
credentials: sourceMap,
|
|
178
|
-
baseUrl: text,
|
|
179
|
-
accountId: source,
|
|
180
|
-
commands: object(
|
|
181
|
-
Object.fromEntries(CAPABILITIES.map((capability) => [capability, command]))
|
|
182
|
-
)
|
|
183
|
-
};
|
|
184
|
-
var configurationSchema = {
|
|
185
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
186
|
-
$id: CONFIG_SCHEMA_URL,
|
|
187
|
-
title: "webfox configuration",
|
|
188
|
-
...object({
|
|
189
|
-
$schema: text,
|
|
190
|
-
defaults: object(
|
|
191
|
-
Object.fromEntries(
|
|
192
|
-
CAPABILITIES.map((capability) => [
|
|
193
|
-
capability,
|
|
194
|
-
object({
|
|
195
|
-
provider: {
|
|
196
|
-
enum: Object.values(providers).filter((provider) => provider.capabilities[capability]).map((provider) => provider.id)
|
|
197
|
-
},
|
|
198
|
-
...capability === "search" ? { maxResults: positive } : {}
|
|
199
|
-
})
|
|
200
|
-
])
|
|
201
|
-
)
|
|
202
|
-
),
|
|
203
|
-
execution: object({
|
|
204
|
-
timeoutMs: timeout,
|
|
205
|
-
researchTimeoutMs: timeout,
|
|
206
|
-
retries: { type: "integer", minimum: 0 },
|
|
207
|
-
retryDelayMs: { type: "integer", minimum: 0 },
|
|
208
|
-
concurrency: positive
|
|
209
|
-
}),
|
|
210
|
-
providers: object(
|
|
211
|
-
Object.fromEntries(
|
|
212
|
-
Object.values(providers).map((provider) => [
|
|
213
|
-
provider.id,
|
|
214
|
-
object(
|
|
215
|
-
Object.fromEntries(
|
|
216
|
-
provider.fields.map((field) => [
|
|
217
|
-
field,
|
|
218
|
-
field === "options" ? object(
|
|
219
|
-
Object.fromEntries(
|
|
220
|
-
CAPABILITIES.filter(
|
|
221
|
-
(capability) => provider.capabilities[capability]
|
|
222
|
-
).map((capability) => [
|
|
223
|
-
capability,
|
|
224
|
-
optionSchema(provider, capability, "defaults") ?? {
|
|
225
|
-
type: "object",
|
|
226
|
-
additionalProperties: provider.id === "custom"
|
|
227
|
-
}
|
|
228
|
-
])
|
|
229
|
-
)
|
|
230
|
-
) : field === "credentials" ? object(
|
|
231
|
-
Object.fromEntries(
|
|
232
|
-
provider.credentials.map((credential) => [
|
|
233
|
-
credential.name,
|
|
234
|
-
source
|
|
235
|
-
])
|
|
236
|
-
)
|
|
237
|
-
) : fields[field]
|
|
238
|
-
])
|
|
239
|
-
)
|
|
240
|
-
)
|
|
241
|
-
])
|
|
242
|
-
)
|
|
243
|
-
)
|
|
244
|
-
})
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
export {
|
|
248
|
-
PACKAGE_VERSION,
|
|
249
|
-
CONFIG_SCHEMA_URL,
|
|
250
|
-
configurationSchema
|
|
251
|
-
};
|
package/dist/chunk-TYJ6RHKB.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
WebfoxError
|
|
3
|
-
} from "./chunk-U4BLULLV.js";
|
|
4
|
-
|
|
5
|
-
// src/contents.ts
|
|
6
|
-
function omittedContents(url) {
|
|
7
|
-
return {
|
|
8
|
-
url,
|
|
9
|
-
error: new WebfoxError(
|
|
10
|
-
"PROVIDER_FAILURE",
|
|
11
|
-
"The provider omitted a result for this URL."
|
|
12
|
-
).toJSON()
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function orderedContents(response) {
|
|
16
|
-
return {
|
|
17
|
-
provider: response.provider,
|
|
18
|
-
answers: response.answers.map((answer, inputIndex) => ({
|
|
19
|
-
...answer,
|
|
20
|
-
inputIndex,
|
|
21
|
-
...answer.error ? {
|
|
22
|
-
error: typeof answer.error === "string" ? new WebfoxError("PROVIDER_FAILURE", answer.error).toJSON() : answer.error
|
|
23
|
-
} : { error: void 0 }
|
|
24
|
-
}))
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
omittedContents,
|
|
30
|
-
orderedContents
|
|
31
|
-
};
|
package/dist/chunk-VVOQKYOP.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// src/tool-definition.ts
|
|
2
|
-
import { Type } from "typebox";
|
|
3
|
-
function webToolParameters(inspection) {
|
|
4
|
-
const capability = inspection.capability;
|
|
5
|
-
const fields = capability === "contents" ? { urls: Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }) } : capability === "research" ? { input: Type.String({ minLength: 1 }) } : {
|
|
6
|
-
queries: Type.Array(Type.String({ minLength: 1 }), {
|
|
7
|
-
minItems: 1,
|
|
8
|
-
maxItems: 10
|
|
9
|
-
}),
|
|
10
|
-
...capability === "search" ? { maxResults: Type.Optional(Type.Integer({ minimum: 1 })) } : {}
|
|
11
|
-
};
|
|
12
|
-
return Type.Object(
|
|
13
|
-
{
|
|
14
|
-
...fields,
|
|
15
|
-
...inspection.optionSchema ? {
|
|
16
|
-
options: Type.Optional(
|
|
17
|
-
inspection.optionSchema
|
|
18
|
-
)
|
|
19
|
-
} : {}
|
|
20
|
-
},
|
|
21
|
-
{ additionalProperties: false }
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
var descriptions = {
|
|
25
|
-
search: "Search up to ten queries and return titles, URLs, and snippets in input order.",
|
|
26
|
-
contents: "Fetch and extract readable contents from web URLs.",
|
|
27
|
-
answer: "Answer up to ten questions using web-grounded evidence.",
|
|
28
|
-
research: "Run foreground multi-step web research and return the final report."
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/pi-validation.ts
|
|
32
|
-
import { stripVTControlCharacters } from "node:util";
|
|
33
|
-
import { Check, Errors } from "typebox/value";
|
|
34
|
-
function isSchema(value) {
|
|
35
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
36
|
-
}
|
|
37
|
-
function alternatives(schema) {
|
|
38
|
-
return ["anyOf", "oneOf", "allOf"].flatMap(
|
|
39
|
-
(key) => Array.isArray(schema[key]) ? schema[key].filter(isSchema) : []
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
function acceptsPath(schema, path) {
|
|
43
|
-
if (schema === true) return true;
|
|
44
|
-
if (!isSchema(schema)) return false;
|
|
45
|
-
if (!path.length) return true;
|
|
46
|
-
if (alternatives(schema).some((branch) => acceptsPath(branch, path)))
|
|
47
|
-
return true;
|
|
48
|
-
const [key, ...rest] = path;
|
|
49
|
-
if (schema.type === "array") return acceptsPath(schema.items, rest);
|
|
50
|
-
if (schema.properties && Object.hasOwn(schema.properties, key))
|
|
51
|
-
return acceptsPath(schema.properties[key], rest);
|
|
52
|
-
if (isSchema(schema.patternProperties)) {
|
|
53
|
-
for (const [pattern, child] of Object.entries(schema.patternProperties))
|
|
54
|
-
if (new RegExp(pattern).test(key) && acceptsPath(child, rest))
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
if (schema.additionalProperties === false) return false;
|
|
58
|
-
if (schema.type && schema.type !== "object") return false;
|
|
59
|
-
if (alternatives(schema).length && !schema.properties && schema.additionalProperties === void 0)
|
|
60
|
-
return false;
|
|
61
|
-
return schema.additionalProperties === void 0 || acceptsPath(schema.additionalProperties, rest);
|
|
62
|
-
}
|
|
63
|
-
function displayPath(path) {
|
|
64
|
-
return path.map((part, index) => {
|
|
65
|
-
const safe = stripVTControlCharacters(part);
|
|
66
|
-
if (/^[a-zA-Z_][\w-]*$/.test(safe)) return `${index ? "." : ""}${safe}`;
|
|
67
|
-
if (/^\d+$/.test(safe)) return `[${safe}]`;
|
|
68
|
-
return `[${JSON.stringify(safe)}]`;
|
|
69
|
-
}).join("");
|
|
70
|
-
}
|
|
71
|
-
function locations(schema, name, path = []) {
|
|
72
|
-
if (!isSchema(schema)) return [];
|
|
73
|
-
const found = alternatives(schema).flatMap(
|
|
74
|
-
(branch) => locations(branch, name, path)
|
|
75
|
-
);
|
|
76
|
-
if (isSchema(schema.properties)) {
|
|
77
|
-
for (const [key, child] of Object.entries(schema.properties)) {
|
|
78
|
-
const next = [...path, key];
|
|
79
|
-
if (key === name) found.push(next);
|
|
80
|
-
found.push(...locations(child, name, next));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return found;
|
|
84
|
-
}
|
|
85
|
-
function prepareToolArguments(schema, args) {
|
|
86
|
-
if (Check(schema, args)) return args;
|
|
87
|
-
const messages = /* @__PURE__ */ new Set();
|
|
88
|
-
for (const error of Errors(schema, args)) {
|
|
89
|
-
if (error.keyword !== "additionalProperties") continue;
|
|
90
|
-
const names = error.params.additionalProperties;
|
|
91
|
-
if (!Array.isArray(names)) continue;
|
|
92
|
-
const parent = error.instancePath.split("/").slice(1).map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
93
|
-
for (const name of names) {
|
|
94
|
-
if (typeof name !== "string") continue;
|
|
95
|
-
const path = [...parent, name];
|
|
96
|
-
if (acceptsPath(schema, path)) continue;
|
|
97
|
-
const targets = [...new Set(locations(schema, name).map(displayPath))];
|
|
98
|
-
const suggestion = targets.length === 1 ? ` Use ${targets[0]} instead.` : " Check the tool's parameter schema.";
|
|
99
|
-
messages.add(`Invalid parameter: ${displayPath(path)}.${suggestion}`);
|
|
100
|
-
if (messages.size === 3) break;
|
|
101
|
-
}
|
|
102
|
-
if (messages.size === 3) break;
|
|
103
|
-
}
|
|
104
|
-
if (messages.size) throw new Error([...messages].join("\n"));
|
|
105
|
-
return args;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export {
|
|
109
|
-
webToolParameters,
|
|
110
|
-
descriptions,
|
|
111
|
-
prepareToolArguments
|
|
112
|
-
};
|
package/dist/contents.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ContentsAnswer as DocumentContents, ProviderId, SerializedError } from "./domain.js";
|
|
2
|
-
/** Internal normalized page, before the adapter associates its request index. */
|
|
3
|
-
export interface ContentsAnswer extends DocumentContents {
|
|
4
|
-
error?: string | SerializedError;
|
|
5
|
-
inputIndex?: number;
|
|
6
|
-
}
|
|
7
|
-
export interface ContentsResponse {
|
|
8
|
-
provider: ProviderId;
|
|
9
|
-
answers: ContentsAnswer[];
|
|
10
|
-
}
|
|
11
|
-
export interface IndexedContentsResponse {
|
|
12
|
-
provider: ProviderId;
|
|
13
|
-
answers: Array<DocumentContents & {
|
|
14
|
-
inputIndex: number;
|
|
15
|
-
error?: SerializedError;
|
|
16
|
-
}>;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A batch response that leaves out a requested URL has no result for it. This
|
|
20
|
-
* is a failure, unlike a page that the provider returned without content.
|
|
21
|
-
*/
|
|
22
|
-
export declare function omittedContents(url: string): ContentsAnswer;
|
|
23
|
-
/** Only adapters that themselves assemble pages in request order use this helper. */
|
|
24
|
-
export declare function orderedContents(response: ContentsResponse): IndexedContentsResponse;
|