@mastra/client-js 1.20.0-alpha.0 → 1.20.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.
@@ -1,6 +1,6 @@
1
1
  # Signals
2
2
 
3
- > **Experimental:** Agent signals are experimental. Breaking changes may occur without a major version bump until the API is stable.
3
+ > **Experimental:** This feature is in alpha. Breaking changes may occur without a major version bump until the API is stable.
4
4
 
5
5
  Signals are a way to interact with an agent through a thread. Instead of starting every interaction with `agent.stream()`, subscribe to a thread and send signals. Mastra either wakes the agent when the thread is idle or drops the signal into the running agent loop.
6
6
 
@@ -86,6 +86,32 @@ agent.sendSignal(
86
86
  )
87
87
  ```
88
88
 
89
+ ## Identify users with attributes
90
+
91
+ Use `attributes` to tag each signal with user identity. The signal type and attributes are rendered as XML so the model can distinguish who said what in a multi-user thread:
92
+
93
+ ```typescript
94
+ agent.sendSignal(
95
+ {
96
+ type: 'user',
97
+ contents: 'Can we simplify the API surface?',
98
+ attributes: { name: 'Devin', from: 'slack' },
99
+ },
100
+ {
101
+ resourceId: 'user_123',
102
+ threadId: 'thread_456',
103
+ },
104
+ )
105
+ ```
106
+
107
+ The model receives:
108
+
109
+ ```xml
110
+ <user name="Devin" from="slack">Can we simplify the API surface?</user>
111
+ ```
112
+
113
+ The UI sees just the message contents but can also read `attributes` and `metadata` off the signal message for custom rendering (e.g. showing user names, avatars, or platform badges).
114
+
89
115
  ## Send external event context
90
116
 
91
117
  Use custom signal types for system-generated context. Non-user signal types are rendered as XML-style user-role context so they can appear inside conversation history without looking like assistant output.
@@ -96,7 +122,7 @@ agent.sendSignal(
96
122
  type: 'system-reminder',
97
123
  contents: 'User X has left a new PR comment asking for a smaller API surface.',
98
124
  attributes: {
99
- type: 'github',
125
+ source: 'github',
100
126
  pr: '123',
101
127
  },
102
128
  },
@@ -110,7 +136,7 @@ agent.sendSignal(
110
136
  The model receives the custom signal as context like this:
111
137
 
112
138
  ```xml
113
- <system-reminder type="github" pr="123">User X has left a new PR comment asking for a smaller API surface.</system-reminder>
139
+ <system-reminder source="github" pr="123">User X has left a new PR comment asking for a smaller API surface.</system-reminder>
114
140
  ```
115
141
 
116
142
  Use XML-safe signal type names and attribute names. Signal type names and attribute names can contain letters, numbers, underscores, periods, and hyphens. They must start with a letter or underscore.
@@ -201,7 +201,7 @@ await agent.sendSignal({
201
201
 
202
202
  Returns `{ accepted: true, runId: string }`.
203
203
 
204
- **signal** (`{ type: 'user-message' | string; contents: string | Array<TextPart | FilePart>; attributes?: Record<string, JSONValue>; metadata?: Record<string, unknown>; providerOptions?: ProviderMetadata }`): \`user-message\` signals are treated as user input. Other signal types are wrapped in XML context (with any \`attributes\`) before the next model call. \`providerOptions\` is attached to the resulting prompt turn and persisted on the stored signal message.
204
+ **signal** (`{ type: 'user-message' | 'system-reminder' | string; contents: string | Array<TextPart | FilePart>; attributes?: Record<string, JSONValue>; metadata?: Record<string, unknown>; providerOptions?: ProviderMetadata }`): \`user-message\` signals without attributes are treated as plain user input. All other signals — including \`user-message\` with \`attributes\`, \`system-reminder\`, and custom types are wrapped in an XML element named after the signal type with \`attributes\` rendered as XML attributes (e.g. \`\<user name="Devin" from="slack">message\</user>\`). The model sees the XML; the UI sees the raw contents and can read \`attributes\` for custom rendering. \`providerOptions\` is attached to the resulting prompt turn and persisted on the stored signal message.
205
205
 
206
206
  **runId** (`string`): Run ID to target directly.
207
207
 
package/dist/index.cjs CHANGED
@@ -449,6 +449,34 @@ var Agent = class extends BaseResource {
449
449
  details(requestContext) {
450
450
  return this.request(`/agents/${this.agentId}${this.getQueryString(requestContext)}`);
451
451
  }
452
+ /**
453
+ * Probe the agent's browser session state before opening a screencast WebSocket.
454
+ *
455
+ * Returns `{ hasSession, screencastAvailable }`. Use this to avoid opening a WS
456
+ * that would either fail (screencast packages not installed) or sit idle (no
457
+ * active browser session yet). See {@link GetAgentBrowserSessionResponse}.
458
+ *
459
+ * @param threadId - Optional thread ID for thread-scoped browser sessions
460
+ */
461
+ browserSession(threadId) {
462
+ const query = threadId ? `?threadId=${encodeURIComponent(threadId)}` : "";
463
+ return this.request(`/agents/${this.agentId}/browser/session${query}`);
464
+ }
465
+ /**
466
+ * Close the agent's browser session.
467
+ *
468
+ * For thread-scoped browsers, pass `threadId` to close only that thread's
469
+ * session. Omit it to close the shared session (or all sessions for the agent
470
+ * depending on the toolset's scope).
471
+ *
472
+ * @param threadId - Optional thread ID for thread-scoped browser sessions
473
+ */
474
+ closeBrowser(threadId) {
475
+ return this.request(`/agents/${this.agentId}/browser/close`, {
476
+ method: "POST",
477
+ body: { threadId }
478
+ });
479
+ }
452
480
  enhanceInstructions(instructions, comment) {
453
481
  return this.request(`/agents/${this.agentId}/instructions/enhance`, {
454
482
  method: "POST",
@@ -1361,6 +1389,7 @@ var Agent = class extends BaseResource {
1361
1389
  }
1362
1390
  const newMessages = lastMessage != null ? [...messages.filter((m) => m.id !== lastMessage.id), lastMessage] : [...messages];
1363
1391
  const updatedMessages = threadId ? newMessages : [...Array.isArray(processedParams.messages) ? processedParams.messages : [], ...newMessages];
1392
+ const recursionRoute = route === "resume-stream" ? "stream" : route === "resume-stream-until-idle" ? "stream-until-idle" : route;
1364
1393
  try {
1365
1394
  await this.processStreamResponse(
1366
1395
  {
@@ -1368,7 +1397,7 @@ var Agent = class extends BaseResource {
1368
1397
  messages: updatedMessages
1369
1398
  },
1370
1399
  controller,
1371
- route
1400
+ recursionRoute
1372
1401
  );
1373
1402
  } catch (error) {
1374
1403
  console.error("Error processing recursive stream response:", error);
@@ -4045,6 +4074,37 @@ var StoredAgent = class extends BaseResource {
4045
4074
  );
4046
4075
  }
4047
4076
  // ==========================================================================
4077
+ // Favorite Methods (EE feature)
4078
+ // ==========================================================================
4079
+ /**
4080
+ * Favorites this agent for the calling user. Idempotent.
4081
+ * Requires the `agent.favorites` builder feature flag to be enabled on the server.
4082
+ * @param requestContext - Optional request context to pass as query parameter
4083
+ * @returns Promise containing the new favorited state and updated favorite count
4084
+ */
4085
+ favorite(requestContext) {
4086
+ return this.request(
4087
+ `/stored/agents/${encodeURIComponent(this.storedAgentId)}/favorite${requestContextQueryString(requestContext)}`,
4088
+ {
4089
+ method: "PUT"
4090
+ }
4091
+ );
4092
+ }
4093
+ /**
4094
+ * Unfavorites this agent for the calling user. Idempotent.
4095
+ * Requires the `agent.favorites` builder feature flag to be enabled on the server.
4096
+ * @param requestContext - Optional request context to pass as query parameter
4097
+ * @returns Promise containing the new favorited state and updated favorite count
4098
+ */
4099
+ unfavorite(requestContext) {
4100
+ return this.request(
4101
+ `/stored/agents/${encodeURIComponent(this.storedAgentId)}/favorite${requestContextQueryString(requestContext)}`,
4102
+ {
4103
+ method: "DELETE"
4104
+ }
4105
+ );
4106
+ }
4107
+ // ==========================================================================
4048
4108
  // Version Methods
4049
4109
  // ==========================================================================
4050
4110
  /**
@@ -4862,6 +4922,30 @@ var StoredSkill = class extends BaseResource {
4862
4922
  }
4863
4923
  );
4864
4924
  }
4925
+ /**
4926
+ * Favorites this skill for the calling user. Idempotent.
4927
+ * Requires the `skill.favorites` builder feature flag to be enabled on the server.
4928
+ */
4929
+ favorite(requestContext) {
4930
+ return this.request(
4931
+ `/stored/skills/${encodeURIComponent(this.storedSkillId)}/favorite${requestContextQueryString(requestContext)}`,
4932
+ {
4933
+ method: "PUT"
4934
+ }
4935
+ );
4936
+ }
4937
+ /**
4938
+ * Unfavorites this skill for the calling user. Idempotent.
4939
+ * Requires the `skill.favorites` builder feature flag to be enabled on the server.
4940
+ */
4941
+ unfavorite(requestContext) {
4942
+ return this.request(
4943
+ `/stored/skills/${encodeURIComponent(this.storedSkillId)}/favorite${requestContextQueryString(requestContext)}`,
4944
+ {
4945
+ method: "DELETE"
4946
+ }
4947
+ );
4948
+ }
4865
4949
  };
4866
4950
 
4867
4951
  // src/resources/responses.ts
@@ -5867,12 +5951,24 @@ var MastraClient = class extends BaseResource {
5867
5951
  searchParams.set("orderBy[direction]", params.orderBy.direction);
5868
5952
  }
5869
5953
  }
5954
+ if (params?.status) {
5955
+ searchParams.set("status", params.status);
5956
+ }
5870
5957
  if (params?.authorId) {
5871
5958
  searchParams.set("authorId", params.authorId);
5872
5959
  }
5960
+ if (params?.visibility) {
5961
+ searchParams.set("visibility", params.visibility);
5962
+ }
5873
5963
  if (params?.metadata) {
5874
5964
  searchParams.set("metadata", JSON.stringify(params.metadata));
5875
5965
  }
5966
+ if (params?.favoritedOnly) {
5967
+ searchParams.set("favoritedOnly", "true");
5968
+ }
5969
+ if (params?.pinFavoritedFor) {
5970
+ searchParams.set("pinFavoritedFor", params.pinFavoritedFor);
5971
+ }
5876
5972
  const queryString = searchParams.toString();
5877
5973
  return this.request(`/stored/agents${queryString ? `?${queryString}` : ""}`);
5878
5974
  }
@@ -6081,9 +6177,18 @@ var MastraClient = class extends BaseResource {
6081
6177
  if (params?.authorId) {
6082
6178
  searchParams.set("authorId", params.authorId);
6083
6179
  }
6180
+ if (params?.visibility) {
6181
+ searchParams.set("visibility", params.visibility);
6182
+ }
6084
6183
  if (params?.metadata) {
6085
6184
  searchParams.set("metadata", JSON.stringify(params.metadata));
6086
6185
  }
6186
+ if (params?.favoritedOnly) {
6187
+ searchParams.set("favoritedOnly", "true");
6188
+ }
6189
+ if (params?.pinFavoritedFor) {
6190
+ searchParams.set("pinFavoritedFor", params.pinFavoritedFor);
6191
+ }
6087
6192
  const queryString = searchParams.toString();
6088
6193
  return this.request(`/stored/skills${queryString ? `?${queryString}` : ""}`);
6089
6194
  }
@@ -6153,6 +6258,80 @@ var MastraClient = class extends BaseResource {
6153
6258
  return this.request("/system/packages");
6154
6259
  }
6155
6260
  // ============================================================================
6261
+ // Editor / Builder
6262
+ // ============================================================================
6263
+ /**
6264
+ * Retrieves agent builder settings for UI gating.
6265
+ * Returns feature flags and configuration set by admin.
6266
+ * @returns Promise containing builder settings
6267
+ */
6268
+ getBuilderSettings() {
6269
+ return this.request("/editor/builder/settings");
6270
+ }
6271
+ /**
6272
+ * Retrieves Agent Builder infrastructure configuration and resolution status.
6273
+ * Requires `infrastructure:read` permission.
6274
+ * @returns Promise containing infrastructure status
6275
+ */
6276
+ getInfrastructureStatus() {
6277
+ return this.request("/editor/builder/infrastructure");
6278
+ }
6279
+ /**
6280
+ * Lists known skill registries surfaced by the Agent Builder config.
6281
+ * Each entry reports whether the registry is enabled. Disabled or unknown
6282
+ * registries return 404 from registry-scoped routes.
6283
+ * Requires `stored-skills:read` permission.
6284
+ */
6285
+ listBuilderRegistries() {
6286
+ return this.request("/editor/builder/registries");
6287
+ }
6288
+ /**
6289
+ * Search a builder skill registry. The registry must be enabled or the
6290
+ * server returns 404.
6291
+ * Requires `stored-skills:read` permission.
6292
+ */
6293
+ searchBuilderRegistry(registryId, params) {
6294
+ const search = new URLSearchParams({ q: params.q });
6295
+ if (params.limit !== void 0) search.set("limit", String(params.limit));
6296
+ return this.request(`/editor/builder/registries/${encodeURIComponent(registryId)}/search?${search.toString()}`);
6297
+ }
6298
+ /**
6299
+ * Fetch the popular skills feed from a builder skill registry.
6300
+ * Requires `stored-skills:read` permission.
6301
+ */
6302
+ getBuilderRegistryPopular(registryId, params) {
6303
+ const search = new URLSearchParams();
6304
+ if (params?.limit !== void 0) search.set("limit", String(params.limit));
6305
+ if (params?.offset !== void 0) search.set("offset", String(params.offset));
6306
+ const query = search.toString();
6307
+ return this.request(
6308
+ `/editor/builder/registries/${encodeURIComponent(registryId)}/popular${query ? `?${query}` : ""}`
6309
+ );
6310
+ }
6311
+ /**
6312
+ * Fetch the rendered preview content for a single registry skill.
6313
+ * Requires `stored-skills:read` permission.
6314
+ */
6315
+ getBuilderRegistryPreview(registryId, params) {
6316
+ const search = new URLSearchParams({
6317
+ owner: params.owner,
6318
+ repo: params.repo,
6319
+ path: params.path
6320
+ });
6321
+ return this.request(`/editor/builder/registries/${encodeURIComponent(registryId)}/preview?${search.toString()}`);
6322
+ }
6323
+ /**
6324
+ * Install a registry skill into the builder's stored-skills DB.
6325
+ * Returns 409 when a stored skill with the derived id already exists.
6326
+ * Requires `stored-skills:write` permission.
6327
+ */
6328
+ installBuilderRegistrySkill(registryId, body) {
6329
+ return this.request(`/editor/builder/registries/${encodeURIComponent(registryId)}/install`, {
6330
+ method: "POST",
6331
+ body
6332
+ });
6333
+ }
6334
+ // ============================================================================
6156
6335
  // Workspace
6157
6336
  // ============================================================================
6158
6337
  /**
@@ -6171,6 +6350,32 @@ var MastraClient = class extends BaseResource {
6171
6350
  return new Workspace(this.options, workspaceId);
6172
6351
  }
6173
6352
  // ============================================================================
6353
+ // Stored Workspaces
6354
+ // ============================================================================
6355
+ /**
6356
+ * Lists stored workspace configurations from the database
6357
+ * @param params - Optional filter and pagination parameters
6358
+ * @returns Promise containing paginated list of stored workspaces
6359
+ */
6360
+ listStoredWorkspaces(params) {
6361
+ const searchParams = new URLSearchParams();
6362
+ if (params?.page !== void 0) searchParams.set("page", String(params.page));
6363
+ if (params?.perPage !== void 0) searchParams.set("perPage", String(params.perPage));
6364
+ if (params?.authorId) searchParams.set("authorId", params.authorId);
6365
+ if (params?.orderBy?.field) searchParams.set("orderBy[field]", params.orderBy.field);
6366
+ if (params?.orderBy?.direction) searchParams.set("orderBy[direction]", params.orderBy.direction);
6367
+ const qs = searchParams.toString();
6368
+ return this.request(`/stored/workspaces${qs ? `?${qs}` : ""}`);
6369
+ }
6370
+ /**
6371
+ * Gets a specific stored workspace by ID
6372
+ * @param id - The workspace ID
6373
+ * @returns Promise containing the stored workspace
6374
+ */
6375
+ getStoredWorkspace(id) {
6376
+ return this.request(`/stored/workspaces/${encodeURIComponent(id)}`);
6377
+ }
6378
+ // ============================================================================
6174
6379
  // Vectors & Embedders
6175
6380
  // ============================================================================
6176
6381
  /**