@vellumai/assistant 0.4.45 → 0.4.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.
Files changed (236) hide show
  1. package/ARCHITECTURE.md +6 -6
  2. package/docs/architecture/memory.md +1 -1
  3. package/docs/architecture/scheduling.md +2 -3
  4. package/docs/architecture/security.md +5 -5
  5. package/docs/trusted-contact-access.md +5 -6
  6. package/package.json +4 -1
  7. package/src/__tests__/avatar-e2e.test.ts +18 -219
  8. package/src/__tests__/avatar-generator.test.ts +5 -57
  9. package/src/__tests__/browser-fill-credential.test.ts +5 -2
  10. package/src/__tests__/bundled-skill-retrieval-guard.test.ts +2 -1
  11. package/src/__tests__/channel-readiness-routes.test.ts +20 -19
  12. package/src/__tests__/cli.test.ts +23 -0
  13. package/src/__tests__/credential-broker-browser-fill.test.ts +23 -22
  14. package/src/__tests__/credential-broker-server-use.test.ts +22 -21
  15. package/src/__tests__/credential-broker.test.ts +2 -1
  16. package/src/__tests__/credential-metadata-store.test.ts +240 -18
  17. package/src/__tests__/credential-resolve.test.ts +5 -4
  18. package/src/__tests__/credential-security-e2e.test.ts +8 -8
  19. package/src/__tests__/credential-security-invariants.test.ts +104 -7
  20. package/src/__tests__/credential-vault-unit.test.ts +22 -20
  21. package/src/__tests__/credential-vault.test.ts +284 -12
  22. package/src/__tests__/credentials-cli.test.ts +11 -6
  23. package/src/__tests__/gateway-only-enforcement.test.ts +4 -2
  24. package/src/__tests__/gemini-image-service.test.ts +75 -45
  25. package/src/__tests__/gemini-provider.test.ts +9 -6
  26. package/src/__tests__/guardian-action-conversation-turn.test.ts +1 -33
  27. package/src/__tests__/guardian-action-copy-generator.test.ts +0 -20
  28. package/src/__tests__/guardian-action-followup-executor.test.ts +1 -28
  29. package/src/__tests__/guardian-action-followup-store.test.ts +1 -1
  30. package/src/__tests__/guardian-grant-minting.test.ts +35 -0
  31. package/src/__tests__/integration-status.test.ts +53 -21
  32. package/src/__tests__/managed-proxy-context.test.ts +5 -3
  33. package/src/__tests__/media-generate-image.test.ts +63 -2
  34. package/src/__tests__/media-reuse-story.e2e.test.ts +7 -3
  35. package/src/__tests__/messaging-send-tool.test.ts +4 -6
  36. package/src/__tests__/provider-fail-open-selection.test.ts +3 -1
  37. package/src/__tests__/provider-managed-proxy-integration.test.ts +70 -6
  38. package/src/__tests__/schedule-store.test.ts +1 -1
  39. package/src/__tests__/schema-transforms.test.ts +226 -0
  40. package/src/__tests__/script-proxy-injection-runtime.test.ts +23 -13
  41. package/src/__tests__/script-proxy-policy-runtime.test.ts +1 -1
  42. package/src/__tests__/script-proxy-session-manager.test.ts +1 -1
  43. package/src/__tests__/secret-onetime-send.test.ts +5 -3
  44. package/src/__tests__/session-messaging-secret-redirect.test.ts +5 -4
  45. package/src/__tests__/skills-uninstall.test.ts +2 -2
  46. package/src/__tests__/skills.test.ts +0 -9
  47. package/src/__tests__/slack-channel-config.test.ts +9 -8
  48. package/src/__tests__/slack-share-routes.test.ts +11 -6
  49. package/src/__tests__/telegram-bot-username-resolution.test.ts +3 -0
  50. package/src/__tests__/twilio-config.test.ts +2 -1
  51. package/src/__tests__/twilio-provider.test.ts +4 -2
  52. package/src/__tests__/twilio-routes.test.ts +5 -4
  53. package/src/__tests__/verification-control-plane-policy.test.ts +1 -1
  54. package/src/approvals/AGENTS.md +1 -1
  55. package/src/calls/call-domain.ts +7 -4
  56. package/src/calls/twilio-config.ts +2 -1
  57. package/src/calls/twilio-provider.ts +2 -1
  58. package/src/calls/twilio-rest.ts +2 -2
  59. package/src/cli/commands/browser-relay.ts +40 -15
  60. package/src/cli/commands/credentials.ts +9 -8
  61. package/src/cli/commands/oauth.ts +1 -1
  62. package/src/cli.ts +3 -2
  63. package/src/config/bundled-skills/claude-code/TOOLS.json +0 -4
  64. package/src/config/bundled-skills/contacts/tools/google-contacts.ts +29 -32
  65. package/src/config/bundled-skills/gmail/SKILL.md +4 -4
  66. package/src/config/bundled-skills/gmail/tools/gmail-archive.ts +54 -61
  67. package/src/config/bundled-skills/gmail/tools/gmail-attachments.ts +25 -28
  68. package/src/config/bundled-skills/gmail/tools/gmail-draft.ts +14 -17
  69. package/src/config/bundled-skills/gmail/tools/gmail-filters.ts +39 -44
  70. package/src/config/bundled-skills/gmail/tools/gmail-follow-up.ts +61 -58
  71. package/src/config/bundled-skills/gmail/tools/gmail-forward.ts +50 -49
  72. package/src/config/bundled-skills/gmail/tools/gmail-label.ts +11 -13
  73. package/src/config/bundled-skills/gmail/tools/gmail-outreach-scan.ts +148 -146
  74. package/src/config/bundled-skills/gmail/tools/gmail-send-draft.ts +4 -7
  75. package/src/config/bundled-skills/gmail/tools/gmail-sender-digest.ts +175 -173
  76. package/src/config/bundled-skills/gmail/tools/gmail-trash.ts +4 -7
  77. package/src/config/bundled-skills/gmail/tools/gmail-unsubscribe.ts +71 -76
  78. package/src/config/bundled-skills/gmail/tools/gmail-vacation.ts +32 -38
  79. package/src/config/bundled-skills/google-calendar/SKILL.md +2 -2
  80. package/src/config/bundled-skills/google-calendar/calendar-client.ts +70 -29
  81. package/src/config/bundled-skills/google-calendar/tools/calendar-check-availability.ts +9 -10
  82. package/src/config/bundled-skills/google-calendar/tools/calendar-create-event.ts +5 -6
  83. package/src/config/bundled-skills/google-calendar/tools/calendar-get-event.ts +4 -5
  84. package/src/config/bundled-skills/google-calendar/tools/calendar-list-events.ts +14 -15
  85. package/src/config/bundled-skills/google-calendar/tools/calendar-rsvp.ts +37 -37
  86. package/src/config/bundled-skills/google-calendar/tools/shared.ts +4 -9
  87. package/src/config/bundled-skills/image-studio/tools/media-generate-image.ts +24 -3
  88. package/src/config/bundled-skills/messaging/SKILL.md +6 -6
  89. package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +62 -63
  90. package/src/config/bundled-skills/messaging/tools/messaging-archive-by-sender.ts +15 -16
  91. package/src/config/bundled-skills/messaging/tools/messaging-auth-test.ts +4 -5
  92. package/src/config/bundled-skills/messaging/tools/messaging-list-conversations.ts +6 -7
  93. package/src/config/bundled-skills/messaging/tools/messaging-mark-read.ts +4 -5
  94. package/src/config/bundled-skills/messaging/tools/messaging-read.ts +14 -15
  95. package/src/config/bundled-skills/messaging/tools/messaging-search.ts +4 -5
  96. package/src/config/bundled-skills/messaging/tools/messaging-send.ts +128 -128
  97. package/src/config/bundled-skills/messaging/tools/messaging-sender-digest.ts +33 -34
  98. package/src/config/bundled-skills/messaging/tools/shared.ts +11 -11
  99. package/src/config/bundled-skills/notifications/SKILL.md +1 -1
  100. package/src/config/bundled-skills/phone-calls/SKILL.md +5 -5
  101. package/src/config/bundled-skills/schedule/SKILL.md +1 -1
  102. package/src/config/bundled-skills/skill-management/SKILL.md +1 -1
  103. package/src/config/bundled-skills/slack/tools/shared.ts +4 -10
  104. package/src/config/bundled-skills/slack/tools/slack-add-reaction.ts +4 -5
  105. package/src/config/bundled-skills/slack/tools/slack-channel-details.ts +15 -16
  106. package/src/config/bundled-skills/slack/tools/slack-delete-message.ts +4 -5
  107. package/src/config/bundled-skills/slack/tools/slack-edit-message.ts +4 -5
  108. package/src/config/bundled-skills/slack/tools/slack-leave-channel.ts +4 -5
  109. package/src/config/bundled-skills/slack/tools/slack-scan-digest.ts +95 -92
  110. package/src/config/loader.ts +6 -0
  111. package/src/daemon/computer-use-session.ts +7 -1
  112. package/src/daemon/guardian-action-generators.ts +4 -5
  113. package/src/daemon/handlers/config-slack-channel.ts +37 -20
  114. package/src/daemon/handlers/config-telegram.ts +33 -20
  115. package/src/daemon/lifecycle.ts +9 -1
  116. package/src/daemon/message-types/integrations.ts +1 -0
  117. package/src/daemon/ride-shotgun-handler.ts +3 -1
  118. package/src/daemon/session-messaging.ts +3 -1
  119. package/src/daemon/session-tool-setup.ts +18 -2
  120. package/src/daemon/session.ts +1 -1
  121. package/src/email/providers/index.ts +2 -1
  122. package/src/instrument.ts +15 -1
  123. package/src/media/app-icon-generator.ts +30 -4
  124. package/src/media/avatar-router.ts +28 -62
  125. package/src/media/gemini-image-service.ts +28 -2
  126. package/src/memory/canonical-guardian-store.ts +1 -1
  127. package/src/memory/guardian-action-store.ts +1 -1
  128. package/src/memory/schema/guardian.ts +1 -1
  129. package/src/messaging/provider.ts +16 -10
  130. package/src/messaging/providers/gmail/adapter.ts +40 -23
  131. package/src/messaging/providers/gmail/client.ts +203 -122
  132. package/src/messaging/providers/gmail/people-client.ts +26 -18
  133. package/src/messaging/providers/slack/adapter.ts +29 -19
  134. package/src/messaging/providers/slack/client.ts +265 -78
  135. package/src/messaging/providers/telegram-bot/adapter.ts +5 -4
  136. package/src/messaging/providers/whatsapp/adapter.ts +6 -3
  137. package/src/messaging/registry.ts +2 -1
  138. package/src/oauth/byo-connection.test.ts +436 -0
  139. package/src/oauth/byo-connection.ts +112 -0
  140. package/src/oauth/connect-orchestrator.ts +27 -0
  141. package/src/oauth/connection-resolver.ts +34 -0
  142. package/src/oauth/connection.ts +38 -0
  143. package/src/oauth/platform-connection.test.ts +163 -0
  144. package/src/oauth/platform-connection.ts +110 -0
  145. package/src/oauth/provider-base-urls.ts +21 -0
  146. package/src/oauth/provider-profiles.ts +1 -1
  147. package/src/oauth/token-persistence.ts +20 -20
  148. package/src/permissions/checker.ts +6 -1
  149. package/src/prompts/system-prompt.ts +52 -15
  150. package/src/prompts/templates/BOOTSTRAP.md +1 -1
  151. package/src/providers/gemini/client.ts +15 -6
  152. package/src/providers/managed-proxy/constants.ts +2 -2
  153. package/src/providers/managed-proxy/context.ts +5 -1
  154. package/src/providers/ratelimit.ts +17 -0
  155. package/src/providers/registry.ts +2 -2
  156. package/src/runtime/AGENTS.md +18 -1
  157. package/src/runtime/auth/route-policy.ts +1 -0
  158. package/src/runtime/channel-invite-transports/telegram.ts +2 -1
  159. package/src/runtime/channel-readiness-service.ts +168 -195
  160. package/src/runtime/channel-readiness-types.ts +4 -0
  161. package/src/runtime/guardian-action-conversation-turn.ts +1 -3
  162. package/src/runtime/guardian-action-followup-executor.ts +1 -2
  163. package/src/runtime/guardian-action-message-composer.ts +3 -23
  164. package/src/runtime/http-server.ts +9 -4
  165. package/src/runtime/http-types.ts +0 -1
  166. package/src/runtime/middleware/rate-limiter.ts +74 -20
  167. package/src/runtime/middleware/twilio-validation.ts +1 -3
  168. package/src/runtime/routes/channel-readiness-routes.ts +2 -0
  169. package/src/runtime/routes/diagnostics-routes.ts +11 -9
  170. package/src/runtime/routes/guardian-approval-interception.ts +20 -5
  171. package/src/runtime/routes/inbound-stages/acl-enforcement.ts +71 -25
  172. package/src/runtime/routes/inbound-stages/guardian-reply-intercept.ts +12 -5
  173. package/src/runtime/routes/integrations/slack/share.ts +3 -2
  174. package/src/runtime/routes/integrations/twilio.ts +6 -5
  175. package/src/runtime/routes/secret-routes.ts +3 -2
  176. package/src/runtime/routes/settings-routes.ts +75 -17
  177. package/src/runtime/telegram-streaming-delivery.test.ts +132 -0
  178. package/src/runtime/telegram-streaming-delivery.ts +11 -1
  179. package/src/schedule/integration-status.ts +5 -4
  180. package/src/security/credential-key.ts +170 -0
  181. package/src/security/token-manager.ts +36 -7
  182. package/src/tools/apps/definitions.ts +0 -5
  183. package/src/tools/assets/materialize.ts +0 -5
  184. package/src/tools/assets/search.ts +0 -5
  185. package/src/tools/browser/headless-browser.ts +1 -67
  186. package/src/tools/claude-code/claude-code.ts +0 -5
  187. package/src/tools/computer-use/request-computer-control.ts +0 -5
  188. package/src/tools/credentials/broker.ts +6 -4
  189. package/src/tools/credentials/metadata-store.ts +72 -20
  190. package/src/tools/credentials/resolve.ts +2 -1
  191. package/src/tools/credentials/vault.ts +77 -16
  192. package/src/tools/filesystem/edit.ts +1 -6
  193. package/src/tools/filesystem/read.ts +0 -5
  194. package/src/tools/filesystem/write.ts +1 -6
  195. package/src/tools/host-filesystem/edit.ts +1 -6
  196. package/src/tools/host-filesystem/read.ts +1 -6
  197. package/src/tools/host-filesystem/write.ts +1 -6
  198. package/src/tools/mcp/mcp-tool-factory.ts +18 -1
  199. package/src/tools/memory/definitions.ts +0 -5
  200. package/src/tools/network/web-fetch.ts +0 -5
  201. package/src/tools/network/web-search.ts +0 -5
  202. package/src/tools/schema-transforms.ts +99 -0
  203. package/src/tools/skills/load.ts +0 -5
  204. package/src/tools/swarm/delegate.ts +0 -5
  205. package/src/tools/system/avatar-generator.ts +3 -44
  206. package/src/tools/ui-surface/definitions.ts +0 -15
  207. package/src/tools/watch/screen-watch.ts +0 -5
  208. package/src/version.ts +10 -0
  209. package/src/watcher/providers/github.ts +51 -52
  210. package/src/watcher/providers/gmail.ts +88 -80
  211. package/src/watcher/providers/google-calendar.ts +93 -86
  212. package/src/watcher/providers/linear.ts +87 -93
  213. package/src/__tests__/avatar-router.test.ts +0 -149
  214. package/src/__tests__/managed-avatar-client.test.ts +0 -337
  215. package/src/config/bundled-skills/doordash/SKILL.md +0 -170
  216. package/src/config/bundled-skills/doordash/__tests__/doordash-client.test.ts +0 -205
  217. package/src/config/bundled-skills/doordash/__tests__/doordash-session.test.ts +0 -74
  218. package/src/config/bundled-skills/doordash/doordash-cli.ts +0 -1081
  219. package/src/config/bundled-skills/doordash/doordash-entry.ts +0 -22
  220. package/src/config/bundled-skills/doordash/lib/cart-queries.ts +0 -787
  221. package/src/config/bundled-skills/doordash/lib/client.ts +0 -1069
  222. package/src/config/bundled-skills/doordash/lib/order-queries.ts +0 -85
  223. package/src/config/bundled-skills/doordash/lib/queries.ts +0 -28
  224. package/src/config/bundled-skills/doordash/lib/query-extractor.ts +0 -94
  225. package/src/config/bundled-skills/doordash/lib/search-queries.ts +0 -203
  226. package/src/config/bundled-skills/doordash/lib/session.ts +0 -96
  227. package/src/config/bundled-skills/doordash/lib/shared/errors.ts +0 -61
  228. package/src/config/bundled-skills/doordash/lib/shared/network-recorder.ts +0 -380
  229. package/src/config/bundled-skills/doordash/lib/shared/platform.ts +0 -55
  230. package/src/config/bundled-skills/doordash/lib/shared/recording-store.ts +0 -43
  231. package/src/config/bundled-skills/doordash/lib/shared/recording-types.ts +0 -49
  232. package/src/config/bundled-skills/doordash/lib/shared/truncate.ts +0 -6
  233. package/src/config/bundled-skills/doordash/lib/store-queries.ts +0 -246
  234. package/src/config/bundled-skills/doordash/lib/types.ts +0 -367
  235. package/src/media/avatar-types.ts +0 -53
  236. package/src/media/managed-avatar-client.ts +0 -225
@@ -1,337 +0,0 @@
1
- import { beforeEach, describe, expect, mock, test } from "bun:test";
2
-
3
- import { createHash } from "crypto";
4
-
5
- // ---------------------------------------------------------------------------
6
- // Mock dependencies — must be before importing the module under test
7
- // ---------------------------------------------------------------------------
8
-
9
- let mockApiKey: string | undefined = "test-api-key-123";
10
- let mockBaseUrl = "https://platform.vellum.ai";
11
- let mockPlatformEnvUrl = "https://env.vellum.ai";
12
-
13
- mock.module("../security/secure-keys.js", () => ({
14
- getSecureKey: (account: string) => {
15
- if (account === "credential:vellum:assistant_api_key") return mockApiKey;
16
- return undefined;
17
- },
18
- }));
19
-
20
- mock.module("../config/loader.js", () => ({
21
- getConfig: () => ({
22
- platform: { baseUrl: mockBaseUrl },
23
- }),
24
- }));
25
-
26
- mock.module("../config/env.js", () => ({
27
- getPlatformBaseUrl: () => mockPlatformEnvUrl,
28
- }));
29
-
30
- mock.module("../util/logger.js", () => ({
31
- getLogger: () => ({
32
- debug: () => {},
33
- info: () => {},
34
- warn: () => {},
35
- error: () => {},
36
- }),
37
- }));
38
-
39
- // Mock global fetch
40
- let lastFetchArgs: [string, RequestInit] | null = null;
41
- let fetchResponse: {
42
- ok: boolean;
43
- status: number;
44
- json: () => Promise<unknown>;
45
- text: () => Promise<string>;
46
- } = {
47
- ok: true,
48
- status: 200,
49
- json: async () => ({}),
50
- text: async () => "",
51
- };
52
-
53
- globalThis.fetch = (async (url: string, init: RequestInit) => {
54
- lastFetchArgs = [url, init];
55
- return fetchResponse;
56
- }) as typeof globalThis.fetch;
57
-
58
- // Import after mocking
59
- import {
60
- AVATAR_MAX_DECODED_BYTES,
61
- AVATAR_PROMPT_MAX_LENGTH,
62
- ManagedAvatarError,
63
- VERTEX_IMAGE_DEFAULT_MODEL,
64
- } from "../media/avatar-types.js";
65
- import {
66
- generateManagedAvatar,
67
- isManagedAvailable,
68
- } from "../media/managed-avatar-client.js";
69
-
70
- // ---------------------------------------------------------------------------
71
- // Helpers
72
- // ---------------------------------------------------------------------------
73
-
74
- const SMALL_PNG_BASE64 = "iVBORw0KGgo=";
75
-
76
- function successResponse() {
77
- return {
78
- predictions: [
79
- {
80
- bytesBase64Encoded: SMALL_PNG_BASE64,
81
- mimeType: "image/png",
82
- },
83
- ],
84
- };
85
- }
86
-
87
- // ---------------------------------------------------------------------------
88
- // Tests
89
- // ---------------------------------------------------------------------------
90
-
91
- beforeEach(() => {
92
- mockApiKey = "test-api-key-123";
93
- mockBaseUrl = "https://platform.vellum.ai";
94
- mockPlatformEnvUrl = "https://env.vellum.ai";
95
- lastFetchArgs = null;
96
- fetchResponse = {
97
- ok: true,
98
- status: 200,
99
- json: async () => successResponse(),
100
- text: async () => JSON.stringify(successResponse()),
101
- };
102
- });
103
-
104
- describe("generateManagedAvatar", () => {
105
- test("successful generation returns parsed response", async () => {
106
- const result = await generateManagedAvatar("a friendly robot avatar");
107
-
108
- expect(result.image.mime_type).toBe("image/png");
109
- expect(result.image.data_base64).toBe(SMALL_PNG_BASE64);
110
- // bytes is computed from base64 length, not from the server response
111
- const padding = SMALL_PNG_BASE64.endsWith("==")
112
- ? 2
113
- : SMALL_PNG_BASE64.endsWith("=")
114
- ? 1
115
- : 0;
116
- const expectedBytes =
117
- Math.ceil((SMALL_PNG_BASE64.length * 3) / 4) - padding;
118
- expect(result.image.bytes).toBe(expectedBytes);
119
- const expectedSha256 = createHash("sha256")
120
- .update(Buffer.from(SMALL_PNG_BASE64, "base64"))
121
- .digest("hex");
122
- expect(result.image.sha256).toBe(expectedSha256);
123
- expect(result.correlation_id).toBeDefined();
124
- });
125
-
126
- test("fetch URL matches runtime proxy Vertex endpoint with default model", async () => {
127
- await generateManagedAvatar("test prompt");
128
-
129
- expect(lastFetchArgs).not.toBeNull();
130
- const url = lastFetchArgs![0];
131
- expect(url).toBe(
132
- `https://platform.vellum.ai/v1/runtime-proxy/vertex/v1/models/${VERTEX_IMAGE_DEFAULT_MODEL}:predict`,
133
- );
134
- });
135
-
136
- test("custom model is used in the URL path", async () => {
137
- const customModel = "imagen-3.0-fast-generate-001";
138
- await generateManagedAvatar("test prompt", { model: customModel });
139
-
140
- expect(lastFetchArgs).not.toBeNull();
141
- const url = lastFetchArgs![0];
142
- expect(url).toBe(
143
- `https://platform.vellum.ai/v1/runtime-proxy/vertex/v1/models/${customModel}:predict`,
144
- );
145
- });
146
-
147
- test("request body uses Vertex Imagen format", async () => {
148
- await generateManagedAvatar("a cool robot");
149
-
150
- expect(lastFetchArgs).not.toBeNull();
151
- const body = JSON.parse(lastFetchArgs![1].body as string);
152
- expect(body).toEqual({
153
- instances: [{ prompt: "a cool robot" }],
154
- parameters: {
155
- sampleCount: 1,
156
- aspectRatio: "1:1",
157
- outputOptions: { mimeType: "image/png" },
158
- },
159
- });
160
- });
161
-
162
- test("prompt exceeding max length throws ManagedAvatarError with code validation_error", async () => {
163
- const longPrompt = "x".repeat(AVATAR_PROMPT_MAX_LENGTH + 1);
164
-
165
- try {
166
- await generateManagedAvatar(longPrompt);
167
- expect(true).toBe(false); // should not reach here
168
- } catch (err) {
169
- expect(err).toBeInstanceOf(ManagedAvatarError);
170
- const avatarErr = err as ManagedAvatarError;
171
- expect(avatarErr.code).toBe("validation_error");
172
- expect(avatarErr.subcode).toBe("prompt_too_long");
173
- }
174
- });
175
-
176
- test("HTTP 429 response throws ManagedAvatarError with retryable true", async () => {
177
- fetchResponse = {
178
- ok: false,
179
- status: 429,
180
- json: async () => ({}),
181
- text: async () => "Rate limit exceeded",
182
- };
183
-
184
- try {
185
- await generateManagedAvatar("test prompt");
186
- expect(true).toBe(false);
187
- } catch (err) {
188
- expect(err).toBeInstanceOf(ManagedAvatarError);
189
- const avatarErr = err as ManagedAvatarError;
190
- expect(avatarErr.retryable).toBe(true);
191
- expect(avatarErr.statusCode).toBe(429);
192
- expect(avatarErr.code).toBe("upstream_error");
193
- expect(avatarErr.subcode).toBe("http_error");
194
- }
195
- });
196
-
197
- test("HTTP 500 response throws retryable ManagedAvatarError", async () => {
198
- fetchResponse = {
199
- ok: false,
200
- status: 500,
201
- json: async () => ({}),
202
- text: async () => "Internal server error",
203
- };
204
-
205
- try {
206
- await generateManagedAvatar("test prompt");
207
- expect(true).toBe(false);
208
- } catch (err) {
209
- expect(err).toBeInstanceOf(ManagedAvatarError);
210
- const avatarErr = err as ManagedAvatarError;
211
- expect(avatarErr.code).toBe("upstream_error");
212
- expect(avatarErr.subcode).toBe("http_error");
213
- expect(avatarErr.statusCode).toBe(500);
214
- expect(avatarErr.retryable).toBe(true);
215
- }
216
- });
217
-
218
- test("HTTP 400 response throws non-retryable ManagedAvatarError", async () => {
219
- fetchResponse = {
220
- ok: false,
221
- status: 400,
222
- json: async () => ({}),
223
- text: async () => "Model not allowed on this platform",
224
- };
225
-
226
- try {
227
- await generateManagedAvatar("test prompt");
228
- expect(true).toBe(false);
229
- } catch (err) {
230
- expect(err).toBeInstanceOf(ManagedAvatarError);
231
- const avatarErr = err as ManagedAvatarError;
232
- expect(avatarErr.code).toBe("upstream_error");
233
- expect(avatarErr.subcode).toBe("http_error");
234
- expect(avatarErr.statusCode).toBe(400);
235
- expect(avatarErr.retryable).toBe(false);
236
- }
237
- });
238
-
239
- test("response with disallowed MIME type throws validation error", async () => {
240
- fetchResponse = {
241
- ok: true,
242
- status: 200,
243
- json: async () => ({
244
- predictions: [
245
- {
246
- bytesBase64Encoded: SMALL_PNG_BASE64,
247
- mimeType: "image/gif",
248
- },
249
- ],
250
- }),
251
- text: async () => "",
252
- };
253
-
254
- try {
255
- await generateManagedAvatar("test prompt");
256
- expect(true).toBe(false);
257
- } catch (err) {
258
- expect(err).toBeInstanceOf(ManagedAvatarError);
259
- const avatarErr = err as ManagedAvatarError;
260
- expect(avatarErr.code).toBe("validation_error");
261
- expect(avatarErr.subcode).toBe("disallowed_mime_type");
262
- }
263
- });
264
-
265
- test("response with oversized image throws validation error", async () => {
266
- const oversizedBase64 = "A".repeat(
267
- Math.ceil(((AVATAR_MAX_DECODED_BYTES + 100) * 4) / 3),
268
- );
269
- fetchResponse = {
270
- ok: true,
271
- status: 200,
272
- json: async () => ({
273
- predictions: [
274
- {
275
- bytesBase64Encoded: oversizedBase64,
276
- mimeType: "image/png",
277
- },
278
- ],
279
- }),
280
- text: async () => "",
281
- };
282
-
283
- try {
284
- await generateManagedAvatar("test prompt");
285
- expect(true).toBe(false);
286
- } catch (err) {
287
- expect(err).toBeInstanceOf(ManagedAvatarError);
288
- const avatarErr = err as ManagedAvatarError;
289
- expect(avatarErr.code).toBe("validation_error");
290
- expect(avatarErr.subcode).toBe("oversized_image");
291
- }
292
- });
293
-
294
- test("Authorization header uses Api-Key prefix", async () => {
295
- await generateManagedAvatar("test prompt");
296
-
297
- expect(lastFetchArgs).not.toBeNull();
298
- const headers = lastFetchArgs![1].headers as Record<string, string>;
299
- expect(headers.Authorization).toBe("Api-Key test-api-key-123");
300
- expect(headers.Authorization).not.toContain("Bearer");
301
- });
302
-
303
- test("Idempotency-Key header is present on every request", async () => {
304
- await generateManagedAvatar("test prompt");
305
-
306
- expect(lastFetchArgs).not.toBeNull();
307
- const headers = lastFetchArgs![1].headers as Record<string, string>;
308
- expect(headers["Idempotency-Key"]).toBeDefined();
309
- expect(headers["Idempotency-Key"].length).toBeGreaterThan(0);
310
- });
311
-
312
- test("caller-provided idempotencyKey is used in the request header", async () => {
313
- const customKey = "my-custom-idempotency-key-123";
314
- await generateManagedAvatar("test prompt", { idempotencyKey: customKey });
315
-
316
- expect(lastFetchArgs).not.toBeNull();
317
- const headers = lastFetchArgs![1].headers as Record<string, string>;
318
- expect(headers["Idempotency-Key"]).toBe(customKey);
319
- });
320
- });
321
-
322
- describe("isManagedAvailable", () => {
323
- test("returns false when API key is missing", () => {
324
- mockApiKey = undefined;
325
- expect(isManagedAvailable()).toBe(false);
326
- });
327
-
328
- test("returns false when base URL is missing", () => {
329
- mockBaseUrl = "";
330
- mockPlatformEnvUrl = "";
331
- expect(isManagedAvailable()).toBe(false);
332
- });
333
-
334
- test("returns true when both API key and base URL are present", () => {
335
- expect(isManagedAvailable()).toBe(true);
336
- });
337
- });
@@ -1,170 +0,0 @@
1
- ---
2
- name: doordash
3
- description: Order food, groceries, and convenience items from DoorDash using the built-in CLI integration
4
- compatibility: "Designed for Vellum personal assistants"
5
- metadata:
6
- emoji: "🍕"
7
- vellum:
8
- display-name: "DoorDash"
9
- user-invocable: true
10
- cli:
11
- command: "doordash"
12
- entry: "doordash-entry.ts"
13
- ---
14
-
15
- You can order food from DoorDash for the user using the `doordash` CLI.
16
-
17
- ## CLI Setup
18
-
19
- **IMPORTANT: Always use `host_bash` (not `bash`) for all `doordash` commands.** The DoorDash CLI needs host access for Chrome CDP, session cookies, and the CLI binary — none of which are available inside the sandbox.
20
-
21
- `doordash` is a standalone CLI tool installed at `~/.vellum/bin/doordash`. It should already be on your PATH. If `doordash` is not found, prepend `PATH="$HOME/.vellum/bin:$PATH"` to the command. Do NOT search for the binary, inspect wrapper scripts, or try to discover how the CLI works. Just run the commands as documented below.
22
-
23
- ## Task Progress Widget
24
-
25
- A task progress card is shown automatically when you run your first `doordash` command. Its surface ID is `doordash-progress`. As each step completes, call `ui_update` with surface ID `doordash-progress` to update step statuses. Update `data.templateData.steps` — set completed steps to `"status": "completed"` with a `"detail"` string, the current step to `"status": "in_progress"`, and future steps to `"status": "pending"`. Adapt the steps to the actual flow (e.g. skip "Search restaurants" if the user named a specific store).
26
-
27
- ## Typical Flow
28
-
29
- When the user asks you to order food (e.g. "Order pizza from Andiamo's"):
30
-
31
- 1. **Check session** — run `doordash status --json`. If `loggedIn` is false or the session is expired, tell the user: "A Chrome window will open to the DoorDash login page. Please sign in there — I'll detect your login automatically and minimize the window." Then run `doordash refresh --json`. This starts a Ride Shotgun learn session that records your login and auto-stops once it detects you've signed in. The session is imported automatically. **This command blocks until login is complete — just wait for it.**
32
-
33
- Keep the DoorDash Chrome window open in the background — it's needed for API requests.
34
-
35
- 2. **Search** — run `doordash search "<query>" --json` to find matching restaurants. Present the top results to the user with name, rating, and delivery info. If the user named a specific restaurant, pick the best match. If ambiguous, ask.
36
-
37
- 3. **Browse menu** — run `doordash menu <storeId> --json` to get the menu. Show the user the categories and items with prices. If the user already said what they want (e.g. "pepperoni pizza"), find the matching item(s). **For convenience/pharmacy stores** (CVS, Duane Reade, Walgreens etc.), the response will have `isRetail: true` and empty items — use `store-search` instead (see step 3b).
38
-
39
- 3b. **Search within a retail store** — for convenience/pharmacy stores, run `doordash store-search <storeId> "<query>" --json` to find specific products. This returns items with IDs, prices, and menuIds that can be added to cart directly.
40
-
41
- 4. **Get item details** (if needed) — run `doordash item <storeId> <itemId> --json` to see options/customizations. The response includes:
42
- - `options`: each option group has `minSelections`/`maxSelections` indicating how many choices are required
43
- - Each choice has `unitAmount` (price impact in cents), `defaultQuantity`, and possibly `nestedOptions` (sub-choices like milk type within a size selection)
44
- - `specialInstructionsConfig`: whether special instructions are accepted, max length, and placeholder text
45
-
46
- If the item has required options (like size or toppings), construct the `nestedOptions` JSON from the option/choice IDs and pass it via `--options`. Ask the user for preferences or pick sensible defaults.
47
-
48
- 5. **Add to cart** — run `doordash cart add --store-id <id> --menu-id <id> --item-id <id> --item-name "<name>" --unit-price <cents> [--options '<json>'] [--special-instructions "<text>"] --json`. For subsequent items at the same store, pass `--cart-id <id>` from the first add response. Use `--special-instructions` for requests like "extra hot", "no ice", etc. Use `--options` to pass customization choices (see Customization Options below).
49
-
50
- 6. **Review cart** — run `doordash cart view <cartId> --json` and show the user what's in their cart with prices. Ask if they want to add anything else or proceed.
51
-
52
- 7. **Checkout** — run `doordash checkout <cartId> --json` to get delivery options. Present them to the user.
53
-
54
- 8. **Payment methods** — run `doordash payment-methods --json` to see saved cards. Show the user which card will be used (the default one).
55
-
56
- 9. **Place order** — after the user explicitly confirms, run `doordash order place --cart-id <id> --store-id <id> --total <cents> [--tip <cents>] [--dropoff-option <id>] --json`. The command auto-selects the default payment method if `--payment-uuid` is not provided. The response contains `orderUuid` on success.
57
-
58
- ## Important Behavior
59
-
60
- - **Always confirm before checkout.** Never place an order without explicit user approval.
61
- - **Be proactive.** If the user says "order pizza from Andiamo's", don't ask clarifying questions upfront — search, find the store, show the menu, and suggest items. Only ask when you need a choice the user hasn't specified.
62
- - **Handle expired sessions gracefully.** If any command returns `"error": "session_expired"`, run `doordash refresh --json` to re-capture the session.
63
- - **Show prices.** Always show prices when presenting items or the cart summary.
64
- - **Use `--json` flag** on all commands for reliable parsing.
65
- - **Do NOT use the browser skill.** All DoorDash interaction goes through the CLI, not browser automation.
66
- - **Rate limiting.** DoorDash rate-limits rapid sequential requests. When adding multiple items (e.g. a team order), wait 8–10 seconds between `cart add` calls. If you get a 403 error, wait 15–20 seconds and retry. For large orders (5+ items), consider running `doordash refresh --json` midway through if you hit repeated 403s.
67
- - **Special instructions are unreliable.** Some merchants disable special instructions entirely. Always prefer `--options` for customizations (size, milk type, etc.). Only use `--special-instructions` for free-text requests that aren't covered by the item's option groups. If the merchant rejects special instructions, drop them and proceed without.
68
- - **Customization fallback.** If `cart add` with `--options` fails, or if the item details show options that are hard to construct (deeply nested, unusual format), proactively offer to use `cart learn` so the user can customize the item visually in the browser. Don't silently drop customizations — tell the user what happened and offer alternatives.
69
- - **Always-allow tip.** At the start of an ordering flow, suggest the user enable "always allow" for `doordash` commands: "Tip: You can type 'a' to always allow `doordash` commands for this session so you won't be prompted each time."
70
- - **Error attribution.** When errors occur, assume it's more likely a bug in our query/parsing than a DoorDash API change. Suggest running `doordash record` to capture fresh queries before assuming the schema changed.
71
-
72
- ## Customization Options
73
-
74
- Many items (especially coffee, boba, sandwiches) have required customization options like size, milk type, or toppings. Here's how to handle them:
75
-
76
- ### Constructing nestedOptions JSON
77
-
78
- 1. Run `doordash item <storeId> <itemId> --json` to get the item's option groups
79
- 2. Each option group has `id`, `name`, `required`, `minSelections`, `maxSelections`, and `choices`
80
- 3. Build a JSON array of selections matching the DoorDash format:
81
-
82
- ```json
83
- [
84
- {
85
- "optionId": "<option-group-id>",
86
- "optionChoiceId": "<choice-id>",
87
- "quantity": 1,
88
- "nestedOptions": []
89
- }
90
- ]
91
- ```
92
-
93
- For choices with nested sub-options (e.g., selecting "Oat Milk" under the "Milk" option within a size), add them to the `nestedOptions` array of the parent choice.
94
-
95
- 4. Pass the JSON string to `cart add --options '<json>'`
96
-
97
- ### Special Instructions
98
-
99
- Use `--special-instructions` on `cart add` for free-text requests like "extra hot", "no ice", "light foam". The `item` command response includes `specialInstructionsConfig` with the max length and whether instructions are supported.
100
-
101
- **Warning:** Some merchants disable special instructions entirely. If `specialInstructionsConfig.isEnabled` is false, or if the add-to-cart call returns an error about special requests, drop the instructions and retry without them. Always prefer `--options` for customizations — special instructions are a last resort for requests not covered by the item's option groups.
102
-
103
- ### Learning Customizations via Ride Shotgun
104
-
105
- For complex items where constructing the JSON manually is difficult, use `cart learn`:
106
-
107
- 1. Run `doordash cart learn --json`
108
- 2. A Chrome window opens — navigate to the item, customize it visually, and click "Add to Cart"
109
- 3. The command auto-detects the `updateCartItem` operation and extracts the exact `nestedOptions` and `specialInstructions`
110
- 4. Use the extracted options directly with `cart add --options '<json>'`
111
-
112
- You can also extract options from an existing recording with `doordash inspect <recordingId> --extract-options --json`.
113
-
114
- ### Coffee Order Example
115
-
116
- **User**: "Order a large oat milk latte with an extra shot from Blue Bottle"
117
-
118
- 1. `doordash search "Blue Bottle" --json` -> finds store
119
- 2. `doordash menu <storeId> --json` -> finds "Latte" item
120
- 3. `doordash item <storeId> <latteItemId> --json` -> returns options:
121
- - Size (required, min:1, max:1): Small (id:101), Medium (id:102), Large (id:103, +$1.00)
122
- - Milk (required, min:1, max:1): Whole (id:201), Oat (id:202, +$0.70), Almond (id:203, +$0.70)
123
- - Extras (optional, min:0, max:5): Extra Shot (id:301, +$0.90), Vanilla Syrup (id:302, +$0.60)
124
- 4. Construct options JSON and add to cart:
125
-
126
- ```
127
- doordash cart add --store-id <id> --menu-id <id> --item-id <id> --item-name "Latte" --unit-price 550 --options '[{"optionId":"size-group-id","optionChoiceId":"103","quantity":1,"nestedOptions":[]},{"optionId":"milk-group-id","optionChoiceId":"202","quantity":1,"nestedOptions":[]},{"optionId":"extras-group-id","optionChoiceId":"301","quantity":1,"nestedOptions":[]}]' --special-instructions "Extra hot" --json
128
- ```
129
-
130
- ## Command Reference
131
-
132
- ```
133
- doordash status --json # Check if logged in
134
- doordash refresh --json # Capture fresh session via Ride Shotgun (auto-stops after login)
135
- doordash logout --json # Clear session
136
- doordash search "<query>" --json # Search restaurants
137
- doordash menu <storeId> --json # Get store menu (auto-detects retail stores)
138
- doordash store-search <storeId> "<query>" --json # Search items within a convenience/pharmacy store
139
- doordash item <storeId> <itemId> --json # Get item details + options
140
- doordash cart add --store-id <id> --menu-id <id> --item-id <id> --item-name "<name>" --unit-price <cents> [--quantity <n>] [--cart-id <id>] [--options '<json>'] [--special-instructions "<text>"] --json
141
- doordash cart remove --cart-id <id> --item-id <orderItemId> --json
142
- doordash cart view <cartId> --json
143
- doordash cart list [--store-id <id>] --json
144
- doordash cart learn --json # Learn customization options by recording browser interaction
145
- doordash inspect <recordingId> --extract-options --json # Extract nestedOptions from a recording
146
- doordash checkout <cartId> [--address-id <id>] --json
147
- doordash payment-methods --json # List saved payment methods
148
- doordash order place --cart-id <id> --store-id <id> --total <cents> [--tip <cents>] [--delivery-option <type>] [--dropoff-option <id>] [--payment-uuid <uuid>] --json
149
- ```
150
-
151
- ## Example Interaction
152
-
153
- **User**: "Order a pepperoni pizza from Andiamo's"
154
-
155
- 1. `doordash status --json` -> logged in
156
- 2. `doordash search "Andiamo's" --json` -> finds store 22926474
157
- 3. `doordash menu 22926474 --json` -> finds "Pepperoni Pizza Pie" (item 2956709006, $28.00)
158
- 4. Tell user: "I found Pepperoni Pizza Pie at Andiamo's for $28.00. Adding it to your cart."
159
- 5. `doordash cart add --store-id 22926474 --menu-id 12847574 --item-id 2956709006 --item-name "Pepperoni Pizza Pie" --unit-price 2800 --json`
160
- 6. `doordash cart view <cartId> --json` -> show summary
161
- 7. "Your cart has 1x Pepperoni Pizza Pie ($28.00), total $28.00. Ready to check out?"
162
-
163
- **User**: "I need Tylenol from CVS"
164
-
165
- 1. `doordash status --json` -> logged in
166
- 2. `doordash search "CVS" --json` -> finds store 1231787
167
- 3. `doordash menu 1231787 --json` -> isRetail: true, categories but no items
168
- 4. `doordash store-search 1231787 "tylenol" --json` -> finds results
169
- 5. Show top results: "Tylenol Extra Strength Gelcaps (24 ct) - $8.79, Tylenol Extra Strength Caplets (100 ct) - $13.49..."
170
- 6. User picks one -> add to cart with the item's `id`, `menuId`, and `unitAmount`