Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/PrinceOfCookies/CookieOS/llms.txt

Use this file to discover all available pages before exploring further.

The system utilities in cosUtils provide the glue between CookieOS programs and the underlying CC:Tweaked environment. They handle time and date formatting in both 12-hour and 24-hour styles, timestamped logging to the OS log file, safe detection of monitor and modem peripherals, elapsed-time conversion, library introspection, and a fully integrated Gemini AI chat endpoint with a built-in modded-Minecraft persona.

cosUtils.getTime(timeFormat, hourMinOnly)

Returns the current date and time as a formatted string, or as individual components for clock display. The format is derived from the timeFormat argument or — when omitted — from the timeFormat CC:Tweaked setting (defined with a default of "12"). Invalid values fall back to 12-hour format. All numeric components are zero-padded to two digits.
timeFormat
string
default:"settings.get('timeFormat')"
"12" for 12-hour AM/PM format, or "24" for 24-hour format. When omitted, reads the timeFormat setting.
hourMinOnly
boolean
default:"false"
If true, returns three separate values — hour, minute, ampm — instead of a full date-time string. Useful for rendering a compact clock.
Returns either a string in the format "YYYY-MM-DD HH:MM:SS AM" (or "YYYY-MM-DD HH:MM:SS" for 24-hour), or three values hour (string), minute (string), ampm (string) when hourMinOnly is true.
-- Full date-time string (12-hour)
local dt = cosUtils.getTime("12")
print(dt) -- "2024-01-15 03:45:22 PM"

-- Full date-time string (24-hour)
local dt24 = cosUtils.getTime("24")
print(dt24) -- "2024-01-15 15:45:22  "

-- Just the clock components for a compact display
local hour, minute, ampm = cosUtils.getTime("12", true)
print(hour .. ":" .. minute .. " " .. ampm) -- "03:45 PM"

-- Read format from the timeFormat setting
local t = cosUtils.getTime()

cosUtils.logToOS(msg)

Appends a timestamped line to the OS log file at os/data/OS.log. If the file does not exist it is created ("w" mode); if it does, the line is appended ("a" mode). The timestamp is appended in square brackets using cosUtils.getTime(). If the file grows beyond 50,000 bytes the log is cleared and a single reset notice is written.
msg
string
The message to log. A timestamp is appended automatically.
cosUtils.logToOS("User opened File Explorer")
-- Appends to os/data/OS.log:
-- "User opened File Explorer [2024-01-15 03:45:22 PM]"
The BSOD function calls cosUtils.logToOS("[BSOD] " .. err) automatically before rebooting, so crash details are always captured in the log.

cosUtils.isMonitorHere()

Searches for a monitor peripheral using peripheral.find(). Returns the monitor peripheral object if one is attached, or nil if none is found.
local mon = cosUtils.isMonitorHere()
if mon then
    mon.setTextScale(0.5)
    mon.write("Hello from the monitor!")
end

cosUtils.isModemHere()

Searches for a modem peripheral and verifies that it exposes a transmit method (confirming it is a functional wireless or wired modem rather than a stub). Returns true, modem if a valid modem is found, or false if none is attached.
local hasModem, modem = cosUtils.isModemHere()
if hasModem then
    modem.open(65535)
    modem.transmit(65535, 65535, "ping")
else
    print("No modem attached")
end

cosUtils.convertToSeconds(previous, current)

Converts the difference between two os.epoch("utc") values into a seconds string formatted to three decimal places. os.epoch returns milliseconds in CC:Tweaked, so the function divides the raw difference by 0.01 (i.e. multiplies by 100 then divides by 1000, which equals dividing by 0.01) to produce seconds.
previous
number
The earlier os.epoch("utc") value.
current
number
The later os.epoch("utc") value.
Returns a string with three decimal places, e.g. "1.500".
local start = os.epoch("utc")
os.sleep(1.5)
local elapsed = cosUtils.convertToSeconds(start, os.epoch("utc"))
print(elapsed .. "s") -- e.g. "1.500s"

cosUtils.getSizeOfCosUtils()

Counts the number of function-type values currently registered in the cosUtils table. Useful for verifying that all expected functions loaded correctly after boot. Returns a number.
local count = cosUtils.getSizeOfCosUtils()
print(count .. " functions loaded") -- e.g. "35 functions loaded"

cosUtils.Gemini(query, history)

Sends a text query to the Google Gemini API (gemini-1.5-flash-latest) and returns the AI’s response trimmed to a maximum of 600 characters. The AI persona is Davey — a player on a modded Minecraft server who is knowledgeable about Create, CC:Tweaked, Mekanism, Powah, Mystical Agriculture, and general programming. The model is configured with maxOutputTokens = 250 and temperature = 0.7. Conversation history is supported: pass a table of "Speaker: message" strings. Lines starting with "Davey: " are mapped to the model role; all other lines are treated as user messages.
query
string
The current user message or question. An error is returned if the query is empty or whitespace-only.
history
table
default:"nil"
Optional ordered table of prior conversation lines in "Speaker: message" format. Pass nil or omit for a fresh conversation.
Returns response (string) on success, or nil, errorMessage (string) on failure (network error, API error, blocked prompt, etc.).
The API key must be configured before use. Open apis/cUtils.lua and replace the placeholder on the line inside cosUtils.Gemini:
-- In apis/cUtils.lua, replace this line in cosUtils.Gemini:
local geminiApiKey = "YOUR_GEMINI_API_KEY"
-- with your actual key from https://aistudio.google.com/
Calling the function with the placeholder key prints an error and returns nil, "Gemini API key not configured" without making any network request.
-- Simple one-shot query
local response, err = cosUtils.Gemini("What is Create mod?")
if response then
    print(response)
else
    print("Error: " .. err)
end

-- With conversation history for multi-turn chat
local history = {
    "Player123: What is Create mod?",
    "Davey: Create is a tech mod focused on rotational power and automation..."
}
local response2, err2 = cosUtils.Gemini("How do I make a windmill?", history)
if response2 then
    print(response2)
end

Build docs developers (and LLMs) love