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.js
CHANGED
|
@@ -171,11 +171,16 @@ var createDebugHandlers = (setDebugData) => {
|
|
|
171
171
|
if (existingItemIndex === -1) {
|
|
172
172
|
currentData.push({ itemType: "reasoning", reasoning: delta, index });
|
|
173
173
|
} else {
|
|
174
|
-
currentData
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
174
|
+
const hasInterleavedItems = currentData.slice(existingItemIndex + 1).some((item) => item.itemType !== "reasoning");
|
|
175
|
+
if (hasInterleavedItems) {
|
|
176
|
+
currentData.push({ itemType: "reasoning", reasoning: delta, index });
|
|
177
|
+
} else {
|
|
178
|
+
currentData[existingItemIndex] = {
|
|
179
|
+
itemType: "reasoning",
|
|
180
|
+
reasoning: currentData[existingItemIndex].reasoning + delta,
|
|
181
|
+
index
|
|
182
|
+
};
|
|
183
|
+
}
|
|
179
184
|
}
|
|
180
185
|
return {
|
|
181
186
|
...prev,
|
|
@@ -330,7 +335,8 @@ function buildStreamCallbacks(deps, debugKey) {
|
|
|
330
335
|
messagesRef,
|
|
331
336
|
toolContext,
|
|
332
337
|
agentId,
|
|
333
|
-
textDeltaModifier
|
|
338
|
+
textDeltaModifier,
|
|
339
|
+
fullTextModifier
|
|
334
340
|
} = deps;
|
|
335
341
|
return {
|
|
336
342
|
onComplete: () => {
|
|
@@ -349,7 +355,14 @@ function buildStreamCallbacks(deps, debugKey) {
|
|
|
349
355
|
},
|
|
350
356
|
onEvent: (event) => {
|
|
351
357
|
if (event.type === "text_delta") {
|
|
352
|
-
handleTextDelta(
|
|
358
|
+
handleTextDelta(
|
|
359
|
+
event,
|
|
360
|
+
setMessages,
|
|
361
|
+
syncSessionRef,
|
|
362
|
+
textDeltaModifier,
|
|
363
|
+
fullTextModifier,
|
|
364
|
+
agentId
|
|
365
|
+
);
|
|
353
366
|
} else if (event.type === "tool_call_start" && event.data.toolType === "client") {
|
|
354
367
|
handleClientToolCall(event, setMessages, syncSessionRef, toolContext, agentId);
|
|
355
368
|
if (debugKey) {
|
|
@@ -379,20 +392,24 @@ function buildStreamCallbacks(deps, debugKey) {
|
|
|
379
392
|
}
|
|
380
393
|
};
|
|
381
394
|
}
|
|
382
|
-
function handleTextDelta(event, setMessages, syncSessionRef, modifier, agentId) {
|
|
395
|
+
function handleTextDelta(event, setMessages, syncSessionRef, modifier, fullTextModifier, agentId) {
|
|
383
396
|
const sequence = event.meta.sequence;
|
|
384
397
|
const originalText = event.data;
|
|
385
398
|
const eventExecutionId = event.meta.executionId;
|
|
386
399
|
setMessages((prev) => {
|
|
387
400
|
const lastMessage = prev[prev.length - 1];
|
|
401
|
+
const meta = {
|
|
402
|
+
executionId: eventExecutionId,
|
|
403
|
+
sequence,
|
|
404
|
+
agentId: event.meta.agentId || agentId
|
|
405
|
+
};
|
|
388
406
|
let text = originalText;
|
|
389
407
|
if (modifier) {
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
});
|
|
408
|
+
const lastTextPart = lastMessage?.role === "agent" ? lastMessage.parts?.findLast(
|
|
409
|
+
(p) => p.type === "text"
|
|
410
|
+
) : void 0;
|
|
411
|
+
const currentFullText = lastTextPart?._rawText ?? lastTextPart?.text ?? "";
|
|
412
|
+
text = modifier(originalText, currentFullText, meta);
|
|
396
413
|
}
|
|
397
414
|
const newPart = {
|
|
398
415
|
type: "text",
|
|
@@ -402,17 +419,53 @@ function handleTextDelta(event, setMessages, syncSessionRef, modifier, agentId)
|
|
|
402
419
|
};
|
|
403
420
|
let updatedMessages;
|
|
404
421
|
if (lastMessage?.role === "agent") {
|
|
422
|
+
const lastTextPart = lastMessage.parts?.findLast(
|
|
423
|
+
(p) => p.type === "text"
|
|
424
|
+
);
|
|
425
|
+
const prevRaw = lastTextPart?._rawText ?? lastTextPart?.text ?? "";
|
|
426
|
+
const rawText = prevRaw + text;
|
|
427
|
+
let updatedParts = updateAgentMessageParts(lastMessage.parts || [], newPart);
|
|
428
|
+
let displayContent = rawText;
|
|
429
|
+
if (fullTextModifier) {
|
|
430
|
+
displayContent = fullTextModifier(rawText, meta);
|
|
431
|
+
const textParts = updatedParts.filter(
|
|
432
|
+
(p) => p.type === "text"
|
|
433
|
+
);
|
|
434
|
+
const nonTextParts = updatedParts.filter((p) => p.type !== "text");
|
|
435
|
+
const modifiedTextPart = {
|
|
436
|
+
type: "text",
|
|
437
|
+
text: displayContent,
|
|
438
|
+
_rawText: rawText,
|
|
439
|
+
firstSequence: textParts[0]?.firstSequence ?? sequence,
|
|
440
|
+
lastSequence: textParts[textParts.length - 1]?.lastSequence ?? sequence
|
|
441
|
+
};
|
|
442
|
+
updatedParts = [...nonTextParts, modifiedTextPart];
|
|
443
|
+
}
|
|
405
444
|
const updatedMessage = {
|
|
406
445
|
...lastMessage,
|
|
407
|
-
content:
|
|
408
|
-
parts:
|
|
446
|
+
content: displayContent,
|
|
447
|
+
parts: updatedParts
|
|
409
448
|
};
|
|
410
449
|
updatedMessages = [...prev.slice(0, -1), updatedMessage];
|
|
411
450
|
} else {
|
|
451
|
+
let displayContent = text;
|
|
452
|
+
let parts = [newPart];
|
|
453
|
+
if (fullTextModifier) {
|
|
454
|
+
displayContent = fullTextModifier(text, meta);
|
|
455
|
+
parts = [
|
|
456
|
+
{
|
|
457
|
+
type: "text",
|
|
458
|
+
text: displayContent,
|
|
459
|
+
_rawText: text,
|
|
460
|
+
firstSequence: sequence,
|
|
461
|
+
lastSequence: sequence
|
|
462
|
+
}
|
|
463
|
+
];
|
|
464
|
+
}
|
|
412
465
|
const updatedMessage = {
|
|
413
466
|
role: "agent",
|
|
414
|
-
content:
|
|
415
|
-
parts
|
|
467
|
+
content: displayContent,
|
|
468
|
+
parts,
|
|
416
469
|
executionId: eventExecutionId
|
|
417
470
|
};
|
|
418
471
|
updatedMessages = [...prev, updatedMessage];
|
|
@@ -425,7 +478,7 @@ function handleTextDelta(event, setMessages, syncSessionRef, modifier, agentId)
|
|
|
425
478
|
}
|
|
426
479
|
function handleClientToolCall(event, setMessages, syncSessionRef, toolContext, agentId) {
|
|
427
480
|
const tool = toolContext?.getTool(agentId, event.data.toolName);
|
|
428
|
-
if (!tool?.render) return;
|
|
481
|
+
if (!tool?.render && !event.data.paused) return;
|
|
429
482
|
setMessages((prev) => {
|
|
430
483
|
const lastMessage = prev[prev.length - 1];
|
|
431
484
|
const newPart = {
|
|
@@ -524,7 +577,8 @@ function useAgent(agent, options) {
|
|
|
524
577
|
syncSessionRef: sessionUtils.syncSessionRef,
|
|
525
578
|
debugHandlers,
|
|
526
579
|
toolContext,
|
|
527
|
-
textDeltaModifier: optionsRef.current?.textDeltaModifier
|
|
580
|
+
textDeltaModifier: optionsRef.current?.textDeltaModifier,
|
|
581
|
+
fullTextModifier: optionsRef.current?.fullTextModifier
|
|
528
582
|
};
|
|
529
583
|
const callbacks = buildStreamCallbacks(deps, debugKey);
|
|
530
584
|
const executeOptions = {
|