paprflare-sdk 0.0.18 → 0.0.19

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.d.mts CHANGED
@@ -1196,7 +1196,7 @@ declare function measureTime<T>(fn: () => Promise<T>): Promise<{
1196
1196
  }>;
1197
1197
 
1198
1198
  /**
1199
- * StreamWriter Events with UI Animation Support
1199
+ * StreamWriter Events
1200
1200
  */
1201
1201
  interface StreamWriterEvents {
1202
1202
  write: (text: string) => void;
@@ -1208,219 +1208,67 @@ interface StreamWriterEvents {
1208
1208
  }) => void;
1209
1209
  done: (message: any) => void;
1210
1210
  start: () => void;
1211
- pause: () => void;
1212
- resume: () => void;
1213
- progress: (data: ProgressData) => void;
1214
- thinking: (status: ThinkingStatus) => void;
1215
1211
  toolUse: (tool: ToolUseData) => void;
1216
1212
  toolResult: (result: ToolResultData) => void;
1217
- metadata: (meta: MetadataEvent) => void;
1218
1213
  chunk: (chunk: ChunkData) => void;
1219
- speed: (wpm: number) => void;
1220
1214
  statusChange: (status: StreamStatus) => void;
1221
1215
  }
1222
1216
  /**
1223
1217
  * Stream Status
1224
1218
  */
1225
- type StreamStatus = 'idle' | 'starting' | 'streaming' | 'thinking' | 'tool_executing' | 'paused' | 'resuming' | 'completing' | 'done' | 'error';
1226
- /**
1227
- * Progress Data
1228
- */
1229
- interface ProgressData {
1230
- /** Current character count */
1231
- characters: number;
1232
- /** Current word count */
1233
- words: number;
1234
- /** Estimated completion percentage (0-100) */
1235
- percentage: number;
1236
- /** Time elapsed in ms */
1237
- elapsed: number;
1238
- /** Estimated time remaining in ms */
1239
- estimatedRemaining?: number;
1240
- }
1241
- /**
1242
- * Thinking Status
1243
- */
1244
- interface ThinkingStatus {
1245
- /** Is currently thinking */
1246
- isThinking: boolean;
1247
- /** Thinking message/phase */
1248
- message?: string;
1249
- /** Duration in ms */
1250
- duration?: number;
1251
- }
1219
+ type StreamStatus = 'idle' | 'starting' | 'streaming' | 'tool_executing' | 'completing' | 'done' | 'error';
1252
1220
  /**
1253
1221
  * Tool Use Data
1254
1222
  */
1255
1223
  interface ToolUseData {
1256
- /** Tool ID */
1257
1224
  id: string;
1258
- /** Tool name */
1259
1225
  name: string;
1260
- /** Tool input parameters */
1261
1226
  input: any;
1262
- /** Tool status */
1263
1227
  status: 'starting' | 'running' | 'completed' | 'failed';
1264
- /** Timestamp */
1265
1228
  timestamp: number;
1266
1229
  }
1267
1230
  /**
1268
1231
  * Tool Result Data
1269
1232
  */
1270
1233
  interface ToolResultData {
1271
- /** Tool ID */
1272
1234
  toolId: string;
1273
- /** Result content */
1274
1235
  content: any;
1275
- /** Success status */
1276
1236
  success: boolean;
1277
- /** Error message if failed */
1278
1237
  error?: string;
1279
- /** Execution duration in ms */
1280
1238
  duration: number;
1281
- /** Timestamp */
1282
- timestamp: number;
1283
- }
1284
- /**
1285
- * Metadata Event
1286
- */
1287
- interface MetadataEvent {
1288
- /** Event type */
1289
- type: 'model' | 'temperature' | 'maxTokens' | 'custom';
1290
- /** Event data */
1291
- data: any;
1292
- /** Timestamp */
1293
1239
  timestamp: number;
1294
1240
  }
1295
1241
  /**
1296
1242
  * Chunk Data
1297
1243
  */
1298
1244
  interface ChunkData {
1299
- /** Chunk text */
1300
1245
  text: string;
1301
- /** Chunk index */
1302
1246
  index: number;
1303
- /** Chunk timestamp */
1304
1247
  timestamp: number;
1305
- /** Time since last chunk (ms) */
1306
1248
  deltaTime: number;
1307
1249
  }
1308
- /**
1309
- * Animation Options
1310
- */
1311
- interface AnimationOptions {
1312
- /** Enable typing animation effect */
1313
- typing?: boolean;
1314
- /** Typing speed in characters per second */
1315
- typingSpeed?: number;
1316
- /** Enable cursor animation */
1317
- cursor?: boolean;
1318
- /** Cursor character */
1319
- cursorChar?: string;
1320
- /** Cursor blink interval in ms */
1321
- cursorBlinkInterval?: number;
1322
- /** Enable smooth scroll */
1323
- smoothScroll?: boolean;
1324
- /** Enable word highlighting */
1325
- highlightWords?: boolean;
1326
- /** Highlight duration in ms */
1327
- highlightDuration?: number;
1328
- }
1329
- /**
1330
- * Auto-output options
1331
- */
1332
- interface AutoOutputOptions {
1333
- /** Enable automatic console output (default: true) */
1334
- enabled?: boolean;
1335
- /** Show usage information (default: true) */
1336
- showUsage?: boolean;
1337
- /** Show final message (default: true) */
1338
- showFinalMessage?: boolean;
1339
- /** Show progress updates (default: true) */
1340
- showProgress?: boolean;
1341
- /** Progress update interval in ms (default: 500) */
1342
- progressInterval?: number;
1343
- /** Show thinking status (default: true) */
1344
- showThinking?: boolean;
1345
- /** Show tool execution (default: true) */
1346
- showTools?: boolean;
1347
- /** Show speed metrics (default: false) */
1348
- showSpeed?: boolean;
1349
- /** Animation options */
1350
- animation?: AnimationOptions;
1351
- /** Custom text output handler */
1352
- onText?: (text: string) => void;
1353
- /** Custom error handler */
1354
- onError?: (error: string) => void;
1355
- /** Custom usage handler */
1356
- onUsage?: (tokens: {
1357
- prompt: number;
1358
- completion: number;
1359
- total: number;
1360
- }) => void;
1361
- /** Custom done handler */
1362
- onDone?: (message: any) => void;
1363
- /** Custom progress handler */
1364
- onProgress?: (data: ProgressData) => void;
1365
- /** Custom thinking handler */
1366
- onThinking?: (status: ThinkingStatus) => void;
1367
- /** Custom tool use handler */
1368
- onToolUse?: (tool: ToolUseData) => void;
1369
- /** Custom tool result handler */
1370
- onToolResult?: (result: ToolResultData) => void;
1371
- /** Custom status change handler */
1372
- onStatusChange?: (status: StreamStatus) => void;
1373
- }
1374
1250
 
1375
1251
  /**
1376
- * Enhanced StreamWriter with UI Animation Support
1377
- * Provides real-time events for live UI updates and animations
1252
+ * StreamWriter for handling streaming text and tool execution
1253
+ * Provides real-time events for live UI updates
1378
1254
  */
1379
1255
  declare class StreamWriter extends EventEmitter$1<StreamWriterEvents> {
1380
1256
  private events;
1381
1257
  private closed;
1382
1258
  private fullText;
1383
- private autoOutput;
1384
- private animation;
1385
- private status;
1386
1259
  private startTime;
1387
1260
  private lastChunkTime;
1388
1261
  private chunkIndex;
1389
- private paused;
1390
- private pauseStartTime;
1391
- private totalPauseDuration;
1392
- private progressInterval?;
1393
- private speedCalculationWindow;
1394
- private currentWPM;
1395
- private thinkingStartTime?;
1262
+ private status;
1396
1263
  private activeTools;
1397
1264
  private currentToolCall;
1398
- private cursorInterval?;
1399
- private typingQueue;
1400
- private isTyping;
1401
- constructor(options?: AutoOutputOptions);
1402
- /**
1403
- * Default handlers
1404
- */
1405
- private defaultTextHandler;
1406
- private defaultErrorHandler;
1407
- private defaultUsageHandler;
1408
- private defaultDoneHandler;
1409
- private defaultProgressHandler;
1410
- private defaultThinkingHandler;
1411
- private defaultToolUseHandler;
1412
- private defaultToolResultHandler;
1413
- private defaultStatusChangeHandler;
1414
- /**
1415
- * Set up automatic event listeners
1416
- */
1417
- private setupAutoListeners;
1265
+ constructor();
1418
1266
  /**
1419
1267
  * Start the stream
1420
1268
  */
1421
1269
  start(): void;
1422
1270
  /**
1423
- * Write text content (method used by providers)
1271
+ * Write text content
1424
1272
  */
1425
1273
  writeText(text: string): void;
1426
1274
  /**
@@ -1439,34 +1287,30 @@ declare class StreamWriter extends EventEmitter$1<StreamWriterEvents> {
1439
1287
  * End a tool call with final arguments
1440
1288
  */
1441
1289
  endToolCall(args: Record<string, unknown>): void;
1442
- /**
1443
- * Write usage information
1444
- */
1445
- writeUsage(tokens: {
1446
- promptTokens: number;
1447
- completionTokens: number;
1448
- totalTokens: number;
1449
- }): void;
1450
- /**
1451
- * Set thinking status
1452
- */
1453
- setThinking(isThinking: boolean, message?: string): void;
1454
1290
  /**
1455
1291
  * Legacy startTool method (for backward compatibility)
1456
1292
  */
1457
1293
  startTool(id: string, name: string, input: any): void;
1458
1294
  /**
1459
- * Legacy completeTool method (for backward compatibility)
1295
+ * Complete a tool (legacy method for backward compatibility)
1460
1296
  */
1461
1297
  completeTool(toolId: string, content: any, success?: boolean, error?: string): void;
1462
1298
  /**
1463
- * Pause the stream
1299
+ * Write usage information
1464
1300
  */
1465
- pause(): void;
1301
+ writeUsage(tokens: {
1302
+ promptTokens: number;
1303
+ completionTokens: number;
1304
+ totalTokens: number;
1305
+ }): void;
1466
1306
  /**
1467
- * Resume the stream
1307
+ * Legacy usage method (for backward compatibility)
1468
1308
  */
1469
- resume(): void;
1309
+ usage(tokens: {
1310
+ prompt: number;
1311
+ completion: number;
1312
+ total: number;
1313
+ }): void;
1470
1314
  /**
1471
1315
  * Write error
1472
1316
  */
@@ -1480,18 +1324,6 @@ declare class StreamWriter extends EventEmitter$1<StreamWriterEvents> {
1480
1324
  * Mark stream as done
1481
1325
  */
1482
1326
  done(finalMessage?: any): void;
1483
- /**
1484
- * Legacy usage method (for backward compatibility)
1485
- */
1486
- usage(tokens: {
1487
- prompt: number;
1488
- completion: number;
1489
- total: number;
1490
- }): void;
1491
- /**
1492
- * Add custom metadata
1493
- */
1494
- metadata(type: MetadataEvent['type'], data: any): void;
1495
1327
  /**
1496
1328
  * Update stream status
1497
1329
  */
@@ -1500,46 +1332,10 @@ declare class StreamWriter extends EventEmitter$1<StreamWriterEvents> {
1500
1332
  * Get current status
1501
1333
  */
1502
1334
  getStatus(): StreamStatus;
1503
- /**
1504
- * Start progress tracking
1505
- */
1506
- private startProgressTracking;
1507
- /**
1508
- * Update speed calculation
1509
- */
1510
- private updateSpeed;
1511
- /**
1512
- * Typing animation
1513
- */
1514
- private queueTyping;
1515
- private processTypingQueue;
1516
- /**
1517
- * Cursor animation
1518
- */
1519
- private startCursorAnimation;
1520
- private stopCursorAnimation;
1521
- /**
1522
- * Helper methods
1523
- */
1524
- private countWords;
1525
- private createProgressBar;
1526
- private sleep;
1527
- /**
1528
- * Get current speed (WPM)
1529
- */
1530
- getSpeed(): number;
1531
- /**
1532
- * Get progress data
1533
- */
1534
- getProgress(): ProgressData;
1535
1335
  /**
1536
1336
  * Check if stream is closed
1537
1337
  */
1538
1338
  isClosed(): boolean;
1539
- /**
1540
- * Check if stream is paused
1541
- */
1542
- isPaused(): boolean;
1543
1339
  /**
1544
1340
  * Get accumulated text
1545
1341
  */
@@ -1548,31 +1344,23 @@ declare class StreamWriter extends EventEmitter$1<StreamWriterEvents> {
1548
1344
  * Get active tools
1549
1345
  */
1550
1346
  getActiveTools(): ToolUseData[];
1551
- /**
1552
- * Convert to async generator (legacy method)
1553
- */
1554
- toGenerator(): AsyncGenerator<StreamEvent>;
1555
1347
  /**
1556
1348
  * Get all events
1557
1349
  */
1558
1350
  getEvents(): StreamEvent[];
1559
1351
  /**
1560
- * Reset the writer
1561
- */
1562
- reset(): void;
1563
- /**
1564
- * Disable auto-output
1352
+ * Convert to async generator (legacy method)
1565
1353
  */
1566
- disableAutoOutput(): void;
1354
+ toGenerator(): AsyncGenerator<StreamEvent>;
1567
1355
  /**
1568
- * Enable auto-output
1356
+ * Reset the writer
1569
1357
  */
1570
- enableAutoOutput(): void;
1358
+ reset(): void;
1571
1359
  }
1572
1360
  /**
1573
1361
  * Create StreamWriter instance
1574
1362
  */
1575
- declare function createStreamWriter(options?: AutoOutputOptions): StreamWriter;
1363
+ declare function createStreamWriter(): StreamWriter;
1576
1364
 
1577
1365
  /**
1578
1366
  * Parse SSE stream into structured events
@@ -1667,12 +1455,6 @@ type UIStreamEvent = {
1667
1455
  } | {
1668
1456
  type: 'message-complete';
1669
1457
  message: UIMessage;
1670
- } | {
1671
- type: 'progress';
1672
- progress: ProgressData;
1673
- } | {
1674
- type: 'thinking';
1675
- status: ThinkingStatus;
1676
1458
  } | {
1677
1459
  type: 'status-change';
1678
1460
  status: StreamStatus;
@@ -1714,8 +1496,6 @@ interface StreamHandlers {
1714
1496
  completion: number;
1715
1497
  total: number;
1716
1498
  }) => void | Promise<void>;
1717
- onProgress?: (progress: ProgressData) => void | Promise<void>;
1718
- onThinking?: (status: ThinkingStatus) => void | Promise<void>;
1719
1499
  onStatusChange?: (status: StreamStatus) => void | Promise<void>;
1720
1500
  }
1721
1501
  /**
@@ -1742,7 +1522,6 @@ declare function processStream(stream: AsyncGenerator<StreamEvent>, handlers: St
1742
1522
  declare function collectText(stream: AsyncGenerator<StreamEvent>): Promise<string>;
1743
1523
  /**
1744
1524
  * Create UI message stream with advanced control and live updates
1745
- * Similar to Vercel AI SDK's createStreamableUI
1746
1525
  *
1747
1526
  * @example
1748
1527
  * const stream = createUIMessageStream({
@@ -1767,37 +1546,17 @@ declare function createUIMessageStream(options: {
1767
1546
  onFinish?: (result: {
1768
1547
  message: UIMessage;
1769
1548
  }) => void | Promise<void>;
1770
- onProgress?: (progress: ProgressData) => void | Promise<void>;
1771
- onThinking?: (status: ThinkingStatus) => void | Promise<void>;
1772
1549
  onToolUse?: (tool: ToolUseData) => void | Promise<void>;
1773
1550
  onToolResult?: (result: ToolResultData) => void | Promise<void>;
1774
1551
  onStatusChange?: (status: StreamStatus) => void | Promise<void>;
1775
- onSpeed?: (wpm: number) => void | Promise<void>;
1776
- writerOptions?: Partial<AutoOutputOptions>;
1777
1552
  }): AsyncGenerator<UIStreamEvent>;
1778
1553
  /**
1779
- * Stream to console with formatting and live updates
1554
+ * Stream to console with formatting
1780
1555
  *
1781
1556
  * @example
1782
- * await streamToConsole(response.stream, {
1783
- * showUsage: true,
1784
- * showProgress: true,
1785
- * showThinking: true,
1786
- * });
1557
+ * await streamToConsole(response.stream);
1787
1558
  */
1788
- declare function streamToConsole(stream: AsyncGenerator<StreamEvent>, options?: {
1789
- showUsage?: boolean;
1790
- showProgress?: boolean;
1791
- showThinking?: boolean;
1792
- showTools?: boolean;
1793
- showSpeed?: boolean;
1794
- colors?: boolean;
1795
- animation?: {
1796
- typing?: boolean;
1797
- typingSpeed?: number;
1798
- cursor?: boolean;
1799
- };
1800
- }): Promise<void>;
1559
+ declare function streamToConsole(stream: AsyncGenerator<StreamEvent>): Promise<void>;
1801
1560
  /**
1802
1561
  * Convert stream to HTTP Response (one-liner for API routes)
1803
1562
  * Works with Next.js, Express, Node.js HTTP, etc.
@@ -1818,7 +1577,7 @@ declare function streamToConsole(stream: AsyncGenerator<StreamEvent>, options?:
1818
1577
  */
1819
1578
  declare function toHTTPResponse(stream: AsyncGenerator<StreamEvent>, target?: any): Promise<Response | void>;
1820
1579
  /**
1821
- * Create a streamable value (like Vercel AI SDK)
1580
+ * Create a streamable value
1822
1581
  *
1823
1582
  * @example
1824
1583
  * const stream = createStreamableValue('initial');