{"_id":"@21st-extension/srpc","_rev":"4-48bc079fc2383ea6acf1e47dcb92ce64","name":"@21st-extension/srpc","dist-tags":{"latest":"0.2.4"},"versions":{"0.2.1":{"name":"@21st-extension/srpc","version":"0.2.1","author":{"name":"21st Labs Inc."},"license":"AGPL-3.0-only","_id":"@21st-extension/srpc@0.2.1","maintainers":[{"name":"danverr","email":"ddmaryakhin@mail.ru"}],"homepage":"https://21st.dev/","bugs":{"url":"https://github.com/21st-dev/21st-extension/issues"},"dist":{"shasum":"f0f5a9a448f748f077aab724867480aa83003a3e","tarball":"https://registry.npmjs.org/@21st-extension/srpc/-/srpc-0.2.1.tgz","fileCount":38,"integrity":"sha512-crjB9lNvMHc4s/0kHUnCFGIOEnibXCU0JvVPK9kpWTcgB2PU1Hd3htIXmznl0YY3WL/lxDenmKwUSLp+gDY+zw==","signatures":[{"sig":"MEUCIFC4/yPIVLfIlqxWSNXidkS1/8PBcyqeaEiTUusXjUJzAiEA66rKsAhwjowPfzNASMf8geB7shNgz5KF22zyq22yp+M=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":187687},"main":"./dist/index.js","type":"module","_from":"file:21st-extension-srpc-0.2.1.tgz","turbo":{"tasks":{"build":{"outputs":["dist/**"],"dependsOn":["^build"]}}},"types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client.d.ts","import":"./dist/client.js","require":"./dist/client.cjs"},"./server":{"types":"./dist/server.d.ts","import":"./dist/server.js","require":"./dist/server.cjs"}},"private":false,"scripts":{"dev":"tsup --watch","test":"vitest run","build":"tsup","clean":"rm -rf dist"},"_npmUser":{"name":"danverr","actor":{"name":"danverr","type":"user","email":"ddmaryakhin@mail.ru"},"email":"ddmaryakhin@mail.ru"},"_resolved":"/tmp/82cbf59e982cb737c7ea760163f8b6e7/21st-extension-srpc-0.2.1.tgz","_integrity":"sha512-crjB9lNvMHc4s/0kHUnCFGIOEnibXCU0JvVPK9kpWTcgB2PU1Hd3htIXmznl0YY3WL/lxDenmKwUSLp+gDY+zw==","repository":{"url":"git+https://github.com/21st-dev/21st-extension.git","type":"git"},"_npmVersion":"10.8.2","description":"A TypeScript framework for type-safe, schema-validated Remote Procedure Calls (RPC) over WebSocket connections. Built with Zod for runtime validation and strong TypeScript type inference.","directories":{},"_nodeVersion":"20.19.2","dependencies":{"ws":"^8.18.2","zod":"^3.24.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.4.0","vitest":"3.1.2","@types/ws":"^8.18.1","typescript":"^5.8.3","@types/node":"22.15.2"},"_npmOperationalInternal":{"tmp":"tmp/srpc_0.2.1_1750942996463_0.14745502182056391","host":"s3://npm-registry-packages-npm-production"}},"0.2.2":{"name":"@21st-extension/srpc","version":"0.2.2","author":{"name":"21st Labs Inc."},"license":"AGPL-3.0-only","_id":"@21st-extension/srpc@0.2.2","maintainers":[{"name":"danverr","email":"ddmaryakhin@mail.ru"}],"homepage":"https://21st.dev/","bugs":{"url":"https://github.com/21st-dev/21st-extension/issues"},"dist":{"shasum":"96ee4a00cc5d8fcf8a2c1e13b19fb96d8f1e61e0","tarball":"https://registry.npmjs.org/@21st-extension/srpc/-/srpc-0.2.2.tgz","fileCount":38,"integrity":"sha512-hOb46YlHC7B29Gt8iy8yaDWvsMRyYBZbyGbVY4VcinVVUiVV033gtArGOLvE/liXx7ohY8uxoWZ9TpEULtgXbQ==","signatures":[{"sig":"MEUCIHoT9IV2J74od1/V7YX2Fh4qan/KxSQGxYAZinUivtr1AiEA5oyewOnmGbFmKtVjen9NJvk4kDf2yp3pVIB4jHeuDxg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":188170},"main":"./dist/index.js","type":"module","_from":"file:21st-extension-srpc-0.2.2.tgz","turbo":{"tasks":{"build":{"outputs":["dist/**"],"dependsOn":["^build"]}}},"types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client.d.ts","import":"./dist/client.js","require":"./dist/client.cjs"},"./server":{"types":"./dist/server.d.ts","import":"./dist/server.js","require":"./dist/server.cjs"}},"private":false,"scripts":{"dev":"tsup --watch","test":"vitest run","build":"tsup","clean":"rm -rf dist"},"_npmUser":{"name":"danverr","actor":{"name":"danverr","type":"user","email":"ddmaryakhin@mail.ru"},"email":"ddmaryakhin@mail.ru"},"_resolved":"/tmp/db8d3ba8404152180e567ccf83b733f5/21st-extension-srpc-0.2.2.tgz","_integrity":"sha512-hOb46YlHC7B29Gt8iy8yaDWvsMRyYBZbyGbVY4VcinVVUiVV033gtArGOLvE/liXx7ohY8uxoWZ9TpEULtgXbQ==","repository":{"url":"git+https://github.com/21st-dev/21st-extension.git","type":"git"},"_npmVersion":"10.8.2","description":"A TypeScript framework for type-safe, schema-validated Remote Procedure Calls (RPC) over WebSocket connections. Built with Zod for runtime validation and strong TypeScript type inference.","directories":{},"_nodeVersion":"20.19.2","dependencies":{"ws":"^8.18.2","zod":"^3.24.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.4.0","vitest":"3.1.2","@types/ws":"^8.18.1","typescript":"^5.8.3","@types/node":"22.15.2"},"_npmOperationalInternal":{"tmp":"tmp/srpc_0.2.2_1751364214017_0.04932628202218403","host":"s3://npm-registry-packages-npm-production"}},"0.2.3":{"name":"@21st-extension/srpc","version":"0.2.3","author":{"name":"21st Labs Inc."},"license":"AGPL-3.0-only","_id":"@21st-extension/srpc@0.2.3","maintainers":[{"name":"danverr","email":"ddmaryakhin@mail.ru"}],"homepage":"https://21st.dev/","bugs":{"url":"https://github.com/21st-dev/21st-extension/issues"},"dist":{"shasum":"59d2805bf5a0a7ee49e90981915ba2fe471a7950","tarball":"https://registry.npmjs.org/@21st-extension/srpc/-/srpc-0.2.3.tgz","fileCount":38,"integrity":"sha512-G+LLHHpoJL1r1uL51//1qwCo5+TTHqSzgZhV+no01t1lod4mVJcMy0Y0Ipmj2zkHVA6hASDyOjyFg/JuIQy2nw==","signatures":[{"sig":"MEUCIGg2xYIOdZDvpp8FYrJJkAMPuEY7qGdwc0+UFifUF5ibAiEAuUZUe3Xx/cSpuUzVu1echN4/2xiYk6JPiu4Y6uTb7iE=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":188322},"main":"./dist/index.js","type":"module","_from":"file:21st-extension-srpc-0.2.3.tgz","turbo":{"tasks":{"build":{"outputs":["dist/**"],"dependsOn":["^build"]}}},"types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client.d.ts","import":"./dist/client.js","require":"./dist/client.cjs"},"./server":{"types":"./dist/server.d.ts","import":"./dist/server.js","require":"./dist/server.cjs"}},"private":false,"scripts":{"dev":"tsup --watch","test":"vitest run","build":"tsup","clean":"rm -rf dist"},"_npmUser":{"name":"danverr","actor":{"name":"danverr","type":"user","email":"ddmaryakhin@mail.ru"},"email":"ddmaryakhin@mail.ru"},"_resolved":"/tmp/0e5f87352448eb0bc682637b80439cd3/21st-extension-srpc-0.2.3.tgz","_integrity":"sha512-G+LLHHpoJL1r1uL51//1qwCo5+TTHqSzgZhV+no01t1lod4mVJcMy0Y0Ipmj2zkHVA6hASDyOjyFg/JuIQy2nw==","repository":{"url":"git+https://github.com/21st-dev/21st-extension.git","type":"git"},"_npmVersion":"10.8.2","description":"A TypeScript framework for type-safe, schema-validated Remote Procedure Calls (RPC) over WebSocket connections. Built with Zod for runtime validation and strong TypeScript type inference.","directories":{},"_nodeVersion":"20.19.2","dependencies":{"ws":"^8.18.2","zod":"^3.24.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.4.0","vitest":"3.1.2","@types/ws":"^8.18.1","typescript":"^5.8.3","@types/node":"22.15.2"},"_npmOperationalInternal":{"tmp":"tmp/srpc_0.2.3_1751377715693_0.337636839482901","host":"s3://npm-registry-packages-npm-production"}},"0.2.4":{"name":"@21st-extension/srpc","version":"0.2.4","license":"AGPL-3.0-only","type":"module","private":false,"main":"./dist/index.js","types":"./dist/index.d.ts","author":{"name":"21st Labs Inc."},"homepage":"https://21st.dev/","repository":{"type":"git","url":"git+https://github.com/21st-dev/21st-extension.git"},"bugs":{"url":"https://github.com/21st-dev/21st-extension/issues"},"publishConfig":{"access":"public"},"dependencies":{"ws":"^8.18.2","zod":"^3.24.4"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./client":{"types":"./dist/client.d.ts","import":"./dist/client.js","require":"./dist/client.cjs"},"./server":{"types":"./dist/server.d.ts","import":"./dist/server.js","require":"./dist/server.cjs"}},"devDependencies":{"@types/node":"22.15.2","@types/ws":"^8.18.1","tsup":"^8.4.0","typescript":"^5.8.3","vitest":"3.1.2"},"turbo":{"tasks":{"build":{"dependsOn":["^build"],"outputs":["dist/**"]}}},"scripts":{"build":"tsup","clean":"rm -rf dist","dev":"tsup --watch","test":"vitest run"},"_id":"@21st-extension/srpc@0.2.4","description":"A TypeScript framework for type-safe, schema-validated Remote Procedure Calls (RPC) over WebSocket connections. Built with Zod for runtime validation and strong TypeScript type inference.","_integrity":"sha512-KXM7sPrAikxe6pWamytLwvHuaUGnO02427RkpgkSQBYBJjig6jv4E5aI9gwZrIoUVct1eWm0gMHGlZ6dAp9zSA==","_resolved":"/tmp/560e4381f3b165dda88eb6a2d2957fc1/21st-extension-srpc-0.2.4.tgz","_from":"file:21st-extension-srpc-0.2.4.tgz","_nodeVersion":"20.19.3","_npmVersion":"10.8.2","dist":{"integrity":"sha512-KXM7sPrAikxe6pWamytLwvHuaUGnO02427RkpgkSQBYBJjig6jv4E5aI9gwZrIoUVct1eWm0gMHGlZ6dAp9zSA==","shasum":"a8b98fab054cc62ab294cbc29793db8341a66a80","tarball":"https://registry.npmjs.org/@21st-extension/srpc/-/srpc-0.2.4.tgz","fileCount":38,"unpackedSize":188322,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHrcb3j0SUFC2vcw3Ml6sny+zFwt1vQ8kLWsqIOTxW2fAiA/3U1HFv9ZnisyvR7+ChOM89xm3fcTin6g0cvLJTHouQ=="}]},"_npmUser":{"name":"danverr","email":"ddmaryakhin@mail.ru","actor":{"name":"danverr","email":"ddmaryakhin@mail.ru","type":"user"}},"directories":{},"maintainers":[{"name":"danverr","email":"ddmaryakhin@mail.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/srpc_0.2.4_1751793711502_0.21682450483014515"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-26T13:03:16.403Z","modified":"2025-07-06T09:21:51.878Z","0.2.1":"2025-06-26T13:03:16.692Z","0.2.2":"2025-07-01T10:03:34.216Z","0.2.3":"2025-07-01T13:48:35.891Z","0.2.4":"2025-07-06T09:21:51.679Z"},"bugs":{"url":"https://github.com/21st-dev/21st-extension/issues"},"author":{"name":"21st Labs Inc."},"license":"AGPL-3.0-only","homepage":"https://21st.dev/","repository":{"type":"git","url":"git+https://github.com/21st-dev/21st-extension.git"},"description":"A TypeScript framework for type-safe, schema-validated Remote Procedure Calls (RPC) over WebSocket connections. Built with Zod for runtime validation and strong TypeScript type inference.","maintainers":[{"name":"danverr","email":"ddmaryakhin@mail.ru"}],"readme":"# SRPC: Schema-validated RPC over WebSocket\n\nA TypeScript framework for type-safe, schema-validated Remote Procedure Calls (RPC) over WebSocket connections. Built with Zod for runtime validation and strong TypeScript type inference.\n\n## Features\n\n- 🔒 **Type Safety**: Full TypeScript support with type inference from Zod schemas\n- ✅ **Runtime Validation**: Automatic request/response validation using Zod schemas\n- 🔄 **Bi-directional Communication**: Both client and server can call methods on each other\n- 📝 **Progress Updates**: Support for sending progress updates during long-running operations\n- 🏃 **Auto-Reconnection**: Client automatically reconnects on connection loss\n- 📚 **Developer-Friendly**: Clear error messages and type hints in your IDE\n\n## Installation\n\n```bash\nnpm install @21st-extension/srpc zod\n```\n\n## Quick Start\n\n1. Define your RPC contract using Zod schemas:\n\n```typescript\nimport { z } from 'zod';\nimport { createBridgeContract } from '@21st-extension/srpc';\n\nconst contract = createBridgeContract({\n  server: {\n    triggerAgentPrompt: {\n      request: z.object({\n        prompt: z.string(),\n        options: z.object({\n          temperature: z.number().min(0).max(1).optional(),\n        }).optional(),\n      }),\n      response: z.object({\n        result: z.object({\n          success: z.boolean(),\n          output: z.string().optional(),\n        }),\n      }),\n      update: z.object({\n        updateText: z.string(),\n        progress: z.number().min(0).max(100).optional(),\n      }),\n    },\n  },\n  client: {\n    getCurrentUrl: {\n      request: z.object({}).optional(),\n      response: z.object({\n        url: z.string().url(),\n        title: z.string().optional(),\n      }),\n    },\n  },\n});\n```\n\n2. Set up the server:\n\n```typescript\nimport http from 'node:http';\nimport { createSRPCServerBridge } from '@21st-extension/srpc';\n\nconst httpServer = http.createServer();\nconst server = createSRPCServerBridge(httpServer, contract);\n\nserver.register({\n  triggerAgentPrompt: async (request, { sendUpdate }) => {\n    console.log('Processing prompt:', request.prompt);\n\n    // Send progress updates\n    await sendUpdate({\n      updateText: 'Processing...',\n      progress: 50,\n    });\n\n    return {\n      result: {\n        success: true,\n        output: 'Example response',\n      },\n    };\n  },\n});\n\nhttpServer.listen(3000);\n```\n\n3. Set up the client:\n\n```typescript\nimport { createSRPCClientBridge } from '@21st-extension/srpc';\n\nconst client = createSRPCClientBridge('ws://localhost:3000', contract);\n\n// Implement client-side methods\nclient.register({\n  getCurrentUrl: async () => ({\n    url: 'https://example.com',\n    title: 'Example Page',\n  }),\n});\n\n// Connect and make calls\nawait client.connect();\n\nconst result = await client.call.triggerAgentPrompt(\n  {\n    prompt: 'Hello, agent!',\n    options: { temperature: 0.7 },\n  },\n  {\n    onUpdate: (update) => {\n      console.log('Progress:', update.updateText, update.progress);\n    },\n  },\n);\n\nconsole.log('Result:', result);\n```\n\n## Features in Detail\n\n### Type Safety\n\nThe framework provides full TypeScript type inference from your Zod schemas:\n\n- Method names are type-checked\n- Request/response payloads are type-checked\n- Update messages are type-checked\n- IDE autocompletion for all types\n\n### Runtime Validation\n\nAll messages are validated at runtime using Zod:\n\n- Incoming requests are validated before reaching your handler\n- Outgoing responses are validated before being sent\n- Update messages are validated before being sent\n- Clear error messages when validation fails\n\n### Progress Updates\n\nLong-running operations can send progress updates:\n\n```typescript\nserver.register({\n  longOperation: async (request, { sendUpdate }) => {\n    await sendUpdate({ progress: 0, status: 'Starting...' });\n    // ... do work ...\n    await sendUpdate({ progress: 50, status: 'Processing...' });\n    // ... do more work ...\n    return { success: true };\n  },\n});\n```\n\n### Auto-Reconnection\n\nThe client automatically handles reconnection:\n\n```typescript\nconst client = createSRPCClientBridge('ws://localhost:3000', contract, {\n  reconnectDelay: 1000, // milliseconds\n  maxReconnectAttempts: 5,\n});\n```\n\n## Error Handling\n\nThe framework provides clear error messages for various failure cases:\n\n- Schema validation errors include the exact validation failure\n- Connection errors include relevant network details\n- Method not found errors include the attempted method name\n- Implementation errors include the original error stack\n\n## Examples\n\nCheck out the `examples/` directory for more detailed examples:\n\n- Full application: `examples/zod-example.ts`","readmeFilename":"README.md"}