@runtypelabs/persona 3.15.0 → 3.16.0
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.cjs +46 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.global.js +65 -65
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -46
- package/dist/index.js.map +1 -1
- package/dist/theme-editor.cjs +445 -222
- package/dist/theme-editor.d.cts +11 -0
- package/dist/theme-editor.d.ts +11 -0
- package/dist/theme-editor.js +445 -222
- package/dist/widget.css +11 -8
- package/package.json +1 -1
- package/src/client.test.ts +361 -0
- package/src/client.ts +352 -158
- package/src/components/header-builder.ts +18 -7
- package/src/components/header-layouts.ts +3 -1
- package/src/defaults.ts +6 -0
- package/src/styles/widget.css +11 -8
- package/src/types.ts +11 -0
- package/src/ui.ts +31 -4
- package/src/utils/sequence-buffer.test.ts +256 -0
- package/src/utils/sequence-buffer.ts +130 -0
package/dist/theme-editor.js
CHANGED
|
@@ -45,6 +45,12 @@ var DEFAULT_WIDGET_CONFIG = {
|
|
|
45
45
|
agentIconSize: "40px",
|
|
46
46
|
headerIconSize: "40px",
|
|
47
47
|
closeButtonSize: "32px",
|
|
48
|
+
// Zero out browser-default <button> padding so the icon gets the full
|
|
49
|
+
// 32x32 content box, matching clearChat.paddingX/Y below. Without this,
|
|
50
|
+
// UA stylesheets add ~1-2px vertical and ~6px horizontal padding that
|
|
51
|
+
// eats into the border-box width and shrinks the rendered icon.
|
|
52
|
+
closeButtonPaddingX: "0px",
|
|
53
|
+
closeButtonPaddingY: "0px",
|
|
48
54
|
callToActionIconName: "arrow-up-right",
|
|
49
55
|
callToActionIconText: "",
|
|
50
56
|
callToActionIconSize: "32px",
|
|
@@ -3453,6 +3459,94 @@ var createXmlParser = () => {
|
|
|
3453
3459
|
};
|
|
3454
3460
|
};
|
|
3455
3461
|
|
|
3462
|
+
// src/utils/sequence-buffer.ts
|
|
3463
|
+
var SequenceReorderBuffer = class {
|
|
3464
|
+
constructor(emitter, gapTimeoutMs = 50) {
|
|
3465
|
+
this.nextExpectedSeq = null;
|
|
3466
|
+
this.buffer = /* @__PURE__ */ new Map();
|
|
3467
|
+
this.flushTimer = null;
|
|
3468
|
+
this.emitter = emitter;
|
|
3469
|
+
this.gapTimeoutMs = gapTimeoutMs;
|
|
3470
|
+
}
|
|
3471
|
+
push(payloadType, payload) {
|
|
3472
|
+
var _a, _b, _c;
|
|
3473
|
+
const seq = (_c = (_a = payload == null ? void 0 : payload.seq) != null ? _a : payload == null ? void 0 : payload.sequenceIndex) != null ? _c : (_b = payload == null ? void 0 : payload.agentContext) == null ? void 0 : _b.seq;
|
|
3474
|
+
if (seq === void 0 || seq === null) {
|
|
3475
|
+
if (this.buffer.size > 0) {
|
|
3476
|
+
this.flushAll();
|
|
3477
|
+
}
|
|
3478
|
+
this.emitter(payloadType, payload);
|
|
3479
|
+
return;
|
|
3480
|
+
}
|
|
3481
|
+
if (this.nextExpectedSeq === null) {
|
|
3482
|
+
this.nextExpectedSeq = 1;
|
|
3483
|
+
}
|
|
3484
|
+
if (seq === this.nextExpectedSeq) {
|
|
3485
|
+
this.emitter(payloadType, payload);
|
|
3486
|
+
this.nextExpectedSeq = seq + 1;
|
|
3487
|
+
this.drainConsecutive();
|
|
3488
|
+
return;
|
|
3489
|
+
}
|
|
3490
|
+
if (seq < this.nextExpectedSeq) {
|
|
3491
|
+
this.emitter(payloadType, payload);
|
|
3492
|
+
return;
|
|
3493
|
+
}
|
|
3494
|
+
const existing = this.buffer.get(seq);
|
|
3495
|
+
if (existing !== void 0) {
|
|
3496
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
3497
|
+
console.warn(
|
|
3498
|
+
`[persona] SequenceReorderBuffer: duplicate seq=${seq} (${existing.payloadType} vs ${payloadType}); emitting earlier event out-of-order to avoid loss`
|
|
3499
|
+
);
|
|
3500
|
+
}
|
|
3501
|
+
this.emitter(existing.payloadType, existing.payload);
|
|
3502
|
+
}
|
|
3503
|
+
this.buffer.set(seq, { payloadType, payload, seq });
|
|
3504
|
+
this.startGapTimer();
|
|
3505
|
+
}
|
|
3506
|
+
drainConsecutive() {
|
|
3507
|
+
while (this.buffer.has(this.nextExpectedSeq)) {
|
|
3508
|
+
const event = this.buffer.get(this.nextExpectedSeq);
|
|
3509
|
+
this.buffer.delete(this.nextExpectedSeq);
|
|
3510
|
+
this.emitter(event.payloadType, event.payload);
|
|
3511
|
+
this.nextExpectedSeq++;
|
|
3512
|
+
}
|
|
3513
|
+
if (this.buffer.size === 0) {
|
|
3514
|
+
this.clearGapTimer();
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
startGapTimer() {
|
|
3518
|
+
if (this.flushTimer !== null) return;
|
|
3519
|
+
this.flushTimer = setTimeout(() => {
|
|
3520
|
+
this.flushAll();
|
|
3521
|
+
}, this.gapTimeoutMs);
|
|
3522
|
+
}
|
|
3523
|
+
clearGapTimer() {
|
|
3524
|
+
if (this.flushTimer !== null) {
|
|
3525
|
+
clearTimeout(this.flushTimer);
|
|
3526
|
+
this.flushTimer = null;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
flushAll() {
|
|
3530
|
+
this.clearGapTimer();
|
|
3531
|
+
if (this.buffer.size === 0) return;
|
|
3532
|
+
const sorted = [...this.buffer.entries()].sort((a, b) => a[0] - b[0]);
|
|
3533
|
+
for (const [seq, event] of sorted) {
|
|
3534
|
+
this.buffer.delete(seq);
|
|
3535
|
+
this.emitter(event.payloadType, event.payload);
|
|
3536
|
+
}
|
|
3537
|
+
if (sorted.length > 0) {
|
|
3538
|
+
this.nextExpectedSeq = sorted[sorted.length - 1][0] + 1;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
destroy() {
|
|
3542
|
+
this.clearGapTimer();
|
|
3543
|
+
this.buffer.clear();
|
|
3544
|
+
}
|
|
3545
|
+
flushPending() {
|
|
3546
|
+
this.flushAll();
|
|
3547
|
+
}
|
|
3548
|
+
};
|
|
3549
|
+
|
|
3456
3550
|
// src/client.ts
|
|
3457
3551
|
var DEFAULT_ENDPOINT = "https://api.runtype.com/v1/dispatch";
|
|
3458
3552
|
var DEFAULT_CLIENT_API_BASE = "https://api.runtype.com";
|
|
@@ -4220,7 +4314,7 @@ var AgentWidgetClient = class {
|
|
|
4220
4314
|
}
|
|
4221
4315
|
}
|
|
4222
4316
|
async streamResponse(body, onEvent, assistantMessageId) {
|
|
4223
|
-
var _a, _b, _c, _d
|
|
4317
|
+
var _a, _b, _c, _d;
|
|
4224
4318
|
const reader = body.getReader();
|
|
4225
4319
|
const decoder = new TextDecoder();
|
|
4226
4320
|
let buffer = "";
|
|
@@ -4259,6 +4353,8 @@ var AgentWidgetClient = class {
|
|
|
4259
4353
|
let didSplitByPartId = false;
|
|
4260
4354
|
const reasoningMessages = /* @__PURE__ */ new Map();
|
|
4261
4355
|
const toolMessages = /* @__PURE__ */ new Map();
|
|
4356
|
+
const nestedStepMessages = /* @__PURE__ */ new Map();
|
|
4357
|
+
const nestedPartIdByStep = /* @__PURE__ */ new Map();
|
|
4262
4358
|
const reasoningContext = {
|
|
4263
4359
|
lastId: null,
|
|
4264
4360
|
byStep: /* @__PURE__ */ new Map()
|
|
@@ -4267,6 +4363,31 @@ var AgentWidgetClient = class {
|
|
|
4267
4363
|
lastId: null,
|
|
4268
4364
|
byCall: /* @__PURE__ */ new Map()
|
|
4269
4365
|
};
|
|
4366
|
+
const getNestedStepKey = (toolId, stepId, partId = "") => `${toolId}::${stepId}::${partId}`;
|
|
4367
|
+
const getNestedStepPrefix = (toolId, stepId) => `${toolId}::${stepId}::`;
|
|
4368
|
+
const ensureNestedStepMessage = (toolId, stepId, partId, executionId) => {
|
|
4369
|
+
const key = getNestedStepKey(toolId, stepId, partId);
|
|
4370
|
+
const existing = nestedStepMessages.get(key);
|
|
4371
|
+
if (existing) return existing;
|
|
4372
|
+
const idSuffix = partId ? `-${partId}` : "";
|
|
4373
|
+
const message = {
|
|
4374
|
+
id: `nested-${toolId}-${stepId}${idSuffix}`,
|
|
4375
|
+
role: "assistant",
|
|
4376
|
+
content: "",
|
|
4377
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4378
|
+
streaming: true,
|
|
4379
|
+
sequence: nextSequence(),
|
|
4380
|
+
...partId ? { partId } : {},
|
|
4381
|
+
agentMetadata: {
|
|
4382
|
+
executionId,
|
|
4383
|
+
parentToolId: toolId,
|
|
4384
|
+
parentStepId: stepId
|
|
4385
|
+
}
|
|
4386
|
+
};
|
|
4387
|
+
nestedStepMessages.set(key, message);
|
|
4388
|
+
emitMessage(message);
|
|
4389
|
+
return message;
|
|
4390
|
+
};
|
|
4270
4391
|
const normalizeKey = (value) => {
|
|
4271
4392
|
if (value === null || value === void 0) return null;
|
|
4272
4393
|
try {
|
|
@@ -4276,15 +4397,15 @@ var AgentWidgetClient = class {
|
|
|
4276
4397
|
}
|
|
4277
4398
|
};
|
|
4278
4399
|
const getStepKey = (payload) => {
|
|
4279
|
-
var _a2, _b2, _c2, _d2,
|
|
4400
|
+
var _a2, _b2, _c2, _d2, _e;
|
|
4280
4401
|
return normalizeKey(
|
|
4281
|
-
(
|
|
4402
|
+
(_e = (_d2 = (_c2 = (_b2 = (_a2 = payload.stepId) != null ? _a2 : payload.step_id) != null ? _b2 : payload.step) != null ? _c2 : payload.parentId) != null ? _d2 : payload.flowStepId) != null ? _e : payload.flow_step_id
|
|
4282
4403
|
);
|
|
4283
4404
|
};
|
|
4284
4405
|
const getToolCallKey = (payload) => {
|
|
4285
|
-
var _a2, _b2, _c2, _d2,
|
|
4406
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g;
|
|
4286
4407
|
return normalizeKey(
|
|
4287
|
-
(
|
|
4408
|
+
(_g = (_f = (_e = (_d2 = (_c2 = (_b2 = (_a2 = payload.callId) != null ? _a2 : payload.call_id) != null ? _b2 : payload.requestId) != null ? _c2 : payload.request_id) != null ? _d2 : payload.toolCallId) != null ? _e : payload.tool_call_id) != null ? _f : payload.stepId) != null ? _g : payload.step_id
|
|
4288
4409
|
);
|
|
4289
4410
|
};
|
|
4290
4411
|
const baseAssistantId = assistantMessageId;
|
|
@@ -4460,26 +4581,37 @@ var AgentWidgetClient = class {
|
|
|
4460
4581
|
};
|
|
4461
4582
|
const streamParsers = /* @__PURE__ */ new Map();
|
|
4462
4583
|
const rawContentBuffers = /* @__PURE__ */ new Map();
|
|
4463
|
-
const
|
|
4464
|
-
const
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4584
|
+
const orderedChunkBuffers = /* @__PURE__ */ new Map();
|
|
4585
|
+
const assistantMessagesByPartId = /* @__PURE__ */ new Map();
|
|
4586
|
+
let lastSealedTextSegment = null;
|
|
4587
|
+
const insertOrderedChunk = (key, seq, text) => {
|
|
4588
|
+
var _a2;
|
|
4589
|
+
let chunks = orderedChunkBuffers.get(key);
|
|
4590
|
+
if (!chunks) {
|
|
4591
|
+
chunks = [];
|
|
4592
|
+
orderedChunkBuffers.set(key, chunks);
|
|
4593
|
+
}
|
|
4594
|
+
let lo = 0;
|
|
4595
|
+
let hi = chunks.length;
|
|
4472
4596
|
while (lo < hi) {
|
|
4473
4597
|
const mid = lo + hi >>> 1;
|
|
4474
|
-
if (
|
|
4475
|
-
|
|
4598
|
+
if (chunks[mid].seq < seq) {
|
|
4599
|
+
lo = mid + 1;
|
|
4600
|
+
} else {
|
|
4601
|
+
hi = mid;
|
|
4602
|
+
}
|
|
4476
4603
|
}
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4604
|
+
if (((_a2 = chunks[lo]) == null ? void 0 : _a2.seq) === seq) {
|
|
4605
|
+
chunks[lo] = { seq, text };
|
|
4606
|
+
} else {
|
|
4607
|
+
chunks.splice(lo, 0, { seq, text });
|
|
4608
|
+
}
|
|
4609
|
+
let accumulated = "";
|
|
4610
|
+
for (let index = 0; index < chunks.length; index++) {
|
|
4611
|
+
accumulated += chunks[index].text;
|
|
4612
|
+
}
|
|
4613
|
+
return accumulated;
|
|
4614
|
+
};
|
|
4483
4615
|
const reconcileSealedAssistantWithFinalResponse = (msg, finalContent) => {
|
|
4484
4616
|
const finalString = ensureStringContent(finalContent);
|
|
4485
4617
|
const rawBuffer = rawContentBuffers.get(msg.id);
|
|
@@ -4546,82 +4678,57 @@ var AgentWidgetClient = class {
|
|
|
4546
4678
|
mergeIfBetter(bestDisplayText(parsedResult));
|
|
4547
4679
|
finalizeCleanup();
|
|
4548
4680
|
};
|
|
4681
|
+
const seqReadyQueue = [];
|
|
4682
|
+
let isDrainScheduled = false;
|
|
4683
|
+
let drainReadyQueue;
|
|
4684
|
+
const scheduleReadyQueueDrain = () => {
|
|
4685
|
+
if (isDrainScheduled) return;
|
|
4686
|
+
isDrainScheduled = true;
|
|
4687
|
+
queueMicrotask(() => {
|
|
4688
|
+
isDrainScheduled = false;
|
|
4689
|
+
drainReadyQueue();
|
|
4690
|
+
});
|
|
4691
|
+
};
|
|
4692
|
+
const seqBuffer = new SequenceReorderBuffer((payloadType, payload) => {
|
|
4693
|
+
seqReadyQueue.push({ payloadType, payload });
|
|
4694
|
+
scheduleReadyQueueDrain();
|
|
4695
|
+
});
|
|
4549
4696
|
let agentExecution = null;
|
|
4550
4697
|
const agentIterationMessages = /* @__PURE__ */ new Map();
|
|
4551
4698
|
const iterationDisplay = (_a = this.config.iterationDisplay) != null ? _a : "separate";
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
buffer = (_b = events.pop()) != null ? _b : "";
|
|
4558
|
-
for (const event of events) {
|
|
4559
|
-
const lines = event.split("\n");
|
|
4560
|
-
let eventType = "message";
|
|
4561
|
-
let data = "";
|
|
4562
|
-
for (const line of lines) {
|
|
4563
|
-
if (line.startsWith("event:")) {
|
|
4564
|
-
eventType = line.replace("event:", "").trim();
|
|
4565
|
-
} else if (line.startsWith("data:")) {
|
|
4566
|
-
data += line.replace("data:", "").trim();
|
|
4567
|
-
}
|
|
4568
|
-
}
|
|
4569
|
-
if (!data) continue;
|
|
4570
|
-
let payload;
|
|
4571
|
-
try {
|
|
4572
|
-
payload = JSON.parse(data);
|
|
4573
|
-
} catch (error) {
|
|
4574
|
-
onEvent({
|
|
4575
|
-
type: "error",
|
|
4576
|
-
error: error instanceof Error ? error : new Error("Failed to parse chat stream payload")
|
|
4577
|
-
});
|
|
4578
|
-
continue;
|
|
4579
|
-
}
|
|
4580
|
-
const payloadType = eventType !== "message" ? eventType : (_c = payload.type) != null ? _c : "message";
|
|
4581
|
-
(_d = this.onSSEEvent) == null ? void 0 : _d.call(this, payloadType, payload);
|
|
4582
|
-
if (this.parseSSEEvent) {
|
|
4583
|
-
assistantMessageRef.current = assistantMessage;
|
|
4584
|
-
const handled = await this.handleCustomSSEEvent(
|
|
4585
|
-
payload,
|
|
4586
|
-
onEvent,
|
|
4587
|
-
assistantMessageRef,
|
|
4588
|
-
emitMessage,
|
|
4589
|
-
nextSequence,
|
|
4590
|
-
partIdState
|
|
4591
|
-
);
|
|
4592
|
-
if (assistantMessageRef.current && assistantMessageRef.current !== assistantMessage) {
|
|
4593
|
-
assistantMessage = assistantMessageRef.current;
|
|
4594
|
-
}
|
|
4595
|
-
if (handled) continue;
|
|
4596
|
-
}
|
|
4699
|
+
drainReadyQueue = () => {
|
|
4700
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub;
|
|
4701
|
+
for (let i = 0; i < seqReadyQueue.length; i++) {
|
|
4702
|
+
const payloadType = seqReadyQueue[i].payloadType;
|
|
4703
|
+
const payload = seqReadyQueue[i].payload;
|
|
4597
4704
|
if (payloadType === "reason_start") {
|
|
4598
|
-
const reasoningId = (
|
|
4705
|
+
const reasoningId = (_a2 = resolveReasoningId(payload, true)) != null ? _a2 : `reason-${nextSequence()}`;
|
|
4599
4706
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
4600
|
-
reasoningMessage.reasoning = (
|
|
4707
|
+
reasoningMessage.reasoning = (_b2 = reasoningMessage.reasoning) != null ? _b2 : {
|
|
4601
4708
|
id: reasoningId,
|
|
4602
4709
|
status: "streaming",
|
|
4603
4710
|
chunks: []
|
|
4604
4711
|
};
|
|
4605
|
-
reasoningMessage.reasoning.startedAt = (
|
|
4712
|
+
reasoningMessage.reasoning.startedAt = (_d2 = reasoningMessage.reasoning.startedAt) != null ? _d2 : resolveTimestamp((_c2 = payload.startedAt) != null ? _c2 : payload.timestamp);
|
|
4606
4713
|
reasoningMessage.reasoning.completedAt = void 0;
|
|
4607
4714
|
reasoningMessage.reasoning.durationMs = void 0;
|
|
4608
4715
|
reasoningMessage.streaming = true;
|
|
4609
4716
|
reasoningMessage.reasoning.status = "streaming";
|
|
4610
4717
|
emitMessage(reasoningMessage);
|
|
4611
4718
|
} else if (payloadType === "reason_delta" || payloadType === "reason_chunk") {
|
|
4612
|
-
const reasoningId = (
|
|
4719
|
+
const reasoningId = (_f = (_e = resolveReasoningId(payload, false)) != null ? _e : resolveReasoningId(payload, true)) != null ? _f : `reason-${nextSequence()}`;
|
|
4613
4720
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
4614
|
-
reasoningMessage.reasoning = (
|
|
4721
|
+
reasoningMessage.reasoning = (_g = reasoningMessage.reasoning) != null ? _g : {
|
|
4615
4722
|
id: reasoningId,
|
|
4616
4723
|
status: "streaming",
|
|
4617
4724
|
chunks: []
|
|
4618
4725
|
};
|
|
4619
|
-
reasoningMessage.reasoning.startedAt = (
|
|
4620
|
-
const chunk = (
|
|
4726
|
+
reasoningMessage.reasoning.startedAt = (_i = reasoningMessage.reasoning.startedAt) != null ? _i : resolveTimestamp((_h = payload.startedAt) != null ? _h : payload.timestamp);
|
|
4727
|
+
const chunk = (_l = (_k = (_j = payload.reasoningText) != null ? _j : payload.text) != null ? _k : payload.delta) != null ? _l : "";
|
|
4621
4728
|
if (chunk && payload.hidden !== true) {
|
|
4622
4729
|
const reasonSeq = typeof payload.sequenceIndex === "number" ? payload.sequenceIndex : void 0;
|
|
4623
4730
|
if (reasonSeq !== void 0) {
|
|
4624
|
-
const ordered =
|
|
4731
|
+
const ordered = insertOrderedChunk(reasoningId, reasonSeq, String(chunk));
|
|
4625
4732
|
reasoningMessage.reasoning.chunks = [ordered];
|
|
4626
4733
|
} else {
|
|
4627
4734
|
reasoningMessage.reasoning.chunks.push(String(chunk));
|
|
@@ -4630,32 +4737,30 @@ var AgentWidgetClient = class {
|
|
|
4630
4737
|
reasoningMessage.reasoning.status = payload.done ? "complete" : "streaming";
|
|
4631
4738
|
if (payload.done) {
|
|
4632
4739
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(
|
|
4633
|
-
(
|
|
4740
|
+
(_m = payload.completedAt) != null ? _m : payload.timestamp
|
|
4634
4741
|
);
|
|
4635
|
-
const start = (
|
|
4742
|
+
const start = (_n = reasoningMessage.reasoning.startedAt) != null ? _n : Date.now();
|
|
4636
4743
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
4637
4744
|
0,
|
|
4638
|
-
((
|
|
4745
|
+
((_o = reasoningMessage.reasoning.completedAt) != null ? _o : Date.now()) - start
|
|
4639
4746
|
);
|
|
4640
|
-
reasonSeqBuffers.delete(reasoningId);
|
|
4641
4747
|
}
|
|
4642
4748
|
reasoningMessage.streaming = reasoningMessage.reasoning.status !== "complete";
|
|
4643
4749
|
emitMessage(reasoningMessage);
|
|
4644
4750
|
} else if (payloadType === "reason_complete") {
|
|
4645
|
-
const reasoningId = (
|
|
4751
|
+
const reasoningId = (_q = (_p = resolveReasoningId(payload, false)) != null ? _p : resolveReasoningId(payload, true)) != null ? _q : `reason-${nextSequence()}`;
|
|
4646
4752
|
const reasoningMessage = reasoningMessages.get(reasoningId);
|
|
4647
4753
|
if (reasoningMessage == null ? void 0 : reasoningMessage.reasoning) {
|
|
4648
4754
|
reasoningMessage.reasoning.status = "complete";
|
|
4649
4755
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(
|
|
4650
|
-
(
|
|
4756
|
+
(_r = payload.completedAt) != null ? _r : payload.timestamp
|
|
4651
4757
|
);
|
|
4652
|
-
const start = (
|
|
4758
|
+
const start = (_s = reasoningMessage.reasoning.startedAt) != null ? _s : Date.now();
|
|
4653
4759
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
4654
4760
|
0,
|
|
4655
|
-
((
|
|
4761
|
+
((_t = reasoningMessage.reasoning.completedAt) != null ? _t : Date.now()) - start
|
|
4656
4762
|
);
|
|
4657
4763
|
reasoningMessage.streaming = false;
|
|
4658
|
-
reasonSeqBuffers.delete(reasoningId);
|
|
4659
4764
|
emitMessage(reasoningMessage);
|
|
4660
4765
|
}
|
|
4661
4766
|
const stepKey = getStepKey(payload);
|
|
@@ -4663,14 +4768,14 @@ var AgentWidgetClient = class {
|
|
|
4663
4768
|
reasoningContext.byStep.delete(stepKey);
|
|
4664
4769
|
}
|
|
4665
4770
|
} else if (payloadType === "tool_start") {
|
|
4666
|
-
const toolId = (
|
|
4667
|
-
const toolName = (
|
|
4771
|
+
const toolId = (_u = resolveToolId(payload, true)) != null ? _u : `tool-${nextSequence()}`;
|
|
4772
|
+
const toolName = (_v = payload.toolName) != null ? _v : payload.name;
|
|
4668
4773
|
if (isArtifactEmitToolName(toolName)) {
|
|
4669
4774
|
artifactToolCallIds.add(toolId);
|
|
4670
4775
|
continue;
|
|
4671
4776
|
}
|
|
4672
4777
|
const toolMessage = ensureToolMessage(toolId);
|
|
4673
|
-
const tool = (
|
|
4778
|
+
const tool = (_w = toolMessage.toolCall) != null ? _w : {
|
|
4674
4779
|
id: toolId,
|
|
4675
4780
|
status: "pending"
|
|
4676
4781
|
};
|
|
@@ -4681,7 +4786,7 @@ var AgentWidgetClient = class {
|
|
|
4681
4786
|
} else if (payload.parameters !== void 0) {
|
|
4682
4787
|
tool.args = payload.parameters;
|
|
4683
4788
|
}
|
|
4684
|
-
tool.startedAt = (
|
|
4789
|
+
tool.startedAt = (_y = tool.startedAt) != null ? _y : resolveTimestamp((_x = payload.startedAt) != null ? _x : payload.timestamp);
|
|
4685
4790
|
tool.completedAt = void 0;
|
|
4686
4791
|
tool.durationMs = void 0;
|
|
4687
4792
|
toolMessage.toolCall = tool;
|
|
@@ -4689,23 +4794,23 @@ var AgentWidgetClient = class {
|
|
|
4689
4794
|
const agentCtx = payload.agentContext;
|
|
4690
4795
|
if (agentCtx || payload.executionId) {
|
|
4691
4796
|
toolMessage.agentMetadata = {
|
|
4692
|
-
executionId: (
|
|
4693
|
-
iteration: (
|
|
4797
|
+
executionId: (_z = agentCtx == null ? void 0 : agentCtx.executionId) != null ? _z : payload.executionId,
|
|
4798
|
+
iteration: (_A = agentCtx == null ? void 0 : agentCtx.iteration) != null ? _A : payload.iteration
|
|
4694
4799
|
};
|
|
4695
4800
|
}
|
|
4696
4801
|
emitMessage(toolMessage);
|
|
4697
4802
|
} else if (payloadType === "tool_chunk" || payloadType === "tool_delta") {
|
|
4698
|
-
const toolId = (
|
|
4803
|
+
const toolId = (_C = (_B = resolveToolId(payload, false)) != null ? _B : resolveToolId(payload, true)) != null ? _C : `tool-${nextSequence()}`;
|
|
4699
4804
|
if (artifactToolCallIds.has(toolId)) continue;
|
|
4700
4805
|
const toolMessage = ensureToolMessage(toolId);
|
|
4701
|
-
const tool = (
|
|
4806
|
+
const tool = (_D = toolMessage.toolCall) != null ? _D : {
|
|
4702
4807
|
id: toolId,
|
|
4703
4808
|
status: "running"
|
|
4704
4809
|
};
|
|
4705
|
-
tool.startedAt = (
|
|
4706
|
-
const chunkText = (
|
|
4810
|
+
tool.startedAt = (_F = tool.startedAt) != null ? _F : resolveTimestamp((_E = payload.startedAt) != null ? _E : payload.timestamp);
|
|
4811
|
+
const chunkText = (_I = (_H = (_G = payload.text) != null ? _G : payload.delta) != null ? _H : payload.message) != null ? _I : "";
|
|
4707
4812
|
if (chunkText) {
|
|
4708
|
-
tool.chunks = (
|
|
4813
|
+
tool.chunks = (_J = tool.chunks) != null ? _J : [];
|
|
4709
4814
|
tool.chunks.push(String(chunkText));
|
|
4710
4815
|
}
|
|
4711
4816
|
tool.status = "running";
|
|
@@ -4713,20 +4818,20 @@ var AgentWidgetClient = class {
|
|
|
4713
4818
|
toolMessage.streaming = true;
|
|
4714
4819
|
const agentCtxChunk = payload.agentContext;
|
|
4715
4820
|
if (agentCtxChunk || payload.executionId) {
|
|
4716
|
-
toolMessage.agentMetadata = (
|
|
4717
|
-
executionId: (
|
|
4718
|
-
iteration: (
|
|
4821
|
+
toolMessage.agentMetadata = (_M = toolMessage.agentMetadata) != null ? _M : {
|
|
4822
|
+
executionId: (_K = agentCtxChunk == null ? void 0 : agentCtxChunk.executionId) != null ? _K : payload.executionId,
|
|
4823
|
+
iteration: (_L = agentCtxChunk == null ? void 0 : agentCtxChunk.iteration) != null ? _L : payload.iteration
|
|
4719
4824
|
};
|
|
4720
4825
|
}
|
|
4721
4826
|
emitMessage(toolMessage);
|
|
4722
4827
|
} else if (payloadType === "tool_complete") {
|
|
4723
|
-
const toolId = (
|
|
4828
|
+
const toolId = (_O = (_N = resolveToolId(payload, false)) != null ? _N : resolveToolId(payload, true)) != null ? _O : `tool-${nextSequence()}`;
|
|
4724
4829
|
if (artifactToolCallIds.has(toolId)) {
|
|
4725
4830
|
artifactToolCallIds.delete(toolId);
|
|
4726
4831
|
continue;
|
|
4727
4832
|
}
|
|
4728
4833
|
const toolMessage = ensureToolMessage(toolId);
|
|
4729
|
-
const tool = (
|
|
4834
|
+
const tool = (_P = toolMessage.toolCall) != null ? _P : {
|
|
4730
4835
|
id: toolId,
|
|
4731
4836
|
status: "running"
|
|
4732
4837
|
};
|
|
@@ -4738,25 +4843,25 @@ var AgentWidgetClient = class {
|
|
|
4738
4843
|
tool.duration = payload.duration;
|
|
4739
4844
|
}
|
|
4740
4845
|
tool.completedAt = resolveTimestamp(
|
|
4741
|
-
(
|
|
4846
|
+
(_Q = payload.completedAt) != null ? _Q : payload.timestamp
|
|
4742
4847
|
);
|
|
4743
|
-
const durationValue = (
|
|
4848
|
+
const durationValue = (_R = payload.duration) != null ? _R : payload.executionTime;
|
|
4744
4849
|
if (typeof durationValue === "number") {
|
|
4745
4850
|
tool.durationMs = durationValue;
|
|
4746
4851
|
} else {
|
|
4747
|
-
const start = (
|
|
4852
|
+
const start = (_S = tool.startedAt) != null ? _S : Date.now();
|
|
4748
4853
|
tool.durationMs = Math.max(
|
|
4749
4854
|
0,
|
|
4750
|
-
((
|
|
4855
|
+
((_T = tool.completedAt) != null ? _T : Date.now()) - start
|
|
4751
4856
|
);
|
|
4752
4857
|
}
|
|
4753
4858
|
toolMessage.toolCall = tool;
|
|
4754
4859
|
toolMessage.streaming = false;
|
|
4755
4860
|
const agentCtxComplete = payload.agentContext;
|
|
4756
4861
|
if (agentCtxComplete || payload.executionId) {
|
|
4757
|
-
toolMessage.agentMetadata = (
|
|
4758
|
-
executionId: (
|
|
4759
|
-
iteration: (
|
|
4862
|
+
toolMessage.agentMetadata = (_W = toolMessage.agentMetadata) != null ? _W : {
|
|
4863
|
+
executionId: (_U = agentCtxComplete == null ? void 0 : agentCtxComplete.executionId) != null ? _U : payload.executionId,
|
|
4864
|
+
iteration: (_V = agentCtxComplete == null ? void 0 : agentCtxComplete.iteration) != null ? _V : payload.iteration
|
|
4760
4865
|
};
|
|
4761
4866
|
}
|
|
4762
4867
|
emitMessage(toolMessage);
|
|
@@ -4765,6 +4870,9 @@ var AgentWidgetClient = class {
|
|
|
4765
4870
|
toolContext.byCall.delete(callKey);
|
|
4766
4871
|
}
|
|
4767
4872
|
} else if (payloadType === "text_start") {
|
|
4873
|
+
if ((_X = payload.toolContext) == null ? void 0 : _X.toolId) {
|
|
4874
|
+
continue;
|
|
4875
|
+
}
|
|
4768
4876
|
const incomingPartId = payload.partId;
|
|
4769
4877
|
if (incomingPartId !== void 0 && partIdState.current !== null && incomingPartId !== partIdState.current) {
|
|
4770
4878
|
const prev = assistantMessage;
|
|
@@ -4780,6 +4888,9 @@ var AgentWidgetClient = class {
|
|
|
4780
4888
|
partIdState.current = incomingPartId;
|
|
4781
4889
|
}
|
|
4782
4890
|
} else if (payloadType === "text_end") {
|
|
4891
|
+
if ((_Y = payload.toolContext) == null ? void 0 : _Y.toolId) {
|
|
4892
|
+
continue;
|
|
4893
|
+
}
|
|
4783
4894
|
const prev = assistantMessage;
|
|
4784
4895
|
if (prev) {
|
|
4785
4896
|
prev.streaming = false;
|
|
@@ -4794,6 +4905,48 @@ var AgentWidgetClient = class {
|
|
|
4794
4905
|
if (stepType === "tool" || executionType === "context") {
|
|
4795
4906
|
continue;
|
|
4796
4907
|
}
|
|
4908
|
+
const nestedToolCtx = payload.toolContext;
|
|
4909
|
+
if (nestedToolCtx == null ? void 0 : nestedToolCtx.toolId) {
|
|
4910
|
+
const nestedStepId = String(
|
|
4911
|
+
(__ = (_Z = payload.id) != null ? _Z : nestedToolCtx.stepId) != null ? __ : `step-${nextSequence()}`
|
|
4912
|
+
);
|
|
4913
|
+
const incomingPartId2 = payload.partId !== void 0 && payload.partId !== null ? String(payload.partId) : "";
|
|
4914
|
+
const stepScopeKey = `${nestedToolCtx.toolId}::${nestedStepId}`;
|
|
4915
|
+
const prevPartId = nestedPartIdByStep.get(stepScopeKey);
|
|
4916
|
+
if (incomingPartId2 !== "" && prevPartId !== void 0 && prevPartId !== "" && prevPartId !== incomingPartId2) {
|
|
4917
|
+
const prev = nestedStepMessages.get(
|
|
4918
|
+
getNestedStepKey(
|
|
4919
|
+
nestedToolCtx.toolId,
|
|
4920
|
+
nestedStepId,
|
|
4921
|
+
prevPartId
|
|
4922
|
+
)
|
|
4923
|
+
);
|
|
4924
|
+
if (prev && prev.streaming !== false) {
|
|
4925
|
+
prev.streaming = false;
|
|
4926
|
+
emitMessage(prev);
|
|
4927
|
+
}
|
|
4928
|
+
}
|
|
4929
|
+
if (incomingPartId2 !== "") {
|
|
4930
|
+
nestedPartIdByStep.set(stepScopeKey, incomingPartId2);
|
|
4931
|
+
}
|
|
4932
|
+
const nestedMsg = ensureNestedStepMessage(
|
|
4933
|
+
nestedToolCtx.toolId,
|
|
4934
|
+
nestedStepId,
|
|
4935
|
+
incomingPartId2,
|
|
4936
|
+
nestedToolCtx.executionId
|
|
4937
|
+
);
|
|
4938
|
+
const nestedChunk = (_ca = (_ba = (_aa = (_$ = payload.text) != null ? _$ : payload.delta) != null ? _aa : payload.content) != null ? _ba : payload.chunk) != null ? _ca : "";
|
|
4939
|
+
if (nestedChunk) {
|
|
4940
|
+
nestedMsg.content += String(nestedChunk);
|
|
4941
|
+
nestedMsg.streaming = true;
|
|
4942
|
+
emitMessage(nestedMsg);
|
|
4943
|
+
}
|
|
4944
|
+
if (payload.isComplete) {
|
|
4945
|
+
nestedMsg.streaming = false;
|
|
4946
|
+
emitMessage(nestedMsg);
|
|
4947
|
+
}
|
|
4948
|
+
continue;
|
|
4949
|
+
}
|
|
4797
4950
|
const incomingPartId = payload.partId;
|
|
4798
4951
|
if (incomingPartId !== void 0 && partIdState.current !== null && incomingPartId !== partIdState.current) {
|
|
4799
4952
|
const prev = assistantMessage;
|
|
@@ -4808,20 +4961,18 @@ var AgentWidgetClient = class {
|
|
|
4808
4961
|
if (incomingPartId !== void 0) {
|
|
4809
4962
|
partIdState.current = incomingPartId;
|
|
4810
4963
|
}
|
|
4811
|
-
const assistant = ensureAssistantMessage();
|
|
4812
|
-
if (incomingPartId !== void 0
|
|
4813
|
-
assistant.partId
|
|
4964
|
+
const assistant = incomingPartId !== void 0 ? (_da = assistantMessagesByPartId.get(incomingPartId)) != null ? _da : ensureAssistantMessage() : ensureAssistantMessage();
|
|
4965
|
+
if (incomingPartId !== void 0) {
|
|
4966
|
+
if (!assistant.partId) {
|
|
4967
|
+
assistant.partId = incomingPartId;
|
|
4968
|
+
}
|
|
4969
|
+
assistantMessagesByPartId.set(incomingPartId, assistant);
|
|
4814
4970
|
}
|
|
4815
|
-
const chunk = (
|
|
4971
|
+
const chunk = (_ha = (_ga = (_fa = (_ea = payload.text) != null ? _ea : payload.delta) != null ? _fa : payload.content) != null ? _ga : payload.chunk) != null ? _ha : "";
|
|
4816
4972
|
if (chunk) {
|
|
4817
4973
|
const chunkSeq = typeof payload.seq === "number" ? payload.seq : void 0;
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
accumulatedRaw = insertSeqChunk(seqChunkBuffers, assistant.id, chunkSeq, chunk);
|
|
4821
|
-
} else {
|
|
4822
|
-
const rawBuffer = (_da = rawContentBuffers.get(assistant.id)) != null ? _da : "";
|
|
4823
|
-
accumulatedRaw = rawBuffer + chunk;
|
|
4824
|
-
}
|
|
4974
|
+
const chunkBufferKey = incomingPartId != null ? incomingPartId : assistant.id;
|
|
4975
|
+
const accumulatedRaw = chunkSeq !== void 0 ? insertOrderedChunk(chunkBufferKey, chunkSeq, String(chunk)) : ((_ia = rawContentBuffers.get(assistant.id)) != null ? _ia : "") + chunk;
|
|
4825
4976
|
assistant.rawContent = accumulatedRaw;
|
|
4826
4977
|
if (!streamParsers.has(assistant.id)) {
|
|
4827
4978
|
streamParsers.set(assistant.id, this.createStreamParser());
|
|
@@ -4833,11 +4984,7 @@ var AgentWidgetClient = class {
|
|
|
4833
4984
|
}
|
|
4834
4985
|
const isPlainTextParser = parser.__isPlainTextParser === true;
|
|
4835
4986
|
if (isPlainTextParser) {
|
|
4836
|
-
|
|
4837
|
-
assistant.content = accumulatedRaw;
|
|
4838
|
-
} else {
|
|
4839
|
-
assistant.content += chunk;
|
|
4840
|
-
}
|
|
4987
|
+
assistant.content = chunkSeq !== void 0 ? accumulatedRaw : assistant.content + chunk;
|
|
4841
4988
|
rawContentBuffers.delete(assistant.id);
|
|
4842
4989
|
streamParsers.delete(assistant.id);
|
|
4843
4990
|
assistant.rawContent = void 0;
|
|
@@ -4847,47 +4994,36 @@ var AgentWidgetClient = class {
|
|
|
4847
4994
|
const parsedResult = parser.processChunk(accumulatedRaw);
|
|
4848
4995
|
if (parsedResult instanceof Promise) {
|
|
4849
4996
|
parsedResult.then((result) => {
|
|
4850
|
-
var
|
|
4851
|
-
const text = typeof result === "string" ? result : (
|
|
4997
|
+
var _a3;
|
|
4998
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
4852
4999
|
if (text !== null && text.trim() !== "") {
|
|
4853
5000
|
assistant.content = text;
|
|
4854
5001
|
emitMessage(assistant);
|
|
4855
5002
|
} else if (!looksLikeJson && !accumulatedRaw.trim().startsWith("<")) {
|
|
4856
5003
|
const currentAssistant = assistantMessage;
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
streamParsers.delete(currentAssistant.id);
|
|
4865
|
-
currentAssistant.rawContent = void 0;
|
|
4866
|
-
emitMessage(currentAssistant);
|
|
5004
|
+
const targetAssistant = currentAssistant && currentAssistant.id === assistant.id ? currentAssistant : assistant;
|
|
5005
|
+
if (targetAssistant.id === assistant.id) {
|
|
5006
|
+
targetAssistant.content = chunkSeq !== void 0 ? accumulatedRaw : targetAssistant.content + chunk;
|
|
5007
|
+
rawContentBuffers.delete(targetAssistant.id);
|
|
5008
|
+
streamParsers.delete(targetAssistant.id);
|
|
5009
|
+
targetAssistant.rawContent = void 0;
|
|
5010
|
+
emitMessage(targetAssistant);
|
|
4867
5011
|
}
|
|
4868
5012
|
}
|
|
4869
5013
|
}).catch(() => {
|
|
4870
|
-
|
|
4871
|
-
assistant.content = accumulatedRaw;
|
|
4872
|
-
} else {
|
|
4873
|
-
assistant.content += chunk;
|
|
4874
|
-
}
|
|
5014
|
+
assistant.content = chunkSeq !== void 0 ? accumulatedRaw : assistant.content + chunk;
|
|
4875
5015
|
rawContentBuffers.delete(assistant.id);
|
|
4876
5016
|
streamParsers.delete(assistant.id);
|
|
4877
5017
|
assistant.rawContent = void 0;
|
|
4878
5018
|
emitMessage(assistant);
|
|
4879
5019
|
});
|
|
4880
5020
|
} else {
|
|
4881
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5021
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_ja = parsedResult == null ? void 0 : parsedResult.text) != null ? _ja : null;
|
|
4882
5022
|
if (text !== null && text.trim() !== "") {
|
|
4883
5023
|
assistant.content = text;
|
|
4884
5024
|
emitMessage(assistant);
|
|
4885
5025
|
} else if (!looksLikeJson && !accumulatedRaw.trim().startsWith("<")) {
|
|
4886
|
-
|
|
4887
|
-
assistant.content = accumulatedRaw;
|
|
4888
|
-
} else {
|
|
4889
|
-
assistant.content += chunk;
|
|
4890
|
-
}
|
|
5026
|
+
assistant.content = chunkSeq !== void 0 ? accumulatedRaw : assistant.content + chunk;
|
|
4891
5027
|
rawContentBuffers.delete(assistant.id);
|
|
4892
5028
|
streamParsers.delete(assistant.id);
|
|
4893
5029
|
assistant.rawContent = void 0;
|
|
@@ -4896,7 +5032,7 @@ var AgentWidgetClient = class {
|
|
|
4896
5032
|
}
|
|
4897
5033
|
}
|
|
4898
5034
|
if (payload.isComplete) {
|
|
4899
|
-
const finalContent = (
|
|
5035
|
+
const finalContent = (_la = (_ka = payload.result) == null ? void 0 : _ka.response) != null ? _la : assistant.content;
|
|
4900
5036
|
if (finalContent) {
|
|
4901
5037
|
const rawBuffer = rawContentBuffers.get(assistant.id);
|
|
4902
5038
|
const contentToProcess = rawBuffer != null ? rawBuffer : ensureStringContent(finalContent);
|
|
@@ -4914,8 +5050,8 @@ var AgentWidgetClient = class {
|
|
|
4914
5050
|
if (parsedResult instanceof Promise) {
|
|
4915
5051
|
asyncPending = true;
|
|
4916
5052
|
parsedResult.then((result) => {
|
|
4917
|
-
var
|
|
4918
|
-
const text = typeof result === "string" ? result : (
|
|
5053
|
+
var _a3;
|
|
5054
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
4919
5055
|
if (text !== null) {
|
|
4920
5056
|
const currentAssistant = assistantMessage;
|
|
4921
5057
|
if (currentAssistant && currentAssistant.id === assistant.id) {
|
|
@@ -4923,13 +5059,12 @@ var AgentWidgetClient = class {
|
|
|
4923
5059
|
currentAssistant.streaming = false;
|
|
4924
5060
|
streamParsers.delete(currentAssistant.id);
|
|
4925
5061
|
rawContentBuffers.delete(currentAssistant.id);
|
|
4926
|
-
seqChunkBuffers.delete(currentAssistant.id);
|
|
4927
5062
|
emitMessage(currentAssistant);
|
|
4928
5063
|
}
|
|
4929
5064
|
}
|
|
4930
5065
|
});
|
|
4931
5066
|
} else {
|
|
4932
|
-
extractedText = typeof parsedResult === "string" ? parsedResult : (
|
|
5067
|
+
extractedText = typeof parsedResult === "string" ? parsedResult : (_ma = parsedResult == null ? void 0 : parsedResult.text) != null ? _ma : null;
|
|
4933
5068
|
}
|
|
4934
5069
|
}
|
|
4935
5070
|
}
|
|
@@ -4941,7 +5076,7 @@ var AgentWidgetClient = class {
|
|
|
4941
5076
|
}
|
|
4942
5077
|
const parserToClose = streamParsers.get(assistant.id);
|
|
4943
5078
|
if (parserToClose) {
|
|
4944
|
-
const closeResult = (
|
|
5079
|
+
const closeResult = (_na = parserToClose.close) == null ? void 0 : _na.call(parserToClose);
|
|
4945
5080
|
if (closeResult instanceof Promise) {
|
|
4946
5081
|
closeResult.catch(() => {
|
|
4947
5082
|
});
|
|
@@ -4949,7 +5084,6 @@ var AgentWidgetClient = class {
|
|
|
4949
5084
|
streamParsers.delete(assistant.id);
|
|
4950
5085
|
}
|
|
4951
5086
|
rawContentBuffers.delete(assistant.id);
|
|
4952
|
-
seqChunkBuffers.delete(assistant.id);
|
|
4953
5087
|
assistant.streaming = false;
|
|
4954
5088
|
emitMessage(assistant);
|
|
4955
5089
|
}
|
|
@@ -4961,18 +5095,39 @@ var AgentWidgetClient = class {
|
|
|
4961
5095
|
if (stepType === "tool" || executionType === "context") {
|
|
4962
5096
|
continue;
|
|
4963
5097
|
}
|
|
5098
|
+
const nestedCompleteCtx = payload.toolContext;
|
|
5099
|
+
if (nestedCompleteCtx == null ? void 0 : nestedCompleteCtx.toolId) {
|
|
5100
|
+
const nestedStepId = String(
|
|
5101
|
+
(_pa = (_oa = payload.id) != null ? _oa : nestedCompleteCtx.stepId) != null ? _pa : ""
|
|
5102
|
+
);
|
|
5103
|
+
if (nestedStepId) {
|
|
5104
|
+
const prefix = getNestedStepPrefix(
|
|
5105
|
+
nestedCompleteCtx.toolId,
|
|
5106
|
+
nestedStepId
|
|
5107
|
+
);
|
|
5108
|
+
for (const [key, msg] of nestedStepMessages) {
|
|
5109
|
+
if (key.startsWith(prefix) && msg.streaming !== false) {
|
|
5110
|
+
msg.streaming = false;
|
|
5111
|
+
emitMessage(msg);
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
nestedPartIdByStep.delete(
|
|
5115
|
+
`${nestedCompleteCtx.toolId}::${nestedStepId}`
|
|
5116
|
+
);
|
|
5117
|
+
}
|
|
5118
|
+
continue;
|
|
5119
|
+
}
|
|
4964
5120
|
if (didSplitByPartId) {
|
|
4965
5121
|
if (assistantMessage !== null) {
|
|
4966
5122
|
const msg = assistantMessage;
|
|
4967
5123
|
streamParsers.delete(msg.id);
|
|
4968
5124
|
rawContentBuffers.delete(msg.id);
|
|
4969
|
-
seqChunkBuffers.delete(msg.id);
|
|
4970
5125
|
if (msg.streaming !== false) {
|
|
4971
5126
|
msg.streaming = false;
|
|
4972
5127
|
emitMessage(msg);
|
|
4973
5128
|
}
|
|
4974
5129
|
}
|
|
4975
|
-
const splitFinalContent = (
|
|
5130
|
+
const splitFinalContent = (_qa = payload.result) == null ? void 0 : _qa.response;
|
|
4976
5131
|
const sealedForReconcile = lastSealedTextSegment;
|
|
4977
5132
|
if (sealedForReconcile) {
|
|
4978
5133
|
if (splitFinalContent !== void 0 && splitFinalContent !== null) {
|
|
@@ -4985,7 +5140,7 @@ var AgentWidgetClient = class {
|
|
|
4985
5140
|
lastSealedTextSegment = null;
|
|
4986
5141
|
continue;
|
|
4987
5142
|
}
|
|
4988
|
-
const finalContent = (
|
|
5143
|
+
const finalContent = (_ra = payload.result) == null ? void 0 : _ra.response;
|
|
4989
5144
|
const assistant = ensureAssistantMessage();
|
|
4990
5145
|
if (finalContent !== void 0 && finalContent !== null) {
|
|
4991
5146
|
const parser = streamParsers.get(assistant.id);
|
|
@@ -5009,8 +5164,8 @@ var AgentWidgetClient = class {
|
|
|
5009
5164
|
if (parsedResult instanceof Promise) {
|
|
5010
5165
|
asyncPending = true;
|
|
5011
5166
|
parsedResult.then((result) => {
|
|
5012
|
-
var
|
|
5013
|
-
const text = typeof result === "string" ? result : (
|
|
5167
|
+
var _a3;
|
|
5168
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
5014
5169
|
if (text !== null && text.trim() !== "") {
|
|
5015
5170
|
const currentAssistant = assistantMessage;
|
|
5016
5171
|
if (currentAssistant && currentAssistant.id === assistant.id) {
|
|
@@ -5018,7 +5173,6 @@ var AgentWidgetClient = class {
|
|
|
5018
5173
|
currentAssistant.streaming = false;
|
|
5019
5174
|
streamParsers.delete(currentAssistant.id);
|
|
5020
5175
|
rawContentBuffers.delete(currentAssistant.id);
|
|
5021
|
-
seqChunkBuffers.delete(currentAssistant.id);
|
|
5022
5176
|
emitMessage(currentAssistant);
|
|
5023
5177
|
}
|
|
5024
5178
|
} else {
|
|
@@ -5033,13 +5187,12 @@ var AgentWidgetClient = class {
|
|
|
5033
5187
|
currentAssistant.streaming = false;
|
|
5034
5188
|
streamParsers.delete(currentAssistant.id);
|
|
5035
5189
|
rawContentBuffers.delete(currentAssistant.id);
|
|
5036
|
-
seqChunkBuffers.delete(currentAssistant.id);
|
|
5037
5190
|
emitMessage(currentAssistant);
|
|
5038
5191
|
}
|
|
5039
5192
|
}
|
|
5040
5193
|
});
|
|
5041
5194
|
} else {
|
|
5042
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5195
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_sa = parsedResult == null ? void 0 : parsedResult.text) != null ? _sa : null;
|
|
5043
5196
|
if (text !== null && text.trim() !== "") {
|
|
5044
5197
|
assistant.content = text;
|
|
5045
5198
|
hasExtractedText = true;
|
|
@@ -5063,7 +5216,7 @@ var AgentWidgetClient = class {
|
|
|
5063
5216
|
assistant.content = ensureStringContent(finalContent);
|
|
5064
5217
|
}
|
|
5065
5218
|
if (parser) {
|
|
5066
|
-
const closeResult = (
|
|
5219
|
+
const closeResult = (_ta = parser.close) == null ? void 0 : _ta.call(parser);
|
|
5067
5220
|
if (closeResult instanceof Promise) {
|
|
5068
5221
|
closeResult.catch(() => {
|
|
5069
5222
|
});
|
|
@@ -5071,25 +5224,22 @@ var AgentWidgetClient = class {
|
|
|
5071
5224
|
}
|
|
5072
5225
|
streamParsers.delete(assistant.id);
|
|
5073
5226
|
rawContentBuffers.delete(assistant.id);
|
|
5074
|
-
seqChunkBuffers.delete(assistant.id);
|
|
5075
5227
|
assistant.streaming = false;
|
|
5076
5228
|
emitMessage(assistant);
|
|
5077
5229
|
}
|
|
5078
5230
|
} else {
|
|
5079
5231
|
streamParsers.delete(assistant.id);
|
|
5080
5232
|
rawContentBuffers.delete(assistant.id);
|
|
5081
|
-
seqChunkBuffers.delete(assistant.id);
|
|
5082
5233
|
assistant.streaming = false;
|
|
5083
5234
|
emitMessage(assistant);
|
|
5084
5235
|
}
|
|
5085
5236
|
} else if (payloadType === "flow_complete") {
|
|
5086
|
-
const finalContent = (
|
|
5237
|
+
const finalContent = (_ua = payload.result) == null ? void 0 : _ua.response;
|
|
5087
5238
|
if (didSplitByPartId) {
|
|
5088
5239
|
if (assistantMessage !== null) {
|
|
5089
5240
|
const msg = assistantMessage;
|
|
5090
5241
|
streamParsers.delete(msg.id);
|
|
5091
5242
|
rawContentBuffers.delete(msg.id);
|
|
5092
|
-
seqChunkBuffers.delete(msg.id);
|
|
5093
5243
|
if (msg.streaming !== false) {
|
|
5094
5244
|
msg.streaming = false;
|
|
5095
5245
|
emitMessage(msg);
|
|
@@ -5110,8 +5260,8 @@ var AgentWidgetClient = class {
|
|
|
5110
5260
|
const parsedResult = parser.processChunk(stringContent);
|
|
5111
5261
|
if (parsedResult instanceof Promise) {
|
|
5112
5262
|
parsedResult.then((result) => {
|
|
5113
|
-
var
|
|
5114
|
-
const text = typeof result === "string" ? result : (
|
|
5263
|
+
var _a3;
|
|
5264
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
5115
5265
|
if (text !== null) {
|
|
5116
5266
|
assistant.content = text;
|
|
5117
5267
|
assistant.streaming = false;
|
|
@@ -5127,7 +5277,6 @@ var AgentWidgetClient = class {
|
|
|
5127
5277
|
}
|
|
5128
5278
|
streamParsers.delete(assistant.id);
|
|
5129
5279
|
rawContentBuffers.delete(assistant.id);
|
|
5130
|
-
seqChunkBuffers.delete(assistant.id);
|
|
5131
5280
|
const contentChanged = displayContent !== assistant.content;
|
|
5132
5281
|
const streamingChanged = assistant.streaming !== false;
|
|
5133
5282
|
if (contentChanged) {
|
|
@@ -5142,7 +5291,6 @@ var AgentWidgetClient = class {
|
|
|
5142
5291
|
const msg = assistantMessage;
|
|
5143
5292
|
streamParsers.delete(msg.id);
|
|
5144
5293
|
rawContentBuffers.delete(msg.id);
|
|
5145
|
-
seqChunkBuffers.delete(msg.id);
|
|
5146
5294
|
if (msg.streaming !== false) {
|
|
5147
5295
|
msg.streaming = false;
|
|
5148
5296
|
emitMessage(msg);
|
|
@@ -5153,11 +5301,11 @@ var AgentWidgetClient = class {
|
|
|
5153
5301
|
} else if (payloadType === "agent_start") {
|
|
5154
5302
|
agentExecution = {
|
|
5155
5303
|
executionId: payload.executionId,
|
|
5156
|
-
agentId: (
|
|
5157
|
-
agentName: (
|
|
5304
|
+
agentId: (_va = payload.agentId) != null ? _va : "virtual",
|
|
5305
|
+
agentName: (_wa = payload.agentName) != null ? _wa : "",
|
|
5158
5306
|
status: "running",
|
|
5159
5307
|
currentIteration: 0,
|
|
5160
|
-
maxTurns: (
|
|
5308
|
+
maxTurns: (_xa = payload.maxTurns) != null ? _xa : 1,
|
|
5161
5309
|
startedAt: resolveTimestamp(payload.startedAt)
|
|
5162
5310
|
};
|
|
5163
5311
|
} else if (payloadType === "agent_iteration_start") {
|
|
@@ -5177,7 +5325,7 @@ var AgentWidgetClient = class {
|
|
|
5177
5325
|
} else if (payloadType === "agent_turn_delta") {
|
|
5178
5326
|
if (payload.contentType === "text") {
|
|
5179
5327
|
const assistant = ensureAssistantMessage();
|
|
5180
|
-
assistant.content += (
|
|
5328
|
+
assistant.content += (_ya = payload.delta) != null ? _ya : "";
|
|
5181
5329
|
assistant.agentMetadata = {
|
|
5182
5330
|
executionId: payload.executionId,
|
|
5183
5331
|
iteration: payload.iteration,
|
|
@@ -5186,14 +5334,14 @@ var AgentWidgetClient = class {
|
|
|
5186
5334
|
};
|
|
5187
5335
|
emitMessage(assistant);
|
|
5188
5336
|
} else if (payload.contentType === "thinking") {
|
|
5189
|
-
const reasoningId = (
|
|
5337
|
+
const reasoningId = (_za = payload.turnId) != null ? _za : `agent-think-${payload.iteration}`;
|
|
5190
5338
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
5191
|
-
reasoningMessage.reasoning = (
|
|
5339
|
+
reasoningMessage.reasoning = (_Aa = reasoningMessage.reasoning) != null ? _Aa : {
|
|
5192
5340
|
id: reasoningId,
|
|
5193
5341
|
status: "streaming",
|
|
5194
5342
|
chunks: []
|
|
5195
5343
|
};
|
|
5196
|
-
reasoningMessage.reasoning.chunks.push((
|
|
5344
|
+
reasoningMessage.reasoning.chunks.push((_Ba = payload.delta) != null ? _Ba : "");
|
|
5197
5345
|
reasoningMessage.agentMetadata = {
|
|
5198
5346
|
executionId: payload.executionId,
|
|
5199
5347
|
iteration: payload.iteration,
|
|
@@ -5201,12 +5349,12 @@ var AgentWidgetClient = class {
|
|
|
5201
5349
|
};
|
|
5202
5350
|
emitMessage(reasoningMessage);
|
|
5203
5351
|
} else if (payload.contentType === "tool_input") {
|
|
5204
|
-
const toolId = (
|
|
5352
|
+
const toolId = (_Ca = payload.toolCallId) != null ? _Ca : toolContext.lastId;
|
|
5205
5353
|
if (toolId) {
|
|
5206
5354
|
const toolMessage = toolMessages.get(toolId);
|
|
5207
5355
|
if (toolMessage == null ? void 0 : toolMessage.toolCall) {
|
|
5208
|
-
toolMessage.toolCall.chunks = (
|
|
5209
|
-
toolMessage.toolCall.chunks.push((
|
|
5356
|
+
toolMessage.toolCall.chunks = (_Da = toolMessage.toolCall.chunks) != null ? _Da : [];
|
|
5357
|
+
toolMessage.toolCall.chunks.push((_Ea = payload.delta) != null ? _Ea : "");
|
|
5210
5358
|
emitMessage(toolMessage);
|
|
5211
5359
|
}
|
|
5212
5360
|
}
|
|
@@ -5218,20 +5366,20 @@ var AgentWidgetClient = class {
|
|
|
5218
5366
|
if (reasoningMessage == null ? void 0 : reasoningMessage.reasoning) {
|
|
5219
5367
|
reasoningMessage.reasoning.status = "complete";
|
|
5220
5368
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(payload.completedAt);
|
|
5221
|
-
const start = (
|
|
5369
|
+
const start = (_Fa = reasoningMessage.reasoning.startedAt) != null ? _Fa : Date.now();
|
|
5222
5370
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
5223
5371
|
0,
|
|
5224
|
-
((
|
|
5372
|
+
((_Ga = reasoningMessage.reasoning.completedAt) != null ? _Ga : Date.now()) - start
|
|
5225
5373
|
);
|
|
5226
5374
|
reasoningMessage.streaming = false;
|
|
5227
5375
|
emitMessage(reasoningMessage);
|
|
5228
5376
|
}
|
|
5229
5377
|
}
|
|
5230
5378
|
} else if (payloadType === "agent_tool_start") {
|
|
5231
|
-
const toolId = (
|
|
5379
|
+
const toolId = (_Ha = payload.toolCallId) != null ? _Ha : `agent-tool-${nextSequence()}`;
|
|
5232
5380
|
trackToolId(getToolCallKey(payload), toolId);
|
|
5233
5381
|
const toolMessage = ensureToolMessage(toolId);
|
|
5234
|
-
const tool = (
|
|
5382
|
+
const tool = (_Ia = toolMessage.toolCall) != null ? _Ia : {
|
|
5235
5383
|
id: toolId,
|
|
5236
5384
|
status: "pending",
|
|
5237
5385
|
name: void 0,
|
|
@@ -5243,12 +5391,12 @@ var AgentWidgetClient = class {
|
|
|
5243
5391
|
completedAt: void 0,
|
|
5244
5392
|
durationMs: void 0
|
|
5245
5393
|
};
|
|
5246
|
-
tool.name = (
|
|
5394
|
+
tool.name = (_Ka = (_Ja = payload.toolName) != null ? _Ja : payload.name) != null ? _Ka : tool.name;
|
|
5247
5395
|
tool.status = "running";
|
|
5248
5396
|
if (payload.parameters !== void 0) {
|
|
5249
5397
|
tool.args = payload.parameters;
|
|
5250
5398
|
}
|
|
5251
|
-
tool.startedAt = resolveTimestamp((
|
|
5399
|
+
tool.startedAt = resolveTimestamp((_La = payload.startedAt) != null ? _La : payload.timestamp);
|
|
5252
5400
|
toolMessage.toolCall = tool;
|
|
5253
5401
|
toolMessage.streaming = true;
|
|
5254
5402
|
toolMessage.agentMetadata = {
|
|
@@ -5257,21 +5405,21 @@ var AgentWidgetClient = class {
|
|
|
5257
5405
|
};
|
|
5258
5406
|
emitMessage(toolMessage);
|
|
5259
5407
|
} else if (payloadType === "agent_tool_delta") {
|
|
5260
|
-
const toolId = (
|
|
5408
|
+
const toolId = (_Ma = payload.toolCallId) != null ? _Ma : toolContext.lastId;
|
|
5261
5409
|
if (toolId) {
|
|
5262
|
-
const toolMessage = (
|
|
5410
|
+
const toolMessage = (_Na = toolMessages.get(toolId)) != null ? _Na : ensureToolMessage(toolId);
|
|
5263
5411
|
if (toolMessage.toolCall) {
|
|
5264
|
-
toolMessage.toolCall.chunks = (
|
|
5265
|
-
toolMessage.toolCall.chunks.push((
|
|
5412
|
+
toolMessage.toolCall.chunks = (_Oa = toolMessage.toolCall.chunks) != null ? _Oa : [];
|
|
5413
|
+
toolMessage.toolCall.chunks.push((_Pa = payload.delta) != null ? _Pa : "");
|
|
5266
5414
|
toolMessage.toolCall.status = "running";
|
|
5267
5415
|
toolMessage.streaming = true;
|
|
5268
5416
|
emitMessage(toolMessage);
|
|
5269
5417
|
}
|
|
5270
5418
|
}
|
|
5271
5419
|
} else if (payloadType === "agent_tool_complete") {
|
|
5272
|
-
const toolId = (
|
|
5420
|
+
const toolId = (_Qa = payload.toolCallId) != null ? _Qa : toolContext.lastId;
|
|
5273
5421
|
if (toolId) {
|
|
5274
|
-
const toolMessage = (
|
|
5422
|
+
const toolMessage = (_Ra = toolMessages.get(toolId)) != null ? _Ra : ensureToolMessage(toolId);
|
|
5275
5423
|
if (toolMessage.toolCall) {
|
|
5276
5424
|
toolMessage.toolCall.status = "complete";
|
|
5277
5425
|
if (payload.result !== void 0) {
|
|
@@ -5280,7 +5428,7 @@ var AgentWidgetClient = class {
|
|
|
5280
5428
|
if (typeof payload.executionTime === "number") {
|
|
5281
5429
|
toolMessage.toolCall.durationMs = payload.executionTime;
|
|
5282
5430
|
}
|
|
5283
|
-
toolMessage.toolCall.completedAt = resolveTimestamp((
|
|
5431
|
+
toolMessage.toolCall.completedAt = resolveTimestamp((_Sa = payload.completedAt) != null ? _Sa : payload.timestamp);
|
|
5284
5432
|
toolMessage.streaming = false;
|
|
5285
5433
|
emitMessage(toolMessage);
|
|
5286
5434
|
const callKey = getToolCallKey(payload);
|
|
@@ -5295,7 +5443,7 @@ var AgentWidgetClient = class {
|
|
|
5295
5443
|
const reflectionMessage = {
|
|
5296
5444
|
id: reflectionId,
|
|
5297
5445
|
role: "assistant",
|
|
5298
|
-
content: (
|
|
5446
|
+
content: (_Ta = payload.reflection) != null ? _Ta : "",
|
|
5299
5447
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5300
5448
|
streaming: false,
|
|
5301
5449
|
variant: "reasoning",
|
|
@@ -5303,7 +5451,7 @@ var AgentWidgetClient = class {
|
|
|
5303
5451
|
reasoning: {
|
|
5304
5452
|
id: reflectionId,
|
|
5305
5453
|
status: "complete",
|
|
5306
|
-
chunks: [(
|
|
5454
|
+
chunks: [(_Ua = payload.reflection) != null ? _Ua : ""]
|
|
5307
5455
|
},
|
|
5308
5456
|
agentMetadata: {
|
|
5309
5457
|
executionId: payload.executionId,
|
|
@@ -5324,7 +5472,7 @@ var AgentWidgetClient = class {
|
|
|
5324
5472
|
}
|
|
5325
5473
|
onEvent({ type: "status", status: "idle" });
|
|
5326
5474
|
} else if (payloadType === "agent_error") {
|
|
5327
|
-
const errorMessage = typeof payload.error === "string" ? payload.error : (
|
|
5475
|
+
const errorMessage = typeof payload.error === "string" ? payload.error : (_Wa = (_Va = payload.error) == null ? void 0 : _Va.message) != null ? _Wa : "Agent execution error";
|
|
5328
5476
|
if (payload.recoverable) {
|
|
5329
5477
|
if (typeof console !== "undefined") {
|
|
5330
5478
|
console.warn("[AgentWidget] Recoverable agent error:", errorMessage);
|
|
@@ -5337,7 +5485,7 @@ var AgentWidgetClient = class {
|
|
|
5337
5485
|
}
|
|
5338
5486
|
} else if (payloadType === "agent_ping") {
|
|
5339
5487
|
} else if (payloadType === "agent_approval_start") {
|
|
5340
|
-
const approvalId = (
|
|
5488
|
+
const approvalId = (_Xa = payload.approvalId) != null ? _Xa : `approval-${nextSequence()}`;
|
|
5341
5489
|
const approvalMessage = {
|
|
5342
5490
|
id: `approval-${approvalId}`,
|
|
5343
5491
|
role: "assistant",
|
|
@@ -5349,17 +5497,17 @@ var AgentWidgetClient = class {
|
|
|
5349
5497
|
approval: {
|
|
5350
5498
|
id: approvalId,
|
|
5351
5499
|
status: "pending",
|
|
5352
|
-
agentId: (
|
|
5353
|
-
executionId: (
|
|
5354
|
-
toolName: (
|
|
5500
|
+
agentId: (_Ya = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _Ya : "virtual",
|
|
5501
|
+
executionId: (__a = (_Za = payload.executionId) != null ? _Za : agentExecution == null ? void 0 : agentExecution.executionId) != null ? __a : "",
|
|
5502
|
+
toolName: (_$a = payload.toolName) != null ? _$a : "",
|
|
5355
5503
|
toolType: payload.toolType,
|
|
5356
|
-
description: (
|
|
5504
|
+
description: (_bb = payload.description) != null ? _bb : `Execute ${(_ab = payload.toolName) != null ? _ab : "tool"}`,
|
|
5357
5505
|
parameters: payload.parameters
|
|
5358
5506
|
}
|
|
5359
5507
|
};
|
|
5360
5508
|
emitMessage(approvalMessage);
|
|
5361
5509
|
} else if (payloadType === "step_await" && payload.awaitReason === "approval_required") {
|
|
5362
|
-
const approvalId = (
|
|
5510
|
+
const approvalId = (_cb = payload.approvalId) != null ? _cb : `approval-${nextSequence()}`;
|
|
5363
5511
|
const approvalMessage = {
|
|
5364
5512
|
id: `approval-${approvalId}`,
|
|
5365
5513
|
role: "assistant",
|
|
@@ -5371,11 +5519,11 @@ var AgentWidgetClient = class {
|
|
|
5371
5519
|
approval: {
|
|
5372
5520
|
id: approvalId,
|
|
5373
5521
|
status: "pending",
|
|
5374
|
-
agentId: (
|
|
5375
|
-
executionId: (
|
|
5376
|
-
toolName: (
|
|
5522
|
+
agentId: (_db = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _db : "virtual",
|
|
5523
|
+
executionId: (_fb = (_eb = payload.executionId) != null ? _eb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _fb : "",
|
|
5524
|
+
toolName: (_gb = payload.toolName) != null ? _gb : "",
|
|
5377
5525
|
toolType: payload.toolType,
|
|
5378
|
-
description: (
|
|
5526
|
+
description: (_ib = payload.description) != null ? _ib : `Execute ${(_hb = payload.toolName) != null ? _hb : "tool"}`,
|
|
5379
5527
|
parameters: payload.parameters
|
|
5380
5528
|
}
|
|
5381
5529
|
};
|
|
@@ -5394,11 +5542,11 @@ var AgentWidgetClient = class {
|
|
|
5394
5542
|
sequence: nextSequence(),
|
|
5395
5543
|
approval: {
|
|
5396
5544
|
id: approvalId,
|
|
5397
|
-
status: (
|
|
5398
|
-
agentId: (
|
|
5399
|
-
executionId: (
|
|
5400
|
-
toolName: (
|
|
5401
|
-
description: (
|
|
5545
|
+
status: (_jb = payload.decision) != null ? _jb : "approved",
|
|
5546
|
+
agentId: (_kb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _kb : "virtual",
|
|
5547
|
+
executionId: (_mb = (_lb = payload.executionId) != null ? _lb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _mb : "",
|
|
5548
|
+
toolName: (_nb = payload.toolName) != null ? _nb : "",
|
|
5549
|
+
description: (_ob = payload.description) != null ? _ob : "",
|
|
5402
5550
|
resolvedAt: Date.now()
|
|
5403
5551
|
}
|
|
5404
5552
|
};
|
|
@@ -5436,7 +5584,7 @@ var AgentWidgetClient = class {
|
|
|
5436
5584
|
}
|
|
5437
5585
|
} else if (payloadType === "artifact_delta") {
|
|
5438
5586
|
const deltaId = String(payload.id);
|
|
5439
|
-
const deltaText = typeof payload.delta === "string" ? payload.delta : String((
|
|
5587
|
+
const deltaText = typeof payload.delta === "string" ? payload.delta : String((_pb = payload.delta) != null ? _pb : "");
|
|
5440
5588
|
onEvent({
|
|
5441
5589
|
type: "artifact_delta",
|
|
5442
5590
|
id: deltaId,
|
|
@@ -5459,7 +5607,7 @@ var AgentWidgetClient = class {
|
|
|
5459
5607
|
if (refMsg) {
|
|
5460
5608
|
refMsg.streaming = false;
|
|
5461
5609
|
try {
|
|
5462
|
-
const parsed = JSON.parse((
|
|
5610
|
+
const parsed = JSON.parse((_qb = refMsg.rawContent) != null ? _qb : "{}");
|
|
5463
5611
|
if (parsed.props) {
|
|
5464
5612
|
parsed.props.status = "complete";
|
|
5465
5613
|
const acc = artifactContent.get(artCompleteId);
|
|
@@ -5480,7 +5628,7 @@ var AgentWidgetClient = class {
|
|
|
5480
5628
|
if (!m || typeof m !== "object") {
|
|
5481
5629
|
continue;
|
|
5482
5630
|
}
|
|
5483
|
-
const id = String((
|
|
5631
|
+
const id = String((_rb = m.id) != null ? _rb : `msg-${nextSequence()}`);
|
|
5484
5632
|
const roleRaw = m.role;
|
|
5485
5633
|
const role = roleRaw === "user" ? "user" : roleRaw === "system" ? "system" : "assistant";
|
|
5486
5634
|
const msg = {
|
|
@@ -5499,7 +5647,7 @@ var AgentWidgetClient = class {
|
|
|
5499
5647
|
if (msg.rawContent) {
|
|
5500
5648
|
try {
|
|
5501
5649
|
const parsed = JSON.parse(msg.rawContent);
|
|
5502
|
-
const refArtId = (
|
|
5650
|
+
const refArtId = (_sb = parsed == null ? void 0 : parsed.props) == null ? void 0 : _sb.artifactId;
|
|
5503
5651
|
if (typeof refArtId === "string") {
|
|
5504
5652
|
artifactIdsWithCards.add(refArtId);
|
|
5505
5653
|
}
|
|
@@ -5510,13 +5658,12 @@ var AgentWidgetClient = class {
|
|
|
5510
5658
|
assistantMessageRef.current = null;
|
|
5511
5659
|
streamParsers.delete(id);
|
|
5512
5660
|
rawContentBuffers.delete(id);
|
|
5513
|
-
seqChunkBuffers.delete(id);
|
|
5514
5661
|
} else if (payloadType === "error" || payloadType === "step_error" || payloadType === "dispatch_error" || payloadType === "flow_error") {
|
|
5515
5662
|
let resolvedError = null;
|
|
5516
5663
|
if (payload.error instanceof Error) {
|
|
5517
5664
|
resolvedError = payload.error;
|
|
5518
5665
|
} else if (payloadType === "dispatch_error") {
|
|
5519
|
-
const msg = (
|
|
5666
|
+
const msg = (_tb = payload.message) != null ? _tb : payload.error;
|
|
5520
5667
|
if (msg != null && msg !== "") {
|
|
5521
5668
|
resolvedError = new Error(String(msg));
|
|
5522
5669
|
}
|
|
@@ -5525,7 +5672,7 @@ var AgentWidgetClient = class {
|
|
|
5525
5672
|
if (typeof e === "string" && e !== "") {
|
|
5526
5673
|
resolvedError = new Error(e);
|
|
5527
5674
|
} else if (e != null && typeof e === "object" && "message" in e) {
|
|
5528
|
-
resolvedError = new Error(String((
|
|
5675
|
+
resolvedError = new Error(String((_ub = e.message) != null ? _ub : e));
|
|
5529
5676
|
}
|
|
5530
5677
|
} else if (payloadType === "error" && payload.error != null && payload.error !== "") {
|
|
5531
5678
|
resolvedError = new Error(String(payload.error));
|
|
@@ -5541,7 +5688,60 @@ var AgentWidgetClient = class {
|
|
|
5541
5688
|
}
|
|
5542
5689
|
}
|
|
5543
5690
|
}
|
|
5691
|
+
seqReadyQueue.length = 0;
|
|
5692
|
+
};
|
|
5693
|
+
while (true) {
|
|
5694
|
+
const { done, value } = await reader.read();
|
|
5695
|
+
if (done) break;
|
|
5696
|
+
buffer += decoder.decode(value, { stream: true });
|
|
5697
|
+
const events = buffer.split("\n\n");
|
|
5698
|
+
buffer = (_b = events.pop()) != null ? _b : "";
|
|
5699
|
+
for (const event of events) {
|
|
5700
|
+
const lines = event.split("\n");
|
|
5701
|
+
let eventType = "message";
|
|
5702
|
+
let data = "";
|
|
5703
|
+
for (const line of lines) {
|
|
5704
|
+
if (line.startsWith("event:")) {
|
|
5705
|
+
eventType = line.replace("event:", "").trim();
|
|
5706
|
+
} else if (line.startsWith("data:")) {
|
|
5707
|
+
data += line.replace("data:", "").trim();
|
|
5708
|
+
}
|
|
5709
|
+
}
|
|
5710
|
+
if (!data) continue;
|
|
5711
|
+
let payload;
|
|
5712
|
+
try {
|
|
5713
|
+
payload = JSON.parse(data);
|
|
5714
|
+
} catch (error) {
|
|
5715
|
+
onEvent({
|
|
5716
|
+
type: "error",
|
|
5717
|
+
error: error instanceof Error ? error : new Error("Failed to parse chat stream payload")
|
|
5718
|
+
});
|
|
5719
|
+
continue;
|
|
5720
|
+
}
|
|
5721
|
+
const payloadType = eventType !== "message" ? eventType : (_c = payload.type) != null ? _c : "message";
|
|
5722
|
+
(_d = this.onSSEEvent) == null ? void 0 : _d.call(this, payloadType, payload);
|
|
5723
|
+
if (this.parseSSEEvent) {
|
|
5724
|
+
assistantMessageRef.current = assistantMessage;
|
|
5725
|
+
const handled = await this.handleCustomSSEEvent(
|
|
5726
|
+
payload,
|
|
5727
|
+
onEvent,
|
|
5728
|
+
assistantMessageRef,
|
|
5729
|
+
emitMessage,
|
|
5730
|
+
nextSequence,
|
|
5731
|
+
partIdState
|
|
5732
|
+
);
|
|
5733
|
+
if (assistantMessageRef.current && assistantMessageRef.current !== assistantMessage) {
|
|
5734
|
+
assistantMessage = assistantMessageRef.current;
|
|
5735
|
+
}
|
|
5736
|
+
if (handled) continue;
|
|
5737
|
+
}
|
|
5738
|
+
seqBuffer.push(payloadType, payload);
|
|
5739
|
+
drainReadyQueue();
|
|
5740
|
+
}
|
|
5544
5741
|
}
|
|
5742
|
+
seqBuffer.flushPending();
|
|
5743
|
+
drainReadyQueue();
|
|
5744
|
+
seqBuffer.destroy();
|
|
5545
5745
|
}
|
|
5546
5746
|
};
|
|
5547
5747
|
|
|
@@ -8448,6 +8648,7 @@ var buildHeader = (context) => {
|
|
|
8448
8648
|
clearChatButton.style.color = clearChatIconColor || HEADER_THEME_CSS.actionIconColor;
|
|
8449
8649
|
const iconSvg = renderLucideIcon(clearChatIconName, "20px", "currentColor", 1);
|
|
8450
8650
|
if (iconSvg) {
|
|
8651
|
+
iconSvg.style.display = "block";
|
|
8451
8652
|
clearChatButton.appendChild(iconSvg);
|
|
8452
8653
|
}
|
|
8453
8654
|
if (clearChatBgColor) {
|
|
@@ -8531,7 +8732,7 @@ var buildHeader = (context) => {
|
|
|
8531
8732
|
}
|
|
8532
8733
|
const closeButtonWrapper = createElement(
|
|
8533
8734
|
"div",
|
|
8534
|
-
closeButtonPlacement === "top-right" ? "persona-absolute persona-top-4 persona-right-4 persona-z-50" : clearChatEnabled && clearChatPlacement === "inline" ? "" : "persona-ml-auto"
|
|
8735
|
+
closeButtonPlacement === "top-right" ? "persona-absolute persona-top-4 persona-right-4 persona-z-50" : clearChatEnabled && clearChatPlacement === "inline" ? "persona-relative persona-inline-flex persona-items-center persona-justify-center" : "persona-relative persona-ml-auto persona-inline-flex persona-items-center persona-justify-center"
|
|
8535
8736
|
);
|
|
8536
8737
|
const closeButton = createElement(
|
|
8537
8738
|
"button",
|
|
@@ -8547,8 +8748,9 @@ var buildHeader = (context) => {
|
|
|
8547
8748
|
const closeButtonIconName = (_E = launcher.closeButtonIconName) != null ? _E : "x";
|
|
8548
8749
|
const closeButtonIconText = (_F = launcher.closeButtonIconText) != null ? _F : "\xD7";
|
|
8549
8750
|
closeButton.style.color = launcher.closeButtonColor || HEADER_THEME_CSS.actionIconColor;
|
|
8550
|
-
const closeIconSvg = renderLucideIcon(closeButtonIconName, "
|
|
8751
|
+
const closeIconSvg = renderLucideIcon(closeButtonIconName, "28px", "currentColor", 1);
|
|
8551
8752
|
if (closeIconSvg) {
|
|
8753
|
+
closeIconSvg.style.display = "block";
|
|
8552
8754
|
closeButton.appendChild(closeIconSvg);
|
|
8553
8755
|
} else {
|
|
8554
8756
|
closeButton.textContent = closeButtonIconText;
|
|
@@ -9076,7 +9278,7 @@ var buildMinimalHeader = (context) => {
|
|
|
9076
9278
|
closeButton.style.display = showClose ? "" : "none";
|
|
9077
9279
|
closeButton.style.color = launcher.closeButtonColor || HEADER_THEME_CSS.actionIconColor;
|
|
9078
9280
|
const closeButtonIconName = (_i = launcher.closeButtonIconName) != null ? _i : "x";
|
|
9079
|
-
const closeIconSvg = renderLucideIcon(closeButtonIconName, "
|
|
9281
|
+
const closeIconSvg = renderLucideIcon(closeButtonIconName, "28px", "currentColor", 1);
|
|
9080
9282
|
if (closeIconSvg) {
|
|
9081
9283
|
closeButton.appendChild(closeIconSvg);
|
|
9082
9284
|
} else {
|
|
@@ -14383,17 +14585,38 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14383
14585
|
} else if (action === "upvote" || action === "downvote") {
|
|
14384
14586
|
const currentVote = (_a2 = messageVoteState.get(messageId)) != null ? _a2 : null;
|
|
14385
14587
|
const wasActive = currentVote === action;
|
|
14588
|
+
const iconName = action === "upvote" ? "thumbs-up" : "thumbs-down";
|
|
14386
14589
|
if (wasActive) {
|
|
14387
14590
|
messageVoteState.delete(messageId);
|
|
14388
14591
|
actionBtn.classList.remove("persona-message-action-active");
|
|
14592
|
+
const outlineIcon = renderLucideIcon(iconName, 14, "currentColor", 2);
|
|
14593
|
+
if (outlineIcon) {
|
|
14594
|
+
actionBtn.innerHTML = "";
|
|
14595
|
+
actionBtn.appendChild(outlineIcon);
|
|
14596
|
+
}
|
|
14389
14597
|
} else {
|
|
14390
14598
|
const oppositeAction = action === "upvote" ? "downvote" : "upvote";
|
|
14391
14599
|
const oppositeBtn = actionsContainer.querySelector(`[data-action="${oppositeAction}"]`);
|
|
14392
14600
|
if (oppositeBtn) {
|
|
14393
14601
|
oppositeBtn.classList.remove("persona-message-action-active");
|
|
14602
|
+
const oppositeIconName = oppositeAction === "upvote" ? "thumbs-up" : "thumbs-down";
|
|
14603
|
+
const outlineIcon = renderLucideIcon(oppositeIconName, 14, "currentColor", 2);
|
|
14604
|
+
if (outlineIcon) {
|
|
14605
|
+
oppositeBtn.innerHTML = "";
|
|
14606
|
+
oppositeBtn.appendChild(outlineIcon);
|
|
14607
|
+
}
|
|
14394
14608
|
}
|
|
14395
14609
|
messageVoteState.set(messageId, action);
|
|
14396
14610
|
actionBtn.classList.add("persona-message-action-active");
|
|
14611
|
+
const filledIcon = renderLucideIcon(iconName, 14, "currentColor", 2);
|
|
14612
|
+
if (filledIcon) {
|
|
14613
|
+
filledIcon.setAttribute("fill", "currentColor");
|
|
14614
|
+
actionBtn.innerHTML = "";
|
|
14615
|
+
actionBtn.appendChild(filledIcon);
|
|
14616
|
+
}
|
|
14617
|
+
actionBtn.classList.remove("persona-message-action-pop");
|
|
14618
|
+
void actionBtn.offsetWidth;
|
|
14619
|
+
actionBtn.classList.add("persona-message-action-pop");
|
|
14397
14620
|
const messages = session.getMessages();
|
|
14398
14621
|
const message = messages.find((m) => m.id === messageId);
|
|
14399
14622
|
if (message && messageActionCallbacks.onFeedback) {
|
|
@@ -17044,7 +17267,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17044
17267
|
const closeButtonIconName = (_ca = launcher.closeButtonIconName) != null ? _ca : "x";
|
|
17045
17268
|
const closeButtonIconText = (_da = launcher.closeButtonIconText) != null ? _da : "\xD7";
|
|
17046
17269
|
closeButton.innerHTML = "";
|
|
17047
|
-
const iconSvg = renderLucideIcon(closeButtonIconName, "
|
|
17270
|
+
const iconSvg = renderLucideIcon(closeButtonIconName, "28px", "currentColor", 1);
|
|
17048
17271
|
if (iconSvg) {
|
|
17049
17272
|
closeButton.appendChild(iconSvg);
|
|
17050
17273
|
} else {
|