@gram-ai/elements 1.20.1 → 1.21.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 (82) hide show
  1. package/bin/cli.js +14 -12
  2. package/dist/components/Chat/stories/ConnectionConfiguration.stories.d.ts +2 -2
  3. package/dist/components/Chat/stories/{ColorScheme.stories.d.ts → ErrorBoundary.stories.d.ts} +4 -4
  4. package/dist/components/Chat/stories/ToolApproval.stories.d.ts +2 -0
  5. package/dist/components/assistant-ui/error-boundary.d.ts +28 -0
  6. package/dist/components/ui/dialog.d.ts +1 -1
  7. package/dist/components/ui/tooltip.d.ts +3 -1
  8. package/dist/constants/tailwind.d.ts +1 -0
  9. package/dist/contexts/portal-container-context.d.ts +2 -0
  10. package/dist/contexts/portal-container.d.ts +7 -0
  11. package/dist/elements.cjs +1 -160
  12. package/dist/elements.cjs.map +1 -1
  13. package/dist/elements.css +1 -1
  14. package/dist/elements.js +11 -47174
  15. package/dist/elements.js.map +1 -1
  16. package/dist/hooks/usePortalContainer.d.ts +8 -0
  17. package/dist/hooks/useSession.d.ts +1 -2
  18. package/dist/index-B48xzOEm.cjs +169 -0
  19. package/dist/index-B48xzOEm.cjs.map +1 -0
  20. package/dist/{index-DaF9fGY-.js → index-BwdTXSZG.js} +4 -3
  21. package/dist/{index-DaF9fGY-.js.map → index-BwdTXSZG.js.map} +1 -1
  22. package/dist/index-C-iaUGd_.js +54687 -0
  23. package/dist/index-C-iaUGd_.js.map +1 -0
  24. package/dist/{index-B52U8PL6.cjs → index-D8g4LkEy.cjs} +3 -3
  25. package/dist/{index-B52U8PL6.cjs.map → index-D8g4LkEy.cjs.map} +1 -1
  26. package/dist/index.d.ts +3 -1
  27. package/dist/lib/auth.d.ts +2 -2
  28. package/dist/lib/errorTracking.config.d.ts +16 -0
  29. package/dist/lib/errorTracking.d.ts +24 -0
  30. package/dist/lib/tools.d.ts +3 -2
  31. package/dist/plugins.cjs +1 -1
  32. package/dist/plugins.js +1 -1
  33. package/dist/profiler-WPgSewiM.js +278 -0
  34. package/dist/profiler-WPgSewiM.js.map +1 -0
  35. package/dist/profiler-j7uDglf5.cjs +2 -0
  36. package/dist/profiler-j7uDglf5.cjs.map +1 -0
  37. package/dist/startRecording-Cahc4WH4.cjs +3 -0
  38. package/dist/startRecording-Cahc4WH4.cjs.map +1 -0
  39. package/dist/startRecording-DpwlHYPJ.js +1212 -0
  40. package/dist/startRecording-DpwlHYPJ.js.map +1 -0
  41. package/dist/types/index.d.ts +45 -15
  42. package/package.json +16 -2
  43. package/src/components/Chat/index.tsx +39 -3
  44. package/src/components/Chat/stories/Composer.stories.tsx +0 -7
  45. package/src/components/Chat/stories/ConnectionConfiguration.stories.tsx +7 -14
  46. package/src/components/Chat/stories/CustomComponents.stories.tsx +0 -7
  47. package/src/components/Chat/stories/Density.stories.tsx +0 -7
  48. package/src/components/Chat/stories/ErrorBoundary.stories.tsx +202 -0
  49. package/src/components/Chat/stories/FrontendTools.stories.tsx +0 -7
  50. package/src/components/Chat/stories/Model.stories.tsx +0 -7
  51. package/src/components/Chat/stories/Plugins.stories.tsx +0 -7
  52. package/src/components/Chat/stories/Radius.stories.tsx +0 -7
  53. package/src/components/Chat/stories/ToolApproval.stories.tsx +51 -7
  54. package/src/components/Chat/stories/Tools.stories.tsx +0 -7
  55. package/src/components/Chat/stories/Variants.stories.tsx +5 -2
  56. package/src/components/Chat/stories/Welcome.stories.tsx +0 -8
  57. package/src/components/assistant-ui/assistant-modal.tsx +4 -1
  58. package/src/components/assistant-ui/assistant-sidecar.tsx +5 -5
  59. package/src/components/assistant-ui/attachment.tsx +1 -4
  60. package/src/components/assistant-ui/error-boundary.tsx +119 -0
  61. package/src/components/assistant-ui/thread-list.tsx +3 -1
  62. package/src/components/assistant-ui/thread.tsx +7 -8
  63. package/src/components/ui/dialog.tsx +10 -1
  64. package/src/components/ui/popover.tsx +10 -12
  65. package/src/components/ui/tooltip.tsx +7 -2
  66. package/src/constants/tailwind.ts +2 -0
  67. package/src/contexts/ElementsProvider.tsx +29 -2
  68. package/src/contexts/portal-container-context.ts +4 -0
  69. package/src/contexts/portal-container.tsx +20 -0
  70. package/src/global.css +129 -16
  71. package/src/hooks/useAuth.ts +6 -16
  72. package/src/hooks/usePortalContainer.ts +16 -0
  73. package/src/hooks/useSession.ts +1 -3
  74. package/src/index.ts +5 -0
  75. package/src/lib/api.test.ts +5 -5
  76. package/src/lib/auth.ts +4 -4
  77. package/src/lib/errorTracking.config.ts +16 -0
  78. package/src/lib/errorTracking.ts +104 -0
  79. package/src/lib/tools.ts +37 -8
  80. package/src/types/index.ts +48 -16
  81. package/src/vite-env.d.ts +3 -0
  82. package/src/components/Chat/stories/ColorScheme.stories.tsx +0 -52
package/bin/cli.js CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { execSync } from 'node:child_process'
4
- import { existsSync } from 'node:fs'
5
- import { resolve } from 'node:path'
4
+ import { existsSync, readFileSync } from 'node:fs'
5
+ import { resolve, dirname } from 'node:path'
6
+ import { fileURLToPath } from 'node:url'
6
7
 
7
8
  // Colors
8
9
  const c = {
@@ -20,15 +21,14 @@ const c = {
20
21
  white: '\x1b[37m',
21
22
  }
22
23
 
23
- const PEER_DEPS = [
24
- 'react',
25
- 'react-dom',
26
- 'motion',
27
- 'remark-gfm',
28
- 'zustand',
29
- 'vega',
30
- 'shiki',
31
- ]
24
+ // Read peer dependencies from package.json (excluding @types/* packages)
25
+ const __dirname = dirname(fileURLToPath(import.meta.url))
26
+ const packageJson = JSON.parse(
27
+ readFileSync(resolve(__dirname, '../package.json'), 'utf-8')
28
+ )
29
+ const PEER_DEPS = Object.keys(packageJson.peerDependencies || {}).filter(
30
+ (dep) => !dep.startsWith('@types/')
31
+ )
32
32
 
33
33
  const PACKAGE_NAME = '@gram-ai/elements'
34
34
 
@@ -110,7 +110,9 @@ ${c.dim}Package manager:${c.reset} ${c.cyan}${pm}${c.reset}
110
110
  `)
111
111
 
112
112
  // Install everything in one command
113
- console.log(`${c.yellow}○${c.reset} Installing ${c.cyan}@gram-ai/elements${c.reset} and peer dependencies...`)
113
+ console.log(
114
+ `${c.yellow}○${c.reset} Installing ${c.cyan}@gram-ai/elements${c.reset} and peer dependencies...`
115
+ )
114
116
  const allPackages = [...PEER_DEPS, PACKAGE_NAME]
115
117
  const cmd = getInstallCommand(pm, allPackages)
116
118
  if (!run(cmd)) {
@@ -1,10 +1,10 @@
1
- import { Chat } from '..';
2
1
  import { Meta, StoryFn } from '@storybook/react-vite';
2
+ import { Chat } from '..';
3
3
  declare const meta: Meta<typeof Chat>;
4
4
  export default meta;
5
5
  type Story = StoryFn<typeof Chat>;
6
6
  export declare const SystemPrompt: Story;
7
7
  export declare const WithImplicitSessionAuth: Story;
8
8
  export declare const WithExplicitSessionAuth: Story;
9
- export declare const WithExplicitAPIKeyAuth: Story;
9
+ export declare const WithStaticSessionAuth: Story;
10
10
  export declare const LanguageModel: Story;
@@ -1,8 +1,8 @@
1
- import { Chat } from '..';
2
1
  import { Meta, StoryFn } from '@storybook/react-vite';
2
+ import { Chat } from '..';
3
3
  declare const meta: Meta<typeof Chat>;
4
4
  export default meta;
5
5
  type Story = StoryFn<typeof Chat>;
6
- export declare const Light: Story;
7
- export declare const Dark: Story;
8
- export declare const System: Story;
6
+ export declare const Modal: Story;
7
+ export declare const Standalone: Story;
8
+ export declare const Sidecar: Story;
@@ -4,5 +4,7 @@ declare const meta: Meta<typeof Chat>;
4
4
  export default meta;
5
5
  type Story = StoryFn<typeof Chat>;
6
6
  export declare const SingleTool: Story;
7
+ export declare const SingleToolWithFunction: Story;
7
8
  export declare const MultipleGroupedTools: Story;
8
9
  export declare const FrontendTool: Story;
10
+ export declare const FrontendToolWithFunction: Story;
@@ -0,0 +1,28 @@
1
+ import { Component, ErrorInfo, ReactNode } from 'react';
2
+ interface ErrorBoundaryProps {
3
+ children: ReactNode;
4
+ fallback?: ReactNode;
5
+ onError?: (error: Error, errorInfo: ErrorInfo) => void;
6
+ onReset?: () => void;
7
+ }
8
+ interface ErrorBoundaryState {
9
+ hasError: boolean;
10
+ error: Error | null;
11
+ resetKey: number;
12
+ }
13
+ /**
14
+ * Global error boundary for the Elements library. Catches unexpected errors and renders a fallback UI.
15
+ * We wrap the assistant-modal, assistant-sidecar, and chat components with this error boundary.
16
+ * Each variant needs to have the error boundary rendered at the appropriate level e.g if using
17
+ * the widget variant, then the error screen must be rendered within the widget modal.
18
+ * TODO: We should add more granular error boundaries (e.g wrapping AssistantMessage, ThreadWelcome, etc.)
19
+ * TODO: We should also wrap ChatHistory, which may yield its own errors.
20
+ */
21
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
22
+ constructor(props: ErrorBoundaryProps);
23
+ static getDerivedStateFromError(error: Error): Partial<ErrorBoundaryState>;
24
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
25
+ handleRetry: () => void;
26
+ render(): ReactNode;
27
+ }
28
+ export {};
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import * as DialogPrimitive from '@radix-ui/react-dialog';
3
3
  declare function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
4
4
  declare function DialogTrigger({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>): import("react/jsx-runtime").JSX.Element;
5
- declare function DialogPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>): import("react/jsx-runtime").JSX.Element;
5
+ declare function DialogPortal({ container, ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>): import("react/jsx-runtime").JSX.Element;
6
6
  declare function DialogClose({ ...props }: React.ComponentProps<typeof DialogPrimitive.Close>): import("react/jsx-runtime").JSX.Element;
7
7
  declare function DialogOverlay({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Overlay>): import("react/jsx-runtime").JSX.Element;
8
8
  declare function DialogContent({ className, children, showCloseButton, ...props }: React.ComponentProps<typeof DialogPrimitive.Content> & {
@@ -3,5 +3,7 @@ import * as TooltipPrimitive from '@radix-ui/react-tooltip';
3
3
  declare function TooltipProvider({ delayDuration, ...props }: React.ComponentProps<typeof TooltipPrimitive.Provider>): import("react/jsx-runtime").JSX.Element;
4
4
  declare function Tooltip({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Root>): import("react/jsx-runtime").JSX.Element;
5
5
  declare function TooltipTrigger({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Trigger>): import("react/jsx-runtime").JSX.Element;
6
- declare function TooltipContent({ className, sideOffset, children, ...props }: React.ComponentProps<typeof TooltipPrimitive.Content>): import("react/jsx-runtime").JSX.Element;
6
+ declare function TooltipContent({ className, sideOffset, children, container, ...props }: React.ComponentProps<typeof TooltipPrimitive.Content> & {
7
+ container?: HTMLElement | null;
8
+ }): import("react/jsx-runtime").JSX.Element;
7
9
  export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
@@ -0,0 +1 @@
1
+ export declare const ROOT_SELECTOR = "gram-elements";
@@ -0,0 +1,2 @@
1
+ import { RefObject } from 'react';
2
+ export declare const PortalContainerContext: import('react').Context<RefObject<HTMLElement | null> | null>;
@@ -0,0 +1,7 @@
1
+ import { RefObject } from 'react';
2
+ import { PortalContainerContext } from './portal-container-context';
3
+ export { PortalContainerContext };
4
+ export declare function PortalContainerProvider({ containerRef, children, }: {
5
+ containerRef: RefObject<HTMLElement | null>;
6
+ children: React.ReactNode;
7
+ }): import("react/jsx-runtime").JSX.Element;