@dexto/core 1.6.25 → 1.6.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/DextoAgent.cjs +102 -104
- package/dist/agent/DextoAgent.d.ts +11 -10
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +103 -105
- package/dist/agent/error-codes.cjs +1 -0
- package/dist/agent/error-codes.d.ts +1 -0
- package/dist/agent/error-codes.d.ts.map +1 -1
- package/dist/agent/error-codes.js +1 -0
- package/dist/agent/errors.cjs +13 -0
- package/dist/agent/errors.d.ts +6 -0
- package/dist/agent/errors.d.ts.map +1 -1
- package/dist/agent/errors.js +13 -0
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/schemas.d.ts +2 -2
- package/dist/agent/types.d.ts +11 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/approval/factory.cjs +1 -0
- package/dist/approval/factory.d.ts.map +1 -1
- package/dist/approval/factory.js +1 -0
- package/dist/approval/manager.cjs +345 -182
- package/dist/approval/manager.d.ts +45 -31
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +345 -182
- package/dist/approval/schemas.cjs +10 -0
- package/dist/approval/schemas.d.ts +305 -0
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +10 -0
- package/dist/approval/session-approval-store.cjs +91 -0
- package/dist/approval/session-approval-store.d.ts +55 -0
- package/dist/approval/session-approval-store.d.ts.map +1 -0
- package/dist/approval/session-approval-store.js +68 -0
- package/dist/events/index.cjs +210 -75
- package/dist/events/index.d.ts +44 -181
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +206 -74
- package/dist/hooks/manager.cjs +5 -2
- package/dist/hooks/manager.d.ts +2 -0
- package/dist/hooks/manager.d.ts.map +1 -1
- package/dist/hooks/manager.js +5 -2
- package/dist/hooks/types.d.ts +3 -0
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/llm/executor/turn-executor.cjs +15 -7
- package/dist/llm/executor/turn-executor.d.ts +3 -1
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +15 -7
- package/dist/llm/services/factory.cjs +10 -4
- package/dist/llm/services/factory.d.ts +2 -21
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +11 -7
- package/dist/llm/services/types.d.ts +33 -2
- package/dist/llm/services/types.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +33 -11
- package/dist/llm/services/vercel.d.ts +6 -3
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +29 -8
- package/dist/logger/default-logger-factory.d.ts +12 -12
- package/dist/logger/v2/schemas.d.ts +6 -6
- package/dist/mcp/manager.cjs +7 -2
- package/dist/mcp/manager.d.ts +3 -1
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +7 -2
- package/dist/mcp/mcp-client.cjs +71 -62
- package/dist/mcp/mcp-client.d.ts +3 -2
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +71 -62
- package/dist/mcp/schemas.d.ts +10 -10
- package/dist/resources/handlers/filesystem-handler.cjs +22 -3
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.js +22 -3
- package/dist/runtime/host-runtime.cjs +163 -0
- package/dist/runtime/host-runtime.d.ts +23 -0
- package/dist/runtime/host-runtime.d.ts.map +1 -0
- package/dist/runtime/host-runtime.js +133 -0
- package/dist/runtime/index.cjs +42 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +21 -0
- package/dist/runtime/run-context.cjs +53 -0
- package/dist/runtime/run-context.d.ts +13 -0
- package/dist/runtime/run-context.d.ts.map +1 -0
- package/dist/runtime/run-context.js +34 -0
- package/dist/session/chat-session.cjs +67 -71
- package/dist/session/chat-session.d.ts +25 -25
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +68 -72
- package/dist/session/error-codes.cjs +1 -0
- package/dist/session/error-codes.d.ts +2 -1
- package/dist/session/error-codes.d.ts.map +1 -1
- package/dist/session/error-codes.js +1 -0
- package/dist/session/errors.cjs +13 -0
- package/dist/session/errors.d.ts +6 -0
- package/dist/session/errors.d.ts.map +1 -1
- package/dist/session/errors.js +13 -0
- package/dist/session/message-queue-store.cjs +75 -0
- package/dist/session/message-queue-store.d.ts +16 -0
- package/dist/session/message-queue-store.d.ts.map +1 -0
- package/dist/session/message-queue-store.js +52 -0
- package/dist/session/message-queue.cjs +140 -46
- package/dist/session/message-queue.d.ts +18 -6
- package/dist/session/message-queue.d.ts.map +1 -1
- package/dist/session/message-queue.js +140 -46
- package/dist/session/session-manager.cjs +130 -25
- package/dist/session/session-manager.d.ts +18 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +130 -25
- package/dist/session/title-generator.cjs +9 -2
- package/dist/session/title-generator.d.ts +2 -0
- package/dist/session/title-generator.d.ts.map +1 -1
- package/dist/session/title-generator.js +9 -2
- package/dist/telemetry/decorators.cjs +75 -57
- package/dist/telemetry/decorators.d.ts +2 -0
- package/dist/telemetry/decorators.d.ts.map +1 -1
- package/dist/telemetry/decorators.js +75 -57
- package/dist/telemetry/errors.cjs +2 -2
- package/dist/telemetry/errors.js +2 -2
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +3 -1
- package/dist/telemetry/telemetry.cjs +62 -21
- package/dist/telemetry/telemetry.d.ts +14 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -1
- package/dist/telemetry/telemetry.js +62 -21
- package/dist/telemetry/utils.cjs +9 -6
- package/dist/telemetry/utils.d.ts +3 -0
- package/dist/telemetry/utils.d.ts.map +1 -1
- package/dist/telemetry/utils.js +9 -6
- package/dist/test-utils/session-state-stores.cjs +68 -0
- package/dist/test-utils/session-state-stores.js +42 -0
- package/dist/tools/session-tool-preferences-store.cjs +86 -0
- package/dist/tools/session-tool-preferences-store.d.ts +29 -0
- package/dist/tools/session-tool-preferences-store.d.ts.map +1 -0
- package/dist/tools/session-tool-preferences-store.js +63 -0
- package/dist/tools/tool-manager.cjs +223 -68
- package/dist/tools/tool-manager.d.ts +29 -9
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +223 -68
- package/dist/tools/types.d.ts +7 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/service-initializer.cjs +38 -5
- package/dist/utils/service-initializer.d.ts +11 -1
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +36 -4
- package/package.json +1 -1
|
@@ -28,16 +28,18 @@ var import_events = require("../events/index.js");
|
|
|
28
28
|
var import_types = require("../logger/v2/types.js");
|
|
29
29
|
var import_errors = require("../errors/index.js");
|
|
30
30
|
var import_error_codes = require("../hooks/error-codes.js");
|
|
31
|
+
var import_message_queue = require("./message-queue.js");
|
|
31
32
|
var import_usage_metadata = require("../llm/usage-metadata.js");
|
|
32
33
|
var import_codex_base_url = require("../llm/providers/codex-base-url.js");
|
|
34
|
+
var import_errors2 = require("./errors.js");
|
|
33
35
|
class ChatSession {
|
|
34
36
|
/**
|
|
35
37
|
* Creates a new ChatSession instance.
|
|
36
38
|
*
|
|
37
39
|
* Each session creates its own isolated services:
|
|
38
40
|
* - ConversationHistoryProvider (with session-specific storage, shared across LLM switches)
|
|
39
|
-
* -
|
|
40
|
-
* - SessionEventBus (session-local event handling
|
|
41
|
+
* - LLM service (creates its own properly-typed ContextManager internally)
|
|
42
|
+
* - SessionEventBus (session-local event handling)
|
|
41
43
|
*
|
|
42
44
|
* @param services - The shared services from the agent (state manager, prompt, client managers, etc.)
|
|
43
45
|
* @param id - Unique identifier for this session
|
|
@@ -48,7 +50,13 @@ class ChatSession {
|
|
|
48
50
|
this.id = id;
|
|
49
51
|
this.logger = logger.createChild(import_types.DextoLogComponent.SESSION);
|
|
50
52
|
this.eventBus = new import_events.SessionEventBus();
|
|
51
|
-
this.
|
|
53
|
+
this.messageQueue = new import_message_queue.MessageQueueService(
|
|
54
|
+
this.eventBus,
|
|
55
|
+
this.logger,
|
|
56
|
+
this.id,
|
|
57
|
+
this.services.messageQueueStore
|
|
58
|
+
);
|
|
59
|
+
this.setupTokenAccumulation();
|
|
52
60
|
this.logger.debug(`ChatSession ${this.id}: Created, awaiting initialization`);
|
|
53
61
|
}
|
|
54
62
|
/**
|
|
@@ -71,15 +79,16 @@ class ChatSession {
|
|
|
71
79
|
/**
|
|
72
80
|
* Handles AI model interactions, tool execution, and response generation for this session.
|
|
73
81
|
*
|
|
74
|
-
* Each session has its own
|
|
82
|
+
* Each session has its own LLM runtime instance that uses the session's
|
|
75
83
|
* ContextManager and event bus.
|
|
76
84
|
*/
|
|
77
85
|
llmService;
|
|
78
86
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
87
|
+
* Durable queued follow-up messages for this session.
|
|
88
|
+
* Reused across LLM switches so mid-task follow-ups survive service recreation.
|
|
81
89
|
*/
|
|
82
|
-
|
|
90
|
+
messageQueue;
|
|
91
|
+
activeForwarderCleanup = null;
|
|
83
92
|
/**
|
|
84
93
|
* Token accumulator listener for cleanup.
|
|
85
94
|
*/
|
|
@@ -97,27 +106,20 @@ class ChatSession {
|
|
|
97
106
|
async init() {
|
|
98
107
|
await this.initializeServices();
|
|
99
108
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* information when needed.
|
|
107
|
-
*/
|
|
108
|
-
setupEventForwarding() {
|
|
109
|
-
import_events.SessionEventNames.forEach((eventName) => {
|
|
110
|
-
const forwarder = (payload) => {
|
|
111
|
-
const payloadWithSession = payload && typeof payload === "object" ? { ...payload, sessionId: this.id } : { sessionId: this.id };
|
|
112
|
-
this.services.agentEventBus.emit(eventName, payloadWithSession);
|
|
113
|
-
};
|
|
114
|
-
this.forwarders.set(eventName, forwarder);
|
|
115
|
-
this.eventBus.on(eventName, forwarder);
|
|
109
|
+
attachRunEventForwarders(runContext) {
|
|
110
|
+
const cleanup = (0, import_events.forwardSessionEventsToAgentBus)({
|
|
111
|
+
sessionEventBus: this.eventBus,
|
|
112
|
+
agentEventBus: this.services.agentEventBus,
|
|
113
|
+
sessionId: this.id,
|
|
114
|
+
...runContext?.hostRuntime !== void 0 ? { hostRuntime: runContext.hostRuntime } : {}
|
|
116
115
|
});
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
116
|
+
this.activeForwarderCleanup = cleanup;
|
|
117
|
+
return () => {
|
|
118
|
+
if (this.activeForwarderCleanup === cleanup) {
|
|
119
|
+
this.activeForwarderCleanup = null;
|
|
120
|
+
}
|
|
121
|
+
cleanup();
|
|
122
|
+
};
|
|
121
123
|
}
|
|
122
124
|
/**
|
|
123
125
|
* Sets up token usage accumulation by listening to llm:response events.
|
|
@@ -166,33 +168,35 @@ class ChatSession {
|
|
|
166
168
|
async initializeServices() {
|
|
167
169
|
const runtimeConfig = this.services.stateManager.getRuntimeConfig(this.id);
|
|
168
170
|
const llmConfig = runtimeConfig.llm;
|
|
169
|
-
|
|
171
|
+
await this.messageQueue.initialize();
|
|
170
172
|
this.historyProvider = (0, import_factory.createDatabaseHistoryProvider)(
|
|
171
173
|
this.services.storageManager.getDatabase(),
|
|
172
174
|
this.id,
|
|
173
175
|
this.logger
|
|
174
176
|
);
|
|
175
|
-
|
|
176
|
-
this.
|
|
177
|
+
this.llmService = await this.createSessionLLMService(llmConfig, runtimeConfig.usageScopeId);
|
|
178
|
+
this.logger.debug(`ChatSession ${this.id}: Services initialized with storage`);
|
|
179
|
+
}
|
|
180
|
+
async createSessionLLMService(llmConfig, usageScopeId) {
|
|
181
|
+
const workspace = await this.services.workspaceManager?.getWorkspace();
|
|
182
|
+
const options = {
|
|
183
|
+
usageScopeId,
|
|
184
|
+
compactionStrategy: this.services.compactionStrategy,
|
|
185
|
+
...workspace?.path !== void 0 && { cwd: workspace.path },
|
|
186
|
+
messageQueue: this.messageQueue
|
|
187
|
+
};
|
|
188
|
+
return (0, import_factory2.createLLMService)(
|
|
177
189
|
llmConfig,
|
|
178
190
|
this.services.toolManager,
|
|
179
191
|
this.services.systemPromptManager,
|
|
180
192
|
this.historyProvider,
|
|
181
|
-
// Pass history provider for service to use
|
|
182
193
|
this.eventBus,
|
|
183
|
-
// Use session event bus
|
|
184
194
|
this.id,
|
|
185
195
|
this.services.resourceManager,
|
|
186
|
-
// Pass ResourceManager for blob storage
|
|
187
196
|
this.logger,
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
usageScopeId: runtimeConfig.usageScopeId,
|
|
191
|
-
compactionStrategy,
|
|
192
|
-
cwd: workspace?.path
|
|
193
|
-
}
|
|
197
|
+
options,
|
|
198
|
+
this.services.languageModelFactory
|
|
194
199
|
);
|
|
195
|
-
this.logger.debug(`ChatSession ${this.id}: Services initialized with storage`);
|
|
196
200
|
}
|
|
197
201
|
/**
|
|
198
202
|
* Saves a blocked interaction to history when a plugin blocks execution.
|
|
@@ -261,8 +265,12 @@ class ChatSession {
|
|
|
261
265
|
this.logger.debug(
|
|
262
266
|
`Streaming session ${this.id} | textParts=${textParts.length} | images=${imageParts.length} | files=${fileParts.length}`
|
|
263
267
|
);
|
|
268
|
+
if (this.isBusy()) {
|
|
269
|
+
throw import_errors2.SessionError.busy(this.id);
|
|
270
|
+
}
|
|
264
271
|
this.currentRunController = new AbortController();
|
|
265
272
|
const signal = options?.signal ? this.combineSignals(options.signal, this.currentRunController.signal) : this.currentRunController.signal;
|
|
273
|
+
const detachForwarders = this.attachRunEventForwarders(options?.runContext);
|
|
266
274
|
try {
|
|
267
275
|
const textContent = textParts.map((p) => p.text).join("\n");
|
|
268
276
|
const firstImage = imageParts[0];
|
|
@@ -292,6 +300,7 @@ class ChatSession {
|
|
|
292
300
|
mcpManager: this.services.mcpManager,
|
|
293
301
|
toolManager: this.services.toolManager,
|
|
294
302
|
stateManager: this.services.stateManager,
|
|
303
|
+
...options?.runContext !== void 0 && { runContext: options.runContext },
|
|
295
304
|
sessionId: this.id,
|
|
296
305
|
abortSignal: signal
|
|
297
306
|
}
|
|
@@ -301,7 +310,10 @@ class ChatSession {
|
|
|
301
310
|
modifiedParts = modifiedParts.filter((p) => p.type !== "text");
|
|
302
311
|
modifiedParts.unshift({ type: "text", text: modifiedBeforePayload.text });
|
|
303
312
|
}
|
|
304
|
-
const streamResult = await this.llmService.stream(modifiedParts, {
|
|
313
|
+
const streamResult = await this.llmService.stream(modifiedParts, {
|
|
314
|
+
signal,
|
|
315
|
+
...options?.runContext !== void 0 && { runContext: options.runContext }
|
|
316
|
+
});
|
|
305
317
|
const llmConfig = this.services.stateManager.getLLMConfig(this.id);
|
|
306
318
|
const beforeResponsePayload = {
|
|
307
319
|
content: streamResult.text,
|
|
@@ -317,6 +329,7 @@ class ChatSession {
|
|
|
317
329
|
mcpManager: this.services.mcpManager,
|
|
318
330
|
toolManager: this.services.toolManager,
|
|
319
331
|
stateManager: this.services.stateManager,
|
|
332
|
+
...options?.runContext !== void 0 && { runContext: options.runContext },
|
|
320
333
|
sessionId: this.id,
|
|
321
334
|
abortSignal: signal
|
|
322
335
|
}
|
|
@@ -372,6 +385,7 @@ class ChatSession {
|
|
|
372
385
|
);
|
|
373
386
|
throw error;
|
|
374
387
|
} finally {
|
|
388
|
+
detachForwarders();
|
|
375
389
|
this.currentRunController = null;
|
|
376
390
|
}
|
|
377
391
|
}
|
|
@@ -448,9 +462,9 @@ class ChatSession {
|
|
|
448
462
|
return this.llmService.getContextManager();
|
|
449
463
|
}
|
|
450
464
|
/**
|
|
451
|
-
* Gets the session's
|
|
465
|
+
* Gets the session's LLM service instance.
|
|
452
466
|
*
|
|
453
|
-
* @returns The
|
|
467
|
+
* @returns The session LLM service for this session
|
|
454
468
|
*/
|
|
455
469
|
getLLMService() {
|
|
456
470
|
return this.llmService;
|
|
@@ -477,26 +491,10 @@ class ChatSession {
|
|
|
477
491
|
async switchLLM(newLLMConfig) {
|
|
478
492
|
try {
|
|
479
493
|
const runtimeConfig = this.services.stateManager.getRuntimeConfig(this.id);
|
|
480
|
-
|
|
481
|
-
const compactionStrategy = this.services.compactionStrategy;
|
|
482
|
-
const newLLMService = (0, import_factory2.createLLMService)(
|
|
494
|
+
this.llmService = await this.createSessionLLMService(
|
|
483
495
|
newLLMConfig,
|
|
484
|
-
|
|
485
|
-
this.services.systemPromptManager,
|
|
486
|
-
this.historyProvider,
|
|
487
|
-
// Pass the SAME history provider - preserves conversation!
|
|
488
|
-
this.eventBus,
|
|
489
|
-
// Use session event bus
|
|
490
|
-
this.id,
|
|
491
|
-
this.services.resourceManager,
|
|
492
|
-
this.logger,
|
|
493
|
-
{
|
|
494
|
-
usageScopeId: runtimeConfig.usageScopeId,
|
|
495
|
-
compactionStrategy,
|
|
496
|
-
cwd: workspace?.path
|
|
497
|
-
}
|
|
496
|
+
runtimeConfig.usageScopeId
|
|
498
497
|
);
|
|
499
|
-
this.llmService = newLLMService;
|
|
500
498
|
this.logger.info(
|
|
501
499
|
`ChatSession ${this.id}: LLM switched to ${newLLMConfig.provider}/${newLLMConfig.model}`
|
|
502
500
|
);
|
|
@@ -538,10 +536,8 @@ class ChatSession {
|
|
|
538
536
|
*/
|
|
539
537
|
dispose() {
|
|
540
538
|
this.logger.debug(`Disposing session ${this.id} - cleaning up event listeners`);
|
|
541
|
-
this.
|
|
542
|
-
|
|
543
|
-
});
|
|
544
|
-
this.forwarders.clear();
|
|
539
|
+
this.activeForwarderCleanup?.();
|
|
540
|
+
this.activeForwarderCleanup = null;
|
|
545
541
|
if (this.tokenAccumulatorListener) {
|
|
546
542
|
this.eventBus.off("llm:response", this.tokenAccumulatorListener);
|
|
547
543
|
this.tokenAccumulatorListener = null;
|
|
@@ -562,8 +558,8 @@ class ChatSession {
|
|
|
562
558
|
* @param message The user message to queue
|
|
563
559
|
* @returns Queue position and message ID
|
|
564
560
|
*/
|
|
565
|
-
queueMessage(message) {
|
|
566
|
-
return this.llmService.getMessageQueue().enqueue(message);
|
|
561
|
+
async queueMessage(message) {
|
|
562
|
+
return await this.llmService.getMessageQueue().enqueue(message);
|
|
567
563
|
}
|
|
568
564
|
/**
|
|
569
565
|
* Get all messages currently in the queue.
|
|
@@ -577,17 +573,17 @@ class ChatSession {
|
|
|
577
573
|
* @param id Message ID to remove
|
|
578
574
|
* @returns true if message was found and removed; false otherwise
|
|
579
575
|
*/
|
|
580
|
-
removeQueuedMessage(id) {
|
|
581
|
-
return this.llmService.getMessageQueue().remove(id);
|
|
576
|
+
async removeQueuedMessage(id) {
|
|
577
|
+
return await this.llmService.getMessageQueue().remove(id);
|
|
582
578
|
}
|
|
583
579
|
/**
|
|
584
580
|
* Clear all queued messages.
|
|
585
581
|
* @returns Number of messages that were cleared
|
|
586
582
|
*/
|
|
587
|
-
clearMessageQueue() {
|
|
583
|
+
async clearMessageQueue() {
|
|
588
584
|
const queue = this.llmService.getMessageQueue();
|
|
589
585
|
const count = queue.pendingCount();
|
|
590
|
-
queue.clear();
|
|
586
|
+
await queue.clear();
|
|
591
587
|
return count;
|
|
592
588
|
}
|
|
593
589
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ContextManager } from '../context/index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LanguageModelFactory } from '../llm/services/types.js';
|
|
3
3
|
import type { SystemPromptManager } from '../systemPrompt/manager.js';
|
|
4
4
|
import type { ToolManager } from '../tools/tool-manager.js';
|
|
5
5
|
import type { ValidatedLLMConfig } from '../llm/schemas.js';
|
|
@@ -10,9 +10,12 @@ import type { MCPManager } from '../mcp/manager.js';
|
|
|
10
10
|
import { SessionEventBus, AgentEventBus } from '../events/index.js';
|
|
11
11
|
import type { Logger } from '../logger/v2/types.js';
|
|
12
12
|
import type { InternalMessage } from '../context/types.js';
|
|
13
|
-
import type
|
|
13
|
+
import { type UserMessageInput } from './message-queue.js';
|
|
14
|
+
import type { MessageQueueStore } from './message-queue-store.js';
|
|
14
15
|
import type { ContentInput } from '../agent/types.js';
|
|
15
16
|
import type { CompactionStrategy } from '../context/compaction/types.js';
|
|
17
|
+
import type { VercelLLMService } from '../llm/services/vercel.js';
|
|
18
|
+
import type { AgentRunContext } from '../runtime/run-context.js';
|
|
16
19
|
/**
|
|
17
20
|
* Represents an isolated conversation session within a Dexto agent.
|
|
18
21
|
*
|
|
@@ -25,7 +28,7 @@ import type { CompactionStrategy } from '../context/compaction/types.js';
|
|
|
25
28
|
* The ChatSession acts as a lightweight wrapper around core Dexto services, providing
|
|
26
29
|
* session-specific instances of:
|
|
27
30
|
* - **ContextManager**: Handles conversation history and message formatting
|
|
28
|
-
* - **
|
|
31
|
+
* - **VercelLLMService**: Manages AI model interactions and tool execution
|
|
29
32
|
* - **TypedEventEmitter**: Provides session-scoped event handling
|
|
30
33
|
*
|
|
31
34
|
* ## Event Handling
|
|
@@ -55,7 +58,7 @@ import type { CompactionStrategy } from '../context/compaction/types.js';
|
|
|
55
58
|
*
|
|
56
59
|
* @see {@link SessionManager} for session lifecycle management
|
|
57
60
|
* @see {@link ContextManager} for conversation history management
|
|
58
|
-
* @see {@link
|
|
61
|
+
* @see {@link createLLMService} for the default AI model integration path
|
|
59
62
|
*/
|
|
60
63
|
export declare class ChatSession {
|
|
61
64
|
private services;
|
|
@@ -80,15 +83,16 @@ export declare class ChatSession {
|
|
|
80
83
|
/**
|
|
81
84
|
* Handles AI model interactions, tool execution, and response generation for this session.
|
|
82
85
|
*
|
|
83
|
-
* Each session has its own
|
|
86
|
+
* Each session has its own LLM runtime instance that uses the session's
|
|
84
87
|
* ContextManager and event bus.
|
|
85
88
|
*/
|
|
86
89
|
private llmService;
|
|
87
90
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
91
|
+
* Durable queued follow-up messages for this session.
|
|
92
|
+
* Reused across LLM switches so mid-task follow-ups survive service recreation.
|
|
90
93
|
*/
|
|
91
|
-
private
|
|
94
|
+
private messageQueue;
|
|
95
|
+
private activeForwarderCleanup;
|
|
92
96
|
/**
|
|
93
97
|
* Token accumulator listener for cleanup.
|
|
94
98
|
*/
|
|
@@ -104,8 +108,8 @@ export declare class ChatSession {
|
|
|
104
108
|
*
|
|
105
109
|
* Each session creates its own isolated services:
|
|
106
110
|
* - ConversationHistoryProvider (with session-specific storage, shared across LLM switches)
|
|
107
|
-
* -
|
|
108
|
-
* - SessionEventBus (session-local event handling
|
|
111
|
+
* - LLM service (creates its own properly-typed ContextManager internally)
|
|
112
|
+
* - SessionEventBus (session-local event handling)
|
|
109
113
|
*
|
|
110
114
|
* @param services - The shared services from the agent (state manager, prompt, client managers, etc.)
|
|
111
115
|
* @param id - Unique identifier for this session
|
|
@@ -121,6 +125,8 @@ export declare class ChatSession {
|
|
|
121
125
|
hookManager: HookManager;
|
|
122
126
|
mcpManager: MCPManager;
|
|
123
127
|
sessionManager: import('./session-manager.js').SessionManager;
|
|
128
|
+
messageQueueStore: Pick<MessageQueueStore, 'load' | 'save' | 'delete'>;
|
|
129
|
+
languageModelFactory?: LanguageModelFactory;
|
|
124
130
|
workspaceManager?: import('../workspace/manager.js').WorkspaceManager;
|
|
125
131
|
compactionStrategy: CompactionStrategy | null;
|
|
126
132
|
}, id: string, logger: Logger);
|
|
@@ -129,15 +135,7 @@ export declare class ChatSession {
|
|
|
129
135
|
* This must be called after construction to set up the storage-backed services.
|
|
130
136
|
*/
|
|
131
137
|
init(): Promise<void>;
|
|
132
|
-
|
|
133
|
-
* Sets up event forwarding from session bus to global agent bus.
|
|
134
|
-
*
|
|
135
|
-
* All session events are automatically forwarded to the global bus with the same
|
|
136
|
-
* event names, but with session context added to the payload. This allows the app
|
|
137
|
-
* layer to continue listening to standard events while having access to session
|
|
138
|
-
* information when needed.
|
|
139
|
-
*/
|
|
140
|
-
private setupEventForwarding;
|
|
138
|
+
private attachRunEventForwarders;
|
|
141
139
|
/**
|
|
142
140
|
* Sets up token usage accumulation by listening to llm:response events.
|
|
143
141
|
* Accumulates token usage and cost to session metadata for /stats tracking.
|
|
@@ -147,6 +145,7 @@ export declare class ChatSession {
|
|
|
147
145
|
* Initializes session-specific services.
|
|
148
146
|
*/
|
|
149
147
|
private initializeServices;
|
|
148
|
+
private createSessionLLMService;
|
|
150
149
|
/**
|
|
151
150
|
* Saves a blocked interaction to history when a plugin blocks execution.
|
|
152
151
|
* This ensures that even when a plugin blocks execution (e.g., due to abusive language),
|
|
@@ -182,6 +181,7 @@ export declare class ChatSession {
|
|
|
182
181
|
*/
|
|
183
182
|
stream(content: ContentInput, options?: {
|
|
184
183
|
signal?: AbortSignal;
|
|
184
|
+
runContext?: AgentRunContext;
|
|
185
185
|
}): Promise<{
|
|
186
186
|
text: string;
|
|
187
187
|
}>;
|
|
@@ -240,9 +240,9 @@ export declare class ChatSession {
|
|
|
240
240
|
*/
|
|
241
241
|
getContextManager(): ContextManager<unknown>;
|
|
242
242
|
/**
|
|
243
|
-
* Gets the session's
|
|
243
|
+
* Gets the session's LLM service instance.
|
|
244
244
|
*
|
|
245
|
-
* @returns The
|
|
245
|
+
* @returns The session LLM service for this session
|
|
246
246
|
*/
|
|
247
247
|
getLLMService(): VercelLLMService;
|
|
248
248
|
/**
|
|
@@ -291,11 +291,11 @@ export declare class ChatSession {
|
|
|
291
291
|
* @param message The user message to queue
|
|
292
292
|
* @returns Queue position and message ID
|
|
293
293
|
*/
|
|
294
|
-
queueMessage(message: UserMessageInput): {
|
|
294
|
+
queueMessage(message: UserMessageInput): Promise<{
|
|
295
295
|
queued: true;
|
|
296
296
|
position: number;
|
|
297
297
|
id: string;
|
|
298
|
-
}
|
|
298
|
+
}>;
|
|
299
299
|
/**
|
|
300
300
|
* Get all messages currently in the queue.
|
|
301
301
|
* @returns Array of queued messages
|
|
@@ -306,12 +306,12 @@ export declare class ChatSession {
|
|
|
306
306
|
* @param id Message ID to remove
|
|
307
307
|
* @returns true if message was found and removed; false otherwise
|
|
308
308
|
*/
|
|
309
|
-
removeQueuedMessage(id: string): boolean
|
|
309
|
+
removeQueuedMessage(id: string): Promise<boolean>;
|
|
310
310
|
/**
|
|
311
311
|
* Clear all queued messages.
|
|
312
312
|
* @returns Number of messages that were cleared
|
|
313
313
|
*/
|
|
314
|
-
clearMessageQueue(): number
|
|
314
|
+
clearMessageQueue(): Promise<number>;
|
|
315
315
|
/**
|
|
316
316
|
* Cancel the currently running turn for this session, if any.
|
|
317
317
|
* Returns true if a run was in progress and was signaled to abort.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../../src/session/chat-session.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"chat-session.d.ts","sourceRoot":"","sources":["../../src/session/chat-session.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,KAAK,EAA2B,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC9F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OA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