refactor(db): group database domain modules
This commit is contained in:
1 parent
e43a89096d
commit
6da0a58769
160 files changed
+2124
-1999
No files matched your search
@@ -5,7 +5,7 @@
|
||||
* `api-server/routes-approvals.ts`: validate → enforce the
|
||||
* `approve_ceo_strategy` ordering gate → request approval → auto-
|
||||
* approve or notify. Both the tool path and the HTTP path funnel
|
||||
* through the same `db.approvalsMod.requestApproval` + `shouldAutoApprove`
|
||||
* through the same `db.core.approvals.requestApproval` + `shouldAutoApprove`
|
||||
* plumbing, so the board sees identical rows regardless of entry point.
|
||||
*
|
||||
* No fallbacks: malformed input throws UserInputError, DB failures
|
||||
@@ -71,7 +71,7 @@ export function handleFileApprovalToolCall(
|
||||
// otherwise re-open the exact loop the HTTP gate was written to
|
||||
// close.
|
||||
if (input.type === "approve_ceo_strategy") {
|
||||
const companyHireApprovals = db.approvalsMod.listCompanyApprovalsByType(companyId, "hire_agent");
|
||||
const companyHireApprovals = db.core.approvals.listCompanyApprovalsByType(companyId, "hire_agent");
|
||||
if (companyHireApprovals.length === 0) {
|
||||
throw new UserInputError({
|
||||
code: "file_approval.strategy.before_hires",
|
||||
@@ -79,7 +79,7 @@ export function handleFileApprovalToolCall(
|
||||
"approve_ceo_strategy requires at least one hire_agent approval to exist first. File the intended hires, then the strategy.",
|
||||
});
|
||||
}
|
||||
const existingStrategy = db.approvalsMod
|
||||
const existingStrategy = db.core.approvals
|
||||
.listCompanyApprovalsByType(companyId, "approve_ceo_strategy")
|
||||
.find((a) => a.state === "pending" || a.state === "approved");
|
||||
if (existingStrategy) {
|
||||
@@ -111,7 +111,7 @@ export function handleFileApprovalToolCall(
|
||||
|
||||
let approvalId: string;
|
||||
try {
|
||||
approvalId = db.approvalsMod.requestApproval({
|
||||
approvalId = db.core.approvals.requestApproval({
|
||||
companyId,
|
||||
type: input.type,
|
||||
relatedTaskId: input.relatedTaskId ?? null,
|
||||
@@ -131,7 +131,7 @@ export function handleFileApprovalToolCall(
|
||||
}
|
||||
|
||||
try {
|
||||
db.activityMod.addActivity({
|
||||
db.core.activity.addActivity({
|
||||
companyId,
|
||||
actor: requesterId,
|
||||
action: "approval.created",
|
||||
|
||||
@@ -137,7 +137,7 @@ export function handleHireAgentToolCall(
|
||||
resolvedReportsTo &&
|
||||
resolvedReportsTo !== requesterId &&
|
||||
!canManageOrganization(db, companyId, requesterId) &&
|
||||
!db.agents.getChainOfCommand(resolvedReportsTo).some((agent) => agent.id === requesterId)
|
||||
!db.core.agents.getChainOfCommand(resolvedReportsTo).some((agent) => agent.id === requesterId)
|
||||
) {
|
||||
throw new UserInputError({
|
||||
code: "hire_agent.routing.not_in_chain",
|
||||
@@ -149,7 +149,7 @@ export function handleHireAgentToolCall(
|
||||
|
||||
const connectorRecord = (() => {
|
||||
try {
|
||||
return db.connectorsCrud.getConnector(input.connectorId);
|
||||
return db.core.connectors.getConnector(input.connectorId);
|
||||
} catch (error) {
|
||||
throw new UserInputError({
|
||||
code: "hire_agent.connector.missing",
|
||||
@@ -167,7 +167,7 @@ export function handleHireAgentToolCall(
|
||||
});
|
||||
}
|
||||
|
||||
const existingAgents = db.agents.listExistingAgentsForHireCheck(companyId);
|
||||
const existingAgents = db.core.agents.listExistingAgentsForHireCheck(companyId);
|
||||
const duplicateByName = existingAgents.find(
|
||||
(a) => a.name.toLowerCase() === input.name.toLowerCase(),
|
||||
);
|
||||
@@ -178,7 +178,7 @@ export function handleHireAgentToolCall(
|
||||
});
|
||||
}
|
||||
|
||||
const pendingHires = db.approvalsMod.listPendingHireApprovalPayloads(companyId);
|
||||
const pendingHires = db.core.approvals.listPendingHireApprovalPayloads(companyId);
|
||||
for (const pending of pendingHires) {
|
||||
try {
|
||||
const payload = pending.payloadJson ? JSON.parse(pending.payloadJson) as Record<string, unknown> : {};
|
||||
@@ -199,7 +199,7 @@ export function handleHireAgentToolCall(
|
||||
const managerLabel = resolvedReportsTo
|
||||
? (() => {
|
||||
try {
|
||||
return db.entityCrud.getAgent(resolvedReportsTo).name;
|
||||
return db.core.entity.getAgent(resolvedReportsTo).name;
|
||||
} catch {
|
||||
return resolvedReportsTo;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ export function handleHireAgentToolCall(
|
||||
}
|
||||
|
||||
try {
|
||||
db.activityMod.addActivity({
|
||||
db.core.activity.addActivity({
|
||||
companyId,
|
||||
actor: requesterId,
|
||||
action: "agent.hire_requested",
|
||||
|
||||
Reference in new issue
Block a user