KosmoKrator

productivity

Google Sheets Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Google Sheets KosmoKrator integration.

20 functions 13 read 7 write OAuth browser flow auth

Lua Namespace

Agents call this integration through app.integrations.google_sheets.*. Use lua_read_doc("integrations.google_sheets") inside KosmoKrator to discover the same reference at runtime.

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Google Integration — Lua API Supplement

Google services are registered as separate namespaces: integrations.gmail, integrations.google_sheets, integrations.google_calendar, integrations.google_drive, etc. All share the same OAuth credentials.

Gmail

Send email with CC/BCC:

app.integrations.gmail.send_email({
    to = "[email protected]",
    subject = "Q1 Report",
    body = "Please find the report attached.",
    cc = "[email protected], [email protected]",
    bcc = "[email protected]",
})

Search, read, then reply workflow:

-- Step 1: Search for messages
local results = app.integrations.gmail.search_emails({
    query = "from:alice subject:meeting is:unread",
    max_results = 5,
})

-- Step 2: Read the full message
local msg = app.integrations.gmail.read_email({ message_id = results.messages[1].id })

-- Step 3: Reply in the same thread
app.integrations.gmail.reply({
    message_id = msg.id,
    thread_id = msg.threadId,
    body = "Thanks, I'll be there.",
    cc = "[email protected]",
})

Draft vs direct send — use create_draft to stage an email without sending, then send_draft to send it later:

-- Create a draft (not sent)
local draft = app.integrations.gmail.create_draft({
    to = "[email protected]",
    subject = "Proposal",
    body = "Draft content here...",
})

-- Send it later using the draft ID
app.integrations.gmail.send_draft({ draft_id = draft.draftId })

Google Sheets

Values use 2D Lua tables — each inner table is one row:

local values = {
    {"Name", "Age", "City"},
    {"Alice", 30, "NYC"},
    {"Bob", 25, "LA"},
}

A1 notation examples:

  • "Sheet1!A1:D10" — specific range
  • "Sheet1!A:A" — entire column
  • "Sheet1" — entire sheet
  • "'My Sheet'!A1:B2" — sheet names with spaces need quotes

Input modes: "user_entered" (default) parses formulas and dates, "raw" stores literal strings.

Create a spreadsheet, add a sheet, write data:

-- Create a new spreadsheet
local ss = app.integrations.google_sheets.create_spreadsheet({ title = "Q1 Sales" })
local id = ss.spreadsheetId

-- Add a second sheet/tab
app.integrations.google_sheets.add({
    spreadsheet_id = id,
    title = "By Region",
})

-- Write data with headers
app.integrations.google_sheets.write_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    values = {
        {"Region", "Revenue", "Growth"},
        {"North", 50000, "=B2/50000-1"},
        {"South", 42000, "=B3/42000-1"},
    },
    input = "user_entered",  -- parses the formulas
})

Read data back:

local data = app.integrations.google_sheets.read_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    render = "formatted",  -- "formatted" (default), "unformatted", or "formula"
})
-- data.values is a 2D table: {{"Region","Revenue","Growth"}, {"North","50000","0%"}, ...}

Append vs write — append_rows auto-detects the last row and adds below it:

app.integrations.google_sheets.append_rows({
    spreadsheet_id = id,
    range = "Sheet1",
    values = {
        {"East", 38000, "=B4/38000-1"},
    },
    input = "user_entered",
})

Google Calendar

Create a timed event with attendees:

app.integrations.google_calendar.create_event({
    summary = "Sprint Planning",
    description = "Bi-weekly sprint planning session",
    location = "Conference Room B",
    start_date_time = "2026-04-01T10:00:00-05:00",
    end_date_time = "2026-04-01T11:00:00-05:00",
    time_zone = "America/New_York",
    attendees = "[email protected], [email protected]",
    recurrence = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10",
})

Create an all-day event:

app.integrations.google_calendar.create_event({
    summary = "Company Holiday",
    start_date = "2026-07-04",
    end_date = "2026-07-05",
})

Date/time format: ISO 8601 with timezone offset for timed events (2026-04-01T10:00:00-05:00), plain YYYY-MM-DD for all-day events. Use time_zone for IANA names like "America/New_York".

Google Drive

Search for files, then get details:

-- Search by name and type
local results = app.integrations.google_drive.search({
    query = "name contains 'report' and mimeType = 'application/vnd.google-apps.spreadsheet'",
    max_results = 10,
    order_by = "modifiedTime desc",
})

-- Get full file info (and optionally export content)
local file = app.integrations.google_drive.get_file({
    file_id = results.files[1].id,
    export_as = "csv",  -- "text", "csv", or "markdown" (Google Workspace files only)
})

Common Drive query patterns:

  • "name contains 'budget'" — by name
  • "mimeType = 'application/vnd.google-apps.spreadsheet'" — Sheets
  • "mimeType = 'application/vnd.google-apps.document'" — Docs
  • "mimeType = 'application/vnd.google-apps.folder'" — folders
  • "modifiedTime > '2026-01-01'" — recently modified
  • "sharedWithMe = true" — shared files
  • "'FOLDER_ID' in parents" — files in a folder

Share a file:

-- Share with a specific user
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "writer",       -- "reader", "writer", or "commenter"
    email = "[email protected]",
    notify = "true",
})

-- Share with anyone via link
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "reader",
    type = "anyone",
})

Tips

  • All Google APIs share the same OAuth token — if Gmail is connected, the same credentials work for Sheets, Drive, Calendar, etc.
  • Use input = "user_entered" when writing Sheets data that contains formulas (e.g., "=SUM(A1:A10)") or dates. Use "raw" for literal strings.
  • Sheet names with spaces must be quoted in A1 notation: "'My Sheet'!A1:B2".
  • append_rows is better than write_range when adding rows to an existing table — it auto-detects where the data ends.
  • Calendar event times use ISO 8601 with timezone offset. Always include the offset or set time_zone explicitly.
  • Drive search excludes trashed files by default.

Multi-Account Usage

If you have multiple google accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.google.function_name({...})

-- Explicit default (portable across setups)
app.integrations.google.default.function_name({...})

-- Named accounts
app.integrations.google.work.function_name({...})
app.integrations.google.personal.function_name({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Google Integration — Lua API Supplement

Google services are registered as separate namespaces: `integrations.gmail`, `integrations.google_sheets`, `integrations.google_calendar`, `integrations.google_drive`, etc. All share the same OAuth credentials.

## Gmail

Send email with CC/BCC:

```lua
app.integrations.gmail.send_email({
    to = "[email protected]",
    subject = "Q1 Report",
    body = "Please find the report attached.",
    cc = "[email protected], [email protected]",
    bcc = "[email protected]",
})
```

Search, read, then reply workflow:

```lua
-- Step 1: Search for messages
local results = app.integrations.gmail.search_emails({
    query = "from:alice subject:meeting is:unread",
    max_results = 5,
})

-- Step 2: Read the full message
local msg = app.integrations.gmail.read_email({ message_id = results.messages[1].id })

-- Step 3: Reply in the same thread
app.integrations.gmail.reply({
    message_id = msg.id,
    thread_id = msg.threadId,
    body = "Thanks, I'll be there.",
    cc = "[email protected]",
})
```

Draft vs direct send -- use `create_draft` to stage an email without sending, then `send_draft` to send it later:

```lua
-- Create a draft (not sent)
local draft = app.integrations.gmail.create_draft({
    to = "[email protected]",
    subject = "Proposal",
    body = "Draft content here...",
})

-- Send it later using the draft ID
app.integrations.gmail.send_draft({ draft_id = draft.draftId })
```

## Google Sheets

Values use 2D Lua tables -- each inner table is one row:

```lua
local values = {
    {"Name", "Age", "City"},
    {"Alice", 30, "NYC"},
    {"Bob", 25, "LA"},
}
```

A1 notation examples:

- `"Sheet1!A1:D10"` -- specific range
- `"Sheet1!A:A"` -- entire column
- `"Sheet1"` -- entire sheet
- `"'My Sheet'!A1:B2"` -- sheet names with spaces need quotes

Input modes: `"user_entered"` (default) parses formulas and dates, `"raw"` stores literal strings.

Create a spreadsheet, add a sheet, write data:

```lua
-- Create a new spreadsheet
local ss = app.integrations.google_sheets.create_spreadsheet({ title = "Q1 Sales" })
local id = ss.spreadsheetId

-- Add a second sheet/tab
app.integrations.google_sheets.add({
    spreadsheet_id = id,
    title = "By Region",
})

-- Write data with headers
app.integrations.google_sheets.write_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    values = {
        {"Region", "Revenue", "Growth"},
        {"North", 50000, "=B2/50000-1"},
        {"South", 42000, "=B3/42000-1"},
    },
    input = "user_entered",  -- parses the formulas
})
```

Read data back:

```lua
local data = app.integrations.google_sheets.read_range({
    spreadsheet_id = id,
    range = "Sheet1!A1:C3",
    render = "formatted",  -- "formatted" (default), "unformatted", or "formula"
})
-- data.values is a 2D table: {{"Region","Revenue","Growth"}, {"North","50000","0%"}, ...}
```

Append vs write -- `append_rows` auto-detects the last row and adds below it:

```lua
app.integrations.google_sheets.append_rows({
    spreadsheet_id = id,
    range = "Sheet1",
    values = {
        {"East", 38000, "=B4/38000-1"},
    },
    input = "user_entered",
})
```

## Google Calendar

Create a timed event with attendees:

```lua
app.integrations.google_calendar.create_event({
    summary = "Sprint Planning",
    description = "Bi-weekly sprint planning session",
    location = "Conference Room B",
    start_date_time = "2026-04-01T10:00:00-05:00",
    end_date_time = "2026-04-01T11:00:00-05:00",
    time_zone = "America/New_York",
    attendees = "[email protected], [email protected]",
    recurrence = "RRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=10",
})
```

Create an all-day event:

```lua
app.integrations.google_calendar.create_event({
    summary = "Company Holiday",
    start_date = "2026-07-04",
    end_date = "2026-07-05",
})
```

Date/time format: ISO 8601 with timezone offset for timed events (`2026-04-01T10:00:00-05:00`), plain `YYYY-MM-DD` for all-day events. Use `time_zone` for IANA names like `"America/New_York"`.

## Google Drive

Search for files, then get details:

```lua
-- Search by name and type
local results = app.integrations.google_drive.search({
    query = "name contains 'report' and mimeType = 'application/vnd.google-apps.spreadsheet'",
    max_results = 10,
    order_by = "modifiedTime desc",
})

-- Get full file info (and optionally export content)
local file = app.integrations.google_drive.get_file({
    file_id = results.files[1].id,
    export_as = "csv",  -- "text", "csv", or "markdown" (Google Workspace files only)
})
```

Common Drive query patterns:

- `"name contains 'budget'"` -- by name
- `"mimeType = 'application/vnd.google-apps.spreadsheet'"` -- Sheets
- `"mimeType = 'application/vnd.google-apps.document'"` -- Docs
- `"mimeType = 'application/vnd.google-apps.folder'"` -- folders
- `"modifiedTime > '2026-01-01'"` -- recently modified
- `"sharedWithMe = true"` -- shared files
- `"'FOLDER_ID' in parents"` -- files in a folder

Share a file:

```lua
-- Share with a specific user
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "writer",       -- "reader", "writer", or "commenter"
    email = "[email protected]",
    notify = "true",
})

-- Share with anyone via link
app.integrations.google_drive.share_file({
    file_id = "abc123",
    role = "reader",
    type = "anyone",
})
```

## Tips

- All Google APIs share the same OAuth token -- if Gmail is connected, the same credentials work for Sheets, Drive, Calendar, etc.
- Use `input = "user_entered"` when writing Sheets data that contains formulas (e.g., `"=SUM(A1:A10)"`) or dates. Use `"raw"` for literal strings.
- Sheet names with spaces must be quoted in A1 notation: `"'My Sheet'!A1:B2"`.
- `append_rows` is better than `write_range` when adding rows to an existing table -- it auto-detects where the data ends.
- Calendar event times use ISO 8601 with timezone offset. Always include the offset or set `time_zone` explicitly.
- Drive search excludes trashed files by default.

---

## Multi-Account Usage

If you have multiple google accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.google.function_name({...})

-- Explicit default (portable across setups)
app.integrations.google.default.function_name({...})

-- Named accounts
app.integrations.google.work.function_name({...})
app.integrations.google.personal.function_name({...})
```

All functions are identical across accounts — only the credentials differ.

Metadata-Derived Lua Example

local result = app.integrations.google_sheets.google_sheets_add_filter({
  spreadsheet_id = "example_spreadsheet_id",
  range = "example_range"
})
print(result)

Functions

google_sheets_add_filter

Apply filter dropdowns to a range in a Google Sheets sheet/tab.

Operation
Write write
Full name
google_sheets.google_sheets_add_filter
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
range string yes A1 notation range including header row (e.g., "Sheet1!A1:D10").

google_sheets_add_sheet

Add a new sheet/tab to a Google Spreadsheet.

Operation
Write write
Full name
google_sheets.google_sheets_add_sheet
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
title string yes Name for the new sheet/tab.

google_sheets_append

Append rows after the last data row in a Google Spreadsheet. Auto-detects the table boundary. Provide the range (e.g., "Sheet1" or "Sheet1!A:D") and a 2D array of rows to append.

Operation
Read read
Full name
google_sheets.google_sheets_append
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
range string yes A1 notation range (e.g., "Sheet1" or "Sheet1!A:D").
values array yes 2D array of rows to append (e.g., [["Alice", 30], ["Bob", 25]]).
input string no Input mode: "user_entered" (default, parses formulas/dates) or "raw" (literal strings).

google_sheets_batch_read

Read multiple ranges from a Google Spreadsheet in one call. Provide an array of A1 notation ranges (e.g., ["Sheet1!A1:B5", "Sheet2!C1:D10"]). Returns results keyed by range.

Operation
Read read
Full name
google_sheets.google_sheets_batch_read
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
ranges array yes Array of A1 notation ranges (e.g., ["Sheet1!A1:B5", "Sheet2!C1:D10"]).
render string no Value rendering: "formatted" (default, as displayed), "unformatted" (raw numbers), or "formula" (shows formulas).

google_sheets_batch_write

Write to multiple ranges in a Google Spreadsheet in one call. Provide an array of {range, values} objects to update several areas at once.

Operation
Read read
Full name
google_sheets.google_sheets_batch_write
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
data array yes Array of {range, values} objects (e.g., [{"range": "Sheet1!A1:B2", "values": [["a", "b"]]}]).
input string no Input mode: "user_entered" (default, parses formulas/dates) or "raw" (literal strings).

google_sheets_clear

Clear all values from a Google Sheets range (keeps formatting intact). Specify the range in A1 notation.

Operation
Read read
Full name
google_sheets.google_sheets_clear
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
range string yes A1 notation range to clear (e.g., "Sheet1!A1:D10").

google_sheets_create

Create a new empty Google Spreadsheet with a given title. Returns the new spreadsheet ID and URL.

Operation
Read read
Full name
google_sheets.google_sheets_create
ParameterTypeRequiredDescription
title string yes Title for the new spreadsheet.

google_sheets_delete_columns

Delete columns from a Google Sheets sheet/tab. Uses 0-based indexing.

Operation
Write write
Full name
google_sheets.google_sheets_delete_columns
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Sheet/tab name.
start_index integer yes 0-based column index to start deleting from.
count integer no Number of columns to delete (default 1).

google_sheets_delete_rows

Delete rows from a Google Sheets sheet/tab. Uses 0-based indexing.

Operation
Write write
Full name
google_sheets.google_sheets_delete_rows
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Sheet/tab name.
start_index integer yes 0-based row index to start deleting from.
count integer no Number of rows to delete (default 1).

google_sheets_delete_sheet

Delete a sheet/tab from a Google Spreadsheet.

Operation
Write write
Full name
google_sheets.google_sheets_delete_sheet
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Sheet/tab name to delete.

google_sheets_duplicate_sheet

Copy a sheet/tab within the same Google Spreadsheet.

Operation
Write write
Full name
google_sheets.google_sheets_duplicate_sheet
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Source sheet/tab name to duplicate.
title string no Name for the copy (defaults to "Copy of {name}").

google_sheets_find

Search for text within a Google Spreadsheet. Searches all sheets by default, or specify a sheet name to narrow the search. Returns match count and number of sheets containing matches.

Operation
Read read
Full name
google_sheets.google_sheets_find
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
query string yes Text to search for.
sheet string no Sheet name to search in. Omit to search all sheets.
match_case boolean no Case-sensitive search. Default false.
match_entire_cell boolean no Match entire cell content only. Default false.

google_sheets_get_metadata

Get spreadsheet title and list of sheets/tabs with their names, IDs, and dimensions. Use this first to discover sheet names and structure before reading or writing data.

Operation
Read read
Full name
google_sheets.google_sheets_get_metadata
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).

google_sheets_insert_columns

Insert blank columns into a Google Sheets sheet/tab. Uses 0-based indexing.

Operation
Read read
Full name
google_sheets.google_sheets_insert_columns
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Sheet/tab name.
start_index integer yes 0-based column index to insert at.
count integer no Number of columns to insert (default 1).

google_sheets_insert_rows

Insert blank rows into a Google Sheets sheet/tab. Uses 0-based indexing.

Operation
Read read
Full name
google_sheets.google_sheets_insert_rows
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Sheet/tab name.
start_index integer yes 0-based row index to insert at.
count integer no Number of rows to insert (default 1).

google_sheets_read_range

Read cell values from a Google Sheets range using A1 notation. A1 notation examples: `Sheet1!A1:D10` (range), `Sheet1!A:A` (whole column), `Sheet1` (entire sheet). Sheet names with spaces need quotes: `'My Sheet'!A1:B2`.

Operation
Read read
Full name
google_sheets.google_sheets_read_range
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
range string yes A1 notation range (e.g., "Sheet1!A1:D10", "Sheet1!A:A", "Sheet1").
render string no Value rendering: "formatted" (default, as displayed), "unformatted" (raw numbers), or "formula" (shows formulas).

google_sheets_remove_filter

Remove the filter from a Google Sheets sheet/tab.

Operation
Write write
Full name
google_sheets.google_sheets_remove_filter
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Sheet/tab name to remove the filter from.

google_sheets_rename_sheet

Rename a sheet/tab in a Google Spreadsheet.

Operation
Read read
Full name
google_sheets.google_sheets_rename_sheet
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
sheet string yes Current sheet/tab name.
title string yes New name for the sheet/tab.

google_sheets_sort_range

Sort data by column(s) in a Google Sheets range.

Operation
Read read
Full name
google_sheets.google_sheets_sort_range
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
range string yes A1 notation range to sort (e.g., "Sheet1!A1:D10").
sort_column integer yes 0-based column index within the range to sort by.
ascending boolean no Sort ascending (true, default) or descending (false).

google_sheets_write_range

Write values to a Google Sheets range. Values format: `[["Name", "Age"], ["Alice", 30]]` — each inner array is one row. Formulas work with user_entered input mode (default): `[["=SUM(A1:A10)"]]`.

Operation
Read read
Full name
google_sheets.google_sheets_write_range
ParameterTypeRequiredDescription
spreadsheet_id string yes Spreadsheet ID (from the URL).
range string yes A1 notation range (e.g., "Sheet1!A1:D10").
values array yes 2D array of values. Each inner array is a row (e.g., [["Name", "Age"], ["Alice", 30]]).
input string no Input mode: "user_entered" (default, parses formulas/dates) or "raw" (literal strings).