@gaunt-sloth/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gsloth.backstory.md +17 -0
- package/.gsloth.chat.md +11 -0
- package/.gsloth.code.md +27 -0
- package/.gsloth.guidelines.md +1 -0
- package/.gsloth.review.md +15 -0
- package/.gsloth.system.md +10 -0
- package/README.md +27 -0
- package/dist/config.d.ts +533 -0
- package/dist/config.js +412 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +13 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/GthAgentRunner.d.ts +27 -0
- package/dist/core/GthAgentRunner.js +109 -0
- package/dist/core/GthAgentRunner.js.map +1 -0
- package/dist/core/GthLangChainAgent.d.ts +56 -0
- package/dist/core/GthLangChainAgent.js +355 -0
- package/dist/core/GthLangChainAgent.js.map +1 -0
- package/dist/core/types.d.ts +39 -0
- package/dist/core/types.js +16 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/anthropic.d.ts +7 -0
- package/dist/providers/anthropic.js +34 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/deepseek.d.ts +4 -0
- package/dist/providers/deepseek.js +30 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/providers/fake.d.ts +3 -0
- package/dist/providers/fake.js +12 -0
- package/dist/providers/fake.js.map +1 -0
- package/dist/providers/google-genai.d.ts +7 -0
- package/dist/providers/google-genai.js +34 -0
- package/dist/providers/google-genai.js.map +1 -0
- package/dist/providers/groq.d.ts +4 -0
- package/dist/providers/groq.js +30 -0
- package/dist/providers/groq.js.map +1 -0
- package/dist/providers/openai.d.ts +5 -0
- package/dist/providers/openai.js +46 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openrouter.d.ts +5 -0
- package/dist/providers/openrouter.js +57 -0
- package/dist/providers/openrouter.js.map +1 -0
- package/dist/providers/vertexai.d.ts +7 -0
- package/dist/providers/vertexai.js +41 -0
- package/dist/providers/vertexai.js.map +1 -0
- package/dist/providers/xai.d.ts +4 -0
- package/dist/providers/xai.js +30 -0
- package/dist/providers/xai.js.map +1 -0
- package/dist/state/artifactStore.d.ts +21 -0
- package/dist/state/artifactStore.js +30 -0
- package/dist/state/artifactStore.js.map +1 -0
- package/dist/utils/ProgressIndicator.d.ts +7 -0
- package/dist/utils/ProgressIndicator.js +26 -0
- package/dist/utils/ProgressIndicator.js.map +1 -0
- package/dist/utils/aiignoreUtils.d.ts +29 -0
- package/dist/utils/aiignoreUtils.js +82 -0
- package/dist/utils/aiignoreUtils.js.map +1 -0
- package/dist/utils/binaryOutputUtils.d.ts +13 -0
- package/dist/utils/binaryOutputUtils.js +138 -0
- package/dist/utils/binaryOutputUtils.js.map +1 -0
- package/dist/utils/consoleUtils.d.ts +76 -0
- package/dist/utils/consoleUtils.js +230 -0
- package/dist/utils/consoleUtils.js.map +1 -0
- package/dist/utils/debugUtils.d.ts +20 -0
- package/dist/utils/debugUtils.js +89 -0
- package/dist/utils/debugUtils.js.map +1 -0
- package/dist/utils/fileUtils.d.ts +68 -0
- package/dist/utils/fileUtils.js +216 -0
- package/dist/utils/fileUtils.js.map +1 -0
- package/dist/utils/globalConfigUtils.d.ts +28 -0
- package/dist/utils/globalConfigUtils.js +61 -0
- package/dist/utils/globalConfigUtils.js.map +1 -0
- package/dist/utils/llmUtils.d.ts +39 -0
- package/dist/utils/llmUtils.js +153 -0
- package/dist/utils/llmUtils.js.map +1 -0
- package/dist/utils/stringUtils.d.ts +4 -0
- package/dist/utils/stringUtils.js +10 -0
- package/dist/utils/stringUtils.js.map +1 -0
- package/dist/utils/systemUtils.d.ts +70 -0
- package/dist/utils/systemUtils.js +207 -0
- package/dist/utils/systemUtils.js.map +1 -0
- package/dist/utils/vertexaiUtils.d.ts +2 -0
- package/dist/utils/vertexaiUtils.js +18 -0
- package/dist/utils/vertexaiUtils.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { GthConfig } from '#src/config.js';
|
|
2
|
+
import { AgentResolvers, GthAgentInterface, GthCommand, Message, StatusUpdateCallback } from '#src/core/types.js';
|
|
3
|
+
import { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
+
import { IterableReadableStream } from '@langchain/core/utils/stream';
|
|
5
|
+
import { BaseCheckpointSaver } from '@langchain/langgraph';
|
|
6
|
+
export type AgentStreamEvent = {
|
|
7
|
+
type: 'text';
|
|
8
|
+
delta: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'tool_start';
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
} | {
|
|
14
|
+
type: 'tool_args';
|
|
15
|
+
id: string;
|
|
16
|
+
delta: string;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'tool_end';
|
|
19
|
+
id: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'tool_result';
|
|
22
|
+
id: string;
|
|
23
|
+
content: string;
|
|
24
|
+
};
|
|
25
|
+
export declare class GthLangChainAgent implements GthAgentInterface {
|
|
26
|
+
private statusUpdate;
|
|
27
|
+
private resolvers;
|
|
28
|
+
private agent;
|
|
29
|
+
private config;
|
|
30
|
+
private command;
|
|
31
|
+
constructor(statusUpdate: StatusUpdateCallback, resolvers?: AgentResolvers);
|
|
32
|
+
init(command: GthCommand | undefined, configIn: GthConfig, checkpointer?: BaseCheckpointSaver | undefined): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Invoke LLM with a message and runnable config.
|
|
35
|
+
* For streaming use {@link #stream} method, streaming is preferred if model API supports it.
|
|
36
|
+
* Please note that this when tools are involved, this method will anyway do multiple LLM
|
|
37
|
+
* calls within LangChain dependency.
|
|
38
|
+
*/
|
|
39
|
+
invoke(messages: Message[], runConfig: RunnableConfig): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Induce LLM to stream AI messages with a user message and runnable config.
|
|
42
|
+
* When stream is not appropriate use {@link invoke}.
|
|
43
|
+
*/
|
|
44
|
+
stream(messages: Message[], runConfig: RunnableConfig): Promise<IterableReadableStream<string>>;
|
|
45
|
+
/**
|
|
46
|
+
* Stream agent events as typed AgentStreamEvent objects.
|
|
47
|
+
* Yields text deltas, tool call lifecycle events, and tool results.
|
|
48
|
+
*/
|
|
49
|
+
streamWithEvents(messages: Message[], runConfig: RunnableConfig): AsyncGenerator<AgentStreamEvent>;
|
|
50
|
+
cleanup(): Promise<void>;
|
|
51
|
+
getEffectiveConfig(config: GthConfig, command: GthCommand | undefined): GthConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Extract and flatten tools from toolkits
|
|
54
|
+
*/
|
|
55
|
+
private extractAndFlattenTools;
|
|
56
|
+
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { StatusLevel, } from '#src/core/types.js';
|
|
2
|
+
import { debugLog, debugLogError, debugLogObject } from '#src/utils/debugUtils.js';
|
|
3
|
+
import { formatToolCalls } from '#src/utils/llmUtils.js';
|
|
4
|
+
import { ProgressIndicator } from '#src/utils/ProgressIndicator.js';
|
|
5
|
+
import { stopWaitingForEscape, waitForEscape, getCurrentWorkDir } from '#src/utils/systemUtils.js';
|
|
6
|
+
import { AIMessage, ToolMessage } from '@langchain/core/messages';
|
|
7
|
+
import { IterableReadableStream } from '@langchain/core/utils/stream';
|
|
8
|
+
import { createAgent, createMiddleware } from 'langchain';
|
|
9
|
+
import { extractInlineBinaryBlocks, materializeBinaryOutputs, renderAssistantContent, } from '#src/utils/binaryOutputUtils.js';
|
|
10
|
+
export class GthLangChainAgent {
|
|
11
|
+
statusUpdate;
|
|
12
|
+
resolvers;
|
|
13
|
+
agent = null;
|
|
14
|
+
config = null;
|
|
15
|
+
command = undefined;
|
|
16
|
+
constructor(statusUpdate, resolvers) {
|
|
17
|
+
this.statusUpdate = (level, message) => {
|
|
18
|
+
statusUpdate(level, message);
|
|
19
|
+
};
|
|
20
|
+
this.resolvers = resolvers;
|
|
21
|
+
}
|
|
22
|
+
async init(command, configIn, checkpointer) {
|
|
23
|
+
this.command = command;
|
|
24
|
+
debugLog(`GthLangChainAgent.init called with command: ${command || 'default'}`);
|
|
25
|
+
// Merge command-specific filesystem config if provided
|
|
26
|
+
this.config = this.getEffectiveConfig(configIn, command);
|
|
27
|
+
debugLogObject('Effective Config', {
|
|
28
|
+
filesystem: this.config.filesystem,
|
|
29
|
+
builtInTools: this.config.builtInTools,
|
|
30
|
+
streamOutput: this.config.streamOutput,
|
|
31
|
+
debugLog: this.config.debugLog,
|
|
32
|
+
});
|
|
33
|
+
this.statusUpdate(StatusLevel.INFO, `Workdir: ${getCurrentWorkDir()}`);
|
|
34
|
+
if (this.config.modelDisplayName) {
|
|
35
|
+
this.statusUpdate(StatusLevel.INFO, `Model: ${this.config.modelDisplayName}`);
|
|
36
|
+
}
|
|
37
|
+
// Resolve tools via resolver or fall back to config tools only
|
|
38
|
+
debugLog('Resolving tools...');
|
|
39
|
+
const resolvedTools = this.resolvers?.resolveTools
|
|
40
|
+
? await this.resolvers.resolveTools(this.config, command)
|
|
41
|
+
: [];
|
|
42
|
+
debugLog(`Resolved tools loaded: ${resolvedTools.length}`);
|
|
43
|
+
// Get user config tools
|
|
44
|
+
const flattenedConfigTools = this.extractAndFlattenTools(this.config.tools || []);
|
|
45
|
+
debugLog(`User config tools loaded: ${flattenedConfigTools.length}`);
|
|
46
|
+
// Combine all tools
|
|
47
|
+
const tools = [...resolvedTools, ...flattenedConfigTools];
|
|
48
|
+
if (tools.length > 0) {
|
|
49
|
+
const toolNames = tools
|
|
50
|
+
.map((tool) => tool.name)
|
|
51
|
+
.filter((name) => name)
|
|
52
|
+
.join(', ');
|
|
53
|
+
this.statusUpdate(StatusLevel.INFO, `Loaded tools: ${toolNames}`);
|
|
54
|
+
debugLog(`Total tools available: ${tools.length}`);
|
|
55
|
+
debugLogObject('All Tools', toolNames.split(', '));
|
|
56
|
+
}
|
|
57
|
+
// Create the React agent
|
|
58
|
+
debugLog('Creating React agent...');
|
|
59
|
+
// Resolve middleware via resolver or fall back to empty
|
|
60
|
+
const configuredMiddleware = this.resolvers?.resolveMiddleware
|
|
61
|
+
? await this.resolvers.resolveMiddleware(
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
this.config.middleware, this.config)
|
|
64
|
+
: [];
|
|
65
|
+
// Add tool call status update middleware
|
|
66
|
+
const toolCallStatusMiddleware = createMiddleware({
|
|
67
|
+
name: 'GthMiddlewareToolCallStatusUpdate',
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
+
afterModel: (state) => {
|
|
70
|
+
debugLogObject('postModel state', state);
|
|
71
|
+
const lastMessage = state.messages[state.messages.length - 1];
|
|
72
|
+
if (AIMessage.isInstance(lastMessage) &&
|
|
73
|
+
lastMessage.tool_calls &&
|
|
74
|
+
lastMessage.tool_calls?.length > 0) {
|
|
75
|
+
this.statusUpdate(StatusLevel.INFO, `\nRequested tools: ${formatToolCalls(lastMessage.tool_calls)}\n`);
|
|
76
|
+
}
|
|
77
|
+
return state;
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
// Combine all middleware
|
|
81
|
+
const middleware = [...configuredMiddleware, toolCallStatusMiddleware];
|
|
82
|
+
this.statusUpdate(StatusLevel.INFO, `Loaded middleware: ${middleware.map((m) => m.name).join(', ')}`);
|
|
83
|
+
// Create agent with configured middleware
|
|
84
|
+
this.agent = createAgent({
|
|
85
|
+
model: this.config.llm,
|
|
86
|
+
tools,
|
|
87
|
+
middleware,
|
|
88
|
+
checkpointer,
|
|
89
|
+
});
|
|
90
|
+
debugLog('React agent created successfully');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Invoke LLM with a message and runnable config.
|
|
94
|
+
* For streaming use {@link #stream} method, streaming is preferred if model API supports it.
|
|
95
|
+
* Please note that this when tools are involved, this method will anyway do multiple LLM
|
|
96
|
+
* calls within LangChain dependency.
|
|
97
|
+
*/
|
|
98
|
+
async invoke(messages, runConfig) {
|
|
99
|
+
if (!this.agent || !this.config) {
|
|
100
|
+
throw new Error('Agent not initialized. Call init() first.');
|
|
101
|
+
}
|
|
102
|
+
debugLog('=== Starting non-streaming invoke ===');
|
|
103
|
+
debugLogObject('LLM Input Messages', messages);
|
|
104
|
+
debugLogObject('Invoke RunConfig', runConfig);
|
|
105
|
+
try {
|
|
106
|
+
const progress = new ProgressIndicator('Thinking.');
|
|
107
|
+
try {
|
|
108
|
+
debugLog('Calling agent.invoke...');
|
|
109
|
+
const response = await this.agent.invoke({ messages }, runConfig);
|
|
110
|
+
const finalMessage = response.messages[response.messages.length - 1];
|
|
111
|
+
const finalContent = finalMessage?.content;
|
|
112
|
+
const processedContent = !this.config.writeBinaryOutputsToFile
|
|
113
|
+
? {
|
|
114
|
+
renderedContent: renderAssistantContent(finalContent),
|
|
115
|
+
successMessages: [],
|
|
116
|
+
}
|
|
117
|
+
: materializeBinaryOutputs(finalContent, this.command);
|
|
118
|
+
if (processedContent.renderedContent.trim().length > 0) {
|
|
119
|
+
this.statusUpdate(StatusLevel.DISPLAY, processedContent.renderedContent);
|
|
120
|
+
}
|
|
121
|
+
for (const successMessage of processedContent.successMessages) {
|
|
122
|
+
this.statusUpdate(StatusLevel.SUCCESS, successMessage);
|
|
123
|
+
}
|
|
124
|
+
return [processedContent.renderedContent, ...processedContent.successMessages]
|
|
125
|
+
.filter((part) => part.trim().length > 0)
|
|
126
|
+
.join('\n');
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
debugLogError('invoke inner', e);
|
|
130
|
+
if (e instanceof Error && e?.name === 'ToolException') {
|
|
131
|
+
throw e; // Re-throw ToolException to be handled by outer catch
|
|
132
|
+
}
|
|
133
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
134
|
+
this.statusUpdate(StatusLevel.ERROR, `LLM invocation failed: ${message}`);
|
|
135
|
+
throw e;
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
progress.stop();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
debugLogError('invoke outer', error);
|
|
143
|
+
if (error instanceof Error) {
|
|
144
|
+
if (error?.name === 'ToolException') {
|
|
145
|
+
this.statusUpdate(StatusLevel.ERROR, `Tool execution failed: ${error?.message}`);
|
|
146
|
+
return `Tool execution failed: ${error?.message}`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Induce LLM to stream AI messages with a user message and runnable config.
|
|
154
|
+
* When stream is not appropriate use {@link invoke}.
|
|
155
|
+
*/
|
|
156
|
+
async stream(messages, runConfig) {
|
|
157
|
+
if (!this.agent || !this.config) {
|
|
158
|
+
throw new Error('Agent not initialized. Call init() first.');
|
|
159
|
+
}
|
|
160
|
+
debugLog('=== Starting streaming invoke ===');
|
|
161
|
+
debugLogObject('LLM Input Messages', messages);
|
|
162
|
+
debugLogObject('Stream RunConfig', runConfig);
|
|
163
|
+
this.statusUpdate(StatusLevel.INFO, '\nThinking...\n');
|
|
164
|
+
const statusUpdate = this.statusUpdate;
|
|
165
|
+
const config = this.config;
|
|
166
|
+
const command = this.command;
|
|
167
|
+
const interruptState = { escape: false, messageShown: false };
|
|
168
|
+
const abortController = new AbortController();
|
|
169
|
+
const showInterruptMessage = () => {
|
|
170
|
+
if (!interruptState.messageShown) {
|
|
171
|
+
interruptState.messageShown = true;
|
|
172
|
+
statusUpdate(StatusLevel.WARNING, '\n\nInterrupted by user, exiting\n\n');
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
waitForEscape(() => {
|
|
176
|
+
interruptState.escape = true;
|
|
177
|
+
showInterruptMessage();
|
|
178
|
+
if (!abortController.signal.aborted) {
|
|
179
|
+
abortController.abort();
|
|
180
|
+
}
|
|
181
|
+
}, this.config.canInterruptInferenceWithEsc);
|
|
182
|
+
const stream = await this.agent.stream({ messages }, { ...runConfig, streamMode: 'messages', signal: abortController.signal });
|
|
183
|
+
return new IterableReadableStream({
|
|
184
|
+
async start(controller) {
|
|
185
|
+
try {
|
|
186
|
+
debugLog('Starting stream processing...');
|
|
187
|
+
let totalChunks = 0;
|
|
188
|
+
const seenBinaryBlocks = new Set();
|
|
189
|
+
const binaryBlocks = [];
|
|
190
|
+
for await (const [chunk, _metadata] of stream) {
|
|
191
|
+
debugLogObject('Stream chunk', { chunk, _metadata });
|
|
192
|
+
if (AIMessage.isInstance(chunk)) {
|
|
193
|
+
const text = chunk.text ?? '';
|
|
194
|
+
totalChunks++;
|
|
195
|
+
if (text.length > 0) {
|
|
196
|
+
statusUpdate(StatusLevel.STREAM, text);
|
|
197
|
+
controller.enqueue(text);
|
|
198
|
+
}
|
|
199
|
+
if (config?.writeBinaryOutputsToFile) {
|
|
200
|
+
for (const block of extractInlineBinaryBlocks(chunk.content)) {
|
|
201
|
+
const binaryKey = `${block.mimeType}:${block.data.length}:${block.data}`;
|
|
202
|
+
if (seenBinaryBlocks.has(binaryKey)) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
seenBinaryBlocks.add(binaryKey);
|
|
206
|
+
binaryBlocks.push({ mimeType: block.mimeType, data: block.data });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (interruptState.escape) {
|
|
211
|
+
if (typeof stream.cancel === 'function') {
|
|
212
|
+
await stream.cancel();
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (config?.writeBinaryOutputsToFile && binaryBlocks.length > 0) {
|
|
218
|
+
const processedContent = materializeBinaryOutputs(binaryBlocks.map((block) => ({
|
|
219
|
+
type: 'inlineData',
|
|
220
|
+
inlineData: block,
|
|
221
|
+
})), command);
|
|
222
|
+
for (const successMessage of processedContent.successMessages) {
|
|
223
|
+
statusUpdate(StatusLevel.SUCCESS, successMessage);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
debugLog(`Stream completed. Total chunks: ${totalChunks}`);
|
|
227
|
+
controller.close();
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
if (interruptState.escape || (error instanceof Error && error.name === 'AbortError')) {
|
|
231
|
+
showInterruptMessage();
|
|
232
|
+
controller.close();
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
debugLogError('stream processing', error);
|
|
236
|
+
if (error instanceof Error) {
|
|
237
|
+
if (error?.name === 'ToolException') {
|
|
238
|
+
statusUpdate(StatusLevel.ERROR, `Tool execution failed: ${error?.message}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
controller.error(error);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
finally {
|
|
245
|
+
stopWaitingForEscape();
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
async cancel() {
|
|
249
|
+
stopWaitingForEscape();
|
|
250
|
+
if (!abortController.signal.aborted) {
|
|
251
|
+
abortController.abort();
|
|
252
|
+
}
|
|
253
|
+
// Clean up the underlying stream if it has a cancel method
|
|
254
|
+
if (stream && typeof stream.cancel === 'function') {
|
|
255
|
+
await stream.cancel();
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Stream agent events as typed AgentStreamEvent objects.
|
|
262
|
+
* Yields text deltas, tool call lifecycle events, and tool results.
|
|
263
|
+
*/
|
|
264
|
+
async *streamWithEvents(messages, runConfig) {
|
|
265
|
+
if (!this.agent || !this.config) {
|
|
266
|
+
throw new Error('Agent not initialized. Call init() first.');
|
|
267
|
+
}
|
|
268
|
+
debugLog('=== Starting streamWithEvents ===');
|
|
269
|
+
debugLogObject('LLM Input Messages', messages);
|
|
270
|
+
const stream = await this.agent.stream({ messages }, { ...runConfig, streamMode: 'messages' });
|
|
271
|
+
// Buffer tool calls across chunks so we use final (complete) args
|
|
272
|
+
const pendingToolCalls = new Map();
|
|
273
|
+
for await (const [chunk, _metadata] of stream) {
|
|
274
|
+
debugLogObject('streamWithEvents chunk', { chunk, _metadata });
|
|
275
|
+
if (AIMessage.isInstance(chunk) && chunk.tool_calls && chunk.tool_calls.length > 0) {
|
|
276
|
+
for (const tool_call of chunk.tool_calls) {
|
|
277
|
+
// Keep updating with latest args as LLM streams them across chunks
|
|
278
|
+
pendingToolCalls.set(tool_call.id, {
|
|
279
|
+
id: tool_call.id,
|
|
280
|
+
name: tool_call.name,
|
|
281
|
+
args: tool_call.args,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
else if (AIMessage.isInstance(chunk) && chunk.text) {
|
|
286
|
+
yield { type: 'text', delta: chunk.text };
|
|
287
|
+
}
|
|
288
|
+
if (chunk instanceof ToolMessage) {
|
|
289
|
+
// Flush buffered tool calls with their final args before the tool result
|
|
290
|
+
for (const tc of pendingToolCalls.values()) {
|
|
291
|
+
yield { type: 'tool_start', id: tc.id, name: tc.name };
|
|
292
|
+
yield { type: 'tool_args', id: tc.id, delta: JSON.stringify(tc.args ?? {}) };
|
|
293
|
+
yield { type: 'tool_end', id: tc.id };
|
|
294
|
+
}
|
|
295
|
+
pendingToolCalls.clear();
|
|
296
|
+
const content = typeof chunk.content === 'string' ? chunk.content : JSON.stringify(chunk.content);
|
|
297
|
+
yield { type: 'tool_result', id: chunk.tool_call_id, content };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Flush any tool calls not followed by a ToolMessage (e.g. terminal tool calls)
|
|
301
|
+
for (const tc of pendingToolCalls.values()) {
|
|
302
|
+
yield { type: 'tool_start', id: tc.id, name: tc.name };
|
|
303
|
+
yield { type: 'tool_args', id: tc.id, delta: JSON.stringify(tc.args ?? {}) };
|
|
304
|
+
yield { type: 'tool_end', id: tc.id };
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
async cleanup() {
|
|
308
|
+
debugLog('Cleaning up GthLangChainAgent...');
|
|
309
|
+
if (this.resolvers?.cleanupTools) {
|
|
310
|
+
await this.resolvers.cleanupTools();
|
|
311
|
+
}
|
|
312
|
+
if (this.resolvers?.cleanupMiddleware) {
|
|
313
|
+
await this.resolvers.cleanupMiddleware();
|
|
314
|
+
}
|
|
315
|
+
this.agent = null;
|
|
316
|
+
this.config = null;
|
|
317
|
+
this.command = undefined;
|
|
318
|
+
debugLog('GthLangChainAgent cleanup complete');
|
|
319
|
+
}
|
|
320
|
+
getEffectiveConfig(config, command) {
|
|
321
|
+
debugLog(`Getting effective config for command: ${command || 'default'}`);
|
|
322
|
+
const supportsTools = !!config.llm.bindTools;
|
|
323
|
+
if (!supportsTools) {
|
|
324
|
+
this.statusUpdate(StatusLevel.WARNING, 'Model does not seem to support tools.');
|
|
325
|
+
debugLog('Warning: Model does not support tools');
|
|
326
|
+
}
|
|
327
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
328
|
+
const cmdConfig = (command && config.commands?.[command]);
|
|
329
|
+
return {
|
|
330
|
+
...config,
|
|
331
|
+
filesystem: cmdConfig?.filesystem !== undefined ? cmdConfig.filesystem : config.filesystem,
|
|
332
|
+
builtInTools: cmdConfig?.builtInTools !== undefined ? cmdConfig.builtInTools : config.builtInTools,
|
|
333
|
+
binaryFormats: cmdConfig?.binaryFormats !== undefined ? cmdConfig.binaryFormats : config.binaryFormats,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Extract and flatten tools from toolkits
|
|
338
|
+
*/
|
|
339
|
+
extractAndFlattenTools(tools) {
|
|
340
|
+
const flattenedTools = [];
|
|
341
|
+
for (const toolOrToolkit of tools) {
|
|
342
|
+
// eslint-disable-next-line
|
|
343
|
+
if (toolOrToolkit['getTools'] instanceof Function) {
|
|
344
|
+
// This is a toolkit
|
|
345
|
+
flattenedTools.push(...toolOrToolkit.getTools());
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
// This is a regular tool
|
|
349
|
+
flattenedTools.push(toolOrToolkit);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return flattenedTools;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
//# sourceMappingURL=GthLangChainAgent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GthLangChainAgent.js","sourceRoot":"","sources":["../../src/core/GthLangChainAgent.ts"],"names":[],"mappings":"AACA,OAAO,EAKL,WAAW,GAEZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnG,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EACL,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AASzC,MAAM,OAAO,iBAAiB;IACpB,YAAY,CAAuB;IACnC,SAAS,CAA6B;IACtC,KAAK,GAA0C,IAAI,CAAC;IACpD,MAAM,GAAqB,IAAI,CAAC;IAChC,OAAO,GAA2B,SAAS,CAAC;IAEpD,YAAY,YAAkC,EAAE,SAA0B;QACxE,IAAI,CAAC,YAAY,GAAG,CAAC,KAAkB,EAAE,OAAe,EAAE,EAAE;YAC1D,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/B,CAAC,CAAC;QACF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,KAAK,C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,CAAC,uCAAuC,CAAC,CAAC;QACpD,CAAC;QACD,8DAA8D;QAC9D,MAAM,SAAS,GAAG,CAAC,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAQ,CAAC;QACjE,OAAO;YACL,GAAG,MAAM;YACT,UAAU,EAAE,SAAS,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU;YAC1F,YAAY,EACV,SAAS,EAAE,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY;YACtF,aAAa,EACX,SAAS,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa;SAC1F,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,sBAAsB,CAC5B,KAA6D;QAE7D,MAAM,cAAc,GAA8B,EAAE,CAAC;QACrD,KAAK,MAAM,aAAa,IAAI,KAAK,EAAE,CAAC;YAClC,2BAA2B;YAC3B,IAAK,aAAqB,CAAC,UAAU,CAAC,YAAY,QAAQ,EAAE,CAAC;gBAC3D,oBAAoB;gBACpB,cAAc,CAAC,IAAI,CAAC,GAAI,aAA6B,CAAC,QAAQ,EAAE,CAAC,CAAC;YACpE,CAAC;iBAAM,CAAC;gBACN,yBAAyB;gBACzB,cAAc,CAAC,IAAI,CAAC,aAAwC,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QACD,OAAO,cAAc,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { GthConfig } from '#src/config.js';
|
|
2
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
+
import type { StructuredToolInterface } from '@langchain/core/tools';
|
|
5
|
+
import type { IterableReadableStream } from '@langchain/core/utils/stream';
|
|
6
|
+
import type { BaseCheckpointSaver } from '@langchain/langgraph';
|
|
7
|
+
export type Message = BaseMessage;
|
|
8
|
+
export type StatusUpdateCallback = (level: StatusLevel, message: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Status level for logging and output control.
|
|
11
|
+
* Levels are ordered by importance, with lower ordinal values being more verbose.
|
|
12
|
+
* DEBUG (0) is the most verbose, STREAM (6) is the least verbose.
|
|
13
|
+
*/
|
|
14
|
+
export declare enum StatusLevel {
|
|
15
|
+
DEBUG = 0,
|
|
16
|
+
INFO = 1,
|
|
17
|
+
DISPLAY = 2,
|
|
18
|
+
SUCCESS = 3,
|
|
19
|
+
WARNING = 4,
|
|
20
|
+
ERROR = 5,
|
|
21
|
+
STREAM = 6
|
|
22
|
+
}
|
|
23
|
+
export type GthCommand = 'ask' | 'pr' | 'review' | 'chat' | 'code' | 'api';
|
|
24
|
+
export interface GthAgentInterface {
|
|
25
|
+
init(command: GthCommand | undefined, configIn: GthConfig, checkpointSaver?: BaseCheckpointSaver | undefined): Promise<void>;
|
|
26
|
+
invoke(messages: Message[], runConfig: RunnableConfig): Promise<string>;
|
|
27
|
+
stream(messages: Message[], runConfig: RunnableConfig): Promise<IterableReadableStream<string>>;
|
|
28
|
+
cleanup?(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
export type ToolsResolver = (config: GthConfig, command?: GthCommand) => Promise<StructuredToolInterface[]>;
|
|
31
|
+
export type ToolsCleanup = () => Promise<void>;
|
|
32
|
+
export type MiddlewareResolver = (middleware: any[] | undefined, config: GthConfig) => Promise<any[]>;
|
|
33
|
+
export type MiddlewareCleanup = () => Promise<void>;
|
|
34
|
+
export interface AgentResolvers {
|
|
35
|
+
resolveTools?: ToolsResolver;
|
|
36
|
+
cleanupTools?: ToolsCleanup;
|
|
37
|
+
resolveMiddleware?: MiddlewareResolver;
|
|
38
|
+
cleanupMiddleware?: MiddlewareCleanup;
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status level for logging and output control.
|
|
3
|
+
* Levels are ordered by importance, with lower ordinal values being more verbose.
|
|
4
|
+
* DEBUG (0) is the most verbose, STREAM (6) is the least verbose.
|
|
5
|
+
*/
|
|
6
|
+
export var StatusLevel;
|
|
7
|
+
(function (StatusLevel) {
|
|
8
|
+
StatusLevel[StatusLevel["DEBUG"] = 0] = "DEBUG";
|
|
9
|
+
StatusLevel[StatusLevel["INFO"] = 1] = "INFO";
|
|
10
|
+
StatusLevel[StatusLevel["DISPLAY"] = 2] = "DISPLAY";
|
|
11
|
+
StatusLevel[StatusLevel["SUCCESS"] = 3] = "SUCCESS";
|
|
12
|
+
StatusLevel[StatusLevel["WARNING"] = 4] = "WARNING";
|
|
13
|
+
StatusLevel[StatusLevel["ERROR"] = 5] = "ERROR";
|
|
14
|
+
StatusLevel[StatusLevel["STREAM"] = 6] = "STREAM";
|
|
15
|
+
})(StatusLevel || (StatusLevel = {}));
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,MAAM,CAAN,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,+CAAS,CAAA;IACT,6CAAQ,CAAA;IACR,mDAAW,CAAA;IACX,mDAAW,CAAA;IACX,mDAAW,CAAA;IACX,+CAAS,CAAA;IACT,iDAAU,CAAA;AACZ,CAAC,EARW,WAAW,KAAX,WAAW,QAQtB"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AnthropicInput } from '@langchain/anthropic';
|
|
2
|
+
import type { BaseChatModel, BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
3
|
+
/**
|
|
4
|
+
* Function to process JSON config and create Anthropic LLM instance
|
|
5
|
+
*/
|
|
6
|
+
export declare function processJsonConfig(llmConfig: AnthropicInput & BaseChatModelParams): Promise<BaseChatModel>;
|
|
7
|
+
export declare function init(configFileName: string): void;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { displayWarning } from '#src/utils/consoleUtils.js';
|
|
2
|
+
import { writeFileIfNotExistsWithMessages } from '#src/utils/fileUtils.js';
|
|
3
|
+
import { env } from '#src/utils/systemUtils.js';
|
|
4
|
+
/**
|
|
5
|
+
* Function to process JSON config and create Anthropic LLM instance
|
|
6
|
+
*/
|
|
7
|
+
// noinspection JSUnusedGlobalSymbols
|
|
8
|
+
export async function processJsonConfig(llmConfig) {
|
|
9
|
+
const anthropic = await import('@langchain/anthropic');
|
|
10
|
+
// Use config value if available, otherwise use the environment variable
|
|
11
|
+
const anthropicApiKey = llmConfig.apiKey || env.ANTHROPIC_API_KEY;
|
|
12
|
+
return new anthropic.ChatAnthropic({
|
|
13
|
+
...llmConfig,
|
|
14
|
+
apiKey: anthropicApiKey,
|
|
15
|
+
model: llmConfig.model || 'claude-sonnet-4-5',
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
const jsonContent = `{
|
|
19
|
+
"llm": {
|
|
20
|
+
"type": "anthropic",
|
|
21
|
+
"model": "claude-sonnet-4-5"
|
|
22
|
+
}
|
|
23
|
+
}`;
|
|
24
|
+
// noinspection JSUnusedGlobalSymbols
|
|
25
|
+
export function init(configFileName) {
|
|
26
|
+
// Determine which content to use based on file extension
|
|
27
|
+
if (!configFileName.endsWith('.json')) {
|
|
28
|
+
throw new Error('Only JSON config is supported.');
|
|
29
|
+
}
|
|
30
|
+
writeFileIfNotExistsWithMessages(configFileName, jsonContent);
|
|
31
|
+
displayWarning(`You need to update your ${configFileName} to add your Anthropic API key, ` +
|
|
32
|
+
'or define ANTHROPIC_API_KEY environment variable.');
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAOhD;;GAEG;AACH,qCAAqC;AACrC,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,SAA+C;IAE/C,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;IACvD,wEAAwE;IACxE,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,IAAI,GAAG,CAAC,iBAAiB,CAAC;IAClE,OAAO,IAAI,SAAS,CAAC,aAAa,CAAC;QACjC,GAAG,SAAS;QACZ,MAAM,EAAE,eAAe;QACvB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,mBAAmB;KAC9C,CAAC,CAAC;AACL,CAAC;AAED,MAAM,WAAW,GAAG;;;;;EAKlB,CAAC;AAEH,qCAAqC;AACrC,MAAM,UAAU,IAAI,CAAC,cAAsB;IACzC,yDAAyD;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,gCAAgC,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC9D,cAAc,CACZ,2BAA2B,cAAc,kCAAkC;QACzE,mDAAmD,CACtD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BaseChatModel, BaseChatModelParams } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import { ChatDeepSeekInput } from '@langchain/deepseek';
|
|
3
|
+
export declare function processJsonConfig(llmConfig: ChatDeepSeekInput & BaseChatModelParams): Promise<BaseChatModel>;
|
|
4
|
+
export declare function init(configFileName: string): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { displayWarning } from '#src/utils/consoleUtils.js';
|
|
2
|
+
import { env } from '#src/utils/systemUtils.js';
|
|
3
|
+
import { writeFileIfNotExistsWithMessages } from '#src/utils/fileUtils.js';
|
|
4
|
+
// Function to process JSON config and create DeepSeek LLM instance
|
|
5
|
+
export async function processJsonConfig(llmConfig) {
|
|
6
|
+
const deepseek = await import('@langchain/deepseek');
|
|
7
|
+
// Use config apiKey if available, otherwise use the environment variable
|
|
8
|
+
const deepseekApiKey = llmConfig.apiKey || env.DEEPSEEK_API_KEY;
|
|
9
|
+
return new deepseek.ChatDeepSeek({
|
|
10
|
+
...llmConfig,
|
|
11
|
+
apiKey: deepseekApiKey,
|
|
12
|
+
model: llmConfig.model || 'deepseek-reasoner',
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const jsonContent = `{
|
|
16
|
+
"llm": {
|
|
17
|
+
"type": "deepseek",
|
|
18
|
+
"model": "deepseek-reasoner"
|
|
19
|
+
}
|
|
20
|
+
}`;
|
|
21
|
+
export function init(configFileName) {
|
|
22
|
+
// Determine which content to use based on file extension
|
|
23
|
+
if (!configFileName.endsWith('.json')) {
|
|
24
|
+
throw new Error('Only JSON config is supported.');
|
|
25
|
+
}
|
|
26
|
+
writeFileIfNotExistsWithMessages(configFileName, jsonContent);
|
|
27
|
+
displayWarning(`You need to update your ${configFileName} to add your DeepSeek API key, ` +
|
|
28
|
+
'or define DEEPSEEK_API_KEY environment variable.');
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=deepseek.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepseek.js","sourceRoot":"","sources":["../../src/providers/deepseek.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAOhD,OAAO,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAE3E,mEAAmE;AACnE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,SAAkD;IAElD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACrD,yEAAyE;IACzE,MAAM,cAAc,GAAG,SAAS,CAAC,MAAM,IAAI,GAAG,CAAC,gBAAgB,CAAC;IAChE,OAAO,IAAI,QAAQ,CAAC,YAAY,CAAC;QAC/B,GAAG,SAAS;QACZ,MAAM,EAAE,cAAc;QACtB,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,mBAAmB;KAC9C,CAAC,CAAC;AACL,CAAC;AAED,MAAM,WAAW,GAAG;;;;;EAKlB,CAAC;AAEH,MAAM,UAAU,IAAI,CAAC,cAAsB;IACzC,yDAAyD;IACzD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,gCAAgC,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC9D,cAAc,CACZ,2BAA2B,cAAc,iCAAiC;QACxE,kDAAkD,CACrD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { displayWarning } from '#src/utils/consoleUtils.js';
|
|
2
|
+
// Function to process JSON config and create Fake LLM instance for testing
|
|
3
|
+
export async function processJsonConfig(llmConfig) {
|
|
4
|
+
if (llmConfig.responses) {
|
|
5
|
+
const test = await import('@langchain/core/utils/testing');
|
|
6
|
+
return new test.FakeListChatModel(llmConfig);
|
|
7
|
+
}
|
|
8
|
+
displayWarning("Fake LLM requires 'responses' array in config");
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
// No init function needed for fake LLM as it's only used for testing
|
|
12
|
+
//# sourceMappingURL=fake.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake.js","sourceRoot":"","sources":["../../src/providers/fake.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,SAAwB;IAC9D,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAC;QAC3D,OAAO,IAAI,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IACD,cAAc,CAAC,+CAA+C,CAAC,CAAC;IAChE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,qEAAqE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { ChatGoogleParams } from '@langchain/google/node';
|
|
3
|
+
export declare function processJsonConfig(llmConfig: ChatGoogleParams & {
|
|
4
|
+
type?: string;
|
|
5
|
+
apiKeyEnvironmentVariable?: string;
|
|
6
|
+
}): Promise<BaseChatModel>;
|
|
7
|
+
export declare function init(configFileName: string): void;
|