@mastra/client-js 0.0.0-vnext-inngest-20250508122351 → 0.0.0-vnext-20251104230439
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/CHANGELOG.md +2389 -2
- package/LICENSE.md +11 -42
- package/README.md +12 -15
- package/dist/client.d.ts +254 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/example.d.ts +2 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/index.cjs +2594 -548
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -730
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2593 -553
- package/dist/index.js.map +1 -0
- package/dist/resources/a2a.d.ts +41 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/agent-builder.d.ts +186 -0
- package/dist/resources/agent-builder.d.ts.map +1 -0
- package/dist/resources/agent.d.ts +181 -0
- package/dist/resources/agent.d.ts.map +1 -0
- package/dist/resources/base.d.ts +13 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/index.d.ts +11 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/mcp-tool.d.ts +28 -0
- package/dist/resources/mcp-tool.d.ts.map +1 -0
- package/dist/resources/memory-thread.d.ts +61 -0
- package/dist/resources/memory-thread.d.ts.map +1 -0
- package/dist/resources/observability.d.ts +35 -0
- package/dist/resources/observability.d.ts.map +1 -0
- package/dist/resources/tool.d.ts +24 -0
- package/dist/resources/tool.d.ts.map +1 -0
- package/dist/resources/vector.d.ts +51 -0
- package/dist/resources/vector.d.ts.map +1 -0
- package/dist/resources/workflow.d.ts +216 -0
- package/dist/resources/workflow.d.ts.map +1 -0
- package/dist/tools.d.ts +22 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/types.d.ts +457 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/process-client-tools.d.ts +3 -0
- package/dist/utils/process-client-tools.d.ts.map +1 -0
- package/dist/utils/process-mastra-stream.d.ts +11 -0
- package/dist/utils/process-mastra-stream.d.ts.map +1 -0
- package/dist/utils/zod-to-json-schema.d.ts +3 -0
- package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
- package/package.json +38 -20
- package/dist/index.d.cts +0 -730
- package/eslint.config.js +0 -6
- package/src/adapters/agui.test.ts +0 -167
- package/src/adapters/agui.ts +0 -219
- package/src/client.ts +0 -259
- package/src/example.ts +0 -65
- package/src/index.test.ts +0 -710
- package/src/index.ts +0 -2
- package/src/resources/agent.ts +0 -206
- package/src/resources/base.ts +0 -70
- package/src/resources/index.ts +0 -8
- package/src/resources/memory-thread.ts +0 -53
- package/src/resources/network.ts +0 -92
- package/src/resources/tool.ts +0 -38
- package/src/resources/vector.ts +0 -83
- package/src/resources/vnext-workflow.ts +0 -257
- package/src/resources/workflow.ts +0 -251
- package/src/types.ts +0 -262
- package/tsconfig.json +0 -5
- package/vitest.config.js +0 -8
package/eslint.config.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import type { Message } from '@ag-ui/client';
|
|
2
|
-
import { describe, it, expect } from 'vitest';
|
|
3
|
-
import { generateUUID, convertMessagesToMastraMessages } from './agui';
|
|
4
|
-
|
|
5
|
-
describe('generateUUID', () => {
|
|
6
|
-
it('should generate a valid UUID v4 string', () => {
|
|
7
|
-
const uuid = generateUUID();
|
|
8
|
-
// Check UUID format (8-4-4-4-12 hex digits)
|
|
9
|
-
expect(uuid).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should generate unique UUIDs', () => {
|
|
13
|
-
const uuids = new Set();
|
|
14
|
-
for (let i = 0; i < 100; i++) {
|
|
15
|
-
uuids.add(generateUUID());
|
|
16
|
-
}
|
|
17
|
-
// All UUIDs should be unique
|
|
18
|
-
expect(uuids.size).toBe(100);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('convertMessagesToMastraMessages', () => {
|
|
23
|
-
it('should convert user messages correctly', () => {
|
|
24
|
-
const messages: Message[] = [
|
|
25
|
-
{
|
|
26
|
-
id: '1',
|
|
27
|
-
role: 'user',
|
|
28
|
-
content: 'Hello, world!',
|
|
29
|
-
},
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
const result = convertMessagesToMastraMessages(messages);
|
|
33
|
-
|
|
34
|
-
expect(result).toEqual([
|
|
35
|
-
{
|
|
36
|
-
role: 'user',
|
|
37
|
-
content: 'Hello, world!',
|
|
38
|
-
},
|
|
39
|
-
]);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should convert assistant messages correctly', () => {
|
|
43
|
-
const messages: Message[] = [
|
|
44
|
-
{
|
|
45
|
-
id: '1',
|
|
46
|
-
role: 'assistant',
|
|
47
|
-
content: 'Hello, I am an assistant',
|
|
48
|
-
},
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
const result = convertMessagesToMastraMessages(messages);
|
|
52
|
-
|
|
53
|
-
expect(result).toEqual([
|
|
54
|
-
{
|
|
55
|
-
role: 'assistant',
|
|
56
|
-
content: [{ type: 'text', text: 'Hello, I am an assistant' }],
|
|
57
|
-
},
|
|
58
|
-
]);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should convert assistant messages with tool calls correctly', () => {
|
|
62
|
-
const messages: Message[] = [
|
|
63
|
-
{
|
|
64
|
-
id: '1',
|
|
65
|
-
role: 'assistant',
|
|
66
|
-
content: undefined,
|
|
67
|
-
toolCalls: [
|
|
68
|
-
{
|
|
69
|
-
id: 'tool-call-1',
|
|
70
|
-
type: 'function',
|
|
71
|
-
function: {
|
|
72
|
-
name: 'getWeather',
|
|
73
|
-
arguments: '{"location":"San Francisco"}',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
},
|
|
78
|
-
];
|
|
79
|
-
|
|
80
|
-
const result = convertMessagesToMastraMessages(messages);
|
|
81
|
-
|
|
82
|
-
expect(result).toEqual([
|
|
83
|
-
{
|
|
84
|
-
role: 'assistant',
|
|
85
|
-
content: [
|
|
86
|
-
{
|
|
87
|
-
type: 'tool-call',
|
|
88
|
-
toolCallId: 'tool-call-1',
|
|
89
|
-
toolName: 'getWeather',
|
|
90
|
-
args: { location: 'San Francisco' },
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
]);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should convert tool messages correctly', () => {
|
|
98
|
-
const messages: Message[] = [
|
|
99
|
-
{
|
|
100
|
-
id: '1',
|
|
101
|
-
role: 'tool',
|
|
102
|
-
toolCallId: 'tool-call-1',
|
|
103
|
-
content: '{"temperature":72,"unit":"F"}',
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
|
|
107
|
-
const result = convertMessagesToMastraMessages(messages);
|
|
108
|
-
|
|
109
|
-
expect(result).toEqual([
|
|
110
|
-
{
|
|
111
|
-
role: 'tool',
|
|
112
|
-
content: [
|
|
113
|
-
{
|
|
114
|
-
type: 'tool-result',
|
|
115
|
-
toolCallId: 'tool-call-1',
|
|
116
|
-
toolName: 'unknown',
|
|
117
|
-
result: '{"temperature":72,"unit":"F"}',
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
},
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('should convert a complex conversation correctly', () => {
|
|
125
|
-
const messages: Message[] = [
|
|
126
|
-
{
|
|
127
|
-
id: '1',
|
|
128
|
-
role: 'user',
|
|
129
|
-
content: "What's the weather in San Francisco?",
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
id: '2',
|
|
133
|
-
role: 'assistant',
|
|
134
|
-
content: undefined,
|
|
135
|
-
toolCalls: [
|
|
136
|
-
{
|
|
137
|
-
id: 'tool-call-1',
|
|
138
|
-
type: 'function',
|
|
139
|
-
function: {
|
|
140
|
-
name: 'getWeather',
|
|
141
|
-
arguments: '{"location":"San Francisco"}',
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
id: '3',
|
|
148
|
-
role: 'tool',
|
|
149
|
-
toolCallId: 'tool-call-1',
|
|
150
|
-
content: '{"temperature":72,"unit":"F"}',
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
id: '4',
|
|
154
|
-
role: 'assistant',
|
|
155
|
-
content: 'The weather in San Francisco is 72°F.',
|
|
156
|
-
},
|
|
157
|
-
];
|
|
158
|
-
|
|
159
|
-
const result = convertMessagesToMastraMessages(messages);
|
|
160
|
-
|
|
161
|
-
expect(result).toHaveLength(4);
|
|
162
|
-
expect(result[0].role).toBe('user');
|
|
163
|
-
expect(result[1].role).toBe('assistant');
|
|
164
|
-
expect(result[2].role).toBe('tool');
|
|
165
|
-
expect(result[3].role).toBe('assistant');
|
|
166
|
-
});
|
|
167
|
-
});
|
package/src/adapters/agui.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
// Cross-platform UUID generation function
|
|
2
|
-
import { AbstractAgent, EventType } from '@ag-ui/client';
|
|
3
|
-
import type {
|
|
4
|
-
BaseEvent,
|
|
5
|
-
RunAgentInput,
|
|
6
|
-
AgentConfig,
|
|
7
|
-
RunStartedEvent,
|
|
8
|
-
RunFinishedEvent,
|
|
9
|
-
TextMessageStartEvent,
|
|
10
|
-
TextMessageContentEvent,
|
|
11
|
-
TextMessageEndEvent,
|
|
12
|
-
Message,
|
|
13
|
-
ToolCallStartEvent,
|
|
14
|
-
ToolCallArgsEvent,
|
|
15
|
-
ToolCallEndEvent,
|
|
16
|
-
} from '@ag-ui/client';
|
|
17
|
-
import type { CoreMessage } from '@mastra/core';
|
|
18
|
-
import { Observable } from 'rxjs';
|
|
19
|
-
import type { Agent } from '../resources/agent';
|
|
20
|
-
|
|
21
|
-
interface MastraAgentConfig extends AgentConfig {
|
|
22
|
-
agent: Agent;
|
|
23
|
-
agentId: string;
|
|
24
|
-
resourceId?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class AGUIAdapter extends AbstractAgent {
|
|
28
|
-
agent: Agent;
|
|
29
|
-
resourceId?: string;
|
|
30
|
-
constructor({ agent, agentId, resourceId, ...rest }: MastraAgentConfig) {
|
|
31
|
-
super({
|
|
32
|
-
agentId,
|
|
33
|
-
...rest,
|
|
34
|
-
});
|
|
35
|
-
this.agent = agent;
|
|
36
|
-
this.resourceId = resourceId;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
protected run(input: RunAgentInput): Observable<BaseEvent> {
|
|
40
|
-
return new Observable<BaseEvent>(subscriber => {
|
|
41
|
-
const convertedMessages = convertMessagesToMastraMessages(input.messages);
|
|
42
|
-
|
|
43
|
-
subscriber.next({
|
|
44
|
-
type: EventType.RUN_STARTED,
|
|
45
|
-
threadId: input.threadId,
|
|
46
|
-
runId: input.runId,
|
|
47
|
-
} as RunStartedEvent);
|
|
48
|
-
|
|
49
|
-
this.agent
|
|
50
|
-
.stream({
|
|
51
|
-
threadId: input.threadId,
|
|
52
|
-
resourceId: this.resourceId ?? '',
|
|
53
|
-
runId: input.runId,
|
|
54
|
-
messages: convertedMessages,
|
|
55
|
-
clientTools: input.tools.reduce(
|
|
56
|
-
(acc, tool) => {
|
|
57
|
-
acc[tool.name as string] = {
|
|
58
|
-
id: tool.name,
|
|
59
|
-
description: tool.description,
|
|
60
|
-
inputSchema: tool.parameters,
|
|
61
|
-
};
|
|
62
|
-
return acc;
|
|
63
|
-
},
|
|
64
|
-
{} as Record<string, any>,
|
|
65
|
-
),
|
|
66
|
-
})
|
|
67
|
-
.then(response => {
|
|
68
|
-
let currentMessageId: string | undefined = undefined;
|
|
69
|
-
return response.processDataStream({
|
|
70
|
-
onTextPart: text => {
|
|
71
|
-
if (currentMessageId === undefined) {
|
|
72
|
-
currentMessageId = generateUUID();
|
|
73
|
-
|
|
74
|
-
const message: TextMessageStartEvent = {
|
|
75
|
-
type: EventType.TEXT_MESSAGE_START,
|
|
76
|
-
messageId: currentMessageId,
|
|
77
|
-
role: 'assistant',
|
|
78
|
-
};
|
|
79
|
-
subscriber.next(message);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const message: TextMessageContentEvent = {
|
|
83
|
-
type: EventType.TEXT_MESSAGE_CONTENT,
|
|
84
|
-
messageId: currentMessageId,
|
|
85
|
-
delta: text,
|
|
86
|
-
};
|
|
87
|
-
subscriber.next(message);
|
|
88
|
-
},
|
|
89
|
-
onFinishMessagePart: message => {
|
|
90
|
-
console.log('onFinishMessagePart', message);
|
|
91
|
-
if (currentMessageId !== undefined) {
|
|
92
|
-
const message: TextMessageEndEvent = {
|
|
93
|
-
type: EventType.TEXT_MESSAGE_END,
|
|
94
|
-
messageId: currentMessageId,
|
|
95
|
-
};
|
|
96
|
-
subscriber.next(message);
|
|
97
|
-
}
|
|
98
|
-
// Emit run finished event
|
|
99
|
-
subscriber.next({
|
|
100
|
-
type: EventType.RUN_FINISHED,
|
|
101
|
-
threadId: input.threadId,
|
|
102
|
-
runId: input.runId,
|
|
103
|
-
} as RunFinishedEvent);
|
|
104
|
-
|
|
105
|
-
// Complete the observable
|
|
106
|
-
subscriber.complete();
|
|
107
|
-
},
|
|
108
|
-
onToolCallPart(streamPart) {
|
|
109
|
-
const parentMessageId = currentMessageId || generateUUID();
|
|
110
|
-
subscriber.next({
|
|
111
|
-
type: EventType.TOOL_CALL_START,
|
|
112
|
-
toolCallId: streamPart.toolCallId,
|
|
113
|
-
toolCallName: streamPart.toolName,
|
|
114
|
-
parentMessageId,
|
|
115
|
-
} as ToolCallStartEvent);
|
|
116
|
-
|
|
117
|
-
subscriber.next({
|
|
118
|
-
type: EventType.TOOL_CALL_ARGS,
|
|
119
|
-
toolCallId: streamPart.toolCallId,
|
|
120
|
-
delta: JSON.stringify(streamPart.args),
|
|
121
|
-
parentMessageId,
|
|
122
|
-
} as ToolCallArgsEvent);
|
|
123
|
-
|
|
124
|
-
subscriber.next({
|
|
125
|
-
type: EventType.TOOL_CALL_END,
|
|
126
|
-
toolCallId: streamPart.toolCallId,
|
|
127
|
-
parentMessageId,
|
|
128
|
-
} as ToolCallEndEvent);
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
})
|
|
132
|
-
.catch(error => {
|
|
133
|
-
console.log('error', error);
|
|
134
|
-
// Handle error
|
|
135
|
-
subscriber.error(error);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
return () => {};
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Generates a UUID v4 that works in both browser and Node.js environments
|
|
145
|
-
*/
|
|
146
|
-
export function generateUUID(): string {
|
|
147
|
-
// Use crypto.randomUUID() if available (Node.js environment or modern browsers)
|
|
148
|
-
if (typeof crypto !== 'undefined') {
|
|
149
|
-
// Browser crypto API or Node.js crypto global
|
|
150
|
-
if (typeof crypto.randomUUID === 'function') {
|
|
151
|
-
return crypto.randomUUID();
|
|
152
|
-
}
|
|
153
|
-
// Fallback for older browsers
|
|
154
|
-
if (typeof crypto.getRandomValues === 'function') {
|
|
155
|
-
const buffer = new Uint8Array(16);
|
|
156
|
-
crypto.getRandomValues(buffer);
|
|
157
|
-
// Set version (4) and variant (8, 9, A, or B)
|
|
158
|
-
buffer[6] = (buffer[6]! & 0x0f) | 0x40; // version 4
|
|
159
|
-
buffer[8] = (buffer[8]! & 0x3f) | 0x80; // variant
|
|
160
|
-
|
|
161
|
-
// Convert to hex string in UUID format
|
|
162
|
-
let hex = '';
|
|
163
|
-
for (let i = 0; i < 16; i++) {
|
|
164
|
-
hex += buffer[i]!.toString(16).padStart(2, '0');
|
|
165
|
-
// Add hyphens at standard positions
|
|
166
|
-
if (i === 3 || i === 5 || i === 7 || i === 9) hex += '-';
|
|
167
|
-
}
|
|
168
|
-
return hex;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Last resort fallback (less secure but works everywhere)
|
|
173
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
174
|
-
const r = (Math.random() * 16) | 0;
|
|
175
|
-
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
176
|
-
return v.toString(16);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function convertMessagesToMastraMessages(messages: Message[]): CoreMessage[] {
|
|
181
|
-
const result: CoreMessage[] = [];
|
|
182
|
-
|
|
183
|
-
for (const message of messages) {
|
|
184
|
-
if (message.role === 'assistant') {
|
|
185
|
-
const parts: any[] = message.content ? [{ type: 'text', text: message.content }] : [];
|
|
186
|
-
for (const toolCall of message.toolCalls ?? []) {
|
|
187
|
-
parts.push({
|
|
188
|
-
type: 'tool-call',
|
|
189
|
-
toolCallId: toolCall.id,
|
|
190
|
-
toolName: toolCall.function.name,
|
|
191
|
-
args: JSON.parse(toolCall.function.arguments),
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
result.push({
|
|
195
|
-
role: 'assistant',
|
|
196
|
-
content: parts,
|
|
197
|
-
});
|
|
198
|
-
} else if (message.role === 'user') {
|
|
199
|
-
result.push({
|
|
200
|
-
role: 'user',
|
|
201
|
-
content: message.content || '',
|
|
202
|
-
});
|
|
203
|
-
} else if (message.role === 'tool') {
|
|
204
|
-
result.push({
|
|
205
|
-
role: 'tool',
|
|
206
|
-
content: [
|
|
207
|
-
{
|
|
208
|
-
type: 'tool-result',
|
|
209
|
-
toolCallId: message.toolCallId,
|
|
210
|
-
toolName: 'unknown',
|
|
211
|
-
result: message.content,
|
|
212
|
-
},
|
|
213
|
-
],
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return result;
|
|
219
|
-
}
|
package/src/client.ts
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import type { AbstractAgent } from '@ag-ui/client';
|
|
2
|
-
import { AGUIAdapter } from './adapters/agui';
|
|
3
|
-
import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow } from './resources';
|
|
4
|
-
import type {
|
|
5
|
-
ClientOptions,
|
|
6
|
-
CreateMemoryThreadParams,
|
|
7
|
-
CreateMemoryThreadResponse,
|
|
8
|
-
GetAgentResponse,
|
|
9
|
-
GetLogParams,
|
|
10
|
-
GetLogsParams,
|
|
11
|
-
GetLogsResponse,
|
|
12
|
-
GetMemoryThreadParams,
|
|
13
|
-
GetMemoryThreadResponse,
|
|
14
|
-
GetNetworkResponse,
|
|
15
|
-
GetTelemetryParams,
|
|
16
|
-
GetTelemetryResponse,
|
|
17
|
-
GetToolResponse,
|
|
18
|
-
GetVNextWorkflowResponse,
|
|
19
|
-
GetWorkflowResponse,
|
|
20
|
-
SaveMessageToMemoryParams,
|
|
21
|
-
SaveMessageToMemoryResponse,
|
|
22
|
-
} from './types';
|
|
23
|
-
|
|
24
|
-
export class MastraClient extends BaseResource {
|
|
25
|
-
constructor(options: ClientOptions) {
|
|
26
|
-
super(options);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Retrieves all available agents
|
|
31
|
-
* @returns Promise containing map of agent IDs to agent details
|
|
32
|
-
*/
|
|
33
|
-
public getAgents(): Promise<Record<string, GetAgentResponse>> {
|
|
34
|
-
return this.request('/api/agents');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
|
|
38
|
-
const agents = await this.getAgents();
|
|
39
|
-
|
|
40
|
-
return Object.entries(agents).reduce(
|
|
41
|
-
(acc, [agentId]) => {
|
|
42
|
-
const agent = this.getAgent(agentId);
|
|
43
|
-
|
|
44
|
-
acc[agentId] = new AGUIAdapter({
|
|
45
|
-
agentId,
|
|
46
|
-
agent,
|
|
47
|
-
resourceId,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return acc;
|
|
51
|
-
},
|
|
52
|
-
{} as Record<string, AbstractAgent>,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Gets an agent instance by ID
|
|
58
|
-
* @param agentId - ID of the agent to retrieve
|
|
59
|
-
* @returns Agent instance
|
|
60
|
-
*/
|
|
61
|
-
public getAgent(agentId: string) {
|
|
62
|
-
return new Agent(this.options, agentId);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Retrieves memory threads for a resource
|
|
67
|
-
* @param params - Parameters containing the resource ID
|
|
68
|
-
* @returns Promise containing array of memory threads
|
|
69
|
-
*/
|
|
70
|
-
public getMemoryThreads(params: GetMemoryThreadParams): Promise<GetMemoryThreadResponse> {
|
|
71
|
-
return this.request(`/api/memory/threads?resourceid=${params.resourceId}&agentId=${params.agentId}`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Creates a new memory thread
|
|
76
|
-
* @param params - Parameters for creating the memory thread
|
|
77
|
-
* @returns Promise containing the created memory thread
|
|
78
|
-
*/
|
|
79
|
-
public createMemoryThread(params: CreateMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
|
|
80
|
-
return this.request(`/api/memory/threads?agentId=${params.agentId}`, { method: 'POST', body: params });
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Gets a memory thread instance by ID
|
|
85
|
-
* @param threadId - ID of the memory thread to retrieve
|
|
86
|
-
* @returns MemoryThread instance
|
|
87
|
-
*/
|
|
88
|
-
public getMemoryThread(threadId: string, agentId: string) {
|
|
89
|
-
return new MemoryThread(this.options, threadId, agentId);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Saves messages to memory
|
|
94
|
-
* @param params - Parameters containing messages to save
|
|
95
|
-
* @returns Promise containing the saved messages
|
|
96
|
-
*/
|
|
97
|
-
public saveMessageToMemory(params: SaveMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
|
|
98
|
-
return this.request(`/api/memory/save-messages?agentId=${params.agentId}`, {
|
|
99
|
-
method: 'POST',
|
|
100
|
-
body: params,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Gets the status of the memory system
|
|
106
|
-
* @returns Promise containing memory system status
|
|
107
|
-
*/
|
|
108
|
-
public getMemoryStatus(agentId: string): Promise<{ result: boolean }> {
|
|
109
|
-
return this.request(`/api/memory/status?agentId=${agentId}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Retrieves all available tools
|
|
114
|
-
* @returns Promise containing map of tool IDs to tool details
|
|
115
|
-
*/
|
|
116
|
-
public getTools(): Promise<Record<string, GetToolResponse>> {
|
|
117
|
-
return this.request('/api/tools');
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Gets a tool instance by ID
|
|
122
|
-
* @param toolId - ID of the tool to retrieve
|
|
123
|
-
* @returns Tool instance
|
|
124
|
-
*/
|
|
125
|
-
public getTool(toolId: string) {
|
|
126
|
-
return new Tool(this.options, toolId);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Retrieves all available workflows
|
|
131
|
-
* @returns Promise containing map of workflow IDs to workflow details
|
|
132
|
-
*/
|
|
133
|
-
public getWorkflows(): Promise<Record<string, GetWorkflowResponse>> {
|
|
134
|
-
return this.request('/api/workflows');
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Gets a workflow instance by ID
|
|
139
|
-
* @param workflowId - ID of the workflow to retrieve
|
|
140
|
-
* @returns Workflow instance
|
|
141
|
-
*/
|
|
142
|
-
public getWorkflow(workflowId: string) {
|
|
143
|
-
return new Workflow(this.options, workflowId);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Retrieves all available vNext workflows
|
|
148
|
-
* @returns Promise containing map of vNext workflow IDs to vNext workflow details
|
|
149
|
-
*/
|
|
150
|
-
public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
|
|
151
|
-
return this.request('/api/workflows/v-next');
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Gets a vNext workflow instance by ID
|
|
156
|
-
* @param workflowId - ID of the vNext workflow to retrieve
|
|
157
|
-
* @returns vNext Workflow instance
|
|
158
|
-
*/
|
|
159
|
-
public getVNextWorkflow(workflowId: string) {
|
|
160
|
-
return new VNextWorkflow(this.options, workflowId);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Gets a vector instance by name
|
|
165
|
-
* @param vectorName - Name of the vector to retrieve
|
|
166
|
-
* @returns Vector instance
|
|
167
|
-
*/
|
|
168
|
-
public getVector(vectorName: string) {
|
|
169
|
-
return new Vector(this.options, vectorName);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Retrieves logs
|
|
174
|
-
* @param params - Parameters for filtering logs
|
|
175
|
-
* @returns Promise containing array of log messages
|
|
176
|
-
*/
|
|
177
|
-
public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
|
|
178
|
-
return this.request(`/api/logs?transportId=${params.transportId}`);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Gets logs for a specific run
|
|
183
|
-
* @param params - Parameters containing run ID to retrieve
|
|
184
|
-
* @returns Promise containing array of log messages
|
|
185
|
-
*/
|
|
186
|
-
public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
|
|
187
|
-
return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* List of all log transports
|
|
192
|
-
* @returns Promise containing list of log transports
|
|
193
|
-
*/
|
|
194
|
-
public getLogTransports(): Promise<{ transports: string[] }> {
|
|
195
|
-
return this.request('/api/logs/transports');
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* List of all traces (paged)
|
|
200
|
-
* @param params - Parameters for filtering traces
|
|
201
|
-
* @returns Promise containing telemetry data
|
|
202
|
-
*/
|
|
203
|
-
public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
|
|
204
|
-
const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
|
|
205
|
-
const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
|
|
206
|
-
|
|
207
|
-
const searchParams = new URLSearchParams();
|
|
208
|
-
if (name) {
|
|
209
|
-
searchParams.set('name', name);
|
|
210
|
-
}
|
|
211
|
-
if (scope) {
|
|
212
|
-
searchParams.set('scope', scope);
|
|
213
|
-
}
|
|
214
|
-
if (page) {
|
|
215
|
-
searchParams.set('page', String(page));
|
|
216
|
-
}
|
|
217
|
-
if (perPage) {
|
|
218
|
-
searchParams.set('perPage', String(perPage));
|
|
219
|
-
}
|
|
220
|
-
if (_attribute) {
|
|
221
|
-
if (Array.isArray(_attribute)) {
|
|
222
|
-
for (const attr of _attribute) {
|
|
223
|
-
searchParams.append('attribute', attr);
|
|
224
|
-
}
|
|
225
|
-
} else {
|
|
226
|
-
searchParams.set('attribute', _attribute);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (fromDate) {
|
|
230
|
-
searchParams.set('fromDate', fromDate.toISOString());
|
|
231
|
-
}
|
|
232
|
-
if (toDate) {
|
|
233
|
-
searchParams.set('toDate', toDate.toISOString());
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (searchParams.size) {
|
|
237
|
-
return this.request(`/api/telemetry?${searchParams}`);
|
|
238
|
-
} else {
|
|
239
|
-
return this.request(`/api/telemetry`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Retrieves all available networks
|
|
245
|
-
* @returns Promise containing map of network IDs to network details
|
|
246
|
-
*/
|
|
247
|
-
public getNetworks(): Promise<Record<string, GetNetworkResponse>> {
|
|
248
|
-
return this.request('/api/networks');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Gets a network instance by ID
|
|
253
|
-
* @param networkId - ID of the network to retrieve
|
|
254
|
-
* @returns Network instance
|
|
255
|
-
*/
|
|
256
|
-
public getNetwork(networkId: string) {
|
|
257
|
-
return new Network(this.options, networkId);
|
|
258
|
-
}
|
|
259
|
-
}
|