@@ -11259,21 +11259,6 @@ Use add_committee_leader to assign a leader.`;
1125911259 // MEMBERSHIP INVITE HANDLERS
1126011260 // ============================================
1126111261
11262- function actionToHeader ( action : string ) : string {
11263- switch ( action ) {
11264- case "invited" :
11265- return "Invitation sent" ;
11266- case "member_added" :
11267- return "Added to org" ;
11268- case "role_updated" :
11269- return "Role updated" ;
11270- case "no_change" :
11271- return "No change" ;
11272- default :
11273- return "Done" ;
11274- }
11275- }
11276-
1127711262 function formatRelativeDays ( d : Date ) : string {
1127811263 const diffMs = d . getTime ( ) - Date . now ( ) ;
1127911264 const days = Math . round ( diffMs / 86400000 ) ;
@@ -11537,126 +11522,11 @@ Use add_committee_leader to assign a leader.`;
1153711522 }
1153811523 } ) ;
1153911524
11540- handlers . set ( "add_member_to_org" , async ( input ) => {
11541- const email = ( ( input . email as string ) || "" ) . trim ( ) . toLowerCase ( ) ;
11542- const orgId = input . org_id as string ;
11543- const role = ( input . role as string ) ?? "member" ;
11544- const seatType = ( input . seat_type as string ) ?? "community_only" ;
11545-
11546- if ( ! email || ! email . includes ( "@" ) ) {
11547- return "❌ email is required (a valid email address)." ;
11548- }
11549- if ( ! orgId || ! orgId . startsWith ( "org_" ) ) {
11550- return "❌ org_id is required (org_…)." ;
11551- }
11552- if ( ! [ "member" , "admin" , "owner" ] . includes ( role ) ) {
11553- return `❌ role must be one of: member, admin, owner (got: ${ role } ).` ;
11554- }
11555- if ( ! [ "contributor" , "community_only" ] . includes ( seatType ) ) {
11556- return `❌ seat_type must be one of: contributor, community_only (got: ${ seatType } ).` ;
11557- }
11558-
11559- const adminUser = memberContext ?. workos_user ;
11560- if ( ! adminUser ) {
11561- return "❌ Cannot add member — no signed-in admin context." ;
11562- }
11563-
11564- const apiKey = process . env . ADMIN_API_KEY ;
11565- if ( ! apiKey ) {
11566- return "❌ ADMIN_API_KEY is not configured on the server." ;
11567- }
11568- // Match the base-URL precedence used by member-tools.ts:getBaseUrl —
11569- // BASE_URL (production) wins; otherwise PORT/CONDUCTOR_PORT for local.
11570- const baseUrl =
11571- process . env . BASE_URL ||
11572- `http://localhost:${
11573- process . env . PORT || process . env . CONDUCTOR_PORT || "3000"
11574- } `;
11575- const endpoint = `${ baseUrl } /api/organizations/${ encodeURIComponent (
11576- orgId ,
11577- ) } /members/by-email`;
11578-
11579- try {
11580- const response = await fetch ( endpoint , {
11581- method : "POST" ,
11582- headers : {
11583- "Content-Type" : "application/json" ,
11584- Authorization : `Bearer ${ apiKey } ` ,
11585- } ,
11586- body : JSON . stringify ( { email, role, seat_type : seatType } ) ,
11587- signal : AbortSignal . timeout ( 10000 ) ,
11588- } ) ;
11589- const data = ( await response . json ( ) . catch ( ( ) => ( { } ) ) ) as Record <
11590- string ,
11591- unknown
11592- > ;
11593- if ( ! response . ok ) {
11594- const errorMsg =
11595- ( data . message as string ) ||
11596- ( data . error as string ) ||
11597- `HTTP ${ response . status } ` ;
11598- logger . warn (
11599- { status : response . status , orgId, email, error : errorMsg } ,
11600- "add_member_to_org route returned non-OK" ,
11601- ) ;
11602- return `❌ Failed to add ${ email } to ${ orgId } : ${ errorMsg } ` ;
11603- }
11604-
11605- const action = data . action as string ;
11606- logger . info (
11607- {
11608- orgId,
11609- email,
11610- action,
11611- role,
11612- seatType,
11613- adminUserId : adminUser . workos_user_id ,
11614- } ,
11615- "Addie called add_member_to_org" ,
11616- ) ;
11617-
11618- // Mirror the route's response shape rather than reflecting the input —
11619- // e.g. the route may keep an existing seat_type when adding to an org
11620- // the user already has a seat in.
11621- const responseSeatType =
11622- ( data . seat_type as string | undefined ) ?? seatType ;
11623-
11624- let md = `## ${ actionToHeader ( action ) } \n\n` ;
11625- md += `**Email:** ${ email } \n` ;
11626- md += `**Org:** ${ orgId } \n` ;
11627-
11628- if ( action === "invited" ) {
11629- const invitation = data . invitation as
11630- | Record < string , unknown >
11631- | undefined ;
11632- const expiresAt = invitation ?. expires_at as string | undefined ;
11633- md += `**Invited as:** member (must be promoted after acceptance for higher roles)\n` ;
11634- md += `**Requested role:** ${ role } \n` ;
11635- md += `**Seat type:** ${ responseSeatType } \n` ;
11636- if ( expiresAt ) md += `**Invite expires:** ${ expiresAt . slice ( 0 , 10 ) } \n` ;
11637- if ( invitation ?. accept_invitation_url ) {
11638- md += `\nThey'll receive an email with a sign-up link.\n` ;
11639- }
11640- } else if ( action === "member_added" ) {
11641- md += `**Role:** ${ role } \n` ;
11642- md += `**Seat type:** ${ responseSeatType } \n` ;
11643- md += `\nThey already had a WorkOS account; added directly to the org.\n` ;
11644- } else if ( action === "role_updated" ) {
11645- const previousRole = data . previous_role as string | null | undefined ;
11646- md += `**New role:** ${ role } \n` ;
11647- md += `**Previous role:** ${ previousRole ?? "(none)" } \n` ;
11648- } else if ( action === "no_change" ) {
11649- md += `\nNo change — they already have role ${ role } .\n` ;
11650- } else {
11651- md += `**Action:** ${ action ?? "unknown" } \n` ;
11652- }
11653- return md ;
11654- } catch ( error ) {
11655- logger . error ( { error, orgId, email } , "Error calling members/by-email" ) ;
11656- return `❌ Failed to add member: ${
11657- error instanceof Error ? error . message : "Unknown error"
11658- } `;
11659- }
11525+ // The old HTTP adapter replaced its human caller with ADMIN_API_KEY.
11526+ // MemberContext supplies canonical person metadata, not an immutable exact
11527+ // credential/organization/epoch proof. Do not launder that into admin writes.
11528+ handlers . set ( "add_member_to_org" , async ( ) => {
11529+ return "❌ Organization membership changes require the signed-in organization management page. Addie cannot forward an exact authenticated actor for this operation." ;
1166011530 } ) ;
1166111531
1166211532 handlers . set ( "diagnose_signin_block" , async ( input ) => {
0 commit comments