A UI-agnostic TrustGraph client library for WebSocket communication and state management.
This package is currently under development as part of migrating the TrustGraph client from a Chakra UI application to a reusable, framework-agnostic library.
@trustgraph/client
- Main entry point@trustgraph/client/state
- State management hooks and stores@trustgraph/client/providers
- React context providers@trustgraph/client/types
- TypeScript type definitions@trustgraph/client/tables
- Table definitions (coming soon - UI-agnostic format)
npm install @trustgraph/client
import { useSessionStore, SocketProvider } from '@trustgraph/client'
// Use state management
const sessionStore = useSessionStore()
// Wrap your app with the socket provider
<SocketProvider>
<YourApp />
</SocketProvider>
import {
tokenCostColumns,
promptColumns,
documentColumns,
schemaColumns,
type TableRenderers
} from '@trustgraph/client/tables'
// Option 1: Simple tables (no renderers needed)
const tokenColumns = tokenCostColumns
// Option 2: Tables with custom renderers for your UI framework
const renderers: TableRenderers = {
code: (value) => <YourCodeComponent>{value}</YourCodeComponent>,
badge: (items) => items.map(item => <YourBadge key={item}>{item}</YourBadge>),
checkbox: (checked, onChange, indeterminate) => (
<YourCheckbox
checked={checked}
onChange={onChange}
indeterminate={indeterminate === 'indeterminate'}
/>
),
button: (label, onClick, variant) => (
<YourButton variant={variant} onClick={onClick}>{label}</YourButton>
)
}
// Complex tables with full renderer support
const docColumns = documentColumns(renderers) // Selection, tags, timestamps
const codeColumns = promptColumns(renderers) // Code syntax highlighting
const dataColumns = schemaColumns(renderers) // Field badges, type indicators
// Use with any table component (TanStack Table, MUI DataGrid, AG-Grid, etc.)
<YourTableComponent columns={docColumns} data={documents} />
import {
useNotification,
useNotificationSubscription,
useNotificationState
} from '@trustgraph/client/state'
// Emit notifications from anywhere in your app
function MyComponent() {
const notification = useNotification()
const handleAction = () => {
notification.success('Action completed successfully!')
notification.error('Something went wrong', { duration: 10000 })
notification.warning('This is a warning')
notification.info('FYI: Something happened')
}
}
// Subscribe to notifications in your UI layer
function NotificationProvider({ children }) {
useNotificationSubscription((notification) => {
// Handle with your UI framework of choice
if (notification.type === 'success') {
showToast(notification.message, { type: 'success' })
} else if (notification.type === 'error') {
showErrorModal(notification.message)
}
// Or log to console for server-side apps
console.log(`[${notification.type}]`, notification.message)
})
return <>{children}</>
}
// Monitor notification state (useful for notification centers)
function NotificationCenter() {
const { notifications, hasActiveListeners } = useNotificationState()
return (
<div>
<p>Active listeners: {hasActiveListeners ? 'Yes' : 'No'}</p>
<p>Recent notifications: {notifications.length}</p>
</div>
)
}
✅ Completed:
- Package configuration and build setup
- State management exports (50+ hooks and stores)
- Basic TypeScript configuration
- CommonJS and ES modules support
- Core API structure
- ✅ UI-agnostic table definitions (13/13 tables migrated)
- Simple tables: tokenCostColumns, ontologyColumns, mcpToolColumns, agentToolColumns, nodePropertyColumns
- Renderer tables: promptColumns, flowClassColumns (support custom code/text renderers)
- Complex tables: processingColumns, schemaColumns, nodeRelationshipColumns, documentColumns, flowColumns, knowledgeCoreColumns (support badges, checkboxes, buttons)
- ✅ Event-based notification system
- Pub/sub architecture with
useNotificationSubscription
- History tracking with
useNotificationState
- Framework-agnostic notification emission
- Auto-dismissal and manual control
- Pub/sub architecture with
🚧 In Progress:
- Complete TypeScript declarations
📝 Planned:
- Full migration from Chakra UI dependencies
- Comprehensive documentation
- Usage examples
- Migration guide from original codebase
npm run build # Build for production
npm run dev # Build in watch mode
npm run type-check # TypeScript validation
npm run lint # ESLint validation
@tanstack/react-query
- Server state management@tanstack/react-table
- Table functionality (will be UI-agnostic)zustand
- Client state managementuuid
- UUID generationcompute-cosine-similarity
- Vector similarity calculations
react
^16.8.0 || ^17.0.0 || ^18.0.0react-dom
^16.8.0 || ^17.0.0 || ^18.0.0
This library follows a layered architecture:
- Core Services - WebSocket management, message protocol, authentication
- State Management - TanStack Query integration and Zustand stores
- Public API - React hooks and providers for consumer applications
See docs/tech-spec/architecture.md
for detailed architectural documentation.
Apache 2.0