@mastra/react 0.2.9-alpha.0 → 0.2.10-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/dist/index.js CHANGED
@@ -1,14 +1,12 @@
1
1
  import { MastraClient } from '@mastra/client-js';
2
2
  import { createContext, useContext, useRef, useState, useEffect, useLayoutEffect, useCallback, Fragment } from 'react';
3
- import { jsxs, jsx } from 'react/jsx-runtime';
3
+ import { jsx, jsxs } from 'react/jsx-runtime';
4
4
  import { v4 } from '@lukeed/uuid';
5
- import { formatStreamCompletionFeedback, formatCompletionFeedback } from '@mastra/core/loop';
6
5
  import { ChevronDownIcon, CheckIcon, CopyIcon } from 'lucide-react';
7
6
  import { twMerge } from 'tailwind-merge';
8
7
  import { TooltipProvider, Root, TooltipPortal, TooltipContent as TooltipContent$1, TooltipTrigger as TooltipTrigger$1 } from '@radix-ui/react-tooltip';
9
8
  import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
10
9
  import { codeToHast } from 'shiki/bundle/web';
11
- import { RequestContext } from '@mastra/core/request-context';
12
10
 
13
11
  // src/mastra-client-context.tsx
14
12
  var MastraClientContext = createContext({});
@@ -42,6 +40,53 @@ var createMastraClient = (baseUrl, mastraClientHeaders = {}, apiPrefix) => {
42
40
  var MastraReactProvider = ({ children, baseUrl, headers, apiPrefix }) => {
43
41
  return /* @__PURE__ */ jsx(MastraClientProvider, { baseUrl, headers, apiPrefix, children });
44
42
  };
43
+
44
+ // src/lib/ai-sdk/utils/formatCompletionFeedback.ts
45
+ var formatBaseCompletionFeedback = (result, maxIterationReached, formatScorerHeading, incompleteMessage) => {
46
+ const lines = [];
47
+ lines.push("#### Completion Check Results");
48
+ lines.push("");
49
+ lines.push(`Overall: ${result.complete ? "\u2705 COMPLETE" : "\u274C NOT COMPLETE"}`);
50
+ lines.push(`Duration: ${result.totalDuration}ms`);
51
+ if (result.timedOut) {
52
+ lines.push("\u26A0\uFE0F Scoring timed out");
53
+ }
54
+ lines.push("");
55
+ for (const scorer of result.scorers) {
56
+ lines.push(formatScorerHeading(scorer));
57
+ lines.push(`Score: ${scorer.score} ${scorer.passed ? "\u2705" : "\u274C"}`);
58
+ if (scorer.reason) {
59
+ lines.push(`Reason: ${scorer.reason}`);
60
+ }
61
+ lines.push("");
62
+ }
63
+ if (result.complete) {
64
+ lines.push("\u2705 The task is complete.");
65
+ } else if (maxIterationReached) {
66
+ lines.push("\u26A0\uFE0F Max iterations reached.");
67
+ } else {
68
+ lines.push(incompleteMessage);
69
+ }
70
+ return lines.join("\n");
71
+ };
72
+ var formatCompletionFeedback = (result, maxIterationReached) => {
73
+ return formatBaseCompletionFeedback(
74
+ result,
75
+ maxIterationReached,
76
+ (scorer) => `###### ${scorer.scorerName} (${scorer.scorerId})`,
77
+ "\u{1F504} Will continue working on the task."
78
+ );
79
+ };
80
+ var formatStreamCompletionFeedback = (result, maxIterationReached) => {
81
+ return formatBaseCompletionFeedback(
82
+ result,
83
+ maxIterationReached,
84
+ (scorer) => `**${scorer.scorerName}** (${scorer.scorerId})`,
85
+ "\u{1F504} The task is not yet complete. Please continue working based on the feedback above."
86
+ );
87
+ };
88
+
89
+ // src/lib/ai-sdk/utils/toUIMessage.ts
45
90
  var mapWorkflowStreamChunkToWatchResult = (prev, chunk) => {
46
91
  if (chunk.type === "workflow-start") {
47
92
  return {
@@ -459,9 +504,7 @@ var toUIMessage = ({ chunk, conversation, metadata }) => {
459
504
  complete: chunk.payload.passed,
460
505
  scorers: chunk.payload.results,
461
506
  totalDuration: chunk.payload.duration,
462
- timedOut: chunk.payload.timedOut,
463
- completionReason: chunk.payload.reason
464
- },
507
+ timedOut: chunk.payload.timedOut},
465
508
  chunk.payload.maxIterationReached
466
509
  );
467
510
  const newMessage = {
@@ -1035,6 +1078,8 @@ var resolveToChildMessages = (messages) => {
1035
1078
  }
1036
1079
  return childMessages;
1037
1080
  };
1081
+
1082
+ // src/lib/ai-sdk/transformers/AISdkNetworkTransformer.ts
1038
1083
  var AISdkNetworkTransformer = class {
1039
1084
  transform({ chunk, conversation, metadata }) {
1040
1085
  const newConversation = [...conversation];
@@ -1057,9 +1102,7 @@ var AISdkNetworkTransformer = class {
1057
1102
  complete: chunk.payload.passed,
1058
1103
  scorers: chunk.payload.results,
1059
1104
  totalDuration: chunk.payload.duration,
1060
- timedOut: chunk.payload.timedOut,
1061
- completionReason: chunk.payload.reason
1062
- },
1105
+ timedOut: chunk.payload.timedOut},
1063
1106
  chunk.payload.maxIterationReached
1064
1107
  );
1065
1108
  const newMessage = {
@@ -2406,16 +2449,12 @@ function useStreamWorkflow({ debugMode, tracingOptions, onError }) {
2406
2449
  if (!isMountedRef.current) return;
2407
2450
  setIsStreaming(true);
2408
2451
  setStreamResult({ input: inputData });
2409
- const requestContext = new RequestContext();
2410
- Object.entries(playgroundRequestContext).forEach(([key, value]) => {
2411
- requestContext.set(key, value);
2412
- });
2413
2452
  const workflow = client.getWorkflow(workflowId);
2414
2453
  const run = await workflow.createRun({ runId });
2415
2454
  const stream = await run.stream({
2416
2455
  inputData,
2417
2456
  initialState,
2418
- requestContext,
2457
+ requestContext: playgroundRequestContext,
2419
2458
  closeOnSuspend: true,
2420
2459
  tracingOptions,
2421
2460
  perStep: perStep ?? debugMode
@@ -2521,15 +2560,11 @@ function useStreamWorkflow({ debugMode, tracingOptions, onError }) {
2521
2560
  if (!isMountedRef.current) return;
2522
2561
  setIsStreaming(true);
2523
2562
  const workflow = client.getWorkflow(workflowId);
2524
- const requestContext = new RequestContext();
2525
- Object.entries(playgroundRequestContext).forEach(([key, value]) => {
2526
- requestContext.set(key, value);
2527
- });
2528
2563
  const run = await workflow.createRun({ runId });
2529
2564
  const stream = await run.resumeStream({
2530
2565
  step,
2531
2566
  resumeData,
2532
- requestContext,
2567
+ requestContext: playgroundRequestContext,
2533
2568
  tracingOptions,
2534
2569
  perStep: perStep ?? debugMode
2535
2570
  });
@@ -2580,15 +2615,11 @@ function useStreamWorkflow({ debugMode, tracingOptions, onError }) {
2580
2615
  if (!isMountedRef.current) return;
2581
2616
  setIsStreaming(true);
2582
2617
  const workflow = client.getWorkflow(workflowId);
2583
- const requestContext = new RequestContext();
2584
- Object.entries(playgroundRequestContext).forEach(([key, value]) => {
2585
- requestContext.set(key, value);
2586
- });
2587
2618
  const run = await workflow.createRun({ runId });
2588
2619
  const stream = await run.timeTravelStream({
2589
2620
  ...params,
2590
2621
  perStep: perStep ?? debugMode,
2591
- requestContext,
2622
+ requestContext: playgroundRequestContext,
2592
2623
  tracingOptions
2593
2624
  });
2594
2625
  if (!stream) {