@dexto/core 1.18.0 → 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/provider-error.cjs +12 -3
- package/dist/llm/executor/provider-error.d.ts +9 -0
- package/dist/llm/executor/provider-error.d.ts.map +1 -1
- package/dist/llm/executor/provider-error.js +10 -3
- package/dist/llm/executor/turn-executor.cjs +19 -2
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +20 -2
- 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/llm/services/factory.cjs +2 -2
- package/dist/llm/services/factory.d.ts +1 -1
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +2 -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
|
@@ -18,7 +18,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var provider_error_exports = {};
|
|
20
20
|
__export(provider_error_exports, {
|
|
21
|
+
HostRetryableModelRequestError: () => HostRetryableModelRequestError,
|
|
21
22
|
extractProviderErrorDetails: () => extractProviderErrorDetails,
|
|
23
|
+
isRejectedCredential: () => isRejectedCredential,
|
|
22
24
|
mapProviderError: () => mapProviderError
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(provider_error_exports);
|
|
@@ -26,6 +28,11 @@ var import_ai = require("ai");
|
|
|
26
28
|
var import_DextoRuntimeError = require("../../errors/DextoRuntimeError.js");
|
|
27
29
|
var import_types = require("../../errors/types.js");
|
|
28
30
|
var import_error_codes = require("../error-codes.js");
|
|
31
|
+
class HostRetryableModelRequestError extends import_ai.APICallError {
|
|
32
|
+
}
|
|
33
|
+
function isRejectedCredential(error) {
|
|
34
|
+
return error.statusCode === 401 && !(error instanceof HostRetryableModelRequestError);
|
|
35
|
+
}
|
|
29
36
|
const INSUFFICIENT_CREDITS_BALANCE_PATTERN = /Insufficient credits\. Balance: \$(-?\d+(?:\.\d+)?)\./;
|
|
30
37
|
function isRecord(value) {
|
|
31
38
|
return typeof value === "object" && value !== null;
|
|
@@ -136,7 +143,6 @@ function errorTypeForStatus(status) {
|
|
|
136
143
|
function errorCodeForStatus(status, details) {
|
|
137
144
|
if (status === 402) return import_error_codes.LLMErrorCode.INSUFFICIENT_CREDITS;
|
|
138
145
|
if (status === 429) return import_error_codes.LLMErrorCode.RATE_LIMIT_EXCEEDED;
|
|
139
|
-
if (status === 401) return import_error_codes.LLMErrorCode.AUTH_FAILED;
|
|
140
146
|
if (status === 400 && (details.openRouterProviderRawCode === "invalid_function_parameters" || isInvalidSchemaMessage(providerMessage(details, "")))) {
|
|
141
147
|
return import_error_codes.LLMErrorCode.REQUEST_INVALID_SCHEMA;
|
|
142
148
|
}
|
|
@@ -217,7 +223,8 @@ function mapProviderError(input) {
|
|
|
217
223
|
const details = extractProviderErrorDetails(input);
|
|
218
224
|
const status = input.error.statusCode;
|
|
219
225
|
const message = providerMessage(details, input.error.message);
|
|
220
|
-
const
|
|
226
|
+
const rejectedCredential = isRejectedCredential(input.error);
|
|
227
|
+
const code = rejectedCredential ? import_error_codes.LLMErrorCode.AUTH_FAILED : errorCodeForStatus(status, details);
|
|
221
228
|
const type = errorTypeForStatus(status);
|
|
222
229
|
const retryDisposition = retryDispositionForProviderError(details);
|
|
223
230
|
if (status === 402) {
|
|
@@ -236,7 +243,7 @@ function mapProviderError(input) {
|
|
|
236
243
|
retryDisposition
|
|
237
244
|
);
|
|
238
245
|
}
|
|
239
|
-
if (
|
|
246
|
+
if (rejectedCredential) {
|
|
240
247
|
const dexto = input.provider === "dexto-nova";
|
|
241
248
|
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
242
249
|
code,
|
|
@@ -262,6 +269,8 @@ function mapProviderError(input) {
|
|
|
262
269
|
}
|
|
263
270
|
// Annotate the CommonJS export names for ESM import in node:
|
|
264
271
|
0 && (module.exports = {
|
|
272
|
+
HostRetryableModelRequestError,
|
|
265
273
|
extractProviderErrorDetails,
|
|
274
|
+
isRejectedCredential,
|
|
266
275
|
mapProviderError
|
|
267
276
|
});
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { APICallError } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* A failed model request that the host's request auth classified as retryable, such as a gateway
|
|
4
|
+
* credential that expired and that the host renews on the next attempt.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HostRetryableModelRequestError extends APICallError {
|
|
7
|
+
}
|
|
8
|
+
/** A 401 is final, unless the host owns the credential and said the next attempt can succeed. */
|
|
9
|
+
export declare function isRejectedCredential(error: APICallError): boolean;
|
|
1
10
|
export type LLMProviderErrorDetails = {
|
|
2
11
|
provider?: string;
|
|
3
12
|
model?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-error.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/provider-error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider-error.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/provider-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAiC,MAAM,IAAI,CAAC;AAMjE;;;GAGG;AACH,qBAAa,8BAA+B,SAAQ,YAAY;CAAG;AAEnE,iGAAiG;AACjG,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAEjE;AAKD,MAAM,MAAM,uBAAuB,GAAG;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,yBAAyB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5C,4BAA4B,CAAC,EAAE,MAAM,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mGAAmG;IACnG,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAmLF,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,qBAAqB,GAAG,uBAAuB,CA2BjG;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,KAAK,CAiGpE"}
|
|
@@ -3,6 +3,11 @@ import { APICallError, UnsupportedFunctionalityError } from "ai";
|
|
|
3
3
|
import { DextoRuntimeError } from "../../errors/DextoRuntimeError.js";
|
|
4
4
|
import { ErrorScope, ErrorType } from "../../errors/types.js";
|
|
5
5
|
import { LLMErrorCode } from "../error-codes.js";
|
|
6
|
+
class HostRetryableModelRequestError extends APICallError {
|
|
7
|
+
}
|
|
8
|
+
function isRejectedCredential(error) {
|
|
9
|
+
return error.statusCode === 401 && !(error instanceof HostRetryableModelRequestError);
|
|
10
|
+
}
|
|
6
11
|
const INSUFFICIENT_CREDITS_BALANCE_PATTERN = /Insufficient credits\. Balance: \$(-?\d+(?:\.\d+)?)\./;
|
|
7
12
|
function isRecord(value) {
|
|
8
13
|
return typeof value === "object" && value !== null;
|
|
@@ -113,7 +118,6 @@ function errorTypeForStatus(status) {
|
|
|
113
118
|
function errorCodeForStatus(status, details) {
|
|
114
119
|
if (status === 402) return LLMErrorCode.INSUFFICIENT_CREDITS;
|
|
115
120
|
if (status === 429) return LLMErrorCode.RATE_LIMIT_EXCEEDED;
|
|
116
|
-
if (status === 401) return LLMErrorCode.AUTH_FAILED;
|
|
117
121
|
if (status === 400 && (details.openRouterProviderRawCode === "invalid_function_parameters" || isInvalidSchemaMessage(providerMessage(details, "")))) {
|
|
118
122
|
return LLMErrorCode.REQUEST_INVALID_SCHEMA;
|
|
119
123
|
}
|
|
@@ -194,7 +198,8 @@ function mapProviderError(input) {
|
|
|
194
198
|
const details = extractProviderErrorDetails(input);
|
|
195
199
|
const status = input.error.statusCode;
|
|
196
200
|
const message = providerMessage(details, input.error.message);
|
|
197
|
-
const
|
|
201
|
+
const rejectedCredential = isRejectedCredential(input.error);
|
|
202
|
+
const code = rejectedCredential ? LLMErrorCode.AUTH_FAILED : errorCodeForStatus(status, details);
|
|
198
203
|
const type = errorTypeForStatus(status);
|
|
199
204
|
const retryDisposition = retryDispositionForProviderError(details);
|
|
200
205
|
if (status === 402) {
|
|
@@ -213,7 +218,7 @@ function mapProviderError(input) {
|
|
|
213
218
|
retryDisposition
|
|
214
219
|
);
|
|
215
220
|
}
|
|
216
|
-
if (
|
|
221
|
+
if (rejectedCredential) {
|
|
217
222
|
const dexto = input.provider === "dexto-nova";
|
|
218
223
|
return new DextoRuntimeError(
|
|
219
224
|
code,
|
|
@@ -238,6 +243,8 @@ function mapProviderError(input) {
|
|
|
238
243
|
);
|
|
239
244
|
}
|
|
240
245
|
export {
|
|
246
|
+
HostRetryableModelRequestError,
|
|
241
247
|
extractProviderErrorDetails,
|
|
248
|
+
isRejectedCredential,
|
|
242
249
|
mapProviderError
|
|
243
250
|
};
|
|
@@ -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
|
}
|
|
@@ -1433,7 +1450,7 @@ class TurnExecutor {
|
|
|
1433
1450
|
if (this.stepAbortController.signal.aborted) return false;
|
|
1434
1451
|
if (error instanceof import_DextoRuntimeError.DextoRuntimeError) return error.code === import_error_codes.LLMErrorCode.STREAM_STALLED;
|
|
1435
1452
|
if (!import_ai.APICallError.isInstance?.(error)) return false;
|
|
1436
|
-
if (
|
|
1453
|
+
if ((0, import_provider_error.isRejectedCredential)(error)) return false;
|
|
1437
1454
|
return error.isRetryable;
|
|
1438
1455
|
}
|
|
1439
1456
|
async applyModelStepResult(input) {
|
|
@@ -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,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAcpD,OAAO,KAAK,EAAE,cAAc,EAAiB,qB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C,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"}
|
|
@@ -24,8 +24,10 @@ import { DextoLogComponent } from "../../logger/v2/types.js";
|
|
|
24
24
|
import { recordOperationSpan } from "../../telemetry/operation-span.js";
|
|
25
25
|
import {
|
|
26
26
|
extractProviderErrorDetails,
|
|
27
|
+
isRejectedCredential,
|
|
27
28
|
mapProviderError as mapCoreProviderError
|
|
28
29
|
} from "./provider-error.js";
|
|
30
|
+
import { isRejectedModelRequest, withholdRequestMedia } from "./withheld-media.js";
|
|
29
31
|
import { isEmptyModelResponse } from "./empty-response.js";
|
|
30
32
|
import { LLMError } from "../errors.js";
|
|
31
33
|
import { LLMErrorCode } from "../error-codes.js";
|
|
@@ -1339,14 +1341,25 @@ class TurnExecutor {
|
|
|
1339
1341
|
async runModelStepWithRetry(request) {
|
|
1340
1342
|
let failedAttempts = 0;
|
|
1341
1343
|
let emptyResponseRetries = 0;
|
|
1344
|
+
let attemptRequest = request;
|
|
1345
|
+
let media = "sent";
|
|
1342
1346
|
for (; ; ) {
|
|
1343
1347
|
const historyLengthBefore = await this.contextManager.countModelMessages();
|
|
1344
1348
|
let result;
|
|
1345
1349
|
try {
|
|
1346
|
-
result = await this.runModelStep(
|
|
1350
|
+
result = await this.runModelStep(attemptRequest);
|
|
1347
1351
|
} catch (error) {
|
|
1348
1352
|
const historyLengthAfter2 = await this.contextManager.countModelMessages();
|
|
1349
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
|
+
}
|
|
1350
1363
|
if (!this.canRetryModelRequest(error, historyLengthChanged) || failedAttempts >= MODEL_REQUEST_MAX_RETRIES) {
|
|
1351
1364
|
throw error;
|
|
1352
1365
|
}
|
|
@@ -1368,6 +1381,11 @@ class TurnExecutor {
|
|
|
1368
1381
|
});
|
|
1369
1382
|
continue;
|
|
1370
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
|
+
}
|
|
1371
1389
|
if (!isEmptyModelResponse(result)) {
|
|
1372
1390
|
return result;
|
|
1373
1391
|
}
|
|
@@ -1419,7 +1437,7 @@ class TurnExecutor {
|
|
|
1419
1437
|
if (this.stepAbortController.signal.aborted) return false;
|
|
1420
1438
|
if (error instanceof DextoRuntimeError) return error.code === LLMErrorCode.STREAM_STALLED;
|
|
1421
1439
|
if (!APICallError.isInstance?.(error)) return false;
|
|
1422
|
-
if (error
|
|
1440
|
+
if (isRejectedCredential(error)) return false;
|
|
1423
1441
|
return error.isRetryable;
|
|
1424
1442
|
}
|
|
1425
1443
|
async applyModelStepResult(input) {
|
|
@@ -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"}
|