openwork icon indicating copy to clipboard operation
openwork copied to clipboard

feat(den-api): convert Office uploads to native Google Docs, and stop advertising an impossible inline base64 limit

Open benjaminshafii opened this issue 4 months ago • 2 comments

Why

Two separate defects, found while trying to get a .docx agreement into Drive as an editable Google Doc.

1. The Drive upload capability cannot produce a Google Doc. POST /v1/capabilities/google-workspace/drive-files built its multipart metadata as { name, parents } with no mimeType, so an uploaded .docx could only ever land as a .docx. There was no path to a native, editable, commentable Google Doc — which is what you actually want for anything that needs redlines.

2. The dataBase64 descriptions instruct an operation that cannot succeed. The schema told agents to "Read the file from the active workspace and base64-encode it" and advertised maxLength: 13981016 (10 MiB).

That 10 MiB ceiling is real server-side but unreachable in practice. I audited every hop and there is no byte limit anywhere in our code:

Hop Cap
execute_capability inputSchema.body none — z.unknown() (mcp/agent.ts:517)
normalizeToolBody → JSON.stringify → app.fetch none (mcp/invoke.ts:29,97,132) — in-process, never crosses a socket
den-api Hono app none — no global bodyLimit
@hono/mcp transport none
uploadDriveFileBodySchema 10 MiB

The actual ceiling is the model's tool-call output budget: the base64 must be emitted by the model as a JSON string argument. A ~137KB payload (a small .docx) truncated mid-generation and arrived as {} — no server error, because the request never became a well-formed tool call. So we were advertising ~100× more headroom than is reachable, and telling agents to walk straight into it.

What changed

  • convertTo (document | spreadsheet | presentation), optional. Sets the metadata mimeType to the target Google editor type while the media part keeps the caller's source mimeType — the documented Drive conversion mechanism. .docx→Doc, .xlsx→Sheet, .pptx→Slides.
  • Omitting convertTo is byte-identical to today (no mimeType key emitted at all). Pinned by the pre-existing test, which asserts the exact metadata JSON {"name":"plan.pdf","parents":["folder_1"]}.
  • Reworded both dataBase64 descriptions to state the practical inline limit and keep 10 MiB labelled as a server ceiling, not a usable one.
  • Updated evals/flows/google-workspace-gmail-draft-attachments.flow.mjs:77, which asserted the old wording verbatim.

No validation limits changed. Change 2 is descriptions only.

Tests

$ pnpm --filter @openwork-ee/den-api exec bun test test/google-workspace-capabilities.test.ts
 31 pass
 0 fail
 188 expect() calls

$ pnpm --filter @openwork-ee/den-api exec tsc --noEmit
(exit 0, no output)

Three new tests: conversion sets the right metadata mimeType and preserves the source media mimeType; invalid convertTo 400s without calling Google; the existing omission test is unchanged and still passes.

Validation honesty

Per AGENTS.md: there is no live Drive proof in this PR, and I want to be explicit about that. Verifying an actual .docx→Google Doc conversion requires a connected Google Workspace account hitting real Drive, against a deployed den-api carrying this change. I ran the unit suite against the fake Google, which asserts the exact multipart bytes we send — that proves we send the documented conversion request, not that Google converts it.

Reviewer check: upload a .docx with convertTo: "document" and confirm file.mimeType comes back as application/vnd.google-apps.document and webViewLink opens in the Docs editor.

Deliberately not in this PR

  • Path- or URL-based upload. This is the real fix for defect 2 — bytes should never transit model context. The correct pattern already exists at apps/server/src/extensions/google-workspace.ts:91-104 (takes attachments: [{ path }], server reads the bytes at :759), but it has no Drive equivalent and is gated off for Cloud users (extensions/index.ts:61-72). Closing that gap spans apps/server↔den-api auth, or needs server-side URL fetching with real SSRF hardening. That's a design decision, not a patch.
  • packages/docs/openapi.json. It is already stale on dev. Regenerating it pulls in ~230 unrelated keys (cloud gateway routes, /v1/org.delete, install-connect, marketplace-capabilities) and 7 unrelated description edits. That belongs in its own chore PR. The runtime path reads live-generated OpenAPI (mcp/catalog.ts), so this change takes effect regardless.
  • The same trap in reverse. gmail-attachment returns up to 10 MiB of base64 into model context (google-workspace.ts:553) and will fail the same way on large attachments.

benjaminshafii avatar Jul 30 '26 06:07 benjaminshafii

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview Jul 30, 2026 6:13am
openwork-den Ready Ready Preview Jul 30, 2026 6:13am
openwork-den-worker-proxy Ready Ready Preview Jul 30, 2026 6:13am
openwork-diagnostics Ready Ready Preview Jul 30, 2026 6:13am
openwork-landing Ready Ready Preview, v0 Jul 30, 2026 6:13am

vercel[bot] avatar Jul 30 '26 06:07 vercel[bot]

Thanks for digging into this and for identifying the base64/tool-call limitation. My product preference is that OpenWork preserve users’ files exactly as supplied rather than converting Office files on their behalf—or allowing the agent to choose a conversion implicitly. If someone uploads a .docx, .xlsx, or .pptx, we should keep the original bytes, filename, and MIME type; if they want a native Google Doc, Sheet, or Slides file, they can make that conversion explicitly in Google Drive.

I’m addressing the underlying upload/download transport separately with a byte-outside-model architecture: scoped, expiring file references; multipart Google Drive uploads for small files; resumable uploads for larger files; and download materialization without returning file bytes through model context.

Given that direction, I recommend that we do not merge the convertTo behavior from this PR. The investigation and corrected guidance around the impractical inline-base64 limit are valuable, and I’ll carry that finding into the parallel transport fix.

reachjalil avatar Jul 30 '26 13:07 reachjalil