@diegoaltoworks/chatter 0.15.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/auth/apikeys.d.ts +0 -1
- package/dist/auth/apikeys.d.ts.map +1 -1
- package/dist/bin/create-apikey.js +1 -3
- package/dist/client/__tests__/markdown.test.d.ts +5 -0
- package/dist/client/__tests__/markdown.test.d.ts.map +1 -0
- package/dist/client/src/Chat.d.ts +1 -0
- package/dist/client/src/Chat.d.ts.map +1 -1
- package/dist/client/src/markdown.d.ts +20 -0
- package/dist/client/src/markdown.d.ts.map +1 -0
- package/dist/core/retrieval.d.ts.map +1 -1
- package/dist/index.js +337 -65
- package/dist/index.mjs +337 -65
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/static/chatter.css +121 -0
- package/dist/static/chatter.js +8 -2
- package/package.json +19 -12
package/dist/index.js
CHANGED
|
@@ -6,7 +6,11 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
-
|
|
9
|
+
try {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
throw mod = 0, e;
|
|
13
|
+
}
|
|
10
14
|
};
|
|
11
15
|
var __export = (target, all) => {
|
|
12
16
|
for (var name in all)
|
|
@@ -205,6 +209,145 @@ var require_dist = __commonJS({
|
|
|
205
209
|
}
|
|
206
210
|
}
|
|
207
211
|
};
|
|
212
|
+
var SAFE_URL_RE = /^(https?:|mailto:|\/|#)/i;
|
|
213
|
+
var CODE_PH_OPEN = "CODE";
|
|
214
|
+
var CODE_PH_CLOSE = "ENDCODE";
|
|
215
|
+
function escapeHtml(input) {
|
|
216
|
+
return input.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
217
|
+
}
|
|
218
|
+
function sanitizeUrl(url) {
|
|
219
|
+
const trimmed = url.trim();
|
|
220
|
+
if (!SAFE_URL_RE.test(trimmed)) return "#";
|
|
221
|
+
return escapeHtml(trimmed);
|
|
222
|
+
}
|
|
223
|
+
function renderInline(escaped) {
|
|
224
|
+
const codeSpans = [];
|
|
225
|
+
let out = escaped.replace(/`([^`\n]+)`/g, (_m, code) => {
|
|
226
|
+
const idx = codeSpans.push(code) - 1;
|
|
227
|
+
return `${CODE_PH_OPEN}${idx}${CODE_PH_CLOSE}`;
|
|
228
|
+
});
|
|
229
|
+
out = out.replace(
|
|
230
|
+
/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^&]*)")?\)/g,
|
|
231
|
+
(_m, text, url, title) => {
|
|
232
|
+
const safeUrl = sanitizeUrl(url);
|
|
233
|
+
const titleAttr = title ? ` title="${title}"` : "";
|
|
234
|
+
return `<a href="${safeUrl}" target="_blank" rel="noopener noreferrer"${titleAttr}>${text}</a>`;
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
out = out.replace(/(\*\*|__)(?=\S)([\s\S]+?)(?<=\S)\1/g, "<strong>$2</strong>");
|
|
238
|
+
out = out.replace(/(?<!\*)\*(?!\*)(?=\S)([\s\S]+?)(?<=\S)\*(?!\*)/g, "<em>$1</em>");
|
|
239
|
+
out = out.replace(/(?<![A-Za-z0-9_])_(?=\S)([\s\S]+?)(?<=\S)_(?![A-Za-z0-9_])/g, "<em>$1</em>");
|
|
240
|
+
const placeholderRe = new RegExp(`${CODE_PH_OPEN}(\\d+)${CODE_PH_CLOSE}`, "g");
|
|
241
|
+
out = out.replace(placeholderRe, (_m, idx) => {
|
|
242
|
+
const code = codeSpans[Number(idx)] ?? "";
|
|
243
|
+
return `<code>${code}</code>`;
|
|
244
|
+
});
|
|
245
|
+
return out;
|
|
246
|
+
}
|
|
247
|
+
function flushParagraph(buffer, out) {
|
|
248
|
+
if (buffer.length === 0) return;
|
|
249
|
+
const text = buffer.join("\n");
|
|
250
|
+
const html = renderInline(escapeHtml(text)).replace(/\n/g, "<br>");
|
|
251
|
+
out.push(`<p>${html}</p>`);
|
|
252
|
+
buffer.length = 0;
|
|
253
|
+
}
|
|
254
|
+
function flushList(list, out) {
|
|
255
|
+
if (!list) return null;
|
|
256
|
+
const items = list.items.map((item) => `<li>${renderInline(escapeHtml(item))}</li>`).join("");
|
|
257
|
+
out.push(`<${list.type}>${items}</${list.type}>`);
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
function flushQuote(quote, out) {
|
|
261
|
+
if (quote.length === 0) return;
|
|
262
|
+
const inner = renderMarkdown(quote.join("\n"));
|
|
263
|
+
out.push(`<blockquote>${inner}</blockquote>`);
|
|
264
|
+
quote.length = 0;
|
|
265
|
+
}
|
|
266
|
+
function renderMarkdown(source) {
|
|
267
|
+
if (!source) return "";
|
|
268
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
269
|
+
const out = [];
|
|
270
|
+
const paragraph = [];
|
|
271
|
+
const quote = [];
|
|
272
|
+
let list = null;
|
|
273
|
+
let inFence = false;
|
|
274
|
+
let fenceLang = "";
|
|
275
|
+
let fenceBuf = [];
|
|
276
|
+
const closeBlocks = () => {
|
|
277
|
+
flushParagraph(paragraph, out);
|
|
278
|
+
list = flushList(list, out);
|
|
279
|
+
flushQuote(quote, out);
|
|
280
|
+
};
|
|
281
|
+
for (const line of lines) {
|
|
282
|
+
if (inFence) {
|
|
283
|
+
if (/^\s*```\s*$/.test(line)) {
|
|
284
|
+
const code = escapeHtml(fenceBuf.join("\n"));
|
|
285
|
+
const langClass = fenceLang ? ` class="language-${escapeHtml(fenceLang)}"` : "";
|
|
286
|
+
out.push(`<pre><code${langClass}>${code}</code></pre>`);
|
|
287
|
+
fenceBuf = [];
|
|
288
|
+
fenceLang = "";
|
|
289
|
+
inFence = false;
|
|
290
|
+
} else {
|
|
291
|
+
fenceBuf.push(line);
|
|
292
|
+
}
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
const fenceMatch = line.match(/^\s*```\s*([\w+-]*)\s*$/);
|
|
296
|
+
if (fenceMatch) {
|
|
297
|
+
closeBlocks();
|
|
298
|
+
inFence = true;
|
|
299
|
+
fenceLang = fenceMatch[1] || "";
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
if (/^\s*$/.test(line)) {
|
|
303
|
+
closeBlocks();
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (/^\s*(?:---|\*\*\*|___)\s*$/.test(line) && paragraph.length === 0) {
|
|
307
|
+
closeBlocks();
|
|
308
|
+
out.push("<hr>");
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const headingMatch = line.match(/^(#{1,6})\s+(.*)$/);
|
|
312
|
+
if (headingMatch) {
|
|
313
|
+
closeBlocks();
|
|
314
|
+
const level = headingMatch[1].length;
|
|
315
|
+
const content = renderInline(escapeHtml(headingMatch[2].trim()));
|
|
316
|
+
out.push(`<h${level}>${content}</h${level}>`);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
const quoteMatch = line.match(/^\s*>\s?(.*)$/);
|
|
320
|
+
if (quoteMatch) {
|
|
321
|
+
flushParagraph(paragraph, out);
|
|
322
|
+
list = flushList(list, out);
|
|
323
|
+
quote.push(quoteMatch[1]);
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (quote.length > 0) flushQuote(quote, out);
|
|
327
|
+
const ulMatch = line.match(/^\s*[-*+]\s+(.*)$/);
|
|
328
|
+
const olMatch = line.match(/^\s*\d+\.\s+(.*)$/);
|
|
329
|
+
if (ulMatch || olMatch) {
|
|
330
|
+
flushParagraph(paragraph, out);
|
|
331
|
+
const type = ulMatch ? "ul" : "ol";
|
|
332
|
+
const item = ulMatch ? ulMatch[1] : olMatch[1];
|
|
333
|
+
if (!list || list.type !== type) {
|
|
334
|
+
list = flushList(list, out);
|
|
335
|
+
list = { type, items: [] };
|
|
336
|
+
}
|
|
337
|
+
list.items.push(item);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (list) list = flushList(list, out);
|
|
341
|
+
paragraph.push(line);
|
|
342
|
+
}
|
|
343
|
+
if (inFence) {
|
|
344
|
+
const code = escapeHtml(fenceBuf.join("\n"));
|
|
345
|
+
const langClass = fenceLang ? ` class="language-${escapeHtml(fenceLang)}"` : "";
|
|
346
|
+
out.push(`<pre><code${langClass}>${code}</code></pre>`);
|
|
347
|
+
}
|
|
348
|
+
closeBlocks();
|
|
349
|
+
return out.join("");
|
|
350
|
+
}
|
|
208
351
|
var Chat2 = class {
|
|
209
352
|
constructor(config2) {
|
|
210
353
|
this.messages = [];
|
|
@@ -300,10 +443,11 @@ var require_dist = __commonJS({
|
|
|
300
443
|
await this.bot.streamConversation(this.messages, {
|
|
301
444
|
onChunk: (delta) => {
|
|
302
445
|
assistantMessage.content += delta;
|
|
303
|
-
contentEl
|
|
446
|
+
this.renderMessageContent(contentEl, assistantMessage);
|
|
304
447
|
this.scrollToBottom();
|
|
305
448
|
},
|
|
306
449
|
onEnd: () => {
|
|
450
|
+
this.renderMessageContent(contentEl, assistantMessage);
|
|
307
451
|
this.setInputEnabled(true);
|
|
308
452
|
if (!this.isMobile()) {
|
|
309
453
|
this.inputElement.focus();
|
|
@@ -332,11 +476,21 @@ var require_dist = __commonJS({
|
|
|
332
476
|
addMessageToUI(message) {
|
|
333
477
|
const messageEl = document.createElement("div");
|
|
334
478
|
messageEl.className = `chatter-ui-message chatter-ui-message-${message.role}`;
|
|
335
|
-
|
|
479
|
+
const contentEl = document.createElement("div");
|
|
480
|
+
contentEl.className = "chatter-ui-message-content";
|
|
481
|
+
messageEl.appendChild(contentEl);
|
|
482
|
+
this.renderMessageContent(contentEl, message);
|
|
336
483
|
this.messagesContainer.appendChild(messageEl);
|
|
337
484
|
this.scrollToBottom();
|
|
338
485
|
return messageEl;
|
|
339
486
|
}
|
|
487
|
+
renderMessageContent(target, message) {
|
|
488
|
+
if (message.role === "assistant") {
|
|
489
|
+
target.innerHTML = renderMarkdown(message.content);
|
|
490
|
+
} else {
|
|
491
|
+
target.innerHTML = escapeHtml(message.content).replace(/\n/g, "<br>");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
340
494
|
setInputEnabled(enabled) {
|
|
341
495
|
this.inputElement.disabled = !enabled;
|
|
342
496
|
this.sendButton.disabled = !enabled;
|
|
@@ -3567,6 +3721,9 @@ var require_utils = __commonJS({
|
|
|
3567
3721
|
"use strict";
|
|
3568
3722
|
var isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
|
|
3569
3723
|
var isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
|
|
3724
|
+
var isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
|
|
3725
|
+
var isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
|
|
3726
|
+
var isPathCharacter = RegExp.prototype.test.bind(/^[\da-z\-._~!$&'()*+,;=:@/]$/iu);
|
|
3570
3727
|
function stringArrayToHexStripped(input) {
|
|
3571
3728
|
let acc = "";
|
|
3572
3729
|
let code = 0;
|
|
@@ -3759,27 +3916,77 @@ var require_utils = __commonJS({
|
|
|
3759
3916
|
}
|
|
3760
3917
|
return output.join("");
|
|
3761
3918
|
}
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3919
|
+
var HOST_DELIMS = { "@": "%40", "/": "%2F", "?": "%3F", "#": "%23", ":": "%3A" };
|
|
3920
|
+
var HOST_DELIM_RE = /[@/?#:]/g;
|
|
3921
|
+
var HOST_DELIM_NO_COLON_RE = /[@/?#]/g;
|
|
3922
|
+
function reescapeHostDelimiters(host, isIP) {
|
|
3923
|
+
const re = isIP ? HOST_DELIM_NO_COLON_RE : HOST_DELIM_RE;
|
|
3924
|
+
re.lastIndex = 0;
|
|
3925
|
+
return host.replace(re, (ch) => HOST_DELIMS[ch]);
|
|
3926
|
+
}
|
|
3927
|
+
function normalizePercentEncoding(input, decodeUnreserved = false) {
|
|
3928
|
+
if (input.indexOf("%") === -1) {
|
|
3929
|
+
return input;
|
|
3772
3930
|
}
|
|
3773
|
-
|
|
3774
|
-
|
|
3931
|
+
let output = "";
|
|
3932
|
+
for (let i = 0; i < input.length; i++) {
|
|
3933
|
+
if (input[i] === "%" && i + 2 < input.length) {
|
|
3934
|
+
const hex = input.slice(i + 1, i + 3);
|
|
3935
|
+
if (isHexPair(hex)) {
|
|
3936
|
+
const normalizedHex = hex.toUpperCase();
|
|
3937
|
+
const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
|
|
3938
|
+
if (decodeUnreserved && isUnreserved(decoded)) {
|
|
3939
|
+
output += decoded;
|
|
3940
|
+
} else {
|
|
3941
|
+
output += "%" + normalizedHex;
|
|
3942
|
+
}
|
|
3943
|
+
i += 2;
|
|
3944
|
+
continue;
|
|
3945
|
+
}
|
|
3946
|
+
}
|
|
3947
|
+
output += input[i];
|
|
3775
3948
|
}
|
|
3776
|
-
|
|
3777
|
-
|
|
3949
|
+
return output;
|
|
3950
|
+
}
|
|
3951
|
+
function normalizePathEncoding(input) {
|
|
3952
|
+
let output = "";
|
|
3953
|
+
for (let i = 0; i < input.length; i++) {
|
|
3954
|
+
if (input[i] === "%" && i + 2 < input.length) {
|
|
3955
|
+
const hex = input.slice(i + 1, i + 3);
|
|
3956
|
+
if (isHexPair(hex)) {
|
|
3957
|
+
const normalizedHex = hex.toUpperCase();
|
|
3958
|
+
const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
|
|
3959
|
+
if (decoded !== "." && isUnreserved(decoded)) {
|
|
3960
|
+
output += decoded;
|
|
3961
|
+
} else {
|
|
3962
|
+
output += "%" + normalizedHex;
|
|
3963
|
+
}
|
|
3964
|
+
i += 2;
|
|
3965
|
+
continue;
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
if (isPathCharacter(input[i])) {
|
|
3969
|
+
output += input[i];
|
|
3970
|
+
} else {
|
|
3971
|
+
output += escape(input[i]);
|
|
3972
|
+
}
|
|
3778
3973
|
}
|
|
3779
|
-
|
|
3780
|
-
|
|
3974
|
+
return output;
|
|
3975
|
+
}
|
|
3976
|
+
function escapePreservingEscapes(input) {
|
|
3977
|
+
let output = "";
|
|
3978
|
+
for (let i = 0; i < input.length; i++) {
|
|
3979
|
+
if (input[i] === "%" && i + 2 < input.length) {
|
|
3980
|
+
const hex = input.slice(i + 1, i + 3);
|
|
3981
|
+
if (isHexPair(hex)) {
|
|
3982
|
+
output += "%" + hex.toUpperCase();
|
|
3983
|
+
i += 2;
|
|
3984
|
+
continue;
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
output += escape(input[i]);
|
|
3781
3988
|
}
|
|
3782
|
-
return
|
|
3989
|
+
return output;
|
|
3783
3990
|
}
|
|
3784
3991
|
function recomposeAuthority(component) {
|
|
3785
3992
|
const uriTokens = [];
|
|
@@ -3794,7 +4001,7 @@ var require_utils = __commonJS({
|
|
|
3794
4001
|
if (ipV6res.isIPV6 === true) {
|
|
3795
4002
|
host = `[${ipV6res.escapedHost}]`;
|
|
3796
4003
|
} else {
|
|
3797
|
-
host =
|
|
4004
|
+
host = reescapeHostDelimiters(host, false);
|
|
3798
4005
|
}
|
|
3799
4006
|
}
|
|
3800
4007
|
uriTokens.push(host);
|
|
@@ -3808,7 +4015,10 @@ var require_utils = __commonJS({
|
|
|
3808
4015
|
module2.exports = {
|
|
3809
4016
|
nonSimpleDomain,
|
|
3810
4017
|
recomposeAuthority,
|
|
3811
|
-
|
|
4018
|
+
reescapeHostDelimiters,
|
|
4019
|
+
normalizePercentEncoding,
|
|
4020
|
+
normalizePathEncoding,
|
|
4021
|
+
escapePreservingEscapes,
|
|
3812
4022
|
removeDotSegments,
|
|
3813
4023
|
isIPv4,
|
|
3814
4024
|
isUUID,
|
|
@@ -4032,12 +4242,12 @@ var require_schemes = __commonJS({
|
|
|
4032
4242
|
var require_fast_uri = __commonJS({
|
|
4033
4243
|
"node_modules/fast-uri/index.js"(exports2, module2) {
|
|
4034
4244
|
"use strict";
|
|
4035
|
-
var { normalizeIPv6, removeDotSegments, recomposeAuthority,
|
|
4245
|
+
var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
|
|
4036
4246
|
var { SCHEMES, getSchemeHandler } = require_schemes();
|
|
4037
4247
|
function normalize(uri, options) {
|
|
4038
4248
|
if (typeof uri === "string") {
|
|
4039
4249
|
uri = /** @type {T} */
|
|
4040
|
-
|
|
4250
|
+
normalizeString(uri, options);
|
|
4041
4251
|
} else if (typeof uri === "object") {
|
|
4042
4252
|
uri = /** @type {T} */
|
|
4043
4253
|
parse3(serialize(uri, options), options);
|
|
@@ -4046,7 +4256,12 @@ var require_fast_uri = __commonJS({
|
|
|
4046
4256
|
}
|
|
4047
4257
|
function resolve(baseURI, relativeURI, options) {
|
|
4048
4258
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
4049
|
-
const
|
|
4259
|
+
const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed } = parseWithStatus(baseURI, schemelessOptions);
|
|
4260
|
+
const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed } = parseWithStatus(relativeURI, schemelessOptions);
|
|
4261
|
+
if (baseMalformed || relativeMalformed) {
|
|
4262
|
+
throw new Error(baseParsed.error || relativeParsed.error || "URI is malformed.");
|
|
4263
|
+
}
|
|
4264
|
+
const resolved = resolveComponent(baseParsed, relativeParsed, schemelessOptions, true);
|
|
4050
4265
|
schemelessOptions.skipEscape = true;
|
|
4051
4266
|
return serialize(resolved, schemelessOptions);
|
|
4052
4267
|
}
|
|
@@ -4104,19 +4319,9 @@ var require_fast_uri = __commonJS({
|
|
|
4104
4319
|
return target;
|
|
4105
4320
|
}
|
|
4106
4321
|
function equal(uriA, uriB, options) {
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
} else if (typeof uriA === "object") {
|
|
4111
|
-
uriA = serialize(normalizeComponentEncoding(uriA, true), { ...options, skipEscape: true });
|
|
4112
|
-
}
|
|
4113
|
-
if (typeof uriB === "string") {
|
|
4114
|
-
uriB = unescape(uriB);
|
|
4115
|
-
uriB = serialize(normalizeComponentEncoding(parse3(uriB, options), true), { ...options, skipEscape: true });
|
|
4116
|
-
} else if (typeof uriB === "object") {
|
|
4117
|
-
uriB = serialize(normalizeComponentEncoding(uriB, true), { ...options, skipEscape: true });
|
|
4118
|
-
}
|
|
4119
|
-
return uriA.toLowerCase() === uriB.toLowerCase();
|
|
4322
|
+
const normalizedA = normalizeComparableURI(uriA, options);
|
|
4323
|
+
const normalizedB = normalizeComparableURI(uriB, options);
|
|
4324
|
+
return normalizedA !== void 0 && normalizedB !== void 0 && normalizedA.toLowerCase() === normalizedB.toLowerCase();
|
|
4120
4325
|
}
|
|
4121
4326
|
function serialize(cmpts, opts) {
|
|
4122
4327
|
const component = {
|
|
@@ -4141,12 +4346,12 @@ var require_fast_uri = __commonJS({
|
|
|
4141
4346
|
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options);
|
|
4142
4347
|
if (component.path !== void 0) {
|
|
4143
4348
|
if (!options.skipEscape) {
|
|
4144
|
-
component.path =
|
|
4349
|
+
component.path = escapePreservingEscapes(component.path);
|
|
4145
4350
|
if (component.scheme !== void 0) {
|
|
4146
4351
|
component.path = component.path.split("%3A").join(":");
|
|
4147
4352
|
}
|
|
4148
4353
|
} else {
|
|
4149
|
-
component.path =
|
|
4354
|
+
component.path = normalizePercentEncoding(component.path);
|
|
4150
4355
|
}
|
|
4151
4356
|
}
|
|
4152
4357
|
if (options.reference !== "suffix" && component.scheme) {
|
|
@@ -4181,7 +4386,18 @@ var require_fast_uri = __commonJS({
|
|
|
4181
4386
|
return uriTokens.join("");
|
|
4182
4387
|
}
|
|
4183
4388
|
var URI_PARSE = /^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;
|
|
4184
|
-
|
|
4389
|
+
var AUTHORITY_PREFIX = /^(?:[^#/:?]+:)?\/\/([^/?#]*)/;
|
|
4390
|
+
var AUTHORITY_INTRODUCER_REGION = /^(?:[^#/:?]+:)?([/\\\t\n\r]*)/;
|
|
4391
|
+
function getParseError(parsed, matches) {
|
|
4392
|
+
if (matches[2] !== void 0 && parsed.path && parsed.path[0] !== "/") {
|
|
4393
|
+
return 'URI path must start with "/" when authority is present.';
|
|
4394
|
+
}
|
|
4395
|
+
if (typeof parsed.port === "number" && (parsed.port < 0 || parsed.port > 65535)) {
|
|
4396
|
+
return "URI port is malformed.";
|
|
4397
|
+
}
|
|
4398
|
+
return void 0;
|
|
4399
|
+
}
|
|
4400
|
+
function parseWithStatus(uri, opts) {
|
|
4185
4401
|
const options = Object.assign({}, opts);
|
|
4186
4402
|
const parsed = {
|
|
4187
4403
|
scheme: void 0,
|
|
@@ -4192,6 +4408,7 @@ var require_fast_uri = __commonJS({
|
|
|
4192
4408
|
query: void 0,
|
|
4193
4409
|
fragment: void 0
|
|
4194
4410
|
};
|
|
4411
|
+
let malformedAuthorityOrPort = false;
|
|
4195
4412
|
let isIP = false;
|
|
4196
4413
|
if (options.reference === "suffix") {
|
|
4197
4414
|
if (options.scheme) {
|
|
@@ -4200,6 +4417,25 @@ var require_fast_uri = __commonJS({
|
|
|
4200
4417
|
uri = "//" + uri;
|
|
4201
4418
|
}
|
|
4202
4419
|
}
|
|
4420
|
+
const authorityMatch = uri.match(AUTHORITY_PREFIX);
|
|
4421
|
+
if (authorityMatch !== null && authorityMatch[1].indexOf("\\") !== -1) {
|
|
4422
|
+
parsed.error = "URI authority must not contain a literal backslash.";
|
|
4423
|
+
malformedAuthorityOrPort = true;
|
|
4424
|
+
}
|
|
4425
|
+
const introducerMatch = uri.match(AUTHORITY_INTRODUCER_REGION);
|
|
4426
|
+
if (introducerMatch !== null) {
|
|
4427
|
+
const region = introducerMatch[1];
|
|
4428
|
+
const normalizedRegion = region.replace(/[\t\n\r]/g, "");
|
|
4429
|
+
if (normalizedRegion.length >= 2) {
|
|
4430
|
+
if (normalizedRegion.slice(0, 2) !== "//") {
|
|
4431
|
+
parsed.error = parsed.error || "URI authority must not contain a literal backslash.";
|
|
4432
|
+
malformedAuthorityOrPort = true;
|
|
4433
|
+
} else if (region.length !== normalizedRegion.length) {
|
|
4434
|
+
parsed.error = parsed.error || "URI authority introducer must not contain whitespace.";
|
|
4435
|
+
malformedAuthorityOrPort = true;
|
|
4436
|
+
}
|
|
4437
|
+
}
|
|
4438
|
+
}
|
|
4203
4439
|
const matches = uri.match(URI_PARSE);
|
|
4204
4440
|
if (matches) {
|
|
4205
4441
|
parsed.scheme = matches[1];
|
|
@@ -4212,6 +4448,11 @@ var require_fast_uri = __commonJS({
|
|
|
4212
4448
|
if (isNaN(parsed.port)) {
|
|
4213
4449
|
parsed.port = matches[5];
|
|
4214
4450
|
}
|
|
4451
|
+
const parseError = getParseError(parsed, matches);
|
|
4452
|
+
if (parseError !== void 0) {
|
|
4453
|
+
parsed.error = parsed.error || parseError;
|
|
4454
|
+
malformedAuthorityOrPort = true;
|
|
4455
|
+
}
|
|
4215
4456
|
if (parsed.host) {
|
|
4216
4457
|
const ipv4result = isIPv4(parsed.host);
|
|
4217
4458
|
if (ipv4result === false) {
|
|
@@ -4238,7 +4479,7 @@ var require_fast_uri = __commonJS({
|
|
|
4238
4479
|
if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
|
|
4239
4480
|
if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
|
|
4240
4481
|
try {
|
|
4241
|
-
parsed.host = URL
|
|
4482
|
+
parsed.host = new URL("http://" + parsed.host).hostname;
|
|
4242
4483
|
} catch (e) {
|
|
4243
4484
|
parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
|
|
4244
4485
|
}
|
|
@@ -4250,14 +4491,18 @@ var require_fast_uri = __commonJS({
|
|
|
4250
4491
|
parsed.scheme = unescape(parsed.scheme);
|
|
4251
4492
|
}
|
|
4252
4493
|
if (parsed.host !== void 0) {
|
|
4253
|
-
parsed.host = unescape(parsed.host);
|
|
4494
|
+
parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP);
|
|
4254
4495
|
}
|
|
4255
4496
|
}
|
|
4256
4497
|
if (parsed.path) {
|
|
4257
|
-
parsed.path =
|
|
4498
|
+
parsed.path = normalizePathEncoding(parsed.path);
|
|
4258
4499
|
}
|
|
4259
4500
|
if (parsed.fragment) {
|
|
4260
|
-
|
|
4501
|
+
try {
|
|
4502
|
+
parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
|
|
4503
|
+
} catch {
|
|
4504
|
+
parsed.error = parsed.error || "URI malformed";
|
|
4505
|
+
}
|
|
4261
4506
|
}
|
|
4262
4507
|
}
|
|
4263
4508
|
if (schemeHandler && schemeHandler.parse) {
|
|
@@ -4266,7 +4511,29 @@ var require_fast_uri = __commonJS({
|
|
|
4266
4511
|
} else {
|
|
4267
4512
|
parsed.error = parsed.error || "URI can not be parsed.";
|
|
4268
4513
|
}
|
|
4269
|
-
return parsed;
|
|
4514
|
+
return { parsed, malformedAuthorityOrPort };
|
|
4515
|
+
}
|
|
4516
|
+
function parse3(uri, opts) {
|
|
4517
|
+
return parseWithStatus(uri, opts).parsed;
|
|
4518
|
+
}
|
|
4519
|
+
function normalizeString(uri, opts) {
|
|
4520
|
+
return normalizeStringWithStatus(uri, opts).normalized;
|
|
4521
|
+
}
|
|
4522
|
+
function normalizeStringWithStatus(uri, opts) {
|
|
4523
|
+
const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
|
|
4524
|
+
return {
|
|
4525
|
+
normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),
|
|
4526
|
+
malformedAuthorityOrPort
|
|
4527
|
+
};
|
|
4528
|
+
}
|
|
4529
|
+
function normalizeComparableURI(uri, opts) {
|
|
4530
|
+
if (typeof uri === "string") {
|
|
4531
|
+
const { normalized, malformedAuthorityOrPort } = normalizeStringWithStatus(uri, opts);
|
|
4532
|
+
return malformedAuthorityOrPort ? void 0 : normalized;
|
|
4533
|
+
}
|
|
4534
|
+
if (typeof uri === "object") {
|
|
4535
|
+
return serialize(uri, opts);
|
|
4536
|
+
}
|
|
4270
4537
|
}
|
|
4271
4538
|
var fastUri = {
|
|
4272
4539
|
SCHEMES,
|
|
@@ -7296,15 +7563,13 @@ module.exports = __toCommonJS(index_exports);
|
|
|
7296
7563
|
var import_node_crypto = require("node:crypto");
|
|
7297
7564
|
var import_jose = require("jose");
|
|
7298
7565
|
var ApiKeyManager = class {
|
|
7566
|
+
secretBytes;
|
|
7299
7567
|
constructor(secret) {
|
|
7300
|
-
this.secret = secret;
|
|
7301
7568
|
if (!secret) {
|
|
7302
7569
|
throw new Error("API key secret is required");
|
|
7303
7570
|
}
|
|
7304
7571
|
this.secretBytes = new TextEncoder().encode(secret);
|
|
7305
7572
|
}
|
|
7306
|
-
secret;
|
|
7307
|
-
secretBytes;
|
|
7308
7573
|
/**
|
|
7309
7574
|
* Create a new API key
|
|
7310
7575
|
*
|
|
@@ -15708,17 +15973,33 @@ function normalizeObjectSchema(schema) {
|
|
|
15708
15973
|
}
|
|
15709
15974
|
return void 0;
|
|
15710
15975
|
}
|
|
15976
|
+
function getDotPath(path) {
|
|
15977
|
+
if (path.length === 0) {
|
|
15978
|
+
return "object root";
|
|
15979
|
+
}
|
|
15980
|
+
return path.reduce((acc, seg, index) => {
|
|
15981
|
+
if (index === 0) {
|
|
15982
|
+
return String(seg);
|
|
15983
|
+
}
|
|
15984
|
+
if (typeof seg === "number") {
|
|
15985
|
+
return `${acc}[${seg}]`;
|
|
15986
|
+
}
|
|
15987
|
+
return `${acc}.${seg}`;
|
|
15988
|
+
}, "");
|
|
15989
|
+
}
|
|
15711
15990
|
function getParseErrorMessage(error2) {
|
|
15712
15991
|
if (error2 && typeof error2 === "object") {
|
|
15992
|
+
if ("issues" in error2 && Array.isArray(error2.issues) && error2.issues.length > 0) {
|
|
15993
|
+
return error2.issues.map((i) => {
|
|
15994
|
+
if (!i.path?.length) {
|
|
15995
|
+
return i.message;
|
|
15996
|
+
}
|
|
15997
|
+
return `${i.message} at ${getDotPath(i.path)}`;
|
|
15998
|
+
}).join("\n");
|
|
15999
|
+
}
|
|
15713
16000
|
if ("message" in error2 && typeof error2.message === "string") {
|
|
15714
16001
|
return error2.message;
|
|
15715
16002
|
}
|
|
15716
|
-
if ("issues" in error2 && Array.isArray(error2.issues) && error2.issues.length > 0) {
|
|
15717
|
-
const firstIssue = error2.issues[0];
|
|
15718
|
-
if (firstIssue && typeof firstIssue === "object" && "message" in firstIssue) {
|
|
15719
|
-
return String(firstIssue.message);
|
|
15720
|
-
}
|
|
15721
|
-
}
|
|
15722
16003
|
try {
|
|
15723
16004
|
return JSON.stringify(error2);
|
|
15724
16005
|
} catch {
|
|
@@ -20661,16 +20942,7 @@ var Server = class extends Protocol {
|
|
|
20661
20942
|
if (!methodSchema) {
|
|
20662
20943
|
throw new Error("Schema is missing a method literal");
|
|
20663
20944
|
}
|
|
20664
|
-
|
|
20665
|
-
if (isZ4Schema(methodSchema)) {
|
|
20666
|
-
const v4Schema = methodSchema;
|
|
20667
|
-
const v4Def = v4Schema._zod?.def;
|
|
20668
|
-
methodValue = v4Def?.value ?? v4Schema.value;
|
|
20669
|
-
} else {
|
|
20670
|
-
const v3Schema = methodSchema;
|
|
20671
|
-
const legacyDef = v3Schema._def;
|
|
20672
|
-
methodValue = legacyDef?.value ?? v3Schema.value;
|
|
20673
|
-
}
|
|
20945
|
+
const methodValue = getLiteralValue(methodSchema);
|
|
20674
20946
|
if (typeof methodValue !== "string") {
|
|
20675
20947
|
throw new Error("Schema method literal must be a string");
|
|
20676
20948
|
}
|