KosmoKrator

storage

Microsoft OneDrive Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Microsoft OneDrive KosmoKrator integration.

6 functions 5 read 1 write Bearer token auth

Lua Namespace

Agents call this integration through app.integrations.one_drive.*. Use lua_read_doc("integrations.one_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.

Microsoft OneDrive — Lua API Reference

list_files

List files and folders in the root of the user’s OneDrive.

Parameters

NameTypeRequiredDescription
topintegernoMaximum number of items to return (default: 100, max: 999)
skip_tokenstringnoPagination token from a previous response

Response

Returns an object with items, count, and optionally next_link and has_more.

Each item contains:

  • id — Drive item ID (use with get_file / download_file)
  • name — File or folder name
  • type"file" or "folder"
  • size — Size in bytes
  • created_at — ISO 8601 creation date
  • modified_at — ISO 8601 last modified date
  • web_url — URL to view in browser
  • mime_type — MIME type (files only)

Examples

-- List all files in root
local result = app.integrations.one_drive.list_files({})

for _, item in ipairs(result.items) do
  print(item.name .. " (" .. item.type .. ", " .. item.size .. " bytes)")
end

-- Paginate through results
local result = app.integrations.one_drive.list_files({ top = 50 })

if result.has_more then
  -- Extract skip token from next_link and fetch more
  local next = app.integrations.one_drive.list_files({
    top = 50,
    skip_token = "extracted_token"
  })
end

get_file

Get detailed metadata for a specific file or folder.

Parameters

NameTypeRequiredDescription
idstringyesThe unique drive item ID

Response

Returns detailed item metadata including download URL, parent reference, file hashes, and folder child count.

Examples

local result = app.integrations.one_drive.get_file({ id = "01ABCD1234..." })

print("Name: " .. result.name)
print("Size: " .. result.size .. " bytes")
print("Type: " .. result.mime_type)
print("Download URL: " .. (result.download_url or "none"))

upload_file

Upload a file to OneDrive. Creates or replaces the file at the specified path.

Supports files up to 4 MB via the simple upload API.

Parameters

NameTypeRequiredDescription
pathstringyesDestination path relative to root (e.g., "Documents/report.txt")
contentstringyesThe file content to upload
content_typestringnoMIME type (default: "application/octet-stream")

Examples

-- Upload a text file
local result = app.integrations.one_drive.upload_file({
  path = "Documents/hello.txt",
  content = "Hello from the AI agent!",
  content_type = "text/plain"
})

print("Uploaded: " .. result.name .. " (" .. result.size .. " bytes)")

-- Upload JSON data
local result = app.integrations.one_drive.upload_file({
  path = "Data/output.json",
  content = '{"status": "ok", "count": 42}',
  content_type = "application/json"
})

download_file

Download a file’s content by its drive item ID.

Parameters

NameTypeRequiredDescription
idstringyesThe unique drive item ID

Response

Returns an object with:

  • content — The raw file content as a string
  • size — Content length in bytes
  • item_id — The requested item ID

Examples

local result = app.integrations.one_drive.download_file({ id = "01ABCD1234..." })

print("Downloaded " .. result.size .. " bytes")
print("Content: " .. result.content)

list_shared

List files and folders shared with the current user.

Parameters

NameTypeRequiredDescription
topintegernoMaximum number of items to return (default: 100, max: 999)
skip_tokenstringnoPagination token from a previous response

Examples

local result = app.integrations.one_drive.list_shared({})

for _, item in ipairs(result.items) do
  print("Shared: " .. item.name .. " (" .. item.type .. ")")
end

get_current_user

Get the profile of the currently authenticated Microsoft user.

Parameters

None.

Response

Returns user profile information:

  • id — Microsoft user ID
  • display_name — Full name
  • email — Email address
  • job_title — Job title
  • office_location — Office location
  • phone — Business phone number

Examples

local result = app.integrations.one_drive.get_current_user({})

print("User: " .. result.display_name)
print("Email: " .. result.email)
print("Title: " .. (result.job_title or "N/A"))

Multi-Account Usage

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

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

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

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

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

Raw agent markdown
# Microsoft OneDrive — Lua API Reference

## list_files

List files and folders in the root of the user's OneDrive.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `top` | integer | no | Maximum number of items to return (default: 100, max: 999) |
| `skip_token` | string | no | Pagination token from a previous response |

### Response

Returns an object with `items`, `count`, and optionally `next_link` and `has_more`.

Each item contains:
- `id` — Drive item ID (use with get_file / download_file)
- `name` — File or folder name
- `type` — `"file"` or `"folder"`
- `size` — Size in bytes
- `created_at` — ISO 8601 creation date
- `modified_at` — ISO 8601 last modified date
- `web_url` — URL to view in browser
- `mime_type` — MIME type (files only)

### Examples

```lua
-- List all files in root
local result = app.integrations.one_drive.list_files({})

for _, item in ipairs(result.items) do
  print(item.name .. " (" .. item.type .. ", " .. item.size .. " bytes)")
end

-- Paginate through results
local result = app.integrations.one_drive.list_files({ top = 50 })

if result.has_more then
  -- Extract skip token from next_link and fetch more
  local next = app.integrations.one_drive.list_files({
    top = 50,
    skip_token = "extracted_token"
  })
end
```

---

## get_file

Get detailed metadata for a specific file or folder.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The unique drive item ID |

### Response

Returns detailed item metadata including download URL, parent reference, file hashes, and folder child count.

### Examples

```lua
local result = app.integrations.one_drive.get_file({ id = "01ABCD1234..." })

print("Name: " .. result.name)
print("Size: " .. result.size .. " bytes")
print("Type: " .. result.mime_type)
print("Download URL: " .. (result.download_url or "none"))
```

---

## upload_file

Upload a file to OneDrive. Creates or replaces the file at the specified path.

> Supports files up to 4 MB via the simple upload API.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `path` | string | yes | Destination path relative to root (e.g., `"Documents/report.txt"`) |
| `content` | string | yes | The file content to upload |
| `content_type` | string | no | MIME type (default: `"application/octet-stream"`) |

### Examples

```lua
-- Upload a text file
local result = app.integrations.one_drive.upload_file({
  path = "Documents/hello.txt",
  content = "Hello from the AI agent!",
  content_type = "text/plain"
})

print("Uploaded: " .. result.name .. " (" .. result.size .. " bytes)")

-- Upload JSON data
local result = app.integrations.one_drive.upload_file({
  path = "Data/output.json",
  content = '{"status": "ok", "count": 42}',
  content_type = "application/json"
})
```

---

## download_file

Download a file's content by its drive item ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The unique drive item ID |

### Response

Returns an object with:
- `content` — The raw file content as a string
- `size` — Content length in bytes
- `item_id` — The requested item ID

### Examples

```lua
local result = app.integrations.one_drive.download_file({ id = "01ABCD1234..." })

print("Downloaded " .. result.size .. " bytes")
print("Content: " .. result.content)
```

---

## list_shared

List files and folders shared with the current user.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `top` | integer | no | Maximum number of items to return (default: 100, max: 999) |
| `skip_token` | string | no | Pagination token from a previous response |

### Examples

```lua
local result = app.integrations.one_drive.list_shared({})

for _, item in ipairs(result.items) do
  print("Shared: " .. item.name .. " (" .. item.type .. ")")
end
```

---

## get_current_user

Get the profile of the currently authenticated Microsoft user.

### Parameters

None.

### Response

Returns user profile information:
- `id` — Microsoft user ID
- `display_name` — Full name
- `email` — Email address
- `job_title` — Job title
- `office_location` — Office location
- `phone` — Business phone number

### Examples

```lua
local result = app.integrations.one_drive.get_current_user({})

print("User: " .. result.display_name)
print("Email: " .. result.email)
print("Title: " .. (result.job_title or "N/A"))
```

---

## Multi-Account Usage

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

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

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

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

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

Metadata-Derived Lua Example

local result = app.integrations.one_drive.onedrive_list_files({
  top = 1,
  skip_token = "example_skip_token"
})
print(result)

Functions

onedrive_list_files

List files and folders in the root of the user's OneDrive. Returns item names, IDs, sizes, and metadata. Use the item ID with onedrive_get_file or onedrive_download_file for details or content.

Operation
Read read
Full name
one_drive.onedrive_list_files
ParameterTypeRequiredDescription
top integer no Maximum number of items to return (default: 100, max: 999).
skip_token string no Pagination token from a previous response to fetch the next page of results.

onedrive_get_file

Get detailed metadata for a specific file or folder in OneDrive by its item ID. Returns name, size, dates, MIME type, and download URL.

Operation
Read read
Full name
one_drive.onedrive_get_file
ParameterTypeRequiredDescription
id string yes The unique identifier of the drive item (obtained from onedrive_list_files or onedrive_list_shared).

onedrive_upload_file

Upload a file to OneDrive. Specify the destination path and file content. Creates the file if it does not exist, or replaces it if it does. Supports files up to 4 MB via the simple upload API.

Operation
Write write
Full name
one_drive.onedrive_upload_file
ParameterTypeRequiredDescription
path string yes The destination path in OneDrive, relative to the root (e.g., "Documents/report.txt" or "photos/image.png").
content string yes The content of the file to upload.
content_type string no The MIME type of the file (e.g., "text/plain", "application/json", "image/png"). Defaults to "application/octet-stream".

onedrive_download_file

Download a file's content from OneDrive by its drive item ID. Returns the raw file content. Use onedrive_list_files or onedrive_get_file to find the item ID.

Operation
Read read
Full name
one_drive.onedrive_download_file
ParameterTypeRequiredDescription
id string yes The unique identifier of the drive item to download.

onedrive_list_shared

List files and folders that have been shared with the current user. Returns item names, IDs, sizes, and metadata for shared content.

Operation
Read read
Full name
one_drive.onedrive_list_shared
ParameterTypeRequiredDescription
top integer no Maximum number of items to return (default: 100, max: 999).
skip_token string no Pagination token from a previous response to fetch the next page of results.

onedrive_get_current_user

Get the profile of the currently authenticated Microsoft user. Returns display name, email, job title, and other profile details.

Operation
Read read
Full name
one_drive.onedrive_get_current_user
ParameterTypeRequiredDescription
No parameters.