@mastra/client-js 1.26.1-alpha.2 → 1.27.0-alpha.4

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.d.ts CHANGED
@@ -3,6 +3,8 @@ export * from './types.js';
3
3
  export * from './tools.js';
4
4
  export type { ChannelPlatformInfo, ChannelInstallationInfo, ChannelConnectOAuth, ChannelConnectDeepLink, ChannelConnectImmediate, ChannelConnectResult, } from './resources/channels.js';
5
5
  export type { AgentCardSignatureKeyProviderInput, AgentCardVerificationKey, GetAgentCardOptions, VerifyAgentCardSignatureOptions, } from './resources/a2a.js';
6
+ export { harnessMessageText } from './resources/harness.js';
7
+ export type { HarnessInfo, HarnessMessage, HarnessMessageContent, HarnessEvent, KnownHarnessEvent, OtherHarnessEvent, CreateHarnessSessionResponse, SubscribeHarnessSessionOptions, HarnessSubscription, HarnessSessionState, HarnessModeInfo, HarnessThreadInfo, HarnessTaskSnapshot, HarnessAvailableModel, HarnessWorkspaceStatus, HarnessGoalRecord, SendNotificationInput, SendNotificationResult, PlanResume, PermissionPolicy, PermissionRules, ToolCategory, } from './resources/harness.js';
6
8
  export { RequestContext } from '@mastra/core/request-context';
7
9
  export type { ObservabilityCollector } from './observability/types.js';
8
10
  export type { UIMessageWithMetadata } from '@mastra/core/agent';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kCAAkC,EAClC,wBAAwB,EACxB,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACxE,YAAY,EACV,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,UAAU,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,MAAM,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kCAAkC,EAClC,wBAAwB,EACxB,mBAAmB,EACnB,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EACV,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,4BAA4B,EAC5B,8BAA8B,EAC9B,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,GACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AACpE,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACxE,YAAY,EACV,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,UAAU,EACV,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,UAAU,GACX,MAAM,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -6082,6 +6082,280 @@ var Channels = class extends BaseResource {
6082
6082
  }
6083
6083
  };
6084
6084
 
6085
+ // src/resources/harness.ts
6086
+ var HarnessSession = class extends BaseResource {
6087
+ constructor(options, harnessId, resourceId) {
6088
+ super(options);
6089
+ this.harnessId = harnessId;
6090
+ this.resourceId = resourceId;
6091
+ }
6092
+ harnessId;
6093
+ resourceId;
6094
+ base() {
6095
+ return `/harness/${encodeURIComponent(this.harnessId)}/sessions/${encodeURIComponent(this.resourceId)}`;
6096
+ }
6097
+ /** Create or resume this session. */
6098
+ create() {
6099
+ return this.request(`/harness/${encodeURIComponent(this.harnessId)}/sessions`, {
6100
+ method: "POST",
6101
+ body: { resourceId: this.resourceId }
6102
+ });
6103
+ }
6104
+ /**
6105
+ * Subscribe to this session's event stream (SSE). The assistant's reply to a
6106
+ * message arrives here as `message_*` events, not on the sendMessage call.
6107
+ */
6108
+ async subscribe(options) {
6109
+ const response = await this.request(`${this.base()}/stream`, { stream: true });
6110
+ if (!response.body) {
6111
+ throw new Error("No response body for harness session stream");
6112
+ }
6113
+ const reader = response.body.getReader();
6114
+ const decoder = new TextDecoder();
6115
+ let cancelled = false;
6116
+ let buffer = "";
6117
+ const pump = async () => {
6118
+ try {
6119
+ while (!cancelled) {
6120
+ const { done, value } = await reader.read();
6121
+ if (done) break;
6122
+ buffer += decoder.decode(value, { stream: true });
6123
+ let sep;
6124
+ while ((sep = buffer.indexOf("\n\n")) !== -1) {
6125
+ const frame = buffer.slice(0, sep);
6126
+ buffer = buffer.slice(sep + 2);
6127
+ for (const line of frame.split("\n")) {
6128
+ if (!line.startsWith("data:")) continue;
6129
+ const data = line.slice(5).trim();
6130
+ if (!data) continue;
6131
+ try {
6132
+ options.onEvent(JSON.parse(data));
6133
+ } catch {
6134
+ }
6135
+ }
6136
+ }
6137
+ }
6138
+ } catch (error) {
6139
+ if (!cancelled) options.onError?.(error);
6140
+ }
6141
+ };
6142
+ void pump();
6143
+ return {
6144
+ unsubscribe: () => {
6145
+ cancelled = true;
6146
+ void reader.cancel().catch(() => {
6147
+ });
6148
+ }
6149
+ };
6150
+ }
6151
+ /** Send a user message. The reply streams over `subscribe()`. */
6152
+ async sendMessage(message) {
6153
+ await this.request(`${this.base()}/messages`, { method: "POST", body: { message } });
6154
+ }
6155
+ /** Abort the in-flight run for this session. */
6156
+ async abort() {
6157
+ await this.request(`${this.base()}/abort`, { method: "POST" });
6158
+ }
6159
+ /** Approve or decline a pending tool call (`tool_approval_required`). */
6160
+ async approveTool(toolCallId, approved) {
6161
+ await this.request(`${this.base()}/tool-approval`, {
6162
+ method: "POST",
6163
+ body: { toolCallId, approved }
6164
+ });
6165
+ }
6166
+ /**
6167
+ * Resume a suspended interactive tool (`tool_suspended`). The resume shape
6168
+ * depends on the tool: a string (or string[]) for `ask_user`, "Yes"/"No" for
6169
+ * `request_access`, and a {@link PlanResume} for `submit_plan`.
6170
+ */
6171
+ async respondToToolSuspension(toolCallId, resumeData) {
6172
+ await this.request(`${this.base()}/tool-suspension`, {
6173
+ method: "POST",
6174
+ body: { toolCallId, resumeData }
6175
+ });
6176
+ }
6177
+ /** Inject a message into the in-flight run without starting a new turn. */
6178
+ async steer(message) {
6179
+ await this.request(`${this.base()}/steer`, { method: "POST", body: { message } });
6180
+ }
6181
+ /** Get the current mode, model, and thread (for initial UI hydration). */
6182
+ state() {
6183
+ return this.request(this.base());
6184
+ }
6185
+ /** Merge key-value pairs into the session state. Existing keys not in the payload are preserved. */
6186
+ async setState(updates) {
6187
+ await this.request(`${this.base()}/state`, { method: "PUT", body: { state: updates } });
6188
+ }
6189
+ /** Switch the active mode (e.g. `build`, `plan`). */
6190
+ async switchMode(modeId) {
6191
+ await this.request(`${this.base()}/mode`, { method: "POST", body: { modeId } });
6192
+ }
6193
+ /** Switch the model. Defaults to thread scope. */
6194
+ async switchModel(modelId, options) {
6195
+ await this.request(`${this.base()}/model`, {
6196
+ method: "POST",
6197
+ body: { modelId, scope: options?.scope, modeId: options?.modeId }
6198
+ });
6199
+ }
6200
+ /** List the threads for this session's resource, most-recently-updated first. Pass `limit` for just the newest N. */
6201
+ async listThreads(limit) {
6202
+ const query = limit != null ? `?limit=${limit}` : "";
6203
+ const body = await this.request(`${this.base()}/threads${query}`);
6204
+ return body.threads;
6205
+ }
6206
+ /** Switch the session to an existing thread (rebinds stream + state). */
6207
+ async switchThread(threadId) {
6208
+ await this.request(`${this.base()}/thread`, { method: "POST", body: { threadId } });
6209
+ }
6210
+ /** Create a new thread (unbinds previous, binds the new one). */
6211
+ async createThread(title) {
6212
+ return this.request(`${this.base()}/threads`, {
6213
+ method: "POST",
6214
+ body: { title }
6215
+ });
6216
+ }
6217
+ /** Delete a thread. If it's the active thread the session unbinds. */
6218
+ async deleteThread(threadId) {
6219
+ await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, {
6220
+ method: "DELETE"
6221
+ });
6222
+ }
6223
+ /** Rename a thread. */
6224
+ async renameThread(threadId, title) {
6225
+ await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, {
6226
+ method: "PUT",
6227
+ body: { title }
6228
+ });
6229
+ }
6230
+ /** Clone a thread (and its messages). The session binds to the clone. */
6231
+ async cloneThread(options) {
6232
+ return this.request(`${this.base()}/threads/clone`, {
6233
+ method: "POST",
6234
+ body: options ?? {}
6235
+ });
6236
+ }
6237
+ /** List messages for a specific thread. */
6238
+ async listMessages(threadId, limit) {
6239
+ const params = limit != null ? `?limit=${limit}` : "";
6240
+ const body = await this.request(
6241
+ `${this.base()}/threads/${encodeURIComponent(threadId)}/messages${params}`
6242
+ );
6243
+ return body.messages;
6244
+ }
6245
+ /**
6246
+ * Queue a follow-up message. If the session is idle it sends immediately;
6247
+ * if a run is active it queues for after completion.
6248
+ */
6249
+ async followUp(message) {
6250
+ await this.request(`${this.base()}/follow-up`, { method: "POST", body: { message } });
6251
+ }
6252
+ /** Get the observational memory record for this session's thread. */
6253
+ async getOMRecord() {
6254
+ const body = await this.request(`${this.base()}/om`);
6255
+ return body.record;
6256
+ }
6257
+ /** Change the session's resource identity. */
6258
+ async setResourceId(newResourceId) {
6259
+ await this.request(`${this.base()}/resource`, {
6260
+ method: "POST",
6261
+ body: { newResourceId }
6262
+ });
6263
+ }
6264
+ /** Get known resource IDs for this session. */
6265
+ async getResourceIds() {
6266
+ const body = await this.request(`${this.base()}/resources`);
6267
+ return body.resourceIds;
6268
+ }
6269
+ /** Get the current goal for this session's thread. */
6270
+ async getGoal() {
6271
+ const body = await this.request(`${this.base()}/goal`);
6272
+ return body.goal;
6273
+ }
6274
+ /** Set a new goal objective. The agent's in-loop judge evaluates progress after each turn. */
6275
+ async setGoal(objective, options) {
6276
+ const body = await this.request(`${this.base()}/goal`, {
6277
+ method: "POST",
6278
+ body: { objective, ...options }
6279
+ });
6280
+ return body.goal;
6281
+ }
6282
+ /** Update goal options (judge model, max runs, status). */
6283
+ async updateGoal(options) {
6284
+ const body = await this.request(`${this.base()}/goal`, {
6285
+ method: "PUT",
6286
+ body: options
6287
+ });
6288
+ return body.goal;
6289
+ }
6290
+ /** Clear the current goal. */
6291
+ async clearGoal() {
6292
+ await this.request(`${this.base()}/goal`, { method: "DELETE" });
6293
+ }
6294
+ // ---------------------------------------------------------------------------
6295
+ // Permissions
6296
+ // ---------------------------------------------------------------------------
6297
+ /** Get the current permission rules (per-category and per-tool policies). */
6298
+ async getPermissions() {
6299
+ return this.request(`${this.base()}/permissions`);
6300
+ }
6301
+ /** Set the approval policy for a tool category. */
6302
+ async setPermissionForCategory(category, policy) {
6303
+ await this.request(`${this.base()}/permissions/category`, {
6304
+ method: "PUT",
6305
+ body: { category, policy }
6306
+ });
6307
+ }
6308
+ /** Set the approval policy for a specific tool. */
6309
+ async setPermissionForTool(toolName, policy) {
6310
+ await this.request(`${this.base()}/permissions/tool`, {
6311
+ method: "PUT",
6312
+ body: { toolName, policy }
6313
+ });
6314
+ }
6315
+ /**
6316
+ * Send a notification signal to this session. The agent's delivery policy
6317
+ * determines whether the notification wakes an idle thread, is summarised,
6318
+ * or is persisted for later.
6319
+ */
6320
+ async sendNotification(input) {
6321
+ return this.request(`${this.base()}/notifications`, {
6322
+ method: "POST",
6323
+ body: input
6324
+ });
6325
+ }
6326
+ };
6327
+ var Harness = class extends BaseResource {
6328
+ constructor(options, harnessId) {
6329
+ super(options);
6330
+ this.harnessId = harnessId;
6331
+ }
6332
+ harnessId;
6333
+ basePath() {
6334
+ return `/harness/${encodeURIComponent(this.harnessId)}`;
6335
+ }
6336
+ /** List the modes configured on this harness (e.g. build, plan). */
6337
+ async listModes() {
6338
+ const body = await this.request(`${this.basePath()}/modes`);
6339
+ return body.modes;
6340
+ }
6341
+ /** List available models on this harness (with auth status and use counts). */
6342
+ async listModels() {
6343
+ const body = await this.request(`${this.basePath()}/models`);
6344
+ return body.models;
6345
+ }
6346
+ /** Get workspace status for this harness. */
6347
+ async workspaceStatus() {
6348
+ return this.request(`${this.basePath()}/workspace`);
6349
+ }
6350
+ /** Scope to a session bound to `resourceId` (e.g. a user or conversation id). */
6351
+ session(resourceId) {
6352
+ return new HarnessSession(this.options, this.harnessId, resourceId);
6353
+ }
6354
+ };
6355
+ function harnessMessageText(message) {
6356
+ return message.content.filter((c) => c.type === "text" && typeof c.text === "string").map((c) => c.text).join("");
6357
+ }
6358
+
6085
6359
  // src/client.ts
6086
6360
  var MastraClient = class extends BaseResource {
6087
6361
  observability;
@@ -6124,6 +6398,23 @@ var MastraClient = class extends BaseResource {
6124
6398
  getAgent(agentId, version) {
6125
6399
  return new Agent(this.options, agentId, version);
6126
6400
  }
6401
+ /**
6402
+ * Lists the harnesses hosted on the connected Mastra instance.
6403
+ * @returns Promise containing an array of harness identifiers
6404
+ */
6405
+ async listHarnesses() {
6406
+ const body = await this.request("/harness");
6407
+ return body.harnesses;
6408
+ }
6409
+ /**
6410
+ * Scopes to a harness hosted on the connected Mastra instance. Use
6411
+ * `getHarness(id).session(resourceId)` to create/resume a session, stream its
6412
+ * events, and send messages.
6413
+ * @param harnessId - The id the harness is registered under on Mastra
6414
+ */
6415
+ getHarness(harnessId) {
6416
+ return new Harness(this.options, harnessId);
6417
+ }
6127
6418
  /**
6128
6419
  * Lists memory threads with optional filtering by resourceId and/or metadata
6129
6420
  * @param params - Parameters containing optional filters, pagination options, and request context
@@ -7753,6 +8044,6 @@ function createTool(opts) {
7753
8044
  return new ClientTool(opts);
7754
8045
  }
7755
8046
 
7756
- export { ClientTool, MastraClient, MastraClientError, createTool };
8047
+ export { ClientTool, MastraClient, MastraClientError, createTool, harnessMessageText };
7757
8048
  //# sourceMappingURL=index.js.map
7758
8049
  //# sourceMappingURL=index.js.map