@narumitw/pi-firecrawl 0.49.3 → 0.50.1
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 +76 -24
- package/dist/index.ts +1254 -0
- package/dist/index.ts.map +7 -0
- package/package.json +15 -8
- package/src/firecrawl.ts +71 -26
- package/src/lazy-tools.ts +246 -0
- package/src/settings.ts +9 -3
- package/src/tool-names.ts +9 -0
- package/src/tool-selector.ts +148 -81
- package/src/tools.ts +1 -18
package/src/tool-selector.ts
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from "node:util";
|
|
1
2
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
import { configuredApiUrl, hasApiKey } from "./client.js";
|
|
4
|
+
import {
|
|
5
|
+
applyAvailableFirecrawlTools,
|
|
6
|
+
availableFirecrawlTools,
|
|
7
|
+
FIRECRAWL_LOAD_TOOL_NAME,
|
|
8
|
+
} from "./lazy-tools.js";
|
|
3
9
|
import {
|
|
4
10
|
loadSettings,
|
|
5
11
|
type SettingsLoadResult,
|
|
6
12
|
saveSettings,
|
|
7
13
|
settingsFilePath,
|
|
8
14
|
} from "./settings.js";
|
|
9
|
-
import { FIRECRAWL_TOOL_NAMES, type FirecrawlToolName } from "./
|
|
15
|
+
import { FIRECRAWL_TOOL_NAMES, type FirecrawlToolName } from "./tool-names.js";
|
|
10
16
|
|
|
11
17
|
type CommandContext = ExtensionCommandContext;
|
|
12
|
-
type
|
|
18
|
+
type ToolAvailabilityStatus = "enabled" | "disabled" | "partial";
|
|
13
19
|
type ToolSelectorScreen = "tools";
|
|
14
20
|
type ToolSelectorAction = "toggle" | "enableAll" | "disableAll";
|
|
15
21
|
interface ToolStatusSummary {
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
availabilityStatus: ToolAvailabilityStatus;
|
|
23
|
+
availableFirecrawlToolCount: number;
|
|
24
|
+
loadedFirecrawlToolCount: number;
|
|
18
25
|
activeNonFirecrawlToolCount: number;
|
|
19
26
|
}
|
|
20
27
|
|
|
28
|
+
type ToolSelectionSaveResult = "saved" | "available-tools-changed" | "failed";
|
|
29
|
+
|
|
21
30
|
let settingsNotice: string | undefined;
|
|
22
31
|
let sessionGeneration = 0;
|
|
23
32
|
let sessionController = new AbortController();
|
|
@@ -45,12 +54,14 @@ export function clearSettingsNotice() {
|
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
export function recordSettingsNotice(settings: SettingsLoadResult) {
|
|
48
|
-
|
|
57
|
+
settingsNotice = settings.notice;
|
|
49
58
|
}
|
|
50
59
|
|
|
51
60
|
export async function showToolSelector(pi: ExtensionAPI, ctx: CommandContext) {
|
|
52
61
|
const generation = sessionGeneration;
|
|
53
|
-
if (!ctx.hasUI)
|
|
62
|
+
if (!ctx.hasUI || (ctx.mode !== "tui" && ctx.mode !== "rpc")) {
|
|
63
|
+
throw new Error("/firecrawl tools requires TUI or RPC mode");
|
|
64
|
+
}
|
|
54
65
|
const menuSignal = sessionController.signal;
|
|
55
66
|
const isCurrent = () => isCurrentFirecrawlSession(generation) && !menuSignal.aborted;
|
|
56
67
|
const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
|
|
@@ -59,7 +70,7 @@ export async function showToolSelector(pi: ExtensionAPI, ctx: CommandContext) {
|
|
|
59
70
|
start: "tools",
|
|
60
71
|
screens: {
|
|
61
72
|
tools: () => {
|
|
62
|
-
const selectedTools = new Set(
|
|
73
|
+
const selectedTools = new Set(availableFirecrawlTools(pi));
|
|
63
74
|
return {
|
|
64
75
|
kind: "multiSelect",
|
|
65
76
|
title: toolSelectorTitle(selectedTools),
|
|
@@ -72,12 +83,12 @@ export async function showToolSelector(pi: ExtensionAPI, ctx: CommandContext) {
|
|
|
72
83
|
actions: [
|
|
73
84
|
{
|
|
74
85
|
id: "enable-all",
|
|
75
|
-
label: "
|
|
86
|
+
label: "Make all Firecrawl tools available",
|
|
76
87
|
action: "enableAll",
|
|
77
88
|
},
|
|
78
89
|
{
|
|
79
90
|
id: "disable-all",
|
|
80
|
-
label: "
|
|
91
|
+
label: "Make all Firecrawl tools unavailable",
|
|
81
92
|
action: "disableAll",
|
|
82
93
|
},
|
|
83
94
|
{ id: "done", label: "Done", close: true },
|
|
@@ -90,24 +101,34 @@ export async function showToolSelector(pi: ExtensionAPI, ctx: CommandContext) {
|
|
|
90
101
|
actions: {
|
|
91
102
|
toggle: async ({ itemId, selected }) => {
|
|
92
103
|
if (!isFirecrawlToolName(itemId)) return { kind: "rejected" };
|
|
93
|
-
const
|
|
104
|
+
const acceptedTools = availableFirecrawlTools(pi);
|
|
105
|
+
const selectedTools = new Set(acceptedTools);
|
|
94
106
|
if (selected) selectedTools.add(itemId);
|
|
95
107
|
else selectedTools.delete(itemId);
|
|
96
|
-
const
|
|
108
|
+
const result = await transactSelectedTools(
|
|
97
109
|
pi,
|
|
98
110
|
ctx,
|
|
99
111
|
orderedFirecrawlTools(selectedTools),
|
|
100
112
|
generation,
|
|
113
|
+
acceptedTools,
|
|
101
114
|
);
|
|
102
|
-
return saved ? { kind: "stay" } : { kind: "rejected" };
|
|
115
|
+
return result === "saved" ? { kind: "stay" } : { kind: "rejected" };
|
|
103
116
|
},
|
|
104
117
|
enableAll: async () => {
|
|
105
|
-
const
|
|
106
|
-
|
|
118
|
+
const acceptedTools = availableFirecrawlTools(pi);
|
|
119
|
+
const result = await transactSelectedTools(
|
|
120
|
+
pi,
|
|
121
|
+
ctx,
|
|
122
|
+
allFirecrawlTools(),
|
|
123
|
+
generation,
|
|
124
|
+
acceptedTools,
|
|
125
|
+
);
|
|
126
|
+
return result === "saved" ? { kind: "stay" } : { kind: "rejected" };
|
|
107
127
|
},
|
|
108
128
|
disableAll: async () => {
|
|
109
|
-
const
|
|
110
|
-
|
|
129
|
+
const acceptedTools = availableFirecrawlTools(pi);
|
|
130
|
+
const result = await transactSelectedTools(pi, ctx, [], generation, acceptedTools);
|
|
131
|
+
return result === "saved" ? { kind: "stay" } : { kind: "rejected" };
|
|
111
132
|
},
|
|
112
133
|
},
|
|
113
134
|
});
|
|
@@ -129,11 +150,14 @@ export async function updateFirecrawlTools(
|
|
|
129
150
|
action: string,
|
|
130
151
|
) {
|
|
131
152
|
const generation = sessionGeneration;
|
|
132
|
-
const
|
|
133
|
-
if (
|
|
153
|
+
const result = await transactSelectedTools(pi, ctx, selectedTools, generation);
|
|
154
|
+
if (result !== "saved" || !isCurrentFirecrawlSession(generation)) return;
|
|
134
155
|
const status = await buildStatusMessage(pi);
|
|
135
156
|
if (!isCurrentFirecrawlSession(generation)) return;
|
|
136
|
-
ctx.ui.notify(
|
|
157
|
+
ctx.ui.notify(
|
|
158
|
+
sanitizeFirecrawlDisplay(`Firecrawl lazy catalog ${action}.\n\n${status}`),
|
|
159
|
+
hasApiKey() ? "info" : "warning",
|
|
160
|
+
);
|
|
137
161
|
}
|
|
138
162
|
|
|
139
163
|
export async function setSelectedFirecrawlTools(
|
|
@@ -141,7 +165,7 @@ export async function setSelectedFirecrawlTools(
|
|
|
141
165
|
ctx: CommandContext,
|
|
142
166
|
selectedTools: readonly FirecrawlToolName[],
|
|
143
167
|
): Promise<boolean> {
|
|
144
|
-
return transactSelectedTools(pi, ctx, selectedTools, sessionGeneration);
|
|
168
|
+
return (await transactSelectedTools(pi, ctx, selectedTools, sessionGeneration)) === "saved";
|
|
145
169
|
}
|
|
146
170
|
|
|
147
171
|
let toolTransactionQueue = Promise.resolve();
|
|
@@ -155,9 +179,10 @@ function transactSelectedTools(
|
|
|
155
179
|
ctx: CommandContext,
|
|
156
180
|
selectedTools: readonly FirecrawlToolName[],
|
|
157
181
|
expectedGeneration: number,
|
|
158
|
-
|
|
182
|
+
expectedAvailableTools?: readonly FirecrawlToolName[],
|
|
183
|
+
): Promise<ToolSelectionSaveResult> {
|
|
159
184
|
const operation = toolTransactionQueue.then(() =>
|
|
160
|
-
transactSelectedToolsNow(pi, ctx, selectedTools, expectedGeneration),
|
|
185
|
+
transactSelectedToolsNow(pi, ctx, selectedTools, expectedGeneration, expectedAvailableTools),
|
|
161
186
|
);
|
|
162
187
|
toolTransactionQueue = operation.then(
|
|
163
188
|
() => undefined,
|
|
@@ -171,84 +196,118 @@ async function transactSelectedToolsNow(
|
|
|
171
196
|
ctx: CommandContext,
|
|
172
197
|
selectedTools: readonly FirecrawlToolName[],
|
|
173
198
|
expectedGeneration: number,
|
|
174
|
-
|
|
175
|
-
|
|
199
|
+
expectedAvailableTools?: readonly FirecrawlToolName[],
|
|
200
|
+
): Promise<ToolSelectionSaveResult> {
|
|
201
|
+
if (!isCurrentFirecrawlSession(expectedGeneration)) return "failed";
|
|
202
|
+
if (expectedAvailableTools && !arraysEqual(availableFirecrawlTools(pi), expectedAvailableTools)) {
|
|
203
|
+
ctx.ui.notify(
|
|
204
|
+
"Firecrawl tool availability changed while the selector was open. Review the current state and try again.",
|
|
205
|
+
"warning",
|
|
206
|
+
);
|
|
207
|
+
return "available-tools-changed";
|
|
208
|
+
}
|
|
176
209
|
const previousActiveTools = pi.getActiveTools();
|
|
210
|
+
const previousAvailableTools = availableFirecrawlTools(pi);
|
|
177
211
|
try {
|
|
178
|
-
applyFirecrawlTools(pi, selectedTools);
|
|
212
|
+
applyFirecrawlTools(pi, selectedTools, ctx.sessionManager);
|
|
179
213
|
await persistSettings(selectedTools);
|
|
180
|
-
return isCurrentFirecrawlSession(expectedGeneration);
|
|
214
|
+
return isCurrentFirecrawlSession(expectedGeneration) ? "saved" : "failed";
|
|
181
215
|
} catch (error) {
|
|
182
216
|
let rollbackError: unknown;
|
|
183
217
|
try {
|
|
184
|
-
|
|
218
|
+
applyAvailableFirecrawlTools(pi, previousAvailableTools, ctx.sessionManager);
|
|
219
|
+
const currentNonCapabilityTools = pi
|
|
220
|
+
.getActiveTools()
|
|
221
|
+
.filter((name) => !FIRECRAWL_TOOL_NAMES.includes(name as FirecrawlToolName));
|
|
222
|
+
const previousLoadedTools = previousActiveTools.filter((name) =>
|
|
185
223
|
FIRECRAWL_TOOL_NAMES.includes(name as FirecrawlToolName),
|
|
186
|
-
)
|
|
187
|
-
|
|
224
|
+
);
|
|
225
|
+
pi.setActiveTools(unique([...currentNonCapabilityTools, ...previousLoadedTools]));
|
|
188
226
|
} catch (caught) {
|
|
189
227
|
rollbackError = caught;
|
|
190
228
|
}
|
|
191
|
-
if (!isCurrentFirecrawlSession(expectedGeneration)) return
|
|
229
|
+
if (!isCurrentFirecrawlSession(expectedGeneration)) return "failed";
|
|
192
230
|
ctx.ui.notify(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
231
|
+
sanitizeFirecrawlDisplay(
|
|
232
|
+
rollbackError
|
|
233
|
+
? `Firecrawl settings save failed: ${formatError(error)}; active-tool rollback failed: ${formatError(rollbackError)}`
|
|
234
|
+
: `Firecrawl settings save failed; active tools restored: ${formatError(error)}`,
|
|
235
|
+
),
|
|
196
236
|
"warning",
|
|
197
237
|
);
|
|
198
|
-
return
|
|
238
|
+
return "failed";
|
|
199
239
|
}
|
|
200
240
|
}
|
|
201
241
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
242
|
+
function arraysEqual<T>(left: readonly T[], right: readonly T[]) {
|
|
243
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function applyFirecrawlTools(
|
|
247
|
+
pi: ExtensionAPI,
|
|
248
|
+
selectedTools: readonly FirecrawlToolName[],
|
|
249
|
+
sessionOwner?: object,
|
|
250
|
+
) {
|
|
251
|
+
applyAvailableFirecrawlTools(pi, selectedTools, sessionOwner);
|
|
209
252
|
}
|
|
210
253
|
|
|
211
254
|
function getToolStatusSummary(pi: ExtensionAPI): ToolStatusSummary {
|
|
212
255
|
const firecrawlToolNames = new Set<string>(FIRECRAWL_TOOL_NAMES);
|
|
213
256
|
const activeToolNames = new Set(pi.getActiveTools());
|
|
214
|
-
const
|
|
257
|
+
const loadedFirecrawlToolCount = FIRECRAWL_TOOL_NAMES.filter((name) =>
|
|
215
258
|
activeToolNames.has(name),
|
|
216
259
|
).length;
|
|
260
|
+
const availableFirecrawlToolCount = availableFirecrawlTools(pi).length;
|
|
217
261
|
const activeNonFirecrawlToolCount = Array.from(activeToolNames).filter(
|
|
218
|
-
(name) => !firecrawlToolNames.has(name),
|
|
262
|
+
(name) => !firecrawlToolNames.has(name) && name !== FIRECRAWL_LOAD_TOOL_NAME,
|
|
219
263
|
).length;
|
|
220
|
-
const
|
|
221
|
-
|
|
264
|
+
const availabilityStatus =
|
|
265
|
+
availableFirecrawlToolCount === FIRECRAWL_TOOL_NAMES.length
|
|
222
266
|
? "enabled"
|
|
223
|
-
:
|
|
267
|
+
: availableFirecrawlToolCount === 0
|
|
224
268
|
? "disabled"
|
|
225
269
|
: "partial";
|
|
226
270
|
|
|
227
|
-
return {
|
|
271
|
+
return {
|
|
272
|
+
availabilityStatus,
|
|
273
|
+
availableFirecrawlToolCount,
|
|
274
|
+
loadedFirecrawlToolCount,
|
|
275
|
+
activeNonFirecrawlToolCount,
|
|
276
|
+
};
|
|
228
277
|
}
|
|
229
278
|
|
|
230
279
|
export async function buildStatusMessage(pi: ExtensionAPI) {
|
|
280
|
+
const generation = sessionGeneration;
|
|
281
|
+
const settings = await loadSettings();
|
|
282
|
+
if (!isCurrentFirecrawlSession(generation)) return "";
|
|
283
|
+
recordSettingsNotice(settings);
|
|
231
284
|
const summary = getToolStatusSummary(pi);
|
|
232
|
-
const persistedSetting =
|
|
233
|
-
return
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
285
|
+
const persistedSetting = persistedSettingLabel(settings);
|
|
286
|
+
return sanitizeFirecrawlDisplay(
|
|
287
|
+
[
|
|
288
|
+
`Firecrawl tools available to lazy-load: ${formatRuntimeStatus(summary)}`,
|
|
289
|
+
`Loaded capability tools this session: ${summary.loadedFirecrawlToolCount}/${FIRECRAWL_TOOL_NAMES.length}`,
|
|
290
|
+
`Loader: ${pi.getActiveTools().includes(FIRECRAWL_LOAD_TOOL_NAME) ? "active" : "inactive"}`,
|
|
291
|
+
`Persisted lazy catalog: ${persistedSetting}`,
|
|
292
|
+
`Settings file: ${settingsFilePath()}`,
|
|
293
|
+
...(settingsNotice ? [`Settings note: ${settingsNotice}`] : []),
|
|
294
|
+
`Other active tools preserved: ${summary.activeNonFirecrawlToolCount}`,
|
|
295
|
+
`API key: ${hasApiKey() ? "present" : "missing"} (FIRECRAWL_API_KEY)`,
|
|
296
|
+
`API URL: ${configuredApiUrl()}`,
|
|
297
|
+
].join("\n"),
|
|
298
|
+
);
|
|
242
299
|
}
|
|
243
300
|
|
|
244
301
|
export function buildConfigMessage() {
|
|
245
|
-
return
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
302
|
+
return sanitizeFirecrawlDisplay(
|
|
303
|
+
[
|
|
304
|
+
"Firecrawl configuration:",
|
|
305
|
+
`API key: ${hasApiKey() ? "present" : "missing"} (FIRECRAWL_API_KEY)`,
|
|
306
|
+
`API URL: ${configuredApiUrl()}`,
|
|
307
|
+
"Override API URL with FIRECRAWL_API_URL or FIRECRAWL_BASE_URL.",
|
|
308
|
+
"This extension never logs, displays, or stores your Firecrawl API key.",
|
|
309
|
+
].join("\n"),
|
|
310
|
+
);
|
|
252
311
|
}
|
|
253
312
|
|
|
254
313
|
export function buildCommandGuide() {
|
|
@@ -259,26 +318,21 @@ export function buildCommandGuide() {
|
|
|
259
318
|
"/firecrawl config — show API key presence and API URL",
|
|
260
319
|
"/firecrawl quickstart — alias for /firecrawl config",
|
|
261
320
|
"/firecrawl status — show tool and settings status",
|
|
262
|
-
"/firecrawl tools —
|
|
321
|
+
"/firecrawl tools — choose tools available to lazy-load",
|
|
263
322
|
"/firecrawl toggle — alias for /firecrawl tools",
|
|
264
|
-
"/firecrawl enable —
|
|
265
|
-
"/firecrawl disable —
|
|
323
|
+
"/firecrawl enable — make all Firecrawl tools available to lazy-load",
|
|
324
|
+
"/firecrawl disable — make all Firecrawl capability tools unavailable",
|
|
266
325
|
].join("\n");
|
|
267
326
|
}
|
|
268
327
|
|
|
269
328
|
function toolSelectorTitle(selectedTools: ReadonlySet<FirecrawlToolName>) {
|
|
270
|
-
return `Firecrawl tools (${selectedTools.size}/${FIRECRAWL_TOOL_NAMES.length}). Non-built-in tools run at user risk.`;
|
|
329
|
+
return `Firecrawl tools available to lazy-load (${selectedTools.size}/${FIRECRAWL_TOOL_NAMES.length}). Non-built-in tools run at user risk.`;
|
|
271
330
|
}
|
|
272
331
|
|
|
273
332
|
function isFirecrawlToolName(value: string): value is FirecrawlToolName {
|
|
274
333
|
return FIRECRAWL_TOOL_NAMES.includes(value as FirecrawlToolName);
|
|
275
334
|
}
|
|
276
335
|
|
|
277
|
-
function getActiveFirecrawlTools(pi: ExtensionAPI) {
|
|
278
|
-
const activeToolNames = new Set(pi.getActiveTools());
|
|
279
|
-
return FIRECRAWL_TOOL_NAMES.filter((toolName) => activeToolNames.has(toolName));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
336
|
export function allFirecrawlTools() {
|
|
283
337
|
return [...FIRECRAWL_TOOL_NAMES];
|
|
284
338
|
}
|
|
@@ -292,27 +346,40 @@ export function orderedFirecrawlTools(selectedTools: ReadonlySet<FirecrawlToolNa
|
|
|
292
346
|
}
|
|
293
347
|
|
|
294
348
|
function formatRuntimeStatus(summary: ToolStatusSummary) {
|
|
295
|
-
return `${summary.
|
|
349
|
+
return `${summary.availabilityStatus} (${summary.availableFirecrawlToolCount}/${FIRECRAWL_TOOL_NAMES.length} available)`;
|
|
296
350
|
}
|
|
297
351
|
|
|
298
|
-
|
|
299
|
-
const settings = await loadSettings();
|
|
300
|
-
recordSettingsNotice(settings);
|
|
352
|
+
function persistedSettingLabel(settings: SettingsLoadResult) {
|
|
301
353
|
if (settings.kind === "loaded") return formatPersistedSelection(settings.settings.tools);
|
|
302
354
|
if (settings.kind === "invalid") {
|
|
303
|
-
return `none; current
|
|
355
|
+
return `none; current availability policy preserved (invalid settings ignored: ${settings.reason})`;
|
|
304
356
|
}
|
|
305
|
-
return "none; current
|
|
357
|
+
return "none; current availability policy preserved";
|
|
306
358
|
}
|
|
307
359
|
|
|
308
360
|
export function formatPersistedSelection(tools: readonly FirecrawlToolName[]) {
|
|
309
361
|
if (tools.length === FIRECRAWL_TOOL_NAMES.length) {
|
|
310
|
-
return `all
|
|
362
|
+
return `all available (${tools.length}/${FIRECRAWL_TOOL_NAMES.length} selected)`;
|
|
311
363
|
}
|
|
312
|
-
if (tools.length === 0) return `all
|
|
364
|
+
if (tools.length === 0) return `all unavailable (0/${FIRECRAWL_TOOL_NAMES.length} selected)`;
|
|
313
365
|
return `${tools.length}/${FIRECRAWL_TOOL_NAMES.length} selected: ${tools.join(", ")}`;
|
|
314
366
|
}
|
|
315
367
|
|
|
368
|
+
export function sanitizeFirecrawlDisplay(value: string, maxCharacters = 50_000) {
|
|
369
|
+
const characters = Array.from(stripVTControlCharacters(value), (character) => {
|
|
370
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
371
|
+
const unsafeControl =
|
|
372
|
+
(codePoint >= 0 && codePoint <= 8) ||
|
|
373
|
+
(codePoint >= 11 && codePoint <= 31) ||
|
|
374
|
+
(codePoint >= 127 && codePoint <= 159);
|
|
375
|
+
return unsafeControl ? "�" : character;
|
|
376
|
+
});
|
|
377
|
+
const limit = Number.isFinite(maxCharacters) ? Math.max(0, Math.floor(maxCharacters)) : 0;
|
|
378
|
+
if (characters.length <= limit) return characters.join("");
|
|
379
|
+
if (limit === 0) return "";
|
|
380
|
+
return `${characters.slice(0, limit - 1).join("")}…`;
|
|
381
|
+
}
|
|
382
|
+
|
|
316
383
|
function formatError(error: unknown) {
|
|
317
384
|
return error instanceof Error ? error.message : String(error);
|
|
318
385
|
}
|
package/src/tools.ts
CHANGED
|
@@ -6,15 +6,7 @@ import {
|
|
|
6
6
|
} from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
8
|
import { cleanObject, firecrawlRequest, jsonResult, withStatus } from "./client.js";
|
|
9
|
-
|
|
10
|
-
export const FIRECRAWL_TOOL_NAMES = [
|
|
11
|
-
"firecrawl_scrape",
|
|
12
|
-
"firecrawl_crawl",
|
|
13
|
-
"firecrawl_crawl_status",
|
|
14
|
-
"firecrawl_map",
|
|
15
|
-
"firecrawl_search",
|
|
16
|
-
] as const;
|
|
17
|
-
export type FirecrawlToolName = (typeof FIRECRAWL_TOOL_NAMES)[number];
|
|
9
|
+
import { FIRECRAWL_TOOL_NAMES } from "./tool-names.js";
|
|
18
10
|
|
|
19
11
|
const StringArray = Type.Array(Type.String());
|
|
20
12
|
const OUTPUT_LIMIT_DESCRIPTION = `Output is truncated to ${DEFAULT_MAX_LINES} lines or ${formatSize(DEFAULT_MAX_BYTES)}; complete truncated responses are saved temporarily and their path is returned.`;
|
|
@@ -23,11 +15,6 @@ export const scrapeTool = defineTool({
|
|
|
23
15
|
name: FIRECRAWL_TOOL_NAMES[0],
|
|
24
16
|
label: "Firecrawl: Scrape",
|
|
25
17
|
description: `Scrape a single URL through Firecrawl and return requested formats. ${OUTPUT_LIMIT_DESCRIPTION}`,
|
|
26
|
-
promptSnippet: "Scrape a URL through Firecrawl",
|
|
27
|
-
promptGuidelines: [
|
|
28
|
-
"Use firecrawl_scrape when you need clean markdown, HTML, links, screenshots, or structured extraction for one URL.",
|
|
29
|
-
"If FIRECRAWL_API_KEY is missing, report the configuration error instead of retrying repeatedly.",
|
|
30
|
-
],
|
|
31
18
|
parameters: Type.Object({
|
|
32
19
|
url: Type.String({ description: "URL to scrape." }),
|
|
33
20
|
formats: Type.Optional(
|
|
@@ -91,7 +78,6 @@ export const crawlTool = defineTool({
|
|
|
91
78
|
name: FIRECRAWL_TOOL_NAMES[1],
|
|
92
79
|
label: "Firecrawl: Crawl",
|
|
93
80
|
description: `Start a Firecrawl crawl job for a website. ${OUTPUT_LIMIT_DESCRIPTION}`,
|
|
94
|
-
promptSnippet: "Start a Firecrawl site crawl job",
|
|
95
81
|
parameters: Type.Object({
|
|
96
82
|
url: Type.String({ description: "Starting URL for the crawl." }),
|
|
97
83
|
limit: Type.Optional(Type.Number({ description: "Maximum number of pages to crawl." })),
|
|
@@ -135,7 +121,6 @@ export const crawlStatusTool = defineTool({
|
|
|
135
121
|
name: FIRECRAWL_TOOL_NAMES[2],
|
|
136
122
|
label: "Firecrawl: Crawl Status",
|
|
137
123
|
description: `Check a Firecrawl crawl job status and retrieve completed crawl data. ${OUTPUT_LIMIT_DESCRIPTION}`,
|
|
138
|
-
promptSnippet: "Check a Firecrawl crawl job status",
|
|
139
124
|
parameters: Type.Object({
|
|
140
125
|
id: Type.String({ description: "Crawl job id returned by firecrawl_crawl." }),
|
|
141
126
|
}),
|
|
@@ -157,7 +142,6 @@ export const mapTool = defineTool({
|
|
|
157
142
|
name: FIRECRAWL_TOOL_NAMES[3],
|
|
158
143
|
label: "Firecrawl: Map",
|
|
159
144
|
description: `Discover URLs for a site through Firecrawl's map endpoint. ${OUTPUT_LIMIT_DESCRIPTION}`,
|
|
160
|
-
promptSnippet: "Map/discover URLs for a site through Firecrawl",
|
|
161
145
|
parameters: Type.Object({
|
|
162
146
|
url: Type.String({ description: "Website URL to map." }),
|
|
163
147
|
search: Type.Optional(
|
|
@@ -190,7 +174,6 @@ export const searchTool = defineTool({
|
|
|
190
174
|
name: FIRECRAWL_TOOL_NAMES[4],
|
|
191
175
|
label: "Firecrawl: Search",
|
|
192
176
|
description: `Search the web through Firecrawl and optionally scrape search results. ${OUTPUT_LIMIT_DESCRIPTION}`,
|
|
193
|
-
promptSnippet: "Search the web through Firecrawl",
|
|
194
177
|
parameters: Type.Object({
|
|
195
178
|
query: Type.String({ description: "Search query." }),
|
|
196
179
|
limit: Type.Optional(Type.Number({ description: "Maximum number of search results." })),
|