Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions apps/agent/agent/lib/builder-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export async function saveBuilderDraft(
backend: "eve-default",
networkPolicy: "deny-all",
credentials: "app-runtime-only",
summary: "Isolated sandbox · deny-all network · bounded CRM tools",
summary: "Isolated sandbox with deny-all network and bounded CRM tools",
};
const files = artifactFiles(input, JSON.stringify(manifest, null, 2));
for (const file of files) assertSafeArtifact(file.content);
Expand Down Expand Up @@ -1009,5 +1009,5 @@ function scopeSummary(
(resource) => resource.kind !== "integration",
);
if (recordScope === "WORKSPACE") return "Workspace CRM records";
return records.map((resource) => resource.label).join(" · ");
return records.map((resource) => resource.label).join(", ");
}
2 changes: 1 addition & 1 deletion apps/agent/agent/tools/write_brief.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default defineTool({
currentRole: z
.string()
.optional()
.describe('e.g. "CEO & Co-founder · Comp AI"'),
.describe('e.g. "CEO and Co-founder at Comp AI"'),
tenure: z.string().optional().describe('e.g. "2 yrs 3 mos"'),
previousRoles: z.array(z.string()).optional(),
seniority: z.string().optional().describe('e.g. "Founder / C-level"'),
Expand Down
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@nestjs/swagger": "^11.4.7",
"@thallesp/nestjs-better-auth": "^2.8.0",
"@trpc/server": "^11.18.0",
"better-auth": "1.6.33",
"better-auth": "1.7.7",
"cache-manager": "^7.2.9",
"class-transformer": "^0.5.1",
"class-validator": "^0.15.1",
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/activities/activities.contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const activityCreateInput = z
.refine(
(input) => input.type !== ActivityType.TASK || Boolean(input.subject),
{
message: "A task needs a subject — it is the thing to do.",
message: "A task needs a subject. It is the thing to do.",
path: ["subject"],
},
);
Expand All @@ -82,7 +82,7 @@ export type ActivityCreateInput = z.infer<typeof activityCreateInput>;
export const activityUpdateInput = z.object({
id: z.string(),
subject: z.string().trim().min(1, {
message: "A task needs a subject — it is the thing to do.",
message: "A task needs a subject. It is the thing to do.",
}),
dueAt: taskDueDayInput.nullable(),
});
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/backfill/backfill.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ export class BackfillService implements OnModuleInit {

const brand = await this.agent.backfill({
kind: "brand",
reason: "Backfill — this company has no logo or icon",
reason: "Backfill: this company has no logo or icon",
companyIds,
budget: 2,
priority: PRIORITY.brand,
});

const profile = await this.agent.backfill({
kind: "company-profile",
reason: "Backfill — this company was never successfully looked up",
reason: "Backfill: this company was never successfully looked up",
companyIds: rows.map((row) => row.id),
});

Expand Down Expand Up @@ -196,7 +196,7 @@ export class BackfillService implements OnModuleInit {

const photos = await this.agent.backfill({
kind: "portrait",
reason: "Backfill — somewhere to look for a picture, and no picture",
reason: "Backfill: somewhere to look for a picture, and no picture",
contactIds: photoRows.map((row) => row.id),
budget: 1,
priority: PRIORITY.portrait,
Expand All @@ -218,7 +218,7 @@ export class BackfillService implements OnModuleInit {

const research = await this.agent.backfill({
kind: "identify",
reason: "Backfill — this contact was never researched",
reason: "Backfill: this contact was never researched",
contactIds: researchRows.map((row) => row.id),
});

Expand Down
6 changes: 6 additions & 0 deletions apps/api/src/companies/companies.contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ export const companyDetailOutput = z.object({
primaryContactId: z.string().nullable(),
primaryContact: companyDetailPrimaryContactOutput.nullable(),
reportingCurrency: z.string(),
openPipeline: z.object({
count: z.number().int().nonnegative(),
totalCents: z.number().nullable(),
unconverted: z.number().int().nonnegative(),
nextClose: z.string().nullable(),
}),
deals: z.array(companyDetailDealOutput),
});

Expand Down
46 changes: 41 additions & 5 deletions apps/api/src/companies/companies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class CompaniesService {
}

async byId(id: string) {
const reportingCurrency = await this.conversion.reportingCurrency();
const company = await this.db.company.findUnique({
where: { id },
select: {
Expand Down Expand Up @@ -226,6 +227,7 @@ export class CompaniesService {
amount: true,
currency: true,
baseAmount: true,
baseCurrency: true,
expectedCloseDate: true,
owner: { select: OWNER_SELECT },
},
Expand All @@ -237,6 +239,30 @@ export class CompaniesService {
throw new NotFoundException(`No company with id ${id}.`);
}

const openWhere: Prisma.DealWhereInput = {
companyId: id,
archivedAt: null,
stage: { in: [...OPEN_DEAL_STAGES] },
};
const [openDeals, openValue, unconverted] = await Promise.all([
this.db.deal.aggregate({
where: openWhere,
_count: { _all: true },
_min: { expectedCloseDate: true },
}),
this.db.deal.aggregate({
where: {
AND: [openWhere, this.conversion.countedWhere(reportingCurrency)],
},
_sum: { baseAmount: true },
}),
this.db.deal.count({
where: {
AND: [openWhere, this.conversion.pendingWhere(reportingCurrency)],
},
}),
]);

const {
deals,
primaryContact,
Expand All @@ -255,13 +281,23 @@ export class CompaniesService {
enrichedAt: enrichedAt?.toISOString() ?? null,
primaryContactId: primaryContact?.id ?? null,
primaryContact,
reportingCurrency: await this.conversion.reportingCurrency(),
reportingCurrency,
openPipeline: {
count: openDeals._count._all,
totalCents: toCents(openValue._sum.baseAmount),
unconverted,
nextClose: openDeals._min.expectedCloseDate?.toISOString() ?? null,
},
deals: deals.map((deal) => ({
...deal,
amount: undefined,
baseAmount: undefined,
baseCurrency: undefined,
amountCents: toCents(deal.amount),
baseAmountCents: toCents(deal.baseAmount),
baseAmountCents:
deal.baseCurrency === reportingCurrency
? toCents(deal.baseAmount)
: null,
expectedCloseDate: deal.expectedCloseDate?.toISOString() ?? null,
})),
};
Expand Down Expand Up @@ -474,7 +510,7 @@ export class CompaniesService {
const domain = normalizeDomain(input.domain);
if (input.domain.trim() && !domain) {
throw new BadRequestException(
`"${input.domain}" is not a domain — try something like "stripe.com".`,
`"${input.domain}" is not a domain. Try something like "stripe.com".`,
);
}
data.domain = domain;
Expand Down Expand Up @@ -507,7 +543,7 @@ export class CompaniesService {
if (data.enrichmentStatus === "PENDING") {
await this.agent.companyCreated(
id,
"Domain changed — anything we knew was about a different company",
"Domain changed. Anything we knew was about a different company",
);
void this.favicon.backfill(id, updated.domain);
}
Expand Down Expand Up @@ -713,7 +749,7 @@ export class CompaniesService {

if (!company.domain) {
throw new BadRequestException(
"There is nothing to read without a domain — add one first.",
"There is nothing to read without a domain. Add one first.",
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/companies/company-directory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class CompanyDirectoryService {

await this.agent.companyCreated(
outcome.id,
`Created from an email domain (${domain}) — it has no name but the domain`,
`Created from an email domain (${domain}). It has no name but the domain`,
);

this.logger.log({
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/contacts/contacts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ export class ContactsService {
const queued = await this.agent.contactCreated(
id,
contact.linkedinUrl && !contact.imageUrl
? "A rep asked for a fresh look — they have a LinkedIn profile on file but no picture"
? "A rep asked for a fresh look. They have a LinkedIn profile on file but no picture"
: "A rep asked for a fresh look",
true,
);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/crm/bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const bulkIdsInput = z.object({
ids: z
.array(z.string())
.min(1, "Nothing was selected.")
.max(MAX_BULK_IDS, "Too many records at once — select a page at a time."),
.max(MAX_BULK_IDS, "Too many records at once. Select a page at a time."),
});

export type BulkResult = {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/currency/currency.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class CurrencyService {

if (quoteCurrency === baseCurrency) {
throw new BadRequestException(
`${baseCurrency} is the reporting currency — its rate is always 1.`,
`${baseCurrency} is the reporting currency. Its rate is always 1.`,
);
}

Expand Down
22 changes: 16 additions & 6 deletions apps/api/src/deals/deals.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export class DealsService {
}

async byId(id: string) {
const reportingCurrency = await this.conversion.reportingCurrency();
const deal = await this.db.deal.findUnique({
where: { id },
select: {
Expand All @@ -203,6 +204,7 @@ export class DealsService {
amount: true,
currency: true,
baseAmount: true,
baseCurrency: true,
fxRate: true,
fxRateAt: true,
expectedCloseDate: true,
Expand All @@ -227,6 +229,7 @@ export class DealsService {
contacts,
amount,
baseAmount,
baseCurrency,
fxRate,
fxRateAt,
archivedAt,
Expand All @@ -237,10 +240,17 @@ export class DealsService {
...rest,
fields: await this.fields.valuesFor("DEAL", id),
amountCents: toCents(amount),
baseAmountCents: toCents(baseAmount),
reportingCurrency: await this.conversion.reportingCurrency(),
fxRate: fxRate?.toNumber() ?? null,
fxRateAt: fxRateAt?.toISOString() ?? null,
baseAmountCents:
baseCurrency === reportingCurrency ? toCents(baseAmount) : null,
reportingCurrency,
fxRate:
baseCurrency === reportingCurrency
? (fxRate?.toNumber() ?? null)
: null,
fxRateAt:
baseCurrency === reportingCurrency
? (fxRateAt?.toISOString() ?? null)
: null,
stageChangedAt: deal.stageChangedAt.toISOString(),
expectedCloseDate: deal.expectedCloseDate?.toISOString() ?? null,
closedAt: deal.closedAt?.toISOString() ?? null,
Expand Down Expand Up @@ -497,7 +507,7 @@ export class DealsService {
}
if (LOSING.has(input.stage) && !closedReason) {
throw new BadRequestException(
"Say why it was lost — a closed-lost deal with no reason teaches nobody anything.",
"Say why it was lost. A closed-lost deal with no reason teaches nobody anything.",
);
}

Expand Down Expand Up @@ -701,7 +711,7 @@ export class DealsService {

if (LOSING.has(input.stage) && !closedReason) {
throw new BadRequestException(
"Say why they were lost — a closed-lost deal with no reason teaches nobody anything.",
"Say why they were lost. A closed-lost deal with no reason teaches nobody anything.",
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/google/google-connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class GoogleConnectionService {
const ours = await this.match.internalIdentity();
if (ours.domains.has(normalised)) {
throw new NotFoundException(
"That is our own domain — it is already excluded.",
"That is our own domain. It is already excluded.",
);
}

Expand Down
8 changes: 6 additions & 2 deletions apps/api/src/mailbox/mailbox-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ export class MailboxTokenService {
source: SyncSource,
): Promise<TokenResult> {
const providerId = PROVIDER_FOR_SOURCE[source];
const account = await this.db.account.findFirst({
where: { userId, providerId },
select: { id: true, scope: true },
});

if (!(await this.isConnected(userId, source))) {
if (!account || !parseScopes(account.scope).has(SCOPE_FOR_SOURCE[source])) {
return {
outcome: "not-connected",
reason: `The ${source} scope has not been granted.`,
Expand All @@ -82,7 +86,7 @@ export class MailboxTokenService {

try {
const { accessToken } = await auth.api.getAccessToken({
body: { providerId, userId },
body: { accountId: account.id, userId },
});

if (!accessToken) {
Expand Down
11 changes: 5 additions & 6 deletions apps/api/src/search/search.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Db } from "@crm/db";
import { QUICK_SEARCH } from "@crm/validation/search-config";
import { Injectable } from "@nestjs/common";
import { InjectDatabase } from "../database/database.constants";

Expand All @@ -13,15 +14,13 @@ export type SearchHit = {
imageUrl: string | null;
};

const PER_KIND = 5;

@Injectable()
export class SearchService {
constructor(@InjectDatabase() private readonly db: Db) {}

async quick(q: string): Promise<{ hits: SearchHit[] }> {
const term = q.trim();
if (term.length < 2) return { hits: [] };
if (term.length < QUICK_SEARCH.query.minLength) return { hits: [] };

const [companies, contacts, deals] = await Promise.all([
this.db.company.findMany({
Expand All @@ -31,7 +30,7 @@ export class SearchService {
{ domain: { contains: term, mode: "insensitive" } },
],
},
take: PER_KIND,
take: QUICK_SEARCH.results.perKind,
orderBy: { name: "asc" },
select: {
id: true,
Expand All @@ -50,7 +49,7 @@ export class SearchService {
{ email: { contains: term, mode: "insensitive" } },
],
},
take: PER_KIND,
take: QUICK_SEARCH.results.perKind,
orderBy: [{ lastName: "asc" }, { firstName: "asc" }],
select: {
id: true,
Expand All @@ -63,7 +62,7 @@ export class SearchService {
}),
this.db.deal.findMany({
where: { name: { contains: term, mode: "insensitive" } },
take: PER_KIND,
take: QUICK_SEARCH.results.perKind,
orderBy: [{ stage: "asc" }, { name: "asc" }],
select: {
id: true,
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/settings/settings.contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const setResearchKeyInput = z.object({
apiKey: z
.string()
.trim()
.min(8, "That does not look like a Context API key — it is too short.")
.max(500, "That does not look like a Context API key — it is too long.")
.min(8, "That does not look like a Context API key. It is too short.")
.max(500, "That does not look like a Context API key. It is too long.")
.refine(
(value) => !/\s/.test(value),
"An API key has no spaces in it. Paste the whole key on its own.",
Expand Down
Loading
Loading