@narumitw/pi-firecrawl 0.50.2 → 0.50.4
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 +66 -97
- package/dist/index.ts +38 -139
- package/dist/index.ts.map +2 -2
- package/package.json +50 -54
- package/src/client.ts +57 -63
- package/src/firecrawl.ts +211 -235
- package/src/lazy-tools.ts +211 -229
- package/src/response-format.ts +134 -150
- package/src/settings.ts +127 -130
- package/src/tool-names.ts +5 -5
- package/src/tool-selector.ts +267 -280
- package/src/tools.ts +120 -179
package/src/lazy-tools.ts
CHANGED
|
@@ -1,301 +1,283 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineTool,
|
|
3
|
-
type ExtensionAPI,
|
|
4
|
-
type ExtensionContext,
|
|
5
|
-
} from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import { defineTool, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
6
2
|
import { Type } from "typebox";
|
|
7
3
|
import { FIRECRAWL_TOOL_NAMES, type FirecrawlToolName } from "./tool-names.js";
|
|
8
4
|
|
|
9
5
|
export const FIRECRAWL_LOAD_TOOL_NAME = "firecrawl_load";
|
|
10
6
|
|
|
11
7
|
const AVAILABLE_TOOLS_STORE = Symbol.for("@narumitw/pi-firecrawl.available-tools-store");
|
|
12
|
-
const SESSION_AVAILABLE_TOOLS_STORE = Symbol.for(
|
|
13
|
-
"@narumitw/pi-firecrawl.session-available-tools-store",
|
|
14
|
-
);
|
|
8
|
+
const SESSION_AVAILABLE_TOOLS_STORE = Symbol.for("@narumitw/pi-firecrawl.session-available-tools-store");
|
|
15
9
|
type FirecrawlGlobal = typeof globalThis & {
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
[AVAILABLE_TOOLS_STORE]?: WeakMap<ExtensionAPI, Set<FirecrawlToolName>>;
|
|
11
|
+
[SESSION_AVAILABLE_TOOLS_STORE]?: WeakMap<object, Set<FirecrawlToolName>>;
|
|
18
12
|
};
|
|
19
13
|
const sharedGlobal = globalThis as FirecrawlGlobal;
|
|
20
14
|
const existingAvailableToolsStore = sharedGlobal[AVAILABLE_TOOLS_STORE];
|
|
21
|
-
const availableToolsByApi =
|
|
22
|
-
existingAvailableToolsStore ?? new WeakMap<ExtensionAPI, Set<FirecrawlToolName>>();
|
|
15
|
+
const availableToolsByApi = existingAvailableToolsStore ?? new WeakMap<ExtensionAPI, Set<FirecrawlToolName>>();
|
|
23
16
|
if (!existingAvailableToolsStore) sharedGlobal[AVAILABLE_TOOLS_STORE] = availableToolsByApi;
|
|
24
17
|
const existingSessionAvailableToolsStore = sharedGlobal[SESSION_AVAILABLE_TOOLS_STORE];
|
|
25
|
-
const availableToolsBySession =
|
|
26
|
-
existingSessionAvailableToolsStore ?? new WeakMap<object, Set<FirecrawlToolName>>();
|
|
18
|
+
const availableToolsBySession = existingSessionAvailableToolsStore ?? new WeakMap<object, Set<FirecrawlToolName>>();
|
|
27
19
|
if (!existingSessionAvailableToolsStore) {
|
|
28
|
-
|
|
20
|
+
sharedGlobal[SESSION_AVAILABLE_TOOLS_STORE] = availableToolsBySession;
|
|
29
21
|
}
|
|
30
22
|
const lazyExposureByApi = new WeakMap<ExtensionAPI, boolean>();
|
|
31
23
|
|
|
32
24
|
const CRAWL_CREATION_TERMS = new Set(["begin", "create", "launch", "start"]);
|
|
33
25
|
|
|
34
26
|
const SEARCH_TEXT: Record<FirecrawlToolName, string> = {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
firecrawl_search:
|
|
42
|
-
"search searching web internet query results research discover discovery optionally scrape",
|
|
27
|
+
firecrawl_scrape:
|
|
28
|
+
"scrape scraping extract extraction single url page pages markdown html raw links screenshot json structured content",
|
|
29
|
+
firecrawl_crawl: "crawl crawling website site start pages depth paths sitemap batch",
|
|
30
|
+
firecrawl_crawl_status: "crawl crawling status job monitor check retrieve completed progress results",
|
|
31
|
+
firecrawl_map: "map mapping discover discovery url urls links sitemap site inventory",
|
|
32
|
+
firecrawl_search: "search searching web internet query results research discover discovery optionally scrape",
|
|
43
33
|
};
|
|
44
34
|
|
|
45
35
|
export function initializeAvailableFirecrawlTools(pi: ExtensionAPI, sessionOwner?: object) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
36
|
+
if (sessionOwner) {
|
|
37
|
+
const sessionTools = availableToolsBySession.get(sessionOwner);
|
|
38
|
+
if (sessionTools) {
|
|
39
|
+
setAvailableTools(pi, sessionTools, sessionOwner);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const apiTools = availableToolsByApi.get(pi);
|
|
44
|
+
if (apiTools) {
|
|
45
|
+
if (sessionOwner) setAvailableTools(pi, apiTools, sessionOwner);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const activeTools = new Set(pi.getActiveTools());
|
|
49
|
+
setAvailableTools(
|
|
50
|
+
pi,
|
|
51
|
+
FIRECRAWL_TOOL_NAMES.filter((name) => activeTools.has(name)),
|
|
52
|
+
sessionOwner,
|
|
53
|
+
);
|
|
64
54
|
}
|
|
65
55
|
|
|
66
56
|
export function configureFirecrawlToolExposure(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
pi: ExtensionAPI,
|
|
58
|
+
availableTools: readonly FirecrawlToolName[],
|
|
59
|
+
loadedTools: readonly FirecrawlToolName[] = [],
|
|
60
|
+
sessionOwner?: object,
|
|
61
|
+
model?: ExtensionContext["model"],
|
|
72
62
|
) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
63
|
+
const available = setAvailableTools(pi, availableTools, sessionOwner);
|
|
64
|
+
const lazyExposure = supportsNativeDeferredToolLoading(model);
|
|
65
|
+
lazyExposureByApi.set(pi, lazyExposure);
|
|
66
|
+
const loaded = new Set(loadedTools);
|
|
67
|
+
const exposedTools = lazyExposure
|
|
68
|
+
? FIRECRAWL_TOOL_NAMES.filter((name) => available.has(name) && loaded.has(name))
|
|
69
|
+
: FIRECRAWL_TOOL_NAMES.filter((name) => available.has(name));
|
|
70
|
+
const nonCapabilityTools = pi
|
|
71
|
+
.getActiveTools()
|
|
72
|
+
.filter((name) => !FIRECRAWL_TOOL_NAMES.includes(name as FirecrawlToolName));
|
|
73
|
+
pi.setActiveTools(unique([...nonCapabilityTools, FIRECRAWL_LOAD_TOOL_NAME, ...exposedTools]));
|
|
84
74
|
}
|
|
85
75
|
|
|
86
76
|
export function requireEagerFirecrawlToolExposure(pi: ExtensionAPI) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
lazyExposureByApi.set(pi, false);
|
|
78
|
+
const active = pi.getActiveTools();
|
|
79
|
+
const available = availableFirecrawlTools(pi);
|
|
80
|
+
pi.setActiveTools(unique([...active, FIRECRAWL_LOAD_TOOL_NAME, ...available]));
|
|
91
81
|
}
|
|
92
82
|
|
|
93
83
|
export function applyAvailableFirecrawlTools(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
84
|
+
pi: ExtensionAPI,
|
|
85
|
+
availableTools: readonly FirecrawlToolName[],
|
|
86
|
+
sessionOwner?: object,
|
|
97
87
|
) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
88
|
+
const available = setAvailableTools(pi, availableTools, sessionOwner);
|
|
89
|
+
const lazyExposure = lazyExposureByApi.get(pi) === true;
|
|
90
|
+
const active = pi
|
|
91
|
+
.getActiveTools()
|
|
92
|
+
.filter(
|
|
93
|
+
(name) =>
|
|
94
|
+
!FIRECRAWL_TOOL_NAMES.includes(name as FirecrawlToolName) ||
|
|
95
|
+
(lazyExposure && available.has(name as FirecrawlToolName)),
|
|
96
|
+
);
|
|
97
|
+
const eagerTools = lazyExposure ? [] : FIRECRAWL_TOOL_NAMES.filter((name) => available.has(name));
|
|
98
|
+
pi.setActiveTools(unique([...active, FIRECRAWL_LOAD_TOOL_NAME, ...eagerTools]));
|
|
109
99
|
}
|
|
110
100
|
|
|
111
101
|
export function firecrawlToolExposureMode(pi: ExtensionAPI) {
|
|
112
|
-
|
|
102
|
+
return lazyExposureByApi.get(pi) === true ? "native deferred" : "eager";
|
|
113
103
|
}
|
|
114
104
|
|
|
115
105
|
export function supportsNativeDeferredToolLoading(model: ExtensionContext["model"]): boolean {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
106
|
+
if (!model) return false;
|
|
107
|
+
if (model.api === "anthropic-messages") {
|
|
108
|
+
// Fireworks Messages requires the canonical ToolSearch/tool_search loader name.
|
|
109
|
+
// firecrawl_load remains package-specific so independently installed loaders cannot collide.
|
|
110
|
+
if (model.provider === "fireworks") return false;
|
|
111
|
+
const configured = compatBoolean(model.compat, "supportsToolReferences");
|
|
112
|
+
if (configured !== undefined) return configured;
|
|
113
|
+
if (model.provider !== "anthropic" || model.id.includes("haiku")) return false;
|
|
114
|
+
const version = model.id.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
|
|
115
|
+
if (!version) return false;
|
|
116
|
+
const major = Number(version[1]);
|
|
117
|
+
const minor = version[2] && version[2].length < 8 ? Number(version[2]) : 0;
|
|
118
|
+
return major > 4 || (major === 4 && minor >= 5);
|
|
119
|
+
}
|
|
120
|
+
if (model.api === "openai-completions") {
|
|
121
|
+
return compatString(model.compat, "deferredToolsMode") === "kimi";
|
|
122
|
+
}
|
|
123
|
+
if (model.api === "openai-responses" || model.api === "openai-codex-responses") {
|
|
124
|
+
return (
|
|
125
|
+
compatBoolean(model.compat, "supportsAdditionalTools") === true ||
|
|
126
|
+
compatBoolean(model.compat, "supportsToolSearch") === true
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
137
130
|
}
|
|
138
131
|
|
|
139
132
|
export function availableFirecrawlTools(pi: ExtensionAPI) {
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
const available = availableToolsByApi.get(pi) ?? new Set();
|
|
134
|
+
return FIRECRAWL_TOOL_NAMES.filter((name) => available.has(name));
|
|
142
135
|
}
|
|
143
136
|
|
|
144
137
|
export function createFirecrawlLoadTool(pi: ExtensionAPI) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
138
|
+
return defineTool({
|
|
139
|
+
name: FIRECRAWL_LOAD_TOOL_NAME,
|
|
140
|
+
label: "Firecrawl: Load Tools",
|
|
141
|
+
description:
|
|
142
|
+
"Find and enable Firecrawl tools relevant to a web scraping, crawling, URL discovery, crawl-status, or search task. Loaded tools remain available for the session.",
|
|
143
|
+
promptSnippet: "Load Firecrawl web research capabilities on demand",
|
|
144
|
+
promptGuidelines: [
|
|
145
|
+
"Use firecrawl_load when a task requires Firecrawl web scraping, crawling, URL discovery, crawl status, or search and the needed firecrawl_* capability is not active.",
|
|
146
|
+
"If FIRECRAWL_API_KEY is missing, report the configuration error instead of retrying repeatedly.",
|
|
147
|
+
],
|
|
148
|
+
parameters: Type.Object({
|
|
149
|
+
query: Type.String({
|
|
150
|
+
description: "Firecrawl capability or web research task to find tools for.",
|
|
151
|
+
maxLength: 500,
|
|
152
|
+
}),
|
|
153
|
+
limit: Type.Optional(
|
|
154
|
+
Type.Integer({
|
|
155
|
+
description: "Maximum tools to load. Defaults to 3.",
|
|
156
|
+
minimum: 1,
|
|
157
|
+
maximum: 5,
|
|
158
|
+
}),
|
|
159
|
+
),
|
|
160
|
+
}),
|
|
161
|
+
async execute(_toolCallId, params, signal) {
|
|
162
|
+
signal?.throwIfAborted();
|
|
163
|
+
const available = new Set(availableFirecrawlTools(pi));
|
|
164
|
+
const matches = matchFirecrawlTools(params.query, params.limit ?? 3, available);
|
|
165
|
+
const active = pi.getActiveTools();
|
|
166
|
+
const activeSet = new Set(active);
|
|
167
|
+
const added = matches.filter((name) => !activeSet.has(name));
|
|
168
|
+
if (added.length > 0) pi.setActiveTools(unique([...active, ...added]));
|
|
176
169
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
170
|
+
const text =
|
|
171
|
+
matches.length === 0
|
|
172
|
+
? "No available Firecrawl tools matched the query."
|
|
173
|
+
: added.length > 0
|
|
174
|
+
? `Loaded Firecrawl tools: ${added.join(", ")}`
|
|
175
|
+
: `Matching Firecrawl tools are already loaded: ${matches.join(", ")}`;
|
|
176
|
+
return {
|
|
177
|
+
content: [{ type: "text" as const, text }],
|
|
178
|
+
details: { matches, added },
|
|
179
|
+
};
|
|
180
|
+
},
|
|
181
|
+
});
|
|
189
182
|
}
|
|
190
183
|
|
|
191
|
-
function matchFirecrawlTools(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
!matches.includes("firecrawl_crawl") &&
|
|
234
|
-
terms.some((term) => CRAWL_CREATION_TERMS.has(term)) &&
|
|
235
|
-
matches.length < limit
|
|
236
|
-
) {
|
|
237
|
-
matches.unshift("firecrawl_crawl");
|
|
238
|
-
}
|
|
239
|
-
return matches;
|
|
184
|
+
function matchFirecrawlTools(query: string, limit: number, available: ReadonlySet<FirecrawlToolName>) {
|
|
185
|
+
const terms = [
|
|
186
|
+
...new Set(
|
|
187
|
+
query
|
|
188
|
+
.toLowerCase()
|
|
189
|
+
.split(/[^a-z0-9]+/)
|
|
190
|
+
.filter((term) => term.length >= 2),
|
|
191
|
+
),
|
|
192
|
+
];
|
|
193
|
+
if (terms.length === 0) return [];
|
|
194
|
+
const ranked = FIRECRAWL_TOOL_NAMES.filter((name) => available.has(name))
|
|
195
|
+
.map((name, index) => ({
|
|
196
|
+
name,
|
|
197
|
+
index,
|
|
198
|
+
score: terms.reduce((score, term) => score + (SEARCH_TEXT[name].split(" ").includes(term) ? 1 : 0), 0),
|
|
199
|
+
}))
|
|
200
|
+
.filter((match) => match.score > 0)
|
|
201
|
+
.sort((left, right) => right.score - left.score || left.index - right.index);
|
|
202
|
+
const bestScore = ranked[0]?.score;
|
|
203
|
+
if (bestScore === undefined) return [];
|
|
204
|
+
const matches = ranked
|
|
205
|
+
.filter((match) => match.score === bestScore)
|
|
206
|
+
.slice(0, limit)
|
|
207
|
+
.map((match) => match.name);
|
|
208
|
+
if (
|
|
209
|
+
matches.includes("firecrawl_crawl") &&
|
|
210
|
+
available.has("firecrawl_crawl_status") &&
|
|
211
|
+
!matches.includes("firecrawl_crawl_status") &&
|
|
212
|
+
matches.length < limit
|
|
213
|
+
) {
|
|
214
|
+
matches.push("firecrawl_crawl_status");
|
|
215
|
+
}
|
|
216
|
+
if (
|
|
217
|
+
matches.includes("firecrawl_crawl_status") &&
|
|
218
|
+
available.has("firecrawl_crawl") &&
|
|
219
|
+
!matches.includes("firecrawl_crawl") &&
|
|
220
|
+
terms.some((term) => CRAWL_CREATION_TERMS.has(term)) &&
|
|
221
|
+
matches.length < limit
|
|
222
|
+
) {
|
|
223
|
+
matches.unshift("firecrawl_crawl");
|
|
224
|
+
}
|
|
225
|
+
return matches;
|
|
240
226
|
}
|
|
241
227
|
|
|
242
228
|
export function loadedFirecrawlToolsFromBranch(
|
|
243
|
-
|
|
244
|
-
|
|
229
|
+
entries: readonly unknown[],
|
|
230
|
+
availableTools: readonly FirecrawlToolName[],
|
|
245
231
|
) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (isFirecrawlToolName(name) && available.has(name)) loaded.add(name);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
return FIRECRAWL_TOOL_NAMES.filter((name) => loaded.has(name));
|
|
232
|
+
const available = new Set(availableTools);
|
|
233
|
+
const loaded = new Set<FirecrawlToolName>();
|
|
234
|
+
for (const entry of entries) {
|
|
235
|
+
if (!isRecord(entry) || entry.type !== "message" || !isRecord(entry.message)) continue;
|
|
236
|
+
const message = entry.message;
|
|
237
|
+
if (message.role !== "toolResult" || message.toolName !== FIRECRAWL_LOAD_TOOL_NAME || message.isError === true) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const details = isRecord(message.details) ? message.details : undefined;
|
|
241
|
+
const recordedNames = [
|
|
242
|
+
...(Array.isArray(message.addedToolNames) ? message.addedToolNames : []),
|
|
243
|
+
...(details && Array.isArray(details.added) ? details.added : []),
|
|
244
|
+
];
|
|
245
|
+
for (const name of recordedNames) {
|
|
246
|
+
if (isFirecrawlToolName(name) && available.has(name)) loaded.add(name);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return FIRECRAWL_TOOL_NAMES.filter((name) => loaded.has(name));
|
|
268
250
|
}
|
|
269
251
|
|
|
270
252
|
function setAvailableTools(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
253
|
+
pi: ExtensionAPI,
|
|
254
|
+
availableTools: readonly FirecrawlToolName[] | ReadonlySet<FirecrawlToolName>,
|
|
255
|
+
sessionOwner?: object,
|
|
274
256
|
) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
257
|
+
const available = new Set(availableTools);
|
|
258
|
+
availableToolsByApi.set(pi, available);
|
|
259
|
+
if (sessionOwner) availableToolsBySession.set(sessionOwner, new Set(available));
|
|
260
|
+
return available;
|
|
279
261
|
}
|
|
280
262
|
|
|
281
263
|
function isFirecrawlToolName(value: unknown): value is FirecrawlToolName {
|
|
282
|
-
|
|
264
|
+
return typeof value === "string" && FIRECRAWL_TOOL_NAMES.includes(value as FirecrawlToolName);
|
|
283
265
|
}
|
|
284
266
|
|
|
285
267
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
286
|
-
|
|
268
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
287
269
|
}
|
|
288
270
|
|
|
289
271
|
function compatBoolean(value: unknown, key: string) {
|
|
290
|
-
|
|
291
|
-
|
|
272
|
+
if (!isRecord(value)) return undefined;
|
|
273
|
+
return typeof value[key] === "boolean" ? value[key] : undefined;
|
|
292
274
|
}
|
|
293
275
|
|
|
294
276
|
function compatString(value: unknown, key: string) {
|
|
295
|
-
|
|
296
|
-
|
|
277
|
+
if (!isRecord(value)) return undefined;
|
|
278
|
+
return typeof value[key] === "string" ? value[key] : undefined;
|
|
297
279
|
}
|
|
298
280
|
|
|
299
281
|
function unique(values: readonly string[]) {
|
|
300
|
-
|
|
282
|
+
return [...new Set(values)];
|
|
301
283
|
}
|