This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/packages/chat/script.star
Jeffrey Smith 6931b125a4
All checks were successful
CI/CD / detect-changes (push) Successful in 3s
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m28s
CI/CD / test-sqlite (push) Successful in 2m42s
CI/CD / build-and-deploy (push) Successful in 1m8s
Feat v0.5.2 chat surface (#32)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
2026-03-30 15:25:33 +00:00

40 lines
1.1 KiB
Plaintext

# Chat Surface — Starlark Backend (v0.1.0)
#
# Thin surface layer on top of chat-core library.
# Only handles typing indicator broadcast — all CRUD is
# delegated to chat-core's own API routes.
#
# Modules: json, realtime
def _resp(status, data):
return {"status": status, "body": json.encode(data), "headers": {"Content-Type": "application/json"}}
def on_request(req):
path = req["path"]
method = req["method"]
user_id = req.get("user_id", "")
# POST /typing/:conversation_id — broadcast typing indicator
if method == "POST" and path.startswith("/typing/"):
cid = path[len("/typing/"):]
if not cid:
return _resp(400, {"error": "conversation_id required"})
body = json.decode(req.get("body", "{}"))
display_name = str(body.get("display_name", ""))
realtime.publish(
"conversation:" + cid,
"typing",
{
"participant_id": user_id,
"display_name": display_name,
"conversation_id": cid,
},
)
return _resp(200, {"ok": True})
return _resp(404, {"error": "not found"})