npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tecla/tools-sdk

v1.0.4

Published

SDK for building and hosting Tecla tools via postMessage

Downloads

4,743

Readme

@tecla/tools-sdk

npm

SDK for building and hosting Tecla tools via postMessage. Provides React hooks for the two sides of the iframe boundary: the tool (inside the iframe) and the parent (the shell that embeds it).

Installation

npm install @tecla/tools-sdk

Requires React 18 or 19 as a peer dependency.

Concepts

Tools communicate with their parent shell through postMessage. Each message follows the format {toolCode}#{eventName} with an optional payload. The tool's toolCode is the canonical identifier; id is accepted only as a legacy fallback.

Every tool has a config — validated via Zod — that the parent sends on init. The base config includes locale and theme; tools extend it with their own fields.

Built-in events:

| Direction | Event | Description | |-----------|-------|-------------| | Tool → Parent | ready | Sent automatically on mount. Carries widthRatio. | | Tool → Parent | progress | Reports completion percentage. | | Parent → Tool | init | Delivers the tool config. | | Parent → Tool | reset | Tells the tool to return to its initial state. |

Usage

Tool side (useToolCommunication)

Used inside the iframe app. Handles the postMessage contract, sends ready on mount, and exposes typed sendMessage / onMessage helpers.

import { useToolCommunication, BaseToolConfigSchema } from '@tecla/tools-sdk'
import type { ToolConfig } from '@tecla/tools-sdk'
import { z } from 'zod'

const MyConfigSchema = BaseToolConfigSchema.extend({
  prompt: z.string(),
})

type MyConfig = z.infer<typeof MyConfigSchema>

const toolDef: ToolConfig = {
  toolCode: 'my-tool',
  name: 'My Tool',
  description: 'Does something useful.',
  version: '1.0.0',
  widthRatio: 0.4,
}

export function MyTool() {
  const { config, sendMessage, onMessage } = useToolCommunication<MyConfig>(toolDef)

  // Listen for a custom inbound event
  onMessage('reset', () => {
    // handle reset
  })

  const handleComplete = () => {
    sendMessage('progress', { percentage: 100, completed: true })
  }

  if (!config) return <p>Waiting for init…</p>

  return (
    <div>
      <p>{config.prompt}</p>
      <button onClick={handleComplete}>Done</button>
    </div>
  )
}

Parent side (useParentCommunication)

Used in the shell that renders the <iframe>. Tracks the full message history and sends typed messages to the tool.

import { useRef } from 'react'
import { useParentCommunication } from '@tecla/tools-sdk'

export function Shell() {
  const iframeRef = useRef<HTMLIFrameElement>(null)

  const { sendMessage, messages, clearMessages } = useParentCommunication(
    iframeRef,
    'my-tool',
    {
      // Automatically sent to the tool whenever it fires `ready`
      autoInit: { locale: 'en', theme: 'dark', prompt: 'Hello!' },
    },
  )

  return (
    <iframe ref={iframeRef} src="https://my-tool.example.com" />
  )
}

Defining a tool config

// tool.config.ts
import { BaseToolConfigSchema } from '@tecla/tools-sdk'
import type { ToolConfig } from '@tecla/tools-sdk'
import { z } from 'zod'

export const ConfigSchema = BaseToolConfigSchema.extend({
  apiKey: z.string(),
})

export const toolDef: ToolConfig = {
  toolCode: 'my-tool',
  name: 'My Tool',
  description: 'Does something useful.',
  version: '1.0.0',
  widthRatio: 0.4,
  additionalInboundEvents: [
    { name: 'update', description: 'Receive new data', schema: z.object({ value: z.string() }) },
  ],
  additionalOutboundEvents: [
    { name: 'result', description: 'Send result back', schema: z.object({ output: z.string() }) },
  ],
}

API

useToolCommunication(toolDef)

| Return | Type | Description | |--------|------|-------------| | config | TConfig \| null | Config received from the parent via init. Null until initialized. | | sendMessage(event, payload) | function | Send a typed event to the parent. | | onMessage(event, handler) | function | Register a handler for an inbound event. Returns a cleanup function. |

useParentCommunication(iframeRef, toolSlug, options?)

| Return | Type | Description | |--------|------|-------------| | sendMessage(event, payload) | function | Send a typed event to the tool. | | messages | ToolEvent[] | Full message log (inbound + outbound). | | clearMessages() | function | Clear the message log. |

Options:

| Option | Type | Description | |--------|------|-------------| | autoInit | Record<string, unknown> | Config sent automatically on every ready received from the tool. |

BaseToolConfigSchema

Zod schema with locale: string (default 'en') and theme: 'light' | 'dark' (default 'light'). Extend it for your tool's config.

License

MIT