KosmoKrator

productivity

Google Drive Lua API for KosmoKrator Agents

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

6 functions 4 read 2 write Manual OAuth token auth

Lua Namespace

Agents call this integration through app.integrations.google_drive.*. Use lua_read_doc("integrations.google-drive") 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 Drive — Lua API Reference

list_files

List files and folders in Google Drive. Supports filtering, pagination, and spaces.

Parameters

NameTypeRequiredDescription
pageSizeintegernoMax files per page (default: 100, max: 1000)
pageTokenstringnoToken from previous response for pagination
qstringnoQuery string for filtering files
spacesstringnoComma-separated spaces: “drive”, “appDataFolder”, “photos”
trashedbooleannoInclude trashed files (true/false)
corporastringnoSource: “user”, “domain”, “allDrives”, or “drive”
fieldsstringnoFields to include in partial response

Query Examples

name = 'hello'                           -- exact name match
name contains 'report'                   -- name contains substring
mimeType = 'application/vnd.google-apps.folder'  -- folders only
mimeType != 'application/vnd.google-apps.folder' -- files only (no folders)
fullText contains 'invoice'              -- full-text search
modifiedTime > '2025-01-01T00:00:00'     -- modified after date
'parentId' in parents                    -- files in a specific folder

Examples

List recent files

local result = app.integrations.google_drive.list_files({
  pageSize = 20,
  fields = "files(id,name,mimeType,modifiedTime,size)"
})

for _, file in ipairs(result.files) do
  print(file.name .. " (" .. file.mimeType .. ")")
end

List only folders

local result = app.integrations.google_drive.list_files({
  q = "mimeType = 'application/vnd.google-apps.folder'",
  fields = "files(id,name)"
})

Paginate through results

local page = app.integrations.google_drive.list_files({ pageSize = 50 })

while page.files do
  for _, file in ipairs(page.files) do
    print(file.name)
  end

  if page.nextPageToken then
    page = app.integrations.google_drive.list_files({
      pageSize = 50,
      pageToken = page.nextPageToken
    })
  else
    break
  end
end

get_file

Get metadata for a specific file or folder by its Google Drive file ID.

Parameters

NameTypeRequiredDescription
fileIdstringyesThe Google Drive file ID
fieldsstringnoFields to include in response

Example

local file = app.integrations.google_drive.get_file({
  fileId = "1aBcDeFgHiJkLmNoPqRsTuVwXyZ",
  fields = "id,name,mimeType,size,modifiedTime,webViewLink"
})

print(file.name .. " — " .. file.webViewLink)

create_file

Create a new file metadata entry in Google Drive.

Parameters

NameTypeRequiredDescription
namestringyesFile name (e.g., “Report.pdf”)
mimeTypestringnoMIME type (e.g., “text/plain”, “application/pdf”)
parentsarraynoList of parent folder IDs
descriptionstringnoShort file description

Example

local file = app.integrations.google_drive.create_file({
  name = "Meeting Notes.txt",
  mimeType = "text/plain",
  parents = { "1aBcDeFgHiJkLmNoPqRsTuVwXyZ" }
})

print("Created: " .. file.id .. " — " .. file.name)

create_folder

Create a new folder in Google Drive.

Parameters

NameTypeRequiredDescription
namestringyesFolder name
parentIdstringnoParent folder ID (root if omitted)

Example

local folder = app.integrations.google_drive.create_folder({
  name = "Project 2026",
  parentId = "1aBcDeFgHiJkLmNoPqRsTuVwXyZ"
})

print("Folder created: " .. folder.id .. " — " .. folder.name)

list_changes

List changes to files in Google Drive. Used for detecting file additions, modifications, and deletions.

Parameters

NameTypeRequiredDescription
pageSizeintegernoMax changes per page (default: 100, max: 1000)
pageTokenstringnoToken from previous response or startPageToken
fieldsstringnoFields to include in response

Example

local result = app.integrations.google_drive.list_changes({
  pageToken = "12345",
  pageSize = 50,
  fields = "changes(fileId,file(name,mimeType)),nextPageToken,newStartPageToken"
})

for _, change in ipairs(result.changes) do
  print(change.fileId .. ": " .. (change.file and change.file.name or "removed"))
end

get_current_user

Get information about the authenticated user and their Drive storage quota.

Parameters

NameTypeRequiredDescription
fieldsstringnoFields to include (default: “user,storageQuota”)

Example

local info = app.integrations.google_drive.get_current_user({})

print("User: " .. info.user.displayName)
print("Email: " .. info.user.emailAddress)
print("Storage: " .. (info.storageQuota.usage / 1073741824) .. " GB used of " .. (info.storageQuota.limit / 1073741824) .. " GB")

Multi-Account Usage

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

-- Default account (always works)
app.integrations.google_drive.list_files({...})

-- Explicit default (portable across setups)
app.integrations.google_drive.default.list_files({...})

-- Named accounts
app.integrations.google_drive.work.list_files({...})
app.integrations.google_drive.personal.list_files({...})

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

Raw agent markdown
# Google Drive — Lua API Reference

## list_files

List files and folders in Google Drive. Supports filtering, pagination, and spaces.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `pageSize` | integer | no | Max files per page (default: 100, max: 1000) |
| `pageToken` | string | no | Token from previous response for pagination |
| `q` | string | no | Query string for filtering files |
| `spaces` | string | no | Comma-separated spaces: "drive", "appDataFolder", "photos" |
| `trashed` | boolean | no | Include trashed files (true/false) |
| `corpora` | string | no | Source: "user", "domain", "allDrives", or "drive" |
| `fields` | string | no | Fields to include in partial response |

### Query Examples

```
name = 'hello'                           -- exact name match
name contains 'report'                   -- name contains substring
mimeType = 'application/vnd.google-apps.folder'  -- folders only
mimeType != 'application/vnd.google-apps.folder' -- files only (no folders)
fullText contains 'invoice'              -- full-text search
modifiedTime > '2025-01-01T00:00:00'     -- modified after date
'parentId' in parents                    -- files in a specific folder
```

## Examples

### List recent files

```lua
local result = app.integrations.google_drive.list_files({
  pageSize = 20,
  fields = "files(id,name,mimeType,modifiedTime,size)"
})

for _, file in ipairs(result.files) do
  print(file.name .. " (" .. file.mimeType .. ")")
end
```

### List only folders

```lua
local result = app.integrations.google_drive.list_files({
  q = "mimeType = 'application/vnd.google-apps.folder'",
  fields = "files(id,name)"
})
```

### Paginate through results

```lua
local page = app.integrations.google_drive.list_files({ pageSize = 50 })

while page.files do
  for _, file in ipairs(page.files) do
    print(file.name)
  end

  if page.nextPageToken then
    page = app.integrations.google_drive.list_files({
      pageSize = 50,
      pageToken = page.nextPageToken
    })
  else
    break
  end
end
```

---

## get_file

Get metadata for a specific file or folder by its Google Drive file ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `fileId` | string | yes | The Google Drive file ID |
| `fields` | string | no | Fields to include in response |

### Example

```lua
local file = app.integrations.google_drive.get_file({
  fileId = "1aBcDeFgHiJkLmNoPqRsTuVwXyZ",
  fields = "id,name,mimeType,size,modifiedTime,webViewLink"
})

print(file.name .. " — " .. file.webViewLink)
```

---

## create_file

Create a new file metadata entry in Google Drive.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | yes | File name (e.g., "Report.pdf") |
| `mimeType` | string | no | MIME type (e.g., "text/plain", "application/pdf") |
| `parents` | array | no | List of parent folder IDs |
| `description` | string | no | Short file description |

### Example

```lua
local file = app.integrations.google_drive.create_file({
  name = "Meeting Notes.txt",
  mimeType = "text/plain",
  parents = { "1aBcDeFgHiJkLmNoPqRsTuVwXyZ" }
})

print("Created: " .. file.id .. " — " .. file.name)
```

---

## create_folder

Create a new folder in Google Drive.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | string | yes | Folder name |
| `parentId` | string | no | Parent folder ID (root if omitted) |

### Example

```lua
local folder = app.integrations.google_drive.create_folder({
  name = "Project 2026",
  parentId = "1aBcDeFgHiJkLmNoPqRsTuVwXyZ"
})

print("Folder created: " .. folder.id .. " — " .. folder.name)
```

---

## list_changes

List changes to files in Google Drive. Used for detecting file additions, modifications, and deletions.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `pageSize` | integer | no | Max changes per page (default: 100, max: 1000) |
| `pageToken` | string | no | Token from previous response or startPageToken |
| `fields` | string | no | Fields to include in response |

### Example

```lua
local result = app.integrations.google_drive.list_changes({
  pageToken = "12345",
  pageSize = 50,
  fields = "changes(fileId,file(name,mimeType)),nextPageToken,newStartPageToken"
})

for _, change in ipairs(result.changes) do
  print(change.fileId .. ": " .. (change.file and change.file.name or "removed"))
end
```

---

## get_current_user

Get information about the authenticated user and their Drive storage quota.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `fields` | string | no | Fields to include (default: "user,storageQuota") |

### Example

```lua
local info = app.integrations.google_drive.get_current_user({})

print("User: " .. info.user.displayName)
print("Email: " .. info.user.emailAddress)
print("Storage: " .. (info.storageQuota.usage / 1073741824) .. " GB used of " .. (info.storageQuota.limit / 1073741824) .. " GB")
```

---

## Multi-Account Usage

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

```lua
-- Default account (always works)
app.integrations.google_drive.list_files({...})

-- Explicit default (portable across setups)
app.integrations.google_drive.default.list_files({...})

-- Named accounts
app.integrations.google_drive.work.list_files({...})
app.integrations.google_drive.personal.list_files({...})
```

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

Metadata-Derived Lua Example

local result = app.integrations.google_drive.gdrive_list_files({
  pageSize = 1,
  pageToken = "example_pageToken",
  q = "example_q",
  spaces = "example_spaces",
  trashed = true,
  corpora = "example_corpora",
  fields = "example_fields"
})
print(result)

Functions

gdrive_list_files

List files and folders in Google Drive. Supports search queries (q), pagination, spaces (drive, appDataFolder, photos), and trashed filtering.

Operation
Read read
Full name
google-drive.gdrive_list_files
ParameterTypeRequiredDescription
pageSize integer no Maximum number of files to return per page (default: 100, max: 1000).
pageToken string no Token for the next page of results, from a previous list response.
q string no Query string for filtering files. E.g., "mimeType = 'application/vnd.google-apps.folder'" to list only folders, or "name contains 'report'" to search by name.
spaces string no Comma-separated list of spaces to query: "drive", "appDataFolder", "photos". Defaults to "drive".
trashed boolean no Whether to include trashed files. Set to true to only show trashed files, false to exclude them.
corpora string no Source of files to list: "user" (default), "domain", "allDrives", or "drive". Use "drive" with driveId parameter.
fields string no Fields to include in the response (partial response). E.g., "files(id,name,mimeType,modifiedTime)".

gdrive_get_file

Get metadata for a specific file or folder in Google Drive by its ID. Returns properties like name, mimeType, size, createdTime, modifiedTime, and parents.

Operation
Read read
Full name
google-drive.gdrive_get_file
ParameterTypeRequiredDescription
fileId string yes The ID of the file or folder.
fields string no Fields to include in the response. E.g., "id,name,mimeType,size,modifiedTime,parents,webContentLink,webViewLink". Defaults to all fields.

gdrive_create_file

Create a new file in Google Drive. Creates the file metadata (name, mimeType, parent folder). For simple file creation without content upload, use uploadType "resumable" or "multipart" via the Google Drive API directly.

Operation
Write write
Full name
google-drive.gdrive_create_file
ParameterTypeRequiredDescription
name string yes The name of the file (e.g., "Report.pdf").
mimeType string no The MIME type of the file (e.g., "text/plain", "application/pdf"). If not set, Google Drive will try to auto-detect.
parents array no List of parent folder IDs to add the file to. If not specified, the file is placed in the root folder.
description string no A short description of the file.

gdrive_create_folder

Create a new folder in Google Drive. Optionally specify a parent folder to nest it inside.

Operation
Write write
Full name
google-drive.gdrive_create_folder
ParameterTypeRequiredDescription
name string yes The name of the new folder.
parentId string no ID of the parent folder. If omitted, the folder is created in the root of Google Drive.

gdrive_list_changes

List changes to files and folders in Google Drive. Use pageToken from the initial startPageToken to begin tracking, then pass the returned next page token for subsequent requests.

Operation
Read read
Full name
google-drive.gdrive_list_changes
ParameterTypeRequiredDescription
pageSize integer no Maximum number of changes to return per page (default: 100, max: 1000).
pageToken string no The token for continuing a previous list request. Use the startPageToken for the initial request.
fields string no Fields to include in the response. E.g., "changes(fileId,file(name,mimeType)),nextPageToken,newStartPageToken".

gdrive_get_current_user

Get information about the authenticated Google Drive user, including display name, email address, and storage quota (usage, limit).

Operation
Read read
Full name
google-drive.gdrive_get_current_user
ParameterTypeRequiredDescription
fields string no Fields to include in the response. Defaults to "user,storageQuota".