pi-paster 0.1.5 → 0.2.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/dist/index.d.mts +49 -1
- package/dist/index.mjs +416 -27
- package/package.json +5 -2
- package/src/clipboard.ts +73 -3
- package/src/editor.ts +2 -8
- package/src/image-utils.ts +192 -11
- package/src/index.ts +12 -5
- package/src/optimize-image.ts +209 -0
- package/src/preview.ts +3 -2
- package/src/terminal-input.ts +2 -6
- package/src/types.ts +19 -1
package/src/terminal-input.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PASTE_END, PASTE_START } from "./editor.ts";
|
|
2
|
-
import { replaceImagePathsInText } from "./image-utils.ts";
|
|
2
|
+
import { describeReject, replaceImagePathsInText } from "./image-utils.ts";
|
|
3
3
|
import type { AttachmentStore } from "./store.ts";
|
|
4
4
|
import type { ImageAttachment, LoadImageResult } from "./types.ts";
|
|
5
5
|
|
|
@@ -19,11 +19,7 @@ export function createImagePasteTerminalInputHandler(options: {
|
|
|
19
19
|
cwd: options.cwd,
|
|
20
20
|
store: options.store,
|
|
21
21
|
loadImage: options.loadImage,
|
|
22
|
-
onReject: (result) =>
|
|
23
|
-
if (result.reason === "too-large") {
|
|
24
|
-
options.notify?.(`paster: image is over 10 MB and was not attached: ${result.path}`);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
22
|
+
onReject: (result) => describeReject(result, options.notify),
|
|
27
23
|
});
|
|
28
24
|
|
|
29
25
|
return (data: string): TerminalInputResult => {
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { ImageDimensions } from "@earendil-works/pi-tui";
|
|
2
2
|
|
|
3
3
|
export const EXTENSION_NAME = "paster";
|
|
4
|
-
|
|
4
|
+
// Cap on the source file we read from disk. Larger inputs are rejected up
|
|
5
|
+
// front with `too-large` so we never try to base64-encode a multi-gigabyte
|
|
6
|
+
// file. Raised from the legacy 10 MB so high-resolution screenshots and raw
|
|
7
|
+
// camera shots can be ingested and then shrunk by optimize-image.ts before
|
|
8
|
+
// being attached.
|
|
9
|
+
export const MAX_IMAGE_BYTES = 64 * 1024 * 1024;
|
|
10
|
+
|
|
11
|
+
// Hard limits enforced by the Anthropic Messages API. Used by
|
|
12
|
+
// optimize-image.ts to decide when an attachment needs to be shrunk.
|
|
13
|
+
export const ANTHROPIC_MAX_DIMENSION = 8000;
|
|
14
|
+
export const ANTHROPIC_MAX_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
5
15
|
|
|
6
16
|
export type SupportedImageMimeType = "image/png" | "image/jpeg" | "image/webp" | "image/gif";
|
|
7
17
|
|
|
@@ -13,6 +23,14 @@ export interface ImageAttachment {
|
|
|
13
23
|
data: string;
|
|
14
24
|
dimensions?: ImageDimensions;
|
|
15
25
|
createdAt: number;
|
|
26
|
+
/** True once optimizeImageBytes has run on this attachment. */
|
|
27
|
+
optimized?: boolean;
|
|
28
|
+
/** Original (pre-optimization) base64 size in bytes — informational. */
|
|
29
|
+
originalBytes?: number;
|
|
30
|
+
/** Final (post-optimization) base64 size in bytes — informational. */
|
|
31
|
+
finalBytes?: number;
|
|
32
|
+
/** Human-readable trail of optimization actions applied, if any. */
|
|
33
|
+
optimizeActions?: string[];
|
|
16
34
|
}
|
|
17
35
|
|
|
18
36
|
export interface LoadedImage {
|