-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.ts
More file actions
68 lines (57 loc) · 1.78 KB
/
Copy pathnotifications.ts
File metadata and controls
68 lines (57 loc) · 1.78 KB
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
// kilocode_change - new file
import { z } from "zod"
import { KILO_API_BASE } from "./constants.js"
/**
* Kilo notification schema
*/
export const KilocodeNotificationSchema = z.object({
id: z.string(),
title: z.string(),
message: z.string(),
action: z
.object({
actionText: z.string(),
actionURL: z.string(),
})
.optional(),
showIn: z.array(z.string()).optional(),
})
export type KilocodeNotification = z.infer<typeof KilocodeNotificationSchema>
const NotificationsResponseSchema = z.object({
notifications: z.array(KilocodeNotificationSchema),
})
const NOTIFICATIONS_TIMEOUT_MS = 5000
/**
* Fetch notifications from Kilo API
*
* @param options - Configuration with token and optional organization ID
* @returns Array of notifications filtered for CLI display
*/
export async function fetchKilocodeNotifications(options: {
kilocodeToken?: string
kilocodeOrganizationId?: string
}): Promise<KilocodeNotification[]> {
const token = options.kilocodeToken
if (!token) return []
const url = `${KILO_API_BASE}/api/users/notifications`
try {
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
signal: AbortSignal.timeout(NOTIFICATIONS_TIMEOUT_MS),
})
if (!response.ok) return []
const json = await response.json()
const result = NotificationsResponseSchema.safeParse(json)
if (!result.success) return []
// Filter to show notifications meant for CLI (or no specific target)
// Accept "cli", "extension", or no showIn field (matches old Kilo CLI behavior)
return result.data.notifications.filter(
({ showIn }) => !showIn || showIn.includes("cli") || showIn.includes("extension"),
)
} catch {
return []
}
}