@mastra/client-js 0.10.15-alpha.1 → 0.10.15-alpha.3
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 +8 -8
- package/CHANGELOG.md +37 -0
- package/README.md +1 -0
- package/dist/index.cjs +327 -248
- package/dist/index.d.cts +124 -19
- package/dist/index.d.ts +124 -19
- package/dist/index.js +327 -248
- package/package.json +2 -2
- package/src/client.ts +97 -0
- package/src/index.test.ts +294 -6
- package/src/resources/agent.ts +272 -297
- package/src/resources/base.ts +3 -1
- package/src/resources/memory-thread.ts +18 -0
- package/src/resources/network.ts +4 -3
- package/src/resources/workflow.ts +9 -0
- package/src/types.ts +75 -1
- package/src/utils/process-client-tools.ts +1 -1
package/src/resources/base.ts
CHANGED
|
@@ -24,7 +24,9 @@ export class BaseResource {
|
|
|
24
24
|
const response = await fetch(`${baseUrl.replace(/\/$/, '')}${path}`, {
|
|
25
25
|
...options,
|
|
26
26
|
headers: {
|
|
27
|
-
...(options.method === 'POST' || options.method === 'PUT'
|
|
27
|
+
...(options.body && (options.method === 'POST' || options.method === 'PUT')
|
|
28
|
+
? { 'content-type': 'application/json' }
|
|
29
|
+
: {}),
|
|
28
30
|
...headers,
|
|
29
31
|
...options.headers,
|
|
30
32
|
// TODO: Bring this back once we figure out what we/users need to do to make this work with cross-origin requests
|
|
@@ -5,6 +5,8 @@ import type {
|
|
|
5
5
|
ClientOptions,
|
|
6
6
|
UpdateMemoryThreadParams,
|
|
7
7
|
GetMemoryThreadMessagesParams,
|
|
8
|
+
GetMemoryThreadMessagesPaginatedParams,
|
|
9
|
+
GetMemoryThreadMessagesPaginatedResponse,
|
|
8
10
|
} from '../types';
|
|
9
11
|
|
|
10
12
|
import { BaseResource } from './base';
|
|
@@ -60,4 +62,20 @@ export class MemoryThread extends BaseResource {
|
|
|
60
62
|
});
|
|
61
63
|
return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
|
|
62
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves paginated messages associated with the thread with advanced filtering and selection options
|
|
68
|
+
* @param params - Pagination parameters including selectBy criteria, page, perPage, date ranges, and message inclusion options
|
|
69
|
+
* @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
|
|
70
|
+
*/
|
|
71
|
+
getMessagesPaginated({
|
|
72
|
+
selectBy,
|
|
73
|
+
...rest
|
|
74
|
+
}: GetMemoryThreadMessagesPaginatedParams): Promise<GetMemoryThreadMessagesPaginatedResponse> {
|
|
75
|
+
const query = new URLSearchParams({
|
|
76
|
+
...rest,
|
|
77
|
+
...(selectBy ? { selectBy: JSON.stringify(selectBy) } : {}),
|
|
78
|
+
});
|
|
79
|
+
return this.request(`/api/memory/threads/${this.threadId}/messages/paginated?${query.toString()}`);
|
|
80
|
+
}
|
|
63
81
|
}
|
package/src/resources/network.ts
CHANGED
|
@@ -28,9 +28,10 @@ export class Network extends BaseResource {
|
|
|
28
28
|
* @param params - Generation parameters including prompt
|
|
29
29
|
* @returns Promise containing the generated response
|
|
30
30
|
*/
|
|
31
|
-
generate<
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
generate<
|
|
32
|
+
Output extends JSONSchema7 | ZodSchema | undefined = undefined,
|
|
33
|
+
StructuredOutput extends JSONSchema7 | ZodSchema | undefined = undefined,
|
|
34
|
+
>(params: GenerateParams<Output>): Promise<GenerateReturn<any, Output, StructuredOutput>> {
|
|
34
35
|
const processedParams = {
|
|
35
36
|
...params,
|
|
36
37
|
output: zodToJsonSchema(params.output),
|
|
@@ -190,6 +190,15 @@ export class Workflow extends BaseResource {
|
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Creates a new workflow run (alias for createRun)
|
|
195
|
+
* @param params - Optional object containing the optional runId
|
|
196
|
+
* @returns Promise containing the runId of the created run
|
|
197
|
+
*/
|
|
198
|
+
createRunAsync(params?: { runId?: string }): Promise<{ runId: string }> {
|
|
199
|
+
return this.createRun(params);
|
|
200
|
+
}
|
|
201
|
+
|
|
193
202
|
/**
|
|
194
203
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
195
204
|
* @param params - Object containing the runId, inputData and runtimeContext
|
package/src/types.ts
CHANGED
|
@@ -7,12 +7,16 @@ import type {
|
|
|
7
7
|
WorkflowRuns,
|
|
8
8
|
WorkflowRun,
|
|
9
9
|
LegacyWorkflowRuns,
|
|
10
|
+
StorageGetMessagesArg,
|
|
11
|
+
PaginationInfo,
|
|
12
|
+
MastraMessageV2,
|
|
10
13
|
} from '@mastra/core';
|
|
11
14
|
import type { AgentGenerateOptions, AgentStreamOptions, ToolsInput } from '@mastra/core/agent';
|
|
12
15
|
import type { BaseLogMessage, LogLevel } from '@mastra/core/logger';
|
|
13
16
|
|
|
14
17
|
import type { MCPToolType, ServerInfo } from '@mastra/core/mcp';
|
|
15
18
|
import type { RuntimeContext } from '@mastra/core/runtime-context';
|
|
19
|
+
import type { MastraScorer, MastraScorerEntry, ScoreRowData } from '@mastra/core/scores';
|
|
16
20
|
import type { Workflow, WatchEvent, WorkflowResult } from '@mastra/core/workflows';
|
|
17
21
|
import type {
|
|
18
22
|
StepAction,
|
|
@@ -248,11 +252,17 @@ export interface GetMemoryThreadMessagesParams {
|
|
|
248
252
|
limit?: number;
|
|
249
253
|
}
|
|
250
254
|
|
|
255
|
+
export type GetMemoryThreadMessagesPaginatedParams = Omit<StorageGetMessagesArg, 'threadConfig' | 'threadId'>;
|
|
256
|
+
|
|
251
257
|
export interface GetMemoryThreadMessagesResponse {
|
|
252
258
|
messages: CoreMessage[];
|
|
253
259
|
uiMessages: AiMessageType[];
|
|
254
260
|
}
|
|
255
261
|
|
|
262
|
+
export type GetMemoryThreadMessagesPaginatedResponse = PaginationInfo & {
|
|
263
|
+
messages: MastraMessageV1[] | MastraMessageV2[];
|
|
264
|
+
};
|
|
265
|
+
|
|
256
266
|
export interface GetLogsParams {
|
|
257
267
|
transportId: string;
|
|
258
268
|
fromDate?: Date;
|
|
@@ -404,7 +414,17 @@ export interface LoopStreamVNextNetworkParams {
|
|
|
404
414
|
export interface LoopVNextNetworkResponse {
|
|
405
415
|
status: 'success';
|
|
406
416
|
result: {
|
|
407
|
-
|
|
417
|
+
task: string;
|
|
418
|
+
resourceId: string;
|
|
419
|
+
resourceType: 'agent' | 'workflow' | 'none' | 'tool';
|
|
420
|
+
result: string;
|
|
421
|
+
iteration: number;
|
|
422
|
+
isOneOff: boolean;
|
|
423
|
+
prompt: string;
|
|
424
|
+
threadId?: string | undefined;
|
|
425
|
+
threadResourceId?: string | undefined;
|
|
426
|
+
isComplete?: boolean | undefined;
|
|
427
|
+
completionReason?: string | undefined;
|
|
408
428
|
};
|
|
409
429
|
steps: WorkflowResult<any, any>['steps'];
|
|
410
430
|
}
|
|
@@ -426,3 +446,57 @@ export interface McpToolInfo {
|
|
|
426
446
|
export interface McpServerToolListResponse {
|
|
427
447
|
tools: McpToolInfo[];
|
|
428
448
|
}
|
|
449
|
+
|
|
450
|
+
export type ClientScoreRowData = Omit<ScoreRowData, 'createdAt' | 'updatedAt'> & {
|
|
451
|
+
createdAt: string;
|
|
452
|
+
updatedAt: string;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// Scores-related types
|
|
456
|
+
export interface GetScoresByRunIdParams {
|
|
457
|
+
runId: string;
|
|
458
|
+
page?: number;
|
|
459
|
+
perPage?: number;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export interface GetScoresByScorerIdParams {
|
|
463
|
+
scorerId: string;
|
|
464
|
+
entityId?: string;
|
|
465
|
+
entityType?: string;
|
|
466
|
+
page?: number;
|
|
467
|
+
perPage?: number;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
export interface GetScoresByEntityIdParams {
|
|
471
|
+
entityId: string;
|
|
472
|
+
entityType: string;
|
|
473
|
+
page?: number;
|
|
474
|
+
perPage?: number;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export interface SaveScoreParams {
|
|
478
|
+
score: ScoreRowData;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export interface GetScoresResponse {
|
|
482
|
+
pagination: {
|
|
483
|
+
total: number;
|
|
484
|
+
page: number;
|
|
485
|
+
perPage: number;
|
|
486
|
+
hasMore: boolean;
|
|
487
|
+
};
|
|
488
|
+
scores: ClientScoreRowData[];
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export interface SaveScoreResponse {
|
|
492
|
+
score: ClientScoreRowData;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export type GetScorerResponse = MastraScorerEntry & {
|
|
496
|
+
agentIds: string[];
|
|
497
|
+
workflowIds: string[];
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
export interface GetScorersResponse {
|
|
501
|
+
scorers: Array<GetScorerResponse>;
|
|
502
|
+
}
|