add logging
This commit is contained in:
parent
2ed5bf1a8f
commit
a71b631cb9
@ -1,6 +1,6 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { generateMockStockData } from './stock-utils';
|
||||
import { callTool, sendPrompt, useProps } from '@mcp-ui/library/ui';
|
||||
import { callTool, sendPrompt, useProps } from 'mcp-ui-kit/ui';
|
||||
|
||||
|
||||
// Types for props passed from the tool handler
|
||||
|
||||
@ -7,6 +7,7 @@ const bundleCache = new Map<string, string>();
|
||||
const isDev = process.env.NODE_ENV !== 'production';
|
||||
|
||||
async function runBuild(entryPath: string): Promise<esbuild.BuildResult<{ write: false }>> {
|
||||
console.log('[mcp-ui-kit] runBuild called for:', entryPath);
|
||||
return esbuild.build({
|
||||
entryPoints: [entryPath],
|
||||
bundle: true,
|
||||
@ -23,15 +24,24 @@ async function runBuild(entryPath: string): Promise<esbuild.BuildResult<{ write:
|
||||
}
|
||||
|
||||
export async function bundleComponent(entryPath: string): Promise<string> {
|
||||
console.log('[mcp-ui-kit] bundleComponent called for:', entryPath);
|
||||
console.log('[mcp-ui-kit] isDev:', isDev, 'NODE_ENV:', process.env.NODE_ENV);
|
||||
console.log('[mcp-ui-kit] Cache has entry:', bundleCache.has(entryPath));
|
||||
|
||||
if (!isDev && bundleCache.has(entryPath)) {
|
||||
console.log('[mcp-ui-kit] Returning cached bundle');
|
||||
return bundleCache.get(entryPath)!;
|
||||
}
|
||||
|
||||
let result: esbuild.BuildResult<{ write: false }>;
|
||||
|
||||
try {
|
||||
console.log('[mcp-ui-kit] Attempting first build...');
|
||||
result = await runBuild(entryPath);
|
||||
console.log('[mcp-ui-kit] First build succeeded');
|
||||
} catch (error) {
|
||||
console.log('[mcp-ui-kit] First build failed:', error instanceof Error ? error.message : error);
|
||||
|
||||
// Handle esbuild service errors in serverless environments (Vercel, Lambda, etc.)
|
||||
// This happens when the serverless runtime freezes/stops the esbuild subprocess.
|
||||
const isServiceError = error instanceof Error && (
|
||||
@ -39,20 +49,26 @@ export async function bundleComponent(entryPath: string): Promise<string> {
|
||||
error.message.includes('service is no longer running') ||
|
||||
error.message.includes('The service')
|
||||
);
|
||||
console.log('[mcp-ui-kit] Is service error:', isServiceError);
|
||||
|
||||
if (isServiceError) {
|
||||
// Force stop the dead service, then retry - esbuild will start fresh
|
||||
console.log('[mcp-ui-kit] Stopping esbuild service and retrying...');
|
||||
await esbuild.stop();
|
||||
result = await runBuild(entryPath);
|
||||
console.log('[mcp-ui-kit] Retry succeeded');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const bundledJS = result.outputFiles[0].text;
|
||||
console.log('[mcp-ui-kit] Bundle size:', bundledJS.length, 'bytes');
|
||||
|
||||
// Only cache in production mode
|
||||
if (!isDev) {
|
||||
bundleCache.set(entryPath, bundledJS);
|
||||
console.log('[mcp-ui-kit] Bundle cached');
|
||||
}
|
||||
|
||||
return bundledJS;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user