From b9f4aa80fac17a9cf51e71f3b5331574d9898e76 Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Wed, 6 May 2026 10:56:00 +0800 Subject: [PATCH] fix: omit inline openclaw artifact content --- internal/acp/openclaw_artifact_download.go | 26 ++++++++++++++++++++++ internal/acp/orchestrator.go | 4 +++- internal/acp/routing_test.go | 26 ++++++++++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/internal/acp/openclaw_artifact_download.go b/internal/acp/openclaw_artifact_download.go index 15fc259..d696500 100644 --- a/internal/acp/openclaw_artifact_download.go +++ b/internal/acp/openclaw_artifact_download.go @@ -175,6 +175,32 @@ func (s *Server) decorateOpenClawArtifactDownloadURLs(result map[string]any, ses } } +func stripOpenClawArtifactInlineContent(result map[string]any) { + if result == nil { + return + } + for _, key := range []string{"artifacts", "files", "attachments"} { + switch items := result[key].(type) { + case []any: + for _, item := range items { + stripOpenClawArtifactMapInlineContent(shared.AsMap(item)) + } + case []map[string]any: + for _, item := range items { + stripOpenClawArtifactMapInlineContent(item) + } + } + } +} + +func stripOpenClawArtifactMapInlineContent(artifact map[string]any) { + if artifact == nil { + return + } + delete(artifact, "encoding") + delete(artifact, "content") +} + func (s *Server) decorateOpenClawArtifactDownloadURL( artifact map[string]any, sessionKey string, diff --git a/internal/acp/orchestrator.go b/internal/acp/orchestrator.go index 3be486e..901a262 100644 --- a/internal/acp/orchestrator.go +++ b/internal/acp/orchestrator.go @@ -256,6 +256,7 @@ func (o *SessionOrchestrator) runOpenClawGatewayChat( notifyWithCollection, )) o.server.decorateOpenClawArtifactDownloadURLs(result, shared.StringArg(chatParams, "sessionKey", ""), artifactRunID) + stripOpenClawArtifactInlineContent(result) guardOpenClawArtifactResult(result, artifactDeliveryRequired) return result, nil } @@ -432,7 +433,8 @@ func (o *SessionOrchestrator) openClawArtifactExport( "runId": strings.TrimSpace(runID), "sinceUnixMs": sinceUnixMs, "maxFiles": 64, - "maxInlineBytes": 10 * 1024 * 1024, + "maxInlineBytes": 0, + "includeContent": false, } if preparedArtifact != nil && strings.TrimSpace(preparedArtifact.ArtifactScope) != "" { exportParams["artifactScope"] = strings.TrimSpace(preparedArtifact.ArtifactScope) diff --git a/internal/acp/routing_test.go b/internal/acp/routing_test.go index c929f3d..802a970 100644 --- a/internal/acp/routing_test.go +++ b/internal/acp/routing_test.go @@ -677,8 +677,11 @@ func TestExecuteSessionTaskGatewayExportsOpenClawArtifacts(t *testing.T) { if got := artifacts[0]["relativePath"]; got != "reports/final.md" { t.Fatalf("expected manifest artifact relative path, got %#v", artifacts[0]) } - if got := artifacts[0]["encoding"]; got != "base64" { - t.Fatalf("expected inline base64 artifact, got %#v", artifacts[0]) + if _, ok := artifacts[0]["encoding"]; ok { + t.Fatalf("expected OpenClaw task response to omit inline artifact encoding, got %#v", artifacts[0]) + } + if _, ok := artifacts[0]["content"]; ok { + t.Fatalf("expected OpenClaw task response to omit inline artifact content, got %#v", artifacts[0]) } downloadURL := strings.TrimSpace(shared.StringArg(artifacts[0], "downloadUrl", "")) if downloadURL == "" { @@ -704,6 +707,13 @@ func TestExecuteSessionTaskGatewayExportsOpenClawArtifacts(t *testing.T) { if parsedDownloadURL.Query().Get("sig") == "" { t.Fatalf("expected signed downloadUrl, got %q", downloadURL) } + exportParams := gateway.LastArtifactExportParams() + if got := strings.TrimSpace(shared.StringArg(exportParams, "maxInlineBytes", "")); got != "0" { + t.Fatalf("expected OpenClaw artifact export to disable inline content, got %#v", exportParams) + } + if got := shared.BoolArg(shared.StringArg(exportParams, "includeContent", ""), true); got { + t.Fatalf("expected OpenClaw artifact export to omit content, got %#v", exportParams) + } if got := gateway.Methods(); !sameMethods(got, []string{"connect", "xworkmate.artifacts.prepare", "chat.send", "agent.wait", "xworkmate.artifacts.export"}) { t.Fatalf("expected connect, artifact prepare, chat.send, agent.wait, then artifact export, got %#v", got) } @@ -766,6 +776,12 @@ func TestExecuteSessionTaskGatewayExportsLatestWorkspaceArtifactsWhenScopedDirec if got := strings.TrimSpace(shared.StringArg(artifacts[0], "downloadUrl", "")); got == "" { t.Fatalf("expected bridge downloadUrl on latest workspace artifact, got %#v", artifacts[0]) } + if _, ok := artifacts[0]["encoding"]; ok { + t.Fatalf("expected latest workspace artifact response to omit inline encoding, got %#v", artifacts[0]) + } + if _, ok := artifacts[0]["content"]; ok { + t.Fatalf("expected latest workspace artifact response to omit inline content, got %#v", artifacts[0]) + } exportParams := gateway.LastArtifactExportParams() if got := strings.TrimSpace(shared.StringArg(exportParams, "artifactScope", "")); !strings.HasPrefix(got, ".xworkmate/artifacts/tasks/thread-openclaw-latest-artifact/") { t.Fatalf("expected scoped artifact export params, got %#v", exportParams) @@ -773,6 +789,12 @@ func TestExecuteSessionTaskGatewayExportsLatestWorkspaceArtifactsWhenScopedDirec if got := shared.BoolArg(shared.StringArg(exportParams, "latestIfEmpty", ""), false); !got { t.Fatalf("expected latestIfEmpty export param, got %#v", exportParams) } + if got := strings.TrimSpace(shared.StringArg(exportParams, "maxInlineBytes", "")); got != "0" { + t.Fatalf("expected latest workspace export to disable inline content, got %#v", exportParams) + } + if got := shared.BoolArg(shared.StringArg(exportParams, "includeContent", ""), true); got { + t.Fatalf("expected latest workspace export to omit content, got %#v", exportParams) + } if got := gateway.Methods(); !sameMethods(got, []string{"connect", "xworkmate.artifacts.prepare", "chat.send", "agent.wait", "xworkmate.artifacts.export"}) { t.Fatalf("expected connect, artifact prepare, chat.send, agent.wait, then artifact export, got %#v", got) }