llmist 0.8.0 → 1.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.
@@ -40,7 +40,7 @@ interface GadgetExecutionResult {
40
40
  interface ParsedGadgetCall {
41
41
  gadgetName: string;
42
42
  invocationId: string;
43
- parametersYaml: string;
43
+ parametersRaw: string;
44
44
  parameters?: Record<string, unknown>;
45
45
  parseError?: string;
46
46
  }
@@ -116,46 +116,6 @@ type TextOnlyAction = {
116
116
  parameters: Record<string, unknown>;
117
117
  };
118
118
 
119
- type ParameterFormat = "json" | "yaml" | "toml" | "auto";
120
- interface StreamParserOptions {
121
- startPrefix?: string;
122
- endPrefix?: string;
123
- /**
124
- * Format for parsing gadget parameters.
125
- * - 'json': Parse as JSON (more robust, recommended for complex nested data)
126
- * - 'yaml': Parse as YAML (backward compatible)
127
- * - 'auto': Try JSON first, fall back to YAML
128
- * @default 'json'
129
- */
130
- parameterFormat?: ParameterFormat;
131
- }
132
- declare class StreamParser {
133
- private buffer;
134
- private lastReportedTextLength;
135
- private readonly startPrefix;
136
- private readonly endPrefix;
137
- private readonly parameterFormat;
138
- constructor(options?: StreamParserOptions);
139
- private takeTextUntil;
140
- /**
141
- * Parse gadget name, handling both old format (name:invocationId) and new format (just name).
142
- * For new format, generates a unique invocation ID.
143
- */
144
- private parseGadgetName;
145
- /**
146
- * Truncate verbose parse errors to avoid context overflow.
147
- * Keeps first meaningful line and limits total length.
148
- */
149
- private truncateParseError;
150
- /**
151
- * Parse parameter string according to configured format
152
- */
153
- private parseParameters;
154
- feed(chunk: string): Generator<StreamEvent>;
155
- finalize(): Generator<StreamEvent>;
156
- reset(): void;
157
- }
158
-
159
119
  /**
160
120
  * Internal base class for gadgets. Most users should use the `Gadget` class
161
121
  * (formerly TypedGadget) or `createGadget()` function instead, as they provide
@@ -205,29 +165,29 @@ declare abstract class BaseGadget {
205
165
  /**
206
166
  * Auto-generated instruction text for the LLM.
207
167
  * Combines name, description, and parameter schema into a formatted instruction.
208
- * @deprecated Use getInstruction(format) instead for format-specific schemas
168
+ * @deprecated Use getInstruction() instead
209
169
  */
210
170
  get instruction(): string;
211
171
  /**
212
- * Generate instruction text for the LLM with format-specific schema.
172
+ * Generate instruction text for the LLM.
213
173
  * Combines name, description, and parameter schema into a formatted instruction.
214
174
  *
215
- * @param format - Format for the schema representation ('json' | 'yaml' | 'toml' | 'auto')
175
+ * @param argPrefix - Optional custom argument prefix for block format examples
216
176
  * @returns Formatted instruction string
217
177
  */
218
- getInstruction(format?: ParameterFormat): string;
178
+ getInstruction(argPrefix?: string): string;
219
179
  }
220
180
 
221
181
  /**
222
182
  * Context provided to prompt template functions for rendering dynamic content.
223
183
  */
224
184
  interface PromptContext {
225
- /** The parameter format being used (json or yaml) */
226
- parameterFormat: ParameterFormat;
227
185
  /** Custom gadget start prefix */
228
186
  startPrefix: string;
229
187
  /** Custom gadget end prefix */
230
188
  endPrefix: string;
189
+ /** Custom argument prefix for block format */
190
+ argPrefix: string;
231
191
  /** Number of gadgets being registered */
232
192
  gadgetCount: number;
233
193
  /** Names of all gadgets */
@@ -268,41 +228,16 @@ interface PromptConfig {
268
228
  */
269
229
  criticalUsage?: PromptTemplate;
270
230
  /**
271
- * Format description for YAML parameter format.
272
- * Default: "Parameters in YAML format (one per line)"
231
+ * Format description for the block parameter format.
232
+ * Default uses the configured argPrefix dynamically.
273
233
  */
274
- formatDescriptionYaml?: PromptTemplate;
275
- /**
276
- * Format description for JSON parameter format.
277
- * Default: "Parameters in JSON format (valid JSON object)"
278
- */
279
- formatDescriptionJson?: PromptTemplate;
280
- /**
281
- * Format description for TOML parameter format.
282
- * Default: "Parameters in TOML format (key = value pairs, use heredoc for multiline: key = <<<EOF ... EOF)"
283
- */
284
- formatDescriptionToml?: PromptTemplate;
234
+ formatDescription?: PromptTemplate;
285
235
  /**
286
236
  * Rules that appear in the rules section.
287
237
  * Can be an array of strings or a function that returns an array.
288
- * Default includes 6 rules about not using function calling.
238
+ * Default includes rules about not using function calling.
289
239
  */
290
240
  rules?: PromptTemplate | string[] | ((context: PromptContext) => string[]);
291
- /**
292
- * Schema label for JSON format.
293
- * Default: "\n\nInput Schema (JSON):"
294
- */
295
- schemaLabelJson?: PromptTemplate;
296
- /**
297
- * Schema label for YAML format.
298
- * Default: "\n\nInput Schema (YAML):"
299
- */
300
- schemaLabelYaml?: PromptTemplate;
301
- /**
302
- * Schema label for TOML format.
303
- * Default: "\n\nInput Schema (TOML):"
304
- */
305
- schemaLabelToml?: PromptTemplate;
306
241
  /**
307
242
  * Custom examples to show in the examples section.
308
243
  * If provided, replaces the default examples entirely.
@@ -312,7 +247,6 @@ interface PromptConfig {
312
247
  }
313
248
  /**
314
249
  * Default prompt templates used by llmist.
315
- * These match the original hardcoded strings.
316
250
  */
317
251
  declare const DEFAULT_PROMPTS: Required<Omit<PromptConfig, "rules" | "customExamples"> & {
318
252
  rules: (context: PromptContext) => string[];
@@ -338,17 +272,19 @@ declare class LLMMessageBuilder {
338
272
  private readonly messages;
339
273
  private startPrefix;
340
274
  private endPrefix;
275
+ private argPrefix;
341
276
  private promptConfig;
342
277
  constructor(promptConfig?: PromptConfig);
343
278
  /**
344
279
  * Set custom prefixes for gadget markers.
345
280
  * Used to configure history builder to match system prompt markers.
346
281
  */
347
- withPrefixes(startPrefix: string, endPrefix: string): this;
282
+ withPrefixes(startPrefix: string, endPrefix: string, argPrefix?: string): this;
348
283
  addSystem(content: string, metadata?: Record<string, unknown>): this;
349
- addGadgets(gadgets: BaseGadget[], parameterFormat?: ParameterFormat, options?: {
284
+ addGadgets(gadgets: BaseGadget[], options?: {
350
285
  startPrefix?: string;
351
286
  endPrefix?: string;
287
+ argPrefix?: string;
352
288
  }): this;
353
289
  private buildGadgetsSection;
354
290
  private buildUsageSection;
@@ -356,8 +292,12 @@ declare class LLMMessageBuilder {
356
292
  private buildRulesSection;
357
293
  addUser(content: string, metadata?: Record<string, unknown>): this;
358
294
  addAssistant(content: string, metadata?: Record<string, unknown>): this;
359
- addGadgetCall(gadget: string, parameters: Record<string, unknown>, result: string, parameterFormat?: ParameterFormat): this;
360
- private formatParameters;
295
+ addGadgetCall(gadget: string, parameters: Record<string, unknown>, result: string): this;
296
+ /**
297
+ * Format parameters as Block format with JSON Pointer paths.
298
+ * Uses the configured argPrefix for consistency with system prompt.
299
+ */
300
+ private formatBlockParameters;
361
301
  build(): LLMMessage[];
362
302
  }
363
303
 
@@ -972,7 +912,7 @@ interface EventHandlers {
972
912
  onGadgetCall?: (call: {
973
913
  gadgetName: string;
974
914
  parameters?: Record<string, unknown>;
975
- parametersYaml: string;
915
+ parametersRaw: string;
976
916
  }) => void | Promise<void>;
977
917
  /** Called when a gadget execution completes */
978
918
  onGadgetResult?: (result: {
@@ -1553,12 +1493,12 @@ interface AgentOptions {
1553
1493
  hooks?: AgentHooks;
1554
1494
  /** Callback for human input */
1555
1495
  onHumanInputRequired?: (question: string) => Promise<string>;
1556
- /** Parameter format */
1557
- parameterFormat?: ParameterFormat;
1558
1496
  /** Custom gadget start prefix */
1559
1497
  gadgetStartPrefix?: string;
1560
1498
  /** Custom gadget end prefix */
1561
1499
  gadgetEndPrefix?: string;
1500
+ /** Custom gadget argument prefix for block format parameters */
1501
+ gadgetArgPrefix?: string;
1562
1502
  /** Initial messages */
1563
1503
  initialMessages?: Array<{
1564
1504
  role: "system" | "user" | "assistant";
@@ -1620,9 +1560,9 @@ declare class Agent {
1620
1560
  private readonly hooks;
1621
1561
  private readonly conversation;
1622
1562
  private readonly registry;
1623
- private readonly parameterFormat;
1624
1563
  private readonly gadgetStartPrefix?;
1625
1564
  private readonly gadgetEndPrefix?;
1565
+ private readonly gadgetArgPrefix?;
1626
1566
  private readonly onHumanInputRequired?;
1627
1567
  private readonly textOnlyHandler;
1628
1568
  private readonly textWithGadgetsHandler?;
@@ -1751,9 +1691,9 @@ declare class AgentBuilder {
1751
1691
  private gadgets;
1752
1692
  private initialMessages;
1753
1693
  private onHumanInputRequired?;
1754
- private parameterFormat?;
1755
1694
  private gadgetStartPrefix?;
1756
1695
  private gadgetEndPrefix?;
1696
+ private gadgetArgPrefix?;
1757
1697
  private textOnlyHandler?;
1758
1698
  private textWithGadgetsHandler?;
1759
1699
  private stopOnGadgetError?;
@@ -1898,18 +1838,6 @@ declare class AgentBuilder {
1898
1838
  * ```
1899
1839
  */
1900
1840
  onHumanInput(handler: (question: string) => Promise<string>): this;
1901
- /**
1902
- * Set the parameter format for gadget calls.
1903
- *
1904
- * @param format - Parameter format ("json" or "xml")
1905
- * @returns This builder for chaining
1906
- *
1907
- * @example
1908
- * ```typescript
1909
- * .withParameterFormat("xml")
1910
- * ```
1911
- */
1912
- withParameterFormat(format: ParameterFormat): this;
1913
1841
  /**
1914
1842
  * Set custom gadget marker prefix.
1915
1843
  *
@@ -1934,6 +1862,18 @@ declare class AgentBuilder {
1934
1862
  * ```
1935
1863
  */
1936
1864
  withGadgetEndPrefix(suffix: string): this;
1865
+ /**
1866
+ * Set custom argument prefix for block format parameters.
1867
+ *
1868
+ * @param prefix - Custom prefix for argument markers (default: "!!!ARG:")
1869
+ * @returns This builder for chaining
1870
+ *
1871
+ * @example
1872
+ * ```typescript
1873
+ * .withGadgetArgPrefix("<<ARG>>")
1874
+ * ```
1875
+ */
1876
+ withGadgetArgPrefix(prefix: string): this;
1937
1877
  /**
1938
1878
  * Set the text-only handler strategy.
1939
1879
  *
@@ -2114,10 +2054,9 @@ declare class AgentBuilder {
2114
2054
  */
2115
2055
  withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
2116
2056
  /**
2117
- * Format parameters for synthetic gadget calls.
2118
- * Uses heredoc for multiline string values.
2057
+ * Format parameters as block format with JSON Pointer paths.
2119
2058
  */
2120
- private formatSyntheticParameters;
2059
+ private formatBlockParameters;
2121
2060
  /**
2122
2061
  * Build and create the agent with the given user prompt.
2123
2062
  * Returns the Agent instance ready to run.
@@ -2773,4 +2712,4 @@ declare function createTextMockStream(text: string, options?: {
2773
2712
  usage?: MockResponse["usage"];
2774
2713
  }): LLMStream;
2775
2714
 
2776
- export { type LLMErrorControllerContext as $, type AgentHooks as A, BaseGadget as B, collectText as C, runWithHandlers as D, type EventHandlers as E, type AfterGadgetExecutionAction as F, GadgetRegistry as G, type HistoryMessage as H, type AfterGadgetExecutionControllerContext as I, type AfterLLMCallAction as J, type AfterLLMCallControllerContext as K, type LLMMessage as L, MockProviderAdapter as M, type AfterLLMErrorAction as N, type AgentOptions as O, type ParameterFormat as P, type BeforeGadgetExecutionAction as Q, type BeforeLLMCallAction as R, type StreamEvent as S, type TokenUsage as T, type ChunkInterceptorContext as U, type Controllers as V, type GadgetExecutionControllerContext as W, type GadgetParameterInterceptorContext as X, type GadgetResultInterceptorContext as Y, type Interceptors as Z, type LLMCallControllerContext as _, MockBuilder as a, type MessageInterceptorContext as a0, type ObserveChunkContext as a1, type ObserveGadgetCompleteContext as a2, type ObserveGadgetStartContext as a3, type ObserveLLMCallContext as a4, type ObserveLLMCompleteContext as a5, type ObserveLLMErrorContext as a6, type Observers as a7, type LLMistOptions as a8, LLMist as a9, type LLMRole as aa, LLMMessageBuilder as ab, type CostEstimate as ac, type ModelFeatures as ad, type ModelLimits as ae, type ModelPricing as af, type ProviderIdentifier as ag, ModelIdentifierParser as ah, type PromptConfig as ai, type PromptContext as aj, type PromptTemplate as ak, DEFAULT_PROMPTS as al, resolvePromptTemplate as am, resolveRulesTemplate as an, type QuickOptions as ao, complete as ap, stream as aq, StreamParser as ar, type GadgetClass as as, type GadgetOrClass as at, type TextOnlyAction as au, type TextOnlyContext as av, type TextOnlyCustomHandler as aw, type TextOnlyGadgetConfig as ax, type TextOnlyHandler as ay, type TextOnlyStrategy as az, createMockClient as b, createMockAdapter as c, MockManager as d, createMockStream as e, createTextMockStream as f, getMockManager as g, type MockMatcher as h, type MockMatcherContext as i, type MockOptions as j, type MockRegistration as k, type MockResponse as l, mockLLM as m, type MockStats as n, ModelRegistry as o, type LLMStreamChunk as p, type GadgetExample as q, type ParsedGadgetCall as r, type GadgetExecutionResult as s, type ProviderAdapter as t, type ModelDescriptor as u, type ModelSpec as v, type LLMGenerationOptions as w, type LLMStream as x, AgentBuilder as y, collectEvents as z };
2715
+ export { type MessageInterceptorContext as $, type AgentHooks as A, BaseGadget as B, runWithHandlers as C, type AfterGadgetExecutionAction as D, type EventHandlers as E, type AfterGadgetExecutionControllerContext as F, GadgetRegistry as G, type HistoryMessage as H, type AfterLLMCallAction as I, type AfterLLMCallControllerContext as J, type AfterLLMErrorAction as K, type LLMMessage as L, MockProviderAdapter as M, type AgentOptions as N, type BeforeGadgetExecutionAction as O, type ParsedGadgetCall as P, type BeforeLLMCallAction as Q, type ChunkInterceptorContext as R, type StreamEvent as S, type TokenUsage as T, type Controllers as U, type GadgetExecutionControllerContext as V, type GadgetParameterInterceptorContext as W, type GadgetResultInterceptorContext as X, type Interceptors as Y, type LLMCallControllerContext as Z, type LLMErrorControllerContext as _, MockBuilder as a, type ObserveChunkContext as a0, type ObserveGadgetCompleteContext as a1, type ObserveGadgetStartContext as a2, type ObserveLLMCallContext as a3, type ObserveLLMCompleteContext as a4, type ObserveLLMErrorContext as a5, type Observers as a6, type LLMistOptions as a7, LLMist as a8, type LLMRole as a9, LLMMessageBuilder as aa, type CostEstimate as ab, type ModelFeatures as ac, type ModelLimits as ad, type ModelPricing as ae, type ProviderIdentifier as af, ModelIdentifierParser as ag, type PromptConfig as ah, type PromptContext as ai, type PromptTemplate as aj, DEFAULT_PROMPTS as ak, resolvePromptTemplate as al, resolveRulesTemplate as am, type QuickOptions as an, complete as ao, stream as ap, type GadgetClass as aq, type GadgetOrClass as ar, type TextOnlyAction as as, type TextOnlyContext as at, type TextOnlyCustomHandler as au, type TextOnlyGadgetConfig as av, type TextOnlyHandler as aw, type TextOnlyStrategy as ax, createMockClient as b, createMockAdapter as c, MockManager as d, createMockStream as e, createTextMockStream as f, getMockManager as g, type MockMatcher as h, type MockMatcherContext as i, type MockOptions as j, type MockRegistration as k, type MockResponse as l, mockLLM as m, type MockStats as n, ModelRegistry as o, type LLMStreamChunk as p, type GadgetExample as q, type GadgetExecutionResult as r, type ProviderAdapter as s, type ModelDescriptor as t, type ModelSpec as u, type LLMGenerationOptions as v, type LLMStream as w, AgentBuilder as x, collectEvents as y, collectText as z };