Repository navigation
Expand file tree
/
Copy pathdynamicTools.ts
More file actions
43 lines (36 loc) · 1.92 KB
/
Copy pathdynamicTools.ts
File metadata and controls
43 lines (36 loc) · 1.92 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
// src/services/dynamicTools.ts
import { getClient } from '@/services/device'
import type { ApiResponse, DynamicTool, GenerateResult, ExecutionResult, GeneratedComponent } from '@/types'
export class DynamicToolsService {
async list(source?: 'ai'): Promise<ApiResponse<DynamicTool[]>> {
const client = getClient()
if (!client) return { success: false }
return client.listDynamicTools(source) as unknown as ApiResponse<DynamicTool[]>
}
async generate(prompt: string, context: string = 'chat'): Promise<ApiResponse<GenerateResult>> {
const client = getClient()
if (!client) return { success: false }
return client.generateDynamicTool(prompt, context) as unknown as ApiResponse<GenerateResult>
}
async execute(toolId: string, params: Record<string, unknown>, mode: 'chat' | 'space' = 'chat'): Promise<ApiResponse<ExecutionResult>> {
const client = getClient()
if (!client) return { success: false }
return client.executeDynamicTool(toolId, params, mode) as unknown as ApiResponse<ExecutionResult>
}
async getSchema(toolId: string, mode: 'chat' | 'space' = 'chat'): Promise<ApiResponse<GeneratedComponent>> {
const client = getClient()
if (!client) return { success: false }
return client.getDynamicToolSchema(toolId, mode) as unknown as ApiResponse<GeneratedComponent>
}
async delete(toolId: string): Promise<ApiResponse<{ id: string; status: string }>> {
const client = getClient()
if (!client) return { success: false }
return client.deleteDynamicTool(toolId) as unknown as ApiResponse<{ id: string; status: string }>
}
async setOnHome(toolId: string, onHome: boolean): Promise<ApiResponse<{ id: string; status: string }>> {
const client = getClient()
if (!client) return { success: false }
return client.setDynamicToolOnHome(toolId, onHome) as unknown as ApiResponse<{ id: string; status: string }>
}
}
export const dynamicToolsService = new DynamicToolsService()