Skip to content

Commit

Permalink
clean up types and registry validation
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsayo committed Feb 11, 2025
1 parent 032858b commit d509751
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
Binary file modified bun.lockb
Binary file not shown.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"typedoc": "0.26.11",
"typescript": "5.6.3",
"vite": "5.4.12",
"vitest": "3.0.5"
"vitest": "3.0.5",
"@types/bun": "latest"
},
"bun": {
"overrides": {
Expand Down Expand Up @@ -63,5 +64,7 @@
"packageManager": "bun@1.2.2",
"workspaces": [
"packages/*"
]
}
],
"module": "index.ts",
"type": "module"
}
1 change: 0 additions & 1 deletion packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ async function setupEnvironment(targetDir: string, database: string) {
}

async function selectPlugins() {
const registry = await getRegistryIndex()

const clients = await listPluginsByType("client")
const plugins = await listPluginsByType("plugin")
Expand Down
32 changes: 20 additions & 12 deletions packages/cli/src/utils/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { registrySchema, type Registry, getPluginType } from "@/src/utils/regist
import { HttpsProxyAgent } from "https-proxy-agent"
import fetch from "node-fetch"
import { REGISTRY_URL } from "./constants"

import { z } from "zod"
const agent = process.env.https_proxy
? new HttpsProxyAgent(process.env.https_proxy)
: undefined
Expand All @@ -11,11 +11,20 @@ export async function getRegistryIndex(): Promise<Registry> {
try {
console.log("REGISTRY_URL", REGISTRY_URL)
const response = await fetch(REGISTRY_URL, { agent })
console.log("repsonse", response);
const result = await response.json()
console.log("result", result)
return registrySchema.parse(result)
} catch (error: any) {
// Get the response body as text first
const text = await response.text()

let registry: Registry
try {
// validate if the response is a valid registry
registry = registrySchema.parse(JSON.parse(text))
} catch {
console.error("Invalid JSON response received from registry:", text)
throw new Error("Registry response is not valid JSON")
}

return registry
} catch (error) {
throw new Error(`Failed to fetch plugins from registry: ${error.message}`)
}
}
Expand All @@ -24,17 +33,16 @@ export async function getPluginRepository(pluginName: string): Promise<string |
try {
const registry = await getRegistryIndex()
return registry[pluginName] || null
} catch (error: any) {
} catch (error) {
throw new Error(`Failed to get plugin repository: ${error.message}`)
}
}

export async function listPluginsByType(type: "adapter" | "client" | "plugin"): Promise<string[]> {
try {
const registry = await getRegistryIndex()
console.log(registry)
return Object.keys(registry).filter(name => name.includes(type + "-"))
} catch (error: any) {
return Object.keys(registry).filter(name => name.includes(`${type}-`))
} catch (error) {
throw new Error(`Failed to list plugins: ${error.message}`)
}
}
Expand All @@ -44,8 +52,8 @@ export async function getAvailableDatabases(): Promise<string[]> {
// const adapters = await listPluginsByType("adapter")
// console.log(adapters)
// return adapters.map(name => name.replace("@elizaos/adapter-", ""))
return ["sqlite"]
} catch (error: any) {
return ["sqlite", "drizzle"]
} catch (error) {
throw new Error(`Failed to get available databases: ${error.message}`)
}
}
2 changes: 1 addition & 1 deletion packages/client/src/components/audio-recorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Record = {

let recorder: MediaRecorder;
let recordingChunks: BlobPart[] = [];
let timerTimeout: NodeJS.Timeout;
let timerTimeout: ReturnType<typeof setTimeout>;

// Utility function to pad a number with leading zeros
const padWithLeadingZeros = (num: number, length: number): string => {
Expand Down

0 comments on commit d509751

Please sign in to comment.