site-operator 0.2.9 → 0.3.1
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/index.d.ts
CHANGED
package/dist/site-operator.es.js
CHANGED
|
@@ -925,6 +925,8 @@ const styles$4 = i$1`
|
|
|
925
925
|
color: var(--agent-text-foreground, #09090b);
|
|
926
926
|
line-height: 1.5;
|
|
927
927
|
white-space: pre-wrap;
|
|
928
|
+
overflow-wrap: anywhere;
|
|
929
|
+
word-break: break-word;
|
|
928
930
|
}
|
|
929
931
|
|
|
930
932
|
:host([role="user"]) .bubble {
|
|
@@ -996,9 +998,36 @@ const styles$4 = i$1`
|
|
|
996
998
|
transform: scale(1);
|
|
997
999
|
}
|
|
998
1000
|
}
|
|
999
|
-
|
|
1001
|
+
.debug-id {
|
|
1002
|
+
font-size: 0.65rem;
|
|
1003
|
+
color: var(--agent-text-zinc-400, #a1a1aa);
|
|
1004
|
+
margin-top: 0.25rem;
|
|
1005
|
+
font-family: monospace;
|
|
1006
|
+
opacity: 0.6;
|
|
1007
|
+
user-select: all;
|
|
1008
|
+
}
|
|
1009
|
+
`, a2uiService = new class extends EventTarget {
|
|
1000
1010
|
constructor() {
|
|
1001
|
-
this.processor = v0_8.Data.createSignalA2uiMessageProcessor();
|
|
1011
|
+
super(), this.processor = v0_8.Data.createSignalA2uiMessageProcessor(), this.surfaceMessageRegistry = /* @__PURE__ */ new Map(), this.processedMessageIds = /* @__PURE__ */ new Set();
|
|
1012
|
+
}
|
|
1013
|
+
clearRegistry() {
|
|
1014
|
+
this.surfaceMessageRegistry.clear(), this.processedMessageIds.clear();
|
|
1015
|
+
}
|
|
1016
|
+
resolveValue(o, O) {
|
|
1017
|
+
if (O) {
|
|
1018
|
+
if (O.literalString !== void 0) return O.literalString;
|
|
1019
|
+
if (O.literalNumber !== void 0) return O.literalNumber;
|
|
1020
|
+
if (O.literalBoolean !== void 0) return O.literalBoolean;
|
|
1021
|
+
if (O.literalArray !== void 0) return O.literalArray;
|
|
1022
|
+
if (O.path) {
|
|
1023
|
+
let M = this.processor.getSurfaces().get(o);
|
|
1024
|
+
if (M) {
|
|
1025
|
+
let o = O.path.startsWith("/") ? O.path.substring(1) : O.path, F = M.dataModel.get(o);
|
|
1026
|
+
if (F !== void 0) return F;
|
|
1027
|
+
}
|
|
1028
|
+
console.warn(`A2UIService: Could not resolve path ${O.path} for surface ${o}`);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1002
1031
|
}
|
|
1003
1032
|
mapMessage(o) {
|
|
1004
1033
|
if (o.role !== "assistant" || !o.toolCalls) throw Error("Unsupported message type for A2UI processing");
|
|
@@ -1074,11 +1103,11 @@ const styles$4 = i$1`
|
|
|
1074
1103
|
return typeof o.path == "string" && (M.path = o.path), M;
|
|
1075
1104
|
}
|
|
1076
1105
|
normalizeDataModelUpdate(o) {
|
|
1077
|
-
let O = {
|
|
1078
|
-
surfaceId:
|
|
1106
|
+
let O = o.surfaceId || o.surface_id, M = {
|
|
1107
|
+
surfaceId: O,
|
|
1079
1108
|
contents: this.normalizeValueMapArray(o.contents)
|
|
1080
1109
|
};
|
|
1081
|
-
return typeof o.path == "string" && (
|
|
1110
|
+
return typeof o.path == "string" && (M.path = o.path), console.log(`A2UIService: Normalized DataModelUpdate for ${O}`, M), M;
|
|
1082
1111
|
}
|
|
1083
1112
|
mapDeleteSurface(o) {
|
|
1084
1113
|
let O = this.getSurfaceId(o);
|
|
@@ -1093,18 +1122,23 @@ const styles$4 = i$1`
|
|
|
1093
1122
|
return typeof O == "string" && O.trim() ? O : typeof O == "number" ? String(O) : null;
|
|
1094
1123
|
}
|
|
1095
1124
|
normalizeValueMapArray(o) {
|
|
1096
|
-
return Array.isArray(o) ? o.filter((o) => o && typeof o == "object" && "key" in o).map((o) => this.normalizeValueMapEntry(o)) : [];
|
|
1125
|
+
return Array.isArray(o) ? o.filter((o) => o && typeof o == "object" && ("key" in o || "path" in o)).map((o) => this.normalizeValueMapEntry(o)) : [];
|
|
1097
1126
|
}
|
|
1098
1127
|
normalizeValueMapEntry(o) {
|
|
1099
1128
|
let O = { ...o };
|
|
1100
|
-
"value_string" in o && (O.valueString = o.value_string), "valueString" in o && (O.valueString = o.valueString), "value_number" in o && (O.valueNumber = o.value_number), "valueNumber" in o && (O.valueNumber = o.valueNumber), "value_boolean" in o && (O.valueBoolean = o.value_boolean), "valueBoolean" in o && (O.valueBoolean = o.valueBoolean)
|
|
1129
|
+
if ("value_string" in o && (O.valueString = o.value_string), "valueString" in o && (O.valueString = o.valueString), "value_number" in o && (O.valueNumber = o.value_number), "valueNumber" in o && (O.valueNumber = o.valueNumber), "value_boolean" in o && (O.valueBoolean = o.value_boolean), "valueBoolean" in o && (O.valueBoolean = o.valueBoolean), !("key" in O) && "path" in o && (O.key = o.path), !("valueString" in O) && !("valueNumber" in O) && !("valueBoolean" in O) && "value" in o) {
|
|
1130
|
+
let M = o.value;
|
|
1131
|
+
typeof M == "string" ? O.valueString = M : typeof M == "number" ? O.valueNumber = M : typeof M == "boolean" && (O.valueBoolean = M);
|
|
1132
|
+
}
|
|
1101
1133
|
let M = o.valueMap ?? o.value_map;
|
|
1102
|
-
|
|
1134
|
+
M !== void 0 && (O.valueMap = this.normalizeValueMapArray(M)), delete O.value_string, delete O.value_number, delete O.value_boolean, delete O.value_map, typeof O.key != "string" && (O.key = String(O.key ?? ""));
|
|
1135
|
+
let F = O.key;
|
|
1136
|
+
return F.startsWith("/") && (O.key = F.substring(1)), O;
|
|
1103
1137
|
}
|
|
1104
1138
|
isServerToClientMessage(o) {
|
|
1105
1139
|
if (!o || typeof o != "object") return !1;
|
|
1106
|
-
let O = o;
|
|
1107
|
-
return "beginRendering" in O || "begin_rendering" in O || "surfaceUpdate" in O || "surface_update" in O || "dataModelUpdate" in O || "data_model_update" in O || "deleteSurface" in O || "delete_surface" in O;
|
|
1140
|
+
let O = o, M = O.content, F = typeof M == "object" && !!M && ("beginRendering" in M || "surfaceUpdate" in M);
|
|
1141
|
+
return "beginRendering" in O || "begin_rendering" in O || "surfaceUpdate" in O || "surface_update" in O || "dataModelUpdate" in O || "data_model_update" in O || "deleteSurface" in O || "delete_surface" in O || F;
|
|
1108
1142
|
}
|
|
1109
1143
|
normalizeServerMessage(o) {
|
|
1110
1144
|
let O = o;
|
|
@@ -1140,10 +1174,25 @@ const styles$4 = i$1`
|
|
|
1140
1174
|
processMessages(o) {
|
|
1141
1175
|
let O = [];
|
|
1142
1176
|
for (let M of o) {
|
|
1177
|
+
if (this.processedMessageIds.has(M.id) && !M.isThinking) continue;
|
|
1143
1178
|
if (this.isServerToClientMessage(M)) {
|
|
1144
1179
|
O.push(this.normalizeServerMessage(M));
|
|
1145
1180
|
continue;
|
|
1146
1181
|
}
|
|
1182
|
+
if (M.role === "tool" && typeof M.content == "string") {
|
|
1183
|
+
try {
|
|
1184
|
+
let o = JSON.parse(M.content);
|
|
1185
|
+
if (o.role === "activity" && o.activity_type === "a2ui" && o.content) {
|
|
1186
|
+
let M = o.content;
|
|
1187
|
+
if (this.isServerToClientMessage(M)) O.push(this.normalizeServerMessage(M));
|
|
1188
|
+
else {
|
|
1189
|
+
let o = Array.isArray(M) ? M : [M];
|
|
1190
|
+
for (let M of o) this.isServerToClientMessage(M) && O.push(this.normalizeServerMessage(M));
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
} catch {}
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1147
1196
|
let o = M;
|
|
1148
1197
|
if (o.role === "activity" && o.activityType === "a2ui" && o.content) {
|
|
1149
1198
|
if (this.isServerToClientMessage(o.content)) O.push(this.normalizeServerMessage(o.content));
|
|
@@ -1155,7 +1204,21 @@ const styles$4 = i$1`
|
|
|
1155
1204
|
}
|
|
1156
1205
|
M.role === "assistant" && M.toolCalls && O.push(...this.mapMessage(M));
|
|
1157
1206
|
}
|
|
1158
|
-
if (O.length !== 0
|
|
1207
|
+
if (O.length !== 0 && O.length > 0) {
|
|
1208
|
+
console.log("A2UIService: Processing mapped messages:", JSON.stringify(O, null, 2)), this.processor.processMessages(O);
|
|
1209
|
+
for (let O of o) this.processedMessageIds.add(O.id);
|
|
1210
|
+
this.dispatchEvent(new CustomEvent("processor-update"));
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
consolidateStream(o, O) {
|
|
1214
|
+
let M = this.getA2UIPayloads(o);
|
|
1215
|
+
if (M.length === 0) return [...O, o];
|
|
1216
|
+
let F = !1, U = !1;
|
|
1217
|
+
for (let O of M) {
|
|
1218
|
+
let M = (O.beginRendering || O.surfaceUpdate || O.dataModelUpdate || O.deleteSurface)?.surfaceId;
|
|
1219
|
+
M && (O.beginRendering || O.surfaceUpdate || O.dataModelUpdate ? this.surfaceMessageRegistry.has(M) ? F = !0 : (this.surfaceMessageRegistry.set(M, o), U = !0) : O.deleteSurface && this.surfaceMessageRegistry.has(M) && (F = !0));
|
|
1220
|
+
}
|
|
1221
|
+
return this.processor.processMessages(M), this.processedMessageIds.add(o.id), this.dispatchEvent(new CustomEvent("processor-update")), F && !U ? (console.log(`A2UIService: Consolidating update for surface(s). Discarding visual message ${o.id}`), O) : [...O, o];
|
|
1159
1222
|
}
|
|
1160
1223
|
processMessage(o) {
|
|
1161
1224
|
this.processMessages([o]);
|
|
@@ -1177,8 +1240,8 @@ const styles$4 = i$1`
|
|
|
1177
1240
|
}
|
|
1178
1241
|
}
|
|
1179
1242
|
return o;
|
|
1180
|
-
}).flat(), G = [...U, ...W];
|
|
1181
|
-
console.log("A2UIService: Processing messages (fixed)", G), this.processor.processMessages(G);
|
|
1243
|
+
}).flat(), G = [...U, ...W].map((o) => this.normalizeServerMessage(o));
|
|
1244
|
+
console.log("A2UIService: Processing messages (fixed & normalized)", JSON.stringify(G, null, 2)), this.processor.processMessages(G);
|
|
1182
1245
|
let K = Array.from(this.processor.getSurfaces().entries());
|
|
1183
1246
|
console.log("A2UIService: Estado del procesador tras procesado:", K.map(([o, O]) => ({
|
|
1184
1247
|
id: o,
|
|
@@ -1196,12 +1259,50 @@ const styles$4 = i$1`
|
|
|
1196
1259
|
M && F.add(M);
|
|
1197
1260
|
}), Array.from(F);
|
|
1198
1261
|
}
|
|
1262
|
+
isBeginRenderingOnly(o) {
|
|
1263
|
+
let O = this.getA2UIPayloads(o);
|
|
1264
|
+
return O.length === 0 ? !1 : O.every((o) => {
|
|
1265
|
+
let O = !!o.beginRendering, M = !!o.surfaceUpdate || !!o.dataModelUpdate || !!o.deleteSurface;
|
|
1266
|
+
return O && !M;
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
isA2UIMessage(o) {
|
|
1270
|
+
return !o || o.role !== "assistant" && o.role !== "activity" ? !1 : o.role === "activity" && o.activityType === "a2ui" ? !0 : o.role === "assistant" && o.toolCalls ? o.toolCalls.some((o) => o.function?.name.startsWith("a2ui_")) : !1;
|
|
1271
|
+
}
|
|
1272
|
+
getA2UIPayloads(o) {
|
|
1273
|
+
let O = [];
|
|
1274
|
+
if (!o) return O;
|
|
1275
|
+
if (o.role === "assistant" && o.toolCalls) O.push(...this.mapMessage(o));
|
|
1276
|
+
else if (o.role === "activity" && o.activityType === "a2ui" && o.content) {
|
|
1277
|
+
let M = o.content;
|
|
1278
|
+
(Array.isArray(M) ? M : [M]).forEach((o) => {
|
|
1279
|
+
this.isServerToClientMessage(o) && O.push(this.normalizeServerMessage(o));
|
|
1280
|
+
});
|
|
1281
|
+
} else if (o.role === "tool" && typeof o.content == "string") try {
|
|
1282
|
+
let M = JSON.parse(o.content);
|
|
1283
|
+
if ((M.role === "activity" || M.activity_type === "a2ui") && M.content) {
|
|
1284
|
+
let o = M.content;
|
|
1285
|
+
(Array.isArray(o) ? o : [o]).forEach((o) => {
|
|
1286
|
+
this.isServerToClientMessage(o) && O.push(this.normalizeServerMessage(o));
|
|
1287
|
+
});
|
|
1288
|
+
} else this.isServerToClientMessage(M) && O.push(this.normalizeServerMessage(M));
|
|
1289
|
+
} catch {}
|
|
1290
|
+
return O;
|
|
1291
|
+
}
|
|
1199
1292
|
}();
|
|
1200
1293
|
var ChatMessage = class extends i {
|
|
1201
1294
|
constructor(...o) {
|
|
1202
|
-
super(...o), this.isLast = !1, this.isStreaming = !1, this.agentAvatar = ""
|
|
1295
|
+
super(...o), this.isLast = !1, this.isStreaming = !1, this.agentAvatar = "", this._processorUpdated = !1, this._handleProcessorUpdate = () => {
|
|
1296
|
+
a2uiService.isA2UIMessage(this.message) && this.requestUpdate();
|
|
1297
|
+
};
|
|
1203
1298
|
}
|
|
1204
1299
|
static #e = this.styles = styles$5;
|
|
1300
|
+
connectedCallback() {
|
|
1301
|
+
super.connectedCallback(), a2uiService.addEventListener("processor-update", this._handleProcessorUpdate);
|
|
1302
|
+
}
|
|
1303
|
+
disconnectedCallback() {
|
|
1304
|
+
a2uiService.removeEventListener("processor-update", this._handleProcessorUpdate), super.disconnectedCallback();
|
|
1305
|
+
}
|
|
1205
1306
|
updated(o) {
|
|
1206
1307
|
o.has("message") && (this.setAttribute("role", this.message.role), this.requestUpdate());
|
|
1207
1308
|
}
|
|
@@ -1217,21 +1318,22 @@ var ChatMessage = class extends i {
|
|
|
1217
1318
|
}));
|
|
1218
1319
|
}
|
|
1219
1320
|
render() {
|
|
1220
|
-
let o = this.message.role === "user"
|
|
1221
|
-
if (
|
|
1222
|
-
a2uiService.
|
|
1223
|
-
|
|
1224
|
-
if (o.length > 0) return b`
|
|
1321
|
+
let o = this.message.role === "user";
|
|
1322
|
+
if (a2uiService.isA2UIMessage(this.message)) {
|
|
1323
|
+
let o = a2uiService.getA2UIPayloads(this.message), O = new Set(o.map((o) => (o.beginRendering || o.surfaceUpdate || o.dataModelUpdate || o.deleteSurface)?.surfaceId).filter(Boolean)), M = a2uiService.processor, F = Array.from(M.getSurfaces().entries()).filter(([o]) => O.has(o));
|
|
1324
|
+
if (F.length > 0) return b`
|
|
1225
1325
|
<div class="message-container activity">
|
|
1326
|
+
${this.agentAvatar ? b`<img src="${this.agentAvatar}" class="avatar-img" alt="AI">` : b`<div class="avatar">C</div>`}
|
|
1226
1327
|
<div class="content-wrapper">
|
|
1227
|
-
${
|
|
1328
|
+
${F.map(([o, O]) => b`
|
|
1228
1329
|
<a2ui-theme-provider
|
|
1229
1330
|
.surfaceId="${o}"
|
|
1230
|
-
.processor="${
|
|
1231
|
-
.surface="${
|
|
1331
|
+
.processor="${M}"
|
|
1332
|
+
.surface="${O}"
|
|
1232
1333
|
.enableCustomElements="${!0}"
|
|
1233
1334
|
></a2ui-theme-provider>
|
|
1234
1335
|
`)}
|
|
1336
|
+
<div class="debug-id">${this.message.id}</div>
|
|
1235
1337
|
</div>
|
|
1236
1338
|
</div>
|
|
1237
1339
|
`;
|
|
@@ -1250,6 +1352,7 @@ var ChatMessage = class extends i {
|
|
|
1250
1352
|
<div class="typing-dot"></div>
|
|
1251
1353
|
</div>
|
|
1252
1354
|
` : this.message.content}</div>
|
|
1355
|
+
<div class="debug-id">${this.message.id}</div>
|
|
1253
1356
|
|
|
1254
1357
|
${o ? "" : b`
|
|
1255
1358
|
<div class="actions">
|
|
@@ -1266,14 +1369,14 @@ var ChatMessage = class extends i {
|
|
|
1266
1369
|
`;
|
|
1267
1370
|
}
|
|
1268
1371
|
};
|
|
1269
|
-
__decorate([n({ type: Object })], ChatMessage.prototype, "message", void 0), __decorate([n({ type: Boolean })], ChatMessage.prototype, "isLast", void 0), __decorate([n({ type: Boolean })], ChatMessage.prototype, "isStreaming", void 0), __decorate([n({ type: String })], ChatMessage.prototype, "agentAvatar", void 0), ChatMessage = __decorate([t("agent-chat-message")], ChatMessage);
|
|
1372
|
+
__decorate([n({ type: Object })], ChatMessage.prototype, "message", void 0), __decorate([n({ type: Boolean })], ChatMessage.prototype, "isLast", void 0), __decorate([n({ type: Boolean })], ChatMessage.prototype, "isStreaming", void 0), __decorate([n({ type: String })], ChatMessage.prototype, "agentAvatar", void 0), __decorate([n({ type: Boolean })], ChatMessage.prototype, "_processorUpdated", void 0), ChatMessage = __decorate([t("agent-chat-message")], ChatMessage);
|
|
1270
1373
|
var ChatThread = class extends i {
|
|
1271
1374
|
constructor(...o) {
|
|
1272
1375
|
super(...o), this.messages = [], this.isRunning = !1, this.agentAvatar = "", this.emptyText = "";
|
|
1273
1376
|
}
|
|
1274
1377
|
static #e = this.styles = styles$4;
|
|
1275
1378
|
updated(o) {
|
|
1276
|
-
o.has("messages") && this.scrollToBottom();
|
|
1379
|
+
o.has("messages") && (a2uiService.processMessages(this.messages), this.scrollToBottom());
|
|
1277
1380
|
}
|
|
1278
1381
|
async scrollToBottom() {
|
|
1279
1382
|
await this.updateComplete, (this.shadowRoot?.querySelector("agent-chat-message:last-of-type"))?.scrollIntoView({
|
|
@@ -1289,7 +1392,7 @@ var ChatThread = class extends i {
|
|
|
1289
1392
|
</div>
|
|
1290
1393
|
` : b`
|
|
1291
1394
|
<div class="messages-list">
|
|
1292
|
-
${this.messages.filter((o) => o.role === "
|
|
1395
|
+
${this.messages.filter((o) => a2uiService.isA2UIMessage(o) || o.role === "user" || o.role === "assistant" ? !0 : !(o.role === "tool" || o.role === "activity")).map((o, O, M) => b`
|
|
1293
1396
|
<agent-chat-message
|
|
1294
1397
|
.message=${o}
|
|
1295
1398
|
.isLast=${O === M.length - 1}
|
|
@@ -3135,7 +3238,14 @@ var ChatSubscriber = class {
|
|
|
3135
3238
|
}
|
|
3136
3239
|
onMessagesSnapshotEvent(o) {
|
|
3137
3240
|
inspectorService.addEvent("onMessagesSnapshotEvent", o.event);
|
|
3138
|
-
let O = o.event.messages.
|
|
3241
|
+
let O = o.event.messages.filter((o) => {
|
|
3242
|
+
if (o.role === "tool") return !1;
|
|
3243
|
+
if (o.role === "assistant" && o.toolCalls && o.toolCalls.length > 0) {
|
|
3244
|
+
let O = o.toolCalls.some((o) => o.function?.name?.startsWith("a2ui_")), M = typeof o.content == "string" && o.content.trim().length > 0;
|
|
3245
|
+
if (!O && !M) return !1;
|
|
3246
|
+
}
|
|
3247
|
+
return !0;
|
|
3248
|
+
}).map((o) => ({
|
|
3139
3249
|
...o,
|
|
3140
3250
|
createdAt: o.createdAt || Date.now()
|
|
3141
3251
|
}));
|
|
@@ -3197,7 +3307,7 @@ var ChatSubscriber = class {
|
|
|
3197
3307
|
inspectorService.addEvent("onStateDeltaEvent", o.event);
|
|
3198
3308
|
}
|
|
3199
3309
|
onActivitySnapshotEvent(o) {
|
|
3200
|
-
inspectorService.addEvent("onActivitySnapshotEvent", o.event), o.event.activityType
|
|
3310
|
+
inspectorService.addEvent("onActivitySnapshotEvent", o.event), o.event.activityType === "a2ui" ? a2uiService.processSnapshot(o.event) : [
|
|
3201
3311
|
"navigation",
|
|
3202
3312
|
"click",
|
|
3203
3313
|
"setValue",
|
|
@@ -3298,7 +3408,7 @@ const chatService = new class extends EventTarget {
|
|
|
3298
3408
|
name: o.appName,
|
|
3299
3409
|
locale: window.navigator.language || window.navigator.languages[0] || "en"
|
|
3300
3410
|
}
|
|
3301
|
-
}, O
|
|
3411
|
+
}, O ? await this.loadConversation(O) : a2uiService.clearRegistry(), inspectorService.setContext(this._appContext), inspectorService.setState(this._appState), inspectorService.setMessages(this.agent?.messages || []);
|
|
3302
3412
|
}
|
|
3303
3413
|
async loadConversation(o) {
|
|
3304
3414
|
try {
|
|
@@ -3399,9 +3509,9 @@ const chatService = new class extends EventTarget {
|
|
|
3399
3509
|
};
|
|
3400
3510
|
break;
|
|
3401
3511
|
}
|
|
3402
|
-
this.notify();
|
|
3512
|
+
this.agent.addMessage(U), this.notify();
|
|
3403
3513
|
try {
|
|
3404
|
-
this.agent?.threadId == threadIdPlaceHolder && await this._ensureConversation(), this.agent.
|
|
3514
|
+
this.agent?.threadId == threadIdPlaceHolder && await this._ensureConversation(), this.agent.state = { appState: this._appState }, await this.agent.runAgent({ tools: [] }, this.subscriber);
|
|
3405
3515
|
} catch (o) {
|
|
3406
3516
|
console.error("Failed to send message", o);
|
|
3407
3517
|
} finally {
|
|
@@ -3448,8 +3558,10 @@ const chatService = new class extends EventTarget {
|
|
|
3448
3558
|
}
|
|
3449
3559
|
setMessages(o) {
|
|
3450
3560
|
if (!this.agent) throw Error("Agent not initialized");
|
|
3451
|
-
|
|
3452
|
-
|
|
3561
|
+
a2uiService.clearRegistry();
|
|
3562
|
+
let O = [];
|
|
3563
|
+
for (let M of o) O = a2uiService.consolidateStream(M, O);
|
|
3564
|
+
O.sort((o, O) => (o.createdAt || 0) - (O.createdAt || 0)), this.agent.messages = O, this.notify();
|
|
3453
3565
|
}
|
|
3454
3566
|
addA2UIMessage(o) {
|
|
3455
3567
|
if (!this.agent) throw Error("Agent not initialized");
|
|
@@ -3465,11 +3577,11 @@ const chatService = new class extends EventTarget {
|
|
|
3465
3577
|
activityType: o.activityType,
|
|
3466
3578
|
content: o.content,
|
|
3467
3579
|
createdAt: Date.now()
|
|
3468
|
-
}, F = this.agent.messages
|
|
3469
|
-
this.agent.messages =
|
|
3580
|
+
}, F = a2uiService.consolidateStream(M, this.agent.messages);
|
|
3581
|
+
this.agent.messages = F, this.notify();
|
|
3470
3582
|
}
|
|
3471
3583
|
async startNewThread() {
|
|
3472
|
-
localStorage.removeItem(STORAGE_THREAD_ID_KEY), this.agent && (this.agent.threadId = threadIdPlaceHolder, this.agent.messages = [], this.agent.isRunning = !1), this._suggestedPrompts.length > 0 && (this._showPrompts = !0), this.notify();
|
|
3584
|
+
localStorage.removeItem(STORAGE_THREAD_ID_KEY), console.log("ChatService: startNewThread"), this.agent && (this.agent.threadId = threadIdPlaceHolder, this.agent.messages = [], this.agent.isRunning = !1), this._suggestedPrompts.length > 0 && (this._showPrompts = !0), a2uiService.clearRegistry(), this.notify();
|
|
3473
3585
|
}
|
|
3474
3586
|
async getConversations() {
|
|
3475
3587
|
return await this.refreshConversations(), this._conversations;
|
|
@@ -3522,7 +3634,7 @@ var ChatController = class {
|
|
|
3522
3634
|
return chatService.sendMessage(o, O);
|
|
3523
3635
|
}
|
|
3524
3636
|
startNewThread() {
|
|
3525
|
-
return chatService.startNewThread();
|
|
3637
|
+
return console.log("Starting new thread"), chatService.startNewThread();
|
|
3526
3638
|
}
|
|
3527
3639
|
loadConversation(o) {
|
|
3528
3640
|
return chatService.loadConversation(o);
|
|
@@ -3567,7 +3679,7 @@ var ChatController = class {
|
|
|
3567
3679
|
window.fetch = async function(O, M) {
|
|
3568
3680
|
try {
|
|
3569
3681
|
let F = new Headers(M?.headers || {});
|
|
3570
|
-
return F.has("Authorization") || F.append("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6InhmcDRfR0tObWNBMHl3UUNrZ1BXVkJjTHZmRDVfZXZKOWg3bUhGbExBVWMiLCJ0eXAiOiJKV1QifQ.
|
|
3682
|
+
return F.has("Authorization") || F.append("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6InhmcDRfR0tObWNBMHl3UUNrZ1BXVkJjTHZmRDVfZXZKOWg3bUhGbExBVWMiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiIwZWZhNWFhNy04OWRiLTQ5MTYtYmZlNC0wNTM3MjhlZWY2M2QiLCJpc3MiOiJodHRwczovL3NrY290ZXN0LmIyY2xvZ2luLmNvbS8wZGI2ZGJjMy02OTA4LTQ1MTctYTdmMi04MWVhNjg1YTI1ZTIvdjIuMC8iLCJleHAiOjE3NzAxNzYyNzUsIm5iZiI6MTc3MDE3NTM3NSwibmFtZSI6IlZpYW5hIFZlbGFzcXVleiwgSm9zZSBTdGV2ZW4iLCJpZHBfYWNjZXNzX3Rva2VuIjoiZXlKMGVYQWlPaUpLVjFRaUxDSnViMjVqWlNJNklrZzRWbmMwWkV4UlowRnBhbnB1V0ZWMldrWkxaRkF4YlVsQ1ZrVXlZMXBGYlVOaVoybExkRXM1TjJNaUxDSmhiR2NpT2lKU1V6STFOaUlzSW5nMWRDSTZJbEJqV0RrNFIxZzBNakJVTVZnMmMwSkVhM3BvVVcxeFozZE5WU0lzSW10cFpDSTZJbEJqV0RrNFIxZzBNakJVTVZnMmMwSkVhM3BvVVcxeFozZE5WU0o5LmV5SmhkV1FpT2lJd01EQ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@ var AgentChat = class extends i {
|
|
|
3593
3705
|
this.dispatchEvent(new CustomEvent("controller-ready", { detail: this._chatController }));
|
|
3594
3706
|
}
|
|
3595
3707
|
connectedCallback() {
|
|
3596
|
-
super.connectedCallback(), this.addEventListener("a2uiaction", this._handleA2UIAction);
|
|
3708
|
+
super.connectedCallback(), this._injectFonts(), this.addEventListener("a2uiaction", this._handleA2UIAction);
|
|
3709
|
+
}
|
|
3710
|
+
_injectFonts() {
|
|
3711
|
+
["https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200", "https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200"].forEach((o) => {
|
|
3712
|
+
if (!document.querySelector(`link[href="${o}"]`)) {
|
|
3713
|
+
let O = document.createElement("link");
|
|
3714
|
+
O.rel = "stylesheet", O.href = o, document.head.appendChild(O);
|
|
3715
|
+
}
|
|
3716
|
+
});
|
|
3597
3717
|
}
|
|
3598
3718
|
disconnectedCallback() {
|
|
3599
3719
|
this.removeEventListener("a2uiaction", this._handleA2UIAction), super.disconnectedCallback();
|
|
@@ -3691,29 +3811,30 @@ var AgentChat = class extends i {
|
|
|
3691
3811
|
this.setAppContext(o.detail);
|
|
3692
3812
|
}
|
|
3693
3813
|
_handleA2UIAction(o) {
|
|
3694
|
-
let { action: O } = o.detail;
|
|
3695
|
-
if (O)
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3814
|
+
let { action: O, surfaceId: M } = o.detail;
|
|
3815
|
+
if (!O) return;
|
|
3816
|
+
console.log("AgentChat: A2UI Action received:", O, "Surface:", M);
|
|
3817
|
+
let F = M || Array.from(a2uiService.processor.getSurfaces().keys())[0] || "root";
|
|
3818
|
+
if (O.name === "decision") {
|
|
3819
|
+
this._handleAuthDecision(O, F);
|
|
3820
|
+
return;
|
|
3701
3821
|
}
|
|
3822
|
+
this._handleGenericUrlAction(O, F);
|
|
3702
3823
|
}
|
|
3703
|
-
_handleAuthDecision(o) {
|
|
3704
|
-
let
|
|
3824
|
+
_handleAuthDecision(o, O) {
|
|
3825
|
+
let M = o.context || [], F = M.find((o) => o.key === "userDecision"), U = a2uiService.resolveValue(O, F?.value), W = M.find((o) => [
|
|
3705
3826
|
"url",
|
|
3706
3827
|
"href",
|
|
3707
3828
|
"link",
|
|
3708
3829
|
"uri"
|
|
3709
|
-
].includes(o.key?.toLowerCase()))?.value
|
|
3710
|
-
if (console.log(`AgentChat: Specialized decision handler: ${
|
|
3830
|
+
].includes(o.key?.toLowerCase())), G = a2uiService.resolveValue(O, W?.value);
|
|
3831
|
+
if (console.log(`AgentChat: Specialized decision handler: ${U}`, o), U === "deny") {
|
|
3711
3832
|
console.log("AgentChat: User denied the request."), this._chatController.sendMessage(`User selected "Deny" for action "${o.name}".`, "tool");
|
|
3712
3833
|
return;
|
|
3713
3834
|
}
|
|
3714
|
-
if (
|
|
3715
|
-
console.log(`AgentChat: User selected "Approve". Opening auth URL: ${
|
|
3716
|
-
let O = window.open(
|
|
3835
|
+
if (U === "approve") if (G) {
|
|
3836
|
+
console.log(`AgentChat: User selected "Approve". Opening auth URL: ${G}`);
|
|
3837
|
+
let O = window.open(G, "_blank");
|
|
3717
3838
|
if (O) {
|
|
3718
3839
|
let M = setInterval(() => {
|
|
3719
3840
|
O.closed && (clearInterval(M), console.log("AgentChat: Auth tab closed. Notifying approval."), this._chatController.sendMessage(`User approved the request "${o.name}" and completed authentication.`, "tool"));
|
|
@@ -3721,14 +3842,14 @@ var AgentChat = class extends i {
|
|
|
3721
3842
|
} else console.error("AgentChat: Failed to open auth tab.");
|
|
3722
3843
|
} else console.log("AgentChat: User approved (no URL provided)."), this._chatController.sendMessage(`User selected "Approve" for action "${o.name}".`, "tool");
|
|
3723
3844
|
}
|
|
3724
|
-
_handleGenericUrlAction(o) {
|
|
3725
|
-
let
|
|
3845
|
+
_handleGenericUrlAction(o, O) {
|
|
3846
|
+
let M = o.context?.find((o) => [
|
|
3726
3847
|
"url",
|
|
3727
3848
|
"href",
|
|
3728
3849
|
"link",
|
|
3729
3850
|
"uri"
|
|
3730
|
-
].includes(o.key?.toLowerCase())),
|
|
3731
|
-
|
|
3851
|
+
].includes(o.key?.toLowerCase())), F = a2uiService.resolveValue(O, M?.value);
|
|
3852
|
+
F ? (console.log(`AgentChat: Opening generic URL: ${F}`), window.open(F, "_blank")) : o.name === "openLink" ? console.warn("AgentChat: openLink action received but no URL could be resolved:", o) : console.warn("AgentChat: A2UI Action received without recognizable purpose:", o);
|
|
3732
3853
|
}
|
|
3733
3854
|
_handleStateUpdate(o) {
|
|
3734
3855
|
this.setAppState(o.detail);
|