veadk-python 0.2.5__py3-none-any.whl → 0.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of veadk-python might be problematic. Click here for more details.
- veadk/agent.py +29 -22
- veadk/agent_builder.py +94 -0
- veadk/auth/__init__.py +13 -0
- veadk/auth/base_auth.py +22 -0
- veadk/auth/veauth/__init__.py +13 -0
- veadk/auth/veauth/apmplus_veauth.py +65 -0
- veadk/auth/veauth/ark_veauth.py +77 -0
- veadk/auth/veauth/base_veauth.py +50 -0
- veadk/auth/veauth/cozeloop_veauth.py +13 -0
- veadk/auth/veauth/prompt_pilot_veauth.py +60 -0
- veadk/auth/veauth/vesearch_veauth.py +62 -0
- veadk/cli/cli.py +2 -0
- veadk/cli/cli_deploy.py +5 -2
- veadk/cli/cli_init.py +25 -6
- veadk/cli/cli_pipeline.py +220 -0
- veadk/cli/cli_prompt.py +4 -4
- veadk/config.py +45 -81
- veadk/configs/__init__.py +13 -0
- veadk/configs/database_configs.py +83 -0
- veadk/configs/model_configs.py +42 -0
- veadk/configs/tool_configs.py +42 -0
- veadk/configs/tracing_configs.py +110 -0
- veadk/consts.py +32 -1
- veadk/database/database_adapter.py +256 -3
- veadk/database/kv/redis_database.py +47 -0
- veadk/database/local_database.py +23 -4
- veadk/database/relational/mysql_database.py +58 -0
- veadk/database/vector/opensearch_vector_database.py +6 -3
- veadk/database/viking/viking_database.py +272 -36
- veadk/integrations/ve_code_pipeline/__init__.py +13 -0
- veadk/integrations/ve_code_pipeline/ve_code_pipeline.py +431 -0
- veadk/integrations/ve_cozeloop/__init__.py +13 -0
- veadk/integrations/ve_cozeloop/ve_cozeloop.py +96 -0
- veadk/integrations/ve_cr/__init__.py +13 -0
- veadk/integrations/ve_cr/ve_cr.py +220 -0
- veadk/integrations/ve_faas/template/cookiecutter.json +3 -2
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py +2 -2
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/agent.py +1 -1
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/app.py +24 -1
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/requirements.txt +3 -1
- veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/run.sh +1 -12
- veadk/integrations/ve_faas/ve_faas.py +352 -35
- veadk/integrations/ve_faas/web_template/cookiecutter.json +17 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/__init__.py +13 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/clean.py +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/config.yaml.example +2 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/deploy.py +41 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/Dockerfile +23 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/app.py +123 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/init_db.py +46 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/models.py +36 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/requirements.txt +4 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/run.sh +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/css/style.css +368 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/static/js/admin.js +0 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/dashboard.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/edit_post.html +24 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/login.html +21 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/admin/posts.html +53 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/base.html +45 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/index.html +29 -0
- veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/templates/post.html +14 -0
- veadk/integrations/ve_prompt_pilot/ve_prompt_pilot.py +6 -3
- veadk/integrations/ve_tls/__init__.py +13 -0
- veadk/integrations/ve_tls/utils.py +117 -0
- veadk/integrations/ve_tls/ve_tls.py +208 -0
- veadk/integrations/ve_tos/ve_tos.py +128 -73
- veadk/knowledgebase/knowledgebase.py +116 -20
- veadk/memory/long_term_memory.py +20 -21
- veadk/memory/short_term_memory_processor.py +9 -4
- veadk/runner.py +213 -223
- veadk/tools/builtin_tools/vesearch.py +2 -2
- veadk/tools/builtin_tools/video_generate.py +27 -20
- veadk/tracing/telemetry/attributes/extractors/common_attributes_extractors.py +5 -0
- veadk/tracing/telemetry/attributes/extractors/llm_attributes_extractors.py +253 -129
- veadk/tracing/telemetry/attributes/extractors/types.py +15 -4
- veadk/tracing/telemetry/exporters/apmplus_exporter.py +158 -12
- veadk/tracing/telemetry/exporters/cozeloop_exporter.py +4 -9
- veadk/tracing/telemetry/exporters/tls_exporter.py +4 -10
- veadk/tracing/telemetry/opentelemetry_tracer.py +11 -5
- veadk/tracing/telemetry/telemetry.py +23 -5
- veadk/utils/logger.py +1 -1
- veadk/utils/misc.py +48 -0
- veadk/utils/volcengine_sign.py +6 -2
- veadk/version.py +1 -1
- {veadk_python-0.2.5.dist-info → veadk_python-0.2.7.dist-info}/METADATA +2 -1
- veadk_python-0.2.7.dist-info/RECORD +172 -0
- veadk_python-0.2.5.dist-info/RECORD +0 -127
- /veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{{ cookiecutter.app_name|replace('-', '_') }} → {{ cookiecutter.app_name }}}/__init__.py +0 -0
- /veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/src/{{{ cookiecutter.app_name|replace('-', '_') }} → {{ cookiecutter.app_name }}}/agent.py +0 -0
- {veadk_python-0.2.5.dist-info → veadk_python-0.2.7.dist-info}/WHEEL +0 -0
- {veadk_python-0.2.5.dist-info → veadk_python-0.2.7.dist-info}/entry_points.txt +0 -0
- {veadk_python-0.2.5.dist-info → veadk_python-0.2.7.dist-info}/licenses/LICENSE +0 -0
- {veadk_python-0.2.5.dist-info → veadk_python-0.2.7.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
from string import Template
|
|
17
|
+
|
|
18
|
+
import requests
|
|
19
|
+
|
|
20
|
+
from veadk.utils.logger import get_logger
|
|
21
|
+
from veadk.utils.misc import formatted_timestamp
|
|
22
|
+
from veadk.utils.volcengine_sign import ve_request
|
|
23
|
+
|
|
24
|
+
logger = get_logger(__name__)
|
|
25
|
+
|
|
26
|
+
SPEC = Template("""version: 1.0.0
|
|
27
|
+
agentPool: public/prod-v2-public
|
|
28
|
+
sources:
|
|
29
|
+
- name: ${code_connection_name}
|
|
30
|
+
type: Github
|
|
31
|
+
url: ${github_url}
|
|
32
|
+
branch: ${github_branch}
|
|
33
|
+
branchingModel: false
|
|
34
|
+
credential:
|
|
35
|
+
type: serviceConnection
|
|
36
|
+
serviceConnectionId: ${code_connection_id}
|
|
37
|
+
cloneDepth: 1
|
|
38
|
+
stages:
|
|
39
|
+
- stage: stage-1
|
|
40
|
+
displayName: 函数构建
|
|
41
|
+
tasks:
|
|
42
|
+
- task: task-1
|
|
43
|
+
displayName: 函数构建
|
|
44
|
+
timeout: 2h
|
|
45
|
+
steps:
|
|
46
|
+
- step: step-c1
|
|
47
|
+
displayName: 镜像构建推送到镜像仓库服务
|
|
48
|
+
component: build@2.0.0/buildkit-cr@3.0.0
|
|
49
|
+
inputs:
|
|
50
|
+
buildParams: ""
|
|
51
|
+
compression: gzip
|
|
52
|
+
contextPath: .
|
|
53
|
+
crDomain: ${cr_domain}
|
|
54
|
+
crNamespace: ${cr_namespace_name}
|
|
55
|
+
crRegion: ${cr_region}
|
|
56
|
+
crRegistryInstance: ${cr_instance_name}
|
|
57
|
+
crRepo: ${cr_repo_name}
|
|
58
|
+
crTag: $(DATETIME)
|
|
59
|
+
disableSSLVerify: false
|
|
60
|
+
dockerfiles:
|
|
61
|
+
default:
|
|
62
|
+
content: |-
|
|
63
|
+
${docker_file}
|
|
64
|
+
loginCredential: []
|
|
65
|
+
useCache: false
|
|
66
|
+
outputs:
|
|
67
|
+
- imageOutput_step-c1
|
|
68
|
+
workspace:
|
|
69
|
+
resources:
|
|
70
|
+
- ref: ${code_connection_name}
|
|
71
|
+
directory: $(CP_WORKSPACE)
|
|
72
|
+
resourcesPolicy: all
|
|
73
|
+
resources:
|
|
74
|
+
limits:
|
|
75
|
+
cpu: 1C
|
|
76
|
+
memory: 2Gi
|
|
77
|
+
- stage: stage-2
|
|
78
|
+
displayName: 函数部署
|
|
79
|
+
tasks:
|
|
80
|
+
- task: task-2
|
|
81
|
+
displayName: 函数部署
|
|
82
|
+
component: deploy@1.0.0/faas-deploy
|
|
83
|
+
inputs:
|
|
84
|
+
artifact:
|
|
85
|
+
mode: output
|
|
86
|
+
type: image
|
|
87
|
+
value: $(stages.stage-1.tasks.task-1.outputs.imageOutput_step-c1)
|
|
88
|
+
deployPolicy:
|
|
89
|
+
type: full
|
|
90
|
+
functionId: ${function_id}
|
|
91
|
+
functionVersion: 0
|
|
92
|
+
region: cn-beijing
|
|
93
|
+
outputs:
|
|
94
|
+
- releaseId
|
|
95
|
+
- releaseStatus
|
|
96
|
+
workspace: {}
|
|
97
|
+
""")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_dockerfile(tag: str = "latest") -> str:
|
|
101
|
+
dockerfile = f"""FROM veadk-cn-beijing.cr.volces.com/veadk/veadk-python:{tag}
|
|
102
|
+
WORKDIR /app
|
|
103
|
+
COPY . .
|
|
104
|
+
RUN pip3 install --no-cache-dir -r requirements.txt
|
|
105
|
+
ENTRYPOINT ["bash", "./run.sh"]"""
|
|
106
|
+
return dockerfile
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class VeCodePipeline:
|
|
110
|
+
def __init__(
|
|
111
|
+
self,
|
|
112
|
+
volcengine_access_key: str,
|
|
113
|
+
volcengine_secret_key: str,
|
|
114
|
+
region: str = "cn-beijing",
|
|
115
|
+
) -> None:
|
|
116
|
+
self.volcengine_access_key = volcengine_access_key
|
|
117
|
+
self.volcengine_secret_key = volcengine_secret_key
|
|
118
|
+
self.region = region
|
|
119
|
+
|
|
120
|
+
self.service = "CP"
|
|
121
|
+
self.version = "2023-05-01"
|
|
122
|
+
self.host = "open.volcengineapi.com"
|
|
123
|
+
self.content_type = "application/json"
|
|
124
|
+
|
|
125
|
+
def _create_code_connection(
|
|
126
|
+
self, github_token: str, github_url: str
|
|
127
|
+
) -> tuple[str, str]:
|
|
128
|
+
logger.info("Creating code connection...")
|
|
129
|
+
|
|
130
|
+
conn_name = f"veadk-conn-{formatted_timestamp()}"
|
|
131
|
+
res = ve_request(
|
|
132
|
+
request_body={
|
|
133
|
+
"Id": f"VEADK_CONN_{formatted_timestamp()}",
|
|
134
|
+
"Name": conn_name,
|
|
135
|
+
"Description": "Created by Volcengine Agent Development Kit (VeADK)",
|
|
136
|
+
"Type": "Github",
|
|
137
|
+
"Credential": {"Token": github_token},
|
|
138
|
+
"IsAllWsShared": True,
|
|
139
|
+
"URL": github_url,
|
|
140
|
+
},
|
|
141
|
+
action="CreateServiceConnection",
|
|
142
|
+
ak=self.volcengine_access_key,
|
|
143
|
+
sk=self.volcengine_secret_key,
|
|
144
|
+
service=self.service,
|
|
145
|
+
version=self.version,
|
|
146
|
+
region=self.region,
|
|
147
|
+
host=self.host,
|
|
148
|
+
content_type=self.content_type,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
logger.info(
|
|
153
|
+
f"Code connection created successfully, code connection id {res['Result']['Id']}",
|
|
154
|
+
)
|
|
155
|
+
return res["Result"]["Id"], conn_name
|
|
156
|
+
except KeyError:
|
|
157
|
+
raise Exception(f"Create code connection failed: {res}")
|
|
158
|
+
|
|
159
|
+
def _get_default_workspace(self) -> str:
|
|
160
|
+
logger.info("Getting default workspace...")
|
|
161
|
+
|
|
162
|
+
res = ve_request(
|
|
163
|
+
request_body={},
|
|
164
|
+
action="GetDefaultWorkspaceInner",
|
|
165
|
+
ak=self.volcengine_access_key,
|
|
166
|
+
sk=self.volcengine_secret_key,
|
|
167
|
+
service=self.service,
|
|
168
|
+
version=self.version,
|
|
169
|
+
region=self.region,
|
|
170
|
+
host=self.host,
|
|
171
|
+
content_type=self.content_type,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
try:
|
|
175
|
+
logger.info(
|
|
176
|
+
f"Default workspace retrieved successfully, workspace id {res['Result']['Id']}",
|
|
177
|
+
)
|
|
178
|
+
return res["Result"]["Id"]
|
|
179
|
+
except KeyError:
|
|
180
|
+
raise Exception(f"Get default workspace failed: {res}")
|
|
181
|
+
|
|
182
|
+
def _create_pipeline(
|
|
183
|
+
self,
|
|
184
|
+
workspace_id: str,
|
|
185
|
+
code_connection_id: str,
|
|
186
|
+
code_connection_name: str,
|
|
187
|
+
github_url: str,
|
|
188
|
+
github_branch: str,
|
|
189
|
+
cr_domain: str,
|
|
190
|
+
cr_namespace_name: str,
|
|
191
|
+
cr_region: str,
|
|
192
|
+
cr_instance_name: str,
|
|
193
|
+
cr_repo_name: str,
|
|
194
|
+
docker_file: str,
|
|
195
|
+
function_id: str,
|
|
196
|
+
) -> str:
|
|
197
|
+
logger.info("Creating pipeline...")
|
|
198
|
+
|
|
199
|
+
spec = SPEC.safe_substitute(
|
|
200
|
+
github_url=github_url,
|
|
201
|
+
github_branch=github_branch,
|
|
202
|
+
workspace_id=workspace_id,
|
|
203
|
+
code_connection_id=code_connection_id,
|
|
204
|
+
code_connection_name=code_connection_name,
|
|
205
|
+
cr_domain=cr_domain,
|
|
206
|
+
cr_namespace_name=cr_namespace_name,
|
|
207
|
+
cr_region=cr_region,
|
|
208
|
+
cr_instance_name=cr_instance_name,
|
|
209
|
+
cr_repo_name=cr_repo_name,
|
|
210
|
+
docker_file=docker_file,
|
|
211
|
+
function_id=function_id,
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
print(spec)
|
|
215
|
+
|
|
216
|
+
res = ve_request(
|
|
217
|
+
request_body={
|
|
218
|
+
"WorkspaceId": workspace_id,
|
|
219
|
+
"Name": f"veadk-pipeline-{formatted_timestamp()}",
|
|
220
|
+
"spec": spec,
|
|
221
|
+
},
|
|
222
|
+
action="CreatePipeline",
|
|
223
|
+
ak=self.volcengine_access_key,
|
|
224
|
+
sk=self.volcengine_secret_key,
|
|
225
|
+
service="CP",
|
|
226
|
+
version="2023-05-01",
|
|
227
|
+
region="cn-beijing",
|
|
228
|
+
host="open.volcengineapi.com",
|
|
229
|
+
content_type="application/json",
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
try:
|
|
233
|
+
logger.info(
|
|
234
|
+
f"Pipeline created successfully, pipeline id {res['Result']['Id']}",
|
|
235
|
+
)
|
|
236
|
+
return res["Result"]["Id"]
|
|
237
|
+
except KeyError:
|
|
238
|
+
raise Exception(f"Create pipeline failed: {res}")
|
|
239
|
+
|
|
240
|
+
def _create_webhook_trigger(self, workspace_id: str, pipeline_id: str) -> str:
|
|
241
|
+
logger.info("Creating webhook trigger...")
|
|
242
|
+
|
|
243
|
+
res = ve_request(
|
|
244
|
+
request_body={
|
|
245
|
+
"WorkspaceId": workspace_id,
|
|
246
|
+
"PipelineId": pipeline_id,
|
|
247
|
+
"Type": "GitWebhook",
|
|
248
|
+
},
|
|
249
|
+
action="CreatePipelineWebhookURL",
|
|
250
|
+
ak=self.volcengine_access_key,
|
|
251
|
+
sk=self.volcengine_secret_key,
|
|
252
|
+
service=self.service,
|
|
253
|
+
version=self.version,
|
|
254
|
+
region=self.region,
|
|
255
|
+
host=self.host,
|
|
256
|
+
content_type=self.content_type,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
webhook_url = ""
|
|
260
|
+
try:
|
|
261
|
+
logger.info(
|
|
262
|
+
f"Webhook trigger created successfully, webhook trigger url {res['Result']['WebhookURL']}",
|
|
263
|
+
)
|
|
264
|
+
webhook_url = res["Result"]["WebhookURL"]
|
|
265
|
+
except KeyError:
|
|
266
|
+
raise Exception(f"Create webhook trigger failed: {res}")
|
|
267
|
+
|
|
268
|
+
# create a trigger with webhook url and pipeline id
|
|
269
|
+
|
|
270
|
+
return webhook_url
|
|
271
|
+
|
|
272
|
+
def _set_github_webhook(
|
|
273
|
+
self, webhook_url: str, github_url: str, github_token: str
|
|
274
|
+
) -> None:
|
|
275
|
+
logger.info("Setting GitHub webhook...")
|
|
276
|
+
|
|
277
|
+
github_url = github_url.replace("https://", "").replace("http://", "")
|
|
278
|
+
github_url_parts = [part for part in github_url.split("/") if part]
|
|
279
|
+
owner = github_url_parts[-2]
|
|
280
|
+
repo = github_url_parts[-1]
|
|
281
|
+
|
|
282
|
+
logger.debug(f"Parsed GitHub URL, owner: {owner}, repo: {repo}")
|
|
283
|
+
|
|
284
|
+
headers = {
|
|
285
|
+
"Accept": "application/vnd.github+json",
|
|
286
|
+
"Authorization": f"Bearer {github_token}",
|
|
287
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
288
|
+
"Content-Type": "application/json",
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
webhook_config = {
|
|
292
|
+
"name": "web",
|
|
293
|
+
"active": True,
|
|
294
|
+
"events": ["push"],
|
|
295
|
+
"config": {"url": webhook_url, "content_type": "json", "insecure_ssl": "1"},
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
try:
|
|
299
|
+
response = requests.post(
|
|
300
|
+
url=f"https://api.github.com/repos/{owner}/{repo}/hooks",
|
|
301
|
+
headers=headers,
|
|
302
|
+
data=json.dumps(webhook_config),
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
if response.status_code == 201:
|
|
306
|
+
logger.info("Create github Webhook successfully.")
|
|
307
|
+
result = response.json()
|
|
308
|
+
logger.info(
|
|
309
|
+
f"Webhook ID: {result['id']}, Webhook URL: {result['url']}, Listening events: {', '.join(result['events'])}"
|
|
310
|
+
)
|
|
311
|
+
return result
|
|
312
|
+
else:
|
|
313
|
+
logger.error(f"Create Webhook failed: HTTP {response.status_code}")
|
|
314
|
+
logger.error(f"Error message: {response.text}")
|
|
315
|
+
return None
|
|
316
|
+
|
|
317
|
+
except requests.exceptions.RequestException as e:
|
|
318
|
+
logger.error(f"Request exception: {e}")
|
|
319
|
+
return None
|
|
320
|
+
|
|
321
|
+
def _create_trigger(
|
|
322
|
+
self,
|
|
323
|
+
workspace_id: str,
|
|
324
|
+
pipeline_id: str,
|
|
325
|
+
webhook_url: str,
|
|
326
|
+
code_connection_name: str,
|
|
327
|
+
github_branch: str,
|
|
328
|
+
) -> None:
|
|
329
|
+
"""Create and bind a trigger to pipeline instance with webhook url."""
|
|
330
|
+
logger.info("Creating trigger and bind it to pipeline instance...")
|
|
331
|
+
|
|
332
|
+
res = ve_request(
|
|
333
|
+
request_body={
|
|
334
|
+
"WorkspaceId": workspace_id,
|
|
335
|
+
"PipelineId": pipeline_id,
|
|
336
|
+
"Name": f"veadk-event-trigger-{formatted_timestamp()}",
|
|
337
|
+
"Type": "GitWebhook",
|
|
338
|
+
"Configuration": {
|
|
339
|
+
"Webhook": {
|
|
340
|
+
"URL": webhook_url,
|
|
341
|
+
"Git": {
|
|
342
|
+
"SourceName": code_connection_name,
|
|
343
|
+
"Filters": [
|
|
344
|
+
{
|
|
345
|
+
"EventType": "Push",
|
|
346
|
+
"Config": {"References": [github_branch]},
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
"EventType": "CreateTag",
|
|
350
|
+
"Config": {"References": []},
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
"TriggerExecutionType": "AllEvents",
|
|
354
|
+
},
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
"Sources": [
|
|
358
|
+
{
|
|
359
|
+
"SourceName": code_connection_name,
|
|
360
|
+
"Reference": "main",
|
|
361
|
+
}
|
|
362
|
+
],
|
|
363
|
+
},
|
|
364
|
+
action="CreateTrigger",
|
|
365
|
+
ak=self.volcengine_access_key,
|
|
366
|
+
sk=self.volcengine_secret_key,
|
|
367
|
+
service=self.service,
|
|
368
|
+
version=self.version,
|
|
369
|
+
region=self.region,
|
|
370
|
+
host=self.host,
|
|
371
|
+
content_type=self.content_type,
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
try:
|
|
375
|
+
logger.info(
|
|
376
|
+
f"Trigger created and bind successfully, result Id is {res['Result']['Id']}",
|
|
377
|
+
)
|
|
378
|
+
except KeyError:
|
|
379
|
+
raise Exception(f"Create webhook trigger failed: {res}")
|
|
380
|
+
|
|
381
|
+
def deploy(
|
|
382
|
+
self,
|
|
383
|
+
base_image_tag: str,
|
|
384
|
+
github_url: str,
|
|
385
|
+
github_branch: str,
|
|
386
|
+
github_token: str,
|
|
387
|
+
cr_domain: str,
|
|
388
|
+
cr_namespace_name: str,
|
|
389
|
+
cr_region: str,
|
|
390
|
+
cr_instance_name: str,
|
|
391
|
+
cr_repo_name: str,
|
|
392
|
+
function_id: str,
|
|
393
|
+
) -> str:
|
|
394
|
+
workspace_id = self._get_default_workspace()
|
|
395
|
+
|
|
396
|
+
code_connection_id, code_connection_name = self._create_code_connection(
|
|
397
|
+
github_token=github_token, github_url=github_url
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
pipeline_id = self._create_pipeline(
|
|
401
|
+
workspace_id=workspace_id,
|
|
402
|
+
code_connection_id=code_connection_id,
|
|
403
|
+
code_connection_name=code_connection_name,
|
|
404
|
+
github_url=github_url,
|
|
405
|
+
github_branch=github_branch,
|
|
406
|
+
cr_domain=cr_domain,
|
|
407
|
+
cr_namespace_name=cr_namespace_name,
|
|
408
|
+
cr_region=cr_region,
|
|
409
|
+
cr_instance_name=cr_instance_name,
|
|
410
|
+
cr_repo_name=cr_repo_name,
|
|
411
|
+
docker_file=get_dockerfile(tag=base_image_tag),
|
|
412
|
+
function_id=function_id,
|
|
413
|
+
)
|
|
414
|
+
|
|
415
|
+
webhook_url = self._create_webhook_trigger(
|
|
416
|
+
workspace_id=workspace_id, pipeline_id=pipeline_id
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
self._set_github_webhook(
|
|
420
|
+
webhook_url=webhook_url, github_url=github_url, github_token=github_token
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
self._create_trigger(
|
|
424
|
+
workspace_id=workspace_id,
|
|
425
|
+
pipeline_id=pipeline_id,
|
|
426
|
+
webhook_url=webhook_url,
|
|
427
|
+
code_connection_name=code_connection_name,
|
|
428
|
+
github_branch=github_branch,
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
return pipeline_id
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import requests
|
|
16
|
+
|
|
17
|
+
from veadk.consts import DEFAULT_COZELOOP_SPACE_NAME
|
|
18
|
+
from veadk.utils.logger import get_logger
|
|
19
|
+
|
|
20
|
+
logger = get_logger(__name__)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class VeCozeloop:
|
|
24
|
+
def __init__(self, api_key: str) -> None:
|
|
25
|
+
self.api_key = api_key
|
|
26
|
+
|
|
27
|
+
def create_workspace(
|
|
28
|
+
self, workspace_name: str = DEFAULT_COZELOOP_SPACE_NAME
|
|
29
|
+
) -> str:
|
|
30
|
+
logger.info(
|
|
31
|
+
f"Automatically create Cozeloop workspace with name {workspace_name}"
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
try:
|
|
35
|
+
workspace_id = self.search_workspace_id(workspace_name=workspace_name)
|
|
36
|
+
logger.info(f"Get existing Cozeloop workspace ID: {workspace_id}")
|
|
37
|
+
|
|
38
|
+
return workspace_id
|
|
39
|
+
except Exception as _:
|
|
40
|
+
URL = "https://api.coze.cn/v1/workspaces"
|
|
41
|
+
|
|
42
|
+
headers = {
|
|
43
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
data = {
|
|
48
|
+
"name": workspace_name,
|
|
49
|
+
"description": "Created by Volcengine Agent Development Kit (VeADK)",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
response = requests.post(URL, headers=headers, json=data)
|
|
53
|
+
|
|
54
|
+
if response.json().get("code") == 0:
|
|
55
|
+
workspace_id = response.json().get("data").get("id")
|
|
56
|
+
logger.info(f"New created Cozeloop workspace ID: {workspace_id}")
|
|
57
|
+
return workspace_id
|
|
58
|
+
else:
|
|
59
|
+
raise Exception(
|
|
60
|
+
f"Failed to automatically create workspace: {response.json()}"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def search_workspace_id(
|
|
64
|
+
self, workspace_name: str = DEFAULT_COZELOOP_SPACE_NAME
|
|
65
|
+
) -> str:
|
|
66
|
+
logger.info(
|
|
67
|
+
f"Automatically fetching Cozeloop workspace ID with name {workspace_name}"
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
URL = "https://api.coze.cn/v1/workspaces"
|
|
71
|
+
|
|
72
|
+
headers = {
|
|
73
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
data = {
|
|
78
|
+
"page_num": 1,
|
|
79
|
+
"page_size": 50,
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
response = requests.get(URL, headers=headers, json=data)
|
|
83
|
+
|
|
84
|
+
if response.json().get("code") == 0:
|
|
85
|
+
workspaces = response.json().get("data").get("workspaces", [])
|
|
86
|
+
|
|
87
|
+
workspace_id = ""
|
|
88
|
+
for workspace in workspaces:
|
|
89
|
+
if workspace.get("name") == workspace_name:
|
|
90
|
+
workspace_id = workspace.get("id")
|
|
91
|
+
logger.info(f"Get Cozeloop workspace ID: {workspace_id}")
|
|
92
|
+
return workspace_id
|
|
93
|
+
|
|
94
|
+
raise Exception(f"Workspace with name {workspace_name} not found.")
|
|
95
|
+
else:
|
|
96
|
+
raise Exception(f"Failed to get workspace ID: {response.json()}")
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|