@gram-ai/elements 1.29.0 → 1.30.1

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 (45) 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-BzA55RRF.js → index-4kebYSVY.js} +7863 -7815
  8. package/dist/index-4kebYSVY.js.map +1 -0
  9. package/dist/{index-C4bFBGfl.cjs → index-COzPF-WM.cjs} +45 -45
  10. package/dist/index-COzPF-WM.cjs.map +1 -0
  11. package/dist/{index-D93pV0_o.js → index-CRhpKl-G.js} +5218 -5201
  12. package/dist/index-CRhpKl-G.js.map +1 -0
  13. package/dist/{index-CgO7wXs-.cjs → index-j7ZTyK_F.cjs} +49 -49
  14. package/dist/index-j7ZTyK_F.cjs.map +1 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/plugins/index.d.ts +4 -1
  17. package/dist/plugins/index.test.d.ts +1 -0
  18. package/dist/plugins.cjs +1 -1
  19. package/dist/plugins.js +1 -1
  20. package/dist/{profiler-BmAwBXpj.cjs → profiler-DQbQSZrm.cjs} +2 -2
  21. package/dist/{profiler-BmAwBXpj.cjs.map → profiler-DQbQSZrm.cjs.map} +1 -1
  22. package/dist/{profiler-BPCxiY-X.js → profiler-DS2JBj9s.js} +2 -2
  23. package/dist/{profiler-BPCxiY-X.js.map → profiler-DS2JBj9s.js.map} +1 -1
  24. package/dist/{startRecording-DXGt4fON.js → startRecording-BEVJ7NHn.js} +2 -2
  25. package/dist/{startRecording-DXGt4fON.js.map → startRecording-BEVJ7NHn.js.map} +1 -1
  26. package/dist/{startRecording-B0Xe2DOI.cjs → startRecording-BRRW8lGG.cjs} +2 -2
  27. package/dist/{startRecording-B0Xe2DOI.cjs.map → startRecording-BRRW8lGG.cjs.map} +1 -1
  28. package/dist/types/plugins.d.ts +5 -0
  29. package/package.json +2 -2
  30. package/src/components/MessageContent.parser.ts +39 -0
  31. package/src/components/MessageContent.test.ts +110 -0
  32. package/src/components/MessageContent.tsx +82 -0
  33. package/src/contexts/ElementsProvider.tsx +13 -3
  34. package/src/global.css +38 -12
  35. package/src/index.ts +2 -0
  36. package/src/plugins/chart/index.ts +1 -0
  37. package/src/plugins/chart/ui/bar-chart.tsx +9 -1
  38. package/src/plugins/generative-ui/index.ts +1 -0
  39. package/src/plugins/index.test.ts +62 -0
  40. package/src/plugins/index.ts +14 -1
  41. package/src/types/plugins.ts +6 -0
  42. package/dist/index-BzA55RRF.js.map +0 -1
  43. package/dist/index-C4bFBGfl.cjs.map +0 -1
  44. package/dist/index-CgO7wXs-.cjs.map +0 -1
  45. package/dist/index-D93pV0_o.js.map +0 -1
@@ -6,6 +6,7 @@ import { GenerativeUIRenderer } from "./component";
6
6
  * Use the language identifier 'ui' or 'json-render' in code blocks.
7
7
  */
8
8
  export const generativeUI: Plugin = {
9
+ id: "generative-ui",
9
10
  language: "ui",
10
11
  prompt: `Render structured data as visual UI using \`\`\`ui code blocks with valid JSON.
11
12
 
@@ -0,0 +1,62 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { recommended, type Plugin } from "./index";
3
+ import { chart } from "./chart";
4
+ import { generativeUI } from "./generative-ui";
5
+
6
+ describe("recommended", () => {
7
+ it("contains chart and generative-ui plugins", () => {
8
+ expect(recommended).toHaveLength(2);
9
+ expect(recommended).toContain(chart);
10
+ expect(recommended).toContain(generativeUI);
11
+ });
12
+
13
+ it("is usable as a plain array", () => {
14
+ const ids = recommended.map((p) => p.id);
15
+ expect(ids).toEqual(["chart", "generative-ui"]);
16
+ });
17
+ });
18
+
19
+ describe("recommended.except", () => {
20
+ it("excludes a plugin by id", () => {
21
+ const result = recommended.except("generative-ui");
22
+ expect(result).toHaveLength(1);
23
+ expect(result[0]).toBe(chart);
24
+ });
25
+
26
+ it("excludes multiple plugins", () => {
27
+ const result = recommended.except("chart", "generative-ui");
28
+ expect(result).toHaveLength(0);
29
+ });
30
+
31
+ it("returns all plugins when no ids match", () => {
32
+ const result = recommended.except("nonexistent");
33
+ expect(result).toHaveLength(2);
34
+ });
35
+
36
+ it("returns all plugins when called with no arguments", () => {
37
+ const result = recommended.except();
38
+ expect(result).toHaveLength(2);
39
+ });
40
+
41
+ it("is assignable to Plugin[] for backwards compatibility", () => {
42
+ // Consumers may have typed variables as Plugin[]
43
+ const plugins: Plugin[] = recommended.except("chart");
44
+ expect(plugins).toHaveLength(1);
45
+
46
+ // Spread into a plain array
47
+ const spread: Plugin[] = [...recommended];
48
+ expect(spread).toHaveLength(2);
49
+
50
+ // Nullish coalescing fallback (common pattern in ElementsProvider)
51
+ const config: { plugins?: Plugin[] } = {};
52
+ const resolved = config.plugins ?? recommended;
53
+ expect(resolved).toHaveLength(2);
54
+ });
55
+
56
+ it("does not match on language when id is set", () => {
57
+ // generative-ui has id="generative-ui" and language="ui"
58
+ // Excluding by language value "ui" should not match because id takes precedence
59
+ const result = recommended.except("ui");
60
+ expect(result).toHaveLength(2);
61
+ });
62
+ });
@@ -2,7 +2,20 @@ import type { Plugin } from "@/types/plugins";
2
2
  import { chart } from "./chart";
3
3
  import { generativeUI } from "./generative-ui";
4
4
 
5
- export const recommended: Plugin[] = [chart, generativeUI];
5
+ export type PluginList = Plugin[] & {
6
+ except(...ids: string[]): Plugin[];
7
+ };
8
+
9
+ function createPluginList(plugins: Plugin[]): PluginList {
10
+ const arr = [...plugins] as PluginList;
11
+ arr.except = (...ids: string[]) => {
12
+ const excluded = new Set(ids);
13
+ return arr.filter((p) => !excluded.has(p.id ?? p.language));
14
+ };
15
+ return arr;
16
+ }
17
+
18
+ export const recommended: PluginList = createPluginList([chart, generativeUI]);
6
19
  export { chart } from "./chart";
7
20
  export { generativeUI } from "./generative-ui";
8
21
 
@@ -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.