MCPcopy Create free account
hub / github.com/astercloud/aster / useAsterClient

Function useAsterClient

ui/src/composables/useAsterClient.ts:16–265  ·  view source on GitHub ↗
(config: AsterClientConfig = {})

Source from the content-addressed store, hash-verified

14}
15
16export function useAsterClient(config: AsterClientConfig = {}) {
17 const baseUrl = config.baseUrl || import.meta.env.VITE_API_URL || "http://localhost:8080";
18 const apiKey = config.apiKey || import.meta.env.VITE_API_KEY || "";
19 const wsUrlEnv = config.wsUrl || import.meta.env.VITE_WS_URL;
20
21 // 构建请求头
22 const buildHeaders = (additionalHeaders: Record<string, string> = {}) => {
23 const headers: Record<string, string> = {
24 "Content-Type": "application/json",
25 ...additionalHeaders,
26 };
27
28 // 如果有 API Key,添加到请求头
29 if (apiKey) {
30 headers["X-API-Key"] = apiKey;
31 }
32
33 return headers;
34 };
35
36 // 创建 Aster Client 并添加 agent 管理方法
37 const client = {
38 agents: {
39 async list() {
40 const response = await fetch(`${baseUrl}/v1/agents`, {
41 headers: buildHeaders(),
42 });
43 return response.json();
44 },
45 async get(id: string) {
46 const response = await fetch(`${baseUrl}/v1/agents/${id}`, {
47 headers: buildHeaders(),
48 });
49 return response.json();
50 },
51 async create(data: any) {
52 const response = await fetch(`${baseUrl}/v1/agents`, {
53 method: "POST",
54 headers: buildHeaders(),
55 body: JSON.stringify(data),
56 });
57 return response.json();
58 },
59 async update(id: string, data: any) {
60 const response = await fetch(`${baseUrl}/v1/agents/${id}`, {
61 method: "PUT",
62 headers: buildHeaders(),
63 body: JSON.stringify(data),
64 });
65 return response.json();
66 },
67 async delete(id: string) {
68 const response = await fetch(`${baseUrl}/v1/agents/${id}`, {
69 method: "DELETE",
70 headers: buildHeaders(),
71 });
72 return response.status === 204 ? { success: true } : response.json();
73 },

Callers 2

useChatFunction · 0.90
useChatFunction · 0.90

Calls 1

disconnectFunction · 0.70

Tested by

no test coverage detected