@mastra/client-js 0.0.0-feat-tool-input-validation-20250731232758 → 0.0.0-feat-support-ai-sdk-5-again-20250813225910
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 +18 -0
- package/CHANGELOG.md +178 -3
- package/dist/adapters/agui.d.ts +22 -0
- package/dist/adapters/agui.d.ts.map +1 -0
- package/dist/client.d.ts +270 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +87 -42
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -1328
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -39
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +41 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +123 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/legacy-workflow.d.ts +87 -0
- package/dist/resources/legacy-workflow.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +27 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +53 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/network-memory-thread.d.ts +47 -0
- package/dist/resources/network-memory-thread.d.ts.map +1 -0
- package/dist/resources/network.d.ts +30 -0
- package/dist/resources/network.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +23 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vNextNetwork.d.ts +42 -0
- package/dist/resources/vNextNetwork.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +48 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +154 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/types.d.ts +427 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +105 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/integration-tests/agui-adapter.test.ts +122 -0
- package/integration-tests/package.json +17 -0
- package/integration-tests/src/mastra/index.ts +38 -0
- package/integration-tests/vitest.config.ts +9 -0
- package/package.json +11 -7
- package/src/adapters/agui.test.ts +145 -3
- package/src/adapters/agui.ts +41 -17
- package/src/client.ts +8 -0
- package/src/index.ts +0 -1
- package/src/resources/a2a.ts +35 -25
- package/src/resources/agent.ts +26 -18
- package/src/resources/base.ts +1 -0
- package/src/resources/memory-thread.ts +1 -0
- package/src/resources/network.ts +1 -1
- package/src/types.ts +9 -5
- package/src/utils/process-client-tools.ts +1 -1
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +17 -0
- package/dist/index.d.cts +0 -1328
package/src/resources/agent.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
processDataStream,
|
|
4
|
-
type JSONValue,
|
|
5
|
-
type ReasoningUIPart,
|
|
6
|
-
type TextUIPart,
|
|
7
|
-
type ToolInvocation,
|
|
8
|
-
type ToolInvocationUIPart,
|
|
9
|
-
type UIMessage,
|
|
10
|
-
type UseChatOptions,
|
|
11
|
-
} from '@ai-sdk/ui-utils';
|
|
12
|
-
import { Tool, type CoreMessage } from '@mastra/core';
|
|
1
|
+
import { processDataStream, type JSONValue, type ToolInvocation, type UIMessage } from 'ai';
|
|
2
|
+
import { Tool, type CoreMessage, type MastraLanguageModel } from '@mastra/core';
|
|
13
3
|
import { type GenerateReturn } from '@mastra/core/llm';
|
|
14
4
|
import type { JSONSchema7 } from 'json-schema';
|
|
15
5
|
import { ZodSchema } from 'zod';
|
|
@@ -213,7 +203,7 @@ export class Agent extends BaseResource {
|
|
|
213
203
|
}: {
|
|
214
204
|
stream: ReadableStream<Uint8Array>;
|
|
215
205
|
update: (options: { message: UIMessage; data: JSONValue[] | undefined; replaceLastMessage: boolean }) => void;
|
|
216
|
-
onToolCall?:
|
|
206
|
+
onToolCall?: any;
|
|
217
207
|
onFinish?: (options: { message: UIMessage | undefined; finishReason: string; usage: string }) => void;
|
|
218
208
|
generateId?: () => string;
|
|
219
209
|
getCurrentDate?: () => Date;
|
|
@@ -238,14 +228,14 @@ export class Agent extends BaseResource {
|
|
|
238
228
|
parts: [],
|
|
239
229
|
};
|
|
240
230
|
|
|
241
|
-
let currentTextPart:
|
|
242
|
-
let currentReasoningPart:
|
|
231
|
+
let currentTextPart: any | undefined = undefined;
|
|
232
|
+
let currentReasoningPart: any | undefined = undefined;
|
|
243
233
|
let currentReasoningTextDetail: { type: 'text'; text: string; signature?: string } | undefined = undefined;
|
|
244
234
|
|
|
245
235
|
function updateToolInvocationPart(toolCallId: string, invocation: ToolInvocation) {
|
|
246
236
|
const part = message.parts.find(
|
|
247
237
|
part => part.type === 'tool-invocation' && part.toolInvocation.toolCallId === toolCallId,
|
|
248
|
-
) as
|
|
238
|
+
) as any | undefined;
|
|
249
239
|
|
|
250
240
|
if (part != null) {
|
|
251
241
|
part.toolInvocation = invocation;
|
|
@@ -415,7 +405,13 @@ export class Agent extends BaseResource {
|
|
|
415
405
|
|
|
416
406
|
partialToolCall!.text += value.argsTextDelta;
|
|
417
407
|
|
|
418
|
-
|
|
408
|
+
// In v4, we don't have parsePartialJson, so we'll try to parse it directly
|
|
409
|
+
let partialArgs;
|
|
410
|
+
try {
|
|
411
|
+
partialArgs = JSON.parse(partialToolCall!.text);
|
|
412
|
+
} catch {
|
|
413
|
+
partialArgs = undefined;
|
|
414
|
+
}
|
|
419
415
|
|
|
420
416
|
const invocation = {
|
|
421
417
|
state: 'partial-call',
|
|
@@ -671,7 +667,7 @@ export class Agent extends BaseResource {
|
|
|
671
667
|
|
|
672
668
|
const toolInvocationPart = lastMessage?.parts?.find(
|
|
673
669
|
part => part.type === 'tool-invocation' && part.toolInvocation?.toolCallId === toolCall.toolCallId,
|
|
674
|
-
) as
|
|
670
|
+
) as any | undefined;
|
|
675
671
|
|
|
676
672
|
if (toolInvocationPart) {
|
|
677
673
|
toolInvocationPart.toolInvocation = {
|
|
@@ -782,4 +778,16 @@ export class Agent extends BaseResource {
|
|
|
782
778
|
liveEvals(): Promise<GetEvalsByAgentIdResponse> {
|
|
783
779
|
return this.request(`/api/agents/${this.agentId}/evals/live`);
|
|
784
780
|
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Updates the model for the agent
|
|
784
|
+
* @param params - Parameters for updating the model
|
|
785
|
+
* @returns Promise containing the updated model
|
|
786
|
+
*/
|
|
787
|
+
updateModel(params: { model: MastraLanguageModel }): Promise<{ message: string }> {
|
|
788
|
+
return this.request(`/api/agents/${this.agentId}/model`, {
|
|
789
|
+
method: 'POST',
|
|
790
|
+
body: params,
|
|
791
|
+
});
|
|
792
|
+
}
|
|
785
793
|
}
|
package/src/resources/base.ts
CHANGED
|
@@ -33,6 +33,7 @@ export class BaseResource {
|
|
|
33
33
|
...options.headers,
|
|
34
34
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
35
35
|
// 'x-mastra-client-type': 'js',
|
|
36
|
+
'x-ai-sdk-compat': 'v4',
|
|
36
37
|
},
|
|
37
38
|
signal: this.options.abortSignal,
|
|
38
39
|
body:
|
|
@@ -59,6 +59,7 @@ export class MemoryThread extends BaseResource {
|
|
|
59
59
|
const query = new URLSearchParams({
|
|
60
60
|
agentId: this.agentId,
|
|
61
61
|
...(params?.limit ? { limit: params.limit.toString() } : {}),
|
|
62
|
+
...(params?.format ? { format: params.format } : {}),
|
|
62
63
|
});
|
|
63
64
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
64
65
|
}
|
package/src/resources/network.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { UIMessage } from 'ai';
|
|
1
2
|
import type {
|
|
2
3
|
MastraMessageV1,
|
|
3
|
-
AiMessageType,
|
|
4
4
|
CoreMessage,
|
|
5
5
|
QueryResult,
|
|
6
6
|
StorageThreadType,
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
PaginationInfo,
|
|
12
12
|
MastraMessageV2,
|
|
13
13
|
} from '@mastra/core';
|
|
14
|
-
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput
|
|
14
|
+
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
15
15
|
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
16
16
|
|
|
17
17
|
import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
|
|
@@ -70,7 +70,7 @@ export interface GetAgentResponse {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
73
|
-
messages: string | string[] | CoreMessage[] |
|
|
73
|
+
messages: string | string[] | CoreMessage[] | UIMessage[];
|
|
74
74
|
output?: T;
|
|
75
75
|
experimental_output?: T;
|
|
76
76
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
@@ -80,7 +80,7 @@ export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undef
|
|
|
80
80
|
>;
|
|
81
81
|
|
|
82
82
|
export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
|
|
83
|
-
messages: string | string[] | CoreMessage[] |
|
|
83
|
+
messages: string | string[] | CoreMessage[] | UIMessage[];
|
|
84
84
|
output?: T;
|
|
85
85
|
experimental_output?: T;
|
|
86
86
|
runtimeContext?: RuntimeContext | Record<string, any>;
|
|
@@ -250,13 +250,17 @@ export interface GetMemoryThreadMessagesParams {
|
|
|
250
250
|
* Limit the number of messages to retrieve (default: 40)
|
|
251
251
|
*/
|
|
252
252
|
limit?: number;
|
|
253
|
+
/**
|
|
254
|
+
* Format of UI messages to return (default: aiv5)
|
|
255
|
+
*/
|
|
256
|
+
format?: 'aiv4' | 'aiv5';
|
|
253
257
|
}
|
|
254
258
|
|
|
255
259
|
export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
|
|
256
260
|
|
|
257
261
|
export interface GetMemoryThreadMessagesResponse {
|
|
258
262
|
messages: CoreMessage[];
|
|
259
|
-
uiMessages:
|
|
263
|
+
uiMessages: UIMessage[];
|
|
260
264
|
}
|
|
261
265
|
|
|
262
266
|
export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
|
|
@@ -14,7 +14,7 @@ export function processClientTools(clientTools: ToolsInput | undefined): ToolsIn
|
|
|
14
14
|
key,
|
|
15
15
|
{
|
|
16
16
|
...value,
|
|
17
|
-
|
|
17
|
+
inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : undefined,
|
|
18
18
|
},
|
|
19
19
|
];
|
|
20
20
|
} else {
|
package/tsconfig.json
CHANGED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
import { generateTypes } from '@internal/types-builder';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
entry: ['src/index.ts'],
|
|
6
|
+
format: ['esm', 'cjs'],
|
|
7
|
+
clean: true,
|
|
8
|
+
dts: false,
|
|
9
|
+
splitting: true,
|
|
10
|
+
treeshake: {
|
|
11
|
+
preset: 'smallest',
|
|
12
|
+
},
|
|
13
|
+
sourcemap: true,
|
|
14
|
+
onSuccess: async () => {
|
|
15
|
+
await generateTypes(process.cwd());
|
|
16
|
+
},
|
|
17
|
+
});
|