@mastra/react 0.1.0 → 0.2.0-alpha.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 +47 -0
- package/dist/{chunk-55VPMN3N-BHqoDkCq.cjs → chunk-REDZDNFN-D4qauMBp.cjs} +4 -4
- package/dist/chunk-REDZDNFN-D4qauMBp.cjs.map +1 -0
- package/dist/{chunk-55VPMN3N-Ax1F4Y75.js → chunk-REDZDNFN-DEIWVTdL.js} +4 -4
- package/dist/chunk-REDZDNFN-DEIWVTdL.js.map +1 -0
- package/dist/{index-D3JtF_Zl.js → index-BrMELKWu.js} +594 -28
- package/dist/index-BrMELKWu.js.map +1 -0
- package/dist/{index-ChvWx-iU.cjs → index-TEBHU8EU.cjs} +595 -26
- package/dist/index-TEBHU8EU.cjs.map +1 -0
- package/dist/index.cjs +4 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lib/use-mutation.d.ts +27 -0
- package/dist/src/mastra-client-context.d.ts +3 -1
- package/dist/src/mastra-react-provider.d.ts +1 -1
- package/dist/src/workflows/hooks.d.ts +33 -0
- package/dist/src/workflows/index.d.ts +2 -0
- package/dist/src/workflows/types.d.ts +121 -0
- package/dist/src/workflows/use-stream-workflow.d.ts +38 -0
- package/dist/{token-6GSAFR2W-SPYPLMBM-CWoxKwfk.cjs → token-6GSAFR2W-XRCSVUPZ-DdTrjI2X.cjs} +5 -5
- package/dist/token-6GSAFR2W-XRCSVUPZ-DdTrjI2X.cjs.map +1 -0
- package/dist/{token-6GSAFR2W-SPYPLMBM-ChURikIE.js → token-6GSAFR2W-XRCSVUPZ-JdBnAp2N.js} +4 -4
- package/dist/token-6GSAFR2W-XRCSVUPZ-JdBnAp2N.js.map +1 -0
- package/dist/token-util-NEHG7TUY-U7CX7GS4-CfBW62uu.cjs +11 -0
- package/dist/token-util-NEHG7TUY-U7CX7GS4-CfBW62uu.cjs.map +1 -0
- package/dist/{token-util-NEHG7TUY-JRJTGTAB-hEay2AHp.js → token-util-NEHG7TUY-U7CX7GS4-DhQqQpmz.js} +2 -2
- package/dist/token-util-NEHG7TUY-U7CX7GS4-DhQqQpmz.js.map +1 -0
- package/package.json +3 -3
- package/dist/chunk-55VPMN3N-Ax1F4Y75.js.map +0 -1
- package/dist/chunk-55VPMN3N-BHqoDkCq.cjs.map +0 -1
- package/dist/index-ChvWx-iU.cjs.map +0 -1
- package/dist/index-D3JtF_Zl.js.map +0 -1
- package/dist/token-6GSAFR2W-SPYPLMBM-CWoxKwfk.cjs.map +0 -1
- package/dist/token-6GSAFR2W-SPYPLMBM-ChURikIE.js.map +0 -1
- package/dist/token-util-NEHG7TUY-JRJTGTAB-BU9ZxL1w.cjs +0 -11
- package/dist/token-util-NEHG7TUY-JRJTGTAB-BU9ZxL1w.cjs.map +0 -1
- package/dist/token-util-NEHG7TUY-JRJTGTAB-hEay2AHp.js.map +0 -1
|
@@ -33,21 +33,22 @@ function _interopNamespaceDefault(e) {
|
|
|
33
33
|
const z4__namespace = /*#__PURE__*/_interopNamespaceDefault(z4);
|
|
34
34
|
|
|
35
35
|
const MastraClientContext = react.createContext({});
|
|
36
|
-
const MastraClientProvider = ({ children, baseUrl, headers }) => {
|
|
37
|
-
const client = createMastraClient(baseUrl, headers);
|
|
36
|
+
const MastraClientProvider = ({ children, baseUrl, headers, apiPrefix }) => {
|
|
37
|
+
const client = createMastraClient(baseUrl, headers, apiPrefix);
|
|
38
38
|
return /* @__PURE__ */ jsxRuntime.jsx(MastraClientContext.Provider, { value: client, children });
|
|
39
39
|
};
|
|
40
40
|
const useMastraClient = () => react.useContext(MastraClientContext);
|
|
41
|
-
const createMastraClient = (baseUrl, mastraClientHeaders = {}) => {
|
|
41
|
+
const createMastraClient = (baseUrl, mastraClientHeaders = {}, apiPrefix) => {
|
|
42
42
|
return new clientJs.MastraClient({
|
|
43
43
|
baseUrl: baseUrl || "",
|
|
44
44
|
// only add the header if the baseUrl is not provided i.e it's a local dev environment
|
|
45
|
-
headers: !baseUrl ? { ...mastraClientHeaders, "x-mastra-dev-playground": "true" } : mastraClientHeaders
|
|
45
|
+
headers: !baseUrl ? { ...mastraClientHeaders, "x-mastra-dev-playground": "true" } : mastraClientHeaders,
|
|
46
|
+
apiPrefix
|
|
46
47
|
});
|
|
47
48
|
};
|
|
48
49
|
|
|
49
|
-
const MastraReactProvider = ({ children, baseUrl, headers }) => {
|
|
50
|
-
return /* @__PURE__ */ jsxRuntime.jsx(MastraClientProvider, { baseUrl, headers, children });
|
|
50
|
+
const MastraReactProvider = ({ children, baseUrl, headers, apiPrefix }) => {
|
|
51
|
+
return /* @__PURE__ */ jsxRuntime.jsx(MastraClientProvider, { baseUrl, headers, apiPrefix, children });
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
const mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
|
|
@@ -966,6 +967,125 @@ const resolveToChildMessages = (messages) => {
|
|
|
966
967
|
return childMessages;
|
|
967
968
|
};
|
|
968
969
|
|
|
970
|
+
// src/request-context/index.ts
|
|
971
|
+
var RequestContext = class {
|
|
972
|
+
registry = /* @__PURE__ */ new Map();
|
|
973
|
+
constructor(iterable) {
|
|
974
|
+
this.registry = new Map(iterable);
|
|
975
|
+
}
|
|
976
|
+
/**
|
|
977
|
+
* set a value with strict typing if `Values` is a Record and the key exists in it.
|
|
978
|
+
*/
|
|
979
|
+
set(key, value) {
|
|
980
|
+
this.registry.set(key, value);
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Get a value with its type
|
|
984
|
+
*/
|
|
985
|
+
get(key) {
|
|
986
|
+
return this.registry.get(key);
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Check if a key exists in the container
|
|
990
|
+
*/
|
|
991
|
+
has(key) {
|
|
992
|
+
return this.registry.has(key);
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Delete a value by key
|
|
996
|
+
*/
|
|
997
|
+
delete(key) {
|
|
998
|
+
return this.registry.delete(key);
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Clear all values from the container
|
|
1002
|
+
*/
|
|
1003
|
+
clear() {
|
|
1004
|
+
this.registry.clear();
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Get all keys in the container
|
|
1008
|
+
*/
|
|
1009
|
+
keys() {
|
|
1010
|
+
return this.registry.keys();
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Get all values in the container
|
|
1014
|
+
*/
|
|
1015
|
+
values() {
|
|
1016
|
+
return this.registry.values();
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Get all entries in the container.
|
|
1020
|
+
* Returns a discriminated union of tuples for proper type narrowing when iterating.
|
|
1021
|
+
*/
|
|
1022
|
+
entries() {
|
|
1023
|
+
return this.registry.entries();
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Get the size of the container
|
|
1027
|
+
*/
|
|
1028
|
+
size() {
|
|
1029
|
+
return this.registry.size;
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Execute a function for each entry in the container.
|
|
1033
|
+
* The callback receives properly typed key-value pairs.
|
|
1034
|
+
*/
|
|
1035
|
+
forEach(callbackfn) {
|
|
1036
|
+
this.registry.forEach(callbackfn);
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Custom JSON serialization method.
|
|
1040
|
+
* Converts the internal Map to a plain object for proper JSON serialization.
|
|
1041
|
+
* Non-serializable values (e.g., RPC proxies, functions, circular references)
|
|
1042
|
+
* are skipped to prevent serialization errors when storing to database.
|
|
1043
|
+
*/
|
|
1044
|
+
toJSON() {
|
|
1045
|
+
const result = {};
|
|
1046
|
+
for (const [key, value] of this.registry.entries()) {
|
|
1047
|
+
if (this.isSerializable(value)) {
|
|
1048
|
+
result[key] = value;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return result;
|
|
1052
|
+
}
|
|
1053
|
+
/**
|
|
1054
|
+
* Check if a value can be safely serialized to JSON.
|
|
1055
|
+
*/
|
|
1056
|
+
isSerializable(value) {
|
|
1057
|
+
if (value === null || value === void 0) return true;
|
|
1058
|
+
if (typeof value === "function") return false;
|
|
1059
|
+
if (typeof value === "symbol") return false;
|
|
1060
|
+
if (typeof value !== "object") return true;
|
|
1061
|
+
try {
|
|
1062
|
+
JSON.stringify(value);
|
|
1063
|
+
return true;
|
|
1064
|
+
} catch {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Get all values as a typed object for destructuring.
|
|
1070
|
+
* Returns Record<string, any> when untyped, or the Values type when typed.
|
|
1071
|
+
*
|
|
1072
|
+
* @example
|
|
1073
|
+
* ```typescript
|
|
1074
|
+
* const ctx = new RequestContext<{ userId: string; apiKey: string }>();
|
|
1075
|
+
* ctx.set('userId', 'user-123');
|
|
1076
|
+
* ctx.set('apiKey', 'key-456');
|
|
1077
|
+
* const { userId, apiKey } = ctx.all;
|
|
1078
|
+
* ```
|
|
1079
|
+
*/
|
|
1080
|
+
get all() {
|
|
1081
|
+
return Object.fromEntries(this.registry);
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
function getDefaultExportFromCjs (x) {
|
|
1086
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
969
1089
|
var __create$3 = Object.create;
|
|
970
1090
|
var __defProp$5 = Object.defineProperty;
|
|
971
1091
|
var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
|
|
@@ -1033,7 +1153,7 @@ var __toESM$2 = (mod, isNodeMode, target) => (target = mod != null ? __create$2(
|
|
|
1033
1153
|
|
|
1034
1154
|
// ../_vendored/ai_v5/dist/chunk-TLQKI65U.js
|
|
1035
1155
|
var require_token_error = __commonJS$2({
|
|
1036
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token-error.js"(exports, module) {
|
|
1156
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/token-error.js"(exports$1, module) {
|
|
1037
1157
|
var __defProp2 = Object.defineProperty;
|
|
1038
1158
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
1039
1159
|
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
@@ -3081,7 +3201,7 @@ function withoutTrailingSlash(url) {
|
|
|
3081
3201
|
}
|
|
3082
3202
|
|
|
3083
3203
|
var require_get_context = __commonJS$2({
|
|
3084
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-context.js"(exports, module) {
|
|
3204
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-context.js"(exports$1, module) {
|
|
3085
3205
|
var __defProp2 = Object.defineProperty;
|
|
3086
3206
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3087
3207
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -3113,7 +3233,7 @@ var require_get_context = __commonJS$2({
|
|
|
3113
3233
|
}
|
|
3114
3234
|
});
|
|
3115
3235
|
var require_get_vercel_oidc_token = __commonJS$2({
|
|
3116
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports, module) {
|
|
3236
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.js"(exports$1, module) {
|
|
3117
3237
|
var __defProp2 = Object.defineProperty;
|
|
3118
3238
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3119
3239
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -3149,8 +3269,8 @@ var require_get_vercel_oidc_token = __commonJS$2({
|
|
|
3149
3269
|
}
|
|
3150
3270
|
try {
|
|
3151
3271
|
const [{ getTokenPayload, isExpired }, { refreshToken }] = await Promise.all([
|
|
3152
|
-
await Promise.resolve().then(() => require('./token-util-NEHG7TUY-
|
|
3153
|
-
await Promise.resolve().then(() => require('./token-6GSAFR2W-
|
|
3272
|
+
await Promise.resolve().then(() => require('./token-util-NEHG7TUY-U7CX7GS4-CfBW62uu.cjs')),
|
|
3273
|
+
await Promise.resolve().then(() => require('./token-6GSAFR2W-XRCSVUPZ-DdTrjI2X.cjs'))
|
|
3154
3274
|
]);
|
|
3155
3275
|
if (!token || isExpired(getTokenPayload(token))) {
|
|
3156
3276
|
await refreshToken();
|
|
@@ -3177,7 +3297,7 @@ ${error.message}`;
|
|
|
3177
3297
|
}
|
|
3178
3298
|
});
|
|
3179
3299
|
var require_dist = __commonJS$2({
|
|
3180
|
-
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/index.js"(exports, module) {
|
|
3300
|
+
"../../../node_modules/.pnpm/@vercel+oidc@3.0.5/node_modules/@vercel/oidc/dist/index.js"(exports$1, module) {
|
|
3181
3301
|
var __defProp2 = Object.defineProperty;
|
|
3182
3302
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3183
3303
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -5773,7 +5893,7 @@ var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(
|
|
|
5773
5893
|
mod
|
|
5774
5894
|
));
|
|
5775
5895
|
var require_secure_json_parse$1 = __commonJS$1({
|
|
5776
|
-
"../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports, module) {
|
|
5896
|
+
"../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports$1, module) {
|
|
5777
5897
|
var hasBuffer = typeof Buffer !== "undefined";
|
|
5778
5898
|
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
5779
5899
|
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
@@ -11546,6 +11666,9 @@ function sanitizeV5UIMessages(messages, filterIncompleteToolCalls = false) {
|
|
|
11546
11666
|
const msgs = messages.map((m) => {
|
|
11547
11667
|
if (m.parts.length === 0) return false;
|
|
11548
11668
|
const safeParts = m.parts.filter((p) => {
|
|
11669
|
+
if (typeof p.type === "string" && p.type.startsWith("data-")) {
|
|
11670
|
+
return false;
|
|
11671
|
+
}
|
|
11549
11672
|
if (!isToolUIPart(p)) return true;
|
|
11550
11673
|
if (filterIncompleteToolCalls) {
|
|
11551
11674
|
return p.state === "output-available" || p.state === "output-error";
|
|
@@ -12059,10 +12182,10 @@ var imageMediaTypeSignatures = [
|
|
|
12059
12182
|
var stripID3 = (data) => {
|
|
12060
12183
|
const bytes = typeof data === "string" ? convertBase64ToUint8Array(data) : data;
|
|
12061
12184
|
const id3Size = (
|
|
12062
|
-
// @ts-
|
|
12063
|
-
(bytes[6] & 127) << 21 | // @ts-
|
|
12064
|
-
(bytes[7] & 127) << 14 | // @ts-
|
|
12065
|
-
(bytes[8] & 127) << 7 | // @ts-
|
|
12185
|
+
// @ts-expect-error - bytes array access
|
|
12186
|
+
(bytes[6] & 127) << 21 | // @ts-expect-error - bytes array access
|
|
12187
|
+
(bytes[7] & 127) << 14 | // @ts-expect-error - bytes array access
|
|
12188
|
+
(bytes[8] & 127) << 7 | // @ts-expect-error - bytes array access
|
|
12066
12189
|
bytes[9] & 127
|
|
12067
12190
|
);
|
|
12068
12191
|
return bytes.slice(id3Size + 10);
|
|
@@ -12270,7 +12393,7 @@ function convertToV1Messages(messages) {
|
|
|
12270
12393
|
role: "user",
|
|
12271
12394
|
...fields,
|
|
12272
12395
|
type: "text",
|
|
12273
|
-
// @ts-
|
|
12396
|
+
// @ts-expect-error - content type mismatch in conversion
|
|
12274
12397
|
content: userContent
|
|
12275
12398
|
});
|
|
12276
12399
|
} else {
|
|
@@ -12941,7 +13064,7 @@ var MessageList$1 = class MessageList {
|
|
|
12941
13064
|
threadId,
|
|
12942
13065
|
resourceId,
|
|
12943
13066
|
generateMessageId,
|
|
12944
|
-
// @ts-
|
|
13067
|
+
// @ts-expect-error Flag for agent network messages
|
|
12945
13068
|
_agentNetworkAppend
|
|
12946
13069
|
} = {}) {
|
|
12947
13070
|
if (threadId) {
|
|
@@ -12997,6 +13120,31 @@ var MessageList$1 = class MessageList {
|
|
|
12997
13120
|
agentNetworkAppend: this._agentNetworkAppend
|
|
12998
13121
|
});
|
|
12999
13122
|
}
|
|
13123
|
+
/**
|
|
13124
|
+
* Custom serialization for tracing/observability spans.
|
|
13125
|
+
* Returns a clean representation with just the essential data,
|
|
13126
|
+
* excluding internal state tracking, methods, and implementation details.
|
|
13127
|
+
*
|
|
13128
|
+
* This is automatically called by the span serialization system when
|
|
13129
|
+
* a MessageList instance appears in span input/output/attributes.
|
|
13130
|
+
*/
|
|
13131
|
+
serializeForSpan() {
|
|
13132
|
+
const coreMessages = this.all.aiV4.core();
|
|
13133
|
+
return {
|
|
13134
|
+
messages: coreMessages.map((msg) => ({
|
|
13135
|
+
role: msg.role,
|
|
13136
|
+
content: msg.content
|
|
13137
|
+
})),
|
|
13138
|
+
systemMessages: [
|
|
13139
|
+
// Untagged first (base instructions)
|
|
13140
|
+
...this.systemMessages.map((m) => ({ role: m.role, content: m.content })),
|
|
13141
|
+
// Tagged after (contextual additions)
|
|
13142
|
+
...Object.entries(this.taggedSystemMessages).flatMap(
|
|
13143
|
+
([tag, msgs]) => msgs.map((m) => ({ role: m.role, content: m.content, tag }))
|
|
13144
|
+
)
|
|
13145
|
+
]
|
|
13146
|
+
};
|
|
13147
|
+
}
|
|
13000
13148
|
deserialize(state) {
|
|
13001
13149
|
const data = this.stateManager.deserializeAll(state);
|
|
13002
13150
|
this.messages = data.messages;
|
|
@@ -13533,10 +13681,6 @@ var MessageList$1 = class MessageList {
|
|
|
13533
13681
|
}
|
|
13534
13682
|
};
|
|
13535
13683
|
|
|
13536
|
-
function getDefaultExportFromCjs (x) {
|
|
13537
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
13538
|
-
}
|
|
13539
|
-
|
|
13540
13684
|
new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
13541
13685
|
|
|
13542
13686
|
// ../_vendored/ai_v4/dist/chunk-OPIPXJLE.js
|
|
@@ -13566,7 +13710,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
13566
13710
|
mod
|
|
13567
13711
|
));
|
|
13568
13712
|
var require_secure_json_parse = __commonJS({
|
|
13569
|
-
"../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports, module) {
|
|
13713
|
+
"../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports$1, module) {
|
|
13570
13714
|
var hasBuffer = typeof Buffer !== "undefined";
|
|
13571
13715
|
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
13572
13716
|
var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
@@ -18992,7 +19136,7 @@ class LRUCache {
|
|
|
18992
19136
|
|
|
18993
19137
|
// ../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js
|
|
18994
19138
|
var require_fast_deep_equal = __commonJS$3({
|
|
18995
|
-
"../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports, module) {
|
|
19139
|
+
"../../node_modules/.pnpm/fast-deep-equal@3.1.3/node_modules/fast-deep-equal/index.js"(exports$1, module) {
|
|
18996
19140
|
module.exports = function equal(a, b) {
|
|
18997
19141
|
if (a === b) return true;
|
|
18998
19142
|
if (a && b && typeof a == "object" && typeof b == "object") {
|
|
@@ -20644,6 +20788,428 @@ const MessageStreaming = ({ className, ...props }) => {
|
|
|
20644
20788
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: className || MessageStreamingClass, ...props });
|
|
20645
20789
|
};
|
|
20646
20790
|
|
|
20791
|
+
function useMutation(mutationFn) {
|
|
20792
|
+
const [isPending, setIsPending] = react.useState(false);
|
|
20793
|
+
const [isSuccess, setIsSuccess] = react.useState(false);
|
|
20794
|
+
const [isError, setIsError] = react.useState(false);
|
|
20795
|
+
const [error, setError] = react.useState(null);
|
|
20796
|
+
const [data, setData] = react.useState(void 0);
|
|
20797
|
+
const mutationFnRef = react.useRef(mutationFn);
|
|
20798
|
+
mutationFnRef.current = mutationFn;
|
|
20799
|
+
const reset = react.useCallback(() => {
|
|
20800
|
+
setIsPending(false);
|
|
20801
|
+
setIsSuccess(false);
|
|
20802
|
+
setIsError(false);
|
|
20803
|
+
setError(null);
|
|
20804
|
+
setData(void 0);
|
|
20805
|
+
}, []);
|
|
20806
|
+
const mutateAsync = react.useCallback(async (variables) => {
|
|
20807
|
+
setIsPending(true);
|
|
20808
|
+
setIsSuccess(false);
|
|
20809
|
+
setIsError(false);
|
|
20810
|
+
setError(null);
|
|
20811
|
+
try {
|
|
20812
|
+
const result = await mutationFnRef.current(variables);
|
|
20813
|
+
setData(result);
|
|
20814
|
+
setIsSuccess(true);
|
|
20815
|
+
return result;
|
|
20816
|
+
} catch (err) {
|
|
20817
|
+
const typedError = err;
|
|
20818
|
+
setError(typedError);
|
|
20819
|
+
setIsError(true);
|
|
20820
|
+
throw err;
|
|
20821
|
+
} finally {
|
|
20822
|
+
setIsPending(false);
|
|
20823
|
+
}
|
|
20824
|
+
}, []);
|
|
20825
|
+
const mutate = react.useCallback(
|
|
20826
|
+
(variables) => {
|
|
20827
|
+
mutateAsync(variables).catch(() => {
|
|
20828
|
+
});
|
|
20829
|
+
},
|
|
20830
|
+
[mutateAsync]
|
|
20831
|
+
);
|
|
20832
|
+
return {
|
|
20833
|
+
mutate,
|
|
20834
|
+
mutateAsync,
|
|
20835
|
+
isPending,
|
|
20836
|
+
isSuccess,
|
|
20837
|
+
isError,
|
|
20838
|
+
error,
|
|
20839
|
+
data,
|
|
20840
|
+
reset
|
|
20841
|
+
};
|
|
20842
|
+
}
|
|
20843
|
+
|
|
20844
|
+
function useStreamWorkflow({ debugMode, tracingOptions, onError }) {
|
|
20845
|
+
const client = useMastraClient();
|
|
20846
|
+
const [streamResult, setStreamResult] = react.useState({});
|
|
20847
|
+
const [isStreaming, setIsStreaming] = react.useState(false);
|
|
20848
|
+
const readerRef = react.useRef(null);
|
|
20849
|
+
const observerRef = react.useRef(null);
|
|
20850
|
+
const resumeStreamRef = react.useRef(null);
|
|
20851
|
+
const timeTravelStreamRef = react.useRef(null);
|
|
20852
|
+
const isMountedRef = react.useRef(true);
|
|
20853
|
+
react.useEffect(() => {
|
|
20854
|
+
isMountedRef.current = true;
|
|
20855
|
+
return () => {
|
|
20856
|
+
isMountedRef.current = false;
|
|
20857
|
+
if (readerRef.current) {
|
|
20858
|
+
try {
|
|
20859
|
+
readerRef.current.releaseLock();
|
|
20860
|
+
} catch (error) {
|
|
20861
|
+
}
|
|
20862
|
+
readerRef.current = null;
|
|
20863
|
+
}
|
|
20864
|
+
if (observerRef.current) {
|
|
20865
|
+
try {
|
|
20866
|
+
observerRef.current.releaseLock();
|
|
20867
|
+
} catch (error) {
|
|
20868
|
+
}
|
|
20869
|
+
observerRef.current = null;
|
|
20870
|
+
}
|
|
20871
|
+
if (resumeStreamRef.current) {
|
|
20872
|
+
try {
|
|
20873
|
+
resumeStreamRef.current.releaseLock();
|
|
20874
|
+
} catch (error) {
|
|
20875
|
+
}
|
|
20876
|
+
resumeStreamRef.current = null;
|
|
20877
|
+
}
|
|
20878
|
+
if (timeTravelStreamRef.current) {
|
|
20879
|
+
try {
|
|
20880
|
+
timeTravelStreamRef.current.releaseLock();
|
|
20881
|
+
} catch (error) {
|
|
20882
|
+
}
|
|
20883
|
+
timeTravelStreamRef.current = null;
|
|
20884
|
+
}
|
|
20885
|
+
};
|
|
20886
|
+
}, []);
|
|
20887
|
+
const handleStreamError = react.useCallback(
|
|
20888
|
+
(err, defaultMessage, setStreamingState) => {
|
|
20889
|
+
if (err instanceof TypeError) {
|
|
20890
|
+
return;
|
|
20891
|
+
}
|
|
20892
|
+
const error = err instanceof Error ? err : new Error(defaultMessage);
|
|
20893
|
+
onError?.(error, defaultMessage);
|
|
20894
|
+
setStreamingState?.(false);
|
|
20895
|
+
},
|
|
20896
|
+
[onError]
|
|
20897
|
+
);
|
|
20898
|
+
const handleWorkflowFinish = react.useCallback((value) => {
|
|
20899
|
+
if (value.type === "workflow-finish") {
|
|
20900
|
+
const streamStatus = value.payload?.workflowStatus;
|
|
20901
|
+
const metadata = value.payload?.metadata;
|
|
20902
|
+
setStreamResult((prev) => ({
|
|
20903
|
+
...prev,
|
|
20904
|
+
status: streamStatus
|
|
20905
|
+
}));
|
|
20906
|
+
if (streamStatus === "failed") {
|
|
20907
|
+
throw new Error(metadata?.errorMessage || "Workflow execution failed");
|
|
20908
|
+
}
|
|
20909
|
+
}
|
|
20910
|
+
}, []);
|
|
20911
|
+
const streamWorkflow = useMutation(
|
|
20912
|
+
async ({ workflowId, runId, inputData, initialState, requestContext: playgroundRequestContext, perStep }) => {
|
|
20913
|
+
if (readerRef.current) {
|
|
20914
|
+
readerRef.current.releaseLock();
|
|
20915
|
+
}
|
|
20916
|
+
if (!isMountedRef.current) return;
|
|
20917
|
+
setIsStreaming(true);
|
|
20918
|
+
setStreamResult({ input: inputData });
|
|
20919
|
+
const requestContext = new RequestContext();
|
|
20920
|
+
Object.entries(playgroundRequestContext).forEach(([key, value]) => {
|
|
20921
|
+
requestContext.set(key, value);
|
|
20922
|
+
});
|
|
20923
|
+
const workflow = client.getWorkflow(workflowId);
|
|
20924
|
+
const run = await workflow.createRun({ runId });
|
|
20925
|
+
const stream = await run.stream({
|
|
20926
|
+
inputData,
|
|
20927
|
+
initialState,
|
|
20928
|
+
requestContext,
|
|
20929
|
+
closeOnSuspend: true,
|
|
20930
|
+
tracingOptions,
|
|
20931
|
+
perStep: perStep ?? debugMode
|
|
20932
|
+
});
|
|
20933
|
+
if (!stream) {
|
|
20934
|
+
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
20935
|
+
}
|
|
20936
|
+
const reader = stream.getReader();
|
|
20937
|
+
readerRef.current = reader;
|
|
20938
|
+
try {
|
|
20939
|
+
while (true) {
|
|
20940
|
+
if (!isMountedRef.current) break;
|
|
20941
|
+
const { done, value } = await reader.read();
|
|
20942
|
+
if (done) break;
|
|
20943
|
+
if (isMountedRef.current) {
|
|
20944
|
+
setStreamResult((prev) => {
|
|
20945
|
+
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
20946
|
+
return newResult;
|
|
20947
|
+
});
|
|
20948
|
+
if (value.type === "workflow-step-start") {
|
|
20949
|
+
setIsStreaming(true);
|
|
20950
|
+
}
|
|
20951
|
+
if (value.type === "workflow-step-suspended") {
|
|
20952
|
+
setIsStreaming(false);
|
|
20953
|
+
}
|
|
20954
|
+
if (value.type === "workflow-finish") {
|
|
20955
|
+
handleWorkflowFinish(value);
|
|
20956
|
+
}
|
|
20957
|
+
}
|
|
20958
|
+
}
|
|
20959
|
+
} catch (err) {
|
|
20960
|
+
handleStreamError(err, "Error streaming workflow");
|
|
20961
|
+
} finally {
|
|
20962
|
+
if (isMountedRef.current) {
|
|
20963
|
+
setIsStreaming(false);
|
|
20964
|
+
}
|
|
20965
|
+
if (readerRef.current) {
|
|
20966
|
+
readerRef.current.releaseLock();
|
|
20967
|
+
readerRef.current = null;
|
|
20968
|
+
}
|
|
20969
|
+
}
|
|
20970
|
+
}
|
|
20971
|
+
);
|
|
20972
|
+
const observeWorkflowStream = useMutation(
|
|
20973
|
+
async ({ workflowId, runId, storeRunResult }) => {
|
|
20974
|
+
if (observerRef.current) {
|
|
20975
|
+
observerRef.current.releaseLock();
|
|
20976
|
+
}
|
|
20977
|
+
if (!isMountedRef.current) return;
|
|
20978
|
+
setIsStreaming(true);
|
|
20979
|
+
setStreamResult(storeRunResult || {});
|
|
20980
|
+
if (storeRunResult?.status === "suspended") {
|
|
20981
|
+
setIsStreaming(false);
|
|
20982
|
+
return;
|
|
20983
|
+
}
|
|
20984
|
+
const workflow = client.getWorkflow(workflowId);
|
|
20985
|
+
const run = await workflow.createRun({ runId });
|
|
20986
|
+
const stream = await run.observeStream();
|
|
20987
|
+
if (!stream) {
|
|
20988
|
+
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
20989
|
+
}
|
|
20990
|
+
const reader = stream.getReader();
|
|
20991
|
+
observerRef.current = reader;
|
|
20992
|
+
try {
|
|
20993
|
+
while (true) {
|
|
20994
|
+
if (!isMountedRef.current) break;
|
|
20995
|
+
const { done, value } = await reader.read();
|
|
20996
|
+
if (done) break;
|
|
20997
|
+
if (isMountedRef.current) {
|
|
20998
|
+
setStreamResult((prev) => {
|
|
20999
|
+
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
21000
|
+
return newResult;
|
|
21001
|
+
});
|
|
21002
|
+
if (value.type === "workflow-step-start") {
|
|
21003
|
+
setIsStreaming(true);
|
|
21004
|
+
}
|
|
21005
|
+
if (value.type === "workflow-step-suspended") {
|
|
21006
|
+
setIsStreaming(false);
|
|
21007
|
+
}
|
|
21008
|
+
if (value.type === "workflow-finish") {
|
|
21009
|
+
handleWorkflowFinish(value);
|
|
21010
|
+
}
|
|
21011
|
+
}
|
|
21012
|
+
}
|
|
21013
|
+
} catch (err) {
|
|
21014
|
+
handleStreamError(err, "Error observing workflow");
|
|
21015
|
+
} finally {
|
|
21016
|
+
if (isMountedRef.current) {
|
|
21017
|
+
setIsStreaming(false);
|
|
21018
|
+
}
|
|
21019
|
+
if (observerRef.current) {
|
|
21020
|
+
observerRef.current.releaseLock();
|
|
21021
|
+
observerRef.current = null;
|
|
21022
|
+
}
|
|
21023
|
+
}
|
|
21024
|
+
}
|
|
21025
|
+
);
|
|
21026
|
+
const resumeWorkflowStream = useMutation(
|
|
21027
|
+
async ({ workflowId, runId, step, resumeData, requestContext: playgroundRequestContext, perStep }) => {
|
|
21028
|
+
if (resumeStreamRef.current) {
|
|
21029
|
+
resumeStreamRef.current.releaseLock();
|
|
21030
|
+
}
|
|
21031
|
+
if (!isMountedRef.current) return;
|
|
21032
|
+
setIsStreaming(true);
|
|
21033
|
+
const workflow = client.getWorkflow(workflowId);
|
|
21034
|
+
const requestContext = new RequestContext();
|
|
21035
|
+
Object.entries(playgroundRequestContext).forEach(([key, value]) => {
|
|
21036
|
+
requestContext.set(key, value);
|
|
21037
|
+
});
|
|
21038
|
+
const run = await workflow.createRun({ runId });
|
|
21039
|
+
const stream = await run.resumeStream({
|
|
21040
|
+
step,
|
|
21041
|
+
resumeData,
|
|
21042
|
+
requestContext,
|
|
21043
|
+
tracingOptions,
|
|
21044
|
+
perStep: perStep ?? debugMode
|
|
21045
|
+
});
|
|
21046
|
+
if (!stream) {
|
|
21047
|
+
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
21048
|
+
}
|
|
21049
|
+
const reader = stream.getReader();
|
|
21050
|
+
resumeStreamRef.current = reader;
|
|
21051
|
+
try {
|
|
21052
|
+
while (true) {
|
|
21053
|
+
if (!isMountedRef.current) break;
|
|
21054
|
+
const { done, value } = await reader.read();
|
|
21055
|
+
if (done) break;
|
|
21056
|
+
if (isMountedRef.current) {
|
|
21057
|
+
setStreamResult((prev) => {
|
|
21058
|
+
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
21059
|
+
return newResult;
|
|
21060
|
+
});
|
|
21061
|
+
if (value.type === "workflow-step-start") {
|
|
21062
|
+
setIsStreaming(true);
|
|
21063
|
+
}
|
|
21064
|
+
if (value.type === "workflow-step-suspended") {
|
|
21065
|
+
setIsStreaming(false);
|
|
21066
|
+
}
|
|
21067
|
+
if (value.type === "workflow-finish") {
|
|
21068
|
+
handleWorkflowFinish(value);
|
|
21069
|
+
}
|
|
21070
|
+
}
|
|
21071
|
+
}
|
|
21072
|
+
} catch (err) {
|
|
21073
|
+
handleStreamError(err, "Error resuming workflow stream");
|
|
21074
|
+
} finally {
|
|
21075
|
+
if (isMountedRef.current) {
|
|
21076
|
+
setIsStreaming(false);
|
|
21077
|
+
}
|
|
21078
|
+
if (resumeStreamRef.current) {
|
|
21079
|
+
resumeStreamRef.current.releaseLock();
|
|
21080
|
+
resumeStreamRef.current = null;
|
|
21081
|
+
}
|
|
21082
|
+
}
|
|
21083
|
+
}
|
|
21084
|
+
);
|
|
21085
|
+
const timeTravelWorkflowStream = useMutation(
|
|
21086
|
+
async ({ workflowId, requestContext: playgroundRequestContext, runId, perStep, ...params }) => {
|
|
21087
|
+
if (timeTravelStreamRef.current) {
|
|
21088
|
+
timeTravelStreamRef.current.releaseLock();
|
|
21089
|
+
}
|
|
21090
|
+
if (!isMountedRef.current) return;
|
|
21091
|
+
setIsStreaming(true);
|
|
21092
|
+
const workflow = client.getWorkflow(workflowId);
|
|
21093
|
+
const requestContext = new RequestContext();
|
|
21094
|
+
Object.entries(playgroundRequestContext).forEach(([key, value]) => {
|
|
21095
|
+
requestContext.set(key, value);
|
|
21096
|
+
});
|
|
21097
|
+
const run = await workflow.createRun({ runId });
|
|
21098
|
+
const stream = await run.timeTravelStream({
|
|
21099
|
+
...params,
|
|
21100
|
+
perStep: perStep ?? debugMode,
|
|
21101
|
+
requestContext,
|
|
21102
|
+
tracingOptions
|
|
21103
|
+
});
|
|
21104
|
+
if (!stream) {
|
|
21105
|
+
return handleStreamError(new Error("No stream returned"), "No stream returned", setIsStreaming);
|
|
21106
|
+
}
|
|
21107
|
+
const reader = stream.getReader();
|
|
21108
|
+
timeTravelStreamRef.current = reader;
|
|
21109
|
+
try {
|
|
21110
|
+
while (true) {
|
|
21111
|
+
if (!isMountedRef.current) break;
|
|
21112
|
+
const { done, value } = await reader.read();
|
|
21113
|
+
if (done) break;
|
|
21114
|
+
if (isMountedRef.current) {
|
|
21115
|
+
setStreamResult((prev) => {
|
|
21116
|
+
const newResult = mapWorkflowStreamChunkToWatchResult(prev, value);
|
|
21117
|
+
return newResult;
|
|
21118
|
+
});
|
|
21119
|
+
if (value.type === "workflow-step-start") {
|
|
21120
|
+
setIsStreaming(true);
|
|
21121
|
+
}
|
|
21122
|
+
if (value.type === "workflow-step-suspended") {
|
|
21123
|
+
setIsStreaming(false);
|
|
21124
|
+
}
|
|
21125
|
+
if (value.type === "workflow-finish") {
|
|
21126
|
+
handleWorkflowFinish(value);
|
|
21127
|
+
}
|
|
21128
|
+
}
|
|
21129
|
+
}
|
|
21130
|
+
} catch (err) {
|
|
21131
|
+
handleStreamError(err, "Error time traveling workflow stream");
|
|
21132
|
+
} finally {
|
|
21133
|
+
if (isMountedRef.current) {
|
|
21134
|
+
setIsStreaming(false);
|
|
21135
|
+
}
|
|
21136
|
+
if (timeTravelStreamRef.current) {
|
|
21137
|
+
timeTravelStreamRef.current.releaseLock();
|
|
21138
|
+
timeTravelStreamRef.current = null;
|
|
21139
|
+
}
|
|
21140
|
+
}
|
|
21141
|
+
}
|
|
21142
|
+
);
|
|
21143
|
+
const closeStreamsAndReset = react.useCallback(() => {
|
|
21144
|
+
setIsStreaming(false);
|
|
21145
|
+
setStreamResult({});
|
|
21146
|
+
if (readerRef.current) {
|
|
21147
|
+
try {
|
|
21148
|
+
readerRef.current.releaseLock();
|
|
21149
|
+
} catch (error) {
|
|
21150
|
+
}
|
|
21151
|
+
readerRef.current = null;
|
|
21152
|
+
}
|
|
21153
|
+
if (observerRef.current) {
|
|
21154
|
+
try {
|
|
21155
|
+
observerRef.current.releaseLock();
|
|
21156
|
+
} catch (error) {
|
|
21157
|
+
}
|
|
21158
|
+
observerRef.current = null;
|
|
21159
|
+
}
|
|
21160
|
+
if (resumeStreamRef.current) {
|
|
21161
|
+
try {
|
|
21162
|
+
resumeStreamRef.current.releaseLock();
|
|
21163
|
+
} catch (error) {
|
|
21164
|
+
}
|
|
21165
|
+
resumeStreamRef.current = null;
|
|
21166
|
+
}
|
|
21167
|
+
if (timeTravelStreamRef.current) {
|
|
21168
|
+
try {
|
|
21169
|
+
timeTravelStreamRef.current.releaseLock();
|
|
21170
|
+
} catch (error) {
|
|
21171
|
+
}
|
|
21172
|
+
timeTravelStreamRef.current = null;
|
|
21173
|
+
}
|
|
21174
|
+
}, []);
|
|
21175
|
+
return {
|
|
21176
|
+
streamWorkflow,
|
|
21177
|
+
streamResult,
|
|
21178
|
+
isStreaming,
|
|
21179
|
+
observeWorkflowStream,
|
|
21180
|
+
closeStreamsAndReset,
|
|
21181
|
+
resumeWorkflowStream,
|
|
21182
|
+
timeTravelWorkflowStream
|
|
21183
|
+
};
|
|
21184
|
+
}
|
|
21185
|
+
|
|
21186
|
+
function useCreateWorkflowRun() {
|
|
21187
|
+
const client = useMastraClient();
|
|
21188
|
+
return useMutation(async ({ workflowId, prevRunId }) => {
|
|
21189
|
+
try {
|
|
21190
|
+
const workflow = client.getWorkflow(workflowId);
|
|
21191
|
+
const { runId: newRunId } = await workflow.createRun({ runId: prevRunId });
|
|
21192
|
+
return { runId: newRunId };
|
|
21193
|
+
} catch (error) {
|
|
21194
|
+
console.error("Error creating workflow run:", error);
|
|
21195
|
+
throw error;
|
|
21196
|
+
}
|
|
21197
|
+
});
|
|
21198
|
+
}
|
|
21199
|
+
function useCancelWorkflowRun() {
|
|
21200
|
+
const client = useMastraClient();
|
|
21201
|
+
return useMutation(async ({ workflowId, runId }) => {
|
|
21202
|
+
try {
|
|
21203
|
+
const workflow = client.getWorkflow(workflowId);
|
|
21204
|
+
const run = await workflow.createRun({ runId });
|
|
21205
|
+
return run.cancelRun();
|
|
21206
|
+
} catch (error) {
|
|
21207
|
+
console.error("Error canceling workflow run:", error);
|
|
21208
|
+
throw error;
|
|
21209
|
+
}
|
|
21210
|
+
});
|
|
21211
|
+
}
|
|
21212
|
+
|
|
20647
21213
|
exports.AgentIcon = AgentIcon;
|
|
20648
21214
|
exports.CodeBlock = CodeBlock;
|
|
20649
21215
|
exports.CodeBlockClass = CodeBlockClass;
|
|
@@ -20705,7 +21271,10 @@ exports.require_token_error = require_token_error;
|
|
|
20705
21271
|
exports.resolveToChildMessages = resolveToChildMessages;
|
|
20706
21272
|
exports.toAssistantUIMessage = toAssistantUIMessage;
|
|
20707
21273
|
exports.toUIMessage = toUIMessage;
|
|
21274
|
+
exports.useCancelWorkflowRun = useCancelWorkflowRun;
|
|
20708
21275
|
exports.useChat = useChat;
|
|
21276
|
+
exports.useCreateWorkflowRun = useCreateWorkflowRun;
|
|
20709
21277
|
exports.useEntity = useEntity;
|
|
20710
21278
|
exports.useMastraClient = useMastraClient;
|
|
20711
|
-
|
|
21279
|
+
exports.useStreamWorkflow = useStreamWorkflow;
|
|
21280
|
+
//# sourceMappingURL=index-TEBHU8EU.cjs.map
|