@gram-ai/elements 1.18.8 → 1.19.0

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 CHANGED
@@ -6,10 +6,21 @@ Elements is a library built for the agentic age. We provide customizable and ele
6
6
 
7
7
  ### Frontend Setup
8
8
 
9
- First ensure that you have installed the required peer dependencies:
9
+ The easiest way to install Elements and all its peer dependencies:
10
10
 
11
11
  ```bash
12
- pnpm add react react-dom @assistant-ui/react @assistant-ui/react-markdown motion remark-gfm zustand vega shiki
12
+ npx @gram-ai/elements install
13
+ ```
14
+
15
+ This will automatically detect your package manager and install everything you need.
16
+
17
+ <details>
18
+ <summary>Manual installation</summary>
19
+
20
+ If you prefer to install manually, first install the peer dependencies:
21
+
22
+ ```bash
23
+ pnpm add react react-dom motion remark-gfm zustand vega shiki
13
24
  ```
14
25
 
15
26
  Then install Elements:
@@ -18,9 +29,11 @@ Then install Elements:
18
29
  pnpm add @gram-ai/elements
19
30
  ```
20
31
 
32
+ </details>
33
+
21
34
  ### Backend Setup
22
35
 
23
- If you're only using the server handlers (`@gram-ai/elements/server`), you can install without React:
36
+ If you're only using the server handlers (`@gram-ai/elements/server`), you can install without needing to install any of the React peer dependencies:
24
37
 
25
38
  ```bash
26
39
  pnpm add @gram-ai/elements
package/bin/cli.js ADDED
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync } from 'node:child_process'
4
+ import { existsSync } from 'node:fs'
5
+ import { resolve } from 'node:path'
6
+
7
+ // Colors
8
+ const c = {
9
+ reset: '\x1b[0m',
10
+ bold: '\x1b[1m',
11
+ dim: '\x1b[2m',
12
+ cyan: '\x1b[36m',
13
+ green: '\x1b[32m',
14
+ yellow: '\x1b[33m',
15
+ red: '\x1b[31m',
16
+ magenta: '\x1b[35m',
17
+ blue: '\x1b[34m',
18
+ bgCyan: '\x1b[46m',
19
+ bgBlue: '\x1b[44m',
20
+ white: '\x1b[37m',
21
+ }
22
+
23
+ const PEER_DEPS = [
24
+ 'react',
25
+ 'react-dom',
26
+ 'motion',
27
+ 'remark-gfm',
28
+ 'zustand',
29
+ 'vega',
30
+ 'shiki',
31
+ ]
32
+
33
+ const PACKAGE_NAME = '@gram-ai/elements'
34
+
35
+ function detectPackageManager() {
36
+ const cwd = process.cwd()
37
+
38
+ // Check for lockfiles
39
+ if (
40
+ existsSync(resolve(cwd, 'bun.lockb')) ||
41
+ existsSync(resolve(cwd, 'bun.lock'))
42
+ ) {
43
+ return 'bun'
44
+ }
45
+ if (existsSync(resolve(cwd, 'pnpm-lock.yaml'))) {
46
+ return 'pnpm'
47
+ }
48
+ if (existsSync(resolve(cwd, 'yarn.lock'))) {
49
+ return 'yarn'
50
+ }
51
+ if (existsSync(resolve(cwd, 'package-lock.json'))) {
52
+ return 'npm'
53
+ }
54
+
55
+ // Check for npm_config_user_agent (set when running via npx/pnpm dlx/etc)
56
+ const userAgent = process.env.npm_config_user_agent || ''
57
+ if (userAgent.includes('bun')) return 'bun'
58
+ if (userAgent.includes('pnpm')) return 'pnpm'
59
+ if (userAgent.includes('yarn')) return 'yarn'
60
+
61
+ // Default to npm
62
+ return 'npm'
63
+ }
64
+
65
+ function getInstallCommand(pm, packages) {
66
+ const pkgString = packages.join(' ')
67
+ switch (pm) {
68
+ case 'bun':
69
+ return `bun add ${pkgString}`
70
+ case 'pnpm':
71
+ return `pnpm add ${pkgString}`
72
+ case 'yarn':
73
+ return `yarn add ${pkgString}`
74
+ case 'npm':
75
+ default:
76
+ return `npm install ${pkgString}`
77
+ }
78
+ }
79
+
80
+ function run(command) {
81
+ console.log(`\n ${c.dim}$${c.reset} ${c.cyan}${command}${c.reset}\n`)
82
+ try {
83
+ execSync(command, { stdio: 'inherit', cwd: process.cwd() })
84
+ return true
85
+ } catch {
86
+ return false
87
+ }
88
+ }
89
+
90
+ function printUsage() {
91
+ console.log(`
92
+ ${c.bold}Usage:${c.reset} npx ${c.cyan}${PACKAGE_NAME}${c.reset} ${c.dim}<command>${c.reset}
93
+
94
+ ${c.bold}Commands:${c.reset}
95
+ ${c.green}install${c.reset} Install ${PACKAGE_NAME} and its peer dependencies
96
+ ${c.green}help${c.reset} Show this help message
97
+
98
+ ${c.bold}Examples:${c.reset}
99
+ ${c.dim}$${c.reset} npx ${c.cyan}${PACKAGE_NAME}${c.reset} install
100
+ `)
101
+ }
102
+
103
+ function install() {
104
+ const pm = detectPackageManager()
105
+
106
+ console.log(`
107
+ ${c.bold}⚡ Installing Gram Elements${c.reset}
108
+
109
+ ${c.dim}Package manager:${c.reset} ${c.cyan}${pm}${c.reset}
110
+ `)
111
+
112
+ // Install everything in one command
113
+ console.log(`${c.yellow}○${c.reset} Installing ${c.cyan}@gram-ai/elements${c.reset} and peer dependencies...`)
114
+ const allPackages = [...PEER_DEPS, PACKAGE_NAME]
115
+ const cmd = getInstallCommand(pm, allPackages)
116
+ if (!run(cmd)) {
117
+ console.error(`\n${c.red}✖${c.reset} Failed to install packages`)
118
+ process.exit(1)
119
+ }
120
+
121
+ console.log(`
122
+ ${c.green}${c.bold}✔ Installation complete!${c.reset}
123
+ `)
124
+ }
125
+
126
+ // Main
127
+ const command = process.argv[2]
128
+
129
+ switch (command) {
130
+ case 'install':
131
+ case 'i':
132
+ install()
133
+ break
134
+ case 'help':
135
+ case '--help':
136
+ case '-h':
137
+ case undefined:
138
+ printUsage()
139
+ break
140
+ default:
141
+ console.error(`Unknown command: ${command}`)
142
+ printUsage()
143
+ process.exit(1)
144
+ }