KosmoKrator

data

Weave Lua API for KosmoKrator Agents

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

Lua Namespace

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

Call Lua from the Headless CLI

Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic Weave workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.weave.list_patients({limit = 1, page = 1, query = "example_query"}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("weave"))' --json
kosmo integrations:lua --eval 'print(docs.read("weave.list_patients"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local weave = app.integrations.weave
local result = weave.list_patients({limit = 1, page = 1, query = "example_query"})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.weave, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.weave.default.* or app.integrations.weave.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Weave, use the narrower mcp:lua command.

MCP Lua command
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json

Agent-Facing Lua Docs

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

Weave — Lua API Reference

list_patients

Search and list patients from the Weave platform.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of patients to return (default: 25)
pageintegernoPage number for pagination, 1-based (default: 1)
querystringnoSearch query to filter patients by name, phone, or email

Example

local result = app.integrations.weave.list_patients({
  query = "Smith",
  limit = 10
})

for _, patient in ipairs(result.patients) do
  print(patient.id .. ": " .. patient.name)
end

get_patient

Retrieve a single patient by ID.

Parameters

NameTypeRequiredDescription
idstringyesThe unique patient identifier

Example

local result = app.integrations.weave.get_patient({
  id = "patient-123"
})

print(result.name .. " — " .. result.email)

list_appointments

List appointments with optional date range filtering.

Parameters

NameTypeRequiredDescription
startDatestringnoStart date (ISO 8601, e.g. “2025-01-01”)
endDatestringnoEnd date (ISO 8601, e.g. “2025-01-31”)
limitintegernoMaximum number of appointments to return (default: 25)

Example

local result = app.integrations.weave.list_appointments({
  startDate = "2025-01-01",
  endDate = "2025-01-31",
  limit = 50
})

for _, appt in ipairs(result.appointments) do
  print(appt.id .. ": " .. appt.patient_name .. " at " .. appt.scheduled_at)
end

get_appointment

Retrieve a single appointment by ID.

Parameters

NameTypeRequiredDescription
idstringyesThe unique appointment identifier

Example

local result = app.integrations.weave.get_appointment({
  id = "appt-456"
})

print(result.patient_name .. " — " .. result.scheduled_at .. " (" .. result.status .. ")")

list_messages

List patient messages with optional type filtering.

Parameters

NameTypeRequiredDescription
limitintegernoMaximum number of messages to return (default: 25)
pageintegernoPage number for pagination, 1-based (default: 1)
typestringnoFilter by message type (e.g. “sms”, “email”)

Example

local result = app.integrations.weave.list_messages({
  type = "sms",
  limit = 20
})

for _, msg in ipairs(result.messages) do
  print(msg.id .. ": " .. msg.preview)
end

get_message

Retrieve a single message by ID.

Parameters

NameTypeRequiredDescription
idstringyesThe unique message identifier

Example

local result = app.integrations.weave.get_message({
  id = "msg-789"
})

print("From: " .. result.sender .. "\n" .. result.body)

get_current_user

Get the currently authenticated Weave user profile.

Parameters

None.

Example

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

print("Logged in as: " .. result.name .. " (" .. result.email .. ")")
print("Role: " .. result.role)

Multi-Account Usage

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

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

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

-- Named accounts
app.integrations.weave.clinic_a.function_name({...})
app.integrations.weave.clinic_b.function_name({...})

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

Raw agent markdown
# Weave — Lua API Reference

## list_patients

Search and list patients from the Weave platform.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of patients to return (default: 25) |
| `page` | integer | no | Page number for pagination, 1-based (default: 1) |
| `query` | string | no | Search query to filter patients by name, phone, or email |

### Example

```lua
local result = app.integrations.weave.list_patients({
  query = "Smith",
  limit = 10
})

for _, patient in ipairs(result.patients) do
  print(patient.id .. ": " .. patient.name)
end
```

---

## get_patient

Retrieve a single patient by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The unique patient identifier |

### Example

```lua
local result = app.integrations.weave.get_patient({
  id = "patient-123"
})

print(result.name .. " — " .. result.email)
```

---

## list_appointments

List appointments with optional date range filtering.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `startDate` | string | no | Start date (ISO 8601, e.g. "2025-01-01") |
| `endDate` | string | no | End date (ISO 8601, e.g. "2025-01-31") |
| `limit` | integer | no | Maximum number of appointments to return (default: 25) |

### Example

```lua
local result = app.integrations.weave.list_appointments({
  startDate = "2025-01-01",
  endDate = "2025-01-31",
  limit = 50
})

for _, appt in ipairs(result.appointments) do
  print(appt.id .. ": " .. appt.patient_name .. " at " .. appt.scheduled_at)
end
```

---

## get_appointment

Retrieve a single appointment by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The unique appointment identifier |

### Example

```lua
local result = app.integrations.weave.get_appointment({
  id = "appt-456"
})

print(result.patient_name .. " — " .. result.scheduled_at .. " (" .. result.status .. ")")
```

---

## list_messages

List patient messages with optional type filtering.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `limit` | integer | no | Maximum number of messages to return (default: 25) |
| `page` | integer | no | Page number for pagination, 1-based (default: 1) |
| `type` | string | no | Filter by message type (e.g. "sms", "email") |

### Example

```lua
local result = app.integrations.weave.list_messages({
  type = "sms",
  limit = 20
})

for _, msg in ipairs(result.messages) do
  print(msg.id .. ": " .. msg.preview)
end
```

---

## get_message

Retrieve a single message by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `id` | string | yes | The unique message identifier |

### Example

```lua
local result = app.integrations.weave.get_message({
  id = "msg-789"
})

print("From: " .. result.sender .. "\n" .. result.body)
```

---

## get_current_user

Get the currently authenticated Weave user profile.

### Parameters

None.

### Example

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

print("Logged in as: " .. result.name .. " (" .. result.email .. ")")
print("Role: " .. result.role)
```

---

## Multi-Account Usage

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

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

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

-- Named accounts
app.integrations.weave.clinic_a.function_name({...})
app.integrations.weave.clinic_b.function_name({...})
```

All functions are identical across accounts — only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.weave.list_patients({limit = 1, page = 1, query = "example_query"})
print(result)

Functions

list_patients Read

Search and list patients from Weave. Returns patient records with names, contact info, and metadata. Use the query parameter to search by name, phone, or email.

Lua path
app.integrations.weave.list_patients
Full name
weave.weave_list_patients
ParameterTypeRequiredDescription
limit integer no Maximum number of patients to return (default: 25).
page integer no Page number for pagination, 1-based (default: 1).
query string no Search query to filter patients by name, phone, or email.
get_patient Read

Retrieve a single patient by ID. Returns full patient details including demographics and contact information.

Lua path
app.integrations.weave.get_patient
Full name
weave.weave_get_patient
ParameterTypeRequiredDescription
id string yes The unique patient identifier.
list_appointments Read

List appointments from Weave with optional date range filtering. Returns appointment records with patient info, scheduled times, and status.

Lua path
app.integrations.weave.list_appointments
Full name
weave.weave_list_appointments
ParameterTypeRequiredDescription
startDate string no Start date for the range (ISO 8601, e.g. "2025-01-01").
endDate string no End date for the range (ISO 8601, e.g. "2025-01-31").
limit integer no Maximum number of appointments to return (default: 25).
get_appointment Read

Retrieve a single appointment by ID. Returns full details including patient info, scheduled time, duration, and status.

Lua path
app.integrations.weave.get_appointment
Full name
weave.weave_get_appointment
ParameterTypeRequiredDescription
id string yes The unique appointment identifier.
list_messages Read

List patient messages from Weave with optional type filtering. Returns message records with sender, recipient, content previews, and status.

Lua path
app.integrations.weave.list_messages
Full name
weave.weave_list_messages
ParameterTypeRequiredDescription
limit integer no Maximum number of messages to return (default: 25).
page integer no Page number for pagination, 1-based (default: 1).
type string no Filter by message type (e.g. "sms", "email").
get_message Read

Retrieve a single message by ID. Returns full message content, sender, recipient, timestamps, and delivery status.

Lua path
app.integrations.weave.get_message
Full name
weave.weave_get_message
ParameterTypeRequiredDescription
id string yes The unique message identifier.
get_current_user Read

Get the currently authenticated Weave user profile. Returns user details including name, email, role, and organization info.

Lua path
app.integrations.weave.get_current_user
Full name
weave.weave_get_current_user
ParameterTypeRequiredDescription
No parameters.