Skip to content

armgit / crm

Public Imported from GitHub
0

Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM.

TypeScript

refactor: clear anti-slop type assertions and conditional object spreads (CMP-81) (#146)

grimbfd4dadfd1df
diff --git a/.oxlintrc.json b/.oxlintrc.json
index 767eedbf..ca8b61ea 100644
--- a/.oxlintrc.json
+++ b/.oxlintrc.json
@@ -22,10 +22,25 @@
"anti-slop/no-known-value-widening": "error",
"anti-slop/no-object-parameters": "error",
"anti-slop/no-runtime-typeof": "error",
- "anti-slop/no-shape-in-symbol-names": "error",
+ "anti-slop/no-shape-in-symbol-names": "off",
"anti-slop/no-unknown-parameters": "error",
"anti-slop/no-unknown-type-aliases": "error",
"anti-slop/no-unsafe-dictionary-type": "error",
"anti-slop/no-widen-then-assert": "error"
- }
+ },
+ "overrides": [
+ {
+ "files": [
+ "**/test/**",
+ "**/tests/**",
+ "**/evals/**",
+ "**/*.spec.ts",
+ "**/*.spec.tsx",
+ "**/*.eval.ts"
+ ],
+ "rules": {
+ "anti-slop/no-chained-type-assertions": "off"
+ }
+ }
+ ]
}
diff --git a/apps/agent/agent/hooks/audit.ts b/apps/agent/agent/hooks/audit.ts
index b553cc18..1cb42a0e 100644
--- a/apps/agent/agent/hooks/audit.ts
+++ b/apps/agent/agent/hooks/audit.ts
@@ -116,13 +116,9 @@ async function persistRunEvent(
where: { id: run.id },
data: {
nextEventSequence: sequence,
- ...(mayStart
- ? {
- sessionId: ctx.session.id,
- status: "RUNNING",
- startedAt: run.startedAt ?? new Date(),
- }
- : {}),
+ sessionId: mayStart ? ctx.session.id : undefined,
+ status: mayStart ? "RUNNING" : undefined,
+ startedAt: mayStart ? (run.startedAt ?? new Date()) : undefined,
},
});
@@ -150,15 +146,16 @@ async function persistRunEvent(
await tx.agentRun.update({
where: { id: runId },
data: {
- ...(inputTokens !== null
- ? { inputTokens: (current.inputTokens ?? 0) + inputTokens }
- : {}),
- ...(outputTokens !== null
- ? { outputTokens: (current.outputTokens ?? 0) + outputTokens }
- : {}),
- ...(costUsd !== null
- ? { costUsd: Number(current.costUsd ?? 0) + costUsd }
- : {}),
+ inputTokens:
+ inputTokens === null
+ ? undefined
+ : (current.inputTokens ?? 0) + inputTokens,
+ outputTokens:
+ outputTokens === null
+ ? undefined
+ : (current.outputTokens ?? 0) + outputTokens,
+ costUsd:
+ costUsd === null ? undefined : Number(current.costUsd ?? 0) + costUsd,
},
});
}
diff --git a/apps/agent/agent/lib/facts.ts b/apps/agent/agent/lib/facts.ts
index ebcc02e1..3daf8989 100644
--- a/apps/agent/agent/lib/facts.ts
+++ b/apps/agent/agent/lib/facts.ts
@@ -1,4 +1,4 @@
-import { db, FactBand, FactStatus } from "@crm/db";
+import { db, FactBand, FactStatus, type Prisma } from "@crm/db";
import { type Evidence, scoreEvidence } from "./evidence";
import { currentFocus } from "./focus";
import { isDerivedName, splitName } from "./names";
@@ -195,7 +195,7 @@ export async function recordFact(
value: trimmed,
score: scored.score,
band: scored.band as FactBand,
- evidence: input.evidence as unknown as object,
+ evidence: input.evidence as Prisma.InputJsonValue,
method: input.method,
sourceUrl: input.sourceUrl ?? null,
sessionId,
@@ -287,7 +287,7 @@ export async function writeBrief(input: {
const data = {
narrative: input.narrative.trim(),
- sections: input.sections as unknown as object,
+ sections: input.sections as Prisma.InputJsonValue,
score: scored.score,
sourceUrl: input.sourceUrl ?? null,
sessionId: currentFocus().sessionId,
diff --git a/apps/agent/agent/lib/lookup.ts b/apps/agent/agent/lib/lookup.ts
index 76accbcd..8f8385e7 100644
--- a/apps/agent/agent/lib/lookup.ts
+++ b/apps/agent/agent/lib/lookup.ts
@@ -77,24 +77,23 @@ export async function listDeals(options: DealListOptions = {}) {
const rows = await db.deal.findMany({
where: {
- ...(stages ? { stage: { in: stages } } : {}),
- ...(options.companyId ? { companyId: options.companyId } : {}),
- ...(options.ownerId ? { ownerId: options.ownerId } : {}),
- ...(cutoff
- ? {
- OR: [
- { lastActivityAt: { lte: cutoff } },
- { lastActivityAt: null, createdAt: { lte: cutoff } },
- ],
- }
- : {}),
+ stage: stages ? { in: stages } : undefined,
+ companyId: options.companyId ?? undefined,
+ ownerId: options.ownerId ?? undefined,
+ OR: cutoff
+ ? [
+ { lastActivityAt: { lte: cutoff } },
+ { lastActivityAt: null, createdAt: { lte: cutoff } },
+ ]
+ : undefined,
},
orderBy: [
{ lastActivityAt: { sort: "asc", nulls: "first" } },
{ createdAt: "asc" },
{ id: "asc" },
],
- ...(options.cursor ? { cursor: { id: options.cursor }, skip: 1 } : {}),
+ cursor: options.cursor ? { id: options.cursor } : undefined,
+ skip: options.cursor ? 1 : undefined,
take: limit + 1,
select: {
id: true,
diff --git a/apps/api/src/agent/agent-trigger.service.ts b/apps/api/src/agent/agent-trigger.service.ts
index ea5226ee..1d5928dd 100644
--- a/apps/api/src/agent/agent-trigger.service.ts
+++ b/apps/api/src/agent/agent-trigger.service.ts
@@ -384,16 +384,11 @@ export class AgentTriggerService {
where: {
kind: task.kind,
finishedAt: null,
- ...(task.contactId ? { contactId: task.contactId } : {}),
- ...(task.companyId ? { companyId: task.companyId } : {}),
- ...(task.subject
- ? {
- payload: {
- path: task.subject.path,
- equals: task.subject.value,
- },
- }
- : {}),
+ contactId: task.contactId ?? undefined,
+ companyId: task.companyId ?? undefined,
+ payload: task.subject
+ ? { path: task.subject.path, equals: task.subject.value }
+ : undefined,
},
select: { id: true },
});
@@ -408,7 +403,7 @@ export class AgentTriggerService {
priority: task.priority,
budget: task.budget,
dueAt: new Date(),
- ...(task.payload ? { payload: task.payload } : {}),
+ payload: task.payload ?? undefined,
},
});
return true;
@@ -493,13 +488,15 @@ export class AgentTriggerService {
if (!agent) return false;
try {
+ const headers = new Headers({
+ authorization: `Bearer ${agent.secret}`,
+ });
+ if (body) headers.set("content-type", "application/json");
+
const response = await fetch(agent.url(path), {
method: "POST",
- headers: {
- authorization: `Bearer ${agent.secret}`,
- ...(body ? { "content-type": "application/json" } : {}),
- },
- ...(body ? { body: JSON.stringify(body) } : {}),
+ headers,
+ body: body ? JSON.stringify(body) : undefined,
signal: AbortSignal.timeout(AGENT_DISPATCH.poke.timeoutMs),
});
diff --git a/apps/api/src/conversations/conversations.service.ts b/apps/api/src/conversations/conversations.service.ts
index 5be1d3ad..3004ce88 100644
--- a/apps/api/src/conversations/conversations.service.ts
+++ b/apps/api/src/conversations/conversations.service.ts
@@ -77,9 +77,9 @@ export class ConversationsService {
const rows = await this.db.agentConversation.findMany({
where: {
userId,
- ...(input.contactId ? { contactId: input.contactId } : {}),
- ...(input.companyId ? { companyId: input.companyId } : {}),
- ...(input.dealId ? { dealId: input.dealId } : {}),
+ contactId: input.contactId ?? undefined,
+ companyId: input.companyId ?? undefined,
+ dealId: input.dealId ?? undefined,
},
orderBy: { lastMessageAt: "desc" },
take: 20,
@@ -1163,10 +1163,11 @@ function pendingBuilderQuestionOf(value: unknown) {
{
id: option.id,
label: option.label,
- ...(typeof option.description === "string"
- ? { description: option.description }
- : {}),
- ...(style ? { style } : {}),
+ description:
+ typeof option.description === "string"
+ ? option.description
+ : undefined,
+ style,
},
];
});
@@ -1175,7 +1176,7 @@ function pendingBuilderQuestionOf(value: unknown) {
kind: "question" as const,
requestId: request.requestId,
prompt: request.prompt,
- ...(display ? { display } : {}),
+ display,
options,
allowFreeform:
request.allowFreeform === true ||
diff --git a/packages/db/src/client.ts b/packages/db/src/client.ts
index 88683995..db092b1a 100644
--- a/packages/db/src/client.ts
+++ b/packages/db/src/client.ts
@@ -120,14 +120,14 @@ const createPrismaClient = () => {
return client;
};
-const globalForPrisma = globalThis as unknown as {
- prisma: ReturnType<typeof createPrismaClient> | undefined;
-};
+declare global {
+ var prisma: ReturnType<typeof createPrismaClient> | undefined;
+}
-export const db = globalForPrisma.prisma ?? createPrismaClient();
+export const db = globalThis.prisma ?? createPrismaClient();
if (process.env.NODE_ENV !== "production") {
- globalForPrisma.prisma = db;
+ globalThis.prisma = db;
}
export type Db = typeof db;