Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 3x 3x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 2x 2x 2x 2x 2x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 1x 1x 1x 1x 1x 3x 3x | import { BASE_URL } from '../api/types/endpoints';
export interface ActivityItem {
id: string;
team_id: string;
user_id: string;
summary: string;
file_path?: string;
source_snapshot_id?: string;
activity_type?: string;
created_at?: string;
display_name?: string; // User-friendly name (from user_profiles.name, email, or fallback)
user_email?: string; // User's email address from auth.users
}
export async function fetchTeamActivity(teamId: string, limit = 25): Promise<{ success: boolean; items?: ActivityItem[]; error?: string }>{
try {
const url = new URL(`${BASE_URL}/api/ai/feed`);
url.searchParams.set('team_id', teamId);
url.searchParams.set('limit', String(limit));
const res = await fetch(url.toString());
if (!res.ok) {
const txt = await res.text();
return { success: false, error: `HTTP ${res.status}: ${txt}` };
}
const data = await res.json();
return { success: true, items: Array.isArray(data) ? data : [] };
} catch (err: any) {
return { success: false, error: err?.message || String(err) };
}
}
/**
* Inserts a Live Share session event into the team activity feed via backend API
* @param teamId - The team ID
* @param userId - The user ID who started/joined the session
* @param eventType - Type of event: 'live_share_started' | 'live_share_joined'
* @param displayName - The display name of the user
* @param sessionId - Optional session ID for reference
* @param snapshotId - Optional snapshot ID for the initial workspace snapshot (used for started events)
* @param sessionLink - Optional session invite link for joining the session
* @returns Promise with success status
*/
export async function insertLiveShareActivity(
teamId: string,
userId: string,
eventType: 'live_share_started' | 'live_share_joined',
displayName: string,
sessionId?: string,
snapshotId?: string,
sessionLink?: string
): Promise<{ success: boolean; error?: string; summary?: string }> {
try {
const url = new URL(`${BASE_URL}/api/ai/live_share_event`);
const payload = {
event_type: eventType === 'live_share_started' ? 'started' : 'joined',
session_id: sessionId,
team_id: teamId,
user_id: userId,
display_name: displayName,
snapshot_id: snapshotId, // Include snapshot ID for linking to initial snapshot
session_link: sessionLink // Include session invite link
};
console.log('[TeamActivityService] Sending Live Share event to backend:', payload);
const res = await fetch(url.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!res.ok) {
const txt = await res.text();
console.error('[TeamActivityService] Error from backend:', txt);
return { success: false, error: `HTTP ${res.status}: ${txt}` };
}
const data = await res.json();
console.log('[TeamActivityService] Live Share activity inserted:', data);
return { success: true, summary: data.summary };
} catch (err: any) {
console.error('[TeamActivityService] Exception inserting Live Share activity:', err);
return { success: false, error: err?.message || String(err) };
}
}
/**
* Updates an existing Live Share Started event with the session invite link
* @param teamId - The team ID
* @param sessionId - The session ID
* @param sessionLink - The session invite link to add
* @returns Promise with success status
*/
export async function updateLiveShareActivityLink(
teamId: string,
sessionId: string,
sessionLink: string
): Promise<{ success: boolean; error?: string }> {
try {
const url = new URL(`${BASE_URL}/api/ai/live_share_update_link`);
const payload = {
team_id: teamId,
session_id: sessionId,
session_link: sessionLink
};
console.log('[TeamActivityService] Updating Live Share event with session link:', payload);
const res = await fetch(url.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!res.ok) {
const txt = await res.text();
console.error('[TeamActivityService] Error from backend:', txt);
return { success: false, error: `HTTP ${res.status}: ${txt}` };
}
const data = await res.json();
console.log('[TeamActivityService] Live Share activity link updated:', data);
return { success: true };
} catch (err: any) {
console.error('[TeamActivityService] Exception updating Live Share activity link:', err);
return { success: false, error: err?.message || String(err) };
}
}
/**
* Cleans up orphaned pinned Live Share Started events
* Unpins all pinned "Live Share Started" events for a team
* This is called when the extension initializes with no active session
* @param teamId - The team ID
* @returns Promise with success status
*/
export async function cleanupOrphanedPinnedEvents(
teamId: string
): Promise<{ success: boolean; error?: string }> {
try {
const url = new URL(`${BASE_URL}/api/ai/cleanup_orphaned_pins`);
const payload = {
team_id: teamId
};
console.log('[TeamActivityService] Cleaning up orphaned pinned events for team:', teamId);
const res = await fetch(url.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!res.ok) {
const txt = await res.text();
console.error('[TeamActivityService] Error from backend:', txt);
return { success: false, error: `HTTP ${res.status}: ${txt}` };
}
const data = await res.json();
console.log('[TeamActivityService] Orphaned events cleaned up:', data);
return { success: true };
} catch (err: any) {
console.error('[TeamActivityService] Exception cleaning up orphaned events:', err);
return { success: false, error: err?.message || String(err) };
}
}
/**
* Inserts a Live Share session end event with participant details via backend API
* @param teamId - The team ID
* @param userId - The user ID who hosted the session
* @param displayName - The display name of the host
* @param sessionId - The session ID
* @param durationMinutes - Duration of the session in minutes
* @param snapshotId - Optional snapshot ID containing git diff
* @returns Promise with success status
*/
export async function insertLiveShareSessionEnd(
teamId: string,
userId: string,
displayName: string,
sessionId: string,
durationMinutes: number,
snapshotId?: string
): Promise<{ success: boolean; error?: string; summary?: string }> {
try {
const url = new URL(`${BASE_URL}/api/ai/live_share_event`);
const payload = {
event_type: 'ended',
session_id: sessionId,
team_id: teamId,
user_id: userId,
display_name: displayName,
duration_minutes: durationMinutes,
snapshot_id: snapshotId // Link to file_snapshots row with git diff
};
console.log('[TeamActivityService] Sending Live Share session end to backend:', payload);
const res = await fetch(url.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!res.ok) {
const txt = await res.text();
console.error('[TeamActivityService] Error from backend:', txt);
return { success: false, error: `HTTP ${res.status}: ${txt}` };
}
const data = await res.json();
console.log('[TeamActivityService] Live Share session end inserted:', data);
return { success: true, summary: data.summary };
} catch (err: any) {
console.error('[TeamActivityService] Exception inserting Live Share session end:', err);
return { success: false, error: err?.message || String(err) };
}
}
/**
* Inserts a Live Share summary with git diff changes via backend API
* @param teamId - The team ID
* @param userId - The user ID who hosted the session
* @param displayName - The display name of the host
* @param sessionId - The session ID
* @param changes - Git diff output
* @returns Promise with success status and snapshot ID
*/
export async function insertLiveShareSummary(
teamId: string,
userId: string,
displayName: string,
sessionId: string,
changes: string
): Promise<{ success: boolean; error?: string; snapshotId?: string }> {
try {
const url = new URL(`${BASE_URL}/api/ai/live_share_summary`);
const payload = {
session_id: sessionId,
team_id: teamId,
user_id: userId,
display_name: displayName,
changes: changes
};
console.log('[TeamActivityService] Sending Live Share summary to backend');
const res = await fetch(url.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!res.ok) {
const txt = await res.text();
console.error('[TeamActivityService] Error from backend:', txt);
return { success: false, error: `HTTP ${res.status}: ${txt}` };
}
const data = await res.json();
console.log('[TeamActivityService] Live Share summary inserted:', data);
return { success: true, snapshotId: data.snapshot_id };
} catch (err: any) {
console.error('[TeamActivityService] Exception inserting Live Share summary:', err);
return { success: false, error: err?.message || String(err) };
}
}
/**
* Inserts a Participant Status event (users joined or left) into the team activity feed.
* Non-clickable informational event used to broadcast membership changes.
* @param teamId Team identifier
* @param initiatorUserId User performing the action (or the user who joined/left)
* @param joinedUserIds Array of user IDs that just joined (optional)
* @param leftUserIds Array of user IDs that just left (optional)
*/
export async function insertParticipantStatusEvent(
teamId: string,
initiatorUserId: string,
joinedUserIds: string[] = [],
leftUserIds: string[] = []
): Promise<{ success: boolean; error?: string }> {
try {
const url = new URL(`${BASE_URL}/api/ai/participant_status_event`);
const payload = {
team_id: teamId,
user_id: initiatorUserId,
joined: joinedUserIds,
left: leftUserIds
};
const res = await fetch(url.toString(), {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
if (res.ok) {
return { success: true };
}
// Fallback: insert directly via Supabase if backend route not available in deployment
const txt = await res.text();
console.warn('[TeamActivityService] Backend insert failed, trying Supabase fallback:', `HTTP ${res.status}: ${txt}`);
// Lazy import to avoid circular deps in webview bundle
const { getSupabase } = require('../auth/supabaseClient');
const { getOrInitDisplayName } = require('./profile-service');
const supabase = getSupabase();
// Compose simple header using initiator's display name (self-join/leave)
let headerParts: string[] = [];
if (joinedUserIds && joinedUserIds.length > 0) {
try {
const dn = await getOrInitDisplayName(true);
headerParts.push(`${dn.displayName} has joined the team`);
} catch {
headerParts.push('Joined: 1 member');
}
}
if (leftUserIds && leftUserIds.length > 0) {
try {
const dn = await getOrInitDisplayName(true);
headerParts.push(`${dn.displayName} has left the team`);
} catch {
headerParts.push('Left: 1 member');
}
}
const event_header = headerParts.join(' ; ');
const feed_row = {
team_id: teamId,
user_id: initiatorUserId,
event_header,
summary: null,
file_path: null,
source_snapshot_id: null,
activity_type: 'participant_status'
} as const;
const { error: insertErr } = await supabase
.from('team_activity_feed')
.insert(feed_row);
if (insertErr) {
console.error('[TeamActivityService] Supabase fallback insert failed:', insertErr);
return { success: false, error: insertErr.message };
}
return { success: true };
} catch (err: any) {
console.error('[TeamActivityService] Exception inserting participant status:', err);
return { success: false, error: err?.message || String(err) };
}
}
|