Skip to content

Commit 3aa414e

Browse files
committed
fix: support BytePlus GitHub automations
1 parent d3dc43c commit 3aa414e

73 files changed

Lines changed: 675 additions & 405 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6522,6 +6522,7 @@ export default function App() {
65226522
) : applicationsView && applicationsView !== "catalog" ? (
65236523
<GitHubIntegration
65246524
automation={applicationsView}
6525+
cloudProvider={cloudProvider}
65256526
onBack={() => setApplicationsView("catalog")}
65266527
/>
65276528
) : applicationsView === "catalog" ? (

frontend/src/adk/githubIntegration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export type GitHubAutomationRegion = "cn-beijing" | "cn-shanghai";
1+
import type { CloudRegion } from "./cloudProvider";
2+
3+
export type GitHubAutomationRegion = CloudRegion;
24

35
export interface GitHubPullRequestResult {
46
number: number;

frontend/src/automations/githubFields.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
defaultCloudRegion,
3+
defaultModelApiBase,
4+
type CloudProvider,
5+
} from "../adk/cloudProvider";
16
import type {
27
AutomationFieldDefinition,
38
AutomationFormValues,
@@ -35,7 +40,54 @@ export const runtimeIdField: AutomationFieldDefinition = {
3540
required: true,
3641
};
3742

43+
const VOLCENGINE_REVIEW_MODEL_BASE_URL =
44+
"https://ark.cn-beijing.volces.com/api/coding/v3";
45+
46+
export interface CloudCredentialSecretNames {
47+
accessKey: string;
48+
secretKey: string;
49+
sessionToken: string;
50+
}
51+
52+
export function defaultReviewModelBaseUrl(provider: CloudProvider): string {
53+
return provider === "byteplus"
54+
? defaultModelApiBase(provider)
55+
: VOLCENGINE_REVIEW_MODEL_BASE_URL;
56+
}
57+
58+
export function cloudCredentialSecretNames(
59+
provider: CloudProvider,
60+
): CloudCredentialSecretNames {
61+
if (provider === "byteplus") {
62+
return {
63+
accessKey: "BYTEPLUS_ACCESS_KEY",
64+
secretKey: "BYTEPLUS_SECRET_KEY",
65+
sessionToken: "BYTEPLUS_SESSION_TOKEN",
66+
};
67+
}
68+
return {
69+
accessKey: "VOLCENGINE_ACCESS_KEY",
70+
secretKey: "VOLCENGINE_SECRET_KEY",
71+
sessionToken: "VOLCENGINE_SESSION_TOKEN",
72+
};
73+
}
74+
75+
export function cloudCredentialSecretLabels(
76+
provider: CloudProvider,
77+
): readonly string[] {
78+
const secrets = cloudCredentialSecretNames(provider);
79+
return [
80+
`${secrets.accessKey}${secrets.secretKey}(必填)`,
81+
`${secrets.sessionToken}(使用临时凭据时必填)`,
82+
];
83+
}
84+
85+
export function cloudProviderDisplayName(provider: CloudProvider): string {
86+
return provider === "byteplus" ? "BytePlus" : "Volcengine";
87+
}
88+
3889
export function initialAutomationValues(
90+
provider: CloudProvider,
3991
overrides: Partial<AutomationFormValues> = {},
4092
): AutomationFormValues {
4193
return {
@@ -46,8 +98,8 @@ export function initialAutomationValues(
4698
runtimeId: "",
4799
sandboxToolId: "",
48100
modelName: "",
49-
modelBaseUrl: "https://ark.cn-beijing.volces.com/api/coding/v3",
50-
region: "cn-beijing",
101+
modelBaseUrl: defaultReviewModelBaseUrl(provider),
102+
region: defaultCloudRegion(provider),
51103
token: "",
52104
...overrides,
53105
};

frontend/src/automations/pullRequestReview.ts

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import {
22
createGitHubPullRequest,
33
type GitHubAutomationRegion,
44
} from "../adk/githubIntegration";
5+
import type { CloudProvider } from "../adk/cloudProvider";
56
import {
67
baseBranchField,
8+
cloudCredentialSecretLabels,
9+
cloudCredentialSecretNames,
710
commonGitHubInput,
811
initialAutomationValues,
912
repositoryField,
@@ -15,6 +18,7 @@ interface PullRequestReviewWorkflowInput {
1518
modelName: string;
1619
modelBaseUrl: string;
1720
region: GitHubAutomationRegion;
21+
cloudProvider?: CloudProvider;
1822
}
1923

2024
const SANDBOX_TOOL_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
@@ -50,6 +54,17 @@ export function validatePullRequestReviewSettings(
5054

5155
export function buildPullRequestReviewWorkflow(input: PullRequestReviewWorkflowInput): string {
5256
validatePullRequestReviewSettings(input);
57+
const cloudProvider = input.cloudProvider ?? "volcengine";
58+
const secrets = cloudCredentialSecretNames(cloudProvider);
59+
const byteplusCompatibilityEnv = cloudProvider === "byteplus"
60+
? `
61+
VOLCENGINE_ACCESS_KEY: \${{ secrets.${secrets.accessKey} }}
62+
VOLCENGINE_SECRET_KEY: \${{ secrets.${secrets.secretKey} }}
63+
VOLCENGINE_SESSION_TOKEN: \${{ secrets.${secrets.sessionToken} }}`
64+
: "";
65+
const providerRegionEnv = cloudProvider === "byteplus"
66+
? ` BYTEPLUS_REGION: ${JSON.stringify(input.region)}`
67+
: ` VOLCENGINE_REGION: ${JSON.stringify(input.region)}`;
5368
const template = String.raw`name: PR Automated Review
5469
5570
"on":
@@ -72,10 +87,13 @@ jobs:
7287
runs-on: ubuntu-latest
7388
timeout-minutes: 30
7489
env:
75-
VOLCENGINE_ACCESS_KEY: __GH__ secrets.VOLCENGINE_ACCESS_KEY }}
76-
VOLCENGINE_SECRET_KEY: __GH__ secrets.VOLCENGINE_SECRET_KEY }}
77-
VOLCENGINE_SESSION_TOKEN: __GH__ secrets.VOLCENGINE_SESSION_TOKEN }}
78-
VOLCENGINE_REGION: __REGION__
90+
AGENTKIT_CLOUD_PROVIDER: __CLOUD_PROVIDER__
91+
CLOUD_PROVIDER: __CLOUD_PROVIDER__
92+
__ACCESS_KEY_SECRET__: __GH__ secrets.__ACCESS_KEY_SECRET__ }}
93+
__SECRET_KEY_SECRET__: __GH__ secrets.__SECRET_KEY_SECRET__ }}
94+
__SESSION_TOKEN_SECRET__: __GH__ secrets.__SESSION_TOKEN_SECRET__ }}__BYTEPLUS_COMPATIBILITY_ENV__
95+
__PROVIDER_REGION_ENV__
96+
AGENTKIT_REGION: __REGION__
7997
AGENTKIT_SANDBOX_TOOL_ID: __SANDBOX_TOOL_ID__
8098
CODEX_MODEL_NAME: __MODEL_NAME__
8199
CODEX_MODEL_BASE_URL: __MODEL_BASE_URL__
@@ -138,6 +156,12 @@ jobs:
138156
const replacements: Record<string, string> = {
139157
"__GH__": "${{",
140158
__REGION__: JSON.stringify(input.region),
159+
__CLOUD_PROVIDER__: JSON.stringify(cloudProvider),
160+
__ACCESS_KEY_SECRET__: secrets.accessKey,
161+
__SECRET_KEY_SECRET__: secrets.secretKey,
162+
__SESSION_TOKEN_SECRET__: secrets.sessionToken,
163+
__BYTEPLUS_COMPATIBILITY_ENV__: byteplusCompatibilityEnv,
164+
__PROVIDER_REGION_ENV__: providerRegionEnv,
141165
__SANDBOX_TOOL_ID__: JSON.stringify(input.sandboxToolId),
142166
__MODEL_NAME__: JSON.stringify(input.modelName),
143167
__MODEL_BASE_URL__: JSON.stringify(input.modelBaseUrl),
@@ -172,26 +196,30 @@ export const pullRequestReviewAutomation: GitHubAutomationDefinition = {
172196
{
173197
name: "modelName",
174198
label: "评审模型",
175-
placeholder: "doubao-seed-code-preview",
199+
placeholder: "review-model",
176200
help: "注入 Sandbox 的代码评审模型名称",
177201
required: true,
178202
},
179203
{
180204
name: "modelBaseUrl",
181205
label: "模型 API 地址",
182-
placeholder: "https://ark.cn-beijing.volces.com/api/coding/v3",
206+
placeholder: "https://ark.example.com/api/v3",
183207
help: "必须使用 OpenAI 兼容的 HTTPS 地址",
184208
required: true,
185209
},
186210
],
187-
initialValues: initialAutomationValues(),
211+
initialValues: ({ cloudProvider }) => initialAutomationValues(cloudProvider),
188212
regionHelp: "必须与 Sandbox Tool 所在地域一致",
189-
secrets: [
190-
"VOLCENGINE_ACCESS_KEY、VOLCENGINE_SECRET_KEY(必填)",
191-
"CODEX_MODEL_API_KEY(必填)",
192-
"VOLCENGINE_SESSION_TOKEN(使用临时凭据时必填)",
193-
],
194-
submit(values, signal) {
213+
secrets: ({ cloudProvider }) => {
214+
const [requiredCredentials, optionalSessionToken] =
215+
cloudCredentialSecretLabels(cloudProvider);
216+
return [
217+
requiredCredentials,
218+
"CODEX_MODEL_API_KEY(必填)",
219+
optionalSessionToken,
220+
];
221+
},
222+
submit(values, context, signal) {
195223
const input = commonGitHubInput(values);
196224
return createGitHubPullRequest(
197225
{
@@ -204,6 +232,7 @@ export const pullRequestReviewAutomation: GitHubAutomationDefinition = {
204232
modelName: values.modelName.trim(),
205233
modelBaseUrl: values.modelBaseUrl.trim(),
206234
region: input.region,
235+
cloudProvider: context.cloudProvider,
207236
}),
208237
commitMessage: "chore: configure PR automated review",
209238
},

frontend/src/automations/runtimeDelivery.ts

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import {
33
normalizeRepositoryPath,
44
type GitHubAutomationRegion,
55
} from "../adk/githubIntegration";
6+
import type { CloudProvider } from "../adk/cloudProvider";
67
import {
78
baseBranchField,
9+
cloudCredentialSecretLabels,
10+
cloudCredentialSecretNames,
11+
cloudProviderDisplayName,
812
commonGitHubInput,
913
initialAutomationValues,
1014
repositoryField,
@@ -20,9 +24,11 @@ interface RuntimeDeliveryWorkflowInput {
2024
runtimeName: string;
2125
runtimeId: string;
2226
region: GitHubAutomationRegion;
27+
cloudProvider?: CloudProvider;
2328
}
2429

2530
const RUNTIME_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
31+
const BYTEPLUS_VIKING_MEMORY_REGION = "cn-hongkong";
2632

2733
export function validateRuntimeSettings(
2834
input: Pick<RuntimeDeliveryWorkflowInput, "runtimeName" | "runtimeId">,
@@ -38,6 +44,19 @@ export function validateRuntimeSettings(
3844

3945
export function buildRuntimeDeliveryWorkflow(input: RuntimeDeliveryWorkflowInput): string {
4046
validateRuntimeSettings(input);
47+
const cloudProvider = input.cloudProvider ?? "volcengine";
48+
const secrets = cloudCredentialSecretNames(cloudProvider);
49+
const byteplusEnv = cloudProvider === "byteplus"
50+
? `
51+
VOLCENGINE_ACCESS_KEY: \${{ secrets.${secrets.accessKey} }}
52+
VOLCENGINE_SECRET_KEY: \${{ secrets.${secrets.secretKey} }}
53+
VOLCENGINE_SESSION_TOKEN: \${{ secrets.${secrets.sessionToken} }}
54+
BYTEPLUS_REGION: ${JSON.stringify(input.region)}`
55+
: "";
56+
const byteplusRuntimeEnv = cloudProvider === "byteplus"
57+
? `
58+
"DATABASE_VIKING_REGION": ${JSON.stringify(BYTEPLUS_VIKING_MEMORY_REGION)},`
59+
: "";
4160
const template = `name: Publish to AgentKit Runtime
4261
4362
on:
@@ -55,15 +74,17 @@ concurrency:
5574
5675
jobs:
5776
publish:
77+
if: \${{ github.event_name != 'push' || !contains(github.event.head_commit.message, '[skip runtime]') }}
5878
runs-on: ubuntu-latest
5979
defaults:
6080
run:
6181
working-directory: __PROJECT_PATH__
6282
env:
63-
AGENTKIT_CLOUD_PROVIDER: volcengine
64-
VOLC_ACCESSKEY: \${{ secrets.VOLCENGINE_ACCESS_KEY }}
65-
VOLC_SECRETKEY: \${{ secrets.VOLCENGINE_SECRET_KEY }}
66-
VOLC_SESSIONTOKEN: \${{ secrets.VOLCENGINE_SESSION_TOKEN }}
83+
AGENTKIT_CLOUD_PROVIDER: __CLOUD_PROVIDER__
84+
CLOUD_PROVIDER: __CLOUD_PROVIDER__
85+
__ACCESS_KEY_SECRET__: \${{ secrets.__ACCESS_KEY_SECRET__ }}
86+
__SECRET_KEY_SECRET__: \${{ secrets.__SECRET_KEY_SECRET__ }}
87+
__SESSION_TOKEN_SECRET__: \${{ secrets.__SESSION_TOKEN_SECRET__ }}__BYTEPLUS_ENV__
6788
AGENTKIT_RUNTIME_NAME: __RUNTIME_NAME__
6889
AGENTKIT_RUNTIME_ID: __RUNTIME_ID__
6990
AGENTKIT_REGION: __REGION__
@@ -90,10 +111,15 @@ jobs:
90111
from agentkit.toolkit import sdk
91112
from agentkit.toolkit.models import PreflightMode
92113
114+
credential_prefix = (
115+
"BYTEPLUS"
116+
if os.environ["AGENTKIT_CLOUD_PROVIDER"] == "byteplus"
117+
else "VOLCENGINE"
118+
)
93119
runtime_client = AgentkitRuntimeClient(
94-
access_key=os.environ["VOLC_ACCESSKEY"],
95-
secret_key=os.environ["VOLC_SECRETKEY"],
96-
session_token=os.environ.get("VOLC_SESSIONTOKEN", ""),
120+
access_key=os.environ[f"{credential_prefix}_ACCESS_KEY"],
121+
secret_key=os.environ[f"{credential_prefix}_SECRET_KEY"],
122+
session_token=os.environ.get(f"{credential_prefix}_SESSION_TOKEN", ""),
97123
region=os.environ["AGENTKIT_REGION"],
98124
)
99125
runtime = runtime_client.get_runtime(
@@ -122,6 +148,10 @@ jobs:
122148
"runtime_name": runtime_name,
123149
"runtime_role_name": runtime_role_name,
124150
"python_version": "3.12",
151+
"runtime_envs": {
152+
"CLOUD_PROVIDER": os.environ["CLOUD_PROVIDER"],
153+
"AGENTKIT_CLOUD_PROVIDER": os.environ["AGENTKIT_CLOUD_PROVIDER"],__BYTEPLUS_RUNTIME_ENV__
154+
},
125155
}
126156
},
127157
}
@@ -141,6 +171,12 @@ jobs:
141171
__RUNTIME_NAME__: JSON.stringify(input.runtimeName),
142172
__RUNTIME_ID__: JSON.stringify(input.runtimeId),
143173
__REGION__: JSON.stringify(input.region),
174+
__CLOUD_PROVIDER__: JSON.stringify(cloudProvider),
175+
__ACCESS_KEY_SECRET__: secrets.accessKey,
176+
__SECRET_KEY_SECRET__: secrets.secretKey,
177+
__SESSION_TOKEN_SECRET__: secrets.sessionToken,
178+
__BYTEPLUS_ENV__: byteplusEnv,
179+
__BYTEPLUS_RUNTIME_ENV__: byteplusRuntimeEnv,
144180
__CONCURRENCY_GROUP__: JSON.stringify(`agentkit-runtime-${input.runtimeId}`),
145181
};
146182
return Object.entries(replacements).reduce(
@@ -173,15 +209,13 @@ export const runtimeDeliveryAutomation: GitHubAutomationDefinition = {
173209
runtimeNameField,
174210
runtimeIdField,
175211
],
176-
initialValues: initialAutomationValues(),
212+
initialValues: ({ cloudProvider }) => initialAutomationValues(cloudProvider),
177213
regionHelp: "必须与目标 Runtime 所在地域一致",
178-
secrets: [
179-
"VOLCENGINE_ACCESS_KEY、VOLCENGINE_SECRET_KEY(必填)",
180-
"VOLCENGINE_SESSION_TOKEN(使用临时凭据时必填)",
181-
],
182-
submit(values, signal) {
214+
secrets: ({ cloudProvider }) => cloudCredentialSecretLabels(cloudProvider),
215+
submit(values, context, signal) {
183216
const input = commonGitHubInput(values);
184217
const projectPath = normalizeRepositoryPath(values.projectPath, ".");
218+
const providerName = cloudProviderDisplayName(context.cloudProvider);
185219
return createGitHubPullRequest(
186220
{
187221
...input,
@@ -194,13 +228,14 @@ export const runtimeDeliveryAutomation: GitHubAutomationDefinition = {
194228
runtimeName: values.runtimeName.trim(),
195229
runtimeId: values.runtimeId.trim(),
196230
region: input.region,
231+
cloudProvider: context.cloudProvider,
197232
}),
198233
commitMessage: "feat: publish Agent to AgentKit Runtime",
199234
},
200235
],
201236
branchPrefix: "feat/agentkit-release",
202237
title: "feat: 持续发布到 AgentKit Runtime",
203-
description: "新增 GitHub Actions 工作流,在目标分支更新时持续发布到 AgentKit Runtime。合并前请配置工作流所需的 Volcengine Secrets。",
238+
description: `新增 GitHub Actions 工作流,在目标分支更新时持续发布到 AgentKit Runtime。合并前请配置工作流所需的 ${providerName} Secrets。`,
204239
},
205240
signal,
206241
);

0 commit comments

Comments
 (0)