MCPcopy
hub / github.com/benjitaylor/agentation / streamText

Function streamText

package/example/src/app/components/FeaturesDemo.tsx:2865–2888  ·  view source on GitHub ↗
(textLength: number)

Source from the content-addressed store, hash-verified

2863 let msgCount = 0;
2864
2865 const streamText = async (textLength: number) => {
2866 const targetIndex = msgCount - 1;
2867 const duration = 500 + textLength * 8; // Longer text = longer duration
2868 const startTime = Date.now();
2869
2870 const animate = () => {
2871 if (cancelled) return;
2872 const elapsed = Date.now() - startTime;
2873 const progress = Math.min(elapsed / duration, 1);
2874 // Ease out for smoother ending
2875 const easedProgress = 1 - Math.pow(1 - progress, 2);
2876
2877 setMessages(prev => prev.map((m, idx) =>
2878 idx === targetIndex ? { ...m, progress: easedProgress } : m
2879 ));
2880
2881 if (progress < 1) {
2882 requestAnimationFrame(animate);
2883 }
2884 };
2885
2886 requestAnimationFrame(animate);
2887 await delay(duration);
2888 };
2889
2890 const runAnimation = async () => {
2891 setMessages([]);

Callers 1

runAnimationFunction · 0.85

Calls 1

delayFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…