Skip to content

Commit 50333b6

Browse files
fix(docs): include document title in getText and getSuggestions responses
docs.getText and docs.getSuggestions were not returning the document title, unlike slides.getText and sheets.getText which already did. - getText: prepends "Document Title: ..." for single-tab plain text, wraps multi-tab JSON in { title, tabs } object - getSuggestions: returns { title, suggestions } instead of bare array
1 parent 6feba6d commit 50333b6

3 files changed

Lines changed: 31 additions & 20 deletions

File tree

workspace-server/src/__tests__/services/DocsService.comments.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('DocsService Comments and Suggestions', () => {
8484
});
8585

8686
expect(result.content[0].type).toBe('text');
87-
const suggestions = JSON.parse(result.content[0].text);
87+
const { suggestions } = JSON.parse(result.content[0].text);
8888
expect(suggestions).toHaveLength(1);
8989
expect(suggestions[0]).toEqual({
9090
type: 'insertion',
@@ -123,7 +123,7 @@ describe('DocsService Comments and Suggestions', () => {
123123
documentId: 'test-doc-id',
124124
});
125125

126-
const suggestions = JSON.parse(result.content[0].text);
126+
const { suggestions } = JSON.parse(result.content[0].text);
127127
expect(suggestions).toHaveLength(1);
128128
expect(suggestions[0].type).toBe('insertion');
129129
expect(suggestions[0].suggestionIds).toEqual(['sug-1', 'sug-2']);
@@ -157,7 +157,7 @@ describe('DocsService Comments and Suggestions', () => {
157157
documentId: 'test-doc-id',
158158
});
159159

160-
const suggestions = JSON.parse(result.content[0].text);
160+
const { suggestions } = JSON.parse(result.content[0].text);
161161
expect(suggestions).toHaveLength(1);
162162
expect(suggestions[0].type).toBe('deletion');
163163
expect(suggestions[0].text).toBe('deleted text');
@@ -194,7 +194,7 @@ describe('DocsService Comments and Suggestions', () => {
194194
documentId: 'test-doc-id',
195195
});
196196

197-
const suggestions = JSON.parse(result.content[0].text);
197+
const { suggestions } = JSON.parse(result.content[0].text);
198198
expect(suggestions).toHaveLength(1);
199199
expect(suggestions[0].type).toBe('styleChange');
200200
expect(suggestions[0].suggestionIds).toEqual(['style-1']);
@@ -234,7 +234,7 @@ describe('DocsService Comments and Suggestions', () => {
234234
documentId: 'test-doc-id',
235235
});
236236

237-
const suggestions = JSON.parse(result.content[0].text);
237+
const { suggestions } = JSON.parse(result.content[0].text);
238238
expect(suggestions).toHaveLength(1);
239239
expect(suggestions[0].type).toBe('paragraphStyleChange');
240240
expect(suggestions[0].suggestionIds).toEqual(['sug-para-1']);
@@ -284,7 +284,7 @@ describe('DocsService Comments and Suggestions', () => {
284284
documentId: 'test-doc-id',
285285
});
286286

287-
const suggestions = JSON.parse(result.content[0].text);
287+
const { suggestions } = JSON.parse(result.content[0].text);
288288
expect(suggestions).toHaveLength(1);
289289
expect(suggestions[0].type).toBe('insertion');
290290
expect(suggestions[0].text).toBe('cell text');
@@ -299,8 +299,8 @@ describe('DocsService Comments and Suggestions', () => {
299299
documentId: 'test-doc-id',
300300
});
301301

302-
const suggestions = JSON.parse(result.content[0].text);
303-
expect(suggestions).toEqual([]);
302+
const parsed = JSON.parse(result.content[0].text);
303+
expect(parsed.suggestions).toEqual([]);
304304
});
305305

306306
it('should handle API errors gracefully', async () => {
@@ -351,7 +351,7 @@ describe('DocsService Comments and Suggestions', () => {
351351
documentId: 'test-doc-id',
352352
});
353353

354-
const suggestions = JSON.parse(result.content[0].text);
354+
const { suggestions } = JSON.parse(result.content[0].text);
355355
expect(suggestions).toHaveLength(2);
356356
const types = suggestions.map((s: any) => s.type);
357357
expect(types).toEqual(['paragraphStyleChange', 'paragraphStyleChange']);
@@ -391,7 +391,7 @@ describe('DocsService Comments and Suggestions', () => {
391391
documentId: 'test-doc-id',
392392
});
393393

394-
const suggestions = JSON.parse(result.content[0].text);
394+
const { suggestions } = JSON.parse(result.content[0].text);
395395
expect(suggestions).toHaveLength(1);
396396
expect(suggestions[0].text).toBe('');
397397
});

workspace-server/src/__tests__/services/DocsService.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,14 @@ describe('DocsService', () => {
550550
const result = await docsService.getText({ documentId: 'test-doc-id' });
551551
const parsed = JSON.parse(result.content[0].text);
552552

553-
expect(parsed).toHaveLength(2);
554-
expect(parsed[0]).toEqual({
553+
expect(parsed.tabs).toHaveLength(2);
554+
expect(parsed.tabs[0]).toEqual({
555555
tabId: 'tab-1',
556556
title: 'Tab 1',
557557
content: 'Tab 1 Content',
558558
index: 0,
559559
});
560-
expect(parsed[1]).toEqual({
560+
expect(parsed.tabs[1]).toEqual({
561561
tabId: 'tab-2',
562562
title: 'Tab 2',
563563
content: 'Tab 2 Content',
@@ -736,14 +736,14 @@ describe('DocsService', () => {
736736
const result = await docsService.getText({ documentId: 'test-doc-id' });
737737
const parsed = JSON.parse(result.content[0].text);
738738

739-
expect(parsed).toHaveLength(2);
740-
expect(parsed[0]).toEqual({
739+
expect(parsed.tabs).toHaveLength(2);
740+
expect(parsed.tabs[0]).toEqual({
741741
tabId: 'parent-tab',
742742
title: 'Parent',
743743
content: 'Parent Content',
744744
index: 0,
745745
});
746-
expect(parsed[1]).toEqual({
746+
expect(parsed.tabs[1]).toEqual({
747747
tabId: 'child-tab',
748748
title: 'Child',
749749
content: 'Child Content',

workspace-server/src/services/DocsService.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class DocsService {
7575
const res = await docs.documents.get({
7676
documentId: id,
7777
suggestionsViewMode: 'SUGGESTIONS_INLINE',
78-
fields: 'body',
78+
fields: 'title,body',
7979
});
8080

8181
const suggestions: DocsSuggestion[] = this._extractSuggestions(
@@ -90,7 +90,11 @@ export class DocsService {
9090
content: [
9191
{
9292
type: 'text' as const,
93-
text: JSON.stringify(suggestions, null, 2),
93+
text: JSON.stringify(
94+
{ title: res.data.title, suggestions },
95+
null,
96+
2,
97+
),
9498
},
9599
],
96100
};
@@ -539,10 +543,11 @@ export class DocsService {
539543
const docs = await this.getDocsClient();
540544
const res = await docs.documents.get({
541545
documentId: id,
542-
fields: 'tabs', // Request tabs only (body is legacy and mutually exclusive with tabs in mask)
546+
fields: 'title,tabs', // Request title and tabs (body is legacy and mutually exclusive with tabs in mask)
543547
includeTabsContent: true,
544548
});
545549

550+
const docTitle = res.data.title;
546551
const tabs = this._flattenTabs(res.data.tabs || []);
547552

548553
// If tabId is provided, try to find it
@@ -565,6 +570,9 @@ export class DocsService {
565570
}
566571

567572
let text = '';
573+
if (docTitle) {
574+
text += `Document Title: ${docTitle}\n\n`;
575+
}
568576
content.forEach((element) => {
569577
text += this._readStructuralElement(element);
570578
});
@@ -595,6 +603,9 @@ export class DocsService {
595603
if (tabs.length === 1) {
596604
const tab = tabs[0];
597605
let text = '';
606+
if (docTitle) {
607+
text += `Document Title: ${docTitle}\n\n`;
608+
}
598609
if (tab.documentTab?.body?.content) {
599610
tab.documentTab.body.content.forEach((element) => {
600611
text += this._readStructuralElement(element);
@@ -630,7 +641,7 @@ export class DocsService {
630641
content: [
631642
{
632643
type: 'text' as const,
633-
text: JSON.stringify(tabsData, null, 2),
644+
text: JSON.stringify({ title: docTitle, tabs: tabsData }, null, 2),
634645
},
635646
],
636647
};

0 commit comments

Comments
 (0)