@opentiny/next-sdk 0.2.2 → 0.2.3
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 +635 -5
- package/agent/AgentModelProvider.ts +47 -17
- package/dist/agent/AgentModelProvider.d.ts +10 -2
- package/dist/index.es.dev.js +74 -32
- package/dist/index.es.js +5942 -5923
- package/dist/index.js +496 -477
- package/dist/index.umd.dev.js +74 -32
- package/dist/index.umd.js +37 -37
- package/dist/{mcpsdk@1.25.2.dev.js → mcpsdk@1.25.3.dev.js} +3 -1
- package/dist/{mcpsdk@1.25.2.es.dev.js → mcpsdk@1.25.3.es.dev.js} +3 -1
- package/dist/{mcpsdk@1.25.2.es.js → mcpsdk@1.25.3.es.js} +1855 -1855
- package/dist/{mcpsdk@1.25.2.js → mcpsdk@1.25.3.js} +13 -13
- package/dist/remoter/createRemoter.d.ts +6 -1
- package/dist/webagent.dev.js +74 -32
- package/dist/webagent.es.dev.js +74 -32
- package/dist/webagent.es.js +3067 -3048
- package/dist/webagent.js +38 -38
- package/dist/webmcp-full.dev.js +3 -1
- package/dist/webmcp-full.es.dev.js +3 -1
- package/dist/webmcp-full.es.js +523 -523
- package/dist/webmcp-full.js +9 -9
- package/package.json +17 -2
- package/remoter/createRemoter.ts +72 -37
package/dist/index.umd.dev.js
CHANGED
|
@@ -19175,7 +19175,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
19175
19175
|
}
|
|
19176
19176
|
return taskValidationResult.data;
|
|
19177
19177
|
}
|
|
19178
|
-
const
|
|
19178
|
+
const hasTools = params.tools || params.toolChoice;
|
|
19179
|
+
const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema;
|
|
19180
|
+
const validationResult = safeParse(resultSchema, result);
|
|
19179
19181
|
if (!validationResult.success) {
|
|
19180
19182
|
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
19181
19183
|
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`);
|
|
@@ -26973,6 +26975,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
26973
26975
|
const iconCopy = "data:image/svg+xml,%3csvg%20viewBox='0%200%2012%2012'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='12.000000'%20height='12.000000'%20fill='none'%3e%3cdefs%3e%3cfilter%20id='pixso_custom_mask_type_luminance'%3e%3cfeColorMatrix%20type='matrix'%20values='1%200%200%200%200%200%201%200%200%200%200%200%201%200%200%200%200%200%201%200%20'%20/%3e%3c/filter%3e%3c/defs%3e%3cmask%20id='mask_0'%20width='11.999876'%20height='11.999876'%20x='0.000000'%20y='0.000000'%20maskUnits='userSpaceOnUse'%3e%3cg%20filter='url(%23pixso_custom_mask_type_luminance)'%3e%3cg%20id='mask401_19830'%3e%3cpath%20id='蒙版'%20d='M0%200L11.9999%200L11.9999%2011.9999L0%2011.9999L0%200ZM2.69992%201.34999L8.09977%201.34999C9.5082%201.34999%2010.6498%202.49167%2010.6498%203.89998L10.6498%209.2999C10.6498%2010.7082%209.5082%2011.8499%208.09977%2011.8499L2.69992%2011.8499C1.29149%2011.8499%200.149901%2010.7082%200.149901%209.2999L0.149901%203.89998C0.149901%202.49167%201.29149%201.34999%202.69992%201.34999Z'%20fill='rgb(196,196,196)'%20fill-rule='evenodd'%20/%3e%3c/g%3e%3c/g%3e%3c/mask%3e%3crect%20id='ic_public_copy'%20width='12.000000'%20height='12.000000'%20x='0.000000'%20y='0.000000'%20/%3e%3crect%20id='ic_public_copy-复制/base/ic_public_copy'%20width='11.999876'%20height='11.999876'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='path1'%20d='M0.000134537%205.99497C0.000134537%205.05748%20-0.00236544%204.11999%200.000134537%203.1825C-0.00236544%202.72751%200.055134%202.27501%200.165133%201.83752C0.41263%200.907526%201.01762%200.355032%201.94761%200.140034C2.41261%200.040035%202.8901%20-0.00746449%203.3651%203.54269e-05C5.16258%203.54269e-05%206.96006%203.54269e-05%208.76004%203.54269e-05C9.21254%20-0.00246455%209.66503%200.0475349%2010.1075%200.155034C11.065%200.387531%2011.64%200.995025%2011.8575%201.95002C11.9575%202.40001%2012.005%202.86001%2011.9975%203.3225C11.9975%205.13998%2011.9975%206.95746%2011.9975%208.77244C12%209.22244%2011.95%209.67243%2011.845%2010.1099C11.61%2011.0674%2011%2011.6374%2010.0475%2011.8574C9.58003%2011.9574%209.10504%2012.0049%208.62754%2011.9974C6.83756%2011.9974%205.04758%2011.9974%203.2576%2011.9974C2.80011%2012.0024%202.34511%2011.9499%201.90011%2011.8449C0.937625%2011.6124%200.360131%2011.0024%200.142633%2010.0424C0.0301342%209.55494%200.000134537%209.06744%200.000134537%208.57495C0.000134537%207.71495%200.000134537%206.85496%200.000134537%205.99497Z'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20fill-rule='evenodd'%20/%3e%3ccircle%20id='path2'%20cx='5.99993801'%20cy='5.99993801'%20r='5.99993801'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cg%20id='mask'%20mask='url(%23mask_0)'%3e%3cg%20id='组合%208'%3e%3cpath%20id='path'%20d='M11.1%203.89993L11.1%206.8999C11.1%208.55488%209.75502%209.89737%208.10004%209.89737L5.10007%209.89737C3.44258%209.89737%202.1001%208.55488%202.1001%206.8999L2.1001%203.89993C2.1001%202.24245%203.44258%200.897461%205.10007%200.897461L8.10004%200.897461C9.75502%200.897461%2011.1%202.24245%2011.1%203.89993Z'%20fill-rule='nonzero'%20stroke='rgb(25,25,25)'%20stroke-linejoin='round'%20stroke-width='0.749992251'%20/%3e%3c/g%3e%3c/g%3e%3cpath%20id='path4'%20d='M2.10008%202.39746L8.10002%202.39746C8.92751%202.39746%209.6%203.06995%209.6%203.89995L9.6%209.89738C9.6%2010.7274%208.92751%2011.3999%208.10002%2011.3999L2.10008%2011.3999C1.27009%2011.3999%200.600098%2010.7274%200.600098%209.89738L0.600098%203.89995C0.600098%203.06995%201.27009%202.39746%202.10008%202.39746Z'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20fill-rule='evenodd'%20/%3e%3cpath%20id='path4'%20d='M9.6%203.89995L9.6%209.89738C9.6%2010.7274%208.92751%2011.3999%208.10002%2011.3999L2.10008%2011.3999C1.27009%2011.3999%200.600098%2010.7274%200.600098%209.89738L0.600098%203.89995C0.600098%203.06995%201.27009%202.39746%202.10008%202.39746L8.10002%202.39746C8.92751%202.39746%209.6%203.06995%209.6%203.89995Z'%20fill-rule='nonzero'%20stroke='rgb(25,25,25)'%20stroke-linejoin='round'%20stroke-width='0.749992251'%20/%3e%3c/svg%3e";
|
|
26974
26976
|
const DEFAULT_REMOTE_URL = "https://agent.opentiny.design/tiny-robot";
|
|
26975
26977
|
const DEFAULT_QR_CODE_URL = "https://ai.opentiny.design/next-remoter";
|
|
26978
|
+
const DEFAULT_LOGO_URL = "https://ai.opentiny.design/next-remoter/svgs/logo-next-no-bg-left.svg";
|
|
26976
26979
|
const getDefaultMenuItems = (options) => {
|
|
26977
26980
|
return [
|
|
26978
26981
|
{
|
|
@@ -27013,6 +27016,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
27013
27016
|
class FloatingBlock {
|
|
27014
27017
|
constructor(options) {
|
|
27015
27018
|
this.isExpanded = false;
|
|
27019
|
+
this.closingTimer = 0;
|
|
27016
27020
|
this.getImageUrl = (asset) => {
|
|
27017
27021
|
if (!asset) return;
|
|
27018
27022
|
const img = new Image();
|
|
@@ -27020,15 +27024,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
27020
27024
|
return img;
|
|
27021
27025
|
};
|
|
27022
27026
|
this.renderItem = () => {
|
|
27023
|
-
this.menuItems.filter((item) => item.show !== false).map(
|
|
27024
|
-
(item)
|
|
27025
|
-
|
|
27026
|
-
|
|
27027
|
-
|
|
27028
|
-
|
|
27029
|
-
|
|
27030
|
-
}
|
|
27031
|
-
);
|
|
27027
|
+
this.menuItems.filter((item) => item.show !== false).map((item) => {
|
|
27028
|
+
const wrapper = document.getElementById(`tiny-remoter-icon-item-${item.action}`);
|
|
27029
|
+
if (!wrapper) return;
|
|
27030
|
+
wrapper.innerHTML = "";
|
|
27031
|
+
const img = this.getImageUrl(item.icon);
|
|
27032
|
+
if (img) wrapper.appendChild(img);
|
|
27033
|
+
});
|
|
27032
27034
|
};
|
|
27033
27035
|
this.readyTips = (el) => {
|
|
27034
27036
|
const element = document.getElementById(el);
|
|
@@ -27047,9 +27049,14 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
27047
27049
|
this.options = {
|
|
27048
27050
|
...options,
|
|
27049
27051
|
qrCodeUrl: options.qrCodeUrl || DEFAULT_QR_CODE_URL,
|
|
27050
|
-
remoteUrl: options.remoteUrl || DEFAULT_REMOTE_URL
|
|
27052
|
+
remoteUrl: options.remoteUrl || DEFAULT_REMOTE_URL,
|
|
27053
|
+
logoUrl: options.logoUrl || DEFAULT_LOGO_URL
|
|
27051
27054
|
};
|
|
27052
|
-
|
|
27055
|
+
if (options.menuItems && options.menuItems.length === 0) {
|
|
27056
|
+
this.menuItems = [];
|
|
27057
|
+
} else {
|
|
27058
|
+
this.menuItems = this.mergeMenuItems(options.menuItems);
|
|
27059
|
+
}
|
|
27053
27060
|
this.init();
|
|
27054
27061
|
}
|
|
27055
27062
|
// 计算 sessionPrefix 属性
|
|
@@ -27090,7 +27097,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
27090
27097
|
this.floatingBlock.className = "tiny-remoter-floating-block";
|
|
27091
27098
|
this.floatingBlock.innerHTML = `
|
|
27092
27099
|
<div class="tiny-remoter-floating-block__icon">
|
|
27093
|
-
<img style="display: block; width: 56px;" src="${
|
|
27100
|
+
<img style="display: block; width: 56px;" src="${this.options.logoUrl}" alt="icon" />
|
|
27094
27101
|
</div>
|
|
27095
27102
|
`;
|
|
27096
27103
|
document.body.appendChild(this.floatingBlock);
|
|
@@ -27128,7 +27135,26 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
27128
27135
|
}
|
|
27129
27136
|
bindEvents() {
|
|
27130
27137
|
this.floatingBlock.addEventListener("click", () => {
|
|
27131
|
-
this.
|
|
27138
|
+
this.showAIChat();
|
|
27139
|
+
});
|
|
27140
|
+
this.floatingBlock.addEventListener("mouseenter", () => {
|
|
27141
|
+
this.openDropdown();
|
|
27142
|
+
if (this.closingTimer) {
|
|
27143
|
+
window.clearTimeout(this.closingTimer);
|
|
27144
|
+
this.closingTimer = 0;
|
|
27145
|
+
}
|
|
27146
|
+
});
|
|
27147
|
+
this.floatingBlock.addEventListener("mouseleave", () => {
|
|
27148
|
+
this.shouldCloseDropdown();
|
|
27149
|
+
});
|
|
27150
|
+
this.dropdownMenu.addEventListener("mouseenter", (e) => {
|
|
27151
|
+
if (this.closingTimer) {
|
|
27152
|
+
window.clearTimeout(this.closingTimer);
|
|
27153
|
+
this.closingTimer = 0;
|
|
27154
|
+
}
|
|
27155
|
+
});
|
|
27156
|
+
this.dropdownMenu.addEventListener("mouseleave", (e) => {
|
|
27157
|
+
this.shouldCloseDropdown();
|
|
27132
27158
|
});
|
|
27133
27159
|
this.dropdownMenu.addEventListener("click", (e) => {
|
|
27134
27160
|
const target = e.target;
|
|
@@ -27159,18 +27185,20 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
27159
27185
|
}
|
|
27160
27186
|
});
|
|
27161
27187
|
}
|
|
27162
|
-
toggleDropdown() {
|
|
27163
|
-
if (this.isExpanded) {
|
|
27164
|
-
this.closeDropdown();
|
|
27165
|
-
} else {
|
|
27166
|
-
this.openDropdown();
|
|
27167
|
-
}
|
|
27168
|
-
}
|
|
27169
27188
|
openDropdown() {
|
|
27189
|
+
if (!this.menuItems || this.menuItems && this.menuItems.length === 0) {
|
|
27190
|
+
return;
|
|
27191
|
+
}
|
|
27170
27192
|
this.isExpanded = true;
|
|
27171
27193
|
this.floatingBlock.classList.add("expanded");
|
|
27172
27194
|
this.dropdownMenu.classList.add("show");
|
|
27173
27195
|
}
|
|
27196
|
+
shouldCloseDropdown() {
|
|
27197
|
+
this.closingTimer = window.setTimeout(() => {
|
|
27198
|
+
this.closeDropdown();
|
|
27199
|
+
}, 300);
|
|
27200
|
+
}
|
|
27201
|
+
/** 真正的立即关闭 */
|
|
27174
27202
|
closeDropdown() {
|
|
27175
27203
|
this.isExpanded = false;
|
|
27176
27204
|
this.floatingBlock.classList.remove("expanded");
|
|
@@ -46538,7 +46566,7 @@ ${user}:`]
|
|
|
46538
46566
|
this.mcpClients = {};
|
|
46539
46567
|
this.mcpTools = {};
|
|
46540
46568
|
this.ignoreToolnames = [];
|
|
46541
|
-
this.
|
|
46569
|
+
this.responseMessages = [];
|
|
46542
46570
|
this.useReActMode = false;
|
|
46543
46571
|
if (!llmConfig) {
|
|
46544
46572
|
throw new Error("llmConfig is required to initialize AgentModelProvider");
|
|
@@ -46780,7 +46808,7 @@ ${toolsPrompt}`;
|
|
|
46780
46808
|
} else if (options.messages) {
|
|
46781
46809
|
currentMessages = [...options.messages];
|
|
46782
46810
|
} else {
|
|
46783
|
-
currentMessages = [...this.
|
|
46811
|
+
currentMessages = [...this.responseMessages];
|
|
46784
46812
|
}
|
|
46785
46813
|
const modelName = typeof model === "string" ? model : model?.modelId || "default-model";
|
|
46786
46814
|
const systemPrompt = this._generateReActSystemPrompt(allTools, modelName, options.system);
|
|
@@ -46827,7 +46855,7 @@ ${toolsPrompt}`;
|
|
|
46827
46855
|
};
|
|
46828
46856
|
}
|
|
46829
46857
|
/**
|
|
46830
|
-
*
|
|
46858
|
+
* 构建用于模型调用的消息列表
|
|
46831
46859
|
* 策略:保留所有文本消息,仅限制图片数量(类似 magentic-ui 的 maybe_remove_old_screenshots)
|
|
46832
46860
|
*
|
|
46833
46861
|
* @param systemMessage 系统提示词
|
|
@@ -46885,7 +46913,7 @@ ${toolsPrompt}`;
|
|
|
46885
46913
|
fullMessageHistory.push(assistantMsg);
|
|
46886
46914
|
const action = parseReActAction(assistantMessage, tools);
|
|
46887
46915
|
if (!action) {
|
|
46888
|
-
this.
|
|
46916
|
+
this.responseMessages = fullMessageHistory;
|
|
46889
46917
|
return {
|
|
46890
46918
|
text: assistantMessage,
|
|
46891
46919
|
response: { messages: fullMessageHistory }
|
|
@@ -46903,7 +46931,7 @@ ${resultString}
|
|
|
46903
46931
|
allUserMessages.push(observationMessage);
|
|
46904
46932
|
fullMessageHistory.push(observationMessage);
|
|
46905
46933
|
}
|
|
46906
|
-
this.
|
|
46934
|
+
this.responseMessages = fullMessageHistory;
|
|
46907
46935
|
const lastMessage = fullMessageHistory[fullMessageHistory.length - 2]?.content || "";
|
|
46908
46936
|
return {
|
|
46909
46937
|
text: lastMessage,
|
|
@@ -46963,14 +46991,14 @@ ${resultString}
|
|
|
46963
46991
|
if (!action) {
|
|
46964
46992
|
controller.enqueue({ type: "text-end" });
|
|
46965
46993
|
controller.close();
|
|
46966
|
-
self2.
|
|
46994
|
+
self2.responseMessages = fullMessageHistory;
|
|
46967
46995
|
streamCompleteResolver({ messages: fullMessageHistory });
|
|
46968
46996
|
return;
|
|
46969
46997
|
}
|
|
46970
46998
|
if (action.toolName === "computer" && action.arguments?.action === "terminate") {
|
|
46971
46999
|
controller.enqueue({ type: "text-end" });
|
|
46972
47000
|
controller.close();
|
|
46973
|
-
self2.
|
|
47001
|
+
self2.responseMessages = fullMessageHistory;
|
|
46974
47002
|
streamCompleteResolver({ messages: fullMessageHistory });
|
|
46975
47003
|
return;
|
|
46976
47004
|
}
|
|
@@ -47032,7 +47060,7 @@ ${observationText}
|
|
|
47032
47060
|
}
|
|
47033
47061
|
controller.enqueue({ type: "text-end" });
|
|
47034
47062
|
controller.close();
|
|
47035
|
-
self2.
|
|
47063
|
+
self2.responseMessages = fullMessageHistory;
|
|
47036
47064
|
streamCompleteResolver({ messages: fullMessageHistory });
|
|
47037
47065
|
} catch (error) {
|
|
47038
47066
|
controller.error(error);
|
|
@@ -47060,13 +47088,27 @@ ${observationText}
|
|
|
47060
47088
|
...options,
|
|
47061
47089
|
tools: this._tempMergeTools(options.tools)
|
|
47062
47090
|
};
|
|
47091
|
+
let lastUserMessage = null;
|
|
47063
47092
|
if (options.message && !options.messages) {
|
|
47064
|
-
|
|
47065
|
-
|
|
47093
|
+
lastUserMessage = { role: "user", content: options.message };
|
|
47094
|
+
this.responseMessages.push(lastUserMessage);
|
|
47095
|
+
chatOptions.messages = [...this.responseMessages];
|
|
47096
|
+
} else if (options.messages && options.messages.length > 0) {
|
|
47097
|
+
const lastMessage = options.messages[options.messages.length - 1];
|
|
47098
|
+
if (lastMessage.role === "user") {
|
|
47099
|
+
lastUserMessage = lastMessage;
|
|
47100
|
+
}
|
|
47066
47101
|
}
|
|
47067
47102
|
const result = chatMethod(chatOptions);
|
|
47068
47103
|
result?.response?.then((res) => {
|
|
47069
|
-
|
|
47104
|
+
const firstMessage = res.messages?.[0];
|
|
47105
|
+
if (lastUserMessage && firstMessage?.role !== "user") {
|
|
47106
|
+
this.responseMessages.push(lastUserMessage);
|
|
47107
|
+
}
|
|
47108
|
+
this.responseMessages.push(...res.messages);
|
|
47109
|
+
});
|
|
47110
|
+
result?.usage?.then((usage) => {
|
|
47111
|
+
this.onUsage?.(usage);
|
|
47070
47112
|
});
|
|
47071
47113
|
return result;
|
|
47072
47114
|
}
|