@gram-ai/elements 1.22.3 → 1.22.4
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/dist/elements.cjs +1 -1
- package/dist/elements.css +1 -1
- package/dist/elements.js +2 -2
- package/dist/hooks/useGramThreadListAdapter.d.ts +1 -1
- package/dist/index-BdXdd2ZM.js +26682 -0
- package/dist/index-BdXdd2ZM.js.map +1 -0
- package/dist/{index-JbEIsMvT.cjs → index-C1TX1kmi.cjs} +34 -34
- package/dist/index-C1TX1kmi.cjs.map +1 -0
- package/dist/index-CNVoovK7.cjs +111 -0
- package/dist/index-CNVoovK7.cjs.map +1 -0
- package/dist/{index-X2BCBKvn.js → index-DqUXeR5-.js} +4294 -4267
- package/dist/index-DqUXeR5-.js.map +1 -0
- package/dist/plugins/chart/chart.test.d.ts +1 -0
- package/dist/plugins.cjs +1 -1
- package/dist/plugins.js +1 -1
- package/dist/{profiler-BUSOvmmE.cjs → profiler-BBSi_UtN.cjs} +2 -2
- package/dist/{profiler-BUSOvmmE.cjs.map → profiler-BBSi_UtN.cjs.map} +1 -1
- package/dist/{profiler-CHsg3NcT.js → profiler-Bc9bwSPu.js} +2 -2
- package/dist/{profiler-CHsg3NcT.js.map → profiler-Bc9bwSPu.js.map} +1 -1
- package/dist/{startRecording-CPa3562Q.js → startRecording-DC-9cgyZ.js} +2 -2
- package/dist/{startRecording-CPa3562Q.js.map → startRecording-DC-9cgyZ.js.map} +1 -1
- package/dist/{startRecording-BE9dMdci.cjs → startRecording-DsKSBkyg.cjs} +2 -2
- package/dist/{startRecording-BE9dMdci.cjs.map → startRecording-DsKSBkyg.cjs.map} +1 -1
- package/dist/types/index.d.ts +11 -0
- package/package.json +3 -5
- package/src/components/Chat/index.tsx +6 -14
- package/src/components/ShadowRoot.tsx +5 -1
- package/src/components/assistant-ui/assistant-modal.tsx +5 -5
- package/src/components/assistant-ui/assistant-sidecar.tsx +2 -2
- package/src/contexts/ElementsProvider.tsx +66 -26
- package/src/global.css +24 -0
- package/src/hooks/useGramThreadListAdapter.tsx +1 -1
- package/src/plugins/chart/chart.test.ts +66 -0
- package/src/plugins/chart/component.tsx +3 -1
- package/src/types/index.ts +12 -0
- package/dist/index-BwdTXSZG.js +0 -3145
- package/dist/index-BwdTXSZG.js.map +0 -1
- package/dist/index-D8g4LkEy.cjs +0 -99
- package/dist/index-D8g4LkEy.cjs.map +0 -1
- package/dist/index-JbEIsMvT.cjs.map +0 -1
- package/dist/index-X2BCBKvn.js.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { parse, View, Warn } from 'vega'
|
|
3
|
+
import { expressionInterpreter } from 'vega-interpreter'
|
|
4
|
+
|
|
5
|
+
describe('ChartRenderer CSP compliance', () => {
|
|
6
|
+
it('renders a chart using vega-interpreter without eval', async () => {
|
|
7
|
+
const spec = {
|
|
8
|
+
$schema: 'https://vega.github.io/schema/vega/v5.json',
|
|
9
|
+
width: 400,
|
|
10
|
+
height: 200,
|
|
11
|
+
data: [
|
|
12
|
+
{
|
|
13
|
+
name: 'table',
|
|
14
|
+
values: [
|
|
15
|
+
{ category: 'A', amount: 28 },
|
|
16
|
+
{ category: 'B', amount: 55 },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
marks: [
|
|
21
|
+
{
|
|
22
|
+
type: 'rect',
|
|
23
|
+
from: { data: 'table' },
|
|
24
|
+
encode: {
|
|
25
|
+
enter: {
|
|
26
|
+
x: { scale: 'xscale', field: 'category' },
|
|
27
|
+
width: { scale: 'xscale', band: 1 },
|
|
28
|
+
y: { scale: 'yscale', field: 'amount' },
|
|
29
|
+
y2: { scale: 'yscale', value: 0 },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
scales: [
|
|
35
|
+
{
|
|
36
|
+
name: 'xscale',
|
|
37
|
+
type: 'band',
|
|
38
|
+
domain: { data: 'table', field: 'category' },
|
|
39
|
+
range: 'width',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'yscale',
|
|
43
|
+
domain: { data: 'table', field: 'amount' },
|
|
44
|
+
range: 'height',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
|
+
const runtime = parse(spec as any, undefined, { ast: true })
|
|
51
|
+
|
|
52
|
+
// This is the key - using expr: vegaInterpreter means no eval() is called
|
|
53
|
+
const view = new View(runtime, {
|
|
54
|
+
renderer: 'none',
|
|
55
|
+
logLevel: Warn,
|
|
56
|
+
expr: expressionInterpreter,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
await view.runAsync()
|
|
60
|
+
|
|
61
|
+
// If we get here without error, CSP compliance works
|
|
62
|
+
expect(view.data('table')).toHaveLength(2)
|
|
63
|
+
|
|
64
|
+
view.finalize()
|
|
65
|
+
})
|
|
66
|
+
})
|
|
@@ -7,6 +7,7 @@ import { SyntaxHighlighterProps } from '@assistant-ui/react-markdown'
|
|
|
7
7
|
import { AlertCircleIcon } from 'lucide-react'
|
|
8
8
|
import { FC, useEffect, useMemo, useRef, useState } from 'react'
|
|
9
9
|
import { parse, View, Warn } from 'vega'
|
|
10
|
+
import { expressionInterpreter } from 'vega-interpreter'
|
|
10
11
|
|
|
11
12
|
export const ChartRenderer: FC<SyntaxHighlighterProps> = ({ code }) => {
|
|
12
13
|
const containerRef = useRef<HTMLDivElement>(null)
|
|
@@ -56,12 +57,13 @@ export const ChartRenderer: FC<SyntaxHighlighterProps> = ({ code }) => {
|
|
|
56
57
|
viewRef.current = null
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
const chart = parse(parsedSpec)
|
|
60
|
+
const chart = parse(parsedSpec, undefined, { ast: true })
|
|
60
61
|
const view = new View(chart, {
|
|
61
62
|
container: containerRef.current ?? undefined,
|
|
62
63
|
renderer: 'svg',
|
|
63
64
|
hover: true,
|
|
64
65
|
logLevel: Warn,
|
|
66
|
+
expr: expressionInterpreter,
|
|
65
67
|
})
|
|
66
68
|
viewRef.current = view
|
|
67
69
|
|
package/src/types/index.ts
CHANGED
|
@@ -336,6 +336,18 @@ export type BaseApiConfig = {
|
|
|
336
336
|
* }
|
|
337
337
|
*/
|
|
338
338
|
url?: string
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Additional headers to send with the API request.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* const config: ElementsConfig = {
|
|
345
|
+
* api: {
|
|
346
|
+
* headers: { 'X-My-Header': 'my-value' },
|
|
347
|
+
* },
|
|
348
|
+
* }
|
|
349
|
+
*/
|
|
350
|
+
headers?: Record<string, string>
|
|
339
351
|
}
|
|
340
352
|
|
|
341
353
|
export type SessionAuthConfig = {
|