@@ -2,7 +2,7 @@ import { registrySchema, type Registry, getPluginType } from "@/src/utils/regist
2
2
import { HttpsProxyAgent } from "https-proxy-agent"
3
3
import fetch from "node-fetch"
4
4
import { REGISTRY_URL } from "./constants"
5
-
5
+ import { z } from "zod"
6
6
const agent = process . env . https_proxy
7
7
? new HttpsProxyAgent ( process . env . https_proxy )
8
8
: undefined
@@ -11,11 +11,20 @@ export async function getRegistryIndex(): Promise<Registry> {
11
11
try {
12
12
console . log ( "REGISTRY_URL" , REGISTRY_URL )
13
13
const response = await fetch ( REGISTRY_URL , { agent } )
14
- console . log ( "repsonse" , response ) ;
15
- const result = await response . json ( )
16
- console . log ( "result" , result )
17
- return registrySchema . parse ( result )
18
- } catch ( error : any ) {
14
+ // Get the response body as text first
15
+ const text = await response . text ( )
16
+
17
+ let registry : Registry
18
+ try {
19
+ // validate if the response is a valid registry
20
+ registry = registrySchema . parse ( JSON . parse ( text ) )
21
+ } catch {
22
+ console . error ( "Invalid JSON response received from registry:" , text )
23
+ throw new Error ( "Registry response is not valid JSON" )
24
+ }
25
+
26
+ return registry
27
+ } catch ( error ) {
19
28
throw new Error ( `Failed to fetch plugins from registry: ${ error . message } ` )
20
29
}
21
30
}
@@ -24,17 +33,16 @@ export async function getPluginRepository(pluginName: string): Promise<string |
24
33
try {
25
34
const registry = await getRegistryIndex ( )
26
35
return registry [ pluginName ] || null
27
- } catch ( error : any ) {
36
+ } catch ( error ) {
28
37
throw new Error ( `Failed to get plugin repository: ${ error . message } ` )
29
38
}
30
39
}
31
40
32
41
export async function listPluginsByType ( type : "adapter" | "client" | "plugin" ) : Promise < string [ ] > {
33
42
try {
34
43
const registry = await getRegistryIndex ( )
35
- console . log ( registry )
36
- return Object . keys ( registry ) . filter ( name => name . includes ( type + "-" ) )
37
- } catch ( error : any ) {
44
+ return Object . keys ( registry ) . filter ( name => name . includes ( `${ type } -` ) )
45
+ } catch ( error ) {
38
46
throw new Error ( `Failed to list plugins: ${ error . message } ` )
39
47
}
40
48
}
@@ -44,8 +52,8 @@ export async function getAvailableDatabases(): Promise<string[]> {
44
52
// const adapters = await listPluginsByType("adapter")
45
53
// console.log(adapters)
46
54
// return adapters.map(name => name.replace("@elizaos/adapter-", ""))
47
- return [ "sqlite" ]
48
- } catch ( error : any ) {
55
+ return [ "sqlite" , "drizzle" ]
56
+ } catch ( error ) {
49
57
throw new Error ( `Failed to get available databases: ${ error . message } ` )
50
58
}
51
59
}
0 commit comments