@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
package/dist/context/manager.js
CHANGED
|
@@ -7,10 +7,13 @@ import {
|
|
|
7
7
|
isLikelyBase64String,
|
|
8
8
|
filterCompacted,
|
|
9
9
|
estimateContextTokens,
|
|
10
|
-
estimateMessagesTokens
|
|
10
|
+
estimateMessagesTokens,
|
|
11
|
+
isBinaryMediaMimeType
|
|
11
12
|
} from "./utils.js";
|
|
12
13
|
import { ContextError } from "./errors.js";
|
|
14
|
+
import { getResourceKind } from "./media-helpers.js";
|
|
13
15
|
class ContextManager {
|
|
16
|
+
static PROMPT_MEDIA_RETENTION_MESSAGES = 2;
|
|
14
17
|
/**
|
|
15
18
|
* The validated LLM configuration.
|
|
16
19
|
*/
|
|
@@ -53,6 +56,114 @@ class ContextManager {
|
|
|
53
56
|
*/
|
|
54
57
|
resourceManager;
|
|
55
58
|
logger;
|
|
59
|
+
static deriveResourceKind(mimeType) {
|
|
60
|
+
if (mimeType.startsWith("text/") || mimeType === "application/json" || mimeType === "application/xml") {
|
|
61
|
+
return "text";
|
|
62
|
+
}
|
|
63
|
+
return getResourceKind(mimeType);
|
|
64
|
+
}
|
|
65
|
+
static hasRetainableMedia(message) {
|
|
66
|
+
if (!Array.isArray(message.content)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return message.content.some((part) => {
|
|
70
|
+
if (part.type === "resource") {
|
|
71
|
+
return isBinaryMediaMimeType(part.mimeType);
|
|
72
|
+
}
|
|
73
|
+
if (part.type === "image") {
|
|
74
|
+
return typeof part.image === "string" && part.image.startsWith("@blob:");
|
|
75
|
+
}
|
|
76
|
+
if (part.type === "file") {
|
|
77
|
+
return typeof part.data === "string" && part.data.startsWith("@blob:") && isBinaryMediaMimeType(part.mimeType);
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async persistContentPart(part, source) {
|
|
83
|
+
if (part.type === "text") {
|
|
84
|
+
return part.text.trim() ? { type: "text", text: part.text } : null;
|
|
85
|
+
}
|
|
86
|
+
if (part.type === "ui-resource") {
|
|
87
|
+
return part;
|
|
88
|
+
}
|
|
89
|
+
if (part.type === "resource") {
|
|
90
|
+
return {
|
|
91
|
+
...part,
|
|
92
|
+
uri: part.uri.startsWith("@blob:") ? part.uri.substring(1) : part.uri
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (part.type === "image") {
|
|
96
|
+
const mimeType = part.mimeType || "image/jpeg";
|
|
97
|
+
if (typeof part.image === "string" && part.image.startsWith("@blob:")) {
|
|
98
|
+
return {
|
|
99
|
+
type: "resource",
|
|
100
|
+
uri: part.image.substring(1),
|
|
101
|
+
name: "image",
|
|
102
|
+
mimeType,
|
|
103
|
+
kind: ContextManager.deriveResourceKind(mimeType),
|
|
104
|
+
metadata: { source: source === "user" ? "upload" : "tool" }
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const processedImage = await this.processUserInput(part.image, {
|
|
108
|
+
mimeType,
|
|
109
|
+
source
|
|
110
|
+
});
|
|
111
|
+
if (typeof processedImage === "string" && processedImage.startsWith("@blob:")) {
|
|
112
|
+
return {
|
|
113
|
+
type: "resource",
|
|
114
|
+
uri: processedImage.substring(1),
|
|
115
|
+
name: "image",
|
|
116
|
+
mimeType,
|
|
117
|
+
kind: ContextManager.deriveResourceKind(mimeType),
|
|
118
|
+
metadata: { source: source === "user" ? "upload" : "tool" }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
type: "image",
|
|
123
|
+
image: processedImage,
|
|
124
|
+
mimeType
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
const metadata = {
|
|
128
|
+
mimeType: part.mimeType,
|
|
129
|
+
source
|
|
130
|
+
};
|
|
131
|
+
if (part.filename) {
|
|
132
|
+
metadata.originalName = part.filename;
|
|
133
|
+
}
|
|
134
|
+
if (typeof part.data === "string" && part.data.startsWith("@blob:")) {
|
|
135
|
+
return {
|
|
136
|
+
type: "resource",
|
|
137
|
+
uri: part.data.substring(1),
|
|
138
|
+
name: part.filename ?? "file",
|
|
139
|
+
mimeType: part.mimeType,
|
|
140
|
+
kind: ContextManager.deriveResourceKind(part.mimeType),
|
|
141
|
+
metadata: {
|
|
142
|
+
source: source === "user" ? "upload" : "tool"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const processedData = await this.processUserInput(part.data, metadata);
|
|
147
|
+
if (typeof processedData === "string" && processedData.startsWith("@blob:")) {
|
|
148
|
+
return {
|
|
149
|
+
type: "resource",
|
|
150
|
+
uri: processedData.substring(1),
|
|
151
|
+
name: part.filename ?? "file",
|
|
152
|
+
mimeType: part.mimeType,
|
|
153
|
+
kind: ContextManager.deriveResourceKind(part.mimeType),
|
|
154
|
+
metadata: {
|
|
155
|
+
source: source === "user" ? "upload" : "tool"
|
|
156
|
+
},
|
|
157
|
+
...part.filename ? {} : {}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
type: "file",
|
|
162
|
+
data: processedData,
|
|
163
|
+
mimeType: part.mimeType,
|
|
164
|
+
...part.filename && { filename: part.filename }
|
|
165
|
+
};
|
|
166
|
+
}
|
|
56
167
|
/**
|
|
57
168
|
* Creates a new ContextManager instance
|
|
58
169
|
* @param llmConfig The validated LLM configuration.
|
|
@@ -493,50 +604,28 @@ ${prompt}`);
|
|
|
493
604
|
throw ContextError.userMessageContentEmpty();
|
|
494
605
|
}
|
|
495
606
|
const hasText = content.some((p) => p.type === "text" && p.text.trim() !== "");
|
|
496
|
-
const hasAttachment = content.some(
|
|
607
|
+
const hasAttachment = content.some(
|
|
608
|
+
(p) => p.type === "image" || p.type === "file" || p.type === "resource"
|
|
609
|
+
);
|
|
497
610
|
if (!hasText && !hasAttachment) {
|
|
498
611
|
throw ContextError.userMessageContentEmpty();
|
|
499
612
|
}
|
|
500
613
|
const processedParts = [];
|
|
501
614
|
for (const part of content) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
} else if (part.type === "image") {
|
|
507
|
-
const processedImage = await this.processUserInput(part.image, {
|
|
508
|
-
mimeType: part.mimeType || "image/jpeg",
|
|
509
|
-
source: "user"
|
|
510
|
-
});
|
|
511
|
-
processedParts.push({
|
|
512
|
-
type: "image",
|
|
513
|
-
image: processedImage,
|
|
514
|
-
mimeType: part.mimeType || "image/jpeg"
|
|
515
|
-
});
|
|
516
|
-
} else if (part.type === "file") {
|
|
517
|
-
const metadata = {
|
|
518
|
-
mimeType: part.mimeType,
|
|
519
|
-
source: "user"
|
|
520
|
-
};
|
|
521
|
-
if (part.filename) {
|
|
522
|
-
metadata.originalName = part.filename;
|
|
523
|
-
}
|
|
524
|
-
const processedData = await this.processUserInput(part.data, metadata);
|
|
525
|
-
processedParts.push({
|
|
526
|
-
type: "file",
|
|
527
|
-
data: processedData,
|
|
528
|
-
mimeType: part.mimeType,
|
|
529
|
-
...part.filename && { filename: part.filename }
|
|
530
|
-
});
|
|
615
|
+
const persisted = await this.persistContentPart(part, "user");
|
|
616
|
+
if (persisted) {
|
|
617
|
+
processedParts.push(persisted);
|
|
531
618
|
}
|
|
532
619
|
}
|
|
533
620
|
const textParts = processedParts.filter((p) => p.type === "text");
|
|
534
621
|
const imageParts = processedParts.filter((p) => p.type === "image");
|
|
535
622
|
const fileParts = processedParts.filter((p) => p.type === "file");
|
|
623
|
+
const resourceParts = processedParts.filter((p) => p.type === "resource");
|
|
536
624
|
this.logger.info("User message received", {
|
|
537
625
|
textParts: textParts.length,
|
|
538
626
|
imageParts: imageParts.length,
|
|
539
627
|
fileParts: fileParts.length,
|
|
628
|
+
resourceParts: resourceParts.length,
|
|
540
629
|
totalParts: processedParts.length
|
|
541
630
|
});
|
|
542
631
|
await this.addMessage({ role: "user", content: processedParts });
|
|
@@ -585,12 +674,19 @@ ${prompt}`);
|
|
|
585
674
|
throw ContextError.toolCallIdNameRequired();
|
|
586
675
|
}
|
|
587
676
|
const summary = sanitizedResult.content.map(
|
|
588
|
-
(p) => p.type === "text" ? `text(${p.text.length})` : p.type === "image" ? `image(${p.mimeType || "image"})` : p.type === "ui-resource" ? `ui-resource(${p.uri})` : `file(${p.mimeType || "file"})`
|
|
677
|
+
(p) => p.type === "text" ? `text(${p.text.length})` : p.type === "image" ? `image(${p.mimeType || "image"})` : p.type === "resource" ? `resource(${p.uri})` : p.type === "ui-resource" ? `ui-resource(${p.uri})` : `file(${p.mimeType || "file"})`
|
|
589
678
|
).join(", ");
|
|
590
679
|
this.logger.debug(`ContextManager: Storing tool result (parts) for ${name}: [${summary}]`);
|
|
680
|
+
const persistedContent = [];
|
|
681
|
+
for (const part of sanitizedResult.content) {
|
|
682
|
+
const persisted = await this.persistContentPart(part, "system");
|
|
683
|
+
if (persisted) {
|
|
684
|
+
persistedContent.push(persisted);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
591
687
|
await this.addMessage({
|
|
592
688
|
role: "tool",
|
|
593
|
-
content:
|
|
689
|
+
content: persistedContent,
|
|
594
690
|
toolCallId,
|
|
595
691
|
name,
|
|
596
692
|
...metadata?.presentationSnapshot !== void 0 && {
|
|
@@ -651,17 +747,30 @@ ${prompt}`);
|
|
|
651
747
|
);
|
|
652
748
|
}
|
|
653
749
|
this.logger.debug("Resolving blob references in message history before formatting");
|
|
750
|
+
const retainedMediaMessageIndexes = /* @__PURE__ */ new Set();
|
|
751
|
+
let retainedMediaMessages = 0;
|
|
752
|
+
for (let index = messageHistory.length - 1; index >= 0; index--) {
|
|
753
|
+
if (retainedMediaMessages >= ContextManager.PROMPT_MEDIA_RETENTION_MESSAGES) {
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
if (ContextManager.hasRetainableMedia(messageHistory[index])) {
|
|
757
|
+
retainedMediaMessageIndexes.add(index);
|
|
758
|
+
retainedMediaMessages += 1;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
654
761
|
messageHistory = await Promise.all(
|
|
655
|
-
messageHistory.map(async (message) => {
|
|
762
|
+
messageHistory.map(async (message, index) => {
|
|
656
763
|
if (isSystemMessage(message) || isAssistantMessage(message)) {
|
|
657
764
|
return message;
|
|
658
765
|
}
|
|
766
|
+
const expandMatchingMedia = retainedMediaMessageIndexes.has(index);
|
|
659
767
|
if (isUserMessage(message)) {
|
|
660
768
|
const expandedContent = await expandBlobReferences(
|
|
661
769
|
message.content,
|
|
662
770
|
this.resourceManager,
|
|
663
771
|
this.logger,
|
|
664
|
-
allowedMediaTypes
|
|
772
|
+
allowedMediaTypes,
|
|
773
|
+
expandMatchingMedia
|
|
665
774
|
);
|
|
666
775
|
return { ...message, content: expandedContent };
|
|
667
776
|
}
|
|
@@ -670,7 +779,8 @@ ${prompt}`);
|
|
|
670
779
|
message.content,
|
|
671
780
|
this.resourceManager,
|
|
672
781
|
this.logger,
|
|
673
|
-
allowedMediaTypes
|
|
782
|
+
allowedMediaTypes,
|
|
783
|
+
expandMatchingMedia
|
|
674
784
|
);
|
|
675
785
|
return { ...message, content: expandedContent };
|
|
676
786
|
}
|
package/dist/context/types.cjs
CHANGED
|
@@ -21,6 +21,7 @@ __export(types_exports, {
|
|
|
21
21
|
isAssistantMessage: () => isAssistantMessage,
|
|
22
22
|
isFilePart: () => isFilePart,
|
|
23
23
|
isImagePart: () => isImagePart,
|
|
24
|
+
isResourcePart: () => isResourcePart,
|
|
24
25
|
isSystemMessage: () => isSystemMessage,
|
|
25
26
|
isTextPart: () => isTextPart,
|
|
26
27
|
isToolMessage: () => isToolMessage,
|
|
@@ -37,6 +38,9 @@ function isImagePart(part) {
|
|
|
37
38
|
function isFilePart(part) {
|
|
38
39
|
return part.type === "file";
|
|
39
40
|
}
|
|
41
|
+
function isResourcePart(part) {
|
|
42
|
+
return part.type === "resource";
|
|
43
|
+
}
|
|
40
44
|
function isUIResourcePart(part) {
|
|
41
45
|
return part.type === "ui-resource";
|
|
42
46
|
}
|
|
@@ -57,6 +61,7 @@ function isToolMessage(msg) {
|
|
|
57
61
|
isAssistantMessage,
|
|
58
62
|
isFilePart,
|
|
59
63
|
isImagePart,
|
|
64
|
+
isResourcePart,
|
|
60
65
|
isSystemMessage,
|
|
61
66
|
isTextPart,
|
|
62
67
|
isToolMessage,
|
package/dist/context/types.d.ts
CHANGED
|
@@ -37,6 +37,22 @@ export interface ImagePart extends ImageData {
|
|
|
37
37
|
export interface FilePart extends FileData {
|
|
38
38
|
type: 'file';
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Canonical resource reference part.
|
|
42
|
+
* Persists stable identity for local files, blobs, and other resource-backed assets.
|
|
43
|
+
*/
|
|
44
|
+
export interface ResourcePart {
|
|
45
|
+
type: 'resource';
|
|
46
|
+
uri: string;
|
|
47
|
+
name: string;
|
|
48
|
+
mimeType: string;
|
|
49
|
+
kind: 'text' | 'image' | 'audio' | 'video' | 'binary';
|
|
50
|
+
size?: number;
|
|
51
|
+
metadata?: {
|
|
52
|
+
mtimeMs?: number;
|
|
53
|
+
source?: 'filesystem' | 'upload' | 'generated' | 'tool' | 'remote';
|
|
54
|
+
};
|
|
55
|
+
}
|
|
40
56
|
/**
|
|
41
57
|
* UI Resource content part for MCP-UI interactive components.
|
|
42
58
|
* Enables MCP servers to return rich, interactive UI (live streams, dashboards, forms).
|
|
@@ -67,7 +83,7 @@ export interface UIResourcePart {
|
|
|
67
83
|
* Union of all content part types.
|
|
68
84
|
* Discriminated by the `type` field.
|
|
69
85
|
*/
|
|
70
|
-
export type ContentPart = TextPart | ImagePart | FilePart | UIResourcePart;
|
|
86
|
+
export type ContentPart = TextPart | ImagePart | FilePart | ResourcePart | UIResourcePart;
|
|
71
87
|
/**
|
|
72
88
|
* Type guard for TextPart.
|
|
73
89
|
*/
|
|
@@ -80,6 +96,10 @@ export declare function isImagePart(part: ContentPart): part is ImagePart;
|
|
|
80
96
|
* Type guard for FilePart.
|
|
81
97
|
*/
|
|
82
98
|
export declare function isFilePart(part: ContentPart): part is FilePart;
|
|
99
|
+
/**
|
|
100
|
+
* Type guard for ResourcePart.
|
|
101
|
+
*/
|
|
102
|
+
export declare function isResourcePart(part: ContentPart): part is ResourcePart;
|
|
83
103
|
/**
|
|
84
104
|
* Type guard for UIResourcePart.
|
|
85
105
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/context/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAMpE;;;GAGG;AACH,MAAM,WAAW,SAAS;IACtB,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,GAAG,CAAC;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,GAAG,CAAC;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,SAAS;IACxC,IAAI,EAAE,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isImagePart(part) {
|
|
|
8
8
|
function isFilePart(part) {
|
|
9
9
|
return part.type === "file";
|
|
10
10
|
}
|
|
11
|
+
function isResourcePart(part) {
|
|
12
|
+
return part.type === "resource";
|
|
13
|
+
}
|
|
11
14
|
function isUIResourcePart(part) {
|
|
12
15
|
return part.type === "ui-resource";
|
|
13
16
|
}
|
|
@@ -27,6 +30,7 @@ export {
|
|
|
27
30
|
isAssistantMessage,
|
|
28
31
|
isFilePart,
|
|
29
32
|
isImagePart,
|
|
33
|
+
isResourcePart,
|
|
30
34
|
isSystemMessage,
|
|
31
35
|
isTextPart,
|
|
32
36
|
isToolMessage,
|
package/dist/context/utils.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(utils_exports, {
|
|
|
36
36
|
getImageData: () => getImageData,
|
|
37
37
|
getImageDataWithBlobSupport: () => getImageDataWithBlobSupport,
|
|
38
38
|
getResourceKind: () => import_media_helpers.getResourceKind,
|
|
39
|
+
isBinaryMediaMimeType: () => isBinaryMediaMimeType,
|
|
39
40
|
isLikelyBase64String: () => isLikelyBase64String,
|
|
40
41
|
matchesAnyMimePattern: () => matchesAnyMimePattern,
|
|
41
42
|
matchesMimePattern: () => matchesMimePattern,
|
|
@@ -129,10 +130,26 @@ function coerceContentToParts(content) {
|
|
|
129
130
|
cloned.filename = item.filename;
|
|
130
131
|
}
|
|
131
132
|
normalized.push(cloned);
|
|
133
|
+
} else if (item.type === "resource") {
|
|
134
|
+
continue;
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
return normalized;
|
|
135
138
|
}
|
|
139
|
+
function normalizeResourceUriForRead(uri) {
|
|
140
|
+
if (uri.startsWith("blob:") || uri.startsWith("mcp:") || uri.startsWith("fs://") || uri.startsWith("http://") || uri.startsWith("https://")) {
|
|
141
|
+
return uri;
|
|
142
|
+
}
|
|
143
|
+
if (uri.startsWith("/") || /^[A-Za-z]:[\\/]/.test(uri)) {
|
|
144
|
+
return `fs://${uri.replace(/\\/g, "/")}`;
|
|
145
|
+
}
|
|
146
|
+
return uri;
|
|
147
|
+
}
|
|
148
|
+
function buildResourceAnchorText(part) {
|
|
149
|
+
const label = part.kind === "image" ? "Attached image" : part.kind === "audio" ? "Attached audio" : part.kind === "video" ? "Attached video" : "Attached file";
|
|
150
|
+
const nameSuffix = part.name && part.name !== part.uri ? ` (${part.name})` : "";
|
|
151
|
+
return `${label}: ${part.uri}${nameSuffix}`;
|
|
152
|
+
}
|
|
136
153
|
function detectInlineMedia(part, index) {
|
|
137
154
|
if (part.type === "text") {
|
|
138
155
|
return null;
|
|
@@ -263,23 +280,23 @@ function buildToolBlobName(kind, mimeType, options, preferredName) {
|
|
|
263
280
|
const unique = generateUniqueSuffix();
|
|
264
281
|
return `${parts.join("-")}-${unique}.${ext}`;
|
|
265
282
|
}
|
|
266
|
-
async function resolveBlobReferenceToParts(resourceUri, resourceManager, logger, allowedMediaTypes) {
|
|
283
|
+
async function resolveBlobReferenceToParts(resourceUri, resourceManager, logger, allowedMediaTypes, expandMatchingMedia = true) {
|
|
267
284
|
try {
|
|
268
|
-
const result = await resourceManager.read(resourceUri);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const placeholder = generateMediaPlaceholder(placeholderMetadata);
|
|
281
|
-
return [{ type: "text", text: placeholder }];
|
|
285
|
+
const result = await resourceManager.read(normalizeResourceUriForRead(resourceUri));
|
|
286
|
+
const mimeType = result.contents[0]?.mimeType;
|
|
287
|
+
const metadata = result._meta;
|
|
288
|
+
const shouldPlaceholderForUnsupportedMedia = mimeType !== void 0 && allowedMediaTypes !== void 0 && !matchesAnyMimePattern(mimeType, allowedMediaTypes);
|
|
289
|
+
const shouldPlaceholderForRetainedHistoryMedia = mimeType !== void 0 && isBinaryMediaMimeType(mimeType) && !expandMatchingMedia;
|
|
290
|
+
if (mimeType && (shouldPlaceholderForUnsupportedMedia || shouldPlaceholderForRetainedHistoryMedia)) {
|
|
291
|
+
const placeholderMetadata = {
|
|
292
|
+
mimeType,
|
|
293
|
+
size: metadata?.size ?? 0
|
|
294
|
+
};
|
|
295
|
+
if (metadata?.originalName) {
|
|
296
|
+
placeholderMetadata.originalName = metadata.originalName;
|
|
282
297
|
}
|
|
298
|
+
const placeholder = generateMediaPlaceholder(placeholderMetadata);
|
|
299
|
+
return [{ type: "text", text: placeholder }];
|
|
283
300
|
}
|
|
284
301
|
const parts = [];
|
|
285
302
|
for (const item of result.contents ?? []) {
|
|
@@ -291,11 +308,11 @@ async function resolveBlobReferenceToParts(resourceUri, resourceManager, logger,
|
|
|
291
308
|
continue;
|
|
292
309
|
}
|
|
293
310
|
const base64Data = "blob" in item && typeof item.blob === "string" ? item.blob : "data" in item && typeof item.data === "string" ? item.data : void 0;
|
|
294
|
-
const
|
|
295
|
-
if (!base64Data || !
|
|
311
|
+
const mimeType2 = typeof item.mimeType === "string" ? item.mimeType : void 0;
|
|
312
|
+
if (!base64Data || !mimeType2) {
|
|
296
313
|
continue;
|
|
297
314
|
}
|
|
298
|
-
const resolvedMime =
|
|
315
|
+
const resolvedMime = mimeType2 ?? "application/octet-stream";
|
|
299
316
|
if (resolvedMime.startsWith("image/")) {
|
|
300
317
|
const imagePart = {
|
|
301
318
|
type: "image",
|
|
@@ -351,6 +368,9 @@ function estimateContentPartTokens(part) {
|
|
|
351
368
|
if (part.type === "file") {
|
|
352
369
|
return 1e3;
|
|
353
370
|
}
|
|
371
|
+
if (part.type === "resource") {
|
|
372
|
+
return part.kind === "text" ? 250 : 1e3;
|
|
373
|
+
}
|
|
354
374
|
return 0;
|
|
355
375
|
}
|
|
356
376
|
function estimateMessagesTokens(messages) {
|
|
@@ -457,11 +477,11 @@ async function getFileDataWithBlobSupport(filePart, resourceManager, logger) {
|
|
|
457
477
|
}
|
|
458
478
|
return getFileData(filePart, logger);
|
|
459
479
|
}
|
|
460
|
-
async function expandBlobsInText(text, resourceManager, logger, allowedMediaTypes) {
|
|
480
|
+
async function expandBlobsInText(text, resourceManager, logger, allowedMediaTypes, expandMatchingMedia = true) {
|
|
461
481
|
if (!text.includes("@blob:")) {
|
|
462
482
|
return [{ type: "text", text }];
|
|
463
483
|
}
|
|
464
|
-
const blobRefPattern = /@blob:[a-f0-9]+/g;
|
|
484
|
+
const blobRefPattern = /@blob:[a-f0-9-]+/g;
|
|
465
485
|
const matches = [...text.matchAll(blobRefPattern)];
|
|
466
486
|
if (matches.length === 0) {
|
|
467
487
|
return [{ type: "text", text }];
|
|
@@ -486,7 +506,8 @@ async function expandBlobsInText(text, resourceManager, logger, allowedMediaType
|
|
|
486
506
|
resourceUri,
|
|
487
507
|
resourceManager,
|
|
488
508
|
logger,
|
|
489
|
-
allowedMediaTypes
|
|
509
|
+
allowedMediaTypes,
|
|
510
|
+
expandMatchingMedia
|
|
490
511
|
);
|
|
491
512
|
resolvedCache.set(resourceUri, resolvedParts);
|
|
492
513
|
}
|
|
@@ -505,7 +526,7 @@ async function expandBlobsInText(text, resourceManager, logger, allowedMediaType
|
|
|
505
526
|
}
|
|
506
527
|
return parts.filter((p) => p.type !== "text" || p.text.length > 0);
|
|
507
528
|
}
|
|
508
|
-
async function expandBlobReferences(content, resourceManager, logger, allowedMediaTypes) {
|
|
529
|
+
async function expandBlobReferences(content, resourceManager, logger, allowedMediaTypes, expandMatchingMedia = true) {
|
|
509
530
|
if (content == null || !Array.isArray(content)) {
|
|
510
531
|
return [];
|
|
511
532
|
}
|
|
@@ -522,7 +543,8 @@ async function expandBlobReferences(content, resourceManager, logger, allowedMed
|
|
|
522
543
|
resourceUri,
|
|
523
544
|
resourceManager,
|
|
524
545
|
logger,
|
|
525
|
-
allowedMediaTypes
|
|
546
|
+
allowedMediaTypes,
|
|
547
|
+
expandMatchingMedia
|
|
526
548
|
);
|
|
527
549
|
if (resolved.length > 0) {
|
|
528
550
|
expandedParts.push(...resolved.map((p) => ({ ...p })));
|
|
@@ -538,7 +560,8 @@ async function expandBlobReferences(content, resourceManager, logger, allowedMed
|
|
|
538
560
|
resourceUri,
|
|
539
561
|
resourceManager,
|
|
540
562
|
logger,
|
|
541
|
-
allowedMediaTypes
|
|
563
|
+
allowedMediaTypes,
|
|
564
|
+
expandMatchingMedia
|
|
542
565
|
);
|
|
543
566
|
if (resolved.length > 0) {
|
|
544
567
|
expandedParts.push(...resolved.map((p) => ({ ...p })));
|
|
@@ -557,12 +580,27 @@ async function expandBlobReferences(content, resourceManager, logger, allowedMed
|
|
|
557
580
|
}
|
|
558
581
|
continue;
|
|
559
582
|
}
|
|
583
|
+
if (part.type === "resource") {
|
|
584
|
+
const resolved = await resolveBlobReferenceToParts(
|
|
585
|
+
part.uri,
|
|
586
|
+
resourceManager,
|
|
587
|
+
logger,
|
|
588
|
+
allowedMediaTypes,
|
|
589
|
+
expandMatchingMedia
|
|
590
|
+
);
|
|
591
|
+
expandedParts.push({ type: "text", text: buildResourceAnchorText(part) });
|
|
592
|
+
if (resolved.length > 0) {
|
|
593
|
+
expandedParts.push(...resolved.map((p) => ({ ...p })));
|
|
594
|
+
}
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
560
597
|
if (part.type === "text" && part.text.includes("@blob:")) {
|
|
561
598
|
const expanded = await expandBlobsInText(
|
|
562
599
|
part.text,
|
|
563
600
|
resourceManager,
|
|
564
601
|
logger,
|
|
565
|
-
allowedMediaTypes
|
|
602
|
+
allowedMediaTypes,
|
|
603
|
+
expandMatchingMedia
|
|
566
604
|
);
|
|
567
605
|
expandedParts.push(...expanded);
|
|
568
606
|
continue;
|
|
@@ -635,6 +673,9 @@ function filterMessagesByLLMCapabilities(messages, config, logger) {
|
|
|
635
673
|
);
|
|
636
674
|
return [part];
|
|
637
675
|
}
|
|
676
|
+
if (part.type === "resource") {
|
|
677
|
+
return [part];
|
|
678
|
+
}
|
|
638
679
|
return [part];
|
|
639
680
|
}
|
|
640
681
|
);
|
|
@@ -721,12 +762,30 @@ function fileTypesToMimePatterns(fileTypes, logger) {
|
|
|
721
762
|
case "video":
|
|
722
763
|
patterns.push("video/*");
|
|
723
764
|
break;
|
|
765
|
+
case "document":
|
|
766
|
+
patterns.push(
|
|
767
|
+
"text/*",
|
|
768
|
+
"application/json",
|
|
769
|
+
"application/xml",
|
|
770
|
+
"application/msword",
|
|
771
|
+
"application/rtf",
|
|
772
|
+
"application/vnd.oasis.opendocument.text",
|
|
773
|
+
"application/vnd.ms-powerpoint",
|
|
774
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
775
|
+
"application/vnd.ms-excel",
|
|
776
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
777
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
778
|
+
);
|
|
779
|
+
break;
|
|
724
780
|
default:
|
|
725
781
|
logger.warn(`Unknown file type in registry: ${fileType}`);
|
|
726
782
|
}
|
|
727
783
|
}
|
|
728
784
|
return patterns;
|
|
729
785
|
}
|
|
786
|
+
function isBinaryMediaMimeType(mimeType) {
|
|
787
|
+
return mimeType.startsWith("image/") || mimeType.startsWith("audio/") || mimeType.startsWith("video/") || mimeType === "application/pdf";
|
|
788
|
+
}
|
|
730
789
|
function generateMediaPlaceholder(metadata) {
|
|
731
790
|
let typeLabel = "File";
|
|
732
791
|
if (metadata.mimeType.startsWith("video/")) typeLabel = "Video";
|
|
@@ -1385,6 +1444,7 @@ function formatToolOutputForDisplay(message) {
|
|
|
1385
1444
|
getImageData,
|
|
1386
1445
|
getImageDataWithBlobSupport,
|
|
1387
1446
|
getResourceKind,
|
|
1447
|
+
isBinaryMediaMimeType,
|
|
1388
1448
|
isLikelyBase64String,
|
|
1389
1449
|
matchesAnyMimePattern,
|
|
1390
1450
|
matchesMimePattern,
|
package/dist/context/utils.d.ts
CHANGED
|
@@ -153,6 +153,7 @@ export declare function getFileDataWithBlobSupport(filePart: {
|
|
|
153
153
|
* Resolves blob references in message content to actual data.
|
|
154
154
|
* Expands @blob:id references to their actual base64 content for LLM consumption.
|
|
155
155
|
* Can optionally filter by MIME type patterns - unsupported types are replaced with descriptive placeholders.
|
|
156
|
+
* Older binary media can also be demoted to placeholders while preserving text/blob expansion.
|
|
156
157
|
*
|
|
157
158
|
* @param content The message content that may contain blob references
|
|
158
159
|
* @param resourceManager Resource manager for resolving blob references
|
|
@@ -161,9 +162,9 @@ export declare function getFileDataWithBlobSupport(filePart: {
|
|
|
161
162
|
* If omitted, all blobs are expanded (legacy behavior).
|
|
162
163
|
* @returns Promise<Resolved content with blob references expanded or replaced with placeholders>
|
|
163
164
|
*/
|
|
164
|
-
export declare function expandBlobReferences(content: null, resourceManager: import('../resources/index.js').ResourceManager, logger: Logger, allowedMediaTypes?: string[]): Promise<ContentPart[]>;
|
|
165
|
-
export declare function expandBlobReferences(content: ContentPart[], resourceManager: import('../resources/index.js').ResourceManager, logger: Logger, allowedMediaTypes?: string[]): Promise<ContentPart[]>;
|
|
166
|
-
export declare function expandBlobReferences(content: ContentPart[] | null, resourceManager: import('../resources/index.js').ResourceManager, logger: Logger, allowedMediaTypes?: string[]): Promise<ContentPart[]>;
|
|
165
|
+
export declare function expandBlobReferences(content: null, resourceManager: import('../resources/index.js').ResourceManager, logger: Logger, allowedMediaTypes?: string[], expandMatchingMedia?: boolean): Promise<ContentPart[]>;
|
|
166
|
+
export declare function expandBlobReferences(content: ContentPart[], resourceManager: import('../resources/index.js').ResourceManager, logger: Logger, allowedMediaTypes?: string[], expandMatchingMedia?: boolean): Promise<ContentPart[]>;
|
|
167
|
+
export declare function expandBlobReferences(content: ContentPart[] | null, resourceManager: import('../resources/index.js').ResourceManager, logger: Logger, allowedMediaTypes?: string[], expandMatchingMedia?: boolean): Promise<ContentPart[]>;
|
|
167
168
|
/**
|
|
168
169
|
* Filters message content based on LLM capabilities.
|
|
169
170
|
* Removes unsupported file attachments while preserving supported content.
|
|
@@ -214,6 +215,7 @@ export declare function matchesAnyMimePattern(mimeType: string | undefined, patt
|
|
|
214
215
|
* @returns Array of MIME type patterns (e.g., ['image/*', 'application/pdf', 'audio/*'])
|
|
215
216
|
*/
|
|
216
217
|
export declare function fileTypesToMimePatterns(fileTypes: string[], logger: Logger): string[];
|
|
218
|
+
export declare function isBinaryMediaMimeType(mimeType: string): boolean;
|
|
217
219
|
export declare function normalizeToolResult(result: unknown, logger: Logger): Promise<NormalizedToolResult>;
|
|
218
220
|
export declare function persistToolMedia(normalized: NormalizedToolResult, options: PersistToolMediaOptions, logger: Logger): Promise<PersistToolMediaResult>;
|
|
219
221
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/context/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,QAAQ,EACR,SAAS,EACT,QAAQ,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/context/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EACf,QAAQ,EACR,SAAS,EACT,QAAQ,EAER,cAAc,EACd,WAAW,EACX,mBAAmB,EAEtB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAMvE,KAAK,qBAAqB,GAAG;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAIF,KAAK,eAAe,GAAG,OAAO,GAAG,MAAM,CAAC;AAExC,KAAK,eAAe,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,QAAQ,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