@notifkit/mcp 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/tools/operations.d.ts +4 -0
- package/dist/tools/operations.d.ts.map +1 -0
- package/dist/tools/operations.js +54 -0
- package/dist/tools/operations.js.map +1 -0
- package/dist/tools/projects.d.ts +4 -0
- package/dist/tools/projects.d.ts.map +1 -0
- package/dist/tools/projects.js +88 -0
- package/dist/tools/projects.js.map +1 -0
- package/dist/tools/sending.d.ts +4 -0
- package/dist/tools/sending.d.ts.map +1 -0
- package/dist/tools/sending.js +375 -0
- package/dist/tools/sending.js.map +1 -0
- package/dist/tools/shared.d.ts +17 -0
- package/dist/tools/shared.d.ts.map +1 -0
- package/dist/tools/shared.js +110 -0
- package/dist/tools/shared.js.map +1 -0
- package/dist/tools/templates.d.ts +4 -0
- package/dist/tools/templates.d.ts.map +1 -0
- package/dist/tools/templates.js +149 -0
- package/dist/tools/templates.js.map +1 -0
- package/dist/tools/users.d.ts +4 -0
- package/dist/tools/users.d.ts.map +1 -0
- package/dist/tools/users.js +251 -0
- package/dist/tools/users.js.map +1 -0
- package/dist/tools/workflows.d.ts +4 -0
- package/dist/tools/workflows.d.ts.map +1 -0
- package/dist/tools/workflows.js +122 -0
- package/dist/tools/workflows.js.map +1 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +12 -1124
- package/dist/tools.js.map +1 -1
- package/package.json +1 -1
- package/src/tools/operations.ts +84 -0
- package/src/tools/projects.ts +131 -0
- package/src/tools/sending.ts +484 -0
- package/src/tools/shared.ts +129 -0
- package/src/tools/templates.ts +206 -0
- package/src/tools/users.ts +330 -0
- package/src/tools/workflows.ts +167 -0
- package/src/tools.ts +12 -1502
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CHANNELS, CONTACT_CHANNELS, handler } from "./shared.js";
|
|
3
|
+
export function registerUsersTools(server, api) {
|
|
4
|
+
server.registerTool("list_users", {
|
|
5
|
+
title: "List users",
|
|
6
|
+
description: "Page through the project's users with comprehensive filtering. Supports filtering by search " +
|
|
7
|
+
"keyword (external ID or email), segment tag, language, timezone, or channel contact. " +
|
|
8
|
+
"Results are paginated — pass the returned `nextCursor` back as `cursor`. For one known user " +
|
|
9
|
+
"prefer get_user, which also returns contacts and preferences.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
limit: z.number().int().min(1).max(200).optional().describe("Users per page."),
|
|
12
|
+
cursor: z
|
|
13
|
+
.string()
|
|
14
|
+
.optional()
|
|
15
|
+
.describe("Pagination cursor from a previous call's `nextCursor`."),
|
|
16
|
+
search: z
|
|
17
|
+
.string()
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("Filter users whose external ID or email contains this search keyword."),
|
|
20
|
+
segment: z.string().optional().describe("Only list users assigned to this segment tag."),
|
|
21
|
+
language: z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("Filter users by language tag, e.g. 'en', 'es', 'fr'."),
|
|
25
|
+
timezone: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Filter users by IANA timezone, e.g. 'Europe/London', 'America/New_York'."),
|
|
29
|
+
channel: z
|
|
30
|
+
.enum(CONTACT_CHANNELS)
|
|
31
|
+
.optional()
|
|
32
|
+
.describe("Only list users who have a registered contact for this channel " +
|
|
33
|
+
"(email, sms, push, webhook, telegram, discord, whatsapp, slack)."),
|
|
34
|
+
},
|
|
35
|
+
annotations: { title: "List users", readOnlyHint: true },
|
|
36
|
+
}, handler(async (args) => api.get("/v1/users", args)));
|
|
37
|
+
server.registerTool("get_user", {
|
|
38
|
+
title: "Get a user",
|
|
39
|
+
description: "Fetch one user with their contacts, segments, and notification preferences. Call this before " +
|
|
40
|
+
"sending to a single user when you need to know which channels they can actually be reached on.",
|
|
41
|
+
inputSchema: { id: z.string().min(1).describe("User id.") },
|
|
42
|
+
annotations: { title: "Get a user", readOnlyHint: true },
|
|
43
|
+
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.id)}/details`)));
|
|
44
|
+
server.registerTool("upsert_user", {
|
|
45
|
+
title: "Create or update a user",
|
|
46
|
+
description: "Create a user profile, or update an existing one with the same id. Sets contact targets, segment " +
|
|
47
|
+
"tags, timezone, and preferences in one call. Segments assigned here are what send_notification's " +
|
|
48
|
+
"`segment` targeting matches on. Timezone drives quiet-hours maths, so set it when known.",
|
|
49
|
+
inputSchema: {
|
|
50
|
+
id: z.string().min(1).describe("Your own stable user id, e.g. 'usr_123'."),
|
|
51
|
+
contacts: z
|
|
52
|
+
.array(z.object({
|
|
53
|
+
channel: z.enum(CHANNELS).describe("Contact delivery channel."),
|
|
54
|
+
target: z.string().min(1).describe("Destination address, phone, token, or URL."),
|
|
55
|
+
label: z.string().optional().describe("Friendly label for this contact."),
|
|
56
|
+
isPrimary: z
|
|
57
|
+
.boolean()
|
|
58
|
+
.optional()
|
|
59
|
+
.describe("Whether this is the primary contact for this channel."),
|
|
60
|
+
}))
|
|
61
|
+
.optional()
|
|
62
|
+
.describe("Array of user contacts across any supported channels (preferred over legacy email/phone/pushToken)."),
|
|
63
|
+
email: z
|
|
64
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
65
|
+
.optional()
|
|
66
|
+
.describe("One email address or several."),
|
|
67
|
+
phone: z
|
|
68
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
69
|
+
.optional()
|
|
70
|
+
.describe("One phone number or several, in E.164 form."),
|
|
71
|
+
pushToken: z
|
|
72
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
73
|
+
.optional()
|
|
74
|
+
.describe("One device push token or several."),
|
|
75
|
+
segments: z
|
|
76
|
+
.array(z.string().min(1))
|
|
77
|
+
.optional()
|
|
78
|
+
.describe("Segment tags to assign to this user."),
|
|
79
|
+
language: z
|
|
80
|
+
.string()
|
|
81
|
+
.optional()
|
|
82
|
+
.describe("BCP 47 language tag used to pick localised content."),
|
|
83
|
+
timezone: z
|
|
84
|
+
.string()
|
|
85
|
+
.optional()
|
|
86
|
+
.describe("IANA timezone, e.g. 'Europe/London'. Drives quiet hours."),
|
|
87
|
+
preferences: z
|
|
88
|
+
.object({
|
|
89
|
+
channels: z
|
|
90
|
+
.record(z.string(), z.boolean())
|
|
91
|
+
.optional()
|
|
92
|
+
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
93
|
+
topics: z.record(z.string(), z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
94
|
+
quietHours: z
|
|
95
|
+
.array(z.object({
|
|
96
|
+
start: z.string().describe("HH:MM, 24h, in the user's timezone."),
|
|
97
|
+
end: z.string().describe("HH:MM, 24h, in the user's timezone."),
|
|
98
|
+
}))
|
|
99
|
+
.optional()
|
|
100
|
+
.describe("Windows during which non-critical sends are deferred."),
|
|
101
|
+
})
|
|
102
|
+
.optional()
|
|
103
|
+
.describe("Consent and quiet-hours settings."),
|
|
104
|
+
},
|
|
105
|
+
annotations: { title: "Create or update a user", readOnlyHint: false, idempotentHint: true },
|
|
106
|
+
}, handler(async (args) => api.post("/v1/users", args)));
|
|
107
|
+
server.registerTool("update_user", {
|
|
108
|
+
title: "Update a user",
|
|
109
|
+
description: "Partially update an existing user profile (e.g. language, timezone, segment tags, preferences, or append new contacts) without replacing unspecified fields.",
|
|
110
|
+
inputSchema: {
|
|
111
|
+
id: z.string().min(1).describe("User id."),
|
|
112
|
+
contacts: z
|
|
113
|
+
.array(z.object({
|
|
114
|
+
channel: z.enum(CHANNELS).describe("Contact delivery channel."),
|
|
115
|
+
target: z.string().min(1).describe("Destination address, phone, token, or URL."),
|
|
116
|
+
label: z.string().optional().describe("Friendly label for this contact."),
|
|
117
|
+
isPrimary: z
|
|
118
|
+
.boolean()
|
|
119
|
+
.optional()
|
|
120
|
+
.describe("Whether this is the primary contact for this channel."),
|
|
121
|
+
}))
|
|
122
|
+
.optional()
|
|
123
|
+
.describe("Array of user contacts across any supported channels to append or update."),
|
|
124
|
+
email: z
|
|
125
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
126
|
+
.optional()
|
|
127
|
+
.describe("One email address or several."),
|
|
128
|
+
phone: z
|
|
129
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
130
|
+
.optional()
|
|
131
|
+
.describe("One phone number or several, in E.164 form."),
|
|
132
|
+
pushToken: z
|
|
133
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
134
|
+
.optional()
|
|
135
|
+
.describe("One device push token or several."),
|
|
136
|
+
segments: z
|
|
137
|
+
.array(z.string().min(1))
|
|
138
|
+
.optional()
|
|
139
|
+
.describe("Segment tags to assign to this user."),
|
|
140
|
+
language: z
|
|
141
|
+
.string()
|
|
142
|
+
.optional()
|
|
143
|
+
.describe("BCP 47 language tag used to pick localised content."),
|
|
144
|
+
timezone: z
|
|
145
|
+
.string()
|
|
146
|
+
.optional()
|
|
147
|
+
.describe("IANA timezone, e.g. 'Europe/London'. Drives quiet hours."),
|
|
148
|
+
preferences: z
|
|
149
|
+
.object({
|
|
150
|
+
channels: z
|
|
151
|
+
.record(z.string(), z.boolean())
|
|
152
|
+
.optional()
|
|
153
|
+
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
154
|
+
topics: z.record(z.string(), z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
155
|
+
quietHours: z
|
|
156
|
+
.array(z.object({
|
|
157
|
+
start: z.string().describe("HH:MM, 24h, in the user's timezone."),
|
|
158
|
+
end: z.string().describe("HH:MM, 24h, in the user's timezone."),
|
|
159
|
+
}))
|
|
160
|
+
.optional()
|
|
161
|
+
.describe("Windows during which non-critical sends are deferred."),
|
|
162
|
+
})
|
|
163
|
+
.optional()
|
|
164
|
+
.describe("Consent and quiet-hours settings."),
|
|
165
|
+
},
|
|
166
|
+
annotations: { title: "Update a user", readOnlyHint: false, idempotentHint: true },
|
|
167
|
+
}, handler(async ({ id, ...body }) => api.patch(`/v1/users/${encodeURIComponent(id)}`, body)));
|
|
168
|
+
server.registerTool("delete_user", {
|
|
169
|
+
title: "Delete a user",
|
|
170
|
+
description: "Permanently delete a user profile and all associated contacts and preferences by user id.",
|
|
171
|
+
inputSchema: {
|
|
172
|
+
id: z.string().min(1).describe("User id to delete."),
|
|
173
|
+
},
|
|
174
|
+
annotations: {
|
|
175
|
+
title: "Delete a user",
|
|
176
|
+
readOnlyHint: false,
|
|
177
|
+
destructiveHint: true,
|
|
178
|
+
idempotentHint: true,
|
|
179
|
+
},
|
|
180
|
+
}, handler(async (args) => {
|
|
181
|
+
await api.delete(`/v1/users/${encodeURIComponent(args.id)}`);
|
|
182
|
+
return `Deleted user ${args.id}.`;
|
|
183
|
+
}));
|
|
184
|
+
server.registerTool("get_user_contacts", {
|
|
185
|
+
title: "Get user contacts",
|
|
186
|
+
description: "Fetch all registered contact addresses and tokens for a specific user.",
|
|
187
|
+
inputSchema: {
|
|
188
|
+
userId: z.string().min(1).describe("User id."),
|
|
189
|
+
},
|
|
190
|
+
annotations: { title: "Get user contacts", readOnlyHint: true },
|
|
191
|
+
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/contacts`)));
|
|
192
|
+
server.registerTool("add_user_contact", {
|
|
193
|
+
title: "Add a contact to a user",
|
|
194
|
+
description: "Add one addressable target (email address, phone number, push token, or webhook URL) to an " +
|
|
195
|
+
"existing user without replacing their other contacts. Prefer this over upsert_user when adding a " +
|
|
196
|
+
"second device or address to someone who already exists.",
|
|
197
|
+
inputSchema: {
|
|
198
|
+
userId: z.string().min(1).describe("Id of the user to add the contact to."),
|
|
199
|
+
channel: z.enum(CONTACT_CHANNELS).describe("Channel this target belongs to."),
|
|
200
|
+
target: z.string().min(1).describe("The address itself: email, phone, push token, or URL."),
|
|
201
|
+
},
|
|
202
|
+
annotations: { title: "Add a contact to a user", readOnlyHint: false },
|
|
203
|
+
}, handler(async ({ userId, ...body }) => api.post(`/v1/users/${encodeURIComponent(userId)}/contacts`, body)));
|
|
204
|
+
server.registerTool("delete_user_contact", {
|
|
205
|
+
title: "Delete a user contact",
|
|
206
|
+
description: "Remove one contact destination (email, phone, push token, or webhook URL) from a user profile.",
|
|
207
|
+
inputSchema: {
|
|
208
|
+
userId: z.string().min(1).describe("User id."),
|
|
209
|
+
channel: z.enum(CONTACT_CHANNELS).describe("Channel of the contact to delete."),
|
|
210
|
+
target: z.string().min(1).describe("The address/number/token/URL to remove."),
|
|
211
|
+
},
|
|
212
|
+
annotations: {
|
|
213
|
+
title: "Delete a user contact",
|
|
214
|
+
readOnlyHint: false,
|
|
215
|
+
destructiveHint: true,
|
|
216
|
+
idempotentHint: true,
|
|
217
|
+
},
|
|
218
|
+
}, handler(async (args) => {
|
|
219
|
+
await api.delete(`/v1/users/${encodeURIComponent(args.userId)}/contacts/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`);
|
|
220
|
+
return `Deleted ${args.channel} contact '${args.target}' for user ${args.userId}.`;
|
|
221
|
+
}));
|
|
222
|
+
server.registerTool("get_user_preferences", {
|
|
223
|
+
title: "Get user preferences",
|
|
224
|
+
description: "Fetch notification channel/topic opt-in preferences and quiet hours for a user.",
|
|
225
|
+
inputSchema: {
|
|
226
|
+
userId: z.string().min(1).describe("User id."),
|
|
227
|
+
},
|
|
228
|
+
annotations: { title: "Get user preferences", readOnlyHint: true },
|
|
229
|
+
}, handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/preferences`)));
|
|
230
|
+
server.registerTool("update_user_preferences", {
|
|
231
|
+
title: "Update user preferences",
|
|
232
|
+
description: "Update notification channel/topic opt-ins and quiet hours settings for a user.",
|
|
233
|
+
inputSchema: {
|
|
234
|
+
userId: z.string().min(1).describe("User id."),
|
|
235
|
+
channels: z
|
|
236
|
+
.record(z.string(), z.boolean())
|
|
237
|
+
.optional()
|
|
238
|
+
.describe("Per-channel opt-in map, e.g. { email: true, sms: false }."),
|
|
239
|
+
topics: z.record(z.string(), z.boolean()).optional().describe("Per-topic opt-in map."),
|
|
240
|
+
quietHours: z
|
|
241
|
+
.array(z.object({
|
|
242
|
+
start: z.string().describe("HH:MM, 24h, in the user's timezone."),
|
|
243
|
+
end: z.string().describe("HH:MM, 24h, in the user's timezone."),
|
|
244
|
+
}))
|
|
245
|
+
.optional()
|
|
246
|
+
.describe("Windows during which non-critical sends are deferred."),
|
|
247
|
+
},
|
|
248
|
+
annotations: { title: "Update user preferences", readOnlyHint: false, idempotentHint: true },
|
|
249
|
+
}, handler(async ({ userId, ...preferences }) => api.patch(`/v1/users/${encodeURIComponent(userId)}/preferences`, preferences)));
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=users.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../src/tools/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAElE,MAAM,UAAU,kBAAkB,CAAC,MAAiB,EAAE,GAAgB;IACpE,MAAM,CAAC,YAAY,CACjB,YAAY,EACZ;QACE,KAAK,EAAE,YAAY;QACnB,WAAW,EACT,8FAA8F;YAC9F,uFAAuF;YACvF,8FAA8F;YAC9F,+DAA+D;QACjE,WAAW,EAAE;YACX,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YAC9E,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CAAC,wDAAwD,CAAC;YACrE,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CAAC,uEAAuE,CAAC;YACpF,OA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NotifkitApi } from \"../client.js\";\nimport { CHANNELS, CONTACT_CHANNELS, handler } from \"./shared.js\";\n\nexport function registerUsersTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"list_users\",\n {\n title: \"List users\",\n description:\n \"Page through the project's users with comprehensive filtering. Supports filtering by search \" +\n \"keyword (external ID or email), segment tag, language, timezone, or channel contact. \" +\n \"Results are paginated — pass the returned `nextCursor` back as `cursor`. For one known user \" +\n \"prefer get_user, which also returns contacts and preferences.\",\n inputSchema: {\n limit: z.number().int().min(1).max(200).optional().describe(\"Users per page.\"),\n cursor: z\n .string()\n .optional()\n .describe(\"Pagination cursor from a previous call's `nextCursor`.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter users whose external ID or email contains this search keyword.\"),\n segment: z.string().optional().describe(\"Only list users assigned to this segment tag.\"),\n language: z\n .string()\n .optional()\n .describe(\"Filter users by language tag, e.g. 'en', 'es', 'fr'.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"Filter users by IANA timezone, e.g. 'Europe/London', 'America/New_York'.\"),\n channel: z\n .enum(CONTACT_CHANNELS)\n .optional()\n .describe(\n \"Only list users who have a registered contact for this channel \" +\n \"(email, sms, push, webhook, telegram, discord, whatsapp, slack).\",\n ),\n },\n annotations: { title: \"List users\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/users\", args)),\n );\n\n server.registerTool(\n \"get_user\",\n {\n title: \"Get a user\",\n description:\n \"Fetch one user with their contacts, segments, and notification preferences. Call this before \" +\n \"sending to a single user when you need to know which channels they can actually be reached on.\",\n inputSchema: { id: z.string().min(1).describe(\"User id.\") },\n annotations: { title: \"Get a user\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.id)}/details`)),\n );\n\n server.registerTool(\n \"upsert_user\",\n {\n title: \"Create or update a user\",\n description:\n \"Create a user profile, or update an existing one with the same id. Sets contact targets, segment \" +\n \"tags, timezone, and preferences in one call. Segments assigned here are what send_notification's \" +\n \"`segment` targeting matches on. Timezone drives quiet-hours maths, so set it when known.\",\n inputSchema: {\n id: z.string().min(1).describe(\"Your own stable user id, e.g. 'usr_123'.\"),\n contacts: z\n .array(\n z.object({\n channel: z.enum(CHANNELS).describe(\"Contact delivery channel.\"),\n target: z.string().min(1).describe(\"Destination address, phone, token, or URL.\"),\n label: z.string().optional().describe(\"Friendly label for this contact.\"),\n isPrimary: z\n .boolean()\n .optional()\n .describe(\"Whether this is the primary contact for this channel.\"),\n }),\n )\n .optional()\n .describe(\n \"Array of user contacts across any supported channels (preferred over legacy email/phone/pushToken).\",\n ),\n email: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One email address or several.\"),\n phone: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One phone number or several, in E.164 form.\"),\n pushToken: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One device push token or several.\"),\n segments: z\n .array(z.string().min(1))\n .optional()\n .describe(\"Segment tags to assign to this user.\"),\n language: z\n .string()\n .optional()\n .describe(\"BCP 47 language tag used to pick localised content.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"IANA timezone, e.g. 'Europe/London'. Drives quiet hours.\"),\n preferences: z\n .object({\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n })\n .optional()\n .describe(\"Consent and quiet-hours settings.\"),\n },\n annotations: { title: \"Create or update a user\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/users\", args)),\n );\n\n server.registerTool(\n \"update_user\",\n {\n title: \"Update a user\",\n description:\n \"Partially update an existing user profile (e.g. language, timezone, segment tags, preferences, or append new contacts) without replacing unspecified fields.\",\n inputSchema: {\n id: z.string().min(1).describe(\"User id.\"),\n contacts: z\n .array(\n z.object({\n channel: z.enum(CHANNELS).describe(\"Contact delivery channel.\"),\n target: z.string().min(1).describe(\"Destination address, phone, token, or URL.\"),\n label: z.string().optional().describe(\"Friendly label for this contact.\"),\n isPrimary: z\n .boolean()\n .optional()\n .describe(\"Whether this is the primary contact for this channel.\"),\n }),\n )\n .optional()\n .describe(\"Array of user contacts across any supported channels to append or update.\"),\n email: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One email address or several.\"),\n phone: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One phone number or several, in E.164 form.\"),\n pushToken: z\n .union([z.string().min(1), z.array(z.string().min(1))])\n .optional()\n .describe(\"One device push token or several.\"),\n segments: z\n .array(z.string().min(1))\n .optional()\n .describe(\"Segment tags to assign to this user.\"),\n language: z\n .string()\n .optional()\n .describe(\"BCP 47 language tag used to pick localised content.\"),\n timezone: z\n .string()\n .optional()\n .describe(\"IANA timezone, e.g. 'Europe/London'. Drives quiet hours.\"),\n preferences: z\n .object({\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n })\n .optional()\n .describe(\"Consent and quiet-hours settings.\"),\n },\n annotations: { title: \"Update a user\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async ({ id, ...body }) => api.patch(`/v1/users/${encodeURIComponent(id)}`, body)),\n );\n\n server.registerTool(\n \"delete_user\",\n {\n title: \"Delete a user\",\n description:\n \"Permanently delete a user profile and all associated contacts and preferences by user id.\",\n inputSchema: {\n id: z.string().min(1).describe(\"User id to delete.\"),\n },\n annotations: {\n title: \"Delete a user\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.delete(`/v1/users/${encodeURIComponent(args.id)}`);\n return `Deleted user ${args.id}.`;\n }),\n );\n\n server.registerTool(\n \"get_user_contacts\",\n {\n title: \"Get user contacts\",\n description: \"Fetch all registered contact addresses and tokens for a specific user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n },\n annotations: { title: \"Get user contacts\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/contacts`)),\n );\n\n server.registerTool(\n \"add_user_contact\",\n {\n title: \"Add a contact to a user\",\n description:\n \"Add one addressable target (email address, phone number, push token, or webhook URL) to an \" +\n \"existing user without replacing their other contacts. Prefer this over upsert_user when adding a \" +\n \"second device or address to someone who already exists.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"Id of the user to add the contact to.\"),\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel this target belongs to.\"),\n target: z.string().min(1).describe(\"The address itself: email, phone, push token, or URL.\"),\n },\n annotations: { title: \"Add a contact to a user\", readOnlyHint: false },\n },\n handler(async ({ userId, ...body }) =>\n api.post(`/v1/users/${encodeURIComponent(userId)}/contacts`, body),\n ),\n );\n\n server.registerTool(\n \"delete_user_contact\",\n {\n title: \"Delete a user contact\",\n description:\n \"Remove one contact destination (email, phone, push token, or webhook URL) from a user profile.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n channel: z.enum(CONTACT_CHANNELS).describe(\"Channel of the contact to delete.\"),\n target: z.string().min(1).describe(\"The address/number/token/URL to remove.\"),\n },\n annotations: {\n title: \"Delete a user contact\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.delete(\n `/v1/users/${encodeURIComponent(args.userId)}/contacts/${encodeURIComponent(args.channel)}/${encodeURIComponent(args.target)}`,\n );\n return `Deleted ${args.channel} contact '${args.target}' for user ${args.userId}.`;\n }),\n );\n\n server.registerTool(\n \"get_user_preferences\",\n {\n title: \"Get user preferences\",\n description:\n \"Fetch notification channel/topic opt-in preferences and quiet hours for a user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n },\n annotations: { title: \"Get user preferences\", readOnlyHint: true },\n },\n handler(async (args) => api.get(`/v1/users/${encodeURIComponent(args.userId)}/preferences`)),\n );\n\n server.registerTool(\n \"update_user_preferences\",\n {\n title: \"Update user preferences\",\n description: \"Update notification channel/topic opt-ins and quiet hours settings for a user.\",\n inputSchema: {\n userId: z.string().min(1).describe(\"User id.\"),\n channels: z\n .record(z.string(), z.boolean())\n .optional()\n .describe(\"Per-channel opt-in map, e.g. { email: true, sms: false }.\"),\n topics: z.record(z.string(), z.boolean()).optional().describe(\"Per-topic opt-in map.\"),\n quietHours: z\n .array(\n z.object({\n start: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n end: z.string().describe(\"HH:MM, 24h, in the user's timezone.\"),\n }),\n )\n .optional()\n .describe(\"Windows during which non-critical sends are deferred.\"),\n },\n annotations: { title: \"Update user preferences\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async ({ userId, ...preferences }) =>\n api.patch(`/v1/users/${encodeURIComponent(userId)}/preferences`, preferences),\n ),\n );\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/tools/workflows.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAiKhF"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { handler } from "./shared.js";
|
|
3
|
+
export function registerWorkflowsTools(server, api) {
|
|
4
|
+
server.registerTool("create_workflow", {
|
|
5
|
+
title: "Create a workflow",
|
|
6
|
+
description: "Define a named multi-step sequence — the way to build a drip, an onboarding series, or a reminder " +
|
|
7
|
+
"chain rather than a single send. Steps run in order and are one of: `notify` (send, using the " +
|
|
8
|
+
"same fields as send_notification), `wait` (pause for a duration like '1h' or '3d'), or " +
|
|
9
|
+
"`waitForEvent` (block until ingest_event reports a named event, with an optional timeout). A " +
|
|
10
|
+
"notify step with no target inherits the user the instance was triggered for. Creating a workflow " +
|
|
11
|
+
"does not run it — call trigger_workflow per user.",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
name: z.string().min(1).describe("Workflow name, used later by trigger_workflow."),
|
|
14
|
+
steps: z
|
|
15
|
+
.array(z.union([
|
|
16
|
+
z.object({
|
|
17
|
+
action: z.literal("notify"),
|
|
18
|
+
payload: z
|
|
19
|
+
.record(z.string(), z.unknown())
|
|
20
|
+
.describe("Same shape as send_notification's arguments. Omit the target to use the instance's own user."),
|
|
21
|
+
}),
|
|
22
|
+
z.object({
|
|
23
|
+
action: z.literal("wait"),
|
|
24
|
+
duration: z.string().describe("Duration string, e.g. '5m', '1h', '3d'."),
|
|
25
|
+
}),
|
|
26
|
+
z.object({
|
|
27
|
+
action: z.literal("waitForEvent"),
|
|
28
|
+
event: z.string().describe("Event name to wait for, as passed to ingest_event."),
|
|
29
|
+
options: z
|
|
30
|
+
.object({
|
|
31
|
+
timeout: z.string().optional().describe("e.g. '24h'."),
|
|
32
|
+
match: z
|
|
33
|
+
.record(z.string(), z.unknown())
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Fields the event must carry to wake this instance, e.g. { userId: 'u1' }. " +
|
|
36
|
+
"Without it any event of that name wakes every waiting instance."),
|
|
37
|
+
})
|
|
38
|
+
.optional()
|
|
39
|
+
.describe("Give a timeout so the instance cannot wait forever."),
|
|
40
|
+
}),
|
|
41
|
+
]))
|
|
42
|
+
.min(1)
|
|
43
|
+
.describe("Ordered steps."),
|
|
44
|
+
},
|
|
45
|
+
annotations: { title: "Create a workflow", readOnlyHint: false, idempotentHint: true },
|
|
46
|
+
}, handler(async (args) => api.post("/v1/workflows", args)));
|
|
47
|
+
server.registerTool("list_workflows", {
|
|
48
|
+
title: "List workflows",
|
|
49
|
+
description: "List registered workflow definitions and their steps. Call this to find the name to pass to " +
|
|
50
|
+
"trigger_workflow, or to check a sequence before triggering it. Supports filtering by search keyword.",
|
|
51
|
+
inputSchema: {
|
|
52
|
+
limit: z
|
|
53
|
+
.number()
|
|
54
|
+
.int()
|
|
55
|
+
.min(1)
|
|
56
|
+
.max(100)
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("Maximum number of workflow definitions to return."),
|
|
59
|
+
search: z
|
|
60
|
+
.string()
|
|
61
|
+
.optional()
|
|
62
|
+
.describe("Filter workflow definitions whose name contains this search keyword."),
|
|
63
|
+
},
|
|
64
|
+
annotations: { title: "List workflows", readOnlyHint: true },
|
|
65
|
+
}, handler(async (args) => api.get("/v1/workflows", args)));
|
|
66
|
+
server.registerTool("trigger_workflow", {
|
|
67
|
+
title: "Trigger a workflow",
|
|
68
|
+
description: "Start one run of a registered workflow, optionally for a specific user, and return the instance " +
|
|
69
|
+
"id. Each call starts an independent instance, so triggering the same workflow twice for one user " +
|
|
70
|
+
"enrols them twice. Track the returned instance with get_workflow_run.",
|
|
71
|
+
inputSchema: {
|
|
72
|
+
name: z.string().min(1).describe("Name of the workflow to run."),
|
|
73
|
+
user: z
|
|
74
|
+
.string()
|
|
75
|
+
.min(1)
|
|
76
|
+
.optional()
|
|
77
|
+
.describe("User id this run is for. Notify steps default to them."),
|
|
78
|
+
input: z
|
|
79
|
+
.record(z.string(), z.unknown())
|
|
80
|
+
.optional()
|
|
81
|
+
.describe("Data made available to the run's steps."),
|
|
82
|
+
},
|
|
83
|
+
annotations: { title: "Trigger a workflow", readOnlyHint: false, idempotentHint: false },
|
|
84
|
+
}, handler(async (args) => api.post("/v1/workflows/trigger", args)));
|
|
85
|
+
server.registerTool("get_workflow_run", {
|
|
86
|
+
title: "Get a workflow run",
|
|
87
|
+
description: "Fetch one workflow instance by id: which step it is on, its status, and what it is waiting for. " +
|
|
88
|
+
"Use this to check on a run started by trigger_workflow.",
|
|
89
|
+
inputSchema: { instanceId: z.string().min(1).describe("Workflow instance id.") },
|
|
90
|
+
annotations: { title: "Get a workflow run", readOnlyHint: true },
|
|
91
|
+
}, handler(async (args) => api.get(`/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`)));
|
|
92
|
+
server.registerTool("cancel_workflow_run", {
|
|
93
|
+
title: "Cancel a workflow run",
|
|
94
|
+
description: "Stop a running or suspended workflow instance so its remaining steps never fire. This does not " +
|
|
95
|
+
"recall notifications already sent, and it cannot be undone — confirm with the user before " +
|
|
96
|
+
"cancelling a run you did not start in this session.",
|
|
97
|
+
inputSchema: { instanceId: z.string().min(1).describe("Workflow instance id to cancel.") },
|
|
98
|
+
annotations: {
|
|
99
|
+
title: "Cancel a workflow run",
|
|
100
|
+
readOnlyHint: false,
|
|
101
|
+
destructiveHint: true,
|
|
102
|
+
idempotentHint: true,
|
|
103
|
+
},
|
|
104
|
+
}, handler(async (args) => {
|
|
105
|
+
await api.request("DELETE", `/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`);
|
|
106
|
+
return `Cancelled workflow instance ${args.instanceId}.`;
|
|
107
|
+
}));
|
|
108
|
+
server.registerTool("ingest_event", {
|
|
109
|
+
title: "Ingest an event",
|
|
110
|
+
description: "Report that something happened in your product. Workflow instances parked on a matching " +
|
|
111
|
+
"`waitForEvent` step resume. Call this to unblock a waiting sequence, e.g. emitting 'order.paid' " +
|
|
112
|
+
"so an abandoned-cart workflow stops before its reminder fires.",
|
|
113
|
+
inputSchema: {
|
|
114
|
+
name: z.string().min(1).describe("Event name, matching a workflow's waitForEvent step."),
|
|
115
|
+
properties: z
|
|
116
|
+
.record(z.string(), z.unknown())
|
|
117
|
+
.describe("Event payload. Include the user id the event is about."),
|
|
118
|
+
},
|
|
119
|
+
annotations: { title: "Ingest an event", readOnlyHint: false, idempotentHint: false },
|
|
120
|
+
}, handler(async (args) => api.post("/v1/events", args)));
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=workflows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflows.js","sourceRoot":"","sources":["../../src/tools/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,UAAU,sBAAsB,CAAC,MAAiB,EAAE,GAAgB;IACxE,MAAM,CAAC,YAAY,CACjB,iBAAiB,EACjB;QACE,KAAK,EAAE,mBAAmB;QAC1B,WAAW,EACT,oGAAoG;YACpG,gGAAgG;YAChG,yFAAyF;YACzF,+FAA+F;YAC/F,mGAAmG;YACnG,mDAAmD;QACrD,WAAW,EAAE;YACX,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gDAAgD,CAAC;YAClF,KAAK,EAAE,CAAC;iBACL,KAAK,CACJ,CAAC,CAAC,KAAK,CAAC;gBACN,CAAC,CAAC,MAAM,CAAC;oBACP,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;oBAC3B,OAAO,EAAE,CAAC;yBACP,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;yBAC/B,QAAQ,CACP,8FAA8F,CAC/F;iBACJ,CAAC;gBACF,CAAC,CAAC,MAAM,CAAC;oBACP,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;oBACzB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ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O,EAAE,CAAC;iBAC/B,QAAQ,CAAC,wDAAwD,CAAC;SACtE;QACD,WAAW,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE;KACtF,EACD,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CACtD,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { NotifkitApi } from \"../client.js\";\nimport { handler } from \"./shared.js\";\n\nexport function registerWorkflowsTools(server: McpServer, api: NotifkitApi): void {\n server.registerTool(\n \"create_workflow\",\n {\n title: \"Create a workflow\",\n description:\n \"Define a named multi-step sequence — the way to build a drip, an onboarding series, or a reminder \" +\n \"chain rather than a single send. Steps run in order and are one of: `notify` (send, using the \" +\n \"same fields as send_notification), `wait` (pause for a duration like '1h' or '3d'), or \" +\n \"`waitForEvent` (block until ingest_event reports a named event, with an optional timeout). A \" +\n \"notify step with no target inherits the user the instance was triggered for. Creating a workflow \" +\n \"does not run it — call trigger_workflow per user.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Workflow name, used later by trigger_workflow.\"),\n steps: z\n .array(\n z.union([\n z.object({\n action: z.literal(\"notify\"),\n payload: z\n .record(z.string(), z.unknown())\n .describe(\n \"Same shape as send_notification's arguments. Omit the target to use the instance's own user.\",\n ),\n }),\n z.object({\n action: z.literal(\"wait\"),\n duration: z.string().describe(\"Duration string, e.g. '5m', '1h', '3d'.\"),\n }),\n z.object({\n action: z.literal(\"waitForEvent\"),\n event: z.string().describe(\"Event name to wait for, as passed to ingest_event.\"),\n options: z\n .object({\n timeout: z.string().optional().describe(\"e.g. '24h'.\"),\n match: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\n \"Fields the event must carry to wake this instance, e.g. { userId: 'u1' }. \" +\n \"Without it any event of that name wakes every waiting instance.\",\n ),\n })\n .optional()\n .describe(\"Give a timeout so the instance cannot wait forever.\"),\n }),\n ]),\n )\n .min(1)\n .describe(\"Ordered steps.\"),\n },\n annotations: { title: \"Create a workflow\", readOnlyHint: false, idempotentHint: true },\n },\n handler(async (args) => api.post(\"/v1/workflows\", args)),\n );\n\n server.registerTool(\n \"list_workflows\",\n {\n title: \"List workflows\",\n description:\n \"List registered workflow definitions and their steps. Call this to find the name to pass to \" +\n \"trigger_workflow, or to check a sequence before triggering it. Supports filtering by search keyword.\",\n inputSchema: {\n limit: z\n .number()\n .int()\n .min(1)\n .max(100)\n .optional()\n .describe(\"Maximum number of workflow definitions to return.\"),\n search: z\n .string()\n .optional()\n .describe(\"Filter workflow definitions whose name contains this search keyword.\"),\n },\n annotations: { title: \"List workflows\", readOnlyHint: true },\n },\n handler(async (args) => api.get(\"/v1/workflows\", args)),\n );\n\n server.registerTool(\n \"trigger_workflow\",\n {\n title: \"Trigger a workflow\",\n description:\n \"Start one run of a registered workflow, optionally for a specific user, and return the instance \" +\n \"id. Each call starts an independent instance, so triggering the same workflow twice for one user \" +\n \"enrols them twice. Track the returned instance with get_workflow_run.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Name of the workflow to run.\"),\n user: z\n .string()\n .min(1)\n .optional()\n .describe(\"User id this run is for. Notify steps default to them.\"),\n input: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Data made available to the run's steps.\"),\n },\n annotations: { title: \"Trigger a workflow\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => api.post(\"/v1/workflows/trigger\", args)),\n );\n\n server.registerTool(\n \"get_workflow_run\",\n {\n title: \"Get a workflow run\",\n description:\n \"Fetch one workflow instance by id: which step it is on, its status, and what it is waiting for. \" +\n \"Use this to check on a run started by trigger_workflow.\",\n inputSchema: { instanceId: z.string().min(1).describe(\"Workflow instance id.\") },\n annotations: { title: \"Get a workflow run\", readOnlyHint: true },\n },\n handler(async (args) =>\n api.get(`/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`),\n ),\n );\n\n server.registerTool(\n \"cancel_workflow_run\",\n {\n title: \"Cancel a workflow run\",\n description:\n \"Stop a running or suspended workflow instance so its remaining steps never fire. This does not \" +\n \"recall notifications already sent, and it cannot be undone — confirm with the user before \" +\n \"cancelling a run you did not start in this session.\",\n inputSchema: { instanceId: z.string().min(1).describe(\"Workflow instance id to cancel.\") },\n annotations: {\n title: \"Cancel a workflow run\",\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n },\n },\n handler(async (args) => {\n await api.request(\"DELETE\", `/v1/workflows/instances/${encodeURIComponent(args.instanceId)}`);\n return `Cancelled workflow instance ${args.instanceId}.`;\n }),\n );\n\n server.registerTool(\n \"ingest_event\",\n {\n title: \"Ingest an event\",\n description:\n \"Report that something happened in your product. Workflow instances parked on a matching \" +\n \"`waitForEvent` step resume. Call this to unblock a waiting sequence, e.g. emitting 'order.paid' \" +\n \"so an abandoned-cart workflow stops before its reminder fires.\",\n inputSchema: {\n name: z.string().min(1).describe(\"Event name, matching a workflow's waitForEvent step.\"),\n properties: z\n .record(z.string(), z.unknown())\n .describe(\"Event payload. Include the user id the event is about.\"),\n },\n annotations: { title: \"Ingest an event\", readOnlyHint: false, idempotentHint: false },\n },\n handler(async (args) => api.post(\"/v1/events\", args)),\n );\n}\n"]}
|
package/dist/tools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAQ/C,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAOvE"}
|