Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up types and registry validation #3436

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ packages/*/dist/*
**/dist/**

**/.docusaurus/**
**/docs/build/**
**/docs/build/**

**lock**
Binary file removed 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": "[email protected]",
"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
Loading