@ryan_nookpi/pi-extension-clipboard 0.1.1 → 0.1.2
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/index.ts +49 -51
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Ask the LLM: "write me a draft reply and put it into clipboard!"
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
13
13
|
import { Type } from "@sinclair/typebox";
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -36,61 +36,59 @@ function copyToClipboard(text: string): void {
|
|
|
36
36
|
process.stdout.write(osc52);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
export default function clipboardExtension(pi: ExtensionAPI): void {
|
|
40
|
+
pi.registerTool({
|
|
41
|
+
name: "copy_to_clipboard",
|
|
42
|
+
label: "Copy to Clipboard",
|
|
43
|
+
description:
|
|
44
|
+
"Copy text to the user's system clipboard. Use this when the user asks you to " +
|
|
45
|
+
"put something in their clipboard, write a draft reply to clipboard, or copy any " +
|
|
46
|
+
"generated text for easy pasting. The text will be available for pasting immediately.",
|
|
47
|
+
parameters: Type.Object({
|
|
48
|
+
text: Type.String({
|
|
49
|
+
description: "The text to copy to the clipboard",
|
|
50
|
+
}),
|
|
49
51
|
}),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const { text } = params;
|
|
52
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
53
|
+
const { text } = params;
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
if (!text || text.trim().length === 0) {
|
|
56
|
+
return {
|
|
57
|
+
content: [{ type: "text", text: "Error: No text provided to copy." }],
|
|
58
|
+
details: { success: false, error: "empty_text" },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
try {
|
|
63
|
+
copyToClipboard(text);
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const preview = text.length > 100 ? `${text.slice(0, 100)}...` : text;
|
|
66
|
+
const charCount = text.length;
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
if (ctx.hasUI) {
|
|
69
|
+
ctx.ui.notify(`Copied ${charCount} characters to clipboard`, "info");
|
|
70
|
+
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
return {
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: "text",
|
|
76
|
+
text: `Successfully copied ${charCount} characters to clipboard.\n\nPreview:\n${preview}`,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
details: {
|
|
80
|
+
success: true,
|
|
81
|
+
characterCount: charCount,
|
|
82
|
+
preview,
|
|
76
83
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
content: [{ type: "text", text: `Failed to copy to clipboard: ${errorMessage}` }],
|
|
88
|
-
details: { success: false, error: errorMessage },
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
export default function clipboardExtension(pi: ExtensionAPI): void {
|
|
95
|
-
pi.registerTool(copyToClipboardTool);
|
|
84
|
+
};
|
|
85
|
+
} catch (error) {
|
|
86
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
87
|
+
return {
|
|
88
|
+
content: [{ type: "text", text: `Failed to copy to clipboard: ${errorMessage}` }],
|
|
89
|
+
details: { success: false, error: errorMessage },
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
});
|
|
96
94
|
}
|