Skip to content

Commit 60fde47

Browse files
committed
fix(google): tighten Docs tab/number parsing, normalize Slides soft breaks, reuse jsonResponse helper
1 parent ce6536b commit 60fde47

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

‎apps/sim/tools/google_docs/utils.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export function resolveDocumentId(params: {
2222
* request targets the document's first tab, matching the API default.
2323
*/
2424
export function resolveTabId(tabId: unknown): string | undefined {
25-
if (typeof tabId !== 'string') return undefined
25+
if (tabId === undefined || tabId === null) return undefined
26+
if (typeof tabId !== 'string') throw new Error('Tab ID must be a string')
2627
const trimmed = tabId.trim()
2728
return trimmed || undefined
2829
}
@@ -32,7 +33,8 @@ export function resolveTabId(tabId: unknown): string | undefined {
3233
* string (agent tool-calls). Returns `undefined` when absent or not finite.
3334
*/
3435
export function parseOptionalNumber(value: unknown): number | undefined {
35-
if (value === undefined || value === null || value === '') return undefined
36+
if (value === undefined || value === null) return undefined
37+
if (typeof value === 'string' && value.trim() === '') return undefined
3638
const parsed = Number(value)
3739
return Number.isFinite(parsed) ? parsed : undefined
3840
}

‎apps/sim/tools/google_drive/get_content.test.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { jsonResponse } from '@sim/testing/helpers/http'
12
import { beforeEach, describe, expect, it, vi } from 'vitest'
23
import { getContentTool } from '@/tools/google_drive/get_content'
34
import { MAX_EXPORT_BYTES } from '@/tools/google_drive/utils'
@@ -6,10 +7,6 @@ const transform = getContentTool.transformResponse as NonNullable<
67
typeof getContentTool.transformResponse
78
>
89

9-
function metadataResponse(metadata: Record<string, unknown>): Response {
10-
return new Response(JSON.stringify(metadata), { status: 200 })
11-
}
12-
1310
function streamOf(totalBytes: number, chunkBytes = 1024 * 1024): ReadableStream<Uint8Array> {
1411
let sent = 0
1512
return new ReadableStream({
@@ -36,7 +33,7 @@ describe('google_drive_get_content byte limits', () => {
3633
it('refuses a binary file whose declared size exceeds the download cap before fetching it', async () => {
3734
await expect(
3835
transform(
39-
metadataResponse({
36+
jsonResponse({
4037
id: 'file-1',
4138
name: 'huge.bin',
4239
mimeType: 'application/octet-stream',
@@ -56,7 +53,7 @@ describe('google_drive_get_content byte limits', () => {
5653

5754
await expect(
5855
transform(
59-
metadataResponse({
56+
jsonResponse({
6057
id: 'doc-1',
6158
name: 'Doc',
6259
mimeType: 'application/vnd.google-apps.document',

‎apps/sim/tools/google_slides/utils.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ export function authJsonHeaders(accessToken: string) {
135135
*/
136136
export function slidesPresentationUrl(
137137
presentationId: string | undefined,
138-
pageObjectId?: string,
138+
pageObjectId?: string | number,
139139
suffix = ''
140140
): string {
141141
const id = presentationId?.trim()
142142
if (!id) throw new Error('Presentation ID is required')
143143
const base = `https://slides.googleapis.com/v1/presentations/${safeUrlPathSegment(id, 'presentationId')}`
144144
if (pageObjectId === undefined) return `${base}${suffix}`
145-
const pageId = pageObjectId.trim()
145+
const pageId = String(pageObjectId).trim()
146146
if (!pageId) throw new Error('Page Object ID is required')
147147
return `${base}/pages/${safeUrlPathSegment(pageId, 'pageObjectId')}${suffix}`
148148
}
@@ -177,6 +177,7 @@ function textContentToString(text: SlidesTextContent | undefined): string {
177177
return elements
178178
.map((element) => element.textRun?.content ?? element.autoText?.content ?? '')
179179
.join('')
180+
.replace(/\v/g, '\n')
180181
}
181182

182183
function pageElementText(element: SlidesPageElement): string[] {

0 commit comments

Comments
 (0)