@vellumai/assistant 0.10.1-dev.202606241504.b2eba1a → 0.10.1-dev.202606241513.0ccab68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.10.1-dev.202606241504.b2eba1a",
3
+ "version": "0.10.1-dev.202606241513.0ccab68",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -10,6 +10,7 @@ let sendMessageError: Error | null = null;
10
10
  let providerResolves = true;
11
11
  let providerSupportsWeb = false;
12
12
  let streamDeltas: string[] = [];
13
+ let streamEvents: Array<Record<string, unknown>> = [];
13
14
 
14
15
  const fakeProvider = {
15
16
  name: "mock-advisor-provider",
@@ -20,9 +21,11 @@ const fakeProvider = {
20
21
  sendMessageArgs = { messages, options } as Record<string, unknown>;
21
22
  if (sendMessageError) throw sendMessageError;
22
23
  const onEvent = (
23
- options as { onEvent?: (e: { type: string; text?: string }) => void }
24
+ options as { onEvent?: (e: Record<string, unknown>) => void }
24
25
  ).onEvent;
25
26
  if (onEvent) {
27
+ // Activity (search/thinking) streams before the final advice text.
28
+ for (const ev of streamEvents) onEvent(ev);
26
29
  for (const text of streamDeltas) onEvent({ type: "text_delta", text });
27
30
  }
28
31
  return {
@@ -70,6 +73,7 @@ beforeEach(() => {
70
73
  providerResolves = true;
71
74
  providerSupportsWeb = false;
72
75
  streamDeltas = [];
76
+ streamEvents = [];
73
77
  resetAdvisorStateForTests();
74
78
  });
75
79
 
@@ -141,6 +145,73 @@ describe("consultAdvisor", () => {
141
145
  expect(optionConfig().tool_choice).toEqual({ type: "auto" });
142
146
  });
143
147
 
148
+ test("streams web-search activity to onText, not just the final advice", async () => {
149
+ providerSupportsWeb = true;
150
+ streamEvents = [
151
+ { type: "server_tool_start", name: "web_search", toolUseId: "s1", input: {} },
152
+ {
153
+ type: "server_tool_complete",
154
+ toolUseId: "s1",
155
+ isError: false,
156
+ resolvedInput: { query: "vellum streaming" },
157
+ },
158
+ ];
159
+ streamDeltas = ["Here is ", "the advice."];
160
+ const chunks: string[] = [];
161
+
162
+ await consultAdvisor({
163
+ systemPrompt: null,
164
+ messages: [userMsg("hi")],
165
+ onText: (c) => chunks.push(c),
166
+ });
167
+
168
+ const joined = chunks.join("");
169
+ // The drawer isn't silent during the search prefix...
170
+ expect(joined).toContain("Searching the web");
171
+ expect(joined).toContain("Searched: vellum streaming");
172
+ // ...and the advice text still streams.
173
+ expect(joined).toContain("Here is the advice.");
174
+ });
175
+
176
+ test("surfaces a failure note (not 'Searched') when a web search errors", async () => {
177
+ providerSupportsWeb = true;
178
+ streamEvents = [
179
+ { type: "server_tool_start", name: "web_search", toolUseId: "s1", input: {} },
180
+ {
181
+ type: "server_tool_complete",
182
+ toolUseId: "s1",
183
+ isError: true,
184
+ errorCode: "query_too_long",
185
+ resolvedInput: { query: "an overly long query" },
186
+ },
187
+ ];
188
+ streamDeltas = ["Proceeding without search."];
189
+ const chunks: string[] = [];
190
+
191
+ await consultAdvisor({
192
+ systemPrompt: null,
193
+ messages: [userMsg("hi")],
194
+ onText: (c) => chunks.push(c),
195
+ });
196
+
197
+ const joined = chunks.join("");
198
+ expect(joined).toContain("Web search failed");
199
+ expect(joined).not.toContain("🔎 Searched:");
200
+ // The consult still continues and streams its guidance.
201
+ expect(joined).toContain("Proceeding without search.");
202
+ });
203
+
204
+ test("streams the model's reasoning summary to onText", async () => {
205
+ streamEvents = [{ type: "thinking_delta", thinking: "weighing tradeoffs" }];
206
+ const chunks: string[] = [];
207
+ await consultAdvisor({
208
+ systemPrompt: null,
209
+ messages: [userMsg("hi")],
210
+ onText: (c) => chunks.push(c),
211
+ });
212
+ expect(chunks.join("")).toContain("weighing tradeoffs");
213
+ });
214
+
144
215
  test("embeds the runtime context in the advisor system prompt", async () => {
145
216
  await consultAdvisor({
146
217
  systemPrompt: "You are a coding agent.",
@@ -78,11 +78,11 @@ export interface ConsultParams {
78
78
  runtimeContext?: string | null;
79
79
  signal?: AbortSignal;
80
80
  /**
81
- * Optional sink for the advisor's generated text as it streams. Each call
82
- * receives an incremental chunk (a provider `text_delta`). Wiring this to the
83
- * tool's `onOutput` surfaces the consult live as `tool_output_chunk` while the
84
- * advisor model is still generating; the complete guidance is still returned
85
- * as the resolved string.
81
+ * Optional sink for the advisor's live activity as it generates: incremental
82
+ * advice text, the reasoning summary (when surfaced), and a note per web
83
+ * search. Wiring this to the tool's `onOutput` surfaces the consult live as
84
+ * `tool_output_chunk` while the advisor is still working; the complete
85
+ * guidance is still returned as the resolved string. See `advisorActivitySink`.
86
86
  */
87
87
  onText?: (chunk: string) => void;
88
88
  }
@@ -93,6 +93,55 @@ function withTimeout(signal: AbortSignal | undefined, ms: number): AbortSignal {
93
93
  return signal ? AbortSignal.any([signal, timeout]) : timeout;
94
94
  }
95
95
 
96
+ /**
97
+ * Build the streaming sink for a consult: forward the advisor's live activity
98
+ * to `onText` so the tool-output drawer streams throughout the consult instead
99
+ * of sitting silent until the final advice lands.
100
+ *
101
+ * The consult searches the web (up to 5×) and reasons over full context before
102
+ * writing its guidance. Forwarding the visible advice text alone would leave
103
+ * the drawer blank for that whole prefix, so the sink also surfaces the
104
+ * reasoning summary (when the model emits one) and a one-line note per web
105
+ * search — a success note with the query, or a failure note when the search
106
+ * errors. The complete guidance is still returned by `consultAdvisor`; the
107
+ * renderer swaps it in once the tool result arrives.
108
+ */
109
+ function advisorActivitySink(
110
+ onText: (chunk: string) => void,
111
+ ): (event: ProviderEvent) => void {
112
+ return (event) => {
113
+ switch (event.type) {
114
+ case "text_delta":
115
+ if (event.text) onText(event.text);
116
+ break;
117
+ case "thinking_delta":
118
+ if (event.thinking) onText(event.thinking);
119
+ break;
120
+ case "server_tool_start":
121
+ if (event.name === "web_search") onText("\n🔎 Searching the web…\n");
122
+ break;
123
+ case "server_tool_complete": {
124
+ const rawQuery = event.resolvedInput?.["query"];
125
+ const query = typeof rawQuery === "string" ? rawQuery.trim() : "";
126
+ if (event.isError) {
127
+ // A failed search (e.g. `query_too_long`, `max_uses_exceeded`) must
128
+ // not be announced as a success — the advisor proceeds without it.
129
+ onText(
130
+ query
131
+ ? `\n⚠️ Web search failed: ${query}\n`
132
+ : "\n⚠️ Web search failed.\n",
133
+ );
134
+ } else if (query) {
135
+ onText(`\n🔎 Searched: ${query}\n`);
136
+ }
137
+ break;
138
+ }
139
+ default:
140
+ break;
141
+ }
142
+ };
143
+ }
144
+
96
145
  /**
97
146
  * Returns the advisor's guidance text, or a short benign notice when the
98
147
  * advisor can't run. Callers should surface the string as a non-error tool
@@ -131,14 +180,10 @@ export async function consultAdvisor(params: ConsultParams): Promise<string> {
131
180
  params.runtimeContext,
132
181
  ),
133
182
  ...(webEnabled ? { tools: [ADVISOR_WEB_SEARCH_TOOL] } : {}),
134
- // Forward the model's visible text deltas to the caller's sink so the
135
- // guidance streams live. Other event types (thinking, usage) ride their
136
- // own channels and are intentionally not surfaced as tool output.
137
- onEvent: onText
138
- ? (event: ProviderEvent) => {
139
- if (event.type === "text_delta" && event.text) onText(event.text);
140
- }
141
- : undefined,
183
+ // Stream the consult's activity live (advice text, reasoning summary, and a
184
+ // note per web search) so the drawer isn't blank while the advisor searches
185
+ // and reasons before writing its guidance. See `advisorActivitySink`.
186
+ onEvent: onText ? advisorActivitySink(onText) : undefined,
142
187
  config: {
143
188
  callSite: ADVISOR_CALL_SITE,
144
189
  ...override,
@@ -10,6 +10,7 @@
10
10
  * is a `Tool` (`Required<ToolDefinition>`).
11
11
  */
12
12
 
13
+ import { resolveExecutionTarget } from "./execution-target.js";
13
14
  import type {
14
15
  RiskLevel,
15
16
  Tool,
@@ -30,7 +31,10 @@ import type {
30
31
  * are rejected at the JSON-schema layer.
31
32
  * - `executionTarget` defaults to `sandbox` — author-supplied tool code
32
33
  * runs in the assistant container by default; opt in to `host` when
33
- * the tool proxies work to the connected client.
34
+ * the tool proxies work to the connected client. The name-prefix
35
+ * heuristic (`host_*` / `computer_use_*` resolves to host) is applied
36
+ * by `resolveExecutionTarget` in `finalizeTool`, so a tool named
37
+ * `host_my_thing` defaults to host even without an explicit field.
34
38
  * - `category` defaults to empty — Slack channel `allowedToolCategories`
35
39
  * policy denies uncategorized tools when a category allow-list is set,
36
40
  * which is the correct deny-by-default for tools the author didn't
@@ -90,7 +94,8 @@ export function finalizeTool(tool: ToolDefinition, defaultName = ""): Tool {
90
94
  content: `tool ${name} has no execute implementation`,
91
95
  isError: true,
92
96
  });
93
- const executionTarget = tool.executionTarget ?? TOOL_DEFAULTS.executionTarget;
97
+ const executionTarget =
98
+ tool.executionTarget ?? resolveExecutionTarget({ name });
94
99
  const category = tool.category ?? TOOL_DEFAULTS.category;
95
100
  const exclusive = tool.exclusive ?? false;
96
101
  return {