@dexto/core 1.6.20 → 1.6.22
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/agent/DextoAgent.cjs +159 -51
- package/dist/agent/DextoAgent.d.ts +3 -1
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +162 -53
- package/dist/agent/types.d.ts +2 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/context/manager.cjs +144 -35
- package/dist/context/manager.d.ts +4 -0
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +146 -36
- package/dist/context/types.cjs +5 -0
- package/dist/context/types.d.ts +21 -1
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/types.js +4 -0
- package/dist/context/utils.cjs +85 -25
- package/dist/context/utils.d.ts +5 -3
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +84 -25
- package/dist/llm/executor/turn-executor.cjs +2 -2
- package/dist/llm/executor/turn-executor.d.ts +1 -1
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +2 -2
- package/dist/llm/formatters/vercel.cjs +3 -1
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +3 -1
- package/dist/llm/registry/index.cjs +43 -12
- package/dist/llm/registry/index.d.ts.map +1 -1
- package/dist/llm/registry/index.js +43 -12
- package/dist/llm/registry/models.generated.cjs +1270 -1324
- package/dist/llm/registry/models.generated.d.ts +617 -210
- package/dist/llm/registry/models.generated.d.ts.map +1 -1
- package/dist/llm/registry/models.generated.js +1270 -1324
- package/dist/llm/registry/sync.cjs +5 -0
- package/dist/llm/registry/sync.d.ts.map +1 -1
- package/dist/llm/registry/sync.js +5 -0
- package/dist/llm/types.cjs +1 -1
- package/dist/llm/types.d.ts +1 -1
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/llm/types.js +1 -1
- package/dist/resources/handlers/filesystem-handler.cjs +55 -9
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.js +55 -9
- package/dist/resources/reference-parser.cjs +47 -12
- package/dist/resources/reference-parser.d.ts +6 -3
- package/dist/resources/reference-parser.d.ts.map +1 -1
- package/dist/resources/reference-parser.js +47 -12
- package/dist/utils/api-key-resolver.cjs +25 -0
- package/dist/utils/api-key-resolver.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.js +25 -0
- package/package.json +1 -1
|
@@ -167,6 +167,11 @@ function getSupportedFileTypesFromModel(provider, model) {
|
|
|
167
167
|
if (inputModalities.includes("pdf")) fileTypes.push("pdf");
|
|
168
168
|
if (inputModalities.includes("image")) fileTypes.push("image");
|
|
169
169
|
if (inputModalities.includes("audio")) fileTypes.push("audio");
|
|
170
|
+
if (inputModalities.includes("video")) fileTypes.push("video");
|
|
171
|
+
const supportsDocumentInputs = provider === "openai" && (inputModalities.includes("image") || inputModalities.includes("pdf")) || (provider === "google" || provider === "vertex") && (inputModalities.includes("image") || inputModalities.includes("audio") || inputModalities.includes("video") || inputModalities.includes("pdf")) || provider === "openrouter" && (model.id.startsWith("openai/") && (inputModalities.includes("image") || inputModalities.includes("pdf")) || model.id.startsWith("google/") && (inputModalities.includes("image") || inputModalities.includes("audio") || inputModalities.includes("video") || inputModalities.includes("pdf")));
|
|
172
|
+
if (supportsDocumentInputs && !fileTypes.includes("document")) {
|
|
173
|
+
fileTypes.push("document");
|
|
174
|
+
}
|
|
170
175
|
if (provider === "openai" && model.attachment === true && inputModalities.includes("image")) {
|
|
171
176
|
if (!fileTypes.includes("pdf")) fileTypes.unshift("pdf");
|
|
172
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../../src/llm/registry/sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE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AAY,EAAE,YAAY,CAAC;CAC9B,GAAG,MAAM,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAuJnC;AAED,wBAAsB,+BAA+B,CAAC,OAAO,CAAC,EAAE;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,CAoB5C"}
|
|
@@ -142,6 +142,11 @@ function getSupportedFileTypesFromModel(provider, model) {
|
|
|
142
142
|
if (inputModalities.includes("pdf")) fileTypes.push("pdf");
|
|
143
143
|
if (inputModalities.includes("image")) fileTypes.push("image");
|
|
144
144
|
if (inputModalities.includes("audio")) fileTypes.push("audio");
|
|
145
|
+
if (inputModalities.includes("video")) fileTypes.push("video");
|
|
146
|
+
const supportsDocumentInputs = provider === "openai" && (inputModalities.includes("image") || inputModalities.includes("pdf")) || (provider === "google" || provider === "vertex") && (inputModalities.includes("image") || inputModalities.includes("audio") || inputModalities.includes("video") || inputModalities.includes("pdf")) || provider === "openrouter" && (model.id.startsWith("openai/") && (inputModalities.includes("image") || inputModalities.includes("pdf")) || model.id.startsWith("google/") && (inputModalities.includes("image") || inputModalities.includes("audio") || inputModalities.includes("video") || inputModalities.includes("pdf")));
|
|
147
|
+
if (supportsDocumentInputs && !fileTypes.includes("document")) {
|
|
148
|
+
fileTypes.push("document");
|
|
149
|
+
}
|
|
145
150
|
if (provider === "openai" && model.attachment === true && inputModalities.includes("image")) {
|
|
146
151
|
if (!fileTypes.includes("pdf")) fileTypes.unshift("pdf");
|
|
147
152
|
}
|
package/dist/llm/types.cjs
CHANGED
|
@@ -46,7 +46,7 @@ const LLM_PROVIDERS = [
|
|
|
46
46
|
// Dexto gateway - routes through api.dexto.ai/v1 with billing
|
|
47
47
|
];
|
|
48
48
|
const LLM_PRICING_STATUSES = ["estimated", "unpriced"];
|
|
49
|
-
const SUPPORTED_FILE_TYPES = ["pdf", "image", "audio"];
|
|
49
|
+
const SUPPORTED_FILE_TYPES = ["pdf", "image", "audio", "video", "document"];
|
|
50
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
51
51
|
0 && (module.exports = {
|
|
52
52
|
LLM_PRICING_STATUSES,
|
package/dist/llm/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare const LLM_PROVIDERS: readonly ["openai", "openai-compatible", "an
|
|
|
2
2
|
export type LLMProvider = (typeof LLM_PROVIDERS)[number];
|
|
3
3
|
export declare const LLM_PRICING_STATUSES: readonly ["estimated", "unpriced"];
|
|
4
4
|
export type LLMPricingStatus = (typeof LLM_PRICING_STATUSES)[number];
|
|
5
|
-
export declare const SUPPORTED_FILE_TYPES: readonly ["pdf", "image", "audio"];
|
|
5
|
+
export declare const SUPPORTED_FILE_TYPES: readonly ["pdf", "image", "audio", "video", "document"];
|
|
6
6
|
export type SupportedFileType = (typeof SUPPORTED_FILE_TYPES)[number];
|
|
7
7
|
export type ReasoningVariant = string;
|
|
8
8
|
export interface LLMReasoningConfig {
|
package/dist/llm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/llm/types.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,oMAkBhB,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,eAAO,MAAM,oBAAoB,oCAAqC,CAAC;AACvE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/llm/types.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,oMAkBhB,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,eAAO,MAAM,oBAAoB,oCAAqC,CAAC;AACvE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,eAAO,MAAM,oBAAoB,yDAA0D,CAAC;AAC5F,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAItE,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,gBAAgB,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED;;;GAGG;AAEH,MAAM,WAAW,UAAU;IACvB,mDAAmD;IACnD,QAAQ,EAAE,WAAW,CAAC;IAEtB,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,EAAE,WAAW,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B"}
|
package/dist/llm/types.js
CHANGED
|
@@ -22,7 +22,7 @@ const LLM_PROVIDERS = [
|
|
|
22
22
|
// Dexto gateway - routes through api.dexto.ai/v1 with billing
|
|
23
23
|
];
|
|
24
24
|
const LLM_PRICING_STATUSES = ["estimated", "unpriced"];
|
|
25
|
-
const SUPPORTED_FILE_TYPES = ["pdf", "image", "audio"];
|
|
25
|
+
const SUPPORTED_FILE_TYPES = ["pdf", "image", "audio", "video", "document"];
|
|
26
26
|
export {
|
|
27
27
|
LLM_PRICING_STATUSES,
|
|
28
28
|
LLM_PROVIDERS,
|
|
@@ -69,7 +69,7 @@ class FileSystemResourceHandler {
|
|
|
69
69
|
return Array.from(this.resourcesCache.values());
|
|
70
70
|
}
|
|
71
71
|
canHandle(uri) {
|
|
72
|
-
return uri.startsWith("fs://");
|
|
72
|
+
return uri.startsWith("fs://") || import_path.default.isAbsolute(uri);
|
|
73
73
|
}
|
|
74
74
|
isPathAllowed(canonicalPath) {
|
|
75
75
|
return this.canonicalRoots.some((root) => {
|
|
@@ -94,7 +94,7 @@ class FileSystemResourceHandler {
|
|
|
94
94
|
if (!this.canHandle(uri)) {
|
|
95
95
|
throw import_errors.ResourceError.noSuitableProvider(uri);
|
|
96
96
|
}
|
|
97
|
-
const filePath = uri.replace("fs://", "");
|
|
97
|
+
const filePath = uri.startsWith("fs://") ? uri.replace("fs://", "") : uri;
|
|
98
98
|
const resolvedPath = import_path.default.resolve(filePath);
|
|
99
99
|
let canonicalPath;
|
|
100
100
|
try {
|
|
@@ -111,18 +111,21 @@ class FileSystemResourceHandler {
|
|
|
111
111
|
throw import_errors.ResourceError.readFailed(uri, `File too large (${stat.size} bytes)`);
|
|
112
112
|
}
|
|
113
113
|
if (this.isBinaryFile(canonicalPath)) {
|
|
114
|
+
const mimeType = this.getMimeType(canonicalPath);
|
|
115
|
+
const content2 = await import_fs.promises.readFile(canonicalPath);
|
|
114
116
|
return {
|
|
115
117
|
contents: [
|
|
116
118
|
{
|
|
117
119
|
uri,
|
|
118
|
-
mimeType
|
|
119
|
-
|
|
120
|
+
mimeType,
|
|
121
|
+
blob: content2.toString("base64")
|
|
120
122
|
}
|
|
121
123
|
],
|
|
122
124
|
_meta: {
|
|
123
125
|
isBinary: true,
|
|
124
126
|
size: stat.size,
|
|
125
|
-
originalMimeType:
|
|
127
|
+
originalMimeType: mimeType,
|
|
128
|
+
originalName: import_path.default.basename(canonicalPath)
|
|
126
129
|
}
|
|
127
130
|
};
|
|
128
131
|
}
|
|
@@ -135,7 +138,7 @@ class FileSystemResourceHandler {
|
|
|
135
138
|
text: content
|
|
136
139
|
}
|
|
137
140
|
],
|
|
138
|
-
_meta: { size: stat.size }
|
|
141
|
+
_meta: { size: stat.size, originalName: import_path.default.basename(canonicalPath) }
|
|
139
142
|
};
|
|
140
143
|
} catch (error) {
|
|
141
144
|
throw import_errors.ResourceError.readFailed(uri, error);
|
|
@@ -160,14 +163,24 @@ class FileSystemResourceHandler {
|
|
|
160
163
|
".ico",
|
|
161
164
|
".tiff",
|
|
162
165
|
".webp",
|
|
166
|
+
".svg",
|
|
167
|
+
".avif",
|
|
163
168
|
".mp3",
|
|
169
|
+
".wav",
|
|
170
|
+
".ogg",
|
|
171
|
+
".oga",
|
|
172
|
+
".m4a",
|
|
173
|
+
".aac",
|
|
174
|
+
".flac",
|
|
164
175
|
".mp4",
|
|
176
|
+
".m4v",
|
|
165
177
|
".avi",
|
|
166
178
|
".mov",
|
|
167
179
|
".wmv",
|
|
168
180
|
".flv",
|
|
169
181
|
".mkv",
|
|
170
182
|
".webm",
|
|
183
|
+
".ogv",
|
|
171
184
|
".pdf",
|
|
172
185
|
".zip",
|
|
173
186
|
".tar",
|
|
@@ -243,14 +256,17 @@ class FileSystemResourceHandler {
|
|
|
243
256
|
const stat = await import_fs.promises.stat(canonical);
|
|
244
257
|
if (stat.isFile()) {
|
|
245
258
|
if (!this.shouldIncludeFile(canonical, includeExtensions, includeHidden)) return;
|
|
246
|
-
const uri =
|
|
259
|
+
const uri = canonical.replace(/\\/g, "/");
|
|
247
260
|
this.resourcesCache.set(uri, {
|
|
248
261
|
uri,
|
|
249
262
|
name: this.generateCleanFileName(canonical),
|
|
250
263
|
description: "Filesystem resource",
|
|
251
264
|
source: "internal",
|
|
252
265
|
size: stat.size,
|
|
253
|
-
lastModified: stat.mtime
|
|
266
|
+
lastModified: stat.mtime,
|
|
267
|
+
metadata: {
|
|
268
|
+
originalUri: canonical.replace(/\\/g, "/")
|
|
269
|
+
}
|
|
254
270
|
});
|
|
255
271
|
this.fileCount++;
|
|
256
272
|
return;
|
|
@@ -375,6 +391,7 @@ class FileSystemResourceHandler {
|
|
|
375
391
|
".tsx": "text/typescript",
|
|
376
392
|
".vue": "text/x-vue",
|
|
377
393
|
".json": "application/json",
|
|
394
|
+
".jsonc": "application/json",
|
|
378
395
|
".xml": "text/xml",
|
|
379
396
|
".yaml": "text/yaml",
|
|
380
397
|
".yml": "text/yaml",
|
|
@@ -382,6 +399,8 @@ class FileSystemResourceHandler {
|
|
|
382
399
|
".ini": "text/plain",
|
|
383
400
|
".cfg": "text/plain",
|
|
384
401
|
".conf": "text/plain",
|
|
402
|
+
".csv": "text/csv",
|
|
403
|
+
".log": "text/plain",
|
|
385
404
|
".py": "text/x-python",
|
|
386
405
|
".rb": "text/x-ruby",
|
|
387
406
|
".php": "text/x-php",
|
|
@@ -401,7 +420,34 @@ class FileSystemResourceHandler {
|
|
|
401
420
|
".sql": "text/x-sql",
|
|
402
421
|
".rst": "text/x-rst",
|
|
403
422
|
".tex": "text/x-tex",
|
|
404
|
-
".dockerfile": "text/x-dockerfile"
|
|
423
|
+
".dockerfile": "text/x-dockerfile",
|
|
424
|
+
".pdf": "application/pdf",
|
|
425
|
+
".jpg": "image/jpeg",
|
|
426
|
+
".jpeg": "image/jpeg",
|
|
427
|
+
".png": "image/png",
|
|
428
|
+
".gif": "image/gif",
|
|
429
|
+
".bmp": "image/bmp",
|
|
430
|
+
".ico": "image/x-icon",
|
|
431
|
+
".tif": "image/tiff",
|
|
432
|
+
".tiff": "image/tiff",
|
|
433
|
+
".webp": "image/webp",
|
|
434
|
+
".svg": "image/svg+xml",
|
|
435
|
+
".avif": "image/avif",
|
|
436
|
+
".mp3": "audio/mpeg",
|
|
437
|
+
".wav": "audio/wav",
|
|
438
|
+
".ogg": "audio/ogg",
|
|
439
|
+
".oga": "audio/ogg",
|
|
440
|
+
".m4a": "audio/mp4",
|
|
441
|
+
".aac": "audio/aac",
|
|
442
|
+
".flac": "audio/flac",
|
|
443
|
+
".weba": "audio/webm",
|
|
444
|
+
".mp4": "video/mp4",
|
|
445
|
+
".m4v": "video/mp4",
|
|
446
|
+
".webm": "video/webm",
|
|
447
|
+
".mov": "video/quicktime",
|
|
448
|
+
".avi": "video/x-msvideo",
|
|
449
|
+
".mkv": "video/x-matroska",
|
|
450
|
+
".ogv": "video/ogg"
|
|
405
451
|
};
|
|
406
452
|
return mimeTypes[ext] || "text/plain";
|
|
407
453
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filesystem-handler.d.ts","sourceRoot":"","sources":["../../../src/resources/handlers/filesystem-handler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEpF,qBAAa,yBAA0B,YAAW,uBAAuB;IACrE,OAAO,CAAC,MAAM,CAAoC;IAClD,OAAO,CAAC,cAAc,CAA4C;IAClE,OAAO,CAAC,YAAY,CAA0B;IAC9C,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,MAAM,CAAS;gBAGnB,MAAM,EAAE,iCAAiC,EACzC,MAAM,EAAE,MAAM,EACd,eAAe,CAAC,EAAE,MAAM;IAO5B,OAAO,IAAI,MAAM;IAIX,UAAU,CAAC,SAAS,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB9D,aA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B,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA6D5D,OAAO,CAAC,YAAY;IA8Dd,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAIhB,kBAAkB;YA8BlB,QAAQ;IA4EtB,OAAO,CAAC,qBAAqB;IAsB7B,OAAO,CAAC,iBAAiB;IAwCzB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IA0C7B,OAAO,CAAC,WAAW;CA4EtB"}
|
|
@@ -37,7 +37,7 @@ class FileSystemResourceHandler {
|
|
|
37
37
|
return Array.from(this.resourcesCache.values());
|
|
38
38
|
}
|
|
39
39
|
canHandle(uri) {
|
|
40
|
-
return uri.startsWith("fs://");
|
|
40
|
+
return uri.startsWith("fs://") || path.isAbsolute(uri);
|
|
41
41
|
}
|
|
42
42
|
isPathAllowed(canonicalPath) {
|
|
43
43
|
return this.canonicalRoots.some((root) => {
|
|
@@ -62,7 +62,7 @@ class FileSystemResourceHandler {
|
|
|
62
62
|
if (!this.canHandle(uri)) {
|
|
63
63
|
throw ResourceError.noSuitableProvider(uri);
|
|
64
64
|
}
|
|
65
|
-
const filePath = uri.replace("fs://", "");
|
|
65
|
+
const filePath = uri.startsWith("fs://") ? uri.replace("fs://", "") : uri;
|
|
66
66
|
const resolvedPath = path.resolve(filePath);
|
|
67
67
|
let canonicalPath;
|
|
68
68
|
try {
|
|
@@ -79,18 +79,21 @@ class FileSystemResourceHandler {
|
|
|
79
79
|
throw ResourceError.readFailed(uri, `File too large (${stat.size} bytes)`);
|
|
80
80
|
}
|
|
81
81
|
if (this.isBinaryFile(canonicalPath)) {
|
|
82
|
+
const mimeType = this.getMimeType(canonicalPath);
|
|
83
|
+
const content2 = await fs.readFile(canonicalPath);
|
|
82
84
|
return {
|
|
83
85
|
contents: [
|
|
84
86
|
{
|
|
85
87
|
uri,
|
|
86
|
-
mimeType
|
|
87
|
-
|
|
88
|
+
mimeType,
|
|
89
|
+
blob: content2.toString("base64")
|
|
88
90
|
}
|
|
89
91
|
],
|
|
90
92
|
_meta: {
|
|
91
93
|
isBinary: true,
|
|
92
94
|
size: stat.size,
|
|
93
|
-
originalMimeType:
|
|
95
|
+
originalMimeType: mimeType,
|
|
96
|
+
originalName: path.basename(canonicalPath)
|
|
94
97
|
}
|
|
95
98
|
};
|
|
96
99
|
}
|
|
@@ -103,7 +106,7 @@ class FileSystemResourceHandler {
|
|
|
103
106
|
text: content
|
|
104
107
|
}
|
|
105
108
|
],
|
|
106
|
-
_meta: { size: stat.size }
|
|
109
|
+
_meta: { size: stat.size, originalName: path.basename(canonicalPath) }
|
|
107
110
|
};
|
|
108
111
|
} catch (error) {
|
|
109
112
|
throw ResourceError.readFailed(uri, error);
|
|
@@ -128,14 +131,24 @@ class FileSystemResourceHandler {
|
|
|
128
131
|
".ico",
|
|
129
132
|
".tiff",
|
|
130
133
|
".webp",
|
|
134
|
+
".svg",
|
|
135
|
+
".avif",
|
|
131
136
|
".mp3",
|
|
137
|
+
".wav",
|
|
138
|
+
".ogg",
|
|
139
|
+
".oga",
|
|
140
|
+
".m4a",
|
|
141
|
+
".aac",
|
|
142
|
+
".flac",
|
|
132
143
|
".mp4",
|
|
144
|
+
".m4v",
|
|
133
145
|
".avi",
|
|
134
146
|
".mov",
|
|
135
147
|
".wmv",
|
|
136
148
|
".flv",
|
|
137
149
|
".mkv",
|
|
138
150
|
".webm",
|
|
151
|
+
".ogv",
|
|
139
152
|
".pdf",
|
|
140
153
|
".zip",
|
|
141
154
|
".tar",
|
|
@@ -211,14 +224,17 @@ class FileSystemResourceHandler {
|
|
|
211
224
|
const stat = await fs.stat(canonical);
|
|
212
225
|
if (stat.isFile()) {
|
|
213
226
|
if (!this.shouldIncludeFile(canonical, includeExtensions, includeHidden)) return;
|
|
214
|
-
const uri =
|
|
227
|
+
const uri = canonical.replace(/\\/g, "/");
|
|
215
228
|
this.resourcesCache.set(uri, {
|
|
216
229
|
uri,
|
|
217
230
|
name: this.generateCleanFileName(canonical),
|
|
218
231
|
description: "Filesystem resource",
|
|
219
232
|
source: "internal",
|
|
220
233
|
size: stat.size,
|
|
221
|
-
lastModified: stat.mtime
|
|
234
|
+
lastModified: stat.mtime,
|
|
235
|
+
metadata: {
|
|
236
|
+
originalUri: canonical.replace(/\\/g, "/")
|
|
237
|
+
}
|
|
222
238
|
});
|
|
223
239
|
this.fileCount++;
|
|
224
240
|
return;
|
|
@@ -343,6 +359,7 @@ class FileSystemResourceHandler {
|
|
|
343
359
|
".tsx": "text/typescript",
|
|
344
360
|
".vue": "text/x-vue",
|
|
345
361
|
".json": "application/json",
|
|
362
|
+
".jsonc": "application/json",
|
|
346
363
|
".xml": "text/xml",
|
|
347
364
|
".yaml": "text/yaml",
|
|
348
365
|
".yml": "text/yaml",
|
|
@@ -350,6 +367,8 @@ class FileSystemResourceHandler {
|
|
|
350
367
|
".ini": "text/plain",
|
|
351
368
|
".cfg": "text/plain",
|
|
352
369
|
".conf": "text/plain",
|
|
370
|
+
".csv": "text/csv",
|
|
371
|
+
".log": "text/plain",
|
|
353
372
|
".py": "text/x-python",
|
|
354
373
|
".rb": "text/x-ruby",
|
|
355
374
|
".php": "text/x-php",
|
|
@@ -369,7 +388,34 @@ class FileSystemResourceHandler {
|
|
|
369
388
|
".sql": "text/x-sql",
|
|
370
389
|
".rst": "text/x-rst",
|
|
371
390
|
".tex": "text/x-tex",
|
|
372
|
-
".dockerfile": "text/x-dockerfile"
|
|
391
|
+
".dockerfile": "text/x-dockerfile",
|
|
392
|
+
".pdf": "application/pdf",
|
|
393
|
+
".jpg": "image/jpeg",
|
|
394
|
+
".jpeg": "image/jpeg",
|
|
395
|
+
".png": "image/png",
|
|
396
|
+
".gif": "image/gif",
|
|
397
|
+
".bmp": "image/bmp",
|
|
398
|
+
".ico": "image/x-icon",
|
|
399
|
+
".tif": "image/tiff",
|
|
400
|
+
".tiff": "image/tiff",
|
|
401
|
+
".webp": "image/webp",
|
|
402
|
+
".svg": "image/svg+xml",
|
|
403
|
+
".avif": "image/avif",
|
|
404
|
+
".mp3": "audio/mpeg",
|
|
405
|
+
".wav": "audio/wav",
|
|
406
|
+
".ogg": "audio/ogg",
|
|
407
|
+
".oga": "audio/ogg",
|
|
408
|
+
".m4a": "audio/mp4",
|
|
409
|
+
".aac": "audio/aac",
|
|
410
|
+
".flac": "audio/flac",
|
|
411
|
+
".weba": "audio/webm",
|
|
412
|
+
".mp4": "video/mp4",
|
|
413
|
+
".m4v": "video/mp4",
|
|
414
|
+
".webm": "video/webm",
|
|
415
|
+
".mov": "video/quicktime",
|
|
416
|
+
".avi": "video/x-msvideo",
|
|
417
|
+
".mkv": "video/x-matroska",
|
|
418
|
+
".ogv": "video/ogg"
|
|
373
419
|
};
|
|
374
420
|
return mimeTypes[ext] || "text/plain";
|
|
375
421
|
}
|
|
@@ -24,9 +24,38 @@ __export(reference_parser_exports, {
|
|
|
24
24
|
resolveResourceReferences: () => resolveResourceReferences
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(reference_parser_exports);
|
|
27
|
+
function matchesMimePattern(mimeType, pattern) {
|
|
28
|
+
if (!mimeType) return false;
|
|
29
|
+
const normalizedMime = mimeType.toLowerCase().trim();
|
|
30
|
+
const normalizedPattern = pattern.toLowerCase().trim();
|
|
31
|
+
if (normalizedPattern === "*/*") {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (normalizedPattern.endsWith("/*")) {
|
|
35
|
+
const patternType = normalizedPattern.split("/")[0];
|
|
36
|
+
const mimeTypeType = normalizedMime.split("/")[0];
|
|
37
|
+
return mimeTypeType === patternType;
|
|
38
|
+
}
|
|
39
|
+
return normalizedMime === normalizedPattern;
|
|
40
|
+
}
|
|
41
|
+
function matchesAnyMimePattern(mimeType, patterns) {
|
|
42
|
+
return patterns.some((pattern) => matchesMimePattern(mimeType, pattern));
|
|
43
|
+
}
|
|
27
44
|
function escapeRegExp(literal) {
|
|
28
45
|
return literal.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
29
46
|
}
|
|
47
|
+
function deriveExtractedKind(mimeType) {
|
|
48
|
+
const normalizedMimeType = mimeType.trim().toLowerCase();
|
|
49
|
+
if (normalizedMimeType.startsWith("image/")) return "image";
|
|
50
|
+
if (normalizedMimeType.startsWith("audio/")) return "audio";
|
|
51
|
+
if (normalizedMimeType.startsWith("video/")) return "video";
|
|
52
|
+
return "binary";
|
|
53
|
+
}
|
|
54
|
+
function getCanonicalResourceReference(resourceUri, resource) {
|
|
55
|
+
const originalUri = typeof resource?.metadata?.originalUri === "string" ? resource.metadata.originalUri : void 0;
|
|
56
|
+
const candidate = originalUri ?? resourceUri;
|
|
57
|
+
return candidate.startsWith("fs://") ? candidate.replace("fs://", "") : candidate;
|
|
58
|
+
}
|
|
30
59
|
function parseResourceReferences(message) {
|
|
31
60
|
const references = [];
|
|
32
61
|
const regex = /(?:^|(?<=\s))@(?:(<[^>]+>)|([a-zA-Z0-9_-]+):([a-zA-Z0-9._/-]+)|([a-zA-Z0-9._/-]+))(?![a-zA-Z0-9@.])/g;
|
|
@@ -150,14 +179,14 @@ function formatResourceContent(resourceUri, resourceName, content) {
|
|
|
150
179
|
contentParts.push("--- End of resource content ---\n");
|
|
151
180
|
return contentParts.join("\n");
|
|
152
181
|
}
|
|
153
|
-
async function expandMessageReferences(message, availableResources, resourceReader) {
|
|
182
|
+
async function expandMessageReferences(message, availableResources, resourceReader, allowedMediaTypes) {
|
|
154
183
|
const parsedRefs = parseResourceReferences(message);
|
|
155
184
|
if (parsedRefs.length === 0) {
|
|
156
185
|
return {
|
|
157
186
|
expandedMessage: message,
|
|
158
187
|
expandedReferences: [],
|
|
159
188
|
unresolvedReferences: [],
|
|
160
|
-
|
|
189
|
+
extractedResources: []
|
|
161
190
|
};
|
|
162
191
|
}
|
|
163
192
|
const resolvedRefs = resolveResourceReferences(parsedRefs, availableResources);
|
|
@@ -165,24 +194,30 @@ async function expandMessageReferences(message, availableResources, resourceRead
|
|
|
165
194
|
const unresolvedReferences = resolvedRefs.filter((ref) => !ref.resourceUri);
|
|
166
195
|
let expandedMessage = message;
|
|
167
196
|
const failedRefs = [];
|
|
168
|
-
const
|
|
197
|
+
const extractedResources = [];
|
|
169
198
|
for (const ref of expandedReferences) {
|
|
170
199
|
try {
|
|
171
200
|
const content = await resourceReader(ref.resourceUri);
|
|
172
201
|
const resource = availableResources[ref.resourceUri];
|
|
173
|
-
|
|
202
|
+
const extractedFromResource = [];
|
|
174
203
|
for (const item of content.contents) {
|
|
175
|
-
if ("blob" in item && item.blob && item.mimeType &&
|
|
176
|
-
|
|
177
|
-
|
|
204
|
+
if ("blob" in item && item.blob && item.mimeType && typeof item.blob === "string") {
|
|
205
|
+
const isAllowed = !allowedMediaTypes || matchesAnyMimePattern(item.mimeType, allowedMediaTypes);
|
|
206
|
+
if (!isAllowed) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
extractedFromResource.push({
|
|
210
|
+
uri: getCanonicalResourceReference(ref.resourceUri, resource),
|
|
211
|
+
data: item.blob,
|
|
178
212
|
mimeType: item.mimeType,
|
|
179
|
-
name: resource?.name || ref.identifier
|
|
213
|
+
name: resource?.name || ref.identifier,
|
|
214
|
+
kind: deriveExtractedKind(item.mimeType),
|
|
215
|
+
...typeof content._meta?.size === "number" ? { size: content._meta.size } : {}
|
|
180
216
|
});
|
|
181
|
-
isImageResource = true;
|
|
182
|
-
break;
|
|
183
217
|
}
|
|
184
218
|
}
|
|
185
|
-
if (
|
|
219
|
+
if (extractedFromResource.length > 0) {
|
|
220
|
+
extractedResources.push(...extractedFromResource);
|
|
186
221
|
const pattern = new RegExp(escapeRegExp(ref.originalRef), "g");
|
|
187
222
|
expandedMessage = expandedMessage.replace(pattern, " ").replace(/\s{2,}/g, " ").trim();
|
|
188
223
|
} else {
|
|
@@ -205,7 +240,7 @@ async function expandMessageReferences(message, availableResources, resourceRead
|
|
|
205
240
|
expandedMessage,
|
|
206
241
|
expandedReferences: finalExpandedReferences,
|
|
207
242
|
unresolvedReferences,
|
|
208
|
-
|
|
243
|
+
extractedResources
|
|
209
244
|
};
|
|
210
245
|
}
|
|
211
246
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -11,10 +11,13 @@ export interface ResourceExpansionResult {
|
|
|
11
11
|
expandedMessage: string;
|
|
12
12
|
expandedReferences: ResourceReference[];
|
|
13
13
|
unresolvedReferences: ResourceReference[];
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
extractedResources: Array<{
|
|
15
|
+
uri: string;
|
|
16
|
+
data: string;
|
|
16
17
|
mimeType: string;
|
|
17
18
|
name: string;
|
|
19
|
+
kind: 'image' | 'audio' | 'video' | 'binary';
|
|
20
|
+
size?: number;
|
|
18
21
|
}>;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
@@ -29,5 +32,5 @@ export interface ResourceExpansionResult {
|
|
|
29
32
|
export declare function parseResourceReferences(message: string): ResourceReference[];
|
|
30
33
|
export declare function resolveResourceReferences(references: ResourceReference[], availableResources: ResourceSet): ResourceReference[];
|
|
31
34
|
export declare function formatResourceContent(resourceUri: string, resourceName: string, content: ReadResourceResult): string;
|
|
32
|
-
export declare function expandMessageReferences(message: string, availableResources: ResourceSet, resourceReader: (uri: string) => Promise<ReadResourceResult
|
|
35
|
+
export declare function expandMessageReferences(message: string, availableResources: ResourceSet, resourceReader: (uri: string) => Promise<ReadResourceResult>, allowedMediaTypes?: string[]): Promise<ResourceExpansionResult>;
|
|
33
36
|
//# sourceMappingURL=reference-parser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reference-parser.d.ts","sourceRoot":"","sources":["../../src/resources/reference-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAK7E,MAAM,WAAW,iBAAiB;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,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,yBAAyB,CACrC,UAAU,EAAE,iBAAiB,EAAE,EAC/B,kBAAkB,EAAE,WAAW,GAChC,iBAAiB,EAAE,CAmCrB;AAiGD,wBAAgB,qBAAqB,CACjC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,kBAAkB,GAC5B,MAAM,CAaR;AAED,wBAAsB,uBAAuB,CACzC,OAAO,EAAE,MAAM,EACf,kBAAkB,EAAE,WAAW,EAC/B,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,CAAC,EAC5D,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,uBAAuB,CAAC,CAoFlC"}
|
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
import "../chunk-PTJYTZNU.js";
|
|
2
|
+
function matchesMimePattern(mimeType, pattern) {
|
|
3
|
+
if (!mimeType) return false;
|
|
4
|
+
const normalizedMime = mimeType.toLowerCase().trim();
|
|
5
|
+
const normalizedPattern = pattern.toLowerCase().trim();
|
|
6
|
+
if (normalizedPattern === "*/*") {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (normalizedPattern.endsWith("/*")) {
|
|
10
|
+
const patternType = normalizedPattern.split("/")[0];
|
|
11
|
+
const mimeTypeType = normalizedMime.split("/")[0];
|
|
12
|
+
return mimeTypeType === patternType;
|
|
13
|
+
}
|
|
14
|
+
return normalizedMime === normalizedPattern;
|
|
15
|
+
}
|
|
16
|
+
function matchesAnyMimePattern(mimeType, patterns) {
|
|
17
|
+
return patterns.some((pattern) => matchesMimePattern(mimeType, pattern));
|
|
18
|
+
}
|
|
2
19
|
function escapeRegExp(literal) {
|
|
3
20
|
return literal.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
4
21
|
}
|
|
22
|
+
function deriveExtractedKind(mimeType) {
|
|
23
|
+
const normalizedMimeType = mimeType.trim().toLowerCase();
|
|
24
|
+
if (normalizedMimeType.startsWith("image/")) return "image";
|
|
25
|
+
if (normalizedMimeType.startsWith("audio/")) return "audio";
|
|
26
|
+
if (normalizedMimeType.startsWith("video/")) return "video";
|
|
27
|
+
return "binary";
|
|
28
|
+
}
|
|
29
|
+
function getCanonicalResourceReference(resourceUri, resource) {
|
|
30
|
+
const originalUri = typeof resource?.metadata?.originalUri === "string" ? resource.metadata.originalUri : void 0;
|
|
31
|
+
const candidate = originalUri ?? resourceUri;
|
|
32
|
+
return candidate.startsWith("fs://") ? candidate.replace("fs://", "") : candidate;
|
|
33
|
+
}
|
|
5
34
|
function parseResourceReferences(message) {
|
|
6
35
|
const references = [];
|
|
7
36
|
const regex = /(?:^|(?<=\s))@(?:(<[^>]+>)|([a-zA-Z0-9_-]+):([a-zA-Z0-9._/-]+)|([a-zA-Z0-9._/-]+))(?![a-zA-Z0-9@.])/g;
|
|
@@ -125,14 +154,14 @@ function formatResourceContent(resourceUri, resourceName, content) {
|
|
|
125
154
|
contentParts.push("--- End of resource content ---\n");
|
|
126
155
|
return contentParts.join("\n");
|
|
127
156
|
}
|
|
128
|
-
async function expandMessageReferences(message, availableResources, resourceReader) {
|
|
157
|
+
async function expandMessageReferences(message, availableResources, resourceReader, allowedMediaTypes) {
|
|
129
158
|
const parsedRefs = parseResourceReferences(message);
|
|
130
159
|
if (parsedRefs.length === 0) {
|
|
131
160
|
return {
|
|
132
161
|
expandedMessage: message,
|
|
133
162
|
expandedReferences: [],
|
|
134
163
|
unresolvedReferences: [],
|
|
135
|
-
|
|
164
|
+
extractedResources: []
|
|
136
165
|
};
|
|
137
166
|
}
|
|
138
167
|
const resolvedRefs = resolveResourceReferences(parsedRefs, availableResources);
|
|
@@ -140,24 +169,30 @@ async function expandMessageReferences(message, availableResources, resourceRead
|
|
|
140
169
|
const unresolvedReferences = resolvedRefs.filter((ref) => !ref.resourceUri);
|
|
141
170
|
let expandedMessage = message;
|
|
142
171
|
const failedRefs = [];
|
|
143
|
-
const
|
|
172
|
+
const extractedResources = [];
|
|
144
173
|
for (const ref of expandedReferences) {
|
|
145
174
|
try {
|
|
146
175
|
const content = await resourceReader(ref.resourceUri);
|
|
147
176
|
const resource = availableResources[ref.resourceUri];
|
|
148
|
-
|
|
177
|
+
const extractedFromResource = [];
|
|
149
178
|
for (const item of content.contents) {
|
|
150
|
-
if ("blob" in item && item.blob && item.mimeType &&
|
|
151
|
-
|
|
152
|
-
|
|
179
|
+
if ("blob" in item && item.blob && item.mimeType && typeof item.blob === "string") {
|
|
180
|
+
const isAllowed = !allowedMediaTypes || matchesAnyMimePattern(item.mimeType, allowedMediaTypes);
|
|
181
|
+
if (!isAllowed) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
extractedFromResource.push({
|
|
185
|
+
uri: getCanonicalResourceReference(ref.resourceUri, resource),
|
|
186
|
+
data: item.blob,
|
|
153
187
|
mimeType: item.mimeType,
|
|
154
|
-
name: resource?.name || ref.identifier
|
|
188
|
+
name: resource?.name || ref.identifier,
|
|
189
|
+
kind: deriveExtractedKind(item.mimeType),
|
|
190
|
+
...typeof content._meta?.size === "number" ? { size: content._meta.size } : {}
|
|
155
191
|
});
|
|
156
|
-
isImageResource = true;
|
|
157
|
-
break;
|
|
158
192
|
}
|
|
159
193
|
}
|
|
160
|
-
if (
|
|
194
|
+
if (extractedFromResource.length > 0) {
|
|
195
|
+
extractedResources.push(...extractedFromResource);
|
|
161
196
|
const pattern = new RegExp(escapeRegExp(ref.originalRef), "g");
|
|
162
197
|
expandedMessage = expandedMessage.replace(pattern, " ").replace(/\s{2,}/g, " ").trim();
|
|
163
198
|
} else {
|
|
@@ -180,7 +215,7 @@ async function expandMessageReferences(message, availableResources, resourceRead
|
|
|
180
215
|
expandedMessage,
|
|
181
216
|
expandedReferences: finalExpandedReferences,
|
|
182
217
|
unresolvedReferences,
|
|
183
|
-
|
|
218
|
+
extractedResources
|
|
184
219
|
};
|
|
185
220
|
}
|
|
186
221
|
export {
|