llmist 2.5.0 → 3.0.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.
@@ -745,9 +745,9 @@ declare class ModelIdentifierParser {
745
745
  */
746
746
 
747
747
  /**
748
- * Options for quick execution methods.
748
+ * Options for text generation methods (complete/stream).
749
749
  */
750
- interface QuickOptions {
750
+ interface TextGenerationOptions {
751
751
  /** Model to use (supports aliases like "gpt4", "sonnet", "flash") */
752
752
  model?: string;
753
753
  /** Temperature (0-1) */
@@ -772,7 +772,7 @@ interface QuickOptions {
772
772
  * console.log(answer); // "4" or "2+2 equals 4"
773
773
  * ```
774
774
  */
775
- declare function complete(client: LLMist, prompt: string, options?: QuickOptions): Promise<string>;
775
+ declare function complete(client: LLMist, prompt: string, options?: TextGenerationOptions): Promise<string>;
776
776
  /**
777
777
  * Quick streaming - returns async generator of text chunks.
778
778
  *
@@ -790,7 +790,7 @@ declare function complete(client: LLMist, prompt: string, options?: QuickOptions
790
790
  * }
791
791
  * ```
792
792
  */
793
- declare function stream(client: LLMist, prompt: string, options?: QuickOptions): AsyncGenerator<string>;
793
+ declare function stream(client: LLMist, prompt: string, options?: TextGenerationOptions): AsyncGenerator<string>;
794
794
 
795
795
  /**
796
796
  * Example of gadget usage to help LLMs understand proper invocation.
@@ -819,6 +819,81 @@ interface GadgetExample<TParams = Record<string, unknown>> {
819
819
  /** Optional description explaining what this example demonstrates */
820
820
  comment?: string;
821
821
  }
822
+ /**
823
+ * Supported media types for gadget output.
824
+ * Extensible via union - add new types as needed.
825
+ */
826
+ type MediaKind = "image" | "audio" | "video" | "file";
827
+ /**
828
+ * Type-specific metadata for media outputs.
829
+ * Extensible via index signature for future media types.
830
+ */
831
+ interface MediaMetadata {
832
+ /** Width in pixels (images, video) */
833
+ width?: number;
834
+ /** Height in pixels (images, video) */
835
+ height?: number;
836
+ /** Duration in milliseconds (audio, video) */
837
+ durationMs?: number;
838
+ /** Allow additional metadata for future extensions */
839
+ [key: string]: unknown;
840
+ }
841
+ /**
842
+ * Media output from a gadget execution.
843
+ * Supports images, audio, video, and arbitrary files.
844
+ *
845
+ * @example
846
+ * ```typescript
847
+ * // Image output
848
+ * const imageOutput: GadgetMediaOutput = {
849
+ * kind: "image",
850
+ * data: base64EncodedPng,
851
+ * mimeType: "image/png",
852
+ * description: "Screenshot of webpage",
853
+ * metadata: { width: 1920, height: 1080 }
854
+ * };
855
+ * ```
856
+ */
857
+ interface GadgetMediaOutput {
858
+ /** Type of media (discriminator for type-specific handling) */
859
+ kind: MediaKind;
860
+ /** Base64-encoded media data */
861
+ data: string;
862
+ /** Full MIME type (e.g., "image/png", "audio/mp3", "video/mp4") */
863
+ mimeType: string;
864
+ /** Human-readable description of the media */
865
+ description?: string;
866
+ /** Type-specific metadata */
867
+ metadata?: MediaMetadata;
868
+ /** Optional filename to use when saving (if not provided, auto-generated) */
869
+ fileName?: string;
870
+ }
871
+ /**
872
+ * Stored media item with metadata and file path.
873
+ *
874
+ * Created by MediaStore when a gadget returns media outputs.
875
+ * Contains the abstract ID, file path, and metadata for display.
876
+ */
877
+ interface StoredMedia {
878
+ /** Unique ID for this media item (e.g., "media_a1b2c3") */
879
+ id: string;
880
+ /** Type of media */
881
+ kind: MediaKind;
882
+ /** Actual file path on disk (internal use) */
883
+ path: string;
884
+ /** MIME type */
885
+ mimeType: string;
886
+ /** File size in bytes */
887
+ sizeBytes: number;
888
+ /** Human-readable description */
889
+ description?: string;
890
+ /** Type-specific metadata */
891
+ metadata?: MediaMetadata;
892
+ /** Name of the gadget that created this media */
893
+ gadgetName: string;
894
+ /** When the media was stored */
895
+ createdAt: Date;
896
+ }
822
897
  interface GadgetExecutionResult {
823
898
  gadgetName: string;
824
899
  invocationId: string;
@@ -829,6 +904,12 @@ interface GadgetExecutionResult {
829
904
  breaksLoop?: boolean;
830
905
  /** Cost of gadget execution in USD. Defaults to 0 if not provided by gadget. */
831
906
  cost?: number;
907
+ /** Media outputs from the gadget (images, audio, video, files) */
908
+ media?: GadgetMediaOutput[];
909
+ /** Abstract IDs for media outputs (e.g., ["media_a1b2c3"]) */
910
+ mediaIds?: string[];
911
+ /** Stored media with paths (for CLI display) */
912
+ storedMedia?: StoredMedia[];
832
913
  }
833
914
  /**
834
915
  * Result returned by gadget execute() method.
@@ -849,12 +930,41 @@ interface GadgetExecuteResult {
849
930
  /** Optional cost in USD (e.g., 0.001 for $0.001) */
850
931
  cost?: number;
851
932
  }
933
+ /**
934
+ * Extended result type with media support.
935
+ * Use this when gadget returns images, audio, video, or files.
936
+ *
937
+ * @example
938
+ * ```typescript
939
+ * // Return with image
940
+ * execute: () => ({
941
+ * result: "Screenshot captured",
942
+ * media: [{
943
+ * kind: "image",
944
+ * data: base64EncodedPng,
945
+ * mimeType: "image/png",
946
+ * description: "Screenshot"
947
+ * }],
948
+ * cost: 0.001
949
+ * })
950
+ * ```
951
+ */
952
+ interface GadgetExecuteResultWithMedia {
953
+ /** The execution result as a string */
954
+ result: string;
955
+ /** Media outputs (images, audio, video, files) */
956
+ media?: GadgetMediaOutput[];
957
+ /** Optional cost in USD (e.g., 0.001 for $0.001) */
958
+ cost?: number;
959
+ }
852
960
  /**
853
961
  * Union type for backwards-compatible execute() return type.
854
- * Gadgets can return either a string (legacy, cost = 0) or
855
- * an object with result and optional cost.
962
+ * Gadgets can return:
963
+ * - string (legacy, cost = 0)
964
+ * - GadgetExecuteResult (result + optional cost)
965
+ * - GadgetExecuteResultWithMedia (result + optional media + optional cost)
856
966
  */
857
- type GadgetExecuteReturn = string | GadgetExecuteResult;
967
+ type GadgetExecuteReturn = string | GadgetExecuteResult | GadgetExecuteResultWithMedia;
858
968
  interface ParsedGadgetCall {
859
969
  gadgetName: string;
860
970
  invocationId: string;
@@ -993,12 +1103,12 @@ interface CostReportingLLMist {
993
1103
  * Quick completion - returns final text response.
994
1104
  * Costs are automatically reported to the execution context.
995
1105
  */
996
- complete(prompt: string, options?: QuickOptions): Promise<string>;
1106
+ complete(prompt: string, options?: TextGenerationOptions): Promise<string>;
997
1107
  /**
998
1108
  * Quick streaming - returns async generator of text chunks.
999
1109
  * Costs are automatically reported when the stream completes.
1000
1110
  */
1001
- streamText(prompt: string, options?: QuickOptions): AsyncGenerator<string>;
1111
+ streamText(prompt: string, options?: TextGenerationOptions): AsyncGenerator<string>;
1002
1112
  /**
1003
1113
  * Low-level stream access for full control.
1004
1114
  * Costs are automatically reported based on usage metadata in chunks.
@@ -1147,16 +1257,111 @@ interface ExecutionContext {
1147
1257
  * ```
1148
1258
  */
1149
1259
  signal: AbortSignal;
1260
+ /**
1261
+ * Parent agent configuration for subagents to inherit.
1262
+ *
1263
+ * Contains the model and settings of the agent that invoked this gadget.
1264
+ * Subagent gadgets (like BrowseWeb) can use this to inherit the parent's
1265
+ * model by default, rather than using hardcoded defaults.
1266
+ *
1267
+ * This is optional - it will be `undefined` for:
1268
+ * - Gadgets executed via CLI `gadget run` command
1269
+ * - Direct gadget testing without agent context
1270
+ *
1271
+ * @example
1272
+ * ```typescript
1273
+ * execute: async (params, ctx) => {
1274
+ * // Inherit parent model unless explicitly specified
1275
+ * const model = params.model ?? ctx.agentConfig?.model ?? "sonnet";
1276
+ *
1277
+ * const agent = new AgentBuilder(new LLMist())
1278
+ * .withModel(model)
1279
+ * .build();
1280
+ * // ...
1281
+ * }
1282
+ * ```
1283
+ */
1284
+ agentConfig?: AgentContextConfig;
1285
+ /**
1286
+ * Subagent-specific configuration overrides from CLI config.
1287
+ *
1288
+ * Contains per-subagent settings defined in `[subagents.Name]` or
1289
+ * `[profile.subagents.Name]` sections of cli.toml. Allows users to
1290
+ * customize subagent behavior without modifying gadget parameters.
1291
+ *
1292
+ * Resolution priority (highest to lowest):
1293
+ * 1. Runtime params (explicit gadget call)
1294
+ * 2. Profile-level subagent config
1295
+ * 3. Global subagent config
1296
+ * 4. Parent model (if "inherit")
1297
+ * 5. Package defaults
1298
+ *
1299
+ * @example
1300
+ * ```typescript
1301
+ * execute: async (params, ctx) => {
1302
+ * const subagentConfig = ctx.subagentConfig?.BrowseWeb ?? {};
1303
+ *
1304
+ * const model = params.model
1305
+ * ?? subagentConfig.model
1306
+ * ?? ctx.agentConfig?.model
1307
+ * ?? "sonnet";
1308
+ *
1309
+ * const maxIterations = params.maxIterations
1310
+ * ?? subagentConfig.maxIterations
1311
+ * ?? 15;
1312
+ * // ...
1313
+ * }
1314
+ * ```
1315
+ */
1316
+ subagentConfig?: SubagentConfigMap;
1150
1317
  }
1318
+ /**
1319
+ * Parent agent configuration passed to gadgets.
1320
+ * Contains settings that subagents can inherit.
1321
+ */
1322
+ interface AgentContextConfig {
1323
+ /** Model identifier used by the parent agent */
1324
+ model: string;
1325
+ /** Temperature setting used by the parent agent */
1326
+ temperature?: number;
1327
+ }
1328
+ /**
1329
+ * Configuration for a single subagent.
1330
+ * Can be defined globally in `[subagents.Name]` or per-profile in `[profile.subagents.Name]`.
1331
+ *
1332
+ * @example
1333
+ * ```toml
1334
+ * [subagents.BrowseWeb]
1335
+ * model = "inherit" # Use parent agent's model
1336
+ * maxIterations = 20
1337
+ * headless = true
1338
+ * ```
1339
+ */
1340
+ interface SubagentConfig {
1341
+ /**
1342
+ * Model to use for this subagent.
1343
+ * - "inherit": Use parent agent's model (default behavior)
1344
+ * - Any model ID: Use specific model (e.g., "sonnet", "haiku", "gpt-4o")
1345
+ */
1346
+ model?: string;
1347
+ /** Maximum iterations for the subagent loop */
1348
+ maxIterations?: number;
1349
+ /** Additional subagent-specific options */
1350
+ [key: string]: unknown;
1351
+ }
1352
+ /**
1353
+ * Map of subagent names to their configurations.
1354
+ */
1355
+ type SubagentConfigMap = Record<string, SubagentConfig>;
1151
1356
 
1152
1357
  /**
1153
- * Internal base class for gadgets. Most users should use the `Gadget` class
1154
- * (formerly TypedGadget) or `createGadget()` function instead, as they provide
1155
- * better type safety and simpler APIs.
1358
+ * Abstract base class for gadgets. Most users should use the `Gadget()` factory
1359
+ * or `createGadget()` function instead, as they provide better type safety
1360
+ * and simpler APIs.
1156
1361
  *
1157
- * @internal
1362
+ * Extend this class directly only when you need advanced control over gadget behavior.
1158
1363
  */
1159
- declare abstract class BaseGadget {
1364
+ declare abstract class AbstractGadget {
1160
1365
  /**
1161
1366
  * The name of the gadget. Used for identification when LLM calls it.
1162
1367
  * If not provided, defaults to the class name.
@@ -1222,14 +1427,14 @@ declare abstract class BaseGadget {
1222
1427
  */
1223
1428
  abstract execute(params: Record<string, unknown>, ctx?: ExecutionContext): GadgetExecuteReturn | Promise<GadgetExecuteReturn>;
1224
1429
  /**
1225
- * Throws an AbortError if the execution has been aborted.
1430
+ * Throws an AbortException if the execution has been aborted.
1226
1431
  *
1227
1432
  * Call this at key checkpoints in long-running gadgets to allow early exit
1228
1433
  * when the gadget has been cancelled (e.g., due to timeout). This enables
1229
1434
  * resource cleanup and prevents unnecessary work after cancellation.
1230
1435
  *
1231
1436
  * @param ctx - The execution context containing the abort signal
1232
- * @throws AbortError if ctx.signal.aborted is true
1437
+ * @throws AbortException if ctx.signal.aborted is true
1233
1438
  *
1234
1439
  * @example
1235
1440
  * ```typescript
@@ -1350,7 +1555,7 @@ type ImageMimeType = "image/jpeg" | "image/png" | "image/gif" | "image/webp";
1350
1555
  * Supported audio MIME types for input.
1351
1556
  * Currently only Gemini supports audio input.
1352
1557
  */
1353
- type AudioMimeType = "audio/mp3" | "audio/mpeg" | "audio/wav" | "audio/webm" | "audio/ogg";
1558
+ type AudioMimeType = "audio/mp3" | "audio/mpeg" | "audio/wav" | "audio/webm" | "audio/ogg" | "audio/flac";
1354
1559
  /**
1355
1560
  * Base interface for all content parts.
1356
1561
  */
@@ -1587,7 +1792,7 @@ type HintTemplate = string | ((context: HintContext) => string);
1587
1792
  *
1588
1793
  * @example
1589
1794
  * ```typescript
1590
- * const customConfig: PromptConfig = {
1795
+ * const customConfig: PromptTemplateConfig = {
1591
1796
  * mainInstruction: "USE ONLY THE GADGET MARKERS BELOW:",
1592
1797
  * criticalUsage: "Important: Follow the exact format shown.",
1593
1798
  * rules: (ctx) => [
@@ -1598,7 +1803,7 @@ type HintTemplate = string | ((context: HintContext) => string);
1598
1803
  * };
1599
1804
  * ```
1600
1805
  */
1601
- interface PromptConfig {
1806
+ interface PromptTemplateConfig {
1602
1807
  /**
1603
1808
  * Main instruction block that appears at the start of the gadget system prompt.
1604
1809
  * Default emphasizes using text markers instead of function calling.
@@ -1652,7 +1857,7 @@ declare const DEFAULT_HINTS: {
1652
1857
  /**
1653
1858
  * Default prompt templates used by llmist.
1654
1859
  */
1655
- declare const DEFAULT_PROMPTS: Required<Omit<PromptConfig, "rules" | "customExamples" | "parallelGadgetsHint" | "iterationProgressHint"> & {
1860
+ declare const DEFAULT_PROMPTS: Required<Omit<PromptTemplateConfig, "rules" | "customExamples" | "parallelGadgetsHint" | "iterationProgressHint"> & {
1656
1861
  rules: (context: PromptContext) => string[];
1657
1862
  customExamples: null;
1658
1863
  }>;
@@ -1663,7 +1868,7 @@ declare function resolvePromptTemplate(template: PromptTemplate | undefined, def
1663
1868
  /**
1664
1869
  * Resolve rules template to an array of strings.
1665
1870
  */
1666
- declare function resolveRulesTemplate(rules: PromptConfig["rules"] | undefined, context: PromptContext): string[];
1871
+ declare function resolveRulesTemplate(rules: PromptTemplateConfig["rules"] | undefined, context: PromptContext): string[];
1667
1872
  /**
1668
1873
  * Resolve a hint template to a string using the given context.
1669
1874
  * Supports both function templates and string templates with placeholders.
@@ -1675,14 +1880,14 @@ declare function resolveRulesTemplate(rules: PromptConfig["rules"] | undefined,
1675
1880
  */
1676
1881
  declare function resolveHintTemplate(template: HintTemplate | undefined, defaultValue: string, context: HintContext): string;
1677
1882
 
1678
- type LLMRole = "system" | "user" | "assistant";
1883
+ type MessageRole = "system" | "user" | "assistant";
1679
1884
  /**
1680
1885
  * Message content can be a simple string (text only) or an array of content parts (multimodal).
1681
1886
  * Using a string is simpler for text-only messages, while arrays support images and audio.
1682
1887
  */
1683
1888
  type MessageContent = string | ContentPart[];
1684
1889
  interface LLMMessage {
1685
- role: LLMRole;
1890
+ role: MessageRole;
1686
1891
  content: MessageContent;
1687
1892
  name?: string;
1688
1893
  metadata?: Record<string, unknown>;
@@ -1694,7 +1899,7 @@ interface LLMMessage {
1694
1899
  * @param content - Message content (string or ContentPart[])
1695
1900
  * @returns Array of content parts
1696
1901
  */
1697
- declare function normalizeContent(content: MessageContent): ContentPart[];
1902
+ declare function normalizeMessageContent(content: MessageContent): ContentPart[];
1698
1903
  /**
1699
1904
  * Extract text from message content.
1700
1905
  * Concatenates all text parts in the content.
@@ -1702,21 +1907,21 @@ declare function normalizeContent(content: MessageContent): ContentPart[];
1702
1907
  * @param content - Message content (string or ContentPart[])
1703
1908
  * @returns Combined text from all text parts
1704
1909
  */
1705
- declare function extractText(content: MessageContent): string;
1910
+ declare function extractMessageText(content: MessageContent): string;
1706
1911
  declare class LLMMessageBuilder {
1707
1912
  private readonly messages;
1708
1913
  private startPrefix;
1709
1914
  private endPrefix;
1710
1915
  private argPrefix;
1711
1916
  private promptConfig;
1712
- constructor(promptConfig?: PromptConfig);
1917
+ constructor(promptConfig?: PromptTemplateConfig);
1713
1918
  /**
1714
1919
  * Set custom prefixes for gadget markers.
1715
1920
  * Used to configure history builder to match system prompt markers.
1716
1921
  */
1717
1922
  withPrefixes(startPrefix: string, endPrefix: string, argPrefix?: string): this;
1718
1923
  addSystem(content: string, metadata?: Record<string, unknown>): this;
1719
- addGadgets(gadgets: BaseGadget[], options?: {
1924
+ addGadgets(gadgets: AbstractGadget[], options?: {
1720
1925
  startPrefix?: string;
1721
1926
  endPrefix?: string;
1722
1927
  argPrefix?: string;
@@ -1811,7 +2016,17 @@ declare class LLMMessageBuilder {
1811
2016
  * ```
1812
2017
  */
1813
2018
  addUserMultimodal(parts: ContentPart[]): this;
1814
- addGadgetCall(gadget: string, parameters: Record<string, unknown>, result: string): this;
2019
+ /**
2020
+ * Record a gadget execution result in the message history.
2021
+ * Creates an assistant message with the gadget invocation and a user message with the result.
2022
+ *
2023
+ * @param gadget - Name of the gadget that was executed
2024
+ * @param parameters - Parameters that were passed to the gadget
2025
+ * @param result - Text result from the gadget execution
2026
+ * @param media - Optional media outputs from the gadget
2027
+ * @param mediaIds - Optional IDs for the media outputs
2028
+ */
2029
+ addGadgetCallResult(gadget: string, parameters: Record<string, unknown>, result: string, media?: GadgetMediaOutput[], mediaIds?: string[]): this;
1815
2030
  /**
1816
2031
  * Format parameters as Block format with JSON Pointer paths.
1817
2032
  * Uses the configured argPrefix for consistency with system prompt.
@@ -2004,7 +2219,7 @@ declare class TextNamespace {
2004
2219
  * @param options - Optional configuration
2005
2220
  * @returns Complete text response
2006
2221
  */
2007
- complete(prompt: string, options?: QuickOptions): Promise<string>;
2222
+ complete(prompt: string, options?: TextGenerationOptions): Promise<string>;
2008
2223
  /**
2009
2224
  * Stream text chunks.
2010
2225
  *
@@ -2012,7 +2227,7 @@ declare class TextNamespace {
2012
2227
  * @param options - Optional configuration
2013
2228
  * @returns Async generator yielding text chunks
2014
2229
  */
2015
- stream(prompt: string, options?: QuickOptions): AsyncGenerator<string>;
2230
+ stream(prompt: string, options?: TextGenerationOptions): AsyncGenerator<string>;
2016
2231
  }
2017
2232
 
2018
2233
  /**
@@ -2235,7 +2450,7 @@ declare class LLMist {
2235
2450
  * });
2236
2451
  * ```
2237
2452
  */
2238
- static complete(prompt: string, options?: QuickOptions): Promise<string>;
2453
+ static complete(prompt: string, options?: TextGenerationOptions): Promise<string>;
2239
2454
  /**
2240
2455
  * Quick streaming - returns async generator of text chunks.
2241
2456
  * Convenient for streaming responses without needing agent setup.
@@ -2259,7 +2474,7 @@ declare class LLMist {
2259
2474
  * }
2260
2475
  * ```
2261
2476
  */
2262
- static stream(prompt: string, options?: QuickOptions): AsyncGenerator<string>;
2477
+ static stream(prompt: string, options?: TextGenerationOptions): AsyncGenerator<string>;
2263
2478
  /**
2264
2479
  * Instance method: Quick completion using this client instance.
2265
2480
  *
@@ -2267,7 +2482,7 @@ declare class LLMist {
2267
2482
  * @param options - Optional configuration
2268
2483
  * @returns Complete text response
2269
2484
  */
2270
- complete(prompt: string, options?: QuickOptions): Promise<string>;
2485
+ complete(prompt: string, options?: TextGenerationOptions): Promise<string>;
2271
2486
  /**
2272
2487
  * Instance method: Quick streaming using this client instance.
2273
2488
  *
@@ -2275,7 +2490,7 @@ declare class LLMist {
2275
2490
  * @param options - Optional configuration
2276
2491
  * @returns Async generator yielding text chunks
2277
2492
  */
2278
- streamText(prompt: string, options?: QuickOptions): AsyncGenerator<string>;
2493
+ streamText(prompt: string, options?: TextGenerationOptions): AsyncGenerator<string>;
2279
2494
  /**
2280
2495
  * Create a fluent agent builder.
2281
2496
  * Provides a chainable API for configuring and creating agents.
@@ -2322,8 +2537,8 @@ declare class LLMist {
2322
2537
  createAgent(): AgentBuilder;
2323
2538
  }
2324
2539
 
2325
- type GadgetClass = new (...args: unknown[]) => BaseGadget;
2326
- type GadgetOrClass = BaseGadget | GadgetClass;
2540
+ type GadgetClass = new (...args: unknown[]) => AbstractGadget;
2541
+ type GadgetOrClass = AbstractGadget | GadgetClass;
2327
2542
  declare class GadgetRegistry {
2328
2543
  private readonly gadgets;
2329
2544
  /**
@@ -2362,16 +2577,131 @@ declare class GadgetRegistry {
2362
2577
  * ```
2363
2578
  */
2364
2579
  registerMany(gadgets: GadgetOrClass[]): this;
2365
- register(name: string, gadget: BaseGadget): void;
2366
- registerByClass(gadget: BaseGadget): void;
2367
- get(name: string): BaseGadget | undefined;
2580
+ register(name: string, gadget: AbstractGadget): void;
2581
+ registerByClass(gadget: AbstractGadget): void;
2582
+ get(name: string): AbstractGadget | undefined;
2368
2583
  has(name: string): boolean;
2369
2584
  getNames(): string[];
2370
- getAll(): BaseGadget[];
2585
+ getAll(): AbstractGadget[];
2371
2586
  unregister(name: string): boolean;
2372
2587
  clear(): void;
2373
2588
  }
2374
2589
 
2590
+ /**
2591
+ * MediaStore: Session-scoped storage for gadget media outputs.
2592
+ *
2593
+ * This module provides an abstraction layer between gadgets and the filesystem.
2594
+ * Instead of exposing raw file paths, it assigns unique IDs to stored media
2595
+ * that can be shared with the LLM and user.
2596
+ *
2597
+ * @example
2598
+ * ```typescript
2599
+ * const store = new MediaStore();
2600
+ *
2601
+ * // Store an image, get back ID
2602
+ * const stored = await store.store({
2603
+ * kind: "image",
2604
+ * data: base64EncodedPng,
2605
+ * mimeType: "image/png",
2606
+ * description: "Screenshot"
2607
+ * }, "Screenshot");
2608
+ *
2609
+ * console.log(stored.id); // "media_a1b2c3"
2610
+ * console.log(stored.path); // "/tmp/llmist-media-xxx/Screenshot_001.png"
2611
+ *
2612
+ * // Later: retrieve by ID
2613
+ * const retrieved = store.get("media_a1b2c3");
2614
+ * ```
2615
+ */
2616
+
2617
+ /**
2618
+ * Session-scoped media storage with ID abstraction.
2619
+ *
2620
+ * Each MediaStore instance manages media for a single agent session.
2621
+ * Media files are stored in a temporary directory and referenced by
2622
+ * short, unique IDs rather than file paths.
2623
+ */
2624
+ declare class MediaStore {
2625
+ private readonly items;
2626
+ private readonly outputDir;
2627
+ private counter;
2628
+ private initialized;
2629
+ /**
2630
+ * Create a new MediaStore.
2631
+ *
2632
+ * @param sessionId - Optional session ID for the output directory.
2633
+ * If not provided, a random ID is generated.
2634
+ */
2635
+ constructor(sessionId?: string);
2636
+ /**
2637
+ * Get the output directory path.
2638
+ */
2639
+ getOutputDir(): string;
2640
+ /**
2641
+ * Ensure the output directory exists.
2642
+ * @throws Error if directory creation fails
2643
+ */
2644
+ private ensureDir;
2645
+ /**
2646
+ * Generate a unique media ID.
2647
+ * Format: "media_" + 6 random alphanumeric characters
2648
+ */
2649
+ private generateId;
2650
+ /**
2651
+ * Get file extension from MIME type.
2652
+ */
2653
+ private getExtension;
2654
+ /**
2655
+ * Store media and return stored metadata with ID.
2656
+ *
2657
+ * @param media - The media output from a gadget
2658
+ * @param gadgetName - Name of the gadget that created this media
2659
+ * @returns Stored media information including generated ID
2660
+ * @throws Error if file write fails
2661
+ */
2662
+ store(media: GadgetMediaOutput, gadgetName: string): Promise<StoredMedia>;
2663
+ /**
2664
+ * Get stored media by ID.
2665
+ *
2666
+ * @param id - The media ID (e.g., "media_a1b2c3")
2667
+ * @returns The stored media or undefined if not found
2668
+ */
2669
+ get(id: string): StoredMedia | undefined;
2670
+ /**
2671
+ * Get the actual file path for a media ID.
2672
+ * Convenience method for gadgets that need the raw path.
2673
+ *
2674
+ * @param id - The media ID
2675
+ * @returns The file path or undefined if not found
2676
+ */
2677
+ getPath(id: string): string | undefined;
2678
+ /**
2679
+ * List all stored media, optionally filtered by kind.
2680
+ *
2681
+ * @param kind - Optional media kind to filter by
2682
+ * @returns Array of stored media items
2683
+ */
2684
+ list(kind?: MediaKind): StoredMedia[];
2685
+ /**
2686
+ * Get the count of stored media items.
2687
+ */
2688
+ get size(): number;
2689
+ /**
2690
+ * Check if a media ID exists.
2691
+ */
2692
+ has(id: string): boolean;
2693
+ /**
2694
+ * Clear in-memory store without deleting files.
2695
+ * Resets the counter but leaves files on disk.
2696
+ */
2697
+ clear(): void;
2698
+ /**
2699
+ * Delete all stored files and clear memory.
2700
+ * Removes the entire session directory.
2701
+ */
2702
+ cleanup(): Promise<void>;
2703
+ }
2704
+
2375
2705
  /**
2376
2706
  * Internal key for Agent instantiation.
2377
2707
  * This Symbol is used to ensure only AgentBuilder can create Agent instances.
@@ -3095,8 +3425,8 @@ interface AgentOptions {
3095
3425
  logger?: Logger<ILogObj>;
3096
3426
  /** Clean hooks system */
3097
3427
  hooks?: AgentHooks;
3098
- /** Callback for human input */
3099
- onHumanInputRequired?: (question: string) => Promise<string>;
3428
+ /** Callback for requesting human input during execution */
3429
+ requestHumanInput?: (question: string) => Promise<string>;
3100
3430
  /** Custom gadget start prefix */
3101
3431
  gadgetStartPrefix?: string;
3102
3432
  /** Custom gadget end prefix */
@@ -3124,8 +3454,8 @@ interface AgentOptions {
3124
3454
  };
3125
3455
  /** Stop on gadget error */
3126
3456
  stopOnGadgetError?: boolean;
3127
- /** Custom error continuation logic */
3128
- shouldContinueAfterError?: (context: {
3457
+ /** Custom error recovery logic */
3458
+ canRecoverFromGadgetError?: (context: {
3129
3459
  error: string;
3130
3460
  gadgetName: string;
3131
3461
  errorType: "parse" | "validation" | "execution";
@@ -3134,7 +3464,7 @@ interface AgentOptions {
3134
3464
  /** Default gadget timeout */
3135
3465
  defaultGadgetTimeoutMs?: number;
3136
3466
  /** Custom prompt configuration for gadget system prompts */
3137
- promptConfig?: PromptConfig;
3467
+ promptConfig?: PromptTemplateConfig;
3138
3468
  /** Enable gadget output limiting (default: true) */
3139
3469
  gadgetOutputLimit?: boolean;
3140
3470
  /** Max gadget output as % of model context window (default: 15) */
@@ -3143,6 +3473,8 @@ interface AgentOptions {
3143
3473
  compactionConfig?: CompactionConfig;
3144
3474
  /** Optional abort signal for cancelling requests mid-flight */
3145
3475
  signal?: AbortSignal;
3476
+ /** Subagent-specific configuration overrides (from CLI config) */
3477
+ subagentConfig?: SubagentConfigMap;
3146
3478
  }
3147
3479
  /**
3148
3480
  * Agent: Lean orchestrator that delegates to StreamProcessor.
@@ -3171,19 +3503,22 @@ declare class Agent {
3171
3503
  private readonly gadgetStartPrefix?;
3172
3504
  private readonly gadgetEndPrefix?;
3173
3505
  private readonly gadgetArgPrefix?;
3174
- private readonly onHumanInputRequired?;
3506
+ private readonly requestHumanInput?;
3175
3507
  private readonly textOnlyHandler;
3176
3508
  private readonly textWithGadgetsHandler?;
3177
3509
  private readonly stopOnGadgetError;
3178
- private readonly shouldContinueAfterError?;
3510
+ private readonly canRecoverFromGadgetError?;
3179
3511
  private readonly defaultGadgetTimeoutMs?;
3180
3512
  private readonly defaultMaxTokens?;
3181
- private userPromptProvided;
3513
+ private hasUserPrompt;
3182
3514
  private readonly outputStore;
3183
3515
  private readonly outputLimitEnabled;
3184
3516
  private readonly outputLimitCharLimit;
3185
3517
  private readonly compactionManager?;
3518
+ private readonly mediaStore;
3186
3519
  private readonly signal?;
3520
+ private readonly agentContextConfig;
3521
+ private readonly subagentConfig?;
3187
3522
  /**
3188
3523
  * Creates a new Agent instance.
3189
3524
  * @internal This constructor is private. Use LLMist.createAgent() or AgentBuilder instead.
@@ -3208,6 +3543,34 @@ declare class Agent {
3208
3543
  * ```
3209
3544
  */
3210
3545
  getRegistry(): GadgetRegistry;
3546
+ /**
3547
+ * Get the media store for this agent session.
3548
+ *
3549
+ * The media store holds all media outputs (images, audio, etc.) produced by gadgets
3550
+ * during this agent's execution. Use this to:
3551
+ * - Access stored media files by ID
3552
+ * - List all stored media
3553
+ * - Clean up temporary files after execution
3554
+ *
3555
+ * @returns The MediaStore instance for this agent
3556
+ *
3557
+ * @example
3558
+ * ```typescript
3559
+ * const agent = new AgentBuilder()
3560
+ * .withModel("sonnet")
3561
+ * .build();
3562
+ *
3563
+ * // After execution, access stored media
3564
+ * const store = agent.getMediaStore();
3565
+ * for (const media of store.list()) {
3566
+ * console.log(`${media.id}: ${media.path}`);
3567
+ * }
3568
+ *
3569
+ * // Clean up when done
3570
+ * await store.cleanup();
3571
+ * ```
3572
+ */
3573
+ getMediaStore(): MediaStore;
3211
3574
  /**
3212
3575
  * Manually trigger context compaction.
3213
3576
  *
@@ -3272,10 +3635,10 @@ declare class Agent {
3272
3635
  */
3273
3636
  private resolveMaxTokensFromCatalog;
3274
3637
  /**
3275
- * Merge the output limiter interceptor into user-provided hooks.
3638
+ * Chain the output limiter interceptor with user-provided hooks.
3276
3639
  * The limiter runs first, then chains to any user interceptor.
3277
3640
  */
3278
- private mergeOutputLimiterHook;
3641
+ private chainOutputLimiterWithUserHooks;
3279
3642
  /**
3280
3643
  * Run agent with named event handlers (syntactic sugar).
3281
3644
  *
@@ -3351,20 +3714,21 @@ declare class AgentBuilder {
3351
3714
  private promptConfig?;
3352
3715
  private gadgets;
3353
3716
  private initialMessages;
3354
- private onHumanInputRequired?;
3717
+ private requestHumanInput?;
3355
3718
  private gadgetStartPrefix?;
3356
3719
  private gadgetEndPrefix?;
3357
3720
  private gadgetArgPrefix?;
3358
3721
  private textOnlyHandler?;
3359
3722
  private textWithGadgetsHandler?;
3360
3723
  private stopOnGadgetError?;
3361
- private shouldContinueAfterError?;
3724
+ private canRecoverFromGadgetError?;
3362
3725
  private defaultGadgetTimeoutMs?;
3363
3726
  private gadgetOutputLimit?;
3364
3727
  private gadgetOutputLimitPercent?;
3365
3728
  private compactionConfig?;
3366
3729
  private signal?;
3367
3730
  private trailingMessage?;
3731
+ private subagentConfig?;
3368
3732
  constructor(client?: LLMist);
3369
3733
  /**
3370
3734
  * Set the model to use.
@@ -3435,13 +3799,13 @@ declare class AgentBuilder {
3435
3799
  *
3436
3800
  * @example
3437
3801
  * ```typescript
3438
- * .withPromptConfig({
3802
+ * .withPromptTemplateConfig({
3439
3803
  * mainInstruction: "Use the gadget markers below:",
3440
3804
  * rules: ["Always use markers", "Never use function calling"]
3441
3805
  * })
3442
3806
  * ```
3443
3807
  */
3444
- withPromptConfig(config: PromptConfig): this;
3808
+ withPromptTemplateConfig(config: PromptTemplateConfig): this;
3445
3809
  /**
3446
3810
  * Add gadgets (classes or instances).
3447
3811
  * Can be called multiple times to add more gadgets.
@@ -3620,9 +3984,9 @@ declare class AgentBuilder {
3620
3984
  * Provides fine-grained control over whether to continue after different types of errors.
3621
3985
  * Overrides `stopOnGadgetError` when provided.
3622
3986
  *
3623
- * **Note:** This builder method configures the underlying `shouldContinueAfterError` option
3987
+ * **Note:** This builder method configures the underlying `canRecoverFromGadgetError` option
3624
3988
  * in `AgentOptions`. The method is named `withErrorHandler` for better developer experience,
3625
- * but maps to the `shouldContinueAfterError` property internally.
3989
+ * but maps to the `canRecoverFromGadgetError` property internally.
3626
3990
  *
3627
3991
  * @param handler - Function that decides whether to continue after an error.
3628
3992
  * Return `true` to continue execution, `false` to stop.
@@ -3762,6 +4126,24 @@ declare class AgentBuilder {
3762
4126
  * ```
3763
4127
  */
3764
4128
  withSignal(signal: AbortSignal): this;
4129
+ /**
4130
+ * Set subagent configuration overrides.
4131
+ *
4132
+ * Subagent gadgets (like BrowseWeb) can read these settings from ExecutionContext
4133
+ * to inherit model and other options from the CLI configuration.
4134
+ *
4135
+ * @param config - Subagent configuration map keyed by gadget name
4136
+ * @returns This builder for chaining
4137
+ *
4138
+ * @example
4139
+ * ```typescript
4140
+ * .withSubagentConfig({
4141
+ * BrowseWeb: { model: "inherit", maxIterations: 20, headless: true },
4142
+ * CodeAnalyzer: { model: "sonnet", maxIterations: 10 }
4143
+ * })
4144
+ * ```
4145
+ */
4146
+ withSubagentConfig(config: SubagentConfigMap): this;
3765
4147
  /**
3766
4148
  * Add an ephemeral trailing message that appears at the end of each LLM request.
3767
4149
  *
@@ -3981,8 +4363,9 @@ interface IConversationManager {
3981
4363
  addAssistantMessage(content: string): void;
3982
4364
  /**
3983
4365
  * Adds a gadget call and its result to the conversation.
4366
+ * Optionally includes media outputs (images, audio, etc.) for multimodal results.
3984
4367
  */
3985
- addGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): void;
4368
+ addGadgetCallResult(gadgetName: string, parameters: Record<string, unknown>, result: string, media?: GadgetMediaOutput[], mediaIds?: string[]): void;
3986
4369
  /**
3987
4370
  * Gets the complete conversation history including base messages (system prompts, gadget instructions).
3988
4371
  */
@@ -4718,4 +5101,4 @@ declare function createTextMockStream(text: string, options?: {
4718
5101
  usage?: MockResponse["usage"];
4719
5102
  }): LLMStream;
4720
5103
 
4721
- export { type TrailingMessage as $, type AgentHooks as A, BaseGadget as B, type CompactionStrategy as C, type GadgetExecuteReturn as D, type ExecutionContext as E, type GadgetExample as F, GadgetRegistry as G, type HintTemplate as H, type IConversationManager as I, type GadgetExecutionResult as J, type ProviderAdapter as K, type LLMStream as L, MockProviderAdapter as M, type ModelDescriptor as N, type ModelSpec as O, type ParsedGadgetCall as P, type LLMGenerationOptions as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, type ImageModelSpec as U, type ImageGenerationOptions as V, type ImageGenerationResult as W, type SpeechModelSpec as X, type SpeechGenerationOptions as Y, type SpeechGenerationResult as Z, type HistoryMessage as _, type LLMStreamChunk as a, type VisionAnalyzeOptions as a$, type TrailingMessageContext as a0, AgentBuilder as a1, type EventHandlers as a2, collectEvents as a3, collectText as a4, runWithHandlers as a5, type AfterGadgetExecutionAction as a6, type AfterGadgetExecutionControllerContext as a7, type AfterLLMCallAction as a8, type AfterLLMCallControllerContext as a9, type AudioMimeType as aA, type AudioSource as aB, type ContentPart as aC, type ImageBase64Source as aD, type ImageContentPart as aE, type ImageMimeType as aF, type ImageSource as aG, type ImageUrlSource as aH, type TextContentPart as aI, audioFromBase64 as aJ, audioFromBuffer as aK, detectAudioMimeType as aL, detectImageMimeType as aM, imageFromBase64 as aN, imageFromBuffer as aO, imageFromUrl as aP, isAudioPart as aQ, isDataUrl as aR, isImagePart as aS, isTextPart as aT, parseDataUrl as aU, text as aV, toBase64 as aW, type LLMRole as aX, extractText as aY, LLMMessageBuilder as aZ, normalizeContent as a_, type AfterLLMErrorAction as aa, type AgentOptions as ab, type BeforeGadgetExecutionAction as ac, type BeforeLLMCallAction as ad, type ChunkInterceptorContext as ae, type Controllers as af, type GadgetExecutionControllerContext as ag, type GadgetParameterInterceptorContext as ah, type GadgetResultInterceptorContext as ai, type Interceptors as aj, type LLMCallControllerContext as ak, type LLMErrorControllerContext as al, type MessageInterceptorContext as am, type ObserveChunkContext as an, type ObserveGadgetCompleteContext as ao, type ObserveGadgetStartContext as ap, type ObserveLLMCallContext as aq, type ObserveLLMCompleteContext as ar, type ObserveLLMErrorContext as as, type Observers as at, type MessageTurn as au, type ObserveCompactionContext as av, DEFAULT_COMPACTION_CONFIG as aw, DEFAULT_SUMMARIZATION_PROMPT as ax, type LLMistOptions as ay, type AudioContentPart as az, type LLMMessage as b, type VisionAnalyzeResult as b0, type CostEstimate as b1, type ModelFeatures as b2, type ModelLimits as b3, type ModelPricing as b4, type ProviderIdentifier as b5, ModelIdentifierParser as b6, type HintContext as b7, type PromptConfig as b8, type PromptContext as b9, type PromptTemplate as ba, DEFAULT_HINTS as bb, DEFAULT_PROMPTS as bc, resolveHintTemplate as bd, resolvePromptTemplate as be, resolveRulesTemplate as bf, type QuickOptions as bg, complete as bh, stream as bi, type GadgetClass as bj, type GadgetOrClass as bk, type CostReportingLLMist as bl, type GadgetExecuteResult as bm, type GadgetSkippedEvent as bn, type TextOnlyAction as bo, type TextOnlyContext as bp, type TextOnlyCustomHandler as bq, type TextOnlyGadgetConfig as br, type TextOnlyHandler as bs, type TextOnlyStrategy as bt, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockAudioData as j, type MockImageData as k, type MockMatcher as l, mockLLM as m, type MockMatcherContext as n, type MockOptions as o, type MockRegistration as p, type MockResponse as q, type MockStats as r, ModelRegistry as s, type MessageContent as t, LLMist as u, type CompactionContext as v, type CompactionResult as w, type CompactionConfig as x, type CompactionEvent as y, type CompactionStats as z };
5104
+ export { type ImageModelSpec as $, AbstractGadget as A, type MessageContent as B, type CompactionConfig as C, GadgetRegistry as D, MediaStore as E, type AgentContextConfig as F, type GadgetMediaOutput as G, type HintTemplate as H, type IConversationManager as I, type SubagentConfigMap as J, type ExecutionContext as K, type LLMMessage as L, MockProviderAdapter as M, type GadgetExecuteReturn as N, type GadgetExample as O, type ParsedGadgetCall as P, type GadgetExecutionResult as Q, type ResolvedCompactionConfig as R, type StreamEvent as S, type TokenUsage as T, type MediaKind as U, type MediaMetadata as V, type GadgetExecuteResultWithMedia as W, type ProviderAdapter as X, type ModelDescriptor as Y, type ModelSpec as Z, type LLMGenerationOptions as _, type LLMStream as a, parseDataUrl as a$, type ImageGenerationOptions as a0, type ImageGenerationResult as a1, type SpeechModelSpec as a2, type SpeechGenerationOptions as a3, type SpeechGenerationResult as a4, type HistoryMessage as a5, type TrailingMessage as a6, type TrailingMessageContext as a7, AgentBuilder as a8, type EventHandlers as a9, type ObserveLLMCompleteContext as aA, type ObserveLLMErrorContext as aB, type Observers as aC, DEFAULT_COMPACTION_CONFIG as aD, DEFAULT_SUMMARIZATION_PROMPT as aE, type LLMistOptions as aF, type AudioContentPart as aG, type AudioMimeType as aH, type AudioSource as aI, type ContentPart as aJ, type ImageBase64Source as aK, type ImageContentPart as aL, type ImageMimeType as aM, type ImageSource as aN, type ImageUrlSource as aO, type TextContentPart as aP, audioFromBase64 as aQ, audioFromBuffer as aR, detectAudioMimeType as aS, detectImageMimeType as aT, imageFromBase64 as aU, imageFromBuffer as aV, imageFromUrl as aW, isAudioPart as aX, isDataUrl as aY, isImagePart as aZ, isTextPart as a_, collectEvents as aa, collectText as ab, runWithHandlers as ac, type AfterGadgetExecutionAction as ad, type AfterGadgetExecutionControllerContext as ae, type AfterLLMCallAction as af, type AfterLLMCallControllerContext as ag, type AfterLLMErrorAction as ah, type AgentOptions as ai, type BeforeGadgetExecutionAction as aj, type BeforeLLMCallAction as ak, type ChunkInterceptorContext as al, type Controllers as am, type GadgetExecutionControllerContext as an, type GadgetParameterInterceptorContext as ao, type GadgetResultInterceptorContext as ap, type Interceptors as aq, type LLMCallControllerContext as ar, type LLMErrorControllerContext as as, type MessageInterceptorContext as at, type MessageTurn as au, type ObserveChunkContext as av, type ObserveCompactionContext as aw, type ObserveGadgetCompleteContext as ax, type ObserveGadgetStartContext as ay, type ObserveLLMCallContext as az, type LLMStreamChunk as b, text as b0, toBase64 as b1, type MessageRole as b2, extractMessageText as b3, LLMMessageBuilder as b4, normalizeMessageContent as b5, type CostEstimate as b6, type ModelFeatures as b7, type ModelLimits as b8, type ModelPricing as b9, type TextOnlyHandler as bA, type TextOnlyStrategy as bB, type VisionAnalyzeOptions as ba, type VisionAnalyzeResult as bb, type ProviderIdentifier as bc, ModelIdentifierParser as bd, type HintContext as be, type PromptContext as bf, type PromptTemplate as bg, type PromptTemplateConfig as bh, DEFAULT_HINTS as bi, DEFAULT_PROMPTS as bj, resolveHintTemplate as bk, resolvePromptTemplate as bl, resolveRulesTemplate as bm, type TextGenerationOptions as bn, complete as bo, stream as bp, type GadgetClass as bq, type GadgetOrClass as br, type CostReportingLLMist as bs, type GadgetExecuteResult as bt, type GadgetSkippedEvent as bu, type StoredMedia as bv, type TextOnlyAction as bw, type TextOnlyContext as bx, type TextOnlyCustomHandler as by, type TextOnlyGadgetConfig as bz, createMockAdapter as c, MockBuilder as d, createMockClient as e, MockManager as f, getMockManager as g, createMockStream as h, createTextMockStream as i, type MockAudioData as j, type MockImageData as k, type MockMatcher as l, mockLLM as m, type MockMatcherContext as n, type MockOptions as o, type MockRegistration as p, type MockResponse as q, type MockStats as r, type AgentHooks as s, ModelRegistry as t, LLMist as u, type CompactionEvent as v, type CompactionStats as w, type CompactionStrategy as x, type CompactionContext as y, type CompactionResult as z };