@standardagents/builder 0.9.17 → 0.10.1-dev.616ec2e

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
@@ -305,6 +305,7 @@ interface Message {
305
305
  reasoning_details?: string | null;
306
306
  parent_id?: string | null;
307
307
  depth?: number;
308
+ attachments?: string | null;
308
309
  }
309
310
  /**
310
311
  * Tool call from OpenAI format
@@ -355,6 +356,12 @@ interface ThreadInstance {
355
356
  loadAgent(name: string): Promise<any>;
356
357
  getPromptNames(): string[];
357
358
  getAgentNames(): string[];
359
+ insertOrphanedToolCall(params: {
360
+ content?: string;
361
+ toolCallId: string;
362
+ toolName: string;
363
+ toolArgs: string;
364
+ }): Promise<Response>;
358
365
  }
359
366
  /**
360
367
  * Tool call for internal flow management
@@ -417,6 +424,8 @@ interface PromptData {
417
424
  reasoning_max_tokens: number | null;
418
425
  reasoning_exclude: boolean;
419
426
  include_reasoning: boolean;
427
+ maxImagePixels: number | null;
428
+ recentImageThreshold: number | null;
420
429
  _tools?: (string | ToolConfig$1)[];
421
430
  _handoffAgents?: string[];
422
431
  _requiredSchema?: any;
@@ -480,13 +489,38 @@ interface FlowState {
480
489
  pendingMessageId?: string;
481
490
  allowedTools?: ToolDefinition[];
482
491
  }
492
+ /**
493
+ * Text content part for multimodal messages
494
+ */
495
+ interface TextContentPart {
496
+ type: "text";
497
+ text: string;
498
+ }
499
+ /**
500
+ * Image URL content part for multimodal messages (OpenAI/OpenRouter format)
501
+ */
502
+ interface ImageContentPart {
503
+ type: "image_url";
504
+ image_url: {
505
+ url: string;
506
+ detail?: "auto" | "low" | "high";
507
+ };
508
+ }
509
+ /**
510
+ * Multimodal content - array of text and image parts
511
+ */
512
+ type MultimodalContent = Array<TextContentPart | ImageContentPart>;
513
+ /**
514
+ * Message content - can be string (text only) or array (multimodal)
515
+ */
516
+ type MessageContent = string | MultimodalContent;
483
517
  /**
484
518
  * Request context for LLM calls
485
519
  */
486
520
  interface RequestContext {
487
521
  messages: Array<{
488
522
  role: "system" | "user" | "assistant" | "tool";
489
- content?: string;
523
+ content?: MessageContent;
490
524
  tool_calls?: ToolCall[];
491
525
  tool_call_id?: string;
492
526
  name?: string;
@@ -509,6 +543,7 @@ interface RequestContext {
509
543
  max_tokens?: number;
510
544
  exclude?: boolean;
511
545
  };
546
+ imagePathMap?: Map<string, string>;
512
547
  }
513
548
  /**
514
549
  * Tool definition for LLM requests
@@ -665,6 +700,82 @@ interface LogData {
665
700
  retry_of_log_id?: string | null;
666
701
  created_at: number;
667
702
  }
703
+ /**
704
+ * Base environment interface for StandardAgents.
705
+ * Extends ThreadEnv with optional provider API keys.
706
+ *
707
+ * User's Env interface should extend this or include these bindings.
708
+ */
709
+ interface Env extends ThreadEnv {
710
+ OPENAI_API_KEY?: string;
711
+ ANTHROPIC_API_KEY?: string;
712
+ OPENROUTER_API_KEY?: string;
713
+ GOOGLE_API_KEY?: string;
714
+ UI_DEV_SERVER?: string;
715
+ ASSETS?: {
716
+ fetch(request: Request | string): Promise<Response>;
717
+ };
718
+ GITHUB_TOKEN?: string;
719
+ GITHUB_REPO?: string;
720
+ GITHUB_BRANCH?: string;
721
+ SUPER_ADMIN_PASSWORD?: string;
722
+ ENCRYPTION_KEY?: string;
723
+ [key: string]: unknown;
724
+ }
725
+ /**
726
+ * Storage backend types for files
727
+ */
728
+ type StorageBackend = "local" | "url" | "s3" | "r2";
729
+ /**
730
+ * File record stored in the files table
731
+ */
732
+ interface FileRecord {
733
+ path: string;
734
+ name: string;
735
+ mimeType: string;
736
+ storage: StorageBackend;
737
+ location?: string | null;
738
+ size: number;
739
+ metadata?: Record<string, unknown> | null;
740
+ isDirectory: boolean;
741
+ createdAt: number;
742
+ }
743
+ /**
744
+ * Image-specific metadata stored in FileRecord.metadata
745
+ */
746
+ interface ImageMetadata {
747
+ width: number;
748
+ height: number;
749
+ }
750
+ /**
751
+ * Attachment reference stored in messages.attachments (JSON array)
752
+ */
753
+ interface AttachmentRef {
754
+ id: string;
755
+ type: "file";
756
+ path: string;
757
+ name: string;
758
+ mimeType: string;
759
+ width?: number;
760
+ height?: number;
761
+ description?: string;
762
+ }
763
+ /**
764
+ * Grep search result
765
+ */
766
+ interface GrepResult {
767
+ path: string;
768
+ name: string;
769
+ matches: string[];
770
+ lineNumbers?: number[];
771
+ }
772
+ /**
773
+ * File stats for storage tracking
774
+ */
775
+ interface FileStats {
776
+ totalSize: number;
777
+ fileCount: number;
778
+ }
668
779
 
669
780
  /**
670
781
  * Minimum required environment bindings for thread endpoints.
@@ -879,7 +990,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
879
990
  * Send a new message to the thread (RPC method)
880
991
  * Enqueues the message processing to be handled by the alarm handler
881
992
  */
882
- sendMessage(threadId: string, content: string, role?: string): Promise<Response>;
993
+ sendMessage(threadId: string, content: string, role?: string, attachments?: string): Promise<Response>;
883
994
  /**
884
995
  * Check if execution should be stopped (called by FlowEngine)
885
996
  * Reads from SQLite for persistence across hibernation
@@ -926,6 +1037,7 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
926
1037
  status: "pending" | "completed" | "failed" | null;
927
1038
  reasoning_content: string | null;
928
1039
  reasoning_details: string | null;
1040
+ attachments: any;
929
1041
  }[];
930
1042
  total: number;
931
1043
  hasMore: boolean;
@@ -1074,6 +1186,8 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
1074
1186
  id: any;
1075
1187
  title: any;
1076
1188
  type: any;
1189
+ description: any;
1190
+ icon: any;
1077
1191
  side_a_label: any;
1078
1192
  side_b_label: any;
1079
1193
  } | null;
@@ -1212,6 +1326,220 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
1212
1326
  * Internal method called by alarm queue
1213
1327
  */
1214
1328
  private testOperation;
1329
+ /**
1330
+ * Get file storage helper instance
1331
+ */
1332
+ private getFileStorage;
1333
+ /**
1334
+ * Write a file to storage (RPC method)
1335
+ */
1336
+ writeFile(path: string, data: string, // base64 encoded
1337
+ mimeType: string, options?: {
1338
+ metadata?: Record<string, unknown>;
1339
+ thumbnail?: string;
1340
+ }): Promise<{
1341
+ success: boolean;
1342
+ file: any;
1343
+ error?: undefined;
1344
+ } | {
1345
+ success: boolean;
1346
+ error: any;
1347
+ file?: undefined;
1348
+ }>;
1349
+ /**
1350
+ * Write a text file to storage (RPC method)
1351
+ */
1352
+ writeTextFile(path: string, content: string, mimeType?: string, options?: {
1353
+ metadata?: Record<string, unknown>;
1354
+ }): Promise<{
1355
+ success: boolean;
1356
+ file: any;
1357
+ error?: undefined;
1358
+ } | {
1359
+ success: boolean;
1360
+ error: any;
1361
+ file?: undefined;
1362
+ }>;
1363
+ /**
1364
+ * Process an image using sip (WASM-based image processing)
1365
+ * This runs inside the DO where WASM is properly initialized.
1366
+ *
1367
+ * @param data - base64 encoded image data
1368
+ * @param mimeType - MIME type of the input image
1369
+ * @returns Processed image data, dimensions, and mimeType
1370
+ */
1371
+ processImage(data: string, mimeType: string): Promise<{
1372
+ success: boolean;
1373
+ data?: string;
1374
+ mimeType?: string;
1375
+ width?: number;
1376
+ height?: number;
1377
+ error?: string;
1378
+ }>;
1379
+ /**
1380
+ * Link to an external file (RPC method)
1381
+ */
1382
+ linkFile(path: string, location: string, options?: {
1383
+ mimeType?: string;
1384
+ size?: number;
1385
+ metadata?: Record<string, unknown>;
1386
+ }): Promise<{
1387
+ success: boolean;
1388
+ file: any;
1389
+ error?: undefined;
1390
+ } | {
1391
+ success: boolean;
1392
+ error: any;
1393
+ file?: undefined;
1394
+ }>;
1395
+ /**
1396
+ * Read a file from storage (RPC method)
1397
+ * Returns base64-encoded data
1398
+ */
1399
+ readFile(path: string): Promise<{
1400
+ success: boolean;
1401
+ data: string;
1402
+ error?: undefined;
1403
+ } | {
1404
+ success: boolean;
1405
+ error: any;
1406
+ data?: undefined;
1407
+ }>;
1408
+ /**
1409
+ * Read a text file from storage (RPC method)
1410
+ */
1411
+ readTextFile(path: string): Promise<{
1412
+ success: boolean;
1413
+ content: any;
1414
+ error?: undefined;
1415
+ } | {
1416
+ success: boolean;
1417
+ error: any;
1418
+ content?: undefined;
1419
+ }>;
1420
+ /**
1421
+ * Get file metadata (RPC method)
1422
+ */
1423
+ statFile(path: string): Promise<{
1424
+ success: boolean;
1425
+ file: any;
1426
+ error?: undefined;
1427
+ } | {
1428
+ success: boolean;
1429
+ error: any;
1430
+ file?: undefined;
1431
+ }>;
1432
+ /**
1433
+ * Check if file exists (RPC method)
1434
+ */
1435
+ fileExists(path: string): Promise<{
1436
+ success: boolean;
1437
+ exists: any;
1438
+ error?: undefined;
1439
+ } | {
1440
+ success: boolean;
1441
+ error: any;
1442
+ exists?: undefined;
1443
+ }>;
1444
+ /**
1445
+ * Delete a file (RPC method)
1446
+ */
1447
+ unlinkFile(path: string): Promise<{
1448
+ success: boolean;
1449
+ error?: undefined;
1450
+ } | {
1451
+ success: boolean;
1452
+ error: any;
1453
+ }>;
1454
+ /**
1455
+ * Create a directory (RPC method)
1456
+ */
1457
+ mkdirFile(path: string): Promise<{
1458
+ success: boolean;
1459
+ directory: any;
1460
+ error?: undefined;
1461
+ } | {
1462
+ success: boolean;
1463
+ error: any;
1464
+ directory?: undefined;
1465
+ }>;
1466
+ /**
1467
+ * List directory contents (RPC method)
1468
+ */
1469
+ readdirFile(path: string): Promise<{
1470
+ success: boolean;
1471
+ files: any;
1472
+ error?: undefined;
1473
+ } | {
1474
+ success: boolean;
1475
+ error: any;
1476
+ files?: undefined;
1477
+ }>;
1478
+ /**
1479
+ * Remove empty directory (RPC method)
1480
+ */
1481
+ rmdirFile(path: string): Promise<{
1482
+ success: boolean;
1483
+ error?: undefined;
1484
+ } | {
1485
+ success: boolean;
1486
+ error: any;
1487
+ }>;
1488
+ /**
1489
+ * Get file storage statistics (RPC method)
1490
+ */
1491
+ getFileStats(): Promise<{
1492
+ success: boolean;
1493
+ stats: any;
1494
+ error?: undefined;
1495
+ } | {
1496
+ success: boolean;
1497
+ error: any;
1498
+ stats?: undefined;
1499
+ }>;
1500
+ /**
1501
+ * Get thumbnail for an image (RPC method)
1502
+ * Returns base64-encoded data
1503
+ */
1504
+ getFileThumbnail(path: string): Promise<{
1505
+ success: boolean;
1506
+ data: string;
1507
+ error?: undefined;
1508
+ } | {
1509
+ success: boolean;
1510
+ error: any;
1511
+ data?: undefined;
1512
+ }>;
1513
+ /**
1514
+ * Search file contents using FTS5 (RPC method)
1515
+ */
1516
+ grepFiles(pattern: string, options?: {
1517
+ path?: string;
1518
+ limit?: number;
1519
+ }): Promise<{
1520
+ success: boolean;
1521
+ results: any;
1522
+ error?: undefined;
1523
+ } | {
1524
+ success: boolean;
1525
+ error: any;
1526
+ results?: undefined;
1527
+ }>;
1528
+ /**
1529
+ * Find files by path pattern (RPC method)
1530
+ */
1531
+ findFiles(pattern: string, options?: {
1532
+ type?: "file" | "directory" | "all";
1533
+ limit?: number;
1534
+ }): Promise<{
1535
+ success: boolean;
1536
+ files: any;
1537
+ error?: undefined;
1538
+ } | {
1539
+ success: boolean;
1540
+ error: any;
1541
+ files?: undefined;
1542
+ }>;
1215
1543
  }
1216
1544
 
1217
1545
  /**
@@ -1627,6 +1955,26 @@ interface ModelDefinition<N extends string = string> {
1627
1955
  * Some providers offer reduced pricing for cached/repeated prompts.
1628
1956
  */
1629
1957
  cachedPrice?: number;
1958
+ /**
1959
+ * Model capabilities - features this model supports.
1960
+ */
1961
+ capabilities?: {
1962
+ /**
1963
+ * Whether the model supports vision (image understanding).
1964
+ * When true, image attachments will be sent to the model as part of the request.
1965
+ * Models like GPT-4o, Claude 3, and Gemini support vision.
1966
+ */
1967
+ vision?: boolean;
1968
+ /**
1969
+ * Whether the model supports function calling (tool use).
1970
+ * Most modern models support this, defaults to true if not specified.
1971
+ */
1972
+ functionCalling?: boolean;
1973
+ /**
1974
+ * Whether the model supports structured outputs (JSON mode).
1975
+ */
1976
+ structuredOutputs?: boolean;
1977
+ };
1630
1978
  }
1631
1979
  /**
1632
1980
  * Defines an LLM model configuration.
@@ -1972,6 +2320,49 @@ interface PromptDefinition<N extends string = string, S extends z.ZodTypeAny = z
1972
2320
  * Configure effort level, token limits, and visibility of reasoning.
1973
2321
  */
1974
2322
  reasoning?: ReasoningConfig;
2323
+ /**
2324
+ * Maximum pixels for image attachments before client-side resize.
2325
+ * Images exceeding this limit are scaled down while preserving aspect ratio.
2326
+ * Images smaller than this limit are not resized up.
2327
+ *
2328
+ * Common values:
2329
+ * - 262144 (256K): 512x512 equivalent - thumbnails, low cost
2330
+ * - 1048576 (1M): 1024x1024 equivalent - good quality (default)
2331
+ * - 2073600 (2M): 1440x1440 equivalent - high quality
2332
+ * - 4194304 (4M): 2048x2048 equivalent - maximum detail
2333
+ *
2334
+ * @default 1048576 (1M pixels, ~1024x1024)
2335
+ *
2336
+ * @example
2337
+ * ```typescript
2338
+ * // High quality images for detailed analysis
2339
+ * maxImagePixels: 2073600
2340
+ *
2341
+ * // Lower quality for cost-sensitive applications
2342
+ * maxImagePixels: 262144
2343
+ * ```
2344
+ */
2345
+ maxImagePixels?: number;
2346
+ /**
2347
+ * Number of recent messages to keep actual images for in context.
2348
+ * Messages older than this threshold will have their images replaced
2349
+ * with text descriptions to save context window space.
2350
+ *
2351
+ * This helps manage context window usage in long conversations with
2352
+ * many image attachments by summarizing older images.
2353
+ *
2354
+ * @default 10
2355
+ *
2356
+ * @example
2357
+ * ```typescript
2358
+ * // Keep more images in context for image-heavy workflows
2359
+ * recentImageThreshold: 20
2360
+ *
2361
+ * // Aggressively summarize to save context
2362
+ * recentImageThreshold: 5
2363
+ * ```
2364
+ */
2365
+ recentImageThreshold?: number;
1975
2366
  }
1976
2367
  /**
1977
2368
  * Helper type to extract the inferred input type from a prompt's Zod schema.
@@ -2184,6 +2575,20 @@ interface AgentDefinition<N extends string = string> {
2184
2575
  * @example ['customer-service', 'tier-1', 'english']
2185
2576
  */
2186
2577
  tags?: string[];
2578
+ /**
2579
+ * Brief description of what this agent does.
2580
+ * Useful for UIs and documentation.
2581
+ *
2582
+ * @example 'Handles customer support inquiries and resolves issues'
2583
+ */
2584
+ description?: string;
2585
+ /**
2586
+ * Icon URL or absolute path for the agent.
2587
+ * Absolute paths (starting with `/`) are converted to full URLs in API responses.
2588
+ *
2589
+ * @example 'https://example.com/icon.svg' or '/icons/support.svg'
2590
+ */
2591
+ icon?: string;
2187
2592
  }
2188
2593
  /**
2189
2594
  * Defines an agent configuration.
@@ -2608,6 +3013,327 @@ declare function updateThread(thread: ThreadContext, params: {
2608
3013
  tags: string[];
2609
3014
  created_at: number;
2610
3015
  } | null>;
3016
+ /**
3017
+ * Write a file to thread storage
3018
+ *
3019
+ * @param flow - The current FlowState
3020
+ * @param path - File path (e.g., "/images/photo.jpg")
3021
+ * @param data - File data as ArrayBuffer or string
3022
+ * @param mimeType - MIME type of the file
3023
+ * @param options - Optional metadata and thumbnail
3024
+ * @returns The created file record
3025
+ *
3026
+ * @example
3027
+ * ```typescript
3028
+ * import { writeFile } from '@standardagents/builder';
3029
+ *
3030
+ * // Write binary file
3031
+ * const imageData = new Uint8Array([...]);
3032
+ * await writeFile(flow, "/images/photo.jpg", imageData.buffer, "image/jpeg");
3033
+ *
3034
+ * // Write text file
3035
+ * await writeFile(flow, "/docs/readme.md", "# Hello", "text/markdown");
3036
+ * ```
3037
+ */
3038
+ declare function writeFile(flow: FlowState, path: string, data: ArrayBuffer | string, mimeType: string, options?: {
3039
+ metadata?: Record<string, unknown>;
3040
+ thumbnail?: ArrayBuffer;
3041
+ }): Promise<FileRecord>;
3042
+ /**
3043
+ * Write an image file with optional thumbnail
3044
+ *
3045
+ * @param flow - The current FlowState
3046
+ * @param path - File path
3047
+ * @param data - Image data as ArrayBuffer
3048
+ * @param mimeType - Image MIME type
3049
+ * @param options - Image metadata (width, height) and optional thumbnail
3050
+ * @returns The created file record
3051
+ *
3052
+ * @example
3053
+ * ```typescript
3054
+ * import { writeImage } from '@standardagents/builder';
3055
+ *
3056
+ * await writeImage(flow, "/images/photo.jpg", imageBuffer, "image/jpeg", {
3057
+ * metadata: { width: 1024, height: 768 },
3058
+ * thumbnail: thumbnailBuffer
3059
+ * });
3060
+ * ```
3061
+ */
3062
+ declare function writeImage(flow: FlowState, path: string, data: ArrayBuffer, mimeType: string, options?: {
3063
+ metadata?: {
3064
+ width: number;
3065
+ height: number;
3066
+ [key: string]: unknown;
3067
+ };
3068
+ thumbnail?: ArrayBuffer;
3069
+ }): Promise<FileRecord>;
3070
+ /**
3071
+ * Link to an external file (URL, S3, R2)
3072
+ *
3073
+ * Creates a file entry pointing to an external location without storing the data locally.
3074
+ *
3075
+ * @param flow - The current FlowState
3076
+ * @param path - File path in thread storage
3077
+ * @param location - External location (https://, s3://, r2://)
3078
+ * @param options - Optional MIME type, size, and metadata
3079
+ * @returns The created file record
3080
+ *
3081
+ * @example
3082
+ * ```typescript
3083
+ * import { linkFile } from '@standardagents/builder';
3084
+ *
3085
+ * // Link to a URL
3086
+ * await linkFile(flow, "/images/hero.jpg", "https://cdn.example.com/hero.jpg");
3087
+ *
3088
+ * // Link to S3
3089
+ * await linkFile(flow, "/data/large.csv", "s3://mybucket/data/large.csv", {
3090
+ * mimeType: "text/csv",
3091
+ * size: 10 * 1024 * 1024 * 1024 // 10GB
3092
+ * });
3093
+ * ```
3094
+ */
3095
+ declare function linkFile(flow: FlowState, path: string, location: string, options?: {
3096
+ mimeType?: string;
3097
+ size?: number;
3098
+ metadata?: Record<string, unknown>;
3099
+ }): Promise<FileRecord>;
3100
+ /**
3101
+ * Read a file from thread storage
3102
+ *
3103
+ * @param flow - The current FlowState
3104
+ * @param path - File path
3105
+ * @returns File data as ArrayBuffer, or null if not found/external
3106
+ *
3107
+ * @example
3108
+ * ```typescript
3109
+ * import { readFile } from '@standardagents/builder';
3110
+ *
3111
+ * const data = await readFile(flow, "/images/photo.jpg");
3112
+ * if (data) {
3113
+ * // Process binary data
3114
+ * }
3115
+ * ```
3116
+ */
3117
+ declare function readFile(flow: FlowState, path: string): Promise<ArrayBuffer | null>;
3118
+ /**
3119
+ * Get file metadata
3120
+ *
3121
+ * @param flow - The current FlowState
3122
+ * @param path - File path
3123
+ * @returns File record or null if not found
3124
+ *
3125
+ * @example
3126
+ * ```typescript
3127
+ * import { stat } from '@standardagents/builder';
3128
+ *
3129
+ * const file = await stat(flow, "/images/photo.jpg");
3130
+ * if (file) {
3131
+ * console.log(`Size: ${file.size}, Type: ${file.mimeType}`);
3132
+ * }
3133
+ * ```
3134
+ */
3135
+ declare function stat(flow: FlowState, path: string): Promise<FileRecord | null>;
3136
+ /**
3137
+ * Check if file or directory exists
3138
+ *
3139
+ * @param flow - The current FlowState
3140
+ * @param path - File path
3141
+ * @returns true if exists, false otherwise
3142
+ *
3143
+ * @example
3144
+ * ```typescript
3145
+ * import { exists } from '@standardagents/builder';
3146
+ *
3147
+ * if (await exists(flow, "/config.json")) {
3148
+ * // File exists
3149
+ * }
3150
+ * ```
3151
+ */
3152
+ declare function exists(flow: FlowState, path: string): Promise<boolean>;
3153
+ /**
3154
+ * Delete a file
3155
+ *
3156
+ * @param flow - The current FlowState
3157
+ * @param path - File path
3158
+ *
3159
+ * @example
3160
+ * ```typescript
3161
+ * import { unlink } from '@standardagents/builder';
3162
+ *
3163
+ * await unlink(flow, "/temp/draft.txt");
3164
+ * ```
3165
+ */
3166
+ declare function unlink(flow: FlowState, path: string): Promise<void>;
3167
+ /**
3168
+ * Create a directory
3169
+ *
3170
+ * @param flow - The current FlowState
3171
+ * @param path - Directory path
3172
+ * @returns The created directory record
3173
+ *
3174
+ * @example
3175
+ * ```typescript
3176
+ * import { mkdir } from '@standardagents/builder';
3177
+ *
3178
+ * await mkdir(flow, "/uploads/2024");
3179
+ * ```
3180
+ */
3181
+ declare function mkdir(flow: FlowState, path: string): Promise<FileRecord>;
3182
+ /**
3183
+ * List directory contents
3184
+ *
3185
+ * @param flow - The current FlowState
3186
+ * @param path - Directory path
3187
+ * @returns Array of file records in the directory
3188
+ *
3189
+ * @example
3190
+ * ```typescript
3191
+ * import { readdir } from '@standardagents/builder';
3192
+ *
3193
+ * const files = await readdir(flow, "/images");
3194
+ * for (const file of files) {
3195
+ * console.log(file.name, file.size);
3196
+ * }
3197
+ * ```
3198
+ */
3199
+ declare function readdir(flow: FlowState, path: string): Promise<FileRecord[]>;
3200
+ /**
3201
+ * Remove an empty directory
3202
+ *
3203
+ * @param flow - The current FlowState
3204
+ * @param path - Directory path
3205
+ *
3206
+ * @example
3207
+ * ```typescript
3208
+ * import { rmdir } from '@standardagents/builder';
3209
+ *
3210
+ * await rmdir(flow, "/temp");
3211
+ * ```
3212
+ */
3213
+ declare function rmdir(flow: FlowState, path: string): Promise<void>;
3214
+ /**
3215
+ * Get file storage statistics
3216
+ *
3217
+ * @param flow - The current FlowState
3218
+ * @returns Storage statistics (total size and file count)
3219
+ *
3220
+ * @example
3221
+ * ```typescript
3222
+ * import { getFileStats } from '@standardagents/builder';
3223
+ *
3224
+ * const stats = await getFileStats(flow);
3225
+ * console.log(`Total: ${stats.totalSize} bytes, Files: ${stats.fileCount}`);
3226
+ * ```
3227
+ */
3228
+ declare function getFileStats(flow: FlowState): Promise<FileStats>;
3229
+ /**
3230
+ * Get thumbnail for an image file
3231
+ *
3232
+ * @param flow - The current FlowState
3233
+ * @param path - Image file path
3234
+ * @returns Thumbnail data as ArrayBuffer, or null if not found
3235
+ *
3236
+ * @example
3237
+ * ```typescript
3238
+ * import { getThumbnail } from '@standardagents/builder';
3239
+ *
3240
+ * const thumb = await getThumbnail(flow, "/images/photo.jpg");
3241
+ * ```
3242
+ */
3243
+ declare function getThumbnail(flow: FlowState, path: string): Promise<ArrayBuffer | null>;
3244
+ /**
3245
+ * Read a text file as string
3246
+ *
3247
+ * @param flow - The current FlowState
3248
+ * @param path - File path
3249
+ * @returns File content as string, or null if not found
3250
+ *
3251
+ * @example
3252
+ * ```typescript
3253
+ * import { cat } from '@standardagents/builder';
3254
+ *
3255
+ * const content = await cat(flow, "/docs/readme.md");
3256
+ * ```
3257
+ */
3258
+ declare function cat(flow: FlowState, path: string): Promise<string | null>;
3259
+ /**
3260
+ * Read first N lines of a text file
3261
+ *
3262
+ * @param flow - The current FlowState
3263
+ * @param path - File path
3264
+ * @param lines - Number of lines to read (default: 10)
3265
+ * @returns First N lines as string, or null if not found
3266
+ *
3267
+ * @example
3268
+ * ```typescript
3269
+ * import { head } from '@standardagents/builder';
3270
+ *
3271
+ * const firstLines = await head(flow, "/logs/app.log", 20);
3272
+ * ```
3273
+ */
3274
+ declare function head(flow: FlowState, path: string, lines?: number): Promise<string | null>;
3275
+ /**
3276
+ * Read last N lines of a text file
3277
+ *
3278
+ * @param flow - The current FlowState
3279
+ * @param path - File path
3280
+ * @param lines - Number of lines to read (default: 10)
3281
+ * @returns Last N lines as string, or null if not found
3282
+ *
3283
+ * @example
3284
+ * ```typescript
3285
+ * import { tail } from '@standardagents/builder';
3286
+ *
3287
+ * const lastLines = await tail(flow, "/logs/app.log", 50);
3288
+ * ```
3289
+ */
3290
+ declare function tail(flow: FlowState, path: string, lines?: number): Promise<string | null>;
3291
+ /**
3292
+ * Search text file contents using FTS5 full-text search
3293
+ *
3294
+ * @param flow - The current FlowState
3295
+ * @param pattern - Search pattern (FTS5 syntax)
3296
+ * @param options - Search options
3297
+ * @returns Array of matching results with snippets
3298
+ *
3299
+ * @example
3300
+ * ```typescript
3301
+ * import { grep } from '@standardagents/builder';
3302
+ *
3303
+ * // Search all files
3304
+ * const results = await grep(flow, "error");
3305
+ *
3306
+ * // Search in specific directory
3307
+ * const results = await grep(flow, "TODO", { path: "/src" });
3308
+ * ```
3309
+ */
3310
+ declare function grep(flow: FlowState, pattern: string, options?: {
3311
+ path?: string;
3312
+ limit?: number;
3313
+ }): Promise<GrepResult[]>;
3314
+ /**
3315
+ * Find files by path pattern
3316
+ *
3317
+ * @param flow - The current FlowState
3318
+ * @param pattern - Glob-like pattern (e.g., "*.md", "/docs/subdir/*.txt")
3319
+ * @param options - Find options
3320
+ * @returns Array of matching file records
3321
+ *
3322
+ * @example
3323
+ * ```typescript
3324
+ * import { find } from '@standardagents/builder';
3325
+ *
3326
+ * // Find all markdown files
3327
+ * const mdFiles = await find(flow, "*.md");
3328
+ *
3329
+ * // Find all files in docs
3330
+ * const docFiles = await find(flow, "/docs/*", { type: "file" });
3331
+ * ```
3332
+ */
3333
+ declare function find(flow: FlowState, pattern: string, options?: {
3334
+ type?: "file" | "directory" | "all";
3335
+ limit?: number;
3336
+ }): Promise<FileRecord[]>;
2611
3337
 
2612
3338
  /**
2613
3339
  * Options for injecting a message
@@ -2854,6 +3580,67 @@ interface FlowStateWithSdk extends FlowState {
2854
3580
  */
2855
3581
  declare function enhanceFlowState(flow: FlowState): FlowStateWithSdk;
2856
3582
 
3583
+ /**
3584
+ * Context Management for Image Attachments
3585
+ *
3586
+ * Handles auto-summarization of old images to reduce context window usage
3587
+ * while preserving the semantic meaning of image content.
3588
+ */
3589
+
3590
+ /**
3591
+ * Configuration for image context management
3592
+ */
3593
+ interface ImageContextConfig {
3594
+ /** Number of recent messages to keep images for (default: 10) */
3595
+ recentMessageThreshold: number;
3596
+ /** System prompt for generating image descriptions */
3597
+ descriptionPrompt: string;
3598
+ }
3599
+ /**
3600
+ * Check if a message has image attachments that could be summarized
3601
+ */
3602
+ declare function hasImageAttachments(message: Message): boolean;
3603
+ /**
3604
+ * Get image attachments from a message that don't have descriptions yet
3605
+ */
3606
+ declare function getUnsummarizedImageAttachments(message: Message): AttachmentRef[];
3607
+ /**
3608
+ * Determine which messages should have their images replaced with descriptions.
3609
+ * Returns indices of messages that are old enough to be summarized.
3610
+ */
3611
+ declare function getMessagesToSummarize(messages: Message[], config?: ImageContextConfig): number[];
3612
+ /**
3613
+ * Build text representation for an image attachment (used when image is too old)
3614
+ */
3615
+ declare function buildImageDescription(attachment: AttachmentRef): string;
3616
+ /**
3617
+ * Transform message content to replace old images with text descriptions.
3618
+ * This modifies the content array for LLM context building.
3619
+ */
3620
+ declare function replaceImagesWithDescriptions(content: MessageContent, attachments: AttachmentRef[]): MessageContent;
3621
+ /**
3622
+ * Process message history to optimize context window usage.
3623
+ * Old images are replaced with their text descriptions.
3624
+ *
3625
+ * @param messages - Full message history
3626
+ * @param config - Context management configuration
3627
+ * @returns Processed messages with old images replaced by descriptions
3628
+ */
3629
+ declare function optimizeImageContext(messages: Message[], config?: ImageContextConfig): Message[];
3630
+ /**
3631
+ * Generate a description for an image using a vision model.
3632
+ * This should be called when storing new messages with images.
3633
+ *
3634
+ * Note: This function is a placeholder for the actual LLM call.
3635
+ * The actual implementation would need to make an API call to a vision model.
3636
+ *
3637
+ * @param imageBase64 - Base64-encoded image data
3638
+ * @param mimeType - MIME type of the image
3639
+ * @param state - Flow state for LLM access
3640
+ * @returns Generated description
3641
+ */
3642
+ declare function generateImageDescription(_imageBase64: string, _mimeType: string, _state: FlowState): Promise<string | null>;
3643
+
2857
3644
  /**
2858
3645
  * Types for GitHub REST API integration.
2859
3646
  */
@@ -3022,4 +3809,4 @@ declare class GitHubApiError extends Error {
3022
3809
  constructor(message: string, status: number, details?: unknown);
3023
3810
  }
3024
3811
 
3025
- export { type Agent, type AgentBuilderEnv, type AgentDefinition, type AgentType, type AuthContext, type AuthUser, type BroadcastOptions, type Controller, type ControllerContext, DurableAgentBuilder, DurableThread, type FlowResult, type FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, type HookSignatures, type ImageContent, type InjectMessageOptions$1 as InjectMessageOptions, type LLMResponse, type Message, type ModelDefinition, type ModelProvider, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type Provider, type ReasoningConfig, type RequestContext, type SideConfig, type StructuredPrompt, type StructuredToolReturn, type TelemetryEvent, type TextContent, type ThreadEndpointContext, type ThreadEnv, type ThreadInstance, type ThreadMetadata, type ThreadRegistryEntry, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolCall, type ToolConfig, type ToolContent, type ToolResult, type UpdateThreadParams, type User, authenticate, defineAgent, defineController, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, emitThreadEvent, enhanceFlowState, forceTurn, generateAgentFile, generateModelFile, generatePromptFile, getMessages, injectMessage, queueTool, reloadHistory, requireAdmin, requireAuth, updateThread };
3812
+ export { type Agent, type AgentBuilderEnv, type AgentDefinition, type AgentType, type AttachmentRef, type AuthContext, type AuthUser, type BroadcastOptions, type Controller, type ControllerContext, DurableAgentBuilder, DurableThread, type Env, type FileRecord, type FileStats, type FlowResult, type FlowState, FlowStateSdk, type FlowStateWithSdk, GitHubApiError, GitHubClient, type GitHubCommitResult, type GitHubConfig, type GitHubFileChange, type GrepResult, type HookSignatures, type ImageContent, type ImageContentPart, type ImageContextConfig, type ImageMetadata, type InjectMessageOptions$1 as InjectMessageOptions, type LLMResponse, type Message, type MessageContent, type ModelDefinition, type ModelProvider, type MultimodalContent, type PromptContent, type PromptDefinition, type PromptIncludePart, type PromptInput, type PromptPart, type PromptTextPart, type Provider, type ReasoningConfig, type RequestContext, type SideConfig, type StorageBackend, type StructuredPrompt, type StructuredToolReturn, type TelemetryEvent, type TextContent, type TextContentPart, type ThreadEndpointContext, type ThreadEnv, type ThreadInstance, type ThreadMetadata, type ThreadRegistryEntry, type Tool, type ToolArgs, type ToolArgsNode, type ToolArgsRawShape, type ToolCall, type ToolConfig, type ToolContent, type ToolResult, type UpdateThreadParams, type User, authenticate, buildImageDescription, cat, defineAgent, defineController, defineHook, defineModel, definePrompt, defineThreadEndpoint, defineTool, emitThreadEvent, enhanceFlowState, exists, find, forceTurn, generateAgentFile, generateImageDescription, generateModelFile, generatePromptFile, getFileStats, getMessages, getMessagesToSummarize, getThumbnail, getUnsummarizedImageAttachments, grep, hasImageAttachments, head, injectMessage, linkFile, mkdir, optimizeImageContext, queueTool, readFile, readdir, reloadHistory, replaceImagesWithDescriptions, requireAdmin, requireAuth, rmdir, stat, tail, unlink, updateThread, writeFile, writeImage };