llmist 0.6.2 → 0.7.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/{chunk-TSR25DAY.js → chunk-CTC2WJZA.js} +2 -2
- package/dist/{chunk-DVK6ZQOV.js → chunk-ZFHFBEQ5.js} +143 -13
- package/dist/chunk-ZFHFBEQ5.js.map +1 -0
- package/dist/cli.cjs +222 -76
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +70 -54
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +153 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/{mock-stream-B5R6XPif.d.cts → mock-stream-B2qwECvd.d.cts} +70 -0
- package/dist/{mock-stream-B5R6XPif.d.ts → mock-stream-B2qwECvd.d.ts} +70 -0
- package/dist/testing/index.cjs +139 -9
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.d.cts +2 -2
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-DVK6ZQOV.js.map +0 -1
- /package/dist/{chunk-TSR25DAY.js.map → chunk-CTC2WJZA.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ZodType, ZodTypeAny } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage, P as ParameterFormat, S as StreamEvent, G as GadgetRegistry, p as LLMStreamChunk, q as GadgetExample, B as BaseGadget, r as ParsedGadgetCall, s as GadgetExecutionResult, t as ProviderAdapter, u as ModelDescriptor, v as ModelSpec, w as LLMGenerationOptions, x as LLMStream } from './mock-stream-
|
|
4
|
-
export { F as AfterGadgetExecutionAction, I as AfterGadgetExecutionControllerContext, J as AfterLLMCallAction, K as AfterLLMCallControllerContext, N as AfterLLMErrorAction, y as AgentBuilder, O as AgentOptions, Q as BeforeGadgetExecutionAction, R as BeforeLLMCallAction, T as ChunkInterceptorContext, U as Controllers, ab as CostEstimate, al as DEFAULT_PROMPTS, E as EventHandlers, as as GadgetClass, V as GadgetExecutionControllerContext, at as GadgetOrClass, W as GadgetParameterInterceptorContext, X as GadgetResultInterceptorContext, H as HistoryMessage, Y as Interceptors, Z as LLMCallControllerContext, _ as LLMErrorControllerContext, aa as LLMMessageBuilder, a9 as LLMRole, a8 as LLMist, a7 as LLMistOptions, $ as MessageInterceptorContext, a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, ac as ModelFeatures, ah as ModelIdentifierParser, ad as ModelLimits, ae as ModelPricing, a0 as ObserveChunkContext, a1 as ObserveGadgetCompleteContext, a2 as ObserveGadgetStartContext, a3 as ObserveLLMCallContext, a4 as ObserveLLMCompleteContext, a5 as ObserveLLMErrorContext, a6 as Observers, ai as PromptConfig, aj as PromptContext, ak as PromptTemplate, af as ProviderIdentifier, ao as QuickOptions, ar as StreamParser, au as TextOnlyAction, av as TextOnlyContext, aw as TextOnlyCustomHandler, ax as TextOnlyGadgetConfig, ay as TextOnlyHandler, az as TextOnlyStrategy, ag as TokenUsage, z as collectEvents, C as collectText, ap as complete, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM, am as resolvePromptTemplate, an as resolveRulesTemplate, D as runWithHandlers, aq as stream } from './mock-stream-
|
|
3
|
+
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage, P as ParameterFormat, S as StreamEvent, G as GadgetRegistry, p as LLMStreamChunk, q as GadgetExample, B as BaseGadget, r as ParsedGadgetCall, s as GadgetExecutionResult, t as ProviderAdapter, u as ModelDescriptor, v as ModelSpec, w as LLMGenerationOptions, x as LLMStream } from './mock-stream-B2qwECvd.cjs';
|
|
4
|
+
export { F as AfterGadgetExecutionAction, I as AfterGadgetExecutionControllerContext, J as AfterLLMCallAction, K as AfterLLMCallControllerContext, N as AfterLLMErrorAction, y as AgentBuilder, O as AgentOptions, Q as BeforeGadgetExecutionAction, R as BeforeLLMCallAction, T as ChunkInterceptorContext, U as Controllers, ab as CostEstimate, al as DEFAULT_PROMPTS, E as EventHandlers, as as GadgetClass, V as GadgetExecutionControllerContext, at as GadgetOrClass, W as GadgetParameterInterceptorContext, X as GadgetResultInterceptorContext, H as HistoryMessage, Y as Interceptors, Z as LLMCallControllerContext, _ as LLMErrorControllerContext, aa as LLMMessageBuilder, a9 as LLMRole, a8 as LLMist, a7 as LLMistOptions, $ as MessageInterceptorContext, a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, ac as ModelFeatures, ah as ModelIdentifierParser, ad as ModelLimits, ae as ModelPricing, a0 as ObserveChunkContext, a1 as ObserveGadgetCompleteContext, a2 as ObserveGadgetStartContext, a3 as ObserveLLMCallContext, a4 as ObserveLLMCompleteContext, a5 as ObserveLLMErrorContext, a6 as Observers, ai as PromptConfig, aj as PromptContext, ak as PromptTemplate, af as ProviderIdentifier, ao as QuickOptions, ar as StreamParser, au as TextOnlyAction, av as TextOnlyContext, aw as TextOnlyCustomHandler, ax as TextOnlyGadgetConfig, ay as TextOnlyHandler, az as TextOnlyStrategy, ag as TokenUsage, z as collectEvents, C as collectText, ap as complete, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM, am as resolvePromptTemplate, an as resolveRulesTemplate, D as runWithHandlers, aq as stream } from './mock-stream-B2qwECvd.cjs';
|
|
5
5
|
import { Logger, ILogObj } from 'tslog';
|
|
6
6
|
import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
|
|
7
7
|
import OpenAI from 'openai';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ZodType, ZodTypeAny } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage, P as ParameterFormat, S as StreamEvent, G as GadgetRegistry, p as LLMStreamChunk, q as GadgetExample, B as BaseGadget, r as ParsedGadgetCall, s as GadgetExecutionResult, t as ProviderAdapter, u as ModelDescriptor, v as ModelSpec, w as LLMGenerationOptions, x as LLMStream } from './mock-stream-
|
|
4
|
-
export { F as AfterGadgetExecutionAction, I as AfterGadgetExecutionControllerContext, J as AfterLLMCallAction, K as AfterLLMCallControllerContext, N as AfterLLMErrorAction, y as AgentBuilder, O as AgentOptions, Q as BeforeGadgetExecutionAction, R as BeforeLLMCallAction, T as ChunkInterceptorContext, U as Controllers, ab as CostEstimate, al as DEFAULT_PROMPTS, E as EventHandlers, as as GadgetClass, V as GadgetExecutionControllerContext, at as GadgetOrClass, W as GadgetParameterInterceptorContext, X as GadgetResultInterceptorContext, H as HistoryMessage, Y as Interceptors, Z as LLMCallControllerContext, _ as LLMErrorControllerContext, aa as LLMMessageBuilder, a9 as LLMRole, a8 as LLMist, a7 as LLMistOptions, $ as MessageInterceptorContext, a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, ac as ModelFeatures, ah as ModelIdentifierParser, ad as ModelLimits, ae as ModelPricing, a0 as ObserveChunkContext, a1 as ObserveGadgetCompleteContext, a2 as ObserveGadgetStartContext, a3 as ObserveLLMCallContext, a4 as ObserveLLMCompleteContext, a5 as ObserveLLMErrorContext, a6 as Observers, ai as PromptConfig, aj as PromptContext, ak as PromptTemplate, af as ProviderIdentifier, ao as QuickOptions, ar as StreamParser, au as TextOnlyAction, av as TextOnlyContext, aw as TextOnlyCustomHandler, ax as TextOnlyGadgetConfig, ay as TextOnlyHandler, az as TextOnlyStrategy, ag as TokenUsage, z as collectEvents, C as collectText, ap as complete, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM, am as resolvePromptTemplate, an as resolveRulesTemplate, D as runWithHandlers, aq as stream } from './mock-stream-
|
|
3
|
+
import { A as AgentHooks, o as ModelRegistry, L as LLMMessage, P as ParameterFormat, S as StreamEvent, G as GadgetRegistry, p as LLMStreamChunk, q as GadgetExample, B as BaseGadget, r as ParsedGadgetCall, s as GadgetExecutionResult, t as ProviderAdapter, u as ModelDescriptor, v as ModelSpec, w as LLMGenerationOptions, x as LLMStream } from './mock-stream-B2qwECvd.js';
|
|
4
|
+
export { F as AfterGadgetExecutionAction, I as AfterGadgetExecutionControllerContext, J as AfterLLMCallAction, K as AfterLLMCallControllerContext, N as AfterLLMErrorAction, y as AgentBuilder, O as AgentOptions, Q as BeforeGadgetExecutionAction, R as BeforeLLMCallAction, T as ChunkInterceptorContext, U as Controllers, ab as CostEstimate, al as DEFAULT_PROMPTS, E as EventHandlers, as as GadgetClass, V as GadgetExecutionControllerContext, at as GadgetOrClass, W as GadgetParameterInterceptorContext, X as GadgetResultInterceptorContext, H as HistoryMessage, Y as Interceptors, Z as LLMCallControllerContext, _ as LLMErrorControllerContext, aa as LLMMessageBuilder, a9 as LLMRole, a8 as LLMist, a7 as LLMistOptions, $ as MessageInterceptorContext, a as MockBuilder, d as MockManager, h as MockMatcher, i as MockMatcherContext, j as MockOptions, M as MockProviderAdapter, k as MockRegistration, l as MockResponse, n as MockStats, ac as ModelFeatures, ah as ModelIdentifierParser, ad as ModelLimits, ae as ModelPricing, a0 as ObserveChunkContext, a1 as ObserveGadgetCompleteContext, a2 as ObserveGadgetStartContext, a3 as ObserveLLMCallContext, a4 as ObserveLLMCompleteContext, a5 as ObserveLLMErrorContext, a6 as Observers, ai as PromptConfig, aj as PromptContext, ak as PromptTemplate, af as ProviderIdentifier, ao as QuickOptions, ar as StreamParser, au as TextOnlyAction, av as TextOnlyContext, aw as TextOnlyCustomHandler, ax as TextOnlyGadgetConfig, ay as TextOnlyHandler, az as TextOnlyStrategy, ag as TokenUsage, z as collectEvents, C as collectText, ap as complete, c as createMockAdapter, b as createMockClient, e as createMockStream, f as createTextMockStream, g as getMockManager, m as mockLLM, am as resolvePromptTemplate, an as resolveRulesTemplate, D as runWithHandlers, aq as stream } from './mock-stream-B2qwECvd.js';
|
|
5
5
|
import { Logger, ILogObj } from 'tslog';
|
|
6
6
|
import { MessageCreateParamsStreaming, MessageStreamEvent } from '@anthropic-ai/sdk/resources/messages';
|
|
7
7
|
import OpenAI from 'openai';
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
mockLLM,
|
|
11
11
|
validateAndApplyDefaults,
|
|
12
12
|
validateGadgetParams
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-CTC2WJZA.js";
|
|
14
14
|
import {
|
|
15
15
|
AgentBuilder,
|
|
16
16
|
AnthropicMessagesProvider,
|
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
resolveRulesTemplate,
|
|
75
75
|
runWithHandlers,
|
|
76
76
|
stream
|
|
77
|
-
} from "./chunk-
|
|
77
|
+
} from "./chunk-ZFHFBEQ5.js";
|
|
78
78
|
|
|
79
79
|
// src/index.ts
|
|
80
80
|
init_builder();
|
|
@@ -1565,6 +1565,18 @@ interface AgentOptions {
|
|
|
1565
1565
|
}>;
|
|
1566
1566
|
/** Text-only handler */
|
|
1567
1567
|
textOnlyHandler?: TextOnlyHandler;
|
|
1568
|
+
/**
|
|
1569
|
+
* Handler for text content that appears alongside gadget calls.
|
|
1570
|
+
* When set, text accompanying gadgets will be wrapped as a synthetic gadget call.
|
|
1571
|
+
*/
|
|
1572
|
+
textWithGadgetsHandler?: {
|
|
1573
|
+
/** Name of the gadget to use for wrapping text */
|
|
1574
|
+
gadgetName: string;
|
|
1575
|
+
/** Maps text content to gadget parameters */
|
|
1576
|
+
parameterMapping: (text: string) => Record<string, unknown>;
|
|
1577
|
+
/** Maps text content to the result string (optional, defaults to text) */
|
|
1578
|
+
resultMapping?: (text: string) => string;
|
|
1579
|
+
};
|
|
1568
1580
|
/** Stop on gadget error */
|
|
1569
1581
|
stopOnGadgetError?: boolean;
|
|
1570
1582
|
/** Custom error continuation logic */
|
|
@@ -1612,6 +1624,7 @@ declare class Agent {
|
|
|
1612
1624
|
private readonly gadgetEndPrefix?;
|
|
1613
1625
|
private readonly onHumanInputRequired?;
|
|
1614
1626
|
private readonly textOnlyHandler;
|
|
1627
|
+
private readonly textWithGadgetsHandler?;
|
|
1615
1628
|
private readonly stopOnGadgetError;
|
|
1616
1629
|
private readonly shouldContinueAfterError?;
|
|
1617
1630
|
private readonly defaultGadgetTimeoutMs?;
|
|
@@ -1741,6 +1754,7 @@ declare class AgentBuilder {
|
|
|
1741
1754
|
private gadgetStartPrefix?;
|
|
1742
1755
|
private gadgetEndPrefix?;
|
|
1743
1756
|
private textOnlyHandler?;
|
|
1757
|
+
private textWithGadgetsHandler?;
|
|
1744
1758
|
private stopOnGadgetError?;
|
|
1745
1759
|
private shouldContinueAfterError?;
|
|
1746
1760
|
private defaultGadgetTimeoutMs?;
|
|
@@ -1949,6 +1963,31 @@ declare class AgentBuilder {
|
|
|
1949
1963
|
* ```
|
|
1950
1964
|
*/
|
|
1951
1965
|
withTextOnlyHandler(handler: TextOnlyHandler): this;
|
|
1966
|
+
/**
|
|
1967
|
+
* Set the handler for text content that appears alongside gadget calls.
|
|
1968
|
+
*
|
|
1969
|
+
* When set, text accompanying gadget responses will be wrapped as a
|
|
1970
|
+
* synthetic gadget call before the actual gadget results in the
|
|
1971
|
+
* conversation history.
|
|
1972
|
+
*
|
|
1973
|
+
* @param handler - Configuration for wrapping text
|
|
1974
|
+
* @returns This builder for chaining
|
|
1975
|
+
*
|
|
1976
|
+
* @example
|
|
1977
|
+
* ```typescript
|
|
1978
|
+
* // Wrap text as TellUser gadget
|
|
1979
|
+
* .withTextWithGadgetsHandler({
|
|
1980
|
+
* gadgetName: "TellUser",
|
|
1981
|
+
* parameterMapping: (text) => ({ message: text, done: false, type: "info" }),
|
|
1982
|
+
* resultMapping: (text) => `ℹ️ ${text}`,
|
|
1983
|
+
* })
|
|
1984
|
+
* ```
|
|
1985
|
+
*/
|
|
1986
|
+
withTextWithGadgetsHandler(handler: {
|
|
1987
|
+
gadgetName: string;
|
|
1988
|
+
parameterMapping: (text: string) => Record<string, unknown>;
|
|
1989
|
+
resultMapping?: (text: string) => string;
|
|
1990
|
+
}): this;
|
|
1952
1991
|
/**
|
|
1953
1992
|
* Set whether to stop gadget execution on first error.
|
|
1954
1993
|
*
|
|
@@ -2047,6 +2086,37 @@ declare class AgentBuilder {
|
|
|
2047
2086
|
* ```
|
|
2048
2087
|
*/
|
|
2049
2088
|
withGadgetOutputLimitPercent(percent: number): this;
|
|
2089
|
+
/**
|
|
2090
|
+
* Add a synthetic gadget call to the conversation history.
|
|
2091
|
+
*
|
|
2092
|
+
* This is useful for in-context learning - showing the LLM what "past self"
|
|
2093
|
+
* did correctly so it mimics the pattern. The call is formatted with proper
|
|
2094
|
+
* markers and parameter format.
|
|
2095
|
+
*
|
|
2096
|
+
* @param gadgetName - Name of the gadget
|
|
2097
|
+
* @param parameters - Parameters passed to the gadget
|
|
2098
|
+
* @param result - Result returned by the gadget
|
|
2099
|
+
* @returns This builder for chaining
|
|
2100
|
+
*
|
|
2101
|
+
* @example
|
|
2102
|
+
* ```typescript
|
|
2103
|
+
* .withSyntheticGadgetCall(
|
|
2104
|
+
* 'TellUser',
|
|
2105
|
+
* {
|
|
2106
|
+
* message: '👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands',
|
|
2107
|
+
* done: false,
|
|
2108
|
+
* type: 'info'
|
|
2109
|
+
* },
|
|
2110
|
+
* 'ℹ️ 👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands'
|
|
2111
|
+
* )
|
|
2112
|
+
* ```
|
|
2113
|
+
*/
|
|
2114
|
+
withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
|
|
2115
|
+
/**
|
|
2116
|
+
* Format parameters for synthetic gadget calls.
|
|
2117
|
+
* Uses heredoc for multiline string values.
|
|
2118
|
+
*/
|
|
2119
|
+
private formatSyntheticParameters;
|
|
2050
2120
|
/**
|
|
2051
2121
|
* Build and create the agent with the given user prompt.
|
|
2052
2122
|
* Returns the Agent instance ready to run.
|
|
@@ -1565,6 +1565,18 @@ interface AgentOptions {
|
|
|
1565
1565
|
}>;
|
|
1566
1566
|
/** Text-only handler */
|
|
1567
1567
|
textOnlyHandler?: TextOnlyHandler;
|
|
1568
|
+
/**
|
|
1569
|
+
* Handler for text content that appears alongside gadget calls.
|
|
1570
|
+
* When set, text accompanying gadgets will be wrapped as a synthetic gadget call.
|
|
1571
|
+
*/
|
|
1572
|
+
textWithGadgetsHandler?: {
|
|
1573
|
+
/** Name of the gadget to use for wrapping text */
|
|
1574
|
+
gadgetName: string;
|
|
1575
|
+
/** Maps text content to gadget parameters */
|
|
1576
|
+
parameterMapping: (text: string) => Record<string, unknown>;
|
|
1577
|
+
/** Maps text content to the result string (optional, defaults to text) */
|
|
1578
|
+
resultMapping?: (text: string) => string;
|
|
1579
|
+
};
|
|
1568
1580
|
/** Stop on gadget error */
|
|
1569
1581
|
stopOnGadgetError?: boolean;
|
|
1570
1582
|
/** Custom error continuation logic */
|
|
@@ -1612,6 +1624,7 @@ declare class Agent {
|
|
|
1612
1624
|
private readonly gadgetEndPrefix?;
|
|
1613
1625
|
private readonly onHumanInputRequired?;
|
|
1614
1626
|
private readonly textOnlyHandler;
|
|
1627
|
+
private readonly textWithGadgetsHandler?;
|
|
1615
1628
|
private readonly stopOnGadgetError;
|
|
1616
1629
|
private readonly shouldContinueAfterError?;
|
|
1617
1630
|
private readonly defaultGadgetTimeoutMs?;
|
|
@@ -1741,6 +1754,7 @@ declare class AgentBuilder {
|
|
|
1741
1754
|
private gadgetStartPrefix?;
|
|
1742
1755
|
private gadgetEndPrefix?;
|
|
1743
1756
|
private textOnlyHandler?;
|
|
1757
|
+
private textWithGadgetsHandler?;
|
|
1744
1758
|
private stopOnGadgetError?;
|
|
1745
1759
|
private shouldContinueAfterError?;
|
|
1746
1760
|
private defaultGadgetTimeoutMs?;
|
|
@@ -1949,6 +1963,31 @@ declare class AgentBuilder {
|
|
|
1949
1963
|
* ```
|
|
1950
1964
|
*/
|
|
1951
1965
|
withTextOnlyHandler(handler: TextOnlyHandler): this;
|
|
1966
|
+
/**
|
|
1967
|
+
* Set the handler for text content that appears alongside gadget calls.
|
|
1968
|
+
*
|
|
1969
|
+
* When set, text accompanying gadget responses will be wrapped as a
|
|
1970
|
+
* synthetic gadget call before the actual gadget results in the
|
|
1971
|
+
* conversation history.
|
|
1972
|
+
*
|
|
1973
|
+
* @param handler - Configuration for wrapping text
|
|
1974
|
+
* @returns This builder for chaining
|
|
1975
|
+
*
|
|
1976
|
+
* @example
|
|
1977
|
+
* ```typescript
|
|
1978
|
+
* // Wrap text as TellUser gadget
|
|
1979
|
+
* .withTextWithGadgetsHandler({
|
|
1980
|
+
* gadgetName: "TellUser",
|
|
1981
|
+
* parameterMapping: (text) => ({ message: text, done: false, type: "info" }),
|
|
1982
|
+
* resultMapping: (text) => `ℹ️ ${text}`,
|
|
1983
|
+
* })
|
|
1984
|
+
* ```
|
|
1985
|
+
*/
|
|
1986
|
+
withTextWithGadgetsHandler(handler: {
|
|
1987
|
+
gadgetName: string;
|
|
1988
|
+
parameterMapping: (text: string) => Record<string, unknown>;
|
|
1989
|
+
resultMapping?: (text: string) => string;
|
|
1990
|
+
}): this;
|
|
1952
1991
|
/**
|
|
1953
1992
|
* Set whether to stop gadget execution on first error.
|
|
1954
1993
|
*
|
|
@@ -2047,6 +2086,37 @@ declare class AgentBuilder {
|
|
|
2047
2086
|
* ```
|
|
2048
2087
|
*/
|
|
2049
2088
|
withGadgetOutputLimitPercent(percent: number): this;
|
|
2089
|
+
/**
|
|
2090
|
+
* Add a synthetic gadget call to the conversation history.
|
|
2091
|
+
*
|
|
2092
|
+
* This is useful for in-context learning - showing the LLM what "past self"
|
|
2093
|
+
* did correctly so it mimics the pattern. The call is formatted with proper
|
|
2094
|
+
* markers and parameter format.
|
|
2095
|
+
*
|
|
2096
|
+
* @param gadgetName - Name of the gadget
|
|
2097
|
+
* @param parameters - Parameters passed to the gadget
|
|
2098
|
+
* @param result - Result returned by the gadget
|
|
2099
|
+
* @returns This builder for chaining
|
|
2100
|
+
*
|
|
2101
|
+
* @example
|
|
2102
|
+
* ```typescript
|
|
2103
|
+
* .withSyntheticGadgetCall(
|
|
2104
|
+
* 'TellUser',
|
|
2105
|
+
* {
|
|
2106
|
+
* message: '👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands',
|
|
2107
|
+
* done: false,
|
|
2108
|
+
* type: 'info'
|
|
2109
|
+
* },
|
|
2110
|
+
* 'ℹ️ 👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands'
|
|
2111
|
+
* )
|
|
2112
|
+
* ```
|
|
2113
|
+
*/
|
|
2114
|
+
withSyntheticGadgetCall(gadgetName: string, parameters: Record<string, unknown>, result: string): this;
|
|
2115
|
+
/**
|
|
2116
|
+
* Format parameters for synthetic gadget calls.
|
|
2117
|
+
* Uses heredoc for multiline string values.
|
|
2118
|
+
*/
|
|
2119
|
+
private formatSyntheticParameters;
|
|
2050
2120
|
/**
|
|
2051
2121
|
* Build and create the agent with the given user prompt.
|
|
2052
2122
|
* Returns the Agent instance ready to run.
|
package/dist/testing/index.cjs
CHANGED
|
@@ -922,6 +922,10 @@ function formatParamsAsYaml(params) {
|
|
|
922
922
|
}
|
|
923
923
|
return lines.join("\n");
|
|
924
924
|
}
|
|
925
|
+
function formatTomlInlineTable(obj) {
|
|
926
|
+
const entries = Object.entries(obj).map(([k, v]) => `${k} = ${formatTomlValue(v)}`);
|
|
927
|
+
return `{ ${entries.join(", ")} }`;
|
|
928
|
+
}
|
|
925
929
|
function formatTomlValue(value) {
|
|
926
930
|
if (typeof value === "string") {
|
|
927
931
|
if (value.includes("\n")) {
|
|
@@ -939,10 +943,17 @@ ${delimiter}`;
|
|
|
939
943
|
return '""';
|
|
940
944
|
}
|
|
941
945
|
if (Array.isArray(value)) {
|
|
942
|
-
|
|
946
|
+
if (value.length === 0) return "[]";
|
|
947
|
+
const items = value.map((item) => {
|
|
948
|
+
if (typeof item === "object" && item !== null && !Array.isArray(item)) {
|
|
949
|
+
return formatTomlInlineTable(item);
|
|
950
|
+
}
|
|
951
|
+
return formatTomlValue(item);
|
|
952
|
+
});
|
|
953
|
+
return `[${items.join(", ")}]`;
|
|
943
954
|
}
|
|
944
955
|
if (typeof value === "object") {
|
|
945
|
-
return
|
|
956
|
+
return formatTomlInlineTable(value);
|
|
946
957
|
}
|
|
947
958
|
return JSON.stringify(value);
|
|
948
959
|
}
|
|
@@ -1958,6 +1969,14 @@ function preprocessTomlHeredoc(tomlStr) {
|
|
|
1958
1969
|
}
|
|
1959
1970
|
return result.join("\n");
|
|
1960
1971
|
}
|
|
1972
|
+
function stripMarkdownFences(content) {
|
|
1973
|
+
let cleaned = content.trim();
|
|
1974
|
+
const openingFence = /^```(?:toml|yaml|json)?\s*\n/i;
|
|
1975
|
+
const closingFence = /\n?```\s*$/;
|
|
1976
|
+
cleaned = cleaned.replace(openingFence, "");
|
|
1977
|
+
cleaned = cleaned.replace(closingFence, "");
|
|
1978
|
+
return cleaned.trim();
|
|
1979
|
+
}
|
|
1961
1980
|
var yaml2, import_js_toml, globalInvocationCounter, StreamParser;
|
|
1962
1981
|
var init_parser = __esm({
|
|
1963
1982
|
"src/gadgets/parser.ts"() {
|
|
@@ -2013,35 +2032,36 @@ var init_parser = __esm({
|
|
|
2013
2032
|
* Parse parameter string according to configured format
|
|
2014
2033
|
*/
|
|
2015
2034
|
parseParameters(raw) {
|
|
2035
|
+
const cleaned = stripMarkdownFences(raw);
|
|
2016
2036
|
if (this.parameterFormat === "json") {
|
|
2017
2037
|
try {
|
|
2018
|
-
return { parameters: JSON.parse(
|
|
2038
|
+
return { parameters: JSON.parse(cleaned) };
|
|
2019
2039
|
} catch (error) {
|
|
2020
2040
|
return { parseError: this.truncateParseError(error, "JSON") };
|
|
2021
2041
|
}
|
|
2022
2042
|
}
|
|
2023
2043
|
if (this.parameterFormat === "yaml") {
|
|
2024
2044
|
try {
|
|
2025
|
-
return { parameters: yaml2.load(preprocessYaml(
|
|
2045
|
+
return { parameters: yaml2.load(preprocessYaml(cleaned)) };
|
|
2026
2046
|
} catch (error) {
|
|
2027
2047
|
return { parseError: this.truncateParseError(error, "YAML") };
|
|
2028
2048
|
}
|
|
2029
2049
|
}
|
|
2030
2050
|
if (this.parameterFormat === "toml") {
|
|
2031
2051
|
try {
|
|
2032
|
-
return { parameters: (0, import_js_toml.load)(preprocessTomlHeredoc(
|
|
2052
|
+
return { parameters: (0, import_js_toml.load)(preprocessTomlHeredoc(cleaned)) };
|
|
2033
2053
|
} catch (error) {
|
|
2034
2054
|
return { parseError: this.truncateParseError(error, "TOML") };
|
|
2035
2055
|
}
|
|
2036
2056
|
}
|
|
2037
2057
|
try {
|
|
2038
|
-
return { parameters: JSON.parse(
|
|
2058
|
+
return { parameters: JSON.parse(cleaned) };
|
|
2039
2059
|
} catch {
|
|
2040
2060
|
try {
|
|
2041
|
-
return { parameters: (0, import_js_toml.load)(preprocessTomlHeredoc(
|
|
2061
|
+
return { parameters: (0, import_js_toml.load)(preprocessTomlHeredoc(cleaned)) };
|
|
2042
2062
|
} catch {
|
|
2043
2063
|
try {
|
|
2044
|
-
return { parameters: yaml2.load(preprocessYaml(
|
|
2064
|
+
return { parameters: yaml2.load(preprocessYaml(cleaned)) };
|
|
2045
2065
|
} catch (error) {
|
|
2046
2066
|
return { parseError: this.truncateParseError(error, "auto") };
|
|
2047
2067
|
}
|
|
@@ -2587,6 +2607,7 @@ var init_agent = __esm({
|
|
|
2587
2607
|
gadgetEndPrefix;
|
|
2588
2608
|
onHumanInputRequired;
|
|
2589
2609
|
textOnlyHandler;
|
|
2610
|
+
textWithGadgetsHandler;
|
|
2590
2611
|
stopOnGadgetError;
|
|
2591
2612
|
shouldContinueAfterError;
|
|
2592
2613
|
defaultGadgetTimeoutMs;
|
|
@@ -2617,6 +2638,7 @@ var init_agent = __esm({
|
|
|
2617
2638
|
this.gadgetEndPrefix = options.gadgetEndPrefix;
|
|
2618
2639
|
this.onHumanInputRequired = options.onHumanInputRequired;
|
|
2619
2640
|
this.textOnlyHandler = options.textOnlyHandler ?? "terminate";
|
|
2641
|
+
this.textWithGadgetsHandler = options.textWithGadgetsHandler;
|
|
2620
2642
|
this.stopOnGadgetError = options.stopOnGadgetError ?? true;
|
|
2621
2643
|
this.shouldContinueAfterError = options.shouldContinueAfterError;
|
|
2622
2644
|
this.defaultGadgetTimeoutMs = options.defaultGadgetTimeoutMs;
|
|
@@ -2804,6 +2826,17 @@ var init_agent = __esm({
|
|
|
2804
2826
|
}
|
|
2805
2827
|
}
|
|
2806
2828
|
if (result.didExecuteGadgets) {
|
|
2829
|
+
if (this.textWithGadgetsHandler) {
|
|
2830
|
+
const textContent = result.outputs.filter((output) => output.type === "text").map((output) => output.content).join("");
|
|
2831
|
+
if (textContent.trim()) {
|
|
2832
|
+
const { gadgetName, parameterMapping, resultMapping } = this.textWithGadgetsHandler;
|
|
2833
|
+
this.conversation.addGadgetCall(
|
|
2834
|
+
gadgetName,
|
|
2835
|
+
parameterMapping(textContent),
|
|
2836
|
+
resultMapping ? resultMapping(textContent) : textContent
|
|
2837
|
+
);
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2807
2840
|
for (const output of result.outputs) {
|
|
2808
2841
|
if (output.type === "gadget_result") {
|
|
2809
2842
|
const gadgetResult = output.result;
|
|
@@ -2815,7 +2848,13 @@ var init_agent = __esm({
|
|
|
2815
2848
|
}
|
|
2816
2849
|
}
|
|
2817
2850
|
} else {
|
|
2818
|
-
|
|
2851
|
+
if (finalMessage.trim()) {
|
|
2852
|
+
this.conversation.addGadgetCall(
|
|
2853
|
+
"TellUser",
|
|
2854
|
+
{ message: finalMessage, done: false, type: "info" },
|
|
2855
|
+
`\u2139\uFE0F ${finalMessage}`
|
|
2856
|
+
);
|
|
2857
|
+
}
|
|
2819
2858
|
const shouldBreak = await this.handleTextOnlyResponse(finalMessage);
|
|
2820
2859
|
if (shouldBreak) {
|
|
2821
2860
|
break;
|
|
@@ -3000,6 +3039,7 @@ var AgentBuilder;
|
|
|
3000
3039
|
var init_builder = __esm({
|
|
3001
3040
|
"src/agent/builder.ts"() {
|
|
3002
3041
|
"use strict";
|
|
3042
|
+
init_constants();
|
|
3003
3043
|
init_model_shortcuts();
|
|
3004
3044
|
init_registry();
|
|
3005
3045
|
init_agent();
|
|
@@ -3021,6 +3061,7 @@ var init_builder = __esm({
|
|
|
3021
3061
|
gadgetStartPrefix;
|
|
3022
3062
|
gadgetEndPrefix;
|
|
3023
3063
|
textOnlyHandler;
|
|
3064
|
+
textWithGadgetsHandler;
|
|
3024
3065
|
stopOnGadgetError;
|
|
3025
3066
|
shouldContinueAfterError;
|
|
3026
3067
|
defaultGadgetTimeoutMs;
|
|
@@ -3283,6 +3324,30 @@ var init_builder = __esm({
|
|
|
3283
3324
|
this.textOnlyHandler = handler;
|
|
3284
3325
|
return this;
|
|
3285
3326
|
}
|
|
3327
|
+
/**
|
|
3328
|
+
* Set the handler for text content that appears alongside gadget calls.
|
|
3329
|
+
*
|
|
3330
|
+
* When set, text accompanying gadget responses will be wrapped as a
|
|
3331
|
+
* synthetic gadget call before the actual gadget results in the
|
|
3332
|
+
* conversation history.
|
|
3333
|
+
*
|
|
3334
|
+
* @param handler - Configuration for wrapping text
|
|
3335
|
+
* @returns This builder for chaining
|
|
3336
|
+
*
|
|
3337
|
+
* @example
|
|
3338
|
+
* ```typescript
|
|
3339
|
+
* // Wrap text as TellUser gadget
|
|
3340
|
+
* .withTextWithGadgetsHandler({
|
|
3341
|
+
* gadgetName: "TellUser",
|
|
3342
|
+
* parameterMapping: (text) => ({ message: text, done: false, type: "info" }),
|
|
3343
|
+
* resultMapping: (text) => `ℹ️ ${text}`,
|
|
3344
|
+
* })
|
|
3345
|
+
* ```
|
|
3346
|
+
*/
|
|
3347
|
+
withTextWithGadgetsHandler(handler) {
|
|
3348
|
+
this.textWithGadgetsHandler = handler;
|
|
3349
|
+
return this;
|
|
3350
|
+
}
|
|
3286
3351
|
/**
|
|
3287
3352
|
* Set whether to stop gadget execution on first error.
|
|
3288
3353
|
*
|
|
@@ -3397,6 +3462,69 @@ var init_builder = __esm({
|
|
|
3397
3462
|
this.gadgetOutputLimitPercent = percent;
|
|
3398
3463
|
return this;
|
|
3399
3464
|
}
|
|
3465
|
+
/**
|
|
3466
|
+
* Add a synthetic gadget call to the conversation history.
|
|
3467
|
+
*
|
|
3468
|
+
* This is useful for in-context learning - showing the LLM what "past self"
|
|
3469
|
+
* did correctly so it mimics the pattern. The call is formatted with proper
|
|
3470
|
+
* markers and parameter format.
|
|
3471
|
+
*
|
|
3472
|
+
* @param gadgetName - Name of the gadget
|
|
3473
|
+
* @param parameters - Parameters passed to the gadget
|
|
3474
|
+
* @param result - Result returned by the gadget
|
|
3475
|
+
* @returns This builder for chaining
|
|
3476
|
+
*
|
|
3477
|
+
* @example
|
|
3478
|
+
* ```typescript
|
|
3479
|
+
* .withSyntheticGadgetCall(
|
|
3480
|
+
* 'TellUser',
|
|
3481
|
+
* {
|
|
3482
|
+
* message: '👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands',
|
|
3483
|
+
* done: false,
|
|
3484
|
+
* type: 'info'
|
|
3485
|
+
* },
|
|
3486
|
+
* 'ℹ️ 👋 Hello!\n\nHere\'s what I can do:\n- Analyze code\n- Run commands'
|
|
3487
|
+
* )
|
|
3488
|
+
* ```
|
|
3489
|
+
*/
|
|
3490
|
+
withSyntheticGadgetCall(gadgetName, parameters, result) {
|
|
3491
|
+
const startPrefix = this.gadgetStartPrefix ?? GADGET_START_PREFIX;
|
|
3492
|
+
const endPrefix = this.gadgetEndPrefix ?? GADGET_END_PREFIX;
|
|
3493
|
+
const format = this.parameterFormat ?? "yaml";
|
|
3494
|
+
const paramStr = this.formatSyntheticParameters(parameters, format);
|
|
3495
|
+
this.initialMessages.push({
|
|
3496
|
+
role: "assistant",
|
|
3497
|
+
content: `${startPrefix}${gadgetName}
|
|
3498
|
+
${paramStr}
|
|
3499
|
+
${endPrefix}`
|
|
3500
|
+
});
|
|
3501
|
+
this.initialMessages.push({
|
|
3502
|
+
role: "user",
|
|
3503
|
+
content: `Result: ${result}`
|
|
3504
|
+
});
|
|
3505
|
+
return this;
|
|
3506
|
+
}
|
|
3507
|
+
/**
|
|
3508
|
+
* Format parameters for synthetic gadget calls.
|
|
3509
|
+
* Uses heredoc for multiline string values.
|
|
3510
|
+
*/
|
|
3511
|
+
formatSyntheticParameters(parameters, format) {
|
|
3512
|
+
if (format === "json" || format === "auto") {
|
|
3513
|
+
return JSON.stringify(parameters);
|
|
3514
|
+
}
|
|
3515
|
+
return Object.entries(parameters).map(([key, value]) => {
|
|
3516
|
+
if (typeof value === "string" && value.includes("\n")) {
|
|
3517
|
+
const separator = format === "yaml" ? ":" : " =";
|
|
3518
|
+
return `${key}${separator} <<<EOF
|
|
3519
|
+
${value}
|
|
3520
|
+
EOF`;
|
|
3521
|
+
}
|
|
3522
|
+
if (format === "yaml") {
|
|
3523
|
+
return typeof value === "string" ? `${key}: ${value}` : `${key}: ${JSON.stringify(value)}`;
|
|
3524
|
+
}
|
|
3525
|
+
return `${key} = ${JSON.stringify(value)}`;
|
|
3526
|
+
}).join("\n");
|
|
3527
|
+
}
|
|
3400
3528
|
/**
|
|
3401
3529
|
* Build and create the agent with the given user prompt.
|
|
3402
3530
|
* Returns the Agent instance ready to run.
|
|
@@ -3439,6 +3567,7 @@ var init_builder = __esm({
|
|
|
3439
3567
|
gadgetStartPrefix: this.gadgetStartPrefix,
|
|
3440
3568
|
gadgetEndPrefix: this.gadgetEndPrefix,
|
|
3441
3569
|
textOnlyHandler: this.textOnlyHandler,
|
|
3570
|
+
textWithGadgetsHandler: this.textWithGadgetsHandler,
|
|
3442
3571
|
stopOnGadgetError: this.stopOnGadgetError,
|
|
3443
3572
|
shouldContinueAfterError: this.shouldContinueAfterError,
|
|
3444
3573
|
defaultGadgetTimeoutMs: this.defaultGadgetTimeoutMs,
|
|
@@ -3540,6 +3669,7 @@ var init_builder = __esm({
|
|
|
3540
3669
|
gadgetStartPrefix: this.gadgetStartPrefix,
|
|
3541
3670
|
gadgetEndPrefix: this.gadgetEndPrefix,
|
|
3542
3671
|
textOnlyHandler: this.textOnlyHandler,
|
|
3672
|
+
textWithGadgetsHandler: this.textWithGadgetsHandler,
|
|
3543
3673
|
stopOnGadgetError: this.stopOnGadgetError,
|
|
3544
3674
|
shouldContinueAfterError: this.shouldContinueAfterError,
|
|
3545
3675
|
defaultGadgetTimeoutMs: this.defaultGadgetTimeoutMs,
|