* Find user IDs for the organization that owns an agent URL. * Looks up member_profiles where the agents JSONB contains the URL, * then finds org members to notify.
(agentUrl: string)
| 35 | * then finds org members to notify. |
| 36 | */ |
| 37 | async function resolveAgentOwnerUserIds(agentUrl: string): Promise<string[]> { |
| 38 | try { |
| 39 | const result = await query( |
| 40 | `SELECT om.workos_user_id |
| 41 | FROM member_profiles mp |
| 42 | JOIN organization_memberships om |
| 43 | ON om.workos_organization_id = mp.workos_organization_id |
| 44 | WHERE mp.agents @> $1::jsonb |
| 45 | LIMIT 5`, |
| 46 | [JSON.stringify([{ url: agentUrl }])], |
| 47 | ); |
| 48 | return result.rows.map((r: any) => r.workos_user_id); |
| 49 | } catch (error) { |
| 50 | logger.debug({ error, agentUrl }, 'Could not resolve agent owner'); |
| 51 | return []; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Extract a short agent name from the URL for display. |
no test coverage detected