@frontextai/extension-toolbar-srpc-contract
v0.2.1
Published
SRPC contract implementation for VS Code extension and toolbar communication
Readme
@frontext/extension-toolbar-srpc-contract
A communication contract between the frontext VS Code extension and the frontext toolbar.
What is this package?
This package defines the communication protocol between the frontext VS Code extension and the frontext toolbar using a schema-validated RPC (Remote Procedure Call) system. It serves as the central contract that ensures type-safe, reliable communication between these two components.
Features
- Type-Safe Communication: Uses Zod schemas to validate all messages at runtime
- Bi-directional Communication: Enables both the extension and toolbar to call methods on each other
- Discovery Mechanism: Provides utilities for the toolbar to discover the running extension
- Automatic Reconnection: Handles connection management and reconnection
- Progress Updates: Supports sending progress updates during long-running operations
Key Components
- Contract Definition: Defines the available methods, their parameters, and return types
- Connection Management: Handles port discovery and ping protocols
- Bridge Creation: Utilities to create server and client bridges
Usage
Installation
npm install @frontext/extension-toolbar-srpc-contractBasic Usage
// Extension (server) side
import { getExtensionBridge } from '@frontext/extension-toolbar-srpc-contract';
import http from 'node:http';
const httpServer = http.createServer();
const bridge = getExtensionBridge(httpServer);
bridge.register({
triggerAgentPrompt: async (request, { sendUpdate }) => {
// Implementation
}
});
// Toolbar (client) side
import { getToolbarBridge } from '@frontext/extension-toolbar-srpc-contract';
const bridge = getToolbarBridge('ws://localhost:5746');
await bridge.connect();
// Call methods on the extension
const result = await bridge.call.triggerAgentPrompt({
prompt: 'Make this button green'
});Related Packages
- @frontext/toolbar: The toolbar component for your web app
- @frontext/srpc: The underlying RPC framework
License
AGPL-3.0-only
