@gram-ai/elements 1.0.7 → 1.0.9

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.
@@ -1,25 +1,37 @@
1
- import { ChatModelAdapter } from '@assistant-ui/react';
2
- import { ComponentType, ReactNode } from 'react';
1
+ import { ToolCallMessagePartComponent } from '@assistant-ui/react';
2
+ import { ReactNode } from 'react';
3
+ import { z } from 'zod';
3
4
  export interface ElementsProviderProps {
4
5
  /**
5
6
  * The children to render.
6
7
  */
7
8
  children: ReactNode;
8
- /**
9
- * The API to use for the elements.
10
- * Can be a GramRuntimeApi or a CustomRuntimeApi.
11
- */
12
- api: GramRuntimeApi | CustomRuntimeApi;
13
9
  /**
14
10
  * Configuration object for the Elements library.
15
11
  */
16
12
  config: ElementsConfig;
17
13
  }
14
+ type ServerUrl = string;
18
15
  export interface ElementsConfig {
16
+ /**
17
+ * The project slug to use for the Elements library.
18
+ */
19
+ projectSlug: string;
20
+ /**
21
+ * The Gram Server URL to use for the Elements library.
22
+ * Can be retrieved from https://app.getgram.ai/{team}/{project}/mcp/{mcp_slug}
23
+ * Note: This config option will likely change in the future
24
+ */
25
+ mcp: ServerUrl;
26
+ /**
27
+ * Custom environment variable overrides for the Elements library.
28
+ * Will be used to override the environment variables for the MCP server.
29
+ */
30
+ environment?: Record<string, unknown>;
19
31
  /**
20
32
  * Whether to render the chat window inside of an expandable modal or a standalone chat window.
21
33
  */
22
- variant?: 'widget' | 'standalone' | 'sidecar';
34
+ variant?: 'widget' | 'standalone';
23
35
  /**
24
36
  * LLM model configuration.
25
37
  *
@@ -54,6 +66,11 @@ export interface ElementsConfig {
54
66
  */
55
67
  tools?: ToolsConfig;
56
68
  }
69
+ /**
70
+ * ModelConfig is used to configure model support in the Elements library.
71
+ *
72
+ * NOTE: Not yet implemented
73
+ */
57
74
  export interface ModelConfig {
58
75
  /**
59
76
  * The models available to the user.
@@ -65,6 +82,20 @@ export interface ModelConfig {
65
82
  */
66
83
  showModelPicker?: boolean;
67
84
  }
85
+ /**
86
+ * ToolsConfig is used to configure tool support in the Elements library.
87
+ * At the moment, you can override the default React components used by
88
+ * individual tool results.
89
+ *
90
+ * @example
91
+ * const config: ElementsConfig = {
92
+ * tools: {
93
+ * components: {
94
+ * "get_current_weather": WeatherComponent,
95
+ * },
96
+ * },
97
+ * }
98
+ */
68
99
  export interface ToolsConfig {
69
100
  /**
70
101
  * `components` can be used to override the default components used by the
@@ -81,7 +112,7 @@ export interface ToolsConfig {
81
112
  * },
82
113
  * }
83
114
  */
84
- components?: Record<string, ComponentType>;
115
+ components?: Record<string, ToolCallMessagePartComponent | undefined> | undefined;
85
116
  }
86
117
  export interface WelcomeConfig {
87
118
  /**
@@ -124,16 +155,30 @@ export interface ComposerConfig {
124
155
  placeholder: string;
125
156
  /**
126
157
  * Whether to enable attachments in the composer.
158
+ *
159
+ * NOTE: Not yet implemented
127
160
  */
128
161
  attachments: boolean;
129
162
  }
130
- export interface GramRuntimeApi {
131
- getSessionToken: () => Promise<string>;
132
- projectToken: string;
133
- }
134
- export type CustomRuntimeApi = ChatModelAdapter;
135
163
  export type ElementsContextType = {
136
164
  config: ElementsConfig;
137
165
  };
138
- export declare function isGramRuntimeApi(api: GramRuntimeApi | CustomRuntimeApi | undefined): api is GramRuntimeApi;
139
- export declare function isCustomRuntimeApi(api: GramRuntimeApi | CustomRuntimeApi | undefined): api is CustomRuntimeApi;
166
+ declare const ContentSchema: z.ZodUnion<readonly [z.ZodObject<{
167
+ type: z.ZodLiteral<"text">;
168
+ text: z.ZodString;
169
+ }, z.core.$strip>, z.ZodObject<{
170
+ type: z.ZodLiteral<"image">;
171
+ data: z.ZodString;
172
+ }, z.core.$strip>]>;
173
+ export type ToolCallResultContent = z.infer<typeof ContentSchema>;
174
+ export declare const ToolCallResultSchema: z.ZodUnion<[z.ZodObject<{
175
+ content: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
176
+ type: z.ZodLiteral<"text">;
177
+ text: z.ZodString;
178
+ }, z.core.$strip>, z.ZodObject<{
179
+ type: z.ZodLiteral<"image">;
180
+ data: z.ZodString;
181
+ }, z.core.$strip>]>>;
182
+ }, z.core.$strip>, z.ZodUndefined]>;
183
+ export type ToolCallResult = z.infer<typeof ToolCallResultSchema>;
184
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@gram-ai/elements",
3
3
  "description": "Gram Elements is a library of UI primitives for building chat-like experiences for MCP Servers.",
4
4
  "type": "module",
5
- "version": "1.0.7",
5
+ "version": "1.0.9",
6
6
  "main": "dist/index.js",
7
7
  "exports": {
8
8
  ".": {
@@ -49,24 +49,33 @@
49
49
  "zustand": "^5.0.0"
50
50
  },
51
51
  "dependencies": {
52
+ "@gram-ai/sdk": "^0.2.3",
53
+ "@openrouter/ai-sdk-provider": "^1.4.1",
52
54
  "@radix-ui/react-avatar": "^1.1.10",
53
55
  "@radix-ui/react-dialog": "^1.1.15",
54
56
  "@radix-ui/react-slot": "^1.2.3",
55
57
  "@radix-ui/react-tooltip": "^1.2.8",
58
+ "assistant-stream": "^0.2.42",
56
59
  "class-variance-authority": "^0.7.1",
57
60
  "clsx": "^2.1.1",
58
61
  "lucide-react": "^0.544.0",
59
- "tailwind-merge": "^3.3.1"
62
+ "sdk": "link:@types/@modelcontextprotocol/sdk",
63
+ "tailwind-merge": "^3.3.1",
64
+ "zod": "^4.1.13"
60
65
  },
61
66
  "devDependencies": {
67
+ "@ai-sdk/mcp": "^0.0.11",
62
68
  "@ai-sdk/openai": "^2.0.0-beta.5",
63
69
  "@assistant-ui/react": "^0.11.37",
70
+ "@assistant-ui/react-ai-sdk": "^1.1.16",
64
71
  "@assistant-ui/react-markdown": "^0.11.4",
65
72
  "@eslint/compat": "^2.0.0",
66
73
  "@eslint/js": "^9.39.1",
74
+ "@modelcontextprotocol/sdk": "^1.24.3",
67
75
  "@storybook/addon-docs": "^10.0.8",
68
76
  "@storybook/react-vite": "^10.0.8",
69
77
  "@tailwindcss/vite": "^4.1.13",
78
+ "@types/lodash.merge": "^4.6.9",
70
79
  "@types/node": "^24.10.1",
71
80
  "@vitejs/plugin-react": "^5.0.3",
72
81
  "ai": "5.0.90",
@@ -78,6 +87,7 @@
78
87
  "eslint-plugin-react-refresh": "^0.4.24",
79
88
  "eslint-plugin-storybook": "^10.1.4",
80
89
  "eslint-plugin-unused-imports": "^4.3.0",
90
+ "lodash.merge": "^4.6.2",
81
91
  "motion": "^12.23.14",
82
92
  "openai": "^6.9.1",
83
93
  "prettier": "^3.7.4",
@@ -1,33 +0,0 @@
1
- export interface ChatHandlerOptions {
2
- /**
3
- * The API key for the OpenAI-compatible provider.
4
- * Defaults to OPENAI_API_KEY environment variable.
5
- */
6
- apiKey?: string;
7
- /**
8
- * The base URL for the OpenAI-compatible API.
9
- * Use this for OpenRouter, Azure, or other compatible providers.
10
- * @example 'https://openrouter.ai/api/v1'
11
- */
12
- baseURL?: string;
13
- /**
14
- * The model to use for chat completions.
15
- * @default 'gpt-4o-mini'
16
- */
17
- model?: string;
18
- }
19
- /**
20
- * Creates a chat handler for Next.js API routes.
21
- * Returns OpenAI-compatible SSE streaming format for use with assistant-ui.
22
- *
23
- * @example
24
- * // app/api/chat/route.ts
25
- * import { createChatHandler } from '@gram-ai/elements/server'
26
- *
27
- * export const POST = createChatHandler({
28
- * apiKey: process.env.OPENROUTER_API_KEY,
29
- * baseURL: 'https://openrouter.ai/api/v1',
30
- * model: 'anthropic/claude-3.5-sonnet',
31
- * })
32
- */
33
- export declare function createChatHandler(options?: ChatHandlerOptions): (req: Request) => Promise<Response>;
@@ -1,18 +0,0 @@
1
- import { ChatModelAdapter } from '@assistant-ui/react';
2
- export interface FetchAdapterOptions {
3
- /**
4
- * The API endpoint to send chat requests to.
5
- * @default '/api/chat'
6
- */
7
- endpoint?: string;
8
- }
9
- /**
10
- * Creates a chat adapter that connects to an OpenAI-compatible API endpoint.
11
- * Handles the SSE streaming format used by OpenAI and compatible providers.
12
- *
13
- * @example
14
- * import { createFetchAdapter } from '@gram-ai/elements'
15
- *
16
- * const adapter = createFetchAdapter({ endpoint: '/api/chat' })
17
- */
18
- export declare function createFetchAdapter(options?: FetchAdapterOptions): ChatModelAdapter;
@@ -1,2 +0,0 @@
1
- import { CustomRuntimeApi, GramRuntimeApi } from '../types';
2
- export declare function createGramRuntimeFromApi(_: GramRuntimeApi): CustomRuntimeApi;