@agenticprimitives/connect-client

中文文档
1.0.0-alpha.36发布于 2026/10/26MITTypeScriptES Module近 30 天下载 2733

Generic relying-party connect client: hand off to the central-auth Home (FedCM-first → OIDC redirect/popup), exchange the code for an SA-signed scoped delegation. The relying half of spec 230/259; no credential ever originates in the relying app.

原始使用文档
文档目录3 节
  1. Why
  2. Usage
  3. Boundary

@agenticprimitives/connect-client

Part of Agentic Primitives — the open-source trust substrate for agentic applications: identity that can sign, authority checked at act time, evidence the owner carries. Developer kit · All packages

The relying-party half of Connect. A relying app makes no credential or OAuth request itself: it hands off to the user's central-auth Home (the IdP) — which runs the credential ceremony (wallet / Google / YouVersion / passkey) and custody — and gets back an SA-signed scoped delegation. Standard OIDC (authorize → code → /token) with a seamless FedCM-first front.

See spec 295, spec 230 / 259, ADR-0019, ADR-0021, ADR-0032.

Why

YouVersion/Google OAuth clients are origin-pinned to the registered Home origin. If a relying app originates the OAuth itself (from its own origin), strict providers reject it. The fix — and the doctrine — is that the Home is the single credential/OAuth origin; relying apps only ever exchange a returned code. This package is that relying-side protocol, extracted once instead of copied per app.

Usage

import { createConnectClient, connectViaFedcm, connectViaPopup, connectViaRedirect } from '@agenticprimitives/connect-client';

// The app injects its domain.ts — NO hostnames live in this package (ADR-0021).
const connect = createConnectClient({
  clientId: 'demo-web',
  delegate: '0x…',                       // the relying-site backend account the Home scopes its grant to
  redirectUri: () => window.location.origin + '/',
  resolveAuthOrigin: (name) => resolveHomeOrigin(name),   // app: name → <home> | apex
  isAllowedIssuerOrigin: (o) => isAllowedHome(o),         // app: issuer allowlist
});

// FedCM-first, then popup, then redirect (the seamless launcher):
try {
  const r = await connectViaFedcm(await resolveHomeOrigin(''), 'demo-web', onProgress);
  // r.idToken + r.delegation — done, no /token round-trip
} catch {
  const p = await connectViaPopup(connect, name, 'demo-web-connect-relay', onProgress, signal);
  if (p.status === 'blocked') {
    const { url, stash } = await connectViaRedirect(connect, name);
    sessionStorage.setItem('connect', JSON.stringify(stash));
    window.location.href = url;                            // returns ?code&state
  } else if (p.status === 'success') {
    const tok = await connect.exchangeCode(p.authOrigin, p.code, p.codeVerifier);
    await connect.verifyIdToken(p.authOrigin, tok.idToken, p.stash.nonce);
  }
}

On ?code&state return (the redirect path), read the stash, exchangeCode, then verifyIdToken.

Boundary

Relying side only. The broker/Home side is @agenticprimitives/connect; credential ceremonies live at the Home (connect-auth). This package imports only @agenticprimitives/types + @agenticprimitives/fedcm-rp, is WebCrypto-only, and contains no hostnames.

版本与发布记录

@agenticprimitives/connect-client 共发布 32 个版本,首次发布于 2026/07/01;过去 12 个月发布了 32 个版本。

版本发布日期距今
1.0.0-alpha.36latest2026/10/2612 天前
1.0.0-alpha.352026/10/2612 天前
1.0.0-alpha.342026/10/1721 天前
1.0.0-alpha.332026/10/1722 天前
1.0.0-alpha.322026/10/1622 天前
1.0.0-alpha.312026/10/1622 天前

关于 @agenticprimitives/connect-client 的常见问题

@agenticprimitives/connect-client 是什么?

Generic relying-party connect client: hand off to the central-auth Home (FedCM-first → OIDC redirect/popup), exchange the code for an SA-signed scoped delegation. The relying half of spec 230/259; no credential ever originates in the relying app.

如何安装 @agenticprimitives/connect-client?

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

@agenticprimitives/connect-client 支持 TypeScript 吗?

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

@agenticprimitives/connect-client 支持 ESM 还是 CommonJS?

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

@agenticprimitives/connect-client 可以商用吗?

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

@agenticprimitives/connect-client 的下载量有多少?

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

@agenticprimitives/connect-client 还在维护吗?

最新版本 1.0.0-alpha.36 发布于 2026/10/26(12 天前);至今共发布 32 个版本,其中过去 12 个月发布了 32 个;首次发布于 2026/07/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。