@mainwp/control 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.
- package/LICENSE +674 -0
- package/README.md +583 -0
- package/bin/_exit.js +12 -0
- package/bin/dev.js +7 -0
- package/bin/run.js +7 -0
- package/dist/chat/chat-engine.d.ts +213 -0
- package/dist/chat/chat-engine.d.ts.map +1 -0
- package/dist/chat/chat-engine.js +636 -0
- package/dist/chat/chat-engine.js.map +1 -0
- package/dist/chat/index.d.ts +10 -0
- package/dist/chat/index.d.ts.map +1 -0
- package/dist/chat/index.js +14 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/providers/anthropic.d.ts +52 -0
- package/dist/chat/providers/anthropic.d.ts.map +1 -0
- package/dist/chat/providers/anthropic.js +292 -0
- package/dist/chat/providers/anthropic.js.map +1 -0
- package/dist/chat/providers/gemini.d.ts +52 -0
- package/dist/chat/providers/gemini.d.ts.map +1 -0
- package/dist/chat/providers/gemini.js +284 -0
- package/dist/chat/providers/gemini.js.map +1 -0
- package/dist/chat/providers/index.d.ts +19 -0
- package/dist/chat/providers/index.d.ts.map +1 -0
- package/dist/chat/providers/index.js +23 -0
- package/dist/chat/providers/index.js.map +1 -0
- package/dist/chat/providers/local.d.ts +37 -0
- package/dist/chat/providers/local.d.ts.map +1 -0
- package/dist/chat/providers/local.js +130 -0
- package/dist/chat/providers/local.js.map +1 -0
- package/dist/chat/providers/openai-compatible.d.ts +155 -0
- package/dist/chat/providers/openai-compatible.d.ts.map +1 -0
- package/dist/chat/providers/openai-compatible.js +264 -0
- package/dist/chat/providers/openai-compatible.js.map +1 -0
- package/dist/chat/providers/openai.d.ts +24 -0
- package/dist/chat/providers/openai.d.ts.map +1 -0
- package/dist/chat/providers/openai.js +62 -0
- package/dist/chat/providers/openai.js.map +1 -0
- package/dist/chat/providers/openrouter.d.ts +26 -0
- package/dist/chat/providers/openrouter.d.ts.map +1 -0
- package/dist/chat/providers/openrouter.js +65 -0
- package/dist/chat/providers/openrouter.js.map +1 -0
- package/dist/chat/providers/provider-fetch.d.ts +15 -0
- package/dist/chat/providers/provider-fetch.d.ts.map +1 -0
- package/dist/chat/providers/provider-fetch.js +35 -0
- package/dist/chat/providers/provider-fetch.js.map +1 -0
- package/dist/chat/providers/provider.d.ts +214 -0
- package/dist/chat/providers/provider.d.ts.map +1 -0
- package/dist/chat/providers/provider.js +166 -0
- package/dist/chat/providers/provider.js.map +1 -0
- package/dist/chat/providers/sse-reader.d.ts +21 -0
- package/dist/chat/providers/sse-reader.d.ts.map +1 -0
- package/dist/chat/providers/sse-reader.js +48 -0
- package/dist/chat/providers/sse-reader.js.map +1 -0
- package/dist/chat/system-prompt.d.ts +33 -0
- package/dist/chat/system-prompt.d.ts.map +1 -0
- package/dist/chat/system-prompt.js +166 -0
- package/dist/chat/system-prompt.js.map +1 -0
- package/dist/chat/tool-envelope.d.ts +72 -0
- package/dist/chat/tool-envelope.d.ts.map +1 -0
- package/dist/chat/tool-envelope.js +263 -0
- package/dist/chat/tool-envelope.js.map +1 -0
- package/dist/commands/abilities/info.d.ts +21 -0
- package/dist/commands/abilities/info.d.ts.map +1 -0
- package/dist/commands/abilities/info.js +80 -0
- package/dist/commands/abilities/info.js.map +1 -0
- package/dist/commands/abilities/list.d.ts +19 -0
- package/dist/commands/abilities/list.d.ts.map +1 -0
- package/dist/commands/abilities/list.js +98 -0
- package/dist/commands/abilities/list.js.map +1 -0
- package/dist/commands/abilities/run.d.ts +75 -0
- package/dist/commands/abilities/run.d.ts.map +1 -0
- package/dist/commands/abilities/run.js +468 -0
- package/dist/commands/abilities/run.js.map +1 -0
- package/dist/commands/chat.d.ts +54 -0
- package/dist/commands/chat.d.ts.map +1 -0
- package/dist/commands/chat.js +384 -0
- package/dist/commands/chat.js.map +1 -0
- package/dist/commands/config/show.d.ts +54 -0
- package/dist/commands/config/show.d.ts.map +1 -0
- package/dist/commands/config/show.js +324 -0
- package/dist/commands/config/show.js.map +1 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +412 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/jobs/watch.d.ts +50 -0
- package/dist/commands/jobs/watch.d.ts.map +1 -0
- package/dist/commands/jobs/watch.js +269 -0
- package/dist/commands/jobs/watch.js.map +1 -0
- package/dist/commands/login.d.ts +25 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +165 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/profile/delete.d.ts +22 -0
- package/dist/commands/profile/delete.d.ts.map +1 -0
- package/dist/commands/profile/delete.js +57 -0
- package/dist/commands/profile/delete.js.map +1 -0
- package/dist/commands/profile/list.d.ts +19 -0
- package/dist/commands/profile/list.d.ts.map +1 -0
- package/dist/commands/profile/list.js +53 -0
- package/dist/commands/profile/list.js.map +1 -0
- package/dist/commands/profile/use.d.ts +22 -0
- package/dist/commands/profile/use.d.ts.map +1 -0
- package/dist/commands/profile/use.js +46 -0
- package/dist/commands/profile/use.js.map +1 -0
- package/dist/config/fs-utils.d.ts +14 -0
- package/dist/config/fs-utils.d.ts.map +1 -0
- package/dist/config/fs-utils.js +31 -0
- package/dist/config/fs-utils.js.map +1 -0
- package/dist/config/keychain.d.ts +53 -0
- package/dist/config/keychain.d.ts.map +1 -0
- package/dist/config/keychain.js +175 -0
- package/dist/config/keychain.js.map +1 -0
- package/dist/config/profile-store.d.ts +85 -0
- package/dist/config/profile-store.d.ts.map +1 -0
- package/dist/config/profile-store.js +228 -0
- package/dist/config/profile-store.js.map +1 -0
- package/dist/config/settings.d.ts +71 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +151 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/core/abilities-executor.d.ts +126 -0
- package/dist/core/abilities-executor.d.ts.map +1 -0
- package/dist/core/abilities-executor.js +264 -0
- package/dist/core/abilities-executor.js.map +1 -0
- package/dist/core/batch-manager.d.ts +113 -0
- package/dist/core/batch-manager.d.ts.map +1 -0
- package/dist/core/batch-manager.js +244 -0
- package/dist/core/batch-manager.js.map +1 -0
- package/dist/core/http-client.d.ts +111 -0
- package/dist/core/http-client.d.ts.map +1 -0
- package/dist/core/http-client.js +329 -0
- package/dist/core/http-client.js.map +1 -0
- package/dist/core/safety-controller.d.ts +114 -0
- package/dist/core/safety-controller.d.ts.map +1 -0
- package/dist/core/safety-controller.js +229 -0
- package/dist/core/safety-controller.js.map +1 -0
- package/dist/hooks/command-not-found.d.ts +12 -0
- package/dist/hooks/command-not-found.d.ts.map +1 -0
- package/dist/hooks/command-not-found.js +58 -0
- package/dist/hooks/command-not-found.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/base-command.d.ts +123 -0
- package/dist/lib/base-command.d.ts.map +1 -0
- package/dist/lib/base-command.js +285 -0
- package/dist/lib/base-command.js.map +1 -0
- package/dist/output/formatter.d.ts +48 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +138 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/json-envelope.d.ts +43 -0
- package/dist/output/json-envelope.d.ts.map +1 -0
- package/dist/output/json-envelope.js +73 -0
- package/dist/output/json-envelope.js.map +1 -0
- package/dist/utils/audit-logger.d.ts +97 -0
- package/dist/utils/audit-logger.d.ts.map +1 -0
- package/dist/utils/audit-logger.js +169 -0
- package/dist/utils/audit-logger.js.map +1 -0
- package/dist/utils/colors.d.ts +29 -0
- package/dist/utils/colors.d.ts.map +1 -0
- package/dist/utils/colors.js +36 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/errors.d.ts +107 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +149 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/exit-codes.d.ts +21 -0
- package/dist/utils/exit-codes.d.ts.map +1 -0
- package/dist/utils/exit-codes.js +20 -0
- package/dist/utils/exit-codes.js.map +1 -0
- package/dist/utils/format.d.ts +64 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +69 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/prompt.d.ts +34 -0
- package/dist/utils/prompt.d.ts.map +1 -0
- package/dist/utils/prompt.js +132 -0
- package/dist/utils/prompt.js.map +1 -0
- package/dist/utils/retry.d.ts +59 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +96 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/terminal-sanitizer.d.ts +60 -0
- package/dist/utils/terminal-sanitizer.d.ts.map +1 -0
- package/dist/utils/terminal-sanitizer.js +166 -0
- package/dist/utils/terminal-sanitizer.js.map +1 -0
- package/dist/validation/input-sanitizer.d.ts +76 -0
- package/dist/validation/input-sanitizer.d.ts.map +1 -0
- package/dist/validation/input-sanitizer.js +199 -0
- package/dist/validation/input-sanitizer.js.map +1 -0
- package/dist/validation/schema-validator.d.ts +75 -0
- package/dist/validation/schema-validator.d.ts.map +1 -0
- package/dist/validation/schema-validator.js +147 -0
- package/dist/validation/schema-validator.js.map +1 -0
- package/oclif.manifest.json +857 -0
- package/package.json +101 -0
- package/scripts/completions/README.md +221 -0
- package/scripts/completions/mainwpcontrol.bash +193 -0
- package/scripts/completions/mainwpcontrol.zsh +267 -0
- package/scripts/completions/profile-completer.sh +35 -0
- package/scripts/completions/regenerate.sh +78 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat Engine for mainwpcontrol
|
|
3
|
+
*
|
|
4
|
+
* LLM interaction loop with safety enforcement.
|
|
5
|
+
*
|
|
6
|
+
* CRITICAL INVARIANTS (from PLAN.md, CHAT_PROMPT.md):
|
|
7
|
+
* - AI proposes tool calls; ChatEngine executes via AbilitiesExecutor
|
|
8
|
+
* - AI NEVER executes directly
|
|
9
|
+
* - Destructive actions always preview first
|
|
10
|
+
* - Max tool calls per turn enforced
|
|
11
|
+
* - JSON retry logic (max 2 retries)
|
|
12
|
+
*/
|
|
13
|
+
import { buildConfiguredPrompt, defaultConfig as defaultPromptConfig, } from './system-prompt.js';
|
|
14
|
+
import { parseResponse, isRetryable, buildRetryPrompt, } from './tool-envelope.js';
|
|
15
|
+
import { SafetyController, } from '../core/safety-controller.js';
|
|
16
|
+
import { abilityToTool } from './providers/provider.js';
|
|
17
|
+
import { logDestructiveActionSafe } from '../utils/audit-logger.js';
|
|
18
|
+
import { getInputSanitizer } from '../validation/input-sanitizer.js';
|
|
19
|
+
/**
|
|
20
|
+
* Chat engine class
|
|
21
|
+
*
|
|
22
|
+
* SAFETY: All execution flows through SafetyController and AbilitiesExecutor.
|
|
23
|
+
* ChatEngine never bypasses safety checks.
|
|
24
|
+
*
|
|
25
|
+
* Context window management: The engine maintains a sliding window of messages
|
|
26
|
+
* to prevent unbounded memory growth. The system prompt is always preserved,
|
|
27
|
+
* and message coherence (user-assistant pairs, tool call-result pairs) is maintained.
|
|
28
|
+
*/
|
|
29
|
+
export class ChatEngine {
|
|
30
|
+
provider;
|
|
31
|
+
executor;
|
|
32
|
+
safetyController;
|
|
33
|
+
maxToolCallsPerTurn;
|
|
34
|
+
maxParseRetries;
|
|
35
|
+
model;
|
|
36
|
+
temperature;
|
|
37
|
+
promptConfig;
|
|
38
|
+
maxContextMessages;
|
|
39
|
+
stream;
|
|
40
|
+
onStreamChunk;
|
|
41
|
+
messages = [];
|
|
42
|
+
abilities = [];
|
|
43
|
+
tools = [];
|
|
44
|
+
pendingPreview = null;
|
|
45
|
+
initialized = false;
|
|
46
|
+
constructor(options) {
|
|
47
|
+
this.provider = options.provider;
|
|
48
|
+
this.executor = options.executor;
|
|
49
|
+
this.safetyController = new SafetyController();
|
|
50
|
+
this.maxToolCallsPerTurn = options.maxToolCallsPerTurn ?? 3;
|
|
51
|
+
this.maxParseRetries = options.maxParseRetries ?? 2;
|
|
52
|
+
this.model = options.model;
|
|
53
|
+
this.temperature = options.temperature;
|
|
54
|
+
this.stream = options.stream ?? false;
|
|
55
|
+
// Only assign if defined to satisfy exactOptionalPropertyTypes
|
|
56
|
+
if (options.onStreamChunk !== undefined) {
|
|
57
|
+
this.onStreamChunk = options.onStreamChunk;
|
|
58
|
+
}
|
|
59
|
+
// Build prompt config, handling optional properties correctly
|
|
60
|
+
const mergedPromptConfig = {
|
|
61
|
+
...defaultPromptConfig,
|
|
62
|
+
...options.promptConfig,
|
|
63
|
+
maxToolCalls: options.maxToolCallsPerTurn ?? defaultPromptConfig.maxToolCalls,
|
|
64
|
+
maxParseRetries: options.maxParseRetries ?? defaultPromptConfig.maxParseRetries,
|
|
65
|
+
};
|
|
66
|
+
// Context window configuration: resolve from options, promptConfig, or default
|
|
67
|
+
// This ensures the default limit (20) is applied unless explicitly overridden
|
|
68
|
+
const resolvedContextMessages = options.maxContextMessages ??
|
|
69
|
+
options.promptConfig?.maxContextMessages ??
|
|
70
|
+
defaultPromptConfig.maxContextMessages;
|
|
71
|
+
this.maxContextMessages = resolvedContextMessages;
|
|
72
|
+
// Sync the resolved value into promptConfig for system prompt generation
|
|
73
|
+
if (resolvedContextMessages !== undefined) {
|
|
74
|
+
mergedPromptConfig.maxContextMessages = resolvedContextMessages;
|
|
75
|
+
}
|
|
76
|
+
// Handle optional token limit (reserved for future use)
|
|
77
|
+
const contextTokens = options.maxContextTokens ?? options.promptConfig?.maxContextTokens;
|
|
78
|
+
if (contextTokens !== undefined) {
|
|
79
|
+
mergedPromptConfig.maxContextTokens = contextTokens;
|
|
80
|
+
}
|
|
81
|
+
this.promptConfig = mergedPromptConfig;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Initialize the chat session
|
|
85
|
+
*/
|
|
86
|
+
async initialize() {
|
|
87
|
+
if (this.initialized)
|
|
88
|
+
return;
|
|
89
|
+
// Load abilities
|
|
90
|
+
this.abilities = await this.executor.listAbilities();
|
|
91
|
+
// Convert to tool definitions
|
|
92
|
+
this.tools = this.abilities.map((a) => abilityToTool(a.name, a.description, a.input_schema));
|
|
93
|
+
// Build system prompt
|
|
94
|
+
const systemPrompt = buildConfiguredPrompt(this.abilities, this.promptConfig);
|
|
95
|
+
// Initialize message history
|
|
96
|
+
this.messages = [{ role: 'system', content: systemPrompt }];
|
|
97
|
+
this.initialized = true;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Send a user message and process the response
|
|
101
|
+
*/
|
|
102
|
+
async sendMessage(userMessage) {
|
|
103
|
+
if (!this.initialized) {
|
|
104
|
+
await this.initialize();
|
|
105
|
+
}
|
|
106
|
+
// Handle pending preview approval
|
|
107
|
+
if (this.pendingPreview) {
|
|
108
|
+
return this.handlePreviewResponse(userMessage);
|
|
109
|
+
}
|
|
110
|
+
// Add user message
|
|
111
|
+
this.messages.push({ role: 'user', content: userMessage });
|
|
112
|
+
// Truncate BEFORE LLM call to ensure the LLM sees a bounded context
|
|
113
|
+
// This prevents sending unbounded history to the provider
|
|
114
|
+
this.truncateHistory();
|
|
115
|
+
// Process with LLM
|
|
116
|
+
const responses = await this.processLLMResponse();
|
|
117
|
+
// Truncate again after processing for storage (handles messages added during tool calling)
|
|
118
|
+
this.truncateHistory();
|
|
119
|
+
return responses;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Handle response to a pending preview
|
|
123
|
+
*/
|
|
124
|
+
async handlePreviewResponse(userMessage) {
|
|
125
|
+
const preview = this.pendingPreview;
|
|
126
|
+
this.pendingPreview = null;
|
|
127
|
+
const lower = userMessage.toLowerCase().trim();
|
|
128
|
+
const approved = lower === 'yes' ||
|
|
129
|
+
lower === 'y' ||
|
|
130
|
+
lower === 'approve' ||
|
|
131
|
+
lower === 'confirm';
|
|
132
|
+
if (!approved) {
|
|
133
|
+
// User declined
|
|
134
|
+
this.messages.push({
|
|
135
|
+
role: 'user',
|
|
136
|
+
content: userMessage,
|
|
137
|
+
});
|
|
138
|
+
this.messages.push({
|
|
139
|
+
role: 'assistant',
|
|
140
|
+
content: JSON.stringify({
|
|
141
|
+
answer: 'Operation cancelled. The destructive action was not executed.',
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
// Log audit entry for declined action (fire-and-forget)
|
|
145
|
+
await logDestructiveActionSafe({
|
|
146
|
+
abilityName: preview.ability.name,
|
|
147
|
+
preview: {
|
|
148
|
+
summary: preview.preview.summary,
|
|
149
|
+
affectedCount: preview.preview.affected.length,
|
|
150
|
+
},
|
|
151
|
+
userDecision: 'declined',
|
|
152
|
+
input: preview.input,
|
|
153
|
+
});
|
|
154
|
+
// Truncate after preview resolution (safe boundary)
|
|
155
|
+
this.truncateHistory();
|
|
156
|
+
return [
|
|
157
|
+
{
|
|
158
|
+
type: 'message',
|
|
159
|
+
content: 'Operation cancelled. The destructive action was not executed.',
|
|
160
|
+
},
|
|
161
|
+
];
|
|
162
|
+
}
|
|
163
|
+
// User approved - execute with confirm
|
|
164
|
+
this.messages.push({
|
|
165
|
+
role: 'user',
|
|
166
|
+
content: 'User approved: yes',
|
|
167
|
+
});
|
|
168
|
+
const result = await this.executor.execute(preview.ability.name, preview.input, { confirm: true });
|
|
169
|
+
// Log audit entry for approved and executed action (fire-and-forget)
|
|
170
|
+
const executionAudit = {
|
|
171
|
+
success: result.success,
|
|
172
|
+
};
|
|
173
|
+
if (result.error?.message) {
|
|
174
|
+
executionAudit.error = getInputSanitizer().sanitizeErrorMessage(result.error.message);
|
|
175
|
+
}
|
|
176
|
+
await logDestructiveActionSafe({
|
|
177
|
+
abilityName: preview.ability.name,
|
|
178
|
+
preview: {
|
|
179
|
+
summary: preview.preview.summary,
|
|
180
|
+
affectedCount: preview.preview.affected.length,
|
|
181
|
+
},
|
|
182
|
+
userDecision: 'approved',
|
|
183
|
+
execution: executionAudit,
|
|
184
|
+
input: preview.input,
|
|
185
|
+
});
|
|
186
|
+
// Add result to context
|
|
187
|
+
const toolResultMsg = {
|
|
188
|
+
role: 'tool',
|
|
189
|
+
content: JSON.stringify(result),
|
|
190
|
+
toolCallId: `execute_${preview.ability.name}`,
|
|
191
|
+
toolName: preview.ability.name,
|
|
192
|
+
};
|
|
193
|
+
this.messages.push(toolResultMsg);
|
|
194
|
+
// Truncate after preview resolution (safe boundary)
|
|
195
|
+
this.truncateHistory();
|
|
196
|
+
return [
|
|
197
|
+
{
|
|
198
|
+
type: 'tool_result',
|
|
199
|
+
tool: preview.ability.name,
|
|
200
|
+
result,
|
|
201
|
+
preview: preview.preview,
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Process LLM response with tool calling loop
|
|
207
|
+
*/
|
|
208
|
+
async processLLMResponse() {
|
|
209
|
+
const responses = [];
|
|
210
|
+
let toolCallCount = 0;
|
|
211
|
+
let retryCount = 0;
|
|
212
|
+
while (toolCallCount < this.maxToolCallsPerTurn) {
|
|
213
|
+
// Call LLM
|
|
214
|
+
const chatOptions = {
|
|
215
|
+
model: this.model,
|
|
216
|
+
temperature: this.temperature,
|
|
217
|
+
tools: this.tools,
|
|
218
|
+
};
|
|
219
|
+
// Get LLM response (streaming or non-streaming)
|
|
220
|
+
let llmResponse;
|
|
221
|
+
if (this.stream && this.provider.chatStream && this.provider.capabilities.streaming) {
|
|
222
|
+
const stream = this.provider.chatStream(this.messages, chatOptions);
|
|
223
|
+
llmResponse = await this.accumulateStream(stream);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
llmResponse = await this.provider.chat(this.messages, chatOptions);
|
|
227
|
+
}
|
|
228
|
+
// Don't process tool calls from interrupted streams — arguments may be incomplete
|
|
229
|
+
if (llmResponse.finishReason === 'error') {
|
|
230
|
+
responses.push({
|
|
231
|
+
type: 'error',
|
|
232
|
+
error: 'Response interrupted — please try again',
|
|
233
|
+
});
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
// Parse response
|
|
237
|
+
const parseResult = parseResponse(llmResponse, {
|
|
238
|
+
abilities: this.abilities,
|
|
239
|
+
validateToolExists: true,
|
|
240
|
+
});
|
|
241
|
+
// Handle parse errors with retry
|
|
242
|
+
if (parseResult.response.type === 'error') {
|
|
243
|
+
if (isRetryable(parseResult) && retryCount < this.maxParseRetries) {
|
|
244
|
+
retryCount++;
|
|
245
|
+
// Add retry prompt
|
|
246
|
+
this.messages.push({
|
|
247
|
+
role: 'assistant',
|
|
248
|
+
content: llmResponse.content,
|
|
249
|
+
});
|
|
250
|
+
this.messages.push({
|
|
251
|
+
role: 'user',
|
|
252
|
+
content: buildRetryPrompt(parseResult),
|
|
253
|
+
});
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
// Unrecoverable error
|
|
257
|
+
responses.push({
|
|
258
|
+
type: 'error',
|
|
259
|
+
error: parseResult.response.error,
|
|
260
|
+
});
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
retryCount = 0; // Reset on successful parse
|
|
264
|
+
// Handle answer
|
|
265
|
+
if (parseResult.response.type === 'answer') {
|
|
266
|
+
this.messages.push({
|
|
267
|
+
role: 'assistant',
|
|
268
|
+
content: llmResponse.content,
|
|
269
|
+
});
|
|
270
|
+
responses.push({
|
|
271
|
+
type: 'message',
|
|
272
|
+
content: parseResult.response.answer,
|
|
273
|
+
});
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
// Handle tool call
|
|
277
|
+
const toolResponse = parseResult.response;
|
|
278
|
+
toolCallCount++;
|
|
279
|
+
// Add assistant message with tool call
|
|
280
|
+
this.messages.push({
|
|
281
|
+
role: 'assistant',
|
|
282
|
+
content: llmResponse.content,
|
|
283
|
+
});
|
|
284
|
+
// Execute tool
|
|
285
|
+
const toolResult = await this.executeTool(toolResponse.tool, toolResponse.input);
|
|
286
|
+
if (toolResult.type === 'preview') {
|
|
287
|
+
// Preview requires user approval - stop here
|
|
288
|
+
responses.push(toolResult);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
responses.push(toolResult);
|
|
292
|
+
// Add tool result to context
|
|
293
|
+
if (toolResult.type === 'tool_result') {
|
|
294
|
+
const resultContent = toolResult.result.success
|
|
295
|
+
? JSON.stringify(toolResult.result.data)
|
|
296
|
+
: JSON.stringify(toolResult.result.error);
|
|
297
|
+
this.messages.push({
|
|
298
|
+
role: 'tool',
|
|
299
|
+
content: resultContent,
|
|
300
|
+
toolCallId: toolResponse.id ?? `call_${toolCallCount}`,
|
|
301
|
+
toolName: toolResponse.tool,
|
|
302
|
+
});
|
|
303
|
+
// Truncate between tool-call iterations to enforce context limit
|
|
304
|
+
// This ensures each provider.chat call receives a bounded history
|
|
305
|
+
// Note: truncateHistory() already skips when pendingPreview is set
|
|
306
|
+
this.truncateHistory();
|
|
307
|
+
}
|
|
308
|
+
else if (toolResult.type === 'error') {
|
|
309
|
+
this.messages.push({
|
|
310
|
+
role: 'tool',
|
|
311
|
+
content: JSON.stringify({ error: toolResult.error }),
|
|
312
|
+
toolCallId: toolResponse.id ?? `call_${toolCallCount}`,
|
|
313
|
+
toolName: toolResponse.tool,
|
|
314
|
+
});
|
|
315
|
+
break; // Stop on error
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
// If we hit max tool calls, add a notice
|
|
319
|
+
if (toolCallCount >= this.maxToolCallsPerTurn) {
|
|
320
|
+
responses.push({
|
|
321
|
+
type: 'message',
|
|
322
|
+
content: `Reached maximum tool calls (${this.maxToolCallsPerTurn}). Please continue if needed.`,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return responses;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Execute a tool with safety checks
|
|
329
|
+
*
|
|
330
|
+
* CRITICAL: All execution goes through SafetyController
|
|
331
|
+
*/
|
|
332
|
+
async executeTool(toolName, input) {
|
|
333
|
+
// Find ability
|
|
334
|
+
const ability = await this.executor.getAbility(toolName);
|
|
335
|
+
if (!ability) {
|
|
336
|
+
return {
|
|
337
|
+
type: 'error',
|
|
338
|
+
error: `Unknown ability: ${toolName}`,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
// Check if destructive
|
|
342
|
+
const classification = this.safetyController.classify(ability);
|
|
343
|
+
if (classification.requiresSafetyFlow) {
|
|
344
|
+
// SAFETY: Destructive actions always preview first
|
|
345
|
+
// AI cannot skip this step
|
|
346
|
+
return this.executeWithPreview(ability, input);
|
|
347
|
+
}
|
|
348
|
+
// Safe to execute directly
|
|
349
|
+
try {
|
|
350
|
+
const result = await this.executor.execute(ability.name, input);
|
|
351
|
+
return {
|
|
352
|
+
type: 'tool_result',
|
|
353
|
+
tool: ability.name,
|
|
354
|
+
result,
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
return {
|
|
359
|
+
type: 'error',
|
|
360
|
+
error: error instanceof Error ? error.message : String(error),
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Execute destructive action with preview
|
|
366
|
+
*/
|
|
367
|
+
async executeWithPreview(ability, input) {
|
|
368
|
+
try {
|
|
369
|
+
// Execute with dry_run
|
|
370
|
+
const previewResult = await this.executor.execute(ability.name, input, { dryRun: true });
|
|
371
|
+
if (!previewResult.success) {
|
|
372
|
+
return {
|
|
373
|
+
type: 'error',
|
|
374
|
+
error: previewResult.error?.message ?? 'Preview failed',
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
// Format preview
|
|
378
|
+
const preview = this.safetyController.formatPreviewResult(ability, input, previewResult);
|
|
379
|
+
// Store pending preview for approval
|
|
380
|
+
this.pendingPreview = { ability, input, preview };
|
|
381
|
+
return {
|
|
382
|
+
type: 'preview',
|
|
383
|
+
preview,
|
|
384
|
+
requiresApproval: true,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
catch (error) {
|
|
388
|
+
return {
|
|
389
|
+
type: 'error',
|
|
390
|
+
error: error instanceof Error ? error.message : String(error),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Accumulate streaming chunks into a complete LLM response.
|
|
396
|
+
* This method consumes an AsyncGenerator<StreamChunk> and reconstructs
|
|
397
|
+
* a complete LLMResponse compatible with the existing parseResponse() logic.
|
|
398
|
+
*
|
|
399
|
+
* @param stream - The streaming generator from the provider
|
|
400
|
+
* @returns A complete LLMResponse with accumulated content and tool calls
|
|
401
|
+
*/
|
|
402
|
+
async accumulateStream(stream) {
|
|
403
|
+
let content = '';
|
|
404
|
+
// Providers yield complete tool calls (not deltas), so we collect them directly
|
|
405
|
+
const toolCalls = [];
|
|
406
|
+
try {
|
|
407
|
+
for await (const chunk of stream) {
|
|
408
|
+
// Handle content chunks
|
|
409
|
+
if (chunk.content) {
|
|
410
|
+
content += chunk.content;
|
|
411
|
+
// Call callback for progressive display
|
|
412
|
+
if (this.onStreamChunk) {
|
|
413
|
+
this.onStreamChunk(chunk.content);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
// Handle tool call chunks - providers yield each complete tool call as a separate chunk
|
|
417
|
+
// before the done chunk, so push each one immediately
|
|
418
|
+
if (chunk.toolCall && chunk.toolCall.id && chunk.toolCall.name) {
|
|
419
|
+
toolCalls.push({
|
|
420
|
+
id: chunk.toolCall.id,
|
|
421
|
+
name: chunk.toolCall.name,
|
|
422
|
+
arguments: chunk.toolCall.arguments ?? {},
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
// When done flag is set, we've collected all tool calls
|
|
426
|
+
if (chunk.done) {
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
// If streaming fails mid-response, return what we have so far
|
|
433
|
+
if (content || toolCalls.length > 0) {
|
|
434
|
+
console.error(`[ChatEngine] Stream interrupted: ${error instanceof Error ? error.message : String(error)}`);
|
|
435
|
+
return {
|
|
436
|
+
content,
|
|
437
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
438
|
+
finishReason: 'error',
|
|
439
|
+
model: this.provider.getDefaultModel(),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
// If no content accumulated, re-throw
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
// Return accumulated LLMResponse
|
|
446
|
+
const parsedToolCalls = toolCalls;
|
|
447
|
+
return {
|
|
448
|
+
content,
|
|
449
|
+
toolCalls: parsedToolCalls.length > 0 ? parsedToolCalls : undefined,
|
|
450
|
+
finishReason: parsedToolCalls.length > 0 ? 'tool_calls' : 'stop',
|
|
451
|
+
model: this.provider.getDefaultModel(),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Check if there's a pending preview awaiting approval
|
|
456
|
+
*/
|
|
457
|
+
hasPendingPreview() {
|
|
458
|
+
return this.pendingPreview !== null;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Get the pending preview
|
|
462
|
+
*/
|
|
463
|
+
getPendingPreview() {
|
|
464
|
+
return this.pendingPreview?.preview ?? null;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Cancel pending preview
|
|
468
|
+
*/
|
|
469
|
+
cancelPendingPreview() {
|
|
470
|
+
this.pendingPreview = null;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Get conversation history (for debugging)
|
|
474
|
+
*/
|
|
475
|
+
getHistory() {
|
|
476
|
+
return [...this.messages];
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Clear conversation history (keep system prompt)
|
|
480
|
+
*/
|
|
481
|
+
clearHistory() {
|
|
482
|
+
if (this.messages.length > 0) {
|
|
483
|
+
const systemPrompt = this.messages[0];
|
|
484
|
+
if (systemPrompt) {
|
|
485
|
+
this.messages = [systemPrompt];
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
this.pendingPreview = null;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Get message count (excluding system prompt)
|
|
492
|
+
*/
|
|
493
|
+
getMessageCount() {
|
|
494
|
+
return this.messages.length - 1;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Estimate tokens for a set of messages using character count as a rough proxy.
|
|
498
|
+
* Uses character_count / 4 as a heuristic (common approximation for English text).
|
|
499
|
+
*
|
|
500
|
+
* NOTE: This is a rough estimate. Actual token counts from LLMResponse.usage
|
|
501
|
+
* are more accurate when available.
|
|
502
|
+
*
|
|
503
|
+
* @param messages - Messages to estimate tokens for
|
|
504
|
+
* @returns Estimated token count
|
|
505
|
+
*/
|
|
506
|
+
estimateTokens(messages) {
|
|
507
|
+
let totalChars = 0;
|
|
508
|
+
for (const msg of messages) {
|
|
509
|
+
if (typeof msg.content === 'string') {
|
|
510
|
+
totalChars += msg.content.length;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
// Character count / 4 is a common heuristic for English text tokenization
|
|
514
|
+
return Math.ceil(totalChars / 4);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Check if context truncation should occur based on message count limits.
|
|
518
|
+
* Token-based limits are reserved for future implementation.
|
|
519
|
+
*
|
|
520
|
+
* @returns true if truncation should occur, false if:
|
|
521
|
+
* - maxContextMessages is undefined (no limit)
|
|
522
|
+
* - maxContextMessages is 0 (explicit unlimited)
|
|
523
|
+
* - message count is within limit
|
|
524
|
+
*/
|
|
525
|
+
shouldTruncate() {
|
|
526
|
+
if (this.maxContextMessages === undefined || this.maxContextMessages === 0) {
|
|
527
|
+
return false; // No limit configured or explicitly unlimited
|
|
528
|
+
}
|
|
529
|
+
return this.getMessageCount() > this.maxContextMessages;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Find the index where truncation should start, respecting message boundaries.
|
|
533
|
+
* This ensures we keep complete user-assistant exchanges and tool call-result pairs.
|
|
534
|
+
*
|
|
535
|
+
* @returns Index in the messages array where truncation should start (exclusive of system prompt)
|
|
536
|
+
*/
|
|
537
|
+
findTruncationPoint() {
|
|
538
|
+
if (this.maxContextMessages === undefined || this.maxContextMessages <= 0) {
|
|
539
|
+
return 1; // Keep only system prompt
|
|
540
|
+
}
|
|
541
|
+
// Calculate how many messages to keep (plus 1 for system prompt)
|
|
542
|
+
const targetLength = this.maxContextMessages + 1;
|
|
543
|
+
if (this.messages.length <= targetLength) {
|
|
544
|
+
return this.messages.length; // No truncation needed
|
|
545
|
+
}
|
|
546
|
+
// Start from where we'd ideally cut
|
|
547
|
+
const idealTruncationIndex = this.messages.length - this.maxContextMessages;
|
|
548
|
+
// Ensure we don't cut the system prompt
|
|
549
|
+
let truncationIndex = Math.max(1, idealTruncationIndex);
|
|
550
|
+
// Walk forward to find a safe boundary (start of a user message)
|
|
551
|
+
// This ensures we don't split:
|
|
552
|
+
// - user message + assistant response
|
|
553
|
+
// - tool call + tool result
|
|
554
|
+
// - retry prompts from their original failed attempt
|
|
555
|
+
const maxSearchIndex = this.messages.length;
|
|
556
|
+
while (truncationIndex < maxSearchIndex) {
|
|
557
|
+
const msg = this.messages[truncationIndex];
|
|
558
|
+
// Safe to cut at the start of a user message
|
|
559
|
+
if (msg && msg.role === 'user') {
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
truncationIndex++;
|
|
563
|
+
}
|
|
564
|
+
// Fallback: if no user boundary found, keep at least maxContextMessages
|
|
565
|
+
// This ensures we don't drop all messages when the limit is very small
|
|
566
|
+
if (truncationIndex >= this.messages.length) {
|
|
567
|
+
truncationIndex = Math.max(1, idealTruncationIndex);
|
|
568
|
+
}
|
|
569
|
+
return truncationIndex;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Truncate message history using a sliding window approach.
|
|
573
|
+
* Preserves:
|
|
574
|
+
* - System prompt (always first message)
|
|
575
|
+
* - Messages since pending preview (if any)
|
|
576
|
+
* - Most recent N messages where N = maxContextMessages
|
|
577
|
+
* - Complete message exchanges (user-assistant, tool call-result pairs)
|
|
578
|
+
*/
|
|
579
|
+
truncateHistory() {
|
|
580
|
+
if (!this.shouldTruncate()) {
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
// Safety: Never truncate if there's a pending preview
|
|
584
|
+
// This preserves context for the approval decision
|
|
585
|
+
if (this.pendingPreview !== null) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const systemPrompt = this.messages[0];
|
|
589
|
+
if (!systemPrompt) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
const truncationIndex = this.findTruncationPoint();
|
|
593
|
+
const messagesBefore = this.messages.length;
|
|
594
|
+
// Keep system prompt + messages from truncation point onwards
|
|
595
|
+
this.messages = [systemPrompt, ...this.messages.slice(truncationIndex)];
|
|
596
|
+
// Debug logging (only if significant truncation occurred)
|
|
597
|
+
const messagesRemoved = messagesBefore - this.messages.length;
|
|
598
|
+
if (messagesRemoved > 0 && process.env['DEBUG']) {
|
|
599
|
+
console.debug(`[ChatEngine] Truncated ${messagesRemoved} messages (${messagesBefore - 1} -> ${this.messages.length - 1})`);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Get context window statistics for monitoring.
|
|
604
|
+
*
|
|
605
|
+
* @returns Object with current message count, max limit, and estimated tokens
|
|
606
|
+
*/
|
|
607
|
+
getContextStats() {
|
|
608
|
+
return {
|
|
609
|
+
messageCount: this.getMessageCount(),
|
|
610
|
+
maxMessages: this.maxContextMessages,
|
|
611
|
+
estimatedTokens: this.estimateTokens(this.messages),
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Get loaded abilities
|
|
616
|
+
*/
|
|
617
|
+
getAbilities() {
|
|
618
|
+
return [...this.abilities];
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Get provider info
|
|
622
|
+
*/
|
|
623
|
+
getProviderInfo() {
|
|
624
|
+
return {
|
|
625
|
+
name: this.provider.name,
|
|
626
|
+
model: this.model ?? this.provider.getDefaultModel(),
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Create a chat engine
|
|
632
|
+
*/
|
|
633
|
+
export function createChatEngine(options) {
|
|
634
|
+
return new ChatEngine(options);
|
|
635
|
+
}
|
|
636
|
+
//# sourceMappingURL=chat-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-engine.js","sourceRoot":"","sources":["../../src/chat/chat-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,OAAO,EACL,qBAAqB,EAErB,aAAa,IAAI,mBAAmB,GACrC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAM5B,OAAO,EACL,gBAAgB,GAEjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAqDrE;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACJ,QAAQ,CAAc;IACtB,QAAQ,CAAoB;IAC5B,gBAAgB,CAAmB;IACnC,mBAAmB,CAAS;IAC5B,eAAe,CAAS;IACxB,KAAK,CAAqB;IAC1B,WAAW,CAAqB;IAChC,YAAY,CAAqB;IACjC,kBAAkB,CAAqB;IACvC,MAAM,CAAU;IAChB,aAAa,CAA6B;IAEnD,QAAQ,GAAc,EAAE,CAAC;IACzB,SAAS,GAAc,EAAE,CAAC;IAC1B,KAAK,GAAqB,EAAE,CAAC;IAC7B,cAAc,GAA0B,IAAI,CAAC;IAC7C,WAAW,GAAG,KAAK,CAAC;IAE5B,YAAY,OAA0B;QACpC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,gBAAgB,GAAG,IAAI,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G,CAAC,YAAY,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;QAExE,0DAA0D;QAC1D,MAAM,eAAe,GAAG,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC9D,IAAI,eAAe,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,KAAK,CACX,0BAA0B,eAAe,cAAc,cAAc,GAAG,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,GAAG,CAC5G,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,eAAe;QAKb,OAAO;YACL,YAAY,EAAE,IAAI,CAAC,eAAe,EAAE;YACpC,WAAW,EAAE,IAAI,CAAC,kBAAkB;YACpC,eAAe,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC;SACpD,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;YACxB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE;SACrD,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IACzD,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat Module Index
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all chat components.
|
|
5
|
+
*/
|
|
6
|
+
export * from './system-prompt.js';
|
|
7
|
+
export * from './tool-envelope.js';
|
|
8
|
+
export * from './chat-engine.js';
|
|
9
|
+
export * from './providers/index.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chat/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,oBAAoB,CAAC;AAGnC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,sBAAsB,CAAC"}
|