@lovelybunch/api 1.0.7

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.
Files changed (131) hide show
  1. package/dist/lib/gait-path.d.ts +13 -0
  2. package/dist/lib/gait-path.js +57 -0
  3. package/dist/lib/project-paths.d.ts +13 -0
  4. package/dist/lib/project-paths.js +57 -0
  5. package/dist/lib/storage/file-storage.d.ts +28 -0
  6. package/dist/lib/storage/file-storage.js +224 -0
  7. package/dist/lib/symlinks/symlink-manager.d.ts +66 -0
  8. package/dist/lib/symlinks/symlink-manager.js +444 -0
  9. package/dist/lib/symlinks/types.d.ts +23 -0
  10. package/dist/lib/symlinks/types.js +4 -0
  11. package/dist/lib/terminal/context-helper.d.ts +11 -0
  12. package/dist/lib/terminal/context-helper.js +164 -0
  13. package/dist/lib/terminal/global-manager.d.ts +2 -0
  14. package/dist/lib/terminal/global-manager.js +15 -0
  15. package/dist/lib/terminal/shell-utils.d.ts +33 -0
  16. package/dist/lib/terminal/shell-utils.js +176 -0
  17. package/dist/lib/terminal/terminal-manager.d.ts +26 -0
  18. package/dist/lib/terminal/terminal-manager.js +276 -0
  19. package/dist/lib/user-preferences.d.ts +48 -0
  20. package/dist/lib/user-preferences.js +87 -0
  21. package/dist/lib/utils.d.ts +2 -0
  22. package/dist/lib/utils.js +5 -0
  23. package/dist/routes/api/symlink-status/route.d.ts +1 -0
  24. package/dist/routes/api/symlink-status/route.js +37 -0
  25. package/dist/routes/api/symlinks/[id]/route.d.ts +19 -0
  26. package/dist/routes/api/symlinks/[id]/route.js +95 -0
  27. package/dist/routes/api/symlinks/[id]/toggle/route.d.ts +11 -0
  28. package/dist/routes/api/symlinks/[id]/toggle/route.js +32 -0
  29. package/dist/routes/api/symlinks/debug/route.d.ts +1 -0
  30. package/dist/routes/api/symlinks/debug/route.js +35 -0
  31. package/dist/routes/api/symlinks/route.d.ts +9 -0
  32. package/dist/routes/api/symlinks/route.js +72 -0
  33. package/dist/routes/api/toggle-symlink/route.d.ts +2 -0
  34. package/dist/routes/api/toggle-symlink/route.js +94 -0
  35. package/dist/routes/api/v1/agents/[id]/index.d.ts +1 -0
  36. package/dist/routes/api/v1/agents/[id]/index.js +1 -0
  37. package/dist/routes/api/v1/agents/[id]/route.d.ts +3 -0
  38. package/dist/routes/api/v1/agents/[id]/route.js +163 -0
  39. package/dist/routes/api/v1/agents/index.d.ts +1 -0
  40. package/dist/routes/api/v1/agents/index.js +1 -0
  41. package/dist/routes/api/v1/agents/route.d.ts +3 -0
  42. package/dist/routes/api/v1/agents/route.js +133 -0
  43. package/dist/routes/api/v1/ai/index.d.ts +3 -0
  44. package/dist/routes/api/v1/ai/index.js +5 -0
  45. package/dist/routes/api/v1/ai/route.d.ts +8 -0
  46. package/dist/routes/api/v1/ai/route.js +86 -0
  47. package/dist/routes/api/v1/chats/[id]/index.d.ts +3 -0
  48. package/dist/routes/api/v1/chats/[id]/index.js +6 -0
  49. package/dist/routes/api/v1/chats/[id]/route.d.ts +12 -0
  50. package/dist/routes/api/v1/chats/[id]/route.js +31 -0
  51. package/dist/routes/api/v1/chats/index.d.ts +3 -0
  52. package/dist/routes/api/v1/chats/index.js +6 -0
  53. package/dist/routes/api/v1/chats/route.d.ts +32 -0
  54. package/dist/routes/api/v1/chats/route.js +67 -0
  55. package/dist/routes/api/v1/config/index.d.ts +3 -0
  56. package/dist/routes/api/v1/config/index.js +5 -0
  57. package/dist/routes/api/v1/config/route.d.ts +9 -0
  58. package/dist/routes/api/v1/config/route.js +29 -0
  59. package/dist/routes/api/v1/context/[...path]/route.d.ts +16 -0
  60. package/dist/routes/api/v1/context/[...path]/route.js +107 -0
  61. package/dist/routes/api/v1/context/architecture/route.d.ts +3 -0
  62. package/dist/routes/api/v1/context/architecture/route.js +198 -0
  63. package/dist/routes/api/v1/context/index.d.ts +3 -0
  64. package/dist/routes/api/v1/context/index.js +9 -0
  65. package/dist/routes/api/v1/context/knowledge/[filename]/index.d.ts +1 -0
  66. package/dist/routes/api/v1/context/knowledge/[filename]/index.js +1 -0
  67. package/dist/routes/api/v1/context/knowledge/[filename]/route.d.ts +3 -0
  68. package/dist/routes/api/v1/context/knowledge/[filename]/route.js +165 -0
  69. package/dist/routes/api/v1/context/knowledge/index.d.ts +1 -0
  70. package/dist/routes/api/v1/context/knowledge/index.js +1 -0
  71. package/dist/routes/api/v1/context/knowledge/route.d.ts +3 -0
  72. package/dist/routes/api/v1/context/knowledge/route.js +121 -0
  73. package/dist/routes/api/v1/context/project/route.d.ts +3 -0
  74. package/dist/routes/api/v1/context/project/route.js +153 -0
  75. package/dist/routes/api/v1/proposals/[id]/route.d.ts +337 -0
  76. package/dist/routes/api/v1/proposals/[id]/route.js +99 -0
  77. package/dist/routes/api/v1/proposals/index.d.ts +3 -0
  78. package/dist/routes/api/v1/proposals/index.js +10 -0
  79. package/dist/routes/api/v1/proposals/route.d.ts +315 -0
  80. package/dist/routes/api/v1/proposals/route.js +103 -0
  81. package/dist/routes/api/v1/resources/[id]/index.d.ts +3 -0
  82. package/dist/routes/api/v1/resources/[id]/index.js +7 -0
  83. package/dist/routes/api/v1/resources/[id]/route.d.ts +46 -0
  84. package/dist/routes/api/v1/resources/[id]/route.js +143 -0
  85. package/dist/routes/api/v1/resources/[id]/thumbnail/index.d.ts +3 -0
  86. package/dist/routes/api/v1/resources/[id]/thumbnail/index.js +5 -0
  87. package/dist/routes/api/v1/resources/[id]/thumbnail/route.d.ts +2 -0
  88. package/dist/routes/api/v1/resources/[id]/thumbnail/route.js +50 -0
  89. package/dist/routes/api/v1/resources/index.d.ts +3 -0
  90. package/dist/routes/api/v1/resources/index.js +6 -0
  91. package/dist/routes/api/v1/resources/route.d.ts +51 -0
  92. package/dist/routes/api/v1/resources/route.js +147 -0
  93. package/dist/routes/api/v1/search/route.d.ts +3 -0
  94. package/dist/routes/api/v1/search/route.js +39 -0
  95. package/dist/routes/api/v1/terminal/[proposalId]/create/index.d.ts +3 -0
  96. package/dist/routes/api/v1/terminal/[proposalId]/create/index.js +5 -0
  97. package/dist/routes/api/v1/terminal/[proposalId]/create/route.d.ts +10 -0
  98. package/dist/routes/api/v1/terminal/[proposalId]/create/route.js +27 -0
  99. package/dist/routes/api/v1/terminal/[proposalId]/destroy/index.d.ts +3 -0
  100. package/dist/routes/api/v1/terminal/[proposalId]/destroy/index.js +5 -0
  101. package/dist/routes/api/v1/terminal/[proposalId]/destroy/route.d.ts +10 -0
  102. package/dist/routes/api/v1/terminal/[proposalId]/destroy/route.js +21 -0
  103. package/dist/routes/api/v1/terminal/[proposalId]/resize/index.d.ts +3 -0
  104. package/dist/routes/api/v1/terminal/[proposalId]/resize/index.js +5 -0
  105. package/dist/routes/api/v1/terminal/[proposalId]/resize/route.d.ts +10 -0
  106. package/dist/routes/api/v1/terminal/[proposalId]/resize/route.js +21 -0
  107. package/dist/routes/api/v1/terminal/sessions/index.d.ts +3 -0
  108. package/dist/routes/api/v1/terminal/sessions/index.js +5 -0
  109. package/dist/routes/api/v1/terminal/sessions/route.d.ts +6 -0
  110. package/dist/routes/api/v1/terminal/sessions/route.js +29 -0
  111. package/dist/routes/api/v1/user/index.d.ts +3 -0
  112. package/dist/routes/api/v1/user/index.js +5 -0
  113. package/dist/routes/api/v1/user/preferences/route.d.ts +11 -0
  114. package/dist/routes/api/v1/user/preferences/route.js +31 -0
  115. package/dist/routes/api/v1/user/profile/route.d.ts +11 -0
  116. package/dist/routes/api/v1/user/profile/route.js +31 -0
  117. package/dist/routes/api/v1/user/settings/index.d.ts +1 -0
  118. package/dist/routes/api/v1/user/settings/index.js +1 -0
  119. package/dist/routes/api/v1/user/settings/route.d.ts +3 -0
  120. package/dist/routes/api/v1/user/settings/route.js +51 -0
  121. package/dist/server-with-static.d.ts +4 -0
  122. package/dist/server-with-static.js +144 -0
  123. package/dist/server.d.ts +1 -0
  124. package/dist/server.js +91 -0
  125. package/package.json +42 -0
  126. package/static/assets/index-BvTnrm0O.js +576 -0
  127. package/static/assets/index-Cm5dZHTl.css +33 -0
  128. package/static/assets/index-ORkAkJNi.js +576 -0
  129. package/static/assets/index-_Keadpms.js +576 -0
  130. package/static/index.html +17 -0
  131. package/static/vite.svg +1 -0
@@ -0,0 +1,144 @@
1
+ import { serve } from '@hono/node-server';
2
+ import { createNodeWebSocket } from '@hono/node-ws';
3
+ import { Hono } from 'hono';
4
+ import { cors } from 'hono/cors';
5
+ import { serveStatic } from '@hono/node-server/serve-static';
6
+ import path from 'path';
7
+ import fs from 'fs';
8
+ import { getGlobalTerminalManager } from './lib/terminal/global-manager.js';
9
+ import { fileURLToPath } from 'url';
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const app = new Hono();
13
+ // Enable CORS for development
14
+ app.use('/api/*', cors({
15
+ origin: '*',
16
+ credentials: true,
17
+ }));
18
+ // Create WebSocket support
19
+ const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
20
+ // WebSocket route for terminal sessions
21
+ app.get('/ws/terminal/:sessionId', upgradeWebSocket((c) => ({
22
+ onOpen: (_evt, ws) => {
23
+ const sessionId = c.req.param('sessionId');
24
+ console.log(`WebSocket connected for terminal session: ${sessionId}`);
25
+ const terminalManager = getGlobalTerminalManager();
26
+ // Extract the raw WebSocket from the WSContext
27
+ const rawWs = ws.raw;
28
+ if (!rawWs) {
29
+ console.error('Failed to get raw WebSocket');
30
+ ws.close(1000, 'WebSocket error');
31
+ return;
32
+ }
33
+ const success = terminalManager.attachWebSocket(sessionId, rawWs);
34
+ if (!success) {
35
+ console.error(`Failed to attach WebSocket to session: ${sessionId}`);
36
+ ws.close(1000, 'Session not found');
37
+ }
38
+ },
39
+ onMessage: (_evt, _ws) => {
40
+ // Message handling is done in the terminal manager
41
+ },
42
+ onClose: (_evt, _ws) => {
43
+ console.log('WebSocket connection closed');
44
+ },
45
+ onError: (evt, _ws) => {
46
+ console.error('WebSocket error:', evt);
47
+ }
48
+ })));
49
+ // Import and register API routes
50
+ import proposals from './routes/api/v1/proposals/index.js';
51
+ import terminalSessions from './routes/api/v1/terminal/sessions/index.js';
52
+ import terminalCreate from './routes/api/v1/terminal/[proposalId]/create/index.js';
53
+ import terminalDestroy from './routes/api/v1/terminal/[proposalId]/destroy/index.js';
54
+ import terminalResize from './routes/api/v1/terminal/[proposalId]/resize/index.js';
55
+ import ai from './routes/api/v1/ai/index.js';
56
+ import chats from './routes/api/v1/chats/index.js';
57
+ import chatsById from './routes/api/v1/chats/[id]/index.js';
58
+ import resources from './routes/api/v1/resources/index.js';
59
+ import resourcesById from './routes/api/v1/resources/[id]/index.js';
60
+ import resourcesThumbnail from './routes/api/v1/resources/[id]/thumbnail/index.js';
61
+ import context from './routes/api/v1/context/index.js';
62
+ import config from './routes/api/v1/config/index.js';
63
+ import user from './routes/api/v1/user/index.js';
64
+ import agents from './routes/api/v1/agents/index.js';
65
+ import agentsById from './routes/api/v1/agents/[id]/index.js';
66
+ // Register API routes
67
+ app.route('/api/v1/proposals', proposals);
68
+ app.route('/api/v1/terminal/sessions', terminalSessions);
69
+ app.route('/api/v1/terminal/:proposalId/create', terminalCreate);
70
+ app.route('/api/v1/terminal/:proposalId/destroy', terminalDestroy);
71
+ app.route('/api/v1/terminal/:proposalId/resize', terminalResize);
72
+ app.route('/api/v1/ai', ai);
73
+ app.route('/api/v1/chats', chats);
74
+ app.route('/api/v1/chats/:id', chatsById);
75
+ app.route('/api/v1/resources', resources);
76
+ app.route('/api/v1/resources/:id', resourcesById);
77
+ app.route('/api/v1/resources/:id/thumbnail', resourcesThumbnail);
78
+ app.route('/api/v1/context', context);
79
+ app.route('/api/v1/config', config);
80
+ app.route('/api/v1/user', user);
81
+ app.route('/api/v1/agents', agents);
82
+ app.route('/api/v1/agents/:id', agentsById);
83
+ // Health check endpoint
84
+ app.get('/api/health', (c) => {
85
+ return c.json({ status: 'ok', timestamp: new Date().toISOString() });
86
+ });
87
+ // Serve static files from the frontend build
88
+ // This will look for the frontend build in multiple possible locations
89
+ const possibleStaticPaths = [
90
+ // When installed via npm globally
91
+ path.join(__dirname, '../../frontend/dist'),
92
+ // When running from development
93
+ path.join(__dirname, '../../../frontend/dist'),
94
+ // When bundled with the API package
95
+ path.join(__dirname, '../static')
96
+ ];
97
+ // Find the first existing static path
98
+ let staticPath = null;
99
+ for (const possiblePath of possibleStaticPaths) {
100
+ try {
101
+ if (fs.existsSync(possiblePath)) {
102
+ staticPath = possiblePath;
103
+ console.log(`📁 Serving static files from: ${staticPath}`);
104
+ break;
105
+ }
106
+ }
107
+ catch (e) {
108
+ // Continue checking other paths
109
+ }
110
+ }
111
+ if (staticPath) {
112
+ // Serve static files for all non-API routes
113
+ app.use('/*', serveStatic({
114
+ root: staticPath,
115
+ // Serve index.html for all non-file routes (SPA routing)
116
+ onNotFound: (_p, c) => {
117
+ const html = fs.readFileSync(path.join(staticPath, 'index.html'), 'utf-8');
118
+ c.html(html);
119
+ }
120
+ }));
121
+ }
122
+ // Export function to start the server
123
+ export async function startServer(options = {}) {
124
+ const port = options.port || (process.env.PORT ? parseInt(process.env.PORT) : 3000);
125
+ const host = options.host || '0.0.0.0';
126
+ console.log(`Starting server on ${host}:${port}...`);
127
+ const server = serve({
128
+ fetch: app.fetch,
129
+ port,
130
+ hostname: host,
131
+ });
132
+ // Inject WebSocket support
133
+ injectWebSocket(server);
134
+ console.log(`🚀 Server running at http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`);
135
+ console.log(`🔌 WebSocket available at ws://${host === '0.0.0.0' ? 'localhost' : host}:${port}/ws/terminal/:sessionId`);
136
+ if (staticPath) {
137
+ console.log(`🌐 Frontend available at http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`);
138
+ }
139
+ return server;
140
+ }
141
+ // Start server if this file is run directly
142
+ if (import.meta.url === `file://${process.argv[1]}`) {
143
+ startServer();
144
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/server.js ADDED
@@ -0,0 +1,91 @@
1
+ import { serve } from '@hono/node-server';
2
+ import { createNodeWebSocket } from '@hono/node-ws';
3
+ import { Hono } from 'hono';
4
+ import { cors } from 'hono/cors';
5
+ import { getGlobalTerminalManager } from './lib/terminal/global-manager.js';
6
+ const app = new Hono();
7
+ // Enable CORS for frontend
8
+ app.use('*', cors({
9
+ origin: ['http://localhost:5173', 'http://localhost:5174', 'http://localhost:3000'], // Vite and Next.js dev servers
10
+ credentials: true,
11
+ }));
12
+ // Create WebSocket support
13
+ const { injectWebSocket, upgradeWebSocket } = createNodeWebSocket({ app });
14
+ // WebSocket route for terminal sessions
15
+ app.get('/ws/terminal/:sessionId', upgradeWebSocket((c) => ({
16
+ onOpen: (evt, ws) => {
17
+ const sessionId = c.req.param('sessionId');
18
+ console.log(`WebSocket connected for terminal session: ${sessionId}`);
19
+ const terminalManager = getGlobalTerminalManager();
20
+ // Extract the raw WebSocket from the WSContext
21
+ const rawWs = ws.raw;
22
+ if (!rawWs) {
23
+ console.error('Failed to get raw WebSocket');
24
+ ws.close(1000, 'WebSocket error');
25
+ return;
26
+ }
27
+ const success = terminalManager.attachWebSocket(sessionId, rawWs);
28
+ if (!success) {
29
+ console.error(`Failed to attach WebSocket to session: ${sessionId}`);
30
+ ws.close(1000, 'Session not found');
31
+ }
32
+ },
33
+ onMessage: (evt, ws) => {
34
+ // Message handling is done in the terminal manager
35
+ },
36
+ onClose: (evt, ws) => {
37
+ console.log('WebSocket connection closed');
38
+ },
39
+ onError: (evt, ws) => {
40
+ console.error('WebSocket error:', evt);
41
+ }
42
+ })));
43
+ // Import and register API routes
44
+ import proposals from './routes/api/v1/proposals/index.js';
45
+ import terminalSessions from './routes/api/v1/terminal/sessions/index.js';
46
+ import terminalCreate from './routes/api/v1/terminal/[proposalId]/create/index.js';
47
+ import terminalDestroy from './routes/api/v1/terminal/[proposalId]/destroy/index.js';
48
+ import terminalResize from './routes/api/v1/terminal/[proposalId]/resize/index.js';
49
+ import ai from './routes/api/v1/ai/index.js';
50
+ import chats from './routes/api/v1/chats/index.js';
51
+ import chatsById from './routes/api/v1/chats/[id]/index.js';
52
+ import resources from './routes/api/v1/resources/index.js';
53
+ import resourcesById from './routes/api/v1/resources/[id]/index.js';
54
+ import resourcesThumbnail from './routes/api/v1/resources/[id]/thumbnail/index.js';
55
+ import context from './routes/api/v1/context/index.js';
56
+ import config from './routes/api/v1/config/index.js';
57
+ import user from './routes/api/v1/user/index.js';
58
+ import agents from './routes/api/v1/agents/index.js';
59
+ import agentsById from './routes/api/v1/agents/[id]/index.js';
60
+ // Register API routes
61
+ app.route('/api/v1/proposals', proposals);
62
+ app.route('/api/v1/terminal/sessions', terminalSessions);
63
+ app.route('/api/v1/terminal/:proposalId/create', terminalCreate);
64
+ app.route('/api/v1/terminal/:proposalId/destroy', terminalDestroy);
65
+ app.route('/api/v1/terminal/:proposalId/resize', terminalResize);
66
+ app.route('/api/v1/ai', ai);
67
+ app.route('/api/v1/chats', chats);
68
+ app.route('/api/v1/chats/:id', chatsById);
69
+ app.route('/api/v1/resources', resources);
70
+ app.route('/api/v1/resources/:id', resourcesById);
71
+ app.route('/api/v1/resources/:id/thumbnail', resourcesThumbnail);
72
+ app.route('/api/v1/context', context);
73
+ app.route('/api/v1/config', config);
74
+ app.route('/api/v1/user', user);
75
+ app.route('/api/v1/agents', agents);
76
+ app.route('/api/v1/agents/:id', agentsById);
77
+ // Health check endpoint
78
+ app.get('/health', (c) => {
79
+ return c.json({ status: 'ok', timestamp: new Date().toISOString() });
80
+ });
81
+ // Start server
82
+ const port = process.env.PORT ? parseInt(process.env.PORT) : 3001;
83
+ console.log(`Starting server on port ${port}...`);
84
+ const server = serve({
85
+ fetch: app.fetch,
86
+ port,
87
+ });
88
+ // Inject WebSocket support
89
+ injectWebSocket(server);
90
+ console.log(`🚀 Server running at http://localhost:${port}`);
91
+ console.log(`🔌 WebSocket available at ws://localhost:${port}/ws/terminal/:sessionId`);
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@lovelybunch/api",
3
+ "version": "1.0.7",
4
+ "type": "module",
5
+ "main": "dist/server-with-static.js",
6
+ "exports": {
7
+ ".": "./dist/server-with-static.js",
8
+ "./server": "./dist/server.js"
9
+ },
10
+ "files": [
11
+ "dist/**/*",
12
+ "static/**/*"
13
+ ],
14
+ "scripts": {
15
+ "dev": "tsx watch src/server.ts",
16
+ "build": "tsc",
17
+ "build:bundle": "tsc && node scripts/bundle-frontend.js",
18
+ "start": "node dist/server-with-static.js",
19
+ "start:dev": "node dist/server.js",
20
+ "test": "echo \"Error: no test specified\" && exit 1"
21
+ },
22
+ "keywords": [],
23
+ "author": "",
24
+ "license": "ISC",
25
+ "description": "",
26
+ "dependencies": {
27
+ "@hono/node-server": "^1.13.7",
28
+ "@hono/node-ws": "^1.0.6",
29
+ "@lovelybunch/types": "^1.0.7",
30
+ "fuse.js": "^7.0.0",
31
+ "gray-matter": "^4.0.3",
32
+ "hono": "^4.9.5",
33
+ "node-pty": "^1.0.0",
34
+ "ws": "^8.18.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^22.10.2",
38
+ "@types/ws": "^8.5.13",
39
+ "tsx": "^4.19.2",
40
+ "typescript": "^5.7.2"
41
+ }
42
+ }