ai 6.0.295 → 6.0.296
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 +8 -0
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +24 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -12
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/07-reference/01-ai-sdk-core/17-create-agent-ui-stream.mdx +3 -3
- package/docs/07-reference/01-ai-sdk-core/18-create-agent-ui-stream-response.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/18-pipe-agent-ui-stream-to-response.mdx +3 -3
- package/package.json +1 -1
- package/src/agent/create-agent-ui-stream-response.ts +2 -2
- package/src/agent/create-agent-ui-stream.ts +5 -3
- package/src/agent/pipe-agent-ui-stream-to-response.ts +2 -2
- package/src/generate-text/smooth-stream.ts +24 -9
- package/src/ui/process-ui-message-stream.ts +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# ai
|
|
2
2
|
|
|
3
|
+
## 6.0.296
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0741da8: fix(ai): allow agent UI streams to use original messages as input
|
|
8
|
+
- a63fa9b: fix(ai): preserve tool metadata from tool output chunks
|
|
9
|
+
- a61bea9: Preserve provider metadata on corresponding `smoothStream` chunks without carrying it into subsequent metadata-free deltas.
|
|
10
|
+
|
|
3
11
|
## 6.0.295
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3564,7 +3564,7 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
|
|
|
3564
3564
|
* Runs the agent and returns a response object with a UI message stream.
|
|
3565
3565
|
*
|
|
3566
3566
|
* @param agent - The agent to run.
|
|
3567
|
-
* @param uiMessages - The input UI messages.
|
|
3567
|
+
* @param uiMessages - The input UI messages. Defaults to originalMessages.
|
|
3568
3568
|
* @param abortSignal - Abort signal. Optional.
|
|
3569
3569
|
* @param timeout - Timeout in milliseconds. Optional.
|
|
3570
3570
|
* @param options - The options for the agent. Optional.
|
|
@@ -3579,7 +3579,7 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
|
|
|
3579
3579
|
*/
|
|
3580
3580
|
declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, consumeSseStream, ...options }: {
|
|
3581
3581
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3582
|
-
uiMessages
|
|
3582
|
+
uiMessages?: unknown[];
|
|
3583
3583
|
abortSignal?: AbortSignal;
|
|
3584
3584
|
timeout?: TimeoutConfiguration;
|
|
3585
3585
|
options?: CALL_OPTIONS;
|
|
@@ -4367,7 +4367,7 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
4367
4367
|
* Runs the agent and stream the output as a UI message stream.
|
|
4368
4368
|
*
|
|
4369
4369
|
* @param agent - The agent to run.
|
|
4370
|
-
* @param uiMessages - The input UI messages.
|
|
4370
|
+
* @param uiMessages - The input UI messages. Defaults to originalMessages.
|
|
4371
4371
|
* @param abortSignal - The abort signal. Optional.
|
|
4372
4372
|
* @param timeout - Timeout in milliseconds. Optional.
|
|
4373
4373
|
* @param options - The options for the agent.
|
|
@@ -4378,7 +4378,7 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
4378
4378
|
*/
|
|
4379
4379
|
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, onStepFinish, ...uiMessageStreamOptions }: {
|
|
4380
4380
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
4381
|
-
uiMessages
|
|
4381
|
+
uiMessages?: unknown[];
|
|
4382
4382
|
abortSignal?: AbortSignal;
|
|
4383
4383
|
timeout?: TimeoutConfiguration;
|
|
4384
4384
|
options?: CALL_OPTIONS;
|
|
@@ -4391,7 +4391,7 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
|
|
|
4391
4391
|
*
|
|
4392
4392
|
* @param response - The Node.js ServerResponse object to pipe to.
|
|
4393
4393
|
* @param agent - The agent to run.
|
|
4394
|
-
* @param uiMessages - The input UI messages.
|
|
4394
|
+
* @param uiMessages - The input UI messages. Defaults to originalMessages.
|
|
4395
4395
|
* @param abortSignal - Abort signal. Optional.
|
|
4396
4396
|
* @param timeout - Timeout in milliseconds. Optional.
|
|
4397
4397
|
* @param options - The options for the agent. Optional.
|
|
@@ -4405,7 +4405,7 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
|
|
|
4405
4405
|
declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, consumeSseStream, ...options }: {
|
|
4406
4406
|
response: ServerResponse;
|
|
4407
4407
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
4408
|
-
uiMessages
|
|
4408
|
+
uiMessages?: unknown[];
|
|
4409
4409
|
abortSignal?: AbortSignal;
|
|
4410
4410
|
timeout?: TimeoutConfiguration;
|
|
4411
4411
|
options?: CALL_OPTIONS;
|
package/dist/index.d.ts
CHANGED
|
@@ -3564,7 +3564,7 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
|
|
|
3564
3564
|
* Runs the agent and returns a response object with a UI message stream.
|
|
3565
3565
|
*
|
|
3566
3566
|
* @param agent - The agent to run.
|
|
3567
|
-
* @param uiMessages - The input UI messages.
|
|
3567
|
+
* @param uiMessages - The input UI messages. Defaults to originalMessages.
|
|
3568
3568
|
* @param abortSignal - Abort signal. Optional.
|
|
3569
3569
|
* @param timeout - Timeout in milliseconds. Optional.
|
|
3570
3570
|
* @param options - The options for the agent. Optional.
|
|
@@ -3579,7 +3579,7 @@ type InferAgentUIMessage<AGENT, MESSAGE_METADATA = unknown> = UIMessage<MESSAGE_
|
|
|
3579
3579
|
*/
|
|
3580
3580
|
declare function createAgentUIStreamResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ headers, status, statusText, consumeSseStream, ...options }: {
|
|
3581
3581
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
3582
|
-
uiMessages
|
|
3582
|
+
uiMessages?: unknown[];
|
|
3583
3583
|
abortSignal?: AbortSignal;
|
|
3584
3584
|
timeout?: TimeoutConfiguration;
|
|
3585
3585
|
options?: CALL_OPTIONS;
|
|
@@ -4367,7 +4367,7 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
4367
4367
|
* Runs the agent and stream the output as a UI message stream.
|
|
4368
4368
|
*
|
|
4369
4369
|
* @param agent - The agent to run.
|
|
4370
|
-
* @param uiMessages - The input UI messages.
|
|
4370
|
+
* @param uiMessages - The input UI messages. Defaults to originalMessages.
|
|
4371
4371
|
* @param abortSignal - The abort signal. Optional.
|
|
4372
4372
|
* @param timeout - Timeout in milliseconds. Optional.
|
|
4373
4373
|
* @param options - The options for the agent.
|
|
@@ -4378,7 +4378,7 @@ declare const UI_MESSAGE_STREAM_HEADERS: {
|
|
|
4378
4378
|
*/
|
|
4379
4379
|
declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ agent, uiMessages, options, abortSignal, timeout, experimental_transform, onStepFinish, ...uiMessageStreamOptions }: {
|
|
4380
4380
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
4381
|
-
uiMessages
|
|
4381
|
+
uiMessages?: unknown[];
|
|
4382
4382
|
abortSignal?: AbortSignal;
|
|
4383
4383
|
timeout?: TimeoutConfiguration;
|
|
4384
4384
|
options?: CALL_OPTIONS;
|
|
@@ -4391,7 +4391,7 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
|
|
|
4391
4391
|
*
|
|
4392
4392
|
* @param response - The Node.js ServerResponse object to pipe to.
|
|
4393
4393
|
* @param agent - The agent to run.
|
|
4394
|
-
* @param uiMessages - The input UI messages.
|
|
4394
|
+
* @param uiMessages - The input UI messages. Defaults to originalMessages.
|
|
4395
4395
|
* @param abortSignal - Abort signal. Optional.
|
|
4396
4396
|
* @param timeout - Timeout in milliseconds. Optional.
|
|
4397
4397
|
* @param options - The options for the agent. Optional.
|
|
@@ -4405,7 +4405,7 @@ declare function createAgentUIStream<CALL_OPTIONS = never, TOOLS extends ToolSet
|
|
|
4405
4405
|
declare function pipeAgentUIStreamToResponse<CALL_OPTIONS = never, TOOLS extends ToolSet = {}, OUTPUT extends Output = never, MESSAGE_METADATA = unknown>({ response, headers, status, statusText, consumeSseStream, ...options }: {
|
|
4406
4406
|
response: ServerResponse;
|
|
4407
4407
|
agent: Agent<CALL_OPTIONS, TOOLS, OUTPUT>;
|
|
4408
|
-
uiMessages
|
|
4408
|
+
uiMessages?: unknown[];
|
|
4409
4409
|
abortSignal?: AbortSignal;
|
|
4410
4410
|
timeout?: TimeoutConfiguration;
|
|
4411
4411
|
options?: CALL_OPTIONS;
|
package/dist/index.js
CHANGED
|
@@ -1334,7 +1334,7 @@ function detectMediaType({
|
|
|
1334
1334
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
1335
1335
|
|
|
1336
1336
|
// src/version.ts
|
|
1337
|
-
var VERSION = true ? "6.0.
|
|
1337
|
+
var VERSION = true ? "6.0.296" : "0.0.0-test";
|
|
1338
1338
|
|
|
1339
1339
|
// src/util/download/download.ts
|
|
1340
1340
|
var download = async ({
|
|
@@ -6023,7 +6023,7 @@ function processUIMessageStream({
|
|
|
6023
6023
|
new TransformStream({
|
|
6024
6024
|
async transform(chunk, controller) {
|
|
6025
6025
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
6026
|
-
var _a23, _b, _c, _d;
|
|
6026
|
+
var _a23, _b, _c, _d, _e, _f, _g, _h;
|
|
6027
6027
|
function getCurrentStepParts() {
|
|
6028
6028
|
const parts = state.message.parts;
|
|
6029
6029
|
let currentStepStartIndex = parts.length - 1;
|
|
@@ -6457,7 +6457,7 @@ function processUIMessageStream({
|
|
|
6457
6457
|
providerExecuted: chunk.providerExecuted,
|
|
6458
6458
|
providerMetadata: chunk.providerMetadata,
|
|
6459
6459
|
title: toolInvocation.title,
|
|
6460
|
-
toolMetadata: toolInvocation.toolMetadata
|
|
6460
|
+
toolMetadata: (_e = chunk.toolMetadata) != null ? _e : toolInvocation.toolMetadata
|
|
6461
6461
|
},
|
|
6462
6462
|
toolInvocation
|
|
6463
6463
|
);
|
|
@@ -6473,7 +6473,7 @@ function processUIMessageStream({
|
|
|
6473
6473
|
preliminary: chunk.preliminary,
|
|
6474
6474
|
providerMetadata: chunk.providerMetadata,
|
|
6475
6475
|
title: toolInvocation.title,
|
|
6476
|
-
toolMetadata: toolInvocation.toolMetadata
|
|
6476
|
+
toolMetadata: (_f = chunk.toolMetadata) != null ? _f : toolInvocation.toolMetadata
|
|
6477
6477
|
},
|
|
6478
6478
|
toolInvocation
|
|
6479
6479
|
);
|
|
@@ -6494,7 +6494,7 @@ function processUIMessageStream({
|
|
|
6494
6494
|
providerExecuted: chunk.providerExecuted,
|
|
6495
6495
|
providerMetadata: chunk.providerMetadata,
|
|
6496
6496
|
title: toolInvocation.title,
|
|
6497
|
-
toolMetadata: toolInvocation.toolMetadata
|
|
6497
|
+
toolMetadata: (_g = chunk.toolMetadata) != null ? _g : toolInvocation.toolMetadata
|
|
6498
6498
|
},
|
|
6499
6499
|
toolInvocation
|
|
6500
6500
|
);
|
|
@@ -6510,7 +6510,7 @@ function processUIMessageStream({
|
|
|
6510
6510
|
providerExecuted: chunk.providerExecuted,
|
|
6511
6511
|
providerMetadata: chunk.providerMetadata,
|
|
6512
6512
|
title: toolInvocation.title,
|
|
6513
|
-
toolMetadata: toolInvocation.toolMetadata
|
|
6513
|
+
toolMetadata: (_h = chunk.toolMetadata) != null ? _h : toolInvocation.toolMetadata
|
|
6514
6514
|
},
|
|
6515
6515
|
toolInvocation
|
|
6516
6516
|
);
|
|
@@ -10332,8 +10332,9 @@ async function createAgentUIStream({
|
|
|
10332
10332
|
...uiMessageStreamOptions
|
|
10333
10333
|
}) {
|
|
10334
10334
|
var _a23;
|
|
10335
|
+
const inputMessages = uiMessages != null ? uiMessages : uiMessageStreamOptions.originalMessages;
|
|
10335
10336
|
const validatedMessages = await validateUIMessagesForAgent({
|
|
10336
|
-
messages:
|
|
10337
|
+
messages: inputMessages,
|
|
10337
10338
|
tools: agent.tools
|
|
10338
10339
|
});
|
|
10339
10340
|
const modelMessages = await convertToModelMessages(validatedMessages, {
|
|
@@ -12737,21 +12738,32 @@ function smoothStream({
|
|
|
12737
12738
|
controller.enqueue(chunk);
|
|
12738
12739
|
return;
|
|
12739
12740
|
}
|
|
12740
|
-
if (
|
|
12741
|
+
if (chunk.text.length === 0 && chunk.providerMetadata != null) {
|
|
12742
|
+
flushBuffer(controller);
|
|
12743
|
+
controller.enqueue(chunk);
|
|
12744
|
+
return;
|
|
12745
|
+
}
|
|
12746
|
+
if (buffer.length > 0 && (chunk.type !== type || chunk.id !== id || providerMetadata != null || chunk.providerMetadata != null)) {
|
|
12741
12747
|
flushBuffer(controller);
|
|
12742
12748
|
}
|
|
12743
12749
|
buffer += chunk.text;
|
|
12744
12750
|
id = chunk.id;
|
|
12745
12751
|
type = chunk.type;
|
|
12746
|
-
|
|
12747
|
-
providerMetadata = chunk.providerMetadata;
|
|
12748
|
-
}
|
|
12752
|
+
providerMetadata = chunk.providerMetadata;
|
|
12749
12753
|
let match;
|
|
12750
12754
|
while ((match = detectChunk(buffer)) != null) {
|
|
12751
|
-
controller.enqueue({
|
|
12755
|
+
controller.enqueue({
|
|
12756
|
+
type,
|
|
12757
|
+
text: match,
|
|
12758
|
+
id,
|
|
12759
|
+
...providerMetadata != null ? { providerMetadata } : {}
|
|
12760
|
+
});
|
|
12752
12761
|
buffer = buffer.slice(match.length);
|
|
12753
12762
|
await delay(isDocumentHidden() ? null : delayInMs);
|
|
12754
12763
|
}
|
|
12764
|
+
if (buffer.length === 0) {
|
|
12765
|
+
providerMetadata = void 0;
|
|
12766
|
+
}
|
|
12755
12767
|
}
|
|
12756
12768
|
});
|
|
12757
12769
|
};
|