ai 6.0.232 → 6.0.233
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 +9 -0
- package/dist/index.js +100 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +100 -57
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/ui/process-ui-message-stream.ts +109 -61
- package/src/util/detect-media-type.ts +10 -1
|
@@ -104,13 +104,43 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
104
104
|
new TransformStream<UIMessageChunk, InferUIMessageChunk<UI_MESSAGE>>({
|
|
105
105
|
async transform(chunk, controller) {
|
|
106
106
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
107
|
+
function getCurrentStepParts() {
|
|
108
|
+
const parts = state.message.parts;
|
|
109
|
+
let currentStepStartIndex = parts.length - 1;
|
|
110
|
+
|
|
111
|
+
while (
|
|
112
|
+
currentStepStartIndex >= 0 &&
|
|
113
|
+
parts[currentStepStartIndex].type !== 'step-start'
|
|
114
|
+
) {
|
|
115
|
+
currentStepStartIndex--;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return parts.slice(currentStepStartIndex + 1);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getCurrentStepToolInvocations() {
|
|
122
|
+
return getCurrentStepParts().filter(isToolUIPart);
|
|
123
|
+
}
|
|
124
|
+
|
|
107
125
|
function getToolInvocation(toolCallId: string) {
|
|
108
|
-
const toolInvocations =
|
|
126
|
+
const toolInvocations = getCurrentStepToolInvocations();
|
|
109
127
|
|
|
110
|
-
|
|
128
|
+
let toolInvocation = toolInvocations.find(
|
|
111
129
|
invocation => invocation.toolCallId === toolCallId,
|
|
112
130
|
);
|
|
113
131
|
|
|
132
|
+
if (toolInvocation == null) {
|
|
133
|
+
const parts = state.message.parts;
|
|
134
|
+
|
|
135
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
136
|
+
const part = parts[i];
|
|
137
|
+
if (isToolUIPart(part) && part.toolCallId === toolCallId) {
|
|
138
|
+
toolInvocation = part;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
114
144
|
if (toolInvocation == null) {
|
|
115
145
|
throw new UIMessageStreamError({
|
|
116
146
|
chunkType: 'tool-invocation',
|
|
@@ -159,12 +189,15 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
159
189
|
providerMetadata?: ProviderMetadata;
|
|
160
190
|
}
|
|
161
191
|
),
|
|
192
|
+
existingPart?: ToolUIPart<InferUIMessageTools<UI_MESSAGE>>,
|
|
162
193
|
) {
|
|
163
|
-
const part =
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
part
|
|
167
|
-
|
|
194
|
+
const part =
|
|
195
|
+
existingPart ??
|
|
196
|
+
(getCurrentStepParts().find(
|
|
197
|
+
part =>
|
|
198
|
+
isStaticToolUIPart(part) &&
|
|
199
|
+
part.toolCallId === options.toolCallId,
|
|
200
|
+
) as ToolUIPart<InferUIMessageTools<UI_MESSAGE>> | undefined);
|
|
168
201
|
|
|
169
202
|
const anyOptions = options as any;
|
|
170
203
|
const anyPart = part as any;
|
|
@@ -266,12 +299,15 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
266
299
|
providerMetadata?: ProviderMetadata;
|
|
267
300
|
}
|
|
268
301
|
),
|
|
302
|
+
existingPart?: DynamicToolUIPart,
|
|
269
303
|
) {
|
|
270
|
-
const part =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
part
|
|
274
|
-
|
|
304
|
+
const part =
|
|
305
|
+
existingPart ??
|
|
306
|
+
(getCurrentStepParts().find(
|
|
307
|
+
part =>
|
|
308
|
+
part.type === 'dynamic-tool' &&
|
|
309
|
+
part.toolCallId === options.toolCallId,
|
|
310
|
+
) as DynamicToolUIPart | undefined);
|
|
275
311
|
|
|
276
312
|
const anyOptions = options as any;
|
|
277
313
|
const anyPart = part as any;
|
|
@@ -510,7 +546,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
510
546
|
|
|
511
547
|
case 'tool-input-start': {
|
|
512
548
|
const toolInvocations =
|
|
513
|
-
|
|
549
|
+
getCurrentStepParts().filter(isStaticToolUIPart);
|
|
514
550
|
|
|
515
551
|
// add the partial tool call to the map
|
|
516
552
|
state.partialToolCalls[chunk.toolCallId] = {
|
|
@@ -635,7 +671,7 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
635
671
|
// When a part already exists for this toolCallId (e.g. from
|
|
636
672
|
// tool-input-start), honour its type so we update in place
|
|
637
673
|
// instead of creating a duplicate with a mismatched type.
|
|
638
|
-
const existingPart =
|
|
674
|
+
const existingPart = getCurrentStepParts()
|
|
639
675
|
.filter(isToolUIPart)
|
|
640
676
|
.find(p => p.toolCallId === chunk.toolCallId);
|
|
641
677
|
const isDynamic =
|
|
@@ -696,31 +732,37 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
696
732
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
697
733
|
|
|
698
734
|
if (toolInvocation.type === 'dynamic-tool') {
|
|
699
|
-
updateDynamicToolPart(
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
735
|
+
updateDynamicToolPart(
|
|
736
|
+
{
|
|
737
|
+
toolCallId: chunk.toolCallId,
|
|
738
|
+
toolName: toolInvocation.toolName,
|
|
739
|
+
state: 'output-available',
|
|
740
|
+
input: (toolInvocation as any).input,
|
|
741
|
+
output: chunk.output,
|
|
742
|
+
preliminary: chunk.preliminary,
|
|
743
|
+
providerExecuted: chunk.providerExecuted,
|
|
744
|
+
providerMetadata: chunk.providerMetadata,
|
|
745
|
+
title: toolInvocation.title,
|
|
746
|
+
toolMetadata: toolInvocation.toolMetadata,
|
|
747
|
+
},
|
|
748
|
+
toolInvocation,
|
|
749
|
+
);
|
|
711
750
|
} else {
|
|
712
|
-
updateToolPart(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
751
|
+
updateToolPart(
|
|
752
|
+
{
|
|
753
|
+
toolCallId: chunk.toolCallId,
|
|
754
|
+
toolName: getStaticToolName(toolInvocation),
|
|
755
|
+
state: 'output-available',
|
|
756
|
+
input: (toolInvocation as any).input,
|
|
757
|
+
output: chunk.output,
|
|
758
|
+
providerExecuted: chunk.providerExecuted,
|
|
759
|
+
preliminary: chunk.preliminary,
|
|
760
|
+
providerMetadata: chunk.providerMetadata,
|
|
761
|
+
title: toolInvocation.title,
|
|
762
|
+
toolMetadata: toolInvocation.toolMetadata,
|
|
763
|
+
},
|
|
764
|
+
toolInvocation as ToolUIPart<InferUIMessageTools<UI_MESSAGE>>,
|
|
765
|
+
);
|
|
724
766
|
}
|
|
725
767
|
|
|
726
768
|
write();
|
|
@@ -731,30 +773,36 @@ export function processUIMessageStream<UI_MESSAGE extends UIMessage>({
|
|
|
731
773
|
const toolInvocation = getToolInvocation(chunk.toolCallId);
|
|
732
774
|
|
|
733
775
|
if (toolInvocation.type === 'dynamic-tool') {
|
|
734
|
-
updateDynamicToolPart(
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
776
|
+
updateDynamicToolPart(
|
|
777
|
+
{
|
|
778
|
+
toolCallId: chunk.toolCallId,
|
|
779
|
+
toolName: toolInvocation.toolName,
|
|
780
|
+
state: 'output-error',
|
|
781
|
+
input: (toolInvocation as any).input,
|
|
782
|
+
errorText: chunk.errorText,
|
|
783
|
+
providerExecuted: chunk.providerExecuted,
|
|
784
|
+
providerMetadata: chunk.providerMetadata,
|
|
785
|
+
title: toolInvocation.title,
|
|
786
|
+
toolMetadata: toolInvocation.toolMetadata,
|
|
787
|
+
},
|
|
788
|
+
toolInvocation,
|
|
789
|
+
);
|
|
745
790
|
} else {
|
|
746
|
-
updateToolPart(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
791
|
+
updateToolPart(
|
|
792
|
+
{
|
|
793
|
+
toolCallId: chunk.toolCallId,
|
|
794
|
+
toolName: getStaticToolName(toolInvocation),
|
|
795
|
+
state: 'output-error',
|
|
796
|
+
input: (toolInvocation as any).input,
|
|
797
|
+
rawInput: (toolInvocation as any).rawInput,
|
|
798
|
+
errorText: chunk.errorText,
|
|
799
|
+
providerExecuted: chunk.providerExecuted,
|
|
800
|
+
providerMetadata: chunk.providerMetadata,
|
|
801
|
+
title: toolInvocation.title,
|
|
802
|
+
toolMetadata: toolInvocation.toolMetadata,
|
|
803
|
+
},
|
|
804
|
+
toolInvocation as ToolUIPart<InferUIMessageTools<UI_MESSAGE>>,
|
|
805
|
+
);
|
|
758
806
|
}
|
|
759
807
|
|
|
760
808
|
write();
|
|
@@ -112,7 +112,16 @@ export const audioMediaTypeSignatures = [
|
|
|
112
112
|
},
|
|
113
113
|
{
|
|
114
114
|
mediaType: 'audio/mp4' as const,
|
|
115
|
-
bytesPrefix: [
|
|
115
|
+
bytesPrefix: [
|
|
116
|
+
0x00,
|
|
117
|
+
0x00,
|
|
118
|
+
0x00,
|
|
119
|
+
null,
|
|
120
|
+
0x66,
|
|
121
|
+
0x74,
|
|
122
|
+
0x79,
|
|
123
|
+
0x70, // ftyp
|
|
124
|
+
],
|
|
116
125
|
},
|
|
117
126
|
{
|
|
118
127
|
mediaType: 'audio/webm',
|