@mastra/client-js 0.0.0-ai-v5-20250729181825 → 0.0.0-ai-v5-20250813235735

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.
Files changed (66) hide show
  1. package/.turbo/turbo-build.log +18 -0
  2. package/CHANGELOG.md +215 -20
  3. package/dist/adapters/agui.d.ts +22 -0
  4. package/dist/adapters/agui.d.ts.map +1 -0
  5. package/dist/client.d.ts +270 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/example.d.ts +2 -0
  8. package/dist/example.d.ts.map +1 -0
  9. package/dist/index.cjs +85 -41
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.ts +3 -1331
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +82 -38
  14. package/dist/index.js.map +1 -0
  15. package/dist/resources/a2a.d.ts +41 -0
  16. package/dist/resources/a2a.d.ts.map +1 -0
  17. package/dist/resources/agent.d.ts +123 -0
  18. package/dist/resources/agent.d.ts.map +1 -0
  19. package/dist/resources/base.d.ts +13 -0
  20. package/dist/resources/base.d.ts.map +1 -0
  21. package/dist/resources/index.d.ts +11 -0
  22. package/dist/resources/index.d.ts.map +1 -0
  23. package/dist/resources/legacy-workflow.d.ts +87 -0
  24. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  25. package/dist/resources/mcp-tool.d.ts +27 -0
  26. package/dist/resources/mcp-tool.d.ts.map +1 -0
  27. package/dist/resources/memory-thread.d.ts +53 -0
  28. package/dist/resources/memory-thread.d.ts.map +1 -0
  29. package/dist/resources/network-memory-thread.d.ts +47 -0
  30. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  31. package/dist/resources/network.d.ts +30 -0
  32. package/dist/resources/network.d.ts.map +1 -0
  33. package/dist/resources/tool.d.ts +23 -0
  34. package/dist/resources/tool.d.ts.map +1 -0
  35. package/dist/resources/vNextNetwork.d.ts +42 -0
  36. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  37. package/dist/resources/vector.d.ts +48 -0
  38. package/dist/resources/vector.d.ts.map +1 -0
  39. package/dist/resources/workflow.d.ts +154 -0
  40. package/dist/resources/workflow.d.ts.map +1 -0
  41. package/dist/types.d.ts +427 -0
  42. package/dist/types.d.ts.map +1 -0
  43. package/dist/utils/index.d.ts +3 -0
  44. package/dist/utils/index.d.ts.map +1 -0
  45. package/dist/utils/process-client-tools.d.ts +3 -0
  46. package/dist/utils/process-client-tools.d.ts.map +1 -0
  47. package/dist/utils/zod-to-json-schema.d.ts +105 -0
  48. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  49. package/integration-tests/agui-adapter.test.ts +122 -0
  50. package/integration-tests/package.json +17 -0
  51. package/integration-tests/src/mastra/index.ts +38 -0
  52. package/integration-tests/vitest.config.ts +9 -0
  53. package/package.json +12 -8
  54. package/src/adapters/agui.test.ts +145 -3
  55. package/src/adapters/agui.ts +41 -17
  56. package/src/client.ts +8 -0
  57. package/src/resources/a2a.ts +35 -25
  58. package/src/resources/agent.ts +26 -18
  59. package/src/resources/base.ts +1 -0
  60. package/src/resources/network.ts +1 -1
  61. package/src/types.ts +1 -1
  62. package/src/utils/process-client-tools.ts +1 -1
  63. package/tsconfig.build.json +9 -0
  64. package/tsconfig.json +1 -1
  65. package/tsup.config.ts +17 -0
  66. package/dist/index.d.cts +0 -1331
@@ -1,15 +1,5 @@
1
- import {
2
- parsePartialJson,
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?: UseChatOptions['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: TextUIPart | undefined = undefined;
242
- let currentReasoningPart: ReasoningUIPart | undefined = undefined;
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 ToolInvocationUIPart | undefined;
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
- const { value: partialArgs } = parsePartialJson(partialToolCall!.text);
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 ToolInvocationUIPart | undefined;
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
  }
@@ -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:
@@ -1,4 +1,4 @@
1
- import { processDataStream } from '@ai-sdk/ui-utils';
1
+ import { processDataStream } from 'ai';
2
2
  import type { GenerateReturn } from '@mastra/core';
3
3
  import type { JSONSchema7 } from 'json-schema';
4
4
  import type { ZodSchema } from 'zod';
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { UIMessage } from '@ai-sdk/ui-utils';
1
+ import type { UIMessage } from 'ai';
2
2
  import type {
3
3
  MastraMessageV1,
4
4
  CoreMessage,
@@ -14,7 +14,7 @@ export function processClientTools(clientTools: ToolsInput | undefined): ToolsIn
14
14
  key,
15
15
  {
16
16
  ...value,
17
- parameters: value.parameters ? zodToJsonSchema(value.parameters) : undefined,
17
+ inputSchema: value.inputSchema ? zodToJsonSchema(value.inputSchema) : undefined,
18
18
  },
19
19
  ];
20
20
  } else {
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": ["./tsconfig.json", "../../tsconfig.build.json"],
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "**/*.test.ts", "src/**/*.mock.ts"]
9
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
3
+ "include": ["src/**/*", "tsup.config.ts"],
4
4
  "exclude": ["node_modules", "**/*.test.ts"]
5
5
  }
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
+ });