Osy#the first language built for agents
Agents firstAgentic appsWorkflowsDurable Execution — built inSecurityTestingThe editorThe UI modelOne program

Reference

Function

61 pages.

Functions (the unit of work)

A function is where your app's logic lives — a top-level unit of work, written like a C# method, that runs on the server. It is transactional by…

(int)x — casts

A C-style cast converts between the numeric types. It truncates toward zero, and it is checked — a value the target type cannot hold fails loudly…

++ / -- (increment / decrement)

Increment or decrement a numeric variable or property by one. In statement position (i++;) and as a for increment the pre- and post-forms are…

Array literals

An array literal [a, b, c] is a value: a list you can return, assign, pass as an argument, or supply as a UI prop. Its element type is inferred from…

Building and reading a TimeSpan

How to build a duration and read it back. Construct one with new TimeSpan(...) or a TimeSpan.FromX factory (including TimeSpan.FromMilliseconds)…

Compound assignment (+= -= *= /= %= ??=)

Update a variable or property in place: x op= y is shorthand for x = x op y. Arithmetic forms need a numeric lvalue; ??= assigns only when the left…

Constructing a DateTime, DateOnly, or TimeOnly

Build a temporal value from its components. DateTime.New takes a date, optionally with a time (defaulting to midnight); DateOnly.New takes a calendar…

Contains, StartsWith, EndsWith

Tests whether a string contains, begins with, or ends with another string. The match is case-sensitive and literal — like C#'s String.Contains, the…

Convert

Explicit conversion between types — number to text, text to number, a Guid to its text form. Osy# will not convert silently where information could…

Crypto.Encrypt and Crypto.Decrypt

Encrypt and decrypt values under your app's key, which the platform mints, protects, and rotates for you. There is no key parameter — you never…

Crypto.HmacSha256Hex and Crypto.FixedTimeEquals

HMAC-SHA-256 authenticates a message under a shared key — proving it came from a key holder and was not altered, which a plain hash cannot do. Always…

Crypto.Md5Hex

MD5 of a string's UTF-8 bytes rendered as 32-character lowercase hex — the canonical C# fingerprint form. Deterministic, so it pushes down into SQL…

Crypto.Sha256Hex

SHA-256 of a string's UTF-8 bytes as 64-character lowercase hex — the secure default hash. Deterministic, so it pushes down into SQL. Use it wherever…

Current time (DateTime.UtcNow, DurableClock.Now)

Read the current instant. `DateTime.UtcNow`/`Today` (and the platform-idiomatic `DurableClock.Now`/…) return the current time from the platform's…

Date arithmetic — AddDays, AddMonths, AddYears, AddHours, AddMinutes

Move a DateTime forward or back. AddDays/AddHours/AddMinutes take a fractional amount and are exact. AddMonths and AddYears are CALENDAR-aware and…

Enum.Label, Enum.Description, Enum.Name

Read the human-facing words of an enum value in code: its Label (the [Label] text, or the member name when there is none), its Description (the…

Enumerable.Range

A sequence of consecutive integers, count of them, starting at start. It is how you iterate by index — including in a render block, which has foreach…

Guid.Empty and Guid.NewGuid

The C# Guid statics. `Guid.Empty` is the all-zero Guid constant, spelled without parens; `Guid.NewGuid()` mints a fresh unique Guid. Guid.Empty…

List OrderBy (in-memory)

Sort a local List<T> in memory by a key selector, returning a NEW sorted List<T> (the source is untouched). Ascending or descending, stable, exactly…

List indexer

Positional get/set on a List<T> by integer index, exactly like C#'s List<T>.this[int]. The index must be an integer; the result is the element type…

LlmClient.Complete — a model's answer, once

`LlmClient.Complete(prompt)` asks a model a question and gives you the finished text. Use it when your code wants the answer as a value — to store…

LlmClient.Stream — a model's answer as it is written

`LlmClient.Stream(prompt)` gives you a model's answer in the pieces it was produced in, so a reader sees it being written instead of waiting for it…

Math.Abs, Math.Sign, Math.Min, Math.Max, Math.Clamp, Math.Truncate, Math.Pow, Math.Sqrt, Math.Sin, Math.Cos, Math.Tan

The numeric helpers, each returning the type C# says it returns. Abs, Min, Max and Clamp answer in the WIDEST of their arguments, so a decimal stays…

Numeric types & literal suffixes

The platform numeric types are int, long, decimal, and double. Literals follow C# exactly, suffixes (L, m, d) included: a bare decimal-point literal…

Reading a date — Year, Month, Day, Hour, Minute, Second, DayOfWeek, Date

Read a component off a DateTime — its year, month, day, hour, minute, second — or its day of the week (Sunday is 0), or truncate it to midnight with…

Regex

Matching, replacing and splitting with regular expressions. A pattern means the same thing wherever your code runs — the platform makes the browser…

String interpolation & format specifiers

Build a string from literal text and embedded expressions with $"…{expr}…". A hole may carry a .NET format specifier after a colon ({amount:F2})…

Text.ByteSize

Formats a byte count as the words a person reads — "0 B", "1.5 KB", "2.7 MB". Binary units (1024) with the conventional KB/MB/GB labels. An ordinary…

Text.Capitalize, Text.Replace, Text.Repeat, Text.Left, Text.Right

Produce a new string from an old one: upper-case the first letter, replace every occurrence of a substring, repeat it, or take characters from one…

Text.Concat

Joins a list of values into one string with NOTHING between the elements. It is Text.Join with no separator, and the same operation as string.Concat…

Text.IndexOf

The C# string.IndexOf: the index of the FIRST ordinal occurrence of a substring, or -1 if absent. The 3-arg overload resumes the forward search at…

Text.Join

Joins a list of values into one string, placing the separator between each pair. It is the inverse of Text.Split, and the same operation as…

Text.LastIndexOf

The C# string.LastIndexOf: the index of the LAST ordinal occurrence of a substring, or -1 if absent. The 3-arg overload starts the backward search at…

Text.Length, Text.IsEmpty, Text.IsBlank, Text.Contains, Text.StartsWith, Text.EndsWith

Ask a string a question without changing it: its length, whether it is empty or blank, and whether it contains, starts with, or ends with a piece of…

Text.Like

Matches a string against a wildcard pattern, where % stands for any run of characters and _ for exactly one. It is the only wildcard search in the…

Text.Split

The C# string.Split: breaks a string on a separator and returns the substrings as a List<string> — iterable with foreach and queryable with .Count /…

Text.TitleCase

Capitalises the first letter of each word and lower-cases the rest, leaving a word that is already entirely upper-case untouched so acronyms survive…

Text.TrimStart, Text.TrimEnd, Text.PadStart, Text.PadEnd

Trim whitespace from one end of a string, or pad it out to a width with a fill string. Trimming uses the full Unicode whitespace set. Padding never…

Text.Truncate

Shorten a string to at most maxLength characters — INCLUDING the ellipsis — cutting back to the last word boundary rather than mid-word. The bound…

Tuples and deconstruction

A function returns several values by declaring a tuple return type and returning a parenthesized list. The caller reads them by name (`t.ok`), or…

Typed locals

Locals can declare an explicit type instead of var; the declared type pins the binding. Literal initializers apply the C# constant conversion…

UnitOfWork

Every body accumulates its writes in a unit of work rather than sending them one at a time. UnitOfWork.Commit() makes everything accumulated so far…

async / await — why Osy# has neither

Osy# has no async and no Task. A function that calls out to the world is written like any other function — the engine suspends and resumes it around…

break / continue

break leaves the enclosing loop; continue skips the rest of this pass. Inside a switch, break leaves the SWITCH, not the loop around it — the one…

const

A value fixed at compile time and folded into the places it is used. Declare one at the TOP LEVEL to share it across the whole app, on a component…

execution side

Where a function runs. Osy# infers it from the body: a function that reads data runs on the server, a function that touches the router or the theme…

for

The C-style counting loop. Runs init once, then repeats the body while cond holds, running update after each pass. Any clause may be omitted; for…

foreach

Walks a collection — a query result, a list, or a parent's children. The normal way to iterate; reach for a for loop only when you need the index.

format specifiers

Formats a number to a string with a .NET format specifier — F2 for two decimal places, N0 for a grouped whole number, C for currency, P for a…

function

A function is a top-level unit of work, written like a C# method — a return type, a name, typed parameters, a body. It runs transactionally: the rows…

if / else

Conditional branching, exactly as in C#. The condition must be a bool — there is no truthiness, so a null or a number is not a condition.

nameof

The C# compile-time name fold: validates the symbol and folds to its simple-name string literal — the last identifier of the chain. Invalid symbols…

reading a secret's value (Secret.Name)

`Secret.Name` in a function body evaluates to the declared secret's value — the key itself, as a string, read at the moment it is used. It is how a…

switch

Branch on a value against constant case labels. Only the matched section runs (no fall-through); a default section handles the rest. break exits the…

switch expression

Choose a VALUE by matching a subject against patterns. Arms are tried in order and the first match wins. Patterns are a constant, a relational…

throw

Raises a fault. It ends the function immediately, and the rows the function wrote are discarded rather than half-written. The exception types are a…

try / catch / finally

Handles a fault. C#'s syntax, including typed catches, catch filters and finally. The rows written inside a try block that throws are discarded — so…

var

Declares a local whose type is inferred from its initializer, exactly as in C#. The local is still statically typed — var is about not repeating the…

verbatim strings (@"…")

`@"…"` is a string where a backslash is just a backslash. Nothing inside is an escape, `""` writes a single quote, and the text may run across lines…

while

Repeats while a bool condition holds. Reach for it when the number of iterations is not known up front — otherwise a foreach or a for loop says more.

yield — a function that produces results over time

A `stream<T>` function produces its results one at a time instead of all at once, and a `live var` bound to one renders each item the moment it…