@dbx-tools/teams 0.3.39

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.
package/src/tool.ts ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The `create_teams_card` Mastra tool: a model describes a card in the small
3
+ * {@link card.CardSpec} vocabulary and gets back a compiled Adaptive Card
4
+ * document. Unlike `send_email`, building a card is a pure, side-effect-free
5
+ * transform - nothing leaves the building - so it is NOT approval-gated: the
6
+ * card is data the app then decides what to do with (render it in a preview,
7
+ * post it to a Teams incoming webhook, attach it to a bot reply).
8
+ *
9
+ * The build runs through the executor the plugin installs on the shared
10
+ * runtime, so a build from this tool picks up the same telemetry / timeout
11
+ * chain as one from the AppKit tool. In a Mastra app with no AppKit plugin
12
+ * registered the build still runs, just without interceptors.
13
+ *
14
+ * @module
15
+ */
16
+
17
+ import { log, string } from "@dbx-tools/shared-core";
18
+ import { card } from "@dbx-tools/shared-teams";
19
+ import { createTool } from "@mastra/core/tools";
20
+ import { buildCard } from "./runtime";
21
+
22
+ const logger = log.logger("teams/tool/create-card");
23
+
24
+ /**
25
+ * The model-facing description of the card-building capability, shared by the
26
+ * Mastra {@link teamsCardTool} and the AppKit `teams.createCard` tool so both
27
+ * agents get the same guidance about the vocabulary and when to reach for it.
28
+ */
29
+ export const CREATE_CARD_DESCRIPTION = string.toDescription(`
30
+ Build a Microsoft Teams Adaptive Card from a short structured description.
31
+ Provide a title, an optional subtitle and body text, an optional list of
32
+ key/value facts, and optional link buttons; the tool returns a compiled
33
+ Adaptive Card document (Adaptive Card 1.5) ready to render or post to Teams.
34
+ Use it when the user asks to summarize a status, result, or record as a Teams
35
+ card / message card, or to prepare something to post to a channel. Keep body
36
+ text to the Teams Markdown subset - **bold**, _italic_, links, and '-'
37
+ bullet lists - and put tabular key/value detail in the 'facts' array, not in
38
+ the text. Do NOT hand-author raw Adaptive Card JSON; describe the card and
39
+ this tool compiles the valid document.
40
+ `);
41
+
42
+ /** Options accepted by {@link teamsCardTool}. */
43
+ export interface TeamsCardToolOptions {
44
+ /**
45
+ * Override the tool id. Defaults to `"create_teams_card"`. A UI that renders
46
+ * the returned card keys off this id, so keep it unless you also teach the
47
+ * client about the new name.
48
+ */
49
+ id?: string;
50
+ }
51
+
52
+ /**
53
+ * Build the `create_teams_card` tool. Spread it into the agents that should be
54
+ * able to produce Teams cards.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { teamsCardTool } from "@dbx-tools/teams";
59
+ * import { createAgent } from "@dbx-tools/appkit-mastra";
60
+ *
61
+ * const support = createAgent({
62
+ * instructions: "...",
63
+ * tools: () => ({ create_teams_card: teamsCardTool() }),
64
+ * });
65
+ * ```
66
+ */
67
+ export function teamsCardTool(opts: TeamsCardToolOptions = {}) {
68
+ return createTool({
69
+ id: opts.id ?? "create_teams_card",
70
+ description: CREATE_CARD_DESCRIPTION,
71
+ inputSchema: card.cardSpecSchema,
72
+ outputSchema: card.cardResultSchema,
73
+ execute: async (input, context) => {
74
+ const spec = card.cardSpecSchema.parse(input);
75
+ const result = await buildCard(spec, context?.abortSignal);
76
+ logger.info("built", {
77
+ title: result.title,
78
+ elements: result.card.body.length,
79
+ actions: result.card.actions?.length ?? 0,
80
+ });
81
+ return result;
82
+ },
83
+ });
84
+ }