@agent-relay/github-primitive

中文文档
7.1.1发布于 2026/05/25TypeScriptES Module构建来源已验证近 30 天下载 1.7万

GitHub workflow primitive for Agent Relay

原始使用文档
文档目录6 节
  1. Runtime Selection
  2. Actions
  3. Workflow Step
  4. End-to-end PR workflow
  5. Multi-tenant routing
  6. Cloud adoption: the resolver helper

@agent-relay/github-primitive

GitHub workflow primitive for Agent Relay. It exposes a typed client and a workflow integration step that can run through the local gh CLI or a cloud GitHub proxy.

Runtime Selection

The primitive supports three runtime modes:

  • auto: prefer cloud when Nango or relay-cloud credentials are present, otherwise use the local gh CLI when available.
  • local: use gh api from the current machine.
  • cloud: use Nango first, then relay-cloud proxy when configured.
import { GitHubClient } from '@agent-relay/github-primitive';

const github = await GitHubClient.create({
  runtime: 'auto',
});

const repo = await github.getRepo('AgentWorkforce', 'relay');
console.log(repo.defaultBranch);

Actions

The client and workflow step support:

  • Repositories: listRepos, getRepo
  • Issues: listIssues, createIssue, updateIssue, closeIssue
  • Pull requests: listPRs, getPR, createPR, updatePR, mergePR
  • Files: listFiles, readFile, createFile, updateFile, deleteFile
  • Branches and commits: listBranches, createBranch, listCommits, createCommit
  • Identity: getUser, listOrganizations

Workflow Step

import { createGitHubStep } from '@agent-relay/github-primitive/workflow-step';

createGitHubStep({
  name: 'read-readme',
  action: 'readFile',
  repo: 'AgentWorkforce/relay',
  params: {
    path: 'README.md',
  },
  output: {
    mode: 'data',
    format: 'text',
  },
});

See examples/github-step.ts for a workflow runner example and examples/github-client.ts for a standalone client example.

End-to-end PR workflow

examples/end-to-end-pr-workflow.ts walks the full PR lifecycle against a single runtime:

  1. getRepo — inspect + log the selected runtime.
  2. createBranch off the base branch.
  3. createFile — write a marker file on the new branch.
  4. createPR — the core integration step cloud workflows migrate to.
  5. getPR — round-trip verify.
  6. updatePR — edit the PR body without code changes.
  7. listPRs — confirm indexability.
  8. (commented) mergePR — off by default so the example never merges anything real.

Run against a scratch repo:

GITHUB_REPO=AgentWorkforce/scratch npx tsx \
  packages/github-primitive/examples/end-to-end-pr-workflow.ts

Runtime selection is automatic:

PathTriggered when
Local ghgh auth status succeeds and no cloud creds are set
NangoNANGO_SECRET_KEY + NANGO_GITHUB_CONNECTION_ID + NANGO_GITHUB_PROVIDER_CONFIG_KEY present
relay-cloudRELAY_CLOUD_API_URL + RELAY_CLOUD_API_TOKEN + WORKSPACE_ID present (fallback when Nango absent)

Multi-tenant routing

In cloud, every workspace has its own GitHub App install — one Nango connection per tenant. createGitHubStep accepts a per-step config field so a single workflow can route different actions through different connections. One workflow, many tenants.

examples/multi-tenant-pr-workflow.ts demonstrates this: it opens PRs in AgentWorkforce/cloud (via the AgentWorkforce app) AND in an MSD-owned repo (via MSD's app), from the same workflow definition, by varying the config: field on each step.

Cloud adoption: the resolver helper

The primitive stays tenant-unaware — it takes a GitHubRuntimeConfig and does what it's told. The tenant lookup lives in cloud, in a small helper:

// cloud/packages/web/lib/github/connection-resolver.ts
import type { GitHubRuntimeConfig } from '@agent-relay/github-primitive';

export async function githubConfigForRepo(opts: {
  repo: string; // "owner/repo"
  workspaceId?: string; // optional — cloud-owned repos default
}): Promise<GitHubRuntimeConfig> {
  const connection = await resolveWorkspaceIntegration(opts.workspaceId, 'github', opts.repo);

  return {
    runtime: 'auto',
    nango: {
      connectionId: connection.connectionId,
      providerConfigKey: connection.providerConfigKey, // 'github-agentworkforce' | 'github-msd' | 'github-nightcto' | ...
      secretKey: process.env.NANGO_SECRET_KEY,
    },
    relayCloud: {
      apiUrl: process.env.CLOUD_API_URL,
      accessToken: process.env.CLOUD_API_TOKEN,
      workspaceId: opts.workspaceId,
    },
  };
}

Workflow authors in cloud then write:

createGitHubStep({
  name: 'open-pr',
  action: 'createPR',
  repo: 'AgentWorkforce/cloud',
  params: { title, head, base, body },
  config: await githubConfigForRepo({
    repo: 'AgentWorkforce/cloud',
    workspaceId: process.env.RELAY_WORKSPACE_ID,
  }),
});

One resolver, one call-site shape. Adding a new GitHub App install is a workspace_integrations row + (optionally) a NANGO_* secret — no code change in the workflows that create PRs.

版本与发布记录

@agent-relay/github-primitive 共发布 45 个版本,首次发布于 2026/04/23;过去 12 个月发布了 45 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
7.1.1latest2026/05/255 个月前
7.1.02026/05/235 个月前
7.0.12026/05/225 个月前
6.3.62026/05/225 个月前
7.0.02026/05/225 个月前
6.3.52026/05/225 个月前

关于 @agent-relay/github-primitive 的常见问题

@agent-relay/github-primitive 是什么?

GitHub workflow primitive for Agent Relay

如何安装 @agent-relay/github-primitive?

在项目目录运行 npm install @agent-relay/github-primitive,或使用 pnpm add / yarn add / bun add。

@agent-relay/github-primitive 支持 TypeScript 吗?

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

@agent-relay/github-primitive 支持 ESM 还是 CommonJS?

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

@agent-relay/github-primitive 可以商用吗?

@agent-relay/github-primitive 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@agent-relay/github-primitive 的下载量有多少?

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

@agent-relay/github-primitive 还在维护吗?

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