@opentiny/next-sdk 0.1.8 → 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.
@@ -74,7 +74,10 @@ export class AgentModelProvider {
74
74
  transport = serverConfig as MCPClientConfig['transport']
75
75
  }
76
76
 
77
- return await createMCPClient({ transport: transport as MCPClientConfig['transport'] })
77
+ const client = await createMCPClient({ transport: transport as MCPClientConfig['transport'] })
78
+ //@ts-ignore
79
+ client['__transport__'] = transport
80
+ return client
78
81
  } catch (error: unknown) {
79
82
  if (this.onError) {
80
83
  this.onError((error as Error)?.message || `Failed to create MCP client`, error)
@@ -83,6 +86,12 @@ export class AgentModelProvider {
83
86
  return null
84
87
  }
85
88
  }
89
+ /** 关闭一个client */
90
+ private async _closeOneClient(client: any) {
91
+ await client['__transport__']?.terminateSession?.()
92
+ await client['__transport__']?.close?.()
93
+ await client?.close?.()
94
+ }
86
95
  /** 创建 ai-sdk的 mcpClient, 失败则保存为null */
87
96
  private async _createMpcClients() {
88
97
  // 使用 Promise.all 并行处理所有 mcpServer 项
@@ -113,7 +122,7 @@ export class AgentModelProvider {
113
122
  await Promise.all(
114
123
  this.mcpClients.map(async (client) => {
115
124
  try {
116
- await client?.close()
125
+ await this._closeOneClient(client)
117
126
  } catch (error: unknown) {
118
127
  if (this.onError) {
119
128
  this.onError((error as Error)?.message || `Failed to close client`, error)
@@ -148,7 +157,7 @@ export class AgentModelProvider {
148
157
  return false
149
158
  }
150
159
  /** 通过引用,删除一个 mcpServers mcpClients mcpTools ignoreToolnames */
151
- removeMcpServer(mcpServer: McpServerConfig) {
160
+ async removeMcpServer(mcpServer: McpServerConfig) {
152
161
  const index = this.mcpServers.findIndex((server) => server === mcpServer)
153
162
 
154
163
  // 移除
@@ -158,7 +167,7 @@ export class AgentModelProvider {
158
167
  const delClient = this.mcpClients[index]
159
168
  this.mcpClients.splice(index, 1)
160
169
  try {
161
- delClient?.close()
170
+ await this._closeOneClient(delClient)
162
171
  } catch (error) {}
163
172
 
164
173
  // 移除 tools
@@ -32,6 +32,8 @@ export declare class AgentModelProvider {
32
32
  constructor({ llmConfig, mcpServers, llm }: IAgentModelProviderOption);
33
33
  /** 创建一个 ai-sdk的 mcpClient, 创建失败则返回 Null */
34
34
  private _createOneClient;
35
+ /** 关闭一个client */
36
+ private _closeOneClient;
35
37
  /** 创建 ai-sdk的 mcpClient, 失败则保存为null */
36
38
  private _createMpcClients;
37
39
  /** 创建所有 mcpClients 的 tools, 失败则保存为null */
@@ -42,7 +44,7 @@ export declare class AgentModelProvider {
42
44
  updateMcpServers(mcpServers: McpServerConfig[]): Promise<void>;
43
45
  insertMcpServer(mcpServer: McpServerConfig): Promise<boolean>;
44
46
  /** 通过引用,删除一个 mcpServers mcpClients mcpTools ignoreToolnames */
45
- removeMcpServer(mcpServer: McpServerConfig): void;
47
+ removeMcpServer(mcpServer: McpServerConfig): Promise<void>;
46
48
  /** 创建临时允许调用的tools集合 */
47
49
  private _tempMergeTools;
48
50
  private _chat;
@@ -79,7 +79,10 @@ export class AgentModelProvider {
79
79
  else {
80
80
  transport = serverConfig;
81
81
  }
82
- return yield createMCPClient({ transport: transport });
82
+ const client = yield createMCPClient({ transport: transport });
83
+ //@ts-ignore
84
+ client['__transport__'] = transport;
85
+ return client;
83
86
  }
84
87
  catch (error) {
85
88
  if (this.onError) {
@@ -90,6 +93,15 @@ export class AgentModelProvider {
90
93
  }
91
94
  });
92
95
  }
96
+ /** 关闭一个client */
97
+ _closeOneClient(client) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ var _a, _b, _c, _d, _e;
100
+ yield ((_b = (_a = client['__transport__']) === null || _a === void 0 ? void 0 : _a.terminateSession) === null || _b === void 0 ? void 0 : _b.call(_a));
101
+ yield ((_d = (_c = client['__transport__']) === null || _c === void 0 ? void 0 : _c.close) === null || _d === void 0 ? void 0 : _d.call(_c));
102
+ yield ((_e = client === null || client === void 0 ? void 0 : client.close) === null || _e === void 0 ? void 0 : _e.call(client));
103
+ });
104
+ }
93
105
  /** 创建 ai-sdk的 mcpClient, 失败则保存为null */
94
106
  _createMpcClients() {
95
107
  return __awaiter(this, void 0, void 0, function* () {
@@ -122,7 +134,7 @@ export class AgentModelProvider {
122
134
  return __awaiter(this, void 0, void 0, function* () {
123
135
  yield Promise.all(this.mcpClients.map((client) => __awaiter(this, void 0, void 0, function* () {
124
136
  try {
125
- yield (client === null || client === void 0 ? void 0 : client.close());
137
+ yield this._closeOneClient(client);
126
138
  }
127
139
  catch (error) {
128
140
  if (this.onError) {
@@ -162,25 +174,27 @@ export class AgentModelProvider {
162
174
  }
163
175
  /** 通过引用,删除一个 mcpServers mcpClients mcpTools ignoreToolnames */
164
176
  removeMcpServer(mcpServer) {
165
- const index = this.mcpServers.findIndex((server) => server === mcpServer);
166
- // 移除
167
- this.mcpServers.splice(index, 1);
168
- // 移除
169
- const delClient = this.mcpClients[index];
170
- this.mcpClients.splice(index, 1);
171
- try {
172
- delClient === null || delClient === void 0 ? void 0 : delClient.close();
173
- }
174
- catch (error) { }
175
- // 移除 tools
176
- const delTool = this.mcpTools[index];
177
- this.mcpTools.splice(index, 1);
178
- // 移除 ignoreToolnames
179
- if (delTool) {
180
- Object.keys(delTool).forEach((toolName) => {
181
- this.ignoreToolnames = this.ignoreToolnames.filter((name) => name !== toolName);
182
- });
183
- }
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ const index = this.mcpServers.findIndex((server) => server === mcpServer);
179
+ // 移除
180
+ this.mcpServers.splice(index, 1);
181
+ // 移除
182
+ const delClient = this.mcpClients[index];
183
+ this.mcpClients.splice(index, 1);
184
+ try {
185
+ yield this._closeOneClient(delClient);
186
+ }
187
+ catch (error) { }
188
+ // 移除 tools
189
+ const delTool = this.mcpTools[index];
190
+ this.mcpTools.splice(index, 1);
191
+ // 移除 ignoreToolnames
192
+ if (delTool) {
193
+ Object.keys(delTool).forEach((toolName) => {
194
+ this.ignoreToolnames = this.ignoreToolnames.filter((name) => name !== toolName);
195
+ });
196
+ }
197
+ });
184
198
  }
185
199
  /** 创建临时允许调用的tools集合 */
186
200
  _tempMergeTools(extraTool = {}) {
@@ -25098,7 +25098,7 @@ class FloatingBlock {
25098
25098
  this.copyToClipboard(this.options.sessionId.slice(-6));
25099
25099
  }
25100
25100
  copyRemoteURL() {
25101
- this.copyToClipboard((this.options.remoteUrl || DEFAULT_REMOTE_URL) + this.sessionPrefix + this.options.sessionId);
25101
+ this.copyToClipboard(this.options.remoteUrl + this.sessionPrefix + this.options.sessionId);
25102
25102
  }
25103
25103
  // 实现复制到剪贴板功能
25104
25104
  async copyToClipboard(text2) {
@@ -42841,7 +42841,9 @@ class AgentModelProvider {
42841
42841
  } else {
42842
42842
  transport = serverConfig;
42843
42843
  }
42844
- return await createMCPClient({ transport });
42844
+ const client = await createMCPClient({ transport });
42845
+ client["__transport__"] = transport;
42846
+ return client;
42845
42847
  } catch (error2) {
42846
42848
  if (this.onError) {
42847
42849
  this.onError((error2 == null ? void 0 : error2.message) || `Failed to create MCP client`, error2);
@@ -42850,6 +42852,13 @@ class AgentModelProvider {
42850
42852
  return null;
42851
42853
  }
42852
42854
  }
42855
+ /** 关闭一个client */
42856
+ async _closeOneClient(client) {
42857
+ var _a16, _b8, _c, _d, _e;
42858
+ await ((_b8 = (_a16 = client["__transport__"]) == null ? void 0 : _a16.terminateSession) == null ? void 0 : _b8.call(_a16));
42859
+ await ((_d = (_c = client["__transport__"]) == null ? void 0 : _c.close) == null ? void 0 : _d.call(_c));
42860
+ await ((_e = client == null ? void 0 : client.close) == null ? void 0 : _e.call(client));
42861
+ }
42853
42862
  /** 创建 ai-sdk的 mcpClient, 失败则保存为null */
42854
42863
  async _createMpcClients() {
42855
42864
  this.mcpClients = await Promise.all(
@@ -42880,7 +42889,7 @@ class AgentModelProvider {
42880
42889
  await Promise.all(
42881
42890
  this.mcpClients.map(async (client) => {
42882
42891
  try {
42883
- await (client == null ? void 0 : client.close());
42892
+ await this._closeOneClient(client);
42884
42893
  } catch (error2) {
42885
42894
  if (this.onError) {
42886
42895
  this.onError((error2 == null ? void 0 : error2.message) || `Failed to close client`, error2);
@@ -42912,13 +42921,13 @@ class AgentModelProvider {
42912
42921
  return false;
42913
42922
  }
42914
42923
  /** 通过引用,删除一个 mcpServers mcpClients mcpTools ignoreToolnames */
42915
- removeMcpServer(mcpServer) {
42924
+ async removeMcpServer(mcpServer) {
42916
42925
  const index = this.mcpServers.findIndex((server) => server === mcpServer);
42917
42926
  this.mcpServers.splice(index, 1);
42918
42927
  const delClient = this.mcpClients[index];
42919
42928
  this.mcpClients.splice(index, 1);
42920
42929
  try {
42921
- delClient == null ? void 0 : delClient.close();
42930
+ await this._closeOneClient(delClient);
42922
42931
  } catch (error2) {
42923
42932
  }
42924
42933
  const delTool = this.mcpTools[index];