@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/client.ts
CHANGED
|
@@ -7,97 +7,91 @@ const STATUS_KEY = "firecrawl";
|
|
|
7
7
|
let apiUrl = normalizeApiUrl(process.env.FIRECRAWL_API_URL ?? process.env.FIRECRAWL_BASE_URL);
|
|
8
8
|
|
|
9
9
|
export function configuredApiUrl() {
|
|
10
|
-
|
|
10
|
+
return apiUrl;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function resetConfiguredApiUrl() {
|
|
14
|
-
|
|
14
|
+
apiUrl = normalizeApiUrl(process.env.FIRECRAWL_API_URL ?? process.env.FIRECRAWL_BASE_URL);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export async function firecrawlRequest(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
method: "GET" | "POST",
|
|
19
|
+
path: string,
|
|
20
|
+
body: unknown,
|
|
21
|
+
signal: AbortSignal | undefined,
|
|
22
|
+
artifactOwner: object,
|
|
23
23
|
) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
24
|
+
const apiKey = getApiKey();
|
|
25
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
26
|
+
method,
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: `Bearer ${apiKey}`,
|
|
29
|
+
...(body === undefined ? {} : { "Content-Type": "application/json" }),
|
|
30
|
+
},
|
|
31
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
32
|
+
signal,
|
|
33
|
+
});
|
|
34
|
+
const responseText = await response.text();
|
|
35
|
+
const payload = parseResponseBody(responseText);
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
const prefix = `Firecrawl ${method} ${path} failed (${response.status}): `;
|
|
38
|
+
const bounded = await boundResponseText(`${prefix}${formatPayload(payload)}`, artifactOwner, {
|
|
39
|
+
artifactText: responseText,
|
|
40
|
+
artifactExtension: "txt",
|
|
41
|
+
});
|
|
42
|
+
throw new Error(bounded.text);
|
|
43
|
+
}
|
|
44
|
+
return payload;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export function getApiKey() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
return apiKey;
|
|
48
|
+
const apiKey = process.env.FIRECRAWL_API_KEY?.trim();
|
|
49
|
+
if (!apiKey) {
|
|
50
|
+
throw new Error("FIRECRAWL_API_KEY is not configured. Set it in your shell or Pi environment, then retry once.");
|
|
51
|
+
}
|
|
52
|
+
return apiKey;
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
export function hasApiKey() {
|
|
58
|
-
|
|
56
|
+
return Boolean(process.env.FIRECRAWL_API_KEY?.trim());
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
export function normalizeApiUrl(value: string | undefined) {
|
|
62
|
-
|
|
60
|
+
return (value?.trim() || DEFAULT_API_URL).replace(/\/+$/, "");
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
export function parseResponseBody(responseText: string) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
if (!responseText) return {};
|
|
65
|
+
try {
|
|
66
|
+
return JSON.parse(responseText) as unknown;
|
|
67
|
+
} catch {
|
|
68
|
+
return responseText;
|
|
69
|
+
}
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
export function formatPayload(payload: unknown) {
|
|
75
|
-
|
|
73
|
+
return typeof payload === "string" ? payload : (JSON.stringify(payload) ?? String(payload));
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
export function jsonResult(payload: unknown, artifactOwner: object) {
|
|
79
|
-
|
|
77
|
+
return formatJsonResult(payload, artifactOwner);
|
|
80
78
|
}
|
|
81
79
|
|
|
82
|
-
export async function withStatus<T>(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return await callback();
|
|
90
|
-
} finally {
|
|
91
|
-
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
92
|
-
}
|
|
80
|
+
export async function withStatus<T>(ctx: Pick<ExtensionContext, "ui">, status: string, callback: () => Promise<T>) {
|
|
81
|
+
ctx.ui.setStatus(STATUS_KEY, status);
|
|
82
|
+
try {
|
|
83
|
+
return await callback();
|
|
84
|
+
} finally {
|
|
85
|
+
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
86
|
+
}
|
|
93
87
|
}
|
|
94
88
|
|
|
95
89
|
export function cleanObject<T>(value: T): T {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
if (Array.isArray(value)) return value.map(cleanObject) as T;
|
|
91
|
+
if (!value || typeof value !== "object") return value;
|
|
92
|
+
return Object.fromEntries(
|
|
93
|
+
Object.entries(value as Record<string, unknown>)
|
|
94
|
+
.filter(([, item]) => item !== undefined)
|
|
95
|
+
.map(([key, item]) => [key, cleanObject(item)]),
|
|
96
|
+
) as T;
|
|
103
97
|
}
|
package/src/firecrawl.ts
CHANGED
|
@@ -1,284 +1,260 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { hasApiKey } from "./client.js";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
availableFirecrawlTools,
|
|
5
|
+
configureFirecrawlToolExposure,
|
|
6
|
+
createFirecrawlLoadTool,
|
|
7
|
+
initializeAvailableFirecrawlTools,
|
|
8
|
+
loadedFirecrawlToolsFromBranch,
|
|
9
|
+
requireEagerFirecrawlToolExposure,
|
|
10
|
+
supportsNativeDeferredToolLoading,
|
|
11
11
|
} from "./lazy-tools.js";
|
|
12
12
|
import { cleanupResponseArtifacts, openResponseArtifacts } from "./response-format.js";
|
|
13
13
|
import { loadSettings } from "./settings.js";
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
advanceFirecrawlSessionGeneration,
|
|
16
|
+
allFirecrawlTools,
|
|
17
|
+
buildCommandGuide,
|
|
18
|
+
buildConfigMessage,
|
|
19
|
+
buildStatusMessage,
|
|
20
|
+
clearSettingsNotice,
|
|
21
|
+
currentFirecrawlSessionGeneration,
|
|
22
|
+
currentFirecrawlSessionSignal,
|
|
23
|
+
isCurrentFirecrawlSession,
|
|
24
|
+
recordSettingsNotice,
|
|
25
|
+
sanitizeFirecrawlDisplay,
|
|
26
|
+
showToolSelector,
|
|
27
|
+
updateFirecrawlTools,
|
|
28
|
+
waitForFirecrawlSettings,
|
|
29
29
|
} from "./tool-selector.js";
|
|
30
30
|
import { crawlStatusTool, crawlTool, mapTool, scrapeTool, searchTool } from "./tools.js";
|
|
31
31
|
|
|
32
32
|
const STATUS_KEY = "firecrawl";
|
|
33
33
|
const COMMAND_COMPLETIONS = [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
{ value: "help", label: "help", description: "Show command usage" },
|
|
35
|
+
{ value: "config", label: "config", description: "Show configuration quick start" },
|
|
36
|
+
{ value: "quickstart", label: "quickstart", description: "Show configuration quick start" },
|
|
37
|
+
{ value: "status", label: "status", description: "Show tool and settings status" },
|
|
38
|
+
{ value: "tools", label: "tools", description: "Choose available Firecrawl tools" },
|
|
39
|
+
{ value: "toggle", label: "toggle", description: "Choose available Firecrawl tools" },
|
|
40
|
+
{ value: "enable", label: "enable", description: "Make all Firecrawl tools available" },
|
|
41
|
+
{ value: "disable", label: "disable", description: "Make all Firecrawl tools unavailable" },
|
|
42
42
|
];
|
|
43
43
|
const MENU_OPTIONS = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
config: "Configuration quick start",
|
|
45
|
+
help: "Command usage guide",
|
|
46
|
+
status: "Show tool status",
|
|
47
|
+
tools: "Choose available Firecrawl tools",
|
|
48
|
+
enable: "Make all Firecrawl tools available",
|
|
49
|
+
disable: "Make all Firecrawl tools unavailable",
|
|
50
50
|
} as const;
|
|
51
|
-
type CommandAction =
|
|
52
|
-
| "menu"
|
|
53
|
-
| "help"
|
|
54
|
-
| "config"
|
|
55
|
-
| "quickstart"
|
|
56
|
-
| "status"
|
|
57
|
-
| "tools"
|
|
58
|
-
| "enable"
|
|
59
|
-
| "disable";
|
|
51
|
+
type CommandAction = "menu" | "help" | "config" | "quickstart" | "status" | "tools" | "enable" | "disable";
|
|
60
52
|
type CommandContext = ExtensionCommandContext;
|
|
61
53
|
export default function firecrawl(pi: ExtensionAPI) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
pi.registerTool(scrapeTool);
|
|
55
|
+
pi.registerTool(crawlTool);
|
|
56
|
+
pi.registerTool(crawlStatusTool);
|
|
57
|
+
pi.registerTool(mapTool);
|
|
58
|
+
pi.registerTool(searchTool);
|
|
59
|
+
pi.registerTool(createFirecrawlLoadTool(pi));
|
|
68
60
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
pi.registerCommand("firecrawl", {
|
|
62
|
+
description: "Open Firecrawl help and tool controls",
|
|
63
|
+
getArgumentCompletions: (prefix) => commandCompletions(prefix),
|
|
64
|
+
handler: async (args, ctx) => {
|
|
65
|
+
initializeAvailableFirecrawlTools(pi, ctx.sessionManager);
|
|
66
|
+
const generation = currentFirecrawlSessionGeneration();
|
|
67
|
+
await handleFirecrawlCommand(pi, args, ctx, generation);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
78
70
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (settings.kind === "invalid") {
|
|
97
|
-
ctx.ui.notify(
|
|
98
|
-
sanitizeFirecrawlDisplay(`Firecrawl settings ignored: ${settings.reason}`),
|
|
99
|
-
"warning",
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
71
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
72
|
+
const generation = advanceFirecrawlSessionGeneration();
|
|
73
|
+
initializeAvailableFirecrawlTools(pi, ctx.sessionManager);
|
|
74
|
+
openResponseArtifacts(ctx.sessionManager);
|
|
75
|
+
clearSettingsNotice();
|
|
76
|
+
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
77
|
+
const settings = await loadSettings();
|
|
78
|
+
if (!isCurrentFirecrawlSession(generation)) return;
|
|
79
|
+
recordSettingsNotice(settings);
|
|
80
|
+
if (settings.notice) ctx.ui.notify(sanitizeFirecrawlDisplay(settings.notice), "warning");
|
|
81
|
+
const availableTools = settings.kind === "loaded" ? settings.settings.tools : availableFirecrawlTools(pi);
|
|
82
|
+
const loadedTools = loadedFirecrawlToolsFromBranch(ctx.sessionManager.getBranch(), availableTools);
|
|
83
|
+
configureFirecrawlToolExposure(pi, availableTools, loadedTools, ctx.sessionManager, ctx.model);
|
|
84
|
+
if (settings.kind === "invalid") {
|
|
85
|
+
ctx.ui.notify(sanitizeFirecrawlDisplay(`Firecrawl settings ignored: ${settings.reason}`), "warning");
|
|
86
|
+
}
|
|
87
|
+
});
|
|
103
88
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
89
|
+
pi.on("model_select", (event) => {
|
|
90
|
+
if (!supportsNativeDeferredToolLoading(event.model)) {
|
|
91
|
+
requireEagerFirecrawlToolExposure(pi);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
109
94
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
95
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
96
|
+
advanceFirecrawlSessionGeneration();
|
|
97
|
+
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
98
|
+
const artifactOwner = ctx.sessionManager;
|
|
99
|
+
await waitForFirecrawlSettings();
|
|
100
|
+
await cleanupResponseArtifacts(artifactOwner);
|
|
101
|
+
});
|
|
117
102
|
}
|
|
118
103
|
|
|
119
|
-
async function handleFirecrawlCommand(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return;
|
|
153
|
-
case "disable":
|
|
154
|
-
await updateFirecrawlTools(pi, ctx, [], "made all unavailable");
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
104
|
+
async function handleFirecrawlCommand(pi: ExtensionAPI, args: string, ctx: CommandContext, generation: number) {
|
|
105
|
+
const command = parseCommand(args);
|
|
106
|
+
switch (command) {
|
|
107
|
+
case "menu":
|
|
108
|
+
await showMenu(pi, ctx, generation);
|
|
109
|
+
return;
|
|
110
|
+
case "help":
|
|
111
|
+
requireObservableUi(ctx, "help");
|
|
112
|
+
ctx.ui.notify(buildCommandGuide(), "info");
|
|
113
|
+
return;
|
|
114
|
+
case "config":
|
|
115
|
+
case "quickstart":
|
|
116
|
+
requireObservableUi(ctx, command);
|
|
117
|
+
ctx.ui.notify(buildConfigMessage(), hasApiKey() ? "info" : "warning");
|
|
118
|
+
return;
|
|
119
|
+
case "status": {
|
|
120
|
+
requireObservableUi(ctx, "status");
|
|
121
|
+
const status = await buildStatusMessage(pi);
|
|
122
|
+
if (!isCurrentFirecrawlSession(generation)) return;
|
|
123
|
+
ctx.ui.notify(status, hasApiKey() ? "info" : "warning");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
case "tools":
|
|
127
|
+
requireObservableUi(ctx, "tools");
|
|
128
|
+
await showToolSelector(pi, ctx);
|
|
129
|
+
return;
|
|
130
|
+
case "enable":
|
|
131
|
+
await updateFirecrawlTools(pi, ctx, allFirecrawlTools(), "made all available");
|
|
132
|
+
return;
|
|
133
|
+
case "disable":
|
|
134
|
+
await updateFirecrawlTools(pi, ctx, [], "made all unavailable");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
157
137
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
"warning",
|
|
166
|
-
);
|
|
138
|
+
if (!ctx.hasUI || (ctx.mode !== "tui" && ctx.mode !== "rpc")) {
|
|
139
|
+
throw new Error(sanitizeFirecrawlDisplay(`Unknown /firecrawl command: ${args.trim()}`));
|
|
140
|
+
}
|
|
141
|
+
ctx.ui.notify(
|
|
142
|
+
sanitizeFirecrawlDisplay(`Unknown /firecrawl command: ${args.trim()}\n\n${buildCommandGuide()}`),
|
|
143
|
+
"warning",
|
|
144
|
+
);
|
|
167
145
|
}
|
|
168
146
|
|
|
169
147
|
async function showMenu(pi: ExtensionAPI, ctx: CommandContext, generation: number) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
148
|
+
requireObservableUi(ctx, "menu");
|
|
149
|
+
const menuSignal = currentFirecrawlSessionSignal();
|
|
150
|
+
const isCurrent = () => isCurrentFirecrawlSession(generation) && !menuSignal.aborted;
|
|
151
|
+
const { defineMenu, runMenu } = await import("@narumitw/pi-tui-kit");
|
|
152
|
+
if (!isCurrent()) return;
|
|
175
153
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
154
|
+
type Screen = "main";
|
|
155
|
+
type Action = keyof typeof MENU_OPTIONS;
|
|
156
|
+
const menu = defineMenu<undefined, Screen, Action>({
|
|
157
|
+
start: "main",
|
|
158
|
+
screens: {
|
|
159
|
+
main: () => ({
|
|
160
|
+
kind: "actions",
|
|
161
|
+
title: "Firecrawl",
|
|
162
|
+
lines: mainMenuLines(pi),
|
|
163
|
+
items: Object.entries(MENU_OPTIONS).map(([id, label]) => ({
|
|
164
|
+
id,
|
|
165
|
+
label,
|
|
166
|
+
action: id as Action,
|
|
167
|
+
})),
|
|
168
|
+
hint: "close",
|
|
169
|
+
}),
|
|
170
|
+
},
|
|
171
|
+
actions: {
|
|
172
|
+
config: async () => {
|
|
173
|
+
ctx.ui.notify(buildConfigMessage(), hasApiKey() ? "info" : "warning");
|
|
174
|
+
return { kind: "close" };
|
|
175
|
+
},
|
|
176
|
+
help: async () => {
|
|
177
|
+
ctx.ui.notify(buildCommandGuide(), "info");
|
|
178
|
+
return { kind: "close" };
|
|
179
|
+
},
|
|
180
|
+
status: async () => {
|
|
181
|
+
const status = await buildStatusMessage(pi);
|
|
182
|
+
if (isCurrentFirecrawlSession(generation)) {
|
|
183
|
+
ctx.ui.notify(status, hasApiKey() ? "info" : "warning");
|
|
184
|
+
}
|
|
185
|
+
return { kind: "close" };
|
|
186
|
+
},
|
|
187
|
+
tools: async () => {
|
|
188
|
+
await showToolSelector(pi, ctx);
|
|
189
|
+
return { kind: "close" };
|
|
190
|
+
},
|
|
191
|
+
enable: async () => {
|
|
192
|
+
await updateFirecrawlTools(pi, ctx, allFirecrawlTools(), "made all available");
|
|
193
|
+
return { kind: "close" };
|
|
194
|
+
},
|
|
195
|
+
disable: async () => {
|
|
196
|
+
await updateFirecrawlTools(pi, ctx, [], "made all unavailable");
|
|
197
|
+
return { kind: "close" };
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
await runMenu(ctx, menu, {
|
|
202
|
+
getState: () => undefined,
|
|
203
|
+
signal: menuSignal,
|
|
204
|
+
isCurrent,
|
|
205
|
+
});
|
|
228
206
|
}
|
|
229
207
|
|
|
230
208
|
function mainMenuLines(pi: ExtensionAPI) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
209
|
+
const active = new Set(pi.getActiveTools());
|
|
210
|
+
const capabilityNames = allFirecrawlTools();
|
|
211
|
+
const loadedCount = capabilityNames.filter((name) => active.has(name)).length;
|
|
212
|
+
return [
|
|
213
|
+
`Tool catalog: ${availableFirecrawlTools(pi).length}/${capabilityNames.length} available`,
|
|
214
|
+
`Loaded this session: ${loadedCount}/${capabilityNames.length}`,
|
|
215
|
+
`API key: ${hasApiKey() ? "present" : "missing"}`,
|
|
216
|
+
];
|
|
239
217
|
}
|
|
240
218
|
|
|
241
219
|
function requireObservableUi(ctx: CommandContext, route: string) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
220
|
+
if (!ctx.hasUI || (ctx.mode !== "tui" && ctx.mode !== "rpc")) {
|
|
221
|
+
throw new Error(`/firecrawl ${route} requires TUI or RPC mode`);
|
|
222
|
+
}
|
|
245
223
|
}
|
|
246
224
|
|
|
247
225
|
export function parseCommand(args: string): CommandAction | "unknown" {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
226
|
+
const command = args.trim().toLowerCase();
|
|
227
|
+
if (!command) return "menu";
|
|
228
|
+
if (command === "help") return "help";
|
|
229
|
+
if (command === "config") return "config";
|
|
230
|
+
if (command === "quickstart") return "quickstart";
|
|
231
|
+
if (command === "status") return "status";
|
|
232
|
+
if (command === "tools" || command === "select" || command === "toggle") return "tools";
|
|
233
|
+
if (command === "enable" || command === "on") return "enable";
|
|
234
|
+
if (command === "disable" || command === "off") return "disable";
|
|
235
|
+
return "unknown";
|
|
258
236
|
}
|
|
259
237
|
|
|
260
238
|
export function commandCompletions(prefix: string) {
|
|
261
|
-
|
|
262
|
-
|
|
239
|
+
const normalized = prefix.trimStart().toLowerCase();
|
|
240
|
+
if (/\s/.test(normalized)) return null;
|
|
263
241
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
);
|
|
267
|
-
return matches.length > 0 ? matches : null;
|
|
242
|
+
const matches = COMMAND_COMPLETIONS.filter((completion) => completion.value.startsWith(normalized));
|
|
243
|
+
return matches.length > 0 ? matches : null;
|
|
268
244
|
}
|
|
269
245
|
|
|
270
246
|
export {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
247
|
+
cleanObject,
|
|
248
|
+
firecrawlRequest,
|
|
249
|
+
formatPayload,
|
|
250
|
+
jsonResult,
|
|
251
|
+
normalizeApiUrl,
|
|
252
|
+
parseResponseBody,
|
|
277
253
|
} from "./client.js";
|
|
278
254
|
export { cleanupResponseArtifacts } from "./response-format.js";
|
|
279
255
|
export { normalizeFirecrawlSettings } from "./settings.js";
|
|
280
256
|
export {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
257
|
+
formatPersistedSelection,
|
|
258
|
+
orderedFirecrawlTools,
|
|
259
|
+
sanitizeFirecrawlDisplay,
|
|
284
260
|
} from "./tool-selector.js";
|