@mastra/client-js 0.0.0-storage-20250225005900 → 0.0.0-stream-vnext-usage-20250908171242

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 (73) hide show
  1. package/CHANGELOG.md +2639 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +12 -6
  4. package/dist/client.d.ts +280 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/example.d.ts +2 -0
  7. package/dist/example.d.ts.map +1 -0
  8. package/dist/index.cjs +3279 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.ts +4 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +3273 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/resources/a2a.d.ts +41 -0
  15. package/dist/resources/a2a.d.ts.map +1 -0
  16. package/dist/resources/agent-builder.d.ts +161 -0
  17. package/dist/resources/agent-builder.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +155 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +13 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/observability.d.ts +19 -0
  35. package/dist/resources/observability.d.ts.map +1 -0
  36. package/dist/resources/tool.d.ts +23 -0
  37. package/dist/resources/tool.d.ts.map +1 -0
  38. package/dist/resources/vNextNetwork.d.ts +42 -0
  39. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  40. package/dist/resources/vector.d.ts +48 -0
  41. package/dist/resources/vector.d.ts.map +1 -0
  42. package/dist/resources/workflow.d.ts +169 -0
  43. package/dist/resources/workflow.d.ts.map +1 -0
  44. package/dist/types.d.ts +461 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/utils/index.d.ts +3 -0
  47. package/dist/utils/index.d.ts.map +1 -0
  48. package/dist/utils/process-client-tools.d.ts +3 -0
  49. package/dist/utils/process-client-tools.d.ts.map +1 -0
  50. package/dist/utils/process-mastra-stream.d.ts +7 -0
  51. package/dist/utils/process-mastra-stream.d.ts.map +1 -0
  52. package/dist/utils/zod-to-json-schema.d.ts +3 -0
  53. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  54. package/package.json +50 -21
  55. package/.turbo/turbo-build.log +0 -16
  56. package/LICENSE +0 -44
  57. package/dist/index.d.mts +0 -405
  58. package/dist/index.mjs +0 -487
  59. package/eslint.config.js +0 -6
  60. package/src/client.ts +0 -205
  61. package/src/example.ts +0 -43
  62. package/src/index.test.ts +0 -597
  63. package/src/index.ts +0 -2
  64. package/src/resources/agent.ts +0 -116
  65. package/src/resources/base.ts +0 -68
  66. package/src/resources/index.ts +0 -6
  67. package/src/resources/memory-thread.ts +0 -60
  68. package/src/resources/tool.ts +0 -32
  69. package/src/resources/vector.ts +0 -83
  70. package/src/resources/workflow.ts +0 -68
  71. package/src/types.ts +0 -163
  72. package/tsconfig.json +0 -5
  73. package/vitest.config.js +0 -8
@@ -1,116 +0,0 @@
1
- import type { GenerateReturn, StreamReturn } from '@mastra/core';
2
- import type { JSONSchema7 } from 'json-schema';
3
- import { ZodSchema } from 'zod';
4
- import { zodToJsonSchema } from 'zod-to-json-schema';
5
-
6
- import type {
7
- GenerateParams,
8
- GetAgentResponse,
9
- GetEvalsByAgentIdResponse,
10
- GetToolResponse,
11
- ClientOptions,
12
- StreamParams,
13
- } from '../types';
14
-
15
- import { BaseResource } from './base';
16
-
17
- export class AgentTool extends BaseResource {
18
- constructor(
19
- options: ClientOptions,
20
- private agentId: string,
21
- private toolId: string,
22
- ) {
23
- super(options);
24
- }
25
-
26
- /**
27
- * Executes a specific tool for an agent
28
- * @param params - Parameters required for tool execution
29
- * @returns Promise containing tool execution results
30
- */
31
- execute(params: { data: any }): Promise<any> {
32
- return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
33
- method: 'POST',
34
- body: params,
35
- });
36
- }
37
- }
38
-
39
- export class Agent extends BaseResource {
40
- constructor(
41
- options: ClientOptions,
42
- private agentId: string,
43
- ) {
44
- super(options);
45
- }
46
-
47
- /**
48
- * Retrieves details about the agent
49
- * @returns Promise containing agent details including model and instructions
50
- */
51
- details(): Promise<GetAgentResponse> {
52
- return this.request(`/api/agents/${this.agentId}`);
53
- }
54
-
55
- /**
56
- * Generates a response from the agent
57
- * @param params - Generation parameters including prompt
58
- * @returns Promise containing the generated response
59
- */
60
- generate<T extends JSONSchema7 | ZodSchema | undefined = undefined>(
61
- params: GenerateParams<T>,
62
- ): Promise<GenerateReturn<T>> {
63
- const processedParams = {
64
- ...params,
65
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
66
- };
67
-
68
- return this.request(`/api/agents/${this.agentId}/generate`, {
69
- method: 'POST',
70
- body: processedParams,
71
- });
72
- }
73
-
74
- /**
75
- * Streams a response from the agent
76
- * @param params - Stream parameters including prompt
77
- * @returns Promise containing the streamed response
78
- */
79
- stream<T extends JSONSchema7 | ZodSchema | undefined = undefined>(params: StreamParams<T>): Promise<Response> {
80
- const processedParams = {
81
- ...params,
82
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
83
- };
84
-
85
- return this.request(`/api/agents/${this.agentId}/stream`, {
86
- method: 'POST',
87
- body: processedParams,
88
- stream: true,
89
- });
90
- }
91
-
92
- /**
93
- * Gets details about a specific tool available to the agent
94
- * @param toolId - ID of the tool to retrieve
95
- * @returns Promise containing tool details
96
- */
97
- getTool(toolId: string): Promise<GetToolResponse> {
98
- return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
99
- }
100
-
101
- /**
102
- * Retrieves evaluation results for the agent
103
- * @returns Promise containing agent evaluations
104
- */
105
- evals(): Promise<GetEvalsByAgentIdResponse> {
106
- return this.request(`/api/agents/${this.agentId}/evals/ci`);
107
- }
108
-
109
- /**
110
- * Retrieves live evaluation results for the agent
111
- * @returns Promise containing live agent evaluations
112
- */
113
- liveEvals(): Promise<GetEvalsByAgentIdResponse> {
114
- return this.request(`/api/agents/${this.agentId}/evals/live`);
115
- }
116
- }
@@ -1,68 +0,0 @@
1
- import type { RequestFunction, RequestOptions, ClientOptions } from '../types';
2
-
3
- export class BaseResource {
4
- readonly options: ClientOptions;
5
-
6
- constructor(options: ClientOptions) {
7
- this.options = options;
8
- }
9
-
10
- /**
11
- * Makes an HTTP request to the API with retries and exponential backoff
12
- * @param path - The API endpoint path
13
- * @param options - Optional request configuration
14
- * @returns Promise containing the response data
15
- */
16
- public async request<T>(path: string, options: RequestOptions = {}): Promise<T> {
17
- let lastError: Error | null = null;
18
- const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1000, headers = {} } = this.options;
19
-
20
- let delay = backoffMs;
21
-
22
- for (let attempt = 0; attempt <= retries; attempt++) {
23
- try {
24
- const response = await fetch(`${baseUrl}${path}`, {
25
- ...options,
26
- headers: {
27
- 'Content-Type': 'application/json',
28
- ...headers,
29
- ...options.headers,
30
- },
31
- body: options.body ? JSON.stringify(options.body) : undefined,
32
- });
33
-
34
- if (!response.ok) {
35
- const errorBody = await response.text();
36
- let errorMessage = `HTTP error! status: ${response.status}`;
37
- try {
38
- const errorJson = JSON.parse(errorBody);
39
- errorMessage += ` - ${JSON.stringify(errorJson)}`;
40
- } catch {
41
- if (errorBody) {
42
- errorMessage += ` - ${errorBody}`;
43
- }
44
- }
45
- throw new Error(errorMessage);
46
- }
47
-
48
- if (options.stream) {
49
- return response as unknown as T;
50
- }
51
-
52
- const data = await response.json();
53
- return data as T;
54
- } catch (error) {
55
- lastError = error as Error;
56
-
57
- if (attempt === retries) {
58
- break;
59
- }
60
-
61
- await new Promise(resolve => setTimeout(resolve, delay));
62
- delay = Math.min(delay * 2, maxBackoffMs);
63
- }
64
- }
65
-
66
- throw lastError || new Error('Request failed');
67
- }
68
- }
@@ -1,6 +0,0 @@
1
- export * from './agent';
2
- export * from './memory-thread';
3
- export * from './vector';
4
- export * from './workflow';
5
- export * from './tool';
6
- export * from './base';
@@ -1,60 +0,0 @@
1
- import type { StorageThreadType } from '@mastra/core';
2
-
3
- import type {
4
- CreateMemoryThreadParams,
5
- GetMemoryThreadMessagesResponse,
6
- GetMemoryThreadResponse,
7
- ClientOptions,
8
- SaveMessageToMemoryParams,
9
- UpdateMemoryThreadParams,
10
- } from '../types';
11
-
12
- import { BaseResource } from './base';
13
-
14
- export class MemoryThread extends BaseResource {
15
- constructor(
16
- options: ClientOptions,
17
- private threadId: string,
18
- private agentId: string,
19
- ) {
20
- super(options);
21
- }
22
-
23
- /**
24
- * Retrieves the memory thread details
25
- * @returns Promise containing thread details including title and metadata
26
- */
27
- get(): Promise<StorageThreadType> {
28
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`);
29
- }
30
-
31
- /**
32
- * Updates the memory thread properties
33
- * @param params - Update parameters including title and metadata
34
- * @returns Promise containing updated thread details
35
- */
36
- update(params: UpdateMemoryThreadParams): Promise<StorageThreadType> {
37
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
38
- method: 'PATCH',
39
- body: params,
40
- });
41
- }
42
-
43
- /**
44
- * Deletes the memory thread
45
- * @returns Promise containing deletion result
46
- */
47
- delete(): Promise<{ result: string }> {
48
- return this.request(`/api/memory/threads/${this.threadId}?agentId=${this.agentId}`, {
49
- method: 'DELETE',
50
- });
51
- }
52
-
53
- /**
54
- * Retrieves messages associated with the thread
55
- * @returns Promise containing thread messages and UI messages
56
- */
57
- getMessages(): Promise<GetMemoryThreadMessagesResponse> {
58
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
59
- }
60
- }
@@ -1,32 +0,0 @@
1
- import type { GetToolResponse, ClientOptions } from '../types';
2
-
3
- import { BaseResource } from './base';
4
-
5
- export class Tool extends BaseResource {
6
- constructor(
7
- options: ClientOptions,
8
- private toolId: string,
9
- ) {
10
- super(options);
11
- }
12
-
13
- /**
14
- * Retrieves details about the tool
15
- * @returns Promise containing tool details including description and schemas
16
- */
17
- details(): Promise<GetToolResponse> {
18
- return this.request(`/api/tools/${this.toolId}`);
19
- }
20
-
21
- /**
22
- * Executes the tool with the provided parameters
23
- * @param params - Parameters required for tool execution
24
- * @returns Promise containing the tool execution results
25
- */
26
- execute(params: { data: any }): Promise<any> {
27
- return this.request(`/api/tools/${this.toolId}/execute`, {
28
- method: 'POST',
29
- body: params,
30
- });
31
- }
32
- }
@@ -1,83 +0,0 @@
1
- import type {
2
- CreateIndexParams,
3
- GetVectorIndexResponse,
4
- QueryVectorParams,
5
- QueryVectorResponse,
6
- ClientOptions,
7
- UpsertVectorParams,
8
- } from '../types';
9
-
10
- import { BaseResource } from './base';
11
-
12
- export class Vector extends BaseResource {
13
- constructor(
14
- options: ClientOptions,
15
- private vectorName: string,
16
- ) {
17
- super(options);
18
- }
19
-
20
- /**
21
- * Retrieves details about a specific vector index
22
- * @param indexName - Name of the index to get details for
23
- * @returns Promise containing vector index details
24
- */
25
- details(indexName: string): Promise<GetVectorIndexResponse> {
26
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
27
- }
28
-
29
- /**
30
- * Deletes a vector index
31
- * @param indexName - Name of the index to delete
32
- * @returns Promise indicating deletion success
33
- */
34
- delete(indexName: string): Promise<{ success: boolean }> {
35
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
36
- method: 'DELETE',
37
- });
38
- }
39
-
40
- /**
41
- * Retrieves a list of all available indexes
42
- * @returns Promise containing array of index names
43
- */
44
- getIndexes(): Promise<{ indexes: string[] }> {
45
- return this.request(`/api/vector/${this.vectorName}/indexes`);
46
- }
47
-
48
- /**
49
- * Creates a new vector index
50
- * @param params - Parameters for index creation including dimension and metric
51
- * @returns Promise indicating creation success
52
- */
53
- createIndex(params: CreateIndexParams): Promise<{ success: boolean }> {
54
- return this.request(`/api/vector/${this.vectorName}/create-index`, {
55
- method: 'POST',
56
- body: params,
57
- });
58
- }
59
-
60
- /**
61
- * Upserts vectors into an index
62
- * @param params - Parameters containing vectors, metadata, and optional IDs
63
- * @returns Promise containing array of vector IDs
64
- */
65
- upsert(params: UpsertVectorParams): Promise<string[]> {
66
- return this.request(`/api/vector/${this.vectorName}/upsert`, {
67
- method: 'POST',
68
- body: params,
69
- });
70
- }
71
-
72
- /**
73
- * Queries vectors in an index
74
- * @param params - Query parameters including query vector and search options
75
- * @returns Promise containing query results
76
- */
77
- query(params: QueryVectorParams): Promise<QueryVectorResponse> {
78
- return this.request(`/api/vector/${this.vectorName}/query`, {
79
- method: 'POST',
80
- body: params,
81
- });
82
- }
83
- }
@@ -1,68 +0,0 @@
1
- import type { GetWorkflowResponse, ClientOptions } from '../types';
2
-
3
- import { BaseResource } from './base';
4
-
5
- export class Workflow extends BaseResource {
6
- constructor(
7
- options: ClientOptions,
8
- private workflowId: string,
9
- ) {
10
- super(options);
11
- }
12
-
13
- /**
14
- * Retrieves details about the workflow
15
- * @returns Promise containing workflow details including steps and graphs
16
- */
17
- details(): Promise<GetWorkflowResponse> {
18
- return this.request(`/api/workflows/${this.workflowId}`);
19
- }
20
-
21
- /**
22
- * Executes the workflow with the provided parameters
23
- * @param params - Parameters required for workflow execution
24
- * @returns Promise containing the workflow execution results
25
- */
26
- execute(params: Record<string, any>): Promise<Record<string, any>> {
27
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
28
- method: 'POST',
29
- body: params,
30
- });
31
- }
32
-
33
- /**
34
- * Resumes a suspended workflow step
35
- * @param stepId - ID of the step to resume
36
- * @param runId - ID of the workflow run
37
- * @param context - Context to resume the workflow with
38
- * @returns Promise containing the workflow resume results
39
- */
40
- resume({
41
- stepId,
42
- runId,
43
- context,
44
- }: {
45
- stepId: string;
46
- runId: string;
47
- context: Record<string, any>;
48
- }): Promise<Record<string, any>> {
49
- return this.request(`/api/workflows/${this.workflowId}/resume`, {
50
- method: 'POST',
51
- body: {
52
- stepId,
53
- runId,
54
- context,
55
- },
56
- });
57
- }
58
-
59
- /**
60
- * Watches workflow transitions in real-time
61
- * @returns Promise containing the workflow watch stream
62
- */
63
- watch(): Promise<Response> {
64
- return this.request(`/api/workflows/${this.workflowId}/watch`, {
65
- stream: true,
66
- });
67
- }
68
- }
package/src/types.ts DELETED
@@ -1,163 +0,0 @@
1
- import type {
2
- MessageType,
3
- AiMessageType,
4
- CoreMessage,
5
- QueryResult,
6
- StepAction,
7
- StepGraph,
8
- StorageThreadType,
9
- BaseLogMessage,
10
- OutputType,
11
- } from '@mastra/core';
12
- import type { JSONSchema7 } from 'json-schema';
13
- import { ZodSchema } from 'zod';
14
-
15
- export interface ClientOptions {
16
- /** Base URL for API requests */
17
- baseUrl: string;
18
- /** Number of retry attempts for failed requests */
19
- retries?: number;
20
- /** Initial backoff time in milliseconds between retries */
21
- backoffMs?: number;
22
- /** Maximum backoff time in milliseconds between retries */
23
- maxBackoffMs?: number;
24
- /** Custom headers to include with requests */
25
- headers?: Record<string, string>;
26
- }
27
-
28
- export interface RequestOptions {
29
- method?: string;
30
- headers?: Record<string, string>;
31
- body?: any;
32
- stream?: boolean;
33
- }
34
-
35
- export interface GetAgentResponse {
36
- name: string;
37
- instructions: string;
38
- tools: Record<string, GetToolResponse>;
39
- provider: string;
40
- }
41
-
42
- export interface GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
43
- messages: string | string[] | CoreMessage[];
44
- threadId?: string;
45
- resourceid?: string;
46
- output?: OutputType | T;
47
- }
48
-
49
- export interface StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
50
- messages: string | string[] | CoreMessage[];
51
- threadId?: string;
52
- resourceid?: string;
53
- output?: OutputType | T;
54
- }
55
-
56
- export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
57
- evals: any[];
58
- }
59
-
60
- export interface GetToolResponse {
61
- id: string;
62
- description: string;
63
- inputSchema: string;
64
- outputSchema: string;
65
- }
66
-
67
- export interface GetWorkflowResponse {
68
- name: string;
69
- triggerSchema: string;
70
- steps: Record<string, StepAction<any, any, any, any>>;
71
- stepGraph: StepGraph;
72
- stepSubscriberGraph: Record<string, StepGraph>;
73
- }
74
-
75
- export interface UpsertVectorParams {
76
- indexName: string;
77
- vectors: number[][];
78
- metadata?: Record<string, any>[];
79
- ids?: string[];
80
- }
81
- export interface CreateIndexParams {
82
- indexName: string;
83
- dimension: number;
84
- metric?: 'cosine' | 'euclidean' | 'dotproduct';
85
- }
86
-
87
- export interface QueryVectorParams {
88
- indexName: string;
89
- queryVector: number[];
90
- topK?: number;
91
- filter?: Record<string, any>;
92
- includeVector?: boolean;
93
- }
94
-
95
- export interface QueryVectorResponse {
96
- results: QueryResult[];
97
- }
98
-
99
- export interface GetVectorIndexResponse {
100
- dimension: number;
101
- metric: 'cosine' | 'euclidean' | 'dotproduct';
102
- count: number;
103
- }
104
-
105
- export interface SaveMessageToMemoryParams {
106
- messages: MessageType[];
107
- agentId: string;
108
- }
109
-
110
- export type SaveMessageToMemoryResponse = MessageType[];
111
-
112
- export interface CreateMemoryThreadParams {
113
- title: string;
114
- metadata: Record<string, any>;
115
- resourceid: string;
116
- threadId: string;
117
- agentId: string;
118
- }
119
-
120
- export type CreateMemoryThreadResponse = StorageThreadType;
121
-
122
- export interface GetMemoryThreadParams {
123
- resourceId: string;
124
- agentId: string;
125
- }
126
-
127
- export type GetMemoryThreadResponse = StorageThreadType[];
128
-
129
- export interface UpdateMemoryThreadParams {
130
- title: string;
131
- metadata: Record<string, any>;
132
- resourceid: string;
133
- }
134
-
135
- export interface GetMemoryThreadMessagesResponse {
136
- messages: CoreMessage[];
137
- uiMessages: AiMessageType[];
138
- }
139
-
140
- export interface GetLogsParams {
141
- transportId: string;
142
- }
143
-
144
- export interface GetLogParams {
145
- runId: string;
146
- transportId: string;
147
- }
148
-
149
- export type GetLogsResponse = BaseLogMessage[];
150
-
151
- export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
152
-
153
- export interface GetTelemetryResponse {
154
- traces: any[];
155
- }
156
-
157
- export interface GetTelemetryParams {
158
- name?: string;
159
- scope?: string;
160
- page?: number;
161
- perPage?: number;
162
- attribute?: Record<string, string>;
163
- }
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.node.json",
3
- "include": ["src/**/*"],
4
- "exclude": ["node_modules", "**/*.test.ts"]
5
- }
package/vitest.config.js DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'node',
6
- include: ['src/**/*.test.ts'],
7
- },
8
- });