@vellumai/assistant 0.12.3 → 0.12.4-dev.202609231715.8da971c

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 (229) hide show
  1. package/Dockerfile +7 -0
  2. package/README.md +12 -12
  3. package/docker/mousepad/90-vellum.gschema.override +4 -0
  4. package/node_modules/@vellumai/avatar-manifest/src/__tests__/notification-avatar.test.ts +48 -4
  5. package/node_modules/@vellumai/avatar-manifest/src/notification-avatar.ts +12 -8
  6. package/openapi.yaml +97 -4
  7. package/package.json +1 -1
  8. package/src/__tests__/approval-routes-http.test.ts +4 -2
  9. package/src/__tests__/call-routes-http.test.ts +4 -2
  10. package/src/__tests__/channel-readiness-discord.test.ts +8 -0
  11. package/src/__tests__/channel-readiness-slack-remote.test.ts +8 -0
  12. package/src/__tests__/config-loader-backfill.test.ts +1 -0
  13. package/src/__tests__/conversation-pairing.test.ts +10 -0
  14. package/src/__tests__/conversation-resurface-done.test.ts +289 -0
  15. package/src/__tests__/default-profile-catalog-fallback.test.ts +1 -0
  16. package/src/__tests__/gemini-provider.test.ts +31 -0
  17. package/src/__tests__/inference-profile-validation-jev.test.ts +17 -0
  18. package/src/__tests__/job-handler-registration-guard.test.ts +1 -0
  19. package/src/__tests__/llm-catalog-parity.test.ts +4 -0
  20. package/src/__tests__/llm-resolver-override-or-default.test.ts +43 -0
  21. package/src/__tests__/openai-responses-prompt-cache.test.ts +3 -1
  22. package/src/__tests__/platform-callback-registration.test.ts +46 -1
  23. package/src/__tests__/plugin-api-model-profiles.test.ts +7 -0
  24. package/src/__tests__/plugin-import-boundary-guard.test.ts +3 -0
  25. package/src/__tests__/pricing.test.ts +33 -0
  26. package/src/__tests__/provider-error-scenarios.test.ts +46 -0
  27. package/src/__tests__/provider-platform-proxy-integration.test.ts +45 -15
  28. package/src/__tests__/retry-fallback-escalation.test.ts +22 -0
  29. package/src/__tests__/runtime-attachment-metadata.test.ts +4 -2
  30. package/src/__tests__/scaffold-managed-skill-tool.test.ts +116 -66
  31. package/src/__tests__/secret-routes-platform-proxy.test.ts +1 -0
  32. package/src/__tests__/send-endpoint-busy.test.ts +4 -2
  33. package/src/__tests__/skill-load-inline-command.test.ts +35 -0
  34. package/src/__tests__/skill-load-tool.test.ts +42 -11
  35. package/src/__tests__/skill-tool-factory.test.ts +50 -2
  36. package/src/__tests__/steer-on-enqueue-question.test.ts +265 -34
  37. package/src/__tests__/validate-input.test.ts +73 -0
  38. package/src/__tests__/workspace-migration-159-rename-colliding-jev-profile-name.test.ts +197 -0
  39. package/src/api/ask-question-tool.ts +50 -0
  40. package/src/api/events/tool-result.ts +11 -0
  41. package/src/api/index.ts +7 -0
  42. package/src/api/requests/dictation.ts +2 -2
  43. package/src/api/responses/home.ts +27 -0
  44. package/src/avatar/notification-avatar.test.ts +42 -34
  45. package/src/avatar/notification-avatar.ts +1 -0
  46. package/src/calls/__tests__/call-controller.test.ts +18 -0
  47. package/src/calls/__tests__/voice-control-protocol.test.ts +6 -1
  48. package/src/calls/__tests__/voice-leg-coordinator.test.ts +42 -0
  49. package/src/calls/__tests__/voice-session-bridge.test.ts +97 -4
  50. package/src/calls/__tests__/voice-triage-escalate.test.ts +69 -11
  51. package/src/calls/call-controller.ts +3 -1
  52. package/src/calls/voice-control-protocol.ts +9 -4
  53. package/src/calls/voice-escalation-judge.ts +7 -6
  54. package/src/calls/voice-leg-coordinator.ts +15 -4
  55. package/src/calls/voice-screen-annotation.ts +44 -0
  56. package/src/calls/voice-session-bridge.ts +50 -20
  57. package/src/calls/voice-triage-escalate.ts +61 -26
  58. package/src/cli/commands/__tests__/plugins.test.ts +29 -1
  59. package/src/cli/commands/channel-verification-sessions.help.ts +12 -2
  60. package/src/cli/commands/oauth/index.help.ts +8 -2
  61. package/src/cli/commands/oauth/request.test.ts +32 -0
  62. package/src/cli/commands/platform/index.help.ts +2 -1
  63. package/src/cli/commands/platform/index.ts +8 -2
  64. package/src/cli/commands/plugins.ts +16 -0
  65. package/src/cli/lib/__tests__/inspect-plugin.test.ts +29 -0
  66. package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +92 -2
  67. package/src/cli/lib/__tests__/plugin-catalog-local.test.ts +15 -0
  68. package/src/cli/lib/__tests__/plugin-catalog-platform.test.ts +66 -2
  69. package/src/cli/lib/__tests__/plugin-catalog-resolve.test.ts +21 -0
  70. package/src/cli/lib/__tests__/plugin-catalog-visibility.test.ts +65 -0
  71. package/src/cli/lib/__tests__/plugin-details.test.ts +43 -0
  72. package/src/cli/lib/__tests__/plugins-install-offline.test.ts +26 -0
  73. package/src/cli/lib/bundled-marketplace.json +4 -4
  74. package/src/cli/lib/inspect-plugin.ts +5 -0
  75. package/src/cli/lib/plugin-catalog-cache.ts +41 -4
  76. package/src/cli/lib/plugin-catalog-local.ts +9 -0
  77. package/src/cli/lib/plugin-catalog-platform.ts +48 -9
  78. package/src/cli/lib/plugin-catalog-visibility.ts +41 -0
  79. package/src/cli/lib/plugin-details.ts +10 -7
  80. package/src/cli/lib/search-plugins.ts +2 -0
  81. package/src/config/__tests__/default-profile-catalog.test.ts +61 -1
  82. package/src/config/__tests__/jev-managed-profile.test.ts +82 -0
  83. package/src/config/__tests__/platform-identity.test.ts +59 -0
  84. package/src/config/__tests__/sync-gated-profiles.test.ts +71 -0
  85. package/src/config/bundled-skills/screen-annotation/SKILL.md +6 -3
  86. package/src/config/call-site-defaults.ts +17 -11
  87. package/src/config/default-profile-catalog.ts +118 -19
  88. package/src/config/default-profile-names.ts +69 -0
  89. package/src/config/feature-flag-registry.json +25 -9
  90. package/src/config/inference-profile-validation.ts +7 -6
  91. package/src/config/llm-resolver.ts +16 -0
  92. package/src/config/platform-identity.ts +22 -5
  93. package/src/config/profile-text-generation.test.ts +9 -0
  94. package/src/config/schemas/call-site-catalog.ts +8 -1
  95. package/src/config/schemas/llm.ts +70 -9
  96. package/src/config/sidebar-done-gate.ts +27 -0
  97. package/src/config/sync-gated-profiles.ts +96 -44
  98. package/src/daemon/__tests__/auto-profile-router.test.ts +228 -0
  99. package/src/daemon/auto-profile-router.ts +220 -0
  100. package/src/daemon/conversation-agent-loop.ts +77 -4
  101. package/src/daemon/conversation-slash.ts +2 -2
  102. package/src/daemon/conversation-turn-finalize.ts +12 -0
  103. package/src/daemon/dictation-text-processing.ts +4 -4
  104. package/src/daemon/handlers/__tests__/conversation-history-search.test.ts +61 -0
  105. package/src/daemon/handlers/config-channels.ts +3 -1
  106. package/src/daemon/handlers/conversation-history.ts +11 -1
  107. package/src/daemon/handlers/conversations.ts +118 -10
  108. package/src/daemon/pkb-reminder-builder.test.ts +10 -3
  109. package/src/daemon/pkb-reminder-builder.ts +1 -1
  110. package/src/desktop/desktop-browser-endpoint.ts +1 -0
  111. package/src/home/feed-types.ts +2 -0
  112. package/src/inbound/platform-callback-registration.ts +19 -6
  113. package/src/ipc/routes/__tests__/conversation-sync-ipc-routes.test.ts +49 -1
  114. package/src/ipc/routes/conversation-sync-ipc-routes.ts +38 -2
  115. package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +27 -0
  116. package/src/live-voice/__tests__/live-voice-triage-escalate.test.ts +37 -1
  117. package/src/live-voice/__tests__/live-voice-vad.test.ts +34 -2
  118. package/src/live-voice/__tests__/protocol.test.ts +22 -0
  119. package/src/live-voice/continuation-judge.ts +1 -1
  120. package/src/live-voice/live-voice-session.ts +17 -14
  121. package/src/live-voice/protocol.ts +16 -5
  122. package/src/messaging/providers/gmail/client.ts +4 -0
  123. package/src/notifications/README.md +11 -3
  124. package/src/notifications/__tests__/assistant-reply-producer.test.ts +13 -0
  125. package/src/notifications/__tests__/home-feed-side-effect.test.ts +87 -3
  126. package/src/notifications/conversation-pairing.ts +23 -8
  127. package/src/notifications/home-feed-mirror.ts +39 -0
  128. package/src/notifications/home-feed-side-effect.ts +46 -19
  129. package/src/oauth/AGENTS.md +9 -1
  130. package/src/oauth/byo-connection.test.ts +28 -0
  131. package/src/permissions/question-prompter.ts +14 -4
  132. package/src/persistence/conversation-crud.ts +116 -3
  133. package/src/persistence/conversation-queries.ts +48 -3
  134. package/src/persistence/conversation-types.ts +6 -2
  135. package/src/persistence/embeddings/__tests__/embedding-local-lifecycle.test.ts +228 -32
  136. package/src/persistence/embeddings/embedding-backend-shutdown.test.ts +47 -0
  137. package/src/persistence/embeddings/embedding-backend.ts +23 -41
  138. package/src/persistence/embeddings/embedding-gemini.test.ts +17 -0
  139. package/src/persistence/embeddings/embedding-gemini.ts +3 -1
  140. package/src/persistence/embeddings/embedding-local.ts +72 -17
  141. package/src/persistence/embeddings/embedding-types.ts +0 -19
  142. package/src/persistence/jobs-store.ts +229 -0
  143. package/src/persistence/migrations/383-normalize-opencode-host-connections.ts +44 -0
  144. package/src/persistence/migrations/__tests__/383-normalize-opencode-host-connections.test.ts +102 -0
  145. package/src/persistence/steps.ts +12 -0
  146. package/src/platform/sync-avatar.test.ts +29 -0
  147. package/src/plugin-api/model-profiles.ts +5 -3
  148. package/src/plugins/defaults/memory/AGENTS.md +5 -3
  149. package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +2 -0
  150. package/src/plugins/defaults/memory/__tests__/skill-update-receipt-boundary-guard.test.ts +45 -0
  151. package/src/plugins/defaults/memory/__tests__/skill-update-receipt-job.test.ts +580 -0
  152. package/src/plugins/defaults/memory/graph/tools.ts +9 -5
  153. package/src/plugins/defaults/memory/hooks/conversation-deleted.ts +4 -0
  154. package/src/plugins/defaults/memory/job-handlers.ts +8 -2
  155. package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +5 -0
  156. package/src/plugins/defaults/memory/skill-update-receipt-job.ts +334 -0
  157. package/src/plugins/defaults/memory/substrate/skill-content.ts +1 -1
  158. package/src/plugins/defaults/memory/tools.test.ts +17 -0
  159. package/src/plugins/defaults/memory/v3/__tests__/render-injection.test.ts +3 -0
  160. package/src/providers/__tests__/connection-model-compat.test.ts +2 -0
  161. package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
  162. package/src/providers/anthropic/client.ts +2 -2
  163. package/src/providers/gemini/client.ts +17 -1
  164. package/src/providers/inference/auth.ts +25 -0
  165. package/src/providers/jev/ask.test.ts +66 -0
  166. package/src/{calls/typesafe-noul.ts → providers/jev/ask.ts} +75 -36
  167. package/src/providers/malformed-tool-call.ts +55 -0
  168. package/src/providers/model-catalog.ts +257 -4
  169. package/src/providers/openai/__tests__/chat-completions-malformed-tool-call.test.ts +105 -0
  170. package/src/providers/openai/chat-completions-provider.ts +30 -0
  171. package/src/providers/openai/codex-models.ts +2 -0
  172. package/src/providers/platform-proxy/constants.ts +5 -0
  173. package/src/providers/retry.ts +68 -36
  174. package/src/providers/search-provider-catalog.ts +10 -0
  175. package/src/providers/vellum-model-routing.test.ts +1 -0
  176. package/src/runtime/__tests__/agent-wake-archived-gate.test.ts +90 -0
  177. package/src/runtime/__tests__/question-resolution.test.ts +32 -0
  178. package/src/runtime/agent-wake.ts +9 -2
  179. package/src/runtime/auth/__tests__/middleware.test.ts +138 -0
  180. package/src/runtime/auth/middleware.ts +15 -11
  181. package/src/runtime/middleware/auth.ts +7 -1
  182. package/src/runtime/pending-interactions.ts +8 -8
  183. package/src/runtime/question-resolution.ts +54 -8
  184. package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +146 -0
  185. package/src/runtime/routes/__tests__/dictation-processing.test.ts +174 -0
  186. package/src/runtime/routes/__tests__/global-search-routes.test.ts +74 -1
  187. package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +60 -0
  188. package/src/runtime/routes/__tests__/llm-call-sites-routes.test.ts +16 -1
  189. package/src/runtime/routes/__tests__/oauth-proxy-routes.test.ts +61 -3
  190. package/src/runtime/routes/__tests__/plugins-routes.test.ts +8 -0
  191. package/src/runtime/routes/conversation-list-routes.ts +16 -14
  192. package/src/runtime/routes/conversation-query-routes.ts +4 -0
  193. package/src/runtime/routes/conversation-routes.ts +4 -2
  194. package/src/runtime/routes/diagnostics-routes.ts +66 -229
  195. package/src/runtime/routes/global-search-routes.ts +22 -7
  196. package/src/runtime/routes/inference-provider-connection-routes.ts +25 -8
  197. package/src/runtime/routes/llm-call-sites-routes.ts +19 -10
  198. package/src/runtime/routes/oauth-proxy-passthrough.test.ts +32 -0
  199. package/src/runtime/routes/platform-routes.ts +6 -1
  200. package/src/runtime/routes/plugins-routes.ts +5 -2
  201. package/src/runtime/sync/documents-sidecar-publish.test.ts +50 -4
  202. package/src/runtime/sync/resource-sync-events.ts +11 -0
  203. package/src/runtime/sync/worker-daemon-notify.test.ts +30 -0
  204. package/src/runtime/sync/worker-daemon-notify.ts +44 -0
  205. package/src/runtime/verification-outbound-actions.ts +2 -2
  206. package/src/skills/validate-input.ts +75 -11
  207. package/src/telegram/__tests__/webhook-health.test.ts +8 -0
  208. package/src/tools/ask-question/ask-question-tool.test.ts +38 -0
  209. package/src/tools/ask-question/ask-question-tool.ts +12 -1
  210. package/src/tools/network/__tests__/web-fetch-firecrawl.test.ts +28 -1
  211. package/src/tools/network/__tests__/web-fetch-metadata.test.ts +34 -0
  212. package/src/tools/network/__tests__/web-fetch-tinyfish.test.ts +35 -1
  213. package/src/tools/network/__tests__/web-search.test.ts +96 -0
  214. package/src/tools/network/web-fetch.ts +30 -9
  215. package/src/tools/network/web-search.ts +235 -4
  216. package/src/tools/skills/execute.ts +1 -1
  217. package/src/tools/skills/format-input-schema.ts +15 -0
  218. package/src/tools/skills/load.ts +15 -43
  219. package/src/tools/skills/scaffold-managed.ts +86 -71
  220. package/src/tools/skills/skill-tool-factory.ts +2 -1
  221. package/src/tools/workflows/manage-workflows.ts +4 -2
  222. package/src/util/oauth-request-body.test.ts +5 -1
  223. package/src/util/worker-pipe.test.ts +146 -0
  224. package/src/util/worker-pipe.ts +49 -0
  225. package/src/workspace/migrations/158-repoint-opencode-host-provider-fragments.ts +163 -0
  226. package/src/workspace/migrations/159-rename-colliding-jev-profile-name.ts +344 -0
  227. package/src/workspace/migrations/__tests__/158-repoint-opencode-host-provider-fragments.test.ts +188 -0
  228. package/src/workspace/migrations/registry.ts +4 -0
  229. package/src/runtime/routes/__tests__/dictation-cleanup-guard.test.ts +0 -107
@@ -243,6 +243,15 @@ export function toAnsweredQuestion(
243
243
  };
244
244
  }
245
245
 
246
+ /**
247
+ * Model-facing note prepended when the user answered by typing in the chat
248
+ * instead of using the card. The text lands as free text on the first
249
+ * question and every other question reads as skipped, so the model is told
250
+ * plainly what happened and left to map the reply onto the batch itself.
251
+ */
252
+ const CHAT_REPLY_PREAMBLE =
253
+ "The user replied in the chat instead of using the question card, so their message is recorded as free text on the first question below and the remaining questions are unanswered. Read their reply as the answer to whichever questions it covers, and ask again only for what it genuinely leaves open.";
254
+
246
255
  // ── Tool ────────────────────────────────────────────────────────────
247
256
 
248
257
  /**
@@ -389,7 +398,9 @@ export const askQuestionTool = {
389
398
 
390
399
  switch (result.overall) {
391
400
  case "completed": {
392
- let content = lines.join("\n");
401
+ let content = result.answeredInChat
402
+ ? [CHAT_REPLY_PREAMBLE, ...lines].join("\n")
403
+ : lines.join("\n");
393
404
  if (desktopHelp) {
394
405
  const entry = result.entries[0];
395
406
  if (entry?.decision === "free_text") {
@@ -1,4 +1,12 @@
1
- import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ mock,
7
+ spyOn,
8
+ test,
9
+ } from "bun:test";
2
10
 
3
11
  import { setConfig } from "../../../__tests__/helpers/set-config.js";
4
12
 
@@ -133,6 +141,25 @@ describe("executeFirecrawlScrape", () => {
133
141
  expect(result.status).toContain("truncated");
134
142
  });
135
143
 
144
+ test("carries the provider's warning and a start past the end in metadata", async () => {
145
+ spyOn(globalThis, "fetch").mockResolvedValue(
146
+ scrapeResponse({
147
+ success: true,
148
+ warning: "The page was served from cache.",
149
+ data: { markdown: "abcdefghij", metadata: { statusCode: 200 } },
150
+ }),
151
+ );
152
+
153
+ const result = await executeFirecrawlScrape(
154
+ { url: "https://example.com", start_index: 50 },
155
+ { apiKey: "fc-key" },
156
+ );
157
+ expect(result.isError).toBe(false);
158
+ const meta = result.activityMetadata?.webFetch;
159
+ expect(meta?.providerWarning).toBe("The page was served from cache.");
160
+ expect(meta?.startIndexPastEnd).toBe(true);
161
+ });
162
+
136
163
  test("empty markdown yields a no-content marker, not an error", async () => {
137
164
  globalThis.fetch = (async () =>
138
165
  scrapeResponse({ success: true, data: { markdown: "" } })) as any;
@@ -130,6 +130,40 @@ describe("web_fetch activityMetadata", () => {
130
130
  expect(meta?.charCount).toBe(maxChars);
131
131
  });
132
132
 
133
+ test("flags a start_index past the end of a page it downloaded whole", async () => {
134
+ const result = await executeWithMockFetch(
135
+ { url: "https://example.com/short", start_index: 500 },
136
+ {
137
+ requestExecutor: async () =>
138
+ new Response("x".repeat(100), {
139
+ status: 200,
140
+ headers: { "content-type": "text/plain; charset=utf-8" },
141
+ }),
142
+ },
143
+ );
144
+ expect(result.isError).toBe(false);
145
+ expect(result.activityMetadata?.webFetch?.startIndexPastEnd).toBe(true);
146
+ });
147
+
148
+ test("does not call a start_index past a capped download the end of the page", async () => {
149
+ // Over the 2 MB download cap: only a prefix is read, so an offset past it
150
+ // may still be inside the page.
151
+ const result = await executeWithMockFetch(
152
+ { url: "https://example.com/huge", start_index: 2_500_000 },
153
+ {
154
+ requestExecutor: async () =>
155
+ new Response("x".repeat(3_000_000), {
156
+ status: 200,
157
+ headers: { "content-type": "text/plain; charset=utf-8" },
158
+ }),
159
+ },
160
+ );
161
+ expect(result.isError).toBe(false);
162
+ const meta = result.activityMetadata?.webFetch;
163
+ expect(meta?.truncated).toBe(true);
164
+ expect(meta?.startIndexPastEnd).toBe(false);
165
+ });
166
+
133
167
  test("populates errorMessage and status on a 404 response", async () => {
134
168
  globalThis.fetch = (async () =>
135
169
  new Response("<title>Not Found</title>not here", {
@@ -1,4 +1,12 @@
1
- import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ mock,
7
+ spyOn,
8
+ test,
9
+ } from "bun:test";
2
10
 
3
11
  import { setConfig } from "../../../__tests__/helpers/set-config.js";
4
12
 
@@ -101,6 +109,32 @@ describe("executeTinyfishFetch", () => {
101
109
  );
102
110
  });
103
111
 
112
+ test("an empty upstream title is no title", async () => {
113
+ spyOn(globalThis, "fetch").mockResolvedValue(
114
+ fetchResponse({
115
+ results: [
116
+ {
117
+ url: "https://example.com/",
118
+ final_url: "https://example.com/",
119
+ title: " ",
120
+ text: "# Example",
121
+ format: "markdown",
122
+ },
123
+ ],
124
+ errors: [],
125
+ }),
126
+ );
127
+
128
+ const result = await executeTinyfishFetch(
129
+ { url: "https://example.com" },
130
+ { apiKey: "tf_test" },
131
+ );
132
+
133
+ expect(result.isError).toBe(false);
134
+ expect(result.activityMetadata?.webFetch?.title).toBeUndefined();
135
+ expect(result.content).not.toContain("Title:");
136
+ });
137
+
104
138
  test("uses a custom API base and applies character windows", async () => {
105
139
  seedWebFetch("tinyfish", "https://fetch.example.com/api/");
106
140
  let capturedUrl = "";
@@ -12,6 +12,7 @@ let mockKeenableSecureKey: string | undefined;
12
12
  let mockFastcrwSecureKey: string | undefined;
13
13
  let mockSearxngSecureKey: string | undefined;
14
14
  let mockTinyfishSecureKey: string | undefined;
15
+ let mockExaSecureKey: string | undefined;
15
16
  let mockManagedSearchProxyResult: any;
16
17
  let mockManagedSearchAvailable = true;
17
18
  let mockManagedSearchProxyCalls: Array<{
@@ -65,6 +66,9 @@ mock.module("../../../security/secure-keys.js", () => ({
65
66
  if (provider === "tinyfish") {
66
67
  return mockTinyfishSecureKey;
67
68
  }
69
+ if (provider === "exa") {
70
+ return mockExaSecureKey;
71
+ }
68
72
  return undefined;
69
73
  },
70
74
  }));
@@ -111,6 +115,7 @@ describe("web_search tool", () => {
111
115
  mockFastcrwSecureKey = undefined;
112
116
  mockSearxngSecureKey = undefined;
113
117
  mockTinyfishSecureKey = undefined;
118
+ mockExaSecureKey = undefined;
114
119
  mockManagedSearchProxyCalls = [];
115
120
  mockManagedSearchAvailable = true;
116
121
  mockManagedSearchProxyResult = {
@@ -1345,6 +1350,97 @@ describe("web_search tool", () => {
1345
1350
  },
1346
1351
  );
1347
1352
 
1353
+ // ---- Exa provider ------------------------------------------------------
1354
+
1355
+ test("Exa search posts the recommended request and maps freshness", async () => {
1356
+ seedWebSearch("your-own", "exa");
1357
+ mockExaSecureKey = "exa_test";
1358
+ let capturedUrl = "";
1359
+ let capturedInit: RequestInit | undefined;
1360
+ globalThis.fetch = (async (url: string, init?: RequestInit) => {
1361
+ capturedUrl = url;
1362
+ capturedInit = init;
1363
+ return new Response(
1364
+ JSON.stringify({
1365
+ requestId: "r1",
1366
+ results: [
1367
+ {
1368
+ title: "Exa Result",
1369
+ url: "https://example.com/exa",
1370
+ publishedDate: "2026-09-18T00:00:00.000Z",
1371
+ highlights: ["Fresh from Exa"],
1372
+ },
1373
+ ],
1374
+ }),
1375
+ { status: 200, headers: { "content-type": "application/json" } },
1376
+ );
1377
+ }) as any;
1378
+
1379
+ const result = await execute({
1380
+ query: "fresh tools",
1381
+ freshness: "pw",
1382
+ count: 5,
1383
+ });
1384
+
1385
+ expect(result.isError).toBe(false);
1386
+ expect(capturedUrl).toBe("https://api.exa.ai/search");
1387
+ expect(capturedInit?.method).toBe("POST");
1388
+ const headers = new Headers(capturedInit?.headers);
1389
+ expect(headers.get("x-api-key")).toBe("exa_test");
1390
+ const body = JSON.parse(String(capturedInit?.body));
1391
+ expect(body.query).toBe("fresh tools");
1392
+ expect(body.type).toBe("auto");
1393
+ expect(body.numResults).toBe(5);
1394
+ expect(body.contents.highlights).toBe(true);
1395
+ expect(typeof body.startPublishedDate).toBe("string");
1396
+ const delta = Date.now() - Date.parse(body.startPublishedDate);
1397
+ expect(delta).toBeGreaterThan(7 * 24 * 60 * 60 * 1000 - 60_000);
1398
+ expect(delta).toBeLessThan(7 * 24 * 60 * 60 * 1000 + 60_000);
1399
+ expect(result.content).toContain("Exa Result");
1400
+ expect(result.content).toContain("Fresh from Exa");
1401
+ expect(result.activityMetadata?.webSearch?.provider).toBe("exa");
1402
+ });
1403
+
1404
+ test("Exa omits the date filter without freshness and trims to count", async () => {
1405
+ seedWebSearch("your-own", "exa");
1406
+ mockExaSecureKey = "exa_test";
1407
+ let capturedInit: RequestInit | undefined;
1408
+ globalThis.fetch = (async (_url: string, init?: RequestInit) => {
1409
+ capturedInit = init;
1410
+ return new Response(
1411
+ JSON.stringify({
1412
+ results: [
1413
+ { title: "A", url: "https://a.example.com", highlights: ["a"] },
1414
+ { title: "B", url: "https://b.example.com", highlights: ["b"] },
1415
+ { title: "C", url: "https://c.example.com", highlights: ["c"] },
1416
+ ],
1417
+ }),
1418
+ { status: 200, headers: { "content-type": "application/json" } },
1419
+ );
1420
+ }) as any;
1421
+
1422
+ const result = await execute({ query: "test", count: 2 });
1423
+
1424
+ const body = JSON.parse(String(capturedInit?.body));
1425
+ expect(body.startPublishedDate).toBeUndefined();
1426
+ expect(result.content).toContain("A");
1427
+ expect(result.content).toContain("B");
1428
+ expect(result.content).not.toContain("https://c.example.com");
1429
+ expect(result.activityMetadata?.webSearch?.resultCount).toBe(2);
1430
+ });
1431
+
1432
+ test.each([401, 402, 403])("Exa handles %d access error", async (status) => {
1433
+ seedWebSearch("your-own", "exa");
1434
+ mockExaSecureKey = "exa_test";
1435
+ globalThis.fetch = (async () =>
1436
+ new Response(JSON.stringify({ error: "denied" }), { status })) as any;
1437
+
1438
+ const result = await execute({ query: "test" });
1439
+
1440
+ expect(result.isError).toBe(true);
1441
+ expect(result.activityMetadata?.webSearch?.provider).toBe("exa");
1442
+ });
1443
+
1348
1444
  // ---- Provider fallback --------------------------------------------------
1349
1445
 
1350
1446
  test("falls back from perplexity to brave when perplexity has no key", async () => {
@@ -58,6 +58,15 @@ const MAX_TIMEOUT_SECONDS = 60;
58
58
  const DEFAULT_MAX_CHARS = 12_000;
59
59
  const MAX_MAX_CHARS = 40_000;
60
60
  const MAX_DOWNLOAD_BYTES = 2_000_000;
61
+
62
+ /**
63
+ * The metadata this assistant writes. `startIndexPastEnd` is optional on the
64
+ * wire because older records lack it; every writer here sets it, which is how
65
+ * a reader tells this metadata carries every reader-facing warning.
66
+ */
67
+ type WrittenWebFetchMetadata = WebFetchMetadata & {
68
+ startIndexPastEnd: boolean;
69
+ };
61
70
  const MAX_REDIRECTS = 10;
62
71
 
63
72
  const TEXT_LIKE_CONTENT_TYPES = [
@@ -672,7 +681,8 @@ export async function executeWebFetch(
672
681
  redirectCount: meta.redirectCount ?? 0,
673
682
  durationMs: Date.now() - startedAt,
674
683
  errorMessage,
675
- },
684
+ startIndexPastEnd: false,
685
+ } satisfies WrittenWebFetchMetadata,
676
686
  },
677
687
  };
678
688
  };
@@ -1023,7 +1033,7 @@ export async function executeWebFetch(
1023
1033
  const truncated = body.truncated || safeEnd < processed.length;
1024
1034
  const parsedTitle = html ? parseHtmlTitle(body.text) : undefined;
1025
1035
  const finalDomain = extractDomain(currentUrl.href);
1026
- const meta: WebFetchMetadata = {
1036
+ const meta: WrittenWebFetchMetadata = {
1027
1037
  url: safeRequestedUrl,
1028
1038
  finalUrl: sanitizeUrlForOutput(currentUrl),
1029
1039
  provider: "default",
@@ -1038,6 +1048,9 @@ export async function executeWebFetch(
1038
1048
  redirectCount,
1039
1049
  durationMs: Date.now() - startedAt,
1040
1050
  mayRequireJavaScript: mayRequireJavaScript || undefined,
1051
+ // Past the end of the page only when the whole page was downloaded: past
1052
+ // a capped prefix, the page may still have content at that offset.
1053
+ startIndexPastEnd: !body.truncated && startIndex > processed.length,
1041
1054
  };
1042
1055
 
1043
1056
  if (!response.ok) {
@@ -1223,7 +1236,8 @@ function hostedScrapeErrorResult(
1223
1236
  redirectCount: 0,
1224
1237
  durationMs: Date.now() - startedAt,
1225
1238
  errorMessage,
1226
- },
1239
+ startIndexPastEnd: false,
1240
+ } satisfies WrittenWebFetchMetadata,
1227
1241
  },
1228
1242
  };
1229
1243
  }
@@ -1394,6 +1408,8 @@ export async function executeFirecrawlCompatScrape(
1394
1408
  );
1395
1409
  }
1396
1410
 
1411
+ // A provider can pass an empty upstream title through; empty is no title.
1412
+ const title = scrapeMeta.title?.trim() || undefined;
1397
1413
  const content = formatWebFetchOutput({
1398
1414
  requestedUrl: safeRequestedUrl,
1399
1415
  finalUrl,
@@ -1405,7 +1421,7 @@ export async function executeFirecrawlCompatScrape(
1405
1421
  startIndex: safeStart,
1406
1422
  endIndex: safeEnd,
1407
1423
  content: sliced,
1408
- title: scrapeMeta.title,
1424
+ title,
1409
1425
  description: scrapeMeta.description,
1410
1426
  notices,
1411
1427
  raw: false,
@@ -1413,7 +1429,7 @@ export async function executeFirecrawlCompatScrape(
1413
1429
  });
1414
1430
 
1415
1431
  const finalDomain = extractDomain(finalUrl);
1416
- const meta: WebFetchMetadata = {
1432
+ const meta: WrittenWebFetchMetadata = {
1417
1433
  url: safeRequestedUrl,
1418
1434
  finalUrl,
1419
1435
  provider: options.provider,
@@ -1422,11 +1438,13 @@ export async function executeFirecrawlCompatScrape(
1422
1438
  byteCount: bytesRead,
1423
1439
  charCount: sliced.length,
1424
1440
  truncated: safeEnd < processed.length,
1425
- title: scrapeMeta.title,
1441
+ title,
1426
1442
  domain: finalDomain,
1427
1443
  faviconUrl: faviconUrlForDomain(finalDomain),
1428
1444
  redirectCount: 0,
1429
1445
  durationMs: Date.now() - startedAt,
1446
+ startIndexPastEnd: startIndex > processed.length,
1447
+ providerWarning: warning || undefined,
1430
1448
  };
1431
1449
 
1432
1450
  return {
@@ -1670,6 +1688,8 @@ export async function executeTinyfishFetch(
1670
1688
  );
1671
1689
  }
1672
1690
 
1691
+ // A provider can pass an empty upstream title through; empty is no title.
1692
+ const title = page.title?.trim() || undefined;
1673
1693
  const content = formatWebFetchOutput({
1674
1694
  requestedUrl: safeRequestedUrl,
1675
1695
  finalUrl,
@@ -1681,14 +1701,14 @@ export async function executeTinyfishFetch(
1681
1701
  startIndex: safeStart,
1682
1702
  endIndex: safeEnd,
1683
1703
  content: sliced,
1684
- title: page.title ?? undefined,
1704
+ title,
1685
1705
  description: page.description ?? undefined,
1686
1706
  notices,
1687
1707
  raw: false,
1688
1708
  markdown: true,
1689
1709
  });
1690
1710
  const finalDomain = extractDomain(finalUrl);
1691
- const metadata: WebFetchMetadata = {
1711
+ const metadata: WrittenWebFetchMetadata = {
1692
1712
  url: safeRequestedUrl,
1693
1713
  finalUrl,
1694
1714
  provider: "tinyfish",
@@ -1697,11 +1717,12 @@ export async function executeTinyfishFetch(
1697
1717
  byteCount: bytesRead,
1698
1718
  charCount: sliced.length,
1699
1719
  truncated: safeEnd < processed.length,
1700
- title: page.title ?? undefined,
1720
+ title,
1701
1721
  domain: finalDomain,
1702
1722
  faviconUrl: faviconUrlForDomain(finalDomain),
1703
1723
  redirectCount: finalUrl === safeRequestedUrl ? 0 : 1,
1704
1724
  durationMs: Date.now() - startedAt,
1725
+ startIndexPastEnd: startIndex > processed.length,
1705
1726
  };
1706
1727
  return {
1707
1728
  content,