@mastra/react 1.1.2-alpha.5 → 1.2.0
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 +60 -0
- package/dist/agent/extract-tasks.d.ts +10 -0
- package/dist/agent/extract-tasks.d.ts.map +1 -0
- package/dist/agent/hooks.d.ts +7 -1
- package/dist/agent/hooks.d.ts.map +1 -1
- package/dist/index.cjs +94 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +94 -8
- package/dist/index.js.map +1 -1
- package/dist/ui/MessageFactory/MessageFactory.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @mastra/react
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `tasks` as a first-class return value on `useChat`. Task state is incrementally updated from streaming task state signals and tool results — no message rescanning required. ([#18374](https://github.com/mastra-ai/mastra/pull/18374))
|
|
8
|
+
|
|
9
|
+
Fixed step framing markers leaking into the chat UI. The MessageFactory now renders step-start parts as nothing by default instead of routing them to your fallback renderer, so internal step boundaries no longer show up as stray output. You can still opt in to rendering a step divider by supplying a StepStart renderer.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- feat(playground): render ask_user tool as interactive question UI in Studio ([#18374](https://github.com/mastra-ai/mastra/pull/18374))
|
|
14
|
+
|
|
15
|
+
Adds an `AskUserBadge` component that renders suspended `ask_user` tool calls
|
|
16
|
+
as interactive prompts with clickable option buttons (single/multi-select) or
|
|
17
|
+
free-text input. The user's answer is sent as `resumeData` through the existing
|
|
18
|
+
`sendToolApproval` flow to properly resume the tool.
|
|
19
|
+
|
|
20
|
+
Plumbing changes:
|
|
21
|
+
- `sendToolApprovalBodySchema` now accepts optional `resumeData`
|
|
22
|
+
- `agent.sendToolApproval()` passes custom `resumeData` when provided
|
|
23
|
+
- `@mastra/client-js` and `@mastra/react` expose the new parameter
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`86623c1`](https://github.com/mastra-ai/mastra/commit/86623c1adf7d22de32cc916dda17f4155184db36), [`023766f`](https://github.com/mastra-ai/mastra/commit/023766f44d59b30a50f3a381e33eddde8ab56c00), [`0200e75`](https://github.com/mastra-ai/mastra/commit/0200e7552d02d4221cd6040bf4eddf189a97a156), [`7c9dd77`](https://github.com/mastra-ai/mastra/commit/7c9dd77bd18cb8dc72797e25f1a0fbdc71a11347), [`7f9ae70`](https://github.com/mastra-ai/mastra/commit/7f9ae70826b047e5a66218f9e92f20e54a2d791f), [`a0509c7`](https://github.com/mastra-ai/mastra/commit/a0509c731a08aa3ed626557c5338126362856f57), [`06e0d63`](https://github.com/mastra-ai/mastra/commit/06e0d63d42bc2a202e18bc091f3781f409f5e6fb), [`bf3fe49`](https://github.com/mastra-ai/mastra/commit/bf3fe49f9467dbbdb8f9eaf74e0f7971ffb19559), [`01caf93`](https://github.com/mastra-ai/mastra/commit/01caf93d71ae2c1e65f49735cafb531975187426), [`438a971`](https://github.com/mastra-ai/mastra/commit/438a9715c8b4398e5eaf8914a1f19dc8a85dc1de), [`9990965`](https://github.com/mastra-ai/mastra/commit/999096571635a83b42ef40841fd7028cfa630779), [`77518cc`](https://github.com/mastra-ai/mastra/commit/77518ccb5bb8cc684875081e64213dc85cffdbee), [`fbeda0c`](https://github.com/mastra-ai/mastra/commit/fbeda0c0f35def07e6837936dd3a003b2b7c5172), [`8a68844`](https://github.com/mastra-ai/mastra/commit/8a688443013816105a09f89c6afa34b5ff13e26d), [`bb2a13b`](https://github.com/mastra-ai/mastra/commit/bb2a13bb4b32e6bb807200fe7b18ae8fa4322118), [`24ceaea`](https://github.com/mastra-ai/mastra/commit/24ceaea0bdd8609cabbab764380608ca6621a194), [`a73cd1a`](https://github.com/mastra-ai/mastra/commit/a73cd1a62a5e4ca023dcc39ba150029f4f1f74c1), [`c0ffa3c`](https://github.com/mastra-ai/mastra/commit/c0ffa3c897ccd326de880df734740a7f0681a18f), [`462a769`](https://github.com/mastra-ai/mastra/commit/462a769da61850862ca1be3d74134d33078ee6a7), [`0504bf5`](https://github.com/mastra-ai/mastra/commit/0504bf5e8cffc571a4b343326178de371e6f859b), [`9e45902`](https://github.com/mastra-ai/mastra/commit/9e4590208e745055cecca202e2db0e5c65e17d3c), [`0b5cc47`](https://github.com/mastra-ai/mastra/commit/0b5cc4726dc18d9a685a27520db39ff1b36bb89a), [`87f38a3`](https://github.com/mastra-ai/mastra/commit/87f38a3de03e24731f2dd6f8ed6a60b6722b85a1), [`d5fa3cd`](https://github.com/mastra-ai/mastra/commit/d5fa3cda1788c3cb93a361a3c6ec47de6ba21e98), [`fe98ef2`](https://github.com/mastra-ai/mastra/commit/fe98ef2e66dbfcbd7d645c88c9ee1e67b458a136), [`6ccf67b`](https://github.com/mastra-ai/mastra/commit/6ccf67bf075753754927a57bc2e1734ba2c820c5), [`793ea0f`](https://github.com/mastra-ai/mastra/commit/793ea0f52f831178837f21c83af6af93bf4ce638), [`825d8de`](https://github.com/mastra-ai/mastra/commit/825d8def9fa64c2bcc3d8dd6b49e09342c3ac5c7), [`507a5c4`](https://github.com/mastra-ai/mastra/commit/507a5c461bdc3136ad80744c0efbb55ce1f18f97), [`5afe423`](https://github.com/mastra-ai/mastra/commit/5afe423e4badf040f1b0d4525183a856fcb8146e), [`307573b`](https://github.com/mastra-ai/mastra/commit/307573b9ff3149b70c79540dbc86f1319b180f29), [`79b3626`](https://github.com/mastra-ai/mastra/commit/79b3626f8d647307eb07c8da14c9073c2699719d), [`c2c1d7b`](https://github.com/mastra-ai/mastra/commit/c2c1d7bb61d2602955f14ed3952f807c2d6eb576), [`86623c1`](https://github.com/mastra-ai/mastra/commit/86623c1adf7d22de32cc916dda17f4155184db36), [`1505c07`](https://github.com/mastra-ai/mastra/commit/1505c07603f6346bae12aa82f140e8b88ffea9ab), [`f328049`](https://github.com/mastra-ai/mastra/commit/f3280498c324afd2a8d36cd828f5b9f94a2dddc1), [`e545228`](https://github.com/mastra-ai/mastra/commit/e54522856934a5dc030b7b6385771e3548020d59), [`3eb852e`](https://github.com/mastra-ai/mastra/commit/3eb852e5435bc908b800193498103dc724f455b0), [`ffa09e7`](https://github.com/mastra-ai/mastra/commit/ffa09e772a5c92270eabe2090fc42d45bd8ec4b7), [`8c9f1c0`](https://github.com/mastra-ai/mastra/commit/8c9f1c0361d89066f9bcd14a2f69e761b01766c8), [`461a7c5`](https://github.com/mastra-ai/mastra/commit/461a7c501449295287f4f0ee4b0b42344f39fcf8), [`4211472`](https://github.com/mastra-ai/mastra/commit/4211472a5a2bd319c60cd2e42d9109c3eef7ac1c), [`9e45902`](https://github.com/mastra-ai/mastra/commit/9e4590208e745055cecca202e2db0e5c65e17d3c), [`5c0df77`](https://github.com/mastra-ai/mastra/commit/5c0df776c40efa420f8c07a2f3ee66010296618e), [`e940f09`](https://github.com/mastra-ai/mastra/commit/e940f099ef5d18b403e6f2b4937e086a4da857b1)]:
|
|
26
|
+
- @mastra/core@1.47.0
|
|
27
|
+
- @mastra/client-js@1.28.0
|
|
28
|
+
|
|
29
|
+
## 1.2.0-alpha.7
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [[`8a68844`](https://github.com/mastra-ai/mastra/commit/8a688443013816105a09f89c6afa34b5ff13e26d)]:
|
|
34
|
+
- @mastra/core@1.47.0-alpha.7
|
|
35
|
+
- @mastra/client-js@1.28.0-alpha.7
|
|
36
|
+
|
|
37
|
+
## 1.2.0-alpha.6
|
|
38
|
+
|
|
39
|
+
### Minor Changes
|
|
40
|
+
|
|
41
|
+
- Added `tasks` as a first-class return value on `useChat`. Task state is incrementally updated from streaming task state signals and tool results — no message rescanning required. ([#18374](https://github.com/mastra-ai/mastra/pull/18374))
|
|
42
|
+
|
|
43
|
+
Fixed step framing markers leaking into the chat UI. The MessageFactory now renders step-start parts as nothing by default instead of routing them to your fallback renderer, so internal step boundaries no longer show up as stray output. You can still opt in to rendering a step divider by supplying a StepStart renderer.
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- feat(playground): render ask_user tool as interactive question UI in Studio ([#18374](https://github.com/mastra-ai/mastra/pull/18374))
|
|
48
|
+
|
|
49
|
+
Adds an `AskUserBadge` component that renders suspended `ask_user` tool calls
|
|
50
|
+
as interactive prompts with clickable option buttons (single/multi-select) or
|
|
51
|
+
free-text input. The user's answer is sent as `resumeData` through the existing
|
|
52
|
+
`sendToolApproval` flow to properly resume the tool.
|
|
53
|
+
|
|
54
|
+
Plumbing changes:
|
|
55
|
+
- `sendToolApprovalBodySchema` now accepts optional `resumeData`
|
|
56
|
+
- `agent.sendToolApproval()` passes custom `resumeData` when provided
|
|
57
|
+
- `@mastra/client-js` and `@mastra/react` expose the new parameter
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [[`0200e75`](https://github.com/mastra-ai/mastra/commit/0200e7552d02d4221cd6040bf4eddf189a97a156), [`06e0d63`](https://github.com/mastra-ai/mastra/commit/06e0d63d42bc2a202e18bc091f3781f409f5e6fb), [`438a971`](https://github.com/mastra-ai/mastra/commit/438a9715c8b4398e5eaf8914a1f19dc8a85dc1de), [`77518cc`](https://github.com/mastra-ai/mastra/commit/77518ccb5bb8cc684875081e64213dc85cffdbee), [`bb2a13b`](https://github.com/mastra-ai/mastra/commit/bb2a13bb4b32e6bb807200fe7b18ae8fa4322118), [`a73cd1a`](https://github.com/mastra-ai/mastra/commit/a73cd1a62a5e4ca023dcc39ba150029f4f1f74c1), [`0b5cc47`](https://github.com/mastra-ai/mastra/commit/0b5cc4726dc18d9a685a27520db39ff1b36bb89a), [`87f38a3`](https://github.com/mastra-ai/mastra/commit/87f38a3de03e24731f2dd6f8ed6a60b6722b85a1), [`d5fa3cd`](https://github.com/mastra-ai/mastra/commit/d5fa3cda1788c3cb93a361a3c6ec47de6ba21e98), [`fe98ef2`](https://github.com/mastra-ai/mastra/commit/fe98ef2e66dbfcbd7d645c88c9ee1e67b458a136), [`793ea0f`](https://github.com/mastra-ai/mastra/commit/793ea0f52f831178837f21c83af6af93bf4ce638), [`507a5c4`](https://github.com/mastra-ai/mastra/commit/507a5c461bdc3136ad80744c0efbb55ce1f18f97), [`79b3626`](https://github.com/mastra-ai/mastra/commit/79b3626f8d647307eb07c8da14c9073c2699719d)]:
|
|
60
|
+
- @mastra/core@1.47.0-alpha.6
|
|
61
|
+
- @mastra/client-js@1.28.0-alpha.6
|
|
62
|
+
|
|
3
63
|
## 1.1.2-alpha.5
|
|
4
64
|
|
|
5
65
|
### Patch Changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MastraDBMessage } from '@mastra/core/agent/message-list';
|
|
2
|
+
import type { TaskItem } from '@mastra/core/signals';
|
|
3
|
+
import type { ChunkType } from '@mastra/core/stream';
|
|
4
|
+
export declare const TASK_TOOL_NAMES: Set<string>;
|
|
5
|
+
export declare const isRecord: (value: unknown) => value is Record<string, unknown>;
|
|
6
|
+
export declare const isTaskItemArray: (value: unknown) => value is TaskItem[];
|
|
7
|
+
export declare const extractTasksFromSignalChunk: (chunk: ChunkType) => TaskItem[] | undefined;
|
|
8
|
+
export declare const extractTasksFromToolResultChunk: (chunk: ChunkType) => TaskItem[] | undefined;
|
|
9
|
+
export declare const extractLatestTasksFromMessages: (messages: MastraDBMessage[]) => TaskItem[];
|
|
10
|
+
//# sourceMappingURL=extract-tasks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-tasks.d.ts","sourceRoot":"","sources":["../../src/agent/extract-tasks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,qBAAqB,CAAC;AAEpE,eAAO,MAAM,eAAe,aAAwE,CAAC;AAUrG,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACH,CAAC;AAKvE,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QAAQ,EAS/D,CAAC;AA6BJ,eAAO,MAAM,2BAA2B,GAAI,OAAO,SAAS,KAAG,QAAQ,EAAE,GAAG,SAG3E,CAAC;AAEF,eAAO,MAAM,+BAA+B,GAAI,OAAO,SAAS,KAAG,QAAQ,EAAE,GAAG,SAO/E,CAAC;AAqBF,eAAO,MAAM,8BAA8B,GAAI,UAAU,eAAe,EAAE,KAAG,QAAQ,EAmBpF,CAAC"}
|
package/dist/agent/hooks.d.ts
CHANGED
|
@@ -69,7 +69,13 @@ export declare const useChat: ({ agentId, resourceId, threadId, initialMessages,
|
|
|
69
69
|
isRunning: boolean;
|
|
70
70
|
isAwaitingToolApproval: boolean;
|
|
71
71
|
messages: MastraDBMessage[];
|
|
72
|
-
|
|
72
|
+
tasks: {
|
|
73
|
+
content: string;
|
|
74
|
+
status: "pending" | "in_progress" | "completed";
|
|
75
|
+
activeForm: string;
|
|
76
|
+
id: string;
|
|
77
|
+
}[];
|
|
78
|
+
approveToolCall: (toolCallId: string, resumeData?: unknown) => Promise<void>;
|
|
73
79
|
declineToolCall: (toolCallId: string) => Promise<void>;
|
|
74
80
|
approveToolCallGenerate: (toolCallId: string) => Promise<void>;
|
|
75
81
|
declineToolCallGenerate: (toolCallId: string) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/agent/hooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,eAAe,EAA4B,MAAM,iCAAiC,CAAC;AAE3G,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC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AC,CAAC;CAC7D,CAAC;AAoDF,eAAO,MAAM,OAAO,GAAI,qMAWrB,eAAe;;qCAw0ByC,eAAe;;;;;;;;;;kCAtN7B,MAAM,eAAe,OAAO;kCAkD5B,MAAM;0CAgDE,MAAM;0CA0BN,MAAM;;;;oBAvtBvB,UAAU,GAAG,UAAU;;;uCAivBT,MAAM,UAAU,MAAM;uCAgCtB,MAAM,UAAU,MAAM;;;oBA9wBtC,UAAU,GAAG,UAAU;;;CA22BxD,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1703,12 +1703,90 @@ var newUserMessage = (parts) => ({
|
|
|
1703
1703
|
var fromCoreUserMessageToMastraDBMessage = (coreUserMessage) => newUserMessage(coreUserMessageToParts(coreUserMessage));
|
|
1704
1704
|
var fromCoreUserMessagesToMastraDBMessage = (coreUserMessages) => newUserMessage(coreUserMessages.flatMap(coreUserMessageToParts));
|
|
1705
1705
|
|
|
1706
|
+
// src/agent/extract-tasks.ts
|
|
1707
|
+
var TASK_TOOL_NAMES = /* @__PURE__ */ new Set(["task_write", "task_update", "task_complete", "task_check"]);
|
|
1708
|
+
var TASK_SIGNAL_ID = "tasks";
|
|
1709
|
+
var TASK_TAG_NAMES = /* @__PURE__ */ new Set(["current-task-list", "task-list-update"]);
|
|
1710
|
+
var TASK_STATUSES = /* @__PURE__ */ new Set(["pending", "in_progress", "completed"]);
|
|
1711
|
+
var isDataChunk2 = (chunk) => typeof chunk.type === "string" && chunk.type.startsWith("data-");
|
|
1712
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1713
|
+
var isTaskStatus = (value) => typeof value === "string" && TASK_STATUSES.has(value);
|
|
1714
|
+
var isTaskItemArray = (value) => Array.isArray(value) && value.every(
|
|
1715
|
+
(item) => isRecord(item) && typeof item.id === "string" && typeof item.content === "string" && isTaskStatus(item.status) && typeof item.activeForm === "string"
|
|
1716
|
+
);
|
|
1717
|
+
var isTaskSignal = (value) => {
|
|
1718
|
+
if (!isRecord(value)) return false;
|
|
1719
|
+
return value.id === TASK_SIGNAL_ID || typeof value.tagName === "string" && TASK_TAG_NAMES.has(value.tagName);
|
|
1720
|
+
};
|
|
1721
|
+
var extractTasksFromSignalData = (data) => {
|
|
1722
|
+
if (!isTaskSignal(data) || !isRecord(data)) return void 0;
|
|
1723
|
+
const metadata = data.metadata;
|
|
1724
|
+
if (!isRecord(metadata)) return void 0;
|
|
1725
|
+
const value = metadata.value;
|
|
1726
|
+
if (!isRecord(value)) return void 0;
|
|
1727
|
+
return isTaskItemArray(value.tasks) ? value.tasks : void 0;
|
|
1728
|
+
};
|
|
1729
|
+
var parseTasksFromResult = (raw) => {
|
|
1730
|
+
if (isRecord(raw) && isTaskItemArray(raw.tasks)) return raw.tasks;
|
|
1731
|
+
if (typeof raw !== "string") return void 0;
|
|
1732
|
+
try {
|
|
1733
|
+
const parsed = JSON.parse(raw);
|
|
1734
|
+
return isRecord(parsed) && isTaskItemArray(parsed.tasks) ? parsed.tasks : void 0;
|
|
1735
|
+
} catch {
|
|
1736
|
+
return void 0;
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
var extractTasksFromSignalChunk = (chunk) => {
|
|
1740
|
+
if (!isDataChunk2(chunk)) return void 0;
|
|
1741
|
+
return extractTasksFromSignalData(chunk.data);
|
|
1742
|
+
};
|
|
1743
|
+
var extractTasksFromToolResultChunk = (chunk) => {
|
|
1744
|
+
if (chunk.type !== "tool-result") return void 0;
|
|
1745
|
+
const payload = chunk.payload;
|
|
1746
|
+
if (!isRecord(payload) || typeof payload.toolName !== "string" || !TASK_TOOL_NAMES.has(payload.toolName)) {
|
|
1747
|
+
return void 0;
|
|
1748
|
+
}
|
|
1749
|
+
return parseTasksFromResult(payload.result);
|
|
1750
|
+
};
|
|
1751
|
+
var extractTasksFromToolInvocationPart = (part) => {
|
|
1752
|
+
if (!isRecord(part) || part.type !== "tool-invocation" || !isRecord(part.toolInvocation)) return void 0;
|
|
1753
|
+
const toolInvocation = part.toolInvocation;
|
|
1754
|
+
if (typeof toolInvocation.toolName !== "string" || !TASK_TOOL_NAMES.has(toolInvocation.toolName)) return void 0;
|
|
1755
|
+
return parseTasksFromResult(toolInvocation.result);
|
|
1756
|
+
};
|
|
1757
|
+
var extractTasksFromDataPart = (part) => {
|
|
1758
|
+
if (!isRecord(part) || typeof part.type !== "string" || !part.type.startsWith("data-")) return void 0;
|
|
1759
|
+
return extractTasksFromSignalData(part.data);
|
|
1760
|
+
};
|
|
1761
|
+
var extractTasksFromSignalMessage = (message) => {
|
|
1762
|
+
if (message.role !== "signal") return void 0;
|
|
1763
|
+
const metadata = message.content?.metadata;
|
|
1764
|
+
if (!isRecord(metadata)) return void 0;
|
|
1765
|
+
return extractTasksFromSignalData(metadata.signal);
|
|
1766
|
+
};
|
|
1767
|
+
var extractLatestTasksFromMessages = (messages) => {
|
|
1768
|
+
let latest;
|
|
1769
|
+
for (const message of messages) {
|
|
1770
|
+
for (const part of message.content?.parts ?? []) {
|
|
1771
|
+
const toolTasks = extractTasksFromToolInvocationPart(part);
|
|
1772
|
+
if (toolTasks !== void 0) latest = toolTasks;
|
|
1773
|
+
}
|
|
1774
|
+
const signalTasks = extractTasksFromSignalMessage(message);
|
|
1775
|
+
if (signalTasks !== void 0) latest = signalTasks;
|
|
1776
|
+
for (const part of message.content?.parts ?? []) {
|
|
1777
|
+
const dataTasks = extractTasksFromDataPart(part);
|
|
1778
|
+
if (dataTasks !== void 0) latest = dataTasks;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
return latest ?? [];
|
|
1782
|
+
};
|
|
1783
|
+
|
|
1706
1784
|
// src/agent/extractRunIdFromMessages.ts
|
|
1707
|
-
var
|
|
1785
|
+
var isRecord2 = (value) => value !== null && typeof value === "object";
|
|
1708
1786
|
var runIdMetadataKeys = ["pendingToolApprovals", "requireApprovalMetadata", "suspendedTools"];
|
|
1709
|
-
var isRunIdMetadataSource = (value) =>
|
|
1787
|
+
var isRunIdMetadataSource = (value) => isRecord2(value) && Object.values(value).every((entry) => isRecord2(entry));
|
|
1710
1788
|
var getRunIdMetadataSources = (metadata) => {
|
|
1711
|
-
if (!
|
|
1789
|
+
if (!isRecord2(metadata)) return [];
|
|
1712
1790
|
const sources = [];
|
|
1713
1791
|
for (const key of runIdMetadataKeys) {
|
|
1714
1792
|
const source = metadata[key];
|
|
@@ -1722,7 +1800,7 @@ var extractRunIdFromMessages = (messages) => {
|
|
|
1722
1800
|
for (const message of messages) {
|
|
1723
1801
|
for (const source of getRunIdMetadataSources(message.content?.metadata)) {
|
|
1724
1802
|
for (const entry of Object.values(source)) {
|
|
1725
|
-
if (
|
|
1803
|
+
if (isRecord2(entry) && typeof entry.runId === "string" && entry.runId.length > 0) {
|
|
1726
1804
|
return entry.runId;
|
|
1727
1805
|
}
|
|
1728
1806
|
}
|
|
@@ -1827,7 +1905,7 @@ var isThreadSignalUnsupportedError = (error) => {
|
|
|
1827
1905
|
}
|
|
1828
1906
|
return status === 400 && typeof error.message === "string" && error.message.includes("No active agent run found for signal target");
|
|
1829
1907
|
};
|
|
1830
|
-
var
|
|
1908
|
+
var isDataChunk3 = (chunk) => typeof chunk.type === "string" && chunk.type.startsWith("data-");
|
|
1831
1909
|
var dbFromServerUiMessages = (uiMessages, metadata) => uiMessages.map((uiMsg) => {
|
|
1832
1910
|
const dbMsg = messageList.AIV5Adapter.fromUIMessage(uiMsg);
|
|
1833
1911
|
return {
|
|
@@ -1868,6 +1946,7 @@ var useChat = ({
|
|
|
1868
1946
|
const _threadSubscriptionPromiseRef = react.useRef(null);
|
|
1869
1947
|
const _threadSignalsUnsupportedRef = react.useRef(false);
|
|
1870
1948
|
const [messages, setMessages] = react.useState([]);
|
|
1949
|
+
const [tasks, setTasks] = react.useState([]);
|
|
1871
1950
|
const [toolCallApprovals, setToolCallApprovals] = react.useState({});
|
|
1872
1951
|
const [networkToolCallApprovals, setNetworkToolCallApprovals] = react.useState({});
|
|
1873
1952
|
const pendingToolApprovalIdsRef = react.useRef(/* @__PURE__ */ new Set());
|
|
@@ -1877,6 +1956,7 @@ var useChat = ({
|
|
|
1877
1956
|
react.useEffect(() => {
|
|
1878
1957
|
const formattedMessages = resolveInitialMessages(initialMessages ?? []);
|
|
1879
1958
|
setMessages(formattedMessages);
|
|
1959
|
+
setTasks(extractLatestTasksFromMessages(formattedMessages));
|
|
1880
1960
|
pendingToolApprovalIdsRef.current = extractPendingToolApprovalIdsFromMessages(formattedMessages);
|
|
1881
1961
|
setIsAwaitingToolApproval(pendingToolApprovalIdsRef.current.size > 0);
|
|
1882
1962
|
_currentRunId.current = extractRunIdFromMessages(formattedMessages);
|
|
@@ -1948,7 +2028,11 @@ var useChat = ({
|
|
|
1948
2028
|
const processStreamChunk = react.useCallback(
|
|
1949
2029
|
async (chunk, onChunk) => {
|
|
1950
2030
|
setMessages((prev) => accumulateChunk({ chunk, conversation: prev, metadata: { mode: "stream" } }));
|
|
1951
|
-
|
|
2031
|
+
const signalTasks = extractTasksFromSignalChunk(chunk);
|
|
2032
|
+
if (signalTasks !== void 0) setTasks(signalTasks);
|
|
2033
|
+
const toolTasks = extractTasksFromToolResultChunk(chunk);
|
|
2034
|
+
if (toolTasks !== void 0) setTasks(toolTasks);
|
|
2035
|
+
if (chunk.type === "data-user-message" && isDataChunk3(chunk) && (chunk.data?.type === "user-message" || chunk.data?.type === "user") && typeof chunk.data?.id === "string") {
|
|
1952
2036
|
onSignalEcho?.(chunk.data.id);
|
|
1953
2037
|
}
|
|
1954
2038
|
if (chunk.type === "start") {
|
|
@@ -2358,7 +2442,7 @@ var useChat = ({
|
|
|
2358
2442
|
_onNetworkChunk.current = void 0;
|
|
2359
2443
|
_requestContext.current = void 0;
|
|
2360
2444
|
};
|
|
2361
|
-
const approveToolCall = async (toolCallId) => {
|
|
2445
|
+
const approveToolCall = async (toolCallId, resumeData) => {
|
|
2362
2446
|
const onChunk = _onChunk.current;
|
|
2363
2447
|
const currentRunId = _currentRunId.current;
|
|
2364
2448
|
if (!currentRunId)
|
|
@@ -2373,6 +2457,7 @@ var useChat = ({
|
|
|
2373
2457
|
threadId,
|
|
2374
2458
|
toolCallId,
|
|
2375
2459
|
approved: true,
|
|
2460
|
+
...resumeData !== void 0 ? { resumeData } : {},
|
|
2376
2461
|
requestContext: _requestContext.current
|
|
2377
2462
|
});
|
|
2378
2463
|
pendingToolApprovalIdsRef.current.delete(toolCallId);
|
|
@@ -2572,6 +2657,7 @@ var useChat = ({
|
|
|
2572
2657
|
isRunning,
|
|
2573
2658
|
isAwaitingToolApproval,
|
|
2574
2659
|
messages,
|
|
2660
|
+
tasks,
|
|
2575
2661
|
approveToolCall,
|
|
2576
2662
|
declineToolCall,
|
|
2577
2663
|
approveToolCallGenerate,
|
|
@@ -2932,7 +3018,7 @@ var renderPart = (part, renderers, fallback) => {
|
|
|
2932
3018
|
case "file":
|
|
2933
3019
|
return renderers.File?.(part) ?? fallback?.(part) ?? null;
|
|
2934
3020
|
case "step-start":
|
|
2935
|
-
return renderers.StepStart?.(part) ??
|
|
3021
|
+
return renderers.StepStart?.(part) ?? null;
|
|
2936
3022
|
case "tool-invocation":
|
|
2937
3023
|
return renderers.ToolInvocation?.(part) ?? fallback?.(part) ?? null;
|
|
2938
3024
|
case "source":
|