Skip to content

Conversation

@aditya-damerla128
Copy link
Collaborator

@aditya-damerla128 aditya-damerla128 commented Dec 24, 2025

Description

Implements the @ozwell/react package as outlined in issue #33.

This PR adds a complete React wrapper around the existing Ozwell chat widget, providing React developers with a familiar component-based API while leveraging the proven vanilla JS implementation.

Changes

Package Structure

  • packages/react/src/types.ts - TypeScript type definitions
  • packages/react/src/OzwellChat.tsx - Main React component
  • packages/react/src/useOzwell.ts - Hook for programmatic control
  • packages/react/src/index.ts - Package exports

Features

  • Dynamic script loading and lifecycle management
  • Prop mapping to vanilla widget config
  • Event handling via postMessage
  • onToolCall prop for simplified MCP tool handling
  • Full TypeScript support with strict types

Documentation

  • README with usage examples
  • Tool handling documentation
  • Clear distinction between current vs planned features

Feature Support

Currently Available

  • Custom endpoints (endpoint prop)
  • Model selection (model prop)
  • MCP tool/function calling (tools prop + onToolCall callback)
  • Context updates (context prop)
  • System prompts (system prop)
  • Debug mode (debug prop)
  • OpenAI API compatibility (openaiApiKey prop)
  • Programmatic open/close control

Coming Soon

  • Scoped API keys (apiKey prop)
  • Agent management (agentId prop)
  • Theme customization (theme, primaryColor props)

Testing

  • Package builds successfully (ESM + CJS)
  • TypeScript compiles without errors
  • Tested with TimeHarbor app integration
  • Tool calls working end-to-end

Closes #33

- Add package.json with React 18/19 peer dependencies
- Configure TypeScript with strict mode and tsup bundler
- Set up npm ignore for clean publishing
- Add README with accurate feature support matrix

Package configuration:
- Dual ESM/CJS output via tsup
- Type declarations enabled
- Development and build scripts ready

Feature clarity:
- Documents currently working features (tools, endpoints, context)
- Clearly marks planned features (apiKey, agentId, theming)
- Warns users about docs describing future API state

Closes part of prerequisites for React package implementation
@aditya-damerla128 aditya-damerla128 changed the title feat: Add @ozwell/react package foundation feat: Add @ozwell/react package Dec 25, 2025
Define complete type system for React package:

Core Types:
- OzwellChatProps: Component props with current + future features
- UseOzwellReturn: Hook return type with state and methods
- OzwellConfig: Configuration matching vanilla widget
- OzwellTool: MCP tool definitions (OpenAI-compatible)

Features:
- Clear separation of implemented vs planned features
- Full JSDoc documentation
- Window type extensions for vanilla API
- PostMessage event types
- Type-safe, no any types

Maps vanilla widget capabilities:
- endpoint, model, system, tools (current)
- apiKey, agentId, theme (future)

Verified: TypeScript compiles without errors
Main React component wrapping vanilla widget with:
- Dynamic script loading and lifecycle management
- Prop mapping to vanilla config
- Event handling via postMessage
- Support for current + future props

Verified: TypeScript compiles successfully
React hook for programmatic widget control with:
- Widget state: isReady, isOpen, iframe
- Working method: setContext() (uses vanilla API)
- Placeholder methods: open(), close(), toggle(), sendMessage()
- Event monitoring via postMessage
- Forward-compatible for future vanilla features

Verified: TypeScript compiles successfully
…sage

Changes:
- Add src/index.ts with component, hook, and type exports
- Fix package.json exports to match actual build output (index.js/index.cjs)
- Add comprehensive "Using Tools" section to README with examples
- Document tool definition and postMessage-based tool handling
- Include tool handler pattern examples for cleaner code

Basic testing done with TimeHarbor app integration - module resolution working
- Add open(), close(), isOpen, hasUnread to OzwellChatAPI types
- Implement open/close methods in useOzwell hook
- Add hasUnread state tracking with unread event listener
- Add autoOpenOnReply config option
- Add assistant_response message type
- Update OzwellWidgetMessage with new event types
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces the @ozwell/react package, providing React developers with a component-based wrapper around the existing Ozwell vanilla JavaScript chat widget. The implementation includes TypeScript type definitions, React components, custom hooks, and comprehensive documentation.

Key Changes:

  • Complete TypeScript implementation with strict type safety
  • OzwellChat component for easy React integration
  • useOzwell hook for programmatic widget control
  • MCP (Model Context Protocol) tool calling support with simplified callback API

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
packages/react/package.json Package configuration with dual ESM/CJS builds, React 18/19 peer dependencies, and npm publishing setup
packages/react/tsconfig.json TypeScript configuration with strict mode, React JSX support, and bundler module resolution
packages/react/src/types.ts Comprehensive TypeScript type definitions for props, config, MCP tools, and message protocols
packages/react/src/OzwellChat.tsx Main React component that loads the vanilla widget script and provides React-friendly props/callbacks
packages/react/src/useOzwell.ts Custom React hook for programmatic widget control (open/close/toggle/sendMessage/setContext)
packages/react/src/index.ts Package entry point exporting all components, hooks, and TypeScript types
packages/react/README.md Package documentation with installation, quick start, feature matrix, and MCP tool examples
packages/react/.npmignore NPM publish configuration excluding source files and development artifacts
packages/react/package-lock.json Dependency lock file with React 19, TypeScript 5.9, and tsup build tooling
docs/frontend/react.md Comprehensive integration guide with API reference, usage examples, and tool handling patterns
Files not reviewed (1)
  • packages/react/package-lock.json: Language not supported

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@aditya-damerla128
Copy link
Collaborator Author

Fixed: removed dead code, emojis, and getElementById examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add in React component usage

2 participants