@ agent-relay/github-原始内容
GitHub 工作流程原始为代理中继器. 它暴露一个打字客户端和一个
工作流程整合步骤,可在本地运行 gh CLI 或一团云
GitHub 代理服务器 .
运行时间选择
原始模式支持三种运行模式:
auto:宁戈或中继云证书出现时更喜欢云, 以其他方式使用当地gh如有CLI的话.local: 使用gh api从当前机器.cloud:先使用南戈,再配置后使用中继-云代理.
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);
行动
客户端和工作流程步骤支持:
- 仓库 :
listRepos, (中文(简体) ),getRepo - 问题:
listIssues, (中文(简体) ),createIssue, (中文(简体) ),updateIssue, (中文(简体) ),closeIssue - 拉动请求 :
listPRs, (中文(简体) ),getPR, (中文(简体) ),createPR, (中文(简体) ),updatePR, (中文(简体) ),mergePR - 文件 :
listFiles, (中文(简体) ),readFile, (中文(简体) ),createFile, (中文(简体) ),updateFile, (中文(简体) ),deleteFile - 分支和承诺:
listBranches, (中文(简体) ),createBranch, (中文(简体) ),listCommits, (中文(简体) ),createCommit - 身份 :
getUser, (中文(简体) ),listOrganizations
工作流程步骤
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',
},
});
见 examples/github-step.ts 用于工作流程运行实例和
examples/github-client.ts 为独立的客户端示例.
端到端的公关工作流程
examples/end-to-end-pr-workflow.ts 环绕整个公关寿命周期
单个运行时间 :
getRepo——检查+登录所选运行时间.createBranch从基地分支.createFile——在新分行上写出标记文件.createPR——核心集成步骤云工作流程迁移到.getPR——来回核实.updatePR——编辑PR正文而无需更改代码.listPRs——确认可索引性.- (评论)
mergePR默认关闭,所以示例永远不会合并 任何真实的.
运行在抓取回:
GITHUB_REPO=AgentWorkforce/scratch npx tsx \
packages/github-primitive/examples/end-to-end-pr-workflow.ts
运行时间选择是自动的 :
| 路径 | 触发当 |
|---|---|
当地 gh | gh auth status 成功且没有设置云卡 |
| 南戈语Name | NANGO_SECRET_KEY + 键 NANGO_GITHUB_CONNECTION_ID + 键 NANGO_GITHUB_PROVIDER_CONFIG_KEY 当前 |
| 中继云 | RELAY_CLOUD_API_URL + 键 RELAY_CLOUD_API_TOKEN + 键 WORKSPACE_ID 现值( 南戈缺席时返回) |
多租户路线
在云中,每个工作空间都有自己的 GitHub App 安装—— 一个南戈
每个租户的连接. createGitHubStep 接受每步 config
字段,所以单个工作流程可以通过
不同的连接。 一个工作流程,许多租户.
examples/multi-tenant-pr-workflow.ts 演示: 它打开 PR
内 AgentWorkforce/cloud (通过Agent Workforce app)和在一个
MSD自有回波(通过MSD的应用),来自相同的工作流程定义,由
更改 config: 字段.
云收养:解相助者
原始人留下的租户 - 不小心 GitHubRuntimeConfig
并按其所传. 租户的望相住在云中,在小地方
帮助者 :
// 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,
},
};
}
云中的工作流作者再写:
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,
}),
});
一个解决器,一个呼叫站台形状。 添加一个新的 GitHub App 安装是一个
workspace_integrations 行 + (可选) a NANGO_* 秘密 - 没有
创建 PR 的工作流程中的代码更改.