@assembly-js/app-bridge

中文文档
2.1.0发布于 2026/10/29MITTypeScriptESM + CJS零依赖近 30 天下载 9259

Helper functions for postMessage communications between custom apps and the Copilot parent application

原始使用文档
文档目录15 节
  1. Installation
  2. npm/yarn
  3. Usage
  4. npm Usage
  5. API Reference
  6. AssemblyBridge.header
  7. AssemblyBridge.configure(config)
  8. AssemblyBridge.navigate(route, options?)
  9. AssemblyBridge.navigateTo(destination, options?)
  10. AssemblyBridge.location.report(path, search, replace?)
  11. AssemblyBridge.location.onNavigate(handler)
  12. Supported Values
  13. TypeScript Support
  14. Development
  15. License

@assembly-js/app-bridge

Helper functions for postMessage communications between custom apps (embedded in iframes) and the Copilot parent application.

Installation

npm/yarn

npm install @assembly-js/app-bridge
# or
yarn add @assembly-js/app-bridge

Usage

npm Usage

import { AssemblyBridge } from "@assembly-js/app-bridge";

// Set breadcrumbs
AssemblyBridge.header.setBreadcrumbs([
  { label: "Dashboard" },
  { label: "Users", onClick: () => console.log("navigated") },
]);

// Set actions menu
AssemblyBridge.header.setActionsMenu([
  { label: "Download", icon: "Download", onClick: () => downloadFile() },
  {
    label: "Delete",
    icon: "Trash",
    color: "red",
    onClick: () => confirmDelete(),
  },
]);

API Reference

AssemblyBridge.header

setBreadcrumbs(items)

Set the breadcrumb navigation items in the header.

AssemblyBridge.header.setBreadcrumbs([
  { label: "Home" },
  { label: "Projects", onClick: () => navigateToProjects() },
  { label: "Current Project" },
]);

Parameters:

  • items: Array of { label: string, onClick?: () => void }

setPrimaryCta(config)

Set or clear the primary CTA button.

// Set a CTA
AssemblyBridge.header.setPrimaryCta({
  label: "Save Changes",
  icon: "Check",
  onClick: () => save(),
});

// Clear the CTA
AssemblyBridge.header.setPrimaryCta(null);

Parameters:

  • config: { label: string, icon?: Icon, onClick: () => void } or null

setSecondaryCta(config)

Set or clear the secondary CTA button. Same API as setPrimaryCta.

setActionsMenu(items)

Set the actions dropdown menu items.

AssemblyBridge.header.setActionsMenu([
  { label: "Archive", icon: "Archive", onClick: () => archive() },
  { label: "Delete", icon: "Trash", color: "red", onClick: () => remove() },
]);

Parameters:

  • items: Array of { label: string, icon?: Icon, color?: 'red', onClick: () => void }

AssemblyBridge.configure(config)

Configure the bridge with additional settings.

AssemblyBridge.configure({
  additionalOrigins: ["portal.yourcompany.com", "https://custom-domain.com"],
  debug: true, // Enable debug logging
});

Parameters:

  • config.additionalOrigins: Array of origins to allow for postMessage communication. Origins without a protocol default to HTTPS. Can be called multiple times - origins are cumulative.
  • config.debug: Enable debug mode to log warnings to the console when messages cannot be sent (e.g., parent origin not in allowlist, not running in an iframe). Useful for troubleshooting.

Note: The bridge includes built-in support for *.copilot.app, *.myassembly.com, dashboard.assembly.com, localhost, and their staging equivalents. You only need to use configure() for custom portal domains. The parent origin is learned from the first source-verified parent message — document.referrer is not used.

AssemblyBridge.navigate(route, options?)

Navigate to a different route in the parent application.

// Navigate to settings
AssemblyBridge.navigate("settings");

// Navigate to a specific app
AssemblyBridge.navigate("apps", { id: "app-123" });

// Navigate to a specific form
AssemblyBridge.navigate("forms", { id: "form-456" });

Parameters:

  • route: One of the supported routes (see below)
  • options: Optional { id?: string }

AssemblyBridge.navigateTo(destination, options?)

Navigate to a typed destination and await the host's acknowledgement. Returns a promise that resolves with { ok: true } on success, { ok: false, reason } when the host rejects the navigation, or rejects after the timeout if the host never responds.

TypeScript enforces the required params for each destination at compile time.

// Navigate to a specific invoice
const result = await AssemblyBridge.navigateTo({ to: "invoice", invoiceId: "inv_abc" });
if (!result.ok) {
  console.warn("Navigation rejected:", result.reason);
}

// Navigate to a client detail page
await AssemblyBridge.navigateTo({ to: "client", clientId: "cli_xyz", tab: "notes" });

// Navigate to home
await AssemblyBridge.navigateTo({ to: "home" });

Supported destinations:

toRequired paramsOptional params
home——
clientclientIdtab
companycompanyIdtab
channel—channelId
files—channelId
contractcontractId—
formformId—
formResponseformId, responseId—
invoiceinvoiceId—
subscriptionsubscriptionId—
product——
helpdesk——
articlearticleId—
notifications——
automations——
settings—page
appinstallId—

Options:

  • replace: Replace the current history entry instead of pushing (default: false)
  • newTab: Open in a new tab (default: false)
  • timeout: Milliseconds to wait for host acknowledgement before rejecting (default: 10000)

AssemblyBridge.location.report(path, search, replace?)

Report the app's current location to the host. Call this on every client-side route change. The path must have any surface prefix stripped — report /orders/42, not /c/orders/42.

AssemblyBridge.location.report("/orders/42", "?tab=details");
AssemblyBridge.location.report("/dashboard", "");
// Signal a replace (no new history entry on the host):
AssemblyBridge.location.report("/settings", "", true);

Parameters:

  • path: App-local path, surface prefix stripped (e.g. /orders/42).
  • search: Query string including the leading ?, or '' when absent.
  • replace: When true, the host should replace its history entry instead of pushing.

AssemblyBridge.location.onNavigate(handler)

Register a handler invoked whenever the host sends a location.navigate command. The handler receives a { path, search, replace? } payload with no surface prefix — the app must re-add its own prefix before navigating.

AssemblyBridge.location.onNavigate(({ path, search, replace }) => {
  const destination = `/c${path}${search}`;
  if (replace) {
    router.replace(destination);
  } else {
    router.push(destination);
  }
});

Parameters:

  • handler: Called with { path: string; search: string; replace?: boolean }.

Supported Values

Icons

Available for CTAs: Archive, Plus, Templates, Trash, Check

Available for action menu items: Archive, Plus, Templates, Trash, Download, Check, Disconnect

Routes

  • apps - Applications page (supports id for specific app)
  • billing - Billing page
  • contracts - Contracts page
  • files - Files page (supports id for channel)
  • forms - Forms page (supports id for specific form)
  • helpdesk - Help desk page (supports id for specific article)
  • invoices - Invoices page
  • messages - Messages page (supports id for channel)
  • notifications - Notifications page (supports id for channel)
  • settings - Settings page
  • settings.billing - Billing settings
  • settings.profile - Profile settings
  • products.create - Create product page
  • products.edit - Edit product page (supports id for product)

TypeScript Support

The package includes TypeScript declarations. Import types as needed:

import type {
  BreadcrumbItem,
  CtaConfig,
  ActionMenuItem,
  Route,
  Icon,
  NavigateDestination,
  NavigateToOptions,
  NavigateResult,
} from "@assembly-js/app-bridge";

Development

# Install dependencies
yarn install

# Build
yarn build

# Type check
yarn type-check

# Run tests
yarn test

# Generate content-hashed files
yarn generate-manifest

License

MIT

版本与发布记录

@assembly-js/app-bridge 共发布 12 个版本,首次发布于 2026/01/29;过去 12 个月发布了 12 个版本。

版本发布日期距今
2.1.0latest2026/10/299 天前
2.1.0-alpha.0alpha2026/10/2810 天前
2.0.02026/09/042 个月前
1.4.02026/08/142 个月前
1.4.0-alpha.02026/07/094 个月前
1.4.0-beta.1beta2026/07/034 个月前

关于 @assembly-js/app-bridge 的常见问题

@assembly-js/app-bridge 是什么?

Helper functions for postMessage communications between custom apps and the Copilot parent application

如何安装 @assembly-js/app-bridge?

在项目目录运行 npm install @assembly-js/app-bridge,或使用 pnpm add / yarn add / bun add。

@assembly-js/app-bridge 支持 TypeScript 吗?

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

@assembly-js/app-bridge 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@assembly-js/app-bridge 可以商用吗?

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

@assembly-js/app-bridge 的下载量有多少?

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

@assembly-js/app-bridge 还在维护吗?

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