bs-agent 0.0.20 → 0.0.22
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 +105 -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 +105 -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,25 @@ 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
|
-
|
|
512
|
+
console.log(
|
|
513
|
+
"[DEBUG] handleClientToolCall:",
|
|
514
|
+
event.data.toolName,
|
|
515
|
+
"paused:",
|
|
516
|
+
event.data.paused,
|
|
517
|
+
"toolFound:",
|
|
518
|
+
!!tool,
|
|
519
|
+
"hasRender:",
|
|
520
|
+
!!tool?.render
|
|
521
|
+
);
|
|
522
|
+
if (!tool?.render && !event.data.paused) {
|
|
523
|
+
console.log("[DEBUG] handleClientToolCall: SKIPPING part creation \u2014 not paused and no render");
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
console.log(
|
|
527
|
+
"[DEBUG] handleClientToolCall: CREATING widget part for",
|
|
528
|
+
event.data.toolName,
|
|
529
|
+
event.data.callId
|
|
530
|
+
);
|
|
460
531
|
setMessages((prev) => {
|
|
461
532
|
const lastMessage = prev[prev.length - 1];
|
|
462
533
|
const newPart = {
|
|
@@ -555,7 +626,8 @@ function useAgent(agent, options) {
|
|
|
555
626
|
syncSessionRef: sessionUtils.syncSessionRef,
|
|
556
627
|
debugHandlers,
|
|
557
628
|
toolContext,
|
|
558
|
-
textDeltaModifier: optionsRef.current?.textDeltaModifier
|
|
629
|
+
textDeltaModifier: optionsRef.current?.textDeltaModifier,
|
|
630
|
+
fullTextModifier: optionsRef.current?.fullTextModifier
|
|
559
631
|
};
|
|
560
632
|
const callbacks = buildStreamCallbacks(deps, debugKey);
|
|
561
633
|
const executeOptions = {
|
|
@@ -1574,6 +1646,19 @@ function ToolRenderer({ agentId, part }) {
|
|
|
1574
1646
|
throw new Error("ToolRenderer must be used within <AgentContextProvider>");
|
|
1575
1647
|
}
|
|
1576
1648
|
const tool = context.getTool(agentId, part.toolName);
|
|
1649
|
+
console.log(
|
|
1650
|
+
"[DEBUG] ToolRenderer:",
|
|
1651
|
+
part.toolName,
|
|
1652
|
+
part.callId,
|
|
1653
|
+
"toolFound:",
|
|
1654
|
+
!!tool,
|
|
1655
|
+
"hasRender:",
|
|
1656
|
+
!!tool?.render,
|
|
1657
|
+
"paused:",
|
|
1658
|
+
part.paused,
|
|
1659
|
+
"status:",
|
|
1660
|
+
localStatus
|
|
1661
|
+
);
|
|
1577
1662
|
const handleSubmit = (0, import_react6.useCallback)(
|
|
1578
1663
|
(result) => {
|
|
1579
1664
|
if (localStatus === "submitted") return;
|