pi-image-tools 1.0.4 → 1.0.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.
package/src/commands.ts CHANGED
@@ -1,79 +1,79 @@
1
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
-
3
- import type { PasteImageCommandHandlers } from "./types.js";
4
-
5
- const SUBCOMMAND_CLIPBOARD = "clipboard";
6
- const SUBCOMMAND_RECENT = "recent";
7
-
8
- const ARGUMENT_COMPLETIONS = [
9
- {
10
- value: SUBCOMMAND_CLIPBOARD,
11
- label: SUBCOMMAND_CLIPBOARD,
12
- description: "Attach image from clipboard",
13
- },
14
- {
15
- value: SUBCOMMAND_RECENT,
16
- label: SUBCOMMAND_RECENT,
17
- description: "Open recent images picker and attach selected image",
18
- },
19
- {
20
- value: "help",
21
- label: "help",
22
- description: "Show usage",
23
- },
24
- ] as const;
25
-
26
- function parseArgs(args: string): string[] {
27
- return args
28
- .trim()
29
- .split(/\s+/)
30
- .map((token) => token.trim().toLowerCase())
31
- .filter((token) => token.length > 0);
32
- }
33
-
34
- function usageMessage(): string {
35
- return "Usage: /paste-image [clipboard|recent]";
36
- }
37
-
38
- export function registerPasteImageCommand(
39
- pi: ExtensionAPI,
40
- handlers: PasteImageCommandHandlers,
41
- ): void {
42
- pi.registerCommand("paste-image", {
43
- description: "Attach an image from clipboard or use a recent-image picker",
44
- getArgumentCompletions: (argumentPrefix) => {
45
- const normalized = argumentPrefix.trim().toLowerCase();
46
- if (!normalized) {
47
- return [...ARGUMENT_COMPLETIONS];
48
- }
49
-
50
- const matches = ARGUMENT_COMPLETIONS.filter((item) => item.value.startsWith(normalized));
51
- return matches.length > 0 ? matches.map((item) => ({ ...item })) : null;
52
- },
53
- handler: async (args, ctx) => {
54
- const tokens = parseArgs(args);
55
-
56
- if (tokens.length === 0 || tokens[0] === SUBCOMMAND_CLIPBOARD) {
57
- await handlers.fromClipboard(ctx);
58
- return;
59
- }
60
-
61
- if (tokens[0] === SUBCOMMAND_RECENT) {
62
- if (tokens.length > 1) {
63
- ctx.ui.notify(usageMessage(), "warning");
64
- return;
65
- }
66
-
67
- await handlers.fromRecent(ctx);
68
- return;
69
- }
70
-
71
- if (tokens[0] === "help") {
72
- ctx.ui.notify(usageMessage(), "info");
73
- return;
74
- }
75
-
76
- ctx.ui.notify(usageMessage(), "warning");
77
- },
78
- });
79
- }
1
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
2
+
3
+ import type { PasteImageCommandHandlers } from "./types.js";
4
+
5
+ const SUBCOMMAND_CLIPBOARD = "clipboard";
6
+ const SUBCOMMAND_RECENT = "recent";
7
+
8
+ const ARGUMENT_COMPLETIONS = [
9
+ {
10
+ value: SUBCOMMAND_CLIPBOARD,
11
+ label: SUBCOMMAND_CLIPBOARD,
12
+ description: "Attach image from clipboard",
13
+ },
14
+ {
15
+ value: SUBCOMMAND_RECENT,
16
+ label: SUBCOMMAND_RECENT,
17
+ description: "Open recent images picker and attach selected image",
18
+ },
19
+ {
20
+ value: "help",
21
+ label: "help",
22
+ description: "Show usage",
23
+ },
24
+ ] as const;
25
+
26
+ function parseArgs(args: string): string[] {
27
+ return args
28
+ .trim()
29
+ .split(/\s+/)
30
+ .map((token) => token.trim().toLowerCase())
31
+ .filter((token) => token.length > 0);
32
+ }
33
+
34
+ function usageMessage(): string {
35
+ return "Usage: /paste-image [clipboard|recent]";
36
+ }
37
+
38
+ export function registerPasteImageCommand(
39
+ pi: ExtensionAPI,
40
+ handlers: PasteImageCommandHandlers,
41
+ ): void {
42
+ pi.registerCommand("paste-image", {
43
+ description: "Attach an image from clipboard or use a recent-image picker",
44
+ getArgumentCompletions: (argumentPrefix) => {
45
+ const normalized = argumentPrefix.trim().toLowerCase();
46
+ if (!normalized) {
47
+ return [...ARGUMENT_COMPLETIONS];
48
+ }
49
+
50
+ const matches = ARGUMENT_COMPLETIONS.filter((item) => item.value.startsWith(normalized));
51
+ return matches.length > 0 ? matches.map((item) => ({ ...item })) : null;
52
+ },
53
+ handler: async (args, ctx) => {
54
+ const tokens = parseArgs(args);
55
+
56
+ if (tokens.length === 0 || tokens[0] === SUBCOMMAND_CLIPBOARD) {
57
+ await handlers.fromClipboard(ctx);
58
+ return;
59
+ }
60
+
61
+ if (tokens[0] === SUBCOMMAND_RECENT) {
62
+ if (tokens.length > 1) {
63
+ ctx.ui.notify(usageMessage(), "warning");
64
+ return;
65
+ }
66
+
67
+ await handlers.fromRecent(ctx);
68
+ return;
69
+ }
70
+
71
+ if (tokens[0] === "help") {
72
+ ctx.ui.notify(usageMessage(), "info");
73
+ return;
74
+ }
75
+
76
+ ctx.ui.notify(usageMessage(), "warning");
77
+ },
78
+ });
79
+ }