0.1.0 • Published 6 months ago
api-city-sdk v0.1.0
Tapestry Plugin SDK
A powerful SDK for building plugins for the Tapestry Chat platform. Create interactive plugins that can integrate with Solana wallets, manage state, and provide rich user interfaces.
Features
- 🔒 Secure wallet integration
- 💾 Persistent storage
- 🎨 React-based UI components
- 📨 Message handling
- 🔔 Notification system
- ⚙️ Settings management
Installation
npm install @tapestry/plugin-sdk
# or
pnpm add @tapestry/plugin-sdk
Quick Start
- Create a new plugin by extending the BasePlugin class:
import { BasePlugin, PluginManifest } from '@tapestry/plugin-sdk';
const manifest: PluginManifest = {
name: 'My Plugin',
version: '1.0.0',
description: 'A simple plugin',
author: 'Your Name',
permissions: ['wallet:read', 'ui:render'],
entryPoints: {
main: 'index.ts'
}
};
export class MyPlugin extends BasePlugin {
constructor() {
super(manifest);
}
protected async onInitialize(): Promise<void> {
// Initialize your plugin
this.showNotification('Plugin initialized!');
}
protected async onCleanup(): Promise<void> {
// Cleanup when plugin is disabled
}
}
- Use the provided APIs:
// Wallet operations
const address = await this.wallet.getAddress();
const signature = await this.wallet.signMessage('Hello');
// Storage operations
await this.storage.set('myKey', { value: 123 });
const data = await this.storage.get('myKey');
// UI rendering
this.ui.render(
<div className="p-4">
<h1>My Plugin UI</h1>
<button onClick={() => this.showNotification('Clicked!')}>
Click me
</button>
</div>
);
// Notifications
this.showNotification('Operation successful!', 'success');
Plugin Manifest
The manifest defines your plugin's metadata and required permissions:
interface PluginManifest {
name: string;
version: string;
description: string;
author: string;
permissions: PluginPermission[];
entryPoints: {
main: string;
settings?: string;
styles?: string;
};
}
Available permissions:
wallet:read
- Read wallet address and public datawallet:write
- Sign messages and send transactionsstorage:read
- Read from plugin storagestorage:write
- Write to plugin storageui:render
- Render UI componentsnotifications:create
- Show notifications
Best Practices
- Error Handling
try {
await this.wallet.sendTransaction(tx);
this.showNotification('Success!', 'success');
} catch (error) {
this.showNotification(error.message, 'error');
}
- State Management
// Save state on changes
private async saveState(): Promise<void> {
await this.storage.set('pluginState', this.state);
}
// Load state on initialization
protected async onInitialize(): Promise<void> {
this.state = await this.storage.get('pluginState') || defaultState;
}
- UI Updates
// Update UI when state changes
private updateUI(): void {
this.ui.update(
<MyComponent
data={this.state}
onAction={this.handleAction}
/>
);
}
Examples
Check out our example plugins:
- Token Swap Plugin
- More examples coming soon...
Development
- Clone the repository
- Install dependencies:
pnpm install
- Build the SDK:
pnpm build
- Run tests:
pnpm test
Contributing
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
MIT License - see LICENSE for details
0.1.0
6 months ago