@webless/agent 0.3.0 → 0.3.2
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/{chunk-MRSLWREA.js → chunk-APNF27K2.js} +57 -16
- package/dist/chunk-APNF27K2.js.map +1 -0
- package/dist/embed.cjs +70 -15
- package/dist/embed.cjs.map +1 -1
- package/dist/embed.css +4 -0
- package/dist/embed.css.map +1 -1
- package/dist/embed.js +15 -1
- package/dist/embed.js.map +1 -1
- package/dist/index.cjs +32 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +32 -7
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +56 -15
- package/dist/react.cjs.map +1 -1
- package/dist/react.css +4 -0
- package/dist/react.css.map +1 -1
- package/dist/react.d.cts +5 -3
- package/dist/react.d.ts +5 -3
- package/dist/react.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-MRSLWREA.js.map +0 -1
package/dist/react.cjs
CHANGED
|
@@ -162,11 +162,12 @@ function createAgentRuntimeCapability(options) {
|
|
|
162
162
|
let pendingBootstrap;
|
|
163
163
|
const bootstrap = async () => {
|
|
164
164
|
let previewGrant;
|
|
165
|
+
const previewBuildId = options.previewBuildId?.trim();
|
|
165
166
|
if (options.version === "unpublished") {
|
|
166
|
-
previewGrant = (await options.getUnpublishedPreviewGrant?.())?.trim();
|
|
167
|
-
if (!previewGrant) {
|
|
167
|
+
previewGrant = previewBuildId ? void 0 : (await options.getUnpublishedPreviewGrant?.())?.trim();
|
|
168
|
+
if (!previewGrant && !previewBuildId) {
|
|
168
169
|
throw new Error(
|
|
169
|
-
"
|
|
170
|
+
"Unpublished preview authorization is required to use the Agent Runtime preview."
|
|
170
171
|
);
|
|
171
172
|
}
|
|
172
173
|
}
|
|
@@ -176,6 +177,7 @@ function createAgentRuntimeCapability(options) {
|
|
|
176
177
|
body: JSON.stringify({
|
|
177
178
|
clientSessionId: options.visitorSessionId,
|
|
178
179
|
indexId: options.indexId,
|
|
180
|
+
...previewBuildId ? { previewBuildId } : {},
|
|
179
181
|
...previewGrant ? { previewGrant } : {},
|
|
180
182
|
version: options.version
|
|
181
183
|
}),
|
|
@@ -495,7 +497,7 @@ function applyWorkEvent(event, handlers, workItems) {
|
|
|
495
497
|
);
|
|
496
498
|
}
|
|
497
499
|
var AgentSession = class {
|
|
498
|
-
constructor(indexId, version, runtimeOrigin, visitorSessionId, storeOptions, getUnpublishedPreviewGrant) {
|
|
500
|
+
constructor(indexId, version, runtimeOrigin, visitorSessionId, storeOptions, previewBuildId, getUnpublishedPreviewGrant) {
|
|
499
501
|
this.indexId = indexId;
|
|
500
502
|
this.version = version;
|
|
501
503
|
this.runtimeOrigin = runtimeOrigin;
|
|
@@ -504,6 +506,7 @@ var AgentSession = class {
|
|
|
504
506
|
this.capability = createAgentRuntimeCapability({
|
|
505
507
|
getUnpublishedPreviewGrant,
|
|
506
508
|
indexId,
|
|
509
|
+
previewBuildId,
|
|
507
510
|
runtimeOrigin,
|
|
508
511
|
version,
|
|
509
512
|
visitorSessionId
|
|
@@ -748,6 +751,7 @@ function createAgentClient(options) {
|
|
|
748
751
|
runtimeOrigin,
|
|
749
752
|
visitorSessionId,
|
|
750
753
|
storeOptions,
|
|
754
|
+
options.previewBuildId,
|
|
751
755
|
options.getUnpublishedPreviewGrant
|
|
752
756
|
);
|
|
753
757
|
return {
|
|
@@ -774,6 +778,16 @@ function createAgentClient(options) {
|
|
|
774
778
|
|
|
775
779
|
// src/runtime/errors.ts
|
|
776
780
|
var import_client3 = require("eve/client");
|
|
781
|
+
var TRANSIENT_AGENT_ERROR_MESSAGE = "I couldn\u2019t finish that answer. Please try again.";
|
|
782
|
+
var PREVIEW_AUTHORIZATION_ERROR_MESSAGE = "This preview could not be authorized. Open the latest preview from Webless.";
|
|
783
|
+
function isTransientRuntimeMessage(message) {
|
|
784
|
+
const normalized = message.trim().toLowerCase();
|
|
785
|
+
return normalized.includes("empty response from runtime") || normalized.includes("failed to fetch") || normalized.includes("networkerror") || normalized.includes("load failed");
|
|
786
|
+
}
|
|
787
|
+
function isPreviewAuthorizationMessage(message) {
|
|
788
|
+
const normalized = message.trim().toLowerCase();
|
|
789
|
+
return normalized.includes("unpublished preview authorization") || normalized.includes("unpublished preview grant") || normalized.includes("agent studio preview grant") || normalized.includes("preview authorization");
|
|
790
|
+
}
|
|
777
791
|
function formatAgentError(error) {
|
|
778
792
|
if (error instanceof import_client3.ClientError) {
|
|
779
793
|
if (error.status === 401 && error.code === "index_required") {
|
|
@@ -785,13 +799,24 @@ function formatAgentError(error) {
|
|
|
785
799
|
if (error.status === 409 && error.code === "session_not_active") {
|
|
786
800
|
return "Session expired \u2014 send a new message to start again.";
|
|
787
801
|
}
|
|
788
|
-
|
|
802
|
+
if (error.message && isPreviewAuthorizationMessage(error.message)) {
|
|
803
|
+
return PREVIEW_AUTHORIZATION_ERROR_MESSAGE;
|
|
804
|
+
}
|
|
805
|
+
if (error.status >= 500 || error.message && isTransientRuntimeMessage(error.message)) {
|
|
806
|
+
return TRANSIENT_AGENT_ERROR_MESSAGE;
|
|
807
|
+
}
|
|
808
|
+
return error.message || "This assistant is unavailable right now.";
|
|
789
809
|
}
|
|
790
810
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
791
811
|
return "";
|
|
792
812
|
}
|
|
793
|
-
if (error instanceof Error)
|
|
794
|
-
|
|
813
|
+
if (error instanceof Error) {
|
|
814
|
+
if (isPreviewAuthorizationMessage(error.message)) {
|
|
815
|
+
return PREVIEW_AUTHORIZATION_ERROR_MESSAGE;
|
|
816
|
+
}
|
|
817
|
+
return isTransientRuntimeMessage(error.message) ? TRANSIENT_AGENT_ERROR_MESSAGE : error.message;
|
|
818
|
+
}
|
|
819
|
+
return TRANSIENT_AGENT_ERROR_MESSAGE;
|
|
795
820
|
}
|
|
796
821
|
|
|
797
822
|
// src/react/persisted-conversation.ts
|
|
@@ -900,6 +925,7 @@ function useAgentChat({
|
|
|
900
925
|
customerId,
|
|
901
926
|
getUnpublishedPreviewGrant,
|
|
902
927
|
indexId,
|
|
928
|
+
previewBuildId,
|
|
903
929
|
version,
|
|
904
930
|
runtimeOrigin,
|
|
905
931
|
visitorSessionId,
|
|
@@ -950,13 +976,14 @@ function useAgentChat({
|
|
|
950
976
|
customerId,
|
|
951
977
|
getUnpublishedPreviewGrant: resolveUnpublishedPreviewGrant,
|
|
952
978
|
indexId,
|
|
979
|
+
previewBuildId,
|
|
953
980
|
version,
|
|
954
981
|
runtimeOrigin,
|
|
955
982
|
visitorSessionId: visitorId,
|
|
956
983
|
storageKeyPrefix: resolvedStorageKeyPrefix
|
|
957
984
|
})
|
|
958
985
|
);
|
|
959
|
-
const identityKey = `${customerId ?? ""}|${indexId}|${version ?? "published"}|${runtimeOrigin ?? ""}|${resolvedStorageKeyPrefix}|${visitorId}|${greeting ?? ""}`;
|
|
986
|
+
const identityKey = `${customerId ?? ""}|${indexId}|${version ?? "published"}|${runtimeOrigin ?? ""}|${previewBuildId ?? ""}|${resolvedStorageKeyPrefix}|${visitorId}|${greeting ?? ""}`;
|
|
960
987
|
const identityRef = (0, import_react2.useRef)(identityKey);
|
|
961
988
|
(0, import_react2.useEffect)(() => {
|
|
962
989
|
if (identityRef.current === identityKey) {
|
|
@@ -969,6 +996,7 @@ function useAgentChat({
|
|
|
969
996
|
customerId,
|
|
970
997
|
getUnpublishedPreviewGrant: resolveUnpublishedPreviewGrant,
|
|
971
998
|
indexId,
|
|
999
|
+
previewBuildId,
|
|
972
1000
|
version,
|
|
973
1001
|
runtimeOrigin,
|
|
974
1002
|
visitorSessionId: visitorId,
|
|
@@ -985,6 +1013,7 @@ function useAgentChat({
|
|
|
985
1013
|
identityKey,
|
|
986
1014
|
indexId,
|
|
987
1015
|
initialState,
|
|
1016
|
+
previewBuildId,
|
|
988
1017
|
runtimeOrigin,
|
|
989
1018
|
resolvedStorageKeyPrefix,
|
|
990
1019
|
version,
|
|
@@ -1088,8 +1117,8 @@ function useAgentChat({
|
|
|
1088
1117
|
if (!message) return;
|
|
1089
1118
|
setState((prev) => ({
|
|
1090
1119
|
...prev,
|
|
1091
|
-
phase: "
|
|
1092
|
-
toolSteps: prev.toolSteps.map(
|
|
1120
|
+
phase: "error",
|
|
1121
|
+
toolSteps: prev.toolSteps.length === 1 && prev.toolSteps[0]?.kind === "planning" ? [] : prev.toolSteps.map(
|
|
1093
1122
|
(step) => step.state === "active" ? {
|
|
1094
1123
|
...step,
|
|
1095
1124
|
detail: "Couldn\u2019t complete this step",
|
|
@@ -1257,11 +1286,12 @@ var defaultAgentRailTheme = {
|
|
|
1257
1286
|
|
|
1258
1287
|
// src/react/components/AgentActivityBubble/AgentActivityBubble.tsx
|
|
1259
1288
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1260
|
-
function workSummary(steps) {
|
|
1289
|
+
function workSummary(steps, failed) {
|
|
1261
1290
|
const active = [...steps].reverse().find((step) => step.state === "active");
|
|
1262
1291
|
if (active?.kind === "specialist") return `Working with ${active.label}`;
|
|
1263
1292
|
if (active?.kind === "search") return "Searching this site";
|
|
1264
1293
|
if (active) return active.label;
|
|
1294
|
+
if (failed) return "Couldn\u2019t complete this request";
|
|
1265
1295
|
const hasError = steps.some((step) => step.state === "error");
|
|
1266
1296
|
const specialists = steps.filter(
|
|
1267
1297
|
(step) => step.kind === "specialist" && step.state === "completed"
|
|
@@ -1276,18 +1306,21 @@ function workSummary(steps) {
|
|
|
1276
1306
|
if (searched) return "Searched this site";
|
|
1277
1307
|
return "Prepared a response";
|
|
1278
1308
|
}
|
|
1279
|
-
function AgentActivityBubble({
|
|
1309
|
+
function AgentActivityBubble({
|
|
1310
|
+
failed = false,
|
|
1311
|
+
steps
|
|
1312
|
+
}) {
|
|
1280
1313
|
const active = steps.some((step) => step.state === "active");
|
|
1281
1314
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("article", { className: "agent-activity-bubble", children: [
|
|
1282
1315
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "agent-activity-bubble__status", "aria-live": "polite", children: [
|
|
1283
1316
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1284
1317
|
"span",
|
|
1285
1318
|
{
|
|
1286
|
-
className: `agent-activity-bubble__pulse${active ? " is-active" : ""}`,
|
|
1319
|
+
className: `agent-activity-bubble__pulse${active ? " is-active" : failed ? " is-error" : ""}`,
|
|
1287
1320
|
"aria-hidden": "true"
|
|
1288
1321
|
}
|
|
1289
1322
|
),
|
|
1290
|
-
workSummary(steps)
|
|
1323
|
+
workSummary(steps, failed)
|
|
1291
1324
|
] }),
|
|
1292
1325
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("details", { className: "agent-activity-bubble__details", open: active, children: [
|
|
1293
1326
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("summary", { children: "Work details" }),
|
|
@@ -1595,7 +1628,13 @@ function AgentRail({
|
|
|
1595
1628
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: transcriptRef, className: "agent-rail__transcript", children: [
|
|
1596
1629
|
state.messages.map((message) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MessageBubble, { message }, message.id)),
|
|
1597
1630
|
streamingMessage ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MessageBubble, { message: streamingMessage }) : null,
|
|
1598
|
-
showActivity ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1631
|
+
showActivity ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1632
|
+
AgentActivityBubble,
|
|
1633
|
+
{
|
|
1634
|
+
failed: state.phase === "error",
|
|
1635
|
+
steps: state.toolSteps
|
|
1636
|
+
}
|
|
1637
|
+
) : null,
|
|
1599
1638
|
!expanded && showIdleFollowUps ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "agent-rail__followups-slot", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1600
1639
|
FollowUpChips,
|
|
1601
1640
|
{
|
|
@@ -1807,6 +1846,7 @@ function AgentWidget({
|
|
|
1807
1846
|
indexId,
|
|
1808
1847
|
customerId,
|
|
1809
1848
|
getUnpublishedPreviewGrant,
|
|
1849
|
+
previewBuildId,
|
|
1810
1850
|
version,
|
|
1811
1851
|
runtimeOrigin,
|
|
1812
1852
|
placement: placementInput,
|
|
@@ -1834,6 +1874,7 @@ function AgentWidget({
|
|
|
1834
1874
|
customerId,
|
|
1835
1875
|
getUnpublishedPreviewGrant,
|
|
1836
1876
|
indexId,
|
|
1877
|
+
previewBuildId,
|
|
1837
1878
|
version,
|
|
1838
1879
|
runtimeOrigin,
|
|
1839
1880
|
greeting: branding?.greeting
|