docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// 画布生成的结构化 IPC 输出;图片以字节传到核心,再由平台资产流程验证和持久化。
|
||||
package codex
|
||||
|
||||
import (
|
||||
@@ -9,13 +10,17 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// CanvasImageBytesLimit 限制原始图片总字节,响应上限另为 JSON/base64 编码留出空间。
|
||||
const CanvasImageBytesLimit = 20 << 20
|
||||
const canvasArtifactResponseLimit = 32 << 20
|
||||
|
||||
// CanvasImage 的 Data 在 JSON 中编码为 base64,仅用于私有 Unix 通道。
|
||||
type CanvasImage struct {
|
||||
MIME string `json:"mime_type"`
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
|
||||
// CanvasOutput 用 Kind 区分文本和图片,由 GenerateOutput 再校验形态与请求模态相符。
|
||||
type CanvasOutput struct {
|
||||
Kind string `json:"kind"`
|
||||
Text string `json:"text,omitempty"`
|
||||
@@ -24,6 +29,7 @@ type CanvasOutput struct {
|
||||
|
||||
// Encoded image bytes exist only on the private Unix IPC channel. Public Canvas
|
||||
// jobs expose stable asset IDs/URLs and never serialize these bytes to browsers.
|
||||
// GenerateOutput 先检查输入预算,再发送 IPC;映射稳定错误码,兼容旧 worker 的 result 文本字段。
|
||||
func (c *CanvasClient) GenerateOutput(ctx context.Context, input CanvasTask) (CanvasOutput, error) {
|
||||
if c == nil {
|
||||
return CanvasOutput{}, errors.New("codex_unavailable")
|
||||
@@ -51,6 +57,7 @@ func (c *CanvasClient) GenerateOutput(ctx context.Context, input CanvasTask) (Ca
|
||||
return CanvasOutput{}, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
// 多读一字节区分刚好达到上限与实际超限,防止截断响应被当成成功结果。
|
||||
raw, err = io.ReadAll(io.LimitReader(response.Body, canvasArtifactResponseLimit+1))
|
||||
if err != nil || len(raw) > canvasArtifactResponseLimit {
|
||||
return CanvasOutput{}, errors.New("generation_failed")
|
||||
@@ -80,6 +87,7 @@ func (c *CanvasClient) GenerateOutput(ctx context.Context, input CanvasTask) (Ca
|
||||
return CanvasOutput{}, errors.New("generation_failed")
|
||||
}
|
||||
}
|
||||
// 旧响应只允许回退到文本;图片请求缺少结构化图片时必须失败。
|
||||
if result.Output == nil {
|
||||
if input.OutputModality == "image" {
|
||||
return CanvasOutput{}, errors.New("generation_failed")
|
||||
|
||||
Reference in New Issue
Block a user