echo-ai-sdk-ts 2.6.0 → 2.6.2
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/LICENSE +21 -0
- package/dist/index.js +66 -60
- package/dist/index.mjs +66 -60
- package/package.json +4 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Echo AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -662,10 +662,10 @@ function ReadableStreamToAsyncIterable(stream) {
|
|
|
662
662
|
return {
|
|
663
663
|
async next() {
|
|
664
664
|
try {
|
|
665
|
-
const
|
|
666
|
-
if (
|
|
665
|
+
const result = await reader.read();
|
|
666
|
+
if (result?.done)
|
|
667
667
|
reader.releaseLock();
|
|
668
|
-
return
|
|
668
|
+
return result;
|
|
669
669
|
} catch (e) {
|
|
670
670
|
reader.releaseLock();
|
|
671
671
|
throw e;
|
|
@@ -1375,9 +1375,9 @@ var Stream = class _Stream {
|
|
|
1375
1375
|
return {
|
|
1376
1376
|
next: () => {
|
|
1377
1377
|
if (queue.length === 0) {
|
|
1378
|
-
const
|
|
1379
|
-
left.push(
|
|
1380
|
-
right.push(
|
|
1378
|
+
const result = iterator.next();
|
|
1379
|
+
left.push(result);
|
|
1380
|
+
right.push(result);
|
|
1381
1381
|
}
|
|
1382
1382
|
return queue.shift();
|
|
1383
1383
|
}
|
|
@@ -1769,23 +1769,23 @@ function getName(value) {
|
|
|
1769
1769
|
return (typeof value === "object" && value !== null && ("name" in value && value.name && String(value.name) || "url" in value && value.url && String(value.url) || "filename" in value && value.filename && String(value.filename) || "path" in value && value.path && String(value.path)) || "").split(/[\\/]/).pop() || void 0;
|
|
1770
1770
|
}
|
|
1771
1771
|
var isAsyncIterable = (value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function";
|
|
1772
|
-
var maybeMultipartFormRequestOptions = async (opts,
|
|
1772
|
+
var maybeMultipartFormRequestOptions = async (opts, fetch7) => {
|
|
1773
1773
|
if (!hasUploadableValue(opts.body))
|
|
1774
1774
|
return opts;
|
|
1775
|
-
return { ...opts, body: await createForm(opts.body,
|
|
1775
|
+
return { ...opts, body: await createForm(opts.body, fetch7) };
|
|
1776
1776
|
};
|
|
1777
|
-
var multipartFormRequestOptions = async (opts,
|
|
1778
|
-
return { ...opts, body: await createForm(opts.body,
|
|
1777
|
+
var multipartFormRequestOptions = async (opts, fetch7) => {
|
|
1778
|
+
return { ...opts, body: await createForm(opts.body, fetch7) };
|
|
1779
1779
|
};
|
|
1780
1780
|
var supportsFormDataMap = /* @__PURE__ */ new WeakMap();
|
|
1781
1781
|
function supportsFormData(fetchObject) {
|
|
1782
|
-
const
|
|
1783
|
-
const cached = supportsFormDataMap.get(
|
|
1782
|
+
const fetch7 = typeof fetchObject === "function" ? fetchObject : fetchObject.fetch;
|
|
1783
|
+
const cached = supportsFormDataMap.get(fetch7);
|
|
1784
1784
|
if (cached)
|
|
1785
1785
|
return cached;
|
|
1786
1786
|
const promise = (async () => {
|
|
1787
1787
|
try {
|
|
1788
|
-
const FetchResponse = "Response" in
|
|
1788
|
+
const FetchResponse = "Response" in fetch7 ? fetch7.Response : (await fetch7("data:,")).constructor;
|
|
1789
1789
|
const data = new FormData();
|
|
1790
1790
|
if (data.toString() === await new FetchResponse(data).text()) {
|
|
1791
1791
|
return false;
|
|
@@ -1795,11 +1795,11 @@ function supportsFormData(fetchObject) {
|
|
|
1795
1795
|
return true;
|
|
1796
1796
|
}
|
|
1797
1797
|
})();
|
|
1798
|
-
supportsFormDataMap.set(
|
|
1798
|
+
supportsFormDataMap.set(fetch7, promise);
|
|
1799
1799
|
return promise;
|
|
1800
1800
|
}
|
|
1801
|
-
var createForm = async (body,
|
|
1802
|
-
if (!await supportsFormData(
|
|
1801
|
+
var createForm = async (body, fetch7) => {
|
|
1802
|
+
if (!await supportsFormData(fetch7)) {
|
|
1803
1803
|
throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");
|
|
1804
1804
|
}
|
|
1805
1805
|
const form = new FormData();
|
|
@@ -6288,17 +6288,17 @@ Uploads.Parts = Parts;
|
|
|
6288
6288
|
// node_modules/openai/lib/Util.mjs
|
|
6289
6289
|
var allSettledWithThrow = async (promises) => {
|
|
6290
6290
|
const results = await Promise.allSettled(promises);
|
|
6291
|
-
const rejected = results.filter((
|
|
6291
|
+
const rejected = results.filter((result) => result.status === "rejected");
|
|
6292
6292
|
if (rejected.length) {
|
|
6293
|
-
for (const
|
|
6294
|
-
console.error(
|
|
6293
|
+
for (const result of rejected) {
|
|
6294
|
+
console.error(result.reason);
|
|
6295
6295
|
}
|
|
6296
6296
|
throw new Error(`${rejected.length} promise(s) failed - see the above errors`);
|
|
6297
6297
|
}
|
|
6298
6298
|
const values = [];
|
|
6299
|
-
for (const
|
|
6300
|
-
if (
|
|
6301
|
-
values.push(
|
|
6299
|
+
for (const result of results) {
|
|
6300
|
+
if (result.status === "fulfilled") {
|
|
6301
|
+
values.push(result.value);
|
|
6302
6302
|
}
|
|
6303
6303
|
}
|
|
6304
6304
|
return values;
|
|
@@ -7690,10 +7690,10 @@ function ReadableStreamToAsyncIterable2(stream) {
|
|
|
7690
7690
|
return {
|
|
7691
7691
|
async next() {
|
|
7692
7692
|
try {
|
|
7693
|
-
const
|
|
7694
|
-
if (
|
|
7693
|
+
const result = await reader.read();
|
|
7694
|
+
if (result?.done)
|
|
7695
7695
|
reader.releaseLock();
|
|
7696
|
-
return
|
|
7696
|
+
return result;
|
|
7697
7697
|
} catch (e) {
|
|
7698
7698
|
reader.releaseLock();
|
|
7699
7699
|
throw e;
|
|
@@ -8036,9 +8036,9 @@ var Stream2 = class _Stream {
|
|
|
8036
8036
|
return {
|
|
8037
8037
|
next: () => {
|
|
8038
8038
|
if (queue.length === 0) {
|
|
8039
|
-
const
|
|
8040
|
-
left.push(
|
|
8041
|
-
right.push(
|
|
8039
|
+
const result = iterator.next();
|
|
8040
|
+
left.push(result);
|
|
8041
|
+
right.push(result);
|
|
8042
8042
|
}
|
|
8043
8043
|
return queue.shift();
|
|
8044
8044
|
}
|
|
@@ -8432,18 +8432,18 @@ function getName2(value, stripPath) {
|
|
|
8432
8432
|
return stripPath ? val.split(/[\\/]/).pop() || void 0 : val;
|
|
8433
8433
|
}
|
|
8434
8434
|
var isAsyncIterable2 = (value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function";
|
|
8435
|
-
var multipartFormRequestOptions2 = async (opts,
|
|
8436
|
-
return { ...opts, body: await createForm2(opts.body,
|
|
8435
|
+
var multipartFormRequestOptions2 = async (opts, fetch7, stripFilenames = true) => {
|
|
8436
|
+
return { ...opts, body: await createForm2(opts.body, fetch7, stripFilenames) };
|
|
8437
8437
|
};
|
|
8438
8438
|
var supportsFormDataMap2 = /* @__PURE__ */ new WeakMap();
|
|
8439
8439
|
function supportsFormData2(fetchObject) {
|
|
8440
|
-
const
|
|
8441
|
-
const cached = supportsFormDataMap2.get(
|
|
8440
|
+
const fetch7 = typeof fetchObject === "function" ? fetchObject : fetchObject.fetch;
|
|
8441
|
+
const cached = supportsFormDataMap2.get(fetch7);
|
|
8442
8442
|
if (cached)
|
|
8443
8443
|
return cached;
|
|
8444
8444
|
const promise = (async () => {
|
|
8445
8445
|
try {
|
|
8446
|
-
const FetchResponse = "Response" in
|
|
8446
|
+
const FetchResponse = "Response" in fetch7 ? fetch7.Response : (await fetch7("data:,")).constructor;
|
|
8447
8447
|
const data = new FormData();
|
|
8448
8448
|
if (data.toString() === await new FetchResponse(data).text()) {
|
|
8449
8449
|
return false;
|
|
@@ -8453,11 +8453,11 @@ function supportsFormData2(fetchObject) {
|
|
|
8453
8453
|
return true;
|
|
8454
8454
|
}
|
|
8455
8455
|
})();
|
|
8456
|
-
supportsFormDataMap2.set(
|
|
8456
|
+
supportsFormDataMap2.set(fetch7, promise);
|
|
8457
8457
|
return promise;
|
|
8458
8458
|
}
|
|
8459
|
-
var createForm2 = async (body,
|
|
8460
|
-
if (!await supportsFormData2(
|
|
8459
|
+
var createForm2 = async (body, fetch7, stripFilenames = true) => {
|
|
8460
|
+
if (!await supportsFormData2(fetch7)) {
|
|
8461
8461
|
throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");
|
|
8462
8462
|
}
|
|
8463
8463
|
const form = new FormData();
|
|
@@ -10157,11 +10157,11 @@ async function generateToolResponse(params, lastMessage = params.messages.at(-1)
|
|
|
10157
10157
|
if ("parse" in tool && tool.parse) {
|
|
10158
10158
|
input = tool.parse(input);
|
|
10159
10159
|
}
|
|
10160
|
-
const
|
|
10160
|
+
const result = await tool.run(input);
|
|
10161
10161
|
return {
|
|
10162
10162
|
type: "tool_result",
|
|
10163
10163
|
tool_use_id: toolUse.id,
|
|
10164
|
-
content:
|
|
10164
|
+
content: result
|
|
10165
10165
|
};
|
|
10166
10166
|
} catch (error) {
|
|
10167
10167
|
return {
|
|
@@ -12502,8 +12502,8 @@ function createTool(options) {
|
|
|
12502
12502
|
schema: options.schema,
|
|
12503
12503
|
execute: async (args) => {
|
|
12504
12504
|
const parsed = options.schema.parse(args);
|
|
12505
|
-
const
|
|
12506
|
-
return typeof
|
|
12505
|
+
const result = await options.execute(parsed);
|
|
12506
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
12507
12507
|
},
|
|
12508
12508
|
getMcpSchema: () => {
|
|
12509
12509
|
const jsonSchema = (0, import_zod_to_json_schema.zodToJsonSchema)(options.schema, "toolParams");
|
|
@@ -12522,6 +12522,7 @@ function createTool(options) {
|
|
|
12522
12522
|
|
|
12523
12523
|
// src/tools/builtin.ts
|
|
12524
12524
|
var import_zod = require("zod");
|
|
12525
|
+
var import_expr_eval = require("expr-eval");
|
|
12525
12526
|
var calculatorTool = createTool({
|
|
12526
12527
|
name: "calculator",
|
|
12527
12528
|
description: "Useful for performing mathematical calculations. Provide a valid JavaScript mathematical expression as a string.",
|
|
@@ -12530,7 +12531,7 @@ var calculatorTool = createTool({
|
|
|
12530
12531
|
}),
|
|
12531
12532
|
execute: async ({ expression }) => {
|
|
12532
12533
|
try {
|
|
12533
|
-
const result =
|
|
12534
|
+
const result = import_expr_eval.Parser.evaluate(expression);
|
|
12534
12535
|
return String(result);
|
|
12535
12536
|
} catch (e) {
|
|
12536
12537
|
return `Calculation error: ${e.message}`;
|
|
@@ -12839,12 +12840,12 @@ var OpenAIWhisperSTT = class extends BaseSTTProvider {
|
|
|
12839
12840
|
response_format: "verbose_json",
|
|
12840
12841
|
timestamp_granularities: ["segment"]
|
|
12841
12842
|
});
|
|
12842
|
-
const
|
|
12843
|
+
const result = response2;
|
|
12843
12844
|
return {
|
|
12844
|
-
text:
|
|
12845
|
-
language:
|
|
12846
|
-
duration:
|
|
12847
|
-
segments:
|
|
12845
|
+
text: result.text,
|
|
12846
|
+
language: result.language,
|
|
12847
|
+
duration: result.duration,
|
|
12848
|
+
segments: result.segments?.map((s) => ({
|
|
12848
12849
|
start: s.start,
|
|
12849
12850
|
end: s.end,
|
|
12850
12851
|
text: s.text,
|
|
@@ -12975,6 +12976,7 @@ var EchoVoice = class {
|
|
|
12975
12976
|
};
|
|
12976
12977
|
|
|
12977
12978
|
// src/widget/connector.ts
|
|
12979
|
+
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
12978
12980
|
var APIConnector = class {
|
|
12979
12981
|
baseUrl;
|
|
12980
12982
|
headers;
|
|
@@ -13002,7 +13004,7 @@ var APIConnector = class {
|
|
|
13002
13004
|
const controller = new AbortController();
|
|
13003
13005
|
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
13004
13006
|
try {
|
|
13005
|
-
const response = await
|
|
13007
|
+
const response = await (0, import_cross_fetch.default)(url, {
|
|
13006
13008
|
method,
|
|
13007
13009
|
headers: this.headers,
|
|
13008
13010
|
body: body ? JSON.stringify(body) : void 0,
|
|
@@ -13022,6 +13024,7 @@ var APIConnector = class {
|
|
|
13022
13024
|
var import_zod4 = require("zod");
|
|
13023
13025
|
|
|
13024
13026
|
// src/rag/knowledge.ts
|
|
13027
|
+
var import_cross_fetch2 = __toESM(require("cross-fetch"));
|
|
13025
13028
|
var fs = __toESM(require("fs/promises"));
|
|
13026
13029
|
function cosineSimilarity(a, b) {
|
|
13027
13030
|
if (a.length !== b.length) return 0;
|
|
@@ -13150,7 +13153,7 @@ var KnowledgeBase = class {
|
|
|
13150
13153
|
return chunks.length;
|
|
13151
13154
|
}
|
|
13152
13155
|
async ingestURL(url) {
|
|
13153
|
-
const response = await
|
|
13156
|
+
const response = await (0, import_cross_fetch2.default)(url);
|
|
13154
13157
|
const html = await response.text();
|
|
13155
13158
|
const text = html.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
13156
13159
|
return this.ingestText(text, url);
|
|
@@ -13355,6 +13358,7 @@ var ConversationAnalytics = class {
|
|
|
13355
13358
|
};
|
|
13356
13359
|
|
|
13357
13360
|
// src/analytics/handoff.ts
|
|
13361
|
+
var import_cross_fetch3 = __toESM(require("cross-fetch"));
|
|
13358
13362
|
var crypto2 = __toESM(require("crypto"));
|
|
13359
13363
|
var HandoffManager = class {
|
|
13360
13364
|
webhookUrl;
|
|
@@ -13463,7 +13467,7 @@ var HandoffManager = class {
|
|
|
13463
13467
|
headers["X-Webhook-Signature"] = `sha256=${hmac.digest("hex")}`;
|
|
13464
13468
|
}
|
|
13465
13469
|
try {
|
|
13466
|
-
await
|
|
13470
|
+
await (0, import_cross_fetch3.default)(this.webhookUrl, { method: "POST", headers, body });
|
|
13467
13471
|
} catch (e) {
|
|
13468
13472
|
console.error(`[HandoffManager] Webhook dispatch failed: ${e.message}`);
|
|
13469
13473
|
}
|
|
@@ -13801,9 +13805,9 @@ var CustomerSupportBot = class {
|
|
|
13801
13805
|
body: import_zod4.z.any().optional().describe("Request body for POST requests")
|
|
13802
13806
|
}),
|
|
13803
13807
|
execute: async ({ endpoint, method, body }) => {
|
|
13804
|
-
const
|
|
13805
|
-
if (!
|
|
13806
|
-
return JSON.stringify(
|
|
13808
|
+
const result = method === "POST" ? await connector.post(endpoint, body) : await connector.get(endpoint);
|
|
13809
|
+
if (!result.ok) return `API returned error (${result.status}): ${JSON.stringify(result.data)}`;
|
|
13810
|
+
return JSON.stringify(result.data, null, 2);
|
|
13807
13811
|
}
|
|
13808
13812
|
}));
|
|
13809
13813
|
}
|
|
@@ -13856,8 +13860,8 @@ Your role:
|
|
|
13856
13860
|
this.analytics.recordQuery(sessionId, activeMessage);
|
|
13857
13861
|
const startTime = Date.now();
|
|
13858
13862
|
for (const mw of this.middlewares) {
|
|
13859
|
-
const
|
|
13860
|
-
if (typeof
|
|
13863
|
+
const result = await mw({ sessionId, message: activeMessage, bot: this });
|
|
13864
|
+
if (typeof result === "string") return result;
|
|
13861
13865
|
}
|
|
13862
13866
|
if (this.handoff) {
|
|
13863
13867
|
const trigger = this.handoff.shouldEscalate(sessionId, activeMessage);
|
|
@@ -14149,6 +14153,7 @@ var SlackAdapter = class extends ChannelAdapter {
|
|
|
14149
14153
|
};
|
|
14150
14154
|
|
|
14151
14155
|
// src/channels/telegram.ts
|
|
14156
|
+
var import_cross_fetch4 = __toESM(require("cross-fetch"));
|
|
14152
14157
|
var TelegramAdapter = class extends ChannelAdapter {
|
|
14153
14158
|
token;
|
|
14154
14159
|
polling = false;
|
|
@@ -14168,7 +14173,7 @@ var TelegramAdapter = class extends ChannelAdapter {
|
|
|
14168
14173
|
async runPollingLoop() {
|
|
14169
14174
|
while (this.polling) {
|
|
14170
14175
|
try {
|
|
14171
|
-
const response = await
|
|
14176
|
+
const response = await (0, import_cross_fetch4.default)(`https://api.telegram.org/bot${this.token}/getUpdates?offset=${this.offset}&timeout=30`);
|
|
14172
14177
|
const data = await response.json();
|
|
14173
14178
|
if (data.ok && data.result && data.result.length > 0) {
|
|
14174
14179
|
for (const update of data.result) {
|
|
@@ -14187,7 +14192,7 @@ var TelegramAdapter = class extends ChannelAdapter {
|
|
|
14187
14192
|
}
|
|
14188
14193
|
}
|
|
14189
14194
|
async sendMessage(chatId, text) {
|
|
14190
|
-
await
|
|
14195
|
+
await (0, import_cross_fetch4.default)(`https://api.telegram.org/bot${this.token}/sendMessage`, {
|
|
14191
14196
|
method: "POST",
|
|
14192
14197
|
headers: { "Content-Type": "application/json" },
|
|
14193
14198
|
body: JSON.stringify({ chat_id: chatId, text })
|
|
@@ -14196,6 +14201,7 @@ var TelegramAdapter = class extends ChannelAdapter {
|
|
|
14196
14201
|
};
|
|
14197
14202
|
|
|
14198
14203
|
// src/deployment/huggingface_manager.ts
|
|
14204
|
+
var import_cross_fetch5 = __toESM(require("cross-fetch"));
|
|
14199
14205
|
var InferenceEndpointManager = class {
|
|
14200
14206
|
token;
|
|
14201
14207
|
baseUrl = "https://api.endpoints.huggingface.cloud/v2";
|
|
@@ -14232,7 +14238,7 @@ var InferenceEndpointManager = class {
|
|
|
14232
14238
|
}
|
|
14233
14239
|
}
|
|
14234
14240
|
};
|
|
14235
|
-
const res = await
|
|
14241
|
+
const res = await (0, import_cross_fetch5.default)(url, {
|
|
14236
14242
|
method: "POST",
|
|
14237
14243
|
headers: this.headers,
|
|
14238
14244
|
body: JSON.stringify(payload)
|
|
@@ -14248,7 +14254,7 @@ var InferenceEndpointManager = class {
|
|
|
14248
14254
|
*/
|
|
14249
14255
|
async getEndpointStatus(accountId, endpointName) {
|
|
14250
14256
|
const url = `${this.baseUrl}/endpoint/${accountId}/${endpointName}`;
|
|
14251
|
-
const res = await
|
|
14257
|
+
const res = await (0, import_cross_fetch5.default)(url, { headers: this.headers });
|
|
14252
14258
|
if (!res.ok) throw new Error("Could not fetch endpoint status");
|
|
14253
14259
|
const data = await res.json();
|
|
14254
14260
|
return data.status.state;
|
|
@@ -14258,7 +14264,7 @@ var InferenceEndpointManager = class {
|
|
|
14258
14264
|
*/
|
|
14259
14265
|
async pauseEndpoint(accountId, endpointName) {
|
|
14260
14266
|
const url = `${this.baseUrl}/endpoint/${accountId}/${endpointName}/pause`;
|
|
14261
|
-
const res = await
|
|
14267
|
+
const res = await (0, import_cross_fetch5.default)(url, { method: "POST", headers: this.headers });
|
|
14262
14268
|
if (!res.ok) throw new Error("Failed to pause endpoint");
|
|
14263
14269
|
}
|
|
14264
14270
|
/**
|
|
@@ -14266,7 +14272,7 @@ var InferenceEndpointManager = class {
|
|
|
14266
14272
|
*/
|
|
14267
14273
|
async resumeEndpoint(accountId, endpointName) {
|
|
14268
14274
|
const url = `${this.baseUrl}/endpoint/${accountId}/${endpointName}/resume`;
|
|
14269
|
-
const res = await
|
|
14275
|
+
const res = await (0, import_cross_fetch5.default)(url, { method: "POST", headers: this.headers });
|
|
14270
14276
|
if (!res.ok) throw new Error("Failed to resume endpoint");
|
|
14271
14277
|
}
|
|
14272
14278
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -569,10 +569,10 @@ function ReadableStreamToAsyncIterable(stream) {
|
|
|
569
569
|
return {
|
|
570
570
|
async next() {
|
|
571
571
|
try {
|
|
572
|
-
const
|
|
573
|
-
if (
|
|
572
|
+
const result = await reader.read();
|
|
573
|
+
if (result?.done)
|
|
574
574
|
reader.releaseLock();
|
|
575
|
-
return
|
|
575
|
+
return result;
|
|
576
576
|
} catch (e) {
|
|
577
577
|
reader.releaseLock();
|
|
578
578
|
throw e;
|
|
@@ -1282,9 +1282,9 @@ var Stream = class _Stream {
|
|
|
1282
1282
|
return {
|
|
1283
1283
|
next: () => {
|
|
1284
1284
|
if (queue.length === 0) {
|
|
1285
|
-
const
|
|
1286
|
-
left.push(
|
|
1287
|
-
right.push(
|
|
1285
|
+
const result = iterator.next();
|
|
1286
|
+
left.push(result);
|
|
1287
|
+
right.push(result);
|
|
1288
1288
|
}
|
|
1289
1289
|
return queue.shift();
|
|
1290
1290
|
}
|
|
@@ -1676,23 +1676,23 @@ function getName(value) {
|
|
|
1676
1676
|
return (typeof value === "object" && value !== null && ("name" in value && value.name && String(value.name) || "url" in value && value.url && String(value.url) || "filename" in value && value.filename && String(value.filename) || "path" in value && value.path && String(value.path)) || "").split(/[\\/]/).pop() || void 0;
|
|
1677
1677
|
}
|
|
1678
1678
|
var isAsyncIterable = (value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function";
|
|
1679
|
-
var maybeMultipartFormRequestOptions = async (opts,
|
|
1679
|
+
var maybeMultipartFormRequestOptions = async (opts, fetch7) => {
|
|
1680
1680
|
if (!hasUploadableValue(opts.body))
|
|
1681
1681
|
return opts;
|
|
1682
|
-
return { ...opts, body: await createForm(opts.body,
|
|
1682
|
+
return { ...opts, body: await createForm(opts.body, fetch7) };
|
|
1683
1683
|
};
|
|
1684
|
-
var multipartFormRequestOptions = async (opts,
|
|
1685
|
-
return { ...opts, body: await createForm(opts.body,
|
|
1684
|
+
var multipartFormRequestOptions = async (opts, fetch7) => {
|
|
1685
|
+
return { ...opts, body: await createForm(opts.body, fetch7) };
|
|
1686
1686
|
};
|
|
1687
1687
|
var supportsFormDataMap = /* @__PURE__ */ new WeakMap();
|
|
1688
1688
|
function supportsFormData(fetchObject) {
|
|
1689
|
-
const
|
|
1690
|
-
const cached = supportsFormDataMap.get(
|
|
1689
|
+
const fetch7 = typeof fetchObject === "function" ? fetchObject : fetchObject.fetch;
|
|
1690
|
+
const cached = supportsFormDataMap.get(fetch7);
|
|
1691
1691
|
if (cached)
|
|
1692
1692
|
return cached;
|
|
1693
1693
|
const promise = (async () => {
|
|
1694
1694
|
try {
|
|
1695
|
-
const FetchResponse = "Response" in
|
|
1695
|
+
const FetchResponse = "Response" in fetch7 ? fetch7.Response : (await fetch7("data:,")).constructor;
|
|
1696
1696
|
const data = new FormData();
|
|
1697
1697
|
if (data.toString() === await new FetchResponse(data).text()) {
|
|
1698
1698
|
return false;
|
|
@@ -1702,11 +1702,11 @@ function supportsFormData(fetchObject) {
|
|
|
1702
1702
|
return true;
|
|
1703
1703
|
}
|
|
1704
1704
|
})();
|
|
1705
|
-
supportsFormDataMap.set(
|
|
1705
|
+
supportsFormDataMap.set(fetch7, promise);
|
|
1706
1706
|
return promise;
|
|
1707
1707
|
}
|
|
1708
|
-
var createForm = async (body,
|
|
1709
|
-
if (!await supportsFormData(
|
|
1708
|
+
var createForm = async (body, fetch7) => {
|
|
1709
|
+
if (!await supportsFormData(fetch7)) {
|
|
1710
1710
|
throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");
|
|
1711
1711
|
}
|
|
1712
1712
|
const form = new FormData();
|
|
@@ -6195,17 +6195,17 @@ Uploads.Parts = Parts;
|
|
|
6195
6195
|
// node_modules/openai/lib/Util.mjs
|
|
6196
6196
|
var allSettledWithThrow = async (promises) => {
|
|
6197
6197
|
const results = await Promise.allSettled(promises);
|
|
6198
|
-
const rejected = results.filter((
|
|
6198
|
+
const rejected = results.filter((result) => result.status === "rejected");
|
|
6199
6199
|
if (rejected.length) {
|
|
6200
|
-
for (const
|
|
6201
|
-
console.error(
|
|
6200
|
+
for (const result of rejected) {
|
|
6201
|
+
console.error(result.reason);
|
|
6202
6202
|
}
|
|
6203
6203
|
throw new Error(`${rejected.length} promise(s) failed - see the above errors`);
|
|
6204
6204
|
}
|
|
6205
6205
|
const values = [];
|
|
6206
|
-
for (const
|
|
6207
|
-
if (
|
|
6208
|
-
values.push(
|
|
6206
|
+
for (const result of results) {
|
|
6207
|
+
if (result.status === "fulfilled") {
|
|
6208
|
+
values.push(result.value);
|
|
6209
6209
|
}
|
|
6210
6210
|
}
|
|
6211
6211
|
return values;
|
|
@@ -7597,10 +7597,10 @@ function ReadableStreamToAsyncIterable2(stream) {
|
|
|
7597
7597
|
return {
|
|
7598
7598
|
async next() {
|
|
7599
7599
|
try {
|
|
7600
|
-
const
|
|
7601
|
-
if (
|
|
7600
|
+
const result = await reader.read();
|
|
7601
|
+
if (result?.done)
|
|
7602
7602
|
reader.releaseLock();
|
|
7603
|
-
return
|
|
7603
|
+
return result;
|
|
7604
7604
|
} catch (e) {
|
|
7605
7605
|
reader.releaseLock();
|
|
7606
7606
|
throw e;
|
|
@@ -7943,9 +7943,9 @@ var Stream2 = class _Stream {
|
|
|
7943
7943
|
return {
|
|
7944
7944
|
next: () => {
|
|
7945
7945
|
if (queue.length === 0) {
|
|
7946
|
-
const
|
|
7947
|
-
left.push(
|
|
7948
|
-
right.push(
|
|
7946
|
+
const result = iterator.next();
|
|
7947
|
+
left.push(result);
|
|
7948
|
+
right.push(result);
|
|
7949
7949
|
}
|
|
7950
7950
|
return queue.shift();
|
|
7951
7951
|
}
|
|
@@ -8339,18 +8339,18 @@ function getName2(value, stripPath) {
|
|
|
8339
8339
|
return stripPath ? val.split(/[\\/]/).pop() || void 0 : val;
|
|
8340
8340
|
}
|
|
8341
8341
|
var isAsyncIterable2 = (value) => value != null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function";
|
|
8342
|
-
var multipartFormRequestOptions2 = async (opts,
|
|
8343
|
-
return { ...opts, body: await createForm2(opts.body,
|
|
8342
|
+
var multipartFormRequestOptions2 = async (opts, fetch7, stripFilenames = true) => {
|
|
8343
|
+
return { ...opts, body: await createForm2(opts.body, fetch7, stripFilenames) };
|
|
8344
8344
|
};
|
|
8345
8345
|
var supportsFormDataMap2 = /* @__PURE__ */ new WeakMap();
|
|
8346
8346
|
function supportsFormData2(fetchObject) {
|
|
8347
|
-
const
|
|
8348
|
-
const cached = supportsFormDataMap2.get(
|
|
8347
|
+
const fetch7 = typeof fetchObject === "function" ? fetchObject : fetchObject.fetch;
|
|
8348
|
+
const cached = supportsFormDataMap2.get(fetch7);
|
|
8349
8349
|
if (cached)
|
|
8350
8350
|
return cached;
|
|
8351
8351
|
const promise = (async () => {
|
|
8352
8352
|
try {
|
|
8353
|
-
const FetchResponse = "Response" in
|
|
8353
|
+
const FetchResponse = "Response" in fetch7 ? fetch7.Response : (await fetch7("data:,")).constructor;
|
|
8354
8354
|
const data = new FormData();
|
|
8355
8355
|
if (data.toString() === await new FetchResponse(data).text()) {
|
|
8356
8356
|
return false;
|
|
@@ -8360,11 +8360,11 @@ function supportsFormData2(fetchObject) {
|
|
|
8360
8360
|
return true;
|
|
8361
8361
|
}
|
|
8362
8362
|
})();
|
|
8363
|
-
supportsFormDataMap2.set(
|
|
8363
|
+
supportsFormDataMap2.set(fetch7, promise);
|
|
8364
8364
|
return promise;
|
|
8365
8365
|
}
|
|
8366
|
-
var createForm2 = async (body,
|
|
8367
|
-
if (!await supportsFormData2(
|
|
8366
|
+
var createForm2 = async (body, fetch7, stripFilenames = true) => {
|
|
8367
|
+
if (!await supportsFormData2(fetch7)) {
|
|
8368
8368
|
throw new TypeError("The provided fetch function does not support file uploads with the current global FormData class.");
|
|
8369
8369
|
}
|
|
8370
8370
|
const form = new FormData();
|
|
@@ -10064,11 +10064,11 @@ async function generateToolResponse(params, lastMessage = params.messages.at(-1)
|
|
|
10064
10064
|
if ("parse" in tool && tool.parse) {
|
|
10065
10065
|
input = tool.parse(input);
|
|
10066
10066
|
}
|
|
10067
|
-
const
|
|
10067
|
+
const result = await tool.run(input);
|
|
10068
10068
|
return {
|
|
10069
10069
|
type: "tool_result",
|
|
10070
10070
|
tool_use_id: toolUse.id,
|
|
10071
|
-
content:
|
|
10071
|
+
content: result
|
|
10072
10072
|
};
|
|
10073
10073
|
} catch (error) {
|
|
10074
10074
|
return {
|
|
@@ -12409,8 +12409,8 @@ function createTool(options) {
|
|
|
12409
12409
|
schema: options.schema,
|
|
12410
12410
|
execute: async (args) => {
|
|
12411
12411
|
const parsed = options.schema.parse(args);
|
|
12412
|
-
const
|
|
12413
|
-
return typeof
|
|
12412
|
+
const result = await options.execute(parsed);
|
|
12413
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
12414
12414
|
},
|
|
12415
12415
|
getMcpSchema: () => {
|
|
12416
12416
|
const jsonSchema = zodToJsonSchema(options.schema, "toolParams");
|
|
@@ -12429,6 +12429,7 @@ function createTool(options) {
|
|
|
12429
12429
|
|
|
12430
12430
|
// src/tools/builtin.ts
|
|
12431
12431
|
import { z } from "zod";
|
|
12432
|
+
import { Parser } from "expr-eval";
|
|
12432
12433
|
var calculatorTool = createTool({
|
|
12433
12434
|
name: "calculator",
|
|
12434
12435
|
description: "Useful for performing mathematical calculations. Provide a valid JavaScript mathematical expression as a string.",
|
|
@@ -12437,7 +12438,7 @@ var calculatorTool = createTool({
|
|
|
12437
12438
|
}),
|
|
12438
12439
|
execute: async ({ expression }) => {
|
|
12439
12440
|
try {
|
|
12440
|
-
const result =
|
|
12441
|
+
const result = Parser.evaluate(expression);
|
|
12441
12442
|
return String(result);
|
|
12442
12443
|
} catch (e) {
|
|
12443
12444
|
return `Calculation error: ${e.message}`;
|
|
@@ -12746,12 +12747,12 @@ var OpenAIWhisperSTT = class extends BaseSTTProvider {
|
|
|
12746
12747
|
response_format: "verbose_json",
|
|
12747
12748
|
timestamp_granularities: ["segment"]
|
|
12748
12749
|
});
|
|
12749
|
-
const
|
|
12750
|
+
const result = response2;
|
|
12750
12751
|
return {
|
|
12751
|
-
text:
|
|
12752
|
-
language:
|
|
12753
|
-
duration:
|
|
12754
|
-
segments:
|
|
12752
|
+
text: result.text,
|
|
12753
|
+
language: result.language,
|
|
12754
|
+
duration: result.duration,
|
|
12755
|
+
segments: result.segments?.map((s) => ({
|
|
12755
12756
|
start: s.start,
|
|
12756
12757
|
end: s.end,
|
|
12757
12758
|
text: s.text,
|
|
@@ -12882,6 +12883,7 @@ var EchoVoice = class {
|
|
|
12882
12883
|
};
|
|
12883
12884
|
|
|
12884
12885
|
// src/widget/connector.ts
|
|
12886
|
+
import fetch2 from "cross-fetch";
|
|
12885
12887
|
var APIConnector = class {
|
|
12886
12888
|
baseUrl;
|
|
12887
12889
|
headers;
|
|
@@ -12909,7 +12911,7 @@ var APIConnector = class {
|
|
|
12909
12911
|
const controller = new AbortController();
|
|
12910
12912
|
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
12911
12913
|
try {
|
|
12912
|
-
const response = await
|
|
12914
|
+
const response = await fetch2(url, {
|
|
12913
12915
|
method,
|
|
12914
12916
|
headers: this.headers,
|
|
12915
12917
|
body: body ? JSON.stringify(body) : void 0,
|
|
@@ -12929,6 +12931,7 @@ var APIConnector = class {
|
|
|
12929
12931
|
import { z as z4 } from "zod";
|
|
12930
12932
|
|
|
12931
12933
|
// src/rag/knowledge.ts
|
|
12934
|
+
import fetch3 from "cross-fetch";
|
|
12932
12935
|
import * as fs from "fs/promises";
|
|
12933
12936
|
function cosineSimilarity(a, b) {
|
|
12934
12937
|
if (a.length !== b.length) return 0;
|
|
@@ -13057,7 +13060,7 @@ var KnowledgeBase = class {
|
|
|
13057
13060
|
return chunks.length;
|
|
13058
13061
|
}
|
|
13059
13062
|
async ingestURL(url) {
|
|
13060
|
-
const response = await
|
|
13063
|
+
const response = await fetch3(url);
|
|
13061
13064
|
const html = await response.text();
|
|
13062
13065
|
const text = html.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, "").replace(/<style[^>]*>[\s\S]*?<\/style>/gi, "").replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
13063
13066
|
return this.ingestText(text, url);
|
|
@@ -13262,6 +13265,7 @@ var ConversationAnalytics = class {
|
|
|
13262
13265
|
};
|
|
13263
13266
|
|
|
13264
13267
|
// src/analytics/handoff.ts
|
|
13268
|
+
import fetch4 from "cross-fetch";
|
|
13265
13269
|
import * as crypto2 from "crypto";
|
|
13266
13270
|
var HandoffManager = class {
|
|
13267
13271
|
webhookUrl;
|
|
@@ -13370,7 +13374,7 @@ var HandoffManager = class {
|
|
|
13370
13374
|
headers["X-Webhook-Signature"] = `sha256=${hmac.digest("hex")}`;
|
|
13371
13375
|
}
|
|
13372
13376
|
try {
|
|
13373
|
-
await
|
|
13377
|
+
await fetch4(this.webhookUrl, { method: "POST", headers, body });
|
|
13374
13378
|
} catch (e) {
|
|
13375
13379
|
console.error(`[HandoffManager] Webhook dispatch failed: ${e.message}`);
|
|
13376
13380
|
}
|
|
@@ -13708,9 +13712,9 @@ var CustomerSupportBot = class {
|
|
|
13708
13712
|
body: z4.any().optional().describe("Request body for POST requests")
|
|
13709
13713
|
}),
|
|
13710
13714
|
execute: async ({ endpoint, method, body }) => {
|
|
13711
|
-
const
|
|
13712
|
-
if (!
|
|
13713
|
-
return JSON.stringify(
|
|
13715
|
+
const result = method === "POST" ? await connector.post(endpoint, body) : await connector.get(endpoint);
|
|
13716
|
+
if (!result.ok) return `API returned error (${result.status}): ${JSON.stringify(result.data)}`;
|
|
13717
|
+
return JSON.stringify(result.data, null, 2);
|
|
13714
13718
|
}
|
|
13715
13719
|
}));
|
|
13716
13720
|
}
|
|
@@ -13763,8 +13767,8 @@ Your role:
|
|
|
13763
13767
|
this.analytics.recordQuery(sessionId, activeMessage);
|
|
13764
13768
|
const startTime = Date.now();
|
|
13765
13769
|
for (const mw of this.middlewares) {
|
|
13766
|
-
const
|
|
13767
|
-
if (typeof
|
|
13770
|
+
const result = await mw({ sessionId, message: activeMessage, bot: this });
|
|
13771
|
+
if (typeof result === "string") return result;
|
|
13768
13772
|
}
|
|
13769
13773
|
if (this.handoff) {
|
|
13770
13774
|
const trigger = this.handoff.shouldEscalate(sessionId, activeMessage);
|
|
@@ -14056,6 +14060,7 @@ var SlackAdapter = class extends ChannelAdapter {
|
|
|
14056
14060
|
};
|
|
14057
14061
|
|
|
14058
14062
|
// src/channels/telegram.ts
|
|
14063
|
+
import fetch5 from "cross-fetch";
|
|
14059
14064
|
var TelegramAdapter = class extends ChannelAdapter {
|
|
14060
14065
|
token;
|
|
14061
14066
|
polling = false;
|
|
@@ -14075,7 +14080,7 @@ var TelegramAdapter = class extends ChannelAdapter {
|
|
|
14075
14080
|
async runPollingLoop() {
|
|
14076
14081
|
while (this.polling) {
|
|
14077
14082
|
try {
|
|
14078
|
-
const response = await
|
|
14083
|
+
const response = await fetch5(`https://api.telegram.org/bot${this.token}/getUpdates?offset=${this.offset}&timeout=30`);
|
|
14079
14084
|
const data = await response.json();
|
|
14080
14085
|
if (data.ok && data.result && data.result.length > 0) {
|
|
14081
14086
|
for (const update of data.result) {
|
|
@@ -14094,7 +14099,7 @@ var TelegramAdapter = class extends ChannelAdapter {
|
|
|
14094
14099
|
}
|
|
14095
14100
|
}
|
|
14096
14101
|
async sendMessage(chatId, text) {
|
|
14097
|
-
await
|
|
14102
|
+
await fetch5(`https://api.telegram.org/bot${this.token}/sendMessage`, {
|
|
14098
14103
|
method: "POST",
|
|
14099
14104
|
headers: { "Content-Type": "application/json" },
|
|
14100
14105
|
body: JSON.stringify({ chat_id: chatId, text })
|
|
@@ -14103,6 +14108,7 @@ var TelegramAdapter = class extends ChannelAdapter {
|
|
|
14103
14108
|
};
|
|
14104
14109
|
|
|
14105
14110
|
// src/deployment/huggingface_manager.ts
|
|
14111
|
+
import fetch6 from "cross-fetch";
|
|
14106
14112
|
var InferenceEndpointManager = class {
|
|
14107
14113
|
token;
|
|
14108
14114
|
baseUrl = "https://api.endpoints.huggingface.cloud/v2";
|
|
@@ -14139,7 +14145,7 @@ var InferenceEndpointManager = class {
|
|
|
14139
14145
|
}
|
|
14140
14146
|
}
|
|
14141
14147
|
};
|
|
14142
|
-
const res = await
|
|
14148
|
+
const res = await fetch6(url, {
|
|
14143
14149
|
method: "POST",
|
|
14144
14150
|
headers: this.headers,
|
|
14145
14151
|
body: JSON.stringify(payload)
|
|
@@ -14155,7 +14161,7 @@ var InferenceEndpointManager = class {
|
|
|
14155
14161
|
*/
|
|
14156
14162
|
async getEndpointStatus(accountId, endpointName) {
|
|
14157
14163
|
const url = `${this.baseUrl}/endpoint/${accountId}/${endpointName}`;
|
|
14158
|
-
const res = await
|
|
14164
|
+
const res = await fetch6(url, { headers: this.headers });
|
|
14159
14165
|
if (!res.ok) throw new Error("Could not fetch endpoint status");
|
|
14160
14166
|
const data = await res.json();
|
|
14161
14167
|
return data.status.state;
|
|
@@ -14165,7 +14171,7 @@ var InferenceEndpointManager = class {
|
|
|
14165
14171
|
*/
|
|
14166
14172
|
async pauseEndpoint(accountId, endpointName) {
|
|
14167
14173
|
const url = `${this.baseUrl}/endpoint/${accountId}/${endpointName}/pause`;
|
|
14168
|
-
const res = await
|
|
14174
|
+
const res = await fetch6(url, { method: "POST", headers: this.headers });
|
|
14169
14175
|
if (!res.ok) throw new Error("Failed to pause endpoint");
|
|
14170
14176
|
}
|
|
14171
14177
|
/**
|
|
@@ -14173,7 +14179,7 @@ var InferenceEndpointManager = class {
|
|
|
14173
14179
|
*/
|
|
14174
14180
|
async resumeEndpoint(accountId, endpointName) {
|
|
14175
14181
|
const url = `${this.baseUrl}/endpoint/${accountId}/${endpointName}/resume`;
|
|
14176
|
-
const res = await
|
|
14182
|
+
const res = await fetch6(url, { method: "POST", headers: this.headers });
|
|
14177
14183
|
if (!res.ok) throw new Error("Failed to resume endpoint");
|
|
14178
14184
|
}
|
|
14179
14185
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "echo-ai-sdk-ts",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"description": "Echo AI SDK: Tier 5 Cloud Native (AWS Bedrock/SageMaker, GCP Vertex, Azure OpenAI/ML)",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@huggingface/inference": "^4.13.15",
|
|
19
19
|
"cors": "^2.8.5",
|
|
20
|
+
"cross-fetch": "^4.1.0",
|
|
21
|
+
"expr-eval": "^2.0.2",
|
|
20
22
|
"express": "^4.18.2",
|
|
21
23
|
"zod": "^3.25.76",
|
|
22
24
|
"zod-to-json-schema": "^3.25.1"
|
|
@@ -38,4 +40,4 @@
|
|
|
38
40
|
"typescript": "^5.3.3",
|
|
39
41
|
"vitest": "^1.3.1"
|
|
40
42
|
}
|
|
41
|
-
}
|
|
43
|
+
}
|