@nuvin/nuvin-core 1.5.2 → 1.6.1

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.ts CHANGED
@@ -54,12 +54,14 @@ type SpecialistAgentResult = {
54
54
  result: string;
55
55
  metadata: {
56
56
  agentId: string;
57
+ agentName: string;
57
58
  tokensUsed?: number;
58
59
  toolCallsExecuted: number;
59
60
  executionTimeMs: number;
60
61
  conversationHistory?: Message[];
61
62
  events?: AgentEvent[];
62
63
  errorMessage?: string;
64
+ metrics?: MetricsSnapshot;
63
65
  };
64
66
  };
65
67
  /**
@@ -193,6 +195,220 @@ declare class AgentRegistry {
193
195
  exists(agentId: string): boolean;
194
196
  }
195
197
 
198
+ /**
199
+ * Type definitions for tool call arguments/parameters
200
+ * These types represent the parameters passed to each tool
201
+ *
202
+ * These are useful for:
203
+ * - Type-safe tool call argument parsing
204
+ * - UI rendering of tool calls with proper parameter display
205
+ * - Validation of tool inputs
206
+ */
207
+ type BashToolArgs = {
208
+ cmd: string;
209
+ cwd?: string;
210
+ timeoutMs?: number;
211
+ description?: string;
212
+ };
213
+ type FileReadArgs = {
214
+ path: string;
215
+ lineStart?: number;
216
+ lineEnd?: number;
217
+ description?: string;
218
+ };
219
+ type FileEditArgs = {
220
+ file_path: string;
221
+ old_text: string;
222
+ new_text: string;
223
+ dry_run?: boolean;
224
+ description?: string;
225
+ };
226
+ type FileNewArgs = {
227
+ file_path: string;
228
+ content: string;
229
+ description?: string;
230
+ };
231
+ type DirLsArgs = {
232
+ path?: string;
233
+ limit?: number;
234
+ description?: string;
235
+ };
236
+ type WebSearchArgs = {
237
+ query: string;
238
+ count?: number;
239
+ offset?: number;
240
+ domains?: string[];
241
+ recencyDays?: number;
242
+ lang?: string;
243
+ region?: string;
244
+ safe?: boolean;
245
+ type?: 'web' | 'images';
246
+ hydrateMeta?: boolean;
247
+ description?: string;
248
+ };
249
+ type WebFetchArgs = {
250
+ url: string;
251
+ description?: string;
252
+ };
253
+ type TodoWriteArgs = {
254
+ todos: Array<{
255
+ id: string;
256
+ content: string;
257
+ status: 'pending' | 'in_progress' | 'completed';
258
+ priority: 'high' | 'medium' | 'low';
259
+ createdAt?: string;
260
+ }>;
261
+ description?: string;
262
+ };
263
+ type AssignTaskArgs = {
264
+ agent: string;
265
+ task: string;
266
+ description: string;
267
+ };
268
+ type ToolArguments = BashToolArgs | FileReadArgs | FileEditArgs | FileNewArgs | DirLsArgs | WebSearchArgs | WebFetchArgs | TodoWriteArgs | AssignTaskArgs;
269
+ /**
270
+ * Type guard to safely parse tool arguments
271
+ */
272
+ declare function parseToolArguments(args: string | unknown): ToolArguments;
273
+ /**
274
+ * Type guards for specific tool arguments
275
+ */
276
+ declare function isBashToolArgs(args: ToolArguments): args is BashToolArgs;
277
+ declare function isFileReadArgs(args: ToolArguments): args is FileReadArgs;
278
+ declare function isFileEditArgs(args: ToolArguments): args is FileEditArgs;
279
+ declare function isFileNewArgs(args: ToolArguments): args is FileNewArgs;
280
+ declare function isTodoWriteArgs(args: ToolArguments): args is TodoWriteArgs;
281
+ declare function isAssignTaskArgs(args: ToolArguments): args is AssignTaskArgs;
282
+ declare function isWebSearchArgs(args: ToolArguments): args is WebSearchArgs;
283
+ declare function isWebFetchArgs(args: ToolArguments): args is WebFetchArgs;
284
+ declare function isDirLsArgs(args: ToolArguments): args is DirLsArgs;
285
+ type ToolParameterMap = {
286
+ bash_tool: BashToolArgs;
287
+ file_read: FileReadArgs;
288
+ file_edit: FileEditArgs;
289
+ file_new: FileNewArgs;
290
+ dir_ls: DirLsArgs;
291
+ web_search: WebSearchArgs;
292
+ web_fetch: WebFetchArgs;
293
+ todo_write: TodoWriteArgs;
294
+ assign_task: AssignTaskArgs;
295
+ };
296
+ type ToolName = keyof ToolParameterMap;
297
+ type TypedToolInvocation<T extends ToolName = ToolName> = {
298
+ id: string;
299
+ name: T;
300
+ parameters: ToolParameterMap[T];
301
+ };
302
+
303
+ type FileMetadata = {
304
+ path: string;
305
+ created?: string;
306
+ modified?: string;
307
+ size?: number;
308
+ };
309
+ type LineRangeMetadata = {
310
+ lineStart: number;
311
+ lineEnd: number;
312
+ linesTotal?: number;
313
+ };
314
+ type CommandMetadata = {
315
+ cwd?: string;
316
+ code?: number | null;
317
+ signal?: string | null;
318
+ timedOut?: boolean;
319
+ };
320
+ type ErrorMetadata = {
321
+ errorReason?: ErrorReason;
322
+ code?: string | number;
323
+ stackTrace?: string;
324
+ retryable?: boolean;
325
+ };
326
+ type DelegationMetadata = {
327
+ agentId: string;
328
+ agentName: string;
329
+ delegationDepth: number;
330
+ status: 'success' | 'error' | 'timeout';
331
+ executionTimeMs: number;
332
+ toolCallsExecuted: number;
333
+ tokensUsed?: number;
334
+ metrics?: MetricsSnapshot;
335
+ taskDescription: string;
336
+ provider?: string;
337
+ model?: string;
338
+ conversationHistoryLength?: number;
339
+ eventsEmitted?: number;
340
+ };
341
+
342
+ type BashToolMetadata = CommandMetadata & {
343
+ stdout?: string;
344
+ stderr?: string;
345
+ stripped?: boolean;
346
+ };
347
+ type FileReadMetadata = FileMetadata & {
348
+ lineRange?: LineRangeMetadata;
349
+ encoding?: string;
350
+ bomStripped?: boolean;
351
+ };
352
+ type FileEditMetadata = FileMetadata & {
353
+ changesMade?: {
354
+ linesAdded: number;
355
+ linesRemoved: number;
356
+ bytesChanged: number;
357
+ };
358
+ backup?: {
359
+ path: string;
360
+ created: string;
361
+ };
362
+ };
363
+ type FileNewMetadata = FileMetadata & {
364
+ overwritten?: boolean;
365
+ };
366
+ type DirLsMetadata = {
367
+ path: string;
368
+ totalEntries?: number;
369
+ entriesReturned?: number;
370
+ truncated?: boolean;
371
+ };
372
+ type WebSearchMetadata = {
373
+ query: string;
374
+ totalResults?: number;
375
+ resultsReturned: number;
376
+ searchTime?: number;
377
+ provider?: string;
378
+ };
379
+ type WebFetchMetadata = {
380
+ url: string;
381
+ statusCode?: number;
382
+ contentType?: string;
383
+ contentLength?: number;
384
+ fetchTime?: number;
385
+ markdown?: boolean;
386
+ };
387
+ type TodoWriteMetadata = {
388
+ todosWritten: number;
389
+ conversationId?: string;
390
+ };
391
+ type AssignTaskMetadata = DelegationMetadata;
392
+ type ToolErrorMetadata = {
393
+ errorReason?: ErrorReason;
394
+ path?: string;
395
+ agentId?: string;
396
+ code?: string | number;
397
+ stackTrace?: string;
398
+ retryable?: boolean;
399
+ };
400
+ type ToolMetadataMap = {
401
+ bash_tool: BashToolMetadata;
402
+ file_read: FileReadMetadata;
403
+ file_edit: FileEditMetadata;
404
+ file_new: FileNewMetadata;
405
+ dir_ls: DirLsMetadata;
406
+ web_search: WebSearchMetadata;
407
+ web_fetch: WebFetchMetadata;
408
+ todo_write: TodoWriteMetadata;
409
+ assign_task: AssignTaskMetadata;
410
+ };
411
+
196
412
  type ToolCall = {
197
413
  id: string;
198
414
  type: 'function';
@@ -324,7 +540,6 @@ type SendMessageOptions = {
324
540
  conversationId?: string;
325
541
  stream?: boolean;
326
542
  signal?: AbortSignal;
327
- retry?: boolean;
328
543
  };
329
544
  type UserAttachment = ImageContentPart & {
330
545
  token?: string;
@@ -366,6 +581,42 @@ type ToolDefinition = {
366
581
  };
367
582
  };
368
583
  type ToolInvocation = {
584
+ id: string;
585
+ name: 'bash_tool';
586
+ parameters: BashToolArgs;
587
+ } | {
588
+ id: string;
589
+ name: 'file_read';
590
+ parameters: FileReadArgs;
591
+ } | {
592
+ id: string;
593
+ name: 'file_edit';
594
+ parameters: FileEditArgs;
595
+ } | {
596
+ id: string;
597
+ name: 'file_new';
598
+ parameters: FileNewArgs;
599
+ } | {
600
+ id: string;
601
+ name: 'dir_ls';
602
+ parameters: DirLsArgs;
603
+ } | {
604
+ id: string;
605
+ name: 'web_search';
606
+ parameters: WebSearchArgs;
607
+ } | {
608
+ id: string;
609
+ name: 'web_fetch';
610
+ parameters: WebFetchArgs;
611
+ } | {
612
+ id: string;
613
+ name: 'todo_write';
614
+ parameters: TodoWriteArgs;
615
+ } | {
616
+ id: string;
617
+ name: 'assign_task';
618
+ parameters: AssignTaskArgs;
619
+ } | {
369
620
  id: string;
370
621
  name: string;
371
622
  parameters: Record<string, unknown>;
@@ -383,14 +634,92 @@ declare enum ErrorReason {
383
634
  Unknown = "unknown"
384
635
  }
385
636
  type ToolExecutionResult = {
637
+ id: string;
638
+ name: 'bash_tool';
639
+ status: 'success';
640
+ type: 'text';
641
+ result: string;
642
+ metadata?: BashToolMetadata;
643
+ durationMs?: number;
644
+ } | {
645
+ id: string;
646
+ name: 'file_read';
647
+ status: 'success';
648
+ type: 'text';
649
+ result: string;
650
+ metadata?: FileReadMetadata;
651
+ durationMs?: number;
652
+ } | {
653
+ id: string;
654
+ name: 'file_edit';
655
+ status: 'success';
656
+ type: 'text';
657
+ result: string;
658
+ metadata?: FileEditMetadata;
659
+ durationMs?: number;
660
+ } | {
661
+ id: string;
662
+ name: 'file_new';
663
+ status: 'success';
664
+ type: 'text';
665
+ result: string;
666
+ metadata?: FileNewMetadata;
667
+ durationMs?: number;
668
+ } | {
669
+ id: string;
670
+ name: 'dir_ls';
671
+ status: 'success';
672
+ type: 'text';
673
+ result: string;
674
+ metadata?: DirLsMetadata;
675
+ durationMs?: number;
676
+ } | {
677
+ id: string;
678
+ name: 'web_search';
679
+ status: 'success';
680
+ type: 'json';
681
+ result: Record<string, unknown> | unknown[];
682
+ metadata?: WebSearchMetadata;
683
+ durationMs?: number;
684
+ } | {
685
+ id: string;
686
+ name: 'web_fetch';
687
+ status: 'success';
688
+ type: 'text';
689
+ result: string;
690
+ metadata?: WebFetchMetadata;
691
+ durationMs?: number;
692
+ } | {
693
+ id: string;
694
+ name: 'todo_write';
695
+ status: 'success';
696
+ type: 'text';
697
+ result: string;
698
+ metadata?: TodoWriteMetadata;
699
+ durationMs?: number;
700
+ } | {
701
+ id: string;
702
+ name: 'assign_task';
703
+ status: 'success';
704
+ type: 'text';
705
+ result: string;
706
+ metadata: AssignTaskMetadata;
707
+ durationMs?: number;
708
+ } | {
386
709
  id: string;
387
710
  name: string;
388
- status: 'success' | 'error';
711
+ status: 'success';
389
712
  type: 'text' | 'json';
390
- result: string | object;
391
- metadata?: Record<string, unknown> & {
392
- errorReason?: ErrorReason;
393
- };
713
+ result: string | Record<string, unknown> | unknown[];
714
+ metadata?: Record<string, unknown>;
715
+ durationMs?: number;
716
+ } | {
717
+ id: string;
718
+ name: string;
719
+ status: 'error';
720
+ type: 'text';
721
+ result: string;
722
+ metadata?: ToolErrorMetadata;
394
723
  durationMs?: number;
395
724
  };
396
725
  interface ToolPort {
@@ -484,6 +813,7 @@ type AgentConfig = {
484
813
  maxToolConcurrency?: number;
485
814
  requireToolApproval?: boolean;
486
815
  reasoningEffort?: string;
816
+ strictToolValidation?: boolean;
487
817
  };
488
818
  declare const MessageRoles: {
489
819
  readonly System: "system";
@@ -507,6 +837,7 @@ declare const AgentEventTypes: {
507
837
  readonly SubAgentToolCall: "sub_agent_tool_call";
508
838
  readonly SubAgentToolResult: "sub_agent_tool_result";
509
839
  readonly SubAgentCompleted: "sub_agent_completed";
840
+ readonly SubAgentMetrics: "sub_agent_metrics";
510
841
  };
511
842
  type ToolApprovalDecision = 'approve' | 'deny' | 'approve_all';
512
843
  type AgentEvent = {
@@ -609,6 +940,13 @@ type AgentEvent = {
609
940
  status: 'success' | 'error' | 'timeout';
610
941
  resultMessage: string;
611
942
  totalDurationMs: number;
943
+ } | {
944
+ type: typeof AgentEventTypes.SubAgentMetrics;
945
+ conversationId: string;
946
+ messageId: string;
947
+ agentId: string;
948
+ toolCallId: string;
949
+ metrics: MetricsSnapshot;
612
950
  };
613
951
  interface EventPort {
614
952
  emit(event: AgentEvent): void | Promise<void>;
@@ -932,7 +1270,26 @@ type TodoItem = {
932
1270
  updatedAt?: string;
933
1271
  };
934
1272
 
935
- type ExecResult = Omit<ToolExecutionResult, 'id' | 'name'>;
1273
+ type ExecResultSuccess = {
1274
+ status: 'success';
1275
+ type: 'text';
1276
+ result: string;
1277
+ metadata?: Record<string, unknown>;
1278
+ } | {
1279
+ status: 'success';
1280
+ type: 'json';
1281
+ result: Record<string, unknown> | unknown[];
1282
+ metadata?: Record<string, unknown>;
1283
+ };
1284
+ type ExecResultError = {
1285
+ status: 'error';
1286
+ type: 'text';
1287
+ result: string;
1288
+ metadata?: Record<string, unknown> & {
1289
+ errorReason?: ErrorReason;
1290
+ };
1291
+ };
1292
+ type ExecResult = ExecResultSuccess | ExecResultError;
936
1293
  type ToolExecutionContext = {
937
1294
  conversationId?: string;
938
1295
  agentId?: string;
@@ -943,11 +1300,11 @@ type ToolExecutionContext = {
943
1300
  eventPort?: EventPort;
944
1301
  signal?: AbortSignal;
945
1302
  } & Record<string, unknown>;
946
- interface FunctionTool<P = Record<string, unknown>, C = ToolExecutionContext> {
1303
+ interface FunctionTool<P = Record<string, unknown>, C = ToolExecutionContext, R extends ExecResult = ExecResult> {
947
1304
  name: string;
948
1305
  parameters: object;
949
1306
  definition(): ToolDefinition['function'];
950
- execute(params: P, context?: C): Promise<ExecResult> | ExecResult;
1307
+ execute(params: P, context?: C): Promise<R> | R;
951
1308
  }
952
1309
 
953
1310
  interface AgentCatalog {
@@ -1093,10 +1450,12 @@ declare class DefaultDelegationResultFormatter implements DelegationResultFormat
1093
1450
  summary: string;
1094
1451
  metadata: {
1095
1452
  agentId: string;
1453
+ agentName: string;
1096
1454
  status: "success" | "error" | "timeout";
1097
1455
  executionTimeMs: number;
1098
1456
  toolCallsExecuted: number;
1099
1457
  tokensUsed: number | undefined;
1458
+ metrics: MetricsSnapshot | undefined;
1100
1459
  };
1101
1460
  };
1102
1461
  formatError(error: unknown): string;
@@ -1167,7 +1526,23 @@ type BashParams = {
1167
1526
  cwd?: string;
1168
1527
  timeoutMs?: number;
1169
1528
  };
1170
- declare class BashTool implements FunctionTool<BashParams, ToolExecutionContext> {
1529
+ type BashSuccessResult$1 = {
1530
+ status: 'success';
1531
+ type: 'text';
1532
+ result: string;
1533
+ metadata?: CommandMetadata & {
1534
+ stdout?: string;
1535
+ stderr?: string;
1536
+ stripped?: boolean;
1537
+ };
1538
+ };
1539
+ type BashErrorResult = ExecResultError & {
1540
+ metadata?: CommandMetadata & {
1541
+ errorReason?: ErrorReason;
1542
+ };
1543
+ };
1544
+ type BashResult = BashSuccessResult$1 | BashErrorResult;
1545
+ declare class BashTool implements FunctionTool<BashParams, ToolExecutionContext, BashResult> {
1171
1546
  name: "bash_tool";
1172
1547
  parameters: {
1173
1548
  readonly type: "object";
@@ -1193,13 +1568,378 @@ declare class BashTool implements FunctionTool<BashParams, ToolExecutionContext>
1193
1568
  readonly required: readonly ["cmd"];
1194
1569
  };
1195
1570
  definition(): ToolDefinition['function'];
1196
- execute(p: BashParams, ctx?: ToolExecutionContext): Promise<ExecResult>;
1571
+ /**
1572
+ * Execute bash command with timeout protection
1573
+ *
1574
+ * @param p - Command parameters including cmd, cwd, and optional timeout
1575
+ * @param ctx - Execution context with optional abort signal
1576
+ * @returns Structured result with command output and execution metadata
1577
+ *
1578
+ * @example
1579
+ * ```typescript
1580
+ * const result = await bashTool.execute({ cmd: 'ls -la' });
1581
+ * if (result.status === 'success' && result.type === 'text') {
1582
+ * console.log(result.result); // command output
1583
+ * console.log(result.metadata?.code); // exit code
1584
+ * console.log(result.metadata?.cwd); // working directory
1585
+ * }
1586
+ * ```
1587
+ */
1588
+ execute(p: BashParams, ctx?: ToolExecutionContext): Promise<BashResult>;
1197
1589
  private execOnce;
1198
1590
  private defaultShell;
1199
1591
  private shellExists;
1200
1592
  private shellArgs;
1201
1593
  }
1202
1594
 
1595
+ type ParseResult<T = unknown> = {
1596
+ success: true;
1597
+ data: T;
1598
+ } | {
1599
+ success: false;
1600
+ error: string;
1601
+ };
1602
+ declare function parseJSON(jsonString: string): ParseResult<Record<string, unknown>>;
1603
+
1604
+ type ValidationResult<T = unknown> = {
1605
+ valid: true;
1606
+ data: T;
1607
+ } | {
1608
+ valid: false;
1609
+ errors: string[];
1610
+ };
1611
+ type ToolValidator<T extends ToolName> = (params: Record<string, unknown>) => ValidationResult<ToolParameterMap[T]>;
1612
+ declare const toolValidators: Partial<{
1613
+ [K in ToolName]: ToolValidator<K>;
1614
+ }>;
1615
+
1616
+ type ToolCallValidation = {
1617
+ valid: true;
1618
+ invocation: ToolInvocation;
1619
+ } | {
1620
+ valid: false;
1621
+ error: string;
1622
+ errorType: 'parse' | 'validation' | 'unknown';
1623
+ callId: string;
1624
+ toolName: string;
1625
+ rawArguments?: string;
1626
+ };
1627
+ declare function convertToolCall(toolCall: ToolCall, options?: {
1628
+ strict?: boolean;
1629
+ }): ToolCallValidation;
1630
+ declare function convertToolCalls(toolCalls: ToolCall[], options?: {
1631
+ strict?: boolean;
1632
+ throwOnError?: boolean;
1633
+ }): ToolInvocation[];
1634
+
1635
+ type FileReadParams = {
1636
+ path: string;
1637
+ lineStart?: number;
1638
+ lineEnd?: number;
1639
+ };
1640
+ type FileReadSuccessResult$1 = {
1641
+ status: 'success';
1642
+ type: 'text';
1643
+ result: string;
1644
+ metadata?: FileMetadata & {
1645
+ lineRange?: LineRangeMetadata;
1646
+ encoding?: string;
1647
+ bomStripped?: boolean;
1648
+ };
1649
+ };
1650
+ type FileReadErrorResult = ExecResultError & {
1651
+ metadata?: {
1652
+ path?: string;
1653
+ errorReason?: ErrorReason;
1654
+ };
1655
+ };
1656
+ type FileReadResult = FileReadSuccessResult$1 | FileReadErrorResult;
1657
+
1658
+ type FileEditSuccessResult$1 = {
1659
+ status: 'success';
1660
+ type: 'text';
1661
+ result: string;
1662
+ metadata: FileMetadata & {
1663
+ eol: 'lf' | 'crlf';
1664
+ oldTextLength: number;
1665
+ newTextLength: number;
1666
+ bytesWritten: number;
1667
+ beforeSha: string;
1668
+ afterSha: string;
1669
+ dryRun: boolean;
1670
+ lineNumbers: {
1671
+ oldStartLine: number;
1672
+ oldEndLine: number;
1673
+ newStartLine: number;
1674
+ newEndLine: number;
1675
+ oldLineCount: number;
1676
+ newLineCount: number;
1677
+ };
1678
+ noChange?: boolean;
1679
+ };
1680
+ };
1681
+ type FileEditResult = FileEditSuccessResult$1 | ExecResultError;
1682
+
1683
+ type FileNewParams = {
1684
+ file_path: string;
1685
+ content: string;
1686
+ };
1687
+ type FileNewSuccessResult$1 = {
1688
+ status: 'success';
1689
+ type: 'text';
1690
+ result: string;
1691
+ metadata: {
1692
+ file_path: string;
1693
+ bytes: number;
1694
+ created: string;
1695
+ overwritten?: boolean;
1696
+ };
1697
+ };
1698
+ type FileNewResult = FileNewSuccessResult$1 | ExecResultError;
1699
+
1700
+ type DirLsParams = {
1701
+ path?: string;
1702
+ limit?: number;
1703
+ };
1704
+ type DirEntry = {
1705
+ name: string;
1706
+ type: 'file' | 'directory' | 'symlink' | 'other';
1707
+ size?: number;
1708
+ mtime?: number;
1709
+ mode?: number;
1710
+ lineCount?: number;
1711
+ };
1712
+ type DirLsSuccessResult$1 = {
1713
+ status: 'success';
1714
+ type: 'json';
1715
+ result: {
1716
+ path: string;
1717
+ entries: DirEntry[];
1718
+ truncated: boolean;
1719
+ total: number;
1720
+ };
1721
+ metadata?: {
1722
+ limit: number;
1723
+ includeHidden: boolean;
1724
+ };
1725
+ };
1726
+ type DirLsResult = DirLsSuccessResult$1 | ExecResultError;
1727
+
1728
+ /**
1729
+ * WebSearchTool — Google Programmable Search Engine (CSE) ONLY
1730
+ * -----------------------------------------------------------------
1731
+ * - Requires env: GOOGLE_CSE_KEY, GOOGLE_CSE_CX
1732
+ * - Supports: count (1..50, paginated 10/req), offset (0-based), domains[] -> site:
1733
+ * recencyDays -> dateRestrict, lang (hl/lr), region (gl), safe, type: web|images
1734
+ * - No HTML scraping fallback. If keys are missing, returns an error.
1735
+ */
1736
+ interface WebSearchParams {
1737
+ query: string;
1738
+ count?: number;
1739
+ offset?: number;
1740
+ domains?: string[];
1741
+ recencyDays?: number;
1742
+ lang?: string;
1743
+ region?: string;
1744
+ safe?: boolean;
1745
+ type?: 'web' | 'images';
1746
+ hydrateMeta?: boolean;
1747
+ }
1748
+ interface WebSearchResult {
1749
+ title: string;
1750
+ url: string;
1751
+ snippet?: string;
1752
+ displayUrl?: string;
1753
+ favicon?: string;
1754
+ publishedAt?: string;
1755
+ source: {
1756
+ engine: 'google-cse';
1757
+ rank: number;
1758
+ };
1759
+ }
1760
+ type WebSearchSuccessResult$1 = {
1761
+ status: 'success';
1762
+ type: 'json';
1763
+ result: {
1764
+ engine: 'google-cse';
1765
+ count: number;
1766
+ items: WebSearchResult[];
1767
+ query: string;
1768
+ appliedFilters?: {
1769
+ domains?: string[];
1770
+ recencyDays?: number;
1771
+ lang?: string;
1772
+ region?: string;
1773
+ };
1774
+ };
1775
+ metadata?: {
1776
+ offset: number;
1777
+ totalRequested: number;
1778
+ hydrated: boolean;
1779
+ };
1780
+ };
1781
+ type WebSearchToolResult = WebSearchSuccessResult$1 | ExecResultError;
1782
+
1783
+ type WebFetchParams = {
1784
+ url: string;
1785
+ };
1786
+ type WebFetchSuccessResult$1 = {
1787
+ status: 'success';
1788
+ type: 'text';
1789
+ result: string;
1790
+ metadata: {
1791
+ url: string;
1792
+ contentType: string;
1793
+ statusCode: number;
1794
+ format: 'markdown' | 'json' | 'text';
1795
+ size: number;
1796
+ fetchedAt: string;
1797
+ };
1798
+ };
1799
+ type WebFetchResult = WebFetchSuccessResult$1 | ExecResultError;
1800
+
1801
+ type TodoWriteSuccessResult$1 = {
1802
+ status: 'success';
1803
+ type: 'text';
1804
+ result: string;
1805
+ metadata: {
1806
+ recentChanges: boolean;
1807
+ stats: {
1808
+ total: number;
1809
+ pending: number;
1810
+ inProgress: number;
1811
+ completed: number;
1812
+ };
1813
+ progress: string;
1814
+ allCompleted: boolean;
1815
+ conversationId: string;
1816
+ };
1817
+ };
1818
+ type TodoWriteResult = TodoWriteSuccessResult$1 | ExecResultError;
1819
+
1820
+ type AssignSuccessResult$1 = {
1821
+ status: 'success';
1822
+ type: 'text';
1823
+ result: string;
1824
+ metadata: DelegationMetadata;
1825
+ };
1826
+ type AssignErrorResult = ExecResultError & {
1827
+ metadata?: {
1828
+ agentId?: string;
1829
+ errorReason?: ErrorReason;
1830
+ delegationDepth?: number;
1831
+ policyDenied?: boolean;
1832
+ agentNotFound?: boolean;
1833
+ };
1834
+ };
1835
+ type AssignResult = AssignSuccessResult$1 | AssignErrorResult;
1836
+
1837
+ declare function isSuccess(result: ExecResult): result is ExecResultSuccess;
1838
+ declare function isError(result: ExecResult): result is ExecResultError;
1839
+ declare function isTextResult(result: ExecResult): result is Extract<ExecResult, {
1840
+ type: 'text';
1841
+ }>;
1842
+ declare function isJsonResult(result: ExecResult): result is Extract<ExecResult, {
1843
+ type: 'json';
1844
+ }>;
1845
+ declare function isSuccessText(result: ExecResult): result is Extract<ExecResultSuccess, {
1846
+ type: 'text';
1847
+ }>;
1848
+ declare function isSuccessJson(result: ExecResult): result is Extract<ExecResultSuccess, {
1849
+ type: 'json';
1850
+ }>;
1851
+
1852
+ type WithToolExecutionFields<T extends {
1853
+ status: string;
1854
+ type: string;
1855
+ result: unknown;
1856
+ metadata?: unknown;
1857
+ }> = Omit<T, 'metadata'> & {
1858
+ id: string;
1859
+ name: string;
1860
+ durationMs?: number;
1861
+ metadata: T['metadata'];
1862
+ };
1863
+ type BashSuccessResult = WithToolExecutionFields<BashSuccessResult$1>;
1864
+ type FileReadSuccessResult = WithToolExecutionFields<FileReadSuccessResult$1>;
1865
+ type FileEditSuccessResult = WithToolExecutionFields<FileEditSuccessResult$1>;
1866
+ type FileNewSuccessResult = WithToolExecutionFields<FileNewSuccessResult$1>;
1867
+ type DirLsSuccessResult = WithToolExecutionFields<DirLsSuccessResult$1>;
1868
+ type WebSearchSuccessResult = WithToolExecutionFields<WebSearchSuccessResult$1>;
1869
+ type WebFetchSuccessResult = WithToolExecutionFields<WebFetchSuccessResult$1>;
1870
+ type TodoWriteSuccessResult = WithToolExecutionFields<TodoWriteSuccessResult$1>;
1871
+ type AssignSuccessResult = WithToolExecutionFields<AssignSuccessResult$1>;
1872
+ declare function isBashResult(result: ToolExecutionResult): result is ToolExecutionResult;
1873
+ declare function isBashSuccess(result: ToolExecutionResult): result is BashSuccessResult;
1874
+ declare function isFileReadResult(result: ToolExecutionResult): result is ToolExecutionResult;
1875
+ declare function isFileReadSuccess(result: ToolExecutionResult): result is FileReadSuccessResult;
1876
+ declare function isFileEditResult(result: ToolExecutionResult): result is ToolExecutionResult;
1877
+ declare function isFileEditSuccess(result: ToolExecutionResult): result is FileEditSuccessResult;
1878
+ declare function isFileNewResult(result: ToolExecutionResult): result is ToolExecutionResult;
1879
+ declare function isFileNewSuccess(result: ToolExecutionResult): result is FileNewSuccessResult;
1880
+ declare function isDirLsResult(result: ToolExecutionResult): result is ToolExecutionResult;
1881
+ declare function isDirLsSuccess(result: ToolExecutionResult): result is DirLsSuccessResult;
1882
+ declare function isWebSearchResult(result: ToolExecutionResult): result is ToolExecutionResult;
1883
+ declare function isWebSearchSuccess(result: ToolExecutionResult): result is WebSearchSuccessResult;
1884
+ declare function isWebFetchResult(result: ToolExecutionResult): result is ToolExecutionResult;
1885
+ declare function isWebFetchSuccess(result: ToolExecutionResult): result is WebFetchSuccessResult;
1886
+ declare function isTodoWriteResult(result: ToolExecutionResult): result is ToolExecutionResult;
1887
+ declare function isTodoWriteSuccess(result: ToolExecutionResult): result is TodoWriteSuccessResult;
1888
+ declare function isAssignResult(result: ToolExecutionResult): result is ToolExecutionResult;
1889
+ declare function isAssignSuccess(result: ToolExecutionResult): result is AssignSuccessResult;
1890
+
1891
+ declare function okText<M extends Record<string, unknown> = Record<string, unknown>>(result: string, metadata: M): {
1892
+ status: 'success';
1893
+ type: 'text';
1894
+ result: string;
1895
+ metadata: M;
1896
+ };
1897
+ declare function okJson<T extends Record<string, unknown> | unknown[], M extends Record<string, unknown> = Record<string, unknown>>(result: T, metadata?: M): {
1898
+ status: 'success';
1899
+ type: 'json';
1900
+ result: T;
1901
+ metadata?: M;
1902
+ };
1903
+ declare function err(result: string, metadata?: Record<string, unknown>, errorReason?: ErrorReason): ExecResultError;
1904
+
1905
+ /**
1906
+ * Sub-agent related types
1907
+ * These types track the state and execution of delegated specialist agents
1908
+ */
1909
+
1910
+ /**
1911
+ * Represents a tool call made by a sub-agent during execution
1912
+ */
1913
+ type SubAgentToolCall = {
1914
+ id: string;
1915
+ name: string;
1916
+ arguments?: string;
1917
+ durationMs?: number;
1918
+ status?: 'success' | 'error';
1919
+ result?: string;
1920
+ metadata?: Record<string, unknown>;
1921
+ };
1922
+ /**
1923
+ * State tracking for a sub-agent execution
1924
+ * Used by UIs to display real-time sub-agent activity
1925
+ */
1926
+ type SubAgentState = {
1927
+ agentId: string;
1928
+ agentName: string;
1929
+ status: 'starting' | 'running' | 'completed';
1930
+ toolCalls: SubAgentToolCall[];
1931
+ resultMessage?: string;
1932
+ totalDurationMs?: number;
1933
+ finalStatus?: 'success' | 'error' | 'timeout';
1934
+ toolCallMessageId?: string;
1935
+ toolCallId?: string;
1936
+ metrics?: MetricsSnapshot;
1937
+ };
1938
+ /**
1939
+ * Parse tool call arguments from string to typed object
1940
+ */
1941
+ declare function parseSubAgentToolCallArguments(argsString?: string): Record<string, unknown>;
1942
+
1203
1943
  type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
1204
1944
  type LogFormat = 'json' | 'structured';
1205
1945
  type PersistOptions = {
@@ -1253,6 +1993,38 @@ declare class GithubAuthTransport implements HttpTransport {
1253
1993
  get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
1254
1994
  }
1255
1995
 
1996
+ interface RetryConfig {
1997
+ maxRetries: number;
1998
+ baseDelayMs: number;
1999
+ maxDelayMs: number;
2000
+ backoffMultiplier: number;
2001
+ jitterFactor: number;
2002
+ retryableStatusCodes: number[];
2003
+ onRetry?: (attempt: number, error: Error, delayMs: number) => void;
2004
+ onExhausted?: (error: Error, attempts: number) => void;
2005
+ }
2006
+ declare const DEFAULT_RETRY_CONFIG: RetryConfig;
2007
+ declare class AbortError extends Error {
2008
+ constructor(message?: string);
2009
+ }
2010
+ declare class RetryTransport implements HttpTransport {
2011
+ private inner;
2012
+ private config;
2013
+ constructor(inner: HttpTransport, config?: Partial<RetryConfig>);
2014
+ get(url: string, headers?: HttpHeaders, signal?: AbortSignal): Promise<TransportResponse>;
2015
+ post(url: string, body: unknown, headers?: HttpHeaders, signal?: AbortSignal): Promise<Response>;
2016
+ private executeWithRetry;
2017
+ private isRetryableResponse;
2018
+ private getDelayForResponse;
2019
+ }
2020
+
2021
+ declare function isRetryableStatusCode(status: number, retryableStatusCodes?: number[]): boolean;
2022
+ declare function isRetryableError(error: unknown, retryableStatusCodes?: number[]): boolean;
2023
+
2024
+ interface BaseLLMOptions {
2025
+ enablePromptCaching?: boolean;
2026
+ retry?: Partial<RetryConfig>;
2027
+ }
1256
2028
  declare class LLMError extends Error {
1257
2029
  readonly statusCode?: number | undefined;
1258
2030
  readonly isRetryable: boolean;
@@ -1262,9 +2034,8 @@ declare abstract class BaseLLM implements LLMPort {
1262
2034
  protected transport: HttpTransport | null;
1263
2035
  protected apiUrl: string;
1264
2036
  protected enablePromptCaching: boolean;
1265
- constructor(apiUrl: string, options?: {
1266
- enablePromptCaching?: boolean;
1267
- });
2037
+ protected retryConfig?: Partial<RetryConfig>;
2038
+ constructor(apiUrl: string, options?: BaseLLMOptions);
1268
2039
  protected abstract createTransport(): HttpTransport;
1269
2040
  protected transformUsage(rawUsage: unknown): UsageData | undefined;
1270
2041
  protected getTransport(): HttpTransport;
@@ -1297,11 +2068,12 @@ type GithubOptions = {
1297
2068
  accessToken?: string;
1298
2069
  apiUrl?: string;
1299
2070
  httpLogFile?: string;
2071
+ retry?: Partial<RetryConfig>;
1300
2072
  };
1301
2073
  declare class GithubLLM extends BaseLLM implements LLMPort {
1302
2074
  private readonly opts;
1303
2075
  constructor(opts?: GithubOptions);
1304
- protected createTransport(): GithubAuthTransport;
2076
+ protected createTransport(): GithubAuthTransport | RetryTransport;
1305
2077
  protected transformUsage(rawUsage: unknown): UsageData | undefined;
1306
2078
  getModels(signal?: AbortSignal): Promise<ModelInfo[]>;
1307
2079
  private handleError;
@@ -1368,6 +2140,7 @@ interface LLMOptions {
1368
2140
  includeUsage?: boolean;
1369
2141
  version?: string;
1370
2142
  providerName?: string;
2143
+ retry?: Partial<RetryConfig>;
1371
2144
  }
1372
2145
  interface CustomProviderDefinition {
1373
2146
  type?: 'openai-compat' | 'anthropic';
@@ -1470,4 +2243,4 @@ declare function resolveBackspaces(s: string): string;
1470
2243
  declare function stripAnsiAndControls(s: string): string;
1471
2244
  declare function canonicalizeTerminalPaste(raw: string): string;
1472
2245
 
1473
- export { AGENT_CREATOR_SYSTEM_PROMPT, type AgentAwareToolPort, type AgentCatalog, type AgentConfig, type AgentEvent, AgentEventTypes, AgentFilePersistence, AgentManager, AgentManagerCommandRunner, AgentOrchestrator, AgentRegistry, type AgentTemplate, AnthropicAISDKLLM, type AssignParams, BashTool, type CompleteAgent, CompositeToolPort, type Conversation, ConversationContext, type ConversationMetadata, type ConversationSnapshot, ConversationStore, CoreMCPClient, DefaultDelegationPolicy, DefaultDelegationResultFormatter, DefaultDelegationService, DefaultSpecialistAgentFactory, type DelegationService, type DelegationServiceConfig, DelegationServiceFactory, ErrorReason, type FolderTreeOptions, GithubLLM, InMemoryMemory, InMemoryMetadata, InMemoryMetricsPort, JsonFileMemoryPersistence, type LLMConfig, LLMError, type LLMFactory, type LLMOptions, type LLMPort, LLMResolver, type MCPConfig, type MCPServerConfig, MCPToolPort, type MemoryPort, MemoryPortMetadataAdapter, type Message, type MessageContent, type MessageContentPart, type MetadataPort, type MetricsChangeHandler, type MetricsPort, type MetricsSnapshot, type ModelInfo, type ModelLimits, NoopMetricsPort, NoopReminders, type OrchestratorAwareToolPort, PersistedMemory, PersistingConsoleEventPort, RuntimeEnv, type SendMessageOptions, SimpleContextBuilder, SimpleCost, SimpleId, type SpecialistAgentConfig, type SpecialistAgentResult, SystemClock, type ToolApprovalDecision, type ToolCall, type ToolExecutionResult, type ToolPort, ToolRegistry, type UsageData, type UserAttachment, type UserMessagePayload, buildAgentCreationPrompt, buildInjectedSystem, canonicalizeTerminalPaste, createEmptySnapshot, createLLM, generateFolderTree, getAvailableProviders, getFallbackLimits, getProviderLabel, loadMCPConfig, normalizeModelInfo, normalizeModelLimits, normalizeNewlines, renderTemplate, resolveBackspaces, resolveCarriageReturns, stripAnsiAndControls, supportsGetModels };
2246
+ export { AGENT_CREATOR_SYSTEM_PROMPT, AbortError, type AgentAwareToolPort, type AgentCatalog, type AgentConfig, type AgentEvent, AgentEventTypes, AgentFilePersistence, AgentManager, AgentManagerCommandRunner, AgentOrchestrator, AgentRegistry, type AgentTemplate, AnthropicAISDKLLM, type AssignErrorResult, type AssignParams, type AssignResult, type AssignSuccessResult$1 as AssignSuccessResult, type AssignTaskArgs, type AssignTaskMetadata, type BaseLLMOptions, type BashErrorResult, type BashParams, type BashResult, type BashSuccessResult$1 as BashSuccessResult, BashTool, type BashToolArgs, type BashToolMetadata, type CommandMetadata, type CompleteAgent, CompositeToolPort, type Conversation, ConversationContext, type ConversationMetadata, type ConversationSnapshot, ConversationStore, CoreMCPClient, DEFAULT_RETRY_CONFIG, DefaultDelegationPolicy, DefaultDelegationResultFormatter, DefaultDelegationService, DefaultSpecialistAgentFactory, type DelegationMetadata, type DelegationService, type DelegationServiceConfig, DelegationServiceFactory, type DirEntry, type DirLsArgs, type DirLsMetadata, type DirLsParams, type DirLsResult, type DirLsSuccessResult$1 as DirLsSuccessResult, type ErrorMetadata, ErrorReason, type ExecResult, type ExecResultError, type ExecResultSuccess, type FileEditArgs, type FileEditMetadata, type FileEditResult, type FileEditSuccessResult$1 as FileEditSuccessResult, type FileMetadata, type FileNewArgs, type FileNewMetadata, type FileNewParams, type FileNewResult, type FileNewSuccessResult$1 as FileNewSuccessResult, type FileReadArgs, type FileReadErrorResult, type FileReadMetadata, type FileReadParams, type FileReadResult, type FileReadSuccessResult$1 as FileReadSuccessResult, type FolderTreeOptions, type FunctionTool, GithubLLM, InMemoryMemory, InMemoryMetadata, InMemoryMetricsPort, JsonFileMemoryPersistence, type LLMConfig, LLMError, type LLMFactory, type LLMOptions, type LLMPort, LLMResolver, type LineRangeMetadata, type MCPConfig, type MCPServerConfig, MCPToolPort, type MemoryPort, MemoryPortMetadataAdapter, type Message, type MessageContent, type MessageContentPart, type MetadataPort, type MetricsChangeHandler, type MetricsPort, type MetricsSnapshot, type ModelInfo, type ModelLimits, NoopMetricsPort, NoopReminders, type OrchestratorAwareToolPort, type ParseResult, PersistedMemory, PersistingConsoleEventPort, type RetryConfig, RetryTransport, RuntimeEnv, type SendMessageOptions, SimpleContextBuilder, SimpleCost, SimpleId, type SpecialistAgentConfig, type SpecialistAgentResult, type SubAgentState, type SubAgentToolCall, SystemClock, type TodoWriteArgs, type TodoWriteMetadata, type TodoWriteResult, type TodoWriteSuccessResult$1 as TodoWriteSuccessResult, type ToolApprovalDecision, type ToolArguments, type ToolCall, type ToolCallValidation, type ToolErrorMetadata, type ToolExecutionContext, type ToolExecutionResult, type ToolMetadataMap, type ToolName, type ToolParameterMap, type ToolPort, ToolRegistry, type ToolValidator, type TypedToolInvocation, type UsageData, type UserAttachment, type UserMessagePayload, type ValidationResult, type WebFetchArgs, type WebFetchMetadata, type WebFetchParams, type WebFetchResult, type WebFetchSuccessResult$1 as WebFetchSuccessResult, type WebSearchArgs, type WebSearchMetadata, type WebSearchParams, type WebSearchResult, type WebSearchSuccessResult$1 as WebSearchSuccessResult, type WebSearchToolResult, buildAgentCreationPrompt, buildInjectedSystem, canonicalizeTerminalPaste, convertToolCall, convertToolCalls, createEmptySnapshot, createLLM, err, generateFolderTree, getAvailableProviders, getFallbackLimits, getProviderLabel, isAssignResult, isAssignSuccess, isAssignTaskArgs, isBashResult, isBashSuccess, isBashToolArgs, isDirLsArgs, isDirLsResult, isDirLsSuccess, isError, isFileEditArgs, isFileEditResult, isFileEditSuccess, isFileNewArgs, isFileNewResult, isFileNewSuccess, isFileReadArgs, isFileReadResult, isFileReadSuccess, isJsonResult, isRetryableError, isRetryableStatusCode, isSuccess, isSuccessJson, isSuccessText, isTextResult, isTodoWriteArgs, isTodoWriteResult, isTodoWriteSuccess, isWebFetchArgs, isWebFetchResult, isWebFetchSuccess, isWebSearchArgs, isWebSearchResult, isWebSearchSuccess, loadMCPConfig, normalizeModelInfo, normalizeModelLimits, normalizeNewlines, okJson, okText, parseJSON, parseSubAgentToolCallArguments, parseToolArguments, renderTemplate, resolveBackspaces, resolveCarriageReturns, stripAnsiAndControls, supportsGetModels, toolValidators };