@mastra/agent-builder 1.0.39 → 1.0.40-alpha.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @mastra/agent-builder
2
2
 
3
+ ## 1.0.40-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`c973db4`](https://github.com/mastra-ai/mastra/commit/c973db428df1b564ff0c35d4b2a90e8f4f1e13fd), [`552285e`](https://github.com/mastra-ai/mastra/commit/552285e5af43cfc680a0972032cab8de8776c6a0), [`77e686c`](https://github.com/mastra-ai/mastra/commit/77e686c264e493e99ae5024e4dfe3ea5d5a09718), [`ece8dba`](https://github.com/mastra-ai/mastra/commit/ece8dba7ec1a5089eee8c33167cd762bfa91e509), [`e751af2`](https://github.com/mastra-ai/mastra/commit/e751af219433fbf4c7035b2d771b4c9ec8813b05), [`43dd577`](https://github.com/mastra-ai/mastra/commit/43dd577aa2b056b86b92cb903433f4fc13e69687), [`e2a8380`](https://github.com/mastra-ai/mastra/commit/e2a838017a7657850404c1e94c70d79ffdc6f14a), [`be3f1cd`](https://github.com/mastra-ai/mastra/commit/be3f1cd81f0e2a649e8eac15a024d542d814aef8), [`a34d9db`](https://github.com/mastra-ai/mastra/commit/a34d9dbc39fedb722f271318e9355ecee70489ab)]:
8
+ - @mastra/core@1.39.0-alpha.0
9
+ - @mastra/memory@1.20.2-alpha.0
10
+
3
11
  ## 1.0.39
4
12
 
5
13
  ### Patch Changes
package/dist/index.js CHANGED
@@ -4969,6 +4969,9 @@ var ParseError = class extends Error {
4969
4969
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
4970
4970
  }
4971
4971
  };
4972
+ var LF = 10;
4973
+ var CR = 13;
4974
+ var SPACE = 32;
4972
4975
  function noop(_arg) {
4973
4976
  }
4974
4977
  function createParser(callbacks) {
@@ -4976,39 +4979,109 @@ function createParser(callbacks) {
4976
4979
  throw new TypeError(
4977
4980
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
4978
4981
  );
4979
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
4980
- let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
4981
- function feed(newChunk) {
4982
- const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
4983
- for (const line of complete)
4984
- parseLine(line);
4985
- incompleteLine = incomplete, isFirstChunk = false;
4986
- }
4987
- function parseLine(line) {
4988
- if (line === "") {
4982
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
4983
+ let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
4984
+ function feed(chunk) {
4985
+ if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
4986
+ const trailing2 = processLines(chunk);
4987
+ trailing2 !== "" && pendingFragments.push(trailing2);
4988
+ return;
4989
+ }
4990
+ if (chunk.indexOf(`
4991
+ `) === -1 && chunk.indexOf("\r") === -1) {
4992
+ pendingFragments.push(chunk);
4993
+ return;
4994
+ }
4995
+ pendingFragments.push(chunk);
4996
+ const input = pendingFragments.join("");
4997
+ pendingFragments.length = 0;
4998
+ const trailing = processLines(input);
4999
+ trailing !== "" && pendingFragments.push(trailing);
5000
+ }
5001
+ function processLines(chunk) {
5002
+ let searchIndex = 0;
5003
+ if (chunk.indexOf("\r") === -1) {
5004
+ let lfIndex = chunk.indexOf(`
5005
+ `, searchIndex);
5006
+ for (; lfIndex !== -1; ) {
5007
+ if (searchIndex === lfIndex) {
5008
+ dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
5009
+ `, searchIndex);
5010
+ continue;
5011
+ }
5012
+ const firstCharCode = chunk.charCodeAt(searchIndex);
5013
+ if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
5014
+ const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
5015
+ if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
5016
+ onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
5017
+ `, searchIndex);
5018
+ continue;
5019
+ }
5020
+ data = dataLines === 0 ? value : `${data}
5021
+ ${value}`, dataLines++;
5022
+ } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
5023
+ chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
5024
+ lfIndex
5025
+ ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
5026
+ searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
5027
+ `, searchIndex);
5028
+ }
5029
+ return chunk.slice(searchIndex);
5030
+ }
5031
+ for (; searchIndex < chunk.length; ) {
5032
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
5033
+ `, searchIndex);
5034
+ let lineEnd = -1;
5035
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
5036
+ break;
5037
+ parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
5038
+ }
5039
+ return chunk.slice(searchIndex);
5040
+ }
5041
+ function parseLine(chunk, start, end) {
5042
+ if (start === end) {
4989
5043
  dispatchEvent();
4990
5044
  return;
4991
5045
  }
4992
- if (line.startsWith(":")) {
4993
- onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
5046
+ const firstCharCode = chunk.charCodeAt(start);
5047
+ if (isDataPrefix(chunk, start, firstCharCode)) {
5048
+ const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
5049
+ data = dataLines === 0 ? value2 : `${data}
5050
+ ${value2}`, dataLines++;
5051
+ return;
5052
+ }
5053
+ if (isEventPrefix(chunk, start, firstCharCode)) {
5054
+ eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
5055
+ return;
5056
+ }
5057
+ if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
5058
+ const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
5059
+ id = value2.includes("\0") ? void 0 : value2;
5060
+ return;
5061
+ }
5062
+ if (firstCharCode === 58) {
5063
+ if (onComment) {
5064
+ const line2 = chunk.slice(start, end);
5065
+ onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
5066
+ }
4994
5067
  return;
4995
5068
  }
4996
- const fieldSeparatorIndex = line.indexOf(":");
4997
- if (fieldSeparatorIndex !== -1) {
4998
- const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4999
- processField(field, value, line);
5069
+ const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
5070
+ if (fieldSeparatorIndex === -1) {
5071
+ processField(line, "", line);
5000
5072
  return;
5001
5073
  }
5002
- processField(line, "", line);
5074
+ const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
5075
+ processField(field, value, line);
5003
5076
  }
5004
5077
  function processField(field, value, line) {
5005
5078
  switch (field) {
5006
5079
  case "event":
5007
- eventType = value;
5080
+ eventType = value || void 0;
5008
5081
  break;
5009
5082
  case "data":
5010
- data = `${data}${value}
5011
- `;
5083
+ data = dataLines === 0 ? value : `${data}
5084
+ ${value}`, dataLines++;
5012
5085
  break;
5013
5086
  case "id":
5014
5087
  id = value.includes("\0") ? void 0 : value;
@@ -5033,37 +5106,26 @@ function createParser(callbacks) {
5033
5106
  }
5034
5107
  }
5035
5108
  function dispatchEvent() {
5036
- data.length > 0 && onEvent({
5109
+ dataLines > 0 && onEvent({
5037
5110
  id,
5038
- event: eventType || void 0,
5039
- // If the data buffer's last character is a U+000A LINE FEED (LF) character,
5040
- // then remove the last character from the data buffer.
5041
- data: data.endsWith(`
5042
- `) ? data.slice(0, -1) : data
5043
- }), id = void 0, data = "", eventType = "";
5111
+ event: eventType,
5112
+ data
5113
+ }), id = void 0, data = "", dataLines = 0, eventType = void 0;
5044
5114
  }
5045
5115
  function reset(options = {}) {
5046
- incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
5116
+ if (options.consume && pendingFragments.length > 0) {
5117
+ const incompleteLine = pendingFragments.join("");
5118
+ parseLine(incompleteLine, 0, incompleteLine.length);
5119
+ }
5120
+ isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
5047
5121
  }
5048
5122
  return { feed, reset };
5049
5123
  }
5050
- function splitLines(chunk) {
5051
- const lines = [];
5052
- let incompleteLine = "", searchIndex = 0;
5053
- for (; searchIndex < chunk.length; ) {
5054
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
5055
- `, searchIndex);
5056
- let lineEnd = -1;
5057
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
5058
- incompleteLine = chunk.slice(searchIndex);
5059
- break;
5060
- } else {
5061
- const line = chunk.slice(searchIndex, lineEnd);
5062
- lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
5063
- ` && searchIndex++;
5064
- }
5065
- }
5066
- return [lines, incompleteLine];
5124
+ function isDataPrefix(chunk, i, firstCharCode) {
5125
+ return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
5126
+ }
5127
+ function isEventPrefix(chunk, i, firstCharCode) {
5128
+ return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
5067
5129
  }
5068
5130
  var EventSourceParserStream = class extends TransformStream {
5069
5131
  constructor({ onError, onRetry, onComment } = {}) {