@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.cjs
CHANGED
|
@@ -154,6 +154,12 @@ var DEFAULT_WIDGET_CONFIG = {
|
|
|
154
154
|
agentIconSize: "40px",
|
|
155
155
|
headerIconSize: "40px",
|
|
156
156
|
closeButtonSize: "32px",
|
|
157
|
+
// Zero out browser-default <button> padding so the icon gets the full
|
|
158
|
+
// 32x32 content box, matching clearChat.paddingX/Y below. Without this,
|
|
159
|
+
// UA stylesheets add ~1-2px vertical and ~6px horizontal padding that
|
|
160
|
+
// eats into the border-box width and shrinks the rendered icon.
|
|
161
|
+
closeButtonPaddingX: "0px",
|
|
162
|
+
closeButtonPaddingY: "0px",
|
|
157
163
|
callToActionIconName: "arrow-up-right",
|
|
158
164
|
callToActionIconText: "",
|
|
159
165
|
callToActionIconSize: "32px",
|
|
@@ -3562,6 +3568,94 @@ var createXmlParser = () => {
|
|
|
3562
3568
|
};
|
|
3563
3569
|
};
|
|
3564
3570
|
|
|
3571
|
+
// src/utils/sequence-buffer.ts
|
|
3572
|
+
var SequenceReorderBuffer = class {
|
|
3573
|
+
constructor(emitter, gapTimeoutMs = 50) {
|
|
3574
|
+
this.nextExpectedSeq = null;
|
|
3575
|
+
this.buffer = /* @__PURE__ */ new Map();
|
|
3576
|
+
this.flushTimer = null;
|
|
3577
|
+
this.emitter = emitter;
|
|
3578
|
+
this.gapTimeoutMs = gapTimeoutMs;
|
|
3579
|
+
}
|
|
3580
|
+
push(payloadType, payload) {
|
|
3581
|
+
var _a, _b, _c;
|
|
3582
|
+
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;
|
|
3583
|
+
if (seq === void 0 || seq === null) {
|
|
3584
|
+
if (this.buffer.size > 0) {
|
|
3585
|
+
this.flushAll();
|
|
3586
|
+
}
|
|
3587
|
+
this.emitter(payloadType, payload);
|
|
3588
|
+
return;
|
|
3589
|
+
}
|
|
3590
|
+
if (this.nextExpectedSeq === null) {
|
|
3591
|
+
this.nextExpectedSeq = 1;
|
|
3592
|
+
}
|
|
3593
|
+
if (seq === this.nextExpectedSeq) {
|
|
3594
|
+
this.emitter(payloadType, payload);
|
|
3595
|
+
this.nextExpectedSeq = seq + 1;
|
|
3596
|
+
this.drainConsecutive();
|
|
3597
|
+
return;
|
|
3598
|
+
}
|
|
3599
|
+
if (seq < this.nextExpectedSeq) {
|
|
3600
|
+
this.emitter(payloadType, payload);
|
|
3601
|
+
return;
|
|
3602
|
+
}
|
|
3603
|
+
const existing = this.buffer.get(seq);
|
|
3604
|
+
if (existing !== void 0) {
|
|
3605
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
3606
|
+
console.warn(
|
|
3607
|
+
`[persona] SequenceReorderBuffer: duplicate seq=${seq} (${existing.payloadType} vs ${payloadType}); emitting earlier event out-of-order to avoid loss`
|
|
3608
|
+
);
|
|
3609
|
+
}
|
|
3610
|
+
this.emitter(existing.payloadType, existing.payload);
|
|
3611
|
+
}
|
|
3612
|
+
this.buffer.set(seq, { payloadType, payload, seq });
|
|
3613
|
+
this.startGapTimer();
|
|
3614
|
+
}
|
|
3615
|
+
drainConsecutive() {
|
|
3616
|
+
while (this.buffer.has(this.nextExpectedSeq)) {
|
|
3617
|
+
const event = this.buffer.get(this.nextExpectedSeq);
|
|
3618
|
+
this.buffer.delete(this.nextExpectedSeq);
|
|
3619
|
+
this.emitter(event.payloadType, event.payload);
|
|
3620
|
+
this.nextExpectedSeq++;
|
|
3621
|
+
}
|
|
3622
|
+
if (this.buffer.size === 0) {
|
|
3623
|
+
this.clearGapTimer();
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3626
|
+
startGapTimer() {
|
|
3627
|
+
if (this.flushTimer !== null) return;
|
|
3628
|
+
this.flushTimer = setTimeout(() => {
|
|
3629
|
+
this.flushAll();
|
|
3630
|
+
}, this.gapTimeoutMs);
|
|
3631
|
+
}
|
|
3632
|
+
clearGapTimer() {
|
|
3633
|
+
if (this.flushTimer !== null) {
|
|
3634
|
+
clearTimeout(this.flushTimer);
|
|
3635
|
+
this.flushTimer = null;
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
flushAll() {
|
|
3639
|
+
this.clearGapTimer();
|
|
3640
|
+
if (this.buffer.size === 0) return;
|
|
3641
|
+
const sorted = [...this.buffer.entries()].sort((a, b) => a[0] - b[0]);
|
|
3642
|
+
for (const [seq, event] of sorted) {
|
|
3643
|
+
this.buffer.delete(seq);
|
|
3644
|
+
this.emitter(event.payloadType, event.payload);
|
|
3645
|
+
}
|
|
3646
|
+
if (sorted.length > 0) {
|
|
3647
|
+
this.nextExpectedSeq = sorted[sorted.length - 1][0] + 1;
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
destroy() {
|
|
3651
|
+
this.clearGapTimer();
|
|
3652
|
+
this.buffer.clear();
|
|
3653
|
+
}
|
|
3654
|
+
flushPending() {
|
|
3655
|
+
this.flushAll();
|
|
3656
|
+
}
|
|
3657
|
+
};
|
|
3658
|
+
|
|
3565
3659
|
// src/client.ts
|
|
3566
3660
|
var DEFAULT_ENDPOINT = "https://api.runtype.com/v1/dispatch";
|
|
3567
3661
|
var DEFAULT_CLIENT_API_BASE = "https://api.runtype.com";
|
|
@@ -4329,7 +4423,7 @@ var AgentWidgetClient = class {
|
|
|
4329
4423
|
}
|
|
4330
4424
|
}
|
|
4331
4425
|
async streamResponse(body, onEvent, assistantMessageId) {
|
|
4332
|
-
var _a, _b, _c, _d
|
|
4426
|
+
var _a, _b, _c, _d;
|
|
4333
4427
|
const reader = body.getReader();
|
|
4334
4428
|
const decoder = new TextDecoder();
|
|
4335
4429
|
let buffer = "";
|
|
@@ -4368,6 +4462,8 @@ var AgentWidgetClient = class {
|
|
|
4368
4462
|
let didSplitByPartId = false;
|
|
4369
4463
|
const reasoningMessages = /* @__PURE__ */ new Map();
|
|
4370
4464
|
const toolMessages = /* @__PURE__ */ new Map();
|
|
4465
|
+
const nestedStepMessages = /* @__PURE__ */ new Map();
|
|
4466
|
+
const nestedPartIdByStep = /* @__PURE__ */ new Map();
|
|
4371
4467
|
const reasoningContext = {
|
|
4372
4468
|
lastId: null,
|
|
4373
4469
|
byStep: /* @__PURE__ */ new Map()
|
|
@@ -4376,6 +4472,31 @@ var AgentWidgetClient = class {
|
|
|
4376
4472
|
lastId: null,
|
|
4377
4473
|
byCall: /* @__PURE__ */ new Map()
|
|
4378
4474
|
};
|
|
4475
|
+
const getNestedStepKey = (toolId, stepId, partId = "") => `${toolId}::${stepId}::${partId}`;
|
|
4476
|
+
const getNestedStepPrefix = (toolId, stepId) => `${toolId}::${stepId}::`;
|
|
4477
|
+
const ensureNestedStepMessage = (toolId, stepId, partId, executionId) => {
|
|
4478
|
+
const key = getNestedStepKey(toolId, stepId, partId);
|
|
4479
|
+
const existing = nestedStepMessages.get(key);
|
|
4480
|
+
if (existing) return existing;
|
|
4481
|
+
const idSuffix = partId ? `-${partId}` : "";
|
|
4482
|
+
const message = {
|
|
4483
|
+
id: `nested-${toolId}-${stepId}${idSuffix}`,
|
|
4484
|
+
role: "assistant",
|
|
4485
|
+
content: "",
|
|
4486
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4487
|
+
streaming: true,
|
|
4488
|
+
sequence: nextSequence(),
|
|
4489
|
+
...partId ? { partId } : {},
|
|
4490
|
+
agentMetadata: {
|
|
4491
|
+
executionId,
|
|
4492
|
+
parentToolId: toolId,
|
|
4493
|
+
parentStepId: stepId
|
|
4494
|
+
}
|
|
4495
|
+
};
|
|
4496
|
+
nestedStepMessages.set(key, message);
|
|
4497
|
+
emitMessage(message);
|
|
4498
|
+
return message;
|
|
4499
|
+
};
|
|
4379
4500
|
const normalizeKey = (value) => {
|
|
4380
4501
|
if (value === null || value === void 0) return null;
|
|
4381
4502
|
try {
|
|
@@ -4385,15 +4506,15 @@ var AgentWidgetClient = class {
|
|
|
4385
4506
|
}
|
|
4386
4507
|
};
|
|
4387
4508
|
const getStepKey = (payload) => {
|
|
4388
|
-
var _a2, _b2, _c2, _d2,
|
|
4509
|
+
var _a2, _b2, _c2, _d2, _e;
|
|
4389
4510
|
return normalizeKey(
|
|
4390
|
-
(
|
|
4511
|
+
(_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
|
|
4391
4512
|
);
|
|
4392
4513
|
};
|
|
4393
4514
|
const getToolCallKey = (payload) => {
|
|
4394
|
-
var _a2, _b2, _c2, _d2,
|
|
4515
|
+
var _a2, _b2, _c2, _d2, _e, _f, _g;
|
|
4395
4516
|
return normalizeKey(
|
|
4396
|
-
(
|
|
4517
|
+
(_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
|
|
4397
4518
|
);
|
|
4398
4519
|
};
|
|
4399
4520
|
const baseAssistantId = assistantMessageId;
|
|
@@ -4569,26 +4690,37 @@ var AgentWidgetClient = class {
|
|
|
4569
4690
|
};
|
|
4570
4691
|
const streamParsers = /* @__PURE__ */ new Map();
|
|
4571
4692
|
const rawContentBuffers = /* @__PURE__ */ new Map();
|
|
4572
|
-
const
|
|
4573
|
-
const
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4693
|
+
const orderedChunkBuffers = /* @__PURE__ */ new Map();
|
|
4694
|
+
const assistantMessagesByPartId = /* @__PURE__ */ new Map();
|
|
4695
|
+
let lastSealedTextSegment = null;
|
|
4696
|
+
const insertOrderedChunk = (key, seq, text) => {
|
|
4697
|
+
var _a2;
|
|
4698
|
+
let chunks = orderedChunkBuffers.get(key);
|
|
4699
|
+
if (!chunks) {
|
|
4700
|
+
chunks = [];
|
|
4701
|
+
orderedChunkBuffers.set(key, chunks);
|
|
4702
|
+
}
|
|
4703
|
+
let lo = 0;
|
|
4704
|
+
let hi = chunks.length;
|
|
4581
4705
|
while (lo < hi) {
|
|
4582
4706
|
const mid = lo + hi >>> 1;
|
|
4583
|
-
if (
|
|
4584
|
-
|
|
4707
|
+
if (chunks[mid].seq < seq) {
|
|
4708
|
+
lo = mid + 1;
|
|
4709
|
+
} else {
|
|
4710
|
+
hi = mid;
|
|
4711
|
+
}
|
|
4585
4712
|
}
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4713
|
+
if (((_a2 = chunks[lo]) == null ? void 0 : _a2.seq) === seq) {
|
|
4714
|
+
chunks[lo] = { seq, text };
|
|
4715
|
+
} else {
|
|
4716
|
+
chunks.splice(lo, 0, { seq, text });
|
|
4717
|
+
}
|
|
4718
|
+
let accumulated = "";
|
|
4719
|
+
for (let index = 0; index < chunks.length; index++) {
|
|
4720
|
+
accumulated += chunks[index].text;
|
|
4721
|
+
}
|
|
4722
|
+
return accumulated;
|
|
4723
|
+
};
|
|
4592
4724
|
const reconcileSealedAssistantWithFinalResponse = (msg, finalContent) => {
|
|
4593
4725
|
const finalString = ensureStringContent(finalContent);
|
|
4594
4726
|
const rawBuffer = rawContentBuffers.get(msg.id);
|
|
@@ -4655,82 +4787,57 @@ var AgentWidgetClient = class {
|
|
|
4655
4787
|
mergeIfBetter(bestDisplayText(parsedResult));
|
|
4656
4788
|
finalizeCleanup();
|
|
4657
4789
|
};
|
|
4790
|
+
const seqReadyQueue = [];
|
|
4791
|
+
let isDrainScheduled = false;
|
|
4792
|
+
let drainReadyQueue;
|
|
4793
|
+
const scheduleReadyQueueDrain = () => {
|
|
4794
|
+
if (isDrainScheduled) return;
|
|
4795
|
+
isDrainScheduled = true;
|
|
4796
|
+
queueMicrotask(() => {
|
|
4797
|
+
isDrainScheduled = false;
|
|
4798
|
+
drainReadyQueue();
|
|
4799
|
+
});
|
|
4800
|
+
};
|
|
4801
|
+
const seqBuffer = new SequenceReorderBuffer((payloadType, payload) => {
|
|
4802
|
+
seqReadyQueue.push({ payloadType, payload });
|
|
4803
|
+
scheduleReadyQueueDrain();
|
|
4804
|
+
});
|
|
4658
4805
|
let agentExecution = null;
|
|
4659
4806
|
const agentIterationMessages = /* @__PURE__ */ new Map();
|
|
4660
4807
|
const iterationDisplay = (_a = this.config.iterationDisplay) != null ? _a : "separate";
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
buffer = (_b = events.pop()) != null ? _b : "";
|
|
4667
|
-
for (const event of events) {
|
|
4668
|
-
const lines = event.split("\n");
|
|
4669
|
-
let eventType = "message";
|
|
4670
|
-
let data = "";
|
|
4671
|
-
for (const line of lines) {
|
|
4672
|
-
if (line.startsWith("event:")) {
|
|
4673
|
-
eventType = line.replace("event:", "").trim();
|
|
4674
|
-
} else if (line.startsWith("data:")) {
|
|
4675
|
-
data += line.replace("data:", "").trim();
|
|
4676
|
-
}
|
|
4677
|
-
}
|
|
4678
|
-
if (!data) continue;
|
|
4679
|
-
let payload;
|
|
4680
|
-
try {
|
|
4681
|
-
payload = JSON.parse(data);
|
|
4682
|
-
} catch (error) {
|
|
4683
|
-
onEvent({
|
|
4684
|
-
type: "error",
|
|
4685
|
-
error: error instanceof Error ? error : new Error("Failed to parse chat stream payload")
|
|
4686
|
-
});
|
|
4687
|
-
continue;
|
|
4688
|
-
}
|
|
4689
|
-
const payloadType = eventType !== "message" ? eventType : (_c = payload.type) != null ? _c : "message";
|
|
4690
|
-
(_d = this.onSSEEvent) == null ? void 0 : _d.call(this, payloadType, payload);
|
|
4691
|
-
if (this.parseSSEEvent) {
|
|
4692
|
-
assistantMessageRef.current = assistantMessage;
|
|
4693
|
-
const handled = await this.handleCustomSSEEvent(
|
|
4694
|
-
payload,
|
|
4695
|
-
onEvent,
|
|
4696
|
-
assistantMessageRef,
|
|
4697
|
-
emitMessage,
|
|
4698
|
-
nextSequence,
|
|
4699
|
-
partIdState
|
|
4700
|
-
);
|
|
4701
|
-
if (assistantMessageRef.current && assistantMessageRef.current !== assistantMessage) {
|
|
4702
|
-
assistantMessage = assistantMessageRef.current;
|
|
4703
|
-
}
|
|
4704
|
-
if (handled) continue;
|
|
4705
|
-
}
|
|
4808
|
+
drainReadyQueue = () => {
|
|
4809
|
+
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;
|
|
4810
|
+
for (let i = 0; i < seqReadyQueue.length; i++) {
|
|
4811
|
+
const payloadType = seqReadyQueue[i].payloadType;
|
|
4812
|
+
const payload = seqReadyQueue[i].payload;
|
|
4706
4813
|
if (payloadType === "reason_start") {
|
|
4707
|
-
const reasoningId = (
|
|
4814
|
+
const reasoningId = (_a2 = resolveReasoningId(payload, true)) != null ? _a2 : `reason-${nextSequence()}`;
|
|
4708
4815
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
4709
|
-
reasoningMessage.reasoning = (
|
|
4816
|
+
reasoningMessage.reasoning = (_b2 = reasoningMessage.reasoning) != null ? _b2 : {
|
|
4710
4817
|
id: reasoningId,
|
|
4711
4818
|
status: "streaming",
|
|
4712
4819
|
chunks: []
|
|
4713
4820
|
};
|
|
4714
|
-
reasoningMessage.reasoning.startedAt = (
|
|
4821
|
+
reasoningMessage.reasoning.startedAt = (_d2 = reasoningMessage.reasoning.startedAt) != null ? _d2 : resolveTimestamp((_c2 = payload.startedAt) != null ? _c2 : payload.timestamp);
|
|
4715
4822
|
reasoningMessage.reasoning.completedAt = void 0;
|
|
4716
4823
|
reasoningMessage.reasoning.durationMs = void 0;
|
|
4717
4824
|
reasoningMessage.streaming = true;
|
|
4718
4825
|
reasoningMessage.reasoning.status = "streaming";
|
|
4719
4826
|
emitMessage(reasoningMessage);
|
|
4720
4827
|
} else if (payloadType === "reason_delta" || payloadType === "reason_chunk") {
|
|
4721
|
-
const reasoningId = (
|
|
4828
|
+
const reasoningId = (_f = (_e = resolveReasoningId(payload, false)) != null ? _e : resolveReasoningId(payload, true)) != null ? _f : `reason-${nextSequence()}`;
|
|
4722
4829
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
4723
|
-
reasoningMessage.reasoning = (
|
|
4830
|
+
reasoningMessage.reasoning = (_g = reasoningMessage.reasoning) != null ? _g : {
|
|
4724
4831
|
id: reasoningId,
|
|
4725
4832
|
status: "streaming",
|
|
4726
4833
|
chunks: []
|
|
4727
4834
|
};
|
|
4728
|
-
reasoningMessage.reasoning.startedAt = (
|
|
4729
|
-
const chunk = (
|
|
4835
|
+
reasoningMessage.reasoning.startedAt = (_i = reasoningMessage.reasoning.startedAt) != null ? _i : resolveTimestamp((_h = payload.startedAt) != null ? _h : payload.timestamp);
|
|
4836
|
+
const chunk = (_l = (_k = (_j = payload.reasoningText) != null ? _j : payload.text) != null ? _k : payload.delta) != null ? _l : "";
|
|
4730
4837
|
if (chunk && payload.hidden !== true) {
|
|
4731
4838
|
const reasonSeq = typeof payload.sequenceIndex === "number" ? payload.sequenceIndex : void 0;
|
|
4732
4839
|
if (reasonSeq !== void 0) {
|
|
4733
|
-
const ordered =
|
|
4840
|
+
const ordered = insertOrderedChunk(reasoningId, reasonSeq, String(chunk));
|
|
4734
4841
|
reasoningMessage.reasoning.chunks = [ordered];
|
|
4735
4842
|
} else {
|
|
4736
4843
|
reasoningMessage.reasoning.chunks.push(String(chunk));
|
|
@@ -4739,32 +4846,30 @@ var AgentWidgetClient = class {
|
|
|
4739
4846
|
reasoningMessage.reasoning.status = payload.done ? "complete" : "streaming";
|
|
4740
4847
|
if (payload.done) {
|
|
4741
4848
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(
|
|
4742
|
-
(
|
|
4849
|
+
(_m = payload.completedAt) != null ? _m : payload.timestamp
|
|
4743
4850
|
);
|
|
4744
|
-
const start = (
|
|
4851
|
+
const start = (_n = reasoningMessage.reasoning.startedAt) != null ? _n : Date.now();
|
|
4745
4852
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
4746
4853
|
0,
|
|
4747
|
-
((
|
|
4854
|
+
((_o = reasoningMessage.reasoning.completedAt) != null ? _o : Date.now()) - start
|
|
4748
4855
|
);
|
|
4749
|
-
reasonSeqBuffers.delete(reasoningId);
|
|
4750
4856
|
}
|
|
4751
4857
|
reasoningMessage.streaming = reasoningMessage.reasoning.status !== "complete";
|
|
4752
4858
|
emitMessage(reasoningMessage);
|
|
4753
4859
|
} else if (payloadType === "reason_complete") {
|
|
4754
|
-
const reasoningId = (
|
|
4860
|
+
const reasoningId = (_q = (_p = resolveReasoningId(payload, false)) != null ? _p : resolveReasoningId(payload, true)) != null ? _q : `reason-${nextSequence()}`;
|
|
4755
4861
|
const reasoningMessage = reasoningMessages.get(reasoningId);
|
|
4756
4862
|
if (reasoningMessage == null ? void 0 : reasoningMessage.reasoning) {
|
|
4757
4863
|
reasoningMessage.reasoning.status = "complete";
|
|
4758
4864
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(
|
|
4759
|
-
(
|
|
4865
|
+
(_r = payload.completedAt) != null ? _r : payload.timestamp
|
|
4760
4866
|
);
|
|
4761
|
-
const start = (
|
|
4867
|
+
const start = (_s = reasoningMessage.reasoning.startedAt) != null ? _s : Date.now();
|
|
4762
4868
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
4763
4869
|
0,
|
|
4764
|
-
((
|
|
4870
|
+
((_t = reasoningMessage.reasoning.completedAt) != null ? _t : Date.now()) - start
|
|
4765
4871
|
);
|
|
4766
4872
|
reasoningMessage.streaming = false;
|
|
4767
|
-
reasonSeqBuffers.delete(reasoningId);
|
|
4768
4873
|
emitMessage(reasoningMessage);
|
|
4769
4874
|
}
|
|
4770
4875
|
const stepKey = getStepKey(payload);
|
|
@@ -4772,14 +4877,14 @@ var AgentWidgetClient = class {
|
|
|
4772
4877
|
reasoningContext.byStep.delete(stepKey);
|
|
4773
4878
|
}
|
|
4774
4879
|
} else if (payloadType === "tool_start") {
|
|
4775
|
-
const toolId = (
|
|
4776
|
-
const toolName = (
|
|
4880
|
+
const toolId = (_u = resolveToolId(payload, true)) != null ? _u : `tool-${nextSequence()}`;
|
|
4881
|
+
const toolName = (_v = payload.toolName) != null ? _v : payload.name;
|
|
4777
4882
|
if (isArtifactEmitToolName(toolName)) {
|
|
4778
4883
|
artifactToolCallIds.add(toolId);
|
|
4779
4884
|
continue;
|
|
4780
4885
|
}
|
|
4781
4886
|
const toolMessage = ensureToolMessage(toolId);
|
|
4782
|
-
const tool = (
|
|
4887
|
+
const tool = (_w = toolMessage.toolCall) != null ? _w : {
|
|
4783
4888
|
id: toolId,
|
|
4784
4889
|
status: "pending"
|
|
4785
4890
|
};
|
|
@@ -4790,7 +4895,7 @@ var AgentWidgetClient = class {
|
|
|
4790
4895
|
} else if (payload.parameters !== void 0) {
|
|
4791
4896
|
tool.args = payload.parameters;
|
|
4792
4897
|
}
|
|
4793
|
-
tool.startedAt = (
|
|
4898
|
+
tool.startedAt = (_y = tool.startedAt) != null ? _y : resolveTimestamp((_x = payload.startedAt) != null ? _x : payload.timestamp);
|
|
4794
4899
|
tool.completedAt = void 0;
|
|
4795
4900
|
tool.durationMs = void 0;
|
|
4796
4901
|
toolMessage.toolCall = tool;
|
|
@@ -4798,23 +4903,23 @@ var AgentWidgetClient = class {
|
|
|
4798
4903
|
const agentCtx = payload.agentContext;
|
|
4799
4904
|
if (agentCtx || payload.executionId) {
|
|
4800
4905
|
toolMessage.agentMetadata = {
|
|
4801
|
-
executionId: (
|
|
4802
|
-
iteration: (
|
|
4906
|
+
executionId: (_z = agentCtx == null ? void 0 : agentCtx.executionId) != null ? _z : payload.executionId,
|
|
4907
|
+
iteration: (_A = agentCtx == null ? void 0 : agentCtx.iteration) != null ? _A : payload.iteration
|
|
4803
4908
|
};
|
|
4804
4909
|
}
|
|
4805
4910
|
emitMessage(toolMessage);
|
|
4806
4911
|
} else if (payloadType === "tool_chunk" || payloadType === "tool_delta") {
|
|
4807
|
-
const toolId = (
|
|
4912
|
+
const toolId = (_C = (_B = resolveToolId(payload, false)) != null ? _B : resolveToolId(payload, true)) != null ? _C : `tool-${nextSequence()}`;
|
|
4808
4913
|
if (artifactToolCallIds.has(toolId)) continue;
|
|
4809
4914
|
const toolMessage = ensureToolMessage(toolId);
|
|
4810
|
-
const tool = (
|
|
4915
|
+
const tool = (_D = toolMessage.toolCall) != null ? _D : {
|
|
4811
4916
|
id: toolId,
|
|
4812
4917
|
status: "running"
|
|
4813
4918
|
};
|
|
4814
|
-
tool.startedAt = (
|
|
4815
|
-
const chunkText = (
|
|
4919
|
+
tool.startedAt = (_F = tool.startedAt) != null ? _F : resolveTimestamp((_E = payload.startedAt) != null ? _E : payload.timestamp);
|
|
4920
|
+
const chunkText = (_I = (_H = (_G = payload.text) != null ? _G : payload.delta) != null ? _H : payload.message) != null ? _I : "";
|
|
4816
4921
|
if (chunkText) {
|
|
4817
|
-
tool.chunks = (
|
|
4922
|
+
tool.chunks = (_J = tool.chunks) != null ? _J : [];
|
|
4818
4923
|
tool.chunks.push(String(chunkText));
|
|
4819
4924
|
}
|
|
4820
4925
|
tool.status = "running";
|
|
@@ -4822,20 +4927,20 @@ var AgentWidgetClient = class {
|
|
|
4822
4927
|
toolMessage.streaming = true;
|
|
4823
4928
|
const agentCtxChunk = payload.agentContext;
|
|
4824
4929
|
if (agentCtxChunk || payload.executionId) {
|
|
4825
|
-
toolMessage.agentMetadata = (
|
|
4826
|
-
executionId: (
|
|
4827
|
-
iteration: (
|
|
4930
|
+
toolMessage.agentMetadata = (_M = toolMessage.agentMetadata) != null ? _M : {
|
|
4931
|
+
executionId: (_K = agentCtxChunk == null ? void 0 : agentCtxChunk.executionId) != null ? _K : payload.executionId,
|
|
4932
|
+
iteration: (_L = agentCtxChunk == null ? void 0 : agentCtxChunk.iteration) != null ? _L : payload.iteration
|
|
4828
4933
|
};
|
|
4829
4934
|
}
|
|
4830
4935
|
emitMessage(toolMessage);
|
|
4831
4936
|
} else if (payloadType === "tool_complete") {
|
|
4832
|
-
const toolId = (
|
|
4937
|
+
const toolId = (_O = (_N = resolveToolId(payload, false)) != null ? _N : resolveToolId(payload, true)) != null ? _O : `tool-${nextSequence()}`;
|
|
4833
4938
|
if (artifactToolCallIds.has(toolId)) {
|
|
4834
4939
|
artifactToolCallIds.delete(toolId);
|
|
4835
4940
|
continue;
|
|
4836
4941
|
}
|
|
4837
4942
|
const toolMessage = ensureToolMessage(toolId);
|
|
4838
|
-
const tool = (
|
|
4943
|
+
const tool = (_P = toolMessage.toolCall) != null ? _P : {
|
|
4839
4944
|
id: toolId,
|
|
4840
4945
|
status: "running"
|
|
4841
4946
|
};
|
|
@@ -4847,25 +4952,25 @@ var AgentWidgetClient = class {
|
|
|
4847
4952
|
tool.duration = payload.duration;
|
|
4848
4953
|
}
|
|
4849
4954
|
tool.completedAt = resolveTimestamp(
|
|
4850
|
-
(
|
|
4955
|
+
(_Q = payload.completedAt) != null ? _Q : payload.timestamp
|
|
4851
4956
|
);
|
|
4852
|
-
const durationValue = (
|
|
4957
|
+
const durationValue = (_R = payload.duration) != null ? _R : payload.executionTime;
|
|
4853
4958
|
if (typeof durationValue === "number") {
|
|
4854
4959
|
tool.durationMs = durationValue;
|
|
4855
4960
|
} else {
|
|
4856
|
-
const start = (
|
|
4961
|
+
const start = (_S = tool.startedAt) != null ? _S : Date.now();
|
|
4857
4962
|
tool.durationMs = Math.max(
|
|
4858
4963
|
0,
|
|
4859
|
-
((
|
|
4964
|
+
((_T = tool.completedAt) != null ? _T : Date.now()) - start
|
|
4860
4965
|
);
|
|
4861
4966
|
}
|
|
4862
4967
|
toolMessage.toolCall = tool;
|
|
4863
4968
|
toolMessage.streaming = false;
|
|
4864
4969
|
const agentCtxComplete = payload.agentContext;
|
|
4865
4970
|
if (agentCtxComplete || payload.executionId) {
|
|
4866
|
-
toolMessage.agentMetadata = (
|
|
4867
|
-
executionId: (
|
|
4868
|
-
iteration: (
|
|
4971
|
+
toolMessage.agentMetadata = (_W = toolMessage.agentMetadata) != null ? _W : {
|
|
4972
|
+
executionId: (_U = agentCtxComplete == null ? void 0 : agentCtxComplete.executionId) != null ? _U : payload.executionId,
|
|
4973
|
+
iteration: (_V = agentCtxComplete == null ? void 0 : agentCtxComplete.iteration) != null ? _V : payload.iteration
|
|
4869
4974
|
};
|
|
4870
4975
|
}
|
|
4871
4976
|
emitMessage(toolMessage);
|
|
@@ -4874,6 +4979,9 @@ var AgentWidgetClient = class {
|
|
|
4874
4979
|
toolContext.byCall.delete(callKey);
|
|
4875
4980
|
}
|
|
4876
4981
|
} else if (payloadType === "text_start") {
|
|
4982
|
+
if ((_X = payload.toolContext) == null ? void 0 : _X.toolId) {
|
|
4983
|
+
continue;
|
|
4984
|
+
}
|
|
4877
4985
|
const incomingPartId = payload.partId;
|
|
4878
4986
|
if (incomingPartId !== void 0 && partIdState.current !== null && incomingPartId !== partIdState.current) {
|
|
4879
4987
|
const prev = assistantMessage;
|
|
@@ -4889,6 +4997,9 @@ var AgentWidgetClient = class {
|
|
|
4889
4997
|
partIdState.current = incomingPartId;
|
|
4890
4998
|
}
|
|
4891
4999
|
} else if (payloadType === "text_end") {
|
|
5000
|
+
if ((_Y = payload.toolContext) == null ? void 0 : _Y.toolId) {
|
|
5001
|
+
continue;
|
|
5002
|
+
}
|
|
4892
5003
|
const prev = assistantMessage;
|
|
4893
5004
|
if (prev) {
|
|
4894
5005
|
prev.streaming = false;
|
|
@@ -4903,6 +5014,48 @@ var AgentWidgetClient = class {
|
|
|
4903
5014
|
if (stepType === "tool" || executionType === "context") {
|
|
4904
5015
|
continue;
|
|
4905
5016
|
}
|
|
5017
|
+
const nestedToolCtx = payload.toolContext;
|
|
5018
|
+
if (nestedToolCtx == null ? void 0 : nestedToolCtx.toolId) {
|
|
5019
|
+
const nestedStepId = String(
|
|
5020
|
+
(__ = (_Z = payload.id) != null ? _Z : nestedToolCtx.stepId) != null ? __ : `step-${nextSequence()}`
|
|
5021
|
+
);
|
|
5022
|
+
const incomingPartId2 = payload.partId !== void 0 && payload.partId !== null ? String(payload.partId) : "";
|
|
5023
|
+
const stepScopeKey = `${nestedToolCtx.toolId}::${nestedStepId}`;
|
|
5024
|
+
const prevPartId = nestedPartIdByStep.get(stepScopeKey);
|
|
5025
|
+
if (incomingPartId2 !== "" && prevPartId !== void 0 && prevPartId !== "" && prevPartId !== incomingPartId2) {
|
|
5026
|
+
const prev = nestedStepMessages.get(
|
|
5027
|
+
getNestedStepKey(
|
|
5028
|
+
nestedToolCtx.toolId,
|
|
5029
|
+
nestedStepId,
|
|
5030
|
+
prevPartId
|
|
5031
|
+
)
|
|
5032
|
+
);
|
|
5033
|
+
if (prev && prev.streaming !== false) {
|
|
5034
|
+
prev.streaming = false;
|
|
5035
|
+
emitMessage(prev);
|
|
5036
|
+
}
|
|
5037
|
+
}
|
|
5038
|
+
if (incomingPartId2 !== "") {
|
|
5039
|
+
nestedPartIdByStep.set(stepScopeKey, incomingPartId2);
|
|
5040
|
+
}
|
|
5041
|
+
const nestedMsg = ensureNestedStepMessage(
|
|
5042
|
+
nestedToolCtx.toolId,
|
|
5043
|
+
nestedStepId,
|
|
5044
|
+
incomingPartId2,
|
|
5045
|
+
nestedToolCtx.executionId
|
|
5046
|
+
);
|
|
5047
|
+
const nestedChunk = (_ca = (_ba = (_aa = (_$ = payload.text) != null ? _$ : payload.delta) != null ? _aa : payload.content) != null ? _ba : payload.chunk) != null ? _ca : "";
|
|
5048
|
+
if (nestedChunk) {
|
|
5049
|
+
nestedMsg.content += String(nestedChunk);
|
|
5050
|
+
nestedMsg.streaming = true;
|
|
5051
|
+
emitMessage(nestedMsg);
|
|
5052
|
+
}
|
|
5053
|
+
if (payload.isComplete) {
|
|
5054
|
+
nestedMsg.streaming = false;
|
|
5055
|
+
emitMessage(nestedMsg);
|
|
5056
|
+
}
|
|
5057
|
+
continue;
|
|
5058
|
+
}
|
|
4906
5059
|
const incomingPartId = payload.partId;
|
|
4907
5060
|
if (incomingPartId !== void 0 && partIdState.current !== null && incomingPartId !== partIdState.current) {
|
|
4908
5061
|
const prev = assistantMessage;
|
|
@@ -4917,20 +5070,18 @@ var AgentWidgetClient = class {
|
|
|
4917
5070
|
if (incomingPartId !== void 0) {
|
|
4918
5071
|
partIdState.current = incomingPartId;
|
|
4919
5072
|
}
|
|
4920
|
-
const assistant = ensureAssistantMessage();
|
|
4921
|
-
if (incomingPartId !== void 0
|
|
4922
|
-
assistant.partId
|
|
5073
|
+
const assistant = incomingPartId !== void 0 ? (_da = assistantMessagesByPartId.get(incomingPartId)) != null ? _da : ensureAssistantMessage() : ensureAssistantMessage();
|
|
5074
|
+
if (incomingPartId !== void 0) {
|
|
5075
|
+
if (!assistant.partId) {
|
|
5076
|
+
assistant.partId = incomingPartId;
|
|
5077
|
+
}
|
|
5078
|
+
assistantMessagesByPartId.set(incomingPartId, assistant);
|
|
4923
5079
|
}
|
|
4924
|
-
const chunk = (
|
|
5080
|
+
const chunk = (_ha = (_ga = (_fa = (_ea = payload.text) != null ? _ea : payload.delta) != null ? _fa : payload.content) != null ? _ga : payload.chunk) != null ? _ha : "";
|
|
4925
5081
|
if (chunk) {
|
|
4926
5082
|
const chunkSeq = typeof payload.seq === "number" ? payload.seq : void 0;
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
accumulatedRaw = insertSeqChunk(seqChunkBuffers, assistant.id, chunkSeq, chunk);
|
|
4930
|
-
} else {
|
|
4931
|
-
const rawBuffer = (_da = rawContentBuffers.get(assistant.id)) != null ? _da : "";
|
|
4932
|
-
accumulatedRaw = rawBuffer + chunk;
|
|
4933
|
-
}
|
|
5083
|
+
const chunkBufferKey = incomingPartId != null ? incomingPartId : assistant.id;
|
|
5084
|
+
const accumulatedRaw = chunkSeq !== void 0 ? insertOrderedChunk(chunkBufferKey, chunkSeq, String(chunk)) : ((_ia = rawContentBuffers.get(assistant.id)) != null ? _ia : "") + chunk;
|
|
4934
5085
|
assistant.rawContent = accumulatedRaw;
|
|
4935
5086
|
if (!streamParsers.has(assistant.id)) {
|
|
4936
5087
|
streamParsers.set(assistant.id, this.createStreamParser());
|
|
@@ -4942,11 +5093,7 @@ var AgentWidgetClient = class {
|
|
|
4942
5093
|
}
|
|
4943
5094
|
const isPlainTextParser = parser.__isPlainTextParser === true;
|
|
4944
5095
|
if (isPlainTextParser) {
|
|
4945
|
-
|
|
4946
|
-
assistant.content = accumulatedRaw;
|
|
4947
|
-
} else {
|
|
4948
|
-
assistant.content += chunk;
|
|
4949
|
-
}
|
|
5096
|
+
assistant.content = chunkSeq !== void 0 ? accumulatedRaw : assistant.content + chunk;
|
|
4950
5097
|
rawContentBuffers.delete(assistant.id);
|
|
4951
5098
|
streamParsers.delete(assistant.id);
|
|
4952
5099
|
assistant.rawContent = void 0;
|
|
@@ -4956,47 +5103,36 @@ var AgentWidgetClient = class {
|
|
|
4956
5103
|
const parsedResult = parser.processChunk(accumulatedRaw);
|
|
4957
5104
|
if (parsedResult instanceof Promise) {
|
|
4958
5105
|
parsedResult.then((result) => {
|
|
4959
|
-
var
|
|
4960
|
-
const text = typeof result === "string" ? result : (
|
|
5106
|
+
var _a3;
|
|
5107
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
4961
5108
|
if (text !== null && text.trim() !== "") {
|
|
4962
5109
|
assistant.content = text;
|
|
4963
5110
|
emitMessage(assistant);
|
|
4964
5111
|
} else if (!looksLikeJson && !accumulatedRaw.trim().startsWith("<")) {
|
|
4965
5112
|
const currentAssistant = assistantMessage;
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
streamParsers.delete(currentAssistant.id);
|
|
4974
|
-
currentAssistant.rawContent = void 0;
|
|
4975
|
-
emitMessage(currentAssistant);
|
|
5113
|
+
const targetAssistant = currentAssistant && currentAssistant.id === assistant.id ? currentAssistant : assistant;
|
|
5114
|
+
if (targetAssistant.id === assistant.id) {
|
|
5115
|
+
targetAssistant.content = chunkSeq !== void 0 ? accumulatedRaw : targetAssistant.content + chunk;
|
|
5116
|
+
rawContentBuffers.delete(targetAssistant.id);
|
|
5117
|
+
streamParsers.delete(targetAssistant.id);
|
|
5118
|
+
targetAssistant.rawContent = void 0;
|
|
5119
|
+
emitMessage(targetAssistant);
|
|
4976
5120
|
}
|
|
4977
5121
|
}
|
|
4978
5122
|
}).catch(() => {
|
|
4979
|
-
|
|
4980
|
-
assistant.content = accumulatedRaw;
|
|
4981
|
-
} else {
|
|
4982
|
-
assistant.content += chunk;
|
|
4983
|
-
}
|
|
5123
|
+
assistant.content = chunkSeq !== void 0 ? accumulatedRaw : assistant.content + chunk;
|
|
4984
5124
|
rawContentBuffers.delete(assistant.id);
|
|
4985
5125
|
streamParsers.delete(assistant.id);
|
|
4986
5126
|
assistant.rawContent = void 0;
|
|
4987
5127
|
emitMessage(assistant);
|
|
4988
5128
|
});
|
|
4989
5129
|
} else {
|
|
4990
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5130
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_ja = parsedResult == null ? void 0 : parsedResult.text) != null ? _ja : null;
|
|
4991
5131
|
if (text !== null && text.trim() !== "") {
|
|
4992
5132
|
assistant.content = text;
|
|
4993
5133
|
emitMessage(assistant);
|
|
4994
5134
|
} else if (!looksLikeJson && !accumulatedRaw.trim().startsWith("<")) {
|
|
4995
|
-
|
|
4996
|
-
assistant.content = accumulatedRaw;
|
|
4997
|
-
} else {
|
|
4998
|
-
assistant.content += chunk;
|
|
4999
|
-
}
|
|
5135
|
+
assistant.content = chunkSeq !== void 0 ? accumulatedRaw : assistant.content + chunk;
|
|
5000
5136
|
rawContentBuffers.delete(assistant.id);
|
|
5001
5137
|
streamParsers.delete(assistant.id);
|
|
5002
5138
|
assistant.rawContent = void 0;
|
|
@@ -5005,7 +5141,7 @@ var AgentWidgetClient = class {
|
|
|
5005
5141
|
}
|
|
5006
5142
|
}
|
|
5007
5143
|
if (payload.isComplete) {
|
|
5008
|
-
const finalContent = (
|
|
5144
|
+
const finalContent = (_la = (_ka = payload.result) == null ? void 0 : _ka.response) != null ? _la : assistant.content;
|
|
5009
5145
|
if (finalContent) {
|
|
5010
5146
|
const rawBuffer = rawContentBuffers.get(assistant.id);
|
|
5011
5147
|
const contentToProcess = rawBuffer != null ? rawBuffer : ensureStringContent(finalContent);
|
|
@@ -5023,8 +5159,8 @@ var AgentWidgetClient = class {
|
|
|
5023
5159
|
if (parsedResult instanceof Promise) {
|
|
5024
5160
|
asyncPending = true;
|
|
5025
5161
|
parsedResult.then((result) => {
|
|
5026
|
-
var
|
|
5027
|
-
const text = typeof result === "string" ? result : (
|
|
5162
|
+
var _a3;
|
|
5163
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
5028
5164
|
if (text !== null) {
|
|
5029
5165
|
const currentAssistant = assistantMessage;
|
|
5030
5166
|
if (currentAssistant && currentAssistant.id === assistant.id) {
|
|
@@ -5032,13 +5168,12 @@ var AgentWidgetClient = class {
|
|
|
5032
5168
|
currentAssistant.streaming = false;
|
|
5033
5169
|
streamParsers.delete(currentAssistant.id);
|
|
5034
5170
|
rawContentBuffers.delete(currentAssistant.id);
|
|
5035
|
-
seqChunkBuffers.delete(currentAssistant.id);
|
|
5036
5171
|
emitMessage(currentAssistant);
|
|
5037
5172
|
}
|
|
5038
5173
|
}
|
|
5039
5174
|
});
|
|
5040
5175
|
} else {
|
|
5041
|
-
extractedText = typeof parsedResult === "string" ? parsedResult : (
|
|
5176
|
+
extractedText = typeof parsedResult === "string" ? parsedResult : (_ma = parsedResult == null ? void 0 : parsedResult.text) != null ? _ma : null;
|
|
5042
5177
|
}
|
|
5043
5178
|
}
|
|
5044
5179
|
}
|
|
@@ -5050,7 +5185,7 @@ var AgentWidgetClient = class {
|
|
|
5050
5185
|
}
|
|
5051
5186
|
const parserToClose = streamParsers.get(assistant.id);
|
|
5052
5187
|
if (parserToClose) {
|
|
5053
|
-
const closeResult = (
|
|
5188
|
+
const closeResult = (_na = parserToClose.close) == null ? void 0 : _na.call(parserToClose);
|
|
5054
5189
|
if (closeResult instanceof Promise) {
|
|
5055
5190
|
closeResult.catch(() => {
|
|
5056
5191
|
});
|
|
@@ -5058,7 +5193,6 @@ var AgentWidgetClient = class {
|
|
|
5058
5193
|
streamParsers.delete(assistant.id);
|
|
5059
5194
|
}
|
|
5060
5195
|
rawContentBuffers.delete(assistant.id);
|
|
5061
|
-
seqChunkBuffers.delete(assistant.id);
|
|
5062
5196
|
assistant.streaming = false;
|
|
5063
5197
|
emitMessage(assistant);
|
|
5064
5198
|
}
|
|
@@ -5070,18 +5204,39 @@ var AgentWidgetClient = class {
|
|
|
5070
5204
|
if (stepType === "tool" || executionType === "context") {
|
|
5071
5205
|
continue;
|
|
5072
5206
|
}
|
|
5207
|
+
const nestedCompleteCtx = payload.toolContext;
|
|
5208
|
+
if (nestedCompleteCtx == null ? void 0 : nestedCompleteCtx.toolId) {
|
|
5209
|
+
const nestedStepId = String(
|
|
5210
|
+
(_pa = (_oa = payload.id) != null ? _oa : nestedCompleteCtx.stepId) != null ? _pa : ""
|
|
5211
|
+
);
|
|
5212
|
+
if (nestedStepId) {
|
|
5213
|
+
const prefix = getNestedStepPrefix(
|
|
5214
|
+
nestedCompleteCtx.toolId,
|
|
5215
|
+
nestedStepId
|
|
5216
|
+
);
|
|
5217
|
+
for (const [key, msg] of nestedStepMessages) {
|
|
5218
|
+
if (key.startsWith(prefix) && msg.streaming !== false) {
|
|
5219
|
+
msg.streaming = false;
|
|
5220
|
+
emitMessage(msg);
|
|
5221
|
+
}
|
|
5222
|
+
}
|
|
5223
|
+
nestedPartIdByStep.delete(
|
|
5224
|
+
`${nestedCompleteCtx.toolId}::${nestedStepId}`
|
|
5225
|
+
);
|
|
5226
|
+
}
|
|
5227
|
+
continue;
|
|
5228
|
+
}
|
|
5073
5229
|
if (didSplitByPartId) {
|
|
5074
5230
|
if (assistantMessage !== null) {
|
|
5075
5231
|
const msg = assistantMessage;
|
|
5076
5232
|
streamParsers.delete(msg.id);
|
|
5077
5233
|
rawContentBuffers.delete(msg.id);
|
|
5078
|
-
seqChunkBuffers.delete(msg.id);
|
|
5079
5234
|
if (msg.streaming !== false) {
|
|
5080
5235
|
msg.streaming = false;
|
|
5081
5236
|
emitMessage(msg);
|
|
5082
5237
|
}
|
|
5083
5238
|
}
|
|
5084
|
-
const splitFinalContent = (
|
|
5239
|
+
const splitFinalContent = (_qa = payload.result) == null ? void 0 : _qa.response;
|
|
5085
5240
|
const sealedForReconcile = lastSealedTextSegment;
|
|
5086
5241
|
if (sealedForReconcile) {
|
|
5087
5242
|
if (splitFinalContent !== void 0 && splitFinalContent !== null) {
|
|
@@ -5094,7 +5249,7 @@ var AgentWidgetClient = class {
|
|
|
5094
5249
|
lastSealedTextSegment = null;
|
|
5095
5250
|
continue;
|
|
5096
5251
|
}
|
|
5097
|
-
const finalContent = (
|
|
5252
|
+
const finalContent = (_ra = payload.result) == null ? void 0 : _ra.response;
|
|
5098
5253
|
const assistant = ensureAssistantMessage();
|
|
5099
5254
|
if (finalContent !== void 0 && finalContent !== null) {
|
|
5100
5255
|
const parser = streamParsers.get(assistant.id);
|
|
@@ -5118,8 +5273,8 @@ var AgentWidgetClient = class {
|
|
|
5118
5273
|
if (parsedResult instanceof Promise) {
|
|
5119
5274
|
asyncPending = true;
|
|
5120
5275
|
parsedResult.then((result) => {
|
|
5121
|
-
var
|
|
5122
|
-
const text = typeof result === "string" ? result : (
|
|
5276
|
+
var _a3;
|
|
5277
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
5123
5278
|
if (text !== null && text.trim() !== "") {
|
|
5124
5279
|
const currentAssistant = assistantMessage;
|
|
5125
5280
|
if (currentAssistant && currentAssistant.id === assistant.id) {
|
|
@@ -5127,7 +5282,6 @@ var AgentWidgetClient = class {
|
|
|
5127
5282
|
currentAssistant.streaming = false;
|
|
5128
5283
|
streamParsers.delete(currentAssistant.id);
|
|
5129
5284
|
rawContentBuffers.delete(currentAssistant.id);
|
|
5130
|
-
seqChunkBuffers.delete(currentAssistant.id);
|
|
5131
5285
|
emitMessage(currentAssistant);
|
|
5132
5286
|
}
|
|
5133
5287
|
} else {
|
|
@@ -5142,13 +5296,12 @@ var AgentWidgetClient = class {
|
|
|
5142
5296
|
currentAssistant.streaming = false;
|
|
5143
5297
|
streamParsers.delete(currentAssistant.id);
|
|
5144
5298
|
rawContentBuffers.delete(currentAssistant.id);
|
|
5145
|
-
seqChunkBuffers.delete(currentAssistant.id);
|
|
5146
5299
|
emitMessage(currentAssistant);
|
|
5147
5300
|
}
|
|
5148
5301
|
}
|
|
5149
5302
|
});
|
|
5150
5303
|
} else {
|
|
5151
|
-
const text = typeof parsedResult === "string" ? parsedResult : (
|
|
5304
|
+
const text = typeof parsedResult === "string" ? parsedResult : (_sa = parsedResult == null ? void 0 : parsedResult.text) != null ? _sa : null;
|
|
5152
5305
|
if (text !== null && text.trim() !== "") {
|
|
5153
5306
|
assistant.content = text;
|
|
5154
5307
|
hasExtractedText = true;
|
|
@@ -5172,7 +5325,7 @@ var AgentWidgetClient = class {
|
|
|
5172
5325
|
assistant.content = ensureStringContent(finalContent);
|
|
5173
5326
|
}
|
|
5174
5327
|
if (parser) {
|
|
5175
|
-
const closeResult = (
|
|
5328
|
+
const closeResult = (_ta = parser.close) == null ? void 0 : _ta.call(parser);
|
|
5176
5329
|
if (closeResult instanceof Promise) {
|
|
5177
5330
|
closeResult.catch(() => {
|
|
5178
5331
|
});
|
|
@@ -5180,25 +5333,22 @@ var AgentWidgetClient = class {
|
|
|
5180
5333
|
}
|
|
5181
5334
|
streamParsers.delete(assistant.id);
|
|
5182
5335
|
rawContentBuffers.delete(assistant.id);
|
|
5183
|
-
seqChunkBuffers.delete(assistant.id);
|
|
5184
5336
|
assistant.streaming = false;
|
|
5185
5337
|
emitMessage(assistant);
|
|
5186
5338
|
}
|
|
5187
5339
|
} else {
|
|
5188
5340
|
streamParsers.delete(assistant.id);
|
|
5189
5341
|
rawContentBuffers.delete(assistant.id);
|
|
5190
|
-
seqChunkBuffers.delete(assistant.id);
|
|
5191
5342
|
assistant.streaming = false;
|
|
5192
5343
|
emitMessage(assistant);
|
|
5193
5344
|
}
|
|
5194
5345
|
} else if (payloadType === "flow_complete") {
|
|
5195
|
-
const finalContent = (
|
|
5346
|
+
const finalContent = (_ua = payload.result) == null ? void 0 : _ua.response;
|
|
5196
5347
|
if (didSplitByPartId) {
|
|
5197
5348
|
if (assistantMessage !== null) {
|
|
5198
5349
|
const msg = assistantMessage;
|
|
5199
5350
|
streamParsers.delete(msg.id);
|
|
5200
5351
|
rawContentBuffers.delete(msg.id);
|
|
5201
|
-
seqChunkBuffers.delete(msg.id);
|
|
5202
5352
|
if (msg.streaming !== false) {
|
|
5203
5353
|
msg.streaming = false;
|
|
5204
5354
|
emitMessage(msg);
|
|
@@ -5219,8 +5369,8 @@ var AgentWidgetClient = class {
|
|
|
5219
5369
|
const parsedResult = parser.processChunk(stringContent);
|
|
5220
5370
|
if (parsedResult instanceof Promise) {
|
|
5221
5371
|
parsedResult.then((result) => {
|
|
5222
|
-
var
|
|
5223
|
-
const text = typeof result === "string" ? result : (
|
|
5372
|
+
var _a3;
|
|
5373
|
+
const text = typeof result === "string" ? result : (_a3 = result == null ? void 0 : result.text) != null ? _a3 : null;
|
|
5224
5374
|
if (text !== null) {
|
|
5225
5375
|
assistant.content = text;
|
|
5226
5376
|
assistant.streaming = false;
|
|
@@ -5236,7 +5386,6 @@ var AgentWidgetClient = class {
|
|
|
5236
5386
|
}
|
|
5237
5387
|
streamParsers.delete(assistant.id);
|
|
5238
5388
|
rawContentBuffers.delete(assistant.id);
|
|
5239
|
-
seqChunkBuffers.delete(assistant.id);
|
|
5240
5389
|
const contentChanged = displayContent !== assistant.content;
|
|
5241
5390
|
const streamingChanged = assistant.streaming !== false;
|
|
5242
5391
|
if (contentChanged) {
|
|
@@ -5251,7 +5400,6 @@ var AgentWidgetClient = class {
|
|
|
5251
5400
|
const msg = assistantMessage;
|
|
5252
5401
|
streamParsers.delete(msg.id);
|
|
5253
5402
|
rawContentBuffers.delete(msg.id);
|
|
5254
|
-
seqChunkBuffers.delete(msg.id);
|
|
5255
5403
|
if (msg.streaming !== false) {
|
|
5256
5404
|
msg.streaming = false;
|
|
5257
5405
|
emitMessage(msg);
|
|
@@ -5262,11 +5410,11 @@ var AgentWidgetClient = class {
|
|
|
5262
5410
|
} else if (payloadType === "agent_start") {
|
|
5263
5411
|
agentExecution = {
|
|
5264
5412
|
executionId: payload.executionId,
|
|
5265
|
-
agentId: (
|
|
5266
|
-
agentName: (
|
|
5413
|
+
agentId: (_va = payload.agentId) != null ? _va : "virtual",
|
|
5414
|
+
agentName: (_wa = payload.agentName) != null ? _wa : "",
|
|
5267
5415
|
status: "running",
|
|
5268
5416
|
currentIteration: 0,
|
|
5269
|
-
maxTurns: (
|
|
5417
|
+
maxTurns: (_xa = payload.maxTurns) != null ? _xa : 1,
|
|
5270
5418
|
startedAt: resolveTimestamp(payload.startedAt)
|
|
5271
5419
|
};
|
|
5272
5420
|
} else if (payloadType === "agent_iteration_start") {
|
|
@@ -5286,7 +5434,7 @@ var AgentWidgetClient = class {
|
|
|
5286
5434
|
} else if (payloadType === "agent_turn_delta") {
|
|
5287
5435
|
if (payload.contentType === "text") {
|
|
5288
5436
|
const assistant = ensureAssistantMessage();
|
|
5289
|
-
assistant.content += (
|
|
5437
|
+
assistant.content += (_ya = payload.delta) != null ? _ya : "";
|
|
5290
5438
|
assistant.agentMetadata = {
|
|
5291
5439
|
executionId: payload.executionId,
|
|
5292
5440
|
iteration: payload.iteration,
|
|
@@ -5295,14 +5443,14 @@ var AgentWidgetClient = class {
|
|
|
5295
5443
|
};
|
|
5296
5444
|
emitMessage(assistant);
|
|
5297
5445
|
} else if (payload.contentType === "thinking") {
|
|
5298
|
-
const reasoningId = (
|
|
5446
|
+
const reasoningId = (_za = payload.turnId) != null ? _za : `agent-think-${payload.iteration}`;
|
|
5299
5447
|
const reasoningMessage = ensureReasoningMessage(reasoningId);
|
|
5300
|
-
reasoningMessage.reasoning = (
|
|
5448
|
+
reasoningMessage.reasoning = (_Aa = reasoningMessage.reasoning) != null ? _Aa : {
|
|
5301
5449
|
id: reasoningId,
|
|
5302
5450
|
status: "streaming",
|
|
5303
5451
|
chunks: []
|
|
5304
5452
|
};
|
|
5305
|
-
reasoningMessage.reasoning.chunks.push((
|
|
5453
|
+
reasoningMessage.reasoning.chunks.push((_Ba = payload.delta) != null ? _Ba : "");
|
|
5306
5454
|
reasoningMessage.agentMetadata = {
|
|
5307
5455
|
executionId: payload.executionId,
|
|
5308
5456
|
iteration: payload.iteration,
|
|
@@ -5310,12 +5458,12 @@ var AgentWidgetClient = class {
|
|
|
5310
5458
|
};
|
|
5311
5459
|
emitMessage(reasoningMessage);
|
|
5312
5460
|
} else if (payload.contentType === "tool_input") {
|
|
5313
|
-
const toolId = (
|
|
5461
|
+
const toolId = (_Ca = payload.toolCallId) != null ? _Ca : toolContext.lastId;
|
|
5314
5462
|
if (toolId) {
|
|
5315
5463
|
const toolMessage = toolMessages.get(toolId);
|
|
5316
5464
|
if (toolMessage == null ? void 0 : toolMessage.toolCall) {
|
|
5317
|
-
toolMessage.toolCall.chunks = (
|
|
5318
|
-
toolMessage.toolCall.chunks.push((
|
|
5465
|
+
toolMessage.toolCall.chunks = (_Da = toolMessage.toolCall.chunks) != null ? _Da : [];
|
|
5466
|
+
toolMessage.toolCall.chunks.push((_Ea = payload.delta) != null ? _Ea : "");
|
|
5319
5467
|
emitMessage(toolMessage);
|
|
5320
5468
|
}
|
|
5321
5469
|
}
|
|
@@ -5327,20 +5475,20 @@ var AgentWidgetClient = class {
|
|
|
5327
5475
|
if (reasoningMessage == null ? void 0 : reasoningMessage.reasoning) {
|
|
5328
5476
|
reasoningMessage.reasoning.status = "complete";
|
|
5329
5477
|
reasoningMessage.reasoning.completedAt = resolveTimestamp(payload.completedAt);
|
|
5330
|
-
const start = (
|
|
5478
|
+
const start = (_Fa = reasoningMessage.reasoning.startedAt) != null ? _Fa : Date.now();
|
|
5331
5479
|
reasoningMessage.reasoning.durationMs = Math.max(
|
|
5332
5480
|
0,
|
|
5333
|
-
((
|
|
5481
|
+
((_Ga = reasoningMessage.reasoning.completedAt) != null ? _Ga : Date.now()) - start
|
|
5334
5482
|
);
|
|
5335
5483
|
reasoningMessage.streaming = false;
|
|
5336
5484
|
emitMessage(reasoningMessage);
|
|
5337
5485
|
}
|
|
5338
5486
|
}
|
|
5339
5487
|
} else if (payloadType === "agent_tool_start") {
|
|
5340
|
-
const toolId = (
|
|
5488
|
+
const toolId = (_Ha = payload.toolCallId) != null ? _Ha : `agent-tool-${nextSequence()}`;
|
|
5341
5489
|
trackToolId(getToolCallKey(payload), toolId);
|
|
5342
5490
|
const toolMessage = ensureToolMessage(toolId);
|
|
5343
|
-
const tool = (
|
|
5491
|
+
const tool = (_Ia = toolMessage.toolCall) != null ? _Ia : {
|
|
5344
5492
|
id: toolId,
|
|
5345
5493
|
status: "pending",
|
|
5346
5494
|
name: void 0,
|
|
@@ -5352,12 +5500,12 @@ var AgentWidgetClient = class {
|
|
|
5352
5500
|
completedAt: void 0,
|
|
5353
5501
|
durationMs: void 0
|
|
5354
5502
|
};
|
|
5355
|
-
tool.name = (
|
|
5503
|
+
tool.name = (_Ka = (_Ja = payload.toolName) != null ? _Ja : payload.name) != null ? _Ka : tool.name;
|
|
5356
5504
|
tool.status = "running";
|
|
5357
5505
|
if (payload.parameters !== void 0) {
|
|
5358
5506
|
tool.args = payload.parameters;
|
|
5359
5507
|
}
|
|
5360
|
-
tool.startedAt = resolveTimestamp((
|
|
5508
|
+
tool.startedAt = resolveTimestamp((_La = payload.startedAt) != null ? _La : payload.timestamp);
|
|
5361
5509
|
toolMessage.toolCall = tool;
|
|
5362
5510
|
toolMessage.streaming = true;
|
|
5363
5511
|
toolMessage.agentMetadata = {
|
|
@@ -5366,21 +5514,21 @@ var AgentWidgetClient = class {
|
|
|
5366
5514
|
};
|
|
5367
5515
|
emitMessage(toolMessage);
|
|
5368
5516
|
} else if (payloadType === "agent_tool_delta") {
|
|
5369
|
-
const toolId = (
|
|
5517
|
+
const toolId = (_Ma = payload.toolCallId) != null ? _Ma : toolContext.lastId;
|
|
5370
5518
|
if (toolId) {
|
|
5371
|
-
const toolMessage = (
|
|
5519
|
+
const toolMessage = (_Na = toolMessages.get(toolId)) != null ? _Na : ensureToolMessage(toolId);
|
|
5372
5520
|
if (toolMessage.toolCall) {
|
|
5373
|
-
toolMessage.toolCall.chunks = (
|
|
5374
|
-
toolMessage.toolCall.chunks.push((
|
|
5521
|
+
toolMessage.toolCall.chunks = (_Oa = toolMessage.toolCall.chunks) != null ? _Oa : [];
|
|
5522
|
+
toolMessage.toolCall.chunks.push((_Pa = payload.delta) != null ? _Pa : "");
|
|
5375
5523
|
toolMessage.toolCall.status = "running";
|
|
5376
5524
|
toolMessage.streaming = true;
|
|
5377
5525
|
emitMessage(toolMessage);
|
|
5378
5526
|
}
|
|
5379
5527
|
}
|
|
5380
5528
|
} else if (payloadType === "agent_tool_complete") {
|
|
5381
|
-
const toolId = (
|
|
5529
|
+
const toolId = (_Qa = payload.toolCallId) != null ? _Qa : toolContext.lastId;
|
|
5382
5530
|
if (toolId) {
|
|
5383
|
-
const toolMessage = (
|
|
5531
|
+
const toolMessage = (_Ra = toolMessages.get(toolId)) != null ? _Ra : ensureToolMessage(toolId);
|
|
5384
5532
|
if (toolMessage.toolCall) {
|
|
5385
5533
|
toolMessage.toolCall.status = "complete";
|
|
5386
5534
|
if (payload.result !== void 0) {
|
|
@@ -5389,7 +5537,7 @@ var AgentWidgetClient = class {
|
|
|
5389
5537
|
if (typeof payload.executionTime === "number") {
|
|
5390
5538
|
toolMessage.toolCall.durationMs = payload.executionTime;
|
|
5391
5539
|
}
|
|
5392
|
-
toolMessage.toolCall.completedAt = resolveTimestamp((
|
|
5540
|
+
toolMessage.toolCall.completedAt = resolveTimestamp((_Sa = payload.completedAt) != null ? _Sa : payload.timestamp);
|
|
5393
5541
|
toolMessage.streaming = false;
|
|
5394
5542
|
emitMessage(toolMessage);
|
|
5395
5543
|
const callKey = getToolCallKey(payload);
|
|
@@ -5404,7 +5552,7 @@ var AgentWidgetClient = class {
|
|
|
5404
5552
|
const reflectionMessage = {
|
|
5405
5553
|
id: reflectionId,
|
|
5406
5554
|
role: "assistant",
|
|
5407
|
-
content: (
|
|
5555
|
+
content: (_Ta = payload.reflection) != null ? _Ta : "",
|
|
5408
5556
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5409
5557
|
streaming: false,
|
|
5410
5558
|
variant: "reasoning",
|
|
@@ -5412,7 +5560,7 @@ var AgentWidgetClient = class {
|
|
|
5412
5560
|
reasoning: {
|
|
5413
5561
|
id: reflectionId,
|
|
5414
5562
|
status: "complete",
|
|
5415
|
-
chunks: [(
|
|
5563
|
+
chunks: [(_Ua = payload.reflection) != null ? _Ua : ""]
|
|
5416
5564
|
},
|
|
5417
5565
|
agentMetadata: {
|
|
5418
5566
|
executionId: payload.executionId,
|
|
@@ -5433,7 +5581,7 @@ var AgentWidgetClient = class {
|
|
|
5433
5581
|
}
|
|
5434
5582
|
onEvent({ type: "status", status: "idle" });
|
|
5435
5583
|
} else if (payloadType === "agent_error") {
|
|
5436
|
-
const errorMessage = typeof payload.error === "string" ? payload.error : (
|
|
5584
|
+
const errorMessage = typeof payload.error === "string" ? payload.error : (_Wa = (_Va = payload.error) == null ? void 0 : _Va.message) != null ? _Wa : "Agent execution error";
|
|
5437
5585
|
if (payload.recoverable) {
|
|
5438
5586
|
if (typeof console !== "undefined") {
|
|
5439
5587
|
console.warn("[AgentWidget] Recoverable agent error:", errorMessage);
|
|
@@ -5446,7 +5594,7 @@ var AgentWidgetClient = class {
|
|
|
5446
5594
|
}
|
|
5447
5595
|
} else if (payloadType === "agent_ping") {
|
|
5448
5596
|
} else if (payloadType === "agent_approval_start") {
|
|
5449
|
-
const approvalId = (
|
|
5597
|
+
const approvalId = (_Xa = payload.approvalId) != null ? _Xa : `approval-${nextSequence()}`;
|
|
5450
5598
|
const approvalMessage = {
|
|
5451
5599
|
id: `approval-${approvalId}`,
|
|
5452
5600
|
role: "assistant",
|
|
@@ -5458,17 +5606,17 @@ var AgentWidgetClient = class {
|
|
|
5458
5606
|
approval: {
|
|
5459
5607
|
id: approvalId,
|
|
5460
5608
|
status: "pending",
|
|
5461
|
-
agentId: (
|
|
5462
|
-
executionId: (
|
|
5463
|
-
toolName: (
|
|
5609
|
+
agentId: (_Ya = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _Ya : "virtual",
|
|
5610
|
+
executionId: (__a = (_Za = payload.executionId) != null ? _Za : agentExecution == null ? void 0 : agentExecution.executionId) != null ? __a : "",
|
|
5611
|
+
toolName: (_$a = payload.toolName) != null ? _$a : "",
|
|
5464
5612
|
toolType: payload.toolType,
|
|
5465
|
-
description: (
|
|
5613
|
+
description: (_bb = payload.description) != null ? _bb : `Execute ${(_ab = payload.toolName) != null ? _ab : "tool"}`,
|
|
5466
5614
|
parameters: payload.parameters
|
|
5467
5615
|
}
|
|
5468
5616
|
};
|
|
5469
5617
|
emitMessage(approvalMessage);
|
|
5470
5618
|
} else if (payloadType === "step_await" && payload.awaitReason === "approval_required") {
|
|
5471
|
-
const approvalId = (
|
|
5619
|
+
const approvalId = (_cb = payload.approvalId) != null ? _cb : `approval-${nextSequence()}`;
|
|
5472
5620
|
const approvalMessage = {
|
|
5473
5621
|
id: `approval-${approvalId}`,
|
|
5474
5622
|
role: "assistant",
|
|
@@ -5480,11 +5628,11 @@ var AgentWidgetClient = class {
|
|
|
5480
5628
|
approval: {
|
|
5481
5629
|
id: approvalId,
|
|
5482
5630
|
status: "pending",
|
|
5483
|
-
agentId: (
|
|
5484
|
-
executionId: (
|
|
5485
|
-
toolName: (
|
|
5631
|
+
agentId: (_db = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _db : "virtual",
|
|
5632
|
+
executionId: (_fb = (_eb = payload.executionId) != null ? _eb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _fb : "",
|
|
5633
|
+
toolName: (_gb = payload.toolName) != null ? _gb : "",
|
|
5486
5634
|
toolType: payload.toolType,
|
|
5487
|
-
description: (
|
|
5635
|
+
description: (_ib = payload.description) != null ? _ib : `Execute ${(_hb = payload.toolName) != null ? _hb : "tool"}`,
|
|
5488
5636
|
parameters: payload.parameters
|
|
5489
5637
|
}
|
|
5490
5638
|
};
|
|
@@ -5503,11 +5651,11 @@ var AgentWidgetClient = class {
|
|
|
5503
5651
|
sequence: nextSequence(),
|
|
5504
5652
|
approval: {
|
|
5505
5653
|
id: approvalId,
|
|
5506
|
-
status: (
|
|
5507
|
-
agentId: (
|
|
5508
|
-
executionId: (
|
|
5509
|
-
toolName: (
|
|
5510
|
-
description: (
|
|
5654
|
+
status: (_jb = payload.decision) != null ? _jb : "approved",
|
|
5655
|
+
agentId: (_kb = agentExecution == null ? void 0 : agentExecution.agentId) != null ? _kb : "virtual",
|
|
5656
|
+
executionId: (_mb = (_lb = payload.executionId) != null ? _lb : agentExecution == null ? void 0 : agentExecution.executionId) != null ? _mb : "",
|
|
5657
|
+
toolName: (_nb = payload.toolName) != null ? _nb : "",
|
|
5658
|
+
description: (_ob = payload.description) != null ? _ob : "",
|
|
5511
5659
|
resolvedAt: Date.now()
|
|
5512
5660
|
}
|
|
5513
5661
|
};
|
|
@@ -5545,7 +5693,7 @@ var AgentWidgetClient = class {
|
|
|
5545
5693
|
}
|
|
5546
5694
|
} else if (payloadType === "artifact_delta") {
|
|
5547
5695
|
const deltaId = String(payload.id);
|
|
5548
|
-
const deltaText = typeof payload.delta === "string" ? payload.delta : String((
|
|
5696
|
+
const deltaText = typeof payload.delta === "string" ? payload.delta : String((_pb = payload.delta) != null ? _pb : "");
|
|
5549
5697
|
onEvent({
|
|
5550
5698
|
type: "artifact_delta",
|
|
5551
5699
|
id: deltaId,
|
|
@@ -5568,7 +5716,7 @@ var AgentWidgetClient = class {
|
|
|
5568
5716
|
if (refMsg) {
|
|
5569
5717
|
refMsg.streaming = false;
|
|
5570
5718
|
try {
|
|
5571
|
-
const parsed = JSON.parse((
|
|
5719
|
+
const parsed = JSON.parse((_qb = refMsg.rawContent) != null ? _qb : "{}");
|
|
5572
5720
|
if (parsed.props) {
|
|
5573
5721
|
parsed.props.status = "complete";
|
|
5574
5722
|
const acc = artifactContent.get(artCompleteId);
|
|
@@ -5589,7 +5737,7 @@ var AgentWidgetClient = class {
|
|
|
5589
5737
|
if (!m || typeof m !== "object") {
|
|
5590
5738
|
continue;
|
|
5591
5739
|
}
|
|
5592
|
-
const id = String((
|
|
5740
|
+
const id = String((_rb = m.id) != null ? _rb : `msg-${nextSequence()}`);
|
|
5593
5741
|
const roleRaw = m.role;
|
|
5594
5742
|
const role = roleRaw === "user" ? "user" : roleRaw === "system" ? "system" : "assistant";
|
|
5595
5743
|
const msg = {
|
|
@@ -5608,7 +5756,7 @@ var AgentWidgetClient = class {
|
|
|
5608
5756
|
if (msg.rawContent) {
|
|
5609
5757
|
try {
|
|
5610
5758
|
const parsed = JSON.parse(msg.rawContent);
|
|
5611
|
-
const refArtId = (
|
|
5759
|
+
const refArtId = (_sb = parsed == null ? void 0 : parsed.props) == null ? void 0 : _sb.artifactId;
|
|
5612
5760
|
if (typeof refArtId === "string") {
|
|
5613
5761
|
artifactIdsWithCards.add(refArtId);
|
|
5614
5762
|
}
|
|
@@ -5619,13 +5767,12 @@ var AgentWidgetClient = class {
|
|
|
5619
5767
|
assistantMessageRef.current = null;
|
|
5620
5768
|
streamParsers.delete(id);
|
|
5621
5769
|
rawContentBuffers.delete(id);
|
|
5622
|
-
seqChunkBuffers.delete(id);
|
|
5623
5770
|
} else if (payloadType === "error" || payloadType === "step_error" || payloadType === "dispatch_error" || payloadType === "flow_error") {
|
|
5624
5771
|
let resolvedError = null;
|
|
5625
5772
|
if (payload.error instanceof Error) {
|
|
5626
5773
|
resolvedError = payload.error;
|
|
5627
5774
|
} else if (payloadType === "dispatch_error") {
|
|
5628
|
-
const msg = (
|
|
5775
|
+
const msg = (_tb = payload.message) != null ? _tb : payload.error;
|
|
5629
5776
|
if (msg != null && msg !== "") {
|
|
5630
5777
|
resolvedError = new Error(String(msg));
|
|
5631
5778
|
}
|
|
@@ -5634,7 +5781,7 @@ var AgentWidgetClient = class {
|
|
|
5634
5781
|
if (typeof e === "string" && e !== "") {
|
|
5635
5782
|
resolvedError = new Error(e);
|
|
5636
5783
|
} else if (e != null && typeof e === "object" && "message" in e) {
|
|
5637
|
-
resolvedError = new Error(String((
|
|
5784
|
+
resolvedError = new Error(String((_ub = e.message) != null ? _ub : e));
|
|
5638
5785
|
}
|
|
5639
5786
|
} else if (payloadType === "error" && payload.error != null && payload.error !== "") {
|
|
5640
5787
|
resolvedError = new Error(String(payload.error));
|
|
@@ -5650,7 +5797,60 @@ var AgentWidgetClient = class {
|
|
|
5650
5797
|
}
|
|
5651
5798
|
}
|
|
5652
5799
|
}
|
|
5800
|
+
seqReadyQueue.length = 0;
|
|
5801
|
+
};
|
|
5802
|
+
while (true) {
|
|
5803
|
+
const { done, value } = await reader.read();
|
|
5804
|
+
if (done) break;
|
|
5805
|
+
buffer += decoder.decode(value, { stream: true });
|
|
5806
|
+
const events = buffer.split("\n\n");
|
|
5807
|
+
buffer = (_b = events.pop()) != null ? _b : "";
|
|
5808
|
+
for (const event of events) {
|
|
5809
|
+
const lines = event.split("\n");
|
|
5810
|
+
let eventType = "message";
|
|
5811
|
+
let data = "";
|
|
5812
|
+
for (const line of lines) {
|
|
5813
|
+
if (line.startsWith("event:")) {
|
|
5814
|
+
eventType = line.replace("event:", "").trim();
|
|
5815
|
+
} else if (line.startsWith("data:")) {
|
|
5816
|
+
data += line.replace("data:", "").trim();
|
|
5817
|
+
}
|
|
5818
|
+
}
|
|
5819
|
+
if (!data) continue;
|
|
5820
|
+
let payload;
|
|
5821
|
+
try {
|
|
5822
|
+
payload = JSON.parse(data);
|
|
5823
|
+
} catch (error) {
|
|
5824
|
+
onEvent({
|
|
5825
|
+
type: "error",
|
|
5826
|
+
error: error instanceof Error ? error : new Error("Failed to parse chat stream payload")
|
|
5827
|
+
});
|
|
5828
|
+
continue;
|
|
5829
|
+
}
|
|
5830
|
+
const payloadType = eventType !== "message" ? eventType : (_c = payload.type) != null ? _c : "message";
|
|
5831
|
+
(_d = this.onSSEEvent) == null ? void 0 : _d.call(this, payloadType, payload);
|
|
5832
|
+
if (this.parseSSEEvent) {
|
|
5833
|
+
assistantMessageRef.current = assistantMessage;
|
|
5834
|
+
const handled = await this.handleCustomSSEEvent(
|
|
5835
|
+
payload,
|
|
5836
|
+
onEvent,
|
|
5837
|
+
assistantMessageRef,
|
|
5838
|
+
emitMessage,
|
|
5839
|
+
nextSequence,
|
|
5840
|
+
partIdState
|
|
5841
|
+
);
|
|
5842
|
+
if (assistantMessageRef.current && assistantMessageRef.current !== assistantMessage) {
|
|
5843
|
+
assistantMessage = assistantMessageRef.current;
|
|
5844
|
+
}
|
|
5845
|
+
if (handled) continue;
|
|
5846
|
+
}
|
|
5847
|
+
seqBuffer.push(payloadType, payload);
|
|
5848
|
+
drainReadyQueue();
|
|
5849
|
+
}
|
|
5653
5850
|
}
|
|
5851
|
+
seqBuffer.flushPending();
|
|
5852
|
+
drainReadyQueue();
|
|
5853
|
+
seqBuffer.destroy();
|
|
5654
5854
|
}
|
|
5655
5855
|
};
|
|
5656
5856
|
|
|
@@ -8557,6 +8757,7 @@ var buildHeader = (context) => {
|
|
|
8557
8757
|
clearChatButton.style.color = clearChatIconColor || HEADER_THEME_CSS.actionIconColor;
|
|
8558
8758
|
const iconSvg = renderLucideIcon(clearChatIconName, "20px", "currentColor", 1);
|
|
8559
8759
|
if (iconSvg) {
|
|
8760
|
+
iconSvg.style.display = "block";
|
|
8560
8761
|
clearChatButton.appendChild(iconSvg);
|
|
8561
8762
|
}
|
|
8562
8763
|
if (clearChatBgColor) {
|
|
@@ -8640,7 +8841,7 @@ var buildHeader = (context) => {
|
|
|
8640
8841
|
}
|
|
8641
8842
|
const closeButtonWrapper = createElement(
|
|
8642
8843
|
"div",
|
|
8643
|
-
closeButtonPlacement === "top-right" ? "persona-absolute persona-top-4 persona-right-4 persona-z-50" : clearChatEnabled && clearChatPlacement === "inline" ? "" : "persona-ml-auto"
|
|
8844
|
+
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"
|
|
8644
8845
|
);
|
|
8645
8846
|
const closeButton = createElement(
|
|
8646
8847
|
"button",
|
|
@@ -8656,8 +8857,9 @@ var buildHeader = (context) => {
|
|
|
8656
8857
|
const closeButtonIconName = (_E = launcher.closeButtonIconName) != null ? _E : "x";
|
|
8657
8858
|
const closeButtonIconText = (_F = launcher.closeButtonIconText) != null ? _F : "\xD7";
|
|
8658
8859
|
closeButton.style.color = launcher.closeButtonColor || HEADER_THEME_CSS.actionIconColor;
|
|
8659
|
-
const closeIconSvg = renderLucideIcon(closeButtonIconName, "
|
|
8860
|
+
const closeIconSvg = renderLucideIcon(closeButtonIconName, "28px", "currentColor", 1);
|
|
8660
8861
|
if (closeIconSvg) {
|
|
8862
|
+
closeIconSvg.style.display = "block";
|
|
8661
8863
|
closeButton.appendChild(closeIconSvg);
|
|
8662
8864
|
} else {
|
|
8663
8865
|
closeButton.textContent = closeButtonIconText;
|
|
@@ -9185,7 +9387,7 @@ var buildMinimalHeader = (context) => {
|
|
|
9185
9387
|
closeButton.style.display = showClose ? "" : "none";
|
|
9186
9388
|
closeButton.style.color = launcher.closeButtonColor || HEADER_THEME_CSS.actionIconColor;
|
|
9187
9389
|
const closeButtonIconName = (_i = launcher.closeButtonIconName) != null ? _i : "x";
|
|
9188
|
-
const closeIconSvg = renderLucideIcon(closeButtonIconName, "
|
|
9390
|
+
const closeIconSvg = renderLucideIcon(closeButtonIconName, "28px", "currentColor", 1);
|
|
9189
9391
|
if (closeIconSvg) {
|
|
9190
9392
|
closeButton.appendChild(closeIconSvg);
|
|
9191
9393
|
} else {
|
|
@@ -14492,17 +14694,38 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
14492
14694
|
} else if (action === "upvote" || action === "downvote") {
|
|
14493
14695
|
const currentVote = (_a2 = messageVoteState.get(messageId)) != null ? _a2 : null;
|
|
14494
14696
|
const wasActive = currentVote === action;
|
|
14697
|
+
const iconName = action === "upvote" ? "thumbs-up" : "thumbs-down";
|
|
14495
14698
|
if (wasActive) {
|
|
14496
14699
|
messageVoteState.delete(messageId);
|
|
14497
14700
|
actionBtn.classList.remove("persona-message-action-active");
|
|
14701
|
+
const outlineIcon = renderLucideIcon(iconName, 14, "currentColor", 2);
|
|
14702
|
+
if (outlineIcon) {
|
|
14703
|
+
actionBtn.innerHTML = "";
|
|
14704
|
+
actionBtn.appendChild(outlineIcon);
|
|
14705
|
+
}
|
|
14498
14706
|
} else {
|
|
14499
14707
|
const oppositeAction = action === "upvote" ? "downvote" : "upvote";
|
|
14500
14708
|
const oppositeBtn = actionsContainer.querySelector(`[data-action="${oppositeAction}"]`);
|
|
14501
14709
|
if (oppositeBtn) {
|
|
14502
14710
|
oppositeBtn.classList.remove("persona-message-action-active");
|
|
14711
|
+
const oppositeIconName = oppositeAction === "upvote" ? "thumbs-up" : "thumbs-down";
|
|
14712
|
+
const outlineIcon = renderLucideIcon(oppositeIconName, 14, "currentColor", 2);
|
|
14713
|
+
if (outlineIcon) {
|
|
14714
|
+
oppositeBtn.innerHTML = "";
|
|
14715
|
+
oppositeBtn.appendChild(outlineIcon);
|
|
14716
|
+
}
|
|
14503
14717
|
}
|
|
14504
14718
|
messageVoteState.set(messageId, action);
|
|
14505
14719
|
actionBtn.classList.add("persona-message-action-active");
|
|
14720
|
+
const filledIcon = renderLucideIcon(iconName, 14, "currentColor", 2);
|
|
14721
|
+
if (filledIcon) {
|
|
14722
|
+
filledIcon.setAttribute("fill", "currentColor");
|
|
14723
|
+
actionBtn.innerHTML = "";
|
|
14724
|
+
actionBtn.appendChild(filledIcon);
|
|
14725
|
+
}
|
|
14726
|
+
actionBtn.classList.remove("persona-message-action-pop");
|
|
14727
|
+
void actionBtn.offsetWidth;
|
|
14728
|
+
actionBtn.classList.add("persona-message-action-pop");
|
|
14506
14729
|
const messages = session.getMessages();
|
|
14507
14730
|
const message = messages.find((m) => m.id === messageId);
|
|
14508
14731
|
if (message && messageActionCallbacks.onFeedback) {
|
|
@@ -17153,7 +17376,7 @@ var createAgentExperience = (mount, initialConfig, runtimeOptions) => {
|
|
|
17153
17376
|
const closeButtonIconName = (_ca = launcher.closeButtonIconName) != null ? _ca : "x";
|
|
17154
17377
|
const closeButtonIconText = (_da = launcher.closeButtonIconText) != null ? _da : "\xD7";
|
|
17155
17378
|
closeButton.innerHTML = "";
|
|
17156
|
-
const iconSvg = renderLucideIcon(closeButtonIconName, "
|
|
17379
|
+
const iconSvg = renderLucideIcon(closeButtonIconName, "28px", "currentColor", 1);
|
|
17157
17380
|
if (iconSvg) {
|
|
17158
17381
|
closeButton.appendChild(iconSvg);
|
|
17159
17382
|
} else {
|