Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/content/docs/integrations/google_maps.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Get solar potential and panel insights for the building nearest a location
| `apiKey` | string | Yes | Google Maps API key with Solar API enabled |
| `lat` | number | Yes | Latitude coordinate |
| `lng` | number | Yes | Longitude coordinate |
| `requiredQuality` | string | No | Minimum imagery quality to accept \(HIGH, MEDIUM, or BASE\) |
| `requiredQuality` | string | No | Minimum imagery quality to accept \(HIGH, MEDIUM, LOW, or BASE\) |

#### Output

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/integrations/google_translate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Translate text between languages using the Google Cloud Translation API. Support
| `text` | string | Yes | The text to translate |
| `target` | string | Yes | Target language code \(e.g., "es", "fr", "de", "ja"\) |
| `source` | string | No | Source language code. If omitted, the API will auto-detect the source language. |
| `format` | string | No | Format of the text: "text" for plain text, "html" for HTML content |
| `format` | string | No | Format of the text: "text" for plain text, "html" for HTML content. Defaults to "html", which returns characters such as apostrophes as HTML entities |

#### Output

Expand Down
16 changes: 16 additions & 0 deletions apps/sim/blocks/blocks/google_maps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ describe('GoogleMapsBlock agent tool calls', () => {
expect({ ...inputs, ...mapped }).toMatchObject(inputs)
})
})

/**
* Every operation's coordinate fields serialize with the block, so a value left in another
* operation's latitude/longitude must not replace the coordinates of the selected operation.
*/
describe('GoogleMapsBlock coordinate fields', () => {
const stored = { latitude: '40.7128', longitude: '-74.006', aqLatitude: '1', aqLongitude: '2' }

it.each([
['reverse_geocode', { lat: 40.7128, lng: -74.006 }],
['air_quality', { lat: 1, lng: 2 }],
])('sends the %s coordinates when the other fields hold stale values', (operation, expected) => {
const mapped = GoogleMapsBlock.tools.config?.params?.({ operation, ...stored })
expect(mapped).toMatchObject(expected)
})
})
34 changes: 14 additions & 20 deletions apps/sim/blocks/blocks/google_maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { mapperOperation, toolCallArg } from '@/blocks/utils'

/** Operations whose coordinates come from the `aqLatitude`/`aqLongitude` fields. */
const AQ_COORDINATE_OPERATIONS = ['air_quality', 'pollen', 'solar', 'places_nearby']

export const GoogleMapsBlock: BlockConfig = {
type: 'google_maps',
name: 'Google Maps',
Expand Down Expand Up @@ -483,16 +486,16 @@ export const GoogleMapsBlock: BlockConfig = {
title: 'Latitude',
type: 'short-input',
placeholder: '37.4224764',
condition: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
required: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
condition: { field: 'operation', value: AQ_COORDINATE_OPERATIONS },
required: { field: 'operation', value: AQ_COORDINATE_OPERATIONS },
},
{
id: 'aqLongitude',
title: 'Longitude',
type: 'short-input',
placeholder: '-122.0842499',
condition: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
required: { field: 'operation', value: ['air_quality', 'pollen', 'solar', 'places_nearby'] },
condition: { field: 'operation', value: AQ_COORDINATE_OPERATIONS },
required: { field: 'operation', value: AQ_COORDINATE_OPERATIONS },
},
{
id: 'languageCode',
Expand Down Expand Up @@ -524,9 +527,10 @@ export const GoogleMapsBlock: BlockConfig = {
title: 'Minimum Imagery Quality',
type: 'dropdown',
options: [
{ label: 'Any', id: '' },
{ label: 'Default (High only)', id: '' },
{ label: 'High', id: 'HIGH' },
{ label: 'Medium', id: 'MEDIUM' },
{ label: 'Low', id: 'LOW' },
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
{ label: 'Base', id: 'BASE' },
],
condition: { field: 'operation', value: 'solar' },
Expand Down Expand Up @@ -595,21 +599,11 @@ export const GoogleMapsBlock: BlockConfig = {
}
}

let lat: number | undefined
let lng: number | undefined
if (params.latitude) {
lat = Number.parseFloat(params.latitude)
}
if (params.longitude) {
lng = Number.parseFloat(params.longitude)
}

if (params.aqLatitude) {
lat = Number.parseFloat(params.aqLatitude)
}
if (params.aqLongitude) {
lng = Number.parseFloat(params.aqLongitude)
}
const usesAqCoordinates = AQ_COORDINATE_OPERATIONS.includes(operation)
const latInput = usesAqCoordinates ? params.aqLatitude : params.latitude
const lngInput = usesAqCoordinates ? params.aqLongitude : params.longitude
const lat = latInput ? Number.parseFloat(latInput) : undefined
const lng = lngInput ? Number.parseFloat(lngInput) : undefined

let timestamp: number | undefined
if (params.timestamp) {
Expand Down
14 changes: 14 additions & 0 deletions apps/sim/blocks/blocks/google_translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ export const GoogleTranslateBlock: BlockConfig = {
options: [{ label: 'Auto-detect', id: '' }, ...SUPPORTED_LANGUAGES],
value: () => '',
},
{
id: 'format',
title: 'Text Format',
type: 'dropdown',
condition: { field: 'operation', value: 'text' },
options: [
{ label: 'Default (HTML)', id: '' },
{ label: 'Plain text', id: 'text' },
{ label: 'HTML', id: 'html' },
],
value: () => '',
mode: 'advanced',
},
{
id: 'apiKey',
title: 'API Key',
Expand All @@ -219,6 +232,7 @@ export const GoogleTranslateBlock: BlockConfig = {
text: { type: 'string', description: 'Text to translate or detect language of' },
target: { type: 'string', description: 'Target language code' },
source: { type: 'string', description: 'Source language code (optional, auto-detected)' },
format: { type: 'string', description: 'Text format: text (plain) or html (default)' },
apiKey: { type: 'string', description: 'Google Cloud API key' },
},
outputs: {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/tools/generated/tool-metadata.ts

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions apps/sim/tools/google_appsheet/add_rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type {
GoogleAppsheetAddParams,
GoogleAppsheetAddResponse,
} from '@/tools/google_appsheet/types'
import { buildAppsheetActionUrl, readAppsheetResponseBody } from '@/tools/google_appsheet/utils'
import {
appsheetResponseRows,
buildAppsheetActionUrl,
readAppsheetResponseBody,
} from '@/tools/google_appsheet/utils'
import type { ToolConfig } from '@/tools/types'

export const googleAppsheetAddRowsTool: ToolConfig<
Expand Down Expand Up @@ -70,7 +74,7 @@ export const googleAppsheetAddRowsTool: ToolConfig<
throw new Error(data.error?.message || data.message || 'Failed to add AppSheet rows')
}

const rows = data.Rows ?? data.rows ?? []
const rows = appsheetResponseRows(data)

return {
success: true,
Expand Down
8 changes: 6 additions & 2 deletions apps/sim/tools/google_appsheet/delete_rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type {
GoogleAppsheetDeleteParams,
GoogleAppsheetDeleteResponse,
} from '@/tools/google_appsheet/types'
import { buildAppsheetActionUrl, readAppsheetResponseBody } from '@/tools/google_appsheet/utils'
import {
appsheetResponseRows,
buildAppsheetActionUrl,
readAppsheetResponseBody,
} from '@/tools/google_appsheet/utils'
import type { ToolConfig } from '@/tools/types'

export const googleAppsheetDeleteRowsTool: ToolConfig<
Expand Down Expand Up @@ -70,7 +74,7 @@ export const googleAppsheetDeleteRowsTool: ToolConfig<
throw new Error(data.error?.message || data.message || 'Failed to delete AppSheet rows')
}

const rows = data.Rows ?? data.rows ?? []
const rows = appsheetResponseRows(data)

return {
success: true,
Expand Down
8 changes: 6 additions & 2 deletions apps/sim/tools/google_appsheet/edit_rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type {
GoogleAppsheetEditParams,
GoogleAppsheetEditResponse,
} from '@/tools/google_appsheet/types'
import { buildAppsheetActionUrl, readAppsheetResponseBody } from '@/tools/google_appsheet/utils'
import {
appsheetResponseRows,
buildAppsheetActionUrl,
readAppsheetResponseBody,
} from '@/tools/google_appsheet/utils'
import type { ToolConfig } from '@/tools/types'

export const googleAppsheetEditRowsTool: ToolConfig<
Expand Down Expand Up @@ -70,7 +74,7 @@ export const googleAppsheetEditRowsTool: ToolConfig<
throw new Error(data.error?.message || data.message || 'Failed to edit AppSheet rows')
}

const rows = data.Rows ?? data.rows ?? []
const rows = appsheetResponseRows(data)

return {
success: true,
Expand Down
8 changes: 6 additions & 2 deletions apps/sim/tools/google_appsheet/find_rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type {
GoogleAppsheetFindParams,
GoogleAppsheetFindResponse,
} from '@/tools/google_appsheet/types'
import { buildAppsheetActionUrl, readAppsheetResponseBody } from '@/tools/google_appsheet/utils'
import {
appsheetResponseRows,
buildAppsheetActionUrl,
readAppsheetResponseBody,
} from '@/tools/google_appsheet/utils'
import type { ToolConfig } from '@/tools/types'

export const googleAppsheetFindRowsTool: ToolConfig<
Expand Down Expand Up @@ -70,7 +74,7 @@ export const googleAppsheetFindRowsTool: ToolConfig<
throw new Error(data.error?.message || data.message || 'Failed to find AppSheet rows')
}

const rows = data.Rows ?? data.rows ?? []
const rows = appsheetResponseRows(data)

return {
success: true,
Expand Down
12 changes: 11 additions & 1 deletion apps/sim/tools/google_appsheet/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { describe, expect, it } from 'vitest'
import { buildAppsheetActionUrl, readAppsheetResponseBody } from '@/tools/google_appsheet/utils'
import {
appsheetResponseRows,
buildAppsheetActionUrl,
readAppsheetResponseBody,
} from '@/tools/google_appsheet/utils'

describe('buildAppsheetActionUrl', () => {
it('defaults to the global www region when unset', () => {
Expand Down Expand Up @@ -45,3 +49,9 @@ describe('readAppsheetResponseBody', () => {
})
})
})

describe('appsheetResponseRows', () => {
it('reads a bare row array body as the rows instead of an empty result', () => {
expect(appsheetResponseRows([{ id: '1' }, { id: '2' }])).toEqual([{ id: '1' }, { id: '2' }])
})
})
14 changes: 14 additions & 0 deletions apps/sim/tools/google_appsheet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ export async function readAppsheetResponseBody(response: Response): Promise<Reco
return { message: text }
}
}

/**
* The rows in an AppSheet Action response. The docs show `{ "Rows": [...] }`, but a body that is
* the bare row array is accepted too rather than read as an empty result.
*/
export function appsheetResponseRows(body: unknown): Record<string, unknown>[] {
if (Array.isArray(body)) return body
if (body && typeof body === 'object') {
const { Rows, rows } = body as { Rows?: unknown; rows?: unknown }
if (Array.isArray(Rows)) return Rows
if (Array.isArray(rows)) return rows
}
return []
}
5 changes: 3 additions & 2 deletions apps/sim/tools/google_bigquery/create_dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
GoogleBigQueryCreateDatasetResponse,
} from '@/tools/google_bigquery/types'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

export const googleBigQueryCreateDatasetTool: ToolConfig<
GoogleBigQueryCreateDatasetParams,
Expand Down Expand Up @@ -59,7 +60,7 @@ export const googleBigQueryCreateDatasetTool: ToolConfig<

request: {
url: (params) =>
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets`,
`https://bigquery.googleapis.com/bigquery/v2/projects/${safeUrlPathSegment(params.projectId, 'projectId')}/datasets`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand All @@ -68,7 +69,7 @@ export const googleBigQueryCreateDatasetTool: ToolConfig<
body: (params) => {
const body: Record<string, unknown> = {
datasetReference: {
projectId: params.projectId,
projectId: String(params.projectId).trim(),
datasetId: params.datasetId.trim(),
},
}
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/tools/google_bigquery/create_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
GoogleBigQueryCreateTableResponse,
} from '@/tools/google_bigquery/types'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

export const googleBigQueryCreateTableTool: ToolConfig<
GoogleBigQueryCreateTableParams,
Expand Down Expand Up @@ -66,7 +67,7 @@ export const googleBigQueryCreateTableTool: ToolConfig<

request: {
url: (params) =>
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets/${encodeURIComponent(params.datasetId.trim())}/tables`,
`https://bigquery.googleapis.com/bigquery/v2/projects/${safeUrlPathSegment(params.projectId, 'projectId')}/datasets/${safeUrlPathSegment(params.datasetId, 'datasetId')}/tables`,
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand All @@ -93,7 +94,7 @@ export const googleBigQueryCreateTableTool: ToolConfig<

const body: Record<string, unknown> = {
tableReference: {
projectId: params.projectId,
projectId: String(params.projectId).trim(),
datasetId: params.datasetId.trim(),
tableId: params.tableId.trim(),
},
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/google_bigquery/delete_dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
GoogleBigQueryDeleteDatasetResponse,
} from '@/tools/google_bigquery/types'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

export const googleBigQueryDeleteDatasetTool: ToolConfig<
GoogleBigQueryDeleteDatasetParams,
Expand Down Expand Up @@ -48,7 +49,7 @@ export const googleBigQueryDeleteDatasetTool: ToolConfig<
request: {
url: (params) => {
const url = new URL(
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets/${encodeURIComponent(params.datasetId.trim())}`
`https://bigquery.googleapis.com/bigquery/v2/projects/${safeUrlPathSegment(params.projectId, 'projectId')}/datasets/${safeUrlPathSegment(params.datasetId, 'datasetId')}`
)
if (params.deleteContents !== undefined) {
url.searchParams.set('deleteContents', String(params.deleteContents))
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/google_bigquery/delete_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
GoogleBigQueryDeleteTableResponse,
} from '@/tools/google_bigquery/types'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

export const googleBigQueryDeleteTableTool: ToolConfig<
GoogleBigQueryDeleteTableParams,
Expand Down Expand Up @@ -47,7 +48,7 @@ export const googleBigQueryDeleteTableTool: ToolConfig<

request: {
url: (params) =>
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets/${encodeURIComponent(params.datasetId.trim())}/tables/${encodeURIComponent(params.tableId.trim())}`,
`https://bigquery.googleapis.com/bigquery/v2/projects/${safeUrlPathSegment(params.projectId, 'projectId')}/datasets/${safeUrlPathSegment(params.datasetId, 'datasetId')}/tables/${safeUrlPathSegment(params.tableId, 'tableId')}`,
method: 'DELETE',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/google_bigquery/get_query_results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
GoogleBigQueryGetQueryResultsResponse,
} from '@/tools/google_bigquery/types'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

export const googleBigQueryGetQueryResultsTool: ToolConfig<
GoogleBigQueryGetQueryResultsParams,
Expand Down Expand Up @@ -73,7 +74,7 @@ export const googleBigQueryGetQueryResultsTool: ToolConfig<
request: {
url: (params) => {
const url = new URL(
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/queries/${encodeURIComponent(params.jobId.trim())}`
`https://bigquery.googleapis.com/bigquery/v2/projects/${safeUrlPathSegment(params.projectId, 'projectId')}/queries/${safeUrlPathSegment(params.jobId, 'jobId')}`
)
if (params.pageToken) url.searchParams.set('pageToken', params.pageToken)
if (params.maxResults !== undefined && params.maxResults !== null) {
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/google_bigquery/get_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
GoogleBigQueryGetTableResponse,
} from '@/tools/google_bigquery/types'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

export const googleBigQueryGetTableTool: ToolConfig<
GoogleBigQueryGetTableParams,
Expand Down Expand Up @@ -47,7 +48,7 @@ export const googleBigQueryGetTableTool: ToolConfig<

request: {
url: (params) =>
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets/${encodeURIComponent(params.datasetId)}/tables/${encodeURIComponent(params.tableId)}`,
`https://bigquery.googleapis.com/bigquery/v2/projects/${safeUrlPathSegment(params.projectId, 'projectId')}/datasets/${safeUrlPathSegment(params.datasetId, 'datasetId')}/tables/${safeUrlPathSegment(params.tableId, 'tableId')}`,
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
method: 'GET',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/google_bigquery/insert_rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
GoogleBigQueryInsertRowsResponse,
} from '@/tools/google_bigquery/types'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

export const googleBigQueryInsertRowsTool: ToolConfig<
GoogleBigQueryInsertRowsParams,
Expand Down Expand Up @@ -65,7 +66,7 @@ export const googleBigQueryInsertRowsTool: ToolConfig<

request: {
url: (params) =>
`https://bigquery.googleapis.com/bigquery/v2/projects/${encodeURIComponent(params.projectId)}/datasets/${encodeURIComponent(params.datasetId)}/tables/${encodeURIComponent(params.tableId)}/insertAll`,
`https://bigquery.googleapis.com/bigquery/v2/projects/${safeUrlPathSegment(params.projectId, 'projectId')}/datasets/${safeUrlPathSegment(params.datasetId, 'datasetId')}/tables/${safeUrlPathSegment(params.tableId, 'tableId')}/insertAll`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.accessToken}`,
Expand Down
Loading
Loading