| 1 | package calls |
| 2 | |
| 3 | import ( |
| 4 | access "amadan.net/oficina/agent-access.git" |
| 5 | "encoding/json" |
| 6 | ) |
| 7 | |
| 8 | func delegatedObject(props map[string]any, required ...string) json.RawMessage { |
| 9 | b, _ := json.Marshal(map[string]any{"type": "object", "properties": props, "required": required, "additionalProperties": false}) |
| 10 | return b |
| 11 | } |
| 12 | func delegatedString(max int) map[string]any { |
| 13 | return map[string]any{"type": "string", "maxLength": max} |
| 14 | } |
| 15 | func delegatedInput(props map[string]any, required ...string) json.RawMessage { |
| 16 | props["team"] = map[string]any{"type": "string", "minLength": 1, "maxLength": 64} |
| 17 | return delegatedObject(props, append([]string{"team"}, required...)...) |
| 18 | } |
| 19 | |
| 20 | var delegatedMeetingSchema = delegatedObject(map[string]any{"sqid": delegatedString(10), "title": delegatedString(200), "starts_at": map[string]any{"type": []string{"string", "null"}}, "ended_at": map[string]any{"type": []string{"string", "null"}}, "created_by": delegatedString(1024), "url": delegatedString(2048)}, "sqid", "title", "starts_at", "ended_at", "created_by", "url") |
| 21 | |
| 22 | func (a *app) delegatedOperations(team string) []access.Operation { |
| 23 | return []access.Operation{ |
| 24 | a.delegatedScheduleOperation(team), |
| 25 | {Name: "calls_list_meetings", Description: "List this team's meetings visible to a current member. Page with after/next_after; has_more says whether more remain. No invitation tokens or call media are returned.", Scope: "calls:read", ReadOnly: true, Idempotent: true, Input: delegatedInput(map[string]any{"after": map[string]any{"type": "integer", "minimum": 0, "maximum": int64(9223372036854775807)}, "limit": map[string]any{"type": "integer", "minimum": 1, "maximum": 100}}), Output: delegatedObject(map[string]any{"meetings": map[string]any{"type": "array", "items": delegatedMeetingSchema}, "next_after": map[string]any{"type": "integer", "minimum": 0}, "has_more": map[string]any{"type": "boolean"}}, "meetings", "next_after", "has_more"), Invoke: a.delegatedGuard(team, "calls:read", a.delegatedList)}, |
| 26 | {Name: "calls_get_meeting", Description: "Read a meeting and its member room URL. Does not disclose a guest invitation or grant access to call media.", Scope: "calls:read", ReadOnly: true, Idempotent: true, Input: delegatedInput(map[string]any{"sqid": delegatedString(10)}, "sqid"), Output: delegatedMeetingSchema, Invoke: a.delegatedGuard(team, "calls:read", a.delegatedGet)}, |
| 27 | {Name: "calls_create_meeting", Description: "Create a meeting, optionally with an RFC3339 starts_at including an explicit offset. Reuse a nonzero UUID client_id only for retries with identical fields. Returns the member room URL; creates no Calendar event and sends no invitations.", Scope: "calls:write", Idempotent: true, Input: delegatedInput(map[string]any{"client_id": map[string]any{"type": "string", "minLength": 36, "maxLength": 36}, "title": delegatedString(200), "starts_at": delegatedString(35)}, "client_id", "title"), Output: delegatedObject(map[string]any{"sqid": delegatedString(10), "url": delegatedString(2048), "invitations_sent": map[string]any{"const": false}}, "sqid", "url", "invitations_sent"), Invoke: a.delegatedGuard(team, "calls:write", a.delegatedCreate)}, |
| 28 | {Name: "calls_get_join_link", Description: "Retrieve an existing live guest invitation URL. This URL grants invitation access: share only with intended recipients. Requires calls:share. Never creates, replaces or sends a link; unavailable for ended meetings or old invitations without a recoverable token.", Scope: "calls:share", ReadOnly: true, Idempotent: true, Input: delegatedInput(map[string]any{"sqid": delegatedString(10)}, "sqid"), Output: delegatedObject(map[string]any{"sqid": delegatedString(10), "join_url": delegatedString(2048)}, "sqid", "join_url"), Invoke: a.delegatedGuard(team, "calls:share", a.delegatedJoinLink)}, |
| 29 | } |
| 30 | } |
| 31 | func AgentContracts() ([]access.Operation, error) { |
| 32 | a := &app{} |
| 33 | ops := a.delegatedOperations("contract") |
| 34 | scopes := []string{} |
| 35 | for _, o := range ops { |
| 36 | scopes = append(scopes, o.Scope) |
| 37 | } |
| 38 | r, err := access.NewRegistry(ops...) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | return r.List(access.Principal{Subject: "contract", Teams: []string{"contract"}, Scopes: scopes}), nil |
| 43 | } |
| 44 | |