@lleverage-ai/agent-sdk 0.0.2 → 0.0.3

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.
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Default prompt components for common use cases.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { PromptComponent } from "./index.js";
7
+ import { PromptBuilder } from "./index.js";
8
+ /**
9
+ * Default identity component providing a basic agent identity.
10
+ *
11
+ * Priority: 100 (highest)
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const builder = new PromptBuilder().register(identityComponent);
16
+ * ```
17
+ *
18
+ * @category Prompt Builder
19
+ */
20
+ export declare const identityComponent: PromptComponent;
21
+ /**
22
+ * Lists available tools in the system prompt.
23
+ *
24
+ * Only included if tools are available.
25
+ * Priority: 70
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const builder = new PromptBuilder().register(toolsComponent);
30
+ * ```
31
+ *
32
+ * @category Prompt Builder
33
+ */
34
+ export declare const toolsComponent: PromptComponent;
35
+ /**
36
+ * Lists available skills in the system prompt.
37
+ *
38
+ * Only included if skills are available.
39
+ * Priority: 65
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const builder = new PromptBuilder().register(skillsComponent);
44
+ * ```
45
+ *
46
+ * @category Prompt Builder
47
+ */
48
+ export declare const skillsComponent: PromptComponent;
49
+ /**
50
+ * Lists agent capabilities based on backend and configuration.
51
+ *
52
+ * Priority: 60
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const builder = new PromptBuilder().register(capabilitiesComponent);
57
+ * ```
58
+ *
59
+ * @category Prompt Builder
60
+ */
61
+ export declare const capabilitiesComponent: PromptComponent;
62
+ /**
63
+ * Provides context about the current conversation.
64
+ *
65
+ * Only included if thread ID or messages are available.
66
+ * Priority: 50
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const builder = new PromptBuilder().register(contextComponent);
71
+ * ```
72
+ *
73
+ * @category Prompt Builder
74
+ */
75
+ export declare const contextComponent: PromptComponent;
76
+ /**
77
+ * Lists loaded plugins.
78
+ *
79
+ * Only included if plugins are available.
80
+ * Priority: 68
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const builder = new PromptBuilder().register(pluginsComponent);
85
+ * ```
86
+ *
87
+ * @category Prompt Builder
88
+ */
89
+ export declare const pluginsComponent: PromptComponent;
90
+ /**
91
+ * Provides information about permission mode.
92
+ *
93
+ * Only included if permission mode is set.
94
+ * Priority: 55
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const builder = new PromptBuilder().register(permissionModeComponent);
99
+ * ```
100
+ *
101
+ * @category Prompt Builder
102
+ */
103
+ export declare const permissionModeComponent: PromptComponent;
104
+ /**
105
+ * Creates a prompt builder with sensible defaults.
106
+ *
107
+ * Includes the following components by default:
108
+ * - `identity`: Basic agent identity
109
+ * - `tools-listing`: Available tools
110
+ * - `skills-listing`: Available skills
111
+ * - `plugins-listing`: Loaded plugins
112
+ * - `capabilities`: Backend capabilities
113
+ * - `permission-mode`: Permission mode info
114
+ * - `context`: Conversation context
115
+ *
116
+ * You can customize by cloning and modifying:
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Use defaults
121
+ * const agent = createAgent({
122
+ * model,
123
+ * // No systemPrompt = uses default builder automatically
124
+ * });
125
+ * ```
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * // Customize defaults
130
+ * const builder = createDefaultPromptBuilder()
131
+ * .unregister('identity')
132
+ * .register({
133
+ * name: 'custom-identity',
134
+ * priority: 100,
135
+ * render: () => 'You are a specialized coding assistant.',
136
+ * });
137
+ *
138
+ * const agent = createAgent({
139
+ * model,
140
+ * promptBuilder: builder,
141
+ * });
142
+ * ```
143
+ *
144
+ * @returns A PromptBuilder with default components registered
145
+ *
146
+ * @category Prompt Builder
147
+ */
148
+ export declare function createDefaultPromptBuilder(): PromptBuilder;
149
+ //# sourceMappingURL=components.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../src/prompt-builder/components.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,iBAAiB,EAAE,eAI/B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,EAAE,eAQ5B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe,EAAE,eAQ7B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,EAAE,eA6BnC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAE,eAqB9B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAE,eAQ9B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,EAAE,eAsBrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,0BAA0B,IAAI,aAAa,CAU1D"}
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Default prompt components for common use cases.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import { PromptBuilder } from "./index.js";
7
+ /**
8
+ * Default identity component providing a basic agent identity.
9
+ *
10
+ * Priority: 100 (highest)
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const builder = new PromptBuilder().register(identityComponent);
15
+ * ```
16
+ *
17
+ * @category Prompt Builder
18
+ */
19
+ export const identityComponent = {
20
+ name: "identity",
21
+ priority: 100,
22
+ render: () => "You are a helpful AI assistant.",
23
+ };
24
+ /**
25
+ * Lists available tools in the system prompt.
26
+ *
27
+ * Only included if tools are available.
28
+ * Priority: 70
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const builder = new PromptBuilder().register(toolsComponent);
33
+ * ```
34
+ *
35
+ * @category Prompt Builder
36
+ */
37
+ export const toolsComponent = {
38
+ name: "tools-listing",
39
+ priority: 70,
40
+ condition: (ctx) => ctx.tools !== undefined && ctx.tools.length > 0,
41
+ render: (ctx) => {
42
+ const toolLines = ctx.tools.map((t) => `- **${t.name}**: ${t.description}`);
43
+ return `# Available Tools\n\nYou have access to the following tools:\n${toolLines.join("\n")}`;
44
+ },
45
+ };
46
+ /**
47
+ * Lists available skills in the system prompt.
48
+ *
49
+ * Only included if skills are available.
50
+ * Priority: 65
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const builder = new PromptBuilder().register(skillsComponent);
55
+ * ```
56
+ *
57
+ * @category Prompt Builder
58
+ */
59
+ export const skillsComponent = {
60
+ name: "skills-listing",
61
+ priority: 65,
62
+ condition: (ctx) => ctx.skills !== undefined && ctx.skills.length > 0,
63
+ render: (ctx) => {
64
+ const skillLines = ctx.skills.map((s) => `- **${s.name}**: ${s.description}`);
65
+ return `# Available Skills\n\nYou can activate these skills on-demand:\n${skillLines.join("\n")}`;
66
+ },
67
+ };
68
+ /**
69
+ * Lists agent capabilities based on backend and configuration.
70
+ *
71
+ * Priority: 60
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const builder = new PromptBuilder().register(capabilitiesComponent);
76
+ * ```
77
+ *
78
+ * @category Prompt Builder
79
+ */
80
+ export const capabilitiesComponent = {
81
+ name: "capabilities",
82
+ priority: 60,
83
+ render: (ctx) => {
84
+ const capabilities = [];
85
+ if (ctx.backend?.hasExecuteCapability) {
86
+ capabilities.push("- Execute shell commands (bash)");
87
+ }
88
+ if (ctx.backend?.type === "filesystem") {
89
+ capabilities.push("- Read and write files to the filesystem");
90
+ if (ctx.backend.rootDir) {
91
+ capabilities.push(`- Working directory: ${ctx.backend.rootDir}`);
92
+ }
93
+ }
94
+ else if (ctx.backend?.type === "state") {
95
+ capabilities.push("- In-memory file operations (sandboxed)");
96
+ }
97
+ if (ctx.state?.todos && ctx.state.todos.length > 0) {
98
+ capabilities.push(`- ${ctx.state.todos.length} active task(s) in the task list`);
99
+ }
100
+ if (capabilities.length === 0) {
101
+ return "";
102
+ }
103
+ return `# Capabilities\n\n${capabilities.join("\n")}`;
104
+ },
105
+ };
106
+ /**
107
+ * Provides context about the current conversation.
108
+ *
109
+ * Only included if thread ID or messages are available.
110
+ * Priority: 50
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const builder = new PromptBuilder().register(contextComponent);
115
+ * ```
116
+ *
117
+ * @category Prompt Builder
118
+ */
119
+ export const contextComponent = {
120
+ name: "context",
121
+ priority: 50,
122
+ condition: (ctx) => !!ctx.threadId || !!(ctx.currentMessages && ctx.currentMessages.length > 0),
123
+ render: (ctx) => {
124
+ const parts = [];
125
+ if (ctx.threadId) {
126
+ parts.push(`- Thread ID: ${ctx.threadId}`);
127
+ }
128
+ if (ctx.currentMessages && ctx.currentMessages.length > 0) {
129
+ parts.push(`- Conversation history: ${ctx.currentMessages.length} message(s)`);
130
+ }
131
+ if (parts.length === 0) {
132
+ return "";
133
+ }
134
+ return `# Context\n\n${parts.join("\n")}`;
135
+ },
136
+ };
137
+ /**
138
+ * Lists loaded plugins.
139
+ *
140
+ * Only included if plugins are available.
141
+ * Priority: 68
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const builder = new PromptBuilder().register(pluginsComponent);
146
+ * ```
147
+ *
148
+ * @category Prompt Builder
149
+ */
150
+ export const pluginsComponent = {
151
+ name: "plugins-listing",
152
+ priority: 68,
153
+ condition: (ctx) => ctx.plugins !== undefined && ctx.plugins.length > 0,
154
+ render: (ctx) => {
155
+ const pluginLines = ctx.plugins.map((p) => `- **${p.name}**: ${p.description}`);
156
+ return `# Loaded Plugins\n\n${pluginLines.join("\n")}`;
157
+ },
158
+ };
159
+ /**
160
+ * Provides information about permission mode.
161
+ *
162
+ * Only included if permission mode is set.
163
+ * Priority: 55
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const builder = new PromptBuilder().register(permissionModeComponent);
168
+ * ```
169
+ *
170
+ * @category Prompt Builder
171
+ */
172
+ export const permissionModeComponent = {
173
+ name: "permission-mode",
174
+ priority: 55,
175
+ condition: (ctx) => !!ctx.permissionMode,
176
+ render: (ctx) => {
177
+ const mode = ctx.permissionMode;
178
+ let description = "";
179
+ if (mode === "default") {
180
+ description = "Default permission mode: tools may require approval based on safety rules.";
181
+ }
182
+ else if (mode === "acceptEdits") {
183
+ description = "File editing tools are auto-approved; other tools may require approval.";
184
+ }
185
+ else if (mode === "bypassPermissions") {
186
+ description = "All tools are auto-approved without permission checks.";
187
+ }
188
+ else if (mode === "plan") {
189
+ description = "Plan mode: tool use is planned but not executed.";
190
+ }
191
+ else {
192
+ description = `Permission mode: ${String(mode)}`;
193
+ }
194
+ return `# Permission Mode\n\n${description}`;
195
+ },
196
+ };
197
+ /**
198
+ * Creates a prompt builder with sensible defaults.
199
+ *
200
+ * Includes the following components by default:
201
+ * - `identity`: Basic agent identity
202
+ * - `tools-listing`: Available tools
203
+ * - `skills-listing`: Available skills
204
+ * - `plugins-listing`: Loaded plugins
205
+ * - `capabilities`: Backend capabilities
206
+ * - `permission-mode`: Permission mode info
207
+ * - `context`: Conversation context
208
+ *
209
+ * You can customize by cloning and modifying:
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * // Use defaults
214
+ * const agent = createAgent({
215
+ * model,
216
+ * // No systemPrompt = uses default builder automatically
217
+ * });
218
+ * ```
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * // Customize defaults
223
+ * const builder = createDefaultPromptBuilder()
224
+ * .unregister('identity')
225
+ * .register({
226
+ * name: 'custom-identity',
227
+ * priority: 100,
228
+ * render: () => 'You are a specialized coding assistant.',
229
+ * });
230
+ *
231
+ * const agent = createAgent({
232
+ * model,
233
+ * promptBuilder: builder,
234
+ * });
235
+ * ```
236
+ *
237
+ * @returns A PromptBuilder with default components registered
238
+ *
239
+ * @category Prompt Builder
240
+ */
241
+ export function createDefaultPromptBuilder() {
242
+ return new PromptBuilder().registerMany([
243
+ identityComponent,
244
+ toolsComponent,
245
+ skillsComponent,
246
+ pluginsComponent,
247
+ capabilitiesComponent,
248
+ permissionModeComponent,
249
+ contextComponent,
250
+ ]);
251
+ }
252
+ //# sourceMappingURL=components.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/prompt-builder/components.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAoB;IAChD,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,GAAG;IACb,MAAM,EAAE,GAAG,EAAE,CAAC,iCAAiC;CAChD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,IAAI,EAAE,eAAe;IACrB,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;IACnE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE;QACd,MAAM,SAAS,GAAG,GAAG,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;QAC7E,OAAO,iEAAiE,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACjG,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoB;IAC9C,IAAI,EAAE,gBAAgB;IACtB,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,IAAI,aAAa,EAAE,CAAC,YAAY,CAAC;QACtC,iBAAiB;QACjB,cAAc;QACd,eAAe;QACf,gBAAgB;QAChB,qBAAqB;QACrB,uBAAuB;QACvB,gBAAgB;KACjB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Prompt builder system for creating dynamic, context-aware system prompts.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { ModelMessage } from "ai";
7
+ import type { AgentState } from "../backends/state.js";
8
+ import type { PermissionMode } from "../types.js";
9
+ /**
10
+ * Context available to prompt components when building prompts.
11
+ * Contains all relevant agent state and configuration.
12
+ *
13
+ * @category Prompt Builder
14
+ */
15
+ export interface PromptContext {
16
+ /**
17
+ * Tools available to the agent.
18
+ * Each entry includes the tool name and description.
19
+ */
20
+ tools?: Array<{
21
+ name: string;
22
+ description: string;
23
+ }>;
24
+ /**
25
+ * Skills available to the agent.
26
+ * Each entry includes the skill name and description.
27
+ */
28
+ skills?: Array<{
29
+ name: string;
30
+ description: string;
31
+ }>;
32
+ /**
33
+ * Plugins loaded by the agent.
34
+ * Each entry includes the plugin name and description.
35
+ */
36
+ plugins?: Array<{
37
+ name: string;
38
+ description: string;
39
+ }>;
40
+ /**
41
+ * Information about the backend being used.
42
+ */
43
+ backend?: {
44
+ /** Type of backend (e.g., 'filesystem', 'state') */
45
+ type: string;
46
+ /** Whether the backend supports command execution */
47
+ hasExecuteCapability: boolean;
48
+ /** Root directory for filesystem backends */
49
+ rootDir?: string;
50
+ };
51
+ /**
52
+ * Agent state for accessing todos and other state.
53
+ */
54
+ state?: AgentState;
55
+ /**
56
+ * Model identifier being used.
57
+ */
58
+ model?: string;
59
+ /**
60
+ * Maximum number of tool call steps allowed.
61
+ */
62
+ maxSteps?: number;
63
+ /**
64
+ * Permission mode for the agent.
65
+ */
66
+ permissionMode?: PermissionMode;
67
+ /**
68
+ * Current conversation messages (available during generation).
69
+ */
70
+ currentMessages?: ModelMessage[];
71
+ /**
72
+ * Thread ID for the current conversation (if any).
73
+ */
74
+ threadId?: string;
75
+ /**
76
+ * Custom user-defined data that can be passed to components.
77
+ */
78
+ custom?: Record<string, unknown>;
79
+ }
80
+ /**
81
+ * A component that contributes to the system prompt.
82
+ *
83
+ * Components are sorted by priority (higher = rendered earlier in prompt)
84
+ * and can conditionally include themselves based on context.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const toolsComponent: PromptComponent = {
89
+ * name: 'tools-listing',
90
+ * priority: 70,
91
+ * condition: (ctx) => ctx.tools !== undefined && ctx.tools.length > 0,
92
+ * render: (ctx) => {
93
+ * const toolLines = ctx.tools!.map((t) => `- **${t.name}**: ${t.description}`);
94
+ * return `# Available Tools\n\n${toolLines.join('\n')}`;
95
+ * },
96
+ * };
97
+ * ```
98
+ *
99
+ * @category Prompt Builder
100
+ */
101
+ export interface PromptComponent {
102
+ /**
103
+ * Unique identifier for this component.
104
+ * Used for unregistering components.
105
+ */
106
+ name: string;
107
+ /**
108
+ * Priority for ordering components in the final prompt.
109
+ * Higher priority components are rendered first.
110
+ * @defaultValue 50
111
+ */
112
+ priority?: number;
113
+ /**
114
+ * Optional condition to determine if this component should be included.
115
+ * If not provided or returns true, the component is included.
116
+ * @param ctx - The prompt context
117
+ * @returns true to include this component, false to skip it
118
+ */
119
+ condition?: (ctx: PromptContext) => boolean;
120
+ /**
121
+ * Render the component's contribution to the prompt.
122
+ * @param ctx - The prompt context
123
+ * @returns The text to include in the system prompt
124
+ */
125
+ render: (ctx: PromptContext) => string;
126
+ }
127
+ /**
128
+ * Builder for constructing dynamic system prompts from components.
129
+ *
130
+ * The PromptBuilder manages a collection of components that are combined
131
+ * to create the final system prompt. Components are sorted by priority
132
+ * and can conditionally include themselves.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const builder = new PromptBuilder()
137
+ * .register({
138
+ * name: 'identity',
139
+ * priority: 100,
140
+ * render: () => 'You are a helpful assistant.',
141
+ * })
142
+ * .register({
143
+ * name: 'tools',
144
+ * priority: 70,
145
+ * condition: (ctx) => ctx.tools && ctx.tools.length > 0,
146
+ * render: (ctx) => `Tools: ${ctx.tools!.map(t => t.name).join(', ')}`,
147
+ * });
148
+ *
149
+ * const prompt = builder.build({ tools: [{ name: 'read', description: 'Read files' }] });
150
+ * ```
151
+ *
152
+ * @category Prompt Builder
153
+ */
154
+ export declare class PromptBuilder {
155
+ private components;
156
+ /**
157
+ * Register a single component.
158
+ *
159
+ * If a component with the same name already exists, it will be replaced.
160
+ *
161
+ * @param component - The component to register
162
+ * @returns This builder for chaining
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * builder.register({
167
+ * name: 'custom',
168
+ * priority: 80,
169
+ * render: () => 'Custom instructions',
170
+ * });
171
+ * ```
172
+ */
173
+ register(component: PromptComponent): this;
174
+ /**
175
+ * Register multiple components at once.
176
+ *
177
+ * @param components - Array of components to register
178
+ * @returns This builder for chaining
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * builder.registerMany([
183
+ * identityComponent,
184
+ * toolsComponent,
185
+ * skillsComponent,
186
+ * ]);
187
+ * ```
188
+ */
189
+ registerMany(components: PromptComponent[]): this;
190
+ /**
191
+ * Remove a component by name.
192
+ *
193
+ * @param name - The name of the component to remove
194
+ * @returns This builder for chaining
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * builder.unregister('identity');
199
+ * ```
200
+ */
201
+ unregister(name: string): this;
202
+ /**
203
+ * Build the final prompt from the registered components.
204
+ *
205
+ * Components are:
206
+ * 1. Filtered by their condition functions (if present)
207
+ * 2. Sorted by priority (higher priority first)
208
+ * 3. Rendered and joined with double newlines
209
+ *
210
+ * @param context - The context to pass to components
211
+ * @returns The final system prompt string
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * const context: PromptContext = {
216
+ * tools: [{ name: 'read', description: 'Read files' }],
217
+ * model: 'claude-3-5-sonnet-20241022',
218
+ * };
219
+ * const prompt = builder.build(context);
220
+ * ```
221
+ */
222
+ build(context: PromptContext): string;
223
+ /**
224
+ * Clone this builder with all its registered components.
225
+ *
226
+ * Useful for creating variants of a base builder.
227
+ *
228
+ * @returns A new PromptBuilder with the same components
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const base = createDefaultPromptBuilder();
233
+ * const custom = base.clone().register({
234
+ * name: 'custom',
235
+ * render: () => 'Additional instructions',
236
+ * });
237
+ * ```
238
+ */
239
+ clone(): PromptBuilder;
240
+ /**
241
+ * Get all registered component names.
242
+ * Useful for debugging and introspection.
243
+ *
244
+ * @returns Array of component names
245
+ */
246
+ getComponentNames(): string[];
247
+ }
248
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prompt-builder/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAErD;;;OAGG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEtD;;;OAGG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEvD;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,oDAAoD;QACpD,IAAI,EAAE,M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