docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// worker 侧画布执行:每次任务新建临时 CODEX_HOME,按模态启动 CLI 并提取完成结果。
|
||||
package codex
|
||||
|
||||
import (
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// executeCanvasTask 由共享执行槽保护;模型已从目录选出,但仍须核对请求模态和输入图片。
|
||||
func executeCanvasTask(w http.ResponseWriter, r *http.Request, input CanvasTask, model CanvasModel) {
|
||||
imageOutput := input.OutputModality == "image"
|
||||
if input.OutputModality != "" && input.OutputModality != "text" && !imageOutput {
|
||||
@@ -32,6 +34,7 @@ func executeCanvasTask(w http.ResponseWriter, r *http.Request, input CanvasTask,
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), duration)
|
||||
defer cancel()
|
||||
// 临时目录承载认证软链接、输入图片和生成产物;成功与所有失败路径都由 defer 删除。
|
||||
job, err := os.MkdirTemp("", "foundry-canvas-")
|
||||
if err != nil {
|
||||
fail(w, 503, "codex_unavailable")
|
||||
@@ -43,11 +46,13 @@ func executeCanvasTask(w http.ResponseWriter, r *http.Request, input CanvasTask,
|
||||
fail(w, 503, "codex_unavailable")
|
||||
return
|
||||
}
|
||||
// 关闭 shell、应用、插件等能力;文本模型还关闭图片生成,画布模式忽略用户配置与规则。
|
||||
args := []string{"--ask-for-approval", "never", "--disable", "shell_tool", "--disable", "apps", "--disable", "plugins", "--disable", "multi_agent", "--disable", "hooks", "--disable", "memories", "-c", `web_search="disabled"`}
|
||||
if !imageOutput {
|
||||
args = append(args, "--disable", "image_generation")
|
||||
}
|
||||
args = append(args, "exec", "--json", "--sandbox", "read-only", "--skip-git-repo-check", "--ephemeral", "--ignore-user-config", "--ignore-rules", "--model", model.Backend)
|
||||
// 对图片内容嗅探 MIME,而非仅信任传入类型;只允许已知栅格格式并限制总大小。
|
||||
total := 0
|
||||
for i, image := range input.Images {
|
||||
total += len(image.Data)
|
||||
@@ -80,6 +85,7 @@ func executeCanvasTask(w http.ResponseWriter, r *http.Request, input CanvasTask,
|
||||
cmd.Dir = "/work"
|
||||
cmd.Env = []string{"PATH=/usr/local/bin:/usr/bin:/bin", "HOME=/home/node", "CODEX_HOME=" + home, "SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt"}
|
||||
cmd.Stdin = strings.NewReader(prompt)
|
||||
// 独立进程组使请求取消/超时可杀掉 CLI 及其子进程,避免残留后台任务。
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
cmd.Cancel = func() error {
|
||||
err := syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||
@@ -103,6 +109,7 @@ func executeCanvasTask(w http.ResponseWriter, r *http.Request, input CanvasTask,
|
||||
fail(w, 502, "generation_failed")
|
||||
return
|
||||
}
|
||||
// CLI 退出零还不够:事件流必须完成且无错误,图片结果还需从专用产物目录读取。
|
||||
text, completed := canvasAgentText(output.buffer.Bytes())
|
||||
if !completed {
|
||||
fail(w, 502, "generation_failed")
|
||||
@@ -122,6 +129,8 @@ func executeCanvasTask(w http.ResponseWriter, r *http.Request, input CanvasTask,
|
||||
}
|
||||
writeJSON(w, 200, map[string]any{"output": result})
|
||||
}
|
||||
|
||||
// canvasAgentText 逐行读取 JSON 事件,保留最后一条 agent_message;任何坏行或失败事件均拒绝。
|
||||
func canvasAgentText(raw []byte) (string, bool) {
|
||||
result := ""
|
||||
completed := false
|
||||
@@ -148,6 +157,9 @@ func canvasAgentText(raw []byte) (string, bool) {
|
||||
}
|
||||
return result, completed
|
||||
}
|
||||
|
||||
// readCanvasGeneratedImage 只遍历本次 generated_images,拒绝软链接、非常规文件和多张候选图片。
|
||||
// 此处只做格式嗅探与字节限制;完整解码和尺寸验证由平台资产接收流程负责。
|
||||
func readCanvasGeneratedImage(root string) (*CanvasImage, error) {
|
||||
var result *CanvasImage
|
||||
err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, walkErr error) error {
|
||||
|
||||
Reference in New Issue
Block a user