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