@mastra/client-js 0.1.0-alpha.16 → 0.1.0-alpha.18
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 +15 -0
- package/CHANGELOG.md +7 -0
- package/README.md +24 -10
- package/dist/index.d.mts +17 -0
- package/dist/index.mjs +37 -6
- package/eslint.config.js +6 -0
- package/package.json +11 -10
- package/src/client.ts +170 -153
- package/src/example.ts +33 -33
- package/src/index.test.ts +541 -531
- package/src/index.ts +1 -1
- package/src/resources/agent.ts +99 -98
- package/src/resources/base.ts +54 -54
- package/src/resources/index.ts +1 -1
- package/src/resources/memory-thread.ts +50 -48
- package/src/resources/tool.ts +25 -24
- package/src/resources/vector.ts +72 -71
- package/src/resources/workflow.ts +62 -25
- package/src/types.ts +92 -86
- package/tsconfig.json +4 -28
- package/.eslintrc.js +0 -10
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -26
package/src/resources/vector.ts
CHANGED
|
@@ -1,82 +1,83 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
CreateIndexParams,
|
|
3
|
+
GetVectorIndexResponse,
|
|
4
|
+
QueryVectorParams,
|
|
5
|
+
QueryVectorResponse,
|
|
6
|
+
ClientOptions,
|
|
7
|
+
UpsertVectorParams,
|
|
8
8
|
} from '../types';
|
|
9
|
+
|
|
9
10
|
import { BaseResource } from './base';
|
|
10
11
|
|
|
11
12
|
export class Vector extends BaseResource {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
constructor(
|
|
14
|
+
options: ClientOptions,
|
|
15
|
+
private vectorName: string,
|
|
16
|
+
) {
|
|
17
|
+
super(options);
|
|
18
|
+
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
}
|
|
70
71
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
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,31 +1,68 @@
|
|
|
1
1
|
import type { GetWorkflowResponse, ClientOptions } from '../types';
|
|
2
|
+
|
|
2
3
|
import { BaseResource } from './base';
|
|
3
4
|
|
|
4
5
|
export class Workflow extends BaseResource {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
}
|
|
11
32
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
}
|
|
19
58
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
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
CHANGED
|
@@ -1,157 +1,163 @@
|
|
|
1
|
-
import type {
|
|
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';
|
|
2
12
|
import type { JSONSchema7 } from 'json-schema';
|
|
3
|
-
import { ZodSchema } from
|
|
13
|
+
import { ZodSchema } from 'zod';
|
|
4
14
|
|
|
5
15
|
export interface ClientOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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>;
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
export interface RequestOptions {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
method?: string;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
body?: any;
|
|
32
|
+
stream?: boolean;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
export interface GetAgentResponse {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
name: string;
|
|
37
|
+
instructions: string;
|
|
38
|
+
tools: Record<string, GetToolResponse>;
|
|
39
|
+
provider: string;
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
export interface GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
messages: string | string[] | CoreMessage[];
|
|
44
|
+
threadId?: string;
|
|
45
|
+
resourceid?: string;
|
|
46
|
+
output?: OutputType | T;
|
|
37
47
|
}
|
|
38
48
|
|
|
39
49
|
export interface StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
messages: string | string[] | CoreMessage[];
|
|
51
|
+
threadId?: string;
|
|
52
|
+
resourceid?: string;
|
|
53
|
+
output?: OutputType | T;
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
|
|
47
|
-
|
|
57
|
+
evals: any[];
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
export interface GetToolResponse {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
id: string;
|
|
62
|
+
description: string;
|
|
63
|
+
inputSchema: string;
|
|
64
|
+
outputSchema: string;
|
|
55
65
|
}
|
|
56
66
|
|
|
57
67
|
export interface GetWorkflowResponse {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
name: string;
|
|
69
|
+
triggerSchema: string;
|
|
70
|
+
steps: Record<string, StepAction<any, any, any, any>>;
|
|
71
|
+
stepGraph: StepGraph;
|
|
72
|
+
stepSubscriberGraph: Record<string, StepGraph>;
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
export interface UpsertVectorParams {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
indexName: string;
|
|
77
|
+
vectors: number[][];
|
|
78
|
+
metadata?: Record<string, any>[];
|
|
79
|
+
ids?: string[];
|
|
70
80
|
}
|
|
71
81
|
export interface CreateIndexParams {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
indexName: string;
|
|
83
|
+
dimension: number;
|
|
84
|
+
metric?: 'cosine' | 'euclidean' | 'dotproduct';
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
export interface QueryVectorParams {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
indexName: string;
|
|
89
|
+
queryVector: number[];
|
|
90
|
+
topK?: number;
|
|
91
|
+
filter?: Record<string, any>;
|
|
92
|
+
includeVector?: boolean;
|
|
83
93
|
}
|
|
84
94
|
|
|
85
95
|
export interface QueryVectorResponse {
|
|
86
|
-
|
|
96
|
+
results: QueryResult[];
|
|
87
97
|
}
|
|
88
98
|
|
|
89
99
|
export interface GetVectorIndexResponse {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
100
|
+
dimension: number;
|
|
101
|
+
metric: 'cosine' | 'euclidean' | 'dotproduct';
|
|
102
|
+
count: number;
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
export interface SaveMessageToMemoryParams {
|
|
96
|
-
|
|
97
|
-
|
|
106
|
+
messages: MessageType[];
|
|
107
|
+
agentId: string;
|
|
98
108
|
}
|
|
99
109
|
|
|
100
|
-
export type SaveMessageToMemoryResponse = MessageType[]
|
|
110
|
+
export type SaveMessageToMemoryResponse = MessageType[];
|
|
101
111
|
|
|
102
112
|
export interface CreateMemoryThreadParams {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
title: string;
|
|
114
|
+
metadata: Record<string, any>;
|
|
115
|
+
resourceid: string;
|
|
116
|
+
threadId: string;
|
|
117
|
+
agentId: string;
|
|
108
118
|
}
|
|
109
119
|
|
|
110
|
-
export type CreateMemoryThreadResponse = StorageThreadType
|
|
120
|
+
export type CreateMemoryThreadResponse = StorageThreadType;
|
|
111
121
|
|
|
112
122
|
export interface GetMemoryThreadParams {
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
resourceId: string;
|
|
124
|
+
agentId: string;
|
|
115
125
|
}
|
|
116
126
|
|
|
117
|
-
export type GetMemoryThreadResponse = StorageThreadType[]
|
|
127
|
+
export type GetMemoryThreadResponse = StorageThreadType[];
|
|
118
128
|
|
|
119
129
|
export interface UpdateMemoryThreadParams {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
130
|
+
title: string;
|
|
131
|
+
metadata: Record<string, any>;
|
|
132
|
+
resourceid: string;
|
|
123
133
|
}
|
|
124
134
|
|
|
125
|
-
|
|
126
135
|
export interface GetMemoryThreadMessagesResponse {
|
|
127
|
-
|
|
128
|
-
|
|
136
|
+
messages: CoreMessage[];
|
|
137
|
+
uiMessages: AiMessageType[];
|
|
129
138
|
}
|
|
130
139
|
|
|
131
140
|
export interface GetLogsParams {
|
|
132
|
-
|
|
141
|
+
transportId: string;
|
|
133
142
|
}
|
|
134
143
|
|
|
135
144
|
export interface GetLogParams {
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
runId: string;
|
|
146
|
+
transportId: string;
|
|
138
147
|
}
|
|
139
148
|
|
|
140
|
-
export type GetLogsResponse = BaseLogMessage[]
|
|
149
|
+
export type GetLogsResponse = BaseLogMessage[];
|
|
141
150
|
|
|
142
|
-
export type RequestFunction = (
|
|
143
|
-
path: string,
|
|
144
|
-
options?: RequestOptions
|
|
145
|
-
) => Promise<any>;
|
|
151
|
+
export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
|
|
146
152
|
|
|
147
153
|
export interface GetTelemetryResponse {
|
|
148
|
-
|
|
154
|
+
traces: any[];
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
export interface GetTelemetryParams {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
158
|
+
name?: string;
|
|
159
|
+
scope?: string;
|
|
160
|
+
page?: number;
|
|
161
|
+
perPage?: number;
|
|
162
|
+
attribute?: Record<string, string>;
|
|
157
163
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,29 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"target": "es2022",
|
|
8
|
-
"allowJs": true,
|
|
9
|
-
"resolveJsonModule": true,
|
|
10
|
-
"moduleDetection": "force",
|
|
11
|
-
"isolatedModules": true,
|
|
12
|
-
"verbatimModuleSyntax": true,
|
|
13
|
-
/* Strictness */
|
|
14
|
-
"strict": true,
|
|
15
|
-
"noUncheckedIndexedAccess": true,
|
|
16
|
-
// "noImplicitOverride": true,
|
|
17
|
-
/* AND if you're building for a library in a monorepo: */
|
|
18
|
-
// "composite": true,
|
|
19
|
-
"declaration": true,
|
|
20
|
-
"declarationMap": true,
|
|
21
|
-
/* If NOT transpiling with TypeScript: */
|
|
22
|
-
"module": "Preserve",
|
|
23
|
-
"noEmit": true,
|
|
24
|
-
/* If your code doesn't run in the DOM: */
|
|
25
|
-
"lib": [
|
|
26
|
-
"es2022"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
}
|
|
2
|
+
"extends": "../../tsconfig.node.json",
|
|
3
|
+
"include": ["src/**/*"],
|
|
4
|
+
"exclude": ["node_modules", "**/*.test.ts"]
|
|
5
|
+
}
|
package/.eslintrc.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
parser: '@typescript-eslint/parser',
|
|
3
|
-
plugins: ['@typescript-eslint', 'unused-imports', 'prettier'],
|
|
4
|
-
rules: {
|
|
5
|
-
'no-unused-vars': 'off',
|
|
6
|
-
'prettier/prettier': 'error',
|
|
7
|
-
'unused-imports/no-unused-imports': 'error',
|
|
8
|
-
},
|
|
9
|
-
root: true,
|
|
10
|
-
};
|
package/.prettierignore
DELETED
package/.prettierrc.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"endOfLine": "lf",
|
|
3
|
-
"semi": true,
|
|
4
|
-
"singleQuote": true,
|
|
5
|
-
"tabWidth": 2,
|
|
6
|
-
"useTabs": false,
|
|
7
|
-
"trailingComma": "all",
|
|
8
|
-
"bracketSpacing": true,
|
|
9
|
-
"printWidth": 120,
|
|
10
|
-
"arrowParens": "avoid",
|
|
11
|
-
"importOrder": [
|
|
12
|
-
"<THIRD_PARTY_MODULES>",
|
|
13
|
-
"^next\\/(.*)$",
|
|
14
|
-
"^@\\/components/(.*)$",
|
|
15
|
-
"^@\\/icons/(.*)$",
|
|
16
|
-
"^@\\/lib/(.*)$",
|
|
17
|
-
"^@\\/(.*)$",
|
|
18
|
-
"^[\\w\\d-_]+\\/(.*)$",
|
|
19
|
-
"^\\.\\.\\/(.*)$",
|
|
20
|
-
"^\\.\\/(.*)$",
|
|
21
|
-
"^[./]"
|
|
22
|
-
],
|
|
23
|
-
"importOrderSeparation": true,
|
|
24
|
-
"importOrderParserPlugins": ["jsx", "typescript", "classProperties", "decorators-legacy"],
|
|
25
|
-
"plugins": ["@trivago/prettier-plugin-sort-imports"]
|
|
26
|
-
}
|