@opentiny/next-sdk 0.1.7 → 0.1.9
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/agent/AgentModelProvider.ts +21 -14
- package/dist/agent/AgentModelProvider.d.ts +6 -10
- package/dist/agent/AgentModelProvider.js +40 -29
- package/dist/index.es.dev.js +26 -17
- package/dist/index.es.js +9347 -9319
- package/dist/index.umd.dev.js +26 -17
- package/dist/index.umd.js +34 -34
- package/dist/mcpsdk@1.17.0.es.js +6297 -6312
- package/dist/mcpsdk@1.17.0.js +16 -16
- package/dist/remoter/createRemoter.d.ts +2 -0
- package/dist/remoter/createRemoter.js +7 -5
- package/dist/webagent.dev.js +26 -17
- package/dist/webagent.es.dev.js +26 -17
- package/dist/webagent.es.js +1595 -1587
- package/dist/webagent.js +22 -22
- package/package.json +1 -1
- package/remoter/createRemoter.ts +12 -6
|
@@ -8,6 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { QrCode } from './QrCode';
|
|
11
|
+
const DEFAULT_REMOTE_URL = 'https://agent.opentiny.design/tiny-robot';
|
|
12
|
+
const DEFAULT_QR_CODE_URL = 'https://ai.opentiny.design/next-remoter';
|
|
11
13
|
const getDefaultMenuItems = (options) => {
|
|
12
14
|
return [
|
|
13
15
|
{
|
|
@@ -56,8 +58,8 @@ const getDefaultMenuItems = (options) => {
|
|
|
56
58
|
{
|
|
57
59
|
action: 'remote-url',
|
|
58
60
|
show: true,
|
|
59
|
-
text: `${options.
|
|
60
|
-
tip: options.
|
|
61
|
+
text: `${options.remoteUrl}`,
|
|
62
|
+
tip: options.remoteUrl,
|
|
61
63
|
showCopyIcon: true,
|
|
62
64
|
icon: `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
63
65
|
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
@@ -77,7 +79,7 @@ class FloatingBlock {
|
|
|
77
79
|
if (!options.sessionId) {
|
|
78
80
|
throw new Error('sessionId is required');
|
|
79
81
|
}
|
|
80
|
-
this.options = Object.assign({ qrCodeUrl: options.qrCodeUrl ||
|
|
82
|
+
this.options = Object.assign(Object.assign({}, options), { qrCodeUrl: options.qrCodeUrl || DEFAULT_QR_CODE_URL, remoteUrl: options.remoteUrl || DEFAULT_REMOTE_URL });
|
|
81
83
|
// 合并默认菜单项配置和用户配置
|
|
82
84
|
this.menuItems = this.mergeMenuItems(options.menuItems);
|
|
83
85
|
this.init();
|
|
@@ -113,7 +115,7 @@ class FloatingBlock {
|
|
|
113
115
|
this.floatingBlock.className = 'tiny-remoter-floating-block';
|
|
114
116
|
this.floatingBlock.innerHTML = `
|
|
115
117
|
<div class="tiny-remoter-floating-block__icon">
|
|
116
|
-
<img style="display: block; width: 56px;" src="
|
|
118
|
+
<img style="display: block; width: 56px;" src="${DEFAULT_QR_CODE_URL}/svgs/logo-next-no-bg-left.svg" alt="icon" />
|
|
117
119
|
</div>
|
|
118
120
|
`;
|
|
119
121
|
document.body.appendChild(this.floatingBlock);
|
|
@@ -224,7 +226,7 @@ class FloatingBlock {
|
|
|
224
226
|
this.copyToClipboard(this.options.sessionId.slice(-6));
|
|
225
227
|
}
|
|
226
228
|
copyRemoteURL() {
|
|
227
|
-
this.copyToClipboard(
|
|
229
|
+
this.copyToClipboard(this.options.remoteUrl + this.sessionPrefix + this.options.sessionId);
|
|
228
230
|
}
|
|
229
231
|
// 实现复制到剪贴板功能
|
|
230
232
|
copyToClipboard(text) {
|
package/dist/webagent.dev.js
CHANGED
|
@@ -24644,7 +24644,6 @@ ${user}:`]
|
|
|
24644
24644
|
this.mcpClients = [];
|
|
24645
24645
|
this.mcpTools = [];
|
|
24646
24646
|
this.ignoreToolnames = [];
|
|
24647
|
-
this.autoUpdateTools = true;
|
|
24648
24647
|
this.messages = [];
|
|
24649
24648
|
this.mcpServers = mcpServers || [];
|
|
24650
24649
|
if (llm) {
|
|
@@ -24673,7 +24672,9 @@ ${user}:`]
|
|
|
24673
24672
|
} else {
|
|
24674
24673
|
transport = serverConfig;
|
|
24675
24674
|
}
|
|
24676
|
-
|
|
24675
|
+
const client = await createMCPClient({ transport });
|
|
24676
|
+
client["__transport__"] = transport;
|
|
24677
|
+
return client;
|
|
24677
24678
|
} catch (error) {
|
|
24678
24679
|
if (this.onError) {
|
|
24679
24680
|
this.onError((error == null ? void 0 : error.message) || `Failed to create MCP client`, error);
|
|
@@ -24682,6 +24683,13 @@ ${user}:`]
|
|
|
24682
24683
|
return null;
|
|
24683
24684
|
}
|
|
24684
24685
|
}
|
|
24686
|
+
/** 关闭一个client */
|
|
24687
|
+
async _closeOneClient(client) {
|
|
24688
|
+
var _a16, _b8, _c, _d, _e;
|
|
24689
|
+
await ((_b8 = (_a16 = client["__transport__"]) == null ? void 0 : _a16.terminateSession) == null ? void 0 : _b8.call(_a16));
|
|
24690
|
+
await ((_d = (_c = client["__transport__"]) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c));
|
|
24691
|
+
await ((_e = client == null ? void 0 : client.close) == null ? void 0 : _e.call(client));
|
|
24692
|
+
}
|
|
24685
24693
|
/** 创建 ai-sdk的 mcpClient, 失败则保存为null */
|
|
24686
24694
|
async _createMpcClients() {
|
|
24687
24695
|
this.mcpClients = await Promise.all(
|
|
@@ -24712,7 +24720,7 @@ ${user}:`]
|
|
|
24712
24720
|
await Promise.all(
|
|
24713
24721
|
this.mcpClients.map(async (client) => {
|
|
24714
24722
|
try {
|
|
24715
|
-
await
|
|
24723
|
+
await this._closeOneClient(client);
|
|
24716
24724
|
} catch (error) {
|
|
24717
24725
|
if (this.onError) {
|
|
24718
24726
|
this.onError((error == null ? void 0 : error.message) || `Failed to close client`, error);
|
|
@@ -24744,13 +24752,13 @@ ${user}:`]
|
|
|
24744
24752
|
return false;
|
|
24745
24753
|
}
|
|
24746
24754
|
/** 通过引用,删除一个 mcpServers mcpClients mcpTools ignoreToolnames */
|
|
24747
|
-
removeMcpServer(mcpServer) {
|
|
24755
|
+
async removeMcpServer(mcpServer) {
|
|
24748
24756
|
const index = this.mcpServers.findIndex((server) => server === mcpServer);
|
|
24749
24757
|
this.mcpServers.splice(index, 1);
|
|
24750
24758
|
const delClient = this.mcpClients[index];
|
|
24751
24759
|
this.mcpClients.splice(index, 1);
|
|
24752
24760
|
try {
|
|
24753
|
-
|
|
24761
|
+
await this._closeOneClient(delClient);
|
|
24754
24762
|
} catch (error) {
|
|
24755
24763
|
}
|
|
24756
24764
|
const delTool = this.mcpTools[index];
|
|
@@ -24762,7 +24770,7 @@ ${user}:`]
|
|
|
24762
24770
|
}
|
|
24763
24771
|
}
|
|
24764
24772
|
/** 创建临时允许调用的tools集合 */
|
|
24765
|
-
|
|
24773
|
+
_tempMergeTools(extraTool = {}) {
|
|
24766
24774
|
const toolsResult = this.mcpTools.reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
24767
24775
|
Object.assign(toolsResult, extraTool);
|
|
24768
24776
|
this.ignoreToolnames.forEach((name16) => {
|
|
@@ -24775,16 +24783,14 @@ ${user}:`]
|
|
|
24775
24783
|
if (!this.llm) {
|
|
24776
24784
|
throw new Error("LLM is not initialized");
|
|
24777
24785
|
}
|
|
24778
|
-
|
|
24779
|
-
|
|
24780
|
-
(_a16 = this.onUpdatedTools) == null ? void 0 : _a16.call(this);
|
|
24781
|
-
}
|
|
24786
|
+
await this.initClientsAndTools();
|
|
24787
|
+
(_a16 = this.onUpdatedTools) == null ? void 0 : _a16.call(this);
|
|
24782
24788
|
const chatOptions = {
|
|
24783
24789
|
// @ts-ignore ProviderV2 是所有llm的父类, 在每一个具体的llm 类都有一个选择model的函数用法
|
|
24784
24790
|
model: this.llm(model),
|
|
24785
24791
|
stopWhen: stepCountIs(maxSteps),
|
|
24786
24792
|
...options,
|
|
24787
|
-
tools: this.
|
|
24793
|
+
tools: this._tempMergeTools(options.tools)
|
|
24788
24794
|
};
|
|
24789
24795
|
if (options.message && !options.messages) {
|
|
24790
24796
|
this.messages.push({ role: "user", content: options.message });
|
|
@@ -26785,6 +26791,8 @@ ${user}:`]
|
|
|
26785
26791
|
img.src = await this.toDataURL();
|
|
26786
26792
|
}
|
|
26787
26793
|
}
|
|
26794
|
+
const DEFAULT_REMOTE_URL = "https://agent.opentiny.design/tiny-robot";
|
|
26795
|
+
const DEFAULT_QR_CODE_URL = "https://ai.opentiny.design/next-remoter";
|
|
26788
26796
|
const getDefaultMenuItems = (options) => {
|
|
26789
26797
|
return [
|
|
26790
26798
|
{
|
|
@@ -26833,8 +26841,8 @@ ${user}:`]
|
|
|
26833
26841
|
{
|
|
26834
26842
|
action: "remote-url",
|
|
26835
26843
|
show: true,
|
|
26836
|
-
text: `${options.
|
|
26837
|
-
tip: options.
|
|
26844
|
+
text: `${options.remoteUrl}`,
|
|
26845
|
+
tip: options.remoteUrl,
|
|
26838
26846
|
showCopyIcon: true,
|
|
26839
26847
|
icon: `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
26840
26848
|
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
@@ -26850,8 +26858,9 @@ ${user}:`]
|
|
|
26850
26858
|
throw new Error("sessionId is required");
|
|
26851
26859
|
}
|
|
26852
26860
|
this.options = {
|
|
26853
|
-
|
|
26854
|
-
|
|
26861
|
+
...options,
|
|
26862
|
+
qrCodeUrl: options.qrCodeUrl || DEFAULT_QR_CODE_URL,
|
|
26863
|
+
remoteUrl: options.remoteUrl || DEFAULT_REMOTE_URL
|
|
26855
26864
|
};
|
|
26856
26865
|
this.menuItems = this.mergeMenuItems(options.menuItems);
|
|
26857
26866
|
this.init();
|
|
@@ -26895,7 +26904,7 @@ ${user}:`]
|
|
|
26895
26904
|
this.floatingBlock.className = "tiny-remoter-floating-block";
|
|
26896
26905
|
this.floatingBlock.innerHTML = `
|
|
26897
26906
|
<div class="tiny-remoter-floating-block__icon">
|
|
26898
|
-
<img style="display: block; width: 56px;" src="
|
|
26907
|
+
<img style="display: block; width: 56px;" src="${DEFAULT_QR_CODE_URL}/svgs/logo-next-no-bg-left.svg" alt="icon" />
|
|
26899
26908
|
</div>
|
|
26900
26909
|
`;
|
|
26901
26910
|
document.body.appendChild(this.floatingBlock);
|
|
@@ -26995,7 +27004,7 @@ ${user}:`]
|
|
|
26995
27004
|
this.copyToClipboard(this.options.sessionId.slice(-6));
|
|
26996
27005
|
}
|
|
26997
27006
|
copyRemoteURL() {
|
|
26998
|
-
this.copyToClipboard(
|
|
27007
|
+
this.copyToClipboard(this.options.remoteUrl + this.sessionPrefix + this.options.sessionId);
|
|
26999
27008
|
}
|
|
27000
27009
|
// 实现复制到剪贴板功能
|
|
27001
27010
|
async copyToClipboard(text2) {
|
package/dist/webagent.es.dev.js
CHANGED
|
@@ -24250,7 +24250,6 @@ class AgentModelProvider {
|
|
|
24250
24250
|
this.mcpClients = [];
|
|
24251
24251
|
this.mcpTools = [];
|
|
24252
24252
|
this.ignoreToolnames = [];
|
|
24253
|
-
this.autoUpdateTools = true;
|
|
24254
24253
|
this.messages = [];
|
|
24255
24254
|
this.mcpServers = mcpServers || [];
|
|
24256
24255
|
if (llm) {
|
|
@@ -24279,7 +24278,9 @@ class AgentModelProvider {
|
|
|
24279
24278
|
} else {
|
|
24280
24279
|
transport = serverConfig;
|
|
24281
24280
|
}
|
|
24282
|
-
|
|
24281
|
+
const client = await createMCPClient({ transport });
|
|
24282
|
+
client["__transport__"] = transport;
|
|
24283
|
+
return client;
|
|
24283
24284
|
} catch (error) {
|
|
24284
24285
|
if (this.onError) {
|
|
24285
24286
|
this.onError((error == null ? void 0 : error.message) || `Failed to create MCP client`, error);
|
|
@@ -24288,6 +24289,13 @@ class AgentModelProvider {
|
|
|
24288
24289
|
return null;
|
|
24289
24290
|
}
|
|
24290
24291
|
}
|
|
24292
|
+
/** 关闭一个client */
|
|
24293
|
+
async _closeOneClient(client) {
|
|
24294
|
+
var _a16, _b8, _c, _d, _e;
|
|
24295
|
+
await ((_b8 = (_a16 = client["__transport__"]) == null ? void 0 : _a16.terminateSession) == null ? void 0 : _b8.call(_a16));
|
|
24296
|
+
await ((_d = (_c = client["__transport__"]) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c));
|
|
24297
|
+
await ((_e = client == null ? void 0 : client.close) == null ? void 0 : _e.call(client));
|
|
24298
|
+
}
|
|
24291
24299
|
/** 创建 ai-sdk的 mcpClient, 失败则保存为null */
|
|
24292
24300
|
async _createMpcClients() {
|
|
24293
24301
|
this.mcpClients = await Promise.all(
|
|
@@ -24318,7 +24326,7 @@ class AgentModelProvider {
|
|
|
24318
24326
|
await Promise.all(
|
|
24319
24327
|
this.mcpClients.map(async (client) => {
|
|
24320
24328
|
try {
|
|
24321
|
-
await
|
|
24329
|
+
await this._closeOneClient(client);
|
|
24322
24330
|
} catch (error) {
|
|
24323
24331
|
if (this.onError) {
|
|
24324
24332
|
this.onError((error == null ? void 0 : error.message) || `Failed to close client`, error);
|
|
@@ -24350,13 +24358,13 @@ class AgentModelProvider {
|
|
|
24350
24358
|
return false;
|
|
24351
24359
|
}
|
|
24352
24360
|
/** 通过引用,删除一个 mcpServers mcpClients mcpTools ignoreToolnames */
|
|
24353
|
-
removeMcpServer(mcpServer) {
|
|
24361
|
+
async removeMcpServer(mcpServer) {
|
|
24354
24362
|
const index = this.mcpServers.findIndex((server) => server === mcpServer);
|
|
24355
24363
|
this.mcpServers.splice(index, 1);
|
|
24356
24364
|
const delClient = this.mcpClients[index];
|
|
24357
24365
|
this.mcpClients.splice(index, 1);
|
|
24358
24366
|
try {
|
|
24359
|
-
|
|
24367
|
+
await this._closeOneClient(delClient);
|
|
24360
24368
|
} catch (error) {
|
|
24361
24369
|
}
|
|
24362
24370
|
const delTool = this.mcpTools[index];
|
|
@@ -24368,7 +24376,7 @@ class AgentModelProvider {
|
|
|
24368
24376
|
}
|
|
24369
24377
|
}
|
|
24370
24378
|
/** 创建临时允许调用的tools集合 */
|
|
24371
|
-
|
|
24379
|
+
_tempMergeTools(extraTool = {}) {
|
|
24372
24380
|
const toolsResult = this.mcpTools.reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
24373
24381
|
Object.assign(toolsResult, extraTool);
|
|
24374
24382
|
this.ignoreToolnames.forEach((name16) => {
|
|
@@ -24381,16 +24389,14 @@ class AgentModelProvider {
|
|
|
24381
24389
|
if (!this.llm) {
|
|
24382
24390
|
throw new Error("LLM is not initialized");
|
|
24383
24391
|
}
|
|
24384
|
-
|
|
24385
|
-
|
|
24386
|
-
(_a16 = this.onUpdatedTools) == null ? void 0 : _a16.call(this);
|
|
24387
|
-
}
|
|
24392
|
+
await this.initClientsAndTools();
|
|
24393
|
+
(_a16 = this.onUpdatedTools) == null ? void 0 : _a16.call(this);
|
|
24388
24394
|
const chatOptions = {
|
|
24389
24395
|
// @ts-ignore ProviderV2 是所有llm的父类, 在每一个具体的llm 类都有一个选择model的函数用法
|
|
24390
24396
|
model: this.llm(model),
|
|
24391
24397
|
stopWhen: stepCountIs(maxSteps),
|
|
24392
24398
|
...options,
|
|
24393
|
-
tools: this.
|
|
24399
|
+
tools: this._tempMergeTools(options.tools)
|
|
24394
24400
|
};
|
|
24395
24401
|
if (options.message && !options.messages) {
|
|
24396
24402
|
this.messages.push({ role: "user", content: options.message });
|
|
@@ -26391,6 +26397,8 @@ class QrCode {
|
|
|
26391
26397
|
img.src = await this.toDataURL();
|
|
26392
26398
|
}
|
|
26393
26399
|
}
|
|
26400
|
+
const DEFAULT_REMOTE_URL = "https://agent.opentiny.design/tiny-robot";
|
|
26401
|
+
const DEFAULT_QR_CODE_URL = "https://ai.opentiny.design/next-remoter";
|
|
26394
26402
|
const getDefaultMenuItems = (options) => {
|
|
26395
26403
|
return [
|
|
26396
26404
|
{
|
|
@@ -26439,8 +26447,8 @@ const getDefaultMenuItems = (options) => {
|
|
|
26439
26447
|
{
|
|
26440
26448
|
action: "remote-url",
|
|
26441
26449
|
show: true,
|
|
26442
|
-
text: `${options.
|
|
26443
|
-
tip: options.
|
|
26450
|
+
text: `${options.remoteUrl}`,
|
|
26451
|
+
tip: options.remoteUrl,
|
|
26444
26452
|
showCopyIcon: true,
|
|
26445
26453
|
icon: `<svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
26446
26454
|
<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
|
|
@@ -26456,8 +26464,9 @@ class FloatingBlock {
|
|
|
26456
26464
|
throw new Error("sessionId is required");
|
|
26457
26465
|
}
|
|
26458
26466
|
this.options = {
|
|
26459
|
-
|
|
26460
|
-
|
|
26467
|
+
...options,
|
|
26468
|
+
qrCodeUrl: options.qrCodeUrl || DEFAULT_QR_CODE_URL,
|
|
26469
|
+
remoteUrl: options.remoteUrl || DEFAULT_REMOTE_URL
|
|
26461
26470
|
};
|
|
26462
26471
|
this.menuItems = this.mergeMenuItems(options.menuItems);
|
|
26463
26472
|
this.init();
|
|
@@ -26501,7 +26510,7 @@ class FloatingBlock {
|
|
|
26501
26510
|
this.floatingBlock.className = "tiny-remoter-floating-block";
|
|
26502
26511
|
this.floatingBlock.innerHTML = `
|
|
26503
26512
|
<div class="tiny-remoter-floating-block__icon">
|
|
26504
|
-
<img style="display: block; width: 56px;" src="
|
|
26513
|
+
<img style="display: block; width: 56px;" src="${DEFAULT_QR_CODE_URL}/svgs/logo-next-no-bg-left.svg" alt="icon" />
|
|
26505
26514
|
</div>
|
|
26506
26515
|
`;
|
|
26507
26516
|
document.body.appendChild(this.floatingBlock);
|
|
@@ -26601,7 +26610,7 @@ class FloatingBlock {
|
|
|
26601
26610
|
this.copyToClipboard(this.options.sessionId.slice(-6));
|
|
26602
26611
|
}
|
|
26603
26612
|
copyRemoteURL() {
|
|
26604
|
-
this.copyToClipboard(
|
|
26613
|
+
this.copyToClipboard(this.options.remoteUrl + this.sessionPrefix + this.options.sessionId);
|
|
26605
26614
|
}
|
|
26606
26615
|
// 实现复制到剪贴板功能
|
|
26607
26616
|
async copyToClipboard(text2) {
|