@dexto/core 1.18.1 → 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/agent/DextoAgent.cjs +12 -6
- package/dist/agent/DextoAgent.d.ts +2 -2
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +17 -7
- package/dist/approval/manager.cjs +7 -7
- package/dist/approval/manager.d.ts +5 -5
- package/dist/approval/manager.js +7 -7
- package/dist/approval/types.d.ts +1 -1
- package/dist/context/manager.cjs +21 -1
- package/dist/context/manager.d.ts +8 -0
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +21 -1
- package/dist/context/types.d.ts +10 -0
- package/dist/context/types.d.ts.map +1 -1
- package/dist/index.browser.cjs +8 -0
- package/dist/index.browser.d.ts +2 -2
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +8 -0
- package/dist/llm/executor/turn-executor.cjs +18 -1
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +18 -1
- package/dist/llm/executor/withheld-media.cjs +83 -0
- package/dist/llm/executor/withheld-media.d.ts +12 -0
- package/dist/llm/executor/withheld-media.d.ts.map +1 -0
- package/dist/llm/executor/withheld-media.js +59 -0
- package/dist/llm/formatters/provider-file-support.cjs +88 -0
- package/dist/llm/formatters/provider-file-support.d.ts +12 -0
- package/dist/llm/formatters/provider-file-support.d.ts.map +1 -0
- package/dist/llm/formatters/provider-file-support.js +64 -0
- package/dist/llm/formatters/vercel.cjs +21 -2
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +21 -2
- package/dist/tools/approval/tool-approval-policy.cjs +2 -2
- package/dist/tools/approval/tool-approval-policy.d.ts +3 -2
- package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -1
- package/dist/tools/approval/tool-approval-policy.js +2 -2
- package/dist/tools/schemas.cjs +38 -6
- package/dist/tools/schemas.d.ts +27 -3
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +33 -5
- package/dist/tools/tool-call-metadata.cjs +2 -3
- package/dist/tools/tool-call-metadata.d.ts.map +1 -1
- package/dist/tools/tool-call-metadata.js +2 -3
- package/dist/tools/tool-manager.cjs +2 -2
- package/dist/tools/tool-manager.d.ts +2 -2
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +2 -2
- package/dist/utils/schema.cjs +8 -1
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +8 -1
- package/dist/utils/service-initializer.d.ts +2 -2
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -46,6 +46,7 @@ var import_provider_options = require("./provider-options.js");
|
|
|
46
46
|
var import_types = require("../../logger/v2/types.js");
|
|
47
47
|
var import_operation_span = require("../../telemetry/operation-span.js");
|
|
48
48
|
var import_provider_error = require("./provider-error.js");
|
|
49
|
+
var import_withheld_media = require("./withheld-media.js");
|
|
49
50
|
var import_empty_response = require("./empty-response.js");
|
|
50
51
|
var import_errors = require("../errors.js");
|
|
51
52
|
var import_error_codes = require("../error-codes.js");
|
|
@@ -1353,14 +1354,25 @@ class TurnExecutor {
|
|
|
1353
1354
|
async runModelStepWithRetry(request) {
|
|
1354
1355
|
let failedAttempts = 0;
|
|
1355
1356
|
let emptyResponseRetries = 0;
|
|
1357
|
+
let attemptRequest = request;
|
|
1358
|
+
let media = "sent";
|
|
1356
1359
|
for (; ; ) {
|
|
1357
1360
|
const historyLengthBefore = await this.contextManager.countModelMessages();
|
|
1358
1361
|
let result;
|
|
1359
1362
|
try {
|
|
1360
|
-
result = await this.runModelStep(
|
|
1363
|
+
result = await this.runModelStep(attemptRequest);
|
|
1361
1364
|
} catch (error) {
|
|
1362
1365
|
const historyLengthAfter2 = await this.contextManager.countModelMessages();
|
|
1363
1366
|
const historyLengthChanged = historyLengthAfter2 !== historyLengthBefore;
|
|
1367
|
+
const withoutMedia = media === "sent" && !historyLengthChanged && !this.stepAbortController.signal.aborted && (0, import_withheld_media.isRejectedModelRequest)(error) ? (0, import_withheld_media.withholdRequestMedia)(attemptRequest.messages) : null;
|
|
1368
|
+
if (withoutMedia !== null) {
|
|
1369
|
+
media = "retried";
|
|
1370
|
+
attemptRequest = { ...attemptRequest, messages: withoutMedia };
|
|
1371
|
+
this.logger.warn("Retrying a rejected model request without its media", {
|
|
1372
|
+
error: this.mapProviderError(error)
|
|
1373
|
+
});
|
|
1374
|
+
continue;
|
|
1375
|
+
}
|
|
1364
1376
|
if (!this.canRetryModelRequest(error, historyLengthChanged) || failedAttempts >= MODEL_REQUEST_MAX_RETRIES) {
|
|
1365
1377
|
throw error;
|
|
1366
1378
|
}
|
|
@@ -1382,6 +1394,11 @@ class TurnExecutor {
|
|
|
1382
1394
|
});
|
|
1383
1395
|
continue;
|
|
1384
1396
|
}
|
|
1397
|
+
if (media === "retried" && result.finishReason !== "cancelled") {
|
|
1398
|
+
media = "withheld";
|
|
1399
|
+
const withheldCount = await this.contextManager.withholdModelMedia();
|
|
1400
|
+
this.logger.warn("Withheld media the model provider rejected", { withheldCount });
|
|
1401
|
+
}
|
|
1385
1402
|
if (!(0, import_empty_response.isEmptyModelResponse)(result)) {
|
|
1386
1403
|
return result;
|
|
1387
1404
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-executor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/turn-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAMb,KAAK,YAAY,EAEpB,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAa,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAY1D,OAAO,EACH,WAAW,EAId,MAAM,6BAA6B,CAAC;AACrC,O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CAAC,6BAA6B;IAgBrC;;;;;;;;;;;;OAYG;YACW,mBAAmB;IA2DjC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;;OAGG;IACH,OAAO,CAAC,OAAO;IASf;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAO/B;;;;;;;;;;;;OAYG;YACW,cAAc;IA2F5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoB9B,OAAO,CAAC,qBAAqB;IAK7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAQ3B"}
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
isRejectedCredential,
|
|
28
28
|
mapProviderError as mapCoreProviderError
|
|
29
29
|
} from "./provider-error.js";
|
|
30
|
+
import { isRejectedModelRequest, withholdRequestMedia } from "./withheld-media.js";
|
|
30
31
|
import { isEmptyModelResponse } from "./empty-response.js";
|
|
31
32
|
import { LLMError } from "../errors.js";
|
|
32
33
|
import { LLMErrorCode } from "../error-codes.js";
|
|
@@ -1340,14 +1341,25 @@ class TurnExecutor {
|
|
|
1340
1341
|
async runModelStepWithRetry(request) {
|
|
1341
1342
|
let failedAttempts = 0;
|
|
1342
1343
|
let emptyResponseRetries = 0;
|
|
1344
|
+
let attemptRequest = request;
|
|
1345
|
+
let media = "sent";
|
|
1343
1346
|
for (; ; ) {
|
|
1344
1347
|
const historyLengthBefore = await this.contextManager.countModelMessages();
|
|
1345
1348
|
let result;
|
|
1346
1349
|
try {
|
|
1347
|
-
result = await this.runModelStep(
|
|
1350
|
+
result = await this.runModelStep(attemptRequest);
|
|
1348
1351
|
} catch (error) {
|
|
1349
1352
|
const historyLengthAfter2 = await this.contextManager.countModelMessages();
|
|
1350
1353
|
const historyLengthChanged = historyLengthAfter2 !== historyLengthBefore;
|
|
1354
|
+
const withoutMedia = media === "sent" && !historyLengthChanged && !this.stepAbortController.signal.aborted && isRejectedModelRequest(error) ? withholdRequestMedia(attemptRequest.messages) : null;
|
|
1355
|
+
if (withoutMedia !== null) {
|
|
1356
|
+
media = "retried";
|
|
1357
|
+
attemptRequest = { ...attemptRequest, messages: withoutMedia };
|
|
1358
|
+
this.logger.warn("Retrying a rejected model request without its media", {
|
|
1359
|
+
error: this.mapProviderError(error)
|
|
1360
|
+
});
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1351
1363
|
if (!this.canRetryModelRequest(error, historyLengthChanged) || failedAttempts >= MODEL_REQUEST_MAX_RETRIES) {
|
|
1352
1364
|
throw error;
|
|
1353
1365
|
}
|
|
@@ -1369,6 +1381,11 @@ class TurnExecutor {
|
|
|
1369
1381
|
});
|
|
1370
1382
|
continue;
|
|
1371
1383
|
}
|
|
1384
|
+
if (media === "retried" && result.finishReason !== "cancelled") {
|
|
1385
|
+
media = "withheld";
|
|
1386
|
+
const withheldCount = await this.contextManager.withholdModelMedia();
|
|
1387
|
+
this.logger.warn("Withheld media the model provider rejected", { withheldCount });
|
|
1388
|
+
}
|
|
1372
1389
|
if (!isEmptyModelResponse(result)) {
|
|
1373
1390
|
return result;
|
|
1374
1391
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var withheld_media_exports = {};
|
|
20
|
+
__export(withheld_media_exports, {
|
|
21
|
+
isRejectedModelRequest: () => isRejectedModelRequest,
|
|
22
|
+
withholdRequestMedia: () => withholdRequestMedia
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(withheld_media_exports);
|
|
25
|
+
var import_ai = require("ai");
|
|
26
|
+
function isRejectedModelRequest(error) {
|
|
27
|
+
return import_ai.APICallError.isInstance(error) && error.statusCode === 400;
|
|
28
|
+
}
|
|
29
|
+
function withheldMediaText(label) {
|
|
30
|
+
return `[${label} withheld: the model provider rejected the request that carried it]`;
|
|
31
|
+
}
|
|
32
|
+
function mediaLabel(mediaType) {
|
|
33
|
+
return mediaType.startsWith("image/") ? "Image" : "File";
|
|
34
|
+
}
|
|
35
|
+
function withholdRequestMedia(messages) {
|
|
36
|
+
let withheld = false;
|
|
37
|
+
const result = messages.map((message) => {
|
|
38
|
+
if (message.role === "user" && Array.isArray(message.content)) {
|
|
39
|
+
return {
|
|
40
|
+
...message,
|
|
41
|
+
content: message.content.map((part) => {
|
|
42
|
+
if (part.type === "text") return part;
|
|
43
|
+
withheld = true;
|
|
44
|
+
return {
|
|
45
|
+
type: "text",
|
|
46
|
+
text: withheldMediaText(
|
|
47
|
+
part.type === "image" ? "Image" : mediaLabel(part.mediaType)
|
|
48
|
+
)
|
|
49
|
+
};
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (message.role === "tool") {
|
|
54
|
+
return {
|
|
55
|
+
...message,
|
|
56
|
+
content: message.content.map((part) => {
|
|
57
|
+
if (part.output.type !== "content") return part;
|
|
58
|
+
return {
|
|
59
|
+
...part,
|
|
60
|
+
output: {
|
|
61
|
+
type: "content",
|
|
62
|
+
value: part.output.value.map((item) => {
|
|
63
|
+
if (item.type === "text") return item;
|
|
64
|
+
withheld = true;
|
|
65
|
+
return {
|
|
66
|
+
type: "text",
|
|
67
|
+
text: withheldMediaText(mediaLabel(item.mediaType))
|
|
68
|
+
};
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return message;
|
|
76
|
+
});
|
|
77
|
+
return withheld ? result : null;
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
isRejectedModelRequest,
|
|
82
|
+
withholdRequestMedia
|
|
83
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ModelMessage } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Whether the provider refused the request itself (HTTP 400). A refusal like this is caused by
|
|
4
|
+
* what the request carries, so sending the same history again fails the same way.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isRejectedModelRequest(error: unknown): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* The request's messages with every user and tool-result image or file replaced by a text
|
|
9
|
+
* placeholder, or null when no message carries media.
|
|
10
|
+
*/
|
|
11
|
+
export declare function withholdRequestMedia(messages: ModelMessage[]): ModelMessage[] | null;
|
|
12
|
+
//# sourceMappingURL=withheld-media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withheld-media.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/withheld-media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAuB,MAAM,IAAI,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE9D;AAUD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,GAAG,IAAI,CA2CpF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import "../../chunk-C6A6W6XS.js";
|
|
2
|
+
import { APICallError } from "ai";
|
|
3
|
+
function isRejectedModelRequest(error) {
|
|
4
|
+
return APICallError.isInstance(error) && error.statusCode === 400;
|
|
5
|
+
}
|
|
6
|
+
function withheldMediaText(label) {
|
|
7
|
+
return `[${label} withheld: the model provider rejected the request that carried it]`;
|
|
8
|
+
}
|
|
9
|
+
function mediaLabel(mediaType) {
|
|
10
|
+
return mediaType.startsWith("image/") ? "Image" : "File";
|
|
11
|
+
}
|
|
12
|
+
function withholdRequestMedia(messages) {
|
|
13
|
+
let withheld = false;
|
|
14
|
+
const result = messages.map((message) => {
|
|
15
|
+
if (message.role === "user" && Array.isArray(message.content)) {
|
|
16
|
+
return {
|
|
17
|
+
...message,
|
|
18
|
+
content: message.content.map((part) => {
|
|
19
|
+
if (part.type === "text") return part;
|
|
20
|
+
withheld = true;
|
|
21
|
+
return {
|
|
22
|
+
type: "text",
|
|
23
|
+
text: withheldMediaText(
|
|
24
|
+
part.type === "image" ? "Image" : mediaLabel(part.mediaType)
|
|
25
|
+
)
|
|
26
|
+
};
|
|
27
|
+
})
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (message.role === "tool") {
|
|
31
|
+
return {
|
|
32
|
+
...message,
|
|
33
|
+
content: message.content.map((part) => {
|
|
34
|
+
if (part.output.type !== "content") return part;
|
|
35
|
+
return {
|
|
36
|
+
...part,
|
|
37
|
+
output: {
|
|
38
|
+
type: "content",
|
|
39
|
+
value: part.output.value.map((item) => {
|
|
40
|
+
if (item.type === "text") return item;
|
|
41
|
+
withheld = true;
|
|
42
|
+
return {
|
|
43
|
+
type: "text",
|
|
44
|
+
text: withheldMediaText(mediaLabel(item.mediaType))
|
|
45
|
+
};
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
})
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return message;
|
|
53
|
+
});
|
|
54
|
+
return withheld ? result : null;
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
isRejectedModelRequest,
|
|
58
|
+
withholdRequestMedia
|
|
59
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var provider_file_support_exports = {};
|
|
20
|
+
__export(provider_file_support_exports, {
|
|
21
|
+
buildUnsendableFileNote: () => buildUnsendableFileNote,
|
|
22
|
+
isFileMediaTypeSendable: () => isFileMediaTypeSendable
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(provider_file_support_exports);
|
|
25
|
+
var import_utils = require("../../context/utils.js");
|
|
26
|
+
const IMAGE = "image/*";
|
|
27
|
+
const PDF = "application/pdf";
|
|
28
|
+
const OPENAI_CHAT_MEDIA_TYPES = [IMAGE, PDF, "audio/wav", "audio/mpeg", "audio/mp3"];
|
|
29
|
+
const ANTHROPIC_MEDIA_TYPES = [IMAGE, PDF];
|
|
30
|
+
const BEDROCK_MEDIA_TYPES = [
|
|
31
|
+
IMAGE,
|
|
32
|
+
PDF,
|
|
33
|
+
"text/csv",
|
|
34
|
+
"application/msword",
|
|
35
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
36
|
+
"application/vnd.ms-excel",
|
|
37
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
38
|
+
"text/html",
|
|
39
|
+
"text/plain",
|
|
40
|
+
"text/markdown"
|
|
41
|
+
];
|
|
42
|
+
function getAdapterMediaTypes(context) {
|
|
43
|
+
switch (context.provider) {
|
|
44
|
+
// OpenAI Responses API adapter
|
|
45
|
+
case "openai":
|
|
46
|
+
return [IMAGE, PDF];
|
|
47
|
+
// OpenAI Chat Completions adapter
|
|
48
|
+
case "minimax":
|
|
49
|
+
case "glm":
|
|
50
|
+
case "litellm":
|
|
51
|
+
case "glama":
|
|
52
|
+
case "ollama":
|
|
53
|
+
return OPENAI_CHAT_MEDIA_TYPES;
|
|
54
|
+
case "openai-compatible":
|
|
55
|
+
case "groq":
|
|
56
|
+
case "xai":
|
|
57
|
+
return [IMAGE];
|
|
58
|
+
case "cohere":
|
|
59
|
+
return [IMAGE, "text/*", "application/json"];
|
|
60
|
+
// OpenRouter forwards anything that is not an image or audio as a PDF-style file
|
|
61
|
+
case "openrouter":
|
|
62
|
+
case "dexto-nova":
|
|
63
|
+
return [IMAGE, "audio/*", PDF];
|
|
64
|
+
case "anthropic":
|
|
65
|
+
return ANTHROPIC_MEDIA_TYPES;
|
|
66
|
+
case "vertex":
|
|
67
|
+
return context.model.includes("claude") ? ANTHROPIC_MEDIA_TYPES : null;
|
|
68
|
+
case "bedrock":
|
|
69
|
+
return BEDROCK_MEDIA_TYPES;
|
|
70
|
+
default:
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function isFileMediaTypeSendable(context, mediaType) {
|
|
75
|
+
const allowed = getAdapterMediaTypes(context);
|
|
76
|
+
if (allowed === null) return true;
|
|
77
|
+
const baseMediaType = mediaType.split(";", 1)[0]?.trim() ?? mediaType;
|
|
78
|
+
return (0, import_utils.matchesAnyMimePattern)(baseMediaType, allowed);
|
|
79
|
+
}
|
|
80
|
+
function buildUnsendableFileNote(file) {
|
|
81
|
+
const name = file.filename ? `"${file.filename}"` : "a file";
|
|
82
|
+
return `[Attached ${name} (${file.mimeType}) was not sent to the model because this provider cannot read that file type directly. Use the available tools to read it, or tell the user.]`;
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
buildUnsendableFileNote,
|
|
87
|
+
isFileMediaTypeSendable
|
|
88
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LLMContext } from '@dexto/llm';
|
|
2
|
+
/** Whether the provider's AI SDK adapter can serialize a file part with this media type. */
|
|
3
|
+
export declare function isFileMediaTypeSendable(context: LLMContext, mediaType: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Text that stands in for a file the provider cannot receive, so the model still learns the file
|
|
6
|
+
* exists and can read it with tools.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildUnsendableFileNote(file: {
|
|
9
|
+
filename?: string;
|
|
10
|
+
mimeType: string;
|
|
11
|
+
}): string;
|
|
12
|
+
//# sourceMappingURL=provider-file-support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-file-support.d.ts","sourceRoot":"","sources":["../../../src/llm/formatters/provider-file-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAiE7C,4FAA4F;AAC5F,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAMvF;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAG7F"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import "../../chunk-C6A6W6XS.js";
|
|
2
|
+
import { matchesAnyMimePattern } from "../../context/utils.js";
|
|
3
|
+
const IMAGE = "image/*";
|
|
4
|
+
const PDF = "application/pdf";
|
|
5
|
+
const OPENAI_CHAT_MEDIA_TYPES = [IMAGE, PDF, "audio/wav", "audio/mpeg", "audio/mp3"];
|
|
6
|
+
const ANTHROPIC_MEDIA_TYPES = [IMAGE, PDF];
|
|
7
|
+
const BEDROCK_MEDIA_TYPES = [
|
|
8
|
+
IMAGE,
|
|
9
|
+
PDF,
|
|
10
|
+
"text/csv",
|
|
11
|
+
"application/msword",
|
|
12
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
13
|
+
"application/vnd.ms-excel",
|
|
14
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
15
|
+
"text/html",
|
|
16
|
+
"text/plain",
|
|
17
|
+
"text/markdown"
|
|
18
|
+
];
|
|
19
|
+
function getAdapterMediaTypes(context) {
|
|
20
|
+
switch (context.provider) {
|
|
21
|
+
// OpenAI Responses API adapter
|
|
22
|
+
case "openai":
|
|
23
|
+
return [IMAGE, PDF];
|
|
24
|
+
// OpenAI Chat Completions adapter
|
|
25
|
+
case "minimax":
|
|
26
|
+
case "glm":
|
|
27
|
+
case "litellm":
|
|
28
|
+
case "glama":
|
|
29
|
+
case "ollama":
|
|
30
|
+
return OPENAI_CHAT_MEDIA_TYPES;
|
|
31
|
+
case "openai-compatible":
|
|
32
|
+
case "groq":
|
|
33
|
+
case "xai":
|
|
34
|
+
return [IMAGE];
|
|
35
|
+
case "cohere":
|
|
36
|
+
return [IMAGE, "text/*", "application/json"];
|
|
37
|
+
// OpenRouter forwards anything that is not an image or audio as a PDF-style file
|
|
38
|
+
case "openrouter":
|
|
39
|
+
case "dexto-nova":
|
|
40
|
+
return [IMAGE, "audio/*", PDF];
|
|
41
|
+
case "anthropic":
|
|
42
|
+
return ANTHROPIC_MEDIA_TYPES;
|
|
43
|
+
case "vertex":
|
|
44
|
+
return context.model.includes("claude") ? ANTHROPIC_MEDIA_TYPES : null;
|
|
45
|
+
case "bedrock":
|
|
46
|
+
return BEDROCK_MEDIA_TYPES;
|
|
47
|
+
default:
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function isFileMediaTypeSendable(context, mediaType) {
|
|
52
|
+
const allowed = getAdapterMediaTypes(context);
|
|
53
|
+
if (allowed === null) return true;
|
|
54
|
+
const baseMediaType = mediaType.split(";", 1)[0]?.trim() ?? mediaType;
|
|
55
|
+
return matchesAnyMimePattern(baseMediaType, allowed);
|
|
56
|
+
}
|
|
57
|
+
function buildUnsendableFileNote(file) {
|
|
58
|
+
const name = file.filename ? `"${file.filename}"` : "a file";
|
|
59
|
+
return `[Attached ${name} (${file.mimeType}) was not sent to the model because this provider cannot read that file type directly. Use the available tools to read it, or tell the user.]`;
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
buildUnsendableFileNote,
|
|
63
|
+
isFileMediaTypeSendable
|
|
64
|
+
};
|
|
@@ -25,6 +25,7 @@ var import_llm = require("@dexto/llm");
|
|
|
25
25
|
var import_types = require("../../context/types.js");
|
|
26
26
|
var import_utils = require("../../context/utils.js");
|
|
27
27
|
var import_types2 = require("../../logger/v2/types.js");
|
|
28
|
+
var import_provider_file_support = require("./provider-file-support.js");
|
|
28
29
|
function normalizeInterleavedToolHistory(history) {
|
|
29
30
|
const normalized = [];
|
|
30
31
|
for (let index = 0; index < history.length; ) {
|
|
@@ -247,6 +248,15 @@ class VercelMessageFormatter {
|
|
|
247
248
|
if (part.type === "file") {
|
|
248
249
|
const textPart = filePartToText(part);
|
|
249
250
|
if (textPart) return textPart;
|
|
251
|
+
if (!(0, import_provider_file_support.isFileMediaTypeSendable)(context, part.mimeType)) {
|
|
252
|
+
this.logger.warn(
|
|
253
|
+
`Replaced attachment "${part.filename ?? "unnamed"}" (${part.mimeType}) with a text note: ${context.provider} cannot receive that file type`
|
|
254
|
+
);
|
|
255
|
+
return {
|
|
256
|
+
type: "text",
|
|
257
|
+
text: (0, import_provider_file_support.buildUnsendableFileNote)(part)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
250
260
|
return {
|
|
251
261
|
type: "file",
|
|
252
262
|
data: toUrlIfString(part.data),
|
|
@@ -298,7 +308,7 @@ class VercelMessageFormatter {
|
|
|
298
308
|
break;
|
|
299
309
|
case "tool":
|
|
300
310
|
if (msg.toolCallId && pendingToolCalls.has(msg.toolCallId)) {
|
|
301
|
-
const toolResult = this.formatToolMessage(msg);
|
|
311
|
+
const toolResult = this.formatToolMessage(msg, context);
|
|
302
312
|
formatted.push(toolResult.message);
|
|
303
313
|
pendingRemoteToolMedia.push(...toolResult.remoteMedia);
|
|
304
314
|
pendingToolCalls.delete(msg.toolCallId);
|
|
@@ -400,7 +410,7 @@ class VercelMessageFormatter {
|
|
|
400
410
|
};
|
|
401
411
|
}
|
|
402
412
|
// Helper to format Tool result messages
|
|
403
|
-
formatToolMessage(msg) {
|
|
413
|
+
formatToolMessage(msg, context) {
|
|
404
414
|
let toolResultPart;
|
|
405
415
|
const remoteMedia = [];
|
|
406
416
|
if (Array.isArray(msg.content)) {
|
|
@@ -428,6 +438,15 @@ class VercelMessageFormatter {
|
|
|
428
438
|
};
|
|
429
439
|
}
|
|
430
440
|
if (part.type === "file") {
|
|
441
|
+
if (!(0, import_provider_file_support.isFileMediaTypeSendable)(context, part.mimeType)) {
|
|
442
|
+
this.logger.warn(
|
|
443
|
+
`Replaced tool attachment "${part.filename ?? "unnamed"}" (${part.mimeType}) with a text note: ${context.provider} cannot receive that file type`
|
|
444
|
+
);
|
|
445
|
+
return {
|
|
446
|
+
type: "text",
|
|
447
|
+
text: (0, import_provider_file_support.buildUnsendableFileNote)(part)
|
|
448
|
+
};
|
|
449
|
+
}
|
|
431
450
|
const data = (0, import_utils.getFileData)(part, this.logger);
|
|
432
451
|
if (/^https?:\/\//i.test(data)) {
|
|
433
452
|
remoteMedia.push({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../src/llm/formatters/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,IAAI,CAAC;AACzE,OAAO,EAA0B,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,KAAK,EACR,eAAe,EAIlB,MAAM,wBAAwB,CAAC;AAQhC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../src/llm/formatters/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,IAAI,CAAC;AACzE,OAAO,EAA0B,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,KAAK,EACR,eAAe,EAIlB,MAAM,wBAAwB,CAAC;AAQhC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAwLvD;;;;;;;;;;GAUG;AACH,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;gBAEhC,MAAM,EAAE,MAAM,EAAE,WAAW,GAAE,aAAsC;IAI/E;;;;;;OAMG;IACH,MAAM,CACF,OAAO,EAAE,QAAQ,CAAC,eAAe,EAAE,CAAC,EACpC,OAAO,EAAE,UAAU,EACnB,YAAY,EAAE,MAAM,GAAG,IAAI,GAC5B,YAAY,EAAE;IAsMjB;;;;;;OAMG;IACH,kBAAkB,IAAI,IAAI;IAI1B,OAAO,CAAC,wBAAwB;IAUhC,OAAO,CAAC,sBAAsB;IAmG9B,OAAO,CAAC,iBAAiB;CA+G5B"}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
parseDataUri
|
|
9
9
|
} from "../../context/utils.js";
|
|
10
10
|
import { DextoLogComponent } from "../../logger/v2/types.js";
|
|
11
|
+
import { buildUnsendableFileNote, isFileMediaTypeSendable } from "./provider-file-support.js";
|
|
11
12
|
function normalizeInterleavedToolHistory(history) {
|
|
12
13
|
const normalized = [];
|
|
13
14
|
for (let index = 0; index < history.length; ) {
|
|
@@ -230,6 +231,15 @@ class VercelMessageFormatter {
|
|
|
230
231
|
if (part.type === "file") {
|
|
231
232
|
const textPart = filePartToText(part);
|
|
232
233
|
if (textPart) return textPart;
|
|
234
|
+
if (!isFileMediaTypeSendable(context, part.mimeType)) {
|
|
235
|
+
this.logger.warn(
|
|
236
|
+
`Replaced attachment "${part.filename ?? "unnamed"}" (${part.mimeType}) with a text note: ${context.provider} cannot receive that file type`
|
|
237
|
+
);
|
|
238
|
+
return {
|
|
239
|
+
type: "text",
|
|
240
|
+
text: buildUnsendableFileNote(part)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
233
243
|
return {
|
|
234
244
|
type: "file",
|
|
235
245
|
data: toUrlIfString(part.data),
|
|
@@ -281,7 +291,7 @@ class VercelMessageFormatter {
|
|
|
281
291
|
break;
|
|
282
292
|
case "tool":
|
|
283
293
|
if (msg.toolCallId && pendingToolCalls.has(msg.toolCallId)) {
|
|
284
|
-
const toolResult = this.formatToolMessage(msg);
|
|
294
|
+
const toolResult = this.formatToolMessage(msg, context);
|
|
285
295
|
formatted.push(toolResult.message);
|
|
286
296
|
pendingRemoteToolMedia.push(...toolResult.remoteMedia);
|
|
287
297
|
pendingToolCalls.delete(msg.toolCallId);
|
|
@@ -383,7 +393,7 @@ class VercelMessageFormatter {
|
|
|
383
393
|
};
|
|
384
394
|
}
|
|
385
395
|
// Helper to format Tool result messages
|
|
386
|
-
formatToolMessage(msg) {
|
|
396
|
+
formatToolMessage(msg, context) {
|
|
387
397
|
let toolResultPart;
|
|
388
398
|
const remoteMedia = [];
|
|
389
399
|
if (Array.isArray(msg.content)) {
|
|
@@ -411,6 +421,15 @@ class VercelMessageFormatter {
|
|
|
411
421
|
};
|
|
412
422
|
}
|
|
413
423
|
if (part.type === "file") {
|
|
424
|
+
if (!isFileMediaTypeSendable(context, part.mimeType)) {
|
|
425
|
+
this.logger.warn(
|
|
426
|
+
`Replaced tool attachment "${part.filename ?? "unnamed"}" (${part.mimeType}) with a text note: ${context.provider} cannot receive that file type`
|
|
427
|
+
);
|
|
428
|
+
return {
|
|
429
|
+
type: "text",
|
|
430
|
+
text: buildUnsendableFileNote(part)
|
|
431
|
+
};
|
|
432
|
+
}
|
|
414
433
|
const data = getFileData(part, this.logger);
|
|
415
434
|
if (/^https?:\/\//i.test(data)) {
|
|
416
435
|
remoteMedia.push({
|
|
@@ -38,8 +38,8 @@ class ToolApprovalPolicy {
|
|
|
38
38
|
if (explicitAllow !== null) {
|
|
39
39
|
return { because: explicitAllow, kind: "ready" };
|
|
40
40
|
}
|
|
41
|
-
if (this.deps.getApprovalMode() === "
|
|
42
|
-
return { because: "
|
|
41
|
+
if (this.deps.getApprovalMode() === "full-access") {
|
|
42
|
+
return { because: "full-access-mode", kind: "ready" };
|
|
43
43
|
}
|
|
44
44
|
if (authored.kind === "allow") {
|
|
45
45
|
return { because: "tool-allows", kind: "ready" };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Tool, ToolExecutionContext, ToolIdentity } from '../types.js';
|
|
2
|
+
import type { PermissionsMode } from '../schemas.js';
|
|
2
3
|
/** Which check let a call run without asking: the first of the policy's checks that passed. */
|
|
3
|
-
export type ToolApprovalReadyReason = ExplicitToolAllow | '
|
|
4
|
+
export type ToolApprovalReadyReason = ExplicitToolAllow | 'full-access-mode' | 'tool-allows' | 'session-approved-key';
|
|
4
5
|
/** Where an explicit allow came from: the session's list, the static list, or the host's provider. */
|
|
5
6
|
export type ExplicitToolAllow = 'session-allowed' | 'always-allow' | 'allowed-tools';
|
|
6
7
|
export type ToolApprovalGate = {
|
|
@@ -21,7 +22,7 @@ export type ToolApprovalPolicyInput = {
|
|
|
21
22
|
toolName: string;
|
|
22
23
|
};
|
|
23
24
|
export type ToolApprovalPolicyDeps = {
|
|
24
|
-
getApprovalMode():
|
|
25
|
+
getApprovalMode(): PermissionsMode;
|
|
25
26
|
getLocalTool(toolName: string): Tool | undefined;
|
|
26
27
|
isApprovalKeySessionApproved(input: {
|
|
27
28
|
approvalKey: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-approval-policy.d.ts","sourceRoot":"","sources":["../../../src/tools/approval/tool-approval-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAwB,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-approval-policy.d.ts","sourceRoot":"","sources":["../../../src/tools/approval/tool-approval-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAwB,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAElG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,+FAA+F;AAC/F,MAAM,MAAM,uBAAuB,GAC7B,iBAAiB,GACjB,kBAAkB,GAClB,aAAa,GACb,sBAAsB,CAAC;AAE7B,sGAAsG;AACtG,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,cAAc,GAAG,eAAe,CAAC;AAErF,MAAM,MAAM,gBAAgB,GACtB;IACI,OAAO,EAAE,uBAAuB,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;CACjB,GACD;IACI,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,IAAI,EAAE,mBAAmB,CAAC;CAC7B,GACD;IACI,4FAA4F;IAC5F,IAAI,EAAE,YAAY,CAAC;CACtB,CAAC;AAiBR,MAAM,MAAM,uBAAuB,GAAG;IAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,QAAQ,EAAE,YAAY,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACjC,eAAe,IAAI,eAAe,CAAC;IACnC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACjD,4BAA4B,CAAC,KAAK,EAAE;QAChC,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAClC,GAAG,OAAO,CAAC;IACZ,qBAAqB,CAAC,KAAK,EAAE;QACzB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC/B,QAAQ,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,iBAAiB,GAAG,IAAI,CAAC;CACpE,CAAC;AAEF,qBAAa,kBAAkB;IACf,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,sBAAsB;IAEnD,OAAO,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC;YA2D1D,qBAAqB;IAmCnC,OAAO,CAAC,wBAAwB;CASnC"}
|
|
@@ -16,8 +16,8 @@ class ToolApprovalPolicy {
|
|
|
16
16
|
if (explicitAllow !== null) {
|
|
17
17
|
return { because: explicitAllow, kind: "ready" };
|
|
18
18
|
}
|
|
19
|
-
if (this.deps.getApprovalMode() === "
|
|
20
|
-
return { because: "
|
|
19
|
+
if (this.deps.getApprovalMode() === "full-access") {
|
|
20
|
+
return { because: "full-access-mode", kind: "ready" };
|
|
21
21
|
}
|
|
22
22
|
if (authored.kind === "allow") {
|
|
23
23
|
return { because: "tool-allows", kind: "ready" };
|