llmist 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,33 @@
1
1
  import { Logger, ILogObj } from 'tslog';
2
2
  import { ZodTypeAny } from 'zod';
3
3
 
4
+ /**
5
+ * Example of gadget usage to help LLMs understand proper invocation.
6
+ *
7
+ * Examples are rendered alongside the schema in `getInstruction()` to provide
8
+ * concrete usage patterns for the LLM.
9
+ *
10
+ * @template TParams - Inferred parameter type from Zod schema (defaults to Record<string, unknown>)
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const calculator = createGadget({
15
+ * schema: z.object({ a: z.number(), b: z.number() }),
16
+ * examples: [
17
+ * { params: { a: 5, b: 3 }, output: "8", comment: "Addition example" }
18
+ * ],
19
+ * // ...
20
+ * });
21
+ * ```
22
+ */
23
+ interface GadgetExample<TParams = Record<string, unknown>> {
24
+ /** Example parameter values (typed to match schema) */
25
+ params: TParams;
26
+ /** Optional expected output/result string */
27
+ output?: string;
28
+ /** Optional description explaining what this example demonstrates */
29
+ comment?: string;
30
+ }
4
31
  interface GadgetExecutionResult {
5
32
  gadgetName: string;
6
33
  invocationId: string;
@@ -89,7 +116,7 @@ type TextOnlyAction = {
89
116
  parameters: Record<string, unknown>;
90
117
  };
91
118
 
92
- type ParameterFormat = "json" | "yaml" | "auto";
119
+ type ParameterFormat = "json" | "yaml" | "toml" | "auto";
93
120
  interface StreamParserOptions {
94
121
  startPrefix?: string;
95
122
  endPrefix?: string;
@@ -110,6 +137,11 @@ declare class StreamParser {
110
137
  private readonly parameterFormat;
111
138
  constructor(options?: StreamParserOptions);
112
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;
113
145
  /**
114
146
  * Parse parameter string according to configured format
115
147
  */
@@ -149,6 +181,14 @@ declare abstract class BaseGadget {
149
181
  * Set to 0 or undefined to disable timeout for this gadget.
150
182
  */
151
183
  timeoutMs?: number;
184
+ /**
185
+ * Optional usage examples to help LLMs understand proper invocation.
186
+ * Examples are rendered in getInstruction() alongside the schema.
187
+ *
188
+ * Note: Uses broader `unknown` type to allow typed examples from subclasses
189
+ * while maintaining runtime compatibility.
190
+ */
191
+ examples?: GadgetExample<unknown>[];
152
192
  /**
153
193
  * Execute the gadget with the given parameters.
154
194
  * Can be synchronous or asynchronous.
@@ -167,7 +207,7 @@ declare abstract class BaseGadget {
167
207
  * Generate instruction text for the LLM with format-specific schema.
168
208
  * Combines name, description, and parameter schema into a formatted instruction.
169
209
  *
170
- * @param format - Format for the schema representation ('json' | 'yaml' | 'auto')
210
+ * @param format - Format for the schema representation ('json' | 'yaml' | 'toml' | 'auto')
171
211
  * @returns Formatted instruction string
172
212
  */
173
213
  getInstruction(format?: ParameterFormat): string;
@@ -232,6 +272,11 @@ interface PromptConfig {
232
272
  * Default: "Parameters in JSON format (valid JSON object)"
233
273
  */
234
274
  formatDescriptionJson?: PromptTemplate;
275
+ /**
276
+ * Format description for TOML parameter format.
277
+ * Default: "Parameters in TOML format (key = value pairs, use triple-quotes for multiline)"
278
+ */
279
+ formatDescriptionToml?: PromptTemplate;
235
280
  /**
236
281
  * Rules that appear in the rules section.
237
282
  * Can be an array of strings or a function that returns an array.
@@ -248,6 +293,11 @@ interface PromptConfig {
248
293
  * Default: "\n\nInput Schema (YAML):"
249
294
  */
250
295
  schemaLabelYaml?: PromptTemplate;
296
+ /**
297
+ * Schema label for TOML format.
298
+ * Default: "\n\nInput Schema (TOML):"
299
+ */
300
+ schemaLabelToml?: PromptTemplate;
251
301
  /**
252
302
  * Custom examples to show in the examples section.
253
303
  * If provided, replaces the default examples entirely.
@@ -285,6 +335,11 @@ declare class LLMMessageBuilder {
285
335
  private endPrefix;
286
336
  private promptConfig;
287
337
  constructor(promptConfig?: PromptConfig);
338
+ /**
339
+ * Set custom prefixes for gadget markers.
340
+ * Used to configure history builder to match system prompt markers.
341
+ */
342
+ withPrefixes(startPrefix: string, endPrefix: string): this;
288
343
  addSystem(content: string, metadata?: Record<string, unknown>): this;
289
344
  addGadgets(gadgets: BaseGadget[], parameterFormat?: ParameterFormat, options?: {
290
345
  startPrefix?: string;
@@ -2598,4 +2653,4 @@ declare function createTextMockStream(text: string, options?: {
2598
2653
  usage?: MockResponse["usage"];
2599
2654
  }): LLMStream;
2600
2655
 
2601
- export { type ObserveChunkContext 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 ParameterFormat as P, type BeforeLLMCallAction as Q, type ChunkInterceptorContext as R, type StreamEvent as S, type Controllers as T, type GadgetExecutionControllerContext as U, type GadgetParameterInterceptorContext as V, type GadgetResultInterceptorContext as W, type Interceptors as X, type LLMCallControllerContext as Y, type LLMErrorControllerContext as Z, type MessageInterceptorContext as _, MockBuilder as a, type ObserveGadgetCompleteContext as a0, type ObserveGadgetStartContext as a1, type ObserveLLMCallContext as a2, type ObserveLLMCompleteContext as a3, type ObserveLLMErrorContext as a4, type Observers as a5, type LLMistOptions as a6, LLMist as a7, type LLMRole as a8, LLMMessageBuilder as a9, type CostEstimate as aa, type ModelFeatures as ab, type ModelLimits as ac, type ModelPricing as ad, type ProviderIdentifier as ae, type TokenUsage 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, StreamParser as aq, type GadgetClass as ar, type GadgetOrClass as as, type TextOnlyAction as at, type TextOnlyContext as au, type TextOnlyCustomHandler as av, type TextOnlyGadgetConfig as aw, type TextOnlyHandler as ax, type TextOnlyStrategy as ay, 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 ParsedGadgetCall 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 };
2656
+ export { type MessageInterceptorContext 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 ChunkInterceptorContext 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, type TokenUsage 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 };