Skip to content

Commit 4f69749

Browse files
committed
fix(google_docs): harden multipart boundary handoff and align postProcess guard
1 parent 449d8b2 commit 4f69749

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

apps/sim/tools/google_docs/create.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,16 @@ export const createTool: ToolConfig<GoogleDocsToolParams, GoogleDocsCreateRespon
125125
}
126126

127127
if (shouldUseMarkdownUpload(params)) {
128-
const boundary =
129-
(params as GoogleDocsToolParams & { _boundary?: string })._boundary ??
130-
`sim_gdocs_md_${generateShortId(24)}`
128+
const boundary = (params as GoogleDocsToolParams & { _boundary?: string })._boundary
129+
if (!boundary) {
130+
// headers() runs before body() in formatRequestParams and stashes the boundary
131+
// on the same params reference. Missing _boundary means that contract was broken,
132+
// which would silently produce a Content-Type / body boundary mismatch (HTTP 400).
133+
// Throw loudly instead of fabricating a mismatched boundary.
134+
throw new Error(
135+
'Multipart boundary missing on params — headers() must run before body() for markdown upload'
136+
)
137+
}
131138
return buildMarkdownMultipartBody(metadata, params.content ?? '', boundary)
132139
}
133140

@@ -142,9 +149,9 @@ export const createTool: ToolConfig<GoogleDocsToolParams, GoogleDocsCreateRespon
142149

143150
const documentId = result.output.metadata.documentId
144151

145-
// When markdown=true, content was already inserted via Drive's text/markdown
146-
// import conversion during files.create — no follow-up write needed.
147-
if (params.markdown) {
152+
// When the markdown upload path ran, content was already inserted via Drive's
153+
// text/markdown import conversion during files.create — no follow-up write needed.
154+
if (shouldUseMarkdownUpload(params)) {
148155
return result
149156
}
150157

0 commit comments

Comments
 (0)