@wiro-ai/wiro-agent-connectors 0.1.0 → 0.2.1
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/CHANGELOG.md +36 -0
- package/README.md +1185 -34
- package/dist/cli.js +15 -12
- package/dist/core/credentials.d.ts +21 -0
- package/dist/core/credentials.js +45 -0
- package/dist/core/origins.d.ts +18 -0
- package/dist/core/origins.js +40 -0
- package/dist/core/upload-hosts.d.ts +15 -0
- package/dist/core/upload-hosts.js +43 -0
- package/dist/host/describe.d.ts +10 -0
- package/dist/host/describe.js +38 -0
- package/dist/host/env.d.ts +25 -2
- package/dist/host/env.js +24 -7
- package/dist/host/guarded-fetch.d.ts +36 -9
- package/dist/host/guarded-fetch.js +175 -52
- package/dist/host/index.d.ts +8 -5
- package/dist/host/index.js +12 -1
- package/dist/host/load.js +31 -1
- package/dist/host/server.d.ts +13 -2
- package/dist/host/server.js +15 -2
- package/dist/types.d.ts +96 -5
- package/dist/vendors/adapty.js +1303 -0
- package/dist/vendors/adjust.js +1372 -0
- package/dist/vendors/apollo.js +2499 -0
- package/dist/vendors/apple-appstore.js +2798 -0
- package/dist/vendors/beehiiv.js +1965 -0
- package/dist/vendors/blogger.js +1687 -0
- package/dist/vendors/bluesky.js +850 -127
- package/dist/vendors/brevo.js +2195 -0
- package/dist/vendors/calendarific.js +1116 -0
- package/dist/vendors/devto.js +685 -92
- package/dist/vendors/facebook-pages.js +2185 -0
- package/dist/vendors/firebase.js +1333 -0
- package/dist/vendors/ga4.js +1585 -0
- package/dist/vendors/gmail.js +1962 -0
- package/dist/vendors/google-ads.js +2201 -0
- package/dist/vendors/google-business.js +1621 -0
- package/dist/vendors/google-calendar.js +1936 -0
- package/dist/vendors/google-drive.js +2654 -0
- package/dist/vendors/google-merchant-center.js +1742 -0
- package/dist/vendors/google-play.js +1856 -0
- package/dist/vendors/google-search-console.js +1572 -0
- package/dist/vendors/hashnode.js +1722 -0
- package/dist/vendors/instagram.js +2249 -0
- package/dist/vendors/kaggle.js +2043 -0
- package/dist/vendors/keepa.js +2087 -0
- package/dist/vendors/linkedin.js +1588 -0
- package/dist/vendors/mailchimp.js +2402 -0
- package/dist/vendors/mastodon.js +1836 -0
- package/dist/vendors/meta-ads.js +2375 -0
- package/dist/vendors/notion.js +1950 -0
- package/dist/vendors/pinterest.js +1744 -0
- package/dist/vendors/qiita.js +1552 -0
- package/dist/vendors/reddit.js +1791 -0
- package/dist/vendors/revenuecat.js +1593 -0
- package/dist/vendors/roasit.js +1460 -0
- package/dist/vendors/sendgrid.js +2188 -0
- package/dist/vendors/serper.js +901 -179
- package/dist/vendors/shopify.js +2511 -0
- package/dist/vendors/threads.js +1869 -0
- package/dist/vendors/tiktok.js +2199 -0
- package/dist/vendors/tumblr.js +1793 -0
- package/dist/vendors/twitter.js +1650 -0
- package/dist/vendors/woocommerce.js +2258 -0
- package/dist/vendors/wordpress.js +1904 -0
- package/dist/vendors/youtube.js +2542 -0
- package/package.json +12 -1
|
@@ -0,0 +1,2195 @@
|
|
|
1
|
+
/* brevo connector module (MIT License). Built from src/vendors/brevo; do not edit. */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// src/core/errors.ts
|
|
5
|
+
var ToolFailure = class extends Error {
|
|
6
|
+
details;
|
|
7
|
+
constructor(message, details = {}) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "ToolFailure";
|
|
10
|
+
this.details = details;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var OutcomeUnknown = class extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "OutcomeUnknown";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/core/accounts.ts
|
|
21
|
+
function allowedAccounts(accounts, key) {
|
|
22
|
+
if (accounts === null) return null;
|
|
23
|
+
const list = accounts?.[key];
|
|
24
|
+
return Array.isArray(list) ? list.map(String) : [];
|
|
25
|
+
}
|
|
26
|
+
function requireAccounts(accounts, key, ids, label = "account") {
|
|
27
|
+
const allowed = allowedAccounts(accounts, key);
|
|
28
|
+
if (allowed === null) return;
|
|
29
|
+
const requested = (Array.isArray(ids) ? ids : [ids]).map(String);
|
|
30
|
+
const refused = requested.filter((id) => !allowed.includes(id));
|
|
31
|
+
if (!refused.length) return;
|
|
32
|
+
throw new ToolFailure(
|
|
33
|
+
`The ${label} ${refused.join(", ")} ${refused.length > 1 ? "are" : "is"} not among the ${label}s chosen for this connection. ` + (allowed.length ? `Use one of: ${allowed.join(", ")}.` : `No ${label} is chosen for it yet.`) + " Nothing was sent."
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/core/text.ts
|
|
38
|
+
var encoder = new TextEncoder();
|
|
39
|
+
var decoder = new TextDecoder();
|
|
40
|
+
function utf8Bytes(text) {
|
|
41
|
+
return encoder.encode(text);
|
|
42
|
+
}
|
|
43
|
+
function utf8Length(text) {
|
|
44
|
+
return encoder.encode(text).length;
|
|
45
|
+
}
|
|
46
|
+
function utf8Decode(bytes) {
|
|
47
|
+
return decoder.decode(bytes);
|
|
48
|
+
}
|
|
49
|
+
function base64Encode(bytes) {
|
|
50
|
+
let binary = "";
|
|
51
|
+
for (let i = 0; i < bytes.length; i += 32768) {
|
|
52
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + 32768));
|
|
53
|
+
}
|
|
54
|
+
return btoa(binary);
|
|
55
|
+
}
|
|
56
|
+
function base64UrlEncode(bytes) {
|
|
57
|
+
return base64Encode(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
58
|
+
}
|
|
59
|
+
function base64UrlDecode(text) {
|
|
60
|
+
if (!/^[A-Za-z0-9_-]*$/.test(text)) throw new Error("not base64url");
|
|
61
|
+
const padded = text.replace(/-/g, "+").replace(/_/g, "/") + "===".slice((text.length + 3) % 4);
|
|
62
|
+
const binary = atob(padded);
|
|
63
|
+
const bytes = new Uint8Array(binary.length);
|
|
64
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
65
|
+
return bytes;
|
|
66
|
+
}
|
|
67
|
+
function truncate(text, max) {
|
|
68
|
+
if (text.length <= max) return text;
|
|
69
|
+
const points = Array.from(text);
|
|
70
|
+
if (points.length <= max) return text;
|
|
71
|
+
return `${points.slice(0, Math.max(0, max - 1)).join("")}\u2026`;
|
|
72
|
+
}
|
|
73
|
+
function cleanVendorText(text, max = 300) {
|
|
74
|
+
if (typeof text !== "string") return void 0;
|
|
75
|
+
if (/^\s*</.test(text)) return void 0;
|
|
76
|
+
const line = text.replace(/[\u0000-\u001f\u007f]+/g, " ").replace(/\s+/g, " ").trim();
|
|
77
|
+
return line ? truncate(line, max) : void 0;
|
|
78
|
+
}
|
|
79
|
+
function formatNumber(value) {
|
|
80
|
+
return value.toLocaleString("en-US");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/core/output.ts
|
|
84
|
+
var OUTPUT_LIMIT_BYTES = 32 * 1024;
|
|
85
|
+
function jsonSize(value) {
|
|
86
|
+
return utf8Length(JSON.stringify(value) ?? "");
|
|
87
|
+
}
|
|
88
|
+
function cutStrings(value, max) {
|
|
89
|
+
if (typeof value === "string") return truncate(value, max);
|
|
90
|
+
if (Array.isArray(value)) return value.map((item) => cutStrings(item, max));
|
|
91
|
+
if (typeof value === "object" && value !== null) {
|
|
92
|
+
const out = {};
|
|
93
|
+
for (const [key, item] of Object.entries(value)) out[key] = cutStrings(item, max);
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
function shrinkToFit(value, limit = OUTPUT_LIMIT_BYTES) {
|
|
99
|
+
if (jsonSize(value) <= limit) return { value, truncated: false };
|
|
100
|
+
for (const max of [4e3, 2e3, 1e3, 500, 200, 80]) {
|
|
101
|
+
const cut = cutStrings(value, max);
|
|
102
|
+
if (jsonSize(cut) <= limit) return { value: cut, truncated: true };
|
|
103
|
+
}
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
function fitPage(input, limit = OUTPUT_LIMIT_BYTES) {
|
|
107
|
+
const build = (count) => {
|
|
108
|
+
const cut = count < input.items.length;
|
|
109
|
+
const result2 = { ...input.extra, [input.key]: input.items.slice(0, count) };
|
|
110
|
+
const next = cut ? input.resumeAt(count) : input.nextPage;
|
|
111
|
+
if (next) result2["nextCursor"] = next;
|
|
112
|
+
if (cut) result2["truncated"] = true;
|
|
113
|
+
return result2;
|
|
114
|
+
};
|
|
115
|
+
const all = build(input.items.length);
|
|
116
|
+
if (jsonSize(all) <= limit) return all;
|
|
117
|
+
let low = 1;
|
|
118
|
+
let high = input.items.length - 1;
|
|
119
|
+
while (low < high) {
|
|
120
|
+
const middle = Math.ceil((low + high) / 2);
|
|
121
|
+
if (jsonSize(build(middle)) <= limit) low = middle;
|
|
122
|
+
else high = middle - 1;
|
|
123
|
+
}
|
|
124
|
+
const best = build(low);
|
|
125
|
+
if (jsonSize(best) <= limit) return best;
|
|
126
|
+
const shrunk = shrinkToFit(best, limit);
|
|
127
|
+
if (shrunk) return { ...shrunk.value, truncated: true };
|
|
128
|
+
throw new ToolFailure("The result is too large to return, even one item at a time.");
|
|
129
|
+
}
|
|
130
|
+
function encodeCursor(tool, state) {
|
|
131
|
+
return base64UrlEncode(utf8Bytes(JSON.stringify({ t: tool, ...state })));
|
|
132
|
+
}
|
|
133
|
+
function decodeCursor(tool, cursor) {
|
|
134
|
+
if (cursor === void 0 || cursor === "") return null;
|
|
135
|
+
try {
|
|
136
|
+
const state = JSON.parse(utf8Decode(base64UrlDecode(cursor)));
|
|
137
|
+
if (typeof state === "object" && state !== null && state.t === tool) {
|
|
138
|
+
return state;
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
}
|
|
142
|
+
throw new ToolFailure(
|
|
143
|
+
"The cursor is not valid for this tool. Pass the nextCursor value of the previous result unchanged, or leave cursor out to start from the beginning."
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/core/api-tools.ts
|
|
148
|
+
var ALL_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
149
|
+
var TEXT_TYPES = /json|^text\/|xml|javascript|x-www-form-urlencoded|csv|yaml|graphql/i;
|
|
150
|
+
var NOTE_ROOM = 400;
|
|
151
|
+
var MAX_CUT_POINTS = 4e4;
|
|
152
|
+
function isQueryValue(value) {
|
|
153
|
+
return typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
|
|
154
|
+
}
|
|
155
|
+
function nothingSent(sentence) {
|
|
156
|
+
return new ToolFailure(`${sentence} Nothing was sent.`);
|
|
157
|
+
}
|
|
158
|
+
function fitReply(reply) {
|
|
159
|
+
if (jsonSize(reply) <= OUTPUT_LIMIT_BYTES) return reply;
|
|
160
|
+
const shrunk = shrinkToFit(reply, OUTPUT_LIMIT_BYTES - NOTE_ROOM);
|
|
161
|
+
if (shrunk) {
|
|
162
|
+
return {
|
|
163
|
+
...shrunk.value,
|
|
164
|
+
truncated: true,
|
|
165
|
+
note: "Long text values were cut to fit 32 KB: ask for fewer items or fields to see them whole."
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const text = typeof reply["data"] === "string" ? reply["data"] : JSON.stringify(reply["data"]) ?? "";
|
|
169
|
+
const points = Array.from(text.length > MAX_CUT_POINTS ? text.slice(0, MAX_CUT_POINTS) : text);
|
|
170
|
+
if (/^[\ud800-\udbff]$/.test(points[points.length - 1] ?? "")) points.pop();
|
|
171
|
+
const cut = (count) => ({
|
|
172
|
+
status: reply["status"],
|
|
173
|
+
...reply["headers"] ? { headers: reply["headers"] } : {},
|
|
174
|
+
truncated: true,
|
|
175
|
+
note: `The reply has ${formatNumber(utf8Length(text))} bytes and was cut to fit 32 KB: ask for fewer items (the API's paging or field parameters) to see it whole.`,
|
|
176
|
+
text: points.slice(0, count).join("")
|
|
177
|
+
});
|
|
178
|
+
let low = 0;
|
|
179
|
+
let high = points.length;
|
|
180
|
+
while (low < high) {
|
|
181
|
+
const middle = Math.ceil((low + high) / 2);
|
|
182
|
+
if (jsonSize(cut(middle)) <= OUTPUT_LIMIT_BYTES) low = middle;
|
|
183
|
+
else high = middle - 1;
|
|
184
|
+
}
|
|
185
|
+
return cut(low);
|
|
186
|
+
}
|
|
187
|
+
function shapeReply(response, headerNames) {
|
|
188
|
+
const reply = { status: response.status };
|
|
189
|
+
const headers = {};
|
|
190
|
+
for (const name2 of headerNames) {
|
|
191
|
+
const value = response.headers.get(name2);
|
|
192
|
+
if (value) headers[name2] = truncate(value, 2e3);
|
|
193
|
+
}
|
|
194
|
+
if (Object.keys(headers).length) reply["headers"] = headers;
|
|
195
|
+
const type = response.headers.get("content-type") ?? "";
|
|
196
|
+
if (type && !TEXT_TYPES.test(type)) {
|
|
197
|
+
reply["contentType"] = truncate(type, 200);
|
|
198
|
+
reply["note"] = "The reply is a binary file and is not shown.";
|
|
199
|
+
return reply;
|
|
200
|
+
}
|
|
201
|
+
if (response.data !== null && response.data !== void 0 && response.data !== "") reply["data"] = response.data;
|
|
202
|
+
return fitReply(reply);
|
|
203
|
+
}
|
|
204
|
+
function checkAccounts(rule, request, h) {
|
|
205
|
+
const label = rule.label ?? "account";
|
|
206
|
+
const allowed = allowedAccounts(h.ctx.accounts, rule.key);
|
|
207
|
+
if (allowed === null) return;
|
|
208
|
+
const namesNone = nothingSent(
|
|
209
|
+
`This request names none of the ${label}s chosen for this connection. ` + (allowed.length ? `It must name one of: ${allowed.join(", ")}.` : `No ${label} is chosen for it yet.`)
|
|
210
|
+
);
|
|
211
|
+
if (rule.ids) {
|
|
212
|
+
const ids = rule.ids(request).map(String);
|
|
213
|
+
if (!ids.length) throw namesNone;
|
|
214
|
+
requireAccounts(h.ctx.accounts, rule.key, ids, label);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (!request.segments.some((segment) => allowed.includes(segment))) throw namesNone;
|
|
218
|
+
}
|
|
219
|
+
function apiTools(options) {
|
|
220
|
+
const { label, basePath } = options;
|
|
221
|
+
const methods = options.methods?.length ? [...new Set(options.methods)] : ALL_METHODS;
|
|
222
|
+
const headerNames = ["link", "location", ...(options.responseHeaders ?? []).map((name2) => name2.toLowerCase())];
|
|
223
|
+
const base = basePath?.replace(/\/+$/, "");
|
|
224
|
+
const pathSchema = {
|
|
225
|
+
type: "string",
|
|
226
|
+
minLength: 1,
|
|
227
|
+
maxLength: 2e3,
|
|
228
|
+
pattern: "^(?!.*//)/[^?#]*$",
|
|
229
|
+
description: `The path${basePath ? `, starting with ${basePath}` : ""}. Query parameters go in query, not in the path.`
|
|
230
|
+
};
|
|
231
|
+
const querySchema = {
|
|
232
|
+
type: "object",
|
|
233
|
+
description: 'Query parameters, e.g. {"page": 2, "fields": "id,name"}. A list repeats the parameter: {"id": [1, 2]} sends id=1&id=2.'
|
|
234
|
+
};
|
|
235
|
+
const originSchema = options.originArgument ? { origin: { type: "string", pattern: "^https://", maxLength: 300, description: options.originArgument } } : {};
|
|
236
|
+
async function run(method, args, h) {
|
|
237
|
+
let origin = h.origins[0];
|
|
238
|
+
if (args.origin !== void 0) {
|
|
239
|
+
let wanted;
|
|
240
|
+
try {
|
|
241
|
+
wanted = new URL(args.origin).origin;
|
|
242
|
+
} catch {
|
|
243
|
+
}
|
|
244
|
+
if (!wanted || !h.origins.includes(wanted)) throw nothingSent(`origin must be one of: ${h.origins.join(", ")}.`);
|
|
245
|
+
origin = wanted;
|
|
246
|
+
}
|
|
247
|
+
const url = new URL(args.path, origin);
|
|
248
|
+
if (url.origin !== origin) throw nothingSent(`The path must stay on ${origin}.`);
|
|
249
|
+
const path = url.pathname;
|
|
250
|
+
if (base !== void 0 && path !== base && !path.startsWith(`${base}/`)) throw nothingSent(`The path must start with ${basePath}.`);
|
|
251
|
+
let segments;
|
|
252
|
+
try {
|
|
253
|
+
segments = path.split("/").slice(1).map((segment) => decodeURIComponent(segment));
|
|
254
|
+
} catch {
|
|
255
|
+
throw nothingSent("The path has a broken percent-escape (a % not followed by two hex digits).");
|
|
256
|
+
}
|
|
257
|
+
if (segments[segments.length - 1] === "") segments.pop();
|
|
258
|
+
const query = {};
|
|
259
|
+
const queryLists = {};
|
|
260
|
+
for (const [key, value] of Object.entries(args.query ?? {})) {
|
|
261
|
+
if (value === void 0 || value === null) continue;
|
|
262
|
+
const list = Array.isArray(value) ? value : [value];
|
|
263
|
+
if (!key || !list.every(isQueryValue)) throw nothingSent(`query.${key} must be text, a number, true or false, or a list of them.`);
|
|
264
|
+
query[key] = Array.isArray(value) ? list : value;
|
|
265
|
+
queryLists[key] = list.map(String);
|
|
266
|
+
}
|
|
267
|
+
const request = { method, origin, path, query };
|
|
268
|
+
if (method !== "GET") {
|
|
269
|
+
if (args.json !== void 0 && args.body !== void 0) throw nothingSent("Give json or body, not both.");
|
|
270
|
+
if (args.body !== void 0 && !args.content_type) throw nothingSent('content_type is required with body, e.g. "application/x-www-form-urlencoded".');
|
|
271
|
+
if (args.json !== void 0 && !args.content_type) {
|
|
272
|
+
request.json = args.json;
|
|
273
|
+
} else if (args.json !== void 0 || args.body !== void 0) {
|
|
274
|
+
request.body = utf8Bytes(args.body ?? JSON.stringify(args.json));
|
|
275
|
+
request.contentType = args.content_type;
|
|
276
|
+
}
|
|
277
|
+
request.write = true;
|
|
278
|
+
}
|
|
279
|
+
const info = { method, origin, path, segments, query: queryLists, ...args.json !== void 0 ? { json: args.json } : {} };
|
|
280
|
+
if (options.accounts) checkAccounts(options.accounts, info, h);
|
|
281
|
+
await options.guard?.(info, h);
|
|
282
|
+
const response = options.send ? await options.send(request, h) : await h.api(request);
|
|
283
|
+
return shapeReply(response, headerNames);
|
|
284
|
+
}
|
|
285
|
+
return [
|
|
286
|
+
{
|
|
287
|
+
name: "api_get",
|
|
288
|
+
kind: "read",
|
|
289
|
+
title: `Call the ${label} API (GET)`,
|
|
290
|
+
description: `${options.description} Sends one GET request with the connection's credentials and returns the HTTP status and the reply, JSON or text, cut to fit 32 KB (use the API's own paging and field parameters for long lists). It changes nothing.`,
|
|
291
|
+
inputSchema: {
|
|
292
|
+
type: "object",
|
|
293
|
+
properties: { path: pathSchema, query: querySchema, ...originSchema },
|
|
294
|
+
required: ["path"],
|
|
295
|
+
additionalProperties: false
|
|
296
|
+
},
|
|
297
|
+
run: (args, h) => run("GET", args, h)
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: "api_request",
|
|
301
|
+
kind: "write",
|
|
302
|
+
check: "api_get",
|
|
303
|
+
title: `Send a request to the ${label} API`,
|
|
304
|
+
description: `${options.description} Sends one ${methods.join(", ")} request with the connection's credentials, with a JSON body (json) or another body (body and content_type), and returns the HTTP status and the reply. It can create, change or delete data. It is never retried: when the outcome is unclear, check with api_get before sending it again.`,
|
|
305
|
+
inputSchema: {
|
|
306
|
+
type: "object",
|
|
307
|
+
properties: {
|
|
308
|
+
method: { type: "string", enum: methods, description: `The HTTP method: ${methods.join(", ")}.` },
|
|
309
|
+
path: pathSchema,
|
|
310
|
+
query: querySchema,
|
|
311
|
+
json: { type: "object", description: "A JSON object to send as the body (application/json unless content_type says otherwise)." },
|
|
312
|
+
body: { type: "string", maxLength: 1e6, description: 'Any other body, as text, with its content_type, e.g. a form: "name=a&tags=b".' },
|
|
313
|
+
content_type: {
|
|
314
|
+
type: "string",
|
|
315
|
+
pattern: "^[A-Za-z0-9!#$&^_.+-]+/[A-Za-z0-9!#$&^_.+-]+(\\s*;.*)?$",
|
|
316
|
+
maxLength: 200,
|
|
317
|
+
description: `The body's media type, e.g. "application/x-www-form-urlencoded"; required with body.`
|
|
318
|
+
},
|
|
319
|
+
...originSchema
|
|
320
|
+
},
|
|
321
|
+
required: ["method", "path"],
|
|
322
|
+
additionalProperties: false
|
|
323
|
+
},
|
|
324
|
+
run: (args, h) => run(args.method, args, h)
|
|
325
|
+
}
|
|
326
|
+
];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/core/credentials.ts
|
|
330
|
+
function requiredAlternatives(module2) {
|
|
331
|
+
return (module2.requiredCredentials ?? [module2.credentials]).map((list) => [...list]);
|
|
332
|
+
}
|
|
333
|
+
function unmetAlternatives(alternatives, has) {
|
|
334
|
+
const lacking = alternatives.map((list) => list.filter((name2) => !has(name2)));
|
|
335
|
+
if (lacking.some((list) => list.length === 0)) return [];
|
|
336
|
+
return lacking.filter((list, index) => !lacking.some((other, otherIndex) => otherIndex !== index && other.every((name2) => list.includes(name2)) && (other.length < list.length || otherIndex < index)));
|
|
337
|
+
}
|
|
338
|
+
function andList(items) {
|
|
339
|
+
if (items.length <= 2) return items.join(" and ");
|
|
340
|
+
return `${items.slice(0, -1).join(", ")} and ${items[items.length - 1]}`;
|
|
341
|
+
}
|
|
342
|
+
function orList(items) {
|
|
343
|
+
if (items.length <= 1) return items.join("");
|
|
344
|
+
return `${items.slice(0, -1).join(", ")}, or ${items[items.length - 1]}`;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// src/core/files.ts
|
|
348
|
+
var ATTACHMENT_URI = "attachment:///";
|
|
349
|
+
var MAX_NAME = 200;
|
|
350
|
+
function fileLimitOf(ctx) {
|
|
351
|
+
const maxBytes = ctx.files?.maxBytes;
|
|
352
|
+
return typeof maxBytes === "number" && Number.isSafeInteger(maxBytes) && maxBytes > 0 ? maxBytes : null;
|
|
353
|
+
}
|
|
354
|
+
function fileName(name2) {
|
|
355
|
+
const clean = String(name2).replace(/[\u0000-\u001f\u007f]/g, "").replace(/[\\/]/g, "_").trim();
|
|
356
|
+
const points = Array.from(clean);
|
|
357
|
+
if (points.length <= MAX_NAME) return clean || "file";
|
|
358
|
+
const extension = /\.[A-Za-z0-9]{1,10}$/.exec(clean)?.[0] ?? "";
|
|
359
|
+
return points.slice(0, MAX_NAME - extension.length).join("") + extension;
|
|
360
|
+
}
|
|
361
|
+
function fileType(mimeType) {
|
|
362
|
+
const type = String(mimeType).split(";")[0]?.trim().toLowerCase() ?? "";
|
|
363
|
+
return /^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/.test(type) ? type : "application/octet-stream";
|
|
364
|
+
}
|
|
365
|
+
function resourceBlock(file) {
|
|
366
|
+
return {
|
|
367
|
+
type: "resource",
|
|
368
|
+
resource: { uri: `${ATTACHMENT_URI}${encodeURIComponent(file.name)}`, mimeType: file.mimeType, blob: base64Encode(file.bytes) }
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/core/http.ts
|
|
373
|
+
var MAX_API_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
374
|
+
var USER_AGENT = "agent-connectors";
|
|
375
|
+
var SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
|
|
376
|
+
function errorCode(error) {
|
|
377
|
+
const code = error?.code;
|
|
378
|
+
return typeof code === "string" ? code : void 0;
|
|
379
|
+
}
|
|
380
|
+
function describe(error) {
|
|
381
|
+
const name2 = error?.name;
|
|
382
|
+
const code = errorCode(error);
|
|
383
|
+
if (code === "TIMEOUT" || name2 === "TimeoutError") return "the request timed out";
|
|
384
|
+
if (code === "ABORTED" || name2 === "AbortError") return "the request was cancelled";
|
|
385
|
+
if (code === "TOO_LARGE") return "the reply was too large";
|
|
386
|
+
return cleanVendorText(error?.message, 200) ?? "a network error";
|
|
387
|
+
}
|
|
388
|
+
function retryAfterSeconds(headers, now = Date.now()) {
|
|
389
|
+
const retryAfter = headers.get("retry-after");
|
|
390
|
+
if (retryAfter) {
|
|
391
|
+
const seconds = Number(retryAfter);
|
|
392
|
+
if (Number.isFinite(seconds) && seconds >= 0) return Math.ceil(seconds);
|
|
393
|
+
const date = Date.parse(retryAfter);
|
|
394
|
+
if (!Number.isNaN(date)) return Math.max(0, Math.ceil((date - now) / 1e3));
|
|
395
|
+
}
|
|
396
|
+
const reset = headers.get("ratelimit-reset") ?? headers.get("x-ratelimit-reset");
|
|
397
|
+
if (reset) {
|
|
398
|
+
const value = Number(reset);
|
|
399
|
+
if (Number.isFinite(value) && value >= 0) {
|
|
400
|
+
return value > 1e9 ? Math.max(0, Math.ceil(value - now / 1e3)) : Math.ceil(value);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return void 0;
|
|
404
|
+
}
|
|
405
|
+
function vendorCode(data) {
|
|
406
|
+
if (typeof data !== "object" || data === null) return void 0;
|
|
407
|
+
for (const key of ["error", "code"]) {
|
|
408
|
+
const value = data[key];
|
|
409
|
+
if (typeof value === "string" && /^[A-Za-z][A-Za-z0-9_.-]{1,63}$/.test(value)) return value;
|
|
410
|
+
}
|
|
411
|
+
return void 0;
|
|
412
|
+
}
|
|
413
|
+
function vendorMessage(data) {
|
|
414
|
+
if (typeof data === "string") return cleanVendorText(data);
|
|
415
|
+
if (typeof data !== "object" || data === null) return void 0;
|
|
416
|
+
const record = data;
|
|
417
|
+
for (const key of ["message", "error_description", "error", "detail", "title"]) {
|
|
418
|
+
const value = record[key];
|
|
419
|
+
if (typeof value === "string" && value.trim()) return cleanVendorText(value);
|
|
420
|
+
const nested = value?.message;
|
|
421
|
+
if (typeof nested === "string" && nested.trim()) return cleanVendorText(nested);
|
|
422
|
+
}
|
|
423
|
+
if (Array.isArray(record["errors"])) {
|
|
424
|
+
const messages = record["errors"].map((item) => typeof item === "string" ? item : item?.message).filter((item) => typeof item === "string" && item.trim() !== "");
|
|
425
|
+
if (messages.length) return cleanVendorText(messages.join("; "));
|
|
426
|
+
}
|
|
427
|
+
return void 0;
|
|
428
|
+
}
|
|
429
|
+
var TooLarge = class extends Error {
|
|
430
|
+
constructor(limit) {
|
|
431
|
+
super(`the reply is larger than ${formatNumber(limit)} bytes`);
|
|
432
|
+
this.limit = limit;
|
|
433
|
+
}
|
|
434
|
+
limit;
|
|
435
|
+
};
|
|
436
|
+
async function readCapped(response, maxBytes) {
|
|
437
|
+
const declared = Number(response.headers.get("content-length"));
|
|
438
|
+
if (Number.isFinite(declared) && declared > maxBytes) {
|
|
439
|
+
await response.body?.cancel().catch(() => {
|
|
440
|
+
});
|
|
441
|
+
throw new TooLarge(maxBytes);
|
|
442
|
+
}
|
|
443
|
+
if (!response.body) return new Uint8Array(0);
|
|
444
|
+
const reader = response.body.getReader();
|
|
445
|
+
const chunks = [];
|
|
446
|
+
let total = 0;
|
|
447
|
+
for (; ; ) {
|
|
448
|
+
const { done, value } = await reader.read();
|
|
449
|
+
if (done) break;
|
|
450
|
+
total += value.byteLength;
|
|
451
|
+
if (total > maxBytes) {
|
|
452
|
+
await reader.cancel().catch(() => {
|
|
453
|
+
});
|
|
454
|
+
throw new TooLarge(maxBytes);
|
|
455
|
+
}
|
|
456
|
+
chunks.push(value);
|
|
457
|
+
}
|
|
458
|
+
const bytes = new Uint8Array(total);
|
|
459
|
+
let offset = 0;
|
|
460
|
+
for (const chunk of chunks) {
|
|
461
|
+
bytes.set(chunk, offset);
|
|
462
|
+
offset += chunk.byteLength;
|
|
463
|
+
}
|
|
464
|
+
return bytes;
|
|
465
|
+
}
|
|
466
|
+
function parseBody(bytes, contentType) {
|
|
467
|
+
if (bytes.length === 0) return null;
|
|
468
|
+
const text = utf8Decode(bytes);
|
|
469
|
+
if (/json/i.test(contentType ?? "") || /^\s*[[{]/.test(text)) {
|
|
470
|
+
try {
|
|
471
|
+
return JSON.parse(text);
|
|
472
|
+
} catch {
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return text;
|
|
476
|
+
}
|
|
477
|
+
function createHttp(env) {
|
|
478
|
+
const { label, ctx } = env;
|
|
479
|
+
const nothingChanged = env.readOnly ? "" : " Nothing was changed.";
|
|
480
|
+
const checkCredentials = env.credentialLabels.length ? `Check that the ${andList(env.credentialLabels)} ${env.credentialLabels.length > 1 ? "are" : "is"} correct and still active.` : `Check that the ${label} credentials are correct and still active.`;
|
|
481
|
+
function failureFor(status, headers, data, request) {
|
|
482
|
+
const message = vendorMessage(data);
|
|
483
|
+
const said = message ? `: ${message.replace(/[.!?。]+$/u, "")}` : "";
|
|
484
|
+
const retryAfter = retryAfterSeconds(headers);
|
|
485
|
+
const code = vendorCode(data);
|
|
486
|
+
const extra = { ...code ? { vendorCode: code } : {}, ...retryAfter !== void 0 ? { retryAfter } : {} };
|
|
487
|
+
const custom = request.errors?.[status];
|
|
488
|
+
const withCustom = (fallback) => custom ? `${custom.replace(/\.$/, "")} (HTTP ${status}).${message ? ` ${label} said: "${message}".` : ""}${nothingChanged}` : fallback;
|
|
489
|
+
if (status >= 500) {
|
|
490
|
+
if (request.write) {
|
|
491
|
+
return new OutcomeUnknown(`${label} answered HTTP ${status}${said}, so it is not known whether the change was made.`);
|
|
492
|
+
}
|
|
493
|
+
return new ToolFailure(withCustom(`${label} had a server error (HTTP ${status})${said}. Try again later.${nothingChanged}`), { status, ...extra });
|
|
494
|
+
}
|
|
495
|
+
if (status === 429) {
|
|
496
|
+
return new ToolFailure(
|
|
497
|
+
`${label} rate limit reached (HTTP 429).${nothingChanged} ` + (retryAfter !== void 0 ? `Retry after ${retryAfter} seconds.` : "Wait a while before retrying."),
|
|
498
|
+
{ status, ...extra }
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
if (status === 401) {
|
|
502
|
+
return new ToolFailure(
|
|
503
|
+
withCustom(`${label} rejected the credentials (HTTP 401)${said}. ${checkCredentials}${nothingChanged}`),
|
|
504
|
+
{ status, ...extra }
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
if (status === 403) return new ToolFailure(withCustom(`${label} refused the request (HTTP 403)${said}.${nothingChanged}`), { status, ...extra });
|
|
508
|
+
if (status === 404) return new ToolFailure(withCustom(`${label} found nothing there (HTTP 404)${said}.${nothingChanged}`), { status, ...extra });
|
|
509
|
+
if (status >= 400) return new ToolFailure(withCustom(`${label} rejected the request (HTTP ${status})${said}.${nothingChanged}`), { status, ...extra });
|
|
510
|
+
return new ToolFailure(`${label} answered with an unexpected HTTP ${status}.${nothingChanged}`, { status });
|
|
511
|
+
}
|
|
512
|
+
async function api(request) {
|
|
513
|
+
const method = request.method ?? "GET";
|
|
514
|
+
if (env.readOnly && !SAFE_METHODS.has(method) && !request.safe) {
|
|
515
|
+
throw new Error(`read-only tool sent ${method}`);
|
|
516
|
+
}
|
|
517
|
+
const origin = request.origin ?? env.origins[0];
|
|
518
|
+
if (!origin || !env.origins.includes(origin)) throw new Error("undeclared origin");
|
|
519
|
+
const url = new URL(request.path, origin);
|
|
520
|
+
if (url.origin !== origin || !request.path.startsWith("/")) throw new Error("path outside the origin");
|
|
521
|
+
for (const [key, value] of Object.entries(request.query ?? {})) {
|
|
522
|
+
if (value === void 0 || value === null) continue;
|
|
523
|
+
if (Array.isArray(value)) {
|
|
524
|
+
url.searchParams.delete(key);
|
|
525
|
+
for (const item of value) url.searchParams.append(key, String(item));
|
|
526
|
+
} else {
|
|
527
|
+
url.searchParams.set(key, String(value));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
const headers = {
|
|
531
|
+
accept: "application/json",
|
|
532
|
+
"user-agent": USER_AGENT,
|
|
533
|
+
...request.auth === false ? {} : env.authHeaders(),
|
|
534
|
+
...request.headers
|
|
535
|
+
};
|
|
536
|
+
let body;
|
|
537
|
+
if (request.json !== void 0) {
|
|
538
|
+
body = JSON.stringify(request.json);
|
|
539
|
+
headers["content-type"] = "application/json";
|
|
540
|
+
} else if (request.body) {
|
|
541
|
+
body = request.body;
|
|
542
|
+
headers["content-type"] = request.contentType ?? "application/octet-stream";
|
|
543
|
+
}
|
|
544
|
+
const started = Date.now();
|
|
545
|
+
if (request.write) env.onWriteSent();
|
|
546
|
+
let response;
|
|
547
|
+
try {
|
|
548
|
+
response = await ctx.fetch(url.toString(), { method, headers, ...body !== void 0 ? { body } : {}, ...ctx.signal ? { signal: ctx.signal } : {} });
|
|
549
|
+
} catch (error) {
|
|
550
|
+
env.log(`${env.vendor} ${env.tool} ${method} failed ${Date.now() - started}ms`);
|
|
551
|
+
if (errorCode(error) === "URL_REFUSED") {
|
|
552
|
+
throw new ToolFailure(`The request to ${label} was blocked before it was sent (${describe(error)}).${nothingChanged}`);
|
|
553
|
+
}
|
|
554
|
+
if (request.write) {
|
|
555
|
+
throw new OutcomeUnknown(`${label} did not answer (${describe(error)}), so it is not known whether the change was made.`);
|
|
556
|
+
}
|
|
557
|
+
if (errorCode(error) === "TOO_LARGE") throw new ToolFailure(`The reply from ${label} is larger than this host can read.${nothingChanged}`);
|
|
558
|
+
throw new ToolFailure(`${label} could not be reached (${describe(error)}). Try again later.${nothingChanged}`);
|
|
559
|
+
}
|
|
560
|
+
env.log(`${env.vendor} ${env.tool} ${method} ${response.status} ${Date.now() - started}ms`);
|
|
561
|
+
let bytes;
|
|
562
|
+
try {
|
|
563
|
+
bytes = await readCapped(response, request.maxBytes ?? MAX_API_RESPONSE_BYTES);
|
|
564
|
+
} catch (error) {
|
|
565
|
+
if (request.write && (response.ok || response.status >= 500)) {
|
|
566
|
+
throw new OutcomeUnknown(`${label} answered HTTP ${response.status}, but the reply could not be read (${describe(error)}), so it is not known whether the change was made.`);
|
|
567
|
+
}
|
|
568
|
+
throw new ToolFailure(`${label} answered HTTP ${response.status}, but the reply could not be read (${describe(error)}).${response.ok ? "" : nothingChanged}`);
|
|
569
|
+
}
|
|
570
|
+
const data = request.binary && response.ok ? bytes : parseBody(bytes, response.headers.get("content-type"));
|
|
571
|
+
if (response.ok) return { status: response.status, headers: response.headers, data };
|
|
572
|
+
throw failureFor(response.status, response.headers, data, request);
|
|
573
|
+
}
|
|
574
|
+
async function media(rawUrl, options) {
|
|
575
|
+
const { what } = options;
|
|
576
|
+
let url;
|
|
577
|
+
try {
|
|
578
|
+
url = new URL(rawUrl);
|
|
579
|
+
} catch {
|
|
580
|
+
throw new ToolFailure(`The ${what} URL is not a valid URL.${nothingChanged}`);
|
|
581
|
+
}
|
|
582
|
+
if (url.protocol !== "https:") throw new ToolFailure(`The ${what} URL must start with https://.${nothingChanged}`);
|
|
583
|
+
const started = Date.now();
|
|
584
|
+
let response;
|
|
585
|
+
try {
|
|
586
|
+
response = await ctx.fetch(url.toString(), {
|
|
587
|
+
method: "GET",
|
|
588
|
+
headers: { accept: options.accept ?? "*/*", "user-agent": USER_AGENT },
|
|
589
|
+
...ctx.signal ? { signal: ctx.signal } : {}
|
|
590
|
+
});
|
|
591
|
+
} catch (error) {
|
|
592
|
+
env.log(`${env.vendor} ${env.tool} media GET failed ${Date.now() - started}ms`);
|
|
593
|
+
if (errorCode(error) === "URL_REFUSED") {
|
|
594
|
+
throw new ToolFailure(`The ${what} URL was refused (${describe(error)}). Use a public https URL.${nothingChanged}`);
|
|
595
|
+
}
|
|
596
|
+
throw new ToolFailure(`The ${what} could not be downloaded (${describe(error)}).${nothingChanged}`);
|
|
597
|
+
}
|
|
598
|
+
env.log(`${env.vendor} ${env.tool} media GET ${response.status} ${Date.now() - started}ms`);
|
|
599
|
+
if (!response.ok) {
|
|
600
|
+
await response.body?.cancel().catch(() => {
|
|
601
|
+
});
|
|
602
|
+
throw new ToolFailure(`The ${what} URL answered HTTP ${response.status}.${nothingChanged}`);
|
|
603
|
+
}
|
|
604
|
+
try {
|
|
605
|
+
const bytes = await readCapped(response, options.maxBytes);
|
|
606
|
+
return { bytes, contentType: response.headers.get("content-type") };
|
|
607
|
+
} catch (error) {
|
|
608
|
+
if (error instanceof TooLarge) {
|
|
609
|
+
throw new ToolFailure(`The ${what} is larger than ${formatNumber(options.maxBytes)} bytes, the most ${label} accepts.${nothingChanged}`);
|
|
610
|
+
}
|
|
611
|
+
throw new ToolFailure(`The ${what} could not be downloaded (${describe(error)}).${nothingChanged}`);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
return { api, media };
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/core/origins.ts
|
|
618
|
+
function parseSiteUrl(value) {
|
|
619
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
620
|
+
if (!text) return { ok: false, problem: "is empty" };
|
|
621
|
+
let url;
|
|
622
|
+
try {
|
|
623
|
+
url = new URL(text.includes("://") ? text : `https://${text}`);
|
|
624
|
+
} catch {
|
|
625
|
+
return { ok: false, problem: "is not a valid address (expected one like https://example.com)" };
|
|
626
|
+
}
|
|
627
|
+
if (url.protocol !== "https:") return { ok: false, problem: `must be an https address, not ${url.protocol}//` };
|
|
628
|
+
if (url.username || url.password) return { ok: false, problem: "must not contain a user name or password" };
|
|
629
|
+
if (!url.hostname) return { ok: false, problem: "has no host name" };
|
|
630
|
+
return { ok: true, url, origin: url.origin };
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/core/schema.ts
|
|
634
|
+
var patterns = /* @__PURE__ */ new Map();
|
|
635
|
+
function patternOf(source) {
|
|
636
|
+
let compiled = patterns.get(source);
|
|
637
|
+
if (!compiled) {
|
|
638
|
+
compiled = new RegExp(source, "u");
|
|
639
|
+
patterns.set(source, compiled);
|
|
640
|
+
}
|
|
641
|
+
return compiled;
|
|
642
|
+
}
|
|
643
|
+
function isPlainObject(value) {
|
|
644
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
645
|
+
}
|
|
646
|
+
function isHttpUrl(value) {
|
|
647
|
+
try {
|
|
648
|
+
const url = new URL(value);
|
|
649
|
+
return url.protocol === "https:" || url.protocol === "http:";
|
|
650
|
+
} catch {
|
|
651
|
+
return false;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
function name(path) {
|
|
655
|
+
return `\`${path}\``;
|
|
656
|
+
}
|
|
657
|
+
function child(path, key) {
|
|
658
|
+
return path ? `${path}.${key}` : key;
|
|
659
|
+
}
|
|
660
|
+
function checkValue(schema, value, path, issues) {
|
|
661
|
+
switch (schema.type) {
|
|
662
|
+
case "object":
|
|
663
|
+
checkObject(schema, value, path, issues);
|
|
664
|
+
return;
|
|
665
|
+
case "array": {
|
|
666
|
+
if (!Array.isArray(value)) {
|
|
667
|
+
issues.push(`${name(path)} must be an array`);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
if (schema.minItems !== void 0 && value.length < schema.minItems) {
|
|
671
|
+
issues.push(`${name(path)} must have at least ${schema.minItems} item${schema.minItems === 1 ? "" : "s"}`);
|
|
672
|
+
}
|
|
673
|
+
if (schema.maxItems !== void 0 && value.length > schema.maxItems) {
|
|
674
|
+
issues.push(`${name(path)} must have at most ${schema.maxItems} item${schema.maxItems === 1 ? "" : "s"}`);
|
|
675
|
+
}
|
|
676
|
+
if (schema.uniqueItems && new Set(value.map((item) => JSON.stringify(item))).size !== value.length) {
|
|
677
|
+
issues.push(`${name(path)} must not repeat an item`);
|
|
678
|
+
}
|
|
679
|
+
if (schema.items) {
|
|
680
|
+
value.forEach((item, index) => checkValue(schema.items, item, `${path}[${index}]`, issues));
|
|
681
|
+
}
|
|
682
|
+
break;
|
|
683
|
+
}
|
|
684
|
+
case "string": {
|
|
685
|
+
if (typeof value !== "string") {
|
|
686
|
+
issues.push(`${name(path)} must be a string`);
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
const length = Array.from(value).length;
|
|
690
|
+
if (schema.minLength !== void 0 && length < schema.minLength) {
|
|
691
|
+
issues.push(schema.minLength === 1 ? `${name(path)} must not be empty` : `${name(path)} must be at least ${schema.minLength} characters`);
|
|
692
|
+
}
|
|
693
|
+
if (schema.maxLength !== void 0 && length > schema.maxLength) {
|
|
694
|
+
issues.push(`${name(path)} must be at most ${schema.maxLength} characters (it has ${length})`);
|
|
695
|
+
}
|
|
696
|
+
if (schema.format === "uri" && !isHttpUrl(value)) {
|
|
697
|
+
issues.push(`${name(path)} must be an absolute http(s) URL`);
|
|
698
|
+
} else if (schema.pattern !== void 0 && !patternOf(schema.pattern).test(value)) {
|
|
699
|
+
issues.push(`${name(path)} does not have the expected format${schema.description ? ` (${schema.description})` : ""}`);
|
|
700
|
+
}
|
|
701
|
+
break;
|
|
702
|
+
}
|
|
703
|
+
case "integer":
|
|
704
|
+
case "number": {
|
|
705
|
+
if (typeof value !== "number" || !Number.isFinite(value) || schema.type === "integer" && !Number.isInteger(value)) {
|
|
706
|
+
issues.push(`${name(path)} must be ${schema.type === "integer" ? "an integer" : "a number"}`);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
710
|
+
issues.push(`${name(path)} must be at least ${schema.minimum}`);
|
|
711
|
+
}
|
|
712
|
+
if (schema.maximum !== void 0 && value > schema.maximum) {
|
|
713
|
+
issues.push(`${name(path)} must be at most ${schema.maximum}`);
|
|
714
|
+
}
|
|
715
|
+
break;
|
|
716
|
+
}
|
|
717
|
+
case "boolean":
|
|
718
|
+
if (typeof value !== "boolean") {
|
|
719
|
+
issues.push(`${name(path)} must be true or false`);
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
break;
|
|
723
|
+
default:
|
|
724
|
+
break;
|
|
725
|
+
}
|
|
726
|
+
if (schema.enum && !schema.enum.includes(value)) {
|
|
727
|
+
issues.push(`${name(path)} must be one of ${schema.enum.map((option) => JSON.stringify(option)).join(", ")}`);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function checkObject(schema, value, path, issues) {
|
|
731
|
+
if (!isPlainObject(value)) {
|
|
732
|
+
issues.push(`${path ? name(path) : "the arguments"} must be an object`);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const properties = schema.properties ?? {};
|
|
736
|
+
for (const key of schema.required ?? []) {
|
|
737
|
+
if (value[key] === void 0 || value[key] === null) issues.push(`${name(child(path, key))} is required`);
|
|
738
|
+
}
|
|
739
|
+
const unknown = [];
|
|
740
|
+
for (const [key, item] of Object.entries(value)) {
|
|
741
|
+
const property = properties[key];
|
|
742
|
+
if (!property) {
|
|
743
|
+
if (schema.additionalProperties === false) unknown.push(key);
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (item === void 0 || item === null) continue;
|
|
747
|
+
checkValue(property, item, child(path, key), issues);
|
|
748
|
+
}
|
|
749
|
+
if (unknown.length) {
|
|
750
|
+
const known = Object.keys(properties);
|
|
751
|
+
issues.push(`unknown ${path ? `field${unknown.length > 1 ? "s" : ""} in ${name(path)}` : `argument${unknown.length > 1 ? "s" : ""}`} ${unknown.map((key) => JSON.stringify(key)).join(", ")}` + (known.length ? ` (expected: ${known.join(", ")})` : ""));
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function copyDefault(value) {
|
|
755
|
+
return typeof value === "object" && value !== null ? JSON.parse(JSON.stringify(value)) : value;
|
|
756
|
+
}
|
|
757
|
+
function validateArguments(schema, args) {
|
|
758
|
+
const input = args === void 0 || args === null ? {} : args;
|
|
759
|
+
if (!isPlainObject(input)) return { ok: false, issues: ["the arguments must be an object"] };
|
|
760
|
+
const value = { ...input };
|
|
761
|
+
if (!schema.properties?.["toolCallId"]) delete value["toolCallId"];
|
|
762
|
+
const issues = [];
|
|
763
|
+
checkObject(schema, value, "", issues);
|
|
764
|
+
if (issues.length) return { ok: false, issues };
|
|
765
|
+
for (const [key, property] of Object.entries(schema.properties ?? {})) {
|
|
766
|
+
if (value[key] === null) delete value[key];
|
|
767
|
+
if (value[key] === void 0 && property.default !== void 0) value[key] = copyDefault(property.default);
|
|
768
|
+
}
|
|
769
|
+
return { ok: true, value };
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// src/core/upload-hosts.ts
|
|
773
|
+
var LABEL = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
774
|
+
function uploadHostProblem(entry) {
|
|
775
|
+
if (typeof entry !== "string") return "must be a host name";
|
|
776
|
+
const name2 = entry.startsWith(".") ? entry.slice(1) : entry;
|
|
777
|
+
const labels = name2.split(".");
|
|
778
|
+
if (name2.length > 253 || !labels.every((label) => LABEL.test(label))) {
|
|
779
|
+
return "must be a lowercase host name like uploads.example.com, or one with a leading dot like .example.com for every host under it";
|
|
780
|
+
}
|
|
781
|
+
if (labels.length < 2) return "needs at least two labels, like example.com";
|
|
782
|
+
if (/^[0-9]+$/.test(labels[labels.length - 1])) return "must be a host name, not an IP address";
|
|
783
|
+
return void 0;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// src/core/connector.ts
|
|
787
|
+
var ANNOTATIONS = {
|
|
788
|
+
read: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
789
|
+
create: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
790
|
+
update: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true },
|
|
791
|
+
delete: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true },
|
|
792
|
+
write: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
|
|
793
|
+
};
|
|
794
|
+
var VENDOR_PATTERN = /^[a-z][a-z0-9-]{1,29}$/;
|
|
795
|
+
var TOOL_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
796
|
+
var CREDENTIAL_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
797
|
+
var PICKER_KEY_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
798
|
+
var DOT_PATH_PATTERN = /^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+){0,5}$/;
|
|
799
|
+
var UNSAFE_PATH_NAMES = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
800
|
+
var PICKER_FIELDS = ["key", "label", "description", "multiple", "tool", "idField", "nameField", "legacyField"];
|
|
801
|
+
function deepFreeze(value) {
|
|
802
|
+
if (typeof value === "object" && value !== null && !Object.isFrozen(value)) {
|
|
803
|
+
Object.freeze(value);
|
|
804
|
+
for (const item of Object.values(value)) deepFreeze(item);
|
|
805
|
+
}
|
|
806
|
+
return value;
|
|
807
|
+
}
|
|
808
|
+
function assertDefinition(def) {
|
|
809
|
+
const problem = (message) => {
|
|
810
|
+
throw new Error(`connector "${def.vendor}": ${message}`);
|
|
811
|
+
};
|
|
812
|
+
if (!VENDOR_PATTERN.test(def.vendor)) problem("vendor must match ^[a-z][a-z0-9-]{1,29}$");
|
|
813
|
+
if (!def.label?.trim()) problem("label is required");
|
|
814
|
+
const originFields = def.originFields ?? [];
|
|
815
|
+
if (!def.origins.length && !originFields.length) problem("at least one origin or origin field is required");
|
|
816
|
+
for (const origin of def.origins) {
|
|
817
|
+
let url;
|
|
818
|
+
try {
|
|
819
|
+
url = new URL(origin);
|
|
820
|
+
} catch {
|
|
821
|
+
}
|
|
822
|
+
if (!url || url.protocol !== "https:" || url.origin !== origin) problem(`origin ${origin} must be an https origin like https://api.example.com`);
|
|
823
|
+
}
|
|
824
|
+
for (const name2 of def.credentials) {
|
|
825
|
+
if (!CREDENTIAL_PATTERN.test(name2)) problem(`credential ${name2} must match ^[a-z][a-z0-9_]*$`);
|
|
826
|
+
}
|
|
827
|
+
for (const [index, name2] of originFields.entries()) {
|
|
828
|
+
if (!def.credentials.includes(name2)) problem(`origin field ${name2} must be one of the credentials`);
|
|
829
|
+
if (originFields.indexOf(name2) !== index) problem(`origin field ${name2} is listed twice`);
|
|
830
|
+
}
|
|
831
|
+
const names = /* @__PURE__ */ new Set();
|
|
832
|
+
for (const tool of def.tools) {
|
|
833
|
+
if (!TOOL_PATTERN.test(tool.name)) problem(`tool ${tool.name} must match ^[a-z][a-z0-9_]{0,63}$`);
|
|
834
|
+
if (names.has(tool.name)) problem(`tool ${tool.name} is defined twice`);
|
|
835
|
+
names.add(tool.name);
|
|
836
|
+
if (!tool.title?.trim() || !tool.description?.trim()) problem(`tool ${tool.name} needs a title and a description`);
|
|
837
|
+
if (tool.description.length > 1024) problem(`tool ${tool.name} has a description over 1024 characters`);
|
|
838
|
+
if (!Object.hasOwn(ANNOTATIONS, tool.kind)) problem(`tool ${tool.name} has an unknown kind`);
|
|
839
|
+
if (tool.inputSchema.type !== "object" || tool.inputSchema.additionalProperties !== false) {
|
|
840
|
+
problem(`tool ${tool.name} needs an object input schema with additionalProperties: false`);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
for (const tool of def.tools) {
|
|
844
|
+
if (tool.kind === "read") continue;
|
|
845
|
+
const check = def.tools.find((candidate) => candidate.name === tool.check);
|
|
846
|
+
if (!check || check.kind !== "read") problem(`write tool ${tool.name} needs check: the name of a read tool`);
|
|
847
|
+
}
|
|
848
|
+
assertUploadHosts(def, problem);
|
|
849
|
+
assertRequiredCredentials(def, problem);
|
|
850
|
+
assertAccountPickers(def, problem);
|
|
851
|
+
}
|
|
852
|
+
function assertUploadHosts(def, problem) {
|
|
853
|
+
const hosts = def.uploadHosts;
|
|
854
|
+
if (hosts === void 0) return;
|
|
855
|
+
if (!Array.isArray(hosts)) problem('uploadHosts must be a list of host names, e.g. [".blobstore.apple.com"]');
|
|
856
|
+
hosts.forEach((entry, index) => {
|
|
857
|
+
const wrong = uploadHostProblem(entry);
|
|
858
|
+
if (wrong) problem(`upload host ${JSON.stringify(entry)} ${wrong}`);
|
|
859
|
+
if (hosts.indexOf(entry) !== index) problem(`upload host ${String(entry)} is listed twice`);
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
function assertRequiredCredentials(def, problem) {
|
|
863
|
+
const required = def.requiredCredentials;
|
|
864
|
+
if (required === void 0) return;
|
|
865
|
+
if (!Array.isArray(required) || !required.length) {
|
|
866
|
+
problem('requiredCredentials must be a list of credential lists, e.g. [["access_token"], ["api_key"]]');
|
|
867
|
+
}
|
|
868
|
+
required.forEach((list, index) => {
|
|
869
|
+
const which = `requiredCredentials[${index}]`;
|
|
870
|
+
if (!Array.isArray(list) || !list.length) problem(`${which} must list at least one credential`);
|
|
871
|
+
list.forEach((name2, position) => {
|
|
872
|
+
if (typeof name2 !== "string" || !def.credentials.includes(name2)) problem(`${which}: ${String(name2)} is not one of the credentials`);
|
|
873
|
+
if (list.indexOf(name2) !== position) problem(`${which} lists ${name2} twice`);
|
|
874
|
+
});
|
|
875
|
+
});
|
|
876
|
+
const lists = required;
|
|
877
|
+
lists.forEach((list, index) => {
|
|
878
|
+
const covered = lists.findIndex((other, otherIndex) => otherIndex !== index && other.every((name2) => list.includes(name2)) && (other.length < list.length || otherIndex < index));
|
|
879
|
+
if (covered !== -1) problem(`requiredCredentials[${index}] contains all of requiredCredentials[${covered}], so it is never needed`);
|
|
880
|
+
if (!def.origins.length && !list.some((name2) => def.originFields?.includes(name2))) {
|
|
881
|
+
problem(`requiredCredentials[${index}] needs an origin field: the module has no fixed origin, so a call made with only these credentials could reach nothing`);
|
|
882
|
+
}
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
function isDotPath(value) {
|
|
886
|
+
return typeof value === "string" && DOT_PATH_PATTERN.test(value) && !value.split(".").some((name2) => UNSAFE_PATH_NAMES.has(name2));
|
|
887
|
+
}
|
|
888
|
+
function assertAccountPickers(def, problem) {
|
|
889
|
+
const pickers = def.accountPickers;
|
|
890
|
+
if (pickers === void 0) return;
|
|
891
|
+
if (!Array.isArray(pickers)) problem("accountPickers must be a list");
|
|
892
|
+
const keys = /* @__PURE__ */ new Set();
|
|
893
|
+
for (const item of pickers) {
|
|
894
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) problem("each account picker must be an object");
|
|
895
|
+
const picker = item;
|
|
896
|
+
const key = picker["key"];
|
|
897
|
+
if (typeof key !== "string" || !PICKER_KEY_PATTERN.test(key)) problem(`account picker ${JSON.stringify(key)}: key must match ^[a-z][a-z0-9_]{0,63}$`);
|
|
898
|
+
if (keys.has(key)) problem(`account picker ${key} is defined twice`);
|
|
899
|
+
keys.add(key);
|
|
900
|
+
const fail = (message) => problem(`account picker ${key}: ${message}`);
|
|
901
|
+
const unknown = Object.keys(picker).filter((field) => !PICKER_FIELDS.includes(field));
|
|
902
|
+
if (unknown.length) fail(`unknown field${unknown.length > 1 ? "s" : ""} ${unknown.join(", ")} (expected: ${PICKER_FIELDS.join(", ")})`);
|
|
903
|
+
const { label, description, multiple, legacyField } = picker;
|
|
904
|
+
if (typeof label !== "string" || !label.trim()) fail("label is required");
|
|
905
|
+
if (description !== void 0 && (typeof description !== "string" || !description.trim() || description.length > 1024)) {
|
|
906
|
+
fail("description, when given, must be a text of 1 to 1024 characters");
|
|
907
|
+
}
|
|
908
|
+
if (typeof multiple !== "boolean") fail("multiple must be true or false");
|
|
909
|
+
const tool = def.tools.find((candidate) => candidate.name === picker["tool"]);
|
|
910
|
+
if (!tool || tool.kind !== "read") fail("tool must be the name of a read tool");
|
|
911
|
+
if (tool.inputSchema.required?.length) fail(`its tool ${tool.name} must take no required argument`);
|
|
912
|
+
for (const field of ["idField", "nameField"]) {
|
|
913
|
+
if (!isDotPath(picker[field])) fail(`${field} must be a dot path into each item the tool returns, like "id" or "account.name"`);
|
|
914
|
+
}
|
|
915
|
+
if (legacyField !== void 0 && (typeof legacyField !== "string" || !CREDENTIAL_PATTERN.test(legacyField))) {
|
|
916
|
+
fail("legacyField, when given, must match ^[a-z][a-z0-9_]{0,63}$");
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
function copyPicker(picker) {
|
|
921
|
+
return {
|
|
922
|
+
key: picker.key,
|
|
923
|
+
label: picker.label,
|
|
924
|
+
...picker.description !== void 0 ? { description: picker.description } : {},
|
|
925
|
+
multiple: picker.multiple,
|
|
926
|
+
tool: picker.tool,
|
|
927
|
+
idField: picker.idField,
|
|
928
|
+
nameField: picker.nameField,
|
|
929
|
+
...picker.legacyField !== void 0 ? { legacyField: picker.legacyField } : {}
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
function result(payload, isError, files = []) {
|
|
933
|
+
return {
|
|
934
|
+
content: [{ type: "text", text: JSON.stringify(payload) }, ...files.map(resourceBlock)],
|
|
935
|
+
...isError ? { isError: true } : {}
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function failure(message, details = {}) {
|
|
939
|
+
return result({ error: message, ...details }, true);
|
|
940
|
+
}
|
|
941
|
+
function trimmed(values) {
|
|
942
|
+
const out = {};
|
|
943
|
+
if (typeof values !== "object" || values === null) return out;
|
|
944
|
+
for (const [key, value] of Object.entries(values)) {
|
|
945
|
+
if (value === void 0 || value === null) continue;
|
|
946
|
+
const text = String(value).trim();
|
|
947
|
+
if (text) out[key] = text;
|
|
948
|
+
}
|
|
949
|
+
return out;
|
|
950
|
+
}
|
|
951
|
+
function defineConnector(def) {
|
|
952
|
+
assertDefinition(def);
|
|
953
|
+
const { label } = def;
|
|
954
|
+
const tools = new Map(def.tools.map((tool) => [tool.name, tool]));
|
|
955
|
+
const toolList = def.tools.map((tool) => tool.name).join(", ");
|
|
956
|
+
const credentialLabel = (name2) => def.credentialLabels?.[name2] ?? `${label} ${name2.replace(/_/g, " ")}`;
|
|
957
|
+
const required = requiredAlternatives(def);
|
|
958
|
+
const notConnected = (unmet) => {
|
|
959
|
+
const [first] = unmet;
|
|
960
|
+
if (unmet.length === 1 && first) {
|
|
961
|
+
return `${label} is not connected: the ${andList(first.map(credentialLabel))} ${first.length > 1 ? "are" : "is"} missing.`;
|
|
962
|
+
}
|
|
963
|
+
return `${label} is not connected: it needs ${orList(unmet.map((missing) => `the ${andList(missing.map(credentialLabel))}`))}.`;
|
|
964
|
+
};
|
|
965
|
+
const descriptors = def.tools.map((tool) => ({
|
|
966
|
+
name: tool.name,
|
|
967
|
+
title: tool.title,
|
|
968
|
+
description: tool.description,
|
|
969
|
+
inputSchema: JSON.parse(JSON.stringify(tool.inputSchema)),
|
|
970
|
+
annotations: { ...ANNOTATIONS[tool.kind] }
|
|
971
|
+
}));
|
|
972
|
+
async function call(toolName, args, ctx) {
|
|
973
|
+
const tool = typeof toolName === "string" ? tools.get(toolName) : void 0;
|
|
974
|
+
if (!tool) return failure(`Unknown tool ${JSON.stringify(String(toolName))}. ${label} tools: ${toolList}.`);
|
|
975
|
+
if (!ctx || typeof ctx.fetch !== "function") return failure(`${tool.name} cannot run: the host gave it no fetch function.`);
|
|
976
|
+
const log = (text) => {
|
|
977
|
+
try {
|
|
978
|
+
ctx.log?.(text);
|
|
979
|
+
} catch {
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
const given = trimmed(ctx.credentials);
|
|
983
|
+
const credentials = def.normalizeCredentials ? def.normalizeCredentials({ ...given }) : given;
|
|
984
|
+
const has = (name2) => Boolean(credentials[name2]);
|
|
985
|
+
const unmet = unmetAlternatives(required, has);
|
|
986
|
+
if (unmet.length) return failure(notConnected(unmet));
|
|
987
|
+
const complete = required.filter((list) => list.every(has));
|
|
988
|
+
const inUse = def.credentials.filter((name2) => complete.some((list) => list.includes(name2)));
|
|
989
|
+
const fieldOrigins = /* @__PURE__ */ new Map();
|
|
990
|
+
for (const name2 of def.originFields ?? []) {
|
|
991
|
+
if (!given[name2] && !inUse.includes(name2)) continue;
|
|
992
|
+
const site = parseSiteUrl(given[name2] ?? "");
|
|
993
|
+
if (!site.ok) return failure(`${label} is not connected correctly: the ${credentialLabel(name2)} ${site.problem}. Nothing was sent to ${label}.`);
|
|
994
|
+
fieldOrigins.set(name2, site.origin);
|
|
995
|
+
}
|
|
996
|
+
const origins = [.../* @__PURE__ */ new Set([...def.origins, ...fieldOrigins.values()])];
|
|
997
|
+
const parsed = validateArguments(tool.inputSchema, args);
|
|
998
|
+
if (!parsed.ok) return failure(`Invalid arguments for ${tool.name}: ${parsed.issues.join("; ")}. Nothing was sent to ${label}.`);
|
|
999
|
+
const frozenCredentials = Object.freeze({ ...credentials });
|
|
1000
|
+
let writeSent = false;
|
|
1001
|
+
const fileLimit = fileLimitOf(ctx);
|
|
1002
|
+
const files = [];
|
|
1003
|
+
let fileBytes = 0;
|
|
1004
|
+
const http = createHttp({
|
|
1005
|
+
vendor: def.vendor,
|
|
1006
|
+
label,
|
|
1007
|
+
tool: tool.name,
|
|
1008
|
+
readOnly: tool.kind === "read",
|
|
1009
|
+
origins,
|
|
1010
|
+
// A 401 names the credentials in use (for a module that needs none, the ones given).
|
|
1011
|
+
credentialLabels: (inUse.length ? inUse : def.credentials.filter(has)).map(credentialLabel),
|
|
1012
|
+
ctx,
|
|
1013
|
+
authHeaders: () => def.authHeaders?.(frozenCredentials) ?? {},
|
|
1014
|
+
log,
|
|
1015
|
+
onWriteSent: () => {
|
|
1016
|
+
writeSent = true;
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
const helpers = {
|
|
1020
|
+
tool: tool.name,
|
|
1021
|
+
credentials: frozenCredentials,
|
|
1022
|
+
ctx,
|
|
1023
|
+
origins: Object.freeze([...origins]),
|
|
1024
|
+
originOf: (credential) => {
|
|
1025
|
+
const origin = fieldOrigins.get(credential);
|
|
1026
|
+
if (!origin) throw new Error(`${credential} gives no origin in this call`);
|
|
1027
|
+
return origin;
|
|
1028
|
+
},
|
|
1029
|
+
api: http.api,
|
|
1030
|
+
media: http.media,
|
|
1031
|
+
page: (input) => fitPage(input),
|
|
1032
|
+
cursor: (cursor) => decodeCursor(tool.name, cursor),
|
|
1033
|
+
makeCursor: (state) => encodeCursor(tool.name, state),
|
|
1034
|
+
fileLimit: () => fileLimit,
|
|
1035
|
+
file: ({ name: name2, mimeType, bytes }) => {
|
|
1036
|
+
if (fileLimit === null) throw new ToolFailure(`This host takes no files, so ${tool.name} cannot hand one back.`);
|
|
1037
|
+
const total = fileBytes + bytes.byteLength;
|
|
1038
|
+
if (total > fileLimit) {
|
|
1039
|
+
throw new ToolFailure(files.length ? `The files of this call have ${formatNumber(total)} bytes in all, more than the ${formatNumber(fileLimit)} bytes this host takes from one call.` : `The file has ${formatNumber(bytes.byteLength)} bytes, more than the ${formatNumber(fileLimit)} bytes this host takes.`);
|
|
1040
|
+
}
|
|
1041
|
+
fileBytes = total;
|
|
1042
|
+
const info = { name: fileName(name2), mimeType: fileType(mimeType), size: bytes.byteLength };
|
|
1043
|
+
files.push({ ...info, bytes });
|
|
1044
|
+
return { ...info };
|
|
1045
|
+
},
|
|
1046
|
+
log
|
|
1047
|
+
};
|
|
1048
|
+
try {
|
|
1049
|
+
const data = await tool.run(parsed.value, helpers);
|
|
1050
|
+
const fitted = shrinkToFit(data ?? {});
|
|
1051
|
+
if (!fitted) return failure(`The ${label} result was too large to return. Ask for fewer items.`);
|
|
1052
|
+
const payload = fitted.value;
|
|
1053
|
+
return result(fitted.truncated && typeof payload === "object" ? { ...payload, truncated: true } : payload, false, files);
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
if (error instanceof OutcomeUnknown) {
|
|
1056
|
+
return result({
|
|
1057
|
+
outcome: "unknown",
|
|
1058
|
+
check: tool.check,
|
|
1059
|
+
error: `${error.message} Call ${tool.check} to see whether it was, before trying again.`
|
|
1060
|
+
}, true);
|
|
1061
|
+
}
|
|
1062
|
+
if (error instanceof ToolFailure) return failure(error.message, error.details);
|
|
1063
|
+
log(`${def.vendor} ${tool.name} unexpected ${error?.name ?? "error"}`);
|
|
1064
|
+
if (writeSent) {
|
|
1065
|
+
return result({
|
|
1066
|
+
outcome: "unknown",
|
|
1067
|
+
check: tool.check,
|
|
1068
|
+
error: `${tool.name} stopped unexpectedly after the change was sent to ${label}. Call ${tool.check} to see whether it was made, before trying again.`
|
|
1069
|
+
}, true);
|
|
1070
|
+
}
|
|
1071
|
+
return failure(`${tool.name} failed unexpectedly.${tool.kind === "read" ? "" : " Nothing was changed."}`);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
return deepFreeze({
|
|
1075
|
+
vendor: def.vendor,
|
|
1076
|
+
origins: [...def.origins],
|
|
1077
|
+
originFields: [...def.originFields ?? []],
|
|
1078
|
+
uploadHosts: [...def.uploadHosts ?? []],
|
|
1079
|
+
credentials: [...def.credentials],
|
|
1080
|
+
requiredCredentials: required.map((list) => [...list]),
|
|
1081
|
+
accountPickers: (def.accountPickers ?? []).map(copyPicker),
|
|
1082
|
+
tools: descriptors,
|
|
1083
|
+
call
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
// src/core/jwt.ts
|
|
1088
|
+
var TOKEN_EARLY_MS = 5 * 60 * 1e3;
|
|
1089
|
+
|
|
1090
|
+
// src/vendors/brevo/shape.ts
|
|
1091
|
+
function compact(value) {
|
|
1092
|
+
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0 && item !== null && item !== ""));
|
|
1093
|
+
}
|
|
1094
|
+
var HTML_LIMIT = 2e4;
|
|
1095
|
+
function html(text) {
|
|
1096
|
+
return typeof text === "string" && text ? truncate(text, HTML_LIMIT) : void 0;
|
|
1097
|
+
}
|
|
1098
|
+
function trimContact(contact) {
|
|
1099
|
+
return compact({
|
|
1100
|
+
id: contact?.id,
|
|
1101
|
+
email: contact?.email,
|
|
1102
|
+
attributes: contact?.attributes && Object.keys(contact.attributes).length ? contact.attributes : void 0,
|
|
1103
|
+
listIds: Array.isArray(contact?.listIds) && contact.listIds.length ? contact.listIds : void 0,
|
|
1104
|
+
listUnsubscribed: Array.isArray(contact?.listUnsubscribed) && contact.listUnsubscribed.length ? contact.listUnsubscribed : void 0,
|
|
1105
|
+
emailBlacklisted: contact?.emailBlacklisted,
|
|
1106
|
+
smsBlacklisted: contact?.smsBlacklisted,
|
|
1107
|
+
createdAt: contact?.createdAt,
|
|
1108
|
+
modifiedAt: contact?.modifiedAt
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
function statisticCounts(statistics) {
|
|
1112
|
+
if (typeof statistics !== "object" || statistics === null) return void 0;
|
|
1113
|
+
const counts = {};
|
|
1114
|
+
for (const [key, value] of Object.entries(statistics)) {
|
|
1115
|
+
if (Array.isArray(value)) counts[key] = value.length;
|
|
1116
|
+
else if (typeof value === "object" && value !== null) counts[key] = Object.keys(value).length;
|
|
1117
|
+
}
|
|
1118
|
+
return Object.keys(counts).length ? counts : void 0;
|
|
1119
|
+
}
|
|
1120
|
+
function trimCampaign(campaign, options = {}) {
|
|
1121
|
+
const statistics = campaign?.statistics;
|
|
1122
|
+
return compact({
|
|
1123
|
+
id: campaign?.id,
|
|
1124
|
+
name: campaign?.name,
|
|
1125
|
+
subject: campaign?.subject,
|
|
1126
|
+
previewText: campaign?.previewText,
|
|
1127
|
+
status: campaign?.status,
|
|
1128
|
+
type: campaign?.type,
|
|
1129
|
+
tag: campaign?.tag,
|
|
1130
|
+
scheduledAt: campaign?.scheduledAt,
|
|
1131
|
+
sentDate: campaign?.sentDate,
|
|
1132
|
+
createdAt: campaign?.createdAt,
|
|
1133
|
+
modifiedAt: campaign?.modifiedAt,
|
|
1134
|
+
sender: campaign?.sender,
|
|
1135
|
+
replyTo: campaign?.replyTo,
|
|
1136
|
+
toField: campaign?.toField,
|
|
1137
|
+
recipients: campaign?.recipients,
|
|
1138
|
+
testSent: campaign?.testSent,
|
|
1139
|
+
shareLink: campaign?.shareLink,
|
|
1140
|
+
globalStats: statistics?.globalStats && Object.keys(statistics.globalStats).length ? statistics.globalStats : void 0,
|
|
1141
|
+
htmlContent: options.html ? html(campaign?.htmlContent) : void 0
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
function trimTemplate(template, options = {}) {
|
|
1145
|
+
return compact({
|
|
1146
|
+
id: template?.id,
|
|
1147
|
+
name: template?.name,
|
|
1148
|
+
subject: template?.subject,
|
|
1149
|
+
isActive: template?.isActive,
|
|
1150
|
+
testSent: template?.testSent,
|
|
1151
|
+
tag: template?.tag,
|
|
1152
|
+
sender: template?.sender,
|
|
1153
|
+
replyTo: template?.replyTo,
|
|
1154
|
+
toField: template?.toField,
|
|
1155
|
+
doiTemplate: template?.doiTemplate,
|
|
1156
|
+
createdAt: template?.createdAt,
|
|
1157
|
+
modifiedAt: template?.modifiedAt,
|
|
1158
|
+
htmlContent: options.html ? html(template?.htmlContent) : void 0
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
async function offsetList(h, cursor, options) {
|
|
1162
|
+
const state = h.cursor(cursor);
|
|
1163
|
+
const offset = typeof state?.["o"] === "number" ? state["o"] : 0;
|
|
1164
|
+
const limit = typeof state?.["n"] === "number" ? state["n"] : options.limit;
|
|
1165
|
+
const skip = typeof state?.["s"] === "number" ? state["s"] : 0;
|
|
1166
|
+
const { data } = await h.api({ path: options.path, query: { ...options.query, limit, offset } });
|
|
1167
|
+
const items = Array.isArray(data?.[options.listField ?? options.key]) ? data[options.listField ?? options.key] : [];
|
|
1168
|
+
const total = typeof data?.count === "number" ? data.count : void 0;
|
|
1169
|
+
const more = total !== void 0 ? offset + items.length < total : items.length >= limit;
|
|
1170
|
+
return h.page({
|
|
1171
|
+
key: options.key,
|
|
1172
|
+
items: items.map(options.trim).slice(skip),
|
|
1173
|
+
extra: { ...total !== void 0 ? { total } : {}, ...options.extra?.(data) },
|
|
1174
|
+
resumeAt: (index) => h.makeCursor({ o: offset, n: limit, s: skip + index }),
|
|
1175
|
+
...more && items.length ? { nextPage: h.makeCursor({ o: offset + limit, n: limit, s: 0 }) } : {}
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
// src/vendors/brevo/index.ts
|
|
1180
|
+
var LABEL2 = "Brevo";
|
|
1181
|
+
var EMAIL = {
|
|
1182
|
+
type: "string",
|
|
1183
|
+
minLength: 3,
|
|
1184
|
+
maxLength: 320,
|
|
1185
|
+
pattern: "^[^@\\s]+@[^@\\s]+$",
|
|
1186
|
+
description: "An email address."
|
|
1187
|
+
};
|
|
1188
|
+
var PERSON = {
|
|
1189
|
+
type: "object",
|
|
1190
|
+
properties: { email: EMAIL, name: { type: "string", maxLength: 70, description: "The display name, up to 70 characters." } },
|
|
1191
|
+
required: ["email"],
|
|
1192
|
+
additionalProperties: false
|
|
1193
|
+
};
|
|
1194
|
+
var SENDER = {
|
|
1195
|
+
type: "object",
|
|
1196
|
+
description: "The sender: {email, name} of a verified sender (see list_senders), or {id} of a sender.",
|
|
1197
|
+
properties: {
|
|
1198
|
+
email: EMAIL,
|
|
1199
|
+
name: { type: "string", maxLength: 70, description: "The sender name." },
|
|
1200
|
+
id: { type: "integer", minimum: 1, description: "A sender id from list_senders, instead of email." }
|
|
1201
|
+
},
|
|
1202
|
+
additionalProperties: false
|
|
1203
|
+
};
|
|
1204
|
+
var CURSOR = { type: "string", description: "nextCursor from the previous result; pass the other arguments unchanged." };
|
|
1205
|
+
var IDENTIFIER = {
|
|
1206
|
+
type: "string",
|
|
1207
|
+
minLength: 1,
|
|
1208
|
+
maxLength: 320,
|
|
1209
|
+
description: "The contact: its email address, or its Brevo id (with identifier_type contact_id for an id that could be read as something else)."
|
|
1210
|
+
};
|
|
1211
|
+
var IDENTIFIER_TYPE = {
|
|
1212
|
+
type: "string",
|
|
1213
|
+
enum: ["email_id", "contact_id", "ext_id", "phone_id", "whatsapp_id", "landline_number_id"],
|
|
1214
|
+
description: "What identifier is: email_id, contact_id, ext_id (your own id), phone_id (the SMS attribute), whatsapp_id or landline_number_id. Leave out for an email address or a Brevo id."
|
|
1215
|
+
};
|
|
1216
|
+
var ATTRIBUTES = {
|
|
1217
|
+
type: "object",
|
|
1218
|
+
description: 'Contact attributes in upper case, as named in Brevo, e.g. {"FIRSTNAME": "Jane", "LASTNAME": "Doe", "SMS": "+15551234567"}.'
|
|
1219
|
+
};
|
|
1220
|
+
var LIST_IDS = {
|
|
1221
|
+
type: "array",
|
|
1222
|
+
items: { type: "integer", minimum: 1 },
|
|
1223
|
+
maxItems: 100,
|
|
1224
|
+
uniqueItems: true,
|
|
1225
|
+
description: "Brevo list ids (see list_lists)."
|
|
1226
|
+
};
|
|
1227
|
+
var DATE_TIME = (what) => ({
|
|
1228
|
+
type: "string",
|
|
1229
|
+
pattern: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}(:\\d{2}(\\.\\d+)?)?(Z|[+-]\\d{2}:?\\d{2})$",
|
|
1230
|
+
description: `${what}, an ISO 8601 date-time with a time zone, e.g. 2026-12-01T09:00:00.000Z.`
|
|
1231
|
+
});
|
|
1232
|
+
var DATE = (what) => ({ type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}$", description: `${what}, as YYYY-MM-DD.` });
|
|
1233
|
+
var CAMPAIGN_FIELDS = {
|
|
1234
|
+
name: { type: "string", minLength: 1, maxLength: 200, description: "The internal campaign name (recipients do not see it)." },
|
|
1235
|
+
subject: { type: "string", minLength: 1, maxLength: 500, description: "The subject line; it can use {{ contact.FIRSTNAME }}." },
|
|
1236
|
+
preview_text: { type: "string", maxLength: 300, description: "The preview text shown after the subject in inboxes." },
|
|
1237
|
+
sender: SENDER,
|
|
1238
|
+
reply_to: EMAIL,
|
|
1239
|
+
to_field: { type: "string", maxLength: 200, description: 'The To name, e.g. "{{ contact.FIRSTNAME }} {{ contact.LASTNAME }}".' },
|
|
1240
|
+
list_ids: { ...LIST_IDS, description: "The lists to send to (see list_lists)." },
|
|
1241
|
+
exclusion_list_ids: { ...LIST_IDS, description: "Lists whose contacts are left out." },
|
|
1242
|
+
segment_ids: { type: "array", items: { type: "integer", minimum: 1 }, maxItems: 100, uniqueItems: true, description: "Segments to send to, instead of or besides lists." },
|
|
1243
|
+
html_content: {
|
|
1244
|
+
type: "string",
|
|
1245
|
+
minLength: 1,
|
|
1246
|
+
maxLength: 1e6,
|
|
1247
|
+
description: "The HTML body. It must contain {{ unsubscribe }}; {{ mirror }} links the web version. Give html_content, html_url or template_id."
|
|
1248
|
+
},
|
|
1249
|
+
html_url: { type: "string", format: "uri", maxLength: 2e3, description: "A public URL Brevo reads the HTML body from, instead of html_content." },
|
|
1250
|
+
template_id: { type: "integer", minimum: 1, description: "A template to use for the body (see list_templates), instead of html_content." },
|
|
1251
|
+
scheduled_at: DATE_TIME("When Brevo sends it. Leave out to keep a draft"),
|
|
1252
|
+
tag: { type: "string", maxLength: 100, description: "A tag to group campaigns by." },
|
|
1253
|
+
params: { type: "object", description: "Values for {{ params.NAME }} placeholders in the body." }
|
|
1254
|
+
};
|
|
1255
|
+
function checkSender(sender) {
|
|
1256
|
+
if (sender && sender.email === void 0 && sender.id === void 0) {
|
|
1257
|
+
throw new ToolFailure("sender needs an email or an id. Nothing was changed.");
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
function campaignBody(args) {
|
|
1261
|
+
checkSender(args.sender);
|
|
1262
|
+
const recipients = compact({
|
|
1263
|
+
listIds: args.list_ids,
|
|
1264
|
+
exclusionListIds: args.exclusion_list_ids,
|
|
1265
|
+
segmentIds: args.segment_ids
|
|
1266
|
+
});
|
|
1267
|
+
return compact({
|
|
1268
|
+
name: args.name,
|
|
1269
|
+
subject: args.subject,
|
|
1270
|
+
previewText: args.preview_text,
|
|
1271
|
+
sender: args.sender,
|
|
1272
|
+
replyTo: args.reply_to,
|
|
1273
|
+
toField: args.to_field,
|
|
1274
|
+
recipients: Object.keys(recipients).length ? recipients : void 0,
|
|
1275
|
+
htmlContent: args.html_content,
|
|
1276
|
+
htmlUrl: args.html_url,
|
|
1277
|
+
templateId: args.template_id,
|
|
1278
|
+
scheduledAt: args.scheduled_at,
|
|
1279
|
+
tag: args.tag,
|
|
1280
|
+
params: args.params
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
function contactPath(identifier) {
|
|
1284
|
+
return `/v3/contacts/${encodeURIComponent(identifier)}`;
|
|
1285
|
+
}
|
|
1286
|
+
var LIST_MEMBERS_MAX = 150;
|
|
1287
|
+
function membersBody(args) {
|
|
1288
|
+
const given = [args.emails?.length ? "emails" : "", args.ids?.length ? "ids" : ""].filter(Boolean);
|
|
1289
|
+
if (given.length !== 1) throw new ToolFailure("Give emails or ids (one of the two). Nothing was changed.");
|
|
1290
|
+
return args.emails?.length ? { emails: args.emails } : { ids: args.ids };
|
|
1291
|
+
}
|
|
1292
|
+
var MEMBERS_SCHEMA = {
|
|
1293
|
+
list_id: { type: "integer", minimum: 1, description: "The list id (see list_lists)." },
|
|
1294
|
+
emails: { type: "array", items: EMAIL, minItems: 1, maxItems: LIST_MEMBERS_MAX, uniqueItems: true, description: `Contacts by email address, up to ${LIST_MEMBERS_MAX}.` },
|
|
1295
|
+
ids: { type: "array", items: { type: "integer", minimum: 1 }, minItems: 1, maxItems: LIST_MEMBERS_MAX, uniqueItems: true, description: `Contacts by Brevo id, up to ${LIST_MEMBERS_MAX}, instead of emails.` }
|
|
1296
|
+
};
|
|
1297
|
+
function listResult(data) {
|
|
1298
|
+
const contacts = data?.contacts ?? {};
|
|
1299
|
+
return compact({
|
|
1300
|
+
success: Array.isArray(contacts.success) ? contacts.success : void 0,
|
|
1301
|
+
failure: Array.isArray(contacts.failure) ? contacts.failure : void 0,
|
|
1302
|
+
total: contacts.total
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
async function sendTransactional(h, body) {
|
|
1306
|
+
return h.api({
|
|
1307
|
+
method: "POST",
|
|
1308
|
+
path: "/v3/smtp/email",
|
|
1309
|
+
json: body,
|
|
1310
|
+
write: true,
|
|
1311
|
+
errors: { 400: "Brevo did not accept the email", 402: "Brevo refused the email: the account has no email credits left" }
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
function routedParts(segments) {
|
|
1315
|
+
const parts = [];
|
|
1316
|
+
for (const piece of segments.join("/").split(/[\\/]/)) {
|
|
1317
|
+
const part = (piece.split(";")[0] ?? "").toLowerCase();
|
|
1318
|
+
if (part === "" || part === ".") continue;
|
|
1319
|
+
if (part === "..") parts.pop();
|
|
1320
|
+
else parts.push(part);
|
|
1321
|
+
}
|
|
1322
|
+
return parts;
|
|
1323
|
+
}
|
|
1324
|
+
var connector = defineConnector({
|
|
1325
|
+
vendor: "brevo",
|
|
1326
|
+
label: LABEL2,
|
|
1327
|
+
origins: ["https://api.brevo.com"],
|
|
1328
|
+
credentials: ["apikey"],
|
|
1329
|
+
credentialLabels: { apikey: "Brevo API key" },
|
|
1330
|
+
authHeaders: (credentials) => ({ "api-key": credentials["apikey"] }),
|
|
1331
|
+
tools: [
|
|
1332
|
+
{
|
|
1333
|
+
name: "get_account",
|
|
1334
|
+
kind: "read",
|
|
1335
|
+
title: "Get the Brevo account",
|
|
1336
|
+
description: "The connected Brevo account: email, company, plan with its remaining email and SMS credits, and whether marketing automation is on. A quick check that the API key works.",
|
|
1337
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
1338
|
+
async run(_args, h) {
|
|
1339
|
+
const { data } = await h.api({ path: "/v3/account" });
|
|
1340
|
+
return compact({
|
|
1341
|
+
email: data?.email,
|
|
1342
|
+
firstName: data?.firstName,
|
|
1343
|
+
lastName: data?.lastName,
|
|
1344
|
+
companyName: data?.companyName,
|
|
1345
|
+
plan: Array.isArray(data?.plan) ? data.plan : void 0,
|
|
1346
|
+
marketingAutomation: data?.marketingAutomation?.enabled
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
},
|
|
1350
|
+
{
|
|
1351
|
+
name: "list_senders",
|
|
1352
|
+
kind: "read",
|
|
1353
|
+
title: "List Brevo senders",
|
|
1354
|
+
description: "The senders of the account with their ids, names, emails and whether they are active. Only active (verified) senders can send campaigns and transactional email.",
|
|
1355
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
1356
|
+
async run(_args, h) {
|
|
1357
|
+
const { data } = await h.api({ path: "/v3/senders" });
|
|
1358
|
+
const senders = Array.isArray(data?.senders) ? data.senders : [];
|
|
1359
|
+
return { senders: senders.map((sender) => compact({ id: sender?.id, name: sender?.name, email: sender?.email, active: sender?.active })) };
|
|
1360
|
+
}
|
|
1361
|
+
},
|
|
1362
|
+
{
|
|
1363
|
+
name: "list_contacts",
|
|
1364
|
+
kind: "read",
|
|
1365
|
+
title: "List Brevo contacts",
|
|
1366
|
+
description: "Contacts with their attributes, lists and blocklist flags, newest first. Filter by lists or a segment, by creation or change date, or by one attribute value. Returns the total; pass nextCursor back as cursor for more.",
|
|
1367
|
+
inputSchema: {
|
|
1368
|
+
type: "object",
|
|
1369
|
+
properties: {
|
|
1370
|
+
limit: { type: "integer", minimum: 1, maximum: 1e3, default: 50, description: "Contacts per page, 1 to 1000 (default 50)." },
|
|
1371
|
+
list_ids: LIST_IDS,
|
|
1372
|
+
segment_id: { type: "integer", minimum: 1, description: "Only contacts of this segment (not with list_ids)." },
|
|
1373
|
+
modified_since: DATE_TIME("Only contacts changed after this time"),
|
|
1374
|
+
created_since: DATE_TIME("Only contacts created after this time"),
|
|
1375
|
+
filter: { type: "string", maxLength: 500, description: 'An attribute filter, equals only, e.g. equals(FIRSTNAME,"Jane").' },
|
|
1376
|
+
sort: { type: "string", enum: ["asc", "desc"], default: "desc", description: "By creation date: desc (default) or asc." },
|
|
1377
|
+
cursor: CURSOR
|
|
1378
|
+
},
|
|
1379
|
+
additionalProperties: false
|
|
1380
|
+
},
|
|
1381
|
+
async run(args, h) {
|
|
1382
|
+
if (args.list_ids?.length && args.segment_id !== void 0) throw new ToolFailure("Give list_ids or segment_id, not both. Nothing was sent.");
|
|
1383
|
+
return offsetList(h, args.cursor, {
|
|
1384
|
+
key: "contacts",
|
|
1385
|
+
path: "/v3/contacts",
|
|
1386
|
+
limit: args.limit,
|
|
1387
|
+
query: {
|
|
1388
|
+
listIds: args.list_ids,
|
|
1389
|
+
segmentId: args.segment_id,
|
|
1390
|
+
modifiedSince: args.modified_since,
|
|
1391
|
+
createdSince: args.created_since,
|
|
1392
|
+
filter: args.filter,
|
|
1393
|
+
sort: args.sort
|
|
1394
|
+
},
|
|
1395
|
+
trim: trimContact
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
},
|
|
1399
|
+
{
|
|
1400
|
+
name: "get_contact",
|
|
1401
|
+
kind: "read",
|
|
1402
|
+
title: "Get a Brevo contact",
|
|
1403
|
+
description: "One contact by email address, Brevo id, your own id or phone: attributes, lists, blocklist flags, and how many campaign messages it was sent, opened and clicked (the events themselves with include_statistics).",
|
|
1404
|
+
inputSchema: {
|
|
1405
|
+
type: "object",
|
|
1406
|
+
properties: {
|
|
1407
|
+
identifier: IDENTIFIER,
|
|
1408
|
+
identifier_type: IDENTIFIER_TYPE,
|
|
1409
|
+
include_statistics: { type: "boolean", default: false, description: "true to return the campaign events (sent, opened, clicked...) instead of their counts." }
|
|
1410
|
+
},
|
|
1411
|
+
required: ["identifier"],
|
|
1412
|
+
additionalProperties: false
|
|
1413
|
+
},
|
|
1414
|
+
async run(args, h) {
|
|
1415
|
+
const { data } = await h.api({
|
|
1416
|
+
path: contactPath(args.identifier),
|
|
1417
|
+
query: { identifierType: args.identifier_type },
|
|
1418
|
+
errors: { 404: "Brevo has no contact with that identifier" }
|
|
1419
|
+
});
|
|
1420
|
+
return compact({
|
|
1421
|
+
...trimContact(data),
|
|
1422
|
+
...args.include_statistics ? { statistics: data?.statistics } : { statisticCounts: statisticCounts(data?.statistics) }
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
},
|
|
1426
|
+
{
|
|
1427
|
+
name: "upsert_contact",
|
|
1428
|
+
kind: "update",
|
|
1429
|
+
check: "get_contact",
|
|
1430
|
+
title: "Create or update a Brevo contact",
|
|
1431
|
+
description: "Creates a contact, or updates the one with the same email (update_existing, on by default): attributes, lists to add it to, and blocklist flags. Lists it already belongs to are kept. Returns its id when Brevo gives one.",
|
|
1432
|
+
inputSchema: {
|
|
1433
|
+
type: "object",
|
|
1434
|
+
properties: {
|
|
1435
|
+
email: EMAIL,
|
|
1436
|
+
ext_id: { type: "string", minLength: 1, maxLength: 200, description: "Your own id for the contact (the EXT_ID attribute)." },
|
|
1437
|
+
attributes: ATTRIBUTES,
|
|
1438
|
+
list_ids: { ...LIST_IDS, description: "Lists to add the contact to." },
|
|
1439
|
+
email_blacklisted: { type: "boolean", description: "true to block it from all email (an unsubscribe), false to unblock." },
|
|
1440
|
+
sms_blacklisted: { type: "boolean", description: "true to block it from all SMS, false to unblock." },
|
|
1441
|
+
update_existing: { type: "boolean", default: true, description: "Update a contact that already exists (default true); false makes an existing email an error." }
|
|
1442
|
+
},
|
|
1443
|
+
additionalProperties: false
|
|
1444
|
+
},
|
|
1445
|
+
async run(args, h) {
|
|
1446
|
+
if (!args.email && !args.ext_id && !args.attributes) {
|
|
1447
|
+
throw new ToolFailure("Give an email, an ext_id or attributes such as SMS to identify the contact. Nothing was changed.");
|
|
1448
|
+
}
|
|
1449
|
+
const { status, data } = await h.api({
|
|
1450
|
+
method: "POST",
|
|
1451
|
+
path: "/v3/contacts",
|
|
1452
|
+
json: compact({
|
|
1453
|
+
email: args.email,
|
|
1454
|
+
ext_id: args.ext_id,
|
|
1455
|
+
attributes: args.attributes,
|
|
1456
|
+
listIds: args.list_ids,
|
|
1457
|
+
emailBlacklisted: args.email_blacklisted,
|
|
1458
|
+
smsBlacklisted: args.sms_blacklisted,
|
|
1459
|
+
updateEnabled: args.update_existing
|
|
1460
|
+
}),
|
|
1461
|
+
write: true,
|
|
1462
|
+
errors: { 400: "Brevo did not accept the contact" }
|
|
1463
|
+
});
|
|
1464
|
+
return compact({
|
|
1465
|
+
saved: true,
|
|
1466
|
+
id: data?.id,
|
|
1467
|
+
email: args.email,
|
|
1468
|
+
created: status === 201 && !args.update_existing ? true : void 0,
|
|
1469
|
+
updated: status === 204 ? true : void 0
|
|
1470
|
+
});
|
|
1471
|
+
}
|
|
1472
|
+
},
|
|
1473
|
+
{
|
|
1474
|
+
name: "update_contact",
|
|
1475
|
+
kind: "update",
|
|
1476
|
+
check: "get_contact",
|
|
1477
|
+
title: "Update a Brevo contact",
|
|
1478
|
+
description: "Changes an existing contact: attributes (only those given), lists to add it to or remove it from, blocklist flags, or its ext_id. Removing it from a list keeps the contact.",
|
|
1479
|
+
inputSchema: {
|
|
1480
|
+
type: "object",
|
|
1481
|
+
properties: {
|
|
1482
|
+
identifier: IDENTIFIER,
|
|
1483
|
+
identifier_type: IDENTIFIER_TYPE,
|
|
1484
|
+
attributes: ATTRIBUTES,
|
|
1485
|
+
ext_id: { type: "string", minLength: 1, maxLength: 200, description: "A new EXT_ID." },
|
|
1486
|
+
list_ids: { ...LIST_IDS, description: "Lists to add the contact to." },
|
|
1487
|
+
unlink_list_ids: { ...LIST_IDS, description: "Lists to remove the contact from." },
|
|
1488
|
+
email_blacklisted: { type: "boolean", description: "true to block it from all email, false to unblock." },
|
|
1489
|
+
sms_blacklisted: { type: "boolean", description: "true to block it from all SMS, false to unblock." }
|
|
1490
|
+
},
|
|
1491
|
+
required: ["identifier"],
|
|
1492
|
+
additionalProperties: false
|
|
1493
|
+
},
|
|
1494
|
+
async run(args, h) {
|
|
1495
|
+
const body = compact({
|
|
1496
|
+
attributes: args.attributes,
|
|
1497
|
+
ext_id: args.ext_id,
|
|
1498
|
+
listIds: args.list_ids,
|
|
1499
|
+
unlinkListIds: args.unlink_list_ids,
|
|
1500
|
+
emailBlacklisted: args.email_blacklisted,
|
|
1501
|
+
smsBlacklisted: args.sms_blacklisted
|
|
1502
|
+
});
|
|
1503
|
+
if (!Object.keys(body).length) throw new ToolFailure("Nothing to change: give attributes, lists or a blocklist flag. Nothing was changed.");
|
|
1504
|
+
await h.api({
|
|
1505
|
+
method: "PUT",
|
|
1506
|
+
path: contactPath(args.identifier),
|
|
1507
|
+
query: { identifierType: args.identifier_type },
|
|
1508
|
+
json: body,
|
|
1509
|
+
write: true,
|
|
1510
|
+
errors: { 404: "Brevo has no contact with that identifier" }
|
|
1511
|
+
});
|
|
1512
|
+
return { updated: true, identifier: args.identifier };
|
|
1513
|
+
}
|
|
1514
|
+
},
|
|
1515
|
+
{
|
|
1516
|
+
name: "delete_contact",
|
|
1517
|
+
kind: "delete",
|
|
1518
|
+
check: "get_contact",
|
|
1519
|
+
title: "Delete a Brevo contact",
|
|
1520
|
+
description: "Deletes a contact for good, with its attributes and history. To stop emailing someone, prefer upsert_contact with email_blacklisted: true.",
|
|
1521
|
+
inputSchema: {
|
|
1522
|
+
type: "object",
|
|
1523
|
+
properties: { identifier: IDENTIFIER, identifier_type: IDENTIFIER_TYPE },
|
|
1524
|
+
required: ["identifier"],
|
|
1525
|
+
additionalProperties: false
|
|
1526
|
+
},
|
|
1527
|
+
async run(args, h) {
|
|
1528
|
+
await h.api({
|
|
1529
|
+
method: "DELETE",
|
|
1530
|
+
path: contactPath(args.identifier),
|
|
1531
|
+
query: { identifierType: args.identifier_type },
|
|
1532
|
+
write: true,
|
|
1533
|
+
errors: { 404: "Brevo has no contact with that identifier" }
|
|
1534
|
+
});
|
|
1535
|
+
return { deleted: true, identifier: args.identifier };
|
|
1536
|
+
}
|
|
1537
|
+
},
|
|
1538
|
+
{
|
|
1539
|
+
name: "list_folders",
|
|
1540
|
+
kind: "read",
|
|
1541
|
+
title: "List Brevo contact folders",
|
|
1542
|
+
description: "The folders that hold contact lists, with their subscriber counts. Every list belongs to a folder. Pass nextCursor back as cursor for more.",
|
|
1543
|
+
inputSchema: {
|
|
1544
|
+
type: "object",
|
|
1545
|
+
properties: {
|
|
1546
|
+
limit: { type: "integer", minimum: 1, maximum: 50, default: 50, description: "Folders per page, 1 to 50 (default 50)." },
|
|
1547
|
+
cursor: CURSOR
|
|
1548
|
+
},
|
|
1549
|
+
additionalProperties: false
|
|
1550
|
+
},
|
|
1551
|
+
async run(args, h) {
|
|
1552
|
+
return offsetList(h, args.cursor, {
|
|
1553
|
+
key: "folders",
|
|
1554
|
+
path: "/v3/contacts/folders",
|
|
1555
|
+
limit: args.limit,
|
|
1556
|
+
trim: (folder) => compact({
|
|
1557
|
+
id: folder?.id,
|
|
1558
|
+
name: folder?.name,
|
|
1559
|
+
totalSubscribers: folder?.totalSubscribers,
|
|
1560
|
+
uniqueSubscribers: folder?.uniqueSubscribers,
|
|
1561
|
+
totalBlacklisted: folder?.totalBlacklisted
|
|
1562
|
+
})
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
name: "create_folder",
|
|
1568
|
+
kind: "create",
|
|
1569
|
+
check: "list_folders",
|
|
1570
|
+
title: "Create a Brevo contact folder",
|
|
1571
|
+
description: "Creates a folder for contact lists and returns its id.",
|
|
1572
|
+
inputSchema: {
|
|
1573
|
+
type: "object",
|
|
1574
|
+
properties: { name: { type: "string", minLength: 1, maxLength: 200, description: "The folder name." } },
|
|
1575
|
+
required: ["name"],
|
|
1576
|
+
additionalProperties: false
|
|
1577
|
+
},
|
|
1578
|
+
async run(args, h) {
|
|
1579
|
+
const { data } = await h.api({ method: "POST", path: "/v3/contacts/folders", json: { name: args.name }, write: true });
|
|
1580
|
+
return { id: data?.id, name: args.name };
|
|
1581
|
+
}
|
|
1582
|
+
},
|
|
1583
|
+
{
|
|
1584
|
+
name: "list_lists",
|
|
1585
|
+
kind: "read",
|
|
1586
|
+
title: "List Brevo contact lists",
|
|
1587
|
+
description: "Contact lists with their ids, folders and subscriber and blocklisted counts; one folder's lists with folder_id. Pass nextCursor back as cursor for more.",
|
|
1588
|
+
inputSchema: {
|
|
1589
|
+
type: "object",
|
|
1590
|
+
properties: {
|
|
1591
|
+
folder_id: { type: "integer", minimum: 1, description: "Only the lists of this folder." },
|
|
1592
|
+
limit: { type: "integer", minimum: 1, maximum: 50, default: 50, description: "Lists per page, 1 to 50 (default 50)." },
|
|
1593
|
+
cursor: CURSOR
|
|
1594
|
+
},
|
|
1595
|
+
additionalProperties: false
|
|
1596
|
+
},
|
|
1597
|
+
async run(args, h) {
|
|
1598
|
+
return offsetList(h, args.cursor, {
|
|
1599
|
+
key: "lists",
|
|
1600
|
+
path: args.folder_id !== void 0 ? `/v3/contacts/folders/${args.folder_id}/lists` : "/v3/contacts/lists",
|
|
1601
|
+
limit: args.limit,
|
|
1602
|
+
trim: (list) => compact({
|
|
1603
|
+
id: list?.id,
|
|
1604
|
+
name: list?.name,
|
|
1605
|
+
folderId: list?.folderId,
|
|
1606
|
+
totalSubscribers: list?.totalSubscribers ?? list?.uniqueSubscribers,
|
|
1607
|
+
totalBlacklisted: list?.totalBlacklisted
|
|
1608
|
+
})
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
},
|
|
1612
|
+
{
|
|
1613
|
+
name: "create_list",
|
|
1614
|
+
kind: "create",
|
|
1615
|
+
check: "list_lists",
|
|
1616
|
+
title: "Create a Brevo contact list",
|
|
1617
|
+
description: "Creates a contact list in a folder (see list_folders, or create_folder) and returns its id.",
|
|
1618
|
+
inputSchema: {
|
|
1619
|
+
type: "object",
|
|
1620
|
+
properties: {
|
|
1621
|
+
name: { type: "string", minLength: 1, maxLength: 200, description: "The list name." },
|
|
1622
|
+
folder_id: { type: "integer", minimum: 1, description: "The folder that holds the list." }
|
|
1623
|
+
},
|
|
1624
|
+
required: ["name", "folder_id"],
|
|
1625
|
+
additionalProperties: false
|
|
1626
|
+
},
|
|
1627
|
+
async run(args, h) {
|
|
1628
|
+
const { data } = await h.api({ method: "POST", path: "/v3/contacts/lists", json: { name: args.name, folderId: args.folder_id }, write: true });
|
|
1629
|
+
return { id: data?.id, name: args.name, folderId: args.folder_id };
|
|
1630
|
+
}
|
|
1631
|
+
},
|
|
1632
|
+
{
|
|
1633
|
+
name: "list_list_contacts",
|
|
1634
|
+
kind: "read",
|
|
1635
|
+
title: "List the contacts of a Brevo list",
|
|
1636
|
+
description: "The contacts of one list with their attributes, newest first; only those changed since a time with modified_since. Pass nextCursor back as cursor for more.",
|
|
1637
|
+
inputSchema: {
|
|
1638
|
+
type: "object",
|
|
1639
|
+
properties: {
|
|
1640
|
+
list_id: { type: "integer", minimum: 1, description: "The list id (see list_lists)." },
|
|
1641
|
+
limit: { type: "integer", minimum: 1, maximum: 500, default: 50, description: "Contacts per page, 1 to 500 (default 50)." },
|
|
1642
|
+
modified_since: DATE_TIME("Only contacts changed after this time"),
|
|
1643
|
+
sort: { type: "string", enum: ["asc", "desc"], default: "desc", description: "By creation date: desc (default) or asc." },
|
|
1644
|
+
cursor: CURSOR
|
|
1645
|
+
},
|
|
1646
|
+
required: ["list_id"],
|
|
1647
|
+
additionalProperties: false
|
|
1648
|
+
},
|
|
1649
|
+
async run(args, h) {
|
|
1650
|
+
return offsetList(h, args.cursor, {
|
|
1651
|
+
key: "contacts",
|
|
1652
|
+
path: `/v3/contacts/lists/${args.list_id}/contacts`,
|
|
1653
|
+
limit: args.limit,
|
|
1654
|
+
query: { modifiedSince: args.modified_since, sort: args.sort },
|
|
1655
|
+
trim: trimContact
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
},
|
|
1659
|
+
{
|
|
1660
|
+
name: "add_contacts_to_list",
|
|
1661
|
+
kind: "update",
|
|
1662
|
+
check: "list_list_contacts",
|
|
1663
|
+
title: "Add contacts to a Brevo list",
|
|
1664
|
+
description: `Adds existing contacts to a list, by email or by id, up to ${LIST_MEMBERS_MAX} at a time. Returns which were added and which failed (for example, not a contact yet: create it with upsert_contact).`,
|
|
1665
|
+
inputSchema: { type: "object", properties: MEMBERS_SCHEMA, required: ["list_id"], additionalProperties: false },
|
|
1666
|
+
async run(args, h) {
|
|
1667
|
+
const { data } = await h.api({
|
|
1668
|
+
method: "POST",
|
|
1669
|
+
path: `/v3/contacts/lists/${args.list_id}/contacts/add`,
|
|
1670
|
+
json: membersBody(args),
|
|
1671
|
+
write: true,
|
|
1672
|
+
errors: { 404: "Brevo has no list with that id" }
|
|
1673
|
+
});
|
|
1674
|
+
return { listId: args.list_id, ...listResult(data) };
|
|
1675
|
+
}
|
|
1676
|
+
},
|
|
1677
|
+
{
|
|
1678
|
+
name: "remove_contacts_from_list",
|
|
1679
|
+
kind: "delete",
|
|
1680
|
+
check: "list_list_contacts",
|
|
1681
|
+
title: "Remove contacts from a Brevo list",
|
|
1682
|
+
description: `Removes contacts from a list, by email or by id, up to ${LIST_MEMBERS_MAX} at a time. The contacts themselves are kept. Returns which were removed and which failed.`,
|
|
1683
|
+
inputSchema: { type: "object", properties: MEMBERS_SCHEMA, required: ["list_id"], additionalProperties: false },
|
|
1684
|
+
async run(args, h) {
|
|
1685
|
+
const { data } = await h.api({
|
|
1686
|
+
method: "POST",
|
|
1687
|
+
path: `/v3/contacts/lists/${args.list_id}/contacts/remove`,
|
|
1688
|
+
json: membersBody(args),
|
|
1689
|
+
write: true,
|
|
1690
|
+
errors: { 404: "Brevo has no list with that id" }
|
|
1691
|
+
});
|
|
1692
|
+
return { listId: args.list_id, ...listResult(data) };
|
|
1693
|
+
}
|
|
1694
|
+
},
|
|
1695
|
+
{
|
|
1696
|
+
name: "list_email_campaigns",
|
|
1697
|
+
kind: "read",
|
|
1698
|
+
title: "List Brevo email campaigns",
|
|
1699
|
+
description: "Email campaigns, newest first, with status, subject, sender, lists, schedule and, with statistics, their delivered, open, click, bounce and unsubscribe counts. Filter by status, type or a sent date range. Pass nextCursor back as cursor for more.",
|
|
1700
|
+
inputSchema: {
|
|
1701
|
+
type: "object",
|
|
1702
|
+
properties: {
|
|
1703
|
+
status: {
|
|
1704
|
+
type: "string",
|
|
1705
|
+
enum: ["draft", "sent", "archive", "queued", "suspended", "inProcess", "inReview", "cancelled"],
|
|
1706
|
+
description: "Only campaigns with this status."
|
|
1707
|
+
},
|
|
1708
|
+
type: { type: "string", enum: ["classic", "trigger"], description: "classic campaigns or trigger (automation) campaigns." },
|
|
1709
|
+
statistics: { type: "boolean", default: false, description: "true to include each campaign's global statistics (last 6 months only)." },
|
|
1710
|
+
start_date: DATE_TIME("Sent at or after this time (with end_date, status sent or none)"),
|
|
1711
|
+
end_date: DATE_TIME("Sent at or before this time (with start_date)"),
|
|
1712
|
+
limit: { type: "integer", minimum: 1, maximum: 100, default: 25, description: "Campaigns per page, 1 to 100 (default 25)." },
|
|
1713
|
+
cursor: CURSOR
|
|
1714
|
+
},
|
|
1715
|
+
additionalProperties: false
|
|
1716
|
+
},
|
|
1717
|
+
async run(args, h) {
|
|
1718
|
+
if (args.start_date === void 0 !== (args.end_date === void 0)) {
|
|
1719
|
+
throw new ToolFailure("Give start_date and end_date together. Nothing was sent.");
|
|
1720
|
+
}
|
|
1721
|
+
return offsetList(h, args.cursor, {
|
|
1722
|
+
key: "campaigns",
|
|
1723
|
+
path: "/v3/emailCampaigns",
|
|
1724
|
+
limit: args.limit,
|
|
1725
|
+
query: {
|
|
1726
|
+
status: args.status,
|
|
1727
|
+
type: args.type,
|
|
1728
|
+
statistics: args.statistics ? "globalStats" : void 0,
|
|
1729
|
+
startDate: args.start_date,
|
|
1730
|
+
endDate: args.end_date,
|
|
1731
|
+
excludeHtmlContent: true
|
|
1732
|
+
},
|
|
1733
|
+
trim: (campaign) => trimCampaign(campaign)
|
|
1734
|
+
});
|
|
1735
|
+
}
|
|
1736
|
+
},
|
|
1737
|
+
{
|
|
1738
|
+
name: "get_email_campaign",
|
|
1739
|
+
kind: "read",
|
|
1740
|
+
title: "Get a Brevo email campaign",
|
|
1741
|
+
description: "One email campaign with its status, settings, recipients and statistics: global counts (delivered, unique opens and clicks, bounces, unsubscriptions, complaints), counts per list and the most clicked links. include_html adds the HTML body.",
|
|
1742
|
+
inputSchema: {
|
|
1743
|
+
type: "object",
|
|
1744
|
+
properties: {
|
|
1745
|
+
campaign_id: { type: "integer", minimum: 1, description: "The campaign id." },
|
|
1746
|
+
include_html: { type: "boolean", default: false, description: "true to include the HTML body (cut at 20,000 characters)." }
|
|
1747
|
+
},
|
|
1748
|
+
required: ["campaign_id"],
|
|
1749
|
+
additionalProperties: false
|
|
1750
|
+
},
|
|
1751
|
+
async run(args, h) {
|
|
1752
|
+
const { data } = await h.api({
|
|
1753
|
+
path: `/v3/emailCampaigns/${args.campaign_id}`,
|
|
1754
|
+
query: { excludeHtmlContent: args.include_html ? void 0 : true },
|
|
1755
|
+
errors: { 404: "Brevo has no email campaign with that id" }
|
|
1756
|
+
});
|
|
1757
|
+
const statistics = data?.statistics ?? {};
|
|
1758
|
+
const links = statistics.linksStats && typeof statistics.linksStats === "object" ? Object.entries(statistics.linksStats).map(([url, value]) => ({ url, clicks: typeof value === "number" ? value : value?.nbClick ?? value })).sort((a, b) => (Number(b.clicks) || 0) - (Number(a.clicks) || 0)).slice(0, 50) : void 0;
|
|
1759
|
+
return compact({
|
|
1760
|
+
...trimCampaign(data, { html: args.include_html }),
|
|
1761
|
+
campaignStats: Array.isArray(statistics.campaignStats) && statistics.campaignStats.length ? statistics.campaignStats : void 0,
|
|
1762
|
+
linksStats: links?.length ? links : void 0,
|
|
1763
|
+
remaining: statistics.remaining
|
|
1764
|
+
});
|
|
1765
|
+
}
|
|
1766
|
+
},
|
|
1767
|
+
{
|
|
1768
|
+
name: "create_email_campaign",
|
|
1769
|
+
kind: "create",
|
|
1770
|
+
check: "list_email_campaigns",
|
|
1771
|
+
title: "Create a Brevo email campaign",
|
|
1772
|
+
description: "Creates an email campaign: a draft that nothing sends until send_campaign_now, or, with scheduled_at, scheduled to send then. Needs a name, a subject, a verified sender, lists or segments, and a body: html_content (with {{ unsubscribe }}), html_url or template_id. Returns the id.",
|
|
1773
|
+
inputSchema: {
|
|
1774
|
+
type: "object",
|
|
1775
|
+
properties: CAMPAIGN_FIELDS,
|
|
1776
|
+
required: ["name", "subject", "sender"],
|
|
1777
|
+
additionalProperties: false
|
|
1778
|
+
},
|
|
1779
|
+
async run(args, h) {
|
|
1780
|
+
const bodies = [args.html_content, args.html_url, args.template_id].filter((item) => item !== void 0).length;
|
|
1781
|
+
if (bodies !== 1) throw new ToolFailure("Give exactly one of html_content, html_url or template_id. Nothing was changed.");
|
|
1782
|
+
if (!args.list_ids?.length && !args.segment_ids?.length) throw new ToolFailure("Give list_ids or segment_ids: who receives it. Nothing was changed.");
|
|
1783
|
+
const { data } = await h.api({
|
|
1784
|
+
method: "POST",
|
|
1785
|
+
path: "/v3/emailCampaigns",
|
|
1786
|
+
json: campaignBody(args),
|
|
1787
|
+
write: true,
|
|
1788
|
+
errors: { 400: "Brevo did not accept the campaign" }
|
|
1789
|
+
});
|
|
1790
|
+
return compact({ id: data?.id, name: args.name, status: args.scheduled_at ? "scheduled" : "draft", scheduledAt: args.scheduled_at });
|
|
1791
|
+
}
|
|
1792
|
+
},
|
|
1793
|
+
{
|
|
1794
|
+
name: "update_email_campaign",
|
|
1795
|
+
kind: "update",
|
|
1796
|
+
check: "get_email_campaign",
|
|
1797
|
+
title: "Update a Brevo email campaign",
|
|
1798
|
+
description: "Changes a draft or scheduled email campaign: only the fields given. scheduled_at schedules it (or moves the time). A sent campaign cannot be changed.",
|
|
1799
|
+
inputSchema: {
|
|
1800
|
+
type: "object",
|
|
1801
|
+
properties: { campaign_id: { type: "integer", minimum: 1, description: "The campaign id." }, ...CAMPAIGN_FIELDS },
|
|
1802
|
+
required: ["campaign_id"],
|
|
1803
|
+
additionalProperties: false
|
|
1804
|
+
},
|
|
1805
|
+
async run(args, h) {
|
|
1806
|
+
const body = campaignBody(args);
|
|
1807
|
+
if (!Object.keys(body).length) throw new ToolFailure("Nothing to change: give at least one campaign field. Nothing was changed.");
|
|
1808
|
+
await h.api({
|
|
1809
|
+
method: "PUT",
|
|
1810
|
+
path: `/v3/emailCampaigns/${args.campaign_id}`,
|
|
1811
|
+
json: body,
|
|
1812
|
+
write: true,
|
|
1813
|
+
errors: { 404: "Brevo has no email campaign with that id", 400: "Brevo did not accept the change" }
|
|
1814
|
+
});
|
|
1815
|
+
return { updated: true, id: args.campaign_id };
|
|
1816
|
+
}
|
|
1817
|
+
},
|
|
1818
|
+
{
|
|
1819
|
+
name: "send_test_email",
|
|
1820
|
+
kind: "create",
|
|
1821
|
+
check: "get_email_campaign",
|
|
1822
|
+
title: "Send a test of a Brevo campaign",
|
|
1823
|
+
description: "Sends a test of an email campaign to the given addresses, or to the account's test list when none are given. Brevo allows 50 test emails a day.",
|
|
1824
|
+
inputSchema: {
|
|
1825
|
+
type: "object",
|
|
1826
|
+
properties: {
|
|
1827
|
+
campaign_id: { type: "integer", minimum: 1, description: "The campaign id." },
|
|
1828
|
+
emails: { type: "array", items: EMAIL, maxItems: 50, uniqueItems: true, description: "Where to send the test; the test list when left out." }
|
|
1829
|
+
},
|
|
1830
|
+
required: ["campaign_id"],
|
|
1831
|
+
additionalProperties: false
|
|
1832
|
+
},
|
|
1833
|
+
async run(args, h) {
|
|
1834
|
+
await h.api({
|
|
1835
|
+
method: "POST",
|
|
1836
|
+
path: `/v3/emailCampaigns/${args.campaign_id}/sendTest`,
|
|
1837
|
+
json: { emailTo: args.emails ?? [] },
|
|
1838
|
+
write: true,
|
|
1839
|
+
errors: { 404: "Brevo has no email campaign with that id", 400: "Brevo did not send the test" }
|
|
1840
|
+
});
|
|
1841
|
+
return { sent: true, id: args.campaign_id, to: args.emails ?? "test list" };
|
|
1842
|
+
}
|
|
1843
|
+
},
|
|
1844
|
+
{
|
|
1845
|
+
name: "send_campaign_now",
|
|
1846
|
+
kind: "create",
|
|
1847
|
+
check: "get_email_campaign",
|
|
1848
|
+
title: "Send a Brevo campaign now",
|
|
1849
|
+
description: "Sends an email campaign to all its recipients right away. It cannot be undone. Check the campaign first with get_email_campaign (and a test with send_test_email). Sending uses the account's email credits.",
|
|
1850
|
+
inputSchema: {
|
|
1851
|
+
type: "object",
|
|
1852
|
+
properties: { campaign_id: { type: "integer", minimum: 1, description: "The campaign id." } },
|
|
1853
|
+
required: ["campaign_id"],
|
|
1854
|
+
additionalProperties: false
|
|
1855
|
+
},
|
|
1856
|
+
async run(args, h) {
|
|
1857
|
+
await h.api({
|
|
1858
|
+
method: "POST",
|
|
1859
|
+
path: `/v3/emailCampaigns/${args.campaign_id}/sendNow`,
|
|
1860
|
+
write: true,
|
|
1861
|
+
errors: {
|
|
1862
|
+
404: "Brevo has no email campaign with that id",
|
|
1863
|
+
400: "Brevo did not send the campaign",
|
|
1864
|
+
402: "Brevo refused to send: the account does not have enough email credits"
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
return { sent: true, id: args.campaign_id, note: "Brevo is sending the campaign; get_email_campaign shows its status and statistics." };
|
|
1868
|
+
}
|
|
1869
|
+
},
|
|
1870
|
+
{
|
|
1871
|
+
name: "delete_email_campaign",
|
|
1872
|
+
kind: "delete",
|
|
1873
|
+
check: "list_email_campaigns",
|
|
1874
|
+
title: "Delete a Brevo email campaign",
|
|
1875
|
+
description: "Deletes an email campaign that is not being sent, such as a draft. It cannot be undone.",
|
|
1876
|
+
inputSchema: {
|
|
1877
|
+
type: "object",
|
|
1878
|
+
properties: { campaign_id: { type: "integer", minimum: 1, description: "The campaign id." } },
|
|
1879
|
+
required: ["campaign_id"],
|
|
1880
|
+
additionalProperties: false
|
|
1881
|
+
},
|
|
1882
|
+
async run(args, h) {
|
|
1883
|
+
await h.api({
|
|
1884
|
+
method: "DELETE",
|
|
1885
|
+
path: `/v3/emailCampaigns/${args.campaign_id}`,
|
|
1886
|
+
write: true,
|
|
1887
|
+
errors: { 404: "Brevo has no email campaign with that id" }
|
|
1888
|
+
});
|
|
1889
|
+
return { deleted: true, id: args.campaign_id };
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1892
|
+
{
|
|
1893
|
+
name: "list_templates",
|
|
1894
|
+
kind: "read",
|
|
1895
|
+
title: "List Brevo email templates",
|
|
1896
|
+
description: "The account's email templates with their ids, names, subjects, senders and whether they are active. Pass nextCursor back as cursor for more.",
|
|
1897
|
+
inputSchema: {
|
|
1898
|
+
type: "object",
|
|
1899
|
+
properties: {
|
|
1900
|
+
active: { type: "boolean", description: "true for active templates only, false for inactive only; both when left out." },
|
|
1901
|
+
limit: { type: "integer", minimum: 1, maximum: 1e3, default: 50, description: "Templates per page, 1 to 1000 (default 50)." },
|
|
1902
|
+
cursor: CURSOR
|
|
1903
|
+
},
|
|
1904
|
+
additionalProperties: false
|
|
1905
|
+
},
|
|
1906
|
+
async run(args, h) {
|
|
1907
|
+
return offsetList(h, args.cursor, {
|
|
1908
|
+
key: "templates",
|
|
1909
|
+
path: "/v3/smtp/templates",
|
|
1910
|
+
limit: args.limit,
|
|
1911
|
+
query: { templateStatus: args.active },
|
|
1912
|
+
trim: (template) => trimTemplate(template)
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
},
|
|
1916
|
+
{
|
|
1917
|
+
name: "get_template",
|
|
1918
|
+
kind: "read",
|
|
1919
|
+
title: "Get a Brevo email template",
|
|
1920
|
+
description: "One email template with its settings and HTML body (cut at 20,000 characters).",
|
|
1921
|
+
inputSchema: {
|
|
1922
|
+
type: "object",
|
|
1923
|
+
properties: { template_id: { type: "integer", minimum: 1, description: "The template id." } },
|
|
1924
|
+
required: ["template_id"],
|
|
1925
|
+
additionalProperties: false
|
|
1926
|
+
},
|
|
1927
|
+
async run(args, h) {
|
|
1928
|
+
const { data } = await h.api({ path: `/v3/smtp/templates/${args.template_id}`, errors: { 404: "Brevo has no template with that id" } });
|
|
1929
|
+
return trimTemplate(data, { html: true });
|
|
1930
|
+
}
|
|
1931
|
+
},
|
|
1932
|
+
{
|
|
1933
|
+
name: "create_template",
|
|
1934
|
+
kind: "create",
|
|
1935
|
+
check: "list_templates",
|
|
1936
|
+
title: "Create a Brevo email template",
|
|
1937
|
+
description: "Creates an email template for campaigns and transactional email: name, subject, sender and an HTML body (html_content or html_url). Placeholders: {{ contact.FIRSTNAME }}, {{ params.NAME }}. Returns its id.",
|
|
1938
|
+
inputSchema: {
|
|
1939
|
+
type: "object",
|
|
1940
|
+
properties: {
|
|
1941
|
+
name: { type: "string", minLength: 1, maxLength: 200, description: "The template name." },
|
|
1942
|
+
subject: { type: "string", minLength: 1, maxLength: 500, description: "The subject line." },
|
|
1943
|
+
sender: SENDER,
|
|
1944
|
+
html_content: { type: "string", minLength: 10, maxLength: 1e6, description: "The HTML body, at least 10 characters." },
|
|
1945
|
+
html_url: { type: "string", format: "uri", maxLength: 2e3, description: "A public URL to read the HTML body from, instead of html_content." },
|
|
1946
|
+
reply_to: EMAIL,
|
|
1947
|
+
to_field: { type: "string", maxLength: 200, description: 'The To name, e.g. "{{ contact.FIRSTNAME }}".' },
|
|
1948
|
+
tag: { type: "string", maxLength: 100, description: "A tag for the template." },
|
|
1949
|
+
is_active: { type: "boolean", default: true, description: "Active templates can be used for transactional email (default true)." }
|
|
1950
|
+
},
|
|
1951
|
+
required: ["name", "subject", "sender"],
|
|
1952
|
+
additionalProperties: false
|
|
1953
|
+
},
|
|
1954
|
+
async run(args, h) {
|
|
1955
|
+
checkSender(args.sender);
|
|
1956
|
+
if (args.html_content === void 0 === (args.html_url === void 0)) throw new ToolFailure("Give html_content or html_url (one of the two). Nothing was changed.");
|
|
1957
|
+
const { data } = await h.api({
|
|
1958
|
+
method: "POST",
|
|
1959
|
+
path: "/v3/smtp/templates",
|
|
1960
|
+
json: compact({
|
|
1961
|
+
templateName: args.name,
|
|
1962
|
+
subject: args.subject,
|
|
1963
|
+
sender: args.sender,
|
|
1964
|
+
htmlContent: args.html_content,
|
|
1965
|
+
htmlUrl: args.html_url,
|
|
1966
|
+
replyTo: args.reply_to,
|
|
1967
|
+
toField: args.to_field,
|
|
1968
|
+
tag: args.tag,
|
|
1969
|
+
isActive: args.is_active
|
|
1970
|
+
}),
|
|
1971
|
+
write: true,
|
|
1972
|
+
errors: { 400: "Brevo did not accept the template" }
|
|
1973
|
+
});
|
|
1974
|
+
return { id: data?.id, name: args.name };
|
|
1975
|
+
}
|
|
1976
|
+
},
|
|
1977
|
+
{
|
|
1978
|
+
name: "update_template",
|
|
1979
|
+
kind: "update",
|
|
1980
|
+
check: "get_template",
|
|
1981
|
+
title: "Update a Brevo email template",
|
|
1982
|
+
description: "Changes an email template: only the fields given.",
|
|
1983
|
+
inputSchema: {
|
|
1984
|
+
type: "object",
|
|
1985
|
+
properties: {
|
|
1986
|
+
template_id: { type: "integer", minimum: 1, description: "The template id." },
|
|
1987
|
+
name: { type: "string", minLength: 1, maxLength: 200, description: "A new name." },
|
|
1988
|
+
subject: { type: "string", minLength: 1, maxLength: 500, description: "A new subject line." },
|
|
1989
|
+
sender: SENDER,
|
|
1990
|
+
html_content: { type: "string", minLength: 10, maxLength: 1e6, description: "A new HTML body." },
|
|
1991
|
+
html_url: { type: "string", format: "uri", maxLength: 2e3, description: "A public URL to read a new HTML body from." },
|
|
1992
|
+
reply_to: EMAIL,
|
|
1993
|
+
to_field: { type: "string", maxLength: 200, description: "A new To name." },
|
|
1994
|
+
tag: { type: "string", maxLength: 100, description: "A new tag." },
|
|
1995
|
+
is_active: { type: "boolean", description: "Activate or deactivate it." }
|
|
1996
|
+
},
|
|
1997
|
+
required: ["template_id"],
|
|
1998
|
+
additionalProperties: false
|
|
1999
|
+
},
|
|
2000
|
+
async run(args, h) {
|
|
2001
|
+
checkSender(args.sender);
|
|
2002
|
+
const body = compact({
|
|
2003
|
+
templateName: args.name,
|
|
2004
|
+
subject: args.subject,
|
|
2005
|
+
sender: args.sender,
|
|
2006
|
+
htmlContent: args.html_content,
|
|
2007
|
+
htmlUrl: args.html_url,
|
|
2008
|
+
replyTo: args.reply_to,
|
|
2009
|
+
toField: args.to_field,
|
|
2010
|
+
tag: args.tag,
|
|
2011
|
+
isActive: args.is_active
|
|
2012
|
+
});
|
|
2013
|
+
if (!Object.keys(body).length) throw new ToolFailure("Nothing to change: give at least one template field. Nothing was changed.");
|
|
2014
|
+
await h.api({
|
|
2015
|
+
method: "PUT",
|
|
2016
|
+
path: `/v3/smtp/templates/${args.template_id}`,
|
|
2017
|
+
json: body,
|
|
2018
|
+
write: true,
|
|
2019
|
+
errors: { 404: "Brevo has no template with that id", 400: "Brevo did not accept the change" }
|
|
2020
|
+
});
|
|
2021
|
+
return { updated: true, id: args.template_id };
|
|
2022
|
+
}
|
|
2023
|
+
},
|
|
2024
|
+
{
|
|
2025
|
+
name: "send_transactional_email",
|
|
2026
|
+
kind: "create",
|
|
2027
|
+
check: "list_transactional_events",
|
|
2028
|
+
title: "Send a Brevo transactional email",
|
|
2029
|
+
description: "Sends one email right away (or at scheduled_at): to up to 50 recipients, with cc, bcc and reply-to, and either a subject with an HTML or text body, or a template_id with params for {{ params.NAME }}. Attachments are public URLs Brevo downloads. Returns the message id. Uses the account's transactional email credits.",
|
|
2030
|
+
inputSchema: {
|
|
2031
|
+
type: "object",
|
|
2032
|
+
properties: {
|
|
2033
|
+
sender: SENDER,
|
|
2034
|
+
to: { type: "array", items: PERSON, minItems: 1, maxItems: 50, description: 'The recipients: [{"email": "a@example.com", "name": "Ann"}].' },
|
|
2035
|
+
cc: { type: "array", items: PERSON, maxItems: 50, description: "Cc recipients." },
|
|
2036
|
+
bcc: { type: "array", items: PERSON, maxItems: 50, description: "Bcc recipients." },
|
|
2037
|
+
reply_to: PERSON,
|
|
2038
|
+
subject: { type: "string", minLength: 1, maxLength: 500, description: "The subject line (not with template_id, which has its own)." },
|
|
2039
|
+
html_content: { type: "string", minLength: 1, maxLength: 1e6, description: "The HTML body." },
|
|
2040
|
+
text_content: { type: "string", minLength: 1, maxLength: 1e6, description: "The plain text body." },
|
|
2041
|
+
template_id: { type: "integer", minimum: 1, description: "A template (see list_templates) instead of subject and body." },
|
|
2042
|
+
params: { type: "object", description: 'Values for {{ params.NAME }} in the template or body, e.g. {"ORDER_ID": "1234"}.' },
|
|
2043
|
+
tags: { type: "array", items: { type: "string", minLength: 1, maxLength: 100 }, maxItems: 10, description: "Tags to find the email by in statistics." },
|
|
2044
|
+
headers: { type: "object", description: 'Custom headers, e.g. {"X-Mailin-custom": "order-1234"}.' },
|
|
2045
|
+
attachments: {
|
|
2046
|
+
type: "array",
|
|
2047
|
+
maxItems: 10,
|
|
2048
|
+
description: 'Files to attach: [{"url": "https://...", "name": "invoice.pdf"}], or {"content": base64, "name"}.',
|
|
2049
|
+
items: {
|
|
2050
|
+
type: "object",
|
|
2051
|
+
properties: {
|
|
2052
|
+
url: { type: "string", format: "uri", maxLength: 2e3, description: "A public URL of the file." },
|
|
2053
|
+
content: { type: "string", maxLength: 7e6, description: "The file in base64, instead of url." },
|
|
2054
|
+
name: { type: "string", minLength: 1, maxLength: 200, description: "The file name with its extension." }
|
|
2055
|
+
},
|
|
2056
|
+
additionalProperties: false
|
|
2057
|
+
}
|
|
2058
|
+
},
|
|
2059
|
+
scheduled_at: DATE_TIME("When to send it (Brevo may send up to 5 minutes later)")
|
|
2060
|
+
},
|
|
2061
|
+
required: ["to"],
|
|
2062
|
+
additionalProperties: false
|
|
2063
|
+
},
|
|
2064
|
+
async run(args, h) {
|
|
2065
|
+
checkSender(args.sender);
|
|
2066
|
+
if (args.template_id === void 0) {
|
|
2067
|
+
if (!args.sender) throw new ToolFailure("sender is required without template_id. Nothing was sent.");
|
|
2068
|
+
if (!args.subject) throw new ToolFailure("subject is required without template_id. Nothing was sent.");
|
|
2069
|
+
if (!args.html_content && !args.text_content) throw new ToolFailure("Give html_content or text_content, or a template_id. Nothing was sent.");
|
|
2070
|
+
}
|
|
2071
|
+
for (const attachment of args.attachments ?? []) {
|
|
2072
|
+
if (attachment.url === void 0 === (attachment.content === void 0)) throw new ToolFailure("Each attachment needs a url or a content (one of the two). Nothing was sent.");
|
|
2073
|
+
if (attachment.content !== void 0 && !attachment.name) throw new ToolFailure("An attachment given as content needs a name. Nothing was sent.");
|
|
2074
|
+
}
|
|
2075
|
+
const { status, data } = await sendTransactional(h, compact({
|
|
2076
|
+
sender: args.sender,
|
|
2077
|
+
to: args.to,
|
|
2078
|
+
cc: args.cc?.length ? args.cc : void 0,
|
|
2079
|
+
bcc: args.bcc?.length ? args.bcc : void 0,
|
|
2080
|
+
replyTo: args.reply_to,
|
|
2081
|
+
subject: args.subject,
|
|
2082
|
+
htmlContent: args.html_content,
|
|
2083
|
+
textContent: args.text_content,
|
|
2084
|
+
templateId: args.template_id,
|
|
2085
|
+
params: args.params,
|
|
2086
|
+
tags: args.tags?.length ? args.tags : void 0,
|
|
2087
|
+
headers: args.headers,
|
|
2088
|
+
attachment: args.attachments?.length ? args.attachments.map((item) => compact(item)) : void 0,
|
|
2089
|
+
scheduledAt: args.scheduled_at
|
|
2090
|
+
}));
|
|
2091
|
+
return compact({
|
|
2092
|
+
sent: status !== 202,
|
|
2093
|
+
scheduled: status === 202 ? true : void 0,
|
|
2094
|
+
messageId: data?.messageId,
|
|
2095
|
+
messageIds: Array.isArray(data?.messageIds) ? data.messageIds : void 0
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
},
|
|
2099
|
+
{
|
|
2100
|
+
name: "get_transactional_stats",
|
|
2101
|
+
kind: "read",
|
|
2102
|
+
title: "Get Brevo transactional email statistics",
|
|
2103
|
+
description: "Totals for transactional email over a period: requests, delivered, opens and unique opens, clicks, bounces, spam reports, blocked, invalid and unsubscribed. Give days, or start_date and end_date; filter by tag.",
|
|
2104
|
+
inputSchema: {
|
|
2105
|
+
type: "object",
|
|
2106
|
+
properties: {
|
|
2107
|
+
days: { type: "integer", minimum: 1, maximum: 90, description: "The last N days (not with start_date)." },
|
|
2108
|
+
start_date: DATE("The first day"),
|
|
2109
|
+
end_date: DATE("The last day"),
|
|
2110
|
+
tag: { type: "string", maxLength: 100, description: "Only emails with this tag." }
|
|
2111
|
+
},
|
|
2112
|
+
additionalProperties: false
|
|
2113
|
+
},
|
|
2114
|
+
async run(args, h) {
|
|
2115
|
+
if (args.start_date === void 0 !== (args.end_date === void 0)) throw new ToolFailure("Give start_date and end_date together. Nothing was sent.");
|
|
2116
|
+
if (args.days !== void 0 && args.start_date !== void 0) throw new ToolFailure("Give days or a date range, not both. Nothing was sent.");
|
|
2117
|
+
const { data } = await h.api({
|
|
2118
|
+
path: "/v3/smtp/statistics/aggregatedReport",
|
|
2119
|
+
query: { days: args.days, startDate: args.start_date, endDate: args.end_date, tag: args.tag }
|
|
2120
|
+
});
|
|
2121
|
+
return data ?? {};
|
|
2122
|
+
}
|
|
2123
|
+
},
|
|
2124
|
+
{
|
|
2125
|
+
name: "list_transactional_events",
|
|
2126
|
+
kind: "read",
|
|
2127
|
+
title: "List Brevo transactional email events",
|
|
2128
|
+
description: "Events of transactional emails, newest first: requests, deliveries, opens, clicks, bounces, spam reports, blocks and unsubscribes, with the email, subject, message id and reason. Filter by recipient, event, message id, template or tag; it shows whether an email was sent. Pass nextCursor back as cursor for more.",
|
|
2129
|
+
inputSchema: {
|
|
2130
|
+
type: "object",
|
|
2131
|
+
properties: {
|
|
2132
|
+
email: EMAIL,
|
|
2133
|
+
event: {
|
|
2134
|
+
type: "string",
|
|
2135
|
+
enum: ["requests", "delivered", "hardBounces", "softBounces", "blocked", "spam", "invalid", "deferred", "clicks", "opened", "uniqueOpened", "unsubscribed", "error", "loadedByProxy"],
|
|
2136
|
+
description: "Only this kind of event."
|
|
2137
|
+
},
|
|
2138
|
+
message_id: { type: "string", maxLength: 300, description: "Only the events of this message id." },
|
|
2139
|
+
template_id: { type: "integer", minimum: 1, description: "Only emails sent with this template." },
|
|
2140
|
+
tags: { type: "array", items: { type: "string", minLength: 1, maxLength: 100 }, maxItems: 10, description: "Only emails with these tags." },
|
|
2141
|
+
days: { type: "integer", minimum: 1, maximum: 90, description: "The last N days (not with start_date)." },
|
|
2142
|
+
start_date: DATE("The first day"),
|
|
2143
|
+
end_date: DATE("The last day"),
|
|
2144
|
+
limit: { type: "integer", minimum: 1, maximum: 500, default: 50, description: "Events per page, 1 to 500 (default 50)." },
|
|
2145
|
+
cursor: CURSOR
|
|
2146
|
+
},
|
|
2147
|
+
additionalProperties: false
|
|
2148
|
+
},
|
|
2149
|
+
async run(args, h) {
|
|
2150
|
+
if (args.start_date === void 0 !== (args.end_date === void 0)) throw new ToolFailure("Give start_date and end_date together. Nothing was sent.");
|
|
2151
|
+
return offsetList(h, args.cursor, {
|
|
2152
|
+
key: "events",
|
|
2153
|
+
path: "/v3/smtp/statistics/events",
|
|
2154
|
+
limit: args.limit,
|
|
2155
|
+
query: {
|
|
2156
|
+
email: args.email,
|
|
2157
|
+
event: args.event,
|
|
2158
|
+
messageId: args.message_id,
|
|
2159
|
+
templateId: args.template_id,
|
|
2160
|
+
// Brevo takes the tags as a serialized array.
|
|
2161
|
+
tags: args.tags?.length ? JSON.stringify(args.tags) : void 0,
|
|
2162
|
+
days: args.days,
|
|
2163
|
+
startDate: args.start_date,
|
|
2164
|
+
endDate: args.end_date
|
|
2165
|
+
},
|
|
2166
|
+
trim: (event) => compact({
|
|
2167
|
+
date: event?.date,
|
|
2168
|
+
event: event?.event,
|
|
2169
|
+
email: event?.email,
|
|
2170
|
+
subject: event?.subject,
|
|
2171
|
+
messageId: event?.messageId,
|
|
2172
|
+
templateId: event?.templateId,
|
|
2173
|
+
tag: event?.tag,
|
|
2174
|
+
reason: event?.reason,
|
|
2175
|
+
link: event?.link,
|
|
2176
|
+
from: event?.from
|
|
2177
|
+
})
|
|
2178
|
+
});
|
|
2179
|
+
}
|
|
2180
|
+
},
|
|
2181
|
+
...apiTools({
|
|
2182
|
+
label: LABEL2,
|
|
2183
|
+
description: "The Brevo API v3 at https://api.brevo.com/v3, with the connected API key: paths start with /v3/, such as /v3/contacts/attributes, /v3/contacts/segments, /v3/smsCampaigns, /v3/emailCampaigns/{id}/status, /v3/emailCampaigns/{id}/sharedUrl, /v3/webhooks or /v3/crm/deals. Reference: https://developers.brevo.com/reference.",
|
|
2184
|
+
basePath: "/v3/",
|
|
2185
|
+
guard(request) {
|
|
2186
|
+
const [base, area] = routedParts(request.segments);
|
|
2187
|
+
if (base !== "v3") throw new ToolFailure("The path must stay under /v3/. Nothing was sent.");
|
|
2188
|
+
if (request.method !== "GET" && (area === "organization" || area === "corporate")) {
|
|
2189
|
+
throw new ToolFailure("Changing the Brevo organization or its sub-accounts is not available here. Nothing was sent.");
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
})
|
|
2193
|
+
]
|
|
2194
|
+
});
|
|
2195
|
+
module.exports = connector;
|