-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuddy.ts
More file actions
85 lines (74 loc) · 2.08 KB
/
buddy.ts
File metadata and controls
85 lines (74 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* Buddy - Voice AI Code Assistant Desktop Launcher
*
* Launches the Buddy UI as a native desktop application
* using Craft (ts-craft) as the UI engine.
*
* Usage:
* bun examples/buddy.ts
*
* Or with the stx CLI:
* stx dev examples/voice-buddy.stx --native
*/
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import process from 'node:process'
// Dynamic import for Craft
async function launchWithCraft() {
try {
const { createApp } = await import('ts-craft')
const stxPath = join(import.meta.dir, 'voice-buddy.stx')
const html = readFileSync(stxPath, 'utf-8')
const app = createApp({
html,
window: {
title: 'Buddy - Voice AI Code Assistant',
width: 1200,
height: 800,
resizable: true,
darkMode: true,
devTools: process.env.NODE_ENV === 'development',
titlebarHidden: true,
systemTray: true, // Enable system tray for native notifications
},
})
console.log('Launching Buddy...')
await app.show()
}
catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ERR_MODULE_NOT_FOUND') {
console.log('Craft (ts-craft) not found. Running in browser mode...')
await launchInBrowser()
}
else {
throw error
}
}
}
// Fallback to browser-based server
async function launchInBrowser() {
const stxPath = join(import.meta.dir, 'voice-buddy.stx')
const html = readFileSync(stxPath, 'utf-8')
const server = Bun.serve({
port: 3456,
fetch() {
return new Response(html, {
headers: { 'Content-Type': 'text/html' },
})
},
})
console.log(`Buddy running at http://localhost:${server.port}`)
console.log('Press Ctrl+C to stop')
const { exec } = await import('node:child_process')
const platform = process.platform
if (platform === 'darwin') {
exec(`open http://localhost:${server.port}`)
}
else if (platform === 'win32') {
exec(`start http://localhost:${server.port}`)
}
else {
exec(`xdg-open http://localhost:${server.port}`)
}
}
launchWithCraft().catch(console.error)