@lovelybunch/api 1.0.10 → 1.0.11

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.
@@ -47,74 +47,41 @@ app.get('/ws/terminal/:sessionId', upgradeWebSocket((c) => ({
47
47
  }
48
48
  })));
49
49
  // Import and register API routes
50
- import * as proposals from './routes/api/v1/proposals/route.js';
51
- import * as proposalsById from './routes/api/v1/proposals/[id]/route.js';
52
- import * as terminalSessions from './routes/api/v1/terminal/sessions/route.js';
53
- import * as ai from './routes/api/v1/ai/route.js';
54
- import * as chats from './routes/api/v1/chats/route.js';
55
- import * as chatsById from './routes/api/v1/chats/[id]/route.js';
56
- import * as resources from './routes/api/v1/resources/route.js';
57
- import * as resourcesById from './routes/api/v1/resources/[id]/route.js';
58
- import * as config from './routes/api/v1/config/route.js';
59
- import agentsApp from './routes/api/v1/agents/route.js';
60
- import agentsByIdApp from './routes/api/v1/agents/[id]/route.js';
61
- // Handle trailing slashes by creating explicit redirect routes
62
- const trailingSlashRoutes = [
63
- '/api/v1/proposals/',
64
- '/api/v1/terminal/sessions/',
65
- '/api/v1/ai/',
66
- '/api/v1/chats/',
67
- '/api/v1/resources/',
68
- '/api/v1/config/'
69
- ];
70
- // Add explicit handlers for trailing slash routes that redirect to non-slash versions
71
- trailingSlashRoutes.forEach(route => {
72
- const methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
73
- methods.forEach(method => {
74
- app.on(method, route, (c) => {
75
- const newPath = route.slice(0, -1);
76
- const url = new URL(c.req.url);
77
- url.pathname = newPath;
78
- return c.redirect(url.toString(), 308);
79
- });
80
- });
81
- });
82
- // Handle trailing slashes for parameterized routes
83
- app.on(['GET', 'PUT', 'PATCH', 'DELETE'], '/api/v1/proposals/:id/', (c) => {
84
- const id = c.req.param('id');
85
- const url = new URL(c.req.url);
86
- url.pathname = `/api/v1/proposals/${id}`;
87
- return c.redirect(url.toString(), 308);
88
- });
89
- app.on(['GET', 'PUT', 'DELETE'], '/api/v1/chats/:id/', (c) => {
90
- const id = c.req.param('id');
91
- const url = new URL(c.req.url);
92
- url.pathname = `/api/v1/chats/${id}`;
93
- return c.redirect(url.toString(), 308);
94
- });
95
- app.on(['GET'], '/api/v1/resources/:id/', (c) => {
96
- const id = c.req.param('id');
97
- const url = new URL(c.req.url);
98
- url.pathname = `/api/v1/resources/${id}`;
99
- return c.redirect(url.toString(), 308);
100
- });
101
- // Register API routes - individual handlers
102
- app.get('/api/v1/proposals', proposals.GET);
103
- app.post('/api/v1/proposals', proposals.POST);
104
- app.get('/api/v1/proposals/:id', proposalsById.GET);
105
- app.patch('/api/v1/proposals/:id', proposalsById.PATCH);
106
- app.delete('/api/v1/proposals/:id', proposalsById.DELETE);
107
- app.get('/api/v1/terminal/sessions', terminalSessions.GET);
108
- app.post('/api/v1/ai', ai.POST);
109
- app.get('/api/v1/chats', chats.GET);
110
- app.post('/api/v1/chats', chats.POST);
111
- app.get('/api/v1/chats/:id', chatsById.GET);
112
- app.get('/api/v1/resources', resources.GET);
113
- app.get('/api/v1/resources/:id', resourcesById.GET);
114
- app.get('/api/v1/config', config.GET);
115
- // Register API routes - Hono apps
116
- app.route('/api/v1/agents', agentsApp);
117
- app.route('/api/v1/agents', agentsByIdApp);
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 FIRST
67
+ console.log('🔗 Registering API routes...');
68
+ app.route('/api/v1/proposals', proposals);
69
+ app.route('/api/v1/terminal/sessions', terminalSessions);
70
+ app.route('/api/v1/terminal/:proposalId/create', terminalCreate);
71
+ app.route('/api/v1/terminal/:proposalId/destroy', terminalDestroy);
72
+ app.route('/api/v1/terminal/:proposalId/resize', terminalResize);
73
+ app.route('/api/v1/ai', ai);
74
+ app.route('/api/v1/chats', chats);
75
+ app.route('/api/v1/chats/:id', chatsById);
76
+ app.route('/api/v1/resources', resources);
77
+ app.route('/api/v1/resources/:id', resourcesById);
78
+ app.route('/api/v1/resources/:id/thumbnail', resourcesThumbnail);
79
+ app.route('/api/v1/context', context);
80
+ app.route('/api/v1/config', config);
81
+ app.route('/api/v1/user', user);
82
+ app.route('/api/v1/agents', agents);
83
+ app.route('/api/v1/agents/:id', agentsById);
84
+ console.log('✅ API routes registered');
118
85
  // Health check endpoint
119
86
  app.get('/api/health', (c) => {
120
87
  return c.json({ status: 'ok', timestamp: new Date().toISOString() });
@@ -127,7 +94,9 @@ const possibleStaticPaths = [
127
94
  // When running from development
128
95
  path.join(__dirname, '../../../frontend/dist'),
129
96
  // When bundled with the API package
130
- path.join(__dirname, '../static')
97
+ path.join(__dirname, '../static'),
98
+ // When running from coconuts globally
99
+ path.join(__dirname, '../../node_modules/@lovelybunch/api/static')
131
100
  ];
132
101
  // Find the first existing static path
133
102
  let staticPath = null;
@@ -144,12 +113,14 @@ for (const possiblePath of possibleStaticPaths) {
144
113
  }
145
114
  }
146
115
  if (staticPath) {
147
- // Serve static assets
116
+ // Serve all static assets (CSS, JS, images, etc.)
148
117
  app.use('/assets/*', serveStatic({ root: staticPath }));
149
118
  // Serve specific static files
150
119
  app.use('/vite.svg', serveStatic({ root: staticPath }));
151
120
  app.use('/favicon.ico', serveStatic({ root: staticPath }));
152
- // Serve index.html for all non-API, non-WebSocket routes (SPA routing)
121
+ }
122
+ // Serve index.html for all non-API, non-WebSocket routes (SPA routing) - LAST
123
+ if (staticPath) {
153
124
  app.get('*', async (c) => {
154
125
  const requestPath = c.req.path;
155
126
  // Don't serve index.html for API or WebSocket routes
@@ -161,10 +132,15 @@ if (staticPath) {
161
132
  return c.html(html);
162
133
  }
163
134
  catch (error) {
135
+ console.error('Failed to serve index.html:', error);
164
136
  return c.text('Not Found', 404);
165
137
  }
166
138
  });
167
139
  }
140
+ else {
141
+ console.warn('⚠️ No static files found. Frontend may not work properly.');
142
+ console.warn(' Run "pnpm run build:bundle" in the api package to bundle frontend files.');
143
+ }
168
144
  // Export function to start the server
169
145
  export async function startServer(options = {}) {
170
146
  const port = options.port || (process.env.PORT ? parseInt(process.env.PORT) : 3000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lovelybunch/api",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "main": "dist/server-with-static.js",
6
6
  "exports": {
@@ -19,14 +19,14 @@
19
19
  "start:dev": "node dist/server.js",
20
20
  "test": "echo \"Error: no test specified\" && exit 1"
21
21
  },
22
- "keywords": [],
22
+ "keywords": ["api", "server", "hono", "gait", "coconut"],
23
23
  "author": "",
24
24
  "license": "ISC",
25
- "description": "",
25
+ "description": "GAIT API server with Hono and static frontend serving",
26
26
  "dependencies": {
27
27
  "@hono/node-server": "^1.13.7",
28
28
  "@hono/node-ws": "^1.0.6",
29
- "@lovelybunch/types": "^1.0.7",
29
+ "@lovelybunch/types": "^1.0.11",
30
30
  "fuse.js": "^7.0.0",
31
31
  "gray-matter": "^4.0.3",
32
32
  "hono": "^4.9.5",