@blastlauncher/cli 1.0.4 → 3.0.0-alpha.0

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 CHANGED
@@ -1,19 +1,5 @@
1
- # `blast-cli`
1
+ # @blastlauncher/cli
2
2
 
3
- ## Development
4
-
5
- ```bash
6
- # Output single cjs file with esbuild
7
- pnpm build
8
-
9
- # Run the cli
10
- node ./dist/index.cjs --help
11
-
12
- # Package to cli executable with pkg
13
- pnpm package
14
-
15
- # Run the cli executable
16
- ./dist/cli-macos --help
17
-
18
-
19
- ```
3
+ Blast's cli package.
4
+ Emitted ESM and TypeScript declarations for Node.js 24.20+.
5
+ See https://github.com/BlastLauncher/blast for documentation.
@@ -0,0 +1,11 @@
1
+ import type { CapabilityHandler } from "@blastlauncher/engine";
2
+ export type BrowserTab = {
3
+ id: number;
4
+ url: string;
5
+ active: boolean;
6
+ title?: string;
7
+ favicon?: string;
8
+ content?: string;
9
+ };
10
+ export declare function parseBrowserTabs(text: string): BrowserTab[];
11
+ export declare function createBrowserHandlers(tabs: BrowserTab[]): Record<string, CapabilityHandler>;
@@ -0,0 +1,49 @@
1
+ export function parseBrowserTabs(text) {
2
+ const tabs = JSON.parse(text);
3
+ if (!Array.isArray(tabs))
4
+ throw new Error("must be a JSON array of tabs");
5
+ const ids = new Set();
6
+ return tabs.map((tab, index) => {
7
+ if (!tab ||
8
+ typeof tab !== "object" ||
9
+ !Number.isInteger(tab.id) ||
10
+ typeof tab.url !== "string" ||
11
+ typeof tab.active !== "boolean")
12
+ throw new Error(`tab ${index + 1} requires integer id, string url and boolean active`);
13
+ if (ids.has(tab.id))
14
+ throw new Error(`duplicate tab id ${tab.id}`);
15
+ ids.add(tab.id);
16
+ const result = { id: tab.id, url: tab.url, active: tab.active };
17
+ for (const field of ["title", "favicon", "content"]) {
18
+ if (tab[field] !== undefined) {
19
+ if (typeof tab[field] !== "string")
20
+ throw new Error(`tab ${index + 1}: ${field} must be a string`);
21
+ result[field] = tab[field];
22
+ }
23
+ }
24
+ return result;
25
+ });
26
+ }
27
+ export function createBrowserHandlers(tabs) {
28
+ return {
29
+ "browser.tabs": () => tabs.map(({ content: _content, ...tab }) => tab),
30
+ "browser.content": (params) => {
31
+ if (!params || typeof params !== "object" || Array.isArray(params))
32
+ throw new Error("browser.content: expected options");
33
+ if (params.tabId !== undefined &&
34
+ (typeof params.tabId !== "number" || !Number.isInteger(params.tabId)))
35
+ throw new Error("browser.content: invalid tabId");
36
+ if (params.format !== undefined &&
37
+ !["html", "text", "markdown"].includes(String(params.format)))
38
+ throw new Error("browser.content: invalid format");
39
+ if (params.cssSelector !== undefined)
40
+ throw new Error("browser.content: headless content does not support CSS selectors");
41
+ const tab = params.tabId === undefined
42
+ ? tabs.find((candidate) => candidate.active)
43
+ : tabs.find((candidate) => candidate.id === params.tabId);
44
+ if (tab?.content === undefined)
45
+ throw new Error("browser.content: no content supplied for tab");
46
+ return tab.content;
47
+ },
48
+ };
49
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};