forked from Soju06/codex-lb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
95 lines (82 loc) · 2.7 KB
/
Copy pathapi.ts
File metadata and controls
95 lines (82 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { del, get, post } from "@/lib/api-client";
import {
AccountActionResponseSchema,
AccountOpenCodeAuthExportResponseSchema,
AccountImportResponseSchema,
AccountsResponseSchema,
AccountTrendsResponseSchema,
ManualOauthCallbackRequestSchema,
ManualOauthCallbackResponseSchema,
OauthCompleteRequestSchema,
OauthCompleteResponseSchema,
OauthStartRequestSchema,
OauthStartResponseSchema,
OauthStatusResponseSchema,
RuntimeConnectAddressResponseSchema,
} from "@/features/accounts/schemas";
const ACCOUNTS_BASE_PATH = "/api/accounts";
const OAUTH_BASE_PATH = "/api/oauth";
export function listAccounts() {
return get(ACCOUNTS_BASE_PATH, AccountsResponseSchema);
}
export function importAccount(file: File) {
const formData = new FormData();
formData.append("auth_json", file);
return post(`${ACCOUNTS_BASE_PATH}/import`, AccountImportResponseSchema, {
body: formData,
});
}
export function pauseAccount(accountId: string) {
return post(
`${ACCOUNTS_BASE_PATH}/${encodeURIComponent(accountId)}/pause`,
AccountActionResponseSchema,
);
}
export function reactivateAccount(accountId: string) {
return post(
`${ACCOUNTS_BASE_PATH}/${encodeURIComponent(accountId)}/reactivate`,
AccountActionResponseSchema,
);
}
export function getAccountTrends(accountId: string) {
return get(
`${ACCOUNTS_BASE_PATH}/${encodeURIComponent(accountId)}/trends`,
AccountTrendsResponseSchema,
);
}
export function exportAccountOpenCodeAuth(accountId: string) {
return post(
`${ACCOUNTS_BASE_PATH}/${encodeURIComponent(accountId)}/export/opencode-auth`,
AccountOpenCodeAuthExportResponseSchema,
);
}
export function deleteAccount(accountId: string) {
return del(
`${ACCOUNTS_BASE_PATH}/${encodeURIComponent(accountId)}`,
AccountActionResponseSchema,
);
}
export function startOauth(payload: unknown) {
const validated = OauthStartRequestSchema.parse(payload);
return post(`${OAUTH_BASE_PATH}/start`, OauthStartResponseSchema, {
body: validated,
});
}
export function getOauthStatus() {
return get(`${OAUTH_BASE_PATH}/status`, OauthStatusResponseSchema);
}
export function completeOauth(payload?: unknown) {
const validated = OauthCompleteRequestSchema.parse(payload ?? {});
return post(`${OAUTH_BASE_PATH}/complete`, OauthCompleteResponseSchema, {
body: validated,
});
}
export function submitManualOauthCallback(payload: unknown) {
const validated = ManualOauthCallbackRequestSchema.parse(payload);
return post(`${OAUTH_BASE_PATH}/manual-callback`, ManualOauthCallbackResponseSchema, {
body: validated,
});
}
export function getRuntimeConnectAddress() {
return get("/api/settings/runtime/connect-address", RuntimeConnectAddressResponseSchema);
}