@framers/agentos-ext-vision-pipeline 0.2.2 → 0.3.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/SKILL.md CHANGED
@@ -11,23 +11,38 @@ tools_required: [vision-pipeline]
11
11
  Extract text from images, documents, and handwritten notes with a progressive 3-tier pipeline: local OCR (PaddleOCR or Tesseract), then local vision models (TrOCR, Florence-2), then cloud vision.
12
12
 
13
13
  ## Tool
14
- **vision-pipeline** takes `imageUrl`, `mode` and `maxTier`. `imageUrl` is a `data:image/...` URL or an http(s) URL on a public host: local file paths and addresses on this machine or a private network are refused, so a model cannot send the machine's files, or what its network serves, to a cloud model. With AgentOS 0.13.16 or later, the tool fetches an http(s) image through `imageToBuffer`'s untrusted mode and hands the pipeline the bytes: every address the host resolves to is checked when the connection is made, each redirect is checked the same way, and the fetch stops at 50 MiB and 30 seconds. With an older AgentOS the check reads the URL's host as written, so the address a public name resolves to and a redirect's target are not checked.
14
+ **vision-pipeline** takes `imageUrl`, `mode` and `maxTier`. `imageUrl` is one of:
15
+ - an http(s) URL on a public host;
16
+ - a `data:image/...` URL;
17
+ - the `file:` URL of an image the image-generation or image-editing tools saved, for the caller it was saved for.
18
+
19
+ Every other local file is refused, and so are addresses on this machine or a private network (for IPv6, everything outside `2000::/3`), so a model cannot send the machine's files, or what its network serves, to a cloud model. An http(s) image is fetched through AgentOS's `imageToBuffer` in its untrusted mode, and the pipeline gets the bytes: every address the host resolves to is checked when the connection is made, each redirect is checked the same way, and the image is held to 50 MiB and 30 seconds.
15
20
 
16
21
  | mode | what it returns | lowest maxTier |
17
22
  |------|-----------------|----------------|
18
23
  | `auto` (default) | the pipeline's best text | 1 |
19
24
  | `ocr` | printed text | 1 |
20
25
  | `handwriting` | handwritten text (TrOCR) | 2 |
21
- | `layout` | document text and structure (Florence-2) | 2 |
26
+ | `layout` | the lines of text, each with its box, in `layout` (Florence-2) | 2 |
22
27
  | `embed` | a CLIP embedding vector | 2 |
23
28
  | `describe` | what the image shows (cloud vision) | 3 |
24
29
 
25
- `maxTier` 1 runs local OCR alone, 2 adds the local vision models, 3 (default) may use cloud vision.
30
+ `maxTier` 1 runs local OCR alone, 2 adds the local vision models, 3 (default) may use cloud vision. Any other value is refused: it is not read as 3.
31
+
32
+ `handwriting` and `layout` run the tier they are named for and nothing else. When its model is not installed the call fails with the reason; it does not come back with plain OCR text. `auto` lets the pipeline choose, and returns as soon as a tier is confident.
33
+
34
+ A text result (every mode but `embed`) names the tiers that ran in `tiers`. A tier that was due to run and failed, such as a model that did not load, is listed in `failedTiers` with its error, and the text comes from the tiers that ran. `embed` returns the vector in `embedding` with its `dimensions`, or the error when the embedding tier cannot run.
35
+
36
+ CLIP is loaded for `embed` alone, the first time it is asked for: no text call runs an embedding.
37
+
38
+ Requires `@framers/agentos` 0.13.40 or later.
26
39
 
27
40
  ## Setup
28
- The local tiers use the optional packages AgentOS finds installed: `ppu-paddle-ocr` or `tesseract.js` for OCR, and `@huggingface/transformers` for handwriting, layout and embeddings. With an OpenAI key in the pack option `openaiApiKey` or the secret `openai.apiKey`, the cloud tier uses OpenAI with that key. Without one, it uses the first provider whose key is in the environment: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY` (or `GEMINI_API_KEY`), `OPENROUTER_API_KEY`. `describe` and the cloud tier need `@framers/agentos` 0.12.14 or later: earlier releases send the image to the cloud model as text, and read the key from the environment only.
41
+ The local tiers use the optional packages AgentOS finds installed: `ppu-paddle-ocr` or `tesseract.js` for OCR, and `@huggingface/transformers` for handwriting, layout and embeddings. With an OpenAI key in the pack option `openaiApiKey` or the secret `openai.apiKey`, the cloud tier uses OpenAI with that key. Without one, it uses the first provider whose key is in the environment: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY` (or `GEMINI_API_KEY`), `OPENROUTER_API_KEY`.
42
+
43
+ The images directory, for `file:` sources, is the pack option `imageDir`, else the environment variable `AGENTOS_IMAGE_DIR`, else `agentos-images-<uid>` in the temp directory: the same as the image-generation and image-editing packs', under the same rule: it belongs to the service's user, and so does every directory above it unless that one is root's (any that others can write must be sticky, as `/tmp` is). Give all three the same `imageDir`.
29
44
 
30
45
  ## Example
31
46
  "Read the text from this receipt"
32
47
  "What does this handwritten note say?"
33
- "Extract the table data from this PDF page"
48
+ "List the lines of this scanned page with where each one sits"
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @fileoverview Where the image tools keep image data, and how a saved image
3
+ * comes back as a source.
4
+ *
5
+ * A provider that answers with image data (OpenAI's GPT Image models always
6
+ * do) used to have that data returned to the model as a `data:` URL: megabytes
7
+ * of base64 in the next request. The tools save the bytes to a file and return
8
+ * its `file:` URL, or hand them to the host's own saver. A saved file's URL is
9
+ * accepted as a source by the image-editing tools and by `vision-pipeline`.
10
+ * The image-generation, image-editing and vision-pipeline packs each carry
11
+ * this file, the same in all three, so they agree on the directory.
12
+ *
13
+ * The directory is private to the service's user, each caller has a
14
+ * subdirectory of its own, and no other user can change a directory above
15
+ * it. That is the trust boundary: only this user can put a file there, or
16
+ * swap the directory for another, so a file there with the saver's name
17
+ * pattern is one the service wrote.
18
+ */
19
+ /** The most bytes of a saved image the tools read back as a source: 50 MiB. */
20
+ export declare const MAX_SOURCE_BYTES: number;
21
+ /**
22
+ * The images directory: the pack option `imageDir`, else the environment
23
+ * variable `AGENTOS_IMAGE_DIR`, else a folder in the user's temp directory,
24
+ * which the operating system clears (the packs delete nothing). On POSIX the
25
+ * default carries the user id, since `/tmp` is shared. On Windows it is the
26
+ * user's own temp folder whatever `TEMP` says: `os.tmpdir()` reads `TEMP`,
27
+ * which can name a folder every user shares.
28
+ */
29
+ export declare function imageDirectory(option?: unknown): string;
30
+ /**
31
+ * The name of a caller's subdirectory: `u-` and 32 hex characters of the
32
+ * SHA-256 of its user id, or `shared` for a call that carries none. A host
33
+ * with several users gives each call its user (`context.userContext.userId`),
34
+ * so one user's saved image is no source for another.
35
+ */
36
+ export declare function scopeOf(context?: {
37
+ userContext?: {
38
+ userId?: unknown;
39
+ };
40
+ }): string;
41
+ /** The kind of image `bytes` are, by their signature: PNG, JPEG or WebP. */
42
+ export declare function imageKind(bytes: Buffer): {
43
+ ext: 'png' | 'jpg' | 'webp';
44
+ mimeType: string;
45
+ } | undefined;
46
+ /**
47
+ * Saves image bytes as a new file in the caller's subdirectory of `dir` and
48
+ * returns its `file:` URL. The extension comes from the bytes' signature, and
49
+ * the name is random, so a file is never overwritten.
50
+ *
51
+ * @throws When the bytes are not a PNG, JPEG or WebP image, or when the
52
+ * directory cannot be made, is not private to this user, or cannot be
53
+ * written. The message names the directory and the option that sets it.
54
+ */
55
+ export declare function saveImageFile(bytes: Buffer, dir: string, scope: string): Promise<string>;
56
+ /**
57
+ * The bytes of the saved image that `source` names, or `undefined` when
58
+ * `source` is not the `file:` URL of an image the saver wrote for this
59
+ * caller. Every reason gives `undefined`, so the caller's one refusal does
60
+ * not tell which files exist.
61
+ *
62
+ * The file must carry the saver's name pattern and sit directly in the
63
+ * caller's subdirectory of the images directory's real path: the same
64
+ * directory by device and inode, itself a directory and not a link, private
65
+ * to this user, as the images directory is, with no directory above it that
66
+ * another user can change. It must be a regular file with one link and at
67
+ * most {@link MAX_SOURCE_BYTES}, and start with a PNG, JPEG or WebP
68
+ * signature. It is opened once, without following a link, and read from
69
+ * that handle.
70
+ */
71
+ export declare function readSavedImage(source: string, dir: string, scope: string): Promise<Buffer | undefined>;
72
+ /** An image as AgentOS's image functions return it. */
73
+ export interface ReturnedImage {
74
+ url?: string;
75
+ dataUrl?: string;
76
+ base64?: string;
77
+ mimeType?: string;
78
+ }
79
+ /**
80
+ * A host's own saver: it stores the bytes where the host's clients can load
81
+ * them and returns that http(s) URL.
82
+ */
83
+ export type SaveImage = (image: {
84
+ bytes: Buffer;
85
+ mimeType: string;
86
+ tool: string;
87
+ context?: unknown;
88
+ }) => string | Promise<string>;
89
+ /** Where the tools keep image data: the directory of the default saver, and a host's own saver when it gave one. */
90
+ export interface ImageStore {
91
+ /** The images directory (see {@link imageDirectory}). */
92
+ dir: string;
93
+ /** The host's saver, which replaces the default. */
94
+ saveImage?: SaveImage;
95
+ }
96
+ /** The store for a pack's options: its `imageDir` and its `saveImage`, when that is a function. */
97
+ export declare function imageStore(options?: {
98
+ imageDir?: unknown;
99
+ saveImage?: unknown;
100
+ }): ImageStore;
101
+ /**
102
+ * An image a provider returned, as the reference the caller gets: the
103
+ * provider's http(s) URL as it is, or, for image data, the URL under which
104
+ * it was saved. Image data is never returned itself: as a `data:` URL it
105
+ * would go into the model's next request, megabytes of base64. `undefined`
106
+ * when the provider returned neither a URL nor data.
107
+ *
108
+ * @throws When the data is not a PNG, JPEG or WebP image, when it cannot be
109
+ * saved, or when the host's saver throws or returns anything but an
110
+ * http(s) URL of at most 2,048 characters.
111
+ */
112
+ export declare function storeImage(image: ReturnedImage | undefined, tool: string, store: ImageStore, context?: unknown): Promise<string | undefined>;
113
+ //# sourceMappingURL=imageFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imageFiles.d.ts","sourceRoot":"","sources":["../src/imageFiles.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AASH,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,QAAmB,CAAC;AAQjD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAOvD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,GAAG,MAAM,CAKhF;AAED,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAStG;AAsCD;;;;;;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C,CAgB7B"}
@@ -0,0 +1,282 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @fileoverview Where the image tools keep image data, and how a saved image
4
+ * comes back as a source.
5
+ *
6
+ * A provider that answers with image data (OpenAI's GPT Image models always
7
+ * do) used to have that data returned to the model as a `data:` URL: megabytes
8
+ * of base64 in the next request. The tools save the bytes to a file and return
9
+ * its `file:` URL, or hand them to the host's own saver. A saved file's URL is
10
+ * accepted as a source by the image-editing tools and by `vision-pipeline`.
11
+ * The image-generation, image-editing and vision-pipeline packs each carry
12
+ * this file, the same in all three, so they agree on the directory.
13
+ *
14
+ * The directory is private to the service's user, each caller has a
15
+ * subdirectory of its own, and no other user can change a directory above
16
+ * it. That is the trust boundary: only this user can put a file there, or
17
+ * swap the directory for another, so a file there with the saver's name
18
+ * pattern is one the service wrote.
19
+ */
20
+ import { createHash, randomBytes } from 'node:crypto';
21
+ import { constants as fsConstants } from 'node:fs';
22
+ import * as fs from 'node:fs/promises';
23
+ import * as os from 'node:os';
24
+ import * as path from 'node:path';
25
+ import { fileURLToPath, pathToFileURL } from 'node:url';
26
+ /** The most bytes of a saved image the tools read back as a source: 50 MiB. */
27
+ export const MAX_SOURCE_BYTES = 50 * 1024 * 1024;
28
+ /** The name of a file the saver wrote. */
29
+ const SAVED_NAME = /^agentos-image-[0-9a-f]{32}\.(png|jpg|webp)$/;
30
+ /** The eight bytes every PNG starts with. */
31
+ const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
32
+ /**
33
+ * The images directory: the pack option `imageDir`, else the environment
34
+ * variable `AGENTOS_IMAGE_DIR`, else a folder in the user's temp directory,
35
+ * which the operating system clears (the packs delete nothing). On POSIX the
36
+ * default carries the user id, since `/tmp` is shared. On Windows it is the
37
+ * user's own temp folder whatever `TEMP` says: `os.tmpdir()` reads `TEMP`,
38
+ * which can name a folder every user shares.
39
+ */
40
+ export function imageDirectory(option) {
41
+ const named = [option, process.env.AGENTOS_IMAGE_DIR]
42
+ .map((value) => (typeof value === 'string' ? value.trim() : ''))
43
+ .find(Boolean);
44
+ if (named)
45
+ return path.resolve(named);
46
+ if (typeof process.getuid === 'function')
47
+ return path.join(os.tmpdir(), `agentos-images-${process.getuid()}`);
48
+ return path.join(os.homedir(), 'AppData', 'Local', 'Temp', 'agentos-images');
49
+ }
50
+ /**
51
+ * The name of a caller's subdirectory: `u-` and 32 hex characters of the
52
+ * SHA-256 of its user id, or `shared` for a call that carries none. A host
53
+ * with several users gives each call its user (`context.userContext.userId`),
54
+ * so one user's saved image is no source for another.
55
+ */
56
+ export function scopeOf(context) {
57
+ const userId = context?.userContext?.userId;
58
+ return typeof userId === 'string' && userId !== ''
59
+ ? `u-${createHash('sha256').update(userId).digest('hex').slice(0, 32)}`
60
+ : 'shared';
61
+ }
62
+ /** The kind of image `bytes` are, by their signature: PNG, JPEG or WebP. */
63
+ export function imageKind(bytes) {
64
+ if (bytes.length >= 8 && bytes.subarray(0, 8).equals(PNG_SIGNATURE))
65
+ return { ext: 'png', mimeType: 'image/png' };
66
+ if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) {
67
+ return { ext: 'jpg', mimeType: 'image/jpeg' };
68
+ }
69
+ if (bytes.length >= 12 && bytes.toString('latin1', 0, 4) === 'RIFF' && bytes.toString('latin1', 8, 12) === 'WEBP') {
70
+ return { ext: 'webp', mimeType: 'image/webp' };
71
+ }
72
+ return undefined;
73
+ }
74
+ /**
75
+ * Whether a directory's `stat` (taken with `bigint: true`) shows it private
76
+ * to this user: a directory this user owns that neither its group nor others
77
+ * can write. Where the platform has no user ids (Windows) only the kind is
78
+ * checked: the default there is inside the user's own profile.
79
+ */
80
+ function isPrivateDirectory(stat) {
81
+ if (!stat.isDirectory())
82
+ return false;
83
+ if (typeof process.getuid !== 'function')
84
+ return true;
85
+ return stat.uid === BigInt(process.getuid()) && (stat.mode & BigInt(0o022)) === BigInt(0);
86
+ }
87
+ /**
88
+ * Whether no other user can rename or replace `dir`, a real path, through a
89
+ * directory above it: each one is owned by this user or by root, and none
90
+ * can be written by its group or by others unless it is sticky (as `/tmp`
91
+ * is), where only an entry's owner can rename it. Where the platform has no
92
+ * user ids (Windows) nothing is checked.
93
+ */
94
+ async function hasTrustedParents(dir) {
95
+ if (typeof process.getuid !== 'function')
96
+ return true;
97
+ const uid = BigInt(process.getuid());
98
+ for (let parent = path.dirname(dir);; parent = path.dirname(parent)) {
99
+ const stat = await fs.lstat(parent, { bigint: true });
100
+ const sticky = (stat.mode & BigInt(0o1000)) !== BigInt(0);
101
+ const writableByOthers = (stat.mode & BigInt(0o022)) !== BigInt(0);
102
+ if (!stat.isDirectory() || (stat.uid !== uid && stat.uid !== BigInt(0)) || (writableByOthers && !sticky))
103
+ return false;
104
+ if (path.dirname(parent) === parent)
105
+ return true;
106
+ }
107
+ }
108
+ /** The error for a directory that is not private to this user. */
109
+ function notPrivate(dir) {
110
+ return new Error(`${dir} is not a directory that this user owns and no one else can write`);
111
+ }
112
+ /**
113
+ * Saves image bytes as a new file in the caller's subdirectory of `dir` and
114
+ * returns its `file:` URL. The extension comes from the bytes' signature, and
115
+ * the name is random, so a file is never overwritten.
116
+ *
117
+ * @throws When the bytes are not a PNG, JPEG or WebP image, or when the
118
+ * directory cannot be made, is not private to this user, or cannot be
119
+ * written. The message names the directory and the option that sets it.
120
+ */
121
+ export async function saveImageFile(bytes, dir, scope) {
122
+ const kind = imageKind(bytes);
123
+ if (!kind)
124
+ throw new Error('The provider returned data that is not a PNG, JPEG or WebP image.');
125
+ try {
126
+ // The directory is written by its real path, which no other user can
127
+ // change once the directories above it are checked.
128
+ await fs.mkdir(dir, { recursive: true, mode: 0o700 });
129
+ const root = await fs.realpath(dir);
130
+ if (!isPrivateDirectory(await fs.stat(root, { bigint: true })))
131
+ throw notPrivate(root);
132
+ if (!(await hasTrustedParents(root)))
133
+ throw new Error(`another user can change a directory above ${root}`);
134
+ const scopeDir = path.join(root, scope);
135
+ await fs.mkdir(scopeDir, { recursive: true, mode: 0o700 });
136
+ // lstat: a caller's directory that is a link to another caller's is refused.
137
+ if (!isPrivateDirectory(await fs.lstat(scopeDir, { bigint: true })))
138
+ throw notPrivate(scopeDir);
139
+ const file = path.join(scopeDir, `agentos-image-${randomBytes(16).toString('hex')}.${kind.ext}`);
140
+ await fs.writeFile(file, bytes, { flag: 'wx', mode: 0o600 });
141
+ return pathToFileURL(file).href;
142
+ }
143
+ catch (error) {
144
+ const reason = error instanceof Error ? error.message : String(error);
145
+ throw new Error(`The image could not be saved under ${dir}: ${reason}. Set the pack's imageDir option, or AGENTOS_IMAGE_DIR, to a directory that the service's user owns and no one else can write.`);
146
+ }
147
+ }
148
+ /**
149
+ * The bytes of the saved image that `source` names, or `undefined` when
150
+ * `source` is not the `file:` URL of an image the saver wrote for this
151
+ * caller. Every reason gives `undefined`, so the caller's one refusal does
152
+ * not tell which files exist.
153
+ *
154
+ * The file must carry the saver's name pattern and sit directly in the
155
+ * caller's subdirectory of the images directory's real path: the same
156
+ * directory by device and inode, itself a directory and not a link, private
157
+ * to this user, as the images directory is, with no directory above it that
158
+ * another user can change. It must be a regular file with one link and at
159
+ * most {@link MAX_SOURCE_BYTES}, and start with a PNG, JPEG or WebP
160
+ * signature. It is opened once, without following a link, and read from
161
+ * that handle.
162
+ */
163
+ export async function readSavedImage(source, dir, scope) {
164
+ let handle;
165
+ try {
166
+ const url = new URL(source);
167
+ if (url.protocol !== 'file:' || url.hostname !== '')
168
+ return undefined;
169
+ const named = fileURLToPath(url);
170
+ if (!SAVED_NAME.test(path.basename(named)))
171
+ return undefined;
172
+ // fs.promises.realpath asks the operating system. (fs.realpathSync and
173
+ // fs.realpath resolve ".." in the text first, as path.resolve does.)
174
+ const real = await fs.realpath(named);
175
+ if (!SAVED_NAME.test(path.basename(real)))
176
+ return undefined;
177
+ // The images directory as it is now, by its real path, so a directory
178
+ // swapped in for it is read as what it is; and the caller's directory in
179
+ // it by lstat, so a link to another caller's directory is refused.
180
+ const root = await fs.realpath(dir);
181
+ const [rootDir, parent, scopeDir] = await Promise.all([
182
+ fs.stat(root, { bigint: true }),
183
+ fs.stat(path.dirname(real), { bigint: true }),
184
+ fs.lstat(path.join(root, scope), { bigint: true }),
185
+ ]);
186
+ if (!isPrivateDirectory(rootDir) || !isPrivateDirectory(scopeDir))
187
+ return undefined;
188
+ if (parent.dev !== scopeDir.dev || parent.ino !== scopeDir.ino)
189
+ return undefined;
190
+ if (!(await hasTrustedParents(root)))
191
+ return undefined;
192
+ // A FIFO would hold an open until a writer came; only a regular file is opened.
193
+ if (!(await fs.lstat(real)).isFile())
194
+ return undefined;
195
+ handle = await fs.open(real, fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0));
196
+ const stat = await handle.stat();
197
+ if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_SOURCE_BYTES)
198
+ return undefined;
199
+ // One byte more than the size at open: a file that has grown is refused.
200
+ const buffer = Buffer.alloc(stat.size + 1);
201
+ let length = 0;
202
+ while (length < buffer.length) {
203
+ const { bytesRead } = await handle.read(buffer, length, buffer.length - length, null);
204
+ if (bytesRead === 0)
205
+ break;
206
+ length += bytesRead;
207
+ }
208
+ if (length > stat.size)
209
+ return undefined;
210
+ const bytes = buffer.subarray(0, length);
211
+ return imageKind(bytes) ? bytes : undefined;
212
+ }
213
+ catch {
214
+ return undefined;
215
+ }
216
+ finally {
217
+ await handle?.close().catch(() => { });
218
+ }
219
+ }
220
+ /** The store for a pack's options: its `imageDir` and its `saveImage`, when that is a function. */
221
+ export function imageStore(options) {
222
+ return {
223
+ dir: imageDirectory(options?.imageDir),
224
+ saveImage: typeof options?.saveImage === 'function' ? options.saveImage : undefined,
225
+ };
226
+ }
227
+ /** The longest reference a host's saver may return. */
228
+ const MAX_REFERENCE_LENGTH = 2048;
229
+ /** The bytes of a base64 `data:` URL, the form AgentOS's providers give image data in; `undefined` for anything else. */
230
+ function dataUrlBytes(value) {
231
+ if (typeof value !== 'string' || !/^data:/i.test(value))
232
+ return undefined;
233
+ const comma = value.indexOf(',');
234
+ if (comma === -1 || !/; *base64 *$/i.test(value.slice(0, comma)))
235
+ return undefined;
236
+ return Buffer.from(value.slice(comma + 1), 'base64');
237
+ }
238
+ /** Whether a saver's result is an http(s) URL short enough to hand to the model. */
239
+ function isHttpReference(value) {
240
+ if (typeof value !== 'string' || value.length === 0 || value.length > MAX_REFERENCE_LENGTH)
241
+ return false;
242
+ try {
243
+ const { protocol } = new URL(value);
244
+ return protocol === 'http:' || protocol === 'https:';
245
+ }
246
+ catch {
247
+ return false;
248
+ }
249
+ }
250
+ /**
251
+ * An image a provider returned, as the reference the caller gets: the
252
+ * provider's http(s) URL as it is, or, for image data, the URL under which
253
+ * it was saved. Image data is never returned itself: as a `data:` URL it
254
+ * would go into the model's next request, megabytes of base64. `undefined`
255
+ * when the provider returned neither a URL nor data.
256
+ *
257
+ * @throws When the data is not a PNG, JPEG or WebP image, when it cannot be
258
+ * saved, or when the host's saver throws or returns anything but an
259
+ * http(s) URL of at most 2,048 characters.
260
+ */
261
+ export async function storeImage(image, tool, store, context) {
262
+ if (!image)
263
+ return undefined;
264
+ if (typeof image.url === 'string' && /^https?:\/\//i.test(image.url))
265
+ return image.url;
266
+ const bytes = typeof image.base64 === 'string' && image.base64 !== ''
267
+ ? Buffer.from(image.base64, 'base64')
268
+ : (dataUrlBytes(image.dataUrl) ?? dataUrlBytes(image.url));
269
+ if (!bytes || bytes.length === 0)
270
+ return undefined;
271
+ if (!store.saveImage)
272
+ return saveImageFile(bytes, store.dir, scopeOf(context));
273
+ const kind = imageKind(bytes);
274
+ if (!kind)
275
+ throw new Error('The provider returned data that is not a PNG, JPEG or WebP image.');
276
+ const reference = await store.saveImage({ bytes, mimeType: kind.mimeType, tool, context });
277
+ if (!isHttpReference(reference)) {
278
+ throw new Error("The host's saveImage must return an http(s) URL of at most 2,048 characters.");
279
+ }
280
+ return reference;
281
+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AAK,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3F,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -12,14 +12,29 @@
12
12
  * The cloud tier reads OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY (or
13
13
  * GEMINI_API_KEY) or OPENROUTER_API_KEY from the environment.
14
14
  *
15
+ * The pipelines are built without the embedding tier. With it, every text
16
+ * call would run a CLIP embedding and wait for it, to return a result that
17
+ * has no place for the vector; the first such call downloads a 350 MB model.
18
+ * The `embed` mode loads CLIP when it is first asked for.
19
+ *
20
+ * An image is an http(s) URL, a data URL, or the `file:` URL of an image the
21
+ * image-generation or image-editing tools saved: the three packs share the
22
+ * images directory (`imageDir`, `AGENTOS_IMAGE_DIR`, or a folder in the
23
+ * user's temp directory).
24
+ *
15
25
  * @module @framers/agentos-ext-vision-pipeline
16
26
  */
17
27
  /** What the extension manager passes the pack factory. */
18
28
  export interface ExtensionContext {
19
- /** `priority` of the tool descriptor (default 45); `openaiApiKey` for the cloud tier. */
29
+ /**
30
+ * `priority` of the tool descriptor (default 45); `openaiApiKey` for the
31
+ * cloud tier; `imageDir`, the images directory the image tools save to
32
+ * (else `AGENTOS_IMAGE_DIR`, else a folder in the user's temp directory).
33
+ */
20
34
  options?: {
21
35
  priority?: number;
22
36
  openaiApiKey?: string;
37
+ imageDir?: string;
23
38
  } & Record<string, unknown>;
24
39
  /** Reads a secret, such as `openai.apiKey`. */
25
40
  getSecret?: (key: string) => string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;GAeG;AAQH,0DAA0D;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,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC3E,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvG,eAAe,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -13,10 +13,21 @@
13
13
  * The cloud tier reads OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY (or
14
14
  * GEMINI_API_KEY) or OPENROUTER_API_KEY from the environment.
15
15
  *
16
+ * The pipelines are built without the embedding tier. With it, every text
17
+ * call would run a CLIP embedding and wait for it, to return a result that
18
+ * has no place for the vector; the first such call downloads a 350 MB model.
19
+ * The `embed` mode loads CLIP when it is first asked for.
20
+ *
21
+ * An image is an http(s) URL, a data URL, or the `file:` URL of an image the
22
+ * image-generation or image-editing tools saved: the three packs share the
23
+ * images directory (`imageDir`, `AGENTOS_IMAGE_DIR`, or a folder in the
24
+ * user's temp directory).
25
+ *
16
26
  * @module @framers/agentos-ext-vision-pipeline
17
27
  */
18
28
  import { createRequire } from 'node:module';
19
29
  import { createVisionPipeline } from '@framers/agentos';
30
+ import { imageStore } from './imageFiles.js';
20
31
  import { VisionPipelineTool } from './tools/visionPipeline.js';
21
32
  const { version } = createRequire(import.meta.url)('../package.json');
22
33
  /**
@@ -43,7 +54,7 @@ export function createExtensionPack(context = {}) {
43
54
  return Promise.reject(new Error('The Vision & OCR Pipeline pack is deactivated.'));
44
55
  let pipeline = pipelines.get(strategy);
45
56
  if (!pipeline) {
46
- pipeline = createVisionPipeline({ strategy, ...cloud });
57
+ pipeline = createVisionPipeline({ strategy, embedding: false, ...cloud });
47
58
  pipelines.set(strategy, pipeline);
48
59
  const built = pipeline;
49
60
  built.catch(() => {
@@ -53,7 +64,7 @@ export function createExtensionPack(context = {}) {
53
64
  }
54
65
  return pipeline;
55
66
  };
56
- const tool = new VisionPipelineTool(pipelineFor);
67
+ const tool = new VisionPipelineTool(pipelineFor, { dir: imageStore({ imageDir: context.options?.imageDir }).dir });
57
68
  return {
58
69
  name: '@framers/agentos-ext-vision-pipeline',
59
70
  version,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAuB,MAAM,2BAA2B,CAAC;AAEpF,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,iBAAiB,CAAC,CAAC;AA0BtE;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,UAA4B,EAAE;IAChE,8EAA8E;IAC9E,6EAA6E;IAC7E,4EAA4E;IAC5E,oDAAoD;IACpD,MAAM,QAAQ,GAAG,CAAC,GAAG,MAAiB,EAAE,EAAE,CACxC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC;IACpG,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC;IAChG,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnF,MAAM,SAAS,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC1D,uEAAuE;IACvE,2CAA2C;IAC3C,IAAI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AQ,IAAI,KAAK,EAAE,CAAC;gBAC7B,IAAI,QAAQ,CAAC;gBACb,IAAI,CAAC;oBACH,QAAQ,GAAG,MAAM,QAAQ,CAAC;gBAC5B,CAAC;gBAAC,MAAM,CAAC;oBACP,SAAS,CAAC,0DAA0D;gBACtE,CAAC;gBACD,IAAI,CAAC;oBACH,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;gBAC3B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;oBACzD,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,0DAA0D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBAChJ,CAAC;YACH,CAAC;YACD,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,6CAA6C,CAAC,CAAC;QACtE,CAAC;KACF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE3E,eAAe,mBAAmB,CAAC"}
@@ -3,11 +3,12 @@
3
3
  * image description and CLIP embeddings through an AgentOS VisionPipeline.
4
4
  */
5
5
  import type { ITool, JSONSchemaObject, ToolExecutionContext, ToolExecutionResult } from '@framers/agentos';
6
+ import { type ImageStore } from '../imageFiles.js';
6
7
  /** What the tool reads from an image; see {@link VisionPipelineTool}. */
7
8
  export type VisionMode = 'ocr' | 'handwriting' | 'layout' | 'describe' | 'embed' | 'auto';
8
9
  /** The vision-pipeline tool's input. */
9
10
  export interface VisionPipelineInput {
10
- /** The image: a data:image URL, or an http(s) URL on a public host. */
11
+ /** The image: a data:image URL, an http(s) URL on a public host, or the file: URL of an image the image tools saved. */
11
12
  imageUrl: string;
12
13
  /** What to read (default `auto`). */
13
14
  mode?: VisionMode;
@@ -24,6 +25,13 @@ export interface VisionPipelineOutput {
24
25
  tiers?: string[];
25
26
  /** How many text regions the winning tier located. */
26
27
  regions?: number;
28
+ /** The document layout, when the layout tier ran: one page, a text block per line with its box. */
29
+ layout?: unknown;
30
+ /** The tiers that were due to run and failed, each with its error. */
31
+ failedTiers?: {
32
+ tier: string;
33
+ error: string;
34
+ }[];
27
35
  durationMs?: number;
28
36
  /** For embed: the CLIP vector. */
29
37
  embedding?: number[];
@@ -49,26 +57,37 @@ export type PipelineFor = (strategy: VisionStrategy) => Promise<{
49
57
  */
50
58
  export declare function isPrivateHost(hostname: string): boolean;
51
59
  /**
52
- * The image as the pipeline takes it: a data URL decoded to its bytes, an
53
- * http(s) URL whose host is not this machine or a private network as is, or
54
- * `undefined` for anything else. AgentOS also reads local file paths and
55
- * fetches any URL, but a tool the model calls must not send the machine's
56
- * files, or what its network serves, to a cloud vision model.
60
+ * The image a value names, when it is one a caller may hand the pipeline: a
61
+ * data URL decoded to its bytes, or an http(s) URL whose host is not this
62
+ * machine or a private network, written as the URL parser serializes it
63
+ * (scheme and host in lower case, dot segments resolved); `undefined` for
64
+ * anything else, a `file:` URL included. AgentOS also reads any local file
65
+ * path and fetches any URL, but a tool the model calls must not send the
66
+ * machine's files, or what its network serves, to a cloud vision model.
67
+ *
68
+ * The tool also takes the `file:` URL of an image the image tools saved,
69
+ * which it reads itself and holds to that directory (see {@link loadImage}).
57
70
  */
58
71
  export declare function imageInput(value: unknown): Buffer | string | undefined;
59
72
  /**
60
- * The image as the tool hands it to the pipeline. A Buffer goes on as it is. An
61
- * http(s) URL is fetched here through AgentOS's `imageToBuffer` with
73
+ * The bytes of the image a call names, for the pipeline. A Buffer goes on as
74
+ * it is.
75
+ *
76
+ * A `file:` URL must name an image that the image-generation or image-editing
77
+ * tools saved for this caller, in the images directory the packs share.
78
+ *
79
+ * An http(s) URL is fetched here through AgentOS's `imageToBuffer` with
62
80
  * `untrusted: true`, which connects only to public network addresses (every
63
- * address the host resolves to, and every redirect, is checked) and stops at
64
- * 50 MiB and 30 seconds; the bytes go on. With an AgentOS without that mode
65
- * (it has no `isPublicNetworkAddress` export) the pipeline gets the URL,
66
- * already checked against the host as written.
81
+ * address the host resolves to, and every redirect, is checked) and holds the
82
+ * image to 50 MiB and 30 seconds. An AgentOS without that mode (it has no
83
+ * `isPublicNetworkAddress` export; the mode came in 0.13.16) would fetch the
84
+ * URL unchecked, so an http(s) image is refused there.
67
85
  */
68
- export declare function loadImage(image: Buffer | string): Promise<Buffer | string>;
86
+ export declare function loadImage(image: Buffer | string, store?: ImageStore, context?: unknown): Promise<Buffer>;
69
87
  /** The vision-pipeline tool, on an AgentOS `VisionPipeline` per strategy. */
70
88
  export declare class VisionPipelineTool implements ITool<VisionPipelineInput, VisionPipelineOutput> {
71
89
  private readonly pipelineFor;
90
+ private readonly store?;
72
91
  readonly id = "tool.vision-pipeline";
73
92
  readonly name = "vision-pipeline";
74
93
  readonly displayName = "Vision & OCR Pipeline";
@@ -76,7 +95,11 @@ export declare class VisionPipelineTool implements ITool<VisionPipelineInput, Vi
76
95
  readonly category = "media";
77
96
  readonly hasSideEffects = false;
78
97
  readonly inputSchema: JSONSchemaObject;
79
- constructor(pipelineFor: PipelineFor);
80
- execute(args: VisionPipelineInput, _context?: ToolExecutionContext): Promise<ToolExecutionResult<VisionPipelineOutput>>;
98
+ /**
99
+ * @param pipelineFor - Returns the pipeline for a strategy.
100
+ * @param store - The images directory, for `file:` sources. Without one, no `file:` URL is read.
101
+ */
102
+ constructor(pipelineFor: PipelineFor, store?: ImageStore | undefined);
103
+ execute(args: VisionPipelineInput, context?: ToolExecutionContext): Promise<ToolExecutionResult<VisionPipelineOutput>>;
81
104
  }
82
105
  //# sourceMappingURL=visionPipeline.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visionPipeline.d.ts","sourceRoot":"","sources":["../../src/tools/visionPipeline.ts"],"names":[],"mappings":"AACA;;;GAGG;AAGH,OAAO,KAAK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CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAClD,CAAC,CAAC;AAqFH;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAQvD;AAiCD;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAGtE;AA8BD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAY9G;AAED,6EAA6E;AAC7E,qBAAa,kBAAmB,YAAW,KAAK,CAAC,mBAAmB,EAAE,oBAAoB,CAAC;IAsCvF,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC;IAtCzB,QAAQ,CAAC,EAAE,0BAA0B;IACrC,QAAQ,CAAC,IAAI,qBAAqB;IAClC,QAAQ,CAAC,WAAW,2BAA2B;IAC/C,QAAQ,CAAC,WAAW,SAE8F;IAClH,QAAQ,CAAC,QAAQ,WAAW;IAC5B,QAAQ,CAAC,cAAc,SAAS;IAEhC,QAAQ,CAAC,WAAW,EAAE,gBAAgB,CAqBpC;IAEF;;;OAGG;gBAEgB,WAAW,EAAE,WAAW,EACxB,KAAK,CAAC,EAAE,UAAU,YAAA;IAG/B,OAAO,CAAC,IAAI,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC;CA6D7H"}
@@ -4,6 +4,7 @@
4
4
  * image description and CLIP embeddings through an AgentOS VisionPipeline.
5
5
  */
6
6
  import * as agentos from '@framers/agentos';
7
+ import { readSavedImage, scopeOf } from '../imageFiles.js';
7
8
  /**
8
9
  * The lowest tier each mode needs: 1 is local OCR, 2 local vision models
9
10
  * (TrOCR, Florence-2, CLIP), 3 cloud vision.
@@ -63,35 +64,32 @@ function ipv6Groups(address) {
63
64
  return groups.map((group) => parseInt(group, 16));
64
65
  }
65
66
  /**
66
- * Whether an IPv6 address is off the public internet, the IPv4 address it
67
- * carries included: unspecified, loopback, IPv4-compatible and IPv4-mapped,
68
- * NAT64 (64:ff9b::/96 and 64:ff9b:1::/48), 6to4 (2002::/16), discard and
69
- * dummy (100::/63), the IETF protocol assignments (2001::/23), documentation
70
- * (2001:db8::/32 and 3fff::/20), SRv6 segment identifiers (5f00::/16),
71
- * unique local, link-local,
72
- * site-local and multicast.
67
+ * Whether an IPv6 address is off the public internet. Only 2000::/3 is
68
+ * allocated for global unicast, so everything outside it is refused
69
+ * (unspecified, loopback, the deprecated IPv4-compatible form, discard, SRv6,
70
+ * unique local, link-local, site-local, multicast, and space no one has been
71
+ * given), except the two forms that reach an IPv4 address and are judged by
72
+ * it: IPv4-mapped (::ffff:0:0/96) and the NAT64 well-known prefix
73
+ * (64:ff9b::/96). Inside 2000::/3, 6to4 (2002::/16) is judged by the address
74
+ * it carries, and the IETF protocol assignments (2001::/23) and documentation
75
+ * (2001:db8::/32 and 3fff::/20) are refused. The same rule as AgentOS's
76
+ * `isPublicNetworkAddress`.
73
77
  */
74
78
  function isNonPublicIPv6(groups) {
75
79
  const carried = (high, low) => isNonPublicIPv4([high >> 8, high & 255, low >> 8, low & 255]);
76
- const [g0, g1, g2, g3, g4, g5, g6, g7] = groups;
80
+ const [g0, g1, g2, , , g5, g6, g7] = groups;
77
81
  const zeros = (from, to) => groups.slice(from, to).every((group) => group === 0);
78
- if (zeros(0, 6))
79
- return (g6 === 0 && g7 <= 1) || carried(g6, g7);
80
82
  if (zeros(0, 5) && g5 === 0xffff)
81
83
  return carried(g6, g7);
82
- if (g0 === 0x64 && g1 === 0xff9b)
83
- return g2 === 1 || !zeros(2, 6) || carried(g6, g7);
84
+ if (g0 === 0x64 && g1 === 0xff9b && zeros(2, 6))
85
+ return carried(g6, g7);
86
+ if ((g0 & 0xe000) !== 0x2000)
87
+ return true;
84
88
  if (g0 === 0x2002)
85
89
  return carried(g1, g2);
86
- if (g0 === 0x100 && g1 === 0 && g2 === 0 && g3 <= 1)
87
- return true;
88
90
  if (g0 === 0x2001 && (g1 <= 0x01ff || g1 === 0xdb8))
89
91
  return true;
90
- if (g0 === 0x3fff && g1 <= 0x0fff)
91
- return true;
92
- if (g0 === 0x5f00)
93
- return true;
94
- return (g0 & 0xfe00) === 0xfc00 || (g0 & 0xffc0) === 0xfe80 || (g0 & 0xffc0) === 0xfec0 || (g0 & 0xff00) === 0xff00;
92
+ return g0 === 0x3fff && g1 <= 0x0fff;
95
93
  }
96
94
  /**
97
95
  * Whether a URL's host is this machine or off the public internet: `localhost`
@@ -147,16 +145,28 @@ function percentDecode(payload) {
147
145
  return out.subarray(0, length);
148
146
  }
149
147
  /**
150
- * The image as the pipeline takes it: a data URL decoded to its bytes, an
151
- * http(s) URL whose host is not this machine or a private network as is, or
152
- * `undefined` for anything else. AgentOS also reads local file paths and
153
- * fetches any URL, but a tool the model calls must not send the machine's
154
- * files, or what its network serves, to a cloud vision model.
148
+ * The image a value names, when it is one a caller may hand the pipeline: a
149
+ * data URL decoded to its bytes, or an http(s) URL whose host is not this
150
+ * machine or a private network, written as the URL parser serializes it
151
+ * (scheme and host in lower case, dot segments resolved); `undefined` for
152
+ * anything else, a `file:` URL included. AgentOS also reads any local file
153
+ * path and fetches any URL, but a tool the model calls must not send the
154
+ * machine's files, or what its network serves, to a cloud vision model.
155
+ *
156
+ * The tool also takes the `file:` URL of an image the image tools saved,
157
+ * which it reads itself and holds to that directory (see {@link loadImage}).
155
158
  */
156
159
  export function imageInput(value) {
160
+ const source = sourceOf(value);
161
+ return typeof source === 'string' && /^file:/i.test(source) ? undefined : source;
162
+ }
163
+ /** The image a call names, as {@link imageInput} reads it, and a `file:` URL as it was written. */
164
+ function sourceOf(value) {
157
165
  if (typeof value !== 'string')
158
166
  return undefined;
159
167
  const source = value.trim();
168
+ if (/^file:/i.test(source))
169
+ return source;
160
170
  if (/^https?:\/\//i.test(source)) {
161
171
  let url;
162
172
  try {
@@ -165,31 +175,53 @@ export function imageInput(value) {
165
175
  catch {
166
176
  return undefined;
167
177
  }
168
- return isPrivateHost(url.hostname) ? undefined : source;
178
+ return isPrivateHost(url.hostname) ? undefined : url.href;
169
179
  }
170
- const data = /^data:image\/[^,]*?(;base64)?,(.*)$/is.exec(source);
171
- if (!data)
180
+ // A data URL as WHATWG Fetch reads one, and as AgentOS's imageToBuffer
181
+ // does: tabs and line breaks dropped first, then base64 when the media type
182
+ // ends in `;base64`, spaces around it allowed.
183
+ const url = source.replace(/[\t\n\r]/g, '');
184
+ const comma = url.indexOf(',');
185
+ if (!/^data:image\//i.test(url) || comma === -1)
172
186
  return undefined;
173
- return data[1] ? Buffer.from(data[2], 'base64') : percentDecode(data[2]);
187
+ const payload = url.slice(comma + 1);
188
+ return /; *base64 *$/i.test(url.slice(0, comma)) ? Buffer.from(payload, 'base64') : percentDecode(payload);
174
189
  }
190
+ /** The error for an input that is not an accepted image source. */
191
+ const SOURCE_ERROR = 'imageUrl must be a data:image URL, an http(s) URL on a public host, or the file: URL of an image the image tools saved: other local files are not read, nor local or private network addresses.';
175
192
  /**
176
- * The image as the tool hands it to the pipeline. A Buffer goes on as it is. An
177
- * http(s) URL is fetched here through AgentOS's `imageToBuffer` with
193
+ * The bytes of the image a call names, for the pipeline. A Buffer goes on as
194
+ * it is.
195
+ *
196
+ * A `file:` URL must name an image that the image-generation or image-editing
197
+ * tools saved for this caller, in the images directory the packs share.
198
+ *
199
+ * An http(s) URL is fetched here through AgentOS's `imageToBuffer` with
178
200
  * `untrusted: true`, which connects only to public network addresses (every
179
- * address the host resolves to, and every redirect, is checked) and stops at
180
- * 50 MiB and 30 seconds; the bytes go on. With an AgentOS without that mode
181
- * (it has no `isPublicNetworkAddress` export) the pipeline gets the URL,
182
- * already checked against the host as written.
201
+ * address the host resolves to, and every redirect, is checked) and holds the
202
+ * image to 50 MiB and 30 seconds. An AgentOS without that mode (it has no
203
+ * `isPublicNetworkAddress` export; the mode came in 0.13.16) would fetch the
204
+ * URL unchecked, so an http(s) image is refused there.
183
205
  */
184
- export async function loadImage(image) {
185
- const { imageToBuffer, isPublicNetworkAddress } = agentos;
186
- if (typeof image !== 'string' || typeof isPublicNetworkAddress !== 'function')
206
+ export async function loadImage(image, store, context) {
207
+ if (typeof image !== 'string')
187
208
  return image;
209
+ if (/^file:/i.test(image)) {
210
+ const bytes = store ? await readSavedImage(image, store.dir, scopeOf(context)) : undefined;
211
+ if (!bytes)
212
+ throw new Error(SOURCE_ERROR);
213
+ return bytes;
214
+ }
215
+ const { imageToBuffer, isPublicNetworkAddress } = agentos;
216
+ if (typeof isPublicNetworkAddress !== 'function') {
217
+ throw new Error('imageUrl is an http(s) URL, which needs @framers/agentos 0.13.16 or later: pass a data:image URL, or update AgentOS.');
218
+ }
188
219
  return imageToBuffer(image, { untrusted: true });
189
220
  }
190
221
  /** The vision-pipeline tool, on an AgentOS `VisionPipeline` per strategy. */
191
222
  export class VisionPipelineTool {
192
223
  pipelineFor;
224
+ store;
193
225
  id = 'tool.vision-pipeline';
194
226
  name = 'vision-pipeline';
195
227
  displayName = 'Vision & OCR Pipeline';
@@ -200,11 +232,14 @@ export class VisionPipelineTool {
200
232
  inputSchema = {
201
233
  type: 'object',
202
234
  properties: {
203
- imageUrl: { type: 'string', description: 'The image: an http(s) URL or a data:image URL.' },
235
+ imageUrl: {
236
+ type: 'string',
237
+ description: 'The image: an http(s) URL, a data:image URL, or the file: URL of an image the image tools saved.',
238
+ },
204
239
  mode: {
205
240
  type: 'string',
206
241
  enum: ['ocr', 'handwriting', 'layout', 'describe', 'embed', 'auto'],
207
- description: 'ocr for printed text, handwriting, layout for document structure, describe for what the image shows, ' +
242
+ description: 'ocr for printed text, handwriting, layout for the lines of text with their boxes, describe for what the image shows, ' +
208
243
  'embed for a CLIP vector, or auto (default) to let the pipeline decide.',
209
244
  },
210
245
  maxTier: {
@@ -215,38 +250,53 @@ export class VisionPipelineTool {
215
250
  },
216
251
  required: ['imageUrl'],
217
252
  };
218
- constructor(pipelineFor) {
253
+ /**
254
+ * @param pipelineFor - Returns the pipeline for a strategy.
255
+ * @param store - The images directory, for `file:` sources. Without one, no `file:` URL is read.
256
+ */
257
+ constructor(pipelineFor, store) {
219
258
  this.pipelineFor = pipelineFor;
259
+ this.store = store;
220
260
  }
221
- async execute(args, _context) {
222
- const image = imageInput(args.imageUrl);
223
- if (image === undefined) {
224
- return {
225
- success: false,
226
- error: 'imageUrl must be a data:image URL or an http(s) URL on a public host: local file paths are not read, nor local or private network addresses.',
227
- };
228
- }
261
+ async execute(args, context) {
262
+ const image = sourceOf(args.imageUrl);
263
+ if (image === undefined)
264
+ return { success: false, error: SOURCE_ERROR };
229
265
  const mode = args.mode ?? 'auto';
230
266
  if (typeof mode !== 'string' || !Object.hasOwn(TIER_NEEDED, mode)) {
231
267
  return { success: false, error: `mode must be one of ${Object.keys(TIER_NEEDED).join(', ')}.` };
232
268
  }
233
- const maxTier = args.maxTier === 1 || args.maxTier === 2 ? args.maxTier : 3;
269
+ // The highest tier is the cloud: only an absent maxTier means it. A value
270
+ // the schema does not allow, null among them, is refused, not read as
271
+ // "no limit".
272
+ let maxTier = 3;
273
+ if (args.maxTier !== undefined) {
274
+ const given = typeof args.maxTier === 'string' && args.maxTier.trim() !== '' ? Number(args.maxTier) : args.maxTier;
275
+ if (given !== 1 && given !== 2 && given !== 3)
276
+ return { success: false, error: 'maxTier must be 1, 2 or 3.' };
277
+ maxTier = given;
278
+ }
234
279
  if (TIER_NEEDED[mode] > maxTier) {
235
280
  return { success: false, error: `${mode} needs maxTier ${TIER_NEEDED[mode]} or higher; this call allows ${maxTier}.` };
236
281
  }
237
282
  try {
238
- const input = await loadImage(image);
283
+ const input = await loadImage(image, this.store, context);
239
284
  const pipeline = await this.pipelineFor(maxTier === 3 ? 'progressive' : 'local-only');
240
285
  if (mode === 'embed') {
241
286
  const embedding = await pipeline.embed(input);
242
287
  return { success: true, output: { mode, embedding, dimensions: embedding.length } };
243
288
  }
289
+ // handwriting and layout name their tier. With the category alone, a
290
+ // pipeline that may reach the cloud returns as soon as plain OCR is
291
+ // confident, before the tier the mode is named for has run; and a tier
292
+ // whose model is not installed is passed over without a word. A named
293
+ // tier runs, or fails with the reason.
244
294
  const options = maxTier === 1 || mode === 'ocr'
245
295
  ? { tiers: ['ocr'] }
246
296
  : mode === 'handwriting'
247
- ? { forceCategory: 'handwritten' }
297
+ ? { tiers: ['handwriting'], forceCategory: 'handwritten' }
248
298
  : mode === 'layout'
249
- ? { forceCategory: 'document-layout' }
299
+ ? { tiers: ['document-ai'], forceCategory: 'document-layout' }
250
300
  : mode === 'describe'
251
301
  ? { tiers: ['cloud-vision'] }
252
302
  : undefined;
@@ -260,6 +310,8 @@ export class VisionPipelineTool {
260
310
  category: result.category,
261
311
  tiers: result.tiers,
262
312
  regions: result.regions?.length ?? 0,
313
+ ...(result.layout ? { layout: result.layout } : {}),
314
+ ...(result.failedTiers?.length ? { failedTiers: result.failedTiers } : {}),
263
315
  durationMs: result.durationMs,
264
316
  },
265
317
  };
@@ -1 +1 @@
1
- {"version":3,"file":"visionPipeline.js","sourceRoot":"","sources":["../../src/tools/visionPipeline.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;GAGG;AAEH,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAC;AAyC5C;;;GAGG;AACH,MAAM,WAAW,GAAkC;IACjD,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,WAAW,EAAE,CAAC;IACd,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,QAAQ,EAAE,CAAC;CACZ,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAW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,EAAE,OAAO,CAAC,CAAC;YACtD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACN,IAAI;oBACJ,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,KAAK,EAAE,MAAM,CAAC,KAAK;oBACnB,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;oBACpC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnD,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC1E,UAAU,EAAE,MAAM,CAAC,UAAU;iBAC9B;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3F,CAAC;IACH,CAAC;CACF"}
package/manifest.json CHANGED
@@ -2,16 +2,16 @@
2
2
  "$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
3
3
  "id": "com.framers.tools.vision-pipeline",
4
4
  "name": "Vision & OCR Pipeline",
5
- "version": "0.2.2",
5
+ "version": "0.3.0",
6
6
  "description": "Progressive vision pipeline with PaddleOCR, TrOCR, Florence-2, CLIP, and cloud vision (GPT-4o, Claude).",
7
7
  "author": {
8
8
  "name": "Frame.dev",
9
9
  "email": "support@frame.dev",
10
10
  "url": "https://github.com/framerslab"
11
11
  },
12
- "license": "MIT",
12
+ "license": "Apache-2.0",
13
13
  "keywords": ["vision", "ocr", "paddle", "trocr", "florence", "clip", "document-ai"],
14
- "agentosVersion": ">=0.10.40",
14
+ "agentosVersion": ">=0.13.40",
15
15
  "categories": ["tool", "media"],
16
16
  "platforms": [],
17
17
  "sdk": "none",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@framers/agentos-ext-vision-pipeline",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Vision & OCR pipeline extension for AgentOS — PaddleOCR, TrOCR, Florence-2, CLIP, and cloud vision",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "url": "https://github.com/jddunn"
36
36
  }
37
37
  ],
38
- "license": "MIT",
38
+ "license": "Apache-2.0",
39
39
  "repository": {
40
40
  "type": "git",
41
41
  "url": "git+https://github.com/framerslab/agentos-extensions.git",
@@ -45,10 +45,10 @@
45
45
  "access": "public"
46
46
  },
47
47
  "peerDependencies": {
48
- "@framers/agentos": ">=0.10.40"
48
+ "@framers/agentos": ">=0.13.40"
49
49
  },
50
50
  "devDependencies": {
51
- "@framers/agentos": "^0.13.19",
51
+ "@framers/agentos": "^0.13.40",
52
52
  "@types/node": "^20.12.12",
53
53
  "rimraf": "^5.0.7",
54
54
  "typescript": "^5.4.5",