Skip to content

Commit 593c063

Browse files
committed
added types and login redirect option
1 parent 7352551 commit 593c063

6 files changed

Lines changed: 195 additions & 46 deletions

File tree

src/modules/agents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RoomsSocket } from "../utils/socket-utils.js";
2-
import { AgentConversation, AgentMessage } from "./types.js";
2+
import { AgentConversation, AgentMessage } from "./agents.types.js";
33
import { AxiosInstance } from "axios";
44
import { ModelFilterParams } from "../types.js";
55

src/modules/agents.types.ts

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

src/modules/app.types.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
2+
3+
export interface AppMessageContent {
4+
content?: string;
5+
file_urls?: string[];
6+
custom_context?: unknown;
7+
additional_message_params?: Record<string, unknown>;
8+
[key: string]: unknown;
9+
}
10+
11+
export interface AppConversationMessage extends AppMessageContent {
12+
id?: string | null;
13+
role?: "user" | "assistant" | string;
14+
}
15+
16+
export interface AppConversationLike {
17+
id?: string | null;
18+
messages?: AppMessageContent[] | null;
19+
model?: string;
20+
functions_fail_silently?: boolean;
21+
}
22+
23+
24+
export interface DenoProjectLike {
25+
project_id: string
26+
project_name: string
27+
app_id: string
28+
deployment_name_to_info: Record<string, {id: string, code: string}>
29+
30+
}
31+
32+
export interface AppLike {
33+
id?: string;
34+
conversation?: AppConversationLike | null;
35+
app_stage?: "pending" | "product_flows" | "ready" | string;
36+
created_date?: string;
37+
updated_date?: string;
38+
created_by?: string;
39+
organization_id?: string;
40+
name?: string;
41+
user_description?: string;
42+
entities?: Record<string, any>;
43+
additional_user_data_schema?: any;
44+
pages?: { [key: string]: string };
45+
components: { [key: string]: any };
46+
layout?: string;
47+
globals_css?: string;
48+
agents?: Record<string, any>;
49+
logo_url?: string;
50+
slug?: string;
51+
public_settings?: "private_with_login" | "public_with_login" | "public_without_login" | "workspace_with_login" | string;
52+
is_blocked?: boolean;
53+
github_repo_url?: string;
54+
main_page?: string;
55+
installable_integrations?: any;
56+
backend_project?: DenoProjectLike;
57+
last_deployed_at?: string;
58+
is_remixable?: boolean;
59+
remixed_from_app_id?: string;
60+
hide_entity_created_by?: boolean;
61+
platform_version?: number;
62+
enable_username_password?: boolean;
63+
auth_config?: AuthConfigLike;
64+
status?: {
65+
state?: string;
66+
details?: any;
67+
last_updated_date?: string;
68+
};
69+
custom_instructions?: any;
70+
frozen_files?: string[];
71+
deep_coding_mode?: boolean;
72+
needs_to_add_diff?: boolean;
73+
installed_integration_context_items?: any[];
74+
model?: string;
75+
is_starred?: boolean;
76+
agents_enabled?: boolean;
77+
categories?: string[];
78+
functions?: any;
79+
function_names?: string[];
80+
user_entity?: UserEntityLike;
81+
app_code_hash?: string;
82+
has_backend_functions_enabled?: boolean;
83+
}
84+
85+
export interface UserLike {
86+
id?: string | null;
87+
}
88+
89+
export interface UserEntityLike {
90+
type: string;
91+
name: string;
92+
title?: string;
93+
properties?: {
94+
role?: {
95+
type?: string;
96+
description?: string;
97+
enum?: ("admin" | "user" | string)[];
98+
};
99+
email?: {
100+
type?: string;
101+
description?: string;
102+
};
103+
full_name?: {
104+
type?: string;
105+
description?: string;
106+
};
107+
};
108+
required: string[];
109+
}
110+
111+
112+
export interface AuthConfigLike {
113+
enable_username_password?: boolean;
114+
enable_google_login?: boolean;
115+
enable_microsoft_login?: boolean;
116+
enable_facebook_login?: boolean;
117+
sso_provider_name?: string;
118+
enable_sso_login?: boolean;
119+
}
120+
121+
122+
123+
124+
export type LoginInfoResponse = Pick<
125+
AppLike,
126+
| "id"
127+
| "name"
128+
| "slug"
129+
| "logo_url"
130+
| "user_description"
131+
| "updated_date"
132+
| "created_date"
133+
| "auth_config"
134+
| "platform_version"
135+
>;

src/modules/auth.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { AxiosInstance } from "axios";
1010
export function createAuthModule(
1111
axios: AxiosInstance,
1212
functionsAxiosClient: AxiosInstance,
13-
appId: string
13+
appId: string,
14+
options: {
15+
serverUrl: string;
16+
onRedirectToLogin?: () => void;
17+
}
1418
) {
1519
return {
1620
/**
@@ -42,6 +46,10 @@ export function createAuthModule(
4246
);
4347
}
4448

49+
if (options.onRedirectToLogin) {
50+
options.onRedirectToLogin();
51+
return;
52+
}
4553
// If nextUrl is not provided, use the current URL
4654
const redirectUrl = nextUrl || window.location.href;
4755

src/modules/types.ts

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

src/utils/axios-client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function createAxiosClient({
9090
serverUrl,
9191
interceptResponses = true,
9292
onError,
93+
onRedirectToLogin,
9394
}: {
9495
baseURL: string;
9596
headers?: Record<string, string>;
@@ -99,6 +100,7 @@ export function createAxiosClient({
99100
serverUrl: string;
100101
interceptResponses?: boolean;
101102
onError?: (error: Error) => void;
103+
onRedirectToLogin?: () => void;
102104
}) {
103105
const client = axios.create({
104106
baseURL,
@@ -159,7 +161,9 @@ export function createAxiosClient({
159161
console.log("Authentication required. Redirecting to login...");
160162
// Use a slight delay to allow the error to propagate first
161163
setTimeout(() => {
162-
redirectToLogin(serverUrl, appId);
164+
onRedirectToLogin
165+
? onRedirectToLogin()
166+
: redirectToLogin(serverUrl, appId);
163167
}, 100);
164168
}
165169

0 commit comments

Comments
 (0)