Skip to content

Commit df1fabc

Browse files
committed
feat(sheets): added sheet selector for microsoft excel and google sheets tools
1 parent d4c171c commit df1fabc

File tree

28 files changed

+2208
-136
lines changed

28 files changed

+2208
-136
lines changed

apps/docs/components/ui/icon-mapping.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
163163
google_forms: GoogleFormsIcon,
164164
google_groups: GoogleGroupsIcon,
165165
google_search: GoogleIcon,
166-
google_sheets: GoogleSheetsIcon,
166+
google_sheets_v2: GoogleSheetsIcon,
167167
google_slides: GoogleSlidesIcon,
168168
google_vault: GoogleVaultIcon,
169169
grafana: GrafanaIcon,
@@ -190,7 +190,7 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
190190
mailgun: MailgunIcon,
191191
mem0: Mem0Icon,
192192
memory: BrainIcon,
193-
microsoft_excel: MicrosoftExcelIcon,
193+
microsoft_excel_v2: MicrosoftExcelIcon,
194194
microsoft_planner: MicrosoftPlannerIcon,
195195
microsoft_teams: MicrosoftTeamsIcon,
196196
mistral_parse: MistralIcon,

apps/docs/content/docs/en/tools/google_sheets.mdx

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,18 @@
11
---
22
title: Google Sheets
3-
description: Read, write, and update data
3+
description: Read, write, and update data with sheet selection
44
---
55

66
import { BlockInfoCard } from "@/components/ui/block-info-card"
77

88
<BlockInfoCard
9-
type="google_sheets"
9+
type="google_sheets_v2"
1010
color="#E0E0E0"
1111
/>
1212

13-
{/* MANUAL-CONTENT-START:intro */}
14-
[Google Sheets](https://sheets.google.com) is a powerful cloud-based spreadsheet application that allows users to create, edit, and collaborate on spreadsheets in real-time. As part of Google's productivity suite, Google Sheets offers a versatile platform for data organization, analysis, and visualization with robust formatting, formula, and sharing capabilities.
15-
16-
Learn how to integrate the Google Sheets "Read" tool in Sim to effortlessly fetch data from your spreadsheets to integrate into your workflows. This tutorial walks you through connecting Google Sheets, setting up data reads, and using that information to automate processes in real-time. Perfect for syncing live data with your agents.
17-
18-
<iframe
19-
width="100%"
20-
height="400"
21-
src="https://www.youtube.com/embed/xxP7MZRuq_0"
22-
title="Use the Google Sheets Read tool in Sim"
23-
frameBorder="0"
24-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
25-
allowFullScreen
26-
></iframe>
27-
28-
Discover how to use the Google Sheets "Write" tool in Sim to automatically send data from your workflows to your Google Sheets. This tutorial covers setting up the integration, configuring write operations, and updating your sheets seamlessly as workflows execute. Perfect for maintaining real-time records without manual input.
29-
30-
<iframe
31-
width="100%"
32-
height="400"
33-
src="https://www.youtube.com/embed/cO86qTj7qeY"
34-
title="Use the Google Sheets Write tool in Sim"
35-
frameBorder="0"
36-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
37-
allowFullScreen
38-
></iframe>
39-
40-
Explore how to leverage the Google Sheets "Update" tool in Sim to modify existing entries in your spreadsheets based on workflow execution. This tutorial demonstrates setting up the update logic, mapping data fields, and synchronizing changes instantly. Perfect for keeping your data current and consistent.
41-
42-
<iframe
43-
width="100%"
44-
height="400"
45-
src="https://www.youtube.com/embed/95by2fL9yn4"
46-
title="Use the Google Sheets Update tool in Sim"
47-
frameBorder="0"
48-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
49-
allowFullScreen
50-
></iframe>
51-
52-
Learn how to use the Google Sheets "Append" tool in Sim to effortlessly add new rows of data to your spreadsheets during workflow execution. This tutorial walks you through setting up the integration, configuring append actions, and ensuring smooth data growth. Perfect for expanding records without manual effort!
53-
54-
<iframe
55-
width="100%"
56-
height="400"
57-
src="https://www.youtube.com/embed/8DgNvLBCsAo"
58-
title="Use the Google Sheets Append tool in Sim"
59-
frameBorder="0"
60-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
61-
allowFullScreen
62-
></iframe>
63-
64-
With Google Sheets, you can:
65-
66-
- **Create and edit spreadsheets**: Develop data-driven documents with comprehensive formatting and calculation options
67-
- **Collaborate in real-time**: Work simultaneously with multiple users on the same spreadsheet
68-
- **Analyze data**: Use formulas, functions, and pivot tables to process and understand your data
69-
- **Visualize information**: Create charts, graphs, and conditional formatting to represent data visually
70-
- **Access anywhere**: Use Google Sheets across devices with automatic cloud synchronization
71-
- **Work offline**: Continue working without internet connection with changes syncing when back online
72-
- **Integrate with other services**: Connect with Google Drive, Forms, and third-party applications
73-
74-
In Sim, the Google Sheets integration enables your agents to interact directly with spreadsheet data programmatically. This allows for powerful automation scenarios such as data extraction, analysis, reporting, and management. Your agents can read existing spreadsheets to extract information, write to spreadsheets to update data, and create new spreadsheets from scratch. This integration bridges the gap between your AI workflows and data management, enabling seamless interaction with structured data. By connecting Sim with Google Sheets, you can automate data workflows, generate reports, extract insights from data, and maintain up-to-date information - all through your intelligent agents. The integration supports various data formats and range specifications, making it flexible enough to handle diverse data management needs while maintaining the collaborative and accessible nature of Google Sheets.
75-
{/* MANUAL-CONTENT-END */}
76-
77-
7813
## Usage Instructions
7914

80-
Integrate Google Sheets into the workflow. Can read, write, append, and update data.
15+
Integrate Google Sheets into the workflow with explicit sheet selection. Can read, write, append, and update data in specific sheets.
8116

8217

8318

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
---
22
title: Microsoft Excel
3-
description: Read, write, and update data
3+
description: Read and write data with sheet selection
44
---
55

66
import { BlockInfoCard } from "@/components/ui/block-info-card"
77

88
<BlockInfoCard
9-
type="microsoft_excel"
9+
type="microsoft_excel_v2"
1010
color="#E0E0E0"
1111
/>
1212

13-
{/* MANUAL-CONTENT-START:intro */}
14-
[Microsoft Teams](https://www.microsoft.com/en-us/microsoft-365/excel) is a powerful spreadsheet application that enables data management, analysis, and visualization. Through the Microsoft Excel integration in Sim, you can programmatically read, write, and manipulate spreadsheet data to support your workflow automation needs.
15-
16-
With Microsoft Excel integration, you can:
17-
18-
- **Read Spreadsheet Data**: Access data from specific ranges, sheets, and cells
19-
- **Write and Update Data**: Add new data or modify existing spreadsheet content
20-
- **Manage Tables**: Create and manipulate tabular data structures
21-
- **Handle Multiple Sheets**: Work with multiple worksheets in a workbook
22-
- **Process Data**: Import, export, and transform spreadsheet data
23-
24-
In Sim, the Microsoft Excel integration provides seamless access to spreadsheet functionality through OAuth authentication. You can read data from specific ranges, write new information, update existing cells, and handle various data formats. The integration supports both reading and writing operations with flexible input and output options. This enables you to build workflows that can effectively manage spreadsheet data, whether you're extracting information for analysis, updating records automatically, or maintaining data consistency across your applications.
25-
{/* MANUAL-CONTENT-END */}
26-
27-
2813
## Usage Instructions
2914

30-
Integrate Microsoft Excel into the workflow. Can read, write, update, add to table, and create new worksheets.
15+
Integrate Microsoft Excel into the workflow with explicit sheet selection. Can read and write data in specific sheets.
3116

3217

3318

@@ -81,50 +66,4 @@ Write data to a Microsoft Excel spreadsheet
8166
|`spreadsheetId` | string | The ID of the spreadsheet |
8267
|`spreadsheetUrl` | string | URL to access the spreadsheet |
8368

84-
### `microsoft_excel_table_add`
85-
86-
Add new rows to a Microsoft Excel table
87-
88-
#### Input
89-
90-
| Parameter | Type | Required | Description |
91-
| --------- | ---- | -------- | ----------- |
92-
| `spreadsheetId` | string | Yes | The ID of the spreadsheet containing the table |
93-
| `tableName` | string | Yes | The name of the table to add rows to |
94-
| `values` | array | Yes | The data to add to the table \(array of arrays or array of objects\) |
95-
96-
#### Output
97-
98-
| Parameter | Type | Description |
99-
| --------- | ---- | ----------- |
100-
| `index` | number | Index of the first row that was added |
101-
| `values` | array | Array of rows that were added to the table |
102-
| `metadata` | object | Spreadsheet metadata |
103-
|`spreadsheetId` | string | The ID of the spreadsheet |
104-
|`spreadsheetUrl` | string | URL to access the spreadsheet |
105-
106-
### `microsoft_excel_worksheet_add`
107-
108-
Create a new worksheet (sheet) in a Microsoft Excel workbook
109-
110-
#### Input
111-
112-
| Parameter | Type | Required | Description |
113-
| --------- | ---- | -------- | ----------- |
114-
| `spreadsheetId` | string | Yes | The ID of the Excel workbook to add the worksheet to |
115-
| `worksheetName` | string | Yes | The name of the new worksheet. Must be unique within the workbook and cannot exceed 31 characters |
116-
117-
#### Output
118-
119-
| Parameter | Type | Description |
120-
| --------- | ---- | ----------- |
121-
| `worksheet` | object | Details of the newly created worksheet |
122-
|`id` | string | The unique ID of the worksheet |
123-
|`name` | string | The name of the worksheet |
124-
|`position` | number | The zero-based position of the worksheet |
125-
|`visibility` | string | The visibility state of the worksheet \(Visible/Hidden/VeryHidden\) |
126-
| `metadata` | object | Spreadsheet metadata |
127-
|`spreadsheetId` | string | The ID of the spreadsheet |
128-
|`spreadsheetUrl` | string | URL to access the spreadsheet |
129-
13069

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { createLogger } from '@sim/logger'
2+
import { type NextRequest, NextResponse } from 'next/server'
3+
import { authorizeCredentialUse } from '@/lib/auth/credential-access'
4+
import { generateRequestId } from '@/lib/core/utils/request'
5+
import { refreshAccessTokenIfNeeded } from '@/app/api/auth/oauth/utils'
6+
7+
export const dynamic = 'force-dynamic'
8+
9+
const logger = createLogger('GoogleSheetsAPI')
10+
11+
interface SheetProperties {
12+
sheetId: number
13+
title: string
14+
index: number
15+
}
16+
17+
interface Sheet {
18+
properties: SheetProperties
19+
}
20+
21+
interface SpreadsheetResponse {
22+
sheets: Sheet[]
23+
}
24+
25+
/**
26+
* Get sheets (tabs) from a Google Spreadsheet
27+
*/
28+
export async function GET(request: NextRequest) {
29+
const requestId = generateRequestId()
30+
logger.info(`[${requestId}] Google Sheets sheets request received`)
31+
32+
try {
33+
const { searchParams } = new URL(request.url)
34+
const credentialId = searchParams.get('credentialId')
35+
const spreadsheetId = searchParams.get('spreadsheetId')
36+
const workflowId = searchParams.get('workflowId') || undefined
37+
38+
if (!credentialId) {
39+
logger.warn(`[${requestId}] Missing credentialId parameter`)
40+
return NextResponse.json({ error: 'Credential ID is required' }, { status: 400 })
41+
}
42+
43+
if (!spreadsheetId) {
44+
logger.warn(`[${requestId}] Missing spreadsheetId parameter`)
45+
return NextResponse.json({ error: 'Spreadsheet ID is required' }, { status: 400 })
46+
}
47+
48+
const authz = await authorizeCredentialUse(request, { credentialId, workflowId })
49+
if (!authz.ok || !authz.credentialOwnerUserId) {
50+
return NextResponse.json({ error: authz.error || 'Unauthorized' }, { status: 403 })
51+
}
52+
53+
const accessToken = await refreshAccessTokenIfNeeded(
54+
credentialId,
55+
authz.credentialOwnerUserId,
56+
requestId
57+
)
58+
59+
if (!accessToken) {
60+
return NextResponse.json({ error: 'Failed to obtain valid access token' }, { status: 401 })
61+
}
62+
63+
logger.info(
64+
`[${requestId}] Fetching sheets from Google Sheets API for spreadsheet ${spreadsheetId}`
65+
)
66+
67+
// Fetch spreadsheet metadata to get sheet names
68+
const sheetsResponse = await fetch(
69+
`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}?fields=sheets.properties`,
70+
{
71+
method: 'GET',
72+
headers: {
73+
Authorization: `Bearer ${accessToken}`,
74+
'Content-Type': 'application/json',
75+
},
76+
}
77+
)
78+
79+
if (!sheetsResponse.ok) {
80+
const errorData = await sheetsResponse
81+
.text()
82+
.then((text) => JSON.parse(text))
83+
.catch(() => ({ error: { message: 'Unknown error' } }))
84+
logger.error(`[${requestId}] Google Sheets API error`, {
85+
status: sheetsResponse.status,
86+
error: errorData.error?.message || 'Failed to fetch sheets',
87+
})
88+
return NextResponse.json(
89+
{ error: errorData.error?.message || 'Failed to fetch sheets' },
90+
{ status: sheetsResponse.status }
91+
)
92+
}
93+
94+
const data: SpreadsheetResponse = await sheetsResponse.json()
95+
const sheets = data.sheets || []
96+
97+
// Sort sheets by index
98+
sheets.sort((a, b) => a.properties.index - b.properties.index)
99+
100+
logger.info(`[${requestId}] Successfully fetched ${sheets.length} sheets`)
101+
102+
return NextResponse.json({
103+
sheets: sheets.map((sheet) => ({
104+
id: sheet.properties.title, // Use title as ID since that's what the API uses
105+
name: sheet.properties.title,
106+
sheetId: sheet.properties.sheetId,
107+
index: sheet.properties.index,
108+
})),
109+
})
110+
} catch (error) {
111+
logger.error(`[${requestId}] Error fetching Google Sheets sheets`, error)
112+
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
113+
}
114+
}

0 commit comments

Comments
 (0)