bs-agent 0.0.20 → 0.0.21
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/react/index.cjs +74 -20
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +6 -0
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.js +74 -20
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/react/index.cjs
CHANGED
|
@@ -202,11 +202,16 @@ var createDebugHandlers = (setDebugData) => {
|
|
|
202
202
|
if (existingItemIndex === -1) {
|
|
203
203
|
currentData.push({ itemType: "reasoning", reasoning: delta, index });
|
|
204
204
|
} else {
|
|
205
|
-
currentData
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
205
|
+
const hasInterleavedItems = currentData.slice(existingItemIndex + 1).some((item) => item.itemType !== "reasoning");
|
|
206
|
+
if (hasInterleavedItems) {
|
|
207
|
+
currentData.push({ itemType: "reasoning", reasoning: delta, index });
|
|
208
|
+
} else {
|
|
209
|
+
currentData[existingItemIndex] = {
|
|
210
|
+
itemType: "reasoning",
|
|
211
|
+
reasoning: currentData[existingItemIndex].reasoning + delta,
|
|
212
|
+
index
|
|
213
|
+
};
|
|
214
|
+
}
|
|
210
215
|
}
|
|
211
216
|
return {
|
|
212
217
|
...prev,
|
|
@@ -361,7 +366,8 @@ function buildStreamCallbacks(deps, debugKey) {
|
|
|
361
366
|
messagesRef,
|
|
362
367
|
toolContext,
|
|
363
368
|
agentId,
|
|
364
|
-
textDeltaModifier
|
|
369
|
+
textDeltaModifier,
|
|
370
|
+
fullTextModifier
|
|
365
371
|
} = deps;
|
|
366
372
|
return {
|
|
367
373
|
onComplete: () => {
|
|
@@ -380,7 +386,14 @@ function buildStreamCallbacks(deps, debugKey) {
|
|
|
380
386
|
},
|
|
381
387
|
onEvent: (event) => {
|
|
382
388
|
if (event.type === "text_delta") {
|
|
383
|
-
handleTextDelta(
|
|
389
|
+
handleTextDelta(
|
|
390
|
+
event,
|
|
391
|
+
setMessages,
|
|
392
|
+
syncSessionRef,
|
|
393
|
+
textDeltaModifier,
|
|
394
|
+
fullTextModifier,
|
|
395
|
+
agentId
|
|
396
|
+
);
|
|
384
397
|
} else if (event.type === "tool_call_start" && event.data.toolType === "client") {
|
|
385
398
|
handleClientToolCall(event, setMessages, syncSessionRef, toolContext, agentId);
|
|
386
399
|
if (debugKey) {
|
|
@@ -410,20 +423,24 @@ function buildStreamCallbacks(deps, debugKey) {
|
|
|
410
423
|
}
|
|
411
424
|
};
|
|
412
425
|
}
|
|
413
|
-
function handleTextDelta(event, setMessages, syncSessionRef, modifier, agentId) {
|
|
426
|
+
function handleTextDelta(event, setMessages, syncSessionRef, modifier, fullTextModifier, agentId) {
|
|
414
427
|
const sequence = event.meta.sequence;
|
|
415
428
|
const originalText = event.data;
|
|
416
429
|
const eventExecutionId = event.meta.executionId;
|
|
417
430
|
setMessages((prev) => {
|
|
418
431
|
const lastMessage = prev[prev.length - 1];
|
|
432
|
+
const meta = {
|
|
433
|
+
executionId: eventExecutionId,
|
|
434
|
+
sequence,
|
|
435
|
+
agentId: event.meta.agentId || agentId
|
|
436
|
+
};
|
|
419
437
|
let text = originalText;
|
|
420
438
|
if (modifier) {
|
|
421
|
-
const
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
});
|
|
439
|
+
const lastTextPart = lastMessage?.role === "agent" ? lastMessage.parts?.findLast(
|
|
440
|
+
(p) => p.type === "text"
|
|
441
|
+
) : void 0;
|
|
442
|
+
const currentFullText = lastTextPart?._rawText ?? lastTextPart?.text ?? "";
|
|
443
|
+
text = modifier(originalText, currentFullText, meta);
|
|
427
444
|
}
|
|
428
445
|
const newPart = {
|
|
429
446
|
type: "text",
|
|
@@ -433,17 +450,53 @@ function handleTextDelta(event, setMessages, syncSessionRef, modifier, agentId)
|
|
|
433
450
|
};
|
|
434
451
|
let updatedMessages;
|
|
435
452
|
if (lastMessage?.role === "agent") {
|
|
453
|
+
const lastTextPart = lastMessage.parts?.findLast(
|
|
454
|
+
(p) => p.type === "text"
|
|
455
|
+
);
|
|
456
|
+
const prevRaw = lastTextPart?._rawText ?? lastTextPart?.text ?? "";
|
|
457
|
+
const rawText = prevRaw + text;
|
|
458
|
+
let updatedParts = updateAgentMessageParts(lastMessage.parts || [], newPart);
|
|
459
|
+
let displayContent = rawText;
|
|
460
|
+
if (fullTextModifier) {
|
|
461
|
+
displayContent = fullTextModifier(rawText, meta);
|
|
462
|
+
const textParts = updatedParts.filter(
|
|
463
|
+
(p) => p.type === "text"
|
|
464
|
+
);
|
|
465
|
+
const nonTextParts = updatedParts.filter((p) => p.type !== "text");
|
|
466
|
+
const modifiedTextPart = {
|
|
467
|
+
type: "text",
|
|
468
|
+
text: displayContent,
|
|
469
|
+
_rawText: rawText,
|
|
470
|
+
firstSequence: textParts[0]?.firstSequence ?? sequence,
|
|
471
|
+
lastSequence: textParts[textParts.length - 1]?.lastSequence ?? sequence
|
|
472
|
+
};
|
|
473
|
+
updatedParts = [...nonTextParts, modifiedTextPart];
|
|
474
|
+
}
|
|
436
475
|
const updatedMessage = {
|
|
437
476
|
...lastMessage,
|
|
438
|
-
content:
|
|
439
|
-
parts:
|
|
477
|
+
content: displayContent,
|
|
478
|
+
parts: updatedParts
|
|
440
479
|
};
|
|
441
480
|
updatedMessages = [...prev.slice(0, -1), updatedMessage];
|
|
442
481
|
} else {
|
|
482
|
+
let displayContent = text;
|
|
483
|
+
let parts = [newPart];
|
|
484
|
+
if (fullTextModifier) {
|
|
485
|
+
displayContent = fullTextModifier(text, meta);
|
|
486
|
+
parts = [
|
|
487
|
+
{
|
|
488
|
+
type: "text",
|
|
489
|
+
text: displayContent,
|
|
490
|
+
_rawText: text,
|
|
491
|
+
firstSequence: sequence,
|
|
492
|
+
lastSequence: sequence
|
|
493
|
+
}
|
|
494
|
+
];
|
|
495
|
+
}
|
|
443
496
|
const updatedMessage = {
|
|
444
497
|
role: "agent",
|
|
445
|
-
content:
|
|
446
|
-
parts
|
|
498
|
+
content: displayContent,
|
|
499
|
+
parts,
|
|
447
500
|
executionId: eventExecutionId
|
|
448
501
|
};
|
|
449
502
|
updatedMessages = [...prev, updatedMessage];
|
|
@@ -456,7 +509,7 @@ function handleTextDelta(event, setMessages, syncSessionRef, modifier, agentId)
|
|
|
456
509
|
}
|
|
457
510
|
function handleClientToolCall(event, setMessages, syncSessionRef, toolContext, agentId) {
|
|
458
511
|
const tool = toolContext?.getTool(agentId, event.data.toolName);
|
|
459
|
-
if (!tool?.render) return;
|
|
512
|
+
if (!tool?.render && !event.data.paused) return;
|
|
460
513
|
setMessages((prev) => {
|
|
461
514
|
const lastMessage = prev[prev.length - 1];
|
|
462
515
|
const newPart = {
|
|
@@ -555,7 +608,8 @@ function useAgent(agent, options) {
|
|
|
555
608
|
syncSessionRef: sessionUtils.syncSessionRef,
|
|
556
609
|
debugHandlers,
|
|
557
610
|
toolContext,
|
|
558
|
-
textDeltaModifier: optionsRef.current?.textDeltaModifier
|
|
611
|
+
textDeltaModifier: optionsRef.current?.textDeltaModifier,
|
|
612
|
+
fullTextModifier: optionsRef.current?.fullTextModifier
|
|
559
613
|
};
|
|
560
614
|
const callbacks = buildStreamCallbacks(deps, debugKey);
|
|
561
615
|
const executeOptions = {
|