@pagelines/sdk 1.0.898 → 1.0.900
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/dist/BotWrap.js +594 -640
- package/dist/BotWrap.js.map +1 -1
- package/dist/bot/BotController.d.ts +2 -40
- package/dist/clients/BotClient.d.ts +1 -1
- package/dist/clients/ChatClient.d.ts +4 -4
- package/dist/sdk.css +1 -1
- package/dist/sdkClient.d.ts +8 -16
- package/dist/sdkClient.js +46 -46
- package/dist/sdkClient.js.map +1 -1
- package/dist/widget.js +115 -115
- package/dist/widget.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,28 +5,6 @@ import { BotMode, ChatAttachment, ChatMessage, TextConnectionState, Bot } from '
|
|
|
5
5
|
import { VoiceClientHandlers, VoiceSessionClient } from './voice/voice-session-client';
|
|
6
6
|
import { LiveTurnBlock, WorkJournalModel, WorkJournalOutcome } from './work-journal';
|
|
7
7
|
import { VoiceRecorderController } from './VoiceRecorderController';
|
|
8
|
-
export type ChatStreamErrorPresentation = {
|
|
9
|
-
surface: 'transcript';
|
|
10
|
-
issue: NonNullable<ChatMessage['issue']>;
|
|
11
|
-
sendBlockedReason?: 'account' | 'bot_deleted';
|
|
12
|
-
} | {
|
|
13
|
-
surface: 'transient';
|
|
14
|
-
issue: NonNullable<TextConnectionState['transientIssue']>;
|
|
15
|
-
} | {
|
|
16
|
-
surface: 'hard';
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Decide the rendering surface for a structured `error` SSE frame.
|
|
20
|
-
*
|
|
21
|
-
* Server contract: an `error` frame is never persisted — a message-shaped
|
|
22
|
-
* render of one silently vanishes on reload ("no disappearing states").
|
|
23
|
-
* Durable blocks (account bucket / deleted bot) keep the transcript row +
|
|
24
|
-
* send block because the widget gate path has no persisted explainer behind
|
|
25
|
-
* them; every other soft issue is retry-in-chat → live chrome, like
|
|
26
|
-
* `workingDescription`.
|
|
27
|
-
*/
|
|
28
|
-
export declare function presentChatStreamError(error: ChatStreamError): ChatStreamErrorPresentation;
|
|
29
|
-
export declare function transcriptMessageForChatStreamError(error: ChatStreamError): string;
|
|
30
8
|
export type ChatStreamFn = (args: {
|
|
31
9
|
message: string;
|
|
32
10
|
attachments?: ChatAttachment[];
|
|
@@ -39,7 +17,7 @@ export type ChatStreamFn = (args: {
|
|
|
39
17
|
onMessage?: (message: ChatMessage) => void;
|
|
40
18
|
onUserMessage?: (message: ChatMessage) => void;
|
|
41
19
|
onDone: (conversationId: string) => void;
|
|
42
|
-
onError: (error:
|
|
20
|
+
onError: (error: ChatStreamError) => void;
|
|
43
21
|
onStatus?: (status: string) => void;
|
|
44
22
|
onToolActivity?: (activity: ChatToolActivityData) => void;
|
|
45
23
|
onWorkingEnd?: () => void;
|
|
@@ -194,15 +172,6 @@ export declare class BotChatController extends SettingsObject<BotChatControllerS
|
|
|
194
172
|
constructor(settings: BotChatControllerSettings);
|
|
195
173
|
get chatEnabled(): boolean;
|
|
196
174
|
get chatUnavailableReason(): string | undefined;
|
|
197
|
-
private mapChatError;
|
|
198
|
-
/**
|
|
199
|
-
* Errors we treat as recoverable mid-conversation: rate limits, timeouts,
|
|
200
|
-
* transient infra blips, dropped streams. We render an inline system bubble
|
|
201
|
-
* and keep the input enabled so the next attempt can succeed without
|
|
202
|
-
* forcing a manual reload. Hard errors (auth lost, bot missing) still
|
|
203
|
-
* fall through to handleError which marks the conversation dead.
|
|
204
|
-
*/
|
|
205
|
-
private isTransientError;
|
|
206
175
|
private isDuplicateMessage;
|
|
207
176
|
private addMessage;
|
|
208
177
|
/**
|
|
@@ -294,14 +263,7 @@ export declare class BotChatController extends SettingsObject<BotChatControllerS
|
|
|
294
263
|
}): WorkJournalModel | undefined;
|
|
295
264
|
private setupModeWatcher;
|
|
296
265
|
private setupAvailabilityWatcher;
|
|
297
|
-
/**
|
|
298
|
-
* Hard error path. Resets the connection and surfaces an inline bubble so
|
|
299
|
-
* the user actually sees what happened — `connectionStatus: 'error'`
|
|
300
|
-
* alone doesn't render anywhere. The raw error is kept on console.error
|
|
301
|
-
* so devs can tell which pipeline stage failed (the `[api]` /
|
|
302
|
-
* `[stream-open]` / `[stream-read]` / `[no-reply]` tags from
|
|
303
|
-
* bot/client.ts survive into the console line).
|
|
304
|
-
*/
|
|
266
|
+
/** Reset failed conversation setup and leave a visible explanation. */
|
|
305
267
|
private handleError;
|
|
306
268
|
setMode(mode: BotMode): Promise<void>;
|
|
307
269
|
startTextConversation(callbacks?: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatAttachmentInput, ChatToolActivityData, ChatStreamError } from '@pagelines/core';
|
|
1
|
+
import { ChatAttachment, ChatAttachmentInput, ChatToolActivityData, ChatStreamError } from '@pagelines/core';
|
|
2
2
|
import { ChatMessage } from '../bot/schema';
|
|
3
3
|
import { SDKContext } from './types';
|
|
4
4
|
type CancelConversationTurnResponse = {
|
|
@@ -26,12 +26,12 @@ export declare class ChatClient {
|
|
|
26
26
|
handle: string;
|
|
27
27
|
message: string;
|
|
28
28
|
anonymousId: string;
|
|
29
|
-
attachments?:
|
|
29
|
+
attachments?: ChatAttachment[];
|
|
30
30
|
context?: string;
|
|
31
31
|
onDelta: (text: string, role?: 'assistant' | 'system') => void;
|
|
32
32
|
onMessage?: (message: ChatMessage) => void;
|
|
33
33
|
onDone: (conversationId: string) => void;
|
|
34
|
-
onError: (error:
|
|
34
|
+
onError: (error: ChatStreamError) => void;
|
|
35
35
|
onStatus?: (status: string) => void;
|
|
36
36
|
onToolActivity?: (activity: ChatToolActivityData) => void;
|
|
37
37
|
onWorkingEnd?: () => void;
|
|
@@ -59,7 +59,7 @@ export declare class ChatClient {
|
|
|
59
59
|
onDelta: (text: string, role?: 'assistant' | 'system') => void;
|
|
60
60
|
onMessage?: (message: ChatMessage) => void;
|
|
61
61
|
onDone: (conversationId: string) => void;
|
|
62
|
-
onError: (error:
|
|
62
|
+
onError: (error: ChatStreamError) => void;
|
|
63
63
|
onStatus?: (status: string) => void;
|
|
64
64
|
onToolActivity?: (activity: ChatToolActivityData) => void;
|
|
65
65
|
onWorkingEnd?: () => void;
|
package/dist/sdk.css
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
:where(.spinner){color:var(--color-theme-300)}.ring-circular{animation:1s linear infinite rotate}.ring-path{will-change:stroke-dasharray;will-change:stroke-dashoffset;stroke-dasharray:1 200;stroke-dashoffset:0;stroke-linecap:round;animation:2s ease-in-out infinite dash}@keyframes rotate{to{transform:rotate(360deg)}}@keyframes dash{0%{stroke-dasharray:1 200;stroke-dashoffset:0}50%{stroke-dasharray:89 200;stroke-dashoffset:-35px}to{stroke-dasharray:89 200;stroke-dashoffset:-124px}}.voice-call-enter-active[data-v-
|
|
1
|
+
:where(.spinner){color:var(--color-theme-300)}.ring-circular{animation:1s linear infinite rotate}.ring-path{will-change:stroke-dasharray;will-change:stroke-dashoffset;stroke-dasharray:1 200;stroke-dashoffset:0;stroke-linecap:round;animation:2s ease-in-out infinite dash}@keyframes rotate{to{transform:rotate(360deg)}}@keyframes dash{0%{stroke-dasharray:1 200;stroke-dashoffset:0}50%{stroke-dasharray:89 200;stroke-dashoffset:-35px}to{stroke-dasharray:89 200;stroke-dashoffset:-124px}}.voice-call-enter-active[data-v-5450b422]{transition:opacity .3s cubic-bezier(.25,1,.33,1)}.voice-call-leave-active[data-v-5450b422]{transition:opacity .2s cubic-bezier(.5,0,.75,0)}.voice-call-enter-active .voice-call-card[data-v-5450b422]{transition:transform .42s cubic-bezier(.25,1,.33,1)}.voice-call-leave-active .voice-call-card[data-v-5450b422]{transition:transform .2s cubic-bezier(.5,0,.75,0)}.voice-call-enter-from[data-v-5450b422],.voice-call-leave-to[data-v-5450b422]{opacity:0}.voice-call-enter-from .voice-call-card[data-v-5450b422]{transform:translateY(32px)}.voice-call-leave-to .voice-call-card[data-v-5450b422]{transform:translateY(12px)}@media (prefers-reduced-motion:reduce){.voice-call-enter-active[data-v-5450b422],.voice-call-leave-active[data-v-5450b422],.voice-call-enter-active .voice-call-card[data-v-5450b422],.voice-call-leave-active .voice-call-card[data-v-5450b422]{transition-duration:1ms}.voice-call-enter-from .voice-call-card[data-v-5450b422],.voice-call-leave-to .voice-call-card[data-v-5450b422]{transform:none}}.nlist-enter-active,.nlist-leave-active,.nlist-move{transition:all .6s cubic-bezier(.68,-.55,.27,1.55)}.nlist-enter-from{opacity:0;transform:translate(-30px)scale(.9)}.nlist-enter-to{opacity:1;transform:translate(0)scale(1)}.nlist-leave-active{position:absolute}.nlist-leave-to{opacity:0;transform:scale(.9)}.widget-container[data-v-5674cae2]{transition:width .4s cubic-bezier(.32,.72,0,1),height .4s cubic-bezier(.32,.72,0,1),border-radius .4s cubic-bezier(.32,.72,0,1),box-shadow .4s cubic-bezier(.32,.72,0,1)}
|
|
2
2
|
/*$vite$:1*/
|
package/dist/sdkClient.d.ts
CHANGED
|
@@ -37,11 +37,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
37
37
|
src?: string | undefined;
|
|
38
38
|
alt?: string | undefined;
|
|
39
39
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
40
|
-
status?: "
|
|
40
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
41
41
|
quality?: "high" | "low" | "standard" | undefined;
|
|
42
42
|
createdAt?: string | undefined;
|
|
43
43
|
updatedAt?: string | undefined;
|
|
44
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
45
44
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
46
45
|
className?: string | undefined;
|
|
47
46
|
width?: number | undefined;
|
|
@@ -80,11 +79,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
80
79
|
src?: string | undefined;
|
|
81
80
|
alt?: string | undefined;
|
|
82
81
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
83
|
-
status?: "
|
|
82
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
84
83
|
quality?: "high" | "low" | "standard" | undefined;
|
|
85
84
|
createdAt?: string | undefined;
|
|
86
85
|
updatedAt?: string | undefined;
|
|
87
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
88
86
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
89
87
|
className?: string | undefined;
|
|
90
88
|
width?: number | undefined;
|
|
@@ -104,11 +102,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
104
102
|
src?: string | undefined;
|
|
105
103
|
alt?: string | undefined;
|
|
106
104
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
107
|
-
status?: "
|
|
105
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
108
106
|
quality?: "high" | "low" | "standard" | undefined;
|
|
109
107
|
createdAt?: string | undefined;
|
|
110
108
|
updatedAt?: string | undefined;
|
|
111
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
112
109
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
113
110
|
className?: string | undefined;
|
|
114
111
|
width?: number | undefined;
|
|
@@ -149,11 +146,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
149
146
|
src?: string | undefined;
|
|
150
147
|
alt?: string | undefined;
|
|
151
148
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
152
|
-
status?: "
|
|
149
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
153
150
|
quality?: "high" | "low" | "standard" | undefined;
|
|
154
151
|
createdAt?: string | undefined;
|
|
155
152
|
updatedAt?: string | undefined;
|
|
156
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
157
153
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
158
154
|
className?: string | undefined;
|
|
159
155
|
width?: number | undefined;
|
|
@@ -192,11 +188,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
192
188
|
src?: string | undefined;
|
|
193
189
|
alt?: string | undefined;
|
|
194
190
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
195
|
-
status?: "
|
|
191
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
196
192
|
quality?: "high" | "low" | "standard" | undefined;
|
|
197
193
|
createdAt?: string | undefined;
|
|
198
194
|
updatedAt?: string | undefined;
|
|
199
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
200
195
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
201
196
|
className?: string | undefined;
|
|
202
197
|
width?: number | undefined;
|
|
@@ -216,11 +211,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
216
211
|
src?: string | undefined;
|
|
217
212
|
alt?: string | undefined;
|
|
218
213
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
219
|
-
status?: "
|
|
214
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
220
215
|
quality?: "high" | "low" | "standard" | undefined;
|
|
221
216
|
createdAt?: string | undefined;
|
|
222
217
|
updatedAt?: string | undefined;
|
|
223
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
224
218
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
225
219
|
className?: string | undefined;
|
|
226
220
|
width?: number | undefined;
|
|
@@ -270,11 +264,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
270
264
|
src?: string | undefined;
|
|
271
265
|
alt?: string | undefined;
|
|
272
266
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
273
|
-
status?: "
|
|
267
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
274
268
|
quality?: "high" | "low" | "standard" | undefined;
|
|
275
269
|
createdAt?: string | undefined;
|
|
276
270
|
updatedAt?: string | undefined;
|
|
277
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
278
271
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
279
272
|
className?: string | undefined;
|
|
280
273
|
width?: number | undefined;
|
|
@@ -294,11 +287,10 @@ export declare class PageLinesSDK extends SettingsObject<PageLinesSDKSettings> {
|
|
|
294
287
|
src?: string | undefined;
|
|
295
288
|
alt?: string | undefined;
|
|
296
289
|
context?: "avatar" | "cover" | "general" | undefined;
|
|
297
|
-
status?: "
|
|
290
|
+
status?: "processing" | "active" | "failed" | "deleted" | undefined;
|
|
298
291
|
quality?: "high" | "low" | "standard" | undefined;
|
|
299
292
|
createdAt?: string | undefined;
|
|
300
293
|
updatedAt?: string | undefined;
|
|
301
|
-
type?: "audio" | "document" | "image" | "video" | undefined;
|
|
302
294
|
mediaType?: "audio" | "document" | "image" | "video" | undefined;
|
|
303
295
|
className?: string | undefined;
|
|
304
296
|
width?: number | undefined;
|
package/dist/sdkClient.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./rolldown-runtime.js";
|
|
2
|
-
import { Bot as e, Computer as t, PAGELINES_APP_CONFIG as n, SettingsObject as r, UNKNOWN_STATUS as i,
|
|
2
|
+
import { Bot as e, Computer as t, PAGELINES_APP_CONFIG as n, SettingsObject as r, UNKNOWN_STATUS as i, chatTransportError as a, cookieUtil as o, createLogger as s, detectBrowserTimezone as c, objectId as l, readChatEventStream as u, runAuthenticatedChatTurnStream as d, serverTransitionBudgets as f, shortId as p } from "@pagelines/core";
|
|
3
3
|
import { computed as m, ref as h, shallowReactive as g, watch as _ } from "vue";
|
|
4
4
|
//#region api.ts
|
|
5
5
|
function resolveApiBase(e, t) {
|
|
@@ -9,8 +9,8 @@ function resolveApiBase(e, t) {
|
|
|
9
9
|
function createApiFetch(e, t, n) {
|
|
10
10
|
let r = resolveApiBase(e.apiBase, e.isDev);
|
|
11
11
|
return async (e, i) => {
|
|
12
|
-
let
|
|
13
|
-
s.has("Content-Type") || s.set("Content-Type", "application/json"),
|
|
12
|
+
let a = o.getAuthToken(), s = new Headers(i?.headers);
|
|
13
|
+
s.has("Content-Type") || s.set("Content-Type", "application/json"), a && !s.has("Authorization") && s.set("Authorization", `Bearer ${a}`);
|
|
14
14
|
let c = typeof e == "string" && e.startsWith("/") ? `${r}${e}` : e, l = await fetch(c, {
|
|
15
15
|
...i,
|
|
16
16
|
headers: s,
|
|
@@ -117,7 +117,7 @@ function _defineProperty(e, t, n) {
|
|
|
117
117
|
//#region sdkStorage.ts
|
|
118
118
|
var T = globalThis, E = T.__PL_AUTH_USER__ ?? (T.__PL_AUTH_USER__ = /* @__PURE__ */ atom(void 0)), D = T.__PL_AUTH_TOKEN__ ?? (T.__PL_AUTH_TOKEN__ = /* @__PURE__ */ atom(null)), O = T.__PL_AUTH_DEVICE_ID__ ?? (T.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ atom(null)), SDKStorage = class {
|
|
119
119
|
constructor() {
|
|
120
|
-
_defineProperty(this, "logger",
|
|
120
|
+
_defineProperty(this, "logger", s("SDKStorage"));
|
|
121
121
|
}
|
|
122
122
|
isLocalStorageFunctional() {
|
|
123
123
|
return typeof window < "u" && typeof localStorage?.getItem == "function" && typeof localStorage?.setItem == "function" && typeof localStorage?.removeItem == "function";
|
|
@@ -134,9 +134,9 @@ var T = globalThis, E = T.__PL_AUTH_USER__ ?? (T.__PL_AUTH_USER__ = /* @__PURE__
|
|
|
134
134
|
}
|
|
135
135
|
loadFromStorage(e) {
|
|
136
136
|
if (typeof window > "u") return;
|
|
137
|
-
let t =
|
|
137
|
+
let t = o.getAuthToken();
|
|
138
138
|
t && (e.token.value = t);
|
|
139
|
-
let n =
|
|
139
|
+
let n = o.getDeviceId();
|
|
140
140
|
if (n && (e.deviceId.value = n), this.isLocalStorageFunctional()) try {
|
|
141
141
|
let t = localStorage.getItem("pagelines-user");
|
|
142
142
|
t && (e.activeUser.value = JSON.parse(t));
|
|
@@ -145,7 +145,7 @@ var T = globalThis, E = T.__PL_AUTH_USER__ ?? (T.__PL_AUTH_USER__ = /* @__PURE__
|
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
saveToStorage(e) {
|
|
148
|
-
if (!(typeof window > "u") && (e.token.value ?
|
|
148
|
+
if (!(typeof window > "u") && (e.token.value ? o.setAuthToken(e.token.value) : o.removeAuthToken(), this.isLocalStorageFunctional())) try {
|
|
149
149
|
e.activeUser.value ? localStorage.setItem("pagelines-user", JSON.stringify(e.activeUser.value)) : localStorage.removeItem("pagelines-user");
|
|
150
150
|
} catch (e) {
|
|
151
151
|
this.logger.error("Failed to save user to localStorage", { data: e });
|
|
@@ -153,7 +153,7 @@ var T = globalThis, E = T.__PL_AUTH_USER__ ?? (T.__PL_AUTH_USER__ = /* @__PURE__
|
|
|
153
153
|
}
|
|
154
154
|
clearStorage() {
|
|
155
155
|
if (!(typeof window > "u")) {
|
|
156
|
-
if (
|
|
156
|
+
if (o.removeAuthToken(), this.isLocalStorageFunctional()) try {
|
|
157
157
|
localStorage.removeItem("pagelines-user");
|
|
158
158
|
} catch (e) {
|
|
159
159
|
this.logger.error("Failed to clear user from localStorage", { data: e });
|
|
@@ -213,11 +213,11 @@ var T = globalThis, E = T.__PL_AUTH_USER__ ?? (T.__PL_AUTH_USER__ = /* @__PURE__
|
|
|
213
213
|
this.bots.clear(), this.computers.clear();
|
|
214
214
|
}
|
|
215
215
|
async webhook(e) {
|
|
216
|
-
let t = await this.ctx.apiFetch(`/api/bot-api/webhooks/
|
|
216
|
+
let t = await this.ctx.apiFetch(`/api/bot-api/webhooks/routine-triggers/${encodeURIComponent(e.triggerId)}`, {
|
|
217
217
|
method: "POST",
|
|
218
218
|
headers: {
|
|
219
219
|
"Content-Type": "application/json",
|
|
220
|
-
"X-PageLines-
|
|
220
|
+
"X-PageLines-Key": e.key
|
|
221
221
|
},
|
|
222
222
|
body: JSON.stringify({
|
|
223
223
|
type: e.type,
|
|
@@ -262,7 +262,7 @@ var T = globalThis, E = T.__PL_AUTH_USER__ ?? (T.__PL_AUTH_USER__ = /* @__PURE__
|
|
|
262
262
|
}
|
|
263
263
|
async waitUntilReady(e) {
|
|
264
264
|
let t = Date.now(), n;
|
|
265
|
-
for (; Date.now() - t < (e.timeoutMs ??
|
|
265
|
+
for (; Date.now() - t < (e.timeoutMs ?? f.wake);) {
|
|
266
266
|
let t = await this.getLiveStatus(e.computerId);
|
|
267
267
|
if (t.lifecycle !== n && (e.onStatus?.(t.lifecycle), n = t.lifecycle), t.lifecycle === "running") return;
|
|
268
268
|
if (t.lifecycle === "error") throw Error("Your computer hit a problem starting");
|
|
@@ -472,9 +472,6 @@ var AuthClient = class {
|
|
|
472
472
|
};
|
|
473
473
|
//#endregion
|
|
474
474
|
//#region clients/ChatClient.ts
|
|
475
|
-
function toAuthenticatedTransportError(e) {
|
|
476
|
-
return e.stage === "stream-open" && e.message.startsWith("HTTP ") ? `Stream failed: ${e.message}` : e.message;
|
|
477
|
-
}
|
|
478
475
|
function toChatMessage(e) {
|
|
479
476
|
if (e.role === "assistant" || e.role === "system") return {
|
|
480
477
|
id: e.messageId,
|
|
@@ -507,52 +504,58 @@ var ChatClient = class {
|
|
|
507
504
|
return i.data;
|
|
508
505
|
}
|
|
509
506
|
async chatStreamPublic(e) {
|
|
510
|
-
let t = `${resolveApiBase(this.ctx.apiBase, this.ctx.isDev)}/api/bots/public/${encodeURIComponent(e.handle)}/chat/stream`, n = "", r = !1, i = !1,
|
|
507
|
+
let t = `${resolveApiBase(this.ctx.apiBase, this.ctx.isDev)}/api/bots/public/${encodeURIComponent(e.handle)}/chat/stream`, n = "", r = !1, i = !1, o;
|
|
511
508
|
try {
|
|
512
|
-
let
|
|
509
|
+
let s = await fetch(t, {
|
|
513
510
|
method: "POST",
|
|
514
511
|
headers: { "Content-Type": "application/json" },
|
|
515
512
|
body: JSON.stringify({
|
|
516
513
|
message: e.message,
|
|
517
514
|
anonymousId: e.anonymousId,
|
|
518
|
-
...e.attachments?.length ? { attachments: e.attachments
|
|
515
|
+
...e.attachments?.length ? { attachments: e.attachments.map(({ type: e, src: t, filename: n, mimeType: r, mediaId: i }) => ({
|
|
516
|
+
type: e,
|
|
517
|
+
url: t,
|
|
518
|
+
name: n,
|
|
519
|
+
mimeType: r,
|
|
520
|
+
mediaId: i
|
|
521
|
+
})) } : {},
|
|
519
522
|
...e.context ? { context: e.context } : {}
|
|
520
523
|
})
|
|
521
524
|
});
|
|
522
|
-
if (!
|
|
523
|
-
let t = await
|
|
524
|
-
e.onError(t.error || `HTTP ${
|
|
525
|
+
if (!s.ok) {
|
|
526
|
+
let t = await s.json().catch(() => ({ error: "Request failed" }));
|
|
527
|
+
e.onError(a("api", t.error || `HTTP ${s.status}`, t.code));
|
|
525
528
|
return;
|
|
526
529
|
}
|
|
527
|
-
if (n =
|
|
528
|
-
e.onError("No response stream");
|
|
530
|
+
if (n = s.headers.get("X-Conversation-Id") || "", o = s.body?.getReader(), !o) {
|
|
531
|
+
e.onError(a("stream-open", "No response stream"));
|
|
529
532
|
return;
|
|
530
533
|
}
|
|
531
|
-
for await (let t of
|
|
534
|
+
for await (let t of u(o)) if (t.event === "working_state") e.onStatus?.(t.data.description);
|
|
532
535
|
else if (t.event === "tool_activity") e.onToolActivity?.(t.data);
|
|
533
536
|
else if (t.event === "working_end") e.onWorkingEnd?.();
|
|
534
537
|
else if (t.event === "message_delta") e.onDelta(t.data.delta, t.data.role);
|
|
535
538
|
else if (t.event === "error") {
|
|
536
|
-
r = !0, e.onError(
|
|
539
|
+
r = !0, e.onError(t.data);
|
|
537
540
|
break;
|
|
538
541
|
} else if (t.event === "message" && (t.data.message.role === "assistant" || t.data.message.role === "system")) {
|
|
539
542
|
i = !0;
|
|
540
543
|
let n = toChatMessage(t.data.message);
|
|
541
544
|
n && e.onMessage?.(n);
|
|
542
545
|
} else if (t.event === "stream_end") break;
|
|
543
|
-
!r && i ? e.onDone(n) : r || e.onError("
|
|
546
|
+
!r && i ? e.onDone(n) : r || e.onError(a("no-reply", "Stream ended before reply arrived"));
|
|
544
547
|
} catch (t) {
|
|
545
|
-
e.onError(t instanceof Error ? t.message : "Stream failed");
|
|
548
|
+
e.onError(a("stream-read", t instanceof Error ? t.message : "Stream failed", "NETWORK_ERROR"));
|
|
546
549
|
} finally {
|
|
547
550
|
try {
|
|
548
|
-
await
|
|
551
|
+
await o?.cancel();
|
|
549
552
|
} catch {}
|
|
550
553
|
}
|
|
551
554
|
}
|
|
552
555
|
async chatStreamAuthenticated(e) {
|
|
553
556
|
let t = resolveApiBase(this.ctx.apiBase, this.ctx.isDev), n = this.ctx.token.value ? { Authorization: `Bearer ${this.ctx.token.value}` } : {}, r = e.conversationId, i = e.latestSequence ?? null;
|
|
554
557
|
if (!r) try {
|
|
555
|
-
let
|
|
558
|
+
let o = await fetch(`${t}/api/conversations`, {
|
|
556
559
|
method: "POST",
|
|
557
560
|
headers: {
|
|
558
561
|
"Content-Type": "application/json",
|
|
@@ -565,26 +568,26 @@ var ChatClient = class {
|
|
|
565
568
|
id: e.botId
|
|
566
569
|
}]
|
|
567
570
|
})
|
|
568
|
-
}),
|
|
569
|
-
if (!
|
|
570
|
-
e.onError(
|
|
571
|
+
}), s = await o.json();
|
|
572
|
+
if (!s.ok) {
|
|
573
|
+
e.onError(a("api", s.error || `Conversation failed: HTTP ${o.status}`, s.code));
|
|
571
574
|
return;
|
|
572
575
|
}
|
|
573
|
-
r =
|
|
576
|
+
r = s.data.conversationId, i = s.data.latestSequence ?? null;
|
|
574
577
|
} catch (t) {
|
|
575
|
-
e.onError(t instanceof Error ? t.message : "Conversation failed");
|
|
578
|
+
e.onError(a("api", t instanceof Error ? t.message : "Conversation failed", "NETWORK_ERROR"));
|
|
576
579
|
return;
|
|
577
580
|
}
|
|
578
|
-
let
|
|
579
|
-
await
|
|
580
|
-
streamUrl:
|
|
581
|
+
let o = i ? `${t}/api/conversations/${encodeURIComponent(r)}/stream?since=${encodeURIComponent(i)}` : `${t}/api/conversations/${encodeURIComponent(r)}/stream`, s = `nonce_${p(16)}`, l = c();
|
|
582
|
+
await d({
|
|
583
|
+
streamUrl: o,
|
|
581
584
|
sendUrl: `${t}/api/messages`,
|
|
582
585
|
headers: n,
|
|
583
586
|
sendBody: {
|
|
584
587
|
conversationId: r,
|
|
585
588
|
content: e.message,
|
|
586
|
-
clientNonce:
|
|
587
|
-
...
|
|
589
|
+
clientNonce: s,
|
|
590
|
+
...l ? { viewerTimezone: l } : {},
|
|
588
591
|
...e.attachments && e.attachments.length > 0 ? { attachments: e.attachments } : {}
|
|
589
592
|
},
|
|
590
593
|
onStatus: e.onStatus,
|
|
@@ -596,11 +599,8 @@ var ChatClient = class {
|
|
|
596
599
|
n && e.onMessage?.(n);
|
|
597
600
|
},
|
|
598
601
|
onDone: () => e.onDone(r),
|
|
599
|
-
onChatError:
|
|
600
|
-
onTransportError:
|
|
601
|
-
code: t.code,
|
|
602
|
-
error: t.message
|
|
603
|
-
} : toAuthenticatedTransportError(t))
|
|
602
|
+
onChatError: e.onError,
|
|
603
|
+
onTransportError: e.onError
|
|
604
604
|
});
|
|
605
605
|
}
|
|
606
606
|
}, UserClient = class {
|
|
@@ -634,7 +634,7 @@ var ChatClient = class {
|
|
|
634
634
|
}
|
|
635
635
|
generateAnonId() {
|
|
636
636
|
let e = "pagelinesAnonId", t = this.ctx.storage.getItem(e);
|
|
637
|
-
return t || (t =
|
|
637
|
+
return t || (t = l({ prefix: "anon" }), this.ctx.storage.setItem(e, t)), t;
|
|
638
638
|
}
|
|
639
639
|
track(e) {
|
|
640
640
|
try {
|
|
@@ -677,7 +677,7 @@ var ChatClient = class {
|
|
|
677
677
|
constructor(e = {}) {
|
|
678
678
|
let t = A.get();
|
|
679
679
|
if (t) return console.debug("[PageLinesSDK] Returning existing singleton instance"), t;
|
|
680
|
-
super("PageLinesSDK", e), _defineProperty(this, "activeUser", h()), _defineProperty(this, "token", h(null)), _defineProperty(this, "deviceId", h(null)), _defineProperty(this, "loading", h(!1)), _defineProperty(this, "error", h(null)), _defineProperty(this, "apiBase", this.settings.apiBase || void 0), _defineProperty(this, "storage", new SDKStorage()), _defineProperty(this, "sessionId",
|
|
680
|
+
super("PageLinesSDK", e), _defineProperty(this, "activeUser", h()), _defineProperty(this, "token", h(null)), _defineProperty(this, "deviceId", h(null)), _defineProperty(this, "loading", h(!1)), _defineProperty(this, "error", h(null)), _defineProperty(this, "apiBase", this.settings.apiBase || void 0), _defineProperty(this, "storage", new SDKStorage()), _defineProperty(this, "sessionId", l({ prefix: "ses" })), _defineProperty(this, "currentBot", m(() => {
|
|
681
681
|
let e = this.activeUser.value;
|
|
682
682
|
return (e?.lastBotId ? this.bot.get(e.lastBotId) : void 0) ?? this.bot.all().find((t) => t.isPrimary.value && t.ownerId.value === e?.userId);
|
|
683
683
|
})), _defineProperty(this, "currentOrg", m(() => {
|
|
@@ -732,7 +732,7 @@ var ChatClient = class {
|
|
|
732
732
|
this.bot.clear(), this.logger.info("Clearing session"), this.activeUser.value = void 0, this.token.value = null, this.deviceId.value = null, this.error.value = null, this.storage.clearStorage();
|
|
733
733
|
}
|
|
734
734
|
clear() {
|
|
735
|
-
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId =
|
|
735
|
+
this.logger.info("Clearing SDK completely"), this.clearSession(), this.loading.value = !1, this.sessionId = l({ prefix: "ses" }), this.stopAccountWatch?.(), A.delete();
|
|
736
736
|
}
|
|
737
737
|
};
|
|
738
738
|
//#endregion
|