refactor(connectors): remove adapter module references from services
Drops every `definition.module.*` call and legacy id hardcode (claude_local, codex_local, gemini_local, claude_compat_*) from the connector services. Health checks now evaluate stored credentials against the declarative auth descriptor, model policy reads provider models via pi-ai, matching keys off provider ids, and hire-hook logs activity without invoking an adapter hook. Introduces a local normalizeCommandValue helper to replace the deleted @agentcompany/adapter-utils/server-utils import.
This commit is contained in:
1 parent
60178ceafa
commit
06a3ba603e
14 files changed
+267
-377
No files matched your search
+28
-35
@@ -1,14 +1,26 @@
|
||||
import log from "electron-log/main.js";
|
||||
import type { HireApprovedPayload, HireApprovedHookResult } from "@agentcompany/adapter-utils";
|
||||
import { getConnectorDefinition } from "./connectors";
|
||||
import type { AppDatabase } from "./database";
|
||||
|
||||
export type { HireApprovedPayload, HireApprovedHookResult };
|
||||
/**
|
||||
* Payload captured when an agent hire is approved. Kept for call-sites that
|
||||
* want to surface the approval in activity feeds or future integrations.
|
||||
*/
|
||||
export interface HireApprovedPayload {
|
||||
companyId: string;
|
||||
agentId: string;
|
||||
agentName: string;
|
||||
connectorId: string;
|
||||
source: "join_request" | "approval";
|
||||
sourceId: string;
|
||||
approvedAt: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the adapter that an agent hire was approved.
|
||||
* Record that an agent hire was approved. Pi-mono does not expose an adapter
|
||||
* hook, so this records an activity row for the company timeline.
|
||||
* Non-fatal: failures are logged but never thrown.
|
||||
* Follows the Paperclip hire-hook.ts pattern.
|
||||
*/
|
||||
export async function notifyHireApproved(
|
||||
db: AppDatabase,
|
||||
@@ -37,49 +49,30 @@ export async function notifyHireApproved(
|
||||
return;
|
||||
}
|
||||
|
||||
const adapter = connectorDef.module;
|
||||
if (!adapter.onHireApproved) {
|
||||
// Adapter doesn't implement the hook — this is normal, not an error
|
||||
return;
|
||||
}
|
||||
|
||||
const locale = (db.queryAll<{ value: string }>("select value from settings where key = 'locale' limit 1")[0]?.value ?? "en");
|
||||
const payload: HireApprovedPayload = {
|
||||
companyId: input.companyId,
|
||||
agentId: input.agentId,
|
||||
agentName: agent.name,
|
||||
adapterType: connectorDef.id,
|
||||
connectorId: connectorDef.id,
|
||||
source: input.source,
|
||||
sourceId: input.sourceId,
|
||||
approvedAt: input.approvedAt ?? new Date().toISOString(),
|
||||
message: (db.queryAll<{ value: string }>("select value from settings where key = 'locale' limit 1")[0]?.value ?? "en") === "zh"
|
||||
message: locale === "zh"
|
||||
? `你已被批准为"${agent.title}"。你现在已激活,可以接收任务。`
|
||||
: `Your hire as "${agent.title}" in the company has been approved. You are now active and ready to receive tasks.`,
|
||||
};
|
||||
|
||||
const result = await adapter.onHireApproved(payload, {});
|
||||
if (result.ok) {
|
||||
log.info(`[hire-hook] Successfully notified adapter for agent ${agent.name} (${input.agentId})`);
|
||||
db.addActivity({
|
||||
companyId: input.companyId,
|
||||
actor: "system",
|
||||
action: "hire_hook.success",
|
||||
entityType: "agent",
|
||||
entityId: input.agentId,
|
||||
detail: `Hire notification sent to ${connectorDef.id} adapter`,
|
||||
});
|
||||
} else {
|
||||
log.warn(`[hire-hook] Adapter returned error for agent ${agent.name}: ${result.error}`);
|
||||
db.addActivity({
|
||||
companyId: input.companyId,
|
||||
actor: "system",
|
||||
action: "hire_hook.failed",
|
||||
entityType: "agent",
|
||||
entityId: input.agentId,
|
||||
detail: `Adapter error: ${result.error ?? "unknown"}`,
|
||||
});
|
||||
}
|
||||
log.info(`[hire-hook] Hire approved for agent ${agent.name} (${input.agentId}) on connector ${connectorDef.id}`);
|
||||
db.addActivity({
|
||||
companyId: input.companyId,
|
||||
actor: "system",
|
||||
action: "hire_hook.success",
|
||||
entityType: "agent",
|
||||
entityId: input.agentId,
|
||||
detail: `Hire approved: ${payload.agentName} via ${connectorDef.id}`,
|
||||
});
|
||||
} catch (error) {
|
||||
// Non-fatal: log and continue
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
log.error(`[hire-hook] Exception notifying hire for agent ${input.agentId}: ${message}`);
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user