title: sharedspace load: requirelib("sharedspace");
A shared space is an area where multiple different users can share texts, images, files and collaboratively edited documents together - the collaboration backbone behind chat-style apps, document collaboration and MeetRoom meetings. Every space carries:
"open" (default - the random space ID acts as the
capability, anyone who knows it can read and post), "public"
(discoverable via listPublicSpaces, any logged-in user can self-join)
or "private" (members only, invited by the owner or a space admin);owner / admin / member;Web clients get the same feature set over /system/sharedspace/* and a
realtime WebSocket channel (/system/sharedspace/ws), so items and
document patches posted from AGI appear live in connected clients.
MeetRoom binds one space to every meeting room (see the meetroom API), so
this library is also how scripts read a live meeting's chat and post
messages or files into it.
sharedspace.createSpace(name) → objectCreate a new space owned by the calling user. Returns
{ spaceid, name, owner, items, createdat }.
requirelib("sharedspace");
var space = sharedspace.createSpace("Design sync");
sendJSONResp(space);
sharedspace.listMySpaces() → arrayList the spaces owned by the calling user (same fields as createSpace).
sharedspace.getSpaceInfo(spaceid) → objectDescribe a space by ID. Returns { exists: false } for unknown IDs.
sharedspace.addText(spaceid, text) → stringPost a text snippet (clipped to 4000 characters) into the space. Returns the
new item ID; throws a SharedSpaceError on failure.
sharedspace.addFile(spaceid, vpath) → stringCopy a file from the calling user's storage into the space. Files with a
raster-image extension (png / jpg / jpeg / gif / webp / bmp) are stored as
image items, everything else as file. Returns the new item ID.
requirelib("sharedspace");
var itemid = sharedspace.addFile(spaceid, "user:/Photo/cat.png");
sharedspace.notifyMembers(spaceid, title, message, priority, usernames) → numberRaise a notification to fellow members of a space through the ArozOS
notification system. Membership-scoped: only a member (or space manager) may
notify, and only current members can be reached, so this cannot be used to
spam arbitrary users (no admin permission required, unlike
notification.sendToUser). Members currently connected to the space's
realtime channel are skipped, since they already receive the live message.
Delivery per recipient follows that user's own notification preferences
(desktop, Telegram, email, webhook).
message, priority ("low" / "medium" / "high", default "medium")
and usernames are optional. When usernames (an array) is omitted every
other member is notified; when given, the recipients are narrowed to that set
intersected with the current members. Returns the number of members actually
notified; throws a SharedSpaceError on error.
requirelib("sharedspace");
//Notify everyone else in the space
sharedspace.notifyMembers(spaceid, "New message", "Alice: are we still on?");
//Notify just two members, at high priority
sharedspace.notifyMembers(spaceid, "Alice in #plan", "@bob @carol ping", "high", ["bob", "carol"]);
sharedspace.listItems(spaceid) → arrayChronological list of items:
{ itemid, type, name, text, size, uploader, origin, time }. type is
"text", "image" or "file"; text is only filled for text items.
sharedspace.getText(spaceid, itemid) → stringRead the content of a text item.
sharedspace.saveFileTo(spaceid, itemid, destVpath) → boolCopy an image / file item into the calling user's storage.
sharedspace.removeItem(spaceid, itemid) → boolRemove an item. Only the item's uploader, a space admin or the space owner may remove it.
sharedspace.deleteSpace(spaceid) → boolDelete a space and all its items. Space owner or a space admin only.
sharedspace.createSpaceAdvanced(name, options) → objectCreate a space with options: { access, persistent, metadata }. Returns the
space descriptor ({ spaceid, name, owner, access, persistent, items, docs,
members, metadata, createdat } - the same shape every listing below uses),
or throws a SharedSpaceError when e.g. persistence is disabled by the
administrator.
requirelib("sharedspace");
var space = sharedspace.createSpaceAdvanced("Team chat", {
access: "private",
persistent: true,
metadata: { purpose: "chat" }
});
sharedspace.listPublicSpaces() → arrayThe public space directory (descriptors of every "public" space).
sharedspace.listJoinedSpaces() → arrayDescriptors of every space the calling user belongs to (owner, admin or
member). listMySpaces() remains the owned-only subset.
sharedspace.joinSpace(spaceid) / sharedspace.leaveSpace(spaceid) → boolSelf-join a public (or open) space as a member / leave a space. Private
spaces are invite-only, so joinSpace fails on them.
sharedspace.setAccess(spaceid, access) → boolChange the access mode ("open", "public" or "private"). Managers only.
sharedspace.setMeta(spaceid, key, value) / sharedspace.getMeta(spaceid) → bool / objectSet (empty value deletes) or read the space metadata. Writing requires manager rights; reading requires read access.
sharedspace.addMember(spaceid, username, role) → boolInvite a user with role "admin" or "member" (default). Managers only.
sharedspace.removeMember(spaceid, username) → boolRemove a member (managers) or leave (self). The owner cannot be removed.
sharedspace.listMembers(spaceid) → objectMember map { username: role, ... }. Members and managers only.
sharedspace.createDoc(spaceid, name) → objectCreate a collaborative document. Returns the document snapshot
{ docid, name, creator, revision, content, createdat, updatedat, updatedby }.
sharedspace.listDocs(spaceid) → arrayDocument snapshots without their content.
sharedspace.getDoc(spaceid, docid) → objectOne document with its full content - also the recovery path after an update conflict.
sharedspace.updateDoc(spaceid, docid, baserev, content) → objectCompare-and-swap update: the new content replaces the document body only
when baserev matches the document's current revision. Returns
{ ok: true, revision } on success or
{ ok: false, conflict: true, revision } when someone else updated the
document first - re-fetch with getDoc, merge your change and retry.
Debounce saves (~500ms): every accepted revision is one database write, and
live WebSocket clients receive each revision as a patch frame.
requirelib("sharedspace");
var doc = sharedspace.getDoc(spaceid, docid);
var result = sharedspace.updateDoc(spaceid, docid, doc.revision, doc.content + "\nAppended by AGI");
if (result.conflict) {
// someone got there first: re-fetch, rebase, retry
}
sharedspace.deleteDoc(spaceid, docid) → boolDelete a document. Creator or space managers only.