@mastra/client-js 0.10.12 → 0.10.14-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.10.12",
3
+ "version": "0.10.14-alpha.0",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -29,11 +29,12 @@
29
29
  "dependencies": {
30
30
  "@ag-ui/client": "^0.0.27",
31
31
  "@ai-sdk/ui-utils": "^1.2.11",
32
+ "@lukeed/uuid": "^2.0.1",
32
33
  "json-schema": "^0.4.0",
33
34
  "rxjs": "7.8.1",
34
35
  "zod": "^3.25.67",
35
36
  "zod-to-json-schema": "^3.24.5",
36
- "@mastra/core": "0.10.13"
37
+ "@mastra/core": "0.10.15-alpha.0"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "zod": "^3.0.0"
package/src/client.ts CHANGED
@@ -13,6 +13,8 @@ import {
13
13
  MCPTool,
14
14
  LegacyWorkflow,
15
15
  } from './resources';
16
+ import { NetworkMemoryThread } from './resources/network-memory-thread';
17
+ import { VNextNetwork } from './resources/vNextNetwork';
16
18
  import type {
17
19
  ClientOptions,
18
20
  CreateMemoryThreadParams,
@@ -38,8 +40,6 @@ import type {
38
40
  CreateNetworkMemoryThreadParams,
39
41
  SaveNetworkMessageToMemoryParams,
40
42
  } from './types';
41
- import { VNextNetwork } from './resources/vNextNetwork';
42
- import { NetworkMemoryThread } from './resources/network-memory-thread';
43
43
 
44
44
  export class MastraClient extends BaseResource {
45
45
  constructor(options: ClientOptions) {
@@ -477,4 +477,50 @@ export class MastraClient extends BaseResource {
477
477
  public getA2A(agentId: string) {
478
478
  return new A2A(this.options, agentId);
479
479
  }
480
+
481
+ /**
482
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
483
+ * @param agentId - ID of the agent.
484
+ * @param threadId - ID of the thread.
485
+ * @param resourceId - Optional ID of the resource.
486
+ * @returns Working memory for the specified thread or resource.
487
+ */
488
+ public getWorkingMemory({
489
+ agentId,
490
+ threadId,
491
+ resourceId,
492
+ }: {
493
+ agentId: string;
494
+ threadId: string;
495
+ resourceId?: string;
496
+ }) {
497
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
498
+ }
499
+
500
+ /**
501
+ * Updates the working memory for a specific thread (optionally resource-scoped).
502
+ * @param agentId - ID of the agent.
503
+ * @param threadId - ID of the thread.
504
+ * @param workingMemory - The new working memory content.
505
+ * @param resourceId - Optional ID of the resource.
506
+ */
507
+ public updateWorkingMemory({
508
+ agentId,
509
+ threadId,
510
+ workingMemory,
511
+ resourceId,
512
+ }: {
513
+ agentId: string;
514
+ threadId: string;
515
+ workingMemory: string;
516
+ resourceId?: string;
517
+ }) {
518
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
519
+ method: 'POST',
520
+ body: {
521
+ workingMemory,
522
+ resourceId,
523
+ },
524
+ });
525
+ }
480
526
  }
@@ -15,6 +15,7 @@ import type { JSONSchema7 } from 'json-schema';
15
15
  import { ZodSchema } from 'zod';
16
16
  import { zodToJsonSchema } from '../utils/zod-to-json-schema';
17
17
  import { processClientTools } from '../utils/process-client-tools';
18
+ import { v4 as uuid } from '@lukeed/uuid';
18
19
 
19
20
  import type {
20
21
  GenerateParams,
@@ -228,7 +229,7 @@ export class Agent extends BaseResource {
228
229
  const message: UIMessage = replaceLastMessage
229
230
  ? structuredClone(lastMessage)
230
231
  : {
231
- id: crypto.randomUUID(),
232
+ id: uuid(),
232
233
  createdAt: getCurrentDate(),
233
234
  role: 'assistant',
234
235
  content: '',
@@ -288,7 +289,7 @@ export class Agent extends BaseResource {
288
289
  // changes. This is why we need to add a revision id to ensure that the message
289
290
  // is updated with SWR (without it, the changes get stuck in SWR and are not
290
291
  // forwarded to rendering):
291
- revisionId: crypto.randomUUID(),
292
+ revisionId: uuid(),
292
293
  } as UIMessage;
293
294
 
294
295
  update({
@@ -10,6 +10,8 @@ import type {
10
10
  } from '../types';
11
11
 
12
12
  import { BaseResource } from './base';
13
+ import { parseClientRuntimeContext } from '../utils';
14
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
13
15
 
14
16
  const RECORD_SEPARATOR = '\x1E';
15
17
 
@@ -37,7 +39,10 @@ export class VNextNetwork extends BaseResource {
37
39
  generate(params: GenerateOrStreamVNextNetworkParams): Promise<GenerateVNextNetworkResponse> {
38
40
  return this.request(`/api/networks/v-next/${this.networkId}/generate`, {
39
41
  method: 'POST',
40
- body: params,
42
+ body: {
43
+ ...params,
44
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
45
+ },
41
46
  });
42
47
  }
43
48
 
@@ -46,10 +51,16 @@ export class VNextNetwork extends BaseResource {
46
51
  * @param params - Generation parameters including message
47
52
  * @returns Promise containing the generated response
48
53
  */
49
- loop(params: { message: string }): Promise<LoopVNextNetworkResponse> {
54
+ loop(params: {
55
+ message: string;
56
+ runtimeContext?: RuntimeContext | Record<string, any>;
57
+ }): Promise<LoopVNextNetworkResponse> {
50
58
  return this.request(`/api/networks/v-next/${this.networkId}/loop`, {
51
59
  method: 'POST',
52
- body: params,
60
+ body: {
61
+ ...params,
62
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
63
+ },
53
64
  });
54
65
  }
55
66
 
@@ -125,7 +136,10 @@ export class VNextNetwork extends BaseResource {
125
136
  async stream(params: GenerateOrStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
126
137
  const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/stream`, {
127
138
  method: 'POST',
128
- body: params,
139
+ body: {
140
+ ...params,
141
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
142
+ },
129
143
  stream: true,
130
144
  });
131
145
 
@@ -154,7 +168,10 @@ export class VNextNetwork extends BaseResource {
154
168
  async loopStream(params: LoopStreamVNextNetworkParams, onRecord: (record: WatchEvent) => void) {
155
169
  const response: Response = await this.request(`/api/networks/v-next/${this.networkId}/loop-stream`, {
156
170
  method: 'POST',
157
- body: params,
171
+ body: {
172
+ ...params,
173
+ runtimeContext: parseClientRuntimeContext(params.runtimeContext),
174
+ },
158
175
  stream: true,
159
176
  });
160
177
 
package/src/types.ts CHANGED
@@ -390,6 +390,7 @@ export interface GenerateOrStreamVNextNetworkParams {
390
390
  message: string;
391
391
  threadId?: string;
392
392
  resourceId?: string;
393
+ runtimeContext?: RuntimeContext | Record<string, any>;
393
394
  }
394
395
 
395
396
  export interface LoopStreamVNextNetworkParams {
@@ -397,6 +398,7 @@ export interface LoopStreamVNextNetworkParams {
397
398
  threadId?: string;
398
399
  resourceId?: string;
399
400
  maxIterations?: number;
401
+ runtimeContext?: RuntimeContext | Record<string, any>;
400
402
  }
401
403
 
402
404
  export interface LoopVNextNetworkResponse {