@dbx-tools/appkit-mastra 0.1.41 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,158 +0,0 @@
1
- /**
2
- * Mastra tool: `send_email`. Gated behind {@link requireApproval}
3
- * so the model can call it freely but execution is paused until a
4
- * human approves via the chat UI.
5
- *
6
- * The execute body is a stub - it logs the would-be email to the
7
- * server console (via `logUtils.logger`) and returns success. Swap
8
- * in a real SMTP / SES / Resend / Workspace Mail call later by
9
- * editing the `execute` body; the tool surface and approval gate
10
- * stay the same.
11
- *
12
- * Approval flow (Mastra + AI SDK V5):
13
- *
14
- * 1. Model calls the tool with `{ to, subject, body, ... }`.
15
- * 2. Mastra evaluates `requireApproval` (here always `true`),
16
- * pauses the agent loop, and emits a `tool-call-approval`
17
- * chunk on the response stream.
18
- * 3. The chat client renders an approve/deny prompt against the
19
- * `state: 'approval-requested'` tool part. On approve, it sends
20
- * a `MastraToolApproval` response back; on deny, the tool call
21
- * is rejected and the model sees an error.
22
- * 4. On approve, this `execute` runs and logs the email.
23
- *
24
- * The tool is intentionally NOT auto-installed on every agent -
25
- * email is domain-specific, not infrastructure. Spread it into the
26
- * specific agents that should be able to draft emails.
27
- */
28
-
29
- import { logUtils, stringUtils } from "@dbx-tools/shared";
30
- import { createTool } from "@mastra/core/tools";
31
- import { z } from "zod";
32
-
33
- const log = logUtils.logger("mastra/tool/send-email");
34
-
35
- const emailInputSchema = z.object({
36
- to: z.string().describe(
37
- stringUtils.toDescription(`
38
- Single recipient email address (e.g. "alice@example.com"). For
39
- multiple recipients, comma-separate them yourself.
40
- `),
41
- ),
42
- subject: z.string().describe(
43
- stringUtils.toDescription(`
44
- Subject line.
45
- `),
46
- ),
47
- body: z.string().describe(
48
- stringUtils.toDescription(`
49
- Email body. Plain text or markdown; the renderer downstream decides
50
- which to honour. Be specific - the recipient may not have any
51
- context the model has from prior chat turns.
52
- `),
53
- ),
54
- cc: z
55
- .array(z.string())
56
- .optional()
57
- .describe(
58
- stringUtils.toDescription(`
59
- Optional CC recipients.
60
- `),
61
- ),
62
- bcc: z
63
- .array(z.string())
64
- .optional()
65
- .describe(
66
- stringUtils.toDescription(`
67
- Optional BCC recipients.
68
- `),
69
- ),
70
- });
71
-
72
- const emailOutputSchema = z.object({
73
- sent: z.boolean().describe(
74
- stringUtils.toDescription(`
75
- True when the email was dispatched. The current implementation
76
- always returns true after console-logging the would-be email; swap
77
- in a real provider to make this meaningful.
78
- `),
79
- ),
80
- recipient: z.string().describe(
81
- stringUtils.toDescription(`
82
- Echo of the \`to\` field for confirmation.
83
- `),
84
- ),
85
- });
86
-
87
- /** Options accepted by {@link buildEmailTool}. */
88
- export interface BuildEmailToolOptions {
89
- /**
90
- * Override the tool id. Defaults to `"send_email"`. Useful if a
91
- * caller wants `send_internal_email` / `send_external_email`
92
- * variants.
93
- */
94
- id?: string;
95
- /**
96
- * Replace the default execute body with a real provider call.
97
- * Receives the validated input and must return `{sent, recipient}`.
98
- * The console-log default is meant for demos / dev; production
99
- * deployments should wire SMTP / SES / Resend / Workspace Mail
100
- * here.
101
- */
102
- send?: (input: z.infer<typeof emailInputSchema>) => Promise<void> | void;
103
- }
104
-
105
- /**
106
- * Build the `send_email` tool. Approval-gated by default; the
107
- * execute body either calls the supplied {@link send} hook or
108
- * logs the email to the server console as a demo stub.
109
- *
110
- * @example
111
- * ```ts
112
- * import { buildEmailTool, createAgent, mastra } from "@dbx-tools/appkit-mastra";
113
- *
114
- * const support = createAgent({
115
- * instructions: "...",
116
- * tools(plugins) {
117
- * return {
118
- * ...(plugins.genie?.toolkit() ?? {}),
119
- * send_email: buildEmailTool(),
120
- * };
121
- * },
122
- * });
123
- * ```
124
- */
125
- export function buildEmailTool(opts: BuildEmailToolOptions = {}) {
126
- return createTool({
127
- id: opts.id ?? "send_email",
128
- description: stringUtils.toDescription(`
129
- Send an email on the user's behalf. Pass a recipient address,
130
- subject, and body; the user will be prompted to approve the send
131
- before it goes out (the tool is approval-gated). Use this when
132
- the user explicitly asks to send / forward / share something via
133
- email - never autonomously. Keep subjects short and bodies
134
- focused; the recipient may not have any of the chat context.
135
- `),
136
- inputSchema: emailInputSchema,
137
- outputSchema: emailOutputSchema,
138
- requireApproval: true,
139
- execute: async (input) => {
140
- const { to, subject, body, cc, bcc } = input as z.infer<typeof emailInputSchema>;
141
- // Default behaviour: dump the email to the server console so
142
- // demos can see the gate fire end-to-end without a real
143
- // provider. Replace by passing `opts.send`.
144
- log.info("send", {
145
- to,
146
- ...(cc && cc.length > 0 ? { cc } : {}),
147
- ...(bcc && bcc.length > 0 ? { bcc } : {}),
148
- subject,
149
- bodyLength: body.length,
150
- body,
151
- });
152
- if (opts.send) {
153
- await opts.send(input as z.infer<typeof emailInputSchema>);
154
- }
155
- return { sent: true, recipient: to };
156
- },
157
- });
158
- }