Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,14 @@ During development, the dummy email transporter writes emails to a local folder.
- `DUMMY_EMAIL_TRANSPORTER_FILE_PATH`: Default is `var/api/dummy-email-transporter/email-dumps.yml`
- `SYSTEM_EMAIL_SENDER_NAME`: the display name for the email sender (required if transport is `aws` or `smtp`)
- `SYSTEM_EMAIL_ADDRESS`: the email address for the email sender (required if transport is `aws` or `smtp`)
- `HASH_FLOW_EMAIL_SENDER`: the address the AI worker sends flow emails from (required on the worker if transporter is `aws` or `smtp`)
- `SMTP_SERVER_HOST`: the host for a SMTP server (required if transporter is `smtp`)
- `SMTP_SERVER_PORT`: the port for a SMTP server (required if transporter is `smtp`)
- `SMTP_SERVER_USERNAME`: auth username for SMTP server (optional if API is automatically authenticated)
- `SMTP_SERVER_PASSWORD`: password for SMTP server (optional if API is automatically authenticated)

The AI worker reads `HASH_EMAIL_TRANSPORTER`, `HASH_FLOW_EMAIL_SENDER` and the `SMTP_SERVER_*` variables for the Send email flow action, and none of the `SYSTEM_EMAIL_*` ones. Without a transporter, or without a sender for `aws` or `smtp`, a Send email step fails. With `dummy`, which the worker only uses in development and tests, it writes emails to `var/ai-worker/dummy-email-transporter/email-dumps.yml`. Unless `ENVIRONMENT` is `production`, the worker only sends to `@hash.ai` addresses.

#### Postgres

- `POSTGRES_PORT` (default: `5432`)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { typedActionDefinitions as actions } from "@local/hash-isomorphic-utils/flows/action-definitions";
import {
constant,
defineFlow,
flowInput,
} from "@local/hash-isomorphic-utils/flows/define-flow";

import { defineScenario } from "../scenario.js";

const composedFlow = defineFlow(
{
flowDefinitionId: "00000000-0000-4000-8000-000000001832",
name: "Send email run",
description: "Send an email with a typed body to an address from an input",
inputs: {
to: flowInput("Text"),
subject: flowInput("Text"),
},
},
({ inputs, step }) => {
const send = step("send", actions.sendEmail, {
description: "Send the email",
inputs: {
to: inputs.to,
subject: inputs.subject,
body: constant(
"Text",
"Hi Ada,\n\nYour order <#1832> has shipped & is on its way.\n\nThanks!",
),
},
});

return { outputs: { messageId: send.outputs.messageId } };
},
);

const draftedFlow = defineFlow(
{
flowDefinitionId: "00000000-0000-4000-8000-000000001833",
name: "Draft and send email run",
description: "Draft an email with AI and send its subject and body",
inputs: {},
},
({ step }) => {
const draft = step("draft", actions.draftMessage, {
description: "Draft the email",
inputs: {
instructions: constant(
"Text",
"Tell Ada, in two sentences, that her order has shipped. Sign off as the HASH team.",
),
},
});

const send = step("send", actions.sendEmail, {
description: "Send the draft",
inputs: {
to: constant("Text", "ada@hash.ai"),
subject: draft.outputs.subject,
body: draft.outputs.body,
replyTo: constant("Text", "grace@hash.ai"),
},
});

return { outputs: { messageId: send.outputs.messageId } };
},
);

/**
* The ID an email is given is different each time, so the runs expect statuses rather than outputs. With the worker's
* `dummy` transporter, the emails are written to `var/ai-worker/dummy-email-transporter/email-dumps.yml`, with the
* sender, Reply-to and ID of each.
*/
export const scenario = defineScenario({
name: "Send email",
purpose:
"Sends an email composed from flow inputs and a typed body, sends one whose subject and body Draft message wrote, and refuses a recipient outside hash.ai, which only production may email.",
runs: [
{
flow: composedFlow,
inputs: {
to: { kind: "Text", value: "ada@hash.ai" },
subject: { kind: "Text", value: "Your order has shipped" },
},
expect: { steps: { send: {} } },
},
{
flow: draftedFlow,
inputs: {},
expect: { steps: { draft: {}, send: {} } },
},
{
flow: composedFlow,
inputs: {
to: { kind: "Text", value: "ada@example.com" },
subject: { kind: "Text", value: "Your order has shipped" },
},
expect: { status: "FAILED", steps: { send: { status: "FAILED" } } },
},
],
});
2 changes: 2 additions & 0 deletions apps/hash-ai-worker-ts/src/activities/flow-activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { planDashboardRefinementAction } from "./flow-activities/plan-dashboard-
import { processAutomaticBrowsingSettingsAction } from "./flow-activities/process-automatic-browsing-settings-action.js";
import { queryEntitiesAction } from "./flow-activities/query-entities-action.js";
import { researchEntitiesAction } from "./flow-activities/research-entities-action.js";
import { sendEmailAction } from "./flow-activities/send-email-action.js";
import { takeFirstAction } from "./flow-activities/take-first-action.js";
import { updateEntityAction } from "./flow-activities/update-entity-action.js";
import { webSearchAction } from "./flow-activities/web-search-action.js";
Expand Down Expand Up @@ -60,6 +61,7 @@ export const createFlowActionActivities: CreateFlowActivities<
processAutomaticBrowsingSettingsAction,
queryEntitiesAction,
researchEntitiesAction,
sendEmailAction,
takeFirstAction,
updateEntityAction,
webSearchAction,
Expand Down
Loading
Loading