@vellumai/assistant 0.4.10 → 0.4.12

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 (203) hide show
  1. package/ARCHITECTURE.md +418 -378
  2. package/Dockerfile +1 -1
  3. package/README.md +16 -9
  4. package/package.json +1 -1
  5. package/src/__tests__/account-registry.test.ts +1 -0
  6. package/src/__tests__/actor-token-service.test.ts +1 -0
  7. package/src/__tests__/app-builder-tool-scripts.test.ts +1 -0
  8. package/src/__tests__/asset-materialize-tool.test.ts +7 -0
  9. package/src/__tests__/asset-search-tool.test.ts +7 -0
  10. package/src/__tests__/browser-fill-credential.test.ts +1 -0
  11. package/src/__tests__/call-start-guardian-guard.test.ts +1 -0
  12. package/src/__tests__/channel-approval-routes.test.ts +29 -0
  13. package/src/__tests__/channel-guardian.test.ts +2143 -1546
  14. package/src/__tests__/channel-retry-sweep.test.ts +169 -14
  15. package/src/__tests__/claude-code-tool-profiles.test.ts +1 -0
  16. package/src/__tests__/computer-use-tools.test.ts +1 -0
  17. package/src/__tests__/contacts-tools.test.ts +1 -0
  18. package/src/__tests__/conversation-attention-telegram.test.ts +1 -0
  19. package/src/__tests__/credential-policy-validate.test.ts +97 -0
  20. package/src/__tests__/credential-security-e2e.test.ts +1 -0
  21. package/src/__tests__/credential-vault-unit.test.ts +1 -0
  22. package/src/__tests__/credential-vault.test.ts +1 -0
  23. package/src/__tests__/delete-managed-skill-tool.test.ts +1 -0
  24. package/src/__tests__/file-edit-tool.test.ts +1 -0
  25. package/src/__tests__/file-read-tool.test.ts +1 -0
  26. package/src/__tests__/file-write-tool.test.ts +1 -0
  27. package/src/__tests__/followup-tools.test.ts +1 -0
  28. package/src/__tests__/gateway-only-guard.test.ts +1 -1
  29. package/src/__tests__/guardian-control-plane-policy.test.ts +5 -4
  30. package/src/__tests__/guardian-grant-minting.test.ts +3 -0
  31. package/src/__tests__/guardian-principal-id-roundtrip.test.ts +4 -3
  32. package/src/__tests__/guardian-routing-state.test.ts +8 -0
  33. package/src/__tests__/guardian-verify-setup-skill-regression.test.ts +75 -61
  34. package/src/__tests__/headless-browser-interactions.test.ts +1 -0
  35. package/src/__tests__/headless-browser-navigate.test.ts +1 -0
  36. package/src/__tests__/headless-browser-read-tools.test.ts +1 -0
  37. package/src/__tests__/headless-browser-snapshot.test.ts +1 -0
  38. package/src/__tests__/host-file-edit-tool.test.ts +1 -0
  39. package/src/__tests__/host-file-read-tool.test.ts +1 -0
  40. package/src/__tests__/host-file-write-tool.test.ts +1 -0
  41. package/src/__tests__/host-shell-tool.test.ts +1 -0
  42. package/src/__tests__/lifecycle-docs-guard.test.ts +207 -0
  43. package/src/__tests__/managed-skill-lifecycle.test.ts +1 -0
  44. package/src/__tests__/media-reuse-story.e2e.test.ts +8 -0
  45. package/src/__tests__/messaging-send-tool.test.ts +1 -0
  46. package/src/__tests__/playbook-execution.test.ts +1 -0
  47. package/src/__tests__/playbook-tools.test.ts +1 -0
  48. package/src/__tests__/registry.test.ts +235 -187
  49. package/src/__tests__/relay-server.test.ts +4 -0
  50. package/src/__tests__/scaffold-managed-skill-tool.test.ts +1 -0
  51. package/src/__tests__/schedule-tools.test.ts +1 -0
  52. package/src/__tests__/secret-onetime-send.test.ts +4 -0
  53. package/src/__tests__/secret-scanner-executor.test.ts +2 -0
  54. package/src/__tests__/secure-keys.test.ts +27 -0
  55. package/src/__tests__/send-notification-tool.test.ts +2 -0
  56. package/src/__tests__/session-agent-loop.test.ts +521 -256
  57. package/src/__tests__/session-surfaces-task-progress.test.ts +1 -0
  58. package/src/__tests__/session-tool-setup-app-refresh.test.ts +1 -0
  59. package/src/__tests__/session-tool-setup-memory-scope.test.ts +1 -0
  60. package/src/__tests__/session-tool-setup-side-effect-flag.test.ts +1 -0
  61. package/src/__tests__/shell-credential-ref.test.ts +1 -0
  62. package/src/__tests__/shell-tool-proxy-mode.test.ts +1 -0
  63. package/src/__tests__/skill-load-feature-flag.test.ts +1 -0
  64. package/src/__tests__/skill-load-tool.test.ts +1 -0
  65. package/src/__tests__/skill-script-runner-host.test.ts +1 -0
  66. package/src/__tests__/skill-script-runner-sandbox.test.ts +1 -0
  67. package/src/__tests__/skill-script-runner.test.ts +1 -0
  68. package/src/__tests__/skill-tool-factory.test.ts +1 -0
  69. package/src/__tests__/skills.test.ts +334 -276
  70. package/src/__tests__/starter-task-flow.test.ts +7 -17
  71. package/src/__tests__/subagent-tools.test.ts +1 -1
  72. package/src/__tests__/swarm-recursion.test.ts +1 -0
  73. package/src/__tests__/swarm-session-integration.test.ts +1 -0
  74. package/src/__tests__/swarm-tool.test.ts +1 -0
  75. package/src/__tests__/task-management-tools.test.ts +1 -0
  76. package/src/__tests__/task-tools.test.ts +1 -0
  77. package/src/__tests__/terminal-tools.test.ts +1 -0
  78. package/src/__tests__/tool-approval-handler.test.ts +2 -2
  79. package/src/__tests__/tool-execution-abort-cleanup.test.ts +1 -0
  80. package/src/__tests__/tool-execution-pipeline.benchmark.test.ts +1 -0
  81. package/src/__tests__/tool-executor-lifecycle-events.test.ts +2 -0
  82. package/src/__tests__/tool-executor-shell-integration.test.ts +1 -0
  83. package/src/__tests__/tool-executor.test.ts +1 -0
  84. package/src/__tests__/trust-context-guards.test.ts +218 -0
  85. package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +6 -0
  86. package/src/__tests__/trusted-contact-lifecycle-notifications.test.ts +6 -0
  87. package/src/__tests__/trusted-contact-multichannel.test.ts +1 -0
  88. package/src/__tests__/trusted-contact-verification.test.ts +1 -0
  89. package/src/__tests__/view-image-tool.test.ts +1 -0
  90. package/src/agent/loop.ts +9 -2
  91. package/src/calls/guardian-dispatch.ts +4 -4
  92. package/src/cli/mcp.ts +183 -3
  93. package/src/config/bundled-skills/agentmail/SKILL.md +4 -4
  94. package/src/config/bundled-skills/chatgpt-import/tools/chatgpt-import.ts +449 -0
  95. package/src/config/bundled-skills/doordash/SKILL.md +171 -0
  96. package/src/config/bundled-skills/doordash/__tests__/doordash-client.test.ts +203 -0
  97. package/src/config/bundled-skills/doordash/__tests__/doordash-session.test.ts +164 -0
  98. package/src/config/bundled-skills/doordash/doordash-cli.ts +1193 -0
  99. package/src/config/bundled-skills/doordash/doordash-entry.ts +22 -0
  100. package/src/config/bundled-skills/doordash/lib/cart-queries.ts +787 -0
  101. package/src/config/bundled-skills/doordash/lib/client.ts +1071 -0
  102. package/src/config/bundled-skills/doordash/lib/order-queries.ts +85 -0
  103. package/src/config/bundled-skills/doordash/lib/queries.ts +28 -0
  104. package/src/config/bundled-skills/doordash/lib/query-extractor.ts +94 -0
  105. package/src/config/bundled-skills/doordash/lib/search-queries.ts +203 -0
  106. package/src/config/bundled-skills/doordash/lib/session.ts +93 -0
  107. package/src/config/bundled-skills/doordash/lib/shared/errors.ts +61 -0
  108. package/src/config/bundled-skills/doordash/lib/shared/ipc.ts +32 -0
  109. package/src/config/bundled-skills/doordash/lib/shared/network-recorder.ts +380 -0
  110. package/src/config/bundled-skills/doordash/lib/shared/platform.ts +35 -0
  111. package/src/config/bundled-skills/doordash/lib/shared/recording-store.ts +43 -0
  112. package/src/config/bundled-skills/doordash/lib/shared/recording-types.ts +49 -0
  113. package/src/config/bundled-skills/doordash/lib/shared/truncate.ts +6 -0
  114. package/src/config/bundled-skills/doordash/lib/store-queries.ts +246 -0
  115. package/src/config/bundled-skills/doordash/lib/types.ts +367 -0
  116. package/src/config/bundled-skills/google-calendar/SKILL.md +4 -5
  117. package/src/config/bundled-skills/google-oauth-setup/SKILL.md +42 -41
  118. package/src/config/bundled-skills/messaging/SKILL.md +59 -42
  119. package/src/config/bundled-skills/messaging/TOOLS.json +2 -2
  120. package/src/config/bundled-skills/messaging/tools/gmail-archive-by-query.ts +5 -1
  121. package/src/config/bundled-skills/messaging/tools/gmail-batch-archive.ts +11 -2
  122. package/src/config/bundled-skills/messaging/tools/gmail-sender-digest.ts +10 -3
  123. package/src/config/bundled-skills/messaging/tools/gmail-unsubscribe.ts +5 -1
  124. package/src/config/bundled-skills/messaging/tools/messaging-archive-by-sender.ts +5 -1
  125. package/src/config/bundled-skills/messaging/tools/messaging-sender-digest.ts +2 -1
  126. package/src/config/bundled-skills/notion/SKILL.md +240 -0
  127. package/src/config/bundled-skills/notion-oauth-setup/SKILL.md +127 -0
  128. package/src/config/bundled-skills/oauth-setup/SKILL.md +144 -0
  129. package/src/config/bundled-skills/phone-calls/SKILL.md +91 -162
  130. package/src/config/bundled-skills/skills-catalog/SKILL.md +32 -29
  131. package/src/config/{vellum-skills → bundled-skills}/sms-setup/SKILL.md +29 -22
  132. package/src/config/{vellum-skills → bundled-skills}/telegram-setup/SKILL.md +17 -14
  133. package/src/config/{vellum-skills → bundled-skills}/twilio-setup/SKILL.md +21 -6
  134. package/src/config/bundled-tool-registry.ts +281 -267
  135. package/src/config/system-prompt.ts +4 -2
  136. package/src/daemon/computer-use-session.ts +1 -0
  137. package/src/daemon/handlers/skills.ts +334 -234
  138. package/src/daemon/ipc-contract/messages.ts +2 -0
  139. package/src/daemon/ipc-contract/surfaces.ts +2 -0
  140. package/src/daemon/lifecycle.ts +358 -221
  141. package/src/daemon/response-tier.ts +2 -0
  142. package/src/daemon/server.ts +453 -193
  143. package/src/daemon/session-agent-loop-handlers.ts +42 -2
  144. package/src/daemon/session-agent-loop.ts +4 -1
  145. package/src/daemon/session-lifecycle.ts +3 -0
  146. package/src/daemon/session-memory.ts +2 -2
  147. package/src/daemon/session-process.ts +1 -0
  148. package/src/daemon/session-runtime-assembly.ts +2 -2
  149. package/src/daemon/session-surfaces.ts +22 -20
  150. package/src/daemon/session-tool-setup.ts +2 -1
  151. package/src/daemon/session.ts +5 -2
  152. package/src/mcp/client.ts +55 -6
  153. package/src/mcp/manager.ts +9 -0
  154. package/src/mcp/mcp-oauth-provider.ts +347 -0
  155. package/src/memory/channel-delivery-store.ts +1 -0
  156. package/src/memory/db-init.ts +4 -0
  157. package/src/memory/delivery-status.ts +43 -0
  158. package/src/memory/guardian-bindings.ts +3 -3
  159. package/src/memory/migrations/127-guardian-principal-id-not-null.ts +108 -0
  160. package/src/memory/migrations/index.ts +1 -0
  161. package/src/memory/migrations/registry.ts +6 -0
  162. package/src/memory/schema.ts +1 -1
  163. package/src/messaging/outreach-classifier.ts +12 -5
  164. package/src/messaging/provider-types.ts +2 -0
  165. package/src/messaging/providers/gmail/adapter.ts +9 -3
  166. package/src/messaging/providers/gmail/client.ts +2 -0
  167. package/src/runtime/actor-trust-resolver.ts +13 -4
  168. package/src/runtime/channel-retry-sweep.ts +31 -14
  169. package/src/runtime/guardian-context-resolver.ts +25 -64
  170. package/src/runtime/guardian-outbound-actions.ts +399 -108
  171. package/src/runtime/guardian-vellum-migration.ts +1 -23
  172. package/src/runtime/guardian-verification-templates.ts +66 -30
  173. package/src/runtime/http-errors.ts +33 -20
  174. package/src/runtime/http-server.ts +706 -291
  175. package/src/runtime/http-types.ts +26 -16
  176. package/src/runtime/local-actor-identity.ts +4 -6
  177. package/src/runtime/middleware/actor-token.ts +2 -8
  178. package/src/runtime/routes/channel-route-shared.ts +0 -1
  179. package/src/runtime/routes/inbound-message-handler.ts +3 -4
  180. package/src/runtime/routes/secret-routes.ts +57 -2
  181. package/src/runtime/routes/surface-action-routes.ts +66 -0
  182. package/src/runtime/routes/trust-rules-routes.ts +140 -0
  183. package/src/runtime/tool-grant-request-helper.ts +1 -1
  184. package/src/security/keychain-to-encrypted-migration.ts +59 -0
  185. package/src/security/secure-keys.ts +17 -0
  186. package/src/skills/frontmatter.ts +9 -7
  187. package/src/tools/apps/executors.ts +2 -1
  188. package/src/tools/credentials/policy-validate.ts +22 -0
  189. package/src/tools/guardian-control-plane-policy.ts +2 -2
  190. package/src/tools/tool-manifest.ts +44 -42
  191. package/src/tools/types.ts +10 -1
  192. package/src/__tests__/skill-mirror-parity.test.ts +0 -176
  193. package/src/config/vellum-skills/catalog.json +0 -63
  194. package/src/config/vellum-skills/chatgpt-import/tools/chatgpt-import.ts +0 -295
  195. package/src/skills/vellum-catalog-remote.ts +0 -166
  196. package/src/tools/skills/vellum-catalog.ts +0 -168
  197. /package/src/config/{vellum-skills → bundled-skills}/chatgpt-import/SKILL.md +0 -0
  198. /package/src/config/{vellum-skills → bundled-skills}/chatgpt-import/TOOLS.json +0 -0
  199. /package/src/config/{vellum-skills → bundled-skills}/deploy-fullstack-vercel/SKILL.md +0 -0
  200. /package/src/config/{vellum-skills → bundled-skills}/document-writer/SKILL.md +0 -0
  201. /package/src/config/{vellum-skills → bundled-skills}/guardian-verify-setup/SKILL.md +0 -0
  202. /package/src/config/{vellum-skills → bundled-skills}/slack-oauth-setup/SKILL.md +0 -0
  203. /package/src/config/{vellum-skills → bundled-skills}/trusted-contacts/SKILL.md +0 -0
@@ -0,0 +1,449 @@
1
+ import { existsSync, mkdirSync, readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { inflateRawSync } from "node:zlib";
5
+
6
+ import { Database } from "bun:sqlite";
7
+ import { eq } from "drizzle-orm";
8
+ import { drizzle } from "drizzle-orm/bun-sqlite";
9
+ import { integer, real, sqliteTable, text } from "drizzle-orm/sqlite-core";
10
+ import { v4 as uuid } from "uuid";
11
+
12
+ import type {
13
+ ToolContext,
14
+ ToolExecutionResult,
15
+ } from "../../../../tools/types.js";
16
+
17
+ // -- Inline schema (only the tables this tool touches) --
18
+
19
+ const conversations = sqliteTable("conversations", {
20
+ id: text("id").primaryKey(),
21
+ title: text("title"),
22
+ createdAt: integer("created_at").notNull(),
23
+ updatedAt: integer("updated_at").notNull(),
24
+ totalInputTokens: integer("total_input_tokens").notNull().default(0),
25
+ totalOutputTokens: integer("total_output_tokens").notNull().default(0),
26
+ totalEstimatedCost: real("total_estimated_cost").notNull().default(0),
27
+ contextSummary: text("context_summary"),
28
+ contextCompactedMessageCount: integer("context_compacted_message_count")
29
+ .notNull()
30
+ .default(0),
31
+ contextCompactedAt: integer("context_compacted_at"),
32
+ threadType: text("thread_type").notNull().default("standard"),
33
+ memoryScopeId: text("memory_scope_id").notNull().default("default"),
34
+ });
35
+
36
+ const messagesTable = sqliteTable("messages", {
37
+ id: text("id").primaryKey(),
38
+ conversationId: text("conversation_id")
39
+ .notNull()
40
+ .references(() => conversations.id),
41
+ role: text("role").notNull(),
42
+ content: text("content").notNull(),
43
+ createdAt: integer("created_at").notNull(),
44
+ metadata: text("metadata"),
45
+ });
46
+
47
+ const conversationKeys = sqliteTable("conversation_keys", {
48
+ id: text("id").primaryKey(),
49
+ conversationKey: text("conversation_key").notNull(),
50
+ conversationId: text("conversation_id")
51
+ .notNull()
52
+ .references(() => conversations.id, { onDelete: "cascade" }),
53
+ createdAt: integer("created_at").notNull(),
54
+ });
55
+
56
+ // -- Inline DB access --
57
+
58
+ const schema = { conversations, messages: messagesTable, conversationKeys };
59
+
60
+ function getDbPath(): string {
61
+ const baseDir = process.env.BASE_DATA_DIR?.trim() || homedir();
62
+ return join(baseDir, ".vellum", "workspace", "data", "db", "assistant.db");
63
+ }
64
+
65
+ let db: ReturnType<typeof drizzle<typeof schema>> | null = null;
66
+
67
+ function getDb() {
68
+ if (!db) {
69
+ const dbPath = getDbPath();
70
+ const dbDir = join(dbPath, "..");
71
+ mkdirSync(dbDir, { recursive: true });
72
+ const sqlite = new Database(dbPath);
73
+ sqlite.exec("PRAGMA journal_mode=WAL");
74
+ sqlite.exec("PRAGMA foreign_keys = ON");
75
+ db = drizzle(sqlite, { schema });
76
+ }
77
+ return db;
78
+ }
79
+
80
+ // -- Inline conversation helpers --
81
+
82
+ let lastTimestamp = 0;
83
+ function monotonicNow(): number {
84
+ const now = Date.now();
85
+ lastTimestamp = Math.max(now, lastTimestamp + 1);
86
+ return lastTimestamp;
87
+ }
88
+
89
+ function createConversation(title: string) {
90
+ const database = getDb();
91
+ const now = Date.now();
92
+ const id = uuid();
93
+ const conversation = {
94
+ id,
95
+ title,
96
+ createdAt: now,
97
+ updatedAt: now,
98
+ totalInputTokens: 0,
99
+ totalOutputTokens: 0,
100
+ totalEstimatedCost: 0,
101
+ contextSummary: null as string | null,
102
+ contextCompactedMessageCount: 0,
103
+ contextCompactedAt: null as number | null,
104
+ threadType: "standard" as const,
105
+ memoryScopeId: "default",
106
+ };
107
+ database.insert(conversations).values(conversation).run();
108
+ return conversation;
109
+ }
110
+
111
+ function addMessage(conversationId: string, role: string, content: string) {
112
+ const database = getDb();
113
+ const now = monotonicNow();
114
+ const message = {
115
+ id: uuid(),
116
+ conversationId,
117
+ role,
118
+ content,
119
+ createdAt: now,
120
+ };
121
+ database.transaction((tx) => {
122
+ tx.insert(messagesTable).values(message).run();
123
+ tx.update(conversations)
124
+ .set({ updatedAt: now })
125
+ .where(eq(conversations.id, conversationId))
126
+ .run();
127
+ });
128
+ return message;
129
+ }
130
+
131
+ // -- ChatGPT export format types --
132
+
133
+ interface ChatGPTContent {
134
+ content_type: string;
135
+ parts?: (string | null | Record<string, unknown>)[];
136
+ }
137
+
138
+ interface ChatGPTNode {
139
+ message: {
140
+ author: { role: string };
141
+ content: ChatGPTContent;
142
+ create_time?: number | null;
143
+ } | null;
144
+ parent: string | null;
145
+ children: string[];
146
+ }
147
+
148
+ interface ChatGPTConversation {
149
+ id?: string;
150
+ title: string;
151
+ create_time: number;
152
+ update_time: number;
153
+ current_node: string;
154
+ mapping: Record<string, ChatGPTNode>;
155
+ }
156
+
157
+ interface ImportedMessage {
158
+ role: string;
159
+ content: Array<{ type: string; text: string }>;
160
+ createdAt: number;
161
+ }
162
+
163
+ interface ImportedConversation {
164
+ sourceId: string;
165
+ title: string;
166
+ createdAt: number;
167
+ updatedAt: number;
168
+ messages: ImportedMessage[];
169
+ }
170
+
171
+ // -- Tool entry point --
172
+
173
+ export async function run(
174
+ input: Record<string, unknown>,
175
+ _context: ToolContext,
176
+ ): Promise<ToolExecutionResult> {
177
+ const filePath = input.file_path as string;
178
+
179
+ if (!filePath) {
180
+ return { content: "Error: file_path is required", isError: true };
181
+ }
182
+
183
+ if (!filePath.endsWith(".zip")) {
184
+ return {
185
+ content:
186
+ "Error: Only ZIP files are accepted. Please provide the ChatGPT export ZIP file.",
187
+ isError: true,
188
+ };
189
+ }
190
+
191
+ if (!existsSync(filePath)) {
192
+ return { content: `Error: File not found: ${filePath}`, isError: true };
193
+ }
194
+
195
+ let imported: ImportedConversation[];
196
+ try {
197
+ imported = parseChatGPTExport(filePath);
198
+ } catch (err) {
199
+ return {
200
+ content: `Error parsing export file: ${err instanceof Error ? err.message : String(err)}`,
201
+ isError: true,
202
+ };
203
+ }
204
+
205
+ if (imported.length === 0) {
206
+ return {
207
+ content: "No conversations found in the export file.",
208
+ isError: false,
209
+ };
210
+ }
211
+
212
+ const database = getDb();
213
+ let importedCount = 0;
214
+ let skippedCount = 0;
215
+ let messageCount = 0;
216
+
217
+ for (const conv of imported) {
218
+ const convKey = `chatgpt:${conv.sourceId}`;
219
+
220
+ const existing = database
221
+ .select()
222
+ .from(conversationKeys)
223
+ .where(eq(conversationKeys.conversationKey, convKey))
224
+ .get();
225
+
226
+ if (existing) {
227
+ skippedCount++;
228
+ continue;
229
+ }
230
+
231
+ const conversation = createConversation(conv.title);
232
+
233
+ for (const msg of conv.messages) {
234
+ addMessage(conversation.id, msg.role, JSON.stringify(msg.content));
235
+ }
236
+
237
+ // Override timestamps to match ChatGPT originals
238
+ database
239
+ .update(conversations)
240
+ .set({ createdAt: conv.createdAt, updatedAt: conv.updatedAt })
241
+ .where(eq(conversations.id, conversation.id))
242
+ .run();
243
+
244
+ // Update message timestamps to match ChatGPT originals
245
+ const dbMessages = database
246
+ .select({ id: messagesTable.id })
247
+ .from(messagesTable)
248
+ .where(eq(messagesTable.conversationId, conversation.id))
249
+ .orderBy(messagesTable.createdAt)
250
+ .all();
251
+
252
+ for (let i = 0; i < dbMessages.length && i < conv.messages.length; i++) {
253
+ database
254
+ .update(messagesTable)
255
+ .set({ createdAt: conv.messages[i].createdAt })
256
+ .where(eq(messagesTable.id, dbMessages[i].id))
257
+ .run();
258
+ }
259
+
260
+ database
261
+ .insert(conversationKeys)
262
+ .values({
263
+ id: uuid(),
264
+ conversationKey: convKey,
265
+ conversationId: conversation.id,
266
+ createdAt: Date.now(),
267
+ })
268
+ .run();
269
+
270
+ importedCount++;
271
+ messageCount += conv.messages.length;
272
+ }
273
+
274
+ const lines = [
275
+ `Imported ${importedCount} conversation(s) with ${messageCount} message(s).`,
276
+ ];
277
+ if (skippedCount > 0) {
278
+ lines.push(`Skipped ${skippedCount} already-imported conversation(s).`);
279
+ }
280
+ return { content: lines.join("\n"), isError: false };
281
+ }
282
+
283
+ // -- Parser --
284
+
285
+ function parseChatGPTExport(zipPath: string): ImportedConversation[] {
286
+ const jsonContent = extractConversationsJsonFromZip(zipPath);
287
+
288
+ const raw = JSON.parse(jsonContent);
289
+ if (!Array.isArray(raw)) {
290
+ throw new Error("Expected conversations.json to contain a JSON array");
291
+ }
292
+
293
+ const results: ImportedConversation[] = [];
294
+ for (const conv of raw as ChatGPTConversation[]) {
295
+ const imported = parseConversation(conv);
296
+ if (imported) {
297
+ results.push(imported);
298
+ }
299
+ }
300
+ return results;
301
+ }
302
+
303
+ function parseConversation(
304
+ conv: ChatGPTConversation,
305
+ ): ImportedConversation | null {
306
+ const { mapping, current_node } = conv;
307
+ if (!mapping || !current_node || !mapping[current_node]) return null;
308
+
309
+ // Walk from current_node to root via parent pointers, then reverse for chronological order
310
+ const nodeIds: string[] = [];
311
+ let nodeId: string | null = current_node;
312
+ while (nodeId) {
313
+ nodeIds.push(nodeId);
314
+ nodeId = mapping[nodeId]?.parent ?? null;
315
+ }
316
+ nodeIds.reverse();
317
+
318
+ const messages: ImportedMessage[] = [];
319
+ for (const id of nodeIds) {
320
+ const node = mapping[id];
321
+ if (!node?.message) continue;
322
+
323
+ const { author, content, create_time } = node.message;
324
+ const role = author?.role;
325
+ if (role !== "user" && role !== "assistant") continue;
326
+
327
+ const text = extractText(content);
328
+ if (!text) continue;
329
+
330
+ messages.push({
331
+ role,
332
+ content: [{ type: "text", text }],
333
+ createdAt: create_time
334
+ ? Math.round(create_time * 1000)
335
+ : Math.round(conv.create_time * 1000),
336
+ });
337
+ }
338
+
339
+ if (messages.length === 0) return null;
340
+
341
+ return {
342
+ sourceId: conv.id ?? `${conv.title}-${conv.create_time}`,
343
+ title: conv.title || "Untitled",
344
+ createdAt: Math.round(conv.create_time * 1000),
345
+ updatedAt: Math.round(conv.update_time * 1000),
346
+ messages,
347
+ };
348
+ }
349
+
350
+ function extractText(content: ChatGPTContent): string {
351
+ if (!content?.parts) return "";
352
+ return content.parts
353
+ .filter((p): p is string => typeof p === "string")
354
+ .join("");
355
+ }
356
+
357
+ // -- ZIP extraction --
358
+
359
+ function extractConversationsJsonFromZip(zipPath: string): string {
360
+ const buffer = readFileSync(zipPath);
361
+
362
+ // Find end of central directory record (EOCD signature: 0x06054b50)
363
+ let eocdOffset = -1;
364
+ for (let i = buffer.length - 22; i >= 0; i--) {
365
+ if (
366
+ buffer[i] === 0x50 &&
367
+ buffer[i + 1] === 0x4b &&
368
+ buffer[i + 2] === 0x05 &&
369
+ buffer[i + 3] === 0x06
370
+ ) {
371
+ eocdOffset = i;
372
+ break;
373
+ }
374
+ }
375
+ if (eocdOffset === -1) {
376
+ throw new Error(
377
+ "Invalid ZIP file: could not find end of central directory",
378
+ );
379
+ }
380
+
381
+ const centralDirOffset = buffer.readUInt32LE(eocdOffset + 16);
382
+ const centralDirEntries = buffer.readUInt16LE(eocdOffset + 10);
383
+
384
+ // Walk central directory to find conversations.json
385
+ let offset = centralDirOffset;
386
+ for (let i = 0; i < centralDirEntries; i++) {
387
+ if (
388
+ buffer[offset] !== 0x50 ||
389
+ buffer[offset + 1] !== 0x4b ||
390
+ buffer[offset + 2] !== 0x01 ||
391
+ buffer[offset + 3] !== 0x02
392
+ ) {
393
+ throw new Error("Invalid ZIP central directory entry");
394
+ }
395
+
396
+ const cdCompressedSize = buffer.readUInt32LE(offset + 20);
397
+ const fileNameLength = buffer.readUInt16LE(offset + 28);
398
+ const extraLength = buffer.readUInt16LE(offset + 30);
399
+ const commentLength = buffer.readUInt16LE(offset + 32);
400
+ const localHeaderOffset = buffer.readUInt32LE(offset + 42);
401
+ const fileName = buffer
402
+ .subarray(offset + 46, offset + 46 + fileNameLength)
403
+ .toString("utf-8");
404
+
405
+ if (
406
+ fileName === "conversations.json" ||
407
+ fileName.endsWith("/conversations.json")
408
+ ) {
409
+ return extractLocalFile(buffer, localHeaderOffset, cdCompressedSize);
410
+ }
411
+
412
+ offset += 46 + fileNameLength + extraLength + commentLength;
413
+ }
414
+
415
+ throw new Error("conversations.json not found in ZIP file");
416
+ }
417
+
418
+ function extractLocalFile(
419
+ buffer: Buffer,
420
+ offset: number,
421
+ cdCompressedSize: number,
422
+ ): string {
423
+ if (
424
+ buffer[offset] !== 0x50 ||
425
+ buffer[offset + 1] !== 0x4b ||
426
+ buffer[offset + 2] !== 0x03 ||
427
+ buffer[offset + 3] !== 0x04
428
+ ) {
429
+ throw new Error("Invalid ZIP local file header");
430
+ }
431
+
432
+ const compressionMethod = buffer.readUInt16LE(offset + 8);
433
+ const localCompressedSize = buffer.readUInt32LE(offset + 18);
434
+ const compressedSize =
435
+ cdCompressedSize > 0 ? cdCompressedSize : localCompressedSize;
436
+ const fileNameLength = buffer.readUInt16LE(offset + 26);
437
+ const extraLength = buffer.readUInt16LE(offset + 28);
438
+
439
+ const dataOffset = offset + 30 + fileNameLength + extraLength;
440
+ const fileData = buffer.subarray(dataOffset, dataOffset + compressedSize);
441
+
442
+ if (compressionMethod === 0) {
443
+ return fileData.toString("utf-8");
444
+ } else if (compressionMethod === 8) {
445
+ return inflateRawSync(fileData).toString("utf-8");
446
+ } else {
447
+ throw new Error(`Unsupported ZIP compression method: ${compressionMethod}`);
448
+ }
449
+ }
@@ -0,0 +1,171 @@
1
+ ---
2
+ name: "DoorDash"
3
+ description: "Order food, groceries, and convenience items from DoorDash using the built-in CLI integration"
4
+ user-invocable: true
5
+ metadata:
6
+ {
7
+ "vellum":
8
+ {
9
+ "emoji": "\uD83C\uDF55",
10
+ "cli": { "command": "doordash", "entry": "doordash-entry.ts" },
11
+ },
12
+ }
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 login --recording <path> # Import session from a recording file manually
136
+ doordash logout --json # Clear session
137
+ doordash search "<query>" --json # Search restaurants
138
+ doordash menu <storeId> --json # Get store menu (auto-detects retail stores)
139
+ doordash store-search <storeId> "<query>" --json # Search items within a convenience/pharmacy store
140
+ doordash item <storeId> <itemId> --json # Get item details + options
141
+ 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
142
+ doordash cart remove --cart-id <id> --item-id <orderItemId> --json
143
+ doordash cart view <cartId> --json
144
+ doordash cart list [--store-id <id>] --json
145
+ doordash cart learn --json # Learn customization options by recording browser interaction
146
+ doordash inspect <recordingId> --extract-options --json # Extract nestedOptions from a recording
147
+ doordash checkout <cartId> [--address-id <id>] --json
148
+ doordash payment-methods --json # List saved payment methods
149
+ doordash order place --cart-id <id> --store-id <id> --total <cents> [--tip <cents>] [--delivery-option <type>] [--dropoff-option <id>] [--payment-uuid <uuid>] --json
150
+ ```
151
+
152
+ ## Example Interaction
153
+
154
+ **User**: "Order a pepperoni pizza from Andiamo's"
155
+
156
+ 1. `doordash status --json` -> logged in
157
+ 2. `doordash search "Andiamo's" --json` -> finds store 22926474
158
+ 3. `doordash menu 22926474 --json` -> finds "Pepperoni Pizza Pie" (item 2956709006, $28.00)
159
+ 4. Tell user: "I found Pepperoni Pizza Pie at Andiamo's for $28.00. Adding it to your cart."
160
+ 5. `doordash cart add --store-id 22926474 --menu-id 12847574 --item-id 2956709006 --item-name "Pepperoni Pizza Pie" --unit-price 2800 --json`
161
+ 6. `doordash cart view <cartId> --json` -> show summary
162
+ 7. "Your cart has 1x Pepperoni Pizza Pie ($28.00), total $28.00. Ready to check out?"
163
+
164
+ **User**: "I need Tylenol from CVS"
165
+
166
+ 1. `doordash status --json` -> logged in
167
+ 2. `doordash search "CVS" --json` -> finds store 1231787
168
+ 3. `doordash menu 1231787 --json` -> isRetail: true, categories but no items
169
+ 4. `doordash store-search 1231787 "tylenol" --json` -> finds results
170
+ 5. Show top results: "Tylenol Extra Strength Gelcaps (24 ct) - $8.79, Tylenol Extra Strength Caplets (100 ct) - $13.49..."
171
+ 6. User picks one -> add to cart with the item's `id`, `menuId`, and `unitAmount`