@ham2k/extension-sdk

中文文档
1.26.0发布于 2026/11/15MITTypeScriptES Module零依赖近 30 天下载 5957

Write extensions for the Ham2K Logger: typed hook contracts and the host API

原始使用文档
文档目录4 节
  1. The reference is in this package
  2. Versions
  3. Export types and settings
  4. About the peer dependencies

@ham2k/extension-sdk

Write extensions for the Ham2K Logger — the typed hook contracts and the host API an extension is built against.

npm install @ham2k/extension-sdk
npm install --save-dev @ham2k/extension-tools esbuild
import { defineExtension } from "@ham2k/extension-sdk"
import type { PanelHook } from "@ham2k/extension-sdk"

import manifest from "../manifest.json"

const HelloPanel: PanelHook = {
  async getPanels() {
    return [{ key: "hello", title: "Hello World", icon: "hand-wave-outline" }]
  },
  async render() {
    return { kind: "markdown", content: "# Hello, World!" }
  },
}

defineExtension({
  ...manifest,
  onActivation({ registerHook }) {
    registerHook("panel", { key: manifest.key, hook: HelloPanel })
  },
})

A panel returns content, not widgets — which is what keeps extensions out of the app's UI toolkit.

npx -p @ham2k/extension-tools h2kext-init <yourcallsign>-<name> writes all of that and the build script; the same package packages the result into a .h2kext the app can install.

The reference is in this package

samples/ holds one worked extension per shape — a callsign lookup with the credentials it needs, an award program, a contest and its scorer, an HTML panel. Each builds and packs; each says in its header what it leaves out.

AGENTS.md beside this file is the map — the manifest, the sandbox's limits, and which of docs/ answers what. docs/ holds the documentation itself: getting started, how extensions run, the manifest, the host API, every hook category, forms, settings panels, templates, packaging and publishing.

They travel in the package rather than being linked to, so they are readable offline and describe the version installed here rather than whatever the repository says today. If an agent is writing your extension, point it at node_modules/@ham2k/extension-sdk/AGENTS.md — h2kext-init does that for you.

Versions

The minor version is the extension API: SDK 1.26 describes API 26, and exports it as API_VERSION. @ham2k/extension-tools follows the same rule, so a ^1.19.0 range says the extension needs API 19 and admits every later one. A major version is a change that breaks an extension already written.

Export types and settings

Export hooks can register shared types with getExportTypes(). Use exportTypeDefinition(activationType, format, label) for an identity shared by extensions serving the same activity. exportType identifies the settings; exportKey identifies an individual file, such as one park in an activation.

The activityExportHook and huntingExportHook helpers register their types and forward export settings to the ADIF generator. Reference activity types use templateCategory: 'reference'; other types use the other-activity defaults. GlobalExportSettings provides separate normal filename, compact filename, and title templates for each category, plus shared ADIF field templates.

When updating an exporter from SDK 0.3, keep a reference-specific identifier in exportKey, register a stable exportType, and forward exportSettings, exportData, exportTitle, and includeLookupData when delegating generation. Per-type custom templates override inherited defaults only when enabled. See docs/import-export.md §export for the complete contract and docs/forms.md for the textTemplate form field.

About the peer dependencies

This package lists the libraries the extension host carries — @ham2k/lib-*, i18next, liquidjs — as optional peers, and you almost certainly do not need to install any of them.

Your extension declares in its manifest.json which of them it uses, and the build rewrites each one into a lookup on the host's single instance before esbuild ever reaches the filesystem. Taking the host up on that is worth roughly thirty times the bundle size. The published types have theirs rolled in, so your editor works with only this package installed.

Install one only to inline it — to ship your own copy because you need a version the host does not carry.

版本与发布记录

@ham2k/extension-sdk 共发布 63 个版本,首次发布于 2026/08/31;过去 12 个月发布了 63 个版本。

版本发布日期距今
1.26.0latest2026/11/151 天前
1.25.02026/11/152 天前
1.24.02026/11/124 天前
1.23.22026/11/125 天前
1.23.12026/11/116 天前
1.23.02026/11/116 天前

关于 @ham2k/extension-sdk 的常见问题

@ham2k/extension-sdk 是什么?

Write extensions for the Ham2K Logger: typed hook contracts and the host API

如何安装 @ham2k/extension-sdk?

在项目目录运行 npm install @ham2k/extension-sdk,或使用 pnpm add / yarn add / bun add。

@ham2k/extension-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ham2k/extension-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ham2k/extension-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ham2k/extension-sdk 可以商用吗?

@ham2k/extension-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ham2k/extension-sdk 的下载量有多少?

根据 npm 官方下载统计,@ham2k/extension-sdk 在 2026/10/17 – 2026/11/15 这 30 天内被下载 5,957 次,日均约 199 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ham2k/extension-sdk 还在维护吗?

最新版本 1.26.0 发布于 2026/11/15(1 天前);至今共发布 63 个版本,其中过去 12 个月发布了 63 个;首次发布于 2026/08/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。