Files
opencode/packages/console/core/src/aws.ts
T
Ryan Vogel bc3fe8f4f5 add LLM-based enterprise lead scoring and auto-replies
Extract delivery logic from the enterprise route into a dedicated
module that grades inquiries via the Zen responses API, falls back
to simple regex scoring on failure, and sends templated auto-replies
for generic and procurement-blocked leads.

Made-with: Cursor
2026-03-19 17:38:16 -04:00

71 lines
1.9 KiB
TypeScript

import { z } from "zod"
import { Resource } from "@opencode-ai/console-resource"
import { AwsClient } from "aws4fetch"
import { fn } from "./util/fn"
export namespace AWS {
let client: AwsClient
const createClient = () => {
if (!client) {
client = new AwsClient({
accessKeyId: Resource.AWS_SES_ACCESS_KEY_ID.value,
secretAccessKey: Resource.AWS_SES_SECRET_ACCESS_KEY.value,
region: "us-east-1",
})
}
return client
}
export const sendEmail = fn(
z.object({
from: z.string().optional(),
to: z.string(),
subject: z.string(),
body: z.string(),
text: z.string().optional(),
html: z.string().optional(),
replyTo: z.string().optional(),
}),
async (input) => {
const text = input.text ?? input.body
const html = input.html ?? input.body
const res = await createClient().fetch("https://email.us-east-1.amazonaws.com/v2/email/outbound-emails", {
method: "POST",
headers: {
"X-Amz-Target": "SES.SendEmail",
"Content-Type": "application/json",
},
body: JSON.stringify({
FromEmailAddress: input.from ?? "OpenCode Zen <contact@anoma.ly>",
Destination: {
ToAddresses: [input.to],
},
...(input.replyTo && { ReplyToAddresses: [input.replyTo] }),
Content: {
Simple: {
Subject: {
Charset: "UTF-8",
Data: input.subject,
},
Body: {
Text: {
Charset: "UTF-8",
Data: text,
},
Html: {
Charset: "UTF-8",
Data: html,
},
},
},
},
}),
})
if (!res.ok) {
throw new Error(`Failed to send email: ${res.statusText}`)
}
},
)
}