@mastra/client-js 0.1.22-alpha.1 → 0.1.22-alpha.3
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 +8 -8
- package/CHANGELOG.md +24 -0
- package/dist/index.cjs +37 -11
- package/dist/index.d.cts +16 -6
- package/dist/index.d.ts +16 -6
- package/dist/index.js +33 -11
- package/package.json +2 -2
- package/src/adapters/agui.test.ts +19 -6
- package/src/adapters/agui.ts +17 -7
- package/src/index.test.ts +30 -0
- package/src/resources/agent.ts +6 -12
- package/src/resources/memory-thread.ts +13 -3
- package/src/resources/network.ts +5 -11
- package/src/types.ts +10 -2
- package/src/utils/zod-to-json-schema.ts +10 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/client-js@0.1.22-alpha.
|
|
2
|
+
> @mastra/client-js@0.1.22-alpha.3 build /home/runner/work/mastra/mastra/client-sdks/client-js
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
[34mCLI[39m Cleaning output folder
|
|
10
10
|
[34mESM[39m Build start
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m38.25 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 1708ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m38.52 KB[39m
|
|
15
|
+
[32mCJS[39m ⚡️ Build success in 1710ms
|
|
12
16
|
[34mDTS[39m Build start
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[32mESM[39m ⚡️ Build success in 1628ms
|
|
17
|
-
[32mDTS[39m ⚡️ Build success in 14543ms
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m27.18 KB[39m
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[32m27.18 KB[39m
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 14928ms
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m27.63 KB[39m
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m27.63 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 0.1.22-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c2f9e60: Resolves type issue and listen response string wrapped in text object twice
|
|
8
|
+
- 0c3d117: Add workflows to agent server handlers
|
|
9
|
+
- a5810ce: Add support for experimental_generateMessageId and remove it from client-js types since it's not serializable
|
|
10
|
+
- Updated dependencies [396be50]
|
|
11
|
+
- Updated dependencies [c3bd795]
|
|
12
|
+
- Updated dependencies [da082f8]
|
|
13
|
+
- Updated dependencies [a5810ce]
|
|
14
|
+
- @mastra/core@0.9.4-alpha.3
|
|
15
|
+
|
|
16
|
+
## 0.1.22-alpha.2
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- b4c6c87: fix: Specify $refStrategy: 'none' when calling zodToJsonSchema.
|
|
21
|
+
- c2b980b: Fix multiple too-calls in AGUI
|
|
22
|
+
- Updated dependencies [3171b5b]
|
|
23
|
+
- Updated dependencies [973e5ac]
|
|
24
|
+
- Updated dependencies [9e1eff5]
|
|
25
|
+
- @mastra/core@0.9.4-alpha.2
|
|
26
|
+
|
|
3
27
|
## 0.1.22-alpha.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,11 @@ var client = require('@ag-ui/client');
|
|
|
4
4
|
var rxjs = require('rxjs');
|
|
5
5
|
var uiUtils = require('@ai-sdk/ui-utils');
|
|
6
6
|
var zod = require('zod');
|
|
7
|
-
var
|
|
7
|
+
var originalZodToJsonSchema = require('zod-to-json-schema');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var originalZodToJsonSchema__default = /*#__PURE__*/_interopDefault(originalZodToJsonSchema);
|
|
8
12
|
|
|
9
13
|
// src/adapters/agui.ts
|
|
10
14
|
var AGUIAdapter = class extends client.AbstractAgent {
|
|
@@ -159,6 +163,17 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
159
163
|
role: "assistant",
|
|
160
164
|
content: parts
|
|
161
165
|
});
|
|
166
|
+
if (message.toolCalls?.length) {
|
|
167
|
+
result.push({
|
|
168
|
+
role: "tool",
|
|
169
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
170
|
+
type: "tool-result",
|
|
171
|
+
toolCallId: toolCall.id,
|
|
172
|
+
toolName: toolCall.function.name,
|
|
173
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
174
|
+
}))
|
|
175
|
+
});
|
|
176
|
+
}
|
|
162
177
|
} else if (message.role === "user") {
|
|
163
178
|
result.push({
|
|
164
179
|
role: "user",
|
|
@@ -180,6 +195,12 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
180
195
|
}
|
|
181
196
|
return result;
|
|
182
197
|
}
|
|
198
|
+
function zodToJsonSchema(zodSchema) {
|
|
199
|
+
if (!(zodSchema instanceof zod.ZodSchema)) {
|
|
200
|
+
return zodSchema;
|
|
201
|
+
}
|
|
202
|
+
return originalZodToJsonSchema__default.default(zodSchema, { $refStrategy: "none" });
|
|
203
|
+
}
|
|
183
204
|
|
|
184
205
|
// src/resources/base.ts
|
|
185
206
|
var BaseResource = class {
|
|
@@ -310,8 +331,8 @@ var Agent = class extends BaseResource {
|
|
|
310
331
|
generate(params) {
|
|
311
332
|
const processedParams = {
|
|
312
333
|
...params,
|
|
313
|
-
output:
|
|
314
|
-
experimental_output:
|
|
334
|
+
output: zodToJsonSchema(params.output),
|
|
335
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
315
336
|
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
316
337
|
};
|
|
317
338
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
@@ -327,8 +348,8 @@ var Agent = class extends BaseResource {
|
|
|
327
348
|
async stream(params) {
|
|
328
349
|
const processedParams = {
|
|
329
350
|
...params,
|
|
330
|
-
output:
|
|
331
|
-
experimental_output:
|
|
351
|
+
output: zodToJsonSchema(params.output),
|
|
352
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
332
353
|
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
333
354
|
};
|
|
334
355
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
@@ -406,8 +427,8 @@ var Network = class extends BaseResource {
|
|
|
406
427
|
generate(params) {
|
|
407
428
|
const processedParams = {
|
|
408
429
|
...params,
|
|
409
|
-
output:
|
|
410
|
-
experimental_output:
|
|
430
|
+
output: zodToJsonSchema(params.output),
|
|
431
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
411
432
|
};
|
|
412
433
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
413
434
|
method: "POST",
|
|
@@ -422,8 +443,8 @@ var Network = class extends BaseResource {
|
|
|
422
443
|
async stream(params) {
|
|
423
444
|
const processedParams = {
|
|
424
445
|
...params,
|
|
425
|
-
output:
|
|
426
|
-
experimental_output:
|
|
446
|
+
output: zodToJsonSchema(params.output),
|
|
447
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
427
448
|
};
|
|
428
449
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
429
450
|
method: "POST",
|
|
@@ -479,10 +500,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
479
500
|
}
|
|
480
501
|
/**
|
|
481
502
|
* Retrieves messages associated with the thread
|
|
503
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
482
504
|
* @returns Promise containing thread messages and UI messages
|
|
483
505
|
*/
|
|
484
|
-
getMessages() {
|
|
485
|
-
|
|
506
|
+
getMessages(params) {
|
|
507
|
+
const query = new URLSearchParams({
|
|
508
|
+
agentId: this.agentId,
|
|
509
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
510
|
+
});
|
|
511
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
486
512
|
}
|
|
487
513
|
};
|
|
488
514
|
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractAgent } from '@ag-ui/client';
|
|
2
2
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
3
|
-
import { CoreMessage, AiMessageType, StorageThreadType, MessageType,
|
|
3
|
+
import { StepAction, StepGraph, CoreMessage, AiMessageType, StorageThreadType, MessageType, WorkflowRuns, WorkflowRunResult as WorkflowRunResult$1, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
|
|
4
4
|
import { JSONSchema7 } from 'json-schema';
|
|
5
5
|
import { ZodSchema } from 'zod';
|
|
6
6
|
import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
@@ -32,15 +32,16 @@ interface GetAgentResponse {
|
|
|
32
32
|
name: string;
|
|
33
33
|
instructions: string;
|
|
34
34
|
tools: Record<string, GetToolResponse>;
|
|
35
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
35
36
|
provider: string;
|
|
36
37
|
modelId: string;
|
|
37
38
|
}
|
|
38
39
|
type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
39
40
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
40
|
-
} & Partial<AgentGenerateOptions<T>>;
|
|
41
|
+
} & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
|
|
41
42
|
type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
42
43
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
43
|
-
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry'>;
|
|
44
|
+
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
|
|
44
45
|
interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
45
46
|
evals: any[];
|
|
46
47
|
instructions: string;
|
|
@@ -148,6 +149,12 @@ interface UpdateMemoryThreadParams {
|
|
|
148
149
|
metadata: Record<string, any>;
|
|
149
150
|
resourceId: string;
|
|
150
151
|
}
|
|
152
|
+
interface GetMemoryThreadMessagesParams {
|
|
153
|
+
/**
|
|
154
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
155
|
+
*/
|
|
156
|
+
limit?: number;
|
|
157
|
+
}
|
|
151
158
|
interface GetMemoryThreadMessagesResponse {
|
|
152
159
|
messages: CoreMessage[];
|
|
153
160
|
uiMessages: AiMessageType[];
|
|
@@ -256,7 +263,9 @@ declare class AgentVoice extends BaseResource {
|
|
|
256
263
|
* @param options - Optional provider-specific options
|
|
257
264
|
* @returns Promise containing the transcribed text
|
|
258
265
|
*/
|
|
259
|
-
listen(audio: Blob, options?: Record<string, any>): Promise<
|
|
266
|
+
listen(audio: Blob, options?: Record<string, any>): Promise<{
|
|
267
|
+
text: string;
|
|
268
|
+
}>;
|
|
260
269
|
/**
|
|
261
270
|
* Get available speakers for the agent's voice provider
|
|
262
271
|
* @returns Promise containing list of available speakers
|
|
@@ -365,9 +374,10 @@ declare class MemoryThread extends BaseResource {
|
|
|
365
374
|
}>;
|
|
366
375
|
/**
|
|
367
376
|
* Retrieves messages associated with the thread
|
|
377
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
368
378
|
* @returns Promise containing thread messages and UI messages
|
|
369
379
|
*/
|
|
370
|
-
getMessages(): Promise<GetMemoryThreadMessagesResponse>;
|
|
380
|
+
getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse>;
|
|
371
381
|
}
|
|
372
382
|
|
|
373
383
|
declare class Vector extends BaseResource {
|
|
@@ -787,4 +797,4 @@ declare class MastraClient extends BaseResource {
|
|
|
787
797
|
getA2A(agentId: string): A2A;
|
|
788
798
|
}
|
|
789
799
|
|
|
790
|
-
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
|
|
800
|
+
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractAgent } from '@ag-ui/client';
|
|
2
2
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
3
|
-
import { CoreMessage, AiMessageType, StorageThreadType, MessageType,
|
|
3
|
+
import { StepAction, StepGraph, CoreMessage, AiMessageType, StorageThreadType, MessageType, WorkflowRuns, WorkflowRunResult as WorkflowRunResult$1, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
|
|
4
4
|
import { JSONSchema7 } from 'json-schema';
|
|
5
5
|
import { ZodSchema } from 'zod';
|
|
6
6
|
import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
|
|
@@ -32,15 +32,16 @@ interface GetAgentResponse {
|
|
|
32
32
|
name: string;
|
|
33
33
|
instructions: string;
|
|
34
34
|
tools: Record<string, GetToolResponse>;
|
|
35
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
35
36
|
provider: string;
|
|
36
37
|
modelId: string;
|
|
37
38
|
}
|
|
38
39
|
type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
39
40
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
40
|
-
} & Partial<AgentGenerateOptions<T>>;
|
|
41
|
+
} & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
|
|
41
42
|
type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
42
43
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
43
|
-
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry'>;
|
|
44
|
+
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
|
|
44
45
|
interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
45
46
|
evals: any[];
|
|
46
47
|
instructions: string;
|
|
@@ -148,6 +149,12 @@ interface UpdateMemoryThreadParams {
|
|
|
148
149
|
metadata: Record<string, any>;
|
|
149
150
|
resourceId: string;
|
|
150
151
|
}
|
|
152
|
+
interface GetMemoryThreadMessagesParams {
|
|
153
|
+
/**
|
|
154
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
155
|
+
*/
|
|
156
|
+
limit?: number;
|
|
157
|
+
}
|
|
151
158
|
interface GetMemoryThreadMessagesResponse {
|
|
152
159
|
messages: CoreMessage[];
|
|
153
160
|
uiMessages: AiMessageType[];
|
|
@@ -256,7 +263,9 @@ declare class AgentVoice extends BaseResource {
|
|
|
256
263
|
* @param options - Optional provider-specific options
|
|
257
264
|
* @returns Promise containing the transcribed text
|
|
258
265
|
*/
|
|
259
|
-
listen(audio: Blob, options?: Record<string, any>): Promise<
|
|
266
|
+
listen(audio: Blob, options?: Record<string, any>): Promise<{
|
|
267
|
+
text: string;
|
|
268
|
+
}>;
|
|
260
269
|
/**
|
|
261
270
|
* Get available speakers for the agent's voice provider
|
|
262
271
|
* @returns Promise containing list of available speakers
|
|
@@ -365,9 +374,10 @@ declare class MemoryThread extends BaseResource {
|
|
|
365
374
|
}>;
|
|
366
375
|
/**
|
|
367
376
|
* Retrieves messages associated with the thread
|
|
377
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
368
378
|
* @returns Promise containing thread messages and UI messages
|
|
369
379
|
*/
|
|
370
|
-
getMessages(): Promise<GetMemoryThreadMessagesResponse>;
|
|
380
|
+
getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse>;
|
|
371
381
|
}
|
|
372
382
|
|
|
373
383
|
declare class Vector extends BaseResource {
|
|
@@ -787,4 +797,4 @@ declare class MastraClient extends BaseResource {
|
|
|
787
797
|
getA2A(agentId: string): A2A;
|
|
788
798
|
}
|
|
789
799
|
|
|
790
|
-
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
|
|
800
|
+
export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
3
|
import { processDataStream } from '@ai-sdk/ui-utils';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
|
-
import
|
|
5
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
6
6
|
|
|
7
7
|
// src/adapters/agui.ts
|
|
8
8
|
var AGUIAdapter = class extends AbstractAgent {
|
|
@@ -157,6 +157,17 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
157
157
|
role: "assistant",
|
|
158
158
|
content: parts
|
|
159
159
|
});
|
|
160
|
+
if (message.toolCalls?.length) {
|
|
161
|
+
result.push({
|
|
162
|
+
role: "tool",
|
|
163
|
+
content: message.toolCalls.map((toolCall) => ({
|
|
164
|
+
type: "tool-result",
|
|
165
|
+
toolCallId: toolCall.id,
|
|
166
|
+
toolName: toolCall.function.name,
|
|
167
|
+
result: JSON.parse(toolCall.function.arguments)
|
|
168
|
+
}))
|
|
169
|
+
});
|
|
170
|
+
}
|
|
160
171
|
} else if (message.role === "user") {
|
|
161
172
|
result.push({
|
|
162
173
|
role: "user",
|
|
@@ -178,6 +189,12 @@ function convertMessagesToMastraMessages(messages) {
|
|
|
178
189
|
}
|
|
179
190
|
return result;
|
|
180
191
|
}
|
|
192
|
+
function zodToJsonSchema(zodSchema) {
|
|
193
|
+
if (!(zodSchema instanceof ZodSchema)) {
|
|
194
|
+
return zodSchema;
|
|
195
|
+
}
|
|
196
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: "none" });
|
|
197
|
+
}
|
|
181
198
|
|
|
182
199
|
// src/resources/base.ts
|
|
183
200
|
var BaseResource = class {
|
|
@@ -308,8 +325,8 @@ var Agent = class extends BaseResource {
|
|
|
308
325
|
generate(params) {
|
|
309
326
|
const processedParams = {
|
|
310
327
|
...params,
|
|
311
|
-
output:
|
|
312
|
-
experimental_output:
|
|
328
|
+
output: zodToJsonSchema(params.output),
|
|
329
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
313
330
|
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
314
331
|
};
|
|
315
332
|
return this.request(`/api/agents/${this.agentId}/generate`, {
|
|
@@ -325,8 +342,8 @@ var Agent = class extends BaseResource {
|
|
|
325
342
|
async stream(params) {
|
|
326
343
|
const processedParams = {
|
|
327
344
|
...params,
|
|
328
|
-
output:
|
|
329
|
-
experimental_output:
|
|
345
|
+
output: zodToJsonSchema(params.output),
|
|
346
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
330
347
|
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
|
|
331
348
|
};
|
|
332
349
|
const response = await this.request(`/api/agents/${this.agentId}/stream`, {
|
|
@@ -404,8 +421,8 @@ var Network = class extends BaseResource {
|
|
|
404
421
|
generate(params) {
|
|
405
422
|
const processedParams = {
|
|
406
423
|
...params,
|
|
407
|
-
output:
|
|
408
|
-
experimental_output:
|
|
424
|
+
output: zodToJsonSchema(params.output),
|
|
425
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
409
426
|
};
|
|
410
427
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
411
428
|
method: "POST",
|
|
@@ -420,8 +437,8 @@ var Network = class extends BaseResource {
|
|
|
420
437
|
async stream(params) {
|
|
421
438
|
const processedParams = {
|
|
422
439
|
...params,
|
|
423
|
-
output:
|
|
424
|
-
experimental_output:
|
|
440
|
+
output: zodToJsonSchema(params.output),
|
|
441
|
+
experimental_output: zodToJsonSchema(params.experimental_output)
|
|
425
442
|
};
|
|
426
443
|
const response = await this.request(`/api/networks/${this.networkId}/stream`, {
|
|
427
444
|
method: "POST",
|
|
@@ -477,10 +494,15 @@ var MemoryThread = class extends BaseResource {
|
|
|
477
494
|
}
|
|
478
495
|
/**
|
|
479
496
|
* Retrieves messages associated with the thread
|
|
497
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
480
498
|
* @returns Promise containing thread messages and UI messages
|
|
481
499
|
*/
|
|
482
|
-
getMessages() {
|
|
483
|
-
|
|
500
|
+
getMessages(params) {
|
|
501
|
+
const query = new URLSearchParams({
|
|
502
|
+
agentId: this.agentId,
|
|
503
|
+
...params?.limit ? { limit: params.limit.toString() } : {}
|
|
504
|
+
});
|
|
505
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
484
506
|
}
|
|
485
507
|
};
|
|
486
508
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "0.1.22-alpha.
|
|
3
|
+
"version": "0.1.22-alpha.3",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"rxjs": "7.8.1",
|
|
29
29
|
"zod": "^3.24.3",
|
|
30
30
|
"zod-to-json-schema": "^3.24.5",
|
|
31
|
-
"@mastra/core": "^0.9.4-alpha.
|
|
31
|
+
"@mastra/core": "^0.9.4-alpha.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"zod": "^3.0.0"
|
|
@@ -91,6 +91,17 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
91
91
|
},
|
|
92
92
|
],
|
|
93
93
|
},
|
|
94
|
+
{
|
|
95
|
+
role: 'tool',
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'tool-result',
|
|
99
|
+
toolCallId: 'tool-call-1',
|
|
100
|
+
toolName: 'getWeather',
|
|
101
|
+
result: { location: 'San Francisco' },
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
94
105
|
]);
|
|
95
106
|
});
|
|
96
107
|
|
|
@@ -143,12 +154,6 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
143
154
|
},
|
|
144
155
|
],
|
|
145
156
|
},
|
|
146
|
-
{
|
|
147
|
-
id: '3',
|
|
148
|
-
role: 'tool',
|
|
149
|
-
toolCallId: 'tool-call-1',
|
|
150
|
-
content: '{"temperature":72,"unit":"F"}',
|
|
151
|
-
},
|
|
152
157
|
{
|
|
153
158
|
id: '4',
|
|
154
159
|
role: 'assistant',
|
|
@@ -162,6 +167,14 @@ describe('convertMessagesToMastraMessages', () => {
|
|
|
162
167
|
expect(result[0].role).toBe('user');
|
|
163
168
|
expect(result[1].role).toBe('assistant');
|
|
164
169
|
expect(result[2].role).toBe('tool');
|
|
170
|
+
expect(result[2].content).toEqual([
|
|
171
|
+
{
|
|
172
|
+
type: 'tool-result',
|
|
173
|
+
toolCallId: 'tool-call-1',
|
|
174
|
+
toolName: 'getWeather',
|
|
175
|
+
result: { location: 'San Francisco' },
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
165
178
|
expect(result[3].role).toBe('assistant');
|
|
166
179
|
});
|
|
167
180
|
});
|
package/src/adapters/agui.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
// Cross-platform UUID generation function
|
|
2
|
-
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
3
2
|
import type {
|
|
3
|
+
AgentConfig,
|
|
4
4
|
BaseEvent,
|
|
5
|
+
Message,
|
|
5
6
|
RunAgentInput,
|
|
6
|
-
AgentConfig,
|
|
7
|
-
RunStartedEvent,
|
|
8
7
|
RunFinishedEvent,
|
|
9
|
-
|
|
8
|
+
RunStartedEvent,
|
|
10
9
|
TextMessageContentEvent,
|
|
11
10
|
TextMessageEndEvent,
|
|
12
|
-
|
|
13
|
-
ToolCallStartEvent,
|
|
11
|
+
TextMessageStartEvent,
|
|
14
12
|
ToolCallArgsEvent,
|
|
15
13
|
ToolCallEndEvent,
|
|
14
|
+
ToolCallStartEvent,
|
|
16
15
|
} from '@ag-ui/client';
|
|
16
|
+
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
17
17
|
import type { CoreMessage } from '@mastra/core';
|
|
18
18
|
import { Observable } from 'rxjs';
|
|
19
19
|
import type { Agent } from '../resources/agent';
|
|
@@ -39,7 +39,6 @@ export class AGUIAdapter extends AbstractAgent {
|
|
|
39
39
|
protected run(input: RunAgentInput): Observable<BaseEvent> {
|
|
40
40
|
return new Observable<BaseEvent>(subscriber => {
|
|
41
41
|
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
42
|
-
|
|
43
42
|
subscriber.next({
|
|
44
43
|
type: EventType.RUN_STARTED,
|
|
45
44
|
threadId: input.threadId,
|
|
@@ -205,6 +204,17 @@ export function convertMessagesToMastraMessages(messages: Message[]): CoreMessag
|
|
|
205
204
|
role: 'assistant',
|
|
206
205
|
content: parts,
|
|
207
206
|
});
|
|
207
|
+
if (message.toolCalls?.length) {
|
|
208
|
+
result.push({
|
|
209
|
+
role: 'tool',
|
|
210
|
+
content: message.toolCalls.map(toolCall => ({
|
|
211
|
+
type: 'tool-result',
|
|
212
|
+
toolCallId: toolCall.id,
|
|
213
|
+
toolName: toolCall.function.name,
|
|
214
|
+
result: JSON.parse(toolCall.function.arguments),
|
|
215
|
+
})),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
208
218
|
} else if (message.role === 'user') {
|
|
209
219
|
result.push({
|
|
210
220
|
role: 'user',
|
package/src/index.test.ts
CHANGED
|
@@ -236,6 +236,7 @@ describe('MastraClient Resources', () => {
|
|
|
236
236
|
model: 'gpt-4',
|
|
237
237
|
instructions: 'Test instructions',
|
|
238
238
|
tools: {},
|
|
239
|
+
workflows: {},
|
|
239
240
|
};
|
|
240
241
|
mockFetchResponse(mockResponse);
|
|
241
242
|
|
|
@@ -552,6 +553,35 @@ describe('MastraClient Resources', () => {
|
|
|
552
553
|
}),
|
|
553
554
|
);
|
|
554
555
|
});
|
|
556
|
+
|
|
557
|
+
it('should get thread messages with limit', async () => {
|
|
558
|
+
const mockResponse = {
|
|
559
|
+
messages: [
|
|
560
|
+
{
|
|
561
|
+
id: '1',
|
|
562
|
+
content: 'test',
|
|
563
|
+
threadId,
|
|
564
|
+
role: 'user',
|
|
565
|
+
type: 'text',
|
|
566
|
+
resourceId: 'test-resource',
|
|
567
|
+
createdAt: new Date(),
|
|
568
|
+
},
|
|
569
|
+
],
|
|
570
|
+
uiMessages: [],
|
|
571
|
+
};
|
|
572
|
+
mockFetchResponse(mockResponse);
|
|
573
|
+
|
|
574
|
+
const limit = 5;
|
|
575
|
+
const result = await memoryThread.getMessages({ limit });
|
|
576
|
+
|
|
577
|
+
expect(result).toEqual(mockResponse);
|
|
578
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
579
|
+
`${clientOptions.baseUrl}/api/memory/threads/${threadId}/messages?agentId=${agentId}&limit=${limit}`,
|
|
580
|
+
expect.objectContaining({
|
|
581
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
582
|
+
}),
|
|
583
|
+
);
|
|
584
|
+
});
|
|
555
585
|
});
|
|
556
586
|
|
|
557
587
|
describe('Tool Resource', () => {
|
package/src/resources/agent.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { processDataStream } from '@ai-sdk/ui-utils';
|
|
|
2
2
|
import type { GenerateReturn } from '@mastra/core';
|
|
3
3
|
import type { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
5
|
+
import { zodToJsonSchema } from '../utils/zod-to-json-schema';
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
GenerateParams,
|
|
@@ -48,7 +48,7 @@ export class AgentVoice extends BaseResource {
|
|
|
48
48
|
* @param options - Optional provider-specific options
|
|
49
49
|
* @returns Promise containing the transcribed text
|
|
50
50
|
*/
|
|
51
|
-
listen(audio: Blob, options?: Record<string, any>): Promise<
|
|
51
|
+
listen(audio: Blob, options?: Record<string, any>): Promise<{ text: string }> {
|
|
52
52
|
const formData = new FormData();
|
|
53
53
|
formData.append('audio', audio);
|
|
54
54
|
|
|
@@ -100,11 +100,8 @@ export class Agent extends BaseResource {
|
|
|
100
100
|
): Promise<GenerateReturn<T>> {
|
|
101
101
|
const processedParams = {
|
|
102
102
|
...params,
|
|
103
|
-
output:
|
|
104
|
-
experimental_output:
|
|
105
|
-
params.experimental_output instanceof ZodSchema
|
|
106
|
-
? zodToJsonSchema(params.experimental_output)
|
|
107
|
-
: params.experimental_output,
|
|
103
|
+
output: zodToJsonSchema(params.output),
|
|
104
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
108
105
|
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
|
|
109
106
|
};
|
|
110
107
|
|
|
@@ -128,11 +125,8 @@ export class Agent extends BaseResource {
|
|
|
128
125
|
> {
|
|
129
126
|
const processedParams = {
|
|
130
127
|
...params,
|
|
131
|
-
output:
|
|
132
|
-
experimental_output:
|
|
133
|
-
params.experimental_output instanceof ZodSchema
|
|
134
|
-
? zodToJsonSchema(params.experimental_output)
|
|
135
|
-
: params.experimental_output,
|
|
128
|
+
output: zodToJsonSchema(params.output),
|
|
129
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
136
130
|
runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
|
|
137
131
|
};
|
|
138
132
|
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { StorageThreadType } from '@mastra/core';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type {
|
|
4
|
+
GetMemoryThreadMessagesResponse,
|
|
5
|
+
ClientOptions,
|
|
6
|
+
UpdateMemoryThreadParams,
|
|
7
|
+
GetMemoryThreadMessagesParams,
|
|
8
|
+
} from '../types';
|
|
4
9
|
|
|
5
10
|
import { BaseResource } from './base';
|
|
6
11
|
|
|
@@ -45,9 +50,14 @@ export class MemoryThread extends BaseResource {
|
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
52
|
* Retrieves messages associated with the thread
|
|
53
|
+
* @param params - Optional parameters including limit for number of messages to retrieve
|
|
48
54
|
* @returns Promise containing thread messages and UI messages
|
|
49
55
|
*/
|
|
50
|
-
getMessages(): Promise<GetMemoryThreadMessagesResponse> {
|
|
51
|
-
|
|
56
|
+
getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse> {
|
|
57
|
+
const query = new URLSearchParams({
|
|
58
|
+
agentId: this.agentId,
|
|
59
|
+
...(params?.limit ? { limit: params.limit.toString() } : {}),
|
|
60
|
+
});
|
|
61
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
52
62
|
}
|
|
53
63
|
}
|
package/src/resources/network.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { processDataStream } from '@ai-sdk/ui-utils';
|
|
|
2
2
|
import type { GenerateReturn } from '@mastra/core';
|
|
3
3
|
import type { JSONSchema7 } from 'json-schema';
|
|
4
4
|
import { ZodSchema } from 'zod';
|
|
5
|
-
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
5
|
+
import { zodToJsonSchema } from '../utils/zod-to-json-schema';
|
|
6
6
|
|
|
7
7
|
import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
|
|
8
8
|
|
|
@@ -34,11 +34,8 @@ export class Network extends BaseResource {
|
|
|
34
34
|
): Promise<GenerateReturn<T>> {
|
|
35
35
|
const processedParams = {
|
|
36
36
|
...params,
|
|
37
|
-
output:
|
|
38
|
-
experimental_output:
|
|
39
|
-
params.experimental_output instanceof ZodSchema
|
|
40
|
-
? zodToJsonSchema(params.experimental_output)
|
|
41
|
-
: params.experimental_output,
|
|
37
|
+
output: zodToJsonSchema(params.output),
|
|
38
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
42
39
|
};
|
|
43
40
|
|
|
44
41
|
return this.request(`/api/networks/${this.networkId}/generate`, {
|
|
@@ -61,11 +58,8 @@ export class Network extends BaseResource {
|
|
|
61
58
|
> {
|
|
62
59
|
const processedParams = {
|
|
63
60
|
...params,
|
|
64
|
-
output:
|
|
65
|
-
experimental_output:
|
|
66
|
-
params.experimental_output instanceof ZodSchema
|
|
67
|
-
? zodToJsonSchema(params.experimental_output)
|
|
68
|
-
: params.experimental_output,
|
|
61
|
+
output: zodToJsonSchema(params.output),
|
|
62
|
+
experimental_output: zodToJsonSchema(params.experimental_output),
|
|
69
63
|
};
|
|
70
64
|
|
|
71
65
|
const response: Response & {
|
package/src/types.ts
CHANGED
|
@@ -42,17 +42,18 @@ export interface GetAgentResponse {
|
|
|
42
42
|
name: string;
|
|
43
43
|
instructions: string;
|
|
44
44
|
tools: Record<string, GetToolResponse>;
|
|
45
|
+
workflows: Record<string, GetWorkflowResponse>;
|
|
45
46
|
provider: string;
|
|
46
47
|
modelId: string;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
50
51
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
51
|
-
} & Partial<AgentGenerateOptions<T>>;
|
|
52
|
+
} & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
|
|
52
53
|
|
|
53
54
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
54
55
|
messages: string | string[] | CoreMessage[] | AiMessageType[];
|
|
55
|
-
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry'>;
|
|
56
|
+
} & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
|
|
56
57
|
|
|
57
58
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
58
59
|
evals: any[];
|
|
@@ -174,6 +175,13 @@ export interface UpdateMemoryThreadParams {
|
|
|
174
175
|
resourceId: string;
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
export interface GetMemoryThreadMessagesParams {
|
|
179
|
+
/**
|
|
180
|
+
* Limit the number of messages to retrieve (default: 40)
|
|
181
|
+
*/
|
|
182
|
+
limit?: number;
|
|
183
|
+
}
|
|
184
|
+
|
|
177
185
|
export interface GetMemoryThreadMessagesResponse {
|
|
178
186
|
messages: CoreMessage[];
|
|
179
187
|
uiMessages: AiMessageType[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ZodSchema } from 'zod';
|
|
2
|
+
import originalZodToJsonSchema from 'zod-to-json-schema';
|
|
3
|
+
|
|
4
|
+
export function zodToJsonSchema<T extends ZodSchema | any>(zodSchema: T) {
|
|
5
|
+
if (!(zodSchema instanceof ZodSchema)) {
|
|
6
|
+
return zodSchema;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return originalZodToJsonSchema(zodSchema, { $refStrategy: 'none' });
|
|
10
|
+
}
|