@memberjunction/realtime-widget 6.2.0-edge.5 → 6.2.0-edge.6

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 (33) hide show
  1. package/README.md +11 -2
  2. package/dist/embed/chunks/UserViewEngine-IVGLM2DH.js +7 -0
  3. package/dist/embed/chunks/chunk-MRWWS7FK.js +162091 -0
  4. package/dist/embed/chunks/chunk-N3BM2W5J.js +36503 -0
  5. package/dist/embed/chunks/chunk-RAIOBPHZ.js +6127 -0
  6. package/dist/embed/chunks/chunk-S3LX5KYE.js +46 -0
  7. package/dist/embed/chunks/chunk-VZ6KR7K2.js +2492 -0
  8. package/dist/embed/chunks/chunk-ZX4SRAYD.js +17043 -0
  9. package/dist/embed/chunks/dist-P2JMWJFV.js +66 -0
  10. package/dist/embed/chunks/guest-tool-relay-GAWXNIUD.js +30 -0
  11. package/dist/embed/chunks/guest-voice-mint-KJMP4VTK.js +94 -0
  12. package/dist/embed/chunks/realtime-voice-controller-PCOD3UBR.js +30558 -0
  13. package/dist/embed/chunks/runtime-widget-transport-AFGCQC7N.js +161 -0
  14. package/dist/embed/mj-widget.js +1056 -0
  15. package/dist/embed.js +3 -2
  16. package/dist/embed.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/loader.d.ts +9 -0
  22. package/dist/loader.d.ts.map +1 -1
  23. package/dist/loader.js +56 -7
  24. package/dist/loader.js.map +1 -1
  25. package/dist/session/widget-session-client.d.ts +46 -5
  26. package/dist/session/widget-session-client.d.ts.map +1 -1
  27. package/dist/session/widget-session-client.js +118 -17
  28. package/dist/session/widget-session-client.js.map +1 -1
  29. package/dist/transport/runtime-widget-transport.d.ts +0 -6
  30. package/dist/transport/runtime-widget-transport.d.ts.map +1 -1
  31. package/dist/transport/runtime-widget-transport.js +2 -31
  32. package/dist/transport/runtime-widget-transport.js.map +1 -1
  33. package/package.json +10 -10
@@ -0,0 +1,161 @@
1
+ import {
2
+ ConversationsRuntime
3
+ } from "./chunk-RAIOBPHZ.js";
4
+ import {
5
+ ConversationEngine,
6
+ Pt,
7
+ Tt,
8
+ agentFailureMessage
9
+ } from "./chunk-MRWWS7FK.js";
10
+ import {
11
+ RunView
12
+ } from "./chunk-N3BM2W5J.js";
13
+ import "./chunk-VZ6KR7K2.js";
14
+ import "./chunk-ZX4SRAYD.js";
15
+
16
+ // dist/transport/runtime-widget-transport.js
17
+ var CONVERSATIONS_ENTITY = "MJ: Conversations";
18
+ var CONVERSATION_DETAILS_ENTITY = "MJ: Conversation Details";
19
+ var RuntimeWidgetTransport = class {
20
+ constructor(apiUrl) {
21
+ this.apiUrl = apiUrl;
22
+ this.token = "";
23
+ this.session = null;
24
+ this.conversationId = null;
25
+ this.contextUser = null;
26
+ this.provider = null;
27
+ }
28
+ /** Configures the GraphQL provider with the guest token, boots the runtime, opens a conversation. */
29
+ async Initialize(session) {
30
+ this.session = session;
31
+ this.token = session.token;
32
+ const provider = await Tt(this.buildConfig());
33
+ this.provider = provider;
34
+ this.contextUser = provider.CurrentUser;
35
+ await ConversationsRuntime.Instance.Config(false, provider.CurrentUser, provider);
36
+ this.conversationId = await this.createConversation();
37
+ }
38
+ /** Swaps in a refreshed token (the next provider call uses it; conversation is preserved). */
39
+ UpdateToken(token) {
40
+ this.token = token;
41
+ }
42
+ /** Persists the user's message, runs the pinned agent, returns its reply. */
43
+ async SendMessage(text, onProgress) {
44
+ if (!this.session || !this.conversationId) {
45
+ return { reply: "", success: false, error: "Widget transport not initialized." };
46
+ }
47
+ try {
48
+ const userDetail = await this.saveUserMessage(text);
49
+ if (!userDetail) {
50
+ return { reply: "", success: false, error: "Could not record your message." };
51
+ }
52
+ const result = await ConversationsRuntime.Instance.AgentRunner.processMessage({
53
+ conversationId: this.conversationId,
54
+ message: userDetail,
55
+ applicationId: this.session.applicationId,
56
+ // D5: ALWAYS pin the support agent — never the unfiltered fallback.
57
+ explicitAgentId: this.session.pinnedAgentId,
58
+ onProgress: (p) => onProgress?.(p.message ?? "Working\u2026", p.percentage)
59
+ });
60
+ if (!result || !result.success) {
61
+ return { reply: "", success: false, error: agentFailureMessage(result, "The agent could not respond.") };
62
+ }
63
+ return { reply: await this.readLatestAgentReply(), success: true };
64
+ } catch (err) {
65
+ return { reply: "", success: false, error: err instanceof Error ? err.message : "Unexpected error." };
66
+ }
67
+ }
68
+ async Dispose() {
69
+ this.session = null;
70
+ this.conversationId = null;
71
+ this.contextUser = null;
72
+ }
73
+ // ── helpers ────────────────────────────────────────────────────────────────
74
+ /**
75
+ * Returns the transport's own GraphQL provider (bound to this widget's guest token), set in
76
+ * {@link Initialize}. All entity work goes through this instance rather than the process-global
77
+ * `Metadata.Provider`, so a page hosting multiple widgets against different servers stays isolated.
78
+ */
79
+ requireProvider() {
80
+ if (!this.provider) {
81
+ throw new Error("Widget transport not initialized \u2014 provider unavailable.");
82
+ }
83
+ return this.provider;
84
+ }
85
+ buildConfig() {
86
+ const base = this.apiUrl.replace(/\/+$/, "");
87
+ const wsUrl = base.replace(/^http/, "ws");
88
+ return new Pt(this.token, base, wsUrl, async () => this.token);
89
+ }
90
+ /** Creates the conversation row the guest's turns attach to. */
91
+ async createConversation() {
92
+ const md = this.requireProvider();
93
+ const convo = await md.GetEntityObject(CONVERSATIONS_ENTITY, this.contextUser ?? void 0);
94
+ convo.NewRecord();
95
+ convo.Name = "Web Widget Support";
96
+ if (this.contextUser?.ID) {
97
+ convo.UserID = this.contextUser.ID;
98
+ }
99
+ if (this.session?.applicationId) {
100
+ convo.ApplicationScope = "Application";
101
+ convo.ApplicationID = this.session.applicationId;
102
+ }
103
+ if (this.session?.sessionId) {
104
+ convo.ExternalID = this.session.sessionId;
105
+ }
106
+ if (this.session?.rememberReturningVisitors) {
107
+ if (this.session.visitorKey) {
108
+ convo.VisitorKey = this.session.visitorKey;
109
+ }
110
+ if (this.session.lastConversationId) {
111
+ convo.LastConversationID = this.session.lastConversationId;
112
+ }
113
+ if (this.session.linkedEntityId && this.session.linkedRecordId) {
114
+ convo.LinkedEntityID = this.session.linkedEntityId;
115
+ convo.LinkedRecordID = this.session.linkedRecordId;
116
+ }
117
+ }
118
+ const saved = await convo.Save();
119
+ if (!saved) {
120
+ throw new Error(`Failed to create widget conversation: ${convo.LatestResult?.CompleteMessage ?? "unknown error"}`);
121
+ }
122
+ return convo.ID;
123
+ }
124
+ /** Saves the visitor's message as a Conversation Detail and returns the entity. */
125
+ async saveUserMessage(text) {
126
+ const md = this.requireProvider();
127
+ const detail = await md.GetEntityObject(CONVERSATION_DETAILS_ENTITY, this.contextUser ?? void 0);
128
+ detail.NewRecord();
129
+ detail.ConversationID = this.conversationId;
130
+ detail.Role = "User";
131
+ detail.Message = text;
132
+ const saved = await detail.Save();
133
+ if (!saved) {
134
+ return null;
135
+ }
136
+ return detail;
137
+ }
138
+ /** Reads the newest AI Conversation Detail in Main (the agent's reply). */
139
+ async readLatestAgentReply() {
140
+ const conversationId = this.conversationId;
141
+ if (!conversationId || !this.contextUser) {
142
+ return "";
143
+ }
144
+ const scope = ConversationEngine.TrunkScope(conversationId);
145
+ const rv = new RunView();
146
+ const result = await rv.RunView({
147
+ EntityName: CONVERSATION_DETAILS_ENTITY,
148
+ ExtraFilter: `${ConversationEngine.ScopeFilter(scope)} AND [Role]='AI'`,
149
+ OrderBy: "Sequence DESC",
150
+ MaxRows: 1,
151
+ ResultType: "entity_object"
152
+ }, this.contextUser ?? void 0);
153
+ if (result.Success && result.Results.length > 0) {
154
+ return result.Results[0].Message ?? "";
155
+ }
156
+ return "";
157
+ }
158
+ };
159
+ export {
160
+ RuntimeWidgetTransport
161
+ };