@probelabs/probe 0.6.0-rc306 → 0.6.0-rc307
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/bin/binaries/{probe-v0.6.0-rc306-aarch64-apple-darwin.tar.gz → probe-v0.6.0-rc307-aarch64-apple-darwin.tar.gz} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc306-aarch64-unknown-linux-musl.tar.gz → probe-v0.6.0-rc307-aarch64-unknown-linux-musl.tar.gz} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc306-x86_64-apple-darwin.tar.gz → probe-v0.6.0-rc307-x86_64-apple-darwin.tar.gz} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc306-x86_64-pc-windows-msvc.zip → probe-v0.6.0-rc307-x86_64-pc-windows-msvc.zip} +0 -0
- package/bin/binaries/{probe-v0.6.0-rc306-x86_64-unknown-linux-musl.tar.gz → probe-v0.6.0-rc307-x86_64-unknown-linux-musl.tar.gz} +0 -0
- package/build/agent/ProbeAgent.js +125 -101
- package/build/agent/mediaConfig.js +122 -0
- package/build/agent/tools.js +2 -0
- package/build/index.js +2 -0
- package/build/tools/common.js +4 -0
- package/build/tools/index.js +1 -0
- package/cjs/agent/ProbeAgent.cjs +128 -81
- package/cjs/index.cjs +131 -81
- package/package.json +1 -1
- package/src/agent/ProbeAgent.js +125 -101
- package/src/agent/mediaConfig.js +122 -0
- package/src/agent/tools.js +2 -0
- package/src/index.js +2 -0
- package/src/tools/common.js +4 -0
- package/src/tools/index.js +1 -0
package/cjs/index.cjs
CHANGED
|
@@ -19578,10 +19578,10 @@ var init_dist2 = __esm({
|
|
|
19578
19578
|
"ETIMEDOUT",
|
|
19579
19579
|
"EPIPE"
|
|
19580
19580
|
];
|
|
19581
|
-
VERSION = true ? "4.0.
|
|
19581
|
+
VERSION = true ? "4.0.21" : "0.0.0-test";
|
|
19582
19582
|
suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
19583
19583
|
suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
19584
|
-
ignoreOverride = Symbol(
|
|
19584
|
+
ignoreOverride = /* @__PURE__ */ Symbol(
|
|
19585
19585
|
"Let zodToJsonSchema decide on which parser to use"
|
|
19586
19586
|
);
|
|
19587
19587
|
defaultOptions = {
|
|
@@ -19917,7 +19917,7 @@ var init_dist2 = __esm({
|
|
|
19917
19917
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
19918
19918
|
return combined;
|
|
19919
19919
|
};
|
|
19920
|
-
schemaSymbol = Symbol.for("vercel.ai.schema");
|
|
19920
|
+
schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
19921
19921
|
getOriginalFetch2 = () => globalThis.fetch;
|
|
19922
19922
|
postJsonToApi = async ({
|
|
19923
19923
|
url: url2,
|
|
@@ -22009,7 +22009,8 @@ async function prepareTools({
|
|
|
22009
22009
|
} = await (0, import_internal2.prepareTools)({
|
|
22010
22010
|
tools: ProviderTools,
|
|
22011
22011
|
toolChoice,
|
|
22012
|
-
supportsStructuredOutput: false
|
|
22012
|
+
supportsStructuredOutput: false,
|
|
22013
|
+
supportsStrictTools: false
|
|
22013
22014
|
});
|
|
22014
22015
|
toolWarnings.push(...anthropicToolWarnings);
|
|
22015
22016
|
anthropicBetas.forEach((beta) => betas.add(beta));
|
|
@@ -24029,7 +24030,7 @@ var init_dist3 = __esm({
|
|
|
24029
24030
|
details: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
24030
24031
|
preview: external_exports.unknown().optional()
|
|
24031
24032
|
});
|
|
24032
|
-
VERSION2 = true ? "4.0.
|
|
24033
|
+
VERSION2 = true ? "4.0.82" : "0.0.0-test";
|
|
24033
24034
|
bedrockRerankingResponseSchema = lazySchema(
|
|
24034
24035
|
() => zodSchema(
|
|
24035
24036
|
external_exports.object({
|
|
@@ -26761,7 +26762,10 @@ var init_HookManager = __esm({
|
|
|
26761
26762
|
}
|
|
26762
26763
|
});
|
|
26763
26764
|
|
|
26764
|
-
// src/agent/
|
|
26765
|
+
// src/agent/mediaConfig.js
|
|
26766
|
+
function isDocumentExtension(extension) {
|
|
26767
|
+
return SUPPORTED_DOCUMENT_EXTENSIONS.includes(extension?.toLowerCase());
|
|
26768
|
+
}
|
|
26765
26769
|
function isFormatSupportedByProvider(extension, provider) {
|
|
26766
26770
|
if (!extension || typeof extension !== "string") {
|
|
26767
26771
|
return false;
|
|
@@ -26770,7 +26774,7 @@ function isFormatSupportedByProvider(extension, provider) {
|
|
|
26770
26774
|
return false;
|
|
26771
26775
|
}
|
|
26772
26776
|
const ext2 = extension.toLowerCase();
|
|
26773
|
-
if (!
|
|
26777
|
+
if (!SUPPORTED_MEDIA_EXTENSIONS.includes(ext2)) {
|
|
26774
26778
|
return false;
|
|
26775
26779
|
}
|
|
26776
26780
|
if (!provider || typeof provider !== "string") {
|
|
@@ -26782,18 +26786,21 @@ function isFormatSupportedByProvider(extension, provider) {
|
|
|
26782
26786
|
}
|
|
26783
26787
|
return true;
|
|
26784
26788
|
}
|
|
26785
|
-
var SUPPORTED_IMAGE_EXTENSIONS,
|
|
26786
|
-
var
|
|
26787
|
-
"src/agent/
|
|
26789
|
+
var SUPPORTED_IMAGE_EXTENSIONS, SUPPORTED_DOCUMENT_EXTENSIONS, SUPPORTED_MEDIA_EXTENSIONS, MEDIA_MIME_TYPES, PROVIDER_UNSUPPORTED_FORMATS;
|
|
26790
|
+
var init_mediaConfig = __esm({
|
|
26791
|
+
"src/agent/mediaConfig.js"() {
|
|
26788
26792
|
"use strict";
|
|
26789
26793
|
SUPPORTED_IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "bmp", "svg"];
|
|
26790
|
-
|
|
26794
|
+
SUPPORTED_DOCUMENT_EXTENSIONS = ["pdf"];
|
|
26795
|
+
SUPPORTED_MEDIA_EXTENSIONS = [...SUPPORTED_IMAGE_EXTENSIONS, ...SUPPORTED_DOCUMENT_EXTENSIONS];
|
|
26796
|
+
MEDIA_MIME_TYPES = {
|
|
26791
26797
|
"png": "image/png",
|
|
26792
26798
|
"jpg": "image/jpeg",
|
|
26793
26799
|
"jpeg": "image/jpeg",
|
|
26794
26800
|
"webp": "image/webp",
|
|
26795
26801
|
"bmp": "image/bmp",
|
|
26796
|
-
"svg": "image/svg+xml"
|
|
26802
|
+
"svg": "image/svg+xml",
|
|
26803
|
+
"pdf": "application/pdf"
|
|
26797
26804
|
};
|
|
26798
26805
|
PROVIDER_UNSUPPORTED_FORMATS = {
|
|
26799
26806
|
"google": ["svg"]
|
|
@@ -27806,7 +27813,7 @@ function resolveTargetPath(target, cwd) {
|
|
|
27806
27813
|
}
|
|
27807
27814
|
return filePart + suffix;
|
|
27808
27815
|
}
|
|
27809
|
-
var import_path6, searchDelegateSchema, searchSchema, searchAllSchema, querySchema, extractSchema, delegateSchema, listSkillsSchema, useSkillSchema, listFilesSchema, searchFilesSchema, readImageSchema, bashSchema, analyzeAllSchema, executePlanSchema, cleanupExecutePlanSchema, searchDescription, searchDelegateDescription, queryDescription, extractDescription, delegateDescription, bashDescription, analyzeAllDescription;
|
|
27816
|
+
var import_path6, searchDelegateSchema, searchSchema, searchAllSchema, querySchema, extractSchema, delegateSchema, listSkillsSchema, useSkillSchema, listFilesSchema, searchFilesSchema, readImageSchema, readMediaSchema, bashSchema, analyzeAllSchema, executePlanSchema, cleanupExecutePlanSchema, searchDescription, searchDelegateDescription, queryDescription, extractDescription, delegateDescription, bashDescription, analyzeAllDescription;
|
|
27810
27817
|
var init_common = __esm({
|
|
27811
27818
|
"src/tools/common.js"() {
|
|
27812
27819
|
"use strict";
|
|
@@ -27862,6 +27869,9 @@ var init_common = __esm({
|
|
|
27862
27869
|
readImageSchema = external_exports2.object({
|
|
27863
27870
|
path: external_exports2.string().describe("Path to the image file to read. Supports png, jpg, jpeg, webp, bmp, and svg formats.")
|
|
27864
27871
|
});
|
|
27872
|
+
readMediaSchema = external_exports2.object({
|
|
27873
|
+
path: external_exports2.string().describe("Path to the media file to read. Supports images (png, jpg, jpeg, webp, bmp, svg) and documents (pdf).")
|
|
27874
|
+
});
|
|
27865
27875
|
bashSchema = external_exports2.object({
|
|
27866
27876
|
command: external_exports2.string().describe("The bash command to execute"),
|
|
27867
27877
|
workingDirectory: external_exports2.string().optional().describe("Directory to execute the command in (optional)"),
|
|
@@ -97485,7 +97495,7 @@ function debugLogToolResults(toolResults) {
|
|
|
97485
97495
|
console.log(`[DEBUG] tool: ${tr.toolName} | args: ${debugTruncate(argsStr)} | result: ${debugTruncate(resultStr)}`);
|
|
97486
97496
|
}
|
|
97487
97497
|
}
|
|
97488
|
-
var import_dotenv, import_ai4, import_crypto8, import_events4, import_fs11, import_promises6, import_path16, ENGINE_ACTIVITY_TIMEOUT_DEFAULT, ENGINE_ACTIVITY_TIMEOUT_MIN, ENGINE_ACTIVITY_TIMEOUT_MAX, MAX_TOOL_ITERATIONS, MAX_HISTORY_MESSAGES, MAX_IMAGE_FILE_SIZE, ProbeAgent;
|
|
97498
|
+
var import_dotenv, import_ai4, import_crypto8, import_events4, import_fs11, import_promises6, import_path16, ENGINE_ACTIVITY_TIMEOUT_DEFAULT, ENGINE_ACTIVITY_TIMEOUT_MIN, ENGINE_ACTIVITY_TIMEOUT_MAX, MAX_TOOL_ITERATIONS, MAX_HISTORY_MESSAGES, MAX_IMAGE_FILE_SIZE, MAX_DOCUMENT_FILE_SIZE, ProbeAgent;
|
|
97489
97499
|
var init_ProbeAgent = __esm({
|
|
97490
97500
|
"src/agent/ProbeAgent.js"() {
|
|
97491
97501
|
"use strict";
|
|
@@ -97501,7 +97511,7 @@ var init_ProbeAgent = __esm({
|
|
|
97501
97511
|
init_simpleTelemetry();
|
|
97502
97512
|
init_InMemoryStorageAdapter();
|
|
97503
97513
|
init_HookManager();
|
|
97504
|
-
|
|
97514
|
+
init_mediaConfig();
|
|
97505
97515
|
init_tools();
|
|
97506
97516
|
init_common();
|
|
97507
97517
|
init_taskTool();
|
|
@@ -97539,6 +97549,7 @@ var init_ProbeAgent = __esm({
|
|
|
97539
97549
|
})();
|
|
97540
97550
|
MAX_HISTORY_MESSAGES = 100;
|
|
97541
97551
|
MAX_IMAGE_FILE_SIZE = 20 * 1024 * 1024;
|
|
97552
|
+
MAX_DOCUMENT_FILE_SIZE = 32 * 1024 * 1024;
|
|
97542
97553
|
ProbeAgent = class _ProbeAgent {
|
|
97543
97554
|
/**
|
|
97544
97555
|
* Create a new ProbeAgent instance
|
|
@@ -98167,28 +98178,29 @@ var init_ProbeAgent = __esm({
|
|
|
98167
98178
|
this.toolImplementations.useSkill = useSkillToolInstance;
|
|
98168
98179
|
}
|
|
98169
98180
|
}
|
|
98170
|
-
|
|
98171
|
-
|
|
98172
|
-
|
|
98173
|
-
|
|
98174
|
-
|
|
98175
|
-
|
|
98176
|
-
|
|
98177
|
-
|
|
98178
|
-
|
|
98179
|
-
|
|
98180
|
-
|
|
98181
|
-
|
|
98182
|
-
|
|
98183
|
-
|
|
98184
|
-
|
|
98185
|
-
|
|
98186
|
-
|
|
98187
|
-
|
|
98188
|
-
|
|
98189
|
-
|
|
98190
|
-
|
|
98191
|
-
};
|
|
98181
|
+
const readMediaExecute = async (params) => {
|
|
98182
|
+
const mediaPath = params.path;
|
|
98183
|
+
if (!mediaPath) {
|
|
98184
|
+
throw new Error("File path is required");
|
|
98185
|
+
}
|
|
98186
|
+
const filename = (0, import_path16.basename)(mediaPath);
|
|
98187
|
+
const extension = filename.toLowerCase().split(".").pop();
|
|
98188
|
+
if (!extension || !SUPPORTED_MEDIA_EXTENSIONS.includes(extension)) {
|
|
98189
|
+
throw new Error(`Unsupported file format: ${extension}. Supported formats: ${SUPPORTED_MEDIA_EXTENSIONS.join(", ")}`);
|
|
98190
|
+
}
|
|
98191
|
+
if (this.apiType && !isFormatSupportedByProvider(extension, this.apiType)) {
|
|
98192
|
+
throw new Error(`File format '${extension}' is not supported by the current AI provider (${this.apiType}). Try converting to a different format.`);
|
|
98193
|
+
}
|
|
98194
|
+
const loaded = await this.loadMediaIfValid(mediaPath);
|
|
98195
|
+
if (!loaded) {
|
|
98196
|
+
throw new Error(`Failed to load file: ${mediaPath}. The file may not exist, be too large, have an unsupported format, or be outside allowed directories.`);
|
|
98197
|
+
}
|
|
98198
|
+
const mediaType = isDocumentExtension(extension) ? "Document" : "Image";
|
|
98199
|
+
return `${mediaType} loaded successfully: ${mediaPath}. The file is now available for analysis in the conversation.`;
|
|
98200
|
+
};
|
|
98201
|
+
if (isToolAllowed("readMedia") || isToolAllowed("readImage")) {
|
|
98202
|
+
this.toolImplementations.readMedia = { execute: readMediaExecute };
|
|
98203
|
+
this.toolImplementations.readImage = { execute: readMediaExecute };
|
|
98192
98204
|
}
|
|
98193
98205
|
if (this.enableBash && wrappedTools.bashToolInstance && isToolAllowed("bash")) {
|
|
98194
98206
|
this.toolImplementations.bash = wrappedTools.bashToolInstance;
|
|
@@ -99184,9 +99196,9 @@ var init_ProbeAgent = __esm({
|
|
|
99184
99196
|
schema: searchFilesSchema,
|
|
99185
99197
|
description: "Find files matching a glob pattern with recursive search capability."
|
|
99186
99198
|
},
|
|
99187
|
-
|
|
99188
|
-
schema:
|
|
99189
|
-
description: "Read and load
|
|
99199
|
+
readMedia: {
|
|
99200
|
+
schema: readMediaSchema,
|
|
99201
|
+
description: "Read and load a media file (image or PDF document) for AI analysis. Supports: png, jpg, jpeg, webp, bmp, svg, pdf."
|
|
99190
99202
|
},
|
|
99191
99203
|
listSkills: {
|
|
99192
99204
|
schema: listSkillsSchema,
|
|
@@ -99331,7 +99343,7 @@ var init_ProbeAgent = __esm({
|
|
|
99331
99343
|
async processImageReferences(content) {
|
|
99332
99344
|
if (!content) return;
|
|
99333
99345
|
const listFilesDirectories = this.extractListFilesDirectories(content);
|
|
99334
|
-
const extensionsPattern = `(?:${
|
|
99346
|
+
const extensionsPattern = `(?:${SUPPORTED_MEDIA_EXTENSIONS.join("|")})`;
|
|
99335
99347
|
const imagePatterns = [
|
|
99336
99348
|
// Direct file path mentions: "./screenshot.png", "/path/to/image.jpg", etc.
|
|
99337
99349
|
new RegExp(`(?:\\.?\\.\\/)?[^\\s"'<>\\[\\]]+\\.${extensionsPattern}(?!\\w)`, "gi"),
|
|
@@ -99413,23 +99425,23 @@ var init_ProbeAgent = __esm({
|
|
|
99413
99425
|
return directories;
|
|
99414
99426
|
}
|
|
99415
99427
|
/**
|
|
99416
|
-
* Load and cache
|
|
99417
|
-
* @param {string}
|
|
99418
|
-
* @returns {Promise<boolean>} - True if
|
|
99428
|
+
* Load and cache a media file (image or PDF) if it's valid and accessible
|
|
99429
|
+
* @param {string} mediaPath - Path to the media file
|
|
99430
|
+
* @returns {Promise<boolean>} - True if file was loaded successfully
|
|
99419
99431
|
*/
|
|
99420
|
-
async
|
|
99432
|
+
async loadMediaIfValid(mediaPath) {
|
|
99421
99433
|
try {
|
|
99422
|
-
if (this.pendingImages.has(
|
|
99434
|
+
if (this.pendingImages.has(mediaPath)) {
|
|
99423
99435
|
if (this.debug) {
|
|
99424
|
-
console.log(`[DEBUG]
|
|
99436
|
+
console.log(`[DEBUG] Media already loaded: ${mediaPath}`);
|
|
99425
99437
|
}
|
|
99426
99438
|
return true;
|
|
99427
99439
|
}
|
|
99428
99440
|
const allowedDirs = this.allowedFolders && this.allowedFolders.length > 0 ? this.allowedFolders : [process.cwd()];
|
|
99429
99441
|
let absolutePath;
|
|
99430
99442
|
let isPathAllowed2 = false;
|
|
99431
|
-
if ((0, import_path16.isAbsolute)(
|
|
99432
|
-
absolutePath = safeRealpath((0, import_path16.resolve)(
|
|
99443
|
+
if ((0, import_path16.isAbsolute)(mediaPath)) {
|
|
99444
|
+
absolutePath = safeRealpath((0, import_path16.resolve)(mediaPath));
|
|
99433
99445
|
isPathAllowed2 = allowedDirs.some((dir) => {
|
|
99434
99446
|
const resolvedDir = safeRealpath(dir);
|
|
99435
99447
|
return absolutePath === resolvedDir || absolutePath.startsWith(resolvedDir + import_path16.sep);
|
|
@@ -99437,7 +99449,7 @@ var init_ProbeAgent = __esm({
|
|
|
99437
99449
|
} else {
|
|
99438
99450
|
for (const dir of allowedDirs) {
|
|
99439
99451
|
const resolvedDir = safeRealpath(dir);
|
|
99440
|
-
const resolvedPath = safeRealpath((0, import_path16.resolve)(dir,
|
|
99452
|
+
const resolvedPath = safeRealpath((0, import_path16.resolve)(dir, mediaPath));
|
|
99441
99453
|
if (resolvedPath === resolvedDir || resolvedPath.startsWith(resolvedDir + import_path16.sep)) {
|
|
99442
99454
|
absolutePath = resolvedPath;
|
|
99443
99455
|
isPathAllowed2 = true;
|
|
@@ -99447,7 +99459,7 @@ var init_ProbeAgent = __esm({
|
|
|
99447
99459
|
}
|
|
99448
99460
|
if (!isPathAllowed2) {
|
|
99449
99461
|
if (this.debug) {
|
|
99450
|
-
console.log(`[DEBUG]
|
|
99462
|
+
console.log(`[DEBUG] Media path outside allowed directories: ${mediaPath}`);
|
|
99451
99463
|
}
|
|
99452
99464
|
return false;
|
|
99453
99465
|
}
|
|
@@ -99456,91 +99468,126 @@ var init_ProbeAgent = __esm({
|
|
|
99456
99468
|
fileStats = await (0, import_promises6.stat)(absolutePath);
|
|
99457
99469
|
} catch (error40) {
|
|
99458
99470
|
if (this.debug) {
|
|
99459
|
-
console.log(`[DEBUG]
|
|
99471
|
+
console.log(`[DEBUG] Media file not found: ${absolutePath}`);
|
|
99460
99472
|
}
|
|
99461
99473
|
return false;
|
|
99462
99474
|
}
|
|
99463
|
-
|
|
99475
|
+
const extension = absolutePath.toLowerCase().split(".").pop();
|
|
99476
|
+
if (!SUPPORTED_MEDIA_EXTENSIONS.includes(extension)) {
|
|
99464
99477
|
if (this.debug) {
|
|
99465
|
-
console.log(`[DEBUG]
|
|
99478
|
+
console.log(`[DEBUG] Unsupported media format: ${extension}`);
|
|
99466
99479
|
}
|
|
99467
99480
|
return false;
|
|
99468
99481
|
}
|
|
99469
|
-
const
|
|
99470
|
-
if (
|
|
99482
|
+
const maxSize = isDocumentExtension(extension) ? MAX_DOCUMENT_FILE_SIZE : MAX_IMAGE_FILE_SIZE;
|
|
99483
|
+
if (fileStats.size > maxSize) {
|
|
99471
99484
|
if (this.debug) {
|
|
99472
|
-
console.log(`[DEBUG]
|
|
99485
|
+
console.log(`[DEBUG] Media file too large: ${absolutePath} (${fileStats.size} bytes, max: ${maxSize})`);
|
|
99473
99486
|
}
|
|
99474
99487
|
return false;
|
|
99475
99488
|
}
|
|
99476
|
-
const mimeType =
|
|
99489
|
+
const mimeType = MEDIA_MIME_TYPES[extension];
|
|
99477
99490
|
const fileBuffer = await (0, import_promises6.readFile)(absolutePath);
|
|
99478
99491
|
const base64Data = fileBuffer.toString("base64");
|
|
99479
|
-
|
|
99480
|
-
|
|
99492
|
+
if (isDocumentExtension(extension)) {
|
|
99493
|
+
this.pendingImages.set(mediaPath, {
|
|
99494
|
+
type: "document",
|
|
99495
|
+
mimeType,
|
|
99496
|
+
data: base64Data,
|
|
99497
|
+
filename: (0, import_path16.basename)(mediaPath)
|
|
99498
|
+
});
|
|
99499
|
+
} else {
|
|
99500
|
+
const dataUrl = `data:${mimeType};base64,${base64Data}`;
|
|
99501
|
+
this.pendingImages.set(mediaPath, dataUrl);
|
|
99502
|
+
}
|
|
99481
99503
|
if (this.debug) {
|
|
99482
|
-
console.log(`[DEBUG] Successfully loaded
|
|
99504
|
+
console.log(`[DEBUG] Successfully loaded media: ${mediaPath} (${fileBuffer.length} bytes, ${mimeType})`);
|
|
99483
99505
|
}
|
|
99484
99506
|
return true;
|
|
99485
99507
|
} catch (error40) {
|
|
99486
99508
|
if (this.debug) {
|
|
99487
|
-
console.log(`[DEBUG] Failed to load
|
|
99509
|
+
console.log(`[DEBUG] Failed to load media ${mediaPath}: ${error40.message}`);
|
|
99488
99510
|
}
|
|
99489
99511
|
return false;
|
|
99490
99512
|
}
|
|
99491
99513
|
}
|
|
99514
|
+
/**
|
|
99515
|
+
* Backward-compatible alias for loadMediaIfValid
|
|
99516
|
+
* @param {string} imagePath - Path to the image file
|
|
99517
|
+
* @returns {Promise<boolean>}
|
|
99518
|
+
*/
|
|
99519
|
+
async loadImageIfValid(imagePath) {
|
|
99520
|
+
return this.loadMediaIfValid(imagePath);
|
|
99521
|
+
}
|
|
99492
99522
|
/**
|
|
99493
99523
|
* Get all currently loaded images as an array for AI model consumption
|
|
99494
|
-
* @returns {Array<string>} - Array of base64 data URLs
|
|
99524
|
+
* @returns {Array<string>} - Array of base64 data URLs (images only, for backward compat)
|
|
99495
99525
|
*/
|
|
99496
99526
|
getCurrentImages() {
|
|
99497
|
-
return Array.from(this.pendingImages.values());
|
|
99527
|
+
return Array.from(this.pendingImages.values()).filter((v) => typeof v === "string");
|
|
99498
99528
|
}
|
|
99499
99529
|
/**
|
|
99500
|
-
*
|
|
99530
|
+
* Get all currently loaded media as an array of content parts
|
|
99531
|
+
* @returns {Array<Object>} - Array of Vercel AI SDK content parts
|
|
99532
|
+
*/
|
|
99533
|
+
getCurrentMedia() {
|
|
99534
|
+
const parts = [];
|
|
99535
|
+
for (const entry of this.pendingImages.values()) {
|
|
99536
|
+
if (typeof entry === "string") {
|
|
99537
|
+
parts.push({ type: "image", image: entry });
|
|
99538
|
+
} else if (entry && entry.type === "document") {
|
|
99539
|
+
parts.push({
|
|
99540
|
+
type: "file",
|
|
99541
|
+
mediaType: entry.mimeType,
|
|
99542
|
+
data: entry.data,
|
|
99543
|
+
filename: entry.filename
|
|
99544
|
+
});
|
|
99545
|
+
}
|
|
99546
|
+
}
|
|
99547
|
+
return parts;
|
|
99548
|
+
}
|
|
99549
|
+
/**
|
|
99550
|
+
* Clear loaded media (useful for new conversations)
|
|
99501
99551
|
*/
|
|
99502
99552
|
clearLoadedImages() {
|
|
99503
99553
|
this.pendingImages.clear();
|
|
99504
99554
|
this.currentImages = [];
|
|
99505
99555
|
if (this.debug) {
|
|
99506
|
-
console.log("[DEBUG] Cleared all loaded
|
|
99556
|
+
console.log("[DEBUG] Cleared all loaded media");
|
|
99507
99557
|
}
|
|
99508
99558
|
}
|
|
99509
99559
|
/**
|
|
99510
|
-
* Prepare messages for AI consumption, adding
|
|
99560
|
+
* Prepare messages for AI consumption, adding media to the latest user message if available
|
|
99511
99561
|
* @param {Array} messages - Current conversation messages
|
|
99512
|
-
* @returns {Array} - Messages formatted for AI SDK with potential
|
|
99562
|
+
* @returns {Array} - Messages formatted for AI SDK with potential media content
|
|
99513
99563
|
*/
|
|
99514
99564
|
prepareMessagesWithImages(messages) {
|
|
99515
|
-
const
|
|
99516
|
-
if (
|
|
99565
|
+
const mediaParts = this.getCurrentMedia();
|
|
99566
|
+
if (mediaParts.length === 0) {
|
|
99517
99567
|
return messages;
|
|
99518
99568
|
}
|
|
99519
|
-
const
|
|
99520
|
-
const lastUserMessageIndex =
|
|
99569
|
+
const messagesWithMedia = [...messages];
|
|
99570
|
+
const lastUserMessageIndex = messagesWithMedia.map((m) => m.role).lastIndexOf("user");
|
|
99521
99571
|
if (lastUserMessageIndex === -1) {
|
|
99522
99572
|
if (this.debug) {
|
|
99523
|
-
console.log("[DEBUG] No user messages found to attach
|
|
99573
|
+
console.log("[DEBUG] No user messages found to attach media to");
|
|
99524
99574
|
}
|
|
99525
99575
|
return messages;
|
|
99526
99576
|
}
|
|
99527
|
-
const lastUserMessage =
|
|
99577
|
+
const lastUserMessage = messagesWithMedia[lastUserMessageIndex];
|
|
99528
99578
|
if (typeof lastUserMessage.content === "string") {
|
|
99529
|
-
|
|
99579
|
+
messagesWithMedia[lastUserMessageIndex] = {
|
|
99530
99580
|
...lastUserMessage,
|
|
99531
99581
|
content: [
|
|
99532
99582
|
{ type: "text", text: lastUserMessage.content },
|
|
99533
|
-
...
|
|
99534
|
-
type: "image",
|
|
99535
|
-
image: imageData
|
|
99536
|
-
}))
|
|
99583
|
+
...mediaParts
|
|
99537
99584
|
]
|
|
99538
99585
|
};
|
|
99539
99586
|
if (this.debug) {
|
|
99540
|
-
console.log(`[DEBUG] Added ${
|
|
99587
|
+
console.log(`[DEBUG] Added ${mediaParts.length} media items to the latest user message`);
|
|
99541
99588
|
}
|
|
99542
99589
|
}
|
|
99543
|
-
return
|
|
99590
|
+
return messagesWithMedia;
|
|
99544
99591
|
}
|
|
99545
99592
|
/**
|
|
99546
99593
|
* Initialize mock model for testing
|
|
@@ -105321,6 +105368,7 @@ __export(tools_exports, {
|
|
|
105321
105368
|
querySchema: () => querySchema,
|
|
105322
105369
|
queryTool: () => queryTool,
|
|
105323
105370
|
readImageSchema: () => readImageSchema,
|
|
105371
|
+
readMediaSchema: () => readMediaSchema,
|
|
105324
105372
|
resolveTargetPath: () => resolveTargetPath,
|
|
105325
105373
|
searchFilesSchema: () => searchFilesSchema,
|
|
105326
105374
|
searchSchema: () => searchSchema,
|
|
@@ -105526,6 +105574,7 @@ __export(index_exports, {
|
|
|
105526
105574
|
querySchema: () => querySchema,
|
|
105527
105575
|
queryTool: () => queryTool,
|
|
105528
105576
|
readImageSchema: () => readImageSchema,
|
|
105577
|
+
readMediaSchema: () => readMediaSchema,
|
|
105529
105578
|
search: () => search,
|
|
105530
105579
|
searchFilesSchema: () => searchFilesSchema,
|
|
105531
105580
|
searchFilesToolInstance: () => searchFilesToolInstance,
|
|
@@ -105615,6 +105664,7 @@ init_index();
|
|
|
105615
105664
|
querySchema,
|
|
105616
105665
|
queryTool,
|
|
105617
105666
|
readImageSchema,
|
|
105667
|
+
readMediaSchema,
|
|
105618
105668
|
search,
|
|
105619
105669
|
searchFilesSchema,
|
|
105620
105670
|
searchFilesToolInstance,
|