@narumitw/pi-firecrawl 0.50.3 → 0.50.5

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