@pagelines/sdk 1.0.878 → 1.0.879
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/README.md +68 -68
- package/dist/BotProvider.js +777 -0
- package/dist/BotProvider.js.map +1 -0
- package/dist/{AgentWidgetInline.js → BotWidgetInline.js} +8 -8
- package/dist/BotWidgetInline.js.map +1 -0
- package/dist/{AgentWidgetModal.js → BotWidgetModal.js} +7 -7
- package/dist/BotWidgetModal.js.map +1 -0
- package/dist/{AgentWrap.js → BotWrap.js} +1174 -1145
- package/dist/BotWrap.js.map +1 -0
- package/dist/{agent/AgentController.d.ts → bot/BotController.d.ts} +35 -18
- package/dist/bot/index.d.ts +14 -0
- package/dist/{agent → bot}/schema.d.ts +6 -6
- package/dist/{agent/ui/AgentAvatar.vue.d.ts → bot/ui/BotAvatar.vue.d.ts} +6 -6
- package/dist/{agent/ui/AgentChat.vue.d.ts → bot/ui/BotChat.vue.d.ts} +5 -5
- package/dist/{agent/ui/AgentProvider.vue.d.ts → bot/ui/BotProvider.vue.d.ts} +3 -3
- package/dist/{agent/ui/AgentWrap.vue.d.ts → bot/ui/BotWrap.vue.d.ts} +3 -4
- package/dist/{agent/ui/ElAgentAbout.vue.d.ts → bot/ui/ElBotAbout.vue.d.ts} +2 -2
- package/dist/{agent/ui/ElAgentChat.vue.d.ts → bot/ui/ElBotChat.vue.d.ts} +5 -5
- package/dist/{agent/ui/ElAgentChatPreview.vue.d.ts → bot/ui/ElBotChatPreview.vue.d.ts} +1 -1
- package/dist/{agent/ui/ElAgentHeader.vue.d.ts → bot/ui/ElBotHeader.vue.d.ts} +2 -2
- package/dist/{agent/ui/ElAgentModeSidebar.vue.d.ts → bot/ui/ElBotModeSidebar.vue.d.ts} +2 -2
- package/dist/{agent/ui/ElAgentSidebar.vue.d.ts → bot/ui/ElBotSidebar.vue.d.ts} +2 -2
- package/dist/bot/ui/ElCreateBot.vue.d.ts +12 -0
- package/dist/{agent → bot}/ui/ElModeHeader.vue.d.ts +2 -2
- package/dist/{agent → bot}/ui/ElProvisioningStatus.vue.d.ts +1 -1
- package/dist/{agent → bot}/ui/VoiceMode.vue.d.ts +4 -4
- package/dist/{agent → bot}/utils.d.ts +5 -5
- package/dist/{agent → bot}/voice/provider.d.ts +2 -2
- package/dist/{agent → bot}/voice/providers/livekit/provider.d.ts +4 -4
- package/dist/{agent → bot}/voice/voice-session-client.d.ts +1 -1
- package/dist/{agent → bot}/work-journal.d.ts +1 -1
- package/dist/{agent.js → bot.js} +83 -80
- package/dist/bot.js.map +1 -0
- package/dist/clients/BillingClient.d.ts +1 -1
- package/dist/clients/BotClient.d.ts +26 -0
- package/dist/clients/ChatClient.d.ts +6 -5
- package/dist/clients/ComputerClient.d.ts +16 -0
- package/dist/clients/UserClient.d.ts +4 -7
- package/dist/clients/types.d.ts +7 -2
- package/dist/contract/build.d.ts +1 -2
- package/dist/index.d.ts +3 -2
- package/dist/provider.js +1 -1
- package/dist/provider.js.map +1 -1
- package/dist/provider2.js +14 -14
- package/dist/provider2.js.map +1 -1
- package/dist/sdk.css +1 -1
- package/dist/sdk.js +4 -4
- package/dist/sdkClient.d.ts +33 -376
- package/dist/sdkClient.js +168 -170
- package/dist/sdkClient.js.map +1 -1
- package/dist/useWidgetState.js +9 -9
- package/dist/useWidgetState.js.map +1 -1
- package/dist/widget/PLWidget.d.ts +6 -6
- package/dist/widget/composables/useWidgetState.d.ts +3 -402
- package/dist/widget/index.d.ts +2 -2
- package/dist/widget/mode.d.ts +2 -2
- package/dist/widget/ui/{AgentWidgetInline.vue.d.ts → BotWidgetInline.vue.d.ts} +2 -2
- package/dist/widget/ui/{AgentWidgetModal.vue.d.ts → BotWidgetModal.vue.d.ts} +2 -2
- package/dist/widget/ui/{AgentWidgetPopup.vue.d.ts → BotWidgetPopup.vue.d.ts} +4 -4
- package/dist/widget.js +206 -206
- package/dist/widget.js.map +1 -1
- package/package.json +5 -5
- package/dist/AgentProvider.js +0 -764
- package/dist/AgentProvider.js.map +0 -1
- package/dist/AgentWidgetInline.js.map +0 -1
- package/dist/AgentWidgetModal.js.map +0 -1
- package/dist/AgentWrap.js.map +0 -1
- package/dist/agent/index.d.ts +0 -14
- package/dist/agent/ui/ElCreateAgent.vue.d.ts +0 -277
- package/dist/agent.js.map +0 -1
- package/dist/clients/AgentClient.d.ts +0 -48
- /package/dist/{agent → bot}/VoiceRecorderController.d.ts +0 -0
- /package/dist/{agent/ui/AgentInputEmail.vue.d.ts → bot/ui/BotInputEmail.vue.d.ts} +0 -0
- /package/dist/{agent/ui/AgentInputOneTimeCode.vue.d.ts → bot/ui/BotInputOneTimeCode.vue.d.ts} +0 -0
- /package/dist/{agent/ui/AgentSidebarClose.vue.d.ts → bot/ui/BotSidebarClose.vue.d.ts} +0 -0
- /package/dist/{agent/ui/AgentToolActivityGroup.vue.d.ts → bot/ui/BotToolActivityGroup.vue.d.ts} +0 -0
- /package/dist/{agent/ui/AgentWidget.vue.d.ts → bot/ui/BotWidget.vue.d.ts} +0 -0
- /package/dist/{agent → bot}/ui/ChatCardBlock.vue.d.ts +0 -0
- /package/dist/{agent → bot}/ui/ChatRichText.vue.d.ts +0 -0
- /package/dist/{agent → bot}/ui/ChatScroller.vue.d.ts +0 -0
- /package/dist/{agent → bot}/ui/ChatVisualBlock.vue.d.ts +0 -0
- /package/dist/{agent → bot}/ui/ElAuthGate.vue.d.ts +0 -0
- /package/dist/{agent → bot}/ui/ElAuthPanel.vue.d.ts +0 -0
- /package/dist/{agent/ui/ElAgentButton.vue.d.ts → bot/ui/ElBotButton.vue.d.ts} +0 -0
- /package/dist/{agent → bot}/ui/ElSidebar.vue.d.ts +0 -0
- /package/dist/{agent → bot}/ui/VoiceHistogramController.d.ts +0 -0
- /package/dist/{agent → bot}/ui/chat-diagram-layout.d.ts +0 -0
- /package/dist/{agent → bot}/ui/chat-visual-format.d.ts +0 -0
- /package/dist/{agent → bot}/ui/voice-mode-presentation.d.ts +0 -0
- /package/dist/{agent → bot}/voice/voice-error-copy.d.ts +0 -0
- /package/dist/{agent → bot}/voice/voice-work-state.d.ts +0 -0
- /package/dist/widget/ui/{AgentWidgetOnboard.vue.d.ts → BotWidgetOnboard.vue.d.ts} +0 -0
package/dist/{agent.js → bot.js}
RENAMED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import "./rolldown-runtime.js";
|
|
2
|
-
import { c as e,
|
|
3
|
-
import { f as n, i as r,
|
|
4
|
-
import { n as l, t as u } from "./
|
|
2
|
+
import { c as e, l as t } from "./sdkClient.js";
|
|
3
|
+
import { f as n, i as r, n as i, r as a, t as o } from "./BotWrap.js";
|
|
4
|
+
import { i as s, n as c, r as l, t as u } from "./BotProvider.js";
|
|
5
5
|
import { n as d, t as f } from "./provider.js";
|
|
6
|
-
import { SettingsObject as p,
|
|
7
|
-
import { Fragment as
|
|
8
|
-
//#region
|
|
9
|
-
var
|
|
6
|
+
import { SettingsObject as p, detectBrowserTimezone as m, readChatEventStream as h, zVoiceSessionMint as g } from "@pagelines/core";
|
|
7
|
+
import { Fragment as _, createBlock as v, createCommentVNode as y, createElementBlock as b, createElementVNode as x, createVNode as S, defineComponent as C, nextTick as w, normalizeClass as T, normalizeStyle as E, openBlock as D, ref as O, renderList as k, watch as A, withCtx as j } from "vue";
|
|
8
|
+
//#region bot/ui/BotWidget.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
+
var M = {
|
|
10
10
|
key: 0,
|
|
11
11
|
class: "relative h-full w-full"
|
|
12
|
-
},
|
|
12
|
+
}, N = { class: "group relative h-full w-full rounded-3xl overflow-hidden shadow-lg transition-all duration-300 ease-[cubic-bezier(0.25,1,0.33,1)] hover:shadow-2xl hover:translate-y-[-1px] hover:brightness-110 active:scale-[1.06] active:-translate-y-0.5 active:duration-100" }, P = ["src", "alt"], F = {
|
|
13
13
|
key: 0,
|
|
14
14
|
class: "absolute top-0.5 right-0.5"
|
|
15
|
-
},
|
|
16
|
-
__name: "
|
|
15
|
+
}, I = /* @__PURE__ */ C({
|
|
16
|
+
__name: "BotWidget",
|
|
17
17
|
props: {
|
|
18
18
|
sdk: {},
|
|
19
19
|
handle: {},
|
|
@@ -22,12 +22,12 @@ var j = {
|
|
|
22
22
|
position: {}
|
|
23
23
|
},
|
|
24
24
|
setup(e, { expose: t }) {
|
|
25
|
-
let n = e, r =
|
|
25
|
+
let n = e, r = O(!1), i = O(!1);
|
|
26
26
|
function toggle() {
|
|
27
27
|
r.value = !r.value;
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
e ? (await
|
|
29
|
+
A(r, async (e) => {
|
|
30
|
+
e ? (await w(), setTimeout(() => {
|
|
31
31
|
i.value = !0;
|
|
32
32
|
}, 400)) : i.value = !1;
|
|
33
33
|
});
|
|
@@ -44,33 +44,33 @@ var j = {
|
|
|
44
44
|
toggle,
|
|
45
45
|
open,
|
|
46
46
|
close
|
|
47
|
-
}), (t, a) => (
|
|
47
|
+
}), (t, a) => (D(), v(o, {
|
|
48
48
|
sdk: e.sdk,
|
|
49
49
|
handle: e.handle,
|
|
50
50
|
context: e.context,
|
|
51
51
|
"first-message": e.firstMessage
|
|
52
52
|
}, {
|
|
53
|
-
default:
|
|
53
|
+
default: j(({ bot: t, sdk: o }) => [t ? (D(), b("div", {
|
|
54
54
|
key: 0,
|
|
55
|
-
class:
|
|
56
|
-
}, [
|
|
57
|
-
class:
|
|
58
|
-
style:
|
|
55
|
+
class: T(["fixed z-[999999] pointer-events-auto", [n.position === "bottom-left" ? "bottom-6 left-6" : n.position === "top-right" ? "top-6 right-6" : n.position === "top-left" ? "top-6 left-6" : "bottom-6 right-6"]])
|
|
56
|
+
}, [x("div", {
|
|
57
|
+
class: T(["transition-all duration-500 ease-[cubic-bezier(0.25,1,0.33,1)] transform-gpu", [r.value ? "widget-expanded w-96 h-[600px] max-w-[calc(100vw-48px)] max-h-[calc(100vh-48px)] rounded-3xl opacity-100 scale-100" : "widget-button w-[80px] h-[80px] opacity-100 scale-100 flex items-center justify-center cursor-pointer"]]),
|
|
58
|
+
style: E({ "transform-origin": n.position === "bottom-left" ? "bottom left" : n.position === "top-right" ? "top right" : n.position === "top-left" ? "top left" : "bottom right" }),
|
|
59
59
|
onClick: a[0] || (a[0] = (e) => r.value ? void 0 : toggle())
|
|
60
|
-
}, [r.value ?
|
|
60
|
+
}, [r.value ? y("", !0) : (D(), b("div", M, [x("div", N, [x("img", {
|
|
61
61
|
src: t.avatarUrl.value,
|
|
62
62
|
alt: `${t.displayName.value} assistant`,
|
|
63
63
|
class: "h-full w-full object-cover pointer-events-none",
|
|
64
64
|
width: "80",
|
|
65
65
|
height: "80"
|
|
66
|
-
}, null, 8,
|
|
66
|
+
}, null, 8, P), a[1] || (a[1] = x("div", { class: "absolute inset-0 pointer-events-none bg-gradient-to-br from-transparent via-black/10 to-black/40 opacity-60 transition-opacity duration-300 group-hover:opacity-40" }, null, -1))]), t.state.value.lifecycle === "running" ? (D(), b("div", F, [...a[2] || (a[2] = [x("div", {
|
|
67
67
|
class: "size-3 bg-green-500 rounded-full ring-2 ring-white absolute animate-ping",
|
|
68
68
|
style: { "animation-duration": "3s" }
|
|
69
|
-
}, null, -1),
|
|
69
|
+
}, null, -1), x("div", { class: "size-3 bg-green-500 rounded-full ring-2 ring-white" }, null, -1)])])) : y("", !0)])), r.value && t ? (D(), v(c, {
|
|
70
70
|
key: 1,
|
|
71
71
|
class: "rounded-3xl shadow-2xl border border-white/10",
|
|
72
72
|
sdk: o,
|
|
73
|
-
|
|
73
|
+
bot: t,
|
|
74
74
|
context: e.context,
|
|
75
75
|
"first-message": e.firstMessage,
|
|
76
76
|
"has-close": !0,
|
|
@@ -78,11 +78,11 @@ var j = {
|
|
|
78
78
|
onClose: handleClose
|
|
79
79
|
}, null, 8, [
|
|
80
80
|
"sdk",
|
|
81
|
-
"
|
|
81
|
+
"bot",
|
|
82
82
|
"context",
|
|
83
83
|
"first-message",
|
|
84
84
|
"is-active"
|
|
85
|
-
])) :
|
|
85
|
+
])) : y("", !0)], 6)], 2)) : y("", !0)]),
|
|
86
86
|
_: 1
|
|
87
87
|
}, 8, [
|
|
88
88
|
"sdk",
|
|
@@ -91,29 +91,29 @@ var j = {
|
|
|
91
91
|
"first-message"
|
|
92
92
|
]));
|
|
93
93
|
}
|
|
94
|
-
}),
|
|
95
|
-
__name: "
|
|
94
|
+
}), L = ["data-sender"], R = /* @__PURE__ */ C({
|
|
95
|
+
__name: "ElBotChatPreview",
|
|
96
96
|
props: {
|
|
97
97
|
messages: {},
|
|
98
98
|
variant: {}
|
|
99
99
|
},
|
|
100
100
|
setup(e) {
|
|
101
|
-
return (t, n) => (
|
|
102
|
-
class:
|
|
103
|
-
"data-test": "
|
|
104
|
-
}, [(
|
|
101
|
+
return (t, n) => (D(), b("div", {
|
|
102
|
+
class: T(["@container/chat-preview flex flex-col gap-3", e.variant === "dark" ? "text-white" : "text-slate-950"]),
|
|
103
|
+
"data-test": "bot-chat-preview"
|
|
104
|
+
}, [(D(!0), b(_, null, k(e.messages, (t, n) => (D(), b("div", {
|
|
105
105
|
key: `${t.sender}-${n}`,
|
|
106
|
-
class:
|
|
107
|
-
"data-test": "
|
|
106
|
+
class: T(["flex", t.sender === "user" ? "justify-end" : "justify-start"]),
|
|
107
|
+
"data-test": "bot-chat-preview-message",
|
|
108
108
|
"data-sender": t.sender
|
|
109
|
-
}, [
|
|
109
|
+
}, [x("div", { class: T(["max-w-[88%] rounded-2xl px-4 py-3 text-sm shadow-sm @sm/chat-preview:max-w-[78%]", t.sender === "user" ? "bg-slate-950 text-white" : e.variant === "dark" ? "border border-white/10 bg-white/10 text-white" : "border border-slate-200 bg-white text-slate-950"]) }, [S(r, {
|
|
110
110
|
text: t.text,
|
|
111
111
|
inverted: t.sender === "user" || e.variant === "dark"
|
|
112
|
-
}, null, 8, ["text", "inverted"])], 2)], 10,
|
|
112
|
+
}, null, 8, ["text", "inverted"])], 2)], 10, L))), 128))], 2));
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
//#endregion
|
|
116
|
-
//#region
|
|
116
|
+
//#region bot/voice/voice-work-state.ts
|
|
117
117
|
function createVoiceWorkState() {
|
|
118
118
|
return { turnIds: /* @__PURE__ */ new Set() };
|
|
119
119
|
}
|
|
@@ -150,30 +150,30 @@ function reduceVoiceWorkEvent(e, t) {
|
|
|
150
150
|
} : e;
|
|
151
151
|
}
|
|
152
152
|
//#endregion
|
|
153
|
-
//#region
|
|
154
|
-
var
|
|
153
|
+
//#region bot/voice/voice-session-client.ts
|
|
154
|
+
var z = {
|
|
155
155
|
start: "/audio/start-call.mp3",
|
|
156
156
|
end: "/audio/end-call.mp3"
|
|
157
|
-
},
|
|
157
|
+
}, B = .7, V = 50, H = 15e3, U = 3e3;
|
|
158
158
|
function unlockAudio(e, t) {
|
|
159
159
|
for (let n of e) n.muted = !0, n.play().catch(() => {}), n.pause(), n.currentTime = 0, n.muted = !1, n.volume = t;
|
|
160
160
|
}
|
|
161
161
|
function createBrowserVoiceChimePlayer(e) {
|
|
162
|
-
let t = Object.fromEntries(Object.entries(
|
|
162
|
+
let t = Object.fromEntries(Object.entries(z).map(([t, n]) => {
|
|
163
163
|
let r = new Audio(`${e}${n}`);
|
|
164
|
-
return r.preload = "auto", r.volume =
|
|
164
|
+
return r.preload = "auto", r.volume = B, [t, r];
|
|
165
165
|
}));
|
|
166
166
|
return {
|
|
167
167
|
play: (e) => {
|
|
168
168
|
t[e].currentTime = 0, t[e].play().catch(() => {});
|
|
169
169
|
},
|
|
170
|
-
unlock: () => unlockAudio(Object.values(t),
|
|
170
|
+
unlock: () => unlockAudio(Object.values(t), B)
|
|
171
171
|
};
|
|
172
172
|
}
|
|
173
|
-
var
|
|
173
|
+
var W = .16;
|
|
174
174
|
function createBrowserVoiceWorkCue(e) {
|
|
175
175
|
let t = new Audio(`${e}/audio/thinking.mp3`);
|
|
176
|
-
return t.preload = "auto", t.loop = !0, t.volume =
|
|
176
|
+
return t.preload = "auto", t.loop = !0, t.volume = W, {
|
|
177
177
|
setActive: (e) => {
|
|
178
178
|
if (e) {
|
|
179
179
|
t.play().catch(() => {});
|
|
@@ -181,19 +181,19 @@ function createBrowserVoiceWorkCue(e) {
|
|
|
181
181
|
}
|
|
182
182
|
t.pause(), t.currentTime = 0;
|
|
183
183
|
},
|
|
184
|
-
unlock: () => unlockAudio([t],
|
|
184
|
+
unlock: () => unlockAudio([t], W)
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
var VoiceSessionClient = class extends p {
|
|
188
|
-
constructor(
|
|
189
|
-
super("VoiceSessionClient",
|
|
188
|
+
constructor(t) {
|
|
189
|
+
super("VoiceSessionClient", t), e(this, "state", O("idle")), e(this, "isMuted", O(!1)), e(this, "provider", void 0), e(this, "teardownPromise", void 0), e(this, "providerName", void 0), e(this, "chime", void 0), e(this, "workCue", void 0), e(this, "generation", 0), e(this, "levelTimer", void 0), e(this, "startAtMs", 0), e(this, "liveAtMs", 0), e(this, "firstPlaybackEmitted", !1), e(this, "mutePending", !1), e(this, "conversationId", void 0), e(this, "workAbort", void 0), e(this, "workState", createVoiceWorkState()), e(this, "workCuePlaying", !1), e(this, "workCueWanted", !1), e(this, "workCuePending", void 0), e(this, "thinking", !1), e(this, "speaking", {
|
|
190
190
|
user: !1,
|
|
191
|
-
|
|
192
|
-
}), this.chime =
|
|
193
|
-
play:
|
|
191
|
+
bot: !1
|
|
192
|
+
}), this.chime = t.playChime ? {
|
|
193
|
+
play: t.playChime,
|
|
194
194
|
unlock: () => {}
|
|
195
|
-
} : void 0, this.workCue =
|
|
196
|
-
setActive:
|
|
195
|
+
} : void 0, this.workCue = t.setWorkCue ? {
|
|
196
|
+
setActive: t.setWorkCue,
|
|
197
197
|
unlock: () => {}
|
|
198
198
|
} : void 0;
|
|
199
199
|
}
|
|
@@ -232,7 +232,7 @@ var VoiceSessionClient = class extends p {
|
|
|
232
232
|
let i = r.connect({
|
|
233
233
|
onDisconnected: (e) => {
|
|
234
234
|
if (!(n !== this.generation || this.provider !== r)) {
|
|
235
|
-
if (this.state.value === "live" && e === "
|
|
235
|
+
if (this.state.value === "live" && e === "bot") {
|
|
236
236
|
this.generation++, this.playChime("end"), this.setState("ended"), this.teardown();
|
|
237
237
|
return;
|
|
238
238
|
}
|
|
@@ -254,7 +254,7 @@ var VoiceSessionClient = class extends p {
|
|
|
254
254
|
}), a;
|
|
255
255
|
try {
|
|
256
256
|
await Promise.race([i, new Promise((e, t) => {
|
|
257
|
-
a = setTimeout(() => t(Object.assign(/* @__PURE__ */ Error("Voice connection timed out."), { code: "VOICE_CONNECT_TIMEOUT" })),
|
|
257
|
+
a = setTimeout(() => t(Object.assign(/* @__PURE__ */ Error("Voice connection timed out."), { code: "VOICE_CONNECT_TIMEOUT" })), H);
|
|
258
258
|
})]);
|
|
259
259
|
} catch (e) {
|
|
260
260
|
if (i.then(() => r.disconnect()).catch(() => {}), n !== this.generation || this.provider !== r) return;
|
|
@@ -313,7 +313,7 @@ var VoiceSessionClient = class extends p {
|
|
|
313
313
|
let e = !!this.workState.activeTurnId;
|
|
314
314
|
this.workState = createVoiceWorkState(), this.thinking = !1, e && this.settings.onWorkChange?.({ active: !1 }), this.setSpeaking({
|
|
315
315
|
user: !1,
|
|
316
|
-
|
|
316
|
+
bot: !1
|
|
317
317
|
}), this.settings.onThinkingChange?.(!1), this.workCueWanted = !1, this.workCuePending !== void 0 && (clearTimeout(this.workCuePending), this.workCuePending = void 0), this.setWorkCue(!1), this.levelTimer !== void 0 && (clearInterval(this.levelTimer), this.levelTimer = void 0);
|
|
318
318
|
let t = this.provider;
|
|
319
319
|
return this.provider = void 0, this.isMuted.value = !1, this.settings.onLevel?.({
|
|
@@ -324,9 +324,9 @@ var VoiceSessionClient = class extends p {
|
|
|
324
324
|
startLevelTimer(e, t) {
|
|
325
325
|
this.levelTimer === void 0 && (this.levelTimer = setInterval(() => {
|
|
326
326
|
if (t !== this.generation || this.provider !== e) return;
|
|
327
|
-
let n = e.sampleLevel(this.speaking.
|
|
327
|
+
let n = e.sampleLevel(this.speaking.bot ? "playback" : this.speaking.user ? "mic" : void 0);
|
|
328
328
|
n && (this.settings.onLevel?.(n), !this.firstPlaybackEmitted && n.source === "playback" && d(n.level) && this.liveAtMs > 0 && (this.firstPlaybackEmitted = !0, this.emitMetric("voice.first_playback", Date.now() - this.liveAtMs)));
|
|
329
|
-
},
|
|
329
|
+
}, V));
|
|
330
330
|
}
|
|
331
331
|
authHeaders() {
|
|
332
332
|
return this.settings.token ? { Authorization: `Bearer ${this.settings.token}` } : {};
|
|
@@ -338,16 +338,16 @@ var VoiceSessionClient = class extends p {
|
|
|
338
338
|
body: {
|
|
339
339
|
...e,
|
|
340
340
|
client: "web",
|
|
341
|
-
|
|
341
|
+
botId: this.settings.botId,
|
|
342
342
|
...this.conversationId ? { conversationId: this.conversationId } : {}
|
|
343
343
|
}
|
|
344
344
|
}).catch(() => {});
|
|
345
345
|
}
|
|
346
|
-
startWorkStream(
|
|
346
|
+
startWorkStream(e, n) {
|
|
347
347
|
this.workAbort?.abort();
|
|
348
348
|
let r = new AbortController();
|
|
349
349
|
this.workAbort = r;
|
|
350
|
-
let i =
|
|
350
|
+
let i = t(this.settings.apiBase, this.settings.isDev), a = this.settings.fetchFn ?? fetch, o = this.settings.latestSequence ? `${i}/api/conversations/${encodeURIComponent(e)}/stream?since=${encodeURIComponent(this.settings.latestSequence)}` : `${i}/api/conversations/${encodeURIComponent(e)}/stream`;
|
|
351
351
|
(async () => {
|
|
352
352
|
let e = await a(o, {
|
|
353
353
|
headers: {
|
|
@@ -357,7 +357,7 @@ var VoiceSessionClient = class extends p {
|
|
|
357
357
|
credentials: "include",
|
|
358
358
|
signal: r.signal
|
|
359
359
|
});
|
|
360
|
-
if (!(!e.ok || !e.body)) for await (let t of
|
|
360
|
+
if (!(!e.ok || !e.body)) for await (let t of h(e.body.getReader())) {
|
|
361
361
|
if (r.signal.aborted || n !== this.generation) return;
|
|
362
362
|
let e = this.workState, i = reduceVoiceWorkEvent(e, t);
|
|
363
363
|
i !== e && (this.workState = i, (i.activeTurnId !== e.activeTurnId || i.description !== e.description) && (this.settings.onWorkChange?.({
|
|
@@ -370,18 +370,18 @@ var VoiceSessionClient = class extends p {
|
|
|
370
370
|
setSpeaking(e) {
|
|
371
371
|
let t = {
|
|
372
372
|
user: e.user && !this.isMuted.value,
|
|
373
|
-
|
|
373
|
+
bot: e.bot
|
|
374
374
|
};
|
|
375
|
-
t.user === this.speaking.user && t.
|
|
375
|
+
t.user === this.speaking.user && t.bot === this.speaking.bot || (this.speaking = t, this.settings.onSpeakingChange?.(t), this.updateWorkCue());
|
|
376
376
|
}
|
|
377
377
|
updateWorkCue() {
|
|
378
|
-
let e = this.state.value === "live" && (this.thinking || !!this.workState.activeTurnId) && !this.speaking.user && !this.speaking.
|
|
378
|
+
let e = this.state.value === "live" && (this.thinking || !!this.workState.activeTurnId) && !this.speaking.user && !this.speaking.bot;
|
|
379
379
|
if (e !== this.workCueWanted) {
|
|
380
380
|
if (this.workCueWanted = e, this.workCuePending !== void 0 && (clearTimeout(this.workCuePending), this.workCuePending = void 0), e) {
|
|
381
381
|
let e = this.generation;
|
|
382
382
|
this.workCuePending = setTimeout(() => {
|
|
383
383
|
this.workCuePending = void 0, e === this.generation && this.workCueWanted && this.setWorkCue(!0);
|
|
384
|
-
}, this.settings.workCueDelayMs ??
|
|
384
|
+
}, this.settings.workCueDelayMs ?? U);
|
|
385
385
|
return;
|
|
386
386
|
}
|
|
387
387
|
this.setWorkCue(!1);
|
|
@@ -391,24 +391,24 @@ var VoiceSessionClient = class extends p {
|
|
|
391
391
|
this.workCuePlaying !== e && (this.workCuePlaying = e, this.ensureWorkCue().setActive(e));
|
|
392
392
|
}
|
|
393
393
|
ensureWorkCue() {
|
|
394
|
-
return this.workCue ?? (this.workCue = createBrowserVoiceWorkCue(
|
|
394
|
+
return this.workCue ?? (this.workCue = createBrowserVoiceWorkCue(t(this.settings.apiBase, this.settings.isDev))), this.workCue;
|
|
395
395
|
}
|
|
396
396
|
ensureChime() {
|
|
397
|
-
return this.chime ?? (this.chime = createBrowserVoiceChimePlayer(
|
|
397
|
+
return this.chime ?? (this.chime = createBrowserVoiceChimePlayer(t(this.settings.apiBase, this.settings.isDev))), this.chime;
|
|
398
398
|
}
|
|
399
399
|
playChime(e) {
|
|
400
400
|
this.ensureChime().play(e);
|
|
401
401
|
}
|
|
402
|
-
async post(
|
|
403
|
-
let n =
|
|
402
|
+
async post(e) {
|
|
403
|
+
let n = t(this.settings.apiBase, this.settings.isDev), r = await (this.settings.fetchFn ?? fetch)(`${n}${e.path}`, {
|
|
404
404
|
method: "POST",
|
|
405
405
|
headers: {
|
|
406
406
|
"Content-Type": "application/json",
|
|
407
407
|
...this.authHeaders()
|
|
408
408
|
},
|
|
409
409
|
credentials: "include",
|
|
410
|
-
keepalive:
|
|
411
|
-
body: JSON.stringify(
|
|
410
|
+
keepalive: e.keepalive,
|
|
411
|
+
body: JSON.stringify(e.body)
|
|
412
412
|
}), i = await r.json();
|
|
413
413
|
if (!r.ok || !i.ok) {
|
|
414
414
|
let e = i.ok ? `HTTP ${r.status}` : i.error, t = !i.ok && i.code ? i.code : "VOICE_MINT_FAILED";
|
|
@@ -423,19 +423,22 @@ var VoiceSessionClient = class extends p {
|
|
|
423
423
|
body: {
|
|
424
424
|
orgId: this.settings.orgId,
|
|
425
425
|
participants: [{
|
|
426
|
-
type: "
|
|
427
|
-
id: this.settings.
|
|
426
|
+
type: "bot",
|
|
427
|
+
id: this.settings.botId
|
|
428
428
|
}]
|
|
429
429
|
}
|
|
430
430
|
})).conversationId, e !== this.generation)) return null;
|
|
431
|
-
let n = await this.post({
|
|
431
|
+
let n = m(), r = await this.post({
|
|
432
432
|
path: "/api/voice/sessions",
|
|
433
|
-
body: {
|
|
433
|
+
body: {
|
|
434
|
+
conversationId: t,
|
|
435
|
+
...n ? { viewerTimezone: n } : {}
|
|
436
|
+
}
|
|
434
437
|
});
|
|
435
438
|
if (e !== this.generation) return null;
|
|
436
|
-
let
|
|
437
|
-
if (!
|
|
438
|
-
return this.conversationId = t,
|
|
439
|
+
let i = g.safeParse(r);
|
|
440
|
+
if (!i.success) throw Object.assign(/* @__PURE__ */ Error("Voice session mint returned an unexpected shape."), { code: "VOICE_MINT_INVALID" });
|
|
441
|
+
return this.conversationId = t, i.data;
|
|
439
442
|
}
|
|
440
443
|
toSessionError(e, t) {
|
|
441
444
|
return e instanceof Error ? {
|
|
@@ -448,6 +451,6 @@ var VoiceSessionClient = class extends p {
|
|
|
448
451
|
}
|
|
449
452
|
};
|
|
450
453
|
//#endregion
|
|
451
|
-
export {
|
|
454
|
+
export { l as BOT_MODES, s as Bot, c as BotChat, n as BotChatController, u as BotProvider, I as BotWidget, o as BotWrap, i as ElBotChat, R as ElBotChatPreview, a as VoiceMode, VoiceSessionClient };
|
|
452
455
|
|
|
453
|
-
//# sourceMappingURL=
|
|
456
|
+
//# sourceMappingURL=bot.js.map
|
package/dist/bot.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.js","names":[],"sources":["../bot/ui/BotWidget.vue","../bot/ui/BotWidget.vue","../bot/ui/ElBotChatPreview.vue","../bot/ui/ElBotChatPreview.vue","../bot/voice/voice-work-state.ts","../bot/voice/voice-session-client.ts"],"sourcesContent":["<script setup lang=\"ts\">\nimport type { PageLinesSDK } from '../../sdkClient'\nimport { nextTick, ref, watch } from 'vue'\nimport BotChat from './BotChat.vue'\nimport BotWrap from './BotWrap.vue'\n\ninterface Props {\n sdk?: PageLinesSDK\n handle: string\n context?: string\n firstMessage?: string\n position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'\n}\n\nconst props = defineProps<Props>()\nconst isOpen = ref(false)\nconst isBotActive = ref(false)\n\nfunction toggle() {\n isOpen.value = !isOpen.value\n}\n\n// Watch isOpen to delay bot activation for smooth transition\nwatch(isOpen, async (newValue) => {\n if (newValue) {\n // When opening, delay bot activation until transition starts\n await nextTick()\n setTimeout(() => {\n isBotActive.value = true\n }, 400) // Delay to let container expand first\n } else {\n // When closing, immediately deactivate bot\n isBotActive.value = false\n }\n})\n\nfunction open() {\n isOpen.value = true\n}\n\nfunction close() {\n isOpen.value = false\n}\n\nfunction handleClose() {\n close()\n}\n\ndefineExpose({\n toggle,\n open,\n close,\n})\n</script>\n\n<template>\n <BotWrap\n v-slot=\"{ bot, sdk: resolvedSdk }\"\n :sdk=\"sdk\"\n :handle=\"handle\"\n :context=\"context\"\n :first-message=\"firstMessage\"\n >\n <!-- Fixed Widget Wrapper -->\n <div\n v-if=\"bot\"\n class=\"fixed z-[999999] pointer-events-auto\"\n :class=\"[\n props.position === 'bottom-left' ? 'bottom-6 left-6'\n : props.position === 'top-right' ? 'top-6 right-6'\n : props.position === 'top-left' ? 'top-6 left-6'\n : 'bottom-6 right-6',\n ]\"\n >\n <!-- Widget Content with Transition -->\n <div\n class=\"transition-all duration-500 ease-[cubic-bezier(0.25,1,0.33,1)] transform-gpu\"\n :class=\"[\n isOpen\n ? 'widget-expanded w-96 h-[600px] max-w-[calc(100vw-48px)] max-h-[calc(100vh-48px)] rounded-3xl opacity-100 scale-100'\n : 'widget-button w-[80px] h-[80px] opacity-100 scale-100 flex items-center justify-center cursor-pointer',\n ]\"\n :style=\"{\n 'transform-origin':\n props.position === 'bottom-left' ? 'bottom left'\n : props.position === 'top-right' ? 'top right'\n : props.position === 'top-left' ? 'top left'\n : 'bottom right',\n }\"\n @click=\"!isOpen ? toggle() : undefined\"\n >\n <!-- Button Content (visible when closed) -->\n <div v-if=\"!isOpen\" class=\"relative h-full w-full\">\n <div class=\"group relative h-full w-full rounded-3xl overflow-hidden shadow-lg transition-all duration-300 ease-[cubic-bezier(0.25,1,0.33,1)] hover:shadow-2xl hover:translate-y-[-1px] hover:brightness-110 active:scale-[1.06] active:-translate-y-0.5 active:duration-100\">\n <img\n :src=\"bot.avatarUrl.value\"\n :alt=\"`${bot.displayName.value} assistant`\"\n class=\"h-full w-full object-cover pointer-events-none\"\n width=\"80\"\n height=\"80\"\n />\n <!-- Gradient overlay for contrast -->\n <div class=\"absolute inset-0 pointer-events-none bg-gradient-to-br from-transparent via-black/10 to-black/40 opacity-60 transition-opacity duration-300 group-hover:opacity-40\" />\n </div>\n <!-- Online indicator -->\n <div v-if=\"bot.state.value.lifecycle === 'running'\" class=\"absolute top-0.5 right-0.5\">\n <div class=\"size-3 bg-green-500 rounded-full ring-2 ring-white absolute animate-ping\" style=\"animation-duration: 3s;\" />\n <div class=\"size-3 bg-green-500 rounded-full ring-2 ring-white\" />\n </div>\n </div>\n\n <!-- Chat Content (visible when open) -->\n <BotChat\n v-if=\"isOpen && bot\"\n class=\"rounded-3xl shadow-2xl border border-white/10\"\n :sdk=\"resolvedSdk\"\n :bot=\"bot\"\n :context=\"context\"\n :first-message=\"firstMessage\"\n :has-close=\"true\"\n :is-active=\"isBotActive\"\n @close=\"handleClose\"\n />\n </div>\n </div>\n </BotWrap>\n</template>\n","<script setup lang=\"ts\">\nimport type { PageLinesSDK } from '../../sdkClient'\nimport { nextTick, ref, watch } from 'vue'\nimport BotChat from './BotChat.vue'\nimport BotWrap from './BotWrap.vue'\n\ninterface Props {\n sdk?: PageLinesSDK\n handle: string\n context?: string\n firstMessage?: string\n position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'\n}\n\nconst props = defineProps<Props>()\nconst isOpen = ref(false)\nconst isBotActive = ref(false)\n\nfunction toggle() {\n isOpen.value = !isOpen.value\n}\n\n// Watch isOpen to delay bot activation for smooth transition\nwatch(isOpen, async (newValue) => {\n if (newValue) {\n // When opening, delay bot activation until transition starts\n await nextTick()\n setTimeout(() => {\n isBotActive.value = true\n }, 400) // Delay to let container expand first\n } else {\n // When closing, immediately deactivate bot\n isBotActive.value = false\n }\n})\n\nfunction open() {\n isOpen.value = true\n}\n\nfunction close() {\n isOpen.value = false\n}\n\nfunction handleClose() {\n close()\n}\n\ndefineExpose({\n toggle,\n open,\n close,\n})\n</script>\n\n<template>\n <BotWrap\n v-slot=\"{ bot, sdk: resolvedSdk }\"\n :sdk=\"sdk\"\n :handle=\"handle\"\n :context=\"context\"\n :first-message=\"firstMessage\"\n >\n <!-- Fixed Widget Wrapper -->\n <div\n v-if=\"bot\"\n class=\"fixed z-[999999] pointer-events-auto\"\n :class=\"[\n props.position === 'bottom-left' ? 'bottom-6 left-6'\n : props.position === 'top-right' ? 'top-6 right-6'\n : props.position === 'top-left' ? 'top-6 left-6'\n : 'bottom-6 right-6',\n ]\"\n >\n <!-- Widget Content with Transition -->\n <div\n class=\"transition-all duration-500 ease-[cubic-bezier(0.25,1,0.33,1)] transform-gpu\"\n :class=\"[\n isOpen\n ? 'widget-expanded w-96 h-[600px] max-w-[calc(100vw-48px)] max-h-[calc(100vh-48px)] rounded-3xl opacity-100 scale-100'\n : 'widget-button w-[80px] h-[80px] opacity-100 scale-100 flex items-center justify-center cursor-pointer',\n ]\"\n :style=\"{\n 'transform-origin':\n props.position === 'bottom-left' ? 'bottom left'\n : props.position === 'top-right' ? 'top right'\n : props.position === 'top-left' ? 'top left'\n : 'bottom right',\n }\"\n @click=\"!isOpen ? toggle() : undefined\"\n >\n <!-- Button Content (visible when closed) -->\n <div v-if=\"!isOpen\" class=\"relative h-full w-full\">\n <div class=\"group relative h-full w-full rounded-3xl overflow-hidden shadow-lg transition-all duration-300 ease-[cubic-bezier(0.25,1,0.33,1)] hover:shadow-2xl hover:translate-y-[-1px] hover:brightness-110 active:scale-[1.06] active:-translate-y-0.5 active:duration-100\">\n <img\n :src=\"bot.avatarUrl.value\"\n :alt=\"`${bot.displayName.value} assistant`\"\n class=\"h-full w-full object-cover pointer-events-none\"\n width=\"80\"\n height=\"80\"\n />\n <!-- Gradient overlay for contrast -->\n <div class=\"absolute inset-0 pointer-events-none bg-gradient-to-br from-transparent via-black/10 to-black/40 opacity-60 transition-opacity duration-300 group-hover:opacity-40\" />\n </div>\n <!-- Online indicator -->\n <div v-if=\"bot.state.value.lifecycle === 'running'\" class=\"absolute top-0.5 right-0.5\">\n <div class=\"size-3 bg-green-500 rounded-full ring-2 ring-white absolute animate-ping\" style=\"animation-duration: 3s;\" />\n <div class=\"size-3 bg-green-500 rounded-full ring-2 ring-white\" />\n </div>\n </div>\n\n <!-- Chat Content (visible when open) -->\n <BotChat\n v-if=\"isOpen && bot\"\n class=\"rounded-3xl shadow-2xl border border-white/10\"\n :sdk=\"resolvedSdk\"\n :bot=\"bot\"\n :context=\"context\"\n :first-message=\"firstMessage\"\n :has-close=\"true\"\n :is-active=\"isBotActive\"\n @close=\"handleClose\"\n />\n </div>\n </div>\n </BotWrap>\n</template>\n","<script setup lang=\"ts\">\nimport ChatRichText from './ChatRichText.vue'\n\nexport type ChatPreviewMessage = {\n sender: 'user' | 'bot'\n text: string\n}\n\ndefineProps<{\n messages: ChatPreviewMessage[]\n variant?: 'light' | 'dark'\n}>()\n</script>\n\n<template>\n <div\n class=\"@container/chat-preview flex flex-col gap-3\"\n :class=\"variant === 'dark' ? 'text-white' : 'text-slate-950'\"\n data-test=\"bot-chat-preview\"\n >\n <div\n v-for=\"(message, index) in messages\"\n :key=\"`${message.sender}-${index}`\"\n class=\"flex\"\n :class=\"message.sender === 'user' ? 'justify-end' : 'justify-start'\"\n data-test=\"bot-chat-preview-message\"\n :data-sender=\"message.sender\"\n >\n <div\n class=\"max-w-[88%] rounded-2xl px-4 py-3 text-sm shadow-sm @sm/chat-preview:max-w-[78%]\"\n :class=\"message.sender === 'user'\n ? 'bg-slate-950 text-white'\n : variant === 'dark'\n ? 'border border-white/10 bg-white/10 text-white'\n : 'border border-slate-200 bg-white text-slate-950'\"\n >\n <ChatRichText\n :text=\"message.text\"\n :inverted=\"message.sender === 'user' || variant === 'dark'\"\n />\n </div>\n </div>\n </div>\n</template>\n","<script setup lang=\"ts\">\nimport ChatRichText from './ChatRichText.vue'\n\nexport type ChatPreviewMessage = {\n sender: 'user' | 'bot'\n text: string\n}\n\ndefineProps<{\n messages: ChatPreviewMessage[]\n variant?: 'light' | 'dark'\n}>()\n</script>\n\n<template>\n <div\n class=\"@container/chat-preview flex flex-col gap-3\"\n :class=\"variant === 'dark' ? 'text-white' : 'text-slate-950'\"\n data-test=\"bot-chat-preview\"\n >\n <div\n v-for=\"(message, index) in messages\"\n :key=\"`${message.sender}-${index}`\"\n class=\"flex\"\n :class=\"message.sender === 'user' ? 'justify-end' : 'justify-start'\"\n data-test=\"bot-chat-preview-message\"\n :data-sender=\"message.sender\"\n >\n <div\n class=\"max-w-[88%] rounded-2xl px-4 py-3 text-sm shadow-sm @sm/chat-preview:max-w-[78%]\"\n :class=\"message.sender === 'user'\n ? 'bg-slate-950 text-white'\n : variant === 'dark'\n ? 'border border-white/10 bg-white/10 text-white'\n : 'border border-slate-200 bg-white text-slate-950'\"\n >\n <ChatRichText\n :text=\"message.text\"\n :inverted=\"message.sender === 'user' || variant === 'dark'\"\n />\n </div>\n </div>\n </div>\n</template>\n","import type { ChatEvent } from '@pagelines/core'\n\nexport interface VoiceWorkState {\n turnIds: ReadonlySet<string>\n activeTurnId?: string\n description?: string\n}\n\nexport function createVoiceWorkState(): VoiceWorkState {\n return { turnIds: new Set() }\n}\n\n/** Project canonical conversation events onto the one active voice work line. */\nexport function reduceVoiceWorkEvent(state: VoiceWorkState, event: ChatEvent): VoiceWorkState {\n if (event.event === 'message') {\n const message = event.data.message\n if (message.role === 'user' && message.metadata?.clientContext === 'voice') {\n return { ...state, turnIds: new Set(state.turnIds).add(message.messageId) }\n }\n const turnId = typeof message.metadata?.turnId === 'string' ? message.metadata.turnId : undefined\n if (turnId && state.turnIds.has(turnId)) {\n const turnIds = new Set(state.turnIds)\n turnIds.delete(turnId)\n return state.activeTurnId === turnId ? { turnIds } : { ...state, turnIds }\n }\n return state\n }\n\n const turnId = 'turnId' in event.data && typeof event.data.turnId === 'string'\n ? event.data.turnId\n : undefined\n if (!turnId || !state.turnIds.has(turnId))\n return state\n\n if (event.event === 'working_state') {\n return {\n ...state,\n activeTurnId: turnId,\n description: event.data.description.trim() || 'Working on it',\n }\n }\n if (event.event === 'tool_activity' && event.data.status === 'started') {\n return {\n ...state,\n activeTurnId: turnId,\n description: event.data.label,\n }\n }\n if (event.event === 'working_end' || event.event === 'stream_end')\n return { ...state, activeTurnId: undefined, description: undefined }\n return state\n}\n","/** Provider-neutral voice session state machine for web clients. */\nimport type { ApiResponse, VoiceClientMetric, VoiceSessionMint } from '@pagelines/core'\nimport type { Ref } from 'vue'\nimport type {\n CreateVoiceProviderClient,\n VoiceLevelEvent,\n VoiceProviderClient,\n VoiceSessionError,\n VoiceSpeakingState,\n} from './provider'\nimport { detectBrowserTimezone, readChatEventStream, SettingsObject, zVoiceSessionMint } from '@pagelines/core'\nimport { ref } from 'vue'\nimport { resolveApiBase } from '../../api'\nimport { createVoiceProviderClient, isVoiceAudible } from './provider'\nimport { createVoiceWorkState, reduceVoiceWorkEvent } from './voice-work-state'\n\nexport type { VoiceLevelEvent, VoiceSessionError, VoiceSpeakingState } from './provider'\nexport { isVoiceAudible, VOICE_SPECTRUM_BANDS, voiceSpectrum } from './provider'\n\nexport type VoiceSessionClientState = 'idle' | 'minting' | 'connecting' | 'live' | 'ended'\nexport type VoiceChimeKind = 'start' | 'end'\nexport interface VoiceWorkStatus { active: boolean, description?: string }\n\n/** Client-owned latency phases — speech-end-to-first-text is measured on the handler. */\nexport type VoiceMetric = Pick<VoiceClientMetric, 'name' | 'durationMs' | 'provider' | 'phase' | 'code'>\nexport type VoiceMetricName = VoiceMetric['name']\n\nexport interface VoiceClientHandlers {\n onStateChange?: (state: VoiceSessionClientState) => void\n onLevel?: (event: VoiceLevelEvent) => void\n onError?: (error: VoiceSessionError) => void\n onThinkingChange?: (thinking: boolean) => void\n onSpeakingChange?: (state: VoiceSpeakingState) => void\n /** Fire-and-forget latency phases for product observability. */\n onMetric?: (metric: VoiceMetric) => void\n onWorkChange?: (work: VoiceWorkStatus) => void\n}\n\nexport interface VoiceSessionClientSettings extends VoiceClientHandlers, Record<string, unknown> {\n botId: string\n orgId: string\n conversationId?: string\n /** Last message already loaded by the host; the work stream starts after it. */\n latestSequence?: string\n apiBase?: string\n isDev?: boolean\n token?: string\n fetchFn?: typeof fetch\n /** Provider composition seam; the default dynamically loads the minted provider. */\n createProvider?: CreateVoiceProviderClient\n playChime?: (kind: VoiceChimeKind) => void\n /** Test seam; production uses the quiet looping work asset. */\n setWorkCue?: (active: boolean) => void\n /** Test seam; production waits WORK_CUE_DELAY_MS before the work loop starts. */\n workCueDelayMs?: number\n}\n\nconst CHIME_PATHS: Record<VoiceChimeKind, string> = {\n start: '/audio/start-call.mp3',\n end: '/audio/end-call.mp3',\n}\nconst CHIME_VOLUME = 0.7\nconst LEVEL_INTERVAL_MS = 50\nconst CONNECT_TIMEOUT_MS = 15_000\n/** Waiting must outlive this before the loop starts — normal turns stay silent. */\nconst WORK_CUE_DELAY_MS = 3_000\n\n/**\n * A chime player plus the one call that makes it audible later.\n *\n * `unlock` must run inside the user gesture that starts the call. The start\n * chime plays after minting and connecting — seconds of async — by which\n * time the gesture has expired and the autoplay policy rejects `play()`.\n * The rejection is swallowed (a missing cue must never take a call down),\n * so the failure is completely silent: exactly the reported bug, a call that\n * connects without ever announcing itself.\n */\nexport interface VoiceChimePlayer {\n play: (kind: VoiceChimeKind) => void\n unlock: () => void\n}\n\n/**\n * Mark elements user-activated so they can be played later without a gesture.\n *\n * Two details decide whether this works, and both are easy to get wrong:\n *\n * `muted`, not `volume` — iOS Safari treats `HTMLMediaElement.volume` as\n * read-only, so silencing by volume is a no-op there and the unlock plays the\n * cue out loud at full volume. iOS is the platform whose policy makes this\n * necessary at all, so getting it wrong there defeats the whole exercise.\n *\n * Stop synchronously, not from the `play()` promise. That promise settles only\n * once playback actually begins, which on a slow connection can be after the\n * real cue has been asked for — the pending stop then pauses the cue the\n * moment it starts. The activation is granted when `play()` is *called* inside\n * the gesture, so pausing on the next line keeps it and removes the race. The\n * interrupted `play()` rejects with `AbortError`; that is expected.\n */\nfunction unlockAudio(elements: HTMLAudioElement[], volume: number): void {\n for (const audio of elements) {\n audio.muted = true\n void audio.play().catch(() => {})\n audio.pause()\n audio.currentTime = 0\n audio.muted = false\n audio.volume = volume\n }\n}\n\n/**\n * The readiness cue is the only signal an eyes-off user gets, so it is served\n * from the API origin rather than the embedding page — a relative path would\n * silently 404 wherever the SDK is not hosted by the app itself.\n */\nexport function createBrowserVoiceChimePlayer(apiBase: string): VoiceChimePlayer {\n const players = Object.fromEntries(Object.entries(CHIME_PATHS).map(([kind, path]) => {\n const audio = new Audio(`${apiBase}${path}`)\n audio.preload = 'auto'\n audio.volume = CHIME_VOLUME\n return [kind, audio]\n })) as Record<VoiceChimeKind, HTMLAudioElement>\n return {\n play: (kind) => {\n players[kind].currentTime = 0\n // Still guarded: a browser that refuses anyway must not break the call.\n void players[kind].play().catch(() => {})\n },\n unlock: () => unlockAudio(Object.values(players), CHIME_VOLUME),\n }\n}\n\nconst WORK_CUE_VOLUME = 0.16\n\n/**\n * The work loop has the chime's problem and worse odds: it first plays from a\n * `WORK_CUE_DELAY_MS` timer, so it is *never* inside a gesture. It needs the\n * same unlock, which is why the session unlocks its audio as a set rather than\n * each caller solving it alone.\n */\nfunction createBrowserVoiceWorkCue(apiBase: string): { setActive: (active: boolean) => void, unlock: () => void } {\n const audio = new Audio(`${apiBase}/audio/thinking.mp3`)\n audio.preload = 'auto'\n audio.loop = true\n audio.volume = WORK_CUE_VOLUME\n return {\n setActive: (active) => {\n if (active) {\n void audio.play().catch(() => {})\n return\n }\n audio.pause()\n audio.currentTime = 0\n },\n unlock: () => unlockAudio([audio], WORK_CUE_VOLUME),\n }\n}\n\nexport class VoiceSessionClient extends SettingsObject<VoiceSessionClientSettings> {\n readonly state: Ref<VoiceSessionClientState> = ref('idle')\n readonly isMuted: Ref<boolean> = ref(false)\n\n private provider?: VoiceProviderClient\n private teardownPromise?: Promise<void>\n private providerName?: VoiceSessionMint['provider']\n private chime?: VoiceChimePlayer\n private workCue?: { setActive: (active: boolean) => void, unlock: () => void }\n private generation = 0\n private levelTimer: ReturnType<typeof setInterval> | undefined\n private startAtMs = 0\n private liveAtMs = 0\n private firstPlaybackEmitted = false\n private mutePending = false\n private conversationId?: string\n private workAbort?: AbortController\n private workState = createVoiceWorkState()\n private workCuePlaying = false\n private workCueWanted = false\n private workCuePending?: ReturnType<typeof setTimeout>\n private thinking = false\n private speaking: VoiceSpeakingState = { user: false, bot: false }\n\n constructor(settings: VoiceSessionClientSettings) {\n super('VoiceSessionClient', settings)\n // The injected seam is a bare function; tests do not need unlocking.\n this.chime = settings.playChime ? { play: settings.playChime, unlock: () => {} } : undefined\n this.workCue = settings.setWorkCue ? { setActive: settings.setWorkCue, unlock: () => {} } : undefined\n }\n\n async start(): Promise<void> {\n if (this.state.value !== 'idle')\n return\n // Before the first await, while the tap that started the call still\n // counts as consent. Everything after this point is async — the chimes\n // wait on minting and connecting, the work loop on a 3s timer — so this\n // is the only moment any of them can be authorised.\n this.ensureChime().unlock()\n this.ensureWorkCue().unlock()\n const generation = ++this.generation\n this.startAtMs = Date.now()\n this.liveAtMs = 0\n this.providerName = undefined\n this.firstPlaybackEmitted = false\n this.workState = createVoiceWorkState()\n this.thinking = false\n this.setState('minting')\n try {\n const mint = await this.mintSession(generation)\n if (!mint || generation !== this.generation)\n return\n if (this.conversationId)\n this.startWorkStream(this.conversationId, generation)\n this.setState('connecting')\n await this.connect({ mint, generation })\n } catch (error) {\n if (generation !== this.generation)\n return\n this.fail(this.toSessionError(error, 'VOICE_MINT_FAILED'))\n }\n }\n\n async end(): Promise<void> {\n if (this.state.value === 'idle')\n return\n if (this.state.value === 'ended')\n return this.teardown()\n const shouldChime = this.state.value === 'live'\n this.generation++\n if (shouldChime)\n this.playChime('end')\n this.setState('ended')\n await this.teardown()\n }\n\n private async connect(args: { mint: VoiceSessionMint, generation: number }): Promise<void> {\n const { mint, generation } = args\n this.providerName = mint.provider\n const provider = await (this.settings.createProvider ?? createVoiceProviderClient)(mint)\n if (generation !== this.generation) {\n await provider.disconnect().catch(() => {})\n return\n }\n this.provider = provider\n\n const connectPromise = provider.connect({\n onDisconnected: (cause) => {\n if (generation !== this.generation || this.provider !== provider)\n return\n if (this.state.value === 'live' && cause === 'bot') {\n this.generation++\n this.playChime('end')\n this.setState('ended')\n void this.teardown()\n return\n }\n this.fail({\n code: this.state.value === 'live' ? 'VOICE_CONNECTION_LOST' : 'VOICE_CONNECT_FAILED',\n message: this.state.value === 'live'\n ? 'The voice connection dropped.'\n : 'Could not open the voice connection.',\n })\n },\n onError: error => {\n if (generation === this.generation && this.provider === provider)\n this.fail(error)\n },\n onThinkingChange: thinking => {\n if (generation === this.generation && this.provider === provider) {\n this.thinking = thinking\n this.settings.onThinkingChange?.(thinking)\n this.updateWorkCue()\n }\n },\n onSpeakingChange: state => {\n if (generation === this.generation && this.provider === provider)\n this.setSpeaking(state)\n },\n })\n let timeoutId: ReturnType<typeof setTimeout> | undefined\n try {\n await Promise.race([\n connectPromise,\n new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => reject(Object.assign(new Error('Voice connection timed out.'), { code: 'VOICE_CONNECT_TIMEOUT' })), CONNECT_TIMEOUT_MS)\n }),\n ])\n } catch (error) {\n void connectPromise.then(() => provider.disconnect()).catch(() => {})\n if (generation !== this.generation || this.provider !== provider)\n return\n this.fail(this.toSessionError(error, 'VOICE_CONNECT_FAILED'))\n return\n } finally {\n if (timeoutId)\n clearTimeout(timeoutId)\n }\n if (generation !== this.generation || this.provider !== provider)\n return\n\n this.startLevelTimer(provider, generation)\n this.liveAtMs = Date.now()\n this.setState('live')\n this.updateWorkCue()\n this.emitMetric('voice.ready', this.liveAtMs - this.startAtMs)\n this.playChime('start')\n }\n\n /** True while a live provider can accept typed text as a spoken turn. */\n get canSendUserMessage(): boolean {\n return this.state.value === 'live' && !!this.provider?.sendUserMessage\n }\n\n sendUserMessage(text: string): boolean {\n const body = text.trim()\n if (!body || !this.canSendUserMessage)\n return false\n this.provider!.sendUserMessage!(body)\n return true\n }\n\n /** Returns the applied state, or undefined when mute is unavailable or fails. */\n async toggleMuted(): Promise<boolean | undefined> {\n const provider = this.provider\n if (this.state.value !== 'live' || !provider?.setMuted || this.mutePending)\n return undefined\n const generation = this.generation\n const next = !this.isMuted.value\n this.mutePending = true\n try {\n await provider.setMuted(next)\n if (generation !== this.generation || this.provider !== provider || this.state.value !== 'live')\n return undefined\n this.isMuted.value = next\n // Mute clears the caller's activity and nothing else: working, thinking,\n // and playback carry on.\n if (next && this.speaking.user)\n this.setSpeaking({ ...this.speaking, user: false })\n return next\n }\n catch {\n return undefined\n }\n finally {\n this.mutePending = false\n }\n }\n\n private emitMetric(name: VoiceMetricName, durationMs: number, details: Pick<VoiceMetric, 'phase' | 'code'> = {}): void {\n const metric: VoiceMetric = {\n name,\n durationMs: Math.max(0, Math.round(durationMs)),\n ...(this.providerName ? { provider: this.providerName } : {}),\n ...details,\n }\n this.settings.onMetric?.(metric)\n this.postMetric(metric)\n }\n\n private setState(state: VoiceSessionClientState): void {\n if (this.state.value === state)\n return\n this.state.value = state\n this.settings.onStateChange?.(state)\n }\n\n private fail(error: VoiceSessionError): void {\n const shouldChime = this.state.value === 'live'\n if (this.startAtMs > 0) {\n this.emitMetric('voice.failed', Date.now() - this.startAtMs, {\n phase: this.state.value,\n code: error.code,\n })\n }\n this.generation++\n if (shouldChime)\n this.playChime('end')\n this.settings.onError?.(error)\n this.setState('ended')\n void this.teardown()\n }\n\n private teardown(): Promise<void> {\n if (this.teardownPromise)\n return this.teardownPromise\n this.workAbort?.abort()\n this.workAbort = undefined\n const hadWork = !!this.workState.activeTurnId\n this.workState = createVoiceWorkState()\n this.thinking = false\n if (hadWork)\n this.settings.onWorkChange?.({ active: false })\n this.setSpeaking({ user: false, bot: false })\n this.settings.onThinkingChange?.(false)\n this.workCueWanted = false\n if (this.workCuePending !== undefined) {\n clearTimeout(this.workCuePending)\n this.workCuePending = undefined\n }\n this.setWorkCue(false)\n if (this.levelTimer !== undefined) {\n clearInterval(this.levelTimer)\n this.levelTimer = undefined\n }\n const provider = this.provider\n this.provider = undefined\n this.isMuted.value = false\n this.settings.onLevel?.({ source: 'playback', level: 0 })\n this.teardownPromise = provider?.disconnect().catch(() => {}) ?? Promise.resolve()\n return this.teardownPromise\n }\n\n private startLevelTimer(provider: VoiceProviderClient, generation: number): void {\n if (this.levelTimer !== undefined)\n return\n this.levelTimer = setInterval(() => {\n if (generation !== this.generation || this.provider !== provider)\n return\n // The transport's speaker state picks the meter: the mic analyser hears\n // the speaker too, so \"loudest wins\" flickered green over the assistant.\n const level = provider.sampleLevel(this.speaking.bot ? 'playback' : this.speaking.user ? 'mic' : undefined)\n if (!level)\n return\n this.settings.onLevel?.(level)\n if (\n !this.firstPlaybackEmitted\n && level.source === 'playback'\n && isVoiceAudible(level.level)\n && this.liveAtMs > 0\n ) {\n this.firstPlaybackEmitted = true\n this.emitMetric('voice.first_playback', Date.now() - this.liveAtMs)\n }\n }, LEVEL_INTERVAL_MS)\n }\n\n private authHeaders(): Record<string, string> {\n return this.settings.token ? { Authorization: `Bearer ${this.settings.token}` } : {}\n }\n\n private postMetric(metric: VoiceMetric): void {\n void this.post<{ recorded: boolean }>({\n path: '/api/voice/metrics',\n keepalive: true,\n body: {\n ...metric,\n client: 'web',\n botId: this.settings.botId,\n ...(this.conversationId ? { conversationId: this.conversationId } : {}),\n },\n }).catch(() => {})\n }\n\n private startWorkStream(conversationId: string, generation: number): void {\n this.workAbort?.abort()\n const abort = new AbortController()\n this.workAbort = abort\n const apiBase = resolveApiBase(this.settings.apiBase, this.settings.isDev)\n const fetchFn = this.settings.fetchFn ?? fetch\n const streamUrl = this.settings.latestSequence\n ? `${apiBase}/api/conversations/${encodeURIComponent(conversationId)}/stream?since=${encodeURIComponent(this.settings.latestSequence)}`\n : `${apiBase}/api/conversations/${encodeURIComponent(conversationId)}/stream`\n void (async () => {\n const response = await fetchFn(streamUrl, {\n headers: { Accept: 'text/event-stream', ...this.authHeaders() },\n credentials: 'include',\n signal: abort.signal,\n })\n if (!response.ok || !response.body)\n return\n for await (const event of readChatEventStream(response.body.getReader())) {\n if (abort.signal.aborted || generation !== this.generation)\n return\n const previous = this.workState\n const next = reduceVoiceWorkEvent(previous, event)\n if (next === previous)\n continue\n this.workState = next\n if (next.activeTurnId !== previous.activeTurnId || next.description !== previous.description) {\n this.settings.onWorkChange?.({\n active: !!next.activeTurnId,\n ...(next.description ? { description: next.description } : {}),\n })\n this.updateWorkCue()\n }\n }\n })().catch(() => {})\n }\n\n private setSpeaking(next: VoiceSpeakingState): void {\n const applied = { user: next.user && !this.isMuted.value, bot: next.bot }\n if (applied.user === this.speaking.user && applied.bot === this.speaking.bot)\n return\n this.speaking = applied\n this.settings.onSpeakingChange?.(applied)\n this.updateWorkCue()\n }\n\n /**\n * Duck on speech, not on energy: room tone kept the loop from ever\n * starting. The loop starts only once waiting outlives the dwell — a blip\n * shorter than that is a normal turn and stays silent.\n */\n private updateWorkCue(): void {\n const wanted = this.state.value === 'live'\n && (this.thinking || !!this.workState.activeTurnId)\n && !this.speaking.user\n && !this.speaking.bot\n if (wanted === this.workCueWanted)\n return\n this.workCueWanted = wanted\n if (this.workCuePending !== undefined) {\n clearTimeout(this.workCuePending)\n this.workCuePending = undefined\n }\n if (wanted) {\n const generation = this.generation\n this.workCuePending = setTimeout(() => {\n this.workCuePending = undefined\n if (generation === this.generation && this.workCueWanted)\n this.setWorkCue(true)\n }, this.settings.workCueDelayMs ?? WORK_CUE_DELAY_MS)\n return\n }\n this.setWorkCue(false)\n }\n\n private setWorkCue(active: boolean): void {\n if (this.workCuePlaying === active)\n return\n this.workCuePlaying = active\n this.ensureWorkCue().setActive(active)\n }\n\n private ensureWorkCue(): { setActive: (active: boolean) => void, unlock: () => void } {\n this.workCue ??= createBrowserVoiceWorkCue(resolveApiBase(this.settings.apiBase, this.settings.isDev))\n return this.workCue\n }\n\n private ensureChime(): VoiceChimePlayer {\n this.chime ??= createBrowserVoiceChimePlayer(resolveApiBase(this.settings.apiBase, this.settings.isDev))\n return this.chime\n }\n\n private playChime(kind: VoiceChimeKind): void {\n this.ensureChime().play(kind)\n }\n\n private async post<T>(args: { path: string, body: unknown, keepalive?: boolean }): Promise<T> {\n const apiBase = resolveApiBase(this.settings.apiBase, this.settings.isDev)\n const fetchFn = this.settings.fetchFn ?? fetch\n const res = await fetchFn(`${apiBase}${args.path}`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json', ...this.authHeaders() },\n credentials: 'include',\n keepalive: args.keepalive,\n body: JSON.stringify(args.body),\n })\n const result = await res.json() as ApiResponse<T>\n if (!res.ok || !result.ok) {\n const message = !result.ok ? result.error : `HTTP ${res.status}`\n const code = !result.ok && result.code ? result.code : 'VOICE_MINT_FAILED'\n throw Object.assign(new Error(message || 'Voice request failed.'), { code })\n }\n return result.data\n }\n\n private async mintSession(generation: number): Promise<VoiceSessionMint | null> {\n let conversationId = this.settings.conversationId\n if (!conversationId) {\n conversationId = (await this.post<{ conversationId: string }>({\n path: '/api/conversations',\n body: {\n orgId: this.settings.orgId,\n participants: [{ type: 'bot', id: this.settings.botId }],\n },\n })).conversationId\n if (generation !== this.generation)\n return null\n }\n\n const viewerTimezone = detectBrowserTimezone()\n const data = await this.post<unknown>({\n path: '/api/voice/sessions',\n body: { conversationId, ...(viewerTimezone ? { viewerTimezone } : {}) },\n })\n if (generation !== this.generation)\n return null\n const parsed = zVoiceSessionMint.safeParse(data)\n if (!parsed.success)\n throw Object.assign(new Error('Voice session mint returned an unexpected shape.'), { code: 'VOICE_MINT_INVALID' })\n this.conversationId = conversationId\n return parsed.data\n }\n\n private toSessionError(error: unknown, fallbackCode: string): VoiceSessionError {\n return error instanceof Error\n ? {\n code: 'code' in error ? String((error as Error & { code: unknown }).code) : fallbackCode,\n message: error.message,\n }\n : { code: fallbackCode, message: 'Voice session failed to start.' }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;EAcA,IAAM,IAAQ,GACR,IAAS,EAAI,EAAK,GAClB,IAAc,EAAI,EAAK;EAE7B,SAAS,SAAS;GAChB,EAAO,QAAQ,CAAC,EAAO;EACzB;EAGA,EAAM,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,OAAO,KAAK,SAAS;IACrB,cAAc,CAAC;KAAE,MAAM;KAAO,IAAI,KAAK,SAAS;IAAM,CAAC;GACzD;EACF,CAAC,EAAA,CAAG,gBACA,MAAe,KAAK,aACtB,OAAO;EAGX,IAAM,IAAiB,EAAsB,GACvC,IAAO,MAAM,KAAK,KAAc;GACpC,MAAM;GACN,MAAM;IAAE;IAAgB,GAAI,IAAiB,EAAE,kBAAe,IAAI,CAAC;GAAG;EACxE,CAAC;EACD,IAAI,MAAe,KAAK,YACtB,OAAO;EACT,IAAM,IAAS,EAAkB,UAAU,CAAI;EAC/C,IAAI,CAAC,EAAO,SACV,MAAM,OAAO,OAAO,gBAAI,MAAM,kDAAkD,GAAG,EAAE,MAAM,qBAAqB,CAAC;EAEnH,OADA,KAAK,iBAAiB,GACf,EAAO;CAChB;CAEA,eAAuB,GAAgB,GAAyC;EAC9E,OAAO,aAAiB,QACpB;GACE,MAAM,UAAU,IAAQ,OAAQ,EAAoC,IAAI,IAAI;GAC5E,SAAS,EAAM;EACjB,IACA;GAAE,MAAM;GAAc,SAAS;EAAiC;CACtE;AACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BotData, ComputerData, Bot, Computer } from '@pagelines/core';
|
|
2
|
+
import { SDKContext } from './types';
|
|
3
|
+
export declare class BotClient {
|
|
4
|
+
private ctx;
|
|
5
|
+
private computers;
|
|
6
|
+
private bots;
|
|
7
|
+
constructor(ctx: Pick<SDKContext, 'apiFetch'>);
|
|
8
|
+
get(botId: string): Bot | undefined;
|
|
9
|
+
computer(computerId: string): Computer | undefined;
|
|
10
|
+
all(): Bot[];
|
|
11
|
+
hydrate(roster: {
|
|
12
|
+
computers: ComputerData[];
|
|
13
|
+
bots: BotData[];
|
|
14
|
+
}): Bot[];
|
|
15
|
+
clear(): void;
|
|
16
|
+
webhook<T = Record<string, unknown>>(args: {
|
|
17
|
+
botId: string;
|
|
18
|
+
key: string;
|
|
19
|
+
type: string;
|
|
20
|
+
data: T;
|
|
21
|
+
meta?: Record<string, unknown>;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
ok: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChatAttachmentInput, ChatToolActivityData, ChatStreamError } from '@pagelines/core';
|
|
2
|
-
import { ChatMessage } from '../
|
|
2
|
+
import { ChatMessage } from '../bot/schema';
|
|
3
3
|
import { SDKContext } from './types';
|
|
4
4
|
type CancelConversationTurnResponse = {
|
|
5
5
|
cancelled: boolean;
|
|
@@ -13,7 +13,7 @@ export declare class ChatClient {
|
|
|
13
13
|
turnId?: string;
|
|
14
14
|
}): Promise<CancelConversationTurnResponse>;
|
|
15
15
|
/**
|
|
16
|
-
* Public/visitor chat — anonymous chat against an
|
|
16
|
+
* Public/visitor chat — anonymous chat against an bot's public handle,
|
|
17
17
|
* routed through the messaging substrate. Same SSE wire format as
|
|
18
18
|
* `chatStreamAuthenticated` — the only difference is the route (no auth,
|
|
19
19
|
* handle-based lookup, anonymousId instead of userId).
|
|
@@ -42,14 +42,15 @@ export declare class ChatClient {
|
|
|
42
42
|
* sequence, then POST /api/messages. Opening the stream before send keeps
|
|
43
43
|
* fast working_state / message_delta frames from outrunning the subscriber.
|
|
44
44
|
* Same callback contract as `chatStream` so callers don't need transport details.
|
|
45
|
-
* Mirrors `src/modules/
|
|
45
|
+
* Mirrors `src/modules/bot/client.ts → sendChatMessageStream`.
|
|
46
46
|
*/
|
|
47
47
|
chatStreamAuthenticated(args: {
|
|
48
|
-
|
|
48
|
+
botId: string;
|
|
49
|
+
orgId: string;
|
|
49
50
|
message: string;
|
|
50
51
|
attachments?: ChatAttachmentInput[];
|
|
51
|
-
/** Reserved — substrate resolves conversation server-side from (userId, agentId). */
|
|
52
52
|
conversationId?: string;
|
|
53
|
+
latestSequence?: string | null;
|
|
53
54
|
/** Reserved — substrate replays history from the canonical messages table. */
|
|
54
55
|
history?: Array<{
|
|
55
56
|
role: 'user' | 'assistant';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Bot, CreateComputerBody, LiveStatus } from '@pagelines/core';
|
|
2
|
+
import { SDKContext } from './types';
|
|
3
|
+
import { BotClient } from './BotClient';
|
|
4
|
+
export declare class ComputerClient {
|
|
5
|
+
private ctx;
|
|
6
|
+
private registry;
|
|
7
|
+
constructor(ctx: Pick<SDKContext, 'apiFetch' | 'logger' | 'token'>, registry: Pick<BotClient, 'hydrate' | 'computer'>);
|
|
8
|
+
create(body: CreateComputerBody): Promise<Bot>;
|
|
9
|
+
getLiveStatus(computerId: string): Promise<LiveStatus>;
|
|
10
|
+
waitUntilReady(args: {
|
|
11
|
+
computerId: string;
|
|
12
|
+
onStatus?: (lifecycle: LiveStatus['lifecycle']) => void;
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
pollIntervalMs?: number;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bot } from '@pagelines/core';
|
|
2
2
|
import { SDKContext } from './types';
|
|
3
3
|
export declare class UserClient {
|
|
4
4
|
private ctx;
|
|
5
5
|
constructor(ctx: SDKContext);
|
|
6
|
-
|
|
6
|
+
getPublicBot(args: {
|
|
7
7
|
handle: string;
|
|
8
|
-
}): Promise<
|
|
9
|
-
getAgentByEmail(args: {
|
|
10
|
-
email: string;
|
|
11
|
-
}): Promise<AgentConfig | undefined>;
|
|
8
|
+
}): Promise<Bot | undefined>;
|
|
12
9
|
generateAnonId(): string;
|
|
13
10
|
track(args: {
|
|
14
11
|
event: 'view_profile' | 'profile_interaction';
|
|
15
|
-
|
|
12
|
+
botId: string;
|
|
16
13
|
properties?: Record<string, any>;
|
|
17
14
|
}): void;
|
|
18
15
|
}
|
package/dist/clients/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bot, BotData, ComputerData, ApiResponse, EnrichedUser, LogHelper } from '@pagelines/core';
|
|
2
2
|
import { ComputedRef, Ref } from 'vue';
|
|
3
3
|
import { SDKStorage } from '../sdkStorage';
|
|
4
4
|
export interface SDKContext {
|
|
@@ -9,7 +9,12 @@ export interface SDKContext {
|
|
|
9
9
|
token: Ref<string | null>;
|
|
10
10
|
loading: Ref<boolean>;
|
|
11
11
|
error: Ref<string | null>;
|
|
12
|
-
|
|
12
|
+
currentBot: ComputedRef<Bot | undefined>;
|
|
13
|
+
hydrateRoster: (roster: {
|
|
14
|
+
computers: ComputerData[];
|
|
15
|
+
bots: BotData[];
|
|
16
|
+
}) => Bot[];
|
|
17
|
+
clearRoster: () => void;
|
|
13
18
|
storage: SDKStorage;
|
|
14
19
|
sessionId: string;
|
|
15
20
|
logger: LogHelper;
|