@ai-setting/roy-agent-core 1.5.91 → 1.5.93

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.
Files changed (32) hide show
  1. package/dist/env/agent/index.js +4 -3
  2. package/dist/env/event-source/index.js +3 -3
  3. package/dist/env/index.js +12 -11
  4. package/dist/env/prompt/index.js +2 -2
  5. package/dist/env/task/delegate/index.js +2 -2
  6. package/dist/env/task/index.js +3 -3
  7. package/dist/env/task/plugins/index.js +2 -2
  8. package/dist/env/tool/built-in/index.js +11 -1
  9. package/dist/env/tool/index.js +14 -3
  10. package/dist/env/workflow/engine/index.js +2 -2
  11. package/dist/env/workflow/index.js +3 -3
  12. package/dist/index.js +29 -111
  13. package/dist/shared/@ai-setting/{roy-agent-core-spzb03na.js → roy-agent-core-09xaxtpf.js} +5 -2
  14. package/dist/shared/@ai-setting/{roy-agent-core-55br4t6v.js → roy-agent-core-27d4js2f.js} +34 -7
  15. package/dist/shared/@ai-setting/{roy-agent-core-9amq4epa.js → roy-agent-core-2pz9075g.js} +2 -2
  16. package/dist/shared/@ai-setting/{roy-agent-core-w1s8yrm5.js → roy-agent-core-2vnw9wbx.js} +59 -18
  17. package/dist/shared/@ai-setting/roy-agent-core-5h49ct1a.js +135 -0
  18. package/dist/shared/@ai-setting/{roy-agent-core-5j649pb1.js → roy-agent-core-8f37pvct.js} +1 -1
  19. package/dist/shared/@ai-setting/{roy-agent-core-snvsn60t.js → roy-agent-core-9z1mem2n.js} +44 -6
  20. package/dist/shared/@ai-setting/roy-agent-core-cy8azvpb.js +13 -0
  21. package/dist/shared/@ai-setting/{roy-agent-core-97tjdb2r.js → roy-agent-core-dj18eyyk.js} +29 -3
  22. package/dist/shared/@ai-setting/{roy-agent-core-q7ffkt1e.js → roy-agent-core-eqcbn89s.js} +1 -1
  23. package/dist/shared/@ai-setting/{roy-agent-core-vady4w02.js → roy-agent-core-hfgqwf5w.js} +1 -1
  24. package/dist/shared/@ai-setting/{roy-agent-core-jf865m5b.js → roy-agent-core-jhdv14ks.js} +11 -139
  25. package/dist/shared/@ai-setting/{roy-agent-core-7svhckhz.js → roy-agent-core-mwb6918x.js} +1 -1
  26. package/dist/shared/@ai-setting/{roy-agent-core-svcr4gjw.js → roy-agent-core-mx9vq7b2.js} +1 -1
  27. package/dist/shared/@ai-setting/{roy-agent-core-at05dk0z.js → roy-agent-core-ss92p0r6.js} +1 -1
  28. package/dist/shared/@ai-setting/roy-agent-core-t7rw68q8.js +185 -0
  29. package/dist/shared/@ai-setting/{roy-agent-core-b1vkkcbr.js → roy-agent-core-x65fyjaw.js} +1 -1
  30. package/dist/utils/temp-file-manager/index.js +10 -0
  31. package/package.json +1 -1
  32. /package/dist/shared/@ai-setting/{roy-agent-core-pt7as39r.js → roy-agent-core-wjmwwc4a.js} +0 -0
@@ -0,0 +1,185 @@
1
+ // src/env/tool/built-in/understand-image.ts
2
+ import { z } from "zod";
3
+
4
+ // src/utils/media.ts
5
+ import * as fs from "node:fs/promises";
6
+ import * as path from "node:path";
7
+ var ATTACH_FILE_MAX_BYTES = 10 * 1024 * 1024;
8
+ function startsWith(buf, sig) {
9
+ if (buf.length < sig.length)
10
+ return false;
11
+ for (let i = 0;i < sig.length; i++) {
12
+ if (buf[i] !== sig[i])
13
+ return false;
14
+ }
15
+ return true;
16
+ }
17
+ function sniffMimeType(buffer, fallbackName) {
18
+ if (startsWith(buffer, [137, 80, 78, 71, 13, 10, 26, 10])) {
19
+ return "image/png";
20
+ }
21
+ if (startsWith(buffer, [255, 216, 255])) {
22
+ return "image/jpeg";
23
+ }
24
+ if (startsWith(buffer, [71, 73, 70, 56])) {
25
+ return "image/gif";
26
+ }
27
+ if (startsWith(buffer, [66, 77])) {
28
+ return "image/bmp";
29
+ }
30
+ if (startsWith(buffer, [37, 80, 68, 70, 45])) {
31
+ return "application/pdf";
32
+ }
33
+ if (startsWith(buffer, [82, 73, 70, 70]) && startsWith(buffer.subarray(8), [87, 69, 66, 80])) {
34
+ return "image/webp";
35
+ }
36
+ if (fallbackName) {
37
+ const ext = path.extname(fallbackName).toLowerCase();
38
+ const extMap = {
39
+ ".png": "image/png",
40
+ ".jpg": "image/jpeg",
41
+ ".jpeg": "image/jpeg",
42
+ ".gif": "image/gif",
43
+ ".webp": "image/webp",
44
+ ".bmp": "image/bmp",
45
+ ".pdf": "application/pdf",
46
+ ".mp3": "audio/mpeg",
47
+ ".wav": "audio/wav",
48
+ ".ogg": "audio/ogg",
49
+ ".m4a": "audio/mp4",
50
+ ".mp4": "video/mp4",
51
+ ".mov": "video/quicktime",
52
+ ".webm": "video/webm"
53
+ };
54
+ const mapped = extMap[ext];
55
+ if (mapped)
56
+ return mapped;
57
+ }
58
+ return "application/octet-stream";
59
+ }
60
+ function isMediaType(mime) {
61
+ if (typeof mime !== "string")
62
+ return false;
63
+ const m = mime.toLowerCase();
64
+ return m.startsWith("image/") || m.startsWith("audio/") || m.startsWith("video/") || m === "application/pdf";
65
+ }
66
+ var HTTP_URL_RE = /^https?:\/\//i;
67
+ var DATA_URL_RE = /^data:([^;,]+)(;base64)?,(.*)$/s;
68
+ async function parseImageInput(input) {
69
+ if (!input || typeof input !== "string" || input.trim().length === 0) {
70
+ throw new Error("parseImageInput: input is empty");
71
+ }
72
+ const trimmed = input.trim();
73
+ if (HTTP_URL_RE.test(trimmed)) {
74
+ return { type: "image", image: trimmed };
75
+ }
76
+ if (DATA_URL_RE.test(trimmed)) {
77
+ return { type: "image", image: trimmed };
78
+ }
79
+ return await parseLocalImagePath(trimmed);
80
+ }
81
+ async function parseLocalImagePath(filePath) {
82
+ let stat2;
83
+ try {
84
+ stat2 = await fs.stat(filePath);
85
+ } catch (err) {
86
+ throw new Error(`parseImageInput: cannot stat file '${filePath}': ${err.message}`);
87
+ }
88
+ if (!stat2.isFile()) {
89
+ throw new Error(`parseImageInput: not a regular file: ${filePath}`);
90
+ }
91
+ if (stat2.size > ATTACH_FILE_MAX_BYTES) {
92
+ throw new Error(`parseImageInput: file '${filePath}' exceeds 10 MiB limit ` + `(${stat2.size} bytes > ${ATTACH_FILE_MAX_BYTES} bytes)`);
93
+ }
94
+ const buffer = await fs.readFile(filePath);
95
+ const mime = sniffMimeType(buffer, filePath);
96
+ if (!mime.startsWith("image/")) {
97
+ throw new Error(`parseImageInput: file '${filePath}' is not an image (detected ${mime}). ` + `Use ContentPart type 'file' for non-image attachments.`);
98
+ }
99
+ return { type: "image", image: buffer };
100
+ }
101
+
102
+ // src/env/tool/built-in/understand-image.ts
103
+ var injectedProvider = null;
104
+ function setUnderstandImageLLMProvider(provider) {
105
+ injectedProvider = provider;
106
+ }
107
+ function getUnderstandImageLLMProvider() {
108
+ return injectedProvider;
109
+ }
110
+ async function resetUnderstandImageLLMProvider() {
111
+ injectedProvider = null;
112
+ }
113
+ function normalizeImageSource(raw) {
114
+ if (typeof raw !== "string")
115
+ return raw;
116
+ return raw.startsWith("@") ? raw.slice(1) : raw;
117
+ }
118
+ var understandImageTool = {
119
+ name: "understand_image",
120
+ description: "Analyze or describe the contents of an image using a multimodal LLM. " + "Provide a prompt describing what you want to extract or understand " + "(e.g. 'Describe this image in detail', 'Read the text in the receipt', " + "'What color is the car?'). The image_source can be an HTTP(S) URL, a " + "data:base64 URL, or a local file path (optionally prefixed with '@').",
121
+ parameters: z.object({
122
+ prompt: z.string().min(1).describe("A text prompt describing what you want to analyze or extract from the image."),
123
+ image_source: z.string().min(1).describe("The location of the image to analyze. Accepts HTTP(S) URL, data:base64 URL, or local file path. Optional '@' prefix is stripped.")
124
+ }),
125
+ metadata: {
126
+ category: "ai",
127
+ tags: ["multimodal", "vision", "image", "llm", "ocr"],
128
+ version: "1.0.0"
129
+ },
130
+ permission: {
131
+ level: "safe"
132
+ },
133
+ execute: async (args, _ctx) => {
134
+ const startTime = Date.now();
135
+ const { prompt, image_source } = args;
136
+ if (!injectedProvider) {
137
+ return {
138
+ success: false,
139
+ output: "",
140
+ error: "understand_image is not initialized: no LLM provider has been " + "registered. AgentComponent should call setUnderstandImageLLMProvider() " + "at agent startup.",
141
+ metadata: { execution_time_ms: Date.now() - startTime }
142
+ };
143
+ }
144
+ let imagePart;
145
+ try {
146
+ imagePart = await parseImageInput(normalizeImageSource(image_source));
147
+ } catch (err) {
148
+ return {
149
+ success: false,
150
+ output: "",
151
+ error: `failed to read image: ${err.message}`,
152
+ metadata: { execution_time_ms: Date.now() - startTime }
153
+ };
154
+ }
155
+ const messages = [
156
+ {
157
+ role: "user",
158
+ content: [
159
+ { type: "text", text: prompt },
160
+ imagePart
161
+ ]
162
+ }
163
+ ];
164
+ let responseText;
165
+ try {
166
+ responseText = await injectedProvider(messages);
167
+ } catch (err) {
168
+ return {
169
+ success: false,
170
+ output: "",
171
+ error: `LLM invocation failed: ${err.message}`,
172
+ metadata: { execution_time_ms: Date.now() - startTime }
173
+ };
174
+ }
175
+ return {
176
+ success: true,
177
+ output: responseText,
178
+ metadata: {
179
+ execution_time_ms: Date.now() - startTime
180
+ }
181
+ };
182
+ }
183
+ };
184
+
185
+ export { ATTACH_FILE_MAX_BYTES, sniffMimeType, isMediaType, parseImageInput, setUnderstandImageLLMProvider, getUnderstandImageLLMProvider, resetUnderstandImageLLMProvider, understandImageTool };
@@ -5,7 +5,7 @@ import {
5
5
  BackgroundTaskManager,
6
6
  createDelegateTool,
7
7
  createStopTool
8
- } from "./roy-agent-core-at05dk0z.js";
8
+ } from "./roy-agent-core-ss92p0r6.js";
9
9
  import {
10
10
  SQLiteTaskStore,
11
11
  getDefaultTaskDbPath
@@ -0,0 +1,10 @@
1
+ import {
2
+ TempFileManager
3
+ } from "../../shared/@ai-setting/roy-agent-core-5h49ct1a.js";
4
+ import"../../shared/@ai-setting/roy-agent-core-vyygk314.js";
5
+ import"../../shared/@ai-setting/roy-agent-core-7z9b1fm8.js";
6
+ import"../../shared/@ai-setting/roy-agent-core-c6592r3c.js";
7
+ import"../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
8
+ export {
9
+ TempFileManager
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.91",
3
+ "version": "1.5.93",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",