@aikdna/kdna-web-client

中文文档
0.3.0发布于 2026/08/08Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 4185

Browser-safe KDNA utilities — file selection, metadata inspection, upload, and load-plan state management. Never performs decryption.

此软件包已被标记为弃用

Deprecated: not part of the current supported KDNA release. This version targets an earlier release line and is no longer maintained; keep it only for existing pinned installs and do not use it for new integrations.

原始使用文档
文档目录14 节
  1. Install
  2. Quick start
  3. API reference
  4. readKDNAMetadata(file)
  5. uploadKDNA(file, endpoint)
  6. KDNALoadPlanManager
  7. KDNAFileSizeError
  8. KDNAFormatError
  9. KDNAUploadError
  10. KDNALoadError
  11. Security model
  12. Consumption traces
  13. Related packages
  14. License

@aikdna/kdna-web-client

Browser-safe KDNA utilities.

Status: Experimental published browser integration at its exact package coordinate. It is not a stable browser Runtime or a complete Host policy.

File selection, metadata inspection, upload to your server, and load-plan state management — without ever performing decryption in the browser.

Design constraint: this package never decrypts anything. It reads public metadata from a .kdna file and delegates all sensitive operations to a server running @aikdna/kdna-web-server.

New to KDNA? → KDNA Core

Need a server-side adapter? → @aikdna/kdna-web-server

Need React components? → @aikdna/kdna-react

npm License


Install

npm install @aikdna/kdna-web-client

No peer dependencies. No Node.js built-ins in the browser bundle.


Quick start

import { readKDNAMetadata, uploadKDNA, KDNALoadPlanManager } from '@aikdna/kdna-web-client'

// 1. Let the user pick a file
const input = document.createElement('input')
input.type = 'file'
input.accept = '.kdna'
input.onchange = async () => {
  const file = input.files[0]

  // 2. Read public metadata (no server round-trip, no decryption)
  const meta = await readKDNAMetadata(file)
  console.log(meta.domain, meta.version, meta.encrypted)

  // 3. Upload to your server and get a fileId
  const { fileId } = await uploadKDNA(file, '/api/kdna/inspect')

  // 4. Manage the load-plan flow
  const manager = new KDNALoadPlanManager('/api/kdna')
  const plan = await manager.planLoad(fileId)

  if (plan.canProceed) {
    const result = await manager.load(fileId, { profile: 'compact' })
    console.log(result.capsule.context)
  } else {
    console.log('Missing:', plan.missing)  // e.g. ['enter_password']
  }
}
input.click()

The file picker establishes an explicit user selection for this operation. If an application remembers the file as an attachment, it must keep exact identity, digest, scope, and reason visible and provide disable/switch/rollback controls. Upload storage alone does not authorize future tasks.


API reference

readKDNAMetadata(file)

Reads public manifest fields from a .kdna File object without uploading it or performing any decryption.

const meta = await readKDNAMetadata(file)

Returns:

{
  domain:      string         // e.g. "kdna:aikdna:laozi-wuwei"
  version:     string         // e.g. "1.2.0"
  title:       string | null
  description: string | null
  encrypted:   boolean
  profiles:    string[]       // available load profiles
  fileSize:    number         // bytes
}

The default maxSizeBytes is 10 MiB, aligned with the official Web Server. Pass a smaller positive integer when your application needs a tighter memory budget. The public manifest is independently limited to 1 MiB.

Throws KDNAFileSizeError if the file is too large. Throws KDNAFormatError if the file is not a valid .kdna container.


uploadKDNA(file, endpoint)

Upload a .kdna File to an endpoint (typically /api/kdna/inspect) and return the fileId assigned by the server.

const { fileId, inspect } = await uploadKDNA(file, '/api/kdna/inspect')

Returns:

{
  fileId:   string    // opaque ID — pass to plan-load and load
  inspect:  object    // bounded public inspect fields only
}

The client keeps only fileId, public asset metadata, the default profile, optional profiles, and the public LoadPlan. Server storage metadata, internal paths, and unknown fields are discarded.

Throws KDNAUploadError if the request fails or the server returns a non-200 status. Public errors contain a fixed local message, HTTP status, and a canonical KDNA error code when the server supplies one. Server error messages and response bodies are never attached; the compatibility response property is always null.


KDNALoadPlanManager

Stateful class that drives the load-plan flow for a single file.

const manager = new KDNALoadPlanManager(baseUrl)
MethodDescription
planLoad(fileId, context?)Evaluate the LoadPlan. Returns requirements.
load(fileId, options)Load the asset. Credentials are passed directly.

planLoad(fileId, context?)

const plan = await manager.planLoad('abc123', {
  hasPassword: false,
  entitlementToken: null,
})

Returns:

{
  canProceed:   boolean
  missing:      string[]    // e.g. ['enter_password']
  requirements: {
    password:   { required: boolean, hint: string | null }
    licenseKey: { required: boolean }
  }
}

load(fileId, options)

const result = await manager.load('abc123', {
  profile:          'compact',
  password:         '...',   // only if required
  entitlementToken: { status: 'active' }, // signed entitlement from /activate, only if required
})

Returns a public projection derived from capsule only after capsule satisfies the complete Runtime Capsule schema closure pinned to an audited KDNA Core commit. Unknown top-level server fields are discarded. The Agent-facing artifact is the Runtime Capsule; content is a web-UI convenience alias of capsule.context:

{
  domain: "kdna:aikdna:laozi-wuwei"
  version: "0.1.1"
  judgmentVersion: "0.1.0"
  profile: "compact"
  content: object
  capsule: {
    type: "kdna.runtime-capsule"
    contract_version: "0.1.0"
    asset: object
    digests: object
    signature: object
    access: "public" | "licensed" | "remote"
    profile: "index" | "compact" | "scenario" | "full"
    context: object
    trace: object
  }
}

KDNAFileSizeError

Thrown by readKDNAMetadata when the file exceeds the configured maximum size.

KDNAFormatError

Thrown by readKDNAMetadata when the file does not have a valid .kdna header.

KDNAUploadError

Thrown by uploadKDNA when the HTTP request fails.

KDNALoadError

Thrown by LoadPlan and load calls when the request fails or the returned Runtime Capsule is invalid. As with KDNAUploadError, upstream response bodies and messages are never exposed.


Security model

See docs/security-model.md.

Short version:

  • This package reads only the container header and public kdna.json manifest in memory. It never parses, decrypts, or exposes payload.kdnab; loading is delegated to the official server-side toolchain.
  • Passwords and signed entitlement records or tokens are passed as arguments to manager.load() and are POSTed directly to the server endpoint. They are not stored in any object property or module-level variable. Raw license keys belong on your activation endpoint, not /load.
  • This package has no Node.js built-in dependencies. It runs entirely within the browser's security model.
  • JSON responses are read as bounded UTF-8 and must be JSON objects. Error payloads are reduced to status and a canonical code; success payloads are projected to the documented public surface.

Consumption traces

parseJudgmentTrace, judgmentTraceView, and the dependency-free JudgmentTraceViewer validate the complete JudgmentTrace schema closure pinned to the same audited KDNA Core commit and fail closed on unknown or inconsistent nested evidence. They keep Capsule delivery, Host execution, semantic consumption, and conformance as separate evidence. A correlated Host response does not prove that a model semantically consumed the judgment or that the answer conforms to it.

Browser clients should receive a trace from a trusted application endpoint. The browser check proves schema conformance only; cryptographic and semantic conformance remain server-side KDNA Core responsibilities. A trace is never permission to read a protected payload.


PackageRole
@aikdna/kdna-coreKDNA format and runtime (Node.js)
@aikdna/kdna-web-serverServer-side adapter
@aikdna/kdna-reactReact components and hooks
create-kdna-web-appProject scaffolding CLI

License

Apache 2.0 — see LICENSE.

版本与发布记录

@aikdna/kdna-web-client 共发布 7 个版本,首次发布于 2026/07/03;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.0latest2026/08/082 个月前
0.2.22026/07/183 个月前
0.2.12026/07/183 个月前
0.2.02026/07/133 个月前
0.1.22026/07/113 个月前
0.1.12026/07/034 个月前

关于 @aikdna/kdna-web-client 的常见问题

@aikdna/kdna-web-client 是什么?

Browser-safe KDNA utilities — file selection, metadata inspection, upload, and load-plan state management. Never performs decryption.注意:该包已被作者标记为弃用——Deprecated: not part of the current supported KDNA release. This version targets an earlier release line and is no longer maintained; keep it only for existing pinned installs and do not use it for new integrations.

如何安装 @aikdna/kdna-web-client?

在项目目录运行 npm install @aikdna/kdna-web-client,或使用 pnpm add / yarn add / bun add。

@aikdna/kdna-web-client 支持 TypeScript 吗?

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

@aikdna/kdna-web-client 支持 ESM 还是 CommonJS?

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

@aikdna/kdna-web-client 需要什么版本的 Node.js?

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

@aikdna/kdna-web-client 可以商用吗?

@aikdna/kdna-web-client 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aikdna/kdna-web-client 的下载量有多少?

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

@aikdna/kdna-web-client 还在维护吗?

最新版本 0.3.0 发布于 2026/08/08(2 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/07/03。作者已将其标记为弃用,新项目建议寻找替代方案。