@vellumai/assistant 0.12.1-dev.202609151418.0cd4c71 → 0.12.1-dev.202609151617.4f8b2b2

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.
@@ -113,7 +113,7 @@ export async function buildSlackUserLabelMap(
113
113
  // that label directly; only queue a lookup when the label is missing,
114
114
  // empty, or ID-shaped. Mirrors the channel builder below.
115
115
  const [, embeddedLabel] = splitSlackLabel(match[0].slice(1, -1));
116
- const sanitizedEmbeddedLabel = sanitizeOptionalLabel(embeddedLabel);
116
+ const sanitizedEmbeddedLabel = sanitizeEmbeddedSlackLabel(embeddedLabel);
117
117
  if (sanitizedEmbeddedLabel && sanitizedEmbeddedLabel !== id) continue;
118
118
  if (seen.has(id)) continue;
119
119
  seen.add(id);
@@ -151,7 +151,7 @@ export async function buildSlackChannelLabelMap(
151
151
  for (const match of text.matchAll(SLACK_CHANNEL_REFERENCE_RE)) {
152
152
  const id = match[1];
153
153
  const [, embeddedLabel] = splitSlackLabel(match[0].slice(1, -1));
154
- const sanitizedEmbeddedLabel = sanitizeOptionalLabel(embeddedLabel);
154
+ const sanitizedEmbeddedLabel = sanitizeEmbeddedSlackLabel(embeddedLabel);
155
155
  if (sanitizedEmbeddedLabel && sanitizedEmbeddedLabel !== id) continue;
156
156
  if (!seen.has(id)) {
157
157
  seen.add(id);
@@ -192,9 +192,7 @@ function renderUserMention(
192
192
  // prefer it over a lookup, mirroring renderChannelReference. The embedded
193
193
  // label is Slack-sourced (part of the token), so entities decode before
194
194
  // sanitization; the caller-resolved label below is not.
195
- const embeddedLabel = sanitizeOptionalLabel(
196
- label === undefined ? undefined : decodeSlackHtmlEntities(label),
197
- );
195
+ const embeddedLabel = sanitizeEmbeddedSlackLabel(label);
198
196
  if (embeddedLabel && embeddedLabel !== id) {
199
197
  return `@${embeddedLabel}`;
200
198
  }
@@ -219,9 +217,7 @@ function renderChannelReference(
219
217
  );
220
218
  // The embedded label is Slack-sourced (part of the token), so entities
221
219
  // decode before sanitization; the caller-resolved label below is not.
222
- const embeddedLabel = sanitizeOptionalLabel(
223
- label === undefined ? undefined : decodeSlackHtmlEntities(label),
224
- );
220
+ const embeddedLabel = sanitizeEmbeddedSlackLabel(label);
225
221
  if (embeddedLabel && embeddedLabel !== channelId) {
226
222
  return `#${embeddedLabel}`;
227
223
  }
@@ -320,6 +316,15 @@ export function sanitizeSlackLabel(
320
316
  return sanitized || undefined;
321
317
  }
322
318
 
319
+ // Slack-sourced labels are decoded before validation in both lookup and render.
320
+ function sanitizeEmbeddedSlackLabel(
321
+ label: string | undefined,
322
+ ): string | undefined {
323
+ return sanitizeOptionalLabel(
324
+ label === undefined ? undefined : decodeSlackHtmlEntities(label),
325
+ );
326
+ }
327
+
323
328
  function sanitizeOptionalLabel(label: string | undefined): string | undefined {
324
329
  return sanitizeSlackLabel(label);
325
330
  }
@@ -0,0 +1,95 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, test } from "bun:test";
3
+ import {
4
+ buildSlackChannelLabelMap,
5
+ buildSlackUserLabelMap,
6
+ renderSlackTextForModel,
7
+ } from "./index.js";
8
+
9
+ describe("Slack embedded-label lookup parity", () => {
10
+ const cases = [
11
+ { id: "U123", prefix: "@", build: buildSlackUserLabelMap, mapKey: "userLabels" },
12
+ {
13
+ id: "C123",
14
+ prefix: "#",
15
+ build: buildSlackChannelLabelMap,
16
+ mapKey: "channelLabels",
17
+ },
18
+ ] as const;
19
+
20
+ for (const { id, prefix, build, mapKey } of cases) {
21
+ for (const label of ["<>", `<${id}>`, "< @# >"]) {
22
+ test(`${prefix} resolves label ${label} after Slack entity decoding`, async () => {
23
+ const text = `<${prefix}${id}|${label}>`;
24
+ const requested: string[] = [];
25
+ const labels = await build([text], async (value) => {
26
+ requested.push(value);
27
+ return "Example Name";
28
+ });
29
+ assert.deepEqual(requested, [id]);
30
+ assert.equal(
31
+ renderSlackTextForModel(text, { [mapKey]: labels }),
32
+ `${prefix}Example Name`,
33
+ );
34
+ });
35
+ }
36
+
37
+ for (const label of ["&lt;Example&gt;", "R&amp;D", "&amp;lt;&amp;gt;"]) {
38
+ test(`${prefix} keeps usable embedded label ${label} without lookup`, async () => {
39
+ const requested: string[] = [];
40
+ const text = `<${prefix}${id}|${label}>`;
41
+ const labels = await build([text], async (value) => {
42
+ requested.push(value);
43
+ return "Wrong Label";
44
+ });
45
+ assert.deepEqual(requested, []);
46
+ assert.deepEqual(labels, {});
47
+ const expected =
48
+ label === "&lt;Example&gt;"
49
+ ? "Example"
50
+ : label === "R&amp;D"
51
+ ? "R&D"
52
+ : "&lt;&gt;";
53
+ assert.equal(
54
+ renderSlackTextForModel(text, { [mapKey]: labels }),
55
+ `${prefix}${expected}`,
56
+ );
57
+ });
58
+ }
59
+
60
+ test(`${prefix} deduplicates required lookups across encoded and bare mentions`, async () => {
61
+ const requested: string[] = [];
62
+ const labels = await build(
63
+ [`<${prefix}${id}|&lt;&gt;>`, `<${prefix}${id}>`],
64
+ async (value) => {
65
+ requested.push(value);
66
+ return "Example";
67
+ },
68
+ );
69
+ assert.deepEqual(requested, [id]);
70
+ assert.deepEqual(labels, { [id]: "Example" });
71
+ });
72
+
73
+ test(`${prefix} does not decode caller-resolved entity text`, async () => {
74
+ const text = `<${prefix}${id}|&lt;&gt;>`;
75
+ const labels = await build([text], async () => "&lt;Example&gt;");
76
+ assert.equal(
77
+ renderSlackTextForModel(text, { [mapKey]: labels }),
78
+ `${prefix}&lt;Example&gt;`,
79
+ );
80
+ });
81
+
82
+ test(`${prefix} preserves unknown fallback after a failed required lookup`, async () => {
83
+ let attempts = 0;
84
+ const text = `<${prefix}${id}|&lt;&gt;>`;
85
+ const labels = await build([text], async () => {
86
+ attempts++;
87
+ throw new Error("unavailable");
88
+ });
89
+ assert.equal(attempts, 1);
90
+ assert.deepEqual(labels, {});
91
+ const expected = prefix === "@" ? "@unknown-user" : "#unknown-channel";
92
+ assert.equal(renderSlackTextForModel(text, { [mapKey]: labels }), expected);
93
+ });
94
+ }
95
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.12.1-dev.202609151418.0cd4c71",
3
+ "version": "0.12.1-dev.202609151617.4f8b2b2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -24,6 +24,7 @@ function proxyDouble() {
24
24
  recordAction,
25
25
  request,
26
26
  reset: () => {},
27
+ endTask: () => {},
27
28
  stepCount: 0,
28
29
  },
29
30
  };
@@ -30,6 +30,7 @@ function proxyDouble() {
30
30
  recordAction: () => {},
31
31
  request,
32
32
  reset: () => {},
33
+ endTask: () => {},
33
34
  stepCount: 0,
34
35
  },
35
36
  };
@@ -485,8 +485,12 @@ describe("surfaceProxyResolver — CU tool routing", () => {
485
485
  // Proxy state is clean after done
486
486
  expect(proxy.stepCount).toBe(0);
487
487
  expect(proxy.actionHistory).toHaveLength(0);
488
- // Only 2 messages sent to client (screenshot + click; done is terminal)
489
- expect(sentMessages).toHaveLength(2);
488
+ // screenshot + click, then done tells the client the task ended so the
489
+ // helper returns the pointer; done itself never reaches the client
490
+ expect(sentMessages).toHaveLength(3);
491
+ expect((sentMessages[2] as Record<string, unknown>).type).toBe(
492
+ "host_cu_cancel",
493
+ );
490
494
  });
491
495
  });
492
496
 
@@ -1232,6 +1232,38 @@ describe("HostCuProxy", () => {
1232
1232
  });
1233
1233
  });
1234
1234
 
1235
+ describe("endTask", () => {
1236
+ test("tells the desktop the task drove that it is over, once, then resets", async () => {
1237
+ setup();
1238
+
1239
+ const resultPromise = proxy.request(
1240
+ "computer_use_click",
1241
+ { element_id: 1 },
1242
+ "session-1",
1243
+ 1,
1244
+ );
1245
+ const requestId = (sentMessages[0] as Record<string, unknown>)
1246
+ .requestId as string;
1247
+ proxy.processObservation(requestId, { axTree: "Button [1]" });
1248
+ await resultPromise;
1249
+
1250
+ proxy.endTask("session-1");
1251
+ const cancels = sentMessages.filter(
1252
+ (m) => (m as Record<string, unknown>).type === "host_cu_cancel",
1253
+ ) as Array<Record<string, unknown>>;
1254
+ expect(cancels).toHaveLength(1);
1255
+ expect(cancels[0].conversationId).toBe("session-1");
1256
+ expect(cancels[0].requestId).not.toBe(requestId);
1257
+
1258
+ proxy.endTask("session-1");
1259
+ expect(
1260
+ sentMessages.filter(
1261
+ (m) => (m as Record<string, unknown>).type === "host_cu_cancel",
1262
+ ),
1263
+ ).toHaveLength(1);
1264
+ });
1265
+ });
1266
+
1235
1267
  describe("late resolve after abort", () => {
1236
1268
  test("resolve is a no-op after abort (entry already deleted)", async () => {
1237
1269
  setup();
@@ -35,6 +35,13 @@ The tree is walked to a limited depth to keep steps fast, and says when it was
35
35
  cut off. If the element you need is not in it, call `computer_use_observe` with
36
36
  `full_tree: true`.
37
37
 
38
+ ## Typing is not sending
39
+
40
+ Pressing enter in a chat, email or form usually sends or submits it, and that
41
+ cannot be taken back. Send only when the user asked you to send, post or
42
+ submit. When they asked you to type, write or draft something, type it and stop
43
+ before pressing enter; tell them it is ready to send.
44
+
38
45
  ## Batching known steps (macOS)
39
46
 
40
47
  When you already know the next few actions and none depends on seeing the
@@ -3180,7 +3180,7 @@ export async function surfaceProxyResolver(
3180
3180
  : typeof input.answer === "string"
3181
3181
  ? input.answer
3182
3182
  : "Task complete";
3183
- hostCuProxy.reset();
3183
+ hostCuProxy.endTask(ctx.conversationId);
3184
3184
  return { content: summary, isError: false };
3185
3185
  }
3186
3186
 
@@ -225,6 +225,11 @@ export class HostCuProxy {
225
225
  * that reset cleared.
226
226
  */
227
227
  private _resetGeneration = 0;
228
+ /**
229
+ * Desktops a request has been sent to since the last reset, keyed by
230
+ * `observedTargetKey`, so the end of a task can reach each one.
231
+ */
232
+ private _dispatchedTargets = new Map<string, string | undefined>();
228
233
  /**
229
234
  * Owned request IDs mapped to whether their observation is scoped, whether
230
235
  * the helper was told to skip the screenshot, and when the request was
@@ -442,6 +447,7 @@ export class HostCuProxy {
442
447
  detachAbort = () => signal.removeEventListener("abort", onAbort);
443
448
  }
444
449
 
450
+ this._dispatchedTargets.set(targetKey, resolvedTargetClientId);
445
451
  this._ownedRequests.set(requestId, {
446
452
  scoped: scopedObservation,
447
453
  screenshotSkipped,
@@ -592,8 +598,36 @@ export class HostCuProxy {
592
598
  }
593
599
  }
594
600
 
601
+ /**
602
+ * Finish the task: tell every desktop this task drove that it is over, then
603
+ * reset. The notice rides `host_cu_cancel` with a fresh request ID, which
604
+ * matches nothing in flight; the helper treats any cancel as the run
605
+ * stopping and puts the pointer back where the user left it, instead of
606
+ * waiting out its idle fallback.
607
+ */
608
+ endTask(conversationId: string): void {
609
+ for (const targetClientId of this._dispatchedTargets.values()) {
610
+ try {
611
+ broadcastMessage(
612
+ {
613
+ type: "host_cu_cancel",
614
+ requestId: uuid(),
615
+ conversationId,
616
+ ...(targetClientId != null ? { targetClientId } : {}),
617
+ },
618
+ conversationId,
619
+ { targetClientId },
620
+ );
621
+ } catch {
622
+ // Best-effort: the helper still returns the pointer after its idle delay.
623
+ }
624
+ }
625
+ this.reset();
626
+ }
627
+
595
628
  /** Reset all CU state. Called on terminal tools (computer_use_done, etc.). */
596
629
  reset(): void {
630
+ this._dispatchedTargets.clear();
597
631
  this._stepCount = 0;
598
632
  this._previousAXTree = undefined;
599
633
  this._consecutiveUnchangedSteps = 0;
@@ -260,7 +260,7 @@ describe("LiveVoiceSession archive and metrics events", () => {
260
260
  // needing a tool to the escalated leg (see
261
261
  // live-voice-triage-escalate.test.ts).
262
262
  voiceControlPrompt:
263
- "You are speaking in a local live voice session. Keep each reply to one to three spoken sentences. The caller is listening, not reading: lead with the answer, say it in the fewest words that are still complete, and stop. No preamble, no recap of the question, no closing offer of more. Your text is sent directly to a text-to-speech engine. Never use markdown formatting (asterisks, headers, backticks, links), bulleted or numbered lists, or emojis. Write plain conversational text only; if something is naturally a list, say it as one sentence. Speech is the main channel: say the answer, and do not narrate a surface instead of answering. You can also put something on screen when it genuinely helps (a form, a list to pick from, a progress card for long work); the call overlay minimizes by itself once you finish speaking, so the user sees it without doing anything. Never tell the user you cannot show them something. Reply in the language the caller is speaking; if they switch languages, switch with them. ",
263
+ "You are speaking in a local live voice session. Keep each reply to one to three spoken sentences. The caller is listening, not reading: lead with the answer, say it in the fewest words that are still complete, and stop. No preamble, no recap of the question, no closing offer of more. Your text is sent directly to a text-to-speech engine. Never use markdown formatting (asterisks, headers, backticks, links), bulleted or numbered lists, or emojis. Write plain conversational text only; if something is naturally a list, say it as one sentence. Speech is the main channel: say the answer, and do not narrate a surface instead of answering. You can also put something on screen when it genuinely helps (a form, a list to pick from, a progress card for long work, or a card with an image or a link instead of reading an address out); the call overlay minimizes by itself once you finish speaking, so the user sees it without doing anything. Never tell the user you cannot show them something. Reply in the language the caller is speaking; if they switch languages, switch with them. ",
264
264
  });
265
265
  callbacks?.assistant_text_delta?.(makeTextDelta("Hello there."));
266
266
  callbacks?.message_complete?.(makeMessageComplete());
@@ -757,7 +757,7 @@ interface ActiveAssistantTurn {
757
757
  // message. When a turn starts from a barge-in, the interruption merge note is
758
758
  // appended to it (see buildInterruptionMergeNote) so the model reconciles the
759
759
  // interrupted request with the new utterance.
760
- const LIVE_VOICE_CONTROL_PROMPT_BASE = `You are speaking in a local live voice session. ${SPOKEN_REPLY_LENGTH_RULE} ${SPOKEN_REPLY_PLAIN_TEXT_RULE} Speech is the main channel: say the answer, and do not narrate a surface instead of answering. You can also put something on screen when it genuinely helps (a form, a list to pick from, a progress card for long work); the call overlay minimizes by itself once you finish speaking, so the user sees it without doing anything. Never tell the user you cannot show them something. Reply in the language the caller is speaking; if they switch languages, switch with them. `;
760
+ const LIVE_VOICE_CONTROL_PROMPT_BASE = `You are speaking in a local live voice session. ${SPOKEN_REPLY_LENGTH_RULE} ${SPOKEN_REPLY_PLAIN_TEXT_RULE} Speech is the main channel: say the answer, and do not narrate a surface instead of answering. You can also put something on screen when it genuinely helps (a form, a list to pick from, a progress card for long work, or a card with an image or a link instead of reading an address out); the call overlay minimizes by itself once you finish speaking, so the user sees it without doing anything. Never tell the user you cannot show them something. Reply in the language the caller is speaking; if they switch languages, switch with them. `;
761
761
 
762
762
  // Appended for the legs that can actually put something on screen: the main
763
763
  // leg and the escalated leg. The front-door (fast) leg never receives it, for
@@ -60,6 +60,16 @@ describe("PROVIDER_SEED_DATA managed mode wiring", () => {
60
60
  );
61
61
  }
62
62
 
63
+ // `folders:read` is documented too, but the app's scope picker only
64
+ // offers `folder_metadata:read` under Folders, so Figma answers
65
+ // "Invalid scopes for app" whenever it is requested.
66
+ expect(figma.defaultScopes).not.toContain("folders:read");
67
+ if (Array.isArray(availableScopes)) {
68
+ expect(availableScopes.map(({ scope }) => scope)).toContain(
69
+ "folders:read",
70
+ );
71
+ }
72
+
63
73
  // GET /v1/me backs both the ping and the identity label.
64
74
  expect(figma.defaultScopes).toContain("current_user:read");
65
75
  });
@@ -1003,7 +1003,11 @@ export const PROVIDER_SEED_DATA: Record<
1003
1003
  // default, because Figma rejects the whole authorization request if the
1004
1004
  // app cannot grant a requested scope. `selections:read` is withheld for
1005
1005
  // that same reason: it is not offered in the app's OAuth scope list, so
1006
- // requesting it would fail the entire authorization.
1006
+ // requesting it would fail the entire authorization. `folders:read` is
1007
+ // withheld likewise: Figma documents it, but the app's scope picker only
1008
+ // offers `folder_metadata:read` under Folders. `file_code_connect:write`
1009
+ // is requested because the managed app enables it; Figma marks it
1010
+ // Organization-plan only.
1007
1011
  defaultScopes: [
1008
1012
  "current_user:read",
1009
1013
  "file_content:read",
@@ -1013,7 +1017,7 @@ export const PROVIDER_SEED_DATA: Record<
1013
1017
  "file_comments:write",
1014
1018
  "file_dev_resources:read",
1015
1019
  "file_dev_resources:write",
1016
- "folders:read",
1020
+ "file_code_connect:write",
1017
1021
  "folder_metadata:read",
1018
1022
  "library_content:read",
1019
1023
  "library_assets:read",
@@ -1053,6 +1057,10 @@ export const PROVIDER_SEED_DATA: Record<
1053
1057
  scope: "file_dev_resources:write",
1054
1058
  description: "Write dev resources to files",
1055
1059
  },
1060
+ {
1061
+ scope: "file_code_connect:write",
1062
+ description: "Write and change component code (Code Connect)",
1063
+ },
1056
1064
  {
1057
1065
  scope: "folders:read",
1058
1066
  description: "List folders and files in folders",