@mastra/client-js 1.13.5-alpha.9 → 1.14.0-alpha.10

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 CHANGED
@@ -1,5 +1,27 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 1.14.0-alpha.10
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `forEachIndex` option to `run.resume()`, `run.resumeAsync()`, and `run.resumeStream()`. Use it to resume a single iteration of a suspended `.foreach()` step while leaving the other iterations suspended. ([#15563](https://github.com/mastra-ai/mastra/pull/15563))
8
+
9
+ ```ts
10
+ await client
11
+ .getWorkflow('myWorkflow')
12
+ .createRun(runId)
13
+ .resume({
14
+ step: 'approve',
15
+ resumeData: { ok: true },
16
+ forEachIndex: 1, // only resume the second iteration
17
+ });
18
+ ```
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`aba393e`](https://github.com/mastra-ai/mastra/commit/aba393e2da7390c69b80e516a4f153cda6f09376), [`0a5fa1d`](https://github.com/mastra-ai/mastra/commit/0a5fa1d3cb0583889d06687155f26fd7d2edc76c), [`ea43e64`](https://github.com/mastra-ai/mastra/commit/ea43e646dd95d507694b6112b0bf1df22ad552b2), [`00d1b16`](https://github.com/mastra-ai/mastra/commit/00d1b16b401199cb294fa23f43336547db4dca9b), [`af8a57e`](https://github.com/mastra-ai/mastra/commit/af8a57ed9ba9685ad8601d5b71ae3706da6222f9)]:
23
+ - @mastra/core@1.26.0-alpha.10
24
+
3
25
  ## 1.13.5-alpha.9
4
26
 
5
27
  ### Patch Changes
@@ -435,6 +435,8 @@ export declare type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T
435
435
  * Attributes is a map from string to attribute values.
436
436
  *
437
437
  * Note: only the own enumerable keys are counted as valid attribute keys.
438
+ *
439
+ * @since 1.3.0
438
440
  */
439
441
  declare interface Attributes {
440
442
  [attributeKey: string]: AttributeValue | undefined;
@@ -444,6 +446,8 @@ declare interface Attributes {
444
446
  * Attribute values may be any non-nullish primitive value except an object.
445
447
  *
446
448
  * null or undefined attribute values are invalid and will result in undefined behavior.
449
+ *
450
+ * @since 1.3.0
447
451
  */
448
452
  declare type AttributeValue = string | number | boolean | Array<null | undefined | string> | Array<null | undefined | number> | Array<null | undefined | boolean>;
449
453
 
@@ -778,6 +782,9 @@ export declare type ContentPart<TOOLS extends ToolSet> = {
778
782
  providerMetadata?: ProviderMetadata;
779
783
  });
780
784
 
785
+ /**
786
+ * @since 1.0.0
787
+ */
781
788
  declare interface Context {
782
789
  /**
783
790
  * Get a value from the context.
@@ -1705,6 +1712,8 @@ declare class EventSourceParserStream extends TransformStream<string, EventSourc
1705
1712
  * Defines Exception.
1706
1713
  *
1707
1714
  * string or an object with one of (message or name or code) and optional stack
1715
+ *
1716
+ * @since 1.0.0
1708
1717
  */
1709
1718
  declare type Exception = ExceptionWithCode | ExceptionWithMessage | ExceptionWithName | string;
1710
1719
 
@@ -2973,6 +2982,8 @@ export declare function hasToolCall(toolName: string): StopCondition<any>;
2973
2982
  * The second number is calculated by converting the digits after the decimal point of the subtraction, (1609504210150 / 1000) - HrTime[0], to nanoseconds:
2974
2983
  * HrTime[1] = Number((1609504210.150 - HrTime[0]).toFixed(9)) * 1e9 = 150000000.
2975
2984
  * This is represented in HrTime format as [1609504210, 150000000].
2985
+ *
2986
+ * @since 1.0.0
2976
2987
  */
2977
2988
  declare type HrTime = [number, number];
2978
2989
 
@@ -5546,6 +5557,8 @@ declare function lazyValidator<OBJECT>(createValidator: () => Validator<OBJECT>)
5546
5557
  * However, it is desirable to associate incoming SpanContext to new trace
5547
5558
  * initiated on service provider side so two traces (from Client and from
5548
5559
  * Service Provider) can be correlated.
5560
+ *
5561
+ * @since 1.0.0
5549
5562
  */
5550
5563
  declare interface Link {
5551
5564
  /** The {@link SpanContext} of a linked span. */
@@ -7019,6 +7032,8 @@ export declare type SourceUrlUIPart = {
7019
7032
  * may have children.
7020
7033
  *
7021
7034
  * Spans are created by the {@link Tracer.startSpan} method.
7035
+ *
7036
+ * @since 1.0.0
7022
7037
  */
7023
7038
  declare interface Span {
7024
7039
  /**
@@ -7078,11 +7093,21 @@ declare interface Span {
7078
7093
  */
7079
7094
  addLinks(links: Link[]): this;
7080
7095
  /**
7081
- * Sets a status to the span. If used, this will override the default Span
7082
- * status. Default is {@link SpanStatusCode.UNSET}. SetStatus overrides the value
7083
- * of previous calls to SetStatus on the Span.
7096
+ * Sets the status of the span.
7097
+ *
7098
+ * By default, a span has status {@link SpanStatusCode.UNSET}.
7099
+ * Calling this method overrides that default.
7100
+ *
7101
+ * The status codes have a total order: `OK > ERROR > UNSET`.
7102
+ *
7103
+ * - Once {@link SpanStatusCode.OK} is set, any further attempts to change
7104
+ * the status are ignored.
7105
+ * - Any attempt to set {@link SpanStatusCode.UNSET} is always ignored.
7106
+ *
7107
+ * The `message` field is only used when {@link SpanStatusCode.ERROR} is set.
7108
+ * For all other status codes, `message` is ignored.
7084
7109
  *
7085
- * @param status the SpanStatus to set.
7110
+ * @param status The {@link SpanStatus} to set.
7086
7111
  */
7087
7112
  setStatus(status: SpanStatus): this;
7088
7113
  /**
@@ -7127,17 +7152,21 @@ declare interface Span {
7127
7152
 
7128
7153
  /**
7129
7154
  * @deprecated please use {@link Attributes}
7155
+ * @since 1.0.0
7130
7156
  */
7131
7157
  declare type SpanAttributes = Attributes;
7132
7158
 
7133
7159
  /**
7134
7160
  * @deprecated please use {@link AttributeValue}
7161
+ * @since 1.0.0
7135
7162
  */
7136
7163
  declare type SpanAttributeValue = AttributeValue;
7137
7164
 
7138
7165
  /**
7139
7166
  * A SpanContext represents the portion of a {@link Span} which must be
7140
7167
  * serialized and propagated along side of a {@link Baggage}.
7168
+ *
7169
+ * @since 1.0.0
7141
7170
  */
7142
7171
  declare interface SpanContext {
7143
7172
  /**
@@ -7187,6 +7216,9 @@ declare interface SpanContext {
7187
7216
  traceState?: TraceState;
7188
7217
  }
7189
7218
 
7219
+ /**
7220
+ * @since 1.0.0
7221
+ */
7190
7222
  declare enum SpanKind {
7191
7223
  /** Default value. Indicates that the span is used internally. */
7192
7224
  INTERNAL = 0,
@@ -7216,6 +7248,8 @@ declare enum SpanKind {
7216
7248
 
7217
7249
  /**
7218
7250
  * Options needed for span creation
7251
+ *
7252
+ * @since 1.0.0
7219
7253
  */
7220
7254
  declare interface SpanOptions {
7221
7255
  /**
@@ -7224,7 +7258,7 @@ declare interface SpanOptions {
7224
7258
  */
7225
7259
  kind?: SpanKind;
7226
7260
  /** A span's attributes */
7227
- attributes?: SpanAttributes;
7261
+ attributes?: Attributes;
7228
7262
  /** {@link Link}s span to other spans */
7229
7263
  links?: Link[];
7230
7264
  /** A manually specified start time for the created `Span` object. */
@@ -7233,6 +7267,9 @@ declare interface SpanOptions {
7233
7267
  root?: boolean;
7234
7268
  }
7235
7269
 
7270
+ /**
7271
+ * @since 1.0.0
7272
+ */
7236
7273
  declare interface SpanStatus {
7237
7274
  /** The status code of this message. */
7238
7275
  code: SpanStatusCode;
@@ -7242,6 +7279,8 @@ declare interface SpanStatus {
7242
7279
 
7243
7280
  /**
7244
7281
  * An enumeration of status codes.
7282
+ *
7283
+ * @since 1.0.0
7245
7284
  */
7246
7285
  declare enum SpanStatusCode {
7247
7286
  /**
@@ -8798,6 +8837,8 @@ export declare type TextUIPart = {
8798
8837
  * Defines TimeInput.
8799
8838
  *
8800
8839
  * hrtime, epoch milliseconds, performance.now() or Date
8840
+ *
8841
+ * @since 1.0.0
8801
8842
  */
8802
8843
  declare type TimeInput = HrTime | number | Date;
8803
8844
 
@@ -9142,6 +9183,8 @@ export declare class TooManyEmbeddingValuesForCallError extends AISDKError {
9142
9183
 
9143
9184
  /**
9144
9185
  * Tracer provides an interface for creating {@link Span}s.
9186
+ *
9187
+ * @since 1.0.0
9145
9188
  */
9146
9189
  declare interface Tracer {
9147
9190
  /**
@@ -9208,6 +9251,9 @@ declare interface Tracer {
9208
9251
  startActiveSpan<F extends (span: Span) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): ReturnType<F>;
9209
9252
  }
9210
9253
 
9254
+ /**
9255
+ * @since 1.0.0
9256
+ */
9211
9257
  declare interface TraceState {
9212
9258
  /**
9213
9259
  * Create a new TraceState which inherits from this TraceState and has the
@@ -3,7 +3,7 @@ name: mastra-client-js
3
3
  description: Documentation for @mastra/client-js. Use when working with @mastra/client-js APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/client-js"
6
- version: "1.13.5-alpha.9"
6
+ version: "1.14.0-alpha.10"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.13.5-alpha.9",
2
+ "version": "1.14.0-alpha.10",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {
5
5
  "RequestContext": {
@@ -214,6 +214,75 @@ curl http://localhost:4111/agents/support-agent?versionId=abc-123
214
214
 
215
215
  See the [Client SDK agents reference](https://mastra.ai/reference/client-js/agents) for API methods.
216
216
 
217
+ ### Sub-agent versioning
218
+
219
+ When a [supervisor agent](https://mastra.ai/docs/agents/supervisor-agents) delegates to sub-agents, version overrides determine which stored version of each sub-agent to use instead of the code-defined default. This lets you iterate on sub-agent prompts and tools through the editor without redeploying the supervisor.
220
+
221
+ Set version overrides at three levels, with later levels taking priority:
222
+
223
+ 1. **Mastra instance config** — global defaults that apply to every `generate()` and `stream()` call.
224
+ 2. **Per-invocation options** — overrides passed directly to `generate()` or `stream()`.
225
+ 3. **Server request body** — overrides sent in the `versions` field of an API request.
226
+
227
+ Resolution order: **per-invocation > request body > Mastra instance defaults > code-defined agent**.
228
+
229
+ #### Mastra instance config
230
+
231
+ Set global defaults when creating the `Mastra` instance. Every supervisor call inherits these overrides:
232
+
233
+ ```typescript
234
+ import { Mastra } from '@mastra/core'
235
+ import { MastraEditor } from '@mastra/editor'
236
+
237
+ export const mastra = new Mastra({
238
+ agents: { supervisor, researchAgent, writerAgent },
239
+ editor: new MastraEditor(),
240
+ versions: {
241
+ agents: {
242
+ 'research-agent': { status: 'published' },
243
+ 'writer-agent': { versionId: 'abc-123' },
244
+ },
245
+ },
246
+ })
247
+ ```
248
+
249
+ #### Per-invocation overrides
250
+
251
+ Override versions for a single call to `generate()` or `stream()`. These take priority over Mastra instance defaults:
252
+
253
+ ```typescript
254
+ const result = await supervisor.generate('Research and write an article about AI safety', {
255
+ versions: {
256
+ agents: {
257
+ 'research-agent': { versionId: 'draft-456' },
258
+ },
259
+ },
260
+ })
261
+ ```
262
+
263
+ #### Server request body
264
+
265
+ When calling agents through the Mastra server, pass version overrides in the request body:
266
+
267
+ ```bash
268
+ curl -X POST http://localhost:4111/agents/supervisor/generate \
269
+ -H "Content-Type: application/json" \
270
+ -d '{
271
+ "messages": [{ "role": "user", "content": "Research AI safety" }],
272
+ "versions": {
273
+ "agents": {
274
+ "research-agent": { "versionId": "draft-456" }
275
+ }
276
+ }
277
+ }'
278
+ ```
279
+
280
+ #### How propagation works
281
+
282
+ Version overrides propagate automatically through sub-agent delegation via `requestContext`. When a supervisor delegates to a sub-agent, the framework checks if a version override exists for that sub-agent's ID. If one is found, it resolves the stored version from the editor and uses it instead of the code-defined default.
283
+
284
+ If version resolution fails (for example, when the editor is not configured or the version ID doesn't exist), the framework logs a warning and falls back to the code-defined agent.
285
+
217
286
  ## Next steps
218
287
 
219
288
  - Set up [prompts](https://mastra.ai/docs/editor/prompts) to build reusable instruction templates.
@@ -140,6 +140,18 @@ await run.resume({
140
140
  })
141
141
  ```
142
142
 
143
+ When a [`.foreach()`](https://mastra.ai/reference/workflows/workflow-methods/foreach) step suspends across multiple iterations, pass `forEachIndex` (zero-based; `0` targets the first iteration) to resume one iteration at a time. Iterations you don't target remain suspended.
144
+
145
+ ```typescript
146
+ await run.resume({
147
+ step: 'approve',
148
+ resumeData: { ok: true },
149
+ forEachIndex: 1, // resumes the second iteration
150
+ })
151
+ ```
152
+
153
+ `forEachIndex` is also supported by `resumeAsync()` and `resumeStream()`.
154
+
143
155
  ### `cancel()`
144
156
 
145
157
  Cancel a running workflow:
package/dist/index.cjs CHANGED
@@ -2159,6 +2159,7 @@ var Run = class extends BaseResource {
2159
2159
  resumeData,
2160
2160
  tracingOptions,
2161
2161
  perStep,
2162
+ forEachIndex,
2162
2163
  ...rest
2163
2164
  }) {
2164
2165
  const requestContext = parseClientRequestContext(rest.requestContext);
@@ -2169,7 +2170,8 @@ var Run = class extends BaseResource {
2169
2170
  resumeData,
2170
2171
  requestContext,
2171
2172
  tracingOptions,
2172
- perStep
2173
+ perStep,
2174
+ forEachIndex
2173
2175
  }
2174
2176
  });
2175
2177
  }
@@ -2260,7 +2262,8 @@ var Run = class extends BaseResource {
2260
2262
  resumeData: params.resumeData,
2261
2263
  requestContext,
2262
2264
  tracingOptions: params.tracingOptions,
2263
- perStep: params.perStep
2265
+ perStep: params.perStep,
2266
+ forEachIndex: params.forEachIndex
2264
2267
  }
2265
2268
  }).then(deserializeWorkflowError);
2266
2269
  }
@@ -2282,7 +2285,8 @@ var Run = class extends BaseResource {
2282
2285
  resumeData: params.resumeData,
2283
2286
  requestContext,
2284
2287
  tracingOptions: params.tracingOptions,
2285
- perStep: params.perStep
2288
+ perStep: params.perStep,
2289
+ forEachIndex: params.forEachIndex
2286
2290
  },
2287
2291
  stream: true
2288
2292
  }