ai.matey.wrapper 0.2.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 +21 -0
- package/dist/cjs/anthropic-sdk.js +203 -0
- package/dist/cjs/anthropic-sdk.js.map +1 -0
- package/dist/cjs/anymethod.js +167 -0
- package/dist/cjs/anymethod.js.map +1 -0
- package/dist/cjs/chat.js +513 -0
- package/dist/cjs/chat.js.map +1 -0
- package/dist/cjs/chrome-ai-legacy.js +168 -0
- package/dist/cjs/chrome-ai-legacy.js.map +1 -0
- package/dist/cjs/chrome-ai.js +156 -0
- package/dist/cjs/chrome-ai.js.map +1 -0
- package/dist/cjs/index.js +58 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/ir-index.js +52 -0
- package/dist/cjs/ir-index.js.map +1 -0
- package/dist/cjs/openai-sdk.js +221 -0
- package/dist/cjs/openai-sdk.js.map +1 -0
- package/dist/cjs/stream-utils.js +21 -0
- package/dist/cjs/stream-utils.js.map +1 -0
- package/dist/cjs/types.js +10 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/anthropic-sdk.js +196 -0
- package/dist/esm/anthropic-sdk.js.map +1 -0
- package/dist/esm/anymethod.js +161 -0
- package/dist/esm/anymethod.js.map +1 -0
- package/dist/esm/chat.js +508 -0
- package/dist/esm/chat.js.map +1 -0
- package/dist/esm/chrome-ai-legacy.js +163 -0
- package/dist/esm/chrome-ai-legacy.js.map +1 -0
- package/dist/esm/chrome-ai.js +152 -0
- package/dist/esm/chrome-ai.js.map +1 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/ir-index.js +41 -0
- package/dist/esm/ir-index.js.map +1 -0
- package/dist/esm/openai-sdk.js +213 -0
- package/dist/esm/openai-sdk.js.map +1 -0
- package/dist/esm/stream-utils.js +14 -0
- package/dist/esm/stream-utils.js.map +1 -0
- package/dist/esm/types.js +9 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/types/anthropic-sdk.d.ts +154 -0
- package/dist/types/anthropic-sdk.d.ts.map +1 -0
- package/dist/types/anymethod.d.ts +45 -0
- package/dist/types/anymethod.d.ts.map +1 -0
- package/dist/types/chat.d.ts +144 -0
- package/dist/types/chat.d.ts.map +1 -0
- package/dist/types/chrome-ai-legacy.d.ts +44 -0
- package/dist/types/chrome-ai-legacy.d.ts.map +1 -0
- package/dist/types/chrome-ai.d.ts +38 -0
- package/dist/types/chrome-ai.d.ts.map +1 -0
- package/dist/types/index.d.ts +20 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/ir-index.d.ts +41 -0
- package/dist/types/ir-index.d.ts.map +1 -0
- package/dist/types/openai-sdk.d.ts +183 -0
- package/dist/types/openai-sdk.d.ts.map +1 -0
- package/dist/types/stream-utils.d.ts +9 -0
- package/dist/types/stream-utils.d.ts.map +1 -0
- package/dist/types/types.d.ts +232 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +132 -0
- package/readme.md +92 -0
package/dist/cjs/chat.js
ADDED
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* IR Chat Client
|
|
4
|
+
*
|
|
5
|
+
* An IR-native chat client that wraps the Bridge/BackendAdapter
|
|
6
|
+
* with conversation state management, streaming helpers, and tool support.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.Chat = void 0;
|
|
12
|
+
exports.createChat = createChat;
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Chat Class
|
|
15
|
+
// ============================================================================
|
|
16
|
+
/**
|
|
17
|
+
* Headless chat client with conversation state management.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { Chat } from 'ai.matey.wrapper/ir';
|
|
22
|
+
* import { AnthropicBackend } from 'ai.matey.backend/anthropic';
|
|
23
|
+
*
|
|
24
|
+
* const chat = new Chat({
|
|
25
|
+
* backend: new AnthropicBackend({ apiKey: process.env.ANTHROPIC_API_KEY }),
|
|
26
|
+
* systemPrompt: 'You are a helpful assistant.',
|
|
27
|
+
* historyLimit: 50,
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Non-streaming
|
|
31
|
+
* const response = await chat.send('Hello!');
|
|
32
|
+
* console.log(response.content);
|
|
33
|
+
*
|
|
34
|
+
* // Streaming
|
|
35
|
+
* await chat.stream('Tell me a story', {
|
|
36
|
+
* onChunk: ({ delta }) => process.stdout.write(delta),
|
|
37
|
+
* onDone: (response) => console.log('\n[Done]'),
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Access state
|
|
41
|
+
* console.log(chat.messages);
|
|
42
|
+
* console.log(chat.totalUsage);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
class Chat {
|
|
46
|
+
config;
|
|
47
|
+
backend;
|
|
48
|
+
// Conversation state
|
|
49
|
+
_messages = [];
|
|
50
|
+
_isLoading = false;
|
|
51
|
+
_error = null;
|
|
52
|
+
_totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
53
|
+
_requestCount = 0;
|
|
54
|
+
// Event listeners
|
|
55
|
+
_listeners = new Map();
|
|
56
|
+
// Request counter for generating IDs
|
|
57
|
+
_requestIdCounter = 0;
|
|
58
|
+
/**
|
|
59
|
+
* Create a new Chat instance.
|
|
60
|
+
*/
|
|
61
|
+
constructor(config) {
|
|
62
|
+
this.config = {
|
|
63
|
+
...config,
|
|
64
|
+
historyLimit: config.historyLimit ?? 100,
|
|
65
|
+
autoExecuteTools: config.autoExecuteTools ?? false,
|
|
66
|
+
maxToolRounds: config.maxToolRounds ?? 10,
|
|
67
|
+
};
|
|
68
|
+
this.backend = config.backend;
|
|
69
|
+
}
|
|
70
|
+
// ==========================================================================
|
|
71
|
+
// Public Getters
|
|
72
|
+
// ==========================================================================
|
|
73
|
+
/**
|
|
74
|
+
* Get all messages in the conversation.
|
|
75
|
+
*/
|
|
76
|
+
get messages() {
|
|
77
|
+
return this._messages;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get whether a request is in progress.
|
|
81
|
+
*/
|
|
82
|
+
get isLoading() {
|
|
83
|
+
return this._isLoading;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get the current error, if any.
|
|
87
|
+
*/
|
|
88
|
+
get error() {
|
|
89
|
+
return this._error;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get cumulative token usage.
|
|
93
|
+
*/
|
|
94
|
+
get totalUsage() {
|
|
95
|
+
return this._totalUsage;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the number of requests made.
|
|
99
|
+
*/
|
|
100
|
+
get requestCount() {
|
|
101
|
+
return this._requestCount;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get a snapshot of the conversation state.
|
|
105
|
+
*/
|
|
106
|
+
get state() {
|
|
107
|
+
return {
|
|
108
|
+
messages: this._messages,
|
|
109
|
+
isLoading: this._isLoading,
|
|
110
|
+
error: this._error,
|
|
111
|
+
totalUsage: { ...this._totalUsage },
|
|
112
|
+
requestCount: this._requestCount,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// ==========================================================================
|
|
116
|
+
// Core Methods
|
|
117
|
+
// ==========================================================================
|
|
118
|
+
/**
|
|
119
|
+
* Send a message and get a response (non-streaming).
|
|
120
|
+
*
|
|
121
|
+
* @param content - The message content (string or structured content)
|
|
122
|
+
* @param options - Request options
|
|
123
|
+
* @returns The assistant's response
|
|
124
|
+
*/
|
|
125
|
+
async send(content, options) {
|
|
126
|
+
this.setLoading(true);
|
|
127
|
+
this.setError(null);
|
|
128
|
+
try {
|
|
129
|
+
// Add user message to history
|
|
130
|
+
const userMessage = this.createUserMessage(content);
|
|
131
|
+
this.addMessage(userMessage);
|
|
132
|
+
// Execute request with potential tool loop
|
|
133
|
+
const response = await this.executeWithToolLoop(options);
|
|
134
|
+
this.setLoading(false);
|
|
135
|
+
return response;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
139
|
+
this.setError(err);
|
|
140
|
+
this.setLoading(false);
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Send a message and stream the response.
|
|
146
|
+
*
|
|
147
|
+
* @param content - The message content
|
|
148
|
+
* @param options - Streaming options with callbacks
|
|
149
|
+
* @returns The final response after streaming completes
|
|
150
|
+
*/
|
|
151
|
+
async stream(content, options) {
|
|
152
|
+
this.setLoading(true);
|
|
153
|
+
this.setError(null);
|
|
154
|
+
try {
|
|
155
|
+
// Add user message to history
|
|
156
|
+
const userMessage = this.createUserMessage(content);
|
|
157
|
+
this.addMessage(userMessage);
|
|
158
|
+
// Execute streaming request with potential tool loop
|
|
159
|
+
const response = await this.executeStreamWithToolLoop(options);
|
|
160
|
+
this.setLoading(false);
|
|
161
|
+
return response;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
165
|
+
this.setError(err);
|
|
166
|
+
this.setLoading(false);
|
|
167
|
+
options?.onError?.(err);
|
|
168
|
+
throw err;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Add a message to the conversation without sending a request.
|
|
173
|
+
* Useful for restoring conversation history or injecting context.
|
|
174
|
+
*/
|
|
175
|
+
addMessage(message) {
|
|
176
|
+
this._messages.push(message);
|
|
177
|
+
this.trimHistory();
|
|
178
|
+
this.emitStateChange();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Clear the conversation history.
|
|
182
|
+
*/
|
|
183
|
+
clear() {
|
|
184
|
+
this._messages = [];
|
|
185
|
+
this._error = null;
|
|
186
|
+
this._totalUsage = { promptTokens: 0, completionTokens: 0, totalTokens: 0 };
|
|
187
|
+
this._requestCount = 0;
|
|
188
|
+
this.emitStateChange();
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Remove the last N messages from the conversation.
|
|
192
|
+
*/
|
|
193
|
+
removeLastMessages(count = 1) {
|
|
194
|
+
const removed = this._messages.splice(-count, count);
|
|
195
|
+
this.emitStateChange();
|
|
196
|
+
return removed;
|
|
197
|
+
}
|
|
198
|
+
// ==========================================================================
|
|
199
|
+
// Event Handling
|
|
200
|
+
// ==========================================================================
|
|
201
|
+
/**
|
|
202
|
+
* Subscribe to chat events.
|
|
203
|
+
*/
|
|
204
|
+
on(event, listener) {
|
|
205
|
+
if (!this._listeners.has(event)) {
|
|
206
|
+
this._listeners.set(event, new Set());
|
|
207
|
+
}
|
|
208
|
+
this._listeners.get(event).add(listener);
|
|
209
|
+
// Return unsubscribe function
|
|
210
|
+
return () => {
|
|
211
|
+
this._listeners.get(event)?.delete(listener);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Unsubscribe from chat events.
|
|
216
|
+
*/
|
|
217
|
+
off(event, listener) {
|
|
218
|
+
this._listeners.get(event)?.delete(listener);
|
|
219
|
+
}
|
|
220
|
+
// ==========================================================================
|
|
221
|
+
// Private Methods
|
|
222
|
+
// ==========================================================================
|
|
223
|
+
async executeWithToolLoop(options) {
|
|
224
|
+
let rounds = 0;
|
|
225
|
+
while (rounds < this.config.maxToolRounds) {
|
|
226
|
+
rounds++;
|
|
227
|
+
const request = await this.buildRequest(options);
|
|
228
|
+
const irResponse = await this.backend.execute(request, options?.signal);
|
|
229
|
+
const response = this.processResponse(irResponse);
|
|
230
|
+
// Add assistant message to history
|
|
231
|
+
this.addMessage(irResponse.message);
|
|
232
|
+
this.emit('message', { message: irResponse.message, response });
|
|
233
|
+
// Check for tool calls
|
|
234
|
+
if (response.toolCalls &&
|
|
235
|
+
response.toolCalls.length > 0 &&
|
|
236
|
+
this.config.autoExecuteTools &&
|
|
237
|
+
this.config.onToolCall) {
|
|
238
|
+
// Execute tools and add results to history
|
|
239
|
+
await this.executeToolCalls(response.toolCalls);
|
|
240
|
+
// Continue the loop to get the next response
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
return response;
|
|
244
|
+
}
|
|
245
|
+
throw new Error(`Max tool rounds (${this.config.maxToolRounds}) exceeded`);
|
|
246
|
+
}
|
|
247
|
+
async executeStreamWithToolLoop(options) {
|
|
248
|
+
let rounds = 0;
|
|
249
|
+
while (rounds < this.config.maxToolRounds) {
|
|
250
|
+
rounds++;
|
|
251
|
+
const request = await this.buildRequest(options);
|
|
252
|
+
// Check if backend supports streaming
|
|
253
|
+
if (!this.backend.executeStream) {
|
|
254
|
+
// Fall back to non-streaming
|
|
255
|
+
const irResponse = await this.backend.execute(request, options?.signal);
|
|
256
|
+
const response = this.processResponse(irResponse);
|
|
257
|
+
this.addMessage(irResponse.message);
|
|
258
|
+
options?.onDone?.(response);
|
|
259
|
+
return response;
|
|
260
|
+
}
|
|
261
|
+
const requestId = request.metadata.requestId;
|
|
262
|
+
options?.onStart?.({ requestId });
|
|
263
|
+
this.emit('stream-start', { requestId });
|
|
264
|
+
let accumulated = '';
|
|
265
|
+
let sequence = 0;
|
|
266
|
+
let finalResponse = null;
|
|
267
|
+
const toolInputs = new Map();
|
|
268
|
+
const stream = this.backend.executeStream(request, options?.signal);
|
|
269
|
+
for await (const chunk of stream) {
|
|
270
|
+
switch (chunk.type) {
|
|
271
|
+
case 'content': {
|
|
272
|
+
accumulated += chunk.delta;
|
|
273
|
+
sequence = chunk.sequence;
|
|
274
|
+
const event = {
|
|
275
|
+
delta: chunk.delta,
|
|
276
|
+
accumulated,
|
|
277
|
+
sequence,
|
|
278
|
+
};
|
|
279
|
+
options?.onChunk?.(event);
|
|
280
|
+
this.emit('stream-chunk', event);
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case 'tool_use': {
|
|
284
|
+
if (chunk.inputDelta) {
|
|
285
|
+
const current = toolInputs.get(chunk.id) ?? '';
|
|
286
|
+
toolInputs.set(chunk.id, current + chunk.inputDelta);
|
|
287
|
+
}
|
|
288
|
+
options?.onToolUse?.({
|
|
289
|
+
id: chunk.id,
|
|
290
|
+
name: chunk.name,
|
|
291
|
+
input: toolInputs.get(chunk.id) ?? '',
|
|
292
|
+
});
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
case 'done': {
|
|
296
|
+
const message = chunk.message ?? {
|
|
297
|
+
role: 'assistant',
|
|
298
|
+
content: accumulated,
|
|
299
|
+
};
|
|
300
|
+
finalResponse = {
|
|
301
|
+
content: accumulated,
|
|
302
|
+
message,
|
|
303
|
+
finishReason: chunk.finishReason,
|
|
304
|
+
usage: chunk.usage,
|
|
305
|
+
toolCalls: this.extractToolCalls(message),
|
|
306
|
+
requestId,
|
|
307
|
+
};
|
|
308
|
+
if (chunk.usage) {
|
|
309
|
+
this.updateUsage(chunk.usage);
|
|
310
|
+
}
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case 'error': {
|
|
314
|
+
throw new Error(chunk.error.message);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (!finalResponse) {
|
|
319
|
+
// Stream ended without done chunk - construct response from accumulated
|
|
320
|
+
finalResponse = {
|
|
321
|
+
content: accumulated,
|
|
322
|
+
message: { role: 'assistant', content: accumulated },
|
|
323
|
+
finishReason: 'stop',
|
|
324
|
+
requestId,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
// Add assistant message to history
|
|
328
|
+
this.addMessage(finalResponse.message);
|
|
329
|
+
options?.onDone?.(finalResponse);
|
|
330
|
+
this.emit('stream-done', { response: finalResponse });
|
|
331
|
+
this.emit('message', { message: finalResponse.message, response: finalResponse });
|
|
332
|
+
// Check for tool calls
|
|
333
|
+
if (finalResponse.toolCalls &&
|
|
334
|
+
finalResponse.toolCalls.length > 0 &&
|
|
335
|
+
this.config.autoExecuteTools &&
|
|
336
|
+
this.config.onToolCall) {
|
|
337
|
+
await this.executeToolCalls(finalResponse.toolCalls);
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
return finalResponse;
|
|
341
|
+
}
|
|
342
|
+
throw new Error(`Max tool rounds (${this.config.maxToolRounds}) exceeded`);
|
|
343
|
+
}
|
|
344
|
+
async executeToolCalls(toolCalls) {
|
|
345
|
+
if (!this.config.onToolCall) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
for (const tool of toolCalls) {
|
|
349
|
+
const result = await this.config.onToolCall(tool.name, tool.input, tool.id);
|
|
350
|
+
const content = typeof result === 'string' ? result : result.content;
|
|
351
|
+
const isError = typeof result === 'object' ? result.isError : false;
|
|
352
|
+
// Add tool result message
|
|
353
|
+
const toolResultMessage = {
|
|
354
|
+
role: 'tool',
|
|
355
|
+
content: [
|
|
356
|
+
{
|
|
357
|
+
type: 'tool_result',
|
|
358
|
+
toolUseId: tool.id,
|
|
359
|
+
content,
|
|
360
|
+
isError,
|
|
361
|
+
},
|
|
362
|
+
],
|
|
363
|
+
};
|
|
364
|
+
this.addMessage(toolResultMessage);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
async buildRequest(options) {
|
|
368
|
+
const messages = await this.getMessagesWithSystem();
|
|
369
|
+
return {
|
|
370
|
+
messages,
|
|
371
|
+
parameters: {
|
|
372
|
+
...this.config.defaultParameters,
|
|
373
|
+
...options?.parameters,
|
|
374
|
+
},
|
|
375
|
+
tools: this.config.tools,
|
|
376
|
+
metadata: {
|
|
377
|
+
requestId: this.generateRequestId(),
|
|
378
|
+
timestamp: Date.now(),
|
|
379
|
+
custom: options?.metadata,
|
|
380
|
+
provenance: {},
|
|
381
|
+
},
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
async getMessagesWithSystem() {
|
|
385
|
+
const messages = [...this._messages];
|
|
386
|
+
if (this.config.systemPrompt) {
|
|
387
|
+
const systemContent = typeof this.config.systemPrompt === 'function'
|
|
388
|
+
? await this.config.systemPrompt()
|
|
389
|
+
: this.config.systemPrompt;
|
|
390
|
+
// Prepend system message if not already present
|
|
391
|
+
const firstMessage = messages[0];
|
|
392
|
+
if (firstMessage?.role !== 'system') {
|
|
393
|
+
messages.unshift({
|
|
394
|
+
role: 'system',
|
|
395
|
+
content: systemContent,
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return messages;
|
|
400
|
+
}
|
|
401
|
+
processResponse(irResponse) {
|
|
402
|
+
this._requestCount++;
|
|
403
|
+
if (irResponse.usage) {
|
|
404
|
+
this.updateUsage(irResponse.usage);
|
|
405
|
+
}
|
|
406
|
+
const content = this.extractTextContent(irResponse.message);
|
|
407
|
+
const toolCalls = this.extractToolCalls(irResponse.message);
|
|
408
|
+
return {
|
|
409
|
+
content,
|
|
410
|
+
message: irResponse.message,
|
|
411
|
+
finishReason: irResponse.finishReason,
|
|
412
|
+
usage: irResponse.usage,
|
|
413
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
414
|
+
requestId: irResponse.metadata.requestId,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
extractTextContent(message) {
|
|
418
|
+
if (typeof message.content === 'string') {
|
|
419
|
+
return message.content;
|
|
420
|
+
}
|
|
421
|
+
return message.content
|
|
422
|
+
.filter((c) => c.type === 'text')
|
|
423
|
+
.map((c) => c.text)
|
|
424
|
+
.join('');
|
|
425
|
+
}
|
|
426
|
+
extractToolCalls(message) {
|
|
427
|
+
if (typeof message.content === 'string') {
|
|
428
|
+
return [];
|
|
429
|
+
}
|
|
430
|
+
return message.content
|
|
431
|
+
.filter((c) => c.type === 'tool_use')
|
|
432
|
+
.map((c) => ({
|
|
433
|
+
id: c.id,
|
|
434
|
+
name: c.name,
|
|
435
|
+
input: c.input,
|
|
436
|
+
}));
|
|
437
|
+
}
|
|
438
|
+
createUserMessage(content) {
|
|
439
|
+
return {
|
|
440
|
+
role: 'user',
|
|
441
|
+
content: typeof content === 'string' ? content : [...content],
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
updateUsage(usage) {
|
|
445
|
+
this._totalUsage.promptTokens += usage.promptTokens;
|
|
446
|
+
this._totalUsage.completionTokens += usage.completionTokens;
|
|
447
|
+
this._totalUsage.totalTokens += usage.totalTokens;
|
|
448
|
+
}
|
|
449
|
+
trimHistory() {
|
|
450
|
+
const limit = this.config.historyLimit;
|
|
451
|
+
if (this._messages.length > limit) {
|
|
452
|
+
// Keep system message if present
|
|
453
|
+
const systemMessage = this._messages[0]?.role === 'system' ? this._messages[0] : null;
|
|
454
|
+
const excess = this._messages.length - limit;
|
|
455
|
+
if (systemMessage) {
|
|
456
|
+
// Remove messages after system, keeping system
|
|
457
|
+
this._messages.splice(1, excess);
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
this._messages.splice(0, excess);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
generateRequestId() {
|
|
465
|
+
return `chat_${Date.now()}_${++this._requestIdCounter}`;
|
|
466
|
+
}
|
|
467
|
+
setLoading(loading) {
|
|
468
|
+
this._isLoading = loading;
|
|
469
|
+
this.emitStateChange();
|
|
470
|
+
}
|
|
471
|
+
setError(error) {
|
|
472
|
+
this._error = error;
|
|
473
|
+
if (error) {
|
|
474
|
+
this.emit('error', { error });
|
|
475
|
+
}
|
|
476
|
+
this.emitStateChange();
|
|
477
|
+
}
|
|
478
|
+
emit(event, data) {
|
|
479
|
+
const listeners = this._listeners.get(event);
|
|
480
|
+
if (listeners) {
|
|
481
|
+
for (const listener of listeners) {
|
|
482
|
+
try {
|
|
483
|
+
listener(data);
|
|
484
|
+
}
|
|
485
|
+
catch {
|
|
486
|
+
// Ignore listener errors
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
emitStateChange() {
|
|
492
|
+
this.emit('state-change', { state: this.state });
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
exports.Chat = Chat;
|
|
496
|
+
// ============================================================================
|
|
497
|
+
// Factory Function
|
|
498
|
+
// ============================================================================
|
|
499
|
+
/**
|
|
500
|
+
* Create a new Chat instance.
|
|
501
|
+
*
|
|
502
|
+
* @example
|
|
503
|
+
* ```typescript
|
|
504
|
+
* const chat = createChat({
|
|
505
|
+
* backend: myBackend,
|
|
506
|
+
* systemPrompt: 'You are helpful.',
|
|
507
|
+
* });
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
function createChat(config) {
|
|
511
|
+
return new Chat(config);
|
|
512
|
+
}
|
|
513
|
+
//# sourceMappingURL=chat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/chat.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAsmBH,gCAEC;AA/kBD,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,IAAI;IACE,MAAM,CAGV;IACI,OAAO,CAAc;IAEtC,qBAAqB;IACb,SAAS,GAAgB,EAAE,CAAC;IAC5B,UAAU,GAAG,KAAK,CAAC;IACnB,MAAM,GAAiB,IAAI,CAAC;IAC5B,WAAW,GAAG,EAAE,YAAY,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;IACvE,aAAa,GAAG,CAAC,CAAC;IAE1B,kBAAkB;IACV,UAAU,GAA+C,IAAI,GAAG,EAAE,CAAC;IAE3E,qCAAqC;IAC7B,iBAAiB,GAAG,CAAC,CAAC;IAE9B;;OAEG;IACH,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,MAAM;YACT,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,GAAG;YACxC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,IAAI,KAAK;YAClD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