ai 5.0.0-beta.26 → 5.0.0-beta.27
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/CHANGELOG.md +10 -0
- package/dist/bin/ai.min.js +17 -17
- package/dist/index.d.mts +19 -9
- package/dist/index.d.ts +19 -9
- package/dist/index.js +59 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
@@ -8633,7 +8633,8 @@ var AbstractChat = class {
|
|
8633
8633
|
onError,
|
8634
8634
|
onToolCall,
|
8635
8635
|
onFinish,
|
8636
|
-
onData
|
8636
|
+
onData,
|
8637
|
+
sendAutomaticallyWhen
|
8637
8638
|
}) {
|
8638
8639
|
this.activeResponse = void 0;
|
8639
8640
|
this.jobExecutor = new SerialJobExecutor();
|
@@ -8731,35 +8732,33 @@ var AbstractChat = class {
|
|
8731
8732
|
tool: tool3,
|
8732
8733
|
toolCallId,
|
8733
8734
|
output
|
8734
|
-
}) => {
|
8735
|
-
|
8736
|
-
|
8737
|
-
|
8738
|
-
|
8739
|
-
|
8740
|
-
|
8741
|
-
|
8742
|
-
|
8743
|
-
});
|
8744
|
-
if (this.activeResponse) {
|
8745
|
-
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
8746
|
-
(part) => isToolUIPart(part) && part.toolCallId === toolCallId ? {
|
8747
|
-
...part,
|
8748
|
-
state: "output-available",
|
8749
|
-
output,
|
8750
|
-
errorText: void 0
|
8751
|
-
} : part
|
8752
|
-
);
|
8753
|
-
}
|
8735
|
+
}) => this.jobExecutor.run(async () => {
|
8736
|
+
var _a16, _b;
|
8737
|
+
const messages = this.state.messages;
|
8738
|
+
const lastMessage = messages[messages.length - 1];
|
8739
|
+
this.state.replaceMessage(messages.length - 1, {
|
8740
|
+
...lastMessage,
|
8741
|
+
parts: lastMessage.parts.map(
|
8742
|
+
(part) => isToolUIPart(part) && part.toolCallId === toolCallId ? { ...part, state: "output-available", output } : part
|
8743
|
+
)
|
8754
8744
|
});
|
8755
|
-
|
8756
|
-
|
8757
|
-
|
8758
|
-
|
8759
|
-
|
8760
|
-
|
8761
|
-
|
8762
|
-
|
8745
|
+
if (this.activeResponse) {
|
8746
|
+
this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(
|
8747
|
+
(part) => isToolUIPart(part) && part.toolCallId === toolCallId ? {
|
8748
|
+
...part,
|
8749
|
+
state: "output-available",
|
8750
|
+
output,
|
8751
|
+
errorText: void 0
|
8752
|
+
} : part
|
8753
|
+
);
|
8754
|
+
}
|
8755
|
+
if (this.status !== "streaming" && this.status !== "submitted" && ((_a16 = this.sendAutomaticallyWhen) == null ? void 0 : _a16.call(this, { messages }))) {
|
8756
|
+
await this.makeRequest({
|
8757
|
+
trigger: "submit-message",
|
8758
|
+
messageId: (_b = this.lastMessage) == null ? void 0 : _b.id
|
8759
|
+
});
|
8760
|
+
}
|
8761
|
+
});
|
8763
8762
|
/**
|
8764
8763
|
* Abort the current request immediately, keep the generated tokens if any.
|
8765
8764
|
*/
|
@@ -8781,6 +8780,7 @@ var AbstractChat = class {
|
|
8781
8780
|
this.onToolCall = onToolCall;
|
8782
8781
|
this.onFinish = onFinish;
|
8783
8782
|
this.onData = onData;
|
8783
|
+
this.sendAutomaticallyWhen = sendAutomaticallyWhen;
|
8784
8784
|
}
|
8785
8785
|
/**
|
8786
8786
|
* Hook status:
|
@@ -8821,7 +8821,7 @@ var AbstractChat = class {
|
|
8821
8821
|
body,
|
8822
8822
|
messageId
|
8823
8823
|
}) {
|
8824
|
-
var _a16;
|
8824
|
+
var _a16, _b, _c;
|
8825
8825
|
this.setStatus({ status: "submitted", error: void 0 });
|
8826
8826
|
const lastMessage = this.lastMessage;
|
8827
8827
|
try {
|
@@ -8908,21 +8908,17 @@ var AbstractChat = class {
|
|
8908
8908
|
} finally {
|
8909
8909
|
this.activeResponse = void 0;
|
8910
8910
|
}
|
8911
|
+
if ((_b = this.sendAutomaticallyWhen) == null ? void 0 : _b.call(this, { messages: this.state.messages })) {
|
8912
|
+
await this.makeRequest({
|
8913
|
+
trigger: "submit-message",
|
8914
|
+
messageId: (_c = this.lastMessage) == null ? void 0 : _c.id,
|
8915
|
+
metadata,
|
8916
|
+
headers,
|
8917
|
+
body
|
8918
|
+
});
|
8919
|
+
}
|
8911
8920
|
}
|
8912
8921
|
};
|
8913
|
-
function isAssistantMessageWithCompletedToolCalls(message) {
|
8914
|
-
if (!message) {
|
8915
|
-
return false;
|
8916
|
-
}
|
8917
|
-
if (message.role !== "assistant") {
|
8918
|
-
return false;
|
8919
|
-
}
|
8920
|
-
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
8921
|
-
return part.type === "step-start" ? index : lastIndex;
|
8922
|
-
}, -1);
|
8923
|
-
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
|
8924
|
-
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
|
8925
|
-
}
|
8926
8922
|
|
8927
8923
|
// src/ui/convert-to-model-messages.ts
|
8928
8924
|
function convertToModelMessages(messages, options) {
|
@@ -9095,6 +9091,24 @@ function convertToModelMessages(messages, options) {
|
|
9095
9091
|
}
|
9096
9092
|
var convertToCoreMessages = convertToModelMessages;
|
9097
9093
|
|
9094
|
+
// src/ui/last-assistant-message-is-complete-with-tool-calls.ts
|
9095
|
+
function lastAssistantMessageIsCompleteWithToolCalls({
|
9096
|
+
messages
|
9097
|
+
}) {
|
9098
|
+
const message = messages[messages.length - 1];
|
9099
|
+
if (!message) {
|
9100
|
+
return false;
|
9101
|
+
}
|
9102
|
+
if (message.role !== "assistant") {
|
9103
|
+
return false;
|
9104
|
+
}
|
9105
|
+
const lastStepStartIndex = message.parts.reduce((lastIndex, part, index) => {
|
9106
|
+
return part.type === "step-start" ? index : lastIndex;
|
9107
|
+
}, -1);
|
9108
|
+
const lastStepToolInvocations = message.parts.slice(lastStepStartIndex + 1).filter(isToolUIPart);
|
9109
|
+
return lastStepToolInvocations.length > 0 && lastStepToolInvocations.every((part) => part.state === "output-available");
|
9110
|
+
}
|
9111
|
+
|
9098
9112
|
// src/ui/transform-text-to-ui-message-stream.ts
|
9099
9113
|
function transformTextToUiMessageStream({
|
9100
9114
|
stream
|
@@ -9341,6 +9355,7 @@ export {
|
|
9341
9355
|
isDeepEqualData,
|
9342
9356
|
isToolUIPart,
|
9343
9357
|
jsonSchema2 as jsonSchema,
|
9358
|
+
lastAssistantMessageIsCompleteWithToolCalls,
|
9344
9359
|
modelMessageSchema,
|
9345
9360
|
parsePartialJson,
|
9346
9361
|
pipeTextStreamToResponse,
|