ai 3.4.24 → 3.4.26
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 +12 -0
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +42 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -3593,8 +3593,6 @@ function runToolsTransformation({
|
|
3593
3593
|
telemetry,
|
3594
3594
|
abortSignal
|
3595
3595
|
}) {
|
3596
|
-
let canClose = false;
|
3597
|
-
const outstandingToolCalls = /* @__PURE__ */ new Set();
|
3598
3596
|
let toolResultsStreamController = null;
|
3599
3597
|
const toolResultsStream = new ReadableStream({
|
3600
3598
|
start(controller) {
|
@@ -3602,6 +3600,17 @@ function runToolsTransformation({
|
|
3602
3600
|
}
|
3603
3601
|
});
|
3604
3602
|
const activeToolCalls = {};
|
3603
|
+
const outstandingToolResults = /* @__PURE__ */ new Set();
|
3604
|
+
let canClose = false;
|
3605
|
+
let finishChunk = void 0;
|
3606
|
+
function attemptClose() {
|
3607
|
+
if (canClose && outstandingToolResults.size === 0) {
|
3608
|
+
if (finishChunk != null) {
|
3609
|
+
toolResultsStreamController.enqueue(finishChunk);
|
3610
|
+
}
|
3611
|
+
toolResultsStreamController.close();
|
3612
|
+
}
|
3613
|
+
}
|
3605
3614
|
const forwardStream = new TransformStream({
|
3606
3615
|
transform(chunk, controller) {
|
3607
3616
|
const chunkType = chunk.type;
|
@@ -3659,7 +3668,7 @@ function runToolsTransformation({
|
|
3659
3668
|
controller.enqueue(toolCall);
|
3660
3669
|
if (tool2.execute != null) {
|
3661
3670
|
const toolExecutionId = generateId();
|
3662
|
-
|
3671
|
+
outstandingToolResults.add(toolExecutionId);
|
3663
3672
|
recordSpan({
|
3664
3673
|
name: "ai.toolCall",
|
3665
3674
|
attributes: selectTelemetryAttributes({
|
@@ -3684,10 +3693,8 @@ function runToolsTransformation({
|
|
3684
3693
|
type: "tool-result",
|
3685
3694
|
result
|
3686
3695
|
});
|
3687
|
-
|
3688
|
-
|
3689
|
-
toolResultsStreamController.close();
|
3690
|
-
}
|
3696
|
+
outstandingToolResults.delete(toolExecutionId);
|
3697
|
+
attemptClose();
|
3691
3698
|
try {
|
3692
3699
|
span.setAttributes(
|
3693
3700
|
selectTelemetryAttributes({
|
@@ -3707,10 +3714,8 @@ function runToolsTransformation({
|
|
3707
3714
|
type: "error",
|
3708
3715
|
error
|
3709
3716
|
});
|
3710
|
-
|
3711
|
-
|
3712
|
-
toolResultsStreamController.close();
|
3713
|
-
}
|
3717
|
+
outstandingToolResults.delete(toolExecutionId);
|
3718
|
+
attemptClose();
|
3714
3719
|
}
|
3715
3720
|
)
|
3716
3721
|
});
|
@@ -3724,13 +3729,13 @@ function runToolsTransformation({
|
|
3724
3729
|
break;
|
3725
3730
|
}
|
3726
3731
|
case "finish": {
|
3727
|
-
|
3732
|
+
finishChunk = {
|
3728
3733
|
type: "finish",
|
3729
3734
|
finishReason: chunk.finishReason,
|
3730
3735
|
logprobs: chunk.logprobs,
|
3731
3736
|
usage: calculateLanguageModelUsage(chunk.usage),
|
3732
3737
|
experimental_providerMetadata: chunk.providerMetadata
|
3733
|
-
}
|
3738
|
+
};
|
3734
3739
|
break;
|
3735
3740
|
}
|
3736
3741
|
default: {
|
@@ -3741,9 +3746,7 @@ function runToolsTransformation({
|
|
3741
3746
|
},
|
3742
3747
|
flush() {
|
3743
3748
|
canClose = true;
|
3744
|
-
|
3745
|
-
toolResultsStreamController.close();
|
3746
|
-
}
|
3749
|
+
attemptClose();
|
3747
3750
|
}
|
3748
3751
|
});
|
3749
3752
|
return new ReadableStream({
|
@@ -4718,7 +4721,9 @@ function attachmentsToParts(attachments) {
|
|
4718
4721
|
}
|
4719
4722
|
|
4720
4723
|
// core/prompt/convert-to-core-messages.ts
|
4721
|
-
function convertToCoreMessages(messages) {
|
4724
|
+
function convertToCoreMessages(messages, options) {
|
4725
|
+
var _a11;
|
4726
|
+
const tools = (_a11 = options == null ? void 0 : options.tools) != null ? _a11 : {};
|
4722
4727
|
const coreMessages = [];
|
4723
4728
|
for (const message of messages) {
|
4724
4729
|
const { role, content, toolInvocations, experimental_attachments } = message;
|
@@ -4749,29 +4754,37 @@ function convertToCoreMessages(messages) {
|
|
4749
4754
|
role: "assistant",
|
4750
4755
|
content: [
|
4751
4756
|
{ type: "text", text: content },
|
4752
|
-
...toolInvocations.map(
|
4753
|
-
|
4754
|
-
|
4755
|
-
|
4756
|
-
|
4757
|
-
|
4757
|
+
...toolInvocations.map(
|
4758
|
+
({ toolCallId, toolName, args }) => ({
|
4759
|
+
type: "tool-call",
|
4760
|
+
toolCallId,
|
4761
|
+
toolName,
|
4762
|
+
args
|
4763
|
+
})
|
4764
|
+
)
|
4758
4765
|
]
|
4759
4766
|
});
|
4760
4767
|
coreMessages.push({
|
4761
4768
|
role: "tool",
|
4762
|
-
content: toolInvocations.map((
|
4763
|
-
if (!("result" in
|
4769
|
+
content: toolInvocations.map((toolInvocation) => {
|
4770
|
+
if (!("result" in toolInvocation)) {
|
4764
4771
|
throw new MessageConversionError({
|
4765
4772
|
originalMessage: message,
|
4766
|
-
message: "ToolInvocation must have a result: " + JSON.stringify(
|
4773
|
+
message: "ToolInvocation must have a result: " + JSON.stringify(toolInvocation)
|
4767
4774
|
});
|
4768
4775
|
}
|
4769
|
-
const { toolCallId, toolName,
|
4770
|
-
|
4776
|
+
const { toolCallId, toolName, result } = toolInvocation;
|
4777
|
+
const tool2 = tools[toolName];
|
4778
|
+
return (tool2 == null ? void 0 : tool2.experimental_toToolResultContent) != null ? {
|
4779
|
+
type: "tool-result",
|
4780
|
+
toolCallId,
|
4781
|
+
toolName,
|
4782
|
+
result: tool2.experimental_toToolResultContent(result),
|
4783
|
+
experimental_content: tool2.experimental_toToolResultContent(result)
|
4784
|
+
} : {
|
4771
4785
|
type: "tool-result",
|
4772
4786
|
toolCallId,
|
4773
4787
|
toolName,
|
4774
|
-
args,
|
4775
4788
|
result
|
4776
4789
|
};
|
4777
4790
|
})
|