@wix/himalaya-cli 0.890.0 → 0.891.0

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 (28) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/genie-chat/src/index.d.ts +59 -4
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-comments.mjs +20 -7
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-genie-chat.mjs +42 -2
  4. package/dist/cli.mjs +42 -7
  5. package/guides/sdk-reference.json +29 -5
  6. package/package.json +2 -2
  7. package/templates/beauty-salon-owner/tier5-src/_shared/aria-chat.ts +197 -32
  8. package/templates/beauty-salon-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  9. package/templates/community-club-owner/tier5-src/_shared/aria-chat.ts +197 -32
  10. package/templates/community-club-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  11. package/templates/events-meetups-owner/tier5-src/_shared/aria-chat.ts +197 -32
  12. package/templates/events-meetups-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  13. package/templates/gym-fitness-owner/tier5-src/_shared/aria-chat.ts +197 -32
  14. package/templates/gym-fitness-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  15. package/templates/nonprofit-cause-owner/tier5-src/_shared/aria-chat.ts +197 -32
  16. package/templates/nonprofit-cause-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  17. package/templates/owner-lite/tier5-src/_shared/aria-chat.ts +197 -32
  18. package/templates/owner-lite/tier5-src/_shared/aria-widgets.ts +181 -0
  19. package/templates/podcast-creator-owner/tier5-src/_shared/aria-chat.ts +197 -32
  20. package/templates/podcast-creator-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  21. package/templates/portfolio-creative-owner/tier5-src/_shared/aria-chat.ts +197 -32
  22. package/templates/portfolio-creative-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  23. package/templates/restaurant-owner/tier5-src/_shared/aria-chat.ts +197 -32
  24. package/templates/restaurant-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  25. package/templates/retail-store-owner/tier5-src/_shared/aria-chat.ts +197 -32
  26. package/templates/retail-store-owner/tier5-src/_shared/aria-widgets.ts +181 -0
  27. package/templates/yoga-studio-owner/tier5-src/_shared/aria-chat.ts +197 -32
  28. package/templates/yoga-studio-owner/tier5-src/_shared/aria-widgets.ts +181 -0
@@ -22,6 +22,12 @@ export declare const ARIA_ORIGIN = "owners-app";
22
22
  export interface GenieChatError extends Error {
23
23
  kind: "no-bridge" | "request";
24
24
  cause?: unknown;
25
+ /** Set ONLY when a send failed at step 2, after step 1 had already stored the
26
+ * owner's turn. Its presence is the signal that retrying the whole send would
27
+ * duplicate that turn, and that `triggerAssistantMessage` with this id is the
28
+ * correct retry instead. Absent on every other failure, including a step-1
29
+ * failure, where nothing was stored and a plain retry is right. */
30
+ storedUserMessageId?: string;
25
31
  }
26
32
  export declare function genieChatError(kind: "no-bridge" | "request", message: string, cause?: unknown): GenieChatError;
27
33
  export declare function isGenieChatError(e: unknown): e is GenieChatError;
@@ -77,23 +83,72 @@ export interface GetConversationMessagesResponse {
77
83
  messages?: ConversationMessage[];
78
84
  conversationMessages?: ConversationMessage[];
79
85
  }
80
- /** Optional wire flags on `sendMessage`. Both were present in the captured
81
- * payload; only POLLING is verified end-to-end. */
86
+ /** Context the dashboard attaches to the TRIGGER call. Every field is optional —
87
+ * Aria answers without any of it (measured) — but `clientMetaSiteId` tells the
88
+ * agent which business it is acting for, and the captured dashboard payload
89
+ * also carries the current page so answers can reference what the user sees. */
90
+ export interface UserMessageMetadata {
91
+ userAgent?: string;
92
+ pageUrl?: string;
93
+ /** A short natural-language SUMMARY of the current page, despite the name —
94
+ * the dashboard sends prose here, not markup. */
95
+ pageHtml?: string;
96
+ additionalMetadata?: Array<{
97
+ key: string;
98
+ value: string;
99
+ excludeFromPrompt?: boolean;
100
+ }>;
101
+ channel?: string;
102
+ }
103
+ /** Optional wire flags on `sendMessage`. `communicationMode` /
104
+ * `enableRealtimeEvents` were in the original captured payload; only POLLING is
105
+ * verified end-to-end. The rest were added from the 2026-09-19 re-capture. */
82
106
  export interface SendMessageOptions {
83
107
  communicationMode?: CommunicationMode;
84
108
  enableRealtimeEvents?: boolean;
109
+ metadata?: UserMessageMetadata;
110
+ /** The dashboard sends `true`. Optional: verified to answer either way. */
111
+ enforceAccountScopedConversations?: boolean;
112
+ /** Tag the turn with the same origin the conversation was created under. */
113
+ origin?: string;
114
+ }
115
+ export interface ConversationUserMessageResponse {
116
+ userMessage?: ConversationMessage;
85
117
  }
86
118
  /** Create a conversation bound to the Aria assistant. Returns `{conversationId}`. */
87
119
  export declare function createConversation(assistantConfig?: AssistantConfig, origin?: string): Promise<CreateConversationResponse>;
88
120
  /** List the tenant's conversations (optionally filtered by origin). */
89
121
  export declare function getConversations(origin?: string): Promise<GetConversationsResponse>;
90
- /** Post a user message (POLLING mode by default). The agent may take a few
91
- * seconds — poll getConversationMessages for the ASSISTANT reply. The immediate
122
+ /** Step 1 of sending a turn: PERSIST the user's message on the conversation.
123
+ * Returns the stored message, whose `id` is what actually triggers the agent in
124
+ * step 2. Exported because a caller that wants to render the user's bubble from
125
+ * the server's own copy can await this before triggering. */
126
+ export declare function conversationUserMessage(conversationId: string, content: string, opts?: SendMessageOptions): Promise<ConversationUserMessageResponse>;
127
+ /** Post a user turn (POLLING mode by default). The agent may take a few seconds
128
+ * — poll getConversationMessages for the ASSISTANT reply. The immediate
92
129
  * response may carry placeholder `assistantMessages` (often empty content).
93
130
  *
131
+ * TWO calls, not one. `/user-message` carries NO message content: it names a
132
+ * `userMessageId` that `/conversation-user-message` has already stored. This
133
+ * replaced the old single-call shape (`{message:{content,role}}`) some time
134
+ * after the 2026-06-04 capture, and the failure mode gave nothing away — every
135
+ * call still returned 200, the agent still ran, and every reply was the
136
+ * service's own "I didn't manage to create a proper answer" fallback with an
137
+ * empty `functionCalls`, because the turn it was asked to answer did not exist.
138
+ * Re-verified live 2026-09-19 against www.wixapis.com with a User
139
+ * signed-instance; `origin`, `metadata` and `enforceAccountScopedConversations`
140
+ * were each measured to be optional, so only the two-step shape is required.
141
+ *
94
142
  * The third argument accepts the bare CommunicationMode for backwards
95
143
  * compatibility, or an options object. */
96
144
  export declare function sendMessage(conversationId: string, content: string, modeOrOptions?: CommunicationMode | SendMessageOptions): Promise<SendMessageResponse>;
145
+ /** Step 2 of sending a turn on its own: ask the agent to answer a user message
146
+ * that `conversationUserMessage` has ALREADY stored.
147
+ *
148
+ * Exported because it is the only safe retry when step 2 is the half that
149
+ * failed — see `sendMessage`, which attaches the id to its error for exactly
150
+ * this call. Carries no content: the turn it names is the content. */
151
+ export declare function triggerAssistantMessage(conversationId: string, userMessageId: string, opts?: SendMessageOptions): Promise<SendMessageResponse>;
97
152
  /** Fetch the messages of a conversation (poll after sendMessage). */
98
153
  export declare function getConversationMessages(conversationId: string): Promise<GetConversationMessagesResponse>;
99
154
  /** The transcript from a getConversationMessages response, under either key. */
@@ -61,18 +61,31 @@ async function listBlogComments(postId) {
61
61
  if (!postId) {
62
62
  throw new Error("postId is required");
63
63
  }
64
- const response = await wixCall("GET", "/comments/v1/comments/list-by-resource", {
65
- appId: BLOG_COMMENTS_APP_ID,
66
- contextId: postId,
67
- resourceId: postId,
68
- commentSort: { fieldName: "createdDate", order: "ASC" }
69
- });
70
- return (response.comments ?? []).map((comment) => ({
64
+ const query = [
65
+ `appId=${encodeURIComponent(BLOG_COMMENTS_APP_ID)}`,
66
+ `contextId=${encodeURIComponent(postId)}`,
67
+ `resourceId=${encodeURIComponent(postId)}`
68
+ ].join("&");
69
+ const response = await wixCall(
70
+ "GET",
71
+ `/comments/v1/comments/list-by-resource?${query}`
72
+ );
73
+ const rows = (response.comments ?? []).map((comment) => ({
71
74
  id: comment.id ?? "comment",
72
75
  authorName: commentAuthor(comment),
73
76
  text: commentText(comment),
74
77
  createdDate: comment.createdDate ?? ""
75
78
  }));
79
+ const instantOf = (row) => {
80
+ if (!row.createdDate) return Number.POSITIVE_INFINITY;
81
+ const ms = Date.parse(row.createdDate);
82
+ return Number.isNaN(ms) ? Number.POSITIVE_INFINITY : ms;
83
+ };
84
+ return rows.sort((a, b) => {
85
+ const x = instantOf(a);
86
+ const y = instantOf(b);
87
+ return x === y ? 0 : x < y ? -1 : 1;
88
+ });
76
89
  }
77
90
 
78
91
  // ../../stdlib/wix-sdk/comments-v1/src/index.ts
@@ -33,14 +33,52 @@ function getConversations(origin) {
33
33
  const qs = origin ? `?origin=${encodeURIComponent(origin)}` : "";
34
34
  return wixCall("GET", `${BASE}/conversations${qs}`);
35
35
  }
36
+ function conversationUserMessage(conversationId, content, opts = {}) {
37
+ if (!conversationId) throw new Error("conversationUserMessage: conversationId is required");
38
+ return wixCall("POST", `${BASE}/conversation-user-message`, {
39
+ attachments: [],
40
+ messageReferences: [],
41
+ userMessageContent: content,
42
+ origin: opts.origin ?? ARIA_ORIGIN,
43
+ conversationId,
44
+ userMessageInputSource: "TEXT",
45
+ ...opts.enforceAccountScopedConversations === void 0 ? {} : { enforceAccountScopedConversations: opts.enforceAccountScopedConversations }
46
+ });
47
+ }
36
48
  function sendMessage(conversationId, content, modeOrOptions = "POLLING") {
37
49
  if (!conversationId) throw new Error("sendMessage: conversationId is required");
38
50
  const opts = typeof modeOrOptions === "string" ? { communicationMode: modeOrOptions } : modeOrOptions;
51
+ return conversationUserMessage(conversationId, content, opts).then((stored) => {
52
+ const userMessageId = stored?.userMessage?.id;
53
+ if (!userMessageId) {
54
+ throw genieChatError(
55
+ "request",
56
+ "@himalaya/wix-genie-chat: conversation-user-message returned no userMessage.id, so the agent would have no turn to answer"
57
+ );
58
+ }
59
+ return triggerAssistantMessage(conversationId, userMessageId, opts).catch((cause) => {
60
+ const e = genieChatError(
61
+ "request",
62
+ `@himalaya/wix-genie-chat: the turn was stored but the agent could not be triggered: ${String(cause?.message ?? cause)}`,
63
+ cause
64
+ );
65
+ e.storedUserMessageId = userMessageId;
66
+ throw e;
67
+ });
68
+ });
69
+ }
70
+ function triggerAssistantMessage(conversationId, userMessageId, opts = {}) {
71
+ if (!conversationId) throw new Error("triggerAssistantMessage: conversationId is required");
72
+ if (!userMessageId) throw new Error("triggerAssistantMessage: userMessageId is required");
39
73
  return wixCall("POST", `${BASE}/user-message`, {
40
74
  conversationId,
41
- message: { content, role: "USER" },
75
+ userMessageId,
76
+ userMessageInputSource: "TEXT",
42
77
  communicationMode: opts.communicationMode ?? "POLLING",
43
- enableRealtimeEvents: opts.enableRealtimeEvents ?? true
78
+ enableRealtimeEvents: opts.enableRealtimeEvents ?? true,
79
+ origin: opts.origin ?? ARIA_ORIGIN,
80
+ ...opts.metadata === void 0 ? {} : { metadata: opts.metadata },
81
+ ...opts.enforceAccountScopedConversations === void 0 ? {} : { enforceAccountScopedConversations: opts.enforceAccountScopedConversations }
44
82
  });
45
83
  }
46
84
  function getConversationMessages(conversationId) {
@@ -78,6 +116,7 @@ export {
78
116
  ARIA_UNIFIED_ASSISTANT_ID,
79
117
  ariaAssistantConfig,
80
118
  conversationIdOf,
119
+ conversationUserMessage,
81
120
  createConversation,
82
121
  genieChatError,
83
122
  getConversationMessages,
@@ -87,6 +126,7 @@ export {
87
126
  messageText,
88
127
  messagesOf,
89
128
  sendMessage,
129
+ triggerAssistantMessage,
90
130
  wixCall
91
131
  };
92
132
  //# sourceMappingURL=wix-genie-chat.mjs.map