oficina / calendar Public

Clone
git clone https://amadan.net/oficina/calendar

Plain git — no account needed to clone.

Download

Download this file

1package calendar
2
3import (
4 access "amadan.net/oficina/agent-access.git"
5 "encoding/json"
6)
7
8func agentObject(properties map[string]any, required ...string) json.RawMessage {
9 if required == nil {
10 required = []string{}
11 }
12 raw, _ := json.Marshal(map[string]any{"type": "object", "properties": properties, "required": required, "additionalProperties": false})
13 return raw
14}
15func agentString(max int) map[string]any { return map[string]any{"type": "string", "maxLength": max} }
16func agentID() map[string]any { return map[string]any{"type": "integer", "minimum": 1} }
17func agentInput(properties map[string]any, required ...string) json.RawMessage {
18 properties["team"] = map[string]any{"type": "string", "minLength": 1, "maxLength": 64}
19 return agentObject(properties, append([]string{"team"}, required...)...)
20}
21
22var agentEventSchema = agentObject(agentAttendeesOutput(map[string]any{
23 "id": agentID(), "calendar_id": agentID(), "title": agentString(MaxTitleLen), "location": agentString(MaxLocationLen), "notes": agentString(MaxNotesLen),
24 "all_day": map[string]any{"type": "boolean"}, "start_local": agentString(16), "end_local": agentString(16), "tz": agentString(128),
25 "start_utc": map[string]any{"type": "integer"}, "end_utc": map[string]any{"type": "integer"}, "sequence": map[string]any{"type": "integer"},
26 "kind": agentString(32), "status": agentString(32), "url": agentString(2048),
27}), "id", "calendar_id", "title", "location", "notes", "all_day", "start_local", "end_local", "tz", "start_utc", "end_utc", "sequence", "kind", "status", "url", "attendees")
28
29func (a *App) agentOperations(team string) []access.Operation {
30 return []access.Operation{
31 a.agentUpdateOperation(team),
32 {Name: "calendar_list", Description: "List calendars currently visible to the linked person, with their roles. Choose a calendar_id explicitly before creating an event.", Scope: "calendar:read", ReadOnly: true, Idempotent: true,
33 Input: agentInput(map[string]any{}), Output: agentObject(map[string]any{"calendars": map[string]any{"type": "array", "items": agentObject(map[string]any{"id": agentID(), "name": agentString(2048), "kind": agentString(32), "role": agentString(32)}, "id", "name", "kind", "role")}}, "calendars"), Invoke: a.agentGuard(team, "calendar:read", a.agentCalendars)},
34 {Name: "calendar_get_event", Description: "Read an event through the person's current calendar grant. Returns its time zone, canonical app URL and recorded attendee email addresses (never invited): at most 50, with attendees_more counting the rest.", Scope: "calendar:read", ReadOnly: true, Idempotent: true,
35 Input: agentInput(map[string]any{"id": agentID()}, "id"), Output: agentEventSchema, Invoke: a.agentGuard(team, "calendar:read", a.agentGetEvent)},
36 a.agentListEventsOperation(team),
37 {Name: "calendar_free_busy", Description: "Return complete busy spans across calendars the person can currently see. Supply RFC3339 start/end with offsets, at most 31 days. All-day events use the person's calendar time zone. Availability is advisory; creating an event does not reserve an otherwise free slot.", Scope: "calendar:read", ReadOnly: true, Idempotent: true,
38 Input: agentInput(map[string]any{"start": agentString(35), "end": agentString(35)}, "start", "end"), Output: agentObject(map[string]any{"tz": agentString(128), "busy": map[string]any{"type": "array", "items": agentObject(map[string]any{"start": agentString(35), "end": agentString(35)}, "start", "end")}}, "tz", "busy"), Invoke: a.agentGuard(team, "calendar:read", a.agentBusy)},
39 {Name: "calendar_create_event", Description: "Create a single event on an explicitly selected writable calendar, with the person's default reminder. Local times are YYYY-MM-DDTHH:MM with an IANA tz; all-day events use dates and an exclusive end. Ambiguous/nonexistent DST times are refused. Reuse client_id only to retry identical fields. Optional attendees are email addresses recorded on the event, never invited: Calendar emails nobody, and invitations_sent is always false.", Scope: "calendar:write", Idempotent: true,
40 Input: agentInput(map[string]any{"calendar_id": agentID(), "client_id": map[string]any{"type": "string", "minLength": 36, "maxLength": 36}, "title": agentString(MaxTitleLen), "location": agentString(MaxLocationLen), "notes": agentString(MaxNotesLen), "all_day": map[string]any{"type": "boolean"}, "start_local": agentString(16), "end_local": agentString(16), "tz": agentString(128), "kind": map[string]any{"enum": []string{KindMeeting, KindCommitment, KindNote}}, "status": map[string]any{"enum": []string{StatusConfirmed, StatusTentative}}, "attendees": agentAttendeesSchema()}, "calendar_id", "client_id", "title", "start_local", "end_local"),
41 Output: agentObject(map[string]any{"id": agentID(), "url": agentString(2048), "invitations_sent": map[string]any{"const": false}}, "id", "url", "invitations_sent"), Invoke: a.agentGuard(team, "calendar:write", a.agentCreateEvent)},
42 }
43}
44
45func AgentContracts() ([]access.Operation, error) {
46 a := &App{}
47 ops := a.agentOperations("contract")
48 scopes := []string{}
49 for _, op := range ops {
50 scopes = append(scopes, op.Scope)
51 }
52 registry, err := access.NewRegistry(ops...)
53 if err != nil {
54 return nil, err
55 }
56 return registry.List(access.Principal{Subject: "contract", Teams: []string{"contract"}, Scopes: scopes}), nil
57}
58