网淘吧来吧,欢迎您!

Pulse Editor Vibe Coding APIs

2026-03-31 新闻来源:网淘吧 围观:21
电脑广告
手机广告

概述

此技能使您能够与 Pulse Editor Vibe Dev Flow API 交互,利用基于云端的 AI 编程代理来生成、构建和发布 Pulse 应用。该 API 使用服务器发送事件 (SSE) 流式传输来提供实时进度更新。

为何使用此技能

此技能为 AI 代理提供了显著优势:

Pulse Editor Vibe Coding APIs

  • 无需本地代码生成:代理无需在用户本地机器上生成代码,可以将代码生成任务卸载至 Pulse Editor 的云端 vibe 编码服务。这消除了对本地构建工具、依赖项或开发环境的需求。

  • 内置版本控制:每次应用生成都会自动进行版本控制。代理可以通过指定appIdversion来更新现有应用,从而轻松迭代应用程序,无需手动管理版本。

  • 即时部署:应用在生成后会自动构建并立即发布。无需单独的构建或部署步骤——用户在生成完成后即可获得一个实时运行的应用 URL。

  • 并行应用生成代理可以通过并发API调用同时生成多个应用程序。这非常适合需要同时搭建多个微服务、创建多个相关应用或批量生成不同用途应用的场景。

  • 无状态与可扩展性:由于所有代码生成都在云端进行,代理保持轻量化,可水平扩展,无需担心本地资源限制。

重要提示:长时运行任务

此API调用属于长时运行操作。Vibe开发流程包含多个步骤,包括工作区创建、AI代码生成、构建和发布。

  • 预计耗时:通常为2-5分钟,复杂应用可能耗时更长
  • 超时阈值:除非超过10分钟
  • SSE流式传输:连接在整个过程中保持开启状态。即使一段时间内未收到SSE消息,只要连接保持开启,请求就不会停滞或卡住。请等待流传输结束或达到10分钟超时。
  • 代币效率:代理应在请求正文中使用"streamUpdatePolicy": "artifactOnly"

以仅接收最终工件输出,从而显著减少输入代币。但即使一段时间内没有收到消息,也不会被视为卡住。

何时使用此技能

  • 当用户希望执行以下操作时使用此技能:
  • 根据描述或提示创建新的 Pulse App
  • 使用新功能更新现有的 Pulse App
  • 为 Pulse Editor 应用程序生成代码

构建并发布 Pulse App

API 身份验证

  1. Pulse Editor API 需要 API 密钥进行身份验证。用户可以通过以下方式获取其 API 密钥:
  2. https://pulse-editor.com/注册或登录前往账户设置下的
  3. 开发者部分(如有需要)
  4. 在开发者部分创建并复制API密钥

API密钥应在Authorization请求头中以Bearer令牌形式传递:

Authorization: Bearer your_api_key_here

API端点

POST https://pulse-editor.com/api/server-function/vibe_dev_flow/latest/generate-code/v2/generate

请求头

请求头必需描述
Authorization包含Pulse Editor API密钥的Bearer令牌
Content-Typeapplication/json
Accepttext/event-stream

请求体参数

参数类型必需描述示例
提示词字符串给 Vibe 编码代理的用户指令"创建一个带有身份验证和深色模式的待办事项应用"
应用名称字符串应用友好的显示名称"我的待办事项应用"
应用ID字符串待更新现有应用的唯一标识符。如未提供,将创建一个新应用"my_app_x7k9q2"
版本字符串现有应用的版本标识符。如未提供,默认为最新版本"0.0.1"
流式更新策略字符串设置为"仅限制品"以仅接收最终制品输出(推荐代理使用以节省令牌)"仅限制品"

响应

响应是一个服务器发送事件(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
}

数据类型

类型描述
文本来自代理的文本输出
工具调用代理执行的工具调用
工具结果工具执行返回的结果
制品输出包含已发布应用信息的最终制品

制品输出格式

生成完成后,一条制品输出消息包含:

{
  "publishedAppLink": "https://pulse-editor.com/app/...",
  "sourceCodeArchiveLink": "https://...",
  "appId": "my_app_x7k9q2",
  "version": "0.0.1"
}

响应状态码

状态码描述
200流式服务器发送事件,包含进度和最终结果
400错误请求 - 参数无效
401未授权 - API密钥无效或缺失
500服务器错误

使用示例

cURL 示例

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"
  }'

Python 示例

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 = {}  # Track messages by messageId
buffer = ""

for chunk in response.iter_content(chunk_size=None, decode_unicode=True):
    buffer += chunk

    # SSE messages end with \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"]

        # Check for artifact output
        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')}")

JavaScript/Node.js 示例

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 messages end with \n\n
  const parts = buffer.split("\n\n");
  buffer = parts.pop(); // Keep incomplete part in buffer

  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;
      }
    }

    // Check for final artifact output
    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"
  }'

更新现有应用

要更新现有应用,需要包含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"
  }'

最佳实践

  1. 清晰的提示: 提供详细、具体的提示来描述您希望应用执行什么操作
  2. 正确处理SSE: 实时处理流式响应以获取进度更新
  3. 错误处理: 对400、401和500响应实现适当的错误处理
  4. API密钥安全: 切勿硬编码API密钥;请使用环境变量或安全存储
  5. 版本管理:更新应用时,请指定版本以确保您在正确的基础上进行构建

故障排除

问题解决方案
401 未授权请确认您的 API 密钥正确且拥有测试版访问权限
无 SSE 事件请确保Accept: text/event-stream请求头已设置
应用未更新请确认应用 ID存在且您拥有访问权限

包含的示例

此技能在examples/文件夹中包含一个可立即运行的 Python 示例:

  • examples/generate_app.py- 完整的 Python 脚本,演示了使用 Vibe Dev Flow API 的 SSE 流式传输
  • examples/generate_app.js- 完整的Node.js脚本,演示使用Vibe Dev Flow API进行SSE流式传输

运行示例Python脚本:

# Set your API key
export PULSE_EDITOR_API_KEY=your_api_key_here  # Linux/Mac
set PULSE_EDITOR_API_KEY=your_api_key_here     # Windows

# Install dependencies
pip install requests

# Run the script
python examples/generate_app.py

运行示例Node.js脚本:

# Set your API key
export PULSE_EDITOR_API_KEY=your_api_key_here  # Linux/Mac
set PULSE_EDITOR_API_KEY=your_api_key_here     # Windows
# Install dependencies
npm install node-fetch
# Run the script
node examples/generate_app.js

资源

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部
上一篇:Birthday Reminder 下一篇:Bambu Lab Local Control

相关文章

您是本站第349352名访客 今日有175篇新文章/评论