@mastra/client-js 0.10.24-alpha.0 → 0.11.0-alpha.1
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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +17 -0
- package/dist/adapters/agui.d.ts +1 -1
- package/dist/adapters/agui.d.ts.map +1 -1
- package/dist/client.d.ts +5 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +117 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +117 -53
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +10 -11
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/base.d.ts.map +1 -1
- package/dist/resources/index.d.ts +1 -0
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/memory-thread.d.ts +1 -1
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/resources/network-memory-thread.d.ts +1 -1
- package/dist/resources/network-memory-thread.d.ts.map +1 -1
- package/dist/resources/network.d.ts +1 -1
- package/dist/resources/network.d.ts.map +1 -1
- package/dist/resources/observability.d.ts +19 -0
- package/dist/resources/observability.d.ts.map +1 -0
- package/dist/resources/tool.d.ts.map +1 -1
- package/dist/resources/vNextNetwork.d.ts +1 -1
- package/dist/resources/vNextNetwork.d.ts.map +1 -1
- package/dist/types.d.ts +16 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-client-tools.d.ts.map +1 -1
- package/dist/utils/zod-to-json-schema.d.ts +2 -104
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -1
- package/eslint.config.js +6 -1
- package/integration-tests/src/mastra/index.ts +2 -2
- package/package.json +6 -4
- package/src/adapters/agui.test.ts +0 -29
- package/src/adapters/agui.ts +1 -1
- package/src/client.ts +13 -0
- package/src/example.ts +1 -1
- package/src/index.test.ts +29 -2
- package/src/resources/agent.ts +30 -31
- package/src/resources/base.ts +2 -1
- package/src/resources/index.ts +1 -0
- package/src/resources/memory-thread.test.ts +1 -1
- package/src/resources/memory-thread.ts +1 -1
- package/src/resources/network-memory-thread.test.ts +1 -1
- package/src/resources/network-memory-thread.ts +1 -1
- package/src/resources/network.ts +1 -1
- package/src/resources/observability.ts +53 -0
- package/src/resources/tool.ts +1 -1
- package/src/resources/vNextNetwork.ts +2 -2
- package/src/resources/workflow.ts +1 -1
- package/src/types.ts +27 -16
- package/src/utils/process-client-tools.ts +1 -1
- package/src/utils/process-mastra-stream.test.ts +2 -2
- package/src/utils/zod-to-json-schema.ts +22 -3
- package/src/v2-messages.test.ts +1 -1
- package/tsconfig.json +2 -2
- package/tsup.config.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { processDataStream, parsePartialJson } from '@ai-sdk/ui-utils';
|
|
4
|
-
import { ZodSchema } from 'zod';
|
|
5
|
-
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
|
-
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
7
4
|
import { v4 } from '@lukeed/uuid';
|
|
8
5
|
import { RuntimeContext } from '@mastra/core/runtime-context';
|
|
6
|
+
import { isVercelTool } from '@mastra/core/tools/is-vercel-tool';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
9
9
|
|
|
10
10
|
// src/adapters/agui.ts
|
|
11
11
|
var AGUIAdapter = class extends AbstractAgent {
|
|
@@ -206,12 +206,29 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
206
206
|
}
|
|
207
207
|
return result;
|
|
208
208
|
}
|
|
209
|
+
function parseClientRuntimeContext(runtimeContext) {
|
|
210
|
+
if (runtimeContext) {
|
|
211
|
+
if (runtimeContext instanceof RuntimeContext) {
|
|
212
|
+
return Object.fromEntries(runtimeContext.entries());
|
|
213
|
+
}
|
|
214
|
+
return runtimeContext;
|
|
215
|
+
}
|
|
216
|
+
return void 0;
|
|
217
|
+
}
|
|
218
|
+
function isZodType(value) {
|
|
219
|
+
return typeof value === "object" && value !== null && "_def" in value && "parse" in value && typeof value.parse === "function" && "safeParse" in value && typeof value.safeParse === "function";
|
|
220
|
+
}
|
|
209
221
|
function zodToJsonSchema(zodSchema) {
|
|
210
|
-
if (!(zodSchema
|
|
222
|
+
if (!isZodType(zodSchema)) {
|
|
211
223
|
return zodSchema;
|
|
212
224
|
}
|
|
225
|
+
if ("toJSONSchema" in z) {
|
|
226
|
+
return z.toJSONSchema(zodSchema);
|
|
227
|
+
}
|
|
213
228
|
return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
214
229
|
}
|
|
230
|
+
|
|
231
|
+
// src/utils/process-client-tools.ts
|
|
215
232
|
function processClientTools(clientTools) {
|
|
216
233
|
if (!clientTools) {
|
|
217
234
|
return void 0;
|
|
@@ -240,6 +257,42 @@ function processClientTools(clientTools) {
|
|
|
240
257
|
);
|
|
241
258
|
}
|
|
242
259
|
|
|
260
|
+
// src/utils/process-mastra-stream.ts
|
|
261
|
+
async function processMastraStream({
|
|
262
|
+
stream,
|
|
263
|
+
onChunk
|
|
264
|
+
}) {
|
|
265
|
+
const reader = stream.getReader();
|
|
266
|
+
const decoder = new TextDecoder();
|
|
267
|
+
let buffer = "";
|
|
268
|
+
try {
|
|
269
|
+
while (true) {
|
|
270
|
+
const { done, value } = await reader.read();
|
|
271
|
+
if (done) break;
|
|
272
|
+
buffer += decoder.decode(value, { stream: true });
|
|
273
|
+
const lines = buffer.split("\n\n");
|
|
274
|
+
buffer = lines.pop() || "";
|
|
275
|
+
for (const line of lines) {
|
|
276
|
+
if (line.startsWith("data: ")) {
|
|
277
|
+
const data = line.slice(6);
|
|
278
|
+
if (data === "[DONE]") {
|
|
279
|
+
console.log("\u{1F3C1} Stream finished");
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const json = JSON.parse(data);
|
|
284
|
+
await onChunk(json);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
} finally {
|
|
292
|
+
reader.releaseLock();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
243
296
|
// src/resources/base.ts
|
|
244
297
|
var BaseResource = class {
|
|
245
298
|
options;
|
|
@@ -254,7 +307,7 @@ var BaseResource = class {
|
|
|
254
307
|
*/
|
|
255
308
|
async request(path, options = {}) {
|
|
256
309
|
let lastError = null;
|
|
257
|
-
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {} } = this.options;
|
|
310
|
+
const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
|
|
258
311
|
let delay = backoffMs;
|
|
259
312
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
260
313
|
try {
|
|
@@ -268,6 +321,7 @@ var BaseResource = class {
|
|
|
268
321
|
// 'x-mastra-client-type': 'js',
|
|
269
322
|
},
|
|
270
323
|
signal: this.options.abortSignal,
|
|
324
|
+
credentials: options.credentials ?? credentials,
|
|
271
325
|
body: options.body instanceof FormData ? options.body : options.body ? JSON.stringify(options.body) : void 0
|
|
272
326
|
});
|
|
273
327
|
if (!response.ok) {
|
|
@@ -300,51 +354,6 @@ var BaseResource = class {
|
|
|
300
354
|
throw lastError || new Error("Request failed");
|
|
301
355
|
}
|
|
302
356
|
};
|
|
303
|
-
function parseClientRuntimeContext(runtimeContext) {
|
|
304
|
-
if (runtimeContext) {
|
|
305
|
-
if (runtimeContext instanceof RuntimeContext) {
|
|
306
|
-
return Object.fromEntries(runtimeContext.entries());
|
|
307
|
-
}
|
|
308
|
-
return runtimeContext;
|
|
309
|
-
}
|
|
310
|
-
return void 0;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
// src/utils/process-mastra-stream.ts
|
|
314
|
-
async function processMastraStream({
|
|
315
|
-
stream,
|
|
316
|
-
onChunk
|
|
317
|
-
}) {
|
|
318
|
-
const reader = stream.getReader();
|
|
319
|
-
const decoder = new TextDecoder();
|
|
320
|
-
let buffer = "";
|
|
321
|
-
try {
|
|
322
|
-
while (true) {
|
|
323
|
-
const { done, value } = await reader.read();
|
|
324
|
-
if (done) break;
|
|
325
|
-
buffer += decoder.decode(value, { stream: true });
|
|
326
|
-
const lines = buffer.split("\n\n");
|
|
327
|
-
buffer = lines.pop() || "";
|
|
328
|
-
for (const line of lines) {
|
|
329
|
-
if (line.startsWith("data: ")) {
|
|
330
|
-
const data = line.slice(6);
|
|
331
|
-
if (data === "[DONE]") {
|
|
332
|
-
console.log("\u{1F3C1} Stream finished");
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
try {
|
|
336
|
-
const json = JSON.parse(data);
|
|
337
|
-
await onChunk(json);
|
|
338
|
-
} catch (error) {
|
|
339
|
-
console.error("\u274C JSON parse error:", error, "Data:", data);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
} finally {
|
|
345
|
-
reader.releaseLock();
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
357
|
|
|
349
358
|
// src/resources/agent.ts
|
|
350
359
|
async function executeToolCallAndRespond({
|
|
@@ -1772,7 +1781,7 @@ var LegacyWorkflow = class extends BaseResource {
|
|
|
1772
1781
|
};
|
|
1773
1782
|
|
|
1774
1783
|
// src/resources/tool.ts
|
|
1775
|
-
var
|
|
1784
|
+
var Tool = class extends BaseResource {
|
|
1776
1785
|
constructor(options, toolId) {
|
|
1777
1786
|
super(options);
|
|
1778
1787
|
this.toolId = toolId;
|
|
@@ -2041,7 +2050,7 @@ var Workflow = class extends BaseResource {
|
|
|
2041
2050
|
const parsedChunk = JSON.parse(newChunk);
|
|
2042
2051
|
controller.enqueue(parsedChunk);
|
|
2043
2052
|
failedChunk = void 0;
|
|
2044
|
-
} catch
|
|
2053
|
+
} catch {
|
|
2045
2054
|
failedChunk = newChunk;
|
|
2046
2055
|
}
|
|
2047
2056
|
}
|
|
@@ -2225,6 +2234,53 @@ var MCPTool = class extends BaseResource {
|
|
|
2225
2234
|
}
|
|
2226
2235
|
};
|
|
2227
2236
|
|
|
2237
|
+
// src/resources/observability.ts
|
|
2238
|
+
var Observability = class extends BaseResource {
|
|
2239
|
+
constructor(options) {
|
|
2240
|
+
super(options);
|
|
2241
|
+
}
|
|
2242
|
+
/**
|
|
2243
|
+
* Retrieves a specific AI trace by ID
|
|
2244
|
+
* @param traceId - ID of the trace to retrieve
|
|
2245
|
+
* @returns Promise containing the AI trace with all its spans
|
|
2246
|
+
*/
|
|
2247
|
+
getTrace(traceId) {
|
|
2248
|
+
return this.request(`/api/observability/traces/${traceId}`);
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* Retrieves paginated list of AI traces with optional filtering
|
|
2252
|
+
* @param params - Parameters for pagination and filtering
|
|
2253
|
+
* @returns Promise containing paginated traces and pagination info
|
|
2254
|
+
*/
|
|
2255
|
+
getTraces(params) {
|
|
2256
|
+
const { pagination, filters } = params;
|
|
2257
|
+
const { page, perPage, dateRange } = pagination || {};
|
|
2258
|
+
const { name, spanType } = filters || {};
|
|
2259
|
+
const searchParams = new URLSearchParams();
|
|
2260
|
+
if (page !== void 0) {
|
|
2261
|
+
searchParams.set("page", String(page));
|
|
2262
|
+
}
|
|
2263
|
+
if (perPage !== void 0) {
|
|
2264
|
+
searchParams.set("perPage", String(perPage));
|
|
2265
|
+
}
|
|
2266
|
+
if (name) {
|
|
2267
|
+
searchParams.set("name", name);
|
|
2268
|
+
}
|
|
2269
|
+
if (spanType !== void 0) {
|
|
2270
|
+
searchParams.set("spanType", String(spanType));
|
|
2271
|
+
}
|
|
2272
|
+
if (dateRange) {
|
|
2273
|
+
const dateRangeStr = JSON.stringify({
|
|
2274
|
+
start: dateRange.start instanceof Date ? dateRange.start.toISOString() : dateRange.start,
|
|
2275
|
+
end: dateRange.end instanceof Date ? dateRange.end.toISOString() : dateRange.end
|
|
2276
|
+
});
|
|
2277
|
+
searchParams.set("dateRange", dateRangeStr);
|
|
2278
|
+
}
|
|
2279
|
+
const queryString = searchParams.toString();
|
|
2280
|
+
return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
|
|
2281
|
+
}
|
|
2282
|
+
};
|
|
2283
|
+
|
|
2228
2284
|
// src/resources/network-memory-thread.ts
|
|
2229
2285
|
var NetworkMemoryThread = class extends BaseResource {
|
|
2230
2286
|
constructor(options, threadId, networkId) {
|
|
@@ -2428,8 +2484,10 @@ var VNextNetwork = class extends BaseResource {
|
|
|
2428
2484
|
|
|
2429
2485
|
// src/client.ts
|
|
2430
2486
|
var MastraClient = class extends BaseResource {
|
|
2487
|
+
observability;
|
|
2431
2488
|
constructor(options) {
|
|
2432
2489
|
super(options);
|
|
2490
|
+
this.observability = new Observability(options);
|
|
2433
2491
|
}
|
|
2434
2492
|
/**
|
|
2435
2493
|
* Retrieves all available agents
|
|
@@ -2558,7 +2616,7 @@ var MastraClient = class extends BaseResource {
|
|
|
2558
2616
|
* @returns Tool instance
|
|
2559
2617
|
*/
|
|
2560
2618
|
getTool(toolId) {
|
|
2561
|
-
return new
|
|
2619
|
+
return new Tool(this.options, toolId);
|
|
2562
2620
|
}
|
|
2563
2621
|
/**
|
|
2564
2622
|
* Retrieves all available legacy workflows
|
|
@@ -2940,6 +2998,12 @@ var MastraClient = class extends BaseResource {
|
|
|
2940
2998
|
getModelProviders() {
|
|
2941
2999
|
return this.request(`/api/model-providers`);
|
|
2942
3000
|
}
|
|
3001
|
+
getAITrace(traceId) {
|
|
3002
|
+
return this.observability.getTrace(traceId);
|
|
3003
|
+
}
|
|
3004
|
+
getAITraces(params) {
|
|
3005
|
+
return this.observability.getTraces(params);
|
|
3006
|
+
}
|
|
2943
3007
|
};
|
|
2944
3008
|
|
|
2945
3009
|
export { MastraClient };
|