-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Issue: Native Format Generation for Workspace Services
Background
Currently, the extension assumes the model outputs Markdown for all services. We then convert this Markdown to the target format on the client side:
- Gmail: Model outputs Markdown ->
marked(presumably) -> HTML (or just raw Markdown sent as text). - Docs: Model outputs Markdown ->
marked-> HTML ->JSDOM->docs.batchUpdaterequests. - Chat: Model outputs Markdown -> Sent as text (Chat supports a subset of Markdown).
Objective
Remove the intermediate Markdown translation layer and instruct the model to generate the specific allowed format for each service directly. This reduces complexity, improves reliability, and allows for better formatting control (e.g., tables in Gmail, specific highlighting in Docs).
Research Findings
- Gmail API: Supports HTML bodies. Best practices include using inline CSS and standard tags (
b,i,a,table,ul,ol, etc.). Scripts and external stylesheets are not supported. - Google Chat API: Text messages support a specific subset of Markdown (
*bold*,_italic_,~strike~,`code`,```codeblock```, links, user mentions). It does not support general HTML or standard Markdown tables. - Google Docs API: Does not support inserting HTML directly. It requires
batchUpdaterequests. However, we can instruct the model to output an "HTML subset" (tags likeb,i,h1-6,p,code,a) that we parse directly into API requests, skipping the Markdown conversion step.
Technical Plan
1. New Architecture & Directory Structure
To adhere to DRY principles and Separation of Concerns, we will introduce a new directory src/utils/formatting/ to centralize formatting logic and instructions.
2. Format Instructions (src/utils/formatting/constants.ts)
We will create a constants file to define the exact formatting rules for each service. These constants will be used to:
- Instruct the Model: Appended to tool descriptions in
src/index.ts. - Validate/Parse Input: Used by the service logic where applicable.
DOCS_FORMAT_INSTRUCTIONS: "Provide content in HTML format using supported tags:<h1>to<h6>for headings,<p>for paragraphs,<b>or<strong>for bold,<i>or<em>for italics,<a>for links, and<code>for formatted code."GMAIL_FORMAT_INSTRUCTIONS: "Format the body as HTML. Use inline CSS for styling. Supported tags includeb,i,a,ul,ol,li,table,tr,td, etc."CHAT_FORMAT_INSTRUCTIONS: "Use the following Markdown syntax only:*bold*,_italic_,~strikethrough~,`inline code`,code block. Standard Markdown tables and headers are NOT supported."
3. Refactor Google Docs Parsing
- New Parser: Create
src/utils/formatting/HtmlToDocsParser.ts.- Responsibility: Convert an HTML string directly into
docs_v1.Schema$Request[]. - Logic: Use
JSDOMto traverse the HTML (similar to the currentmarkdownToDocsRequests.tsbut without themarkedstep) and map elements toinsertTextandupdateTextStyle/updateParagraphStylerequests.
- Responsibility: Convert an HTML string directly into
- DocsService: Update
create,insertText,appendText, andreplaceTextto accept HTML directly and useHtmlToDocsParser. - Cleanup: Delete
markdownToDocsRequests.tsand remove themarkeddependency from the project.
4. Update Gmail & Chat Services
- Gmail: Ensure
GmailServicemethods (send, createDraft) pass thebodydirectly as HTML whenisHtmlis true. - Chat: No code changes needed for message formatting, but we must ensure the tool descriptions in
src/index.tsinclude theCHAT_FORMAT_INSTRUCTIONSto prevent the model from generating unsupported Markdown.
Tasks
- Create
src/utils/formatting/constants.tswith format instructions. - Create
src/utils/formatting/HtmlToDocsParser.ts(refactoringmarkdownToDocsRequests.ts). - Update
src/index.tsto append format instructions to tool descriptions. - Update
DocsServiceto useHtmlToDocsParser. - Update
GmailService/ChatServicetool descriptions insrc/index.ts. - Delete
markdownToDocsRequests.ts. - Remove
markeddependency.
Metadata
Metadata
Assignees
Labels
No labels