@gram-ai/elements 1.28.0 → 1.30.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.
Files changed (60) hide show
  1. package/dist/components/MessageContent.d.ts +20 -0
  2. package/dist/components/MessageContent.parser.d.ts +12 -0
  3. package/dist/components/MessageContent.test.d.ts +1 -0
  4. package/dist/elements.cjs +1 -1
  5. package/dist/elements.css +1 -1
  6. package/dist/elements.js +14 -13
  7. package/dist/{index-C4bFBGfl.cjs → index-COzPF-WM.cjs} +45 -45
  8. package/dist/index-COzPF-WM.cjs.map +1 -0
  9. package/dist/{index-D93pV0_o.js → index-CRhpKl-G.js} +5218 -5201
  10. package/dist/index-CRhpKl-G.js.map +1 -0
  11. package/dist/{index-CtZz13Cf.js → index-QUz5guSg.js} +11835 -11604
  12. package/dist/index-QUz5guSg.js.map +1 -0
  13. package/dist/index-fVcTljYT.cjs +194 -0
  14. package/dist/index-fVcTljYT.cjs.map +1 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/lib/contextCompaction.d.ts +58 -0
  17. package/dist/lib/contextCompaction.test.d.ts +1 -0
  18. package/dist/lib/errorTracking.config.d.ts +2 -0
  19. package/dist/lib/tools.byte-cap.test.d.ts +1 -0
  20. package/dist/lib/tools.d.ts +19 -0
  21. package/dist/lib/tools.test.d.ts +1 -0
  22. package/dist/plugins/index.d.ts +4 -1
  23. package/dist/plugins/index.test.d.ts +1 -0
  24. package/dist/plugins.cjs +1 -1
  25. package/dist/plugins.js +1 -1
  26. package/dist/{profiler-Ccma0l1p.js → profiler-DifNjGGB.js} +2 -2
  27. package/dist/{profiler-Ccma0l1p.js.map → profiler-DifNjGGB.js.map} +1 -1
  28. package/dist/{profiler-CjNa3A1d.cjs → profiler-KLtVMM14.cjs} +2 -2
  29. package/dist/{profiler-CjNa3A1d.cjs.map → profiler-KLtVMM14.cjs.map} +1 -1
  30. package/dist/{startRecording-DAURU74n.js → startRecording-C6xu9UA9.js} +2 -2
  31. package/dist/{startRecording-DAURU74n.js.map → startRecording-C6xu9UA9.js.map} +1 -1
  32. package/dist/{startRecording-jSovclaq.cjs → startRecording-YENzw_0G.cjs} +2 -2
  33. package/dist/{startRecording-jSovclaq.cjs.map → startRecording-YENzw_0G.cjs.map} +1 -1
  34. package/dist/types/index.d.ts +49 -0
  35. package/dist/types/plugins.d.ts +5 -0
  36. package/package.json +2 -2
  37. package/src/components/MessageContent.parser.ts +39 -0
  38. package/src/components/MessageContent.test.ts +110 -0
  39. package/src/components/MessageContent.tsx +82 -0
  40. package/src/contexts/ElementsProvider.tsx +57 -7
  41. package/src/index.ts +2 -0
  42. package/src/lib/contextCompaction.test.ts +201 -0
  43. package/src/lib/contextCompaction.ts +211 -0
  44. package/src/lib/errorTracking.config.ts +2 -0
  45. package/src/lib/errorTracking.ts +1 -1
  46. package/src/lib/tools.byte-cap.test.ts +132 -0
  47. package/src/lib/tools.test.ts +259 -0
  48. package/src/lib/tools.ts +122 -0
  49. package/src/plugins/chart/index.ts +1 -0
  50. package/src/plugins/chart/ui/bar-chart.tsx +9 -1
  51. package/src/plugins/generative-ui/index.ts +1 -0
  52. package/src/plugins/index.test.ts +62 -0
  53. package/src/plugins/index.ts +14 -1
  54. package/src/types/index.ts +55 -0
  55. package/src/types/plugins.ts +6 -0
  56. package/dist/index-BmTGnEaV.cjs +0 -190
  57. package/dist/index-BmTGnEaV.cjs.map +0 -1
  58. package/dist/index-C4bFBGfl.cjs.map +0 -1
  59. package/dist/index-CtZz13Cf.js.map +0 -1
  60. package/dist/index-D93pV0_o.js.map +0 -1
@@ -268,6 +268,13 @@ export interface ElementsConfig {
268
268
  */
269
269
  tools?: ToolsConfig;
270
270
 
271
+ /**
272
+ * Configuration for automatic conversation compaction when the estimated
273
+ * input size approaches the model's context window. Defaults are safe for
274
+ * all models; override per-page to tighten or disable.
275
+ */
276
+ contextCompaction?: ContextCompactionConfig;
277
+
271
278
  /**
272
279
  * Configuration for chat history and thread persistence.
273
280
  * When enabled, conversations are saved and the thread list is shown.
@@ -690,6 +697,54 @@ export interface ToolsConfig {
690
697
  * }
691
698
  */
692
699
  toolsToInclude?: ToolsFilter;
700
+
701
+ /**
702
+ * Maximum UTF-8 byte size for any single tool call's result. Results larger
703
+ * than this are truncated with a head+tail preserving strategy and a notice
704
+ * suffix before being added to the conversation. Prevents one greedy tool
705
+ * call (e.g. a wide log search) from filling the model's context window.
706
+ *
707
+ * Omit or set to 0 to disable.
708
+ *
709
+ * @example
710
+ * tools: {
711
+ * maxOutputBytes: 50_000, // ~12.5K tokens per tool call
712
+ * }
713
+ */
714
+ maxOutputBytes?: number;
715
+ }
716
+
717
+ /**
718
+ * Configuration for automatic compaction of older conversation turns when the
719
+ * estimated input size approaches the model's context window. Prevents
720
+ * upstream 400 "prompt too long" errors without losing the system prompt or
721
+ * the most recent turns.
722
+ */
723
+ export interface ContextCompactionConfig {
724
+ /**
725
+ * Hard ceiling (in tokens) for the outbound request. Overrides the built-in
726
+ * per-model map. Use this when you know your upstream provider enforces a
727
+ * smaller limit than the model's nominal maximum.
728
+ */
729
+ maxTokens?: number;
730
+
731
+ /**
732
+ * Fraction of the model ceiling at which compaction kicks in. Defaults to
733
+ * 0.7 — leaves room for the assistant's response and some slack for the
734
+ * chars/4 token heuristic's error.
735
+ */
736
+ compactAtFraction?: number;
737
+
738
+ /**
739
+ * Number of most-recent messages preserved verbatim during compaction.
740
+ * Defaults to 4 (covers the current turn + its immediate predecessor).
741
+ */
742
+ keepRecent?: number;
743
+
744
+ /**
745
+ * Disable compaction entirely. Useful in tests and for opting out per-page.
746
+ */
747
+ disabled?: boolean;
693
748
  }
694
749
 
695
750
  export interface WelcomeConfig {
@@ -15,6 +15,12 @@ import { ComponentType } from "react";
15
15
  * 3. The code fence is rendered using the custom renderer
16
16
  */
17
17
  export interface Plugin {
18
+ /**
19
+ * Unique identifier for the plugin. Used by `recommended.except()` to
20
+ * selectively exclude plugins. Defaults to `language` if not set.
21
+ */
22
+ id?: string;
23
+
18
24
  /**
19
25
  * Any prompt that the plugin may need to add to the system prompt.
20
26
  * Will be appended to the built-in system prompt.