agent-window 1.0.2 → 1.0.3

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/api/server.js +22 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-window",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A window to interact with AI agents through chat interfaces. Simplified interaction, powerful backend capabilities.",
5
5
  "type": "module",
6
6
  "main": "src/bot.js",
package/src/api/server.js CHANGED
@@ -75,23 +75,32 @@ export function createServer(options = {}) {
75
75
  registerWebSocket(fastify);
76
76
 
77
77
  // Serve static files (frontend build)
78
- const distPath = join(process.cwd(), 'web', 'dist');
79
- if (existsSync(distPath)) {
78
+ // __dirname is src/api/, so we go up two levels to package root, then into web/dist
79
+ const distPath = join(__dirname, '..', '..', 'web', 'dist');
80
+ const hasDist = existsSync(distPath);
81
+
82
+ if (hasDist) {
80
83
  fastify.register(fastifyStatic, {
81
84
  root: distPath,
82
- prefix: '/'
83
- });
84
-
85
- // SPA fallback - serve index.html for non-API routes
86
- fastify.setNotFoundHandler(async (request, reply) => {
87
- if (request.url.startsWith('/api/') || request.url.startsWith('/ws/')) {
88
- reply.code(404).send({ error: 'Not found' });
89
- } else {
90
- reply.sendFile('index.html');
91
- }
85
+ prefix: '/',
86
+ decorateReply: false
92
87
  });
93
88
  }
94
89
 
90
+ // SPA fallback - serve index.html for non-API routes (if dist exists)
91
+ fastify.setNotFoundHandler(async (request, reply) => {
92
+ if (request.url.startsWith('/api/') || request.url.startsWith('/ws/')) {
93
+ reply.code(404).send({ error: 'Not found' });
94
+ } else if (hasDist) {
95
+ reply.sendFile('index.html');
96
+ } else {
97
+ reply.code(500).send({
98
+ error: 'Frontend not built',
99
+ message: 'The web UI assets are not available. Please report this issue.'
100
+ });
101
+ }
102
+ });
103
+
95
104
  // Graceful shutdown
96
105
  const gracefulShutdown = async (signal) => {
97
106
  fastify.log.info(`Received ${signal}, shutting down gracefully...`);
@@ -110,7 +119,7 @@ export function createServer(options = {}) {
110
119
  */
111
120
  export function getPackageVersion() {
112
121
  try {
113
- const pkgPath = join(process.cwd(), 'package.json');
122
+ const pkgPath = join(__dirname, '..', '..', 'package.json');
114
123
  const pkg = require(pkgPath);
115
124
  return pkg.version || 'unknown';
116
125
  } catch {