@vellumai/assistant 0.12.0-dev.202609121414.3df3699 → 0.12.0-dev.202609122019.43571ed

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.12.0-dev.202609121414.3df3699",
3
+ "version": "0.12.0-dev.202609122019.43571ed",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -901,6 +901,32 @@ describe("pairDeliveryWithConversation", () => {
901
901
  // body has to land there for that button to open something that contains
902
902
  // the notification the user tapped.
903
903
 
904
+ test("assistant reply keeps the source conversation without appending its preview", async () => {
905
+ mockExistingConversations["conv-user-chat"] = {
906
+ id: "conv-user-chat",
907
+ source: "user",
908
+ title: "An ordinary chat",
909
+ };
910
+ const signal = makeSignal({
911
+ requiresConversation: undefined,
912
+ sourceContextId: "conv-user-chat",
913
+ sourceEventName: "chat.assistant_reply",
914
+ });
915
+
916
+ const result = await pairDeliveryWithConversation(
917
+ signal,
918
+ "vellum" as NotificationChannel,
919
+ makeCopy({ body: "A short push preview…" }),
920
+ );
921
+
922
+ expect(result.conversationId).toBe("conv-user-chat");
923
+ expect(result.messageId).toBeNull();
924
+ expect(result.createdNewConversation).toBe(false);
925
+ expect(createConversationMock).not.toHaveBeenCalled();
926
+ expect(addMessageMock).not.toHaveBeenCalled();
927
+ expect(messagesInvalidated).toEqual([]);
928
+ });
929
+
904
930
  test("passive vellum signal appends the body to the producing conversation", async () => {
905
931
  mockExistingConversations["conv-producer"] = {
906
932
  id: "conv-producer",
@@ -268,7 +268,11 @@ describe("writeHomeFeedItemForSignal", () => {
268
268
  },
269
269
  });
270
270
 
271
- const item = await writeHomeFeedItemForSignal(signal, decision);
271
+ const item = await writeHomeFeedItemForSignal(
272
+ signal,
273
+ decision,
274
+ makeVellumDelivery(),
275
+ );
272
276
 
273
277
  expect(item).not.toBeNull();
274
278
  expect(appendCalls).toHaveLength(1);
@@ -277,7 +281,10 @@ describe("writeHomeFeedItemForSignal", () => {
277
281
  "The deployment completed successfully.",
278
282
  );
279
283
  expect(appendCalls[0]!.conversationId).toBe("conv-source-1");
280
- expect(conversationLookups).toEqual(["conv-source-1"]);
284
+ expect(appendCalls[0]!.metadata?.notificationConversationMessageId).toBeUndefined();
285
+ expect(messageAppends).toEqual([]);
286
+ expect(messagesInvalidated).toEqual([]);
287
+ expect(conversationLookups).toEqual(["conv-source-1", "conv-source-1"]);
281
288
  });
282
289
 
283
290
  test("isAsyncBackground hint writes even when sourceContextId does not resolve", async () => {
@@ -130,6 +130,7 @@ export interface PairingOptions {
130
130
  * transactional request or a system alert.
131
131
  */
132
132
  const ASSISTANT_SHARE_EVENT = "assistant.share";
133
+ const ASSISTANT_REPLY_EVENT = "chat.assistant_reply";
133
134
 
134
135
  /**
135
136
  * Promote a background share into an assistant-initiated thread, under the
@@ -263,7 +264,25 @@ export async function pairDeliveryWithConversation(
263
264
  // notification can appear. The home feed aims its "Go to Conversation"
264
265
  // button at the same row whenever it mirrors the signal.
265
266
  //
266
- // So this is deliberately not gated on home-feed eligibility: a signal the
267
+ // `chat.assistant_reply` already has its complete reply in that transcript.
268
+ // Its notification body is a lock-screen preview, so appending it would
269
+ // create a second, truncated assistant row. Keep the conversation target
270
+ // for deep links without writing the preview into the transcript.
271
+ if (
272
+ strategy === "start_new_conversation" &&
273
+ !signal.requiresConversation &&
274
+ signal.sourceEventName === ASSISTANT_REPLY_EVENT
275
+ ) {
276
+ return {
277
+ conversationId: resolveSourceConversationId(signal),
278
+ messageId: null,
279
+ strategy,
280
+ createdNewConversation: false,
281
+ conversationFallbackUsed: false,
282
+ };
283
+ }
284
+
285
+ // This is deliberately not gated on home-feed eligibility: a signal the
267
286
  // feed declines to mirror still reaches the user through the banner, and
268
287
  // this row is what makes that landing honest.
269
288
  if (strategy === "start_new_conversation" && !signal.requiresConversation) {
@@ -748,44 +767,45 @@ async function resolveChannelDeliveryHome(params: {
748
767
  * Indexing is skipped for parity with the other notification write paths:
749
768
  * notification copy is delivery audit, not conversational memory.
750
769
  */
751
- async function appendBodyToSourceConversation(
752
- signal: NotificationSignal,
753
- channel: NotificationChannel,
754
- messageContent: string,
755
- ): Promise<{ conversationId: string; messageId: string } | null> {
756
- const sourceContextId = signal.sourceContextId;
757
- if (!sourceContextId) {
770
+ function resolveSourceConversationId(signal: NotificationSignal): string | null {
771
+ if (!signal.sourceContextId) {
758
772
  return null;
759
773
  }
760
-
761
- let existing: ReturnType<typeof getConversation>;
762
774
  try {
763
- existing = getConversation(sourceContextId);
775
+ return getConversation(signal.sourceContextId)?.id ?? null;
764
776
  } catch {
765
777
  return null;
766
778
  }
767
- if (!existing) {
779
+ }
780
+
781
+ async function appendBodyToSourceConversation(
782
+ signal: NotificationSignal,
783
+ channel: NotificationChannel,
784
+ messageContent: string,
785
+ ): Promise<{ conversationId: string; messageId: string } | null> {
786
+ const conversationId = resolveSourceConversationId(signal);
787
+ if (!conversationId) {
768
788
  return null;
769
789
  }
770
790
 
771
- const message = await addMessage(existing.id, "assistant", messageContent, {
791
+ const message = await addMessage(conversationId, "assistant", messageContent, {
772
792
  skipIndexing: true,
773
793
  });
774
794
  // `addMessage` projects attention metadata alone, so a client with this
775
795
  // conversation open needs the messages tag to refetch the transcript. A
776
796
  // notification the user taps through to has every chance of landing on an
777
797
  // already-open conversation.
778
- publishConversationMessagesChanged(existing.id);
798
+ publishConversationMessagesChanged(conversationId);
779
799
 
780
800
  log.info(
781
801
  {
782
802
  signalId: signal.signalId,
783
803
  channel,
784
- conversationId: existing.id,
804
+ conversationId,
785
805
  messageId: message.id,
786
806
  },
787
807
  "Appended notification body to producing conversation",
788
808
  );
789
809
 
790
- return { conversationId: existing.id, messageId: message.id };
810
+ return { conversationId, messageId: message.id };
791
811
  }
@@ -275,6 +275,11 @@ async function resolveOwnedConversationMessageId(
275
275
  sourceConversationId: string | undefined,
276
276
  summary: string,
277
277
  ): Promise<string | undefined> {
278
+ // The completed reply is already the source conversation's canonical row.
279
+ // This signal's body is a compact push preview, not conversation content.
280
+ if (signal.sourceEventName === "chat.assistant_reply") {
281
+ return undefined;
282
+ }
278
283
  if (vellumDelivery?.conversationId) {
279
284
  return vellumDelivery.conversationId === sourceConversationId
280
285
  ? vellumDelivery.messageId