chatgsd 0.5.0 → 1.1.8

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eric Li
4
+ Copyright (c) 2026 Mick Ryan
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,247 +1,12 @@
1
- # ChatGSD
1
+ # chatgsd
2
2
 
3
- A conversational UI component where AI orchestrates the interface. The AI decides when to show calendars, collect payments, submit forms — chat becomes the control layer.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm install chatgsd
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```tsx
14
- import { ChatGSD } from "chatgsd";
15
- import "chatgsd/styles.css";
16
-
17
- function App() {
18
- return (
19
- <ChatGSD
20
- endpoint="/api/chat"
21
- brandName="assistant"
22
- initialMessage="Hey! How can I help you today?"
23
- />
24
- );
25
- }
26
- ```
27
-
28
- ## How It Works
29
-
30
- Your backend streams responses to the chat. ChatGSD supports two formats:
31
-
32
- ### SSE Format (recommended)
33
-
34
- Server-Sent Events with JSON payloads. Auto-detected via `Content-Type: text/event-stream`.
35
-
36
- ```
37
- data: {"type": "text", "content": "Let me "}
38
- data: {"type": "text", "content": "show you "}
39
- data: {"type": "text", "content": "available times."}
40
- data: {"type": "tool_call", "name": "show_slots", "args": {}}
41
- data: {"type": "done"}
42
- ```
43
-
44
- ### Plain Text Format
45
-
46
- Raw streaming text with tool calls embedded. Falls back to this when not SSE.
47
-
48
- ```
49
- Let me show you available times.
50
-
51
- [TOOL:show_slots]
52
- ```
53
-
54
- Or with arguments:
55
-
56
- ```
57
- [TOOL:show_slots({"date": "2024-01-15"})]
58
- ```
59
-
60
- ## Tools
61
-
62
- Tools are handlers that run when the AI invokes them. They can render UI, call APIs, update parent state — anything.
63
-
64
- ```tsx
65
- import { ChatGSD, Tool } from "chatgsd";
66
-
67
- const tools: Record<string, Tool> = {
68
- show_slots: {
69
- handler: async (args, messages) => {
70
- // Fetch data, update state, etc.
71
- return { success: true };
72
- },
73
- renderSuccess: () => (
74
- <div className="slots">
75
- {slots.map(slot => (
76
- <button key={slot.id} onClick={() => selectSlot(slot)}>
77
- {slot.time}
78
- </button>
79
- ))}
80
- </div>
81
- ),
82
- },
83
-
84
- submit_inquiry: {
85
- terminal: true, // Ends the conversation
86
- handler: async (args, messages) => {
87
- await fetch("/api/submit", {
88
- method: "POST",
89
- body: JSON.stringify({ messages }),
90
- });
91
- return { success: true, message: "Submitted!" };
92
- },
93
- },
94
- };
95
-
96
- <ChatGSD endpoint="/api/chat" tools={tools} />
97
- ```
98
-
99
- ### Tool Configuration
100
-
101
- | Property | Type | Description |
102
- |----------|------|-------------|
103
- | `handler` | `(args, messages) => Promise<ToolResult>` | Called when tool is invoked |
104
- | `terminal` | `boolean` | If true, ends the conversation |
105
- | `renderCalling` | `() => ReactNode` | Custom UI while tool is running |
106
- | `renderSuccess` | `(result) => ReactNode` | Custom UI on success |
107
- | `renderError` | `(result) => ReactNode` | Custom UI on error |
108
-
109
- ### ToolResult
110
-
111
- ```ts
112
- interface ToolResult {
113
- success: boolean;
114
- message?: string;
115
- }
116
- ```
117
-
118
- ## Props
119
-
120
- | Prop | Type | Default | Description |
121
- |------|------|---------|-------------|
122
- | `endpoint` | `string` | `"/api/chat"` | Chat API endpoint |
123
- | `tools` | `Record<string, Tool>` | `{}` | Tool definitions |
124
- | `context` | `Record<string, unknown>` | `{}` | Context sent with each request |
125
- | `headers` | `Record<string, string>` | `{}` | Custom headers for API requests |
126
- | `brandName` | `string` | `"assistant"` | Name shown in chat |
127
- | `initialMessage` | `string` | `"How can I help?"` | First message displayed |
128
- | `className` | `string` | `""` | Additional CSS class |
129
- | `format` | `"auto" \| "sse" \| "text"` | `"auto"` | Stream format (auto-detects from Content-Type) |
130
- | `onMessagesChange` | `(messages) => void` | - | Called when messages update |
131
- | `onComplete` | `(messages) => void` | - | Called when conversation ends |
132
-
133
- ## Backend API
134
-
135
- The component expects a streaming endpoint that accepts:
136
-
137
- ```ts
138
- // Request
139
- {
140
- messages: Array<{ role: "system" | "user", content: string }>,
141
- context: Record<string, unknown>
142
- }
143
- ```
144
-
145
- ### SSE Response (Node.js)
146
-
147
- ```ts
148
- app.post("/api/chat", async (req, res) => {
149
- const { messages, context } = req.body;
150
-
151
- res.setHeader("Content-Type", "text/event-stream");
152
- res.setHeader("Cache-Control", "no-cache");
153
- res.setHeader("Connection", "keep-alive");
154
-
155
- const stream = await openai.chat.completions.create({
156
- model: "gpt-4",
157
- stream: true,
158
- messages: [
159
- {
160
- role: "system",
161
- content: `You are a helpful assistant. Available tools:
162
- - show_slots: Show available meeting times
163
- - submit_inquiry: Submit the inquiry
164
-
165
- When you want to use a tool, I'll signal it in the stream.`
166
- },
167
- ...messages
168
- ],
169
- });
170
-
171
- for await (const chunk of stream) {
172
- const text = chunk.choices[0]?.delta?.content || "";
173
- if (text) {
174
- res.write(`data: ${JSON.stringify({ type: "text", content: text })}\n\n`);
175
- }
176
- }
177
-
178
- // Send tool call if needed (based on your logic)
179
- res.write(`data: ${JSON.stringify({ type: "tool_call", name: "show_slots", args: {} })}\n\n`);
180
- res.write(`data: ${JSON.stringify({ type: "done" })}\n\n`);
181
- res.end();
182
- });
183
- ```
184
-
185
- ### With Vercel AI SDK
186
-
187
- ```ts
188
- import { streamText, tool } from "ai";
189
- import { openai } from "@ai-sdk/openai";
190
-
191
- export async function POST(req: Request) {
192
- const { messages, context } = await req.json();
193
-
194
- const result = await streamText({
195
- model: openai("gpt-4"),
196
- messages,
197
- tools: {
198
- show_slots: tool({
199
- description: "Show available meeting times",
200
- parameters: z.object({ date: z.string().optional() }),
201
- }),
202
- },
203
- });
204
-
205
- // AI SDK streams in a compatible format
206
- return result.toDataStreamResponse();
207
- }
208
- ```
209
-
210
- ## Styling
211
-
212
- Import the default styles:
213
-
214
- ```tsx
215
- import "chatgsd/styles.css";
216
- ```
217
-
218
- Customize with CSS variables:
219
-
220
- ```css
221
- :root {
222
- --chatgsd-bg: #0a0a0a;
223
- --chatgsd-border: #333;
224
- --chatgsd-green: #27ca40;
225
- --chatgsd-yellow: #ffbd2e;
226
- --chatgsd-red: #ff5f56;
227
- --chatgsd-text: #e0e0e0;
228
- --chatgsd-muted: #666;
229
- --chatgsd-font: ui-monospace, monospace;
230
- }
231
- ```
232
-
233
- Or write your own styles targeting `.chatgsd-*` classes.
234
-
235
- ## Example
236
-
237
- Run the example app:
3
+ Installs or updates [ChatGSD](https://github.com/mickr/chatgsd), the markdown notes app you co-edit with ChatGPT, then opens it.
238
4
 
239
5
  ```bash
240
- cd example
241
- npm install
242
- npm run dev
6
+ npx chatgsd # install or update, then open
7
+ npx chatgsd notes.md # open a file in it
243
8
  ```
244
9
 
245
- ## License
10
+ Apple Silicon Macs only. Each version installs the ChatGSD release with the same number. The download must match the checksum published with this package, and the app must pass macOS's notarization check and carry ChatGSD's Developer ID signature, or nothing is installed. Once installed, ChatGSD updates itself.
246
11
 
247
- MIT
12
+ Versions before 1.0 were a different, retired project.
package/bin/chatgsd.js ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ // npx chatgsd [files...]: installs or updates ChatGSD.app, then opens it.
3
+ import { spawnSync } from "node:child_process";
4
+ import { accessSync, constants, mkdirSync, readFileSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { dirname, join } from "node:path";
7
+ import { appVersion, findApp, install, isNewer, isRunning } from "../lib/install.js";
8
+
9
+ const release = JSON.parse(readFileSync(new URL("../release.json", import.meta.url), "utf8"));
10
+ const files = process.argv.slice(2);
11
+
12
+ if (files.includes("--help") || files.includes("-h")) {
13
+ console.log("Usage: npx chatgsd [file.md ...]\n\nInstalls or updates ChatGSD, then opens it (and any files given).");
14
+ process.exit(0);
15
+ }
16
+ if (files.includes("--version") || files.includes("-v")) {
17
+ console.log(release.version);
18
+ process.exit(0);
19
+ }
20
+ if (process.platform !== "darwin" || process.arch !== "arm64") {
21
+ console.error("ChatGSD is available for Apple Silicon Macs.");
22
+ process.exit(1);
23
+ }
24
+
25
+ // An update goes where the app already is. A new install goes to
26
+ // /Applications when this user can write there, otherwise ~/Applications.
27
+ function installFolder(app) {
28
+ if (app) return dirname(app);
29
+ try {
30
+ accessSync("/Applications", constants.W_OK);
31
+ return "/Applications";
32
+ } catch {
33
+ const own = join(homedir(), "Applications");
34
+ mkdirSync(own, { recursive: true });
35
+ return own;
36
+ }
37
+ }
38
+
39
+ async function main() {
40
+ let app = findApp();
41
+ const installed = app && appVersion(app);
42
+ if (!app || !installed || isNewer(release.version, installed)) {
43
+ if (app && isRunning(app)) {
44
+ console.log(`ChatGSD ${installed} is running; it updates itself, or quit it and run this again for ${release.version}.`);
45
+ } else {
46
+ console.log(installed ? `Updating ChatGSD ${installed} to ${release.version}...` : `Installing ChatGSD ${release.version}...`);
47
+ app = await install(release, installFolder(app));
48
+ console.log(`Installed ${app}`);
49
+ }
50
+ }
51
+ const opened = spawnSync("open", ["-a", app, ...files], { stdio: "inherit" });
52
+ process.exit(opened.status ?? 1);
53
+ }
54
+
55
+ main().catch((error) => {
56
+ console.error(error.message);
57
+ process.exit(1);
58
+ });
package/lib/install.js ADDED
@@ -0,0 +1,120 @@
1
+ // Installs ChatGSD.app from the GitHub release this package was published with.
2
+ // The DMG must match the checksum pinned at publish time, and the app inside
3
+ // must carry a valid, notarized Developer ID signature from ChatGSD's team.
4
+ import { spawnSync } from "node:child_process";
5
+ import { createHash } from "node:crypto";
6
+ import { createReadStream, createWriteStream, existsSync, mkdtempSync, renameSync, rmSync } from "node:fs";
7
+ import { homedir, tmpdir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { Readable } from "node:stream";
10
+ import { pipeline } from "node:stream/promises";
11
+
12
+ export const APP_NAME = "ChatGSD.app";
13
+ export const TEAM_ID = "M9G92WURV3";
14
+ export const RELEASES = "https://github.com/mickr/chatgsd/releases/download";
15
+
16
+ function run(command, args) {
17
+ const result = spawnSync(command, args, { encoding: "utf8" });
18
+ if (result.status !== 0) {
19
+ throw new Error(`${command} ${args[0]} failed: ${(result.stderr || result.stdout).trim()}`);
20
+ }
21
+ return result;
22
+ }
23
+
24
+ /** Whether version `a` is newer than `b` (MAJOR.MINOR.PATCH). */
25
+ export function isNewer(a, b) {
26
+ const [x, y] = [a, b].map((v) => v.split(".").map(Number));
27
+ for (let i = 0; i < 3; i++) {
28
+ if (x[i] !== y[i]) return x[i] > y[i];
29
+ }
30
+ return false;
31
+ }
32
+
33
+ /** The installed copy, preferring the system Applications folder. */
34
+ export function findApp(folders = ["/Applications", join(homedir(), "Applications")]) {
35
+ return folders.map((folder) => join(folder, APP_NAME)).find((path) => existsSync(path)) ?? null;
36
+ }
37
+
38
+ export function appVersion(app) {
39
+ const result = spawnSync("plutil", ["-extract", "CFBundleShortVersionString", "raw", "-o", "-", join(app, "Contents/Info.plist")], { encoding: "utf8" });
40
+ return result.status === 0 ? result.stdout.trim() : null;
41
+ }
42
+
43
+ export function isRunning(app) {
44
+ return spawnSync("pgrep", ["-f", join(app, "Contents/MacOS/")]).status === 0;
45
+ }
46
+
47
+ async function sha256(file) {
48
+ const hash = createHash("sha256");
49
+ await pipeline(createReadStream(file), hash);
50
+ return hash.digest("hex");
51
+ }
52
+
53
+ /** Downloads the release DMG to `file` and checks it against the pinned checksum. */
54
+ export async function download(release, file, base = RELEASES) {
55
+ const response = await fetch(`${base}/v${release.version}/${release.dmg}`);
56
+ if (!response.ok) throw new Error(`Download failed (HTTP ${response.status})`);
57
+ await pipeline(Readable.fromWeb(response.body), createWriteStream(file));
58
+ const actual = await sha256(file);
59
+ if (actual !== release.sha256) {
60
+ throw new Error(`The download doesn't match the published checksum (${actual}), so nothing was installed`);
61
+ }
62
+ }
63
+
64
+ function verifySignature(app) {
65
+ run("codesign", ["--verify", "--deep", "--strict", app]);
66
+ run("spctl", ["--assess", "--type", "execute", app]);
67
+ const details = spawnSync("codesign", ["-dv", app], { encoding: "utf8" }).stderr;
68
+ if (!details.includes(`TeamIdentifier=${TEAM_ID}`)) {
69
+ throw new Error("The app isn't signed by ChatGSD's developer team, so nothing was installed");
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Installs `release` into `folder`, replacing any copy there. The new app is
75
+ * copied beside the old one and swapped in, so a failure leaves the old one.
76
+ */
77
+ export async function install(release, folder, base = RELEASES) {
78
+ const work = mkdtempSync(join(tmpdir(), "chatgsd-"));
79
+ const mount = join(work, "mount");
80
+ const target = join(folder, APP_NAME);
81
+ const incoming = `${target}.installing`;
82
+ let mounted = false;
83
+ try {
84
+ const dmg = join(work, release.dmg);
85
+ await download(release, dmg, base);
86
+ run("hdiutil", ["attach", "-quiet", "-nobrowse", "-readonly", "-mountpoint", mount, dmg]);
87
+ mounted = true;
88
+ verifySignature(join(mount, APP_NAME));
89
+ rmSync(incoming, { recursive: true, force: true });
90
+ run("ditto", [join(mount, APP_NAME), incoming]);
91
+ verifySignature(incoming);
92
+ swapIn(incoming, target);
93
+ return target;
94
+ } finally {
95
+ if (mounted) spawnSync("hdiutil", ["detach", "-quiet", mount]);
96
+ rmSync(incoming, { recursive: true, force: true });
97
+ rmSync(work, { recursive: true, force: true });
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Moves the verified `incoming` app to `target`. Any app already there is set
103
+ * aside first and put back if the move fails, so a failure never leaves the
104
+ * user without ChatGSD.
105
+ */
106
+ export function swapIn(incoming, target, rename = renameSync) {
107
+ const outgoing = `${target}.replaced`;
108
+ // A run killed between the two moves left the user's app set aside.
109
+ if (!existsSync(target) && existsSync(outgoing)) rename(outgoing, target);
110
+ rmSync(outgoing, { recursive: true, force: true });
111
+ const replacing = existsSync(target);
112
+ if (replacing) rename(target, outgoing);
113
+ try {
114
+ rename(incoming, target);
115
+ } catch (error) {
116
+ if (replacing) rename(outgoing, target);
117
+ throw error;
118
+ }
119
+ rmSync(outgoing, { recursive: true, force: true });
120
+ }
package/package.json CHANGED
@@ -1,50 +1,31 @@
1
1
  {
2
2
  "name": "chatgsd",
3
- "version": "0.5.0",
4
- "description": "Portable terminal-style chat intake form component",
3
+ "version": "1.1.8",
4
+ "description": "Install and open ChatGSD, the markdown notes app you co-edit with ChatGPT",
5
5
  "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js",
13
- "require": "./dist/index.cjs"
14
- },
15
- "./styles.css": "./dist/styles.css"
6
+ "bin": {
7
+ "chatgsd": "bin/chatgsd.js"
16
8
  },
17
9
  "files": [
18
- "dist"
10
+ "bin",
11
+ "lib/install.js",
12
+ "release.json",
13
+ "LICENSE"
19
14
  ],
20
- "scripts": {
21
- "build": "tsup && cp src/styles.css dist/styles.css",
22
- "dev": "cp src/styles.css dist/styles.css && tsup --watch",
23
- "typecheck": "tsc --noEmit",
24
- "prepublishOnly": "npm run build",
25
- "release": "npm run typecheck && npm version minor && npm publish && git push && git push --tags",
26
- "release:patch": "npm run typecheck && npm version patch && npm publish && git push && git push --tags",
27
- "release:major": "npm run typecheck && npm version major && npm publish && git push && git push --tags"
28
- },
29
- "peerDependencies": {
30
- "react": ">=18.0.0",
31
- "react-dom": ">=18.0.0"
32
- },
33
- "devDependencies": {
34
- "@types/react": "^18.2.0",
35
- "@types/react-dom": "^18.2.0",
36
- "react": "^18.2.0",
37
- "react-dom": "^18.2.0",
38
- "tsup": "^8.0.0",
39
- "typescript": "^5.3.0"
40
- },
41
- "keywords": [
42
- "react",
43
- "chat",
44
- "terminal",
45
- "intake",
46
- "form"
15
+ "os": [
16
+ "darwin"
47
17
  ],
48
- "author": "",
49
- "license": "MIT"
18
+ "cpu": [
19
+ "arm64"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "license": "MIT",
25
+ "homepage": "https://github.com/mickr/chatgsd",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/mickr/chatgsd.git",
29
+ "directory": "npm/chatgsd"
30
+ }
50
31
  }
package/release.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "version": "1.1.8",
3
+ "dmg": "ChatGSD_1.1.8_aarch64.dmg",
4
+ "sha256": "50338ba41edc544a929fe7617edc7b7fc197e5f378121f4efcfbb54bc8b6ca74"
5
+ }