Compare commits
2
Commits
2be8b08074
...
0afcc07642
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0afcc07642 | ||
|
|
0d4802f14a |
@@ -34,8 +34,8 @@ export async function getAgents(clientSiteUuid?: string): Promise<Agent[]> {
|
|||||||
SITE_UUID = user.site_uuid;
|
SITE_UUID = user.site_uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
// All agent data comes from MongoDB agent_registry if MONGODB_URI is provided or API key is sk_db_
|
// All agent data comes from MongoDB agent_registry (single source of truth)
|
||||||
if (process.env.MONGODB_URI || (API_KEY && API_KEY.startsWith("sk_db_"))) {
|
if (API_KEY && API_KEY.startsWith("sk_db_")) {
|
||||||
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/backone_dpi';
|
const MONGODB_URI = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/backone_dpi';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -44,7 +44,7 @@ export async function getAgents(clientSiteUuid?: string): Promise<Agent[]> {
|
|||||||
}
|
}
|
||||||
} catch (connErr: any) {
|
} catch (connErr: any) {
|
||||||
console.error("[getAgents Action] Connection failed:", connErr.message);
|
console.error("[getAgents Action] Connection failed:", connErr.message);
|
||||||
throw connErr;
|
return []; // Do not throw to avoid Next.js Server Component crash
|
||||||
}
|
}
|
||||||
const db = mongoose.connection.db;
|
const db = mongoose.connection.db;
|
||||||
|
|
||||||
@@ -71,15 +71,15 @@ export async function getAgents(clientSiteUuid?: string): Promise<Agent[]> {
|
|||||||
|
|
||||||
return result.data || [];
|
return result.data || [];
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Error fetching agents:", error);
|
console.error("[getAgents Action] Error fetching agents:", error);
|
||||||
throw new Error(error.message || "Failed to retrieve agents inventory.");
|
return []; // Do not throw to avoid Next.js Server Component crash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAgent(agentId: string): Promise<Agent | null> {
|
export async function getAgent(agentId: string): Promise<Agent | null> {
|
||||||
try {
|
try {
|
||||||
const API_KEY = getApiKey();
|
const API_KEY = getApiKey();
|
||||||
if (process.env.MONGODB_URI || (API_KEY && API_KEY.startsWith("sk_db_"))) {
|
if (API_KEY && API_KEY.startsWith("sk_db_")) {
|
||||||
const agents = await getAgents();
|
const agents = await getAgents();
|
||||||
return agents.find(a => a.uuid === agentId || String(a.id) === agentId) || null;
|
return agents.find(a => a.uuid === agentId || String(a.id) === agentId) || null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user