Back

Version 31

12/19/2024
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import React, { useState, useEffect, useRef } from "https://esm.sh/react@18.2.0";
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
import { OpenAI } from "https://esm.town/v/std/openai";

// Robust type definitions
interface Message {
id: number;
type: 'user' | 'bot';
content: string;
timestamp: string;
}

// Error Boundary Component with improved error handling
class ErrorBoundary extends React.Component<
{ children: React.ReactNode },
{ hasError: boolean; error?: Error }
> {
constructor(props: { children: React.ReactNode }) {
super(props);
this.state = { hasError: false };
}

static getDerivedStateFromError(error: Error) {
return { hasError: true, error };
}

componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
console.error("Uncaught error:", error, errorInfo);
}

render() {
if (this.state.hasError) {
return (
<div style={{
padding: '20px',
lucasmillen-millenchat.web.val.run
Updated: December 19, 2024