@mastra/server 1.13.3-alpha.1 → 1.14.0-alpha.2

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/_types/@internal_core/dist/index.d.ts +1333 -0
  3. package/dist/chunk-2UVJD67W.cjs +136 -0
  4. package/dist/chunk-2UVJD67W.cjs.map +1 -0
  5. package/dist/chunk-4VGZOVOI.js +656 -0
  6. package/dist/chunk-4VGZOVOI.js.map +1 -0
  7. package/dist/{chunk-A2443FGH.js → chunk-55AD3MAT.js} +24 -18
  8. package/dist/chunk-55AD3MAT.js.map +1 -0
  9. package/dist/{observational-memory-XXD6E2SO-RTIRYSYO.cjs → chunk-A6HL3JRC.cjs} +306 -130
  10. package/dist/chunk-A6HL3JRC.cjs.map +1 -0
  11. package/dist/{observational-memory-XXD6E2SO-TGAG7QCA.js → chunk-KZAB4IB3.js} +305 -131
  12. package/dist/chunk-KZAB4IB3.js.map +1 -0
  13. package/dist/{chunk-SFC2UJ2C.js → chunk-LL5SPRAA.js} +5 -5
  14. package/dist/{chunk-SFC2UJ2C.js.map → chunk-LL5SPRAA.js.map} +1 -1
  15. package/dist/chunk-LUHJDABR.cjs +675 -0
  16. package/dist/chunk-LUHJDABR.cjs.map +1 -0
  17. package/dist/{chunk-7P6XT5WB.cjs → chunk-OXZCCCIJ.cjs} +28 -22
  18. package/dist/chunk-OXZCCCIJ.cjs.map +1 -0
  19. package/dist/chunk-RSIZIEPW.js +131 -0
  20. package/dist/chunk-RSIZIEPW.js.map +1 -0
  21. package/dist/{chunk-4AR4SH3H.cjs → chunk-UDDFVPPC.cjs} +6 -6
  22. package/dist/{chunk-4AR4SH3H.cjs.map → chunk-UDDFVPPC.cjs.map} +1 -1
  23. package/dist/docs/SKILL.md +1 -1
  24. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  25. package/dist/observational-memory-UEDVTWS2-COV6JJZK.js +3 -0
  26. package/dist/observational-memory-UEDVTWS2-COV6JJZK.js.map +1 -0
  27. package/dist/observational-memory-UEDVTWS2-TU3KK4ZG.cjs +68 -0
  28. package/dist/observational-memory-UEDVTWS2-TU3KK4ZG.cjs.map +1 -0
  29. package/dist/server/handlers/agent-builder.cjs +16 -16
  30. package/dist/server/handlers/agent-builder.js +1 -1
  31. package/dist/server/handlers/observability-new-endpoints.cjs +80 -0
  32. package/dist/server/handlers/observability-new-endpoints.cjs.map +1 -0
  33. package/dist/server/handlers/observability-new-endpoints.d.ts +1212 -0
  34. package/dist/server/handlers/observability-new-endpoints.d.ts.map +1 -0
  35. package/dist/server/handlers/observability-new-endpoints.js +3 -0
  36. package/dist/server/handlers/observability-new-endpoints.js.map +1 -0
  37. package/dist/server/handlers/observability-shared.cjs +24 -0
  38. package/dist/server/handlers/observability-shared.cjs.map +1 -0
  39. package/dist/server/handlers/observability-shared.d.ts +126 -0
  40. package/dist/server/handlers/observability-shared.d.ts.map +1 -0
  41. package/dist/server/handlers/observability-shared.js +3 -0
  42. package/dist/server/handlers/observability-shared.js.map +1 -0
  43. package/dist/server/handlers/observability.cjs +78 -5
  44. package/dist/server/handlers/observability.d.ts +22 -20
  45. package/dist/server/handlers/observability.d.ts.map +1 -1
  46. package/dist/server/handlers/observability.js +2 -1
  47. package/dist/server/handlers.cjs +10 -10
  48. package/dist/server/handlers.js +3 -3
  49. package/dist/server/schemas/index.cjs +82 -82
  50. package/dist/server/schemas/index.js +2 -2
  51. package/dist/server/server-adapter/index.cjs +43 -24
  52. package/dist/server/server-adapter/index.cjs.map +1 -1
  53. package/dist/server/server-adapter/index.js +25 -6
  54. package/dist/server/server-adapter/index.js.map +1 -1
  55. package/dist/server/server-adapter/routes/observability.d.ts +531 -21
  56. package/dist/server/server-adapter/routes/observability.d.ts.map +1 -1
  57. package/package.json +6 -5
  58. package/dist/chunk-3NG2FRSI.js +0 -41
  59. package/dist/chunk-3NG2FRSI.js.map +0 -1
  60. package/dist/chunk-5ZBS3CWT.cjs +0 -43
  61. package/dist/chunk-5ZBS3CWT.cjs.map +0 -1
  62. package/dist/chunk-7P6XT5WB.cjs.map +0 -1
  63. package/dist/chunk-A2443FGH.js.map +0 -1
  64. package/dist/observational-memory-XXD6E2SO-RTIRYSYO.cjs.map +0 -1
  65. package/dist/observational-memory-XXD6E2SO-TGAG7QCA.js.map +0 -1
@@ -1,4 +1,3 @@
1
- import { e } from './chunk-3NG2FRSI.js';
2
1
  import { appendFileSync, mkdirSync, writeFileSync } from 'fs';
3
2
  import { join } from 'path';
4
3
  import { Agent } from '@mastra/core/agent';
@@ -9,6 +8,99 @@ import { MessageHistory } from '@mastra/core/processors';
9
8
  import { createHash, randomUUID } from 'crypto';
10
9
  import { AsyncLocalStorage } from 'async_hooks';
11
10
 
11
+ // ../memory/dist/chunk-4KPXPQX3.js
12
+
13
+ // ../../node_modules/.pnpm/xxhash-wasm@1.1.0/node_modules/xxhash-wasm/esm/xxhash-wasm.js
14
+ var t = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 48, 8, 96, 3, 127, 127, 127, 1, 127, 96, 3, 127, 127, 127, 0, 96, 2, 127, 127, 0, 96, 1, 127, 1, 127, 96, 3, 127, 127, 126, 1, 126, 96, 3, 126, 127, 127, 1, 126, 96, 2, 127, 126, 0, 96, 1, 127, 1, 126, 3, 11, 10, 0, 0, 2, 1, 3, 4, 5, 6, 1, 7, 5, 3, 1, 0, 1, 7, 85, 9, 3, 109, 101, 109, 2, 0, 5, 120, 120, 104, 51, 50, 0, 0, 6, 105, 110, 105, 116, 51, 50, 0, 2, 8, 117, 112, 100, 97, 116, 101, 51, 50, 0, 3, 8, 100, 105, 103, 101, 115, 116, 51, 50, 0, 4, 5, 120, 120, 104, 54, 52, 0, 5, 6, 105, 110, 105, 116, 54, 52, 0, 7, 8, 117, 112, 100, 97, 116, 101, 54, 52, 0, 8, 8, 100, 105, 103, 101, 115, 116, 54, 52, 0, 9, 10, 251, 22, 10, 242, 1, 1, 4, 127, 32, 0, 32, 1, 106, 33, 3, 32, 1, 65, 16, 79, 4, 127, 32, 3, 65, 16, 107, 33, 6, 32, 2, 65, 168, 136, 141, 161, 2, 106, 33, 3, 32, 2, 65, 137, 235, 208, 208, 7, 107, 33, 4, 32, 2, 65, 207, 140, 162, 142, 6, 106, 33, 5, 3, 64, 32, 3, 32, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 3, 32, 4, 32, 0, 65, 4, 106, 34, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 4, 32, 2, 32, 0, 65, 4, 106, 34, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 2, 32, 5, 32, 0, 65, 4, 106, 34, 0, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 5, 32, 6, 32, 0, 65, 4, 106, 34, 0, 79, 13, 0, 11, 32, 2, 65, 12, 119, 32, 5, 65, 18, 119, 106, 32, 4, 65, 7, 119, 106, 32, 3, 65, 1, 119, 106, 5, 32, 2, 65, 177, 207, 217, 178, 1, 106, 11, 32, 1, 106, 32, 0, 32, 1, 65, 15, 113, 16, 1, 11, 146, 1, 0, 32, 1, 32, 2, 106, 33, 2, 3, 64, 32, 1, 65, 4, 106, 32, 2, 75, 69, 4, 64, 32, 0, 32, 1, 40, 2, 0, 65, 189, 220, 202, 149, 124, 108, 106, 65, 17, 119, 65, 175, 214, 211, 190, 2, 108, 33, 0, 32, 1, 65, 4, 106, 33, 1, 12, 1, 11, 11, 3, 64, 32, 1, 32, 2, 79, 69, 4, 64, 32, 0, 32, 1, 45, 0, 0, 65, 177, 207, 217, 178, 1, 108, 106, 65, 11, 119, 65, 177, 243, 221, 241, 121, 108, 33, 0, 32, 1, 65, 1, 106, 33, 1, 12, 1, 11, 11, 32, 0, 32, 0, 65, 15, 118, 115, 65, 247, 148, 175, 175, 120, 108, 34, 0, 65, 13, 118, 32, 0, 115, 65, 189, 220, 202, 149, 124, 108, 34, 0, 65, 16, 118, 32, 0, 115, 11, 63, 0, 32, 0, 65, 8, 106, 32, 1, 65, 168, 136, 141, 161, 2, 106, 54, 2, 0, 32, 0, 65, 12, 106, 32, 1, 65, 137, 235, 208, 208, 7, 107, 54, 2, 0, 32, 0, 65, 16, 106, 32, 1, 54, 2, 0, 32, 0, 65, 20, 106, 32, 1, 65, 207, 140, 162, 142, 6, 106, 54, 2, 0, 11, 195, 4, 1, 6, 127, 32, 1, 32, 2, 106, 33, 6, 32, 0, 65, 24, 106, 33, 4, 32, 0, 65, 40, 106, 40, 2, 0, 33, 3, 32, 0, 32, 0, 40, 2, 0, 32, 2, 106, 54, 2, 0, 32, 0, 65, 4, 106, 34, 5, 32, 5, 40, 2, 0, 32, 2, 65, 16, 79, 32, 0, 40, 2, 0, 65, 16, 79, 114, 114, 54, 2, 0, 32, 2, 32, 3, 106, 65, 16, 73, 4, 64, 32, 3, 32, 4, 106, 32, 1, 32, 2, 252, 10, 0, 0, 32, 0, 65, 40, 106, 32, 2, 32, 3, 106, 54, 2, 0, 15, 11, 32, 3, 4, 64, 32, 3, 32, 4, 106, 32, 1, 65, 16, 32, 3, 107, 34, 2, 252, 10, 0, 0, 32, 0, 65, 8, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 12, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 65, 4, 106, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 16, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 65, 8, 106, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 20, 106, 34, 3, 32, 3, 40, 2, 0, 32, 4, 65, 12, 106, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 54, 2, 0, 32, 0, 65, 40, 106, 65, 0, 54, 2, 0, 32, 1, 32, 2, 106, 33, 1, 11, 32, 1, 32, 6, 65, 16, 107, 77, 4, 64, 32, 6, 65, 16, 107, 33, 8, 32, 0, 65, 8, 106, 40, 2, 0, 33, 2, 32, 0, 65, 12, 106, 40, 2, 0, 33, 3, 32, 0, 65, 16, 106, 40, 2, 0, 33, 5, 32, 0, 65, 20, 106, 40, 2, 0, 33, 7, 3, 64, 32, 2, 32, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 2, 32, 3, 32, 1, 65, 4, 106, 34, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 3, 32, 5, 32, 1, 65, 4, 106, 34, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 5, 32, 7, 32, 1, 65, 4, 106, 34, 1, 40, 2, 0, 65, 247, 148, 175, 175, 120, 108, 106, 65, 13, 119, 65, 177, 243, 221, 241, 121, 108, 33, 7, 32, 8, 32, 1, 65, 4, 106, 34, 1, 79, 13, 0, 11, 32, 0, 65, 8, 106, 32, 2, 54, 2, 0, 32, 0, 65, 12, 106, 32, 3, 54, 2, 0, 32, 0, 65, 16, 106, 32, 5, 54, 2, 0, 32, 0, 65, 20, 106, 32, 7, 54, 2, 0, 11, 32, 1, 32, 6, 73, 4, 64, 32, 4, 32, 1, 32, 6, 32, 1, 107, 34, 1, 252, 10, 0, 0, 32, 0, 65, 40, 106, 32, 1, 54, 2, 0, 11, 11, 97, 1, 1, 127, 32, 0, 65, 16, 106, 40, 2, 0, 33, 1, 32, 0, 65, 4, 106, 40, 2, 0, 4, 127, 32, 1, 65, 12, 119, 32, 0, 65, 20, 106, 40, 2, 0, 65, 18, 119, 106, 32, 0, 65, 12, 106, 40, 2, 0, 65, 7, 119, 106, 32, 0, 65, 8, 106, 40, 2, 0, 65, 1, 119, 106, 5, 32, 1, 65, 177, 207, 217, 178, 1, 106, 11, 32, 0, 40, 2, 0, 106, 32, 0, 65, 24, 106, 32, 0, 65, 40, 106, 40, 2, 0, 16, 1, 11, 255, 3, 2, 3, 126, 1, 127, 32, 0, 32, 1, 106, 33, 6, 32, 1, 65, 32, 79, 4, 126, 32, 6, 65, 32, 107, 33, 6, 32, 2, 66, 214, 235, 130, 238, 234, 253, 137, 245, 224, 0, 124, 33, 3, 32, 2, 66, 177, 169, 172, 193, 173, 184, 212, 166, 61, 125, 33, 4, 32, 2, 66, 249, 234, 208, 208, 231, 201, 161, 228, 225, 0, 124, 33, 5, 3, 64, 32, 3, 32, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 3, 32, 4, 32, 0, 65, 8, 106, 34, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 4, 32, 2, 32, 0, 65, 8, 106, 34, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 2, 32, 5, 32, 0, 65, 8, 106, 34, 0, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 5, 32, 6, 32, 0, 65, 8, 106, 34, 0, 79, 13, 0, 11, 32, 2, 66, 12, 137, 32, 5, 66, 18, 137, 124, 32, 4, 66, 7, 137, 124, 32, 3, 66, 1, 137, 124, 32, 3, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 4, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 2, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 5, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 5, 32, 2, 66, 197, 207, 217, 178, 241, 229, 186, 234, 39, 124, 11, 32, 1, 173, 124, 32, 0, 32, 1, 65, 31, 113, 16, 6, 11, 134, 2, 0, 32, 1, 32, 2, 106, 33, 2, 3, 64, 32, 2, 32, 1, 65, 8, 106, 79, 4, 64, 32, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 32, 0, 133, 66, 27, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 33, 0, 32, 1, 65, 8, 106, 33, 1, 12, 1, 11, 11, 32, 1, 65, 4, 106, 32, 2, 77, 4, 64, 32, 0, 32, 1, 53, 2, 0, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 23, 137, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 249, 243, 221, 241, 153, 246, 153, 171, 22, 124, 33, 0, 32, 1, 65, 4, 106, 33, 1, 11, 3, 64, 32, 1, 32, 2, 73, 4, 64, 32, 0, 32, 1, 49, 0, 0, 66, 197, 207, 217, 178, 241, 229, 186, 234, 39, 126, 133, 66, 11, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 0, 32, 1, 65, 1, 106, 33, 1, 12, 1, 11, 11, 32, 0, 32, 0, 66, 33, 136, 133, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 34, 0, 32, 0, 66, 29, 136, 133, 66, 249, 243, 221, 241, 153, 246, 153, 171, 22, 126, 34, 0, 32, 0, 66, 32, 136, 133, 11, 77, 0, 32, 0, 65, 8, 106, 32, 1, 66, 214, 235, 130, 238, 234, 253, 137, 245, 224, 0, 124, 55, 3, 0, 32, 0, 65, 16, 106, 32, 1, 66, 177, 169, 172, 193, 173, 184, 212, 166, 61, 125, 55, 3, 0, 32, 0, 65, 24, 106, 32, 1, 55, 3, 0, 32, 0, 65, 32, 106, 32, 1, 66, 249, 234, 208, 208, 231, 201, 161, 228, 225, 0, 124, 55, 3, 0, 11, 244, 4, 2, 3, 127, 4, 126, 32, 1, 32, 2, 106, 33, 5, 32, 0, 65, 40, 106, 33, 4, 32, 0, 65, 200, 0, 106, 40, 2, 0, 33, 3, 32, 0, 32, 0, 41, 3, 0, 32, 2, 173, 124, 55, 3, 0, 32, 2, 32, 3, 106, 65, 32, 73, 4, 64, 32, 3, 32, 4, 106, 32, 1, 32, 2, 252, 10, 0, 0, 32, 0, 65, 200, 0, 106, 32, 2, 32, 3, 106, 54, 2, 0, 15, 11, 32, 3, 4, 64, 32, 3, 32, 4, 106, 32, 1, 65, 32, 32, 3, 107, 34, 2, 252, 10, 0, 0, 32, 0, 65, 8, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 16, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 65, 8, 106, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 24, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 65, 16, 106, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 32, 106, 34, 3, 32, 3, 41, 3, 0, 32, 4, 65, 24, 106, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 55, 3, 0, 32, 0, 65, 200, 0, 106, 65, 0, 54, 2, 0, 32, 1, 32, 2, 106, 33, 1, 11, 32, 1, 65, 32, 106, 32, 5, 77, 4, 64, 32, 5, 65, 32, 107, 33, 2, 32, 0, 65, 8, 106, 41, 3, 0, 33, 6, 32, 0, 65, 16, 106, 41, 3, 0, 33, 7, 32, 0, 65, 24, 106, 41, 3, 0, 33, 8, 32, 0, 65, 32, 106, 41, 3, 0, 33, 9, 3, 64, 32, 6, 32, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 6, 32, 7, 32, 1, 65, 8, 106, 34, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 7, 32, 8, 32, 1, 65, 8, 106, 34, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 8, 32, 9, 32, 1, 65, 8, 106, 34, 1, 41, 3, 0, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 124, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 33, 9, 32, 2, 32, 1, 65, 8, 106, 34, 1, 79, 13, 0, 11, 32, 0, 65, 8, 106, 32, 6, 55, 3, 0, 32, 0, 65, 16, 106, 32, 7, 55, 3, 0, 32, 0, 65, 24, 106, 32, 8, 55, 3, 0, 32, 0, 65, 32, 106, 32, 9, 55, 3, 0, 11, 32, 1, 32, 5, 73, 4, 64, 32, 4, 32, 1, 32, 5, 32, 1, 107, 34, 1, 252, 10, 0, 0, 32, 0, 65, 200, 0, 106, 32, 1, 54, 2, 0, 11, 11, 188, 2, 1, 5, 126, 32, 0, 65, 24, 106, 41, 3, 0, 33, 1, 32, 0, 41, 3, 0, 34, 2, 66, 32, 90, 4, 126, 32, 0, 65, 8, 106, 41, 3, 0, 34, 3, 66, 1, 137, 32, 0, 65, 16, 106, 41, 3, 0, 34, 4, 66, 7, 137, 124, 32, 1, 66, 12, 137, 32, 0, 65, 32, 106, 41, 3, 0, 34, 5, 66, 18, 137, 124, 124, 32, 3, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 4, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 1, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 32, 5, 66, 207, 214, 211, 190, 210, 199, 171, 217, 66, 126, 66, 31, 137, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 133, 66, 135, 149, 175, 175, 152, 182, 222, 155, 158, 127, 126, 66, 157, 163, 181, 234, 131, 177, 141, 138, 250, 0, 125, 5, 32, 1, 66, 197, 207, 217, 178, 241, 229, 186, 234, 39, 124, 11, 32, 2, 124, 32, 0, 65, 40, 106, 32, 2, 66, 31, 131, 167, 16, 6, 11]);
15
+ async function e() {
16
+ return (function(t2) {
17
+ const { exports: { mem: e2, xxh32: n, xxh64: r, init32: i, update32: a, digest32: o, init64: s, update64: u, digest64: c } } = t2;
18
+ let h = new Uint8Array(e2.buffer);
19
+ function g(t3, n2) {
20
+ if (e2.buffer.byteLength < t3 + n2) {
21
+ const r2 = Math.ceil((t3 + n2 - e2.buffer.byteLength) / 65536);
22
+ e2.grow(r2), h = new Uint8Array(e2.buffer);
23
+ }
24
+ }
25
+ function f(t3, e3, n2, r2, i2, a2) {
26
+ g(t3);
27
+ const o2 = new Uint8Array(t3);
28
+ return h.set(o2), n2(0, e3), o2.set(h.subarray(0, t3)), { update(e4) {
29
+ let n3;
30
+ return h.set(o2), "string" == typeof e4 ? (g(3 * e4.length, t3), n3 = w.encodeInto(e4, h.subarray(t3)).written) : (g(e4.byteLength, t3), h.set(e4, t3), n3 = e4.byteLength), r2(0, t3, n3), o2.set(h.subarray(0, t3)), this;
31
+ }, digest: () => (h.set(o2), a2(i2(0))) };
32
+ }
33
+ function y(t3) {
34
+ return t3 >>> 0;
35
+ }
36
+ const b = 2n ** 64n - 1n;
37
+ function d(t3) {
38
+ return t3 & b;
39
+ }
40
+ const w = new TextEncoder(), l = 0, p = 0n;
41
+ function x(t3, e3 = l) {
42
+ return g(3 * t3.length, 0), y(n(0, w.encodeInto(t3, h).written, e3));
43
+ }
44
+ function L(t3, e3 = p) {
45
+ return g(3 * t3.length, 0), d(r(0, w.encodeInto(t3, h).written, e3));
46
+ }
47
+ return { h32: x, h32ToString: (t3, e3 = l) => x(t3, e3).toString(16).padStart(8, "0"), h32Raw: (t3, e3 = l) => (g(t3.byteLength, 0), h.set(t3), y(n(0, t3.byteLength, e3))), create32: (t3 = l) => f(48, t3, i, a, o, y), h64: L, h64ToString: (t3, e3 = p) => L(t3, e3).toString(16).padStart(16, "0"), h64Raw: (t3, e3 = p) => (g(t3.byteLength, 0), h.set(t3), d(r(0, t3.byteLength, e3))), create64: (t3 = p) => f(88, t3, s, u, c, d) };
48
+ })((await WebAssembly.instantiate(t)).instance);
49
+ }
50
+
51
+ // ../../node_modules/.pnpm/tokenx@1.3.0/node_modules/tokenx/dist/index.mjs
52
+ var PATTERNS = {
53
+ whitespace: /^\s+$/,
54
+ cjk: /[\u4E00-\u9FFF\u3400-\u4DBF\u3000-\u303F\uFF00-\uFFEF\u30A0-\u30FF\u2E80-\u2EFF\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\uAC00-\uD7AF\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uD7B0-\uD7FF]/,
55
+ numeric: /^\d+(?:[.,]\d+)*$/,
56
+ punctuation: /[.,!?;(){}[\]<>:/\\|@#$%^&*+=`~_-]/,
57
+ alphanumeric: /^[a-zA-Z0-9\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]+$/
58
+ };
59
+ var TOKEN_SPLIT_PATTERN = /* @__PURE__ */ new RegExp(`(\\s+|${PATTERNS.punctuation.source}+)`);
60
+ var DEFAULT_CHARS_PER_TOKEN = 6;
61
+ var SHORT_TOKEN_THRESHOLD = 3;
62
+ var DEFAULT_LANGUAGE_CONFIGS = [
63
+ {
64
+ pattern: /[äöüßẞ]/i,
65
+ averageCharsPerToken: 3
66
+ },
67
+ {
68
+ pattern: /[éèêëàâîïôûùüÿçœæáíóúñ]/i,
69
+ averageCharsPerToken: 3
70
+ },
71
+ {
72
+ pattern: /[ąćęłńóśźżěščřžýůúďťň]/i,
73
+ averageCharsPerToken: 3.5
74
+ }
75
+ ];
76
+ function estimateTokenCount(text, options = {}) {
77
+ if (!text) return 0;
78
+ const { defaultCharsPerToken = DEFAULT_CHARS_PER_TOKEN, languageConfigs = DEFAULT_LANGUAGE_CONFIGS } = options;
79
+ const segments = text.split(TOKEN_SPLIT_PATTERN).filter(Boolean);
80
+ let tokenCount = 0;
81
+ for (const segment of segments) tokenCount += estimateSegmentTokens(segment, languageConfigs, defaultCharsPerToken);
82
+ return tokenCount;
83
+ }
84
+ function estimateSegmentTokens(segment, languageConfigs, defaultCharsPerToken) {
85
+ if (PATTERNS.whitespace.test(segment)) return 0;
86
+ if (PATTERNS.cjk.test(segment)) return getCharacterCount(segment);
87
+ if (PATTERNS.numeric.test(segment)) return 1;
88
+ if (segment.length <= SHORT_TOKEN_THRESHOLD) return 1;
89
+ if (PATTERNS.punctuation.test(segment)) return segment.length > 1 ? Math.ceil(segment.length / 2) : 1;
90
+ if (PATTERNS.alphanumeric.test(segment)) {
91
+ const charsPerToken$1 = getLanguageSpecificCharsPerToken(segment, languageConfigs) ?? defaultCharsPerToken;
92
+ return Math.ceil(segment.length / charsPerToken$1);
93
+ }
94
+ const charsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs) ?? defaultCharsPerToken;
95
+ return Math.ceil(segment.length / charsPerToken);
96
+ }
97
+ function getLanguageSpecificCharsPerToken(segment, languageConfigs) {
98
+ for (const config of languageConfigs) if (config.pattern.test(segment)) return config.averageCharsPerToken;
99
+ }
100
+ function getCharacterCount(text) {
101
+ return Array.from(text).length;
102
+ }
103
+
12
104
  // ../../node_modules/.pnpm/image-size@2.0.2/node_modules/image-size/dist/index.mjs
13
105
  var decoder = new TextDecoder();
14
106
  var toUTF8String = (input, start = 0, end = input.length) => decoder.decode(input.slice(start, end));
@@ -947,60 +1039,7 @@ function imageSize(input) {
947
1039
  throw new TypeError(`unsupported file type: ${type}`);
948
1040
  }
949
1041
 
950
- // ../../node_modules/.pnpm/tokenx@1.3.0/node_modules/tokenx/dist/index.mjs
951
- var PATTERNS = {
952
- whitespace: /^\s+$/,
953
- cjk: /[\u4E00-\u9FFF\u3400-\u4DBF\u3000-\u303F\uFF00-\uFFEF\u30A0-\u30FF\u2E80-\u2EFF\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\uAC00-\uD7AF\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uD7B0-\uD7FF]/,
954
- numeric: /^\d+(?:[.,]\d+)*$/,
955
- punctuation: /[.,!?;(){}[\]<>:/\\|@#$%^&*+=`~_-]/,
956
- alphanumeric: /^[a-zA-Z0-9\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]+$/
957
- };
958
- var TOKEN_SPLIT_PATTERN = /* @__PURE__ */ new RegExp(`(\\s+|${PATTERNS.punctuation.source}+)`);
959
- var DEFAULT_CHARS_PER_TOKEN = 6;
960
- var SHORT_TOKEN_THRESHOLD = 3;
961
- var DEFAULT_LANGUAGE_CONFIGS = [
962
- {
963
- pattern: /[äöüßẞ]/i,
964
- averageCharsPerToken: 3
965
- },
966
- {
967
- pattern: /[éèêëàâîïôûùüÿçœæáíóúñ]/i,
968
- averageCharsPerToken: 3
969
- },
970
- {
971
- pattern: /[ąćęłńóśźżěščřžýůúďťň]/i,
972
- averageCharsPerToken: 3.5
973
- }
974
- ];
975
- function estimateTokenCount(text, options = {}) {
976
- if (!text) return 0;
977
- const { defaultCharsPerToken = DEFAULT_CHARS_PER_TOKEN, languageConfigs = DEFAULT_LANGUAGE_CONFIGS } = options;
978
- const segments = text.split(TOKEN_SPLIT_PATTERN).filter(Boolean);
979
- let tokenCount = 0;
980
- for (const segment of segments) tokenCount += estimateSegmentTokens(segment, languageConfigs, defaultCharsPerToken);
981
- return tokenCount;
982
- }
983
- function estimateSegmentTokens(segment, languageConfigs, defaultCharsPerToken) {
984
- if (PATTERNS.whitespace.test(segment)) return 0;
985
- if (PATTERNS.cjk.test(segment)) return getCharacterCount(segment);
986
- if (PATTERNS.numeric.test(segment)) return 1;
987
- if (segment.length <= SHORT_TOKEN_THRESHOLD) return 1;
988
- if (PATTERNS.punctuation.test(segment)) return segment.length > 1 ? Math.ceil(segment.length / 2) : 1;
989
- if (PATTERNS.alphanumeric.test(segment)) {
990
- const charsPerToken$1 = getLanguageSpecificCharsPerToken(segment, languageConfigs) ?? defaultCharsPerToken;
991
- return Math.ceil(segment.length / charsPerToken$1);
992
- }
993
- const charsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs) ?? defaultCharsPerToken;
994
- return Math.ceil(segment.length / charsPerToken);
995
- }
996
- function getLanguageSpecificCharsPerToken(segment, languageConfigs) {
997
- for (const config of languageConfigs) if (config.pattern.test(segment)) return config.averageCharsPerToken;
998
- }
999
- function getCharacterCount(text) {
1000
- return Array.from(text).length;
1001
- }
1002
-
1003
- // ../memory/dist/chunk-SUU4IAZJ.js
1042
+ // ../memory/dist/chunk-4KPXPQX3.js
1004
1043
  function formatRelativeTime(date, currentDate) {
1005
1044
  const diffMs = currentDate.getTime() - date.getTime();
1006
1045
  const diffDays = Math.floor(diffMs / (1e3 * 60 * 60 * 24));
@@ -1285,6 +1324,97 @@ function createActivationMarker(params) {
1285
1324
  }
1286
1325
  };
1287
1326
  }
1327
+ var ENCRYPTED_CONTENT_KEY = "encryptedContent";
1328
+ var ENCRYPTED_CONTENT_REDACTION_THRESHOLD = 256;
1329
+ var DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS = 1e4;
1330
+ function isObjectLike(value) {
1331
+ return typeof value === "object" && value !== null;
1332
+ }
1333
+ function sanitizeToolResultValue(value, seen = /* @__PURE__ */ new WeakMap()) {
1334
+ if (!isObjectLike(value)) {
1335
+ return value;
1336
+ }
1337
+ if (seen.has(value)) {
1338
+ return seen.get(value);
1339
+ }
1340
+ if (Array.isArray(value)) {
1341
+ const sanitizedArray = [];
1342
+ seen.set(value, sanitizedArray);
1343
+ for (const item of value) {
1344
+ sanitizedArray.push(sanitizeToolResultValue(item, seen));
1345
+ }
1346
+ return sanitizedArray;
1347
+ }
1348
+ const sanitizedObject = {};
1349
+ seen.set(value, sanitizedObject);
1350
+ for (const [key, entry] of Object.entries(value)) {
1351
+ if (key === ENCRYPTED_CONTENT_KEY && typeof entry === "string" && entry.length > ENCRYPTED_CONTENT_REDACTION_THRESHOLD) {
1352
+ sanitizedObject[key] = `[stripped encryptedContent: ${entry.length} characters]`;
1353
+ continue;
1354
+ }
1355
+ sanitizedObject[key] = sanitizeToolResultValue(entry, seen);
1356
+ }
1357
+ return sanitizedObject;
1358
+ }
1359
+ function stringifyToolResult(value) {
1360
+ if (typeof value === "string") {
1361
+ return value;
1362
+ }
1363
+ const sanitized = sanitizeToolResultValue(value);
1364
+ try {
1365
+ return JSON.stringify(sanitized, null, 2);
1366
+ } catch {
1367
+ return String(sanitized);
1368
+ }
1369
+ }
1370
+ function resolveToolResultValue(part, invocationResult) {
1371
+ const mastraMetadata = part?.providerMetadata?.mastra;
1372
+ if (mastraMetadata && typeof mastraMetadata === "object" && "modelOutput" in mastraMetadata) {
1373
+ return {
1374
+ value: mastraMetadata.modelOutput,
1375
+ usingStoredModelOutput: true
1376
+ };
1377
+ }
1378
+ return {
1379
+ value: invocationResult,
1380
+ usingStoredModelOutput: false
1381
+ };
1382
+ }
1383
+ function truncateStringByTokens(text, maxTokens) {
1384
+ if (!text || maxTokens <= 0) {
1385
+ return "";
1386
+ }
1387
+ const totalTokens = estimateTokenCount(text);
1388
+ if (totalTokens <= maxTokens) {
1389
+ return text;
1390
+ }
1391
+ const buildCandidate = (sliceEnd) => {
1392
+ const visible = text.slice(0, sliceEnd);
1393
+ const omittedChars = text.length - sliceEnd;
1394
+ return `${visible}
1395
+ ... [truncated ~${totalTokens - estimateTokenCount(visible)} tokens / ${omittedChars} characters]`;
1396
+ };
1397
+ let low = 0;
1398
+ let high = text.length;
1399
+ let best = buildCandidate(0);
1400
+ while (low <= high) {
1401
+ const mid = Math.floor((low + high) / 2);
1402
+ const candidate = buildCandidate(mid);
1403
+ const candidateTokens = estimateTokenCount(candidate);
1404
+ if (candidateTokens <= maxTokens) {
1405
+ best = candidate;
1406
+ low = mid + 1;
1407
+ } else {
1408
+ high = mid - 1;
1409
+ }
1410
+ }
1411
+ return best;
1412
+ }
1413
+ function formatToolResultForObserver(value, options) {
1414
+ const serialized = stringifyToolResult(value);
1415
+ const maxTokens = options?.maxTokens ?? DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS;
1416
+ return truncateStringByTokens(serialized, maxTokens);
1417
+ }
1288
1418
  var OBSERVER_EXTRACTION_INSTRUCTIONS = `CRITICAL: DISTINGUISH USER ASSERTIONS FROM QUESTIONS
1289
1419
 
1290
1420
  When the user TELLS you something about themselves, mark it as an assertion:
@@ -1757,6 +1887,7 @@ function formatObserverAttachmentPlaceholder(part, counter) {
1757
1887
  }
1758
1888
  function formatObserverMessage(msg, counter, options) {
1759
1889
  const maxLen = options?.maxPartLength;
1890
+ const maxToolResultTokens = options?.maxToolResultTokens ?? DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS;
1760
1891
  const timestamp = formatObserverTimestamp(msg.createdAt);
1761
1892
  const role = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);
1762
1893
  const timestampStr = timestamp ? ` (${timestamp})` : "";
@@ -1770,7 +1901,11 @@ function formatObserverMessage(msg, counter, options) {
1770
1901
  if (part.type === "tool-invocation") {
1771
1902
  const inv = part.toolInvocation;
1772
1903
  if (inv.state === "result") {
1773
- const resultStr = JSON.stringify(inv.result, null, 2);
1904
+ const { value: resultForObserver } = resolveToolResultValue(
1905
+ part,
1906
+ inv.result
1907
+ );
1908
+ const resultStr = formatToolResultForObserver(resultForObserver, { maxTokens: maxToolResultTokens });
1774
1909
  return `[Tool Result: ${inv.toolName}]
1775
1910
  ${maybeTruncate(resultStr, maxLen)}`;
1776
1911
  }
@@ -1811,12 +1946,12 @@ function formatMessagesForObserver(messages, options) {
1811
1946
  const counter = { nextImageId: 1, nextFileId: 1 };
1812
1947
  return messages.map((msg) => formatObserverMessage(msg, counter, options).text).filter(Boolean).join("\n\n---\n\n");
1813
1948
  }
1814
- function buildObserverHistoryMessage(messages) {
1949
+ function buildObserverHistoryMessage(messages, options) {
1815
1950
  const counter = { nextImageId: 1, nextFileId: 1 };
1816
1951
  const content = [{ type: "text", text: "## New Message History to Observe\n\n" }];
1817
1952
  let visibleCount = 0;
1818
1953
  messages.forEach((message) => {
1819
- const formatted = formatObserverMessage(message, counter);
1954
+ const formatted = formatObserverMessage(message, counter, options);
1820
1955
  if (!formatted.text && formatted.attachments.length === 0) return;
1821
1956
  if (visibleCount > 0) {
1822
1957
  content.push({ type: "text", text: "\n\n---\n\n" });
@@ -1837,7 +1972,7 @@ function maybeTruncate(str, maxLen) {
1837
1972
  return `${truncated}
1838
1973
  ... [truncated ${remaining} characters]`;
1839
1974
  }
1840
- function buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder) {
1975
+ function buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder, options) {
1841
1976
  const counter = { nextImageId: 1, nextFileId: 1 };
1842
1977
  const content = [
1843
1978
  {
@@ -1855,7 +1990,7 @@ The following messages are from ${threadOrder.length} different conversation thr
1855
1990
  const threadContent = [];
1856
1991
  let visibleCount = 0;
1857
1992
  messages.forEach((message) => {
1858
- const formatted = formatObserverMessage(message, counter);
1993
+ const formatted = formatObserverMessage(message, counter, options);
1859
1994
  if (!formatted.text && formatted.attachments.length === 0) return;
1860
1995
  if (visibleCount > 0) {
1861
1996
  threadContent.push({ type: "text", text: "\n\n---\n\n" });
@@ -3493,17 +3628,7 @@ var TokenCounter = class _TokenCounter {
3493
3628
  return tokens;
3494
3629
  }
3495
3630
  resolveToolResultForTokenCounting(part, invocationResult) {
3496
- const mastraMetadata = part?.providerMetadata?.mastra;
3497
- if (mastraMetadata && typeof mastraMetadata === "object" && "modelOutput" in mastraMetadata) {
3498
- return {
3499
- value: mastraMetadata.modelOutput,
3500
- usingStoredModelOutput: true
3501
- };
3502
- }
3503
- return {
3504
- value: invocationResult,
3505
- usingStoredModelOutput: false
3506
- };
3631
+ return resolveToolResultValue(part, invocationResult);
3507
3632
  }
3508
3633
  estimateImageAssetTokens(part, asset, kind) {
3509
3634
  const modelContext = this.getModelContext();
@@ -3742,19 +3867,13 @@ var TokenCounter = class _TokenCounter {
3742
3867
  invocation.result
3743
3868
  );
3744
3869
  if (resultForCounting !== void 0) {
3745
- if (typeof resultForCounting === "string") {
3746
- tokens += this.readOrPersistPartEstimate(
3747
- part,
3748
- usingStoredModelOutput ? "tool-result-model-output" : "tool-result",
3749
- resultForCounting
3750
- );
3751
- } else {
3752
- const resultJson = JSON.stringify(resultForCounting);
3753
- tokens += this.readOrPersistPartEstimate(
3754
- part,
3755
- usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json",
3756
- resultJson
3757
- );
3870
+ const formattedResult = formatToolResultForObserver(resultForCounting);
3871
+ tokens += this.readOrPersistPartEstimate(
3872
+ part,
3873
+ usingStoredModelOutput ? "tool-result-model-output-json" : "tool-result-json",
3874
+ formattedResult
3875
+ );
3876
+ if (typeof resultForCounting !== "string") {
3758
3877
  overheadDelta -= 12;
3759
3878
  }
3760
3879
  }
@@ -3868,6 +3987,14 @@ function omDebug(msg) {
3868
3987
  } catch {
3869
3988
  }
3870
3989
  }
3990
+ function getLatestStepParts(parts) {
3991
+ for (let i = parts.length - 1; i >= 0; i--) {
3992
+ if (parts[i]?.type === "step-start") {
3993
+ return parts.slice(i + 1);
3994
+ }
3995
+ }
3996
+ return parts;
3997
+ }
3871
3998
  function omError(msg, err) {
3872
3999
  const errStr = err instanceof Error ? err.stack ?? err.message : err !== void 0 ? String(err) : "";
3873
4000
  const full = errStr ? `${msg}: ${errStr}` : msg;
@@ -5314,38 +5441,51 @@ ${unreflectedContent}` : bufferedReflection;
5314
5441
  if (currentDate) {
5315
5442
  optimized = addRelativeTimeToObservations(optimized, currentDate);
5316
5443
  }
5317
- let content = `
5318
- ${OBSERVATION_CONTEXT_PROMPT}
5444
+ const messages = [`${OBSERVATION_CONTEXT_PROMPT}
5319
5445
 
5320
- <observations>
5321
- ${optimized}
5322
- </observations>
5323
-
5324
- ${OBSERVATION_CONTEXT_INSTRUCTIONS}`;
5446
+ ${OBSERVATION_CONTEXT_INSTRUCTIONS}`];
5325
5447
  if (unobservedContextBlocks) {
5326
- content += `
5327
-
5328
- The following content is from OTHER conversations different from the current conversation, they're here for reference, but they're not necessarily your focus:
5448
+ messages.push(
5449
+ `The following content is from OTHER conversations different from the current conversation, they're here for reference, but they're not necessarily your focus:
5329
5450
  START_OTHER_CONVERSATIONS_BLOCK
5330
5451
  ${unobservedContextBlocks}
5331
- END_OTHER_CONVERSATIONS_BLOCK`;
5452
+ END_OTHER_CONVERSATIONS_BLOCK`
5453
+ );
5454
+ }
5455
+ const observationChunks = this.splitObservationContextChunks(optimized);
5456
+ if (observationChunks.length > 0) {
5457
+ messages.push("<observations>", ...observationChunks);
5332
5458
  }
5333
5459
  if (currentTask) {
5334
- content += `
5335
-
5336
- <current-task>
5460
+ messages.push(`<current-task>
5337
5461
  ${currentTask}
5338
- </current-task>`;
5462
+ </current-task>`);
5339
5463
  }
5340
5464
  if (suggestedResponse) {
5341
- content += `
5342
-
5343
- <suggested-response>
5465
+ messages.push(`<suggested-response>
5344
5466
  ${suggestedResponse}
5345
- </suggested-response>
5346
- `;
5467
+ </suggested-response>`);
5347
5468
  }
5348
- return content;
5469
+ return messages;
5470
+ }
5471
+ splitObservationContextChunks(observations) {
5472
+ const trimmed = observations.trim();
5473
+ if (!trimmed) {
5474
+ return [];
5475
+ }
5476
+ return trimmed.split(/\n{2,}--- message boundary \(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z\) ---\n{2,}/).map((chunk) => chunk.trim()).filter(Boolean);
5477
+ }
5478
+ /**
5479
+ * Create a message boundary delimiter with an ISO 8601 date.
5480
+ * The date should be the lastObservedAt timestamp — the latest message
5481
+ * timestamp that was observed to produce the observations following this boundary.
5482
+ */
5483
+ static createMessageBoundary(date) {
5484
+ return `
5485
+
5486
+ --- message boundary (${date.toISOString()}) ---
5487
+
5488
+ `;
5349
5489
  }
5350
5490
  /**
5351
5491
  * Get threadId and resourceId from either RequestContext or MessageList
@@ -5783,7 +5923,7 @@ ${suggestedResponse}
5783
5923
  if (!record.activeObservations) {
5784
5924
  return;
5785
5925
  }
5786
- const observationSystemMessage = this.formatObservationsForContext(
5926
+ const observationSystemMessages = this.formatObservationsForContext(
5787
5927
  record.activeObservations,
5788
5928
  currentTask,
5789
5929
  suggestedResponse,
@@ -5791,7 +5931,7 @@ ${suggestedResponse}
5791
5931
  currentDate
5792
5932
  );
5793
5933
  messageList.clearSystemMessages("observational-memory");
5794
- messageList.addSystem(observationSystemMessage, "observational-memory");
5934
+ messageList.addSystem(observationSystemMessages, "observational-memory");
5795
5935
  const continuationMessage = {
5796
5936
  id: `om-continuation`,
5797
5937
  role: "user",
@@ -6067,12 +6207,20 @@ ${suggestedResponse}
6067
6207
  const sealedIds = /* @__PURE__ */ new Set([...stateSealedIds, ...staticSealedIds]);
6068
6208
  state.sealedIds = sealedIds;
6069
6209
  const lockKey = this.getLockKey(threadId, resourceId);
6210
+ const lastMessage = allMessages[allMessages.length - 1];
6211
+ const latestStepParts = getLatestStepParts(lastMessage?.content?.parts ?? []);
6212
+ const hasIncompleteToolCalls = latestStepParts.some(
6213
+ (part) => part?.type === "tool-invocation" && part.toolInvocation?.state === "call"
6214
+ );
6215
+ omDebug(
6216
+ `[OM:deferred-check] hasIncompleteToolCalls=${hasIncompleteToolCalls}, latestStepPartsCount=${latestStepParts.length}`
6217
+ );
6070
6218
  if (this.isAsyncObservationEnabled() && totalPendingTokens < threshold) {
6071
6219
  const shouldTrigger = this.shouldTriggerAsyncObservation(totalPendingTokens, lockKey, record, threshold);
6072
6220
  omDebug(
6073
- `[OM:async-obs] belowThreshold: pending=${totalPendingTokens}, unbuffered=${unbufferedPendingTokens}, threshold=${threshold}, shouldTrigger=${shouldTrigger}, isBufferingObs=${record.isBufferingObservation}, lastBufferedAt=${record.lastBufferedAtTokens}`
6221
+ `[OM:async-obs] belowThreshold: pending=${totalPendingTokens}, unbuffered=${unbufferedPendingTokens}, threshold=${threshold}, shouldTrigger=${shouldTrigger}, isBufferingObs=${record.isBufferingObservation}, lastBufferedAt=${record.lastBufferedAtTokens}, hasIncompleteToolCalls=${hasIncompleteToolCalls}`
6074
6222
  );
6075
- if (shouldTrigger) {
6223
+ if (shouldTrigger && !hasIncompleteToolCalls) {
6076
6224
  void this.startAsyncBufferedObservation(
6077
6225
  record,
6078
6226
  threadId,
@@ -6086,9 +6234,9 @@ ${suggestedResponse}
6086
6234
  } else if (this.isAsyncObservationEnabled()) {
6087
6235
  const shouldTrigger = this.shouldTriggerAsyncObservation(totalPendingTokens, lockKey, record, threshold);
6088
6236
  omDebug(
6089
- `[OM:async-obs] atOrAboveThreshold: pending=${totalPendingTokens}, unbuffered=${unbufferedPendingTokens}, threshold=${threshold}, step=${stepNumber}, shouldTrigger=${shouldTrigger}`
6237
+ `[OM:async-obs] atOrAboveThreshold: pending=${totalPendingTokens}, unbuffered=${unbufferedPendingTokens}, threshold=${threshold}, step=${stepNumber}, shouldTrigger=${shouldTrigger}, hasIncompleteToolCalls=${hasIncompleteToolCalls}`
6090
6238
  );
6091
- if (shouldTrigger) {
6239
+ if (shouldTrigger && !hasIncompleteToolCalls) {
6092
6240
  void this.startAsyncBufferedObservation(
6093
6241
  record,
6094
6242
  threadId,
@@ -6103,7 +6251,7 @@ ${suggestedResponse}
6103
6251
  if (stepNumber > 0) {
6104
6252
  await this.handlePerStepSave(messageList, sealedIds, threadId, resourceId, state);
6105
6253
  }
6106
- if (stepNumber > 0 && totalPendingTokens >= threshold) {
6254
+ if (stepNumber > 0 && !hasIncompleteToolCalls && totalPendingTokens >= threshold) {
6107
6255
  reproCaptureDetails.thresholdReached = true;
6108
6256
  const { observationSucceeded, updatedRecord, activatedMessageIds } = await this.handleThresholdReached(
6109
6257
  messageList,
@@ -6461,16 +6609,14 @@ ${cleanObservations}
6461
6609
  * merge the observations into that section to reduce token usage.
6462
6610
  * Otherwise, append as a new section.
6463
6611
  */
6464
- replaceOrAppendThreadSection(existingObservations, _threadId, newThreadSection) {
6612
+ replaceOrAppendThreadSection(existingObservations, _threadId, newThreadSection, lastObservedAt) {
6465
6613
  if (!existingObservations) {
6466
6614
  return newThreadSection;
6467
6615
  }
6468
6616
  const threadIdMatch = newThreadSection.match(/<thread id="([^"]+)">/);
6469
6617
  const dateMatch = newThreadSection.match(/Date:\s*([A-Za-z]+\s+\d+,\s+\d+)/);
6470
6618
  if (!threadIdMatch || !dateMatch) {
6471
- return `${existingObservations}
6472
-
6473
- ${newThreadSection}`;
6619
+ return `${existingObservations}${_ObservationalMemory.createMessageBoundary(lastObservedAt)}${newThreadSection}`;
6474
6620
  }
6475
6621
  const newThreadId = threadIdMatch[1];
6476
6622
  const newDate = dateMatch[1];
@@ -6505,9 +6651,7 @@ ${threadClose}`;
6505
6651
  }
6506
6652
  }
6507
6653
  }
6508
- return `${existingObservations}
6509
-
6510
- ${newThreadSection}`;
6654
+ return `${existingObservations}${_ObservationalMemory.createMessageBoundary(lastObservedAt)}${newThreadSection}`;
6511
6655
  }
6512
6656
  /**
6513
6657
  * Sort threads by their oldest unobserved message.
@@ -6521,7 +6665,7 @@ ${newThreadSection}`;
6521
6665
  );
6522
6666
  return { threadId, oldestTimestamp };
6523
6667
  }).sort((a, b) => a.oldestTimestamp - b.oldestTimestamp);
6524
- return threadOrder.map((t) => t.threadId);
6668
+ return threadOrder.map((t2) => t2.threadId);
6525
6669
  }
6526
6670
  /**
6527
6671
  * Do synchronous observation (fallback when no buffering)
@@ -6590,19 +6734,22 @@ ${newThreadSection}`;
6590
6734
  priorSuggestedResponse: threadOMMetadata?.suggestedResponse,
6591
6735
  wasTruncated
6592
6736
  });
6737
+ const lastObservedAt = this.getMaxMessageTimestamp(messagesToObserve);
6593
6738
  const existingObservations = freshRecord?.activeObservations ?? record.activeObservations ?? "";
6594
6739
  let newObservations;
6595
6740
  if (this.scope === "resource") {
6596
6741
  const threadSection = await this.wrapWithThreadTag(threadId, result.observations);
6597
- newObservations = this.replaceOrAppendThreadSection(existingObservations, threadId, threadSection);
6742
+ newObservations = this.replaceOrAppendThreadSection(
6743
+ existingObservations,
6744
+ threadId,
6745
+ threadSection,
6746
+ lastObservedAt
6747
+ );
6598
6748
  } else {
6599
- newObservations = existingObservations ? `${existingObservations}
6600
-
6601
- ${result.observations}` : result.observations;
6749
+ newObservations = existingObservations ? `${existingObservations}${_ObservationalMemory.createMessageBoundary(lastObservedAt)}${result.observations}` : result.observations;
6602
6750
  }
6603
6751
  let totalTokenCount = this.tokenCounter.countObservations(newObservations);
6604
6752
  const cycleObservationTokens = this.tokenCounter.countObservations(result.observations);
6605
- const lastObservedAt = this.getMaxMessageTimestamp(messagesToObserve);
6606
6753
  const newMessageIds = messagesToObserve.map((m) => m.id);
6607
6754
  const existingIds = freshRecord?.observedMessageIds ?? record.observedMessageIds ?? [];
6608
6755
  const allObservedIds = [.../* @__PURE__ */ new Set([...Array.isArray(existingIds) ? existingIds : [], ...newMessageIds])];
@@ -7496,9 +7643,14 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
7496
7643
  if (!obsResult) continue;
7497
7644
  const { threadId, threadMessages, result } = obsResult;
7498
7645
  cycleObservationTokens += this.tokenCounter.countObservations(result.observations);
7499
- const threadSection = await this.wrapWithThreadTag(threadId, result.observations);
7500
- currentObservations = this.replaceOrAppendThreadSection(currentObservations, threadId, threadSection);
7501
7646
  const threadLastObservedAt = this.getMaxMessageTimestamp(threadMessages);
7647
+ const threadSection = await this.wrapWithThreadTag(threadId, result.observations);
7648
+ currentObservations = this.replaceOrAppendThreadSection(
7649
+ currentObservations,
7650
+ threadId,
7651
+ threadSection,
7652
+ threadLastObservedAt
7653
+ );
7502
7654
  const thread = await this.storage.getThreadById({ threadId });
7503
7655
  if (thread) {
7504
7656
  const newMetadata = setThreadOMMetadata(thread.metadata, {
@@ -7942,7 +8094,29 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
7942
8094
  return this.reflectionConfig;
7943
8095
  }
7944
8096
  };
7945
-
7946
- export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, extractCurrentTask, formatMessagesForObserver, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput };
7947
- //# sourceMappingURL=observational-memory-XXD6E2SO-TGAG7QCA.js.map
7948
- //# sourceMappingURL=observational-memory-XXD6E2SO-TGAG7QCA.js.map
8097
+ var BOUNDARY_WITH_DATE_RE = /\n{2,}--- message boundary \((\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z)\) ---\n{2,}/;
8098
+ function getObservationsAsOf(activeObservations, asOf) {
8099
+ const trimmed = activeObservations.trim();
8100
+ if (!trimmed) return "";
8101
+ const parts = trimmed.split(BOUNDARY_WITH_DATE_RE);
8102
+ const chunks = [];
8103
+ const firstChunk = parts[0]?.trim();
8104
+ if (firstChunk) {
8105
+ chunks.push(firstChunk);
8106
+ }
8107
+ for (let i = 1; i < parts.length; i += 2) {
8108
+ const dateStr = parts[i];
8109
+ const chunk = parts[i + 1]?.trim();
8110
+ if (!chunk) continue;
8111
+ const boundaryDate = new Date(dateStr);
8112
+ if (isNaN(boundaryDate.getTime())) continue;
8113
+ if (boundaryDate <= asOf) {
8114
+ chunks.push(chunk);
8115
+ }
8116
+ }
8117
+ return chunks.join("\n\n");
8118
+ }
8119
+
8120
+ export { OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, e, extractCurrentTask, formatMessagesForObserver, getObservationsAsOf, hasCurrentTaskSection, optimizeObservationsForContext, parseObserverOutput };
8121
+ //# sourceMappingURL=chunk-KZAB4IB3.js.map
8122
+ //# sourceMappingURL=chunk-KZAB4IB3.js.map