@gram-ai/elements 1.26.1 → 1.27.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.
- package/README.md +83 -15
- package/dist/components/Chat/stories/ConnectionConfiguration.stories.d.ts +1 -1
- package/dist/components/ui/calendar.d.ts +25 -0
- package/dist/components/ui/time-range-picker.d.ts +46 -0
- package/dist/components/ui/time-range-picker.stories.d.ts +37 -0
- package/dist/elements.cjs +1 -1
- package/dist/elements.css +1 -1
- package/dist/elements.js +18 -14
- package/dist/hooks/useModel.d.ts +2 -0
- package/dist/index-CP-wWZCV.cjs +172 -0
- package/dist/index-CP-wWZCV.cjs.map +1 -0
- package/dist/{index-DfqYP0CD.js → index-oO5BAmPI.js} +12578 -11964
- package/dist/index-oO5BAmPI.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/lib/auth.d.ts +12 -4
- package/dist/lib/models.d.ts +1 -1
- package/dist/{profiler-ZLr2-8s7.cjs → profiler-CEpc7O5Q.cjs} +2 -2
- package/dist/{profiler-ZLr2-8s7.cjs.map → profiler-CEpc7O5Q.cjs.map} +1 -1
- package/dist/{profiler-WoFj2UH8.js → profiler-ECh1zoXF.js} +2 -2
- package/dist/{profiler-WoFj2UH8.js.map → profiler-ECh1zoXF.js.map} +1 -1
- package/dist/server/bun.cjs +2 -0
- package/dist/server/bun.cjs.map +1 -0
- package/dist/server/bun.d.ts +8 -0
- package/dist/server/bun.js +26 -0
- package/dist/server/bun.js.map +1 -0
- package/dist/server/core.cjs +2 -0
- package/dist/server/core.cjs.map +1 -0
- package/dist/server/core.d.ts +37 -0
- package/dist/server/core.js +36 -0
- package/dist/server/core.js.map +1 -0
- package/dist/server/express.cjs +2 -0
- package/dist/server/express.cjs.map +1 -0
- package/dist/server/express.d.ts +9 -0
- package/dist/server/express.js +21 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/fastify.cjs +2 -0
- package/dist/server/fastify.cjs.map +1 -0
- package/dist/server/fastify.d.ts +9 -0
- package/dist/server/fastify.js +19 -0
- package/dist/server/fastify.js.map +1 -0
- package/dist/server/hono.cjs +2 -0
- package/dist/server/hono.cjs.map +1 -0
- package/dist/server/hono.d.ts +9 -0
- package/dist/server/hono.js +20 -0
- package/dist/server/hono.js.map +1 -0
- package/dist/server/nextjs.cjs +2 -0
- package/dist/server/nextjs.cjs.map +1 -0
- package/dist/server/nextjs.d.ts +8 -0
- package/dist/server/nextjs.js +26 -0
- package/dist/server/nextjs.js.map +1 -0
- package/dist/server/tanstack-start.cjs +2 -0
- package/dist/server/tanstack-start.cjs.map +1 -0
- package/dist/server/tanstack-start.d.ts +11 -0
- package/dist/server/tanstack-start.js +26 -0
- package/dist/server/tanstack-start.js.map +1 -0
- package/dist/server.cjs +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +10 -16
- package/dist/server.js +22 -29
- package/dist/server.js.map +1 -1
- package/dist/{startRecording-DzQo16WK.js → startRecording-CmZjjJoz.js} +2 -2
- package/dist/{startRecording-DzQo16WK.js.map → startRecording-CmZjjJoz.js.map} +1 -1
- package/dist/{startRecording-BGnWDInp.cjs → startRecording-qDCAu4Q0.cjs} +2 -2
- package/dist/{startRecording-BGnWDInp.cjs.map → startRecording-qDCAu4Q0.cjs.map} +1 -1
- package/dist/types/index.d.ts +22 -10
- package/package.json +68 -3
- package/src/components/Chat/stories/ConnectionConfiguration.stories.tsx +6 -8
- package/src/components/assistant-ui/thread.tsx +8 -14
- package/src/components/ui/calendar.tsx +262 -0
- package/src/components/ui/time-range-picker.stories.tsx +249 -0
- package/src/components/ui/time-range-picker.tsx +675 -0
- package/src/hooks/useAuth.ts +59 -7
- package/src/hooks/useFollowOnSuggestions.ts +7 -14
- package/src/hooks/useModel.ts +30 -0
- package/src/index.ts +17 -0
- package/src/lib/api.test.ts +4 -4
- package/src/lib/auth.ts +34 -4
- package/src/lib/models.ts +1 -0
- package/src/server/bun.ts +63 -0
- package/src/server/core.ts +84 -0
- package/src/server/express.ts +60 -0
- package/src/server/fastify.ts +61 -0
- package/src/server/hono.ts +55 -0
- package/src/server/nextjs.ts +58 -0
- package/src/server/tanstack-start.ts +77 -0
- package/src/server.ts +37 -49
- package/src/types/index.ts +25 -9
- package/dist/index-DdrZQXwQ.cjs +0 -147
- package/dist/index-DdrZQXwQ.cjs.map +0 -1
- package/dist/index-DfqYP0CD.js.map +0 -1
package/README.md
CHANGED
|
@@ -43,36 +43,104 @@ pnpm add @gram-ai/elements
|
|
|
43
43
|
|
|
44
44
|
## Setting up your backend
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
We provide framework-specific adapters to make it easy to set up a backend endpoint for Gram Elements. These adapters handle the session token creation securely on your server without exposing your `GRAM_API_KEY` to the browser.
|
|
47
|
+
|
|
48
|
+
### Express
|
|
47
49
|
|
|
48
50
|
```typescript
|
|
49
|
-
import {
|
|
51
|
+
import { createExpressHandler } from '@gram-ai/elements/server/express'
|
|
50
52
|
import express from 'express'
|
|
51
53
|
|
|
52
|
-
const handlers = createElementsServerHandlers()
|
|
53
54
|
const app = express()
|
|
54
|
-
|
|
55
55
|
app.use(express.json())
|
|
56
56
|
|
|
57
|
-
app.post('/chat/session', (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
app.post('/chat/session', createExpressHandler({
|
|
58
|
+
embedOrigin: 'http://localhost:3000',
|
|
59
|
+
userIdentifier: 'user-123',
|
|
60
|
+
expiresAfter: 3600, // optional, max 3600 seconds
|
|
61
|
+
}))
|
|
62
|
+
|
|
63
|
+
app.listen(3000)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For dynamic options based on the request:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
app.post('/chat/session', createExpressHandler((req) => ({
|
|
70
|
+
embedOrigin: req.headers.origin || 'http://localhost:3000',
|
|
71
|
+
userIdentifier: req.user?.id || 'anonymous',
|
|
72
|
+
expiresAfter: 3600,
|
|
73
|
+
})))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Next.js App Router
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
// app/chat/session/route.ts
|
|
80
|
+
import { createNextHandler } from '@gram-ai/elements/server/nextjs'
|
|
81
|
+
|
|
82
|
+
export const POST = createNextHandler({
|
|
83
|
+
embedOrigin: 'http://localhost:3000',
|
|
84
|
+
userIdentifier: 'user-123',
|
|
85
|
+
expiresAfter: 3600,
|
|
86
|
+
})
|
|
87
|
+
import { cookies } from 'next/headers'
|
|
88
|
+
|
|
89
|
+
export const POST = createNextHandler(async (request) => {
|
|
90
|
+
const cookieStore = await cookies()
|
|
91
|
+
const userId = cookieStore.get('userId')?.value || 'anonymous'
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
embedOrigin: request.headers.get('origin') || 'http://localhost:3000',
|
|
95
|
+
userIdentifier: userId,
|
|
64
96
|
expiresAfter: 3600,
|
|
65
|
-
}
|
|
66
|
-
)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Fastify
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { createFastifyHandler } from '@gram-ai/elements/server/fastify'
|
|
105
|
+
import Fastify from 'fastify'
|
|
106
|
+
|
|
107
|
+
const fastify = Fastify()
|
|
108
|
+
|
|
109
|
+
fastify.post('/chat/session', createFastifyHandler({
|
|
110
|
+
embedOrigin: 'http://localhost:3000',
|
|
111
|
+
userIdentifier: 'user-123',
|
|
112
|
+
expiresAfter: 3600,
|
|
113
|
+
}))
|
|
114
|
+
|
|
115
|
+
fastify.listen({ port: 3000 })
|
|
67
116
|
```
|
|
68
117
|
|
|
69
|
-
|
|
118
|
+
### Hono
|
|
70
119
|
|
|
120
|
+
```typescript
|
|
121
|
+
import { createHonoHandler } from '@gram-ai/elements/server/hono'
|
|
122
|
+
import { Hono } from 'hono'
|
|
123
|
+
|
|
124
|
+
const app = new Hono()
|
|
125
|
+
|
|
126
|
+
app.post('/chat/session', createHonoHandler({
|
|
127
|
+
embedOrigin: 'http://localhost:3000',
|
|
128
|
+
userIdentifier: 'user-123',
|
|
129
|
+
expiresAfter: 3600,
|
|
130
|
+
}))
|
|
131
|
+
|
|
132
|
+
export default app
|
|
71
133
|
```
|
|
134
|
+
|
|
135
|
+
### Environment Variables
|
|
136
|
+
|
|
137
|
+
All adapters require the `GRAM_API_KEY` environment variable to be set:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
72
140
|
GRAM_API_KEY=xxx
|
|
73
141
|
```
|
|
74
142
|
|
|
75
|
-
This
|
|
143
|
+
This key is kept on your server and never exposed to the browser, ensuring secure communication with Gram's API.
|
|
76
144
|
|
|
77
145
|
## Setting up your frontend
|
|
78
146
|
|
|
@@ -6,5 +6,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
|
|
9
|
+
export declare const WithDangerousApiKey: Story;
|
|
10
10
|
export declare const LanguageModel: Story;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface CalendarProps {
|
|
2
|
+
/** Selected date range */
|
|
3
|
+
selected?: {
|
|
4
|
+
start: Date | null;
|
|
5
|
+
end: Date | null;
|
|
6
|
+
};
|
|
7
|
+
/** Called when a date or range is selected */
|
|
8
|
+
onSelect?: (range: {
|
|
9
|
+
start: Date;
|
|
10
|
+
end: Date | null;
|
|
11
|
+
}) => void;
|
|
12
|
+
/** Whether range selection is enabled */
|
|
13
|
+
mode?: 'single' | 'range';
|
|
14
|
+
/** Disable dates before this */
|
|
15
|
+
minDate?: Date;
|
|
16
|
+
/** Disable dates after this */
|
|
17
|
+
maxDate?: Date;
|
|
18
|
+
/** Additional className */
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
declare function Calendar({ selected, onSelect, mode, minDate, maxDate, className, }: CalendarProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
declare namespace Calendar {
|
|
23
|
+
var displayName: string;
|
|
24
|
+
}
|
|
25
|
+
export { Calendar };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface TimeRange {
|
|
2
|
+
from: Date;
|
|
3
|
+
to: Date;
|
|
4
|
+
}
|
|
5
|
+
export type DateRangePreset = '15m' | '1h' | '4h' | '1d' | '2d' | '3d' | '7d' | '15d' | '30d' | '90d';
|
|
6
|
+
export interface TimeRangePreset {
|
|
7
|
+
label: string;
|
|
8
|
+
shortLabel: string;
|
|
9
|
+
value: DateRangePreset;
|
|
10
|
+
getRange: () => TimeRange;
|
|
11
|
+
}
|
|
12
|
+
export declare const PRESETS: TimeRangePreset[];
|
|
13
|
+
export declare function getPresetRange(preset: DateRangePreset): TimeRange;
|
|
14
|
+
export interface TimeRangePickerProps {
|
|
15
|
+
/** Current preset value */
|
|
16
|
+
preset?: DateRangePreset | null;
|
|
17
|
+
/** Current custom range */
|
|
18
|
+
customRange?: TimeRange | null;
|
|
19
|
+
/** Called when a preset is selected */
|
|
20
|
+
onPresetChange?: (preset: DateRangePreset) => void;
|
|
21
|
+
/** Called when a custom range is selected */
|
|
22
|
+
onCustomRangeChange?: (from: Date, to: Date, label?: string) => void;
|
|
23
|
+
/** Called to clear custom range */
|
|
24
|
+
onClearCustomRange?: () => void;
|
|
25
|
+
/** Initial label for custom range (from URL params) */
|
|
26
|
+
customRangeLabel?: string | null;
|
|
27
|
+
/** Show LIVE mode option */
|
|
28
|
+
showLive?: boolean;
|
|
29
|
+
/** Is LIVE mode active */
|
|
30
|
+
isLive?: boolean;
|
|
31
|
+
/** Called when LIVE mode changes */
|
|
32
|
+
onLiveChange?: (isLive: boolean) => void;
|
|
33
|
+
/** Disabled state */
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
/** Timezone display (e.g., "UTC-08:00") */
|
|
36
|
+
timezone?: string;
|
|
37
|
+
/** API URL for AI parsing (defaults to window.location.origin) */
|
|
38
|
+
apiUrl?: string;
|
|
39
|
+
/** Project slug for API authentication */
|
|
40
|
+
projectSlug?: string;
|
|
41
|
+
}
|
|
42
|
+
declare function TimeRangePicker({ preset, customRange, onPresetChange, onCustomRangeChange, onClearCustomRange, customRangeLabel: initialCustomLabel, showLive, isLive, onLiveChange, disabled, timezone, apiUrl, projectSlug, }: TimeRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
declare namespace TimeRangePicker {
|
|
44
|
+
var displayName: string;
|
|
45
|
+
}
|
|
46
|
+
export { TimeRangePicker };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
|
+
import { TimeRangePicker } from './time-range-picker';
|
|
3
|
+
declare const meta: Meta<typeof TimeRangePicker>;
|
|
4
|
+
export default meta;
|
|
5
|
+
type Story = StoryObj<typeof TimeRangePicker>;
|
|
6
|
+
/**
|
|
7
|
+
* Default time range picker with preset badges and calendar.
|
|
8
|
+
* Supports natural language input with AI parsing.
|
|
9
|
+
*/
|
|
10
|
+
export declare const Default: Story;
|
|
11
|
+
/**
|
|
12
|
+
* Time range picker with timezone indicator.
|
|
13
|
+
*/
|
|
14
|
+
export declare const WithTimezone: Story;
|
|
15
|
+
/**
|
|
16
|
+
* With LIVE mode toggle enabled.
|
|
17
|
+
*/
|
|
18
|
+
export declare const WithLiveMode: Story;
|
|
19
|
+
/**
|
|
20
|
+
* Disabled state.
|
|
21
|
+
*/
|
|
22
|
+
export declare const Disabled: Story;
|
|
23
|
+
/**
|
|
24
|
+
* Full Datadog-style configuration with all features.
|
|
25
|
+
* Type natural language like "3 days ago", "last Wednesday", "past 2 weeks".
|
|
26
|
+
*/
|
|
27
|
+
export declare const DatadogStyle: Story;
|
|
28
|
+
/**
|
|
29
|
+
* Natural language parsing demo.
|
|
30
|
+
* Type things like:
|
|
31
|
+
* - "yesterday"
|
|
32
|
+
* - "3 days ago"
|
|
33
|
+
* - "last Wednesday"
|
|
34
|
+
* - "past 2 weeks"
|
|
35
|
+
* - "January 2024"
|
|
36
|
+
*/
|
|
37
|
+
export declare const NaturalLanguageParsing: Story;
|
package/dist/elements.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CP-wWZCV.cjs"),r=require("./index-BpJstUh1.cjs");exports.Calendar=e.Calendar;exports.Chat=e.Chat;exports.ChatHistory=e.ChatHistory;exports.ElementsProvider=e.ElementsProvider;exports.GramElementsProvider=e.ElementsProvider;exports.MODELS=e.MODELS;exports.PRESETS=e.PRESETS;exports.Replay=e.Replay;exports.ShareButton=e.ShareButton;exports.TimeRangePicker=e.TimeRangePicker;exports.defineFrontendTool=e.defineFrontendTool;exports.getPresetRange=e.getPresetRange;exports.trackError=e.trackError;exports.useRecordCassette=e.useRecordCassette;exports.useThreadId=e.useThreadId;exports.useChatId=r.useChatId;exports.useElements=r.useElements;exports.useGramElements=r.useElements;
|
|
2
2
|
//# sourceMappingURL=elements.cjs.map
|