@standardagents/builder 0.9.16 → 0.10.0
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/built-in-routes.js +306 -4
- package/dist/built-in-routes.js.map +1 -1
- package/dist/client/assets/index.css +1 -1
- package/dist/client/index.js +19 -19
- package/dist/client/vendor.js +1 -1
- package/dist/client/vue.js +1 -1
- package/dist/image-processing.d.ts +41 -0
- package/dist/image-processing.js +198 -0
- package/dist/image-processing.js.map +1 -0
- package/dist/index.d.ts +758 -3
- package/dist/index.js +1342 -37
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +16 -2
- package/dist/plugin.js.map +1 -1
- package/package.json +11 -1
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?:
|
|
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;
|
|
@@ -1212,6 +1324,204 @@ declare class DurableThread<Env extends ThreadEnv = ThreadEnv> extends DurableOb
|
|
|
1212
1324
|
* Internal method called by alarm queue
|
|
1213
1325
|
*/
|
|
1214
1326
|
private testOperation;
|
|
1327
|
+
/**
|
|
1328
|
+
* Get file storage helper instance
|
|
1329
|
+
*/
|
|
1330
|
+
private getFileStorage;
|
|
1331
|
+
/**
|
|
1332
|
+
* Write a file to storage (RPC method)
|
|
1333
|
+
*/
|
|
1334
|
+
writeFile(path: string, data: string, // base64 encoded
|
|
1335
|
+
mimeType: string, options?: {
|
|
1336
|
+
metadata?: Record<string, unknown>;
|
|
1337
|
+
thumbnail?: string;
|
|
1338
|
+
}): Promise<{
|
|
1339
|
+
success: boolean;
|
|
1340
|
+
file: any;
|
|
1341
|
+
error?: undefined;
|
|
1342
|
+
} | {
|
|
1343
|
+
success: boolean;
|
|
1344
|
+
error: any;
|
|
1345
|
+
file?: undefined;
|
|
1346
|
+
}>;
|
|
1347
|
+
/**
|
|
1348
|
+
* Write a text file to storage (RPC method)
|
|
1349
|
+
*/
|
|
1350
|
+
writeTextFile(path: string, content: string, mimeType?: string, options?: {
|
|
1351
|
+
metadata?: Record<string, unknown>;
|
|
1352
|
+
}): Promise<{
|
|
1353
|
+
success: boolean;
|
|
1354
|
+
file: any;
|
|
1355
|
+
error?: undefined;
|
|
1356
|
+
} | {
|
|
1357
|
+
success: boolean;
|
|
1358
|
+
error: any;
|
|
1359
|
+
file?: undefined;
|
|
1360
|
+
}>;
|
|
1361
|
+
/**
|
|
1362
|
+
* Link to an external file (RPC method)
|
|
1363
|
+
*/
|
|
1364
|
+
linkFile(path: string, location: string, options?: {
|
|
1365
|
+
mimeType?: string;
|
|
1366
|
+
size?: number;
|
|
1367
|
+
metadata?: Record<string, unknown>;
|
|
1368
|
+
}): Promise<{
|
|
1369
|
+
success: boolean;
|
|
1370
|
+
file: any;
|
|
1371
|
+
error?: undefined;
|
|
1372
|
+
} | {
|
|
1373
|
+
success: boolean;
|
|
1374
|
+
error: any;
|
|
1375
|
+
file?: undefined;
|
|
1376
|
+
}>;
|
|
1377
|
+
/**
|
|
1378
|
+
* Read a file from storage (RPC method)
|
|
1379
|
+
* Returns base64-encoded data
|
|
1380
|
+
*/
|
|
1381
|
+
readFile(path: string): Promise<{
|
|
1382
|
+
success: boolean;
|
|
1383
|
+
data: string;
|
|
1384
|
+
error?: undefined;
|
|
1385
|
+
} | {
|
|
1386
|
+
success: boolean;
|
|
1387
|
+
error: any;
|
|
1388
|
+
data?: undefined;
|
|
1389
|
+
}>;
|
|
1390
|
+
/**
|
|
1391
|
+
* Read a text file from storage (RPC method)
|
|
1392
|
+
*/
|
|
1393
|
+
readTextFile(path: string): Promise<{
|
|
1394
|
+
success: boolean;
|
|
1395
|
+
content: any;
|
|
1396
|
+
error?: undefined;
|
|
1397
|
+
} | {
|
|
1398
|
+
success: boolean;
|
|
1399
|
+
error: any;
|
|
1400
|
+
content?: undefined;
|
|
1401
|
+
}>;
|
|
1402
|
+
/**
|
|
1403
|
+
* Get file metadata (RPC method)
|
|
1404
|
+
*/
|
|
1405
|
+
statFile(path: string): Promise<{
|
|
1406
|
+
success: boolean;
|
|
1407
|
+
file: any;
|
|
1408
|
+
error?: undefined;
|
|
1409
|
+
} | {
|
|
1410
|
+
success: boolean;
|
|
1411
|
+
error: any;
|
|
1412
|
+
file?: undefined;
|
|
1413
|
+
}>;
|
|
1414
|
+
/**
|
|
1415
|
+
* Check if file exists (RPC method)
|
|
1416
|
+
*/
|
|
1417
|
+
fileExists(path: string): Promise<{
|
|
1418
|
+
success: boolean;
|
|
1419
|
+
exists: any;
|
|
1420
|
+
error?: undefined;
|
|
1421
|
+
} | {
|
|
1422
|
+
success: boolean;
|
|
1423
|
+
error: any;
|
|
1424
|
+
exists?: undefined;
|
|
1425
|
+
}>;
|
|
1426
|
+
/**
|
|
1427
|
+
* Delete a file (RPC method)
|
|
1428
|
+
*/
|
|
1429
|
+
unlinkFile(path: string): Promise<{
|
|
1430
|
+
success: boolean;
|
|
1431
|
+
error?: undefined;
|
|
1432
|
+
} | {
|
|
1433
|
+
success: boolean;
|
|
1434
|
+
error: any;
|
|
1435
|
+
}>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Create a directory (RPC method)
|
|
1438
|
+
*/
|
|
1439
|
+
mkdirFile(path: string): Promise<{
|
|
1440
|
+
success: boolean;
|
|
1441
|
+
directory: any;
|
|
1442
|
+
error?: undefined;
|
|
1443
|
+
} | {
|
|
1444
|
+
success: boolean;
|
|
1445
|
+
error: any;
|
|
1446
|
+
directory?: undefined;
|
|
1447
|
+
}>;
|
|
1448
|
+
/**
|
|
1449
|
+
* List directory contents (RPC method)
|
|
1450
|
+
*/
|
|
1451
|
+
readdirFile(path: string): Promise<{
|
|
1452
|
+
success: boolean;
|
|
1453
|
+
files: any;
|
|
1454
|
+
error?: undefined;
|
|
1455
|
+
} | {
|
|
1456
|
+
success: boolean;
|
|
1457
|
+
error: any;
|
|
1458
|
+
files?: undefined;
|
|
1459
|
+
}>;
|
|
1460
|
+
/**
|
|
1461
|
+
* Remove empty directory (RPC method)
|
|
1462
|
+
*/
|
|
1463
|
+
rmdirFile(path: string): Promise<{
|
|
1464
|
+
success: boolean;
|
|
1465
|
+
error?: undefined;
|
|
1466
|
+
} | {
|
|
1467
|
+
success: boolean;
|
|
1468
|
+
error: any;
|
|
1469
|
+
}>;
|
|
1470
|
+
/**
|
|
1471
|
+
* Get file storage statistics (RPC method)
|
|
1472
|
+
*/
|
|
1473
|
+
getFileStats(): Promise<{
|
|
1474
|
+
success: boolean;
|
|
1475
|
+
stats: any;
|
|
1476
|
+
error?: undefined;
|
|
1477
|
+
} | {
|
|
1478
|
+
success: boolean;
|
|
1479
|
+
error: any;
|
|
1480
|
+
stats?: undefined;
|
|
1481
|
+
}>;
|
|
1482
|
+
/**
|
|
1483
|
+
* Get thumbnail for an image (RPC method)
|
|
1484
|
+
* Returns base64-encoded data
|
|
1485
|
+
*/
|
|
1486
|
+
getFileThumbnail(path: string): Promise<{
|
|
1487
|
+
success: boolean;
|
|
1488
|
+
data: string;
|
|
1489
|
+
error?: undefined;
|
|
1490
|
+
} | {
|
|
1491
|
+
success: boolean;
|
|
1492
|
+
error: any;
|
|
1493
|
+
data?: undefined;
|
|
1494
|
+
}>;
|
|
1495
|
+
/**
|
|
1496
|
+
* Search file contents using FTS5 (RPC method)
|
|
1497
|
+
*/
|
|
1498
|
+
grepFiles(pattern: string, options?: {
|
|
1499
|
+
path?: string;
|
|
1500
|
+
limit?: number;
|
|
1501
|
+
}): Promise<{
|
|
1502
|
+
success: boolean;
|
|
1503
|
+
results: any;
|
|
1504
|
+
error?: undefined;
|
|
1505
|
+
} | {
|
|
1506
|
+
success: boolean;
|
|
1507
|
+
error: any;
|
|
1508
|
+
results?: undefined;
|
|
1509
|
+
}>;
|
|
1510
|
+
/**
|
|
1511
|
+
* Find files by path pattern (RPC method)
|
|
1512
|
+
*/
|
|
1513
|
+
findFiles(pattern: string, options?: {
|
|
1514
|
+
type?: "file" | "directory" | "all";
|
|
1515
|
+
limit?: number;
|
|
1516
|
+
}): Promise<{
|
|
1517
|
+
success: boolean;
|
|
1518
|
+
files: any;
|
|
1519
|
+
error?: undefined;
|
|
1520
|
+
} | {
|
|
1521
|
+
success: boolean;
|
|
1522
|
+
error: any;
|
|
1523
|
+
files?: undefined;
|
|
1524
|
+
}>;
|
|
1215
1525
|
}
|
|
1216
1526
|
|
|
1217
1527
|
/**
|
|
@@ -1627,6 +1937,26 @@ interface ModelDefinition<N extends string = string> {
|
|
|
1627
1937
|
* Some providers offer reduced pricing for cached/repeated prompts.
|
|
1628
1938
|
*/
|
|
1629
1939
|
cachedPrice?: number;
|
|
1940
|
+
/**
|
|
1941
|
+
* Model capabilities - features this model supports.
|
|
1942
|
+
*/
|
|
1943
|
+
capabilities?: {
|
|
1944
|
+
/**
|
|
1945
|
+
* Whether the model supports vision (image understanding).
|
|
1946
|
+
* When true, image attachments will be sent to the model as part of the request.
|
|
1947
|
+
* Models like GPT-4o, Claude 3, and Gemini support vision.
|
|
1948
|
+
*/
|
|
1949
|
+
vision?: boolean;
|
|
1950
|
+
/**
|
|
1951
|
+
* Whether the model supports function calling (tool use).
|
|
1952
|
+
* Most modern models support this, defaults to true if not specified.
|
|
1953
|
+
*/
|
|
1954
|
+
functionCalling?: boolean;
|
|
1955
|
+
/**
|
|
1956
|
+
* Whether the model supports structured outputs (JSON mode).
|
|
1957
|
+
*/
|
|
1958
|
+
structuredOutputs?: boolean;
|
|
1959
|
+
};
|
|
1630
1960
|
}
|
|
1631
1961
|
/**
|
|
1632
1962
|
* Defines an LLM model configuration.
|
|
@@ -1972,6 +2302,49 @@ interface PromptDefinition<N extends string = string, S extends z.ZodTypeAny = z
|
|
|
1972
2302
|
* Configure effort level, token limits, and visibility of reasoning.
|
|
1973
2303
|
*/
|
|
1974
2304
|
reasoning?: ReasoningConfig;
|
|
2305
|
+
/**
|
|
2306
|
+
* Maximum pixels for image attachments before client-side resize.
|
|
2307
|
+
* Images exceeding this limit are scaled down while preserving aspect ratio.
|
|
2308
|
+
* Images smaller than this limit are not resized up.
|
|
2309
|
+
*
|
|
2310
|
+
* Common values:
|
|
2311
|
+
* - 262144 (256K): 512x512 equivalent - thumbnails, low cost
|
|
2312
|
+
* - 1048576 (1M): 1024x1024 equivalent - good quality (default)
|
|
2313
|
+
* - 2073600 (2M): 1440x1440 equivalent - high quality
|
|
2314
|
+
* - 4194304 (4M): 2048x2048 equivalent - maximum detail
|
|
2315
|
+
*
|
|
2316
|
+
* @default 1048576 (1M pixels, ~1024x1024)
|
|
2317
|
+
*
|
|
2318
|
+
* @example
|
|
2319
|
+
* ```typescript
|
|
2320
|
+
* // High quality images for detailed analysis
|
|
2321
|
+
* maxImagePixels: 2073600
|
|
2322
|
+
*
|
|
2323
|
+
* // Lower quality for cost-sensitive applications
|
|
2324
|
+
* maxImagePixels: 262144
|
|
2325
|
+
* ```
|
|
2326
|
+
*/
|
|
2327
|
+
maxImagePixels?: number;
|
|
2328
|
+
/**
|
|
2329
|
+
* Number of recent messages to keep actual images for in context.
|
|
2330
|
+
* Messages older than this threshold will have their images replaced
|
|
2331
|
+
* with text descriptions to save context window space.
|
|
2332
|
+
*
|
|
2333
|
+
* This helps manage context window usage in long conversations with
|
|
2334
|
+
* many image attachments by summarizing older images.
|
|
2335
|
+
*
|
|
2336
|
+
* @default 10
|
|
2337
|
+
*
|
|
2338
|
+
* @example
|
|
2339
|
+
* ```typescript
|
|
2340
|
+
* // Keep more images in context for image-heavy workflows
|
|
2341
|
+
* recentImageThreshold: 20
|
|
2342
|
+
*
|
|
2343
|
+
* // Aggressively summarize to save context
|
|
2344
|
+
* recentImageThreshold: 5
|
|
2345
|
+
* ```
|
|
2346
|
+
*/
|
|
2347
|
+
recentImageThreshold?: number;
|
|
1975
2348
|
}
|
|
1976
2349
|
/**
|
|
1977
2350
|
* Helper type to extract the inferred input type from a prompt's Zod schema.
|
|
@@ -2608,6 +2981,327 @@ declare function updateThread(thread: ThreadContext, params: {
|
|
|
2608
2981
|
tags: string[];
|
|
2609
2982
|
created_at: number;
|
|
2610
2983
|
} | null>;
|
|
2984
|
+
/**
|
|
2985
|
+
* Write a file to thread storage
|
|
2986
|
+
*
|
|
2987
|
+
* @param flow - The current FlowState
|
|
2988
|
+
* @param path - File path (e.g., "/images/photo.jpg")
|
|
2989
|
+
* @param data - File data as ArrayBuffer or string
|
|
2990
|
+
* @param mimeType - MIME type of the file
|
|
2991
|
+
* @param options - Optional metadata and thumbnail
|
|
2992
|
+
* @returns The created file record
|
|
2993
|
+
*
|
|
2994
|
+
* @example
|
|
2995
|
+
* ```typescript
|
|
2996
|
+
* import { writeFile } from '@standardagents/builder';
|
|
2997
|
+
*
|
|
2998
|
+
* // Write binary file
|
|
2999
|
+
* const imageData = new Uint8Array([...]);
|
|
3000
|
+
* await writeFile(flow, "/images/photo.jpg", imageData.buffer, "image/jpeg");
|
|
3001
|
+
*
|
|
3002
|
+
* // Write text file
|
|
3003
|
+
* await writeFile(flow, "/docs/readme.md", "# Hello", "text/markdown");
|
|
3004
|
+
* ```
|
|
3005
|
+
*/
|
|
3006
|
+
declare function writeFile(flow: FlowState, path: string, data: ArrayBuffer | string, mimeType: string, options?: {
|
|
3007
|
+
metadata?: Record<string, unknown>;
|
|
3008
|
+
thumbnail?: ArrayBuffer;
|
|
3009
|
+
}): Promise<FileRecord>;
|
|
3010
|
+
/**
|
|
3011
|
+
* Write an image file with optional thumbnail
|
|
3012
|
+
*
|
|
3013
|
+
* @param flow - The current FlowState
|
|
3014
|
+
* @param path - File path
|
|
3015
|
+
* @param data - Image data as ArrayBuffer
|
|
3016
|
+
* @param mimeType - Image MIME type
|
|
3017
|
+
* @param options - Image metadata (width, height) and optional thumbnail
|
|
3018
|
+
* @returns The created file record
|
|
3019
|
+
*
|
|
3020
|
+
* @example
|
|
3021
|
+
* ```typescript
|
|
3022
|
+
* import { writeImage } from '@standardagents/builder';
|
|
3023
|
+
*
|
|
3024
|
+
* await writeImage(flow, "/images/photo.jpg", imageBuffer, "image/jpeg", {
|
|
3025
|
+
* metadata: { width: 1024, height: 768 },
|
|
3026
|
+
* thumbnail: thumbnailBuffer
|
|
3027
|
+
* });
|
|
3028
|
+
* ```
|
|
3029
|
+
*/
|
|
3030
|
+
declare function writeImage(flow: FlowState, path: string, data: ArrayBuffer, mimeType: string, options?: {
|
|
3031
|
+
metadata?: {
|
|
3032
|
+
width: number;
|
|
3033
|
+
height: number;
|
|
3034
|
+
[key: string]: unknown;
|
|
3035
|
+
};
|
|
3036
|
+
thumbnail?: ArrayBuffer;
|
|
3037
|
+
}): Promise<FileRecord>;
|
|
3038
|
+
/**
|
|
3039
|
+
* Link to an external file (URL, S3, R2)
|
|
3040
|
+
*
|
|
3041
|
+
* Creates a file entry pointing to an external location without storing the data locally.
|
|
3042
|
+
*
|
|
3043
|
+
* @param flow - The current FlowState
|
|
3044
|
+
* @param path - File path in thread storage
|
|
3045
|
+
* @param location - External location (https://, s3://, r2://)
|
|
3046
|
+
* @param options - Optional MIME type, size, and metadata
|
|
3047
|
+
* @returns The created file record
|
|
3048
|
+
*
|
|
3049
|
+
* @example
|
|
3050
|
+
* ```typescript
|
|
3051
|
+
* import { linkFile } from '@standardagents/builder';
|
|
3052
|
+
*
|
|
3053
|
+
* // Link to a URL
|
|
3054
|
+
* await linkFile(flow, "/images/hero.jpg", "https://cdn.example.com/hero.jpg");
|
|
3055
|
+
*
|
|
3056
|
+
* // Link to S3
|
|
3057
|
+
* await linkFile(flow, "/data/large.csv", "s3://mybucket/data/large.csv", {
|
|
3058
|
+
* mimeType: "text/csv",
|
|
3059
|
+
* size: 10 * 1024 * 1024 * 1024 // 10GB
|
|
3060
|
+
* });
|
|
3061
|
+
* ```
|
|
3062
|
+
*/
|
|
3063
|
+
declare function linkFile(flow: FlowState, path: string, location: string, options?: {
|
|
3064
|
+
mimeType?: string;
|
|
3065
|
+
size?: number;
|
|
3066
|
+
metadata?: Record<string, unknown>;
|
|
3067
|
+
}): Promise<FileRecord>;
|
|
3068
|
+
/**
|
|
3069
|
+
* Read a file from thread storage
|
|
3070
|
+
*
|
|
3071
|
+
* @param flow - The current FlowState
|
|
3072
|
+
* @param path - File path
|
|
3073
|
+
* @returns File data as ArrayBuffer, or null if not found/external
|
|
3074
|
+
*
|
|
3075
|
+
* @example
|
|
3076
|
+
* ```typescript
|
|
3077
|
+
* import { readFile } from '@standardagents/builder';
|
|
3078
|
+
*
|
|
3079
|
+
* const data = await readFile(flow, "/images/photo.jpg");
|
|
3080
|
+
* if (data) {
|
|
3081
|
+
* // Process binary data
|
|
3082
|
+
* }
|
|
3083
|
+
* ```
|
|
3084
|
+
*/
|
|
3085
|
+
declare function readFile(flow: FlowState, path: string): Promise<ArrayBuffer | null>;
|
|
3086
|
+
/**
|
|
3087
|
+
* Get file metadata
|
|
3088
|
+
*
|
|
3089
|
+
* @param flow - The current FlowState
|
|
3090
|
+
* @param path - File path
|
|
3091
|
+
* @returns File record or null if not found
|
|
3092
|
+
*
|
|
3093
|
+
* @example
|
|
3094
|
+
* ```typescript
|
|
3095
|
+
* import { stat } from '@standardagents/builder';
|
|
3096
|
+
*
|
|
3097
|
+
* const file = await stat(flow, "/images/photo.jpg");
|
|
3098
|
+
* if (file) {
|
|
3099
|
+
* console.log(`Size: ${file.size}, Type: ${file.mimeType}`);
|
|
3100
|
+
* }
|
|
3101
|
+
* ```
|
|
3102
|
+
*/
|
|
3103
|
+
declare function stat(flow: FlowState, path: string): Promise<FileRecord | null>;
|
|
3104
|
+
/**
|
|
3105
|
+
* Check if file or directory exists
|
|
3106
|
+
*
|
|
3107
|
+
* @param flow - The current FlowState
|
|
3108
|
+
* @param path - File path
|
|
3109
|
+
* @returns true if exists, false otherwise
|
|
3110
|
+
*
|
|
3111
|
+
* @example
|
|
3112
|
+
* ```typescript
|
|
3113
|
+
* import { exists } from '@standardagents/builder';
|
|
3114
|
+
*
|
|
3115
|
+
* if (await exists(flow, "/config.json")) {
|
|
3116
|
+
* // File exists
|
|
3117
|
+
* }
|
|
3118
|
+
* ```
|
|
3119
|
+
*/
|
|
3120
|
+
declare function exists(flow: FlowState, path: string): Promise<boolean>;
|
|
3121
|
+
/**
|
|
3122
|
+
* Delete a file
|
|
3123
|
+
*
|
|
3124
|
+
* @param flow - The current FlowState
|
|
3125
|
+
* @param path - File path
|
|
3126
|
+
*
|
|
3127
|
+
* @example
|
|
3128
|
+
* ```typescript
|
|
3129
|
+
* import { unlink } from '@standardagents/builder';
|
|
3130
|
+
*
|
|
3131
|
+
* await unlink(flow, "/temp/draft.txt");
|
|
3132
|
+
* ```
|
|
3133
|
+
*/
|
|
3134
|
+
declare function unlink(flow: FlowState, path: string): Promise<void>;
|
|
3135
|
+
/**
|
|
3136
|
+
* Create a directory
|
|
3137
|
+
*
|
|
3138
|
+
* @param flow - The current FlowState
|
|
3139
|
+
* @param path - Directory path
|
|
3140
|
+
* @returns The created directory record
|
|
3141
|
+
*
|
|
3142
|
+
* @example
|
|
3143
|
+
* ```typescript
|
|
3144
|
+
* import { mkdir } from '@standardagents/builder';
|
|
3145
|
+
*
|
|
3146
|
+
* await mkdir(flow, "/uploads/2024");
|
|
3147
|
+
* ```
|
|
3148
|
+
*/
|
|
3149
|
+
declare function mkdir(flow: FlowState, path: string): Promise<FileRecord>;
|
|
3150
|
+
/**
|
|
3151
|
+
* List directory contents
|
|
3152
|
+
*
|
|
3153
|
+
* @param flow - The current FlowState
|
|
3154
|
+
* @param path - Directory path
|
|
3155
|
+
* @returns Array of file records in the directory
|
|
3156
|
+
*
|
|
3157
|
+
* @example
|
|
3158
|
+
* ```typescript
|
|
3159
|
+
* import { readdir } from '@standardagents/builder';
|
|
3160
|
+
*
|
|
3161
|
+
* const files = await readdir(flow, "/images");
|
|
3162
|
+
* for (const file of files) {
|
|
3163
|
+
* console.log(file.name, file.size);
|
|
3164
|
+
* }
|
|
3165
|
+
* ```
|
|
3166
|
+
*/
|
|
3167
|
+
declare function readdir(flow: FlowState, path: string): Promise<FileRecord[]>;
|
|
3168
|
+
/**
|
|
3169
|
+
* Remove an empty directory
|
|
3170
|
+
*
|
|
3171
|
+
* @param flow - The current FlowState
|
|
3172
|
+
* @param path - Directory path
|
|
3173
|
+
*
|
|
3174
|
+
* @example
|
|
3175
|
+
* ```typescript
|
|
3176
|
+
* import { rmdir } from '@standardagents/builder';
|
|
3177
|
+
*
|
|
3178
|
+
* await rmdir(flow, "/temp");
|
|
3179
|
+
* ```
|
|
3180
|
+
*/
|
|
3181
|
+
declare function rmdir(flow: FlowState, path: string): Promise<void>;
|
|
3182
|
+
/**
|
|
3183
|
+
* Get file storage statistics
|
|
3184
|
+
*
|
|
3185
|
+
* @param flow - The current FlowState
|
|
3186
|
+
* @returns Storage statistics (total size and file count)
|
|
3187
|
+
*
|
|
3188
|
+
* @example
|
|
3189
|
+
* ```typescript
|
|
3190
|
+
* import { getFileStats } from '@standardagents/builder';
|
|
3191
|
+
*
|
|
3192
|
+
* const stats = await getFileStats(flow);
|
|
3193
|
+
* console.log(`Total: ${stats.totalSize} bytes, Files: ${stats.fileCount}`);
|
|
3194
|
+
* ```
|
|
3195
|
+
*/
|
|
3196
|
+
declare function getFileStats(flow: FlowState): Promise<FileStats>;
|
|
3197
|
+
/**
|
|
3198
|
+
* Get thumbnail for an image file
|
|
3199
|
+
*
|
|
3200
|
+
* @param flow - The current FlowState
|
|
3201
|
+
* @param path - Image file path
|
|
3202
|
+
* @returns Thumbnail data as ArrayBuffer, or null if not found
|
|
3203
|
+
*
|
|
3204
|
+
* @example
|
|
3205
|
+
* ```typescript
|
|
3206
|
+
* import { getThumbnail } from '@standardagents/builder';
|
|
3207
|
+
*
|
|
3208
|
+
* const thumb = await getThumbnail(flow, "/images/photo.jpg");
|
|
3209
|
+
* ```
|
|
3210
|
+
*/
|
|
3211
|
+
declare function getThumbnail(flow: FlowState, path: string): Promise<ArrayBuffer | null>;
|
|
3212
|
+
/**
|
|
3213
|
+
* Read a text file as string
|
|
3214
|
+
*
|
|
3215
|
+
* @param flow - The current FlowState
|
|
3216
|
+
* @param path - File path
|
|
3217
|
+
* @returns File content as string, or null if not found
|
|
3218
|
+
*
|
|
3219
|
+
* @example
|
|
3220
|
+
* ```typescript
|
|
3221
|
+
* import { cat } from '@standardagents/builder';
|
|
3222
|
+
*
|
|
3223
|
+
* const content = await cat(flow, "/docs/readme.md");
|
|
3224
|
+
* ```
|
|
3225
|
+
*/
|
|
3226
|
+
declare function cat(flow: FlowState, path: string): Promise<string | null>;
|
|
3227
|
+
/**
|
|
3228
|
+
* Read first N lines of a text file
|
|
3229
|
+
*
|
|
3230
|
+
* @param flow - The current FlowState
|
|
3231
|
+
* @param path - File path
|
|
3232
|
+
* @param lines - Number of lines to read (default: 10)
|
|
3233
|
+
* @returns First N lines as string, or null if not found
|
|
3234
|
+
*
|
|
3235
|
+
* @example
|
|
3236
|
+
* ```typescript
|
|
3237
|
+
* import { head } from '@standardagents/builder';
|
|
3238
|
+
*
|
|
3239
|
+
* const firstLines = await head(flow, "/logs/app.log", 20);
|
|
3240
|
+
* ```
|
|
3241
|
+
*/
|
|
3242
|
+
declare function head(flow: FlowState, path: string, lines?: number): Promise<string | null>;
|
|
3243
|
+
/**
|
|
3244
|
+
* Read last N lines of a text file
|
|
3245
|
+
*
|
|
3246
|
+
* @param flow - The current FlowState
|
|
3247
|
+
* @param path - File path
|
|
3248
|
+
* @param lines - Number of lines to read (default: 10)
|
|
3249
|
+
* @returns Last N lines as string, or null if not found
|
|
3250
|
+
*
|
|
3251
|
+
* @example
|
|
3252
|
+
* ```typescript
|
|
3253
|
+
* import { tail } from '@standardagents/builder';
|
|
3254
|
+
*
|
|
3255
|
+
* const lastLines = await tail(flow, "/logs/app.log", 50);
|
|
3256
|
+
* ```
|
|
3257
|
+
*/
|
|
3258
|
+
declare function tail(flow: FlowState, path: string, lines?: number): Promise<string | null>;
|
|
3259
|
+
/**
|
|
3260
|
+
* Search text file contents using FTS5 full-text search
|
|
3261
|
+
*
|
|
3262
|
+
* @param flow - The current FlowState
|
|
3263
|
+
* @param pattern - Search pattern (FTS5 syntax)
|
|
3264
|
+
* @param options - Search options
|
|
3265
|
+
* @returns Array of matching results with snippets
|
|
3266
|
+
*
|
|
3267
|
+
* @example
|
|
3268
|
+
* ```typescript
|
|
3269
|
+
* import { grep } from '@standardagents/builder';
|
|
3270
|
+
*
|
|
3271
|
+
* // Search all files
|
|
3272
|
+
* const results = await grep(flow, "error");
|
|
3273
|
+
*
|
|
3274
|
+
* // Search in specific directory
|
|
3275
|
+
* const results = await grep(flow, "TODO", { path: "/src" });
|
|
3276
|
+
* ```
|
|
3277
|
+
*/
|
|
3278
|
+
declare function grep(flow: FlowState, pattern: string, options?: {
|
|
3279
|
+
path?: string;
|
|
3280
|
+
limit?: number;
|
|
3281
|
+
}): Promise<GrepResult[]>;
|
|
3282
|
+
/**
|
|
3283
|
+
* Find files by path pattern
|
|
3284
|
+
*
|
|
3285
|
+
* @param flow - The current FlowState
|
|
3286
|
+
* @param pattern - Glob-like pattern (e.g., "*.md", "/docs/subdir/*.txt")
|
|
3287
|
+
* @param options - Find options
|
|
3288
|
+
* @returns Array of matching file records
|
|
3289
|
+
*
|
|
3290
|
+
* @example
|
|
3291
|
+
* ```typescript
|
|
3292
|
+
* import { find } from '@standardagents/builder';
|
|
3293
|
+
*
|
|
3294
|
+
* // Find all markdown files
|
|
3295
|
+
* const mdFiles = await find(flow, "*.md");
|
|
3296
|
+
*
|
|
3297
|
+
* // Find all files in docs
|
|
3298
|
+
* const docFiles = await find(flow, "/docs/*", { type: "file" });
|
|
3299
|
+
* ```
|
|
3300
|
+
*/
|
|
3301
|
+
declare function find(flow: FlowState, pattern: string, options?: {
|
|
3302
|
+
type?: "file" | "directory" | "all";
|
|
3303
|
+
limit?: number;
|
|
3304
|
+
}): Promise<FileRecord[]>;
|
|
2611
3305
|
|
|
2612
3306
|
/**
|
|
2613
3307
|
* Options for injecting a message
|
|
@@ -2854,6 +3548,67 @@ interface FlowStateWithSdk extends FlowState {
|
|
|
2854
3548
|
*/
|
|
2855
3549
|
declare function enhanceFlowState(flow: FlowState): FlowStateWithSdk;
|
|
2856
3550
|
|
|
3551
|
+
/**
|
|
3552
|
+
* Context Management for Image Attachments
|
|
3553
|
+
*
|
|
3554
|
+
* Handles auto-summarization of old images to reduce context window usage
|
|
3555
|
+
* while preserving the semantic meaning of image content.
|
|
3556
|
+
*/
|
|
3557
|
+
|
|
3558
|
+
/**
|
|
3559
|
+
* Configuration for image context management
|
|
3560
|
+
*/
|
|
3561
|
+
interface ImageContextConfig {
|
|
3562
|
+
/** Number of recent messages to keep images for (default: 10) */
|
|
3563
|
+
recentMessageThreshold: number;
|
|
3564
|
+
/** System prompt for generating image descriptions */
|
|
3565
|
+
descriptionPrompt: string;
|
|
3566
|
+
}
|
|
3567
|
+
/**
|
|
3568
|
+
* Check if a message has image attachments that could be summarized
|
|
3569
|
+
*/
|
|
3570
|
+
declare function hasImageAttachments(message: Message): boolean;
|
|
3571
|
+
/**
|
|
3572
|
+
* Get image attachments from a message that don't have descriptions yet
|
|
3573
|
+
*/
|
|
3574
|
+
declare function getUnsummarizedImageAttachments(message: Message): AttachmentRef[];
|
|
3575
|
+
/**
|
|
3576
|
+
* Determine which messages should have their images replaced with descriptions.
|
|
3577
|
+
* Returns indices of messages that are old enough to be summarized.
|
|
3578
|
+
*/
|
|
3579
|
+
declare function getMessagesToSummarize(messages: Message[], config?: ImageContextConfig): number[];
|
|
3580
|
+
/**
|
|
3581
|
+
* Build text representation for an image attachment (used when image is too old)
|
|
3582
|
+
*/
|
|
3583
|
+
declare function buildImageDescription(attachment: AttachmentRef): string;
|
|
3584
|
+
/**
|
|
3585
|
+
* Transform message content to replace old images with text descriptions.
|
|
3586
|
+
* This modifies the content array for LLM context building.
|
|
3587
|
+
*/
|
|
3588
|
+
declare function replaceImagesWithDescriptions(content: MessageContent, attachments: AttachmentRef[]): MessageContent;
|
|
3589
|
+
/**
|
|
3590
|
+
* Process message history to optimize context window usage.
|
|
3591
|
+
* Old images are replaced with their text descriptions.
|
|
3592
|
+
*
|
|
3593
|
+
* @param messages - Full message history
|
|
3594
|
+
* @param config - Context management configuration
|
|
3595
|
+
* @returns Processed messages with old images replaced by descriptions
|
|
3596
|
+
*/
|
|
3597
|
+
declare function optimizeImageContext(messages: Message[], config?: ImageContextConfig): Message[];
|
|
3598
|
+
/**
|
|
3599
|
+
* Generate a description for an image using a vision model.
|
|
3600
|
+
* This should be called when storing new messages with images.
|
|
3601
|
+
*
|
|
3602
|
+
* Note: This function is a placeholder for the actual LLM call.
|
|
3603
|
+
* The actual implementation would need to make an API call to a vision model.
|
|
3604
|
+
*
|
|
3605
|
+
* @param imageBase64 - Base64-encoded image data
|
|
3606
|
+
* @param mimeType - MIME type of the image
|
|
3607
|
+
* @param state - Flow state for LLM access
|
|
3608
|
+
* @returns Generated description
|
|
3609
|
+
*/
|
|
3610
|
+
declare function generateImageDescription(_imageBase64: string, _mimeType: string, _state: FlowState): Promise<string | null>;
|
|
3611
|
+
|
|
2857
3612
|
/**
|
|
2858
3613
|
* Types for GitHub REST API integration.
|
|
2859
3614
|
*/
|
|
@@ -3022,4 +3777,4 @@ declare class GitHubApiError extends Error {
|
|
|
3022
3777
|
constructor(message: string, status: number, details?: unknown);
|
|
3023
3778
|
}
|
|
3024
3779
|
|
|
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 };
|
|
3780
|
+
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 };
|