@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/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 {
|
|
@@ -775,10 +779,15 @@ function createAgentClient(options) {
|
|
|
775
779
|
// src/runtime/errors.ts
|
|
776
780
|
var import_client3 = require("eve/client");
|
|
777
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.";
|
|
778
783
|
function isTransientRuntimeMessage(message) {
|
|
779
784
|
const normalized = message.trim().toLowerCase();
|
|
780
785
|
return normalized.includes("empty response from runtime") || normalized.includes("failed to fetch") || normalized.includes("networkerror") || normalized.includes("load failed");
|
|
781
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
|
+
}
|
|
782
791
|
function formatAgentError(error) {
|
|
783
792
|
if (error instanceof import_client3.ClientError) {
|
|
784
793
|
if (error.status === 401 && error.code === "index_required") {
|
|
@@ -790,6 +799,9 @@ function formatAgentError(error) {
|
|
|
790
799
|
if (error.status === 409 && error.code === "session_not_active") {
|
|
791
800
|
return "Session expired \u2014 send a new message to start again.";
|
|
792
801
|
}
|
|
802
|
+
if (error.message && isPreviewAuthorizationMessage(error.message)) {
|
|
803
|
+
return PREVIEW_AUTHORIZATION_ERROR_MESSAGE;
|
|
804
|
+
}
|
|
793
805
|
if (error.status >= 500 || error.message && isTransientRuntimeMessage(error.message)) {
|
|
794
806
|
return TRANSIENT_AGENT_ERROR_MESSAGE;
|
|
795
807
|
}
|
|
@@ -799,6 +811,9 @@ function formatAgentError(error) {
|
|
|
799
811
|
return "";
|
|
800
812
|
}
|
|
801
813
|
if (error instanceof Error) {
|
|
814
|
+
if (isPreviewAuthorizationMessage(error.message)) {
|
|
815
|
+
return PREVIEW_AUTHORIZATION_ERROR_MESSAGE;
|
|
816
|
+
}
|
|
802
817
|
return isTransientRuntimeMessage(error.message) ? TRANSIENT_AGENT_ERROR_MESSAGE : error.message;
|
|
803
818
|
}
|
|
804
819
|
return TRANSIENT_AGENT_ERROR_MESSAGE;
|
|
@@ -910,6 +925,7 @@ function useAgentChat({
|
|
|
910
925
|
customerId,
|
|
911
926
|
getUnpublishedPreviewGrant,
|
|
912
927
|
indexId,
|
|
928
|
+
previewBuildId,
|
|
913
929
|
version,
|
|
914
930
|
runtimeOrigin,
|
|
915
931
|
visitorSessionId,
|
|
@@ -960,13 +976,14 @@ function useAgentChat({
|
|
|
960
976
|
customerId,
|
|
961
977
|
getUnpublishedPreviewGrant: resolveUnpublishedPreviewGrant,
|
|
962
978
|
indexId,
|
|
979
|
+
previewBuildId,
|
|
963
980
|
version,
|
|
964
981
|
runtimeOrigin,
|
|
965
982
|
visitorSessionId: visitorId,
|
|
966
983
|
storageKeyPrefix: resolvedStorageKeyPrefix
|
|
967
984
|
})
|
|
968
985
|
);
|
|
969
|
-
const identityKey = `${customerId ?? ""}|${indexId}|${version ?? "published"}|${runtimeOrigin ?? ""}|${resolvedStorageKeyPrefix}|${visitorId}|${greeting ?? ""}`;
|
|
986
|
+
const identityKey = `${customerId ?? ""}|${indexId}|${version ?? "published"}|${runtimeOrigin ?? ""}|${previewBuildId ?? ""}|${resolvedStorageKeyPrefix}|${visitorId}|${greeting ?? ""}`;
|
|
970
987
|
const identityRef = (0, import_react2.useRef)(identityKey);
|
|
971
988
|
(0, import_react2.useEffect)(() => {
|
|
972
989
|
if (identityRef.current === identityKey) {
|
|
@@ -979,6 +996,7 @@ function useAgentChat({
|
|
|
979
996
|
customerId,
|
|
980
997
|
getUnpublishedPreviewGrant: resolveUnpublishedPreviewGrant,
|
|
981
998
|
indexId,
|
|
999
|
+
previewBuildId,
|
|
982
1000
|
version,
|
|
983
1001
|
runtimeOrigin,
|
|
984
1002
|
visitorSessionId: visitorId,
|
|
@@ -995,6 +1013,7 @@ function useAgentChat({
|
|
|
995
1013
|
identityKey,
|
|
996
1014
|
indexId,
|
|
997
1015
|
initialState,
|
|
1016
|
+
previewBuildId,
|
|
998
1017
|
runtimeOrigin,
|
|
999
1018
|
resolvedStorageKeyPrefix,
|
|
1000
1019
|
version,
|
|
@@ -1098,8 +1117,8 @@ function useAgentChat({
|
|
|
1098
1117
|
if (!message) return;
|
|
1099
1118
|
setState((prev) => ({
|
|
1100
1119
|
...prev,
|
|
1101
|
-
phase: "
|
|
1102
|
-
toolSteps: prev.toolSteps.map(
|
|
1120
|
+
phase: "error",
|
|
1121
|
+
toolSteps: prev.toolSteps.length === 1 && prev.toolSteps[0]?.kind === "planning" ? [] : prev.toolSteps.map(
|
|
1103
1122
|
(step) => step.state === "active" ? {
|
|
1104
1123
|
...step,
|
|
1105
1124
|
detail: "Couldn\u2019t complete this step",
|
|
@@ -1267,11 +1286,12 @@ var defaultAgentRailTheme = {
|
|
|
1267
1286
|
|
|
1268
1287
|
// src/react/components/AgentActivityBubble/AgentActivityBubble.tsx
|
|
1269
1288
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1270
|
-
function workSummary(steps) {
|
|
1289
|
+
function workSummary(steps, failed) {
|
|
1271
1290
|
const active = [...steps].reverse().find((step) => step.state === "active");
|
|
1272
1291
|
if (active?.kind === "specialist") return `Working with ${active.label}`;
|
|
1273
1292
|
if (active?.kind === "search") return "Searching this site";
|
|
1274
1293
|
if (active) return active.label;
|
|
1294
|
+
if (failed) return "Couldn\u2019t complete this request";
|
|
1275
1295
|
const hasError = steps.some((step) => step.state === "error");
|
|
1276
1296
|
const specialists = steps.filter(
|
|
1277
1297
|
(step) => step.kind === "specialist" && step.state === "completed"
|
|
@@ -1286,18 +1306,21 @@ function workSummary(steps) {
|
|
|
1286
1306
|
if (searched) return "Searched this site";
|
|
1287
1307
|
return "Prepared a response";
|
|
1288
1308
|
}
|
|
1289
|
-
function AgentActivityBubble({
|
|
1309
|
+
function AgentActivityBubble({
|
|
1310
|
+
failed = false,
|
|
1311
|
+
steps
|
|
1312
|
+
}) {
|
|
1290
1313
|
const active = steps.some((step) => step.state === "active");
|
|
1291
1314
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("article", { className: "agent-activity-bubble", children: [
|
|
1292
1315
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "agent-activity-bubble__status", "aria-live": "polite", children: [
|
|
1293
1316
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1294
1317
|
"span",
|
|
1295
1318
|
{
|
|
1296
|
-
className: `agent-activity-bubble__pulse${active ? " is-active" : ""}`,
|
|
1319
|
+
className: `agent-activity-bubble__pulse${active ? " is-active" : failed ? " is-error" : ""}`,
|
|
1297
1320
|
"aria-hidden": "true"
|
|
1298
1321
|
}
|
|
1299
1322
|
),
|
|
1300
|
-
workSummary(steps)
|
|
1323
|
+
workSummary(steps, failed)
|
|
1301
1324
|
] }),
|
|
1302
1325
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("details", { className: "agent-activity-bubble__details", open: active, children: [
|
|
1303
1326
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("summary", { children: "Work details" }),
|
|
@@ -1605,7 +1628,13 @@ function AgentRail({
|
|
|
1605
1628
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: transcriptRef, className: "agent-rail__transcript", children: [
|
|
1606
1629
|
state.messages.map((message) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MessageBubble, { message }, message.id)),
|
|
1607
1630
|
streamingMessage ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(MessageBubble, { message: streamingMessage }) : null,
|
|
1608
|
-
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,
|
|
1609
1638
|
!expanded && showIdleFollowUps ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "agent-rail__followups-slot", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1610
1639
|
FollowUpChips,
|
|
1611
1640
|
{
|
|
@@ -1817,6 +1846,7 @@ function AgentWidget({
|
|
|
1817
1846
|
indexId,
|
|
1818
1847
|
customerId,
|
|
1819
1848
|
getUnpublishedPreviewGrant,
|
|
1849
|
+
previewBuildId,
|
|
1820
1850
|
version,
|
|
1821
1851
|
runtimeOrigin,
|
|
1822
1852
|
placement: placementInput,
|
|
@@ -1844,6 +1874,7 @@ function AgentWidget({
|
|
|
1844
1874
|
customerId,
|
|
1845
1875
|
getUnpublishedPreviewGrant,
|
|
1846
1876
|
indexId,
|
|
1877
|
+
previewBuildId,
|
|
1847
1878
|
version,
|
|
1848
1879
|
runtimeOrigin,
|
|
1849
1880
|
greeting: branding?.greeting
|