@webless/agent 0.3.1 → 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-MMYSBSHG.js → chunk-APNF27K2.js} +44 -13
- package/dist/chunk-APNF27K2.js.map +1 -0
- package/dist/embed.cjs +57 -12
- 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 +19 -4
- 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 +19 -4
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +43 -12
- 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-MMYSBSHG.js.map +0 -1
package/dist/embed.cjs
CHANGED
|
@@ -178,11 +178,12 @@ function createAgentRuntimeCapability(options) {
|
|
|
178
178
|
let pendingBootstrap;
|
|
179
179
|
const bootstrap = async () => {
|
|
180
180
|
let previewGrant;
|
|
181
|
+
const previewBuildId = options.previewBuildId?.trim();
|
|
181
182
|
if (options.version === "unpublished") {
|
|
182
|
-
previewGrant = (await options.getUnpublishedPreviewGrant?.())?.trim();
|
|
183
|
-
if (!previewGrant) {
|
|
183
|
+
previewGrant = previewBuildId ? void 0 : (await options.getUnpublishedPreviewGrant?.())?.trim();
|
|
184
|
+
if (!previewGrant && !previewBuildId) {
|
|
184
185
|
throw new Error(
|
|
185
|
-
"
|
|
186
|
+
"Unpublished preview authorization is required to use the Agent Runtime preview."
|
|
186
187
|
);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
@@ -192,6 +193,7 @@ function createAgentRuntimeCapability(options) {
|
|
|
192
193
|
body: JSON.stringify({
|
|
193
194
|
clientSessionId: options.visitorSessionId,
|
|
194
195
|
indexId: options.indexId,
|
|
196
|
+
...previewBuildId ? { previewBuildId } : {},
|
|
195
197
|
...previewGrant ? { previewGrant } : {},
|
|
196
198
|
version: options.version
|
|
197
199
|
}),
|
|
@@ -511,7 +513,7 @@ function applyWorkEvent(event, handlers, workItems) {
|
|
|
511
513
|
);
|
|
512
514
|
}
|
|
513
515
|
var AgentSession = class {
|
|
514
|
-
constructor(indexId, version, runtimeOrigin, visitorSessionId, storeOptions, getUnpublishedPreviewGrant) {
|
|
516
|
+
constructor(indexId, version, runtimeOrigin, visitorSessionId, storeOptions, previewBuildId, getUnpublishedPreviewGrant) {
|
|
515
517
|
this.indexId = indexId;
|
|
516
518
|
this.version = version;
|
|
517
519
|
this.runtimeOrigin = runtimeOrigin;
|
|
@@ -520,6 +522,7 @@ var AgentSession = class {
|
|
|
520
522
|
this.capability = createAgentRuntimeCapability({
|
|
521
523
|
getUnpublishedPreviewGrant,
|
|
522
524
|
indexId,
|
|
525
|
+
previewBuildId,
|
|
523
526
|
runtimeOrigin,
|
|
524
527
|
version,
|
|
525
528
|
visitorSessionId
|
|
@@ -764,6 +767,7 @@ function createAgentClient(options) {
|
|
|
764
767
|
runtimeOrigin,
|
|
765
768
|
visitorSessionId,
|
|
766
769
|
storeOptions,
|
|
770
|
+
options.previewBuildId,
|
|
767
771
|
options.getUnpublishedPreviewGrant
|
|
768
772
|
);
|
|
769
773
|
return {
|
|
@@ -791,10 +795,15 @@ function createAgentClient(options) {
|
|
|
791
795
|
// src/runtime/errors.ts
|
|
792
796
|
var import_client3 = require("eve/client");
|
|
793
797
|
var TRANSIENT_AGENT_ERROR_MESSAGE = "I couldn\u2019t finish that answer. Please try again.";
|
|
798
|
+
var PREVIEW_AUTHORIZATION_ERROR_MESSAGE = "This preview could not be authorized. Open the latest preview from Webless.";
|
|
794
799
|
function isTransientRuntimeMessage(message) {
|
|
795
800
|
const normalized = message.trim().toLowerCase();
|
|
796
801
|
return normalized.includes("empty response from runtime") || normalized.includes("failed to fetch") || normalized.includes("networkerror") || normalized.includes("load failed");
|
|
797
802
|
}
|
|
803
|
+
function isPreviewAuthorizationMessage(message) {
|
|
804
|
+
const normalized = message.trim().toLowerCase();
|
|
805
|
+
return normalized.includes("unpublished preview authorization") || normalized.includes("unpublished preview grant") || normalized.includes("agent studio preview grant") || normalized.includes("preview authorization");
|
|
806
|
+
}
|
|
798
807
|
function formatAgentError(error) {
|
|
799
808
|
if (error instanceof import_client3.ClientError) {
|
|
800
809
|
if (error.status === 401 && error.code === "index_required") {
|
|
@@ -806,6 +815,9 @@ function formatAgentError(error) {
|
|
|
806
815
|
if (error.status === 409 && error.code === "session_not_active") {
|
|
807
816
|
return "Session expired \u2014 send a new message to start again.";
|
|
808
817
|
}
|
|
818
|
+
if (error.message && isPreviewAuthorizationMessage(error.message)) {
|
|
819
|
+
return PREVIEW_AUTHORIZATION_ERROR_MESSAGE;
|
|
820
|
+
}
|
|
809
821
|
if (error.status >= 500 || error.message && isTransientRuntimeMessage(error.message)) {
|
|
810
822
|
return TRANSIENT_AGENT_ERROR_MESSAGE;
|
|
811
823
|
}
|
|
@@ -815,6 +827,9 @@ function formatAgentError(error) {
|
|
|
815
827
|
return "";
|
|
816
828
|
}
|
|
817
829
|
if (error instanceof Error) {
|
|
830
|
+
if (isPreviewAuthorizationMessage(error.message)) {
|
|
831
|
+
return PREVIEW_AUTHORIZATION_ERROR_MESSAGE;
|
|
832
|
+
}
|
|
818
833
|
return isTransientRuntimeMessage(error.message) ? TRANSIENT_AGENT_ERROR_MESSAGE : error.message;
|
|
819
834
|
}
|
|
820
835
|
return TRANSIENT_AGENT_ERROR_MESSAGE;
|
|
@@ -926,6 +941,7 @@ function useAgentChat({
|
|
|
926
941
|
customerId,
|
|
927
942
|
getUnpublishedPreviewGrant,
|
|
928
943
|
indexId,
|
|
944
|
+
previewBuildId,
|
|
929
945
|
version,
|
|
930
946
|
runtimeOrigin,
|
|
931
947
|
visitorSessionId,
|
|
@@ -976,13 +992,14 @@ function useAgentChat({
|
|
|
976
992
|
customerId,
|
|
977
993
|
getUnpublishedPreviewGrant: resolveUnpublishedPreviewGrant,
|
|
978
994
|
indexId,
|
|
995
|
+
previewBuildId,
|
|
979
996
|
version,
|
|
980
997
|
runtimeOrigin,
|
|
981
998
|
visitorSessionId: visitorId,
|
|
982
999
|
storageKeyPrefix: resolvedStorageKeyPrefix
|
|
983
1000
|
})
|
|
984
1001
|
);
|
|
985
|
-
const identityKey = `${customerId ?? ""}|${indexId}|${version ?? "published"}|${runtimeOrigin ?? ""}|${resolvedStorageKeyPrefix}|${visitorId}|${greeting ?? ""}`;
|
|
1002
|
+
const identityKey = `${customerId ?? ""}|${indexId}|${version ?? "published"}|${runtimeOrigin ?? ""}|${previewBuildId ?? ""}|${resolvedStorageKeyPrefix}|${visitorId}|${greeting ?? ""}`;
|
|
986
1003
|
const identityRef = (0, import_react2.useRef)(identityKey);
|
|
987
1004
|
(0, import_react2.useEffect)(() => {
|
|
988
1005
|
if (identityRef.current === identityKey) {
|
|
@@ -995,6 +1012,7 @@ function useAgentChat({
|
|
|
995
1012
|
customerId,
|
|
996
1013
|
getUnpublishedPreviewGrant: resolveUnpublishedPreviewGrant,
|
|
997
1014
|
indexId,
|
|
1015
|
+
previewBuildId,
|
|
998
1016
|
version,
|
|
999
1017
|
runtimeOrigin,
|
|
1000
1018
|
visitorSessionId: visitorId,
|
|
@@ -1011,6 +1029,7 @@ function useAgentChat({
|
|
|
1011
1029
|
identityKey,
|
|
1012
1030
|
indexId,
|
|
1013
1031
|
initialState,
|
|
1032
|
+
previewBuildId,
|
|
1014
1033
|
runtimeOrigin,
|
|
1015
1034
|
resolvedStorageKeyPrefix,
|
|
1016
1035
|
version,
|
|
@@ -1114,8 +1133,8 @@ function useAgentChat({
|
|
|
1114
1133
|
if (!message) return;
|
|
1115
1134
|
setState((prev) => ({
|
|
1116
1135
|
...prev,
|
|
1117
|
-
phase: "
|
|
1118
|
-
toolSteps: prev.toolSteps.map(
|
|
1136
|
+
phase: "error",
|
|
1137
|
+
toolSteps: prev.toolSteps.length === 1 && prev.toolSteps[0]?.kind === "planning" ? [] : prev.toolSteps.map(
|
|
1119
1138
|
(step) => step.state === "active" ? {
|
|
1120
1139
|
...step,
|
|
1121
1140
|
detail: "Couldn\u2019t complete this step",
|
|
@@ -1274,11 +1293,12 @@ var defaultAgentRailTheme = {
|
|
|
1274
1293
|
|
|
1275
1294
|
// src/react/components/AgentActivityBubble/AgentActivityBubble.tsx
|
|
1276
1295
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1277
|
-
function workSummary(steps) {
|
|
1296
|
+
function workSummary(steps, failed) {
|
|
1278
1297
|
const active = [...steps].reverse().find((step) => step.state === "active");
|
|
1279
1298
|
if (active?.kind === "specialist") return `Working with ${active.label}`;
|
|
1280
1299
|
if (active?.kind === "search") return "Searching this site";
|
|
1281
1300
|
if (active) return active.label;
|
|
1301
|
+
if (failed) return "Couldn\u2019t complete this request";
|
|
1282
1302
|
const hasError = steps.some((step) => step.state === "error");
|
|
1283
1303
|
const specialists = steps.filter(
|
|
1284
1304
|
(step) => step.kind === "specialist" && step.state === "completed"
|
|
@@ -1293,18 +1313,21 @@ function workSummary(steps) {
|
|
|
1293
1313
|
if (searched) return "Searched this site";
|
|
1294
1314
|
return "Prepared a response";
|
|
1295
1315
|
}
|
|
1296
|
-
function AgentActivityBubble({
|
|
1316
|
+
function AgentActivityBubble({
|
|
1317
|
+
failed = false,
|
|
1318
|
+
steps
|
|
1319
|
+
}) {
|
|
1297
1320
|
const active = steps.some((step) => step.state === "active");
|
|
1298
1321
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("article", { className: "agent-activity-bubble", children: [
|
|
1299
1322
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "agent-activity-bubble__status", "aria-live": "polite", children: [
|
|
1300
1323
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1301
1324
|
"span",
|
|
1302
1325
|
{
|
|
1303
|
-
className: `agent-activity-bubble__pulse${active ? " is-active" : ""}`,
|
|
1326
|
+
className: `agent-activity-bubble__pulse${active ? " is-active" : failed ? " is-error" : ""}`,
|
|
1304
1327
|
"aria-hidden": "true"
|
|
1305
1328
|
}
|
|
1306
1329
|
),
|
|
1307
|
-
workSummary(steps)
|
|
1330
|
+
workSummary(steps, failed)
|
|
1308
1331
|
] }),
|
|
1309
1332
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("details", { className: "agent-activity-bubble__details", open: active, children: [
|
|
1310
1333
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("summary", { children: "Work details" }),
|
|
@@ -1612,7 +1635,13 @@ function AgentRail({
|
|
|
1612
1635
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: transcriptRef, className: "agent-rail__transcript", children: [
|
|
1613
1636
|
state.messages.map((message) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MessageBubble, { message }, message.id)),
|
|
1614
1637
|
streamingMessage ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MessageBubble, { message: streamingMessage }) : null,
|
|
1615
|
-
showActivity ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1638
|
+
showActivity ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1639
|
+
AgentActivityBubble,
|
|
1640
|
+
{
|
|
1641
|
+
failed: state.phase === "error",
|
|
1642
|
+
steps: state.toolSteps
|
|
1643
|
+
}
|
|
1644
|
+
) : null,
|
|
1616
1645
|
!expanded && showIdleFollowUps ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "agent-rail__followups-slot", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1617
1646
|
FollowUpChips,
|
|
1618
1647
|
{
|
|
@@ -1824,6 +1853,7 @@ function AgentWidget({
|
|
|
1824
1853
|
indexId,
|
|
1825
1854
|
customerId,
|
|
1826
1855
|
getUnpublishedPreviewGrant,
|
|
1856
|
+
previewBuildId,
|
|
1827
1857
|
version,
|
|
1828
1858
|
runtimeOrigin,
|
|
1829
1859
|
placement: placementInput,
|
|
@@ -1851,6 +1881,7 @@ function AgentWidget({
|
|
|
1851
1881
|
customerId,
|
|
1852
1882
|
getUnpublishedPreviewGrant,
|
|
1853
1883
|
indexId,
|
|
1884
|
+
previewBuildId,
|
|
1854
1885
|
version,
|
|
1855
1886
|
runtimeOrigin,
|
|
1856
1887
|
greeting: branding?.greeting
|
|
@@ -1956,6 +1987,19 @@ function AgentWidget({
|
|
|
1956
1987
|
] });
|
|
1957
1988
|
}
|
|
1958
1989
|
|
|
1990
|
+
// src/embed/preview-build.ts
|
|
1991
|
+
var PREVIEW_BUILD_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
1992
|
+
function readUnpublishedPreviewBuildId(href) {
|
|
1993
|
+
const source = href ?? (typeof window === "undefined" ? void 0 : window.location.href);
|
|
1994
|
+
if (!source) return void 0;
|
|
1995
|
+
try {
|
|
1996
|
+
const buildId = new URL(source).searchParams.get("v")?.trim();
|
|
1997
|
+
return buildId && PREVIEW_BUILD_ID_PATTERN.test(buildId) ? buildId : void 0;
|
|
1998
|
+
} catch {
|
|
1999
|
+
return void 0;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
|
|
1959
2003
|
// src/embed/AgentWidget.tsx
|
|
1960
2004
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1961
2005
|
function AgentWidget2({
|
|
@@ -1968,6 +2012,7 @@ function AgentWidget2({
|
|
|
1968
2012
|
customerId: manifest.customerId,
|
|
1969
2013
|
version: manifest.version,
|
|
1970
2014
|
runtimeOrigin: manifest.runtimeOrigin,
|
|
2015
|
+
previewBuildId: manifest.version === "unpublished" ? readUnpublishedPreviewBuildId() : void 0,
|
|
1971
2016
|
placement: manifest.placement,
|
|
1972
2017
|
pageShift: manifest.pageShift,
|
|
1973
2018
|
branding: manifest.branding,
|