Skip to content

Commit 704d956

Browse files
committed
response types
1 parent 5d1b264 commit 704d956

File tree

2 files changed

+77
-22
lines changed

2 files changed

+77
-22
lines changed

src/modules/agents.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { AxiosInstance } from "axios";
21
import { RoomsSocket, RoomsSocketConfig } from "../utils/socket-utils";
32
import { createAxiosClient } from "../utils/axios-client";
3+
import { AgentConversation, AgentMessage } from "./agents.types";
44

55
export type AgentsModuleConfig = {
66
serverUrl: string;
@@ -10,11 +10,11 @@ export type AgentsModuleConfig = {
1010

1111
export function createAgentsModule({
1212
appId,
13-
serverUrl,
14-
token,
13+
serverUrl,
14+
token,
1515
}: AgentsModuleConfig) {
1616
let currentConversation: any = null;
17-
const socketConfig: RoomsSocketConfig = {
17+
const socketConfig: RoomsSocketConfig = {
1818
serverUrl,
1919
mountPath: "/ws-user-apps/socket.io/",
2020
transports: ["websocket"],
@@ -24,18 +24,18 @@ export function createAgentsModule({
2424
},
2525
};
2626

27-
const axiosConfig: AgentsModuleConfig = {
28-
serverUrl,
29-
appId,
30-
token,
31-
};
27+
const axiosConfig: AgentsModuleConfig = {
28+
serverUrl,
29+
appId,
30+
token,
31+
};
32+
33+
let axios = createAgentsAxiosClient({
34+
serverUrl,
35+
appId,
36+
token,
37+
});
3238

33-
let axios = createAgentsAxiosClient({
34-
serverUrl,
35-
appId,
36-
token,
37-
});
38-
3939
const roomSocket = RoomsSocket({
4040
config: socketConfig,
4141
});
@@ -46,19 +46,23 @@ export function createAgentsModule({
4646
};
4747

4848
const getConversations = () => {
49-
return axios.get(`/conversations`);
49+
return axios.get<any, AgentConversation[]>(`/conversations`);
5050
};
5151

5252
const getConversation = (conversationId: string) => {
53-
return axios.get(`/conversations/${conversationId}`);
53+
return axios.get<any, AgentConversation | undefined>(
54+
`/conversations/${conversationId}`
55+
);
5456
};
5557

5658
const listConversations = (filterParams: any) => {
57-
return axios.get(`/conversations`, { params: filterParams });
59+
return axios.get<any, AgentConversation[]>(`/conversations`, {
60+
params: filterParams,
61+
});
5862
};
5963

6064
const createConversation = (conversation: any) => {
61-
return axios.post(`/conversations`, conversation);
65+
return axios.post<any, AgentConversation>(`/conversations`, conversation);
6266
};
6367

6468
const addMessage = (conversation: any, message: any) => {
@@ -75,7 +79,10 @@ export function createAgentsModule({
7579
room: `/agent-conversations/${conversation.id}`,
7680
data: JSON.stringify(conversation),
7781
});
78-
return axios.post(`/conversations/${conversation.id}/messages`, message);
82+
return axios.post<any, AgentMessage>(
83+
`/conversations/${conversation.id}/messages`,
84+
message
85+
);
7986
};
8087

8188
const subscribeToConversation = (conversationId: string, onUpdate: any) => {
@@ -115,8 +122,8 @@ function createAgentsAxiosClient({
115122
appId,
116123
serverUrl,
117124
token,
118-
interceptResponses: false,
119-
headers: {
125+
interceptResponses: true,
126+
headers: {
120127
"X-App-Id": String(appId),
121128
},
122129
});

src/modules/agents.types.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
3+
4+
5+
export type AgentConversation = {
6+
id: string;
7+
app_id: string;
8+
agent_name: string;
9+
created_by_id: string;
10+
messages: AgentMessage[];
11+
metadata?: Record<string, any>;
12+
};
13+
14+
15+
export type AgentMessage = {
16+
id: string;
17+
role: "user" | "assistant" | "system";
18+
reasoning: {
19+
start_date: string;
20+
end_date?: string;
21+
content: string;
22+
}
23+
content?: string | Record<string, any> | null;
24+
file_urls?: string[] | null;
25+
tool_calls?: {id: string;
26+
name: string;
27+
arguments_string: string;
28+
status: "running" | "success" | "error" | "stopped";
29+
results?: string | null;
30+
}[] | null;
31+
32+
usage: { prompt_tokens?: number
33+
completion_tokens?: number
34+
} | null;
35+
hidden?: boolean;
36+
custom_context?: {message: string;
37+
data: Record<string, any>;
38+
type: string;
39+
}[] | null;
40+
model: string | null;
41+
checkpoint_id: string | null;
42+
metadata?: {
43+
created_date: string;
44+
created_by_email: string;
45+
created_by_full_name: string | null;
46+
};
47+
additional_message_params?: Record<string, any>;
48+
};

0 commit comments

Comments
 (0)