@introspection-ai/recipes 0.49.0 → 0.51.0

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.
Files changed (160) hide show
  1. package/dist/api/mcp.d.ts +1 -0
  2. package/dist/api/mcp.d.ts.map +1 -1
  3. package/dist/api/mcp.js +1 -0
  4. package/dist/api/mcp.js.map +1 -1
  5. package/dist/channels/tools.d.ts.map +1 -1
  6. package/dist/channels/tools.js +2 -17
  7. package/dist/channels/tools.js.map +1 -1
  8. package/dist/command-parameters.d.ts +10 -0
  9. package/dist/command-parameters.d.ts.map +1 -0
  10. package/dist/command-parameters.js +25 -0
  11. package/dist/command-parameters.js.map +1 -0
  12. package/dist/connector-tools.d.ts +1 -1
  13. package/dist/connector-tools.d.ts.map +1 -1
  14. package/dist/connector-tools.js +13 -5
  15. package/dist/connector-tools.js.map +1 -1
  16. package/dist/documents/module.d.ts.map +1 -1
  17. package/dist/documents/module.js +2 -4
  18. package/dist/documents/module.js.map +1 -1
  19. package/dist/documents/profile.d.ts +1 -1
  20. package/dist/documents/profile.js +1 -1
  21. package/dist/egress.d.ts +23 -0
  22. package/dist/egress.d.ts.map +1 -0
  23. package/dist/egress.js +36 -0
  24. package/dist/egress.js.map +1 -0
  25. package/dist/extensions.d.ts +1 -1
  26. package/dist/extensions.d.ts.map +1 -1
  27. package/dist/extensions.js +23 -2
  28. package/dist/extensions.js.map +1 -1
  29. package/dist/introspection-open.d.ts +46 -0
  30. package/dist/introspection-open.d.ts.map +1 -0
  31. package/dist/introspection-open.js +278 -0
  32. package/dist/introspection-open.js.map +1 -0
  33. package/dist/mcp/index.d.ts +37 -0
  34. package/dist/mcp/index.d.ts.map +1 -1
  35. package/dist/mcp/index.js +14 -4
  36. package/dist/mcp/index.js.map +1 -1
  37. package/dist/mcp/pi-client.d.ts +97 -0
  38. package/dist/mcp/pi-client.d.ts.map +1 -0
  39. package/dist/mcp/pi-client.js +342 -0
  40. package/dist/mcp/pi-client.js.map +1 -0
  41. package/dist/mcp/policy.d.ts +2 -0
  42. package/dist/mcp/policy.d.ts.map +1 -1
  43. package/dist/mcp/policy.js +6 -0
  44. package/dist/mcp/policy.js.map +1 -1
  45. package/dist/mcp-chunks/{chunk-3M4OCQR5.js → chunk-PO2SOBEN.js} +1 -0
  46. package/dist/mcp-daemon.js +1 -1
  47. package/dist/mcp-run-worker.js +1 -1
  48. package/dist/open.d.ts +82 -0
  49. package/dist/open.d.ts.map +1 -0
  50. package/dist/open.js +152 -0
  51. package/dist/open.js.map +1 -0
  52. package/dist/pi-extension.d.ts.map +1 -1
  53. package/dist/pi-extension.js +99 -8
  54. package/dist/pi-extension.js.map +1 -1
  55. package/dist/productivity/content.d.ts +25 -0
  56. package/dist/productivity/content.d.ts.map +1 -0
  57. package/dist/productivity/content.js +94 -0
  58. package/dist/productivity/content.js.map +1 -0
  59. package/dist/productivity/handles.d.ts +72 -0
  60. package/dist/productivity/handles.d.ts.map +1 -0
  61. package/dist/productivity/handles.js +111 -0
  62. package/dist/productivity/handles.js.map +1 -0
  63. package/dist/productivity/http.d.ts +35 -0
  64. package/dist/productivity/http.d.ts.map +1 -0
  65. package/dist/productivity/http.js +203 -0
  66. package/dist/productivity/http.js.map +1 -0
  67. package/dist/productivity/index.d.ts +11 -0
  68. package/dist/productivity/index.d.ts.map +1 -0
  69. package/dist/productivity/index.js +7 -0
  70. package/dist/productivity/index.js.map +1 -0
  71. package/dist/productivity/module.d.ts +63 -0
  72. package/dist/productivity/module.d.ts.map +1 -0
  73. package/dist/productivity/module.js +119 -0
  74. package/dist/productivity/module.js.map +1 -0
  75. package/dist/productivity/paging.d.ts +32 -0
  76. package/dist/productivity/paging.d.ts.map +1 -0
  77. package/dist/productivity/paging.js +42 -0
  78. package/dist/productivity/paging.js.map +1 -0
  79. package/dist/productivity/tools.d.ts +40 -0
  80. package/dist/productivity/tools.d.ts.map +1 -0
  81. package/dist/productivity/tools.js +969 -0
  82. package/dist/productivity/tools.js.map +1 -0
  83. package/dist/productivity/types.d.ts +538 -0
  84. package/dist/productivity/types.d.ts.map +1 -0
  85. package/dist/productivity/types.js +119 -0
  86. package/dist/productivity/types.js.map +1 -0
  87. package/dist/recipe/agent.d.ts +6 -1
  88. package/dist/recipe/agent.d.ts.map +1 -1
  89. package/dist/recipe/agent.js +48 -7
  90. package/dist/recipe/agent.js.map +1 -1
  91. package/dist/recipe/companions.d.ts +2 -1
  92. package/dist/recipe/companions.d.ts.map +1 -1
  93. package/dist/recipe/companions.js +14 -11
  94. package/dist/recipe/companions.js.map +1 -1
  95. package/dist/recipe/manifest.generated.d.ts +4 -1
  96. package/dist/recipe/manifest.generated.d.ts.map +1 -1
  97. package/dist/recipe/manifest.generated.js +5 -2
  98. package/dist/recipe/manifest.generated.js.map +1 -1
  99. package/dist/recipe/package.d.ts +12 -0
  100. package/dist/recipe/package.d.ts.map +1 -1
  101. package/dist/recipe/package.js +93 -0
  102. package/dist/recipe/package.js.map +1 -1
  103. package/dist/review.d.ts +1 -0
  104. package/dist/review.d.ts.map +1 -1
  105. package/dist/review.js +1 -0
  106. package/dist/review.js.map +1 -1
  107. package/dist/search/egress.d.ts +12 -0
  108. package/dist/search/egress.d.ts.map +1 -0
  109. package/dist/search/egress.js +24 -0
  110. package/dist/search/egress.js.map +1 -0
  111. package/dist/search/http.d.ts +16 -0
  112. package/dist/search/http.d.ts.map +1 -0
  113. package/dist/search/http.js +75 -0
  114. package/dist/search/http.js.map +1 -0
  115. package/dist/search/index.d.ts +9 -0
  116. package/dist/search/index.d.ts.map +1 -0
  117. package/dist/search/index.js +5 -0
  118. package/dist/search/index.js.map +1 -0
  119. package/dist/search/mcp.d.ts +58 -0
  120. package/dist/search/mcp.d.ts.map +1 -0
  121. package/dist/search/mcp.js +84 -0
  122. package/dist/search/mcp.js.map +1 -0
  123. package/dist/search/module.d.ts +16 -0
  124. package/dist/search/module.d.ts.map +1 -0
  125. package/dist/search/module.js +27 -0
  126. package/dist/search/module.js.map +1 -0
  127. package/dist/search/tool.d.ts +96 -0
  128. package/dist/search/tool.d.ts.map +1 -0
  129. package/dist/search/tool.js +505 -0
  130. package/dist/search/tool.js.map +1 -0
  131. package/dist/search/types.d.ts +247 -0
  132. package/dist/search/types.d.ts.map +1 -0
  133. package/dist/search/types.js +60 -0
  134. package/dist/search/types.js.map +1 -0
  135. package/dist/session.d.ts.map +1 -1
  136. package/dist/session.js +175 -15
  137. package/dist/session.js.map +1 -1
  138. package/dist/skill-progress.d.ts.map +1 -1
  139. package/dist/skill-progress.js +5 -1
  140. package/dist/skill-progress.js.map +1 -1
  141. package/dist/tool-search.d.ts +2 -2
  142. package/dist/tool-search.d.ts.map +1 -1
  143. package/dist/tool-search.js +4 -2
  144. package/dist/tool-search.js.map +1 -1
  145. package/docs/{index.md → README.md} +10 -3
  146. package/docs/{slack.md → channels/slack.md} +1 -1
  147. package/docs/{documents.md → documents/README.md} +4 -4
  148. package/docs/interactions.md +90 -31
  149. package/docs/mcp-configuration.md +77 -2
  150. package/docs/productivity/README.md +360 -0
  151. package/docs/productivity/google.md +226 -0
  152. package/docs/productivity/microsoft.md +143 -0
  153. package/docs/recipe-format.md +24 -3
  154. package/docs/search/README.md +801 -0
  155. package/package.json +19 -8
  156. package/skills/README.md +12 -0
  157. package/skills/productivity/SKILL.md +76 -0
  158. package/skills/search/SKILL.md +72 -0
  159. /package/docs/{channels.md → channels/README.md} +0 -0
  160. /package/{documents → skills/documents}/SKILL.md +0 -0
@@ -48,8 +48,9 @@ including tools a server may add later; patterns such as `search_*` are invalid.
48
48
  `"required": true` must resolve to a bound endpoint at session materialization
49
49
  or the session fails closed rather than starting without the capability.
50
50
 
51
- In `mode: tools`, a required server must also be discovered when the session
52
- starts. A session skips that check for a server only when both of these hold:
51
+ In `mode: tools` and `mode: codemode`, a required server must also be
52
+ discovered when the session starts: `codemode` waits up to
53
+ `PI_RECIPES_MCP_CONNECT_TIMEOUT_MS` (default 30 seconds) for it to connect. A session skips that check for a server only when both of these hold:
53
54
 
54
55
  - the server's declaration sets `"discovery": "defer"` (default `"require"`),
55
56
  so the Recipe chooses which servers may be skipped and an unmarked one is
@@ -115,12 +116,75 @@ change in the session, so loaded tools survive resume. It never grants access
115
116
  beyond the Recipe manifest and agent policy. Recipes also registers `mcp_search` as a
116
117
  compatibility alias when MCP tools are deferred.
117
118
 
119
+ `mode: codemode` runs the agent's MCP servers on Pi's own MCP support, inside
120
+ the Pi process, with no `mcp` command and no daemon. The model sees a `codemode`
121
+ tool, and its scripts call each authorized tool as
122
+ `tools.mcp__<server>__<tool>(args)`, finding tools with `searchTools()` and
123
+ getting the whole MCP result back. `eager` tools are also declared to the model
124
+ directly:
125
+
126
+ ```yaml
127
+ mcp:
128
+ mode: codemode
129
+ servers:
130
+ contacts:
131
+ include: ["*"]
132
+ eager:
133
+ - search_contacts
134
+ ```
135
+
136
+ Tools outside the authorized set cannot be called, from a script or otherwise.
137
+ `defer` is invalid in codemode, since every tool but the `eager` ones is already
138
+ off the model's declarations.
139
+
118
140
  `defer` and `eager` are invalid in CLI mode. An omitted agent `mcp` block
119
141
  inherits its base policy. Once a child declares `mcp`, the complete block
120
142
  replaces the inherited policy; restate its mode, servers, authorization, and
121
143
  activation selectors. This makes external capability changes reviewable at the
122
144
  derived agent. Every resolved agent owns its mode independently.
123
145
 
146
+ ### Keep a server behind a tool
147
+
148
+ A server can sit behind one of the agent's own tools, so the model sees that
149
+ one stable tool and the Recipe can change or compare the providers behind it.
150
+ The productivity tools (`mail`, `calendar`, `drive`) work this way, as does
151
+ `web_search` with its providers' servers ([Web search](search/README.md#declare-the-servers)):
152
+
153
+ ```yaml
154
+ tools: [mail]
155
+ mcp:
156
+ mode: cli
157
+ servers:
158
+ gmail:
159
+ include: ["*"]
160
+ behind: [mail]
161
+ ```
162
+
163
+ `behind` lists the tools allowed to call the server: each must be in the
164
+ agent's `tools`, and the list is never empty. Its tools are reachable only from
165
+ inside a call of one of those tools, through `ctx.executeTool(mcpToolName(server,
166
+ tool), args)`, and a call from inside a codemode script the tool runs counts.
167
+ Recipes refuses every other call before it reaches the server: one the model
168
+ makes, one from a codemode script, and one from any other tool, each with a
169
+ result that names the tool to call instead.
170
+
171
+ Whatever the agent's mode, such a server runs on Pi's own MCP client, as in
172
+ codemode, and stays out of the `mcp` command and the tools-mode daemon. The
173
+ model is not told about it: its tools are not declared, codemode does not list
174
+ them, `tool_search` does not find them, and Pi's list of MCP servers in the
175
+ system prompt leaves it out. `required` and discovery behave as in codemode: a
176
+ required server must connect before the first turn, and a call through the
177
+ front tool waits for one still connecting. `defer` and `eager` are invalid
178
+ with `behind`.
179
+
180
+ What Pi cannot hide: a codemode script can still see the tools' names through
181
+ `searchTools()`, `describeTool()` and `ALL_TOOLS`, though calling one is
182
+ refused. The record of the front tool's nested calls (`nestedCalls` on its
183
+ result) stays in the session file and is never sent to the model. The guard
184
+ holds calls inside the Pi process; it is no network boundary, so a sandbox
185
+ that must not reach the server's endpoint at all needs that enforced by the
186
+ host's egress and credential rules.
187
+
124
188
  ## 3. Supply endpoint configuration
125
189
 
126
190
  A referenced MCP manifest can carry a portable configured endpoint and catalog.
@@ -198,6 +262,17 @@ own registered tool catalog and active set. The MCP daemon and mcporter config
198
262
  remain private to those wrappers; shell tools do not receive an `mcp` command,
199
263
  `MCPORTER_CONFIG`, or MCP session path.
200
264
 
265
+ In codemode, Pi's MCP support connects each server in the background when the
266
+ session starts and keeps no state outside the session: no `mcp.json` is read
267
+ and no OAuth credential is stored. A Recipe extension calls an MCP tool with
268
+ `ctx.executeTool(mcpToolName(server, tool), args)`, `mcpToolName` coming from
269
+ `@introspection-ai/recipes/mcp`. Each Recipe extension tool waits for servers
270
+ still connecting before it runs; a tool that calls no MCP tool can declare
271
+ `reachesTools: () => []` to skip the wait, or name the servers it reaches
272
+ (`() => ["mcp__contacts"]`). Every call, a script's nested ones included, passes
273
+ through Pi's `tool_call` and `tool_result` hooks. A binding that authenticates
274
+ with an OAuth flow is not supported in codemode; bind it with a header.
275
+
201
276
  Pi receives each tool's MCP input schema. If the server declares
202
277
  `outputSchema`, Recipes retains and validates it locally against successful
203
278
  `structuredContent`; providers do not currently receive it as a tool
@@ -0,0 +1,360 @@
1
+ # Productivity tools
2
+
3
+ **Status: the host is built** (`@introspection-ai/recipes/productivity`): the
4
+ `pi.productivity` declaration and its checks, the provider contract, the
5
+ `mail`, `calendar` and `drive` tools, handles, and the core skill. Provider
6
+ packages are built separately: see each provider's guide for its status.
7
+ [As built](#as-built) lists where the host differs from the design below.
8
+
9
+ A Recipe that works with a person's mail, calendar and files declares a
10
+ **productivity provider**. The host then registers up to three tools, `mail`,
11
+ `calendar` and `drive`, each with a `command` discriminator, shaped
12
+ identically for every provider. A provider package supplies the transport and
13
+ a capability descriptor; the commands, their schemas and the handle rules
14
+ live in the host, as they do for [channels](../channels/README.md) and
15
+ [documents](../documents/README.md).
16
+
17
+ The same properties follow:
18
+
19
+ - **A command a provider cannot support is absent, not failing.** Each
20
+ provider declares what it supports per tool, and registration filters on
21
+ it. A provider with no free/busy API has no `calendar free_busy`.
22
+ - **The vocabulary is neutral.** A Recipe written against `mail search` runs
23
+ against Microsoft 365 or Google Workspace by changing the `provider`, not
24
+ the prompt. There is no raw provider payload in a command's arguments or
25
+ results.
26
+ - **The model can act only on what a tool returned.** Messages, events and
27
+ files are addressed by opaque handles the host mints for the session, never
28
+ by a provider ID the model could have read or invented.
29
+
30
+ ## Declare a productivity provider
31
+
32
+ ```json
33
+ {
34
+ "pi": {
35
+ "productivity": [
36
+ {
37
+ "provider": "microsoft",
38
+ "tools": {
39
+ "mail": ["search", "read", "draft"],
40
+ "calendar": ["list", "create", "respond"],
41
+ "drive": ["search", "read"]
42
+ }
43
+ }
44
+ ]
45
+ }
46
+ }
47
+ ```
48
+
49
+ ```yaml
50
+ tools: [mail, calendar, drive]
51
+ ```
52
+
53
+ - `provider` is served by the package
54
+ `@introspection-ai/recipe-productivity-<provider>`. The first two are
55
+ `microsoft` (Outlook mail, Outlook calendar, OneDrive and SharePoint) and
56
+ `google` (Gmail, Google Calendar, Google Drive).
57
+ - `tools` is an optional allowlist per tool, like the channels `commands`
58
+ list. Omitting a tool exposes all of its supported commands; an empty list
59
+ exposes none of that tool. Unknown or unsupported commands fail at
60
+ registration, and commands outside the allowlist are rejected before any
61
+ provider call.
62
+ - One declaration per Recipe. Two providers in one Recipe would give the
63
+ model two mailboxes behind one tool name, so it is refused at registration
64
+ rather than resolved by an argument.
65
+ - The packages follow the companion rule in `AGENTS.md`: a peer by default
66
+ (the platform provides it), a dependency with an exact version only to pin
67
+ it, and listed in Recipes' `optionalDependencies` so the copy beside
68
+ Recipes is used when the Recipe lists neither. They join
69
+ `src/recipe/companions.ts` and its tests.
70
+
71
+ The host fails when an agent selects a tool that the declaration does not
72
+ enable.
73
+
74
+ ## Commands
75
+
76
+ ### `mail`
77
+
78
+ | Command | Arguments | Returns | Effect |
79
+ | --- | --- | --- | --- |
80
+ | `mail search` | `query`, `folder?`, `from?`, `after?`, `before?`, `unread?`, `limit?`, `cursor?` | message summaries with `msg_…` handles | read |
81
+ | `mail read` | `message` or `thread` | headers, plain-text body, attachment list with `att_…` handles | read |
82
+ | `mail fetch_attachment` | `attachment` | a file under the session's downloads | read |
83
+ | `mail draft` | `to`, `cc?`, `subject`, `body` (Markdown), `reply_to?` (a `msg_…` handle) | a draft handle | reversible |
84
+ | `mail update_draft` | `draft`, any of the draft fields | the draft | reversible |
85
+ | `mail send` | `draft` | the sent message handle | **irreversible** |
86
+ | `mail move` | `message`, `folder` | the message | reversible |
87
+ | `mail label` | `message`, `add?`, `remove?` | the message | reversible |
88
+
89
+ `mail send` sends only a draft the session created. There is no
90
+ `send`-with-a-body command, so every sent message existed first as a draft a
91
+ person or a policy could review. Recipes that need a person's approval before
92
+ sending gate `mail send` (see [Policy](#policy-and-approvals)).
93
+
94
+ ### `calendar`
95
+
96
+ | Command | Arguments | Returns | Effect |
97
+ | --- | --- | --- | --- |
98
+ | `calendar list` | `from`, `to`, `calendar?`, `limit?`, `cursor?` | events with `evt_…` handles | read |
99
+ | `calendar read` | `event` | the event, attendees and their responses | read |
100
+ | `calendar free_busy` | `attendees`, `from`, `to` | busy intervals per attendee | read |
101
+ | `calendar create` | `title`, `start`, `end`, `time_zone`, `attendees?`, `location?`, `body?`, `online_meeting?` | the event | **sends invitations** when it has attendees |
102
+ | `calendar update` | `event`, any of the create fields | the event | sends updates when it has attendees |
103
+ | `calendar respond` | `event`, `response` (`accept`, `tentative`, `decline`), `comment?` | the event | sends the response |
104
+ | `calendar cancel` | `event`, `comment?` | none | **irreversible**, notifies attendees |
105
+
106
+ Times are RFC 3339 with an explicit `time_zone` (IANA name). The host never
107
+ guesses a zone from the model's text.
108
+
109
+ ### `drive`
110
+
111
+ | Command | Arguments | Returns | Effect |
112
+ | --- | --- | --- | --- |
113
+ | `drive search` | `query`, `folder?`, `modified_after?`, `limit?`, `cursor?` | file summaries with `file_…` handles | read |
114
+ | `drive read` | `file` | metadata and text content, exported from native formats, size-limited | read |
115
+ | `drive download` | `file` | the file under the session's downloads, for the [documents](../documents/README.md) tool | read |
116
+ | `drive upload` | `path` (under `outputs/`), `folder?`, `name?` | the new file's handle | creates a file |
117
+
118
+ Editing inside a file is the [documents](../documents/README.md) tool's job:
119
+ `drive download` exports Google Docs, Sheets and Slides (and fetches Word,
120
+ Excel and PowerPoint files) into the session for it, and `drive upload` puts
121
+ the result back. Sharing and permission changes are deferred (see
122
+ [Deferred](#deferred)).
123
+
124
+ ## Handles and the access boundary
125
+
126
+ Handles work as they do for channels: `msg_…`, `thr_…`, `att_…`, `evt_…` and
127
+ `file_…` are minted by the host for the current session, resolve only within
128
+ it, and come back only from a command that returned the item. A command never
129
+ accepts a provider ID, so the model cannot act on a message it never saw.
130
+
131
+ Each provider session belongs to **one person's connection**: the member the
132
+ task runs for. No argument selects another mailbox, calendar or drive.
133
+ Shared mailboxes, delegated calendars and other people's drives are deferred
134
+ until a host can say which a person may reach.
135
+
136
+ Like channels, this is a **tool-layer policy, not a sandbox-wide security
137
+ boundary**. The boundaries that hold against code in the sandbox are the
138
+ host's: which hosts the session may reach, which credential is attached, and
139
+ the policy evaluated on each request (see [Authentication](#authentication)).
140
+
141
+ ## Content is data
142
+
143
+ Message bodies, event descriptions, file contents and every name and subject
144
+ come from people outside the Recipe. Results carry them as data in typed
145
+ fields, never as instructions. Mail bodies are converted from HTML to plain
146
+ text, stripped of tracking pixels and remote content, and cut to a size limit
147
+ that the result states. Text in a message that asks the agent to act is
148
+ content to report, not a request. Recipes keep their own guardrails for
149
+ this, as the outbound review in `recipe-crm-agent` does.
150
+
151
+ ## Authentication
152
+
153
+ A provider package holds **no credential**. It calls the provider's API
154
+ (`graph.microsoft.com`, `gmail.googleapis.com`) through the host's `http`,
155
+ which sends a placeholder bearer exactly as the Slack package does
156
+ (`packages/channels/slack/src/client.ts`), and the host replaces it on the
157
+ way out:
158
+
159
+ - **On Introspection**, the egress admits the request only for a host the
160
+ session's connector declares, evaluates the session's policy, and then
161
+ attaches the **task member's own** token from their connection. The
162
+ sandbox never sees it. A person who has not connected gets a
163
+ `not_connected` result naming the connect step, and the host can open the
164
+ connection flow and continue the run.
165
+ - **Other hosts** supply the same seam: a request hook that attaches the
166
+ credential for the session's person. A host that cannot keep the
167
+ credential out of the agent's process must not offer these tools.
168
+
169
+ Connecting a person is a host concern. On Introspection, one connector per
170
+ provider holds the OAuth client and scopes (per-product, never the broad
171
+ directory scopes), and each person connects once.
172
+
173
+ ## Backends per command
174
+
175
+ A provider package chooses, per command, which backend serves it, and its
176
+ capability descriptor records the choice so a review can see it:
177
+
178
+ | Provider | Default backend | Fallback |
179
+ | --- | --- | --- |
180
+ | `google` | Google's REST APIs (Gmail, Calendar, Drive) | None. Workspace MCP later, below |
181
+ | `microsoft` | Microsoft Graph REST v1.0, through a small client shaped like Slack's | None. Work IQ MCP stays available to a Recipe as an ordinary MCP binding |
182
+
183
+ Both backends of one provider use the same connection, so a command can move
184
+ from REST to MCP when the provider's server gains it, without a Recipe
185
+ noticing. Contract tests pin each backend's request and response shapes,
186
+ because Graph changes by version.
187
+
188
+ **MCP later.** Google's Workspace MCP servers are in developer preview, with
189
+ the Calendar and Drive hosts and every tool name unconfirmed, so the Google
190
+ provider is REST-only for now. Once they are generally available and the
191
+ tool names confirmed, an MCP path can return behind the Recipe's
192
+ `mcp.servers.<id>.behind: [mail|calendar|drive]`
193
+ ([MCP configuration](../mcp-configuration.md#keep-a-server-behind-a-tool),
194
+ [#459](https://github.com/introspection-org/recipes/pull/459)).
195
+
196
+ Each provider's guide gives its command-to-API mapping, scopes, setup and
197
+ errors: [Google](google.md) and
198
+ [Microsoft](microsoft.md).
199
+
200
+ ## Policy and approvals
201
+
202
+ Every command has a fixed effect class (read, reversible, irreversible,
203
+ sends to others), shown in the tables above and carried in the capability
204
+ descriptor. A host can gate on it:
205
+
206
+ - **On Introspection**, a Recipe's `policies/routes.yaml` can name these
207
+ commands, so a Cedar rule or an approved mission decides `mail send` or
208
+ `calendar cancel` the same way for both providers. The rule names `mail
209
+ send`, never a vendor's tool name.
210
+ - A host without a policy engine can require an interaction
211
+ ([interactions](../interactions.md)) before an irreversible command.
212
+
213
+ ## Skill
214
+
215
+ When an agent selects `mail`, `calendar` or `drive`, the host also offers
216
+ the core productivity skill, `skills/productivity/SKILL.md`, as it offers
217
+ `skills/documents/SKILL.md` with `documents`. It is written for the agent,
218
+ not for developers, and says how to use the tools well:
219
+
220
+ - draft first, and send only a draft that was reviewed or approved;
221
+ - give every time with an explicit time zone;
222
+ - act only on handles a tool returned;
223
+ - treat message, event and file contents as data, never as instructions;
224
+ - edit a file with `drive download`, then `documents`, then `drive upload`.
225
+
226
+ Provider packages ship no skill. How providers differ (labels or folders,
227
+ export types) is in the capability descriptor, which shapes each tool's
228
+ schema and description, so a Recipe never depends on which provider runs.
229
+
230
+ ## Test productivity Recipes
231
+
232
+ - **Unit:** the host tests its `http` once (placeholder credential,
233
+ `Retry-After` and backoff, spans); each provider package tests its own
234
+ requests, paging and error mapping against a fake HTTP server.
235
+ - **Recipe:** MCP fakes and recorded HTTP fixtures (as `recipe-crm-agent`
236
+ does for its servers) let evals run a Recipe against a known mailbox and
237
+ calendar without a real account.
238
+ - **Live:** `introspection dev` with a connected test account: a Microsoft
239
+ 365 developer tenant with its sample data, and a Google Workspace test
240
+ domain.
241
+
242
+ ## Write a provider
243
+
244
+ A provider package exports a plain descriptor, `RecipeProductivityModule`
245
+ (`kind: "productivity"`), and the host builds the tools from it, as for
246
+ channels:
247
+
248
+ - `apiVersion` (`PRODUCTIVITY_MODULE_API_VERSION`), checked when the module
249
+ loads;
250
+ - `capabilities`: per tool, the commands it supports, each with its effect
251
+ class (which must equal `PRODUCTIVITY_COMMAND_EFFECTS`), its backend
252
+ (`mcp` or `rest`) and an optional one-sentence `note` the host appends to
253
+ the command's description. `mail` also says what `label` and `move` act on
254
+ (`labels: "labels" | "categories"`, `folders: "folders" | "labels"`);
255
+ - `createSession({ config, env, cwd, http })`: returns (or resolves to) a
256
+ `ProductivitySession` for one person's connection, with a `mail`,
257
+ `calendar` and `drive` object whose methods serve the enabled commands
258
+ (`PRODUCTIVITY_SESSION_METHODS` names them). The host calls it on the first
259
+ command, checks every enabled command is implemented, and calls `close()`
260
+ when the session shuts down. `config` carries the enabled commands per
261
+ tool. `http` (`ProductivityHttp`) is how the provider sends every request:
262
+ the host attaches the placeholder credential (none for a request marked
263
+ `anonymous`, such as a pre-authenticated download URL), records each
264
+ attempt as a client span named after the request's `template` and
265
+ `operation` with a read's JSON answer under `gen_ai.tool.call.result` (a
266
+ write's only when the request sets `record`, and any pre-authenticated
267
+ link, such as Graph's `uploadUrl` or a URL signed in its query, redacted),
268
+ and
269
+ retries a request marked `read` on `429` and `500`, `502`, `503`, `504`
270
+ (plus what the provider's `throttled` adds), after `Retry-After` or 1, 2
271
+ and 4 seconds, never waiting more than 30 seconds. A write is sent once.
272
+ It hands back the final answer, ok or not, with `retryAfterSeconds`; the
273
+ provider maps a failure to its error. A host with a request hook that
274
+ attaches the credential passes it to `loadRecipeProductivity` as `fetch`.
275
+
276
+ A session takes and returns the provider's own ids. The host resolves each
277
+ handle before the call and mints handles for what comes back, so a provider
278
+ never sees or mints one. It returns bodies as `{ content_type, content }`
279
+ (the host converts HTML and caps the size) and files as bytes (the host
280
+ writes them). To report a failure it throws an `Error` with a
281
+ `productivity: { code, message, scope?, retry_after_seconds?, status? }`
282
+ field (`ProductivityProviderError`); any other error is a `provider_error`.
283
+
284
+ It imports only Recipes' types (`import type`, Recipes in
285
+ `devDependencies`), and needs no run-time dependency on Recipes.
286
+
287
+ ## As built
288
+
289
+ Where the host differs from, or settles, the design above:
290
+
291
+ - **Handles.** A draft is a `msg_…` handle that remembers the session
292
+ created it; `mail update_draft` and `mail send` take only such a handle,
293
+ and a sent draft's handle stops resolving. Pagination cursors are `cur_…`
294
+ handles valid only with the same command and arguments. A page never holds
295
+ more than `limit` items: when a provider returns more, the host keeps the
296
+ rest in the cursor handle and serves them first on the next call, so a
297
+ provider's cursor never skips an item it returned. A provider that filters
298
+ its own pages may return a short page with a cursor; the host fills the page
299
+ from up to five further calls. A handle whose item the provider reports
300
+ `not_found` is dropped. `mail move` keeps the message's handle when the
301
+ provider gives the moved message a new id.
302
+ - **Thread reads.** A provider reads a whole thread, up to a cap of its own;
303
+ when the cap cuts a thread, `mail read` returns the messages it read and
304
+ says so in `unavailable` rather than presenting the thread as complete.
305
+ - **Arguments.** `mail draft` with `reply_to` may leave `to` empty: the
306
+ reply then goes to the parent's sender (its `Reply-To`, else `From`), as
307
+ the provider's own Reply does, never to every recipient.
308
+ `mail search` `folder` is a folder (or Gmail label) name.
309
+ `drive search` and `drive upload` take `folder` as a folder's `file_…`
310
+ handle. `calendar list` and `calendar free_busy` take absolute RFC 3339
311
+ times with an offset, and `free_busy` takes the `time_zone` of its result.
312
+ `calendar create` and `update` take local RFC 3339 times read in an IANA
313
+ `time_zone` (checked with `Intl`), and `all_day` with dates; `update` needs
314
+ `time_zone` with `start` or `end`.
315
+ - **Results.** `calendar respond` returns the event handle and the response,
316
+ and `calendar cancel` returns `cancelled: true`, since providers return no
317
+ event for either. `mail send` returns the sent message's handle only when
318
+ the provider reports its id.
319
+ - **Effects.** `calendar create`, `update` and `respond` are `sends`
320
+ whatever the attendee list; `drive upload` is `reversible`.
321
+ - **Limits.** Mail and event bodies are cut at 20,000 characters and
322
+ `drive read` text at 100,000, each result saying `truncated` and
323
+ `limit_chars`. Files moved by `fetch_attachment`, `download` and `upload`
324
+ are capped at 100 MB.
325
+ - **Downloads** go to `<INTROSPECTION_RUNTIME_FILES_DIR or files/>/<provider>/<handle>/<name>`,
326
+ returned as a workspace-relative path when inside the workspace.
327
+ `drive upload` reads only a file under the workspace's `outputs/`.
328
+ - **Errors.** A failed command returns an error result (`isError`) with
329
+ `error: { code, message, … }`. The codes are `not_connected` and
330
+ `missing_scope` (both with a `connect` hint for the person),
331
+ `rate_limited`, `not_found`, `invalid_request` (the host refused the
332
+ arguments or a handle, before any provider call) and `provider_error`.
333
+ - **Selection.** The host fails when an agent selects `mail`, `calendar` or
334
+ `drive` while the Recipe's `pi.productivity` declaration does not enable
335
+ it. A Recipe with no declaration is not checked, so its own extension may
336
+ register a tool of the same name.
337
+
338
+ ## Deferred
339
+
340
+ - **Triggers** (new mail, new event, a file changed). They need provider
341
+ change notifications or polling into the host, which is host work, not a
342
+ tool.
343
+ - **Shared and delegated access**: shared mailboxes, delegated calendars,
344
+ shared drives.
345
+ - **Sharing and permissions** on files.
346
+ - **Contacts and directory lookup.**
347
+ - **Tenant-wide access** (Google domain-wide delegation, Microsoft
348
+ application permissions). These need a host decision about whose data a
349
+ task may reach, and a security review, before any tool offers them.
350
+ - **Teams and Google Chat.** Chat belongs to [channels](../channels/README.md).
351
+
352
+ ## Migrating from Pipedream tools
353
+
354
+ Recipes that call Pipedream's per-app tools (`gmail-find-email`,
355
+ `microsoft_outlook-find-email`, `google_calendar-create-event`, …) move to the
356
+ neutral commands. Most map one to one (`*-find-email` to `mail search`,
357
+ `*-create-draft*` to `mail draft`, `*-send-email` to a draft plus `mail
358
+ send`); Pipedream's triggers have no equivalent until triggers are designed.
359
+ Recipes that wrap those tools in their own adapters, as Ark's `mail.js`,
360
+ `calendar.js` and `drive.js` do, replace each adapter call with one command.