@mastra/server 1.78.0-alpha.9 → 1.78.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/dist/{dist-KzbPuRgb.cjs → dist-BRej8vIF.cjs} +67 -30
- package/dist/dist-BRej8vIF.cjs.map +1 -0
- package/dist/{dist-0eJzATDs.js → dist-CPHBJa2G.js} +67 -30
- package/dist/dist-CPHBJa2G.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/server/handlers/agent-builder.cjs +1 -1
- package/dist/server/handlers/agent-builder.js +1 -1
- package/package.json +9 -9
- package/dist/dist-0eJzATDs.js.map +0 -1
- package/dist/dist-KzbPuRgb.cjs.map +0 -1
|
@@ -4637,7 +4637,7 @@ function splitLines(text) {
|
|
|
4637
4637
|
return result;
|
|
4638
4638
|
}
|
|
4639
4639
|
//#endregion
|
|
4640
|
-
//#region ../memory/dist/src-
|
|
4640
|
+
//#region ../memory/dist/src-CTyZJ6A-.js
|
|
4641
4641
|
var __defProp$3 = Object.defineProperty;
|
|
4642
4642
|
var __exportAll = (all, no_symbols) => {
|
|
4643
4643
|
let target = {};
|
|
@@ -24319,18 +24319,19 @@ function safeSlice(str, end) {
|
|
|
24319
24319
|
}
|
|
24320
24320
|
const PATTERNS = {
|
|
24321
24321
|
whitespace: /^\s+$/,
|
|
24322
|
-
|
|
24323
|
-
|
|
24324
|
-
|
|
24325
|
-
|
|
24322
|
+
structuredWhitespace: /\n\s/,
|
|
24323
|
+
cjk: /[\u4E00-\u9FFF\u3400-\u4DBF\u3000-\u30FF\uFF00-\uFFEF\u2E80-\u2EFF\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\uAC00-\uD7AF\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uD7B0-\uD7FF]/,
|
|
24324
|
+
numeric: /^\d+$/,
|
|
24325
|
+
punctuation: /[.,!?;(){}[\]<>:/\\|@#$%^&*+=`~_"-]/
|
|
24326
24326
|
};
|
|
24327
|
-
const TOKEN_SPLIT_PATTERN =
|
|
24327
|
+
const TOKEN_SPLIT_PATTERN = new RegExp(`(\\s+|${PATTERNS.punctuation.source}+)`);
|
|
24328
24328
|
const DEFAULT_CHARS_PER_TOKEN = 6;
|
|
24329
24329
|
const SHORT_TOKEN_THRESHOLD = 3;
|
|
24330
|
+
const KANA_CHARS_PER_TOKEN = 1.35;
|
|
24330
24331
|
const DEFAULT_LANGUAGE_CONFIGS = [
|
|
24331
24332
|
{
|
|
24332
24333
|
pattern: /[äöüßẞ]/i,
|
|
24333
|
-
averageCharsPerToken:
|
|
24334
|
+
averageCharsPerToken: 2.6
|
|
24334
24335
|
},
|
|
24335
24336
|
{
|
|
24336
24337
|
pattern: /[éèêëàâîïôûùüÿçœæáíóúñ]/i,
|
|
@@ -24338,39 +24339,75 @@ const DEFAULT_LANGUAGE_CONFIGS = [
|
|
|
24338
24339
|
},
|
|
24339
24340
|
{
|
|
24340
24341
|
pattern: /[ąćęłńóśźżěščřžýůúďťň]/i,
|
|
24341
|
-
averageCharsPerToken:
|
|
24342
|
+
averageCharsPerToken: 2.5
|
|
24343
|
+
},
|
|
24344
|
+
{
|
|
24345
|
+
pattern: /[\u0430-\u044F\u0451]/i,
|
|
24346
|
+
averageCharsPerToken: 4
|
|
24347
|
+
},
|
|
24348
|
+
{
|
|
24349
|
+
pattern: /[\u03AC-\u03CE]/i,
|
|
24350
|
+
averageCharsPerToken: 2.75
|
|
24351
|
+
},
|
|
24352
|
+
{
|
|
24353
|
+
pattern: /^\p{Extended_Pictographic}[\p{Extended_Pictographic}\p{Emoji_Component}]*$/u,
|
|
24354
|
+
averageCharsPerToken: .75
|
|
24342
24355
|
}
|
|
24343
24356
|
];
|
|
24344
24357
|
/**
|
|
24345
|
-
*
|
|
24358
|
+
* Walks a text as (segment, estimated token count) pairs. The segments
|
|
24359
|
+
* concatenate back to the original text; whitespace segments count zero
|
|
24360
|
+
* tokens unless they carry structure (indentation or blank lines).
|
|
24346
24361
|
*/
|
|
24347
|
-
function
|
|
24348
|
-
if (!text) return
|
|
24349
|
-
const
|
|
24350
|
-
const
|
|
24351
|
-
|
|
24352
|
-
|
|
24353
|
-
|
|
24362
|
+
function* walkSegments(text, options = {}) {
|
|
24363
|
+
if (!text) return;
|
|
24364
|
+
const resolvedOptions = resolveOptions(options);
|
|
24365
|
+
for (const segment of text.split(TOKEN_SPLIT_PATTERN)) if (segment) yield {
|
|
24366
|
+
segment,
|
|
24367
|
+
tokenCount: estimateSegmentTokens(segment, resolvedOptions)
|
|
24368
|
+
};
|
|
24354
24369
|
}
|
|
24355
|
-
function
|
|
24356
|
-
|
|
24357
|
-
|
|
24358
|
-
|
|
24370
|
+
function resolveOptions(options) {
|
|
24371
|
+
return {
|
|
24372
|
+
defaultCharsPerToken: options.defaultCharsPerToken ?? DEFAULT_CHARS_PER_TOKEN,
|
|
24373
|
+
languageConfigs: options.languageConfigs ?? DEFAULT_LANGUAGE_CONFIGS
|
|
24374
|
+
};
|
|
24375
|
+
}
|
|
24376
|
+
function estimateSegmentTokens(segment, { languageConfigs, defaultCharsPerToken }) {
|
|
24377
|
+
if (PATTERNS.whitespace.test(segment)) return PATTERNS.structuredWhitespace.test(segment) ? 1 : 0;
|
|
24378
|
+
const languageCharsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs);
|
|
24379
|
+
if (languageCharsPerToken !== void 0) return Math.ceil(getCharacterCount(segment) / languageCharsPerToken);
|
|
24380
|
+
if (PATTERNS.cjk.test(segment)) return estimateCjkTokens(segment);
|
|
24381
|
+
if (PATTERNS.numeric.test(segment)) return Math.ceil(segment.length / 3);
|
|
24359
24382
|
if (segment.length <= SHORT_TOKEN_THRESHOLD) return 1;
|
|
24360
|
-
if (PATTERNS.punctuation.test(segment)) return
|
|
24361
|
-
|
|
24362
|
-
const charsPerToken$1 = getLanguageSpecificCharsPerToken(segment, languageConfigs) ?? defaultCharsPerToken;
|
|
24363
|
-
return Math.ceil(segment.length / charsPerToken$1);
|
|
24364
|
-
}
|
|
24365
|
-
const charsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs) ?? defaultCharsPerToken;
|
|
24366
|
-
return Math.ceil(segment.length / charsPerToken);
|
|
24383
|
+
if (PATTERNS.punctuation.test(segment)) return Math.ceil(segment.length / 2);
|
|
24384
|
+
return Math.ceil(segment.length / defaultCharsPerToken);
|
|
24367
24385
|
}
|
|
24368
24386
|
function getLanguageSpecificCharsPerToken(segment, languageConfigs) {
|
|
24369
|
-
for (const config of languageConfigs) if (config.pattern
|
|
24387
|
+
for (const config of languageConfigs) if (segment.search(config.pattern) !== -1) return config.averageCharsPerToken;
|
|
24370
24388
|
}
|
|
24371
24389
|
function getCharacterCount(text) {
|
|
24372
24390
|
return Array.from(text).length;
|
|
24373
24391
|
}
|
|
24392
|
+
function estimateCjkTokens(segment) {
|
|
24393
|
+
let kanaCount = 0;
|
|
24394
|
+
let otherCount = 0;
|
|
24395
|
+
for (const character of segment) {
|
|
24396
|
+
const codePoint = character.codePointAt(0);
|
|
24397
|
+
if (codePoint >= 12352 && codePoint <= 12543) kanaCount++;
|
|
24398
|
+
else otherCount++;
|
|
24399
|
+
}
|
|
24400
|
+
return otherCount + Math.ceil(kanaCount / KANA_CHARS_PER_TOKEN);
|
|
24401
|
+
}
|
|
24402
|
+
/**
|
|
24403
|
+
* Estimates the number of tokens in a text string using heuristic rules
|
|
24404
|
+
*/
|
|
24405
|
+
function estimateTokenCount(text, options = {}) {
|
|
24406
|
+
if (!text) return 0;
|
|
24407
|
+
let tokenCount = 0;
|
|
24408
|
+
for (const segmentEstimate of walkSegments(text, options)) tokenCount += segmentEstimate.tokenCount;
|
|
24409
|
+
return tokenCount;
|
|
24410
|
+
}
|
|
24374
24411
|
const DEFAULT_OBSERVER_TOOL_ARGUMENT_MAX_TOKENS = 2e3;
|
|
24375
24412
|
const OBSERVER_TOOL_ARGUMENT_INLINE_STRING_MAX_CHARS = 160;
|
|
24376
24413
|
const OBSERVER_TOOL_ARGUMENT_MAX_DEPTH = 5;
|
|
@@ -26873,7 +26910,7 @@ const IMAGE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
26873
26910
|
"heif",
|
|
26874
26911
|
"avif"
|
|
26875
26912
|
]);
|
|
26876
|
-
const TOKEN_ESTIMATE_CACHE_VERSION =
|
|
26913
|
+
const TOKEN_ESTIMATE_CACHE_VERSION = 8;
|
|
26877
26914
|
/**
|
|
26878
26915
|
* Cache `source` marker for token estimates supplied by the caller via
|
|
26879
26916
|
* `part.providerMetadata.mastra.tokenEstimate`. Pipelines that strip the real
|
|
@@ -51862,4 +51899,4 @@ const agentBuilderWorkflows = {
|
|
|
51862
51899
|
//#endregion
|
|
51863
51900
|
exports.agentBuilderWorkflows = agentBuilderWorkflows;
|
|
51864
51901
|
|
|
51865
|
-
//# sourceMappingURL=dist-
|
|
51902
|
+
//# sourceMappingURL=dist-BRej8vIF.cjs.map
|