@mastra/client-js 0.1.0-alpha.8 → 0.1.0

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.
@@ -1,82 +1,83 @@
1
1
  import type {
2
- CreateIndexParams,
3
- GetVectorIndexResponse,
4
- QueryVectorParams,
5
- QueryVectorResponse,
6
- ClientOptions,
7
- UpsertVectorParams,
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
- constructor(
13
- options: ClientOptions,
14
- private vectorName: string
15
- ) {
16
- super(options);
17
- }
13
+ constructor(
14
+ options: ClientOptions,
15
+ private vectorName: string,
16
+ ) {
17
+ super(options);
18
+ }
18
19
 
19
- /**
20
- * Retrieves details about a specific vector index
21
- * @param indexName - Name of the index to get details for
22
- * @returns Promise containing vector index details
23
- */
24
- details(indexName: string): Promise<GetVectorIndexResponse> {
25
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
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
- * Deletes a vector index
30
- * @param indexName - Name of the index to delete
31
- * @returns Promise indicating deletion success
32
- */
33
- delete(indexName: string): Promise<{ success: boolean }> {
34
- return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
35
- method: 'DELETE'
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
- * Retrieves a list of all available indexes
41
- * @returns Promise containing array of index names
42
- */
43
- getIndexes(): Promise<{ indexes: string[] }> {
44
- return this.request(`/api/vector/${this.vectorName}/indexes`);
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
- * Creates a new vector index
49
- * @param params - Parameters for index creation including dimension and metric
50
- * @returns Promise indicating creation success
51
- */
52
- createIndex(params: CreateIndexParams): Promise<{ success: boolean }> {
53
- return this.request(`/api/vector/${this.vectorName}/create-index`, {
54
- method: 'POST',
55
- body: params
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
- * Upserts vectors into an index
61
- * @param params - Parameters containing vectors, metadata, and optional IDs
62
- * @returns Promise containing array of vector IDs
63
- */
64
- upsert(params: UpsertVectorParams): Promise<string[]> {
65
- return this.request(`/api/vector/${this.vectorName}/upsert`, {
66
- method: 'POST',
67
- body: params
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
- * Queries vectors in an index
73
- * @param params - Query parameters including query vector and search options
74
- * @returns Promise containing query results
75
- */
76
- query(params: QueryVectorParams): Promise<QueryVectorResponse> {
77
- return this.request(`/api/vector/${this.vectorName}/query`, {
78
- method: 'POST',
79
- body: params
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
- constructor(
6
- options: ClientOptions,
7
- private workflowId: string
8
- ) {
9
- super(options);
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
- * Retrieves details about the workflow
14
- * @returns Promise containing workflow details including steps and graphs
15
- */
16
- details(): Promise<GetWorkflowResponse> {
17
- return this.request(`/api/workflows/${this.workflowId}`);
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
- * Executes the workflow with the provided parameters
22
- * @param params - Parameters required for workflow execution
23
- * @returns Promise containing the workflow execution results
24
- */
25
- execute(params: Record<string, any>): Promise<Record<string, any>> {
26
- return this.request(`/api/workflows/${this.workflowId}/execute`, {
27
- method: 'POST',
28
- body: params,
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,142 +1,163 @@
1
- import type { MessageType, AiMessageType, CoreMessage, QueryResult, StepAction, StepGraph, StorageThreadType, BaseLogMessage, OutputType } from "@mastra/core";
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 "zod";
13
+ import { ZodSchema } from 'zod';
4
14
 
5
15
  export interface ClientOptions {
6
- /** Base URL for API requests */
7
- baseUrl: string;
8
- /** Number of retry attempts for failed requests */
9
- retries?: number;
10
- /** Initial backoff time in milliseconds between retries */
11
- backoffMs?: number;
12
- /** Maximum backoff time in milliseconds between retries */
13
- maxBackoffMs?: number;
14
- /** Custom headers to include with requests */
15
- headers?: Record<string, string>;
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
- method?: string;
20
- headers?: Record<string, string>;
21
- body?: any;
22
- stream?: boolean;
29
+ method?: string;
30
+ headers?: Record<string, string>;
31
+ body?: any;
32
+ stream?: boolean;
23
33
  }
24
34
 
25
35
  export interface GetAgentResponse {
26
- name: string;
27
- model: string;
28
- instructions: string;
29
- tools: Record<string, GetToolResponse>;
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
- messages: MessageType[];
34
- threadId?: string;
35
- resourceid?: string;
36
- output?: OutputType | T
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
- messages: MessageType[];
41
- threadId?: string;
42
- resourceid?: string;
43
- output?: OutputType | T
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
- evals: any[];
57
+ evals: any[];
48
58
  }
49
59
 
50
60
  export interface GetToolResponse {
51
- id: string;
52
- description: string;
53
- inputSchema: string;
54
- outputSchema: string;
61
+ id: string;
62
+ description: string;
63
+ inputSchema: string;
64
+ outputSchema: string;
55
65
  }
56
66
 
57
67
  export interface GetWorkflowResponse {
58
- name: string;
59
- triggerSchema: string;
60
- steps: Record<string, StepAction<any, any, any, any>>;
61
- stepGraph: StepGraph
62
- stepSubscriberGraph: Record<string, StepGraph>
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
- indexName: string;
67
- vectors: number[][];
68
- metadata?: Record<string, any>[];
69
- ids?: string[];
76
+ indexName: string;
77
+ vectors: number[][];
78
+ metadata?: Record<string, any>[];
79
+ ids?: string[];
70
80
  }
71
81
  export interface CreateIndexParams {
72
- indexName: string;
73
- dimension: number;
74
- metric?: 'cosine' | 'euclidean' | 'dotproduct';
82
+ indexName: string;
83
+ dimension: number;
84
+ metric?: 'cosine' | 'euclidean' | 'dotproduct';
75
85
  }
76
86
 
77
87
  export interface QueryVectorParams {
78
- indexName: string;
79
- queryVector: number[];
80
- topK?: number;
81
- filter?: Record<string, any>;
82
- includeVector?: boolean;
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
- results: QueryResult[];
96
+ results: QueryResult[];
87
97
  }
88
98
 
89
99
  export interface GetVectorIndexResponse {
90
- dimension: number;
91
- metric: 'cosine' | 'euclidean' | 'dotproduct';
92
- count: number;
100
+ dimension: number;
101
+ metric: 'cosine' | 'euclidean' | 'dotproduct';
102
+ count: number;
93
103
  }
94
104
 
95
105
  export interface SaveMessageToMemoryParams {
96
- messages: MessageType[];
106
+ messages: MessageType[];
107
+ agentId: string;
97
108
  }
98
109
 
99
- export type SaveMessageToMemoryResponse = MessageType[]
110
+ export type SaveMessageToMemoryResponse = MessageType[];
100
111
 
101
112
  export interface CreateMemoryThreadParams {
102
- title: string;
103
- metadata: Record<string, any>;
104
- resourceid: string;
105
- threadId: string;
113
+ title: string;
114
+ metadata: Record<string, any>;
115
+ resourceid: string;
116
+ threadId: string;
117
+ agentId: string;
106
118
  }
107
119
 
108
- export type CreateMemoryThreadResponse = StorageThreadType
120
+ export type CreateMemoryThreadResponse = StorageThreadType;
109
121
 
110
122
  export interface GetMemoryThreadParams {
111
- resourceId: string;
123
+ resourceId: string;
124
+ agentId: string;
112
125
  }
113
126
 
114
- export type GetMemoryThreadResponse = StorageThreadType[]
127
+ export type GetMemoryThreadResponse = StorageThreadType[];
115
128
 
116
129
  export interface UpdateMemoryThreadParams {
117
- title: string;
118
- metadata: Record<string, any>;
119
- resourceid: string;
130
+ title: string;
131
+ metadata: Record<string, any>;
132
+ resourceid: string;
120
133
  }
121
134
 
122
-
123
135
  export interface GetMemoryThreadMessagesResponse {
124
- messages: CoreMessage[];
125
- uiMessages: AiMessageType[];
136
+ messages: CoreMessage[];
137
+ uiMessages: AiMessageType[];
126
138
  }
127
139
 
128
140
  export interface GetLogsParams {
129
- transportId: string;
141
+ transportId: string;
130
142
  }
131
143
 
132
144
  export interface GetLogParams {
133
- runId: string;
134
- transportId: string;
145
+ runId: string;
146
+ transportId: string;
135
147
  }
136
148
 
137
- export type GetLogsResponse = BaseLogMessage[]
149
+ export type GetLogsResponse = BaseLogMessage[];
150
+
151
+ export type RequestFunction = (path: string, options?: RequestOptions) => Promise<any>;
138
152
 
139
- export type RequestFunction = (
140
- path: string,
141
- options?: RequestOptions
142
- ) => Promise<any>;
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 CHANGED
@@ -1,29 +1,5 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "compilerOptions": {
4
- /* Base Options: */
5
- "esModuleInterop": true,
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
@@ -1,3 +0,0 @@
1
-
2
- /node_modules
3
- /dist
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
- }