@mastra/client-js 1.60.0-alpha.0 → 1.60.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/dist/client.d.ts +15 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +5 -5
- package/dist/docs/assets/SOURCE_MAP.json +6 -6
- package/dist/docs/references/docs-harness-schedules.md +3 -1
- package/dist/docs/references/docs-signals-sending-signals.md +3 -1
- package/dist/docs/references/integrations-auth-clerk.md +46 -7
- package/dist/docs/references/integrations-auth-neon.md +217 -0
- package/dist/docs/references/integrations-auth-supabase.md +46 -7
- package/dist/docs/references/integrations-auth-workos.md +54 -15
- package/dist/docs/references/reference-client-js-agents.md +4 -4
- package/dist/docs/references/reference-client-js-observability.md +36 -6
- package/dist/docs/references/reference-observability-tracing-advanced-queries.md +49 -59
- package/dist/index.cjs +87 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +87 -39
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +18 -11
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/observability-route-types.d.ts +8 -10
- package/dist/resources/observability-route-types.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +12 -2
- package/dist/resources/observability.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +343 -212
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +5 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/docs/references/reference-migrations-upgrade-to-v1-client.md +0 -341
package/dist/index.cjs
CHANGED
|
@@ -1338,11 +1338,13 @@ async function executeClientToolWithObservability({ clientTool, args, toolName,
|
|
|
1338
1338
|
}
|
|
1339
1339
|
};
|
|
1340
1340
|
}
|
|
1341
|
-
async function executeToolCallAndRespond({ response, params, agentId, resourceId, threadId, requestContext, respondFn }) {
|
|
1341
|
+
async function executeToolCallAndRespond({ response, params, agentId, resourceId, threadId, requestContext, respondFn, abortSignal }) {
|
|
1342
1342
|
if (response.finishReason === "tool-calls") {
|
|
1343
1343
|
const toolCalls = response.toolCalls;
|
|
1344
1344
|
if (!toolCalls || !Array.isArray(toolCalls)) return response;
|
|
1345
|
+
const toolResults = [];
|
|
1345
1346
|
for (const toolCall of toolCalls) {
|
|
1347
|
+
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
1346
1348
|
const clientTool = params.clientTools?.[toolCall.payload.toolName];
|
|
1347
1349
|
if (clientTool && clientTool.execute) {
|
|
1348
1350
|
const { result, observability } = await executeClientToolWithObservability({
|
|
@@ -1372,19 +1374,22 @@ async function executeToolCallAndRespond({ response, params, agentId, resourceId
|
|
|
1372
1374
|
...modelOutput != null ? { providerOptions: { mastra: { modelOutput } } } : {}
|
|
1373
1375
|
};
|
|
1374
1376
|
if (observability) toolResultContent.__mastraObservability = observability;
|
|
1375
|
-
|
|
1376
|
-
role: "tool",
|
|
1377
|
-
content: [toolResultContent]
|
|
1378
|
-
}];
|
|
1379
|
-
const updatedMessages = threadId ? newMessages : [...Array.isArray(params.messages) ? params.messages : [], ...newMessages];
|
|
1380
|
-
const respondOptions = {
|
|
1381
|
-
...params,
|
|
1382
|
-
clientTools: params.clientToolsResolver?.() ?? params.clientTools
|
|
1383
|
-
};
|
|
1384
|
-
delete respondOptions.messages;
|
|
1385
|
-
return respondFn(updatedMessages, respondOptions);
|
|
1377
|
+
toolResults.push(toolResultContent);
|
|
1386
1378
|
}
|
|
1387
1379
|
}
|
|
1380
|
+
if (toolResults.length > 0) {
|
|
1381
|
+
const newMessages = [...response.response.messages || [], {
|
|
1382
|
+
role: "tool",
|
|
1383
|
+
content: toolResults
|
|
1384
|
+
}];
|
|
1385
|
+
const updatedMessages = threadId ? newMessages : [...Array.isArray(params.messages) ? params.messages : [], ...newMessages];
|
|
1386
|
+
const respondOptions = {
|
|
1387
|
+
...params,
|
|
1388
|
+
clientTools: params.clientToolsResolver?.() ?? params.clientTools
|
|
1389
|
+
};
|
|
1390
|
+
delete respondOptions.messages;
|
|
1391
|
+
return respondFn(updatedMessages, respondOptions);
|
|
1392
|
+
}
|
|
1388
1393
|
}
|
|
1389
1394
|
return response;
|
|
1390
1395
|
}
|
|
@@ -2081,7 +2086,9 @@ var Agent = class extends BaseResource {
|
|
|
2081
2086
|
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
2082
2087
|
const toolCalls = response.toolCalls;
|
|
2083
2088
|
if (!toolCalls || !Array.isArray(toolCalls)) return response;
|
|
2089
|
+
const toolResults = [];
|
|
2084
2090
|
for (const toolCall of toolCalls) {
|
|
2091
|
+
if (abortSignal?.aborted) throw abortSignal.reason ?? new DOMException("This operation was aborted", "AbortError");
|
|
2085
2092
|
const clientTool = processedParams.clientTools?.[toolCall.toolName];
|
|
2086
2093
|
if (clientTool && clientTool.execute) {
|
|
2087
2094
|
const { result, observability } = await executeClientToolWithObservability({
|
|
@@ -2102,22 +2109,25 @@ var Agent = class extends BaseResource {
|
|
|
2102
2109
|
}
|
|
2103
2110
|
}
|
|
2104
2111
|
});
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
result,
|
|
2112
|
-
...observability ? { __mastraObservability: observability } : {}
|
|
2113
|
-
}]
|
|
2114
|
-
}];
|
|
2115
|
-
return this.generateLegacy({
|
|
2116
|
-
...params,
|
|
2117
|
-
messages: updatedMessages
|
|
2112
|
+
toolResults.push({
|
|
2113
|
+
type: "tool-result",
|
|
2114
|
+
toolCallId: toolCall.toolCallId,
|
|
2115
|
+
toolName: toolCall.toolName,
|
|
2116
|
+
result,
|
|
2117
|
+
...observability ? { __mastraObservability: observability } : {}
|
|
2118
2118
|
});
|
|
2119
2119
|
}
|
|
2120
2120
|
}
|
|
2121
|
+
if (toolResults.length > 0) {
|
|
2122
|
+
const updatedMessages = [...response.response.messages, {
|
|
2123
|
+
role: "tool",
|
|
2124
|
+
content: toolResults
|
|
2125
|
+
}];
|
|
2126
|
+
return this.generateLegacy({
|
|
2127
|
+
...params,
|
|
2128
|
+
messages: updatedMessages
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2121
2131
|
}
|
|
2122
2132
|
return response;
|
|
2123
2133
|
}
|
|
@@ -2159,7 +2169,8 @@ var Agent = class extends BaseResource {
|
|
|
2159
2169
|
resourceId,
|
|
2160
2170
|
threadId,
|
|
2161
2171
|
requestContext,
|
|
2162
|
-
respondFn: this.generate.bind(this)
|
|
2172
|
+
respondFn: this.generate.bind(this),
|
|
2173
|
+
abortSignal
|
|
2163
2174
|
});
|
|
2164
2175
|
}
|
|
2165
2176
|
return response;
|
|
@@ -3247,20 +3258,27 @@ var Agent = class extends BaseResource {
|
|
|
3247
3258
|
* Use this to resume receiving events after a disconnection.
|
|
3248
3259
|
*
|
|
3249
3260
|
* @param params.runId - The run ID to observe
|
|
3250
|
-
* @param params.offset -
|
|
3261
|
+
* @param params.offset - Run-log position to resume from. Chunks from `observe()`, and from `stream()` on
|
|
3262
|
+
* durable and evented agents, carry an `index`; pass the `index + 1` of the last chunk that has one. Chunks without an `index`
|
|
3263
|
+
* (`abort` and structured-output `object` chunks) are skipped when choosing the offset. If omitted,
|
|
3264
|
+
* replays the chunks still cached for the run, or only live chunks if the server's transport can't replay.
|
|
3251
3265
|
* @returns Promise containing a streaming Response
|
|
3252
3266
|
*
|
|
3253
3267
|
* @example
|
|
3254
3268
|
* ```typescript
|
|
3255
|
-
*
|
|
3256
|
-
*
|
|
3257
|
-
*
|
|
3258
|
-
*
|
|
3259
|
-
*
|
|
3269
|
+
* const agent = client.getAgent('my-agent');
|
|
3270
|
+
* let offset = 0;
|
|
3271
|
+
* const trackOffset = async (chunk: { index?: number }) => {
|
|
3272
|
+
* if (chunk.index === undefined) return;
|
|
3273
|
+
* offset = chunk.index + 1;
|
|
3274
|
+
* };
|
|
3260
3275
|
*
|
|
3261
|
-
* await
|
|
3262
|
-
*
|
|
3263
|
-
*
|
|
3276
|
+
* const stream = await agent.stream(messages, { runId: 'run-123' });
|
|
3277
|
+
* await stream.processDataStream({ onChunk: trackOffset });
|
|
3278
|
+
*
|
|
3279
|
+
* // After a dropped connection, resume where the last indexed chunk left off
|
|
3280
|
+
* const response = await agent.observe({ runId: 'run-123', offset });
|
|
3281
|
+
* await response.processDataStream({ onChunk: trackOffset });
|
|
3264
3282
|
* ```
|
|
3265
3283
|
*/
|
|
3266
3284
|
async observe(params) {
|
|
@@ -5645,7 +5663,9 @@ var Observability = class extends BaseResource {
|
|
|
5645
5663
|
* On ClickHouse-backed stores, reads may briefly return deleted rows until
|
|
5646
5664
|
* the lightweight delete is fully applied.
|
|
5647
5665
|
* @param params - IDs of the traces to delete
|
|
5648
|
-
* @returns
|
|
5666
|
+
* @returns `{ success: true }` after OSS deletion, or `{ accepted: true }`
|
|
5667
|
+
* when a supporting Platform backend queues cleanup. Acceptance does not
|
|
5668
|
+
* mean records have disappeared from reads.
|
|
5649
5669
|
*/
|
|
5650
5670
|
deleteTraces(params) {
|
|
5651
5671
|
return this.request(`/observability/traces/delete`, {
|
|
@@ -5664,6 +5684,10 @@ var Observability = class extends BaseResource {
|
|
|
5664
5684
|
]);
|
|
5665
5685
|
return this.request(`/observability/logs${queryString ? `?${queryString}` : ""}`);
|
|
5666
5686
|
}
|
|
5687
|
+
/** Retrieves one score by ID; the response contains null when it is missing. */
|
|
5688
|
+
getScore(id) {
|
|
5689
|
+
return this.request(`/observability/scores/${encodeURIComponent(id)}`);
|
|
5690
|
+
}
|
|
5667
5691
|
/**
|
|
5668
5692
|
* Retrieves a paginated list of scores with optional filtering and sorting.
|
|
5669
5693
|
*/
|
|
@@ -5694,6 +5718,8 @@ var Observability = class extends BaseResource {
|
|
|
5694
5718
|
* Deletes score records by scoreId, optionally scoped to a tenant.
|
|
5695
5719
|
* Idempotent: deleting missing ids succeeds. Depending on the storage
|
|
5696
5720
|
* backend (e.g. ClickHouse), deletion may be eventually consistent.
|
|
5721
|
+
* A supporting Platform backend returns `{ accepted: true }` after queueing
|
|
5722
|
+
* cleanup; OSS returns `{ success: boolean }` after deletion.
|
|
5697
5723
|
*/
|
|
5698
5724
|
deleteScores(params) {
|
|
5699
5725
|
return this.request(`/observability/scores`, {
|
|
@@ -5737,6 +5763,10 @@ var Observability = class extends BaseResource {
|
|
|
5737
5763
|
body: params
|
|
5738
5764
|
});
|
|
5739
5765
|
}
|
|
5766
|
+
/** Retrieves one feedback by ID; the response contains null when it is missing. */
|
|
5767
|
+
getFeedback(id) {
|
|
5768
|
+
return this.request(`/observability/feedback/${encodeURIComponent(id)}`);
|
|
5769
|
+
}
|
|
5740
5770
|
/**
|
|
5741
5771
|
* Retrieves a paginated list of feedback with optional filtering and sorting.
|
|
5742
5772
|
*/
|
|
@@ -5778,6 +5808,8 @@ var Observability = class extends BaseResource {
|
|
|
5778
5808
|
* Deletes feedback records by feedbackId, optionally scoped to a tenant.
|
|
5779
5809
|
* Idempotent: deleting missing ids succeeds. Depending on the storage
|
|
5780
5810
|
* backend (e.g. ClickHouse), deletion may be eventually consistent.
|
|
5811
|
+
* A supporting Platform backend returns `{ accepted: true }` after queueing
|
|
5812
|
+
* cleanup; OSS returns `{ success: boolean }` after deletion.
|
|
5781
5813
|
*/
|
|
5782
5814
|
deleteFeedback(params) {
|
|
5783
5815
|
return this.request(`/observability/feedback`, {
|
|
@@ -8511,7 +8543,8 @@ var MastraClient = class extends BaseResource {
|
|
|
8511
8543
|
* Deletes traces by ID, cascading to all associated spans and trace-linked
|
|
8512
8544
|
* signal events (scores, feedback, metrics, logs). Signals without a trace ID
|
|
8513
8545
|
* are untouched. On ClickHouse-backed stores, reads may briefly return
|
|
8514
|
-
* deleted rows until the delete is fully applied.
|
|
8546
|
+
* deleted rows until the delete is fully applied. A supporting Platform backend
|
|
8547
|
+
* returns `{ accepted: true }` after queueing cleanup, before records disappear.
|
|
8515
8548
|
*/
|
|
8516
8549
|
deleteTraces(params) {
|
|
8517
8550
|
return this.observability.deleteTraces(params);
|
|
@@ -8524,6 +8557,10 @@ var MastraClient = class extends BaseResource {
|
|
|
8524
8557
|
listLogsVNext(params = {}) {
|
|
8525
8558
|
return this.observability.listLogs(params);
|
|
8526
8559
|
}
|
|
8560
|
+
/** Retrieves one score by ID; the response contains null when it is missing. */
|
|
8561
|
+
getScore(id) {
|
|
8562
|
+
return this.observability.getScore(id);
|
|
8563
|
+
}
|
|
8527
8564
|
/** Retrieves a paginated list of observability scores. */
|
|
8528
8565
|
listScores(params = {}) {
|
|
8529
8566
|
return this.observability.listScores(params);
|
|
@@ -8532,7 +8569,10 @@ var MastraClient = class extends BaseResource {
|
|
|
8532
8569
|
createScore(params, options) {
|
|
8533
8570
|
return this.observability.createScore(params, options);
|
|
8534
8571
|
}
|
|
8535
|
-
/**
|
|
8572
|
+
/**
|
|
8573
|
+
* Deletes score records by scoreId, optionally scoped to a tenant.
|
|
8574
|
+
* Returns OSS success or Platform acceptance; accepted cleanup is asynchronous.
|
|
8575
|
+
*/
|
|
8536
8576
|
deleteScores(params) {
|
|
8537
8577
|
return this.observability.deleteScores(params);
|
|
8538
8578
|
}
|
|
@@ -8552,6 +8592,10 @@ var MastraClient = class extends BaseResource {
|
|
|
8552
8592
|
getScorePercentiles(params) {
|
|
8553
8593
|
return this.observability.getScorePercentiles(params);
|
|
8554
8594
|
}
|
|
8595
|
+
/** Retrieves one feedback by ID; the response contains null when it is missing. */
|
|
8596
|
+
getFeedback(id) {
|
|
8597
|
+
return this.observability.getFeedback(id);
|
|
8598
|
+
}
|
|
8555
8599
|
/** Retrieves a paginated list of feedback records. */
|
|
8556
8600
|
listFeedback(params = {}) {
|
|
8557
8601
|
return this.observability.listFeedback(params);
|
|
@@ -8564,7 +8608,10 @@ var MastraClient = class extends BaseResource {
|
|
|
8564
8608
|
replaceFeedback(params, options) {
|
|
8565
8609
|
return this.observability.replaceFeedback(params, options);
|
|
8566
8610
|
}
|
|
8567
|
-
/**
|
|
8611
|
+
/**
|
|
8612
|
+
* Deletes feedback records by feedbackId, optionally scoped to a tenant.
|
|
8613
|
+
* Returns OSS success or Platform acceptance; accepted cleanup is asynchronous.
|
|
8614
|
+
*/
|
|
8568
8615
|
deleteFeedback(params) {
|
|
8569
8616
|
return this.observability.deleteFeedback(params);
|
|
8570
8617
|
}
|
|
@@ -9339,6 +9386,7 @@ var MastraClient = class extends BaseResource {
|
|
|
9339
9386
|
if (options?.page !== void 0) searchParams.set("page", String(options.page));
|
|
9340
9387
|
if (options?.perPage !== void 0) searchParams.set("perPage", String(options.perPage));
|
|
9341
9388
|
for (const tag of options?.tags ?? []) searchParams.append("tags", tag);
|
|
9389
|
+
if (options?.status) searchParams.set("status", options.status);
|
|
9342
9390
|
if (options?.orderBy) {
|
|
9343
9391
|
searchParams.set("orderBy[field]", options.orderBy.field);
|
|
9344
9392
|
searchParams.set("orderBy[direction]", options.orderBy.direction);
|