名称: Pulse Editor Vibe Dev Flow
描述: 使用 Vibe Dev Flow API 生成和构建 Pulse 应用。当用户需要创建、更新或为 Pulse Editor 应用程序生成代码时,使用此技能。
此技能使您能够与 Pulse Editor Vibe Dev Flow API 交互,利用基于云的 AI 编码代理来生成、构建和发布 Pulse 应用。该 API 使用服务器发送事件(SSE)流式传输来提供实时进度更新。
此技能为 AI 代理提供了显著优势:
appId 和 version 来更新现有应用,从而轻松迭代应用程序,无需手动管理版本。此 API 调用是一个长时间运行的操作。 Vibe Dev Flow 执行多个步骤,包括工作区创建、AI 代码生成、构建和发布。
"streamUpdatePolicy": "artifactOnly",以便仅接收最终工件输出,从而显著减少输入令牌。但即使一段时间没有收到消息,也不应视为卡住。当用户希望执行以下操作时,请使用此技能:
Pulse Editor API 需要 API 密钥进行身份验证。用户可以通过以下方式获取其 API 密钥:
API 密钥应在 Authorization 请求头中以 Bearer 令牌形式传递:
Authorization: Bearer your_api_key_here
POST https://pulse-editor.com/api/server-function/vibe_dev_flow/latest/generate-code/v2/generate
| 请求头 | 是否必需 | 描述 |
|---|---|---|
Authorization |
是 | 包含 Pulse Editor API 密钥的 Bearer 令牌 |
Content-Type |
是 | application/json |
Accept |
是 | text/event-stream |
| 参数 | 类型 | 是否必需 | 描述 | 示例 |
|---|---|---|---|---|
prompt |
string | 是 | 指示 Vibe 编码代理的用户提示 | "创建一个带有身份验证和深色模式的待办事项应用" |
appName |
string | 否 | 应用的友好显示名称 | "我的待办事项应用" |
appId |
string | 否 | 要更新的现有应用的唯一标识符。如果未提供,将创建一个新应用 | "my_app_x7k9q2" |
version |
string | 否 | 现有应用的版本标识符。如果未提供,则默认为最新版本 | "0.0.1" |
streamUpdatePolicy |
string | 否 | 设置为 "artifactOnly" 以仅接收最终工件输出(推荐给代理以节省令牌) |
"artifactOnly" |
响应是一个服务器发送事件(SSE)流。每个事件包含一个 JSON 编码的消息。消息之间由 \n\n 分隔。
每个 SSE 消息的格式为:
data: <JSON>
后跟一个空行。
有两种消息类型:
创建消息 - 流中的新消息:
{
"messageId": "msg_abc123",
"type": "creation",
"data": {
"type": "text" | "toolCall" | "toolResult" | "artifactOutput",
"result": "string content",
"error": "error message if any"
},
"isFinal": false
}
更新消息 - 对现有消息的增量更新:
{
"messageId": "msg_abc123",
"type": "update",
"delta": {
"result": "additional content to append",
"error": "additional error to append"
},
"isFinal": true
}
| 类型 | 描述 |
|---|---|
text |
来自代理的文本输出 |
toolCall |
代理调用的工具 |
toolResult |
工具执行的结果 |
artifactOutput |
包含已发布应用信息的最终工件 |
当生成完成时,artifactOutput 消息包含:
{
"publishedAppLink": "https://pulse-editor.com/app/...",
"sourceCodeArchiveLink": "https://...",
"appId": "my_app_x7k9q2",
"version": "0.0.1"
}
| 状态码 | 描述 |
|---|---|
| 200 | 流式传输 SSE,包含进度和最终结果 |
| 400 | 错误请求 - 参数无效 |
| 401 | 未授权 - API 密钥无效或缺失 |
| 500 | 服务器错误 |
curl -L 'https://pulse-editor.com/api/server-function/vibe_dev_flow/latest/generate-code/v2/generate' \
-H 'Content-Type: application/json' \
-H 'Accept: text/event-stream' \
-H 'Authorization: Bearer your_api_key_here' \
-d '{
"prompt": "Create a todo app with auth and dark mode",
"appName": "My Todo App"
}'
import requests
import json
url = "https://pulse-editor.com/api/server-function/vibe_dev_flow/latest/generate-code/v2/generate"
headers = {
"Authorization": "Bearer your_api_key_here",
"Content-Type": "application/json",
"Accept": "text/event-stream"
}
payload = {
"prompt": "Create a todo app with auth and dark mode",
"appName": "My Todo App"
}
response = requests.post(url, json=payload, headers=headers, stream=True)
messages = {} # 按 messageId 跟踪消息
buffer = ""
for chunk in response.iter_content(chunk_size=None, decode_unicode=True):
buffer += chunk
# SSE 消息以 \n\n 结尾
while "\n\n" in buffer:
part, buffer = buffer.split("\n\n", 1)
if not part.startswith("data:"):
continue
data = json.loads(part.replace("data: ", "", 1))
if data["type"] == "creation":
messages[data["messageId"]] = data
print(f"New: {data['data'].get('result', '')}")
elif data["type"] == "update":
msg = messages.get(data["messageId"])
if msg:
msg["data"]["result"] = (msg["data"].get("result") or "") + (data["delta"].get("result") or "")
msg["isFinal"] = data["isFinal"]
# 检查工件输出
if data.get("data", {}).get("type") == "artifactOutput" and data.get("isFinal"):
result = json.loads(messages[data["messageId"]]["data"]["result"])
print(f"Published: {result.get('publishedAppLink')}")
const response = await fetch(
"https://pulse-editor.com/api/server-function/vibe_dev_flow/latest/generate-code/v2/generate",
{
method: "POST",
headers: {
Authorization: "Bearer your_api_key_here",
"Content-Type": "application/json",
},
body: JSON.stringify({
prompt: "Create a todo app with auth and dark mode",
appName: "My Todo App",
}),
},
);
const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
const messages = new Map();
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
// SSE 消息以 \n\n 结尾
const parts = buffer.split("\n\n");
buffer = parts.pop(); // 将不完整的部分保留在缓冲区中
for (const part of parts) {
if (!part.startsWith("data:")) continue;
const json = part.replace(/^data:\s*/, "");
const message = JSON.parse(json);
if (message.type === "creation") {
messages.set(message.messageId, message);
} else if (message.type === "update") {
const msg = messages.get(message.messageId);
if (msg) {
msg.data.result =
(msg.data.result ?? "") + (message.delta.result ?? "");
msg.data.error = (msg.data.error ?? "") + (message.delta.error ?? "");
msg.isFinal = message.isFinal;
}
}
// 检查最终工件输出
const msg = messages.get(message.messageId);
if (msg?.data.type === "artifactOutput" && msg.isFinal) {
const result = JSON.parse(msg.data.result);
console.log("Published:", result.publishedAppLink);
}
}
}
要更新现有应用,请包含 appId 和可选的 version:
curl -L 'https://pulse-editor.com/api/server-function/vibe_dev_flow/latest/generate-code/v2/generate' \
-H 'Content-Type: application/json' \
-H 'Accept: text/event-stream' \
-H 'Authorization: Bearer your_api_key_here' \
-d '{
"prompt": "Add a calendar view to display tasks by date",
"appName": "My Todo App",
"appId": "my_app_x7k9q2",
"version": "0.0.1"
}'
| 问题 | 解决方案 |
|---|---|
| 401 未授权 | 验证您的 API 密钥是否正确并具有 Beta 访问权限 |
| 无 SSE 事件 | 确保设置了 Accept: text/event-stream 请求头 |
| 应用未更新 | 验证 appId 是否存在且您有权访问它 |
此技能在 examples/ 文件夹中包含一个可直接运行的 Python 示例:
examples/generate_app.py - 完整的 Python 脚本,演示了使用 Vibe Dev Flow API 进行 SSE 流式传输。examples/generate_app.js - 完整的 Node.js 脚本,演示了使用 Vibe Dev Flow API 进行 SSE 流式传输。运行 Python 示例脚本:
# 设置您的 API 密钥
export PULSE_EDITOR_API_KEY=your_api_key_here # Linux/Mac
set PULSE_EDITOR_API_KEY=your_api_key_here # Windows
# 安装依赖项
pip install requests
# 运行脚本
python examples/generate_app.py
运行 Node.js 示例脚本:
# 设置您的 API 密钥
export PULSE_EDITOR_API_KEY=your_api_key_here # Linux/Mac
set PULSE_EDITOR_API_KEY=your_api_key_here # Windows
# 安装依赖项
npm install node-fetch
# 运行脚本
node examples/generate_app.js