@dexto/core 1.6.26 → 1.7.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/dist/agent/DextoAgent.cjs +75 -90
- package/dist/agent/DextoAgent.d.ts +7 -7
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +76 -91
- 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.cjs +5 -5
- package/dist/agent/schemas.d.ts +69 -980
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +5 -5
- 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 +19 -6
- package/dist/approval/manager.d.ts +6 -0
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +19 -6
- package/dist/approval/schemas.cjs +16 -6
- package/dist/approval/schemas.d.ts +373 -1044
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +16 -6
- package/dist/approval/session-approval-store.cjs +1 -1
- package/dist/approval/session-approval-store.d.ts +12 -30
- package/dist/approval/session-approval-store.d.ts.map +1 -1
- package/dist/approval/session-approval-store.js +1 -1
- 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 +8 -4
- 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 +8 -4
- package/dist/llm/providers/local/schemas.d.ts +102 -262
- package/dist/llm/providers/local/schemas.d.ts.map +1 -1
- package/dist/llm/registry/index.d.ts +5 -3
- package/dist/llm/registry/index.d.ts.map +1 -1
- package/dist/llm/resolver.cjs +0 -1
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +0 -1
- package/dist/llm/schemas.d.ts +95 -199
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +29 -6
- package/dist/llm/services/vercel.d.ts +3 -0
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +27 -5
- package/dist/logger/default-logger-factory.d.ts +28 -256
- package/dist/logger/default-logger-factory.d.ts.map +1 -1
- package/dist/logger/v2/schemas.d.ts +18 -120
- package/dist/logger/v2/schemas.d.ts.map +1 -1
- 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.cjs +4 -4
- package/dist/mcp/schemas.d.ts +77 -270
- package/dist/mcp/schemas.d.ts.map +1 -1
- package/dist/mcp/schemas.js +4 -4
- package/dist/memory/schemas.d.ts +37 -117
- package/dist/memory/schemas.d.ts.map +1 -1
- package/dist/prompts/schemas.d.ts +46 -190
- package/dist/prompts/schemas.d.ts.map +1 -1
- 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/resources/schemas.d.ts +14 -68
- package/dist/resources/schemas.d.ts.map +1 -1
- package/dist/runtime/host-runtime.cjs +163 -0
- package/dist/runtime/host-runtime.d.ts +19 -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 +30 -32
- package/dist/session/chat-session.d.ts +5 -15
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +31 -33
- 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/schemas.d.ts +1 -7
- package/dist/session/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.cjs +2 -10
- package/dist/systemPrompt/schemas.d.ts +53 -343
- package/dist/systemPrompt/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.js +2 -10
- 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/schemas.cjs +1 -1
- package/dist/telemetry/schemas.d.ts +9 -44
- package/dist/telemetry/schemas.d.ts.map +1 -1
- package/dist/telemetry/schemas.js +1 -1
- 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/tools/schemas.cjs +1 -1
- package/dist/tools/schemas.d.ts +19 -62
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +1 -1
- package/dist/tools/session-tool-preferences-store.d.ts +3 -9
- package/dist/tools/session-tool-preferences-store.d.ts.map +1 -1
- package/dist/tools/tool-manager.cjs +92 -36
- package/dist/tools/tool-manager.d.ts +12 -3
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +92 -36
- package/dist/tools/types.d.ts +7 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/result.cjs +11 -8
- package/dist/utils/result.d.ts +6 -6
- package/dist/utils/result.d.ts.map +1 -1
- package/dist/utils/result.js +12 -9
- package/dist/utils/schema.cjs +6 -2
- package/dist/utils/schema.d.ts +2 -7
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +6 -2
- package/dist/utils/zod-schema-converter.cjs +66 -66
- package/dist/utils/zod-schema-converter.d.ts +3 -2
- package/dist/utils/zod-schema-converter.d.ts.map +1 -1
- package/dist/utils/zod-schema-converter.js +66 -66
- package/package.json +4 -5
|
@@ -15,6 +15,7 @@ import type { MessageQueueStore } from './message-queue-store.js';
|
|
|
15
15
|
import type { ContentInput } from '../agent/types.js';
|
|
16
16
|
import type { CompactionStrategy } from '../context/compaction/types.js';
|
|
17
17
|
import type { VercelLLMService } from '../llm/services/vercel.js';
|
|
18
|
+
import type { AgentRunContext } from '../runtime/run-context.js';
|
|
18
19
|
/**
|
|
19
20
|
* Represents an isolated conversation session within a Dexto agent.
|
|
20
21
|
*
|
|
@@ -91,11 +92,7 @@ export declare class ChatSession {
|
|
|
91
92
|
* Reused across LLM switches so mid-task follow-ups survive service recreation.
|
|
92
93
|
*/
|
|
93
94
|
private messageQueue;
|
|
94
|
-
|
|
95
|
-
* Map of event forwarder functions for cleanup.
|
|
96
|
-
* Stores the bound functions so they can be removed from the event bus.
|
|
97
|
-
*/
|
|
98
|
-
private forwarders;
|
|
95
|
+
private activeForwarderCleanup;
|
|
99
96
|
/**
|
|
100
97
|
* Token accumulator listener for cleanup.
|
|
101
98
|
*/
|
|
@@ -112,7 +109,7 @@ export declare class ChatSession {
|
|
|
112
109
|
* Each session creates its own isolated services:
|
|
113
110
|
* - ConversationHistoryProvider (with session-specific storage, shared across LLM switches)
|
|
114
111
|
* - LLM service (creates its own properly-typed ContextManager internally)
|
|
115
|
-
* - SessionEventBus (session-local event handling
|
|
112
|
+
* - SessionEventBus (session-local event handling)
|
|
116
113
|
*
|
|
117
114
|
* @param services - The shared services from the agent (state manager, prompt, client managers, etc.)
|
|
118
115
|
* @param id - Unique identifier for this session
|
|
@@ -138,15 +135,7 @@ export declare class ChatSession {
|
|
|
138
135
|
* This must be called after construction to set up the storage-backed services.
|
|
139
136
|
*/
|
|
140
137
|
init(): Promise<void>;
|
|
141
|
-
|
|
142
|
-
* Sets up event forwarding from session bus to global agent bus.
|
|
143
|
-
*
|
|
144
|
-
* All session events are automatically forwarded to the global bus with the same
|
|
145
|
-
* event names, but with session context added to the payload. This allows the app
|
|
146
|
-
* layer to continue listening to standard events while having access to session
|
|
147
|
-
* information when needed.
|
|
148
|
-
*/
|
|
149
|
-
private setupEventForwarding;
|
|
138
|
+
private attachRunEventForwarders;
|
|
150
139
|
/**
|
|
151
140
|
* Sets up token usage accumulation by listening to llm:response events.
|
|
152
141
|
* Accumulates token usage and cost to session metadata for /stats tracking.
|
|
@@ -192,6 +181,7 @@ export declare class ChatSession {
|
|
|
192
181
|
*/
|
|
193
182
|
stream(content: ContentInput, options?: {
|
|
194
183
|
signal?: AbortSignal;
|
|
184
|
+
runContext?: AgentRunContext;
|
|
195
185
|
}): Promise<{
|
|
196
186
|
text: string;
|
|
197
187
|
}>;
|
|
@@ -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,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,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EACH,eAAe,EACf,aAAa,
|
|
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,EAA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B,IAAI,cAAc,CAAC,OAAO,CAAC;IAInD;;;;OAIG;IACI,aAAa,IAAI,gBAAgB;IAIxC;;;;;;;;;;;;;;;;;;OAkBG;IACU,SAAS,CAAC,YAAY,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBvE;;;;OAIG;IACU,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBrC;;;;;;OAMG;IACI,OAAO,IAAI,IAAI;IAetB;;;OAGG;IACI,MAAM,IAAI,OAAO;IAIxB;;;;;;OAMG;IACU,YAAY,CACrB,OAAO,EAAE,gBAAgB,GAC1B,OAAO,CAAC;QAAE,MAAM,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAI1D;;;OAGG;IACI,iBAAiB,IAAI,OAAO,YAAY,EAAE,aAAa,EAAE;IAIhE;;;;OAIG;IACU,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI9D;;;OAGG;IACU,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAOjD;;;OAGG;IACI,MAAM,IAAI,OAAO;CAa3B"}
|
|
@@ -4,7 +4,7 @@ import { createDatabaseHistoryProvider } from "./history/factory.js";
|
|
|
4
4
|
import { createLLMService } from "../llm/services/factory.js";
|
|
5
5
|
import {
|
|
6
6
|
SessionEventBus,
|
|
7
|
-
|
|
7
|
+
forwardSessionEventsToAgentBus
|
|
8
8
|
} from "../events/index.js";
|
|
9
9
|
import { DextoLogComponent } from "../logger/v2/types.js";
|
|
10
10
|
import { DextoRuntimeError, ErrorScope, ErrorType } from "../errors/index.js";
|
|
@@ -12,6 +12,7 @@ import { HookErrorCode } from "../hooks/error-codes.js";
|
|
|
12
12
|
import { MessageQueueService } from "./message-queue.js";
|
|
13
13
|
import { getUsagePricingMetadata, hasMeaningfulTokenUsage } from "../llm/usage-metadata.js";
|
|
14
14
|
import { parseCodexBaseURL } from "../llm/providers/codex-base-url.js";
|
|
15
|
+
import { SessionError } from "./errors.js";
|
|
15
16
|
class ChatSession {
|
|
16
17
|
/**
|
|
17
18
|
* Creates a new ChatSession instance.
|
|
@@ -19,7 +20,7 @@ class ChatSession {
|
|
|
19
20
|
* Each session creates its own isolated services:
|
|
20
21
|
* - ConversationHistoryProvider (with session-specific storage, shared across LLM switches)
|
|
21
22
|
* - LLM service (creates its own properly-typed ContextManager internally)
|
|
22
|
-
* - SessionEventBus (session-local event handling
|
|
23
|
+
* - SessionEventBus (session-local event handling)
|
|
23
24
|
*
|
|
24
25
|
* @param services - The shared services from the agent (state manager, prompt, client managers, etc.)
|
|
25
26
|
* @param id - Unique identifier for this session
|
|
@@ -36,7 +37,7 @@ class ChatSession {
|
|
|
36
37
|
this.id,
|
|
37
38
|
this.services.messageQueueStore
|
|
38
39
|
);
|
|
39
|
-
this.
|
|
40
|
+
this.setupTokenAccumulation();
|
|
40
41
|
this.logger.debug(`ChatSession ${this.id}: Created, awaiting initialization`);
|
|
41
42
|
}
|
|
42
43
|
/**
|
|
@@ -68,11 +69,7 @@ class ChatSession {
|
|
|
68
69
|
* Reused across LLM switches so mid-task follow-ups survive service recreation.
|
|
69
70
|
*/
|
|
70
71
|
messageQueue;
|
|
71
|
-
|
|
72
|
-
* Map of event forwarder functions for cleanup.
|
|
73
|
-
* Stores the bound functions so they can be removed from the event bus.
|
|
74
|
-
*/
|
|
75
|
-
forwarders = /* @__PURE__ */ new Map();
|
|
72
|
+
activeForwarderCleanup = null;
|
|
76
73
|
/**
|
|
77
74
|
* Token accumulator listener for cleanup.
|
|
78
75
|
*/
|
|
@@ -90,27 +87,20 @@ class ChatSession {
|
|
|
90
87
|
async init() {
|
|
91
88
|
await this.initializeServices();
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
* information when needed.
|
|
100
|
-
*/
|
|
101
|
-
setupEventForwarding() {
|
|
102
|
-
SessionEventNames.forEach((eventName) => {
|
|
103
|
-
const forwarder = (payload) => {
|
|
104
|
-
const payloadWithSession = payload && typeof payload === "object" ? { ...payload, sessionId: this.id } : { sessionId: this.id };
|
|
105
|
-
this.services.agentEventBus.emit(eventName, payloadWithSession);
|
|
106
|
-
};
|
|
107
|
-
this.forwarders.set(eventName, forwarder);
|
|
108
|
-
this.eventBus.on(eventName, forwarder);
|
|
90
|
+
attachRunEventForwarders(runContext) {
|
|
91
|
+
const cleanup = forwardSessionEventsToAgentBus({
|
|
92
|
+
sessionEventBus: this.eventBus,
|
|
93
|
+
agentEventBus: this.services.agentEventBus,
|
|
94
|
+
sessionId: this.id,
|
|
95
|
+
...runContext?.hostRuntime !== void 0 ? { hostRuntime: runContext.hostRuntime } : {}
|
|
109
96
|
});
|
|
110
|
-
this.
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
97
|
+
this.activeForwarderCleanup = cleanup;
|
|
98
|
+
return () => {
|
|
99
|
+
if (this.activeForwarderCleanup === cleanup) {
|
|
100
|
+
this.activeForwarderCleanup = null;
|
|
101
|
+
}
|
|
102
|
+
cleanup();
|
|
103
|
+
};
|
|
114
104
|
}
|
|
115
105
|
/**
|
|
116
106
|
* Sets up token usage accumulation by listening to llm:response events.
|
|
@@ -256,8 +246,12 @@ class ChatSession {
|
|
|
256
246
|
this.logger.debug(
|
|
257
247
|
`Streaming session ${this.id} | textParts=${textParts.length} | images=${imageParts.length} | files=${fileParts.length}`
|
|
258
248
|
);
|
|
249
|
+
if (this.isBusy()) {
|
|
250
|
+
throw SessionError.busy(this.id);
|
|
251
|
+
}
|
|
259
252
|
this.currentRunController = new AbortController();
|
|
260
253
|
const signal = options?.signal ? this.combineSignals(options.signal, this.currentRunController.signal) : this.currentRunController.signal;
|
|
254
|
+
const detachForwarders = this.attachRunEventForwarders(options?.runContext);
|
|
261
255
|
try {
|
|
262
256
|
const textContent = textParts.map((p) => p.text).join("\n");
|
|
263
257
|
const firstImage = imageParts[0];
|
|
@@ -287,6 +281,7 @@ class ChatSession {
|
|
|
287
281
|
mcpManager: this.services.mcpManager,
|
|
288
282
|
toolManager: this.services.toolManager,
|
|
289
283
|
stateManager: this.services.stateManager,
|
|
284
|
+
...options?.runContext !== void 0 && { runContext: options.runContext },
|
|
290
285
|
sessionId: this.id,
|
|
291
286
|
abortSignal: signal
|
|
292
287
|
}
|
|
@@ -296,7 +291,10 @@ class ChatSession {
|
|
|
296
291
|
modifiedParts = modifiedParts.filter((p) => p.type !== "text");
|
|
297
292
|
modifiedParts.unshift({ type: "text", text: modifiedBeforePayload.text });
|
|
298
293
|
}
|
|
299
|
-
const streamResult = await this.llmService.stream(modifiedParts, {
|
|
294
|
+
const streamResult = await this.llmService.stream(modifiedParts, {
|
|
295
|
+
signal,
|
|
296
|
+
...options?.runContext !== void 0 && { runContext: options.runContext }
|
|
297
|
+
});
|
|
300
298
|
const llmConfig = this.services.stateManager.getLLMConfig(this.id);
|
|
301
299
|
const beforeResponsePayload = {
|
|
302
300
|
content: streamResult.text,
|
|
@@ -312,6 +310,7 @@ class ChatSession {
|
|
|
312
310
|
mcpManager: this.services.mcpManager,
|
|
313
311
|
toolManager: this.services.toolManager,
|
|
314
312
|
stateManager: this.services.stateManager,
|
|
313
|
+
...options?.runContext !== void 0 && { runContext: options.runContext },
|
|
315
314
|
sessionId: this.id,
|
|
316
315
|
abortSignal: signal
|
|
317
316
|
}
|
|
@@ -367,6 +366,7 @@ class ChatSession {
|
|
|
367
366
|
);
|
|
368
367
|
throw error;
|
|
369
368
|
} finally {
|
|
369
|
+
detachForwarders();
|
|
370
370
|
this.currentRunController = null;
|
|
371
371
|
}
|
|
372
372
|
}
|
|
@@ -517,10 +517,8 @@ class ChatSession {
|
|
|
517
517
|
*/
|
|
518
518
|
dispose() {
|
|
519
519
|
this.logger.debug(`Disposing session ${this.id} - cleaning up event listeners`);
|
|
520
|
-
this.
|
|
521
|
-
|
|
522
|
-
});
|
|
523
|
-
this.forwarders.clear();
|
|
520
|
+
this.activeForwarderCleanup?.();
|
|
521
|
+
this.activeForwarderCleanup = null;
|
|
524
522
|
if (this.tokenAccumulatorListener) {
|
|
525
523
|
this.eventBus.off("llm:response", this.tokenAccumulatorListener);
|
|
526
524
|
this.tokenAccumulatorListener = null;
|
|
@@ -27,6 +27,7 @@ var SessionErrorCode = /* @__PURE__ */ ((SessionErrorCode2) => {
|
|
|
27
27
|
SessionErrorCode2["SESSION_MAX_SESSIONS_EXCEEDED"] = "session_max_sessions_exceeded";
|
|
28
28
|
SessionErrorCode2["SESSION_STORAGE_FAILED"] = "session_storage_failed";
|
|
29
29
|
SessionErrorCode2["SESSION_RESET_FAILED"] = "session_reset_failed";
|
|
30
|
+
SessionErrorCode2["SESSION_BUSY"] = "session_busy";
|
|
30
31
|
return SessionErrorCode2;
|
|
31
32
|
})(SessionErrorCode || {});
|
|
32
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -7,6 +7,7 @@ export declare enum SessionErrorCode {
|
|
|
7
7
|
SESSION_INITIALIZATION_FAILED = "session_initialization_failed",
|
|
8
8
|
SESSION_MAX_SESSIONS_EXCEEDED = "session_max_sessions_exceeded",
|
|
9
9
|
SESSION_STORAGE_FAILED = "session_storage_failed",
|
|
10
|
-
SESSION_RESET_FAILED = "session_reset_failed"
|
|
10
|
+
SESSION_RESET_FAILED = "session_reset_failed",
|
|
11
|
+
SESSION_BUSY = "session_busy"
|
|
11
12
|
}
|
|
12
13
|
//# sourceMappingURL=error-codes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/session/error-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,gBAAgB;IAExB,iBAAiB,sBAAsB;IACvC,6BAA6B,kCAAkC;IAC/D,6BAA6B,kCAAkC;IAG/D,sBAAsB,2BAA2B;IAGjD,oBAAoB,yBAAyB;
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../../src/session/error-codes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,gBAAgB;IAExB,iBAAiB,sBAAsB;IACvC,6BAA6B,kCAAkC;IAC/D,6BAA6B,kCAAkC;IAG/D,sBAAsB,2BAA2B;IAGjD,oBAAoB,yBAAyB;IAC7C,YAAY,iBAAiB;CAChC"}
|
|
@@ -5,6 +5,7 @@ var SessionErrorCode = /* @__PURE__ */ ((SessionErrorCode2) => {
|
|
|
5
5
|
SessionErrorCode2["SESSION_MAX_SESSIONS_EXCEEDED"] = "session_max_sessions_exceeded";
|
|
6
6
|
SessionErrorCode2["SESSION_STORAGE_FAILED"] = "session_storage_failed";
|
|
7
7
|
SessionErrorCode2["SESSION_RESET_FAILED"] = "session_reset_failed";
|
|
8
|
+
SessionErrorCode2["SESSION_BUSY"] = "session_busy";
|
|
8
9
|
return SessionErrorCode2;
|
|
9
10
|
})(SessionErrorCode || {});
|
|
10
11
|
export {
|
package/dist/session/errors.cjs
CHANGED
|
@@ -86,6 +86,19 @@ class SessionError {
|
|
|
86
86
|
{ sessionId, reason }
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Session already processing a run
|
|
91
|
+
*/
|
|
92
|
+
static busy(sessionId) {
|
|
93
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
94
|
+
import_error_codes.SessionErrorCode.SESSION_BUSY,
|
|
95
|
+
import_types.ErrorScope.SESSION,
|
|
96
|
+
import_types.ErrorType.CONFLICT,
|
|
97
|
+
`Session '${sessionId}' is already processing a message`,
|
|
98
|
+
{ sessionId },
|
|
99
|
+
"Wait for the current run to finish before starting another one"
|
|
100
|
+
);
|
|
101
|
+
}
|
|
89
102
|
}
|
|
90
103
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
104
|
0 && (module.exports = {
|
package/dist/session/errors.d.ts
CHANGED
|
@@ -39,5 +39,11 @@ export declare class SessionError {
|
|
|
39
39
|
sessionId: string;
|
|
40
40
|
reason: string;
|
|
41
41
|
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Session already processing a run
|
|
44
|
+
*/
|
|
45
|
+
static busy(sessionId: string): DextoRuntimeError<{
|
|
46
|
+
sessionId: string;
|
|
47
|
+
}>;
|
|
42
48
|
}
|
|
43
49
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/session/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAInE;;;GAGG;AACH,qBAAa,YAAY;IACrB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM;;;IAUjC;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAU7D;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;;;;IAWpE;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;IAUzE;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/session/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAInE;;;GAGG;AACH,qBAAa,YAAY;IACrB;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM;;;IAUjC;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAU7D;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;;;;IAWpE;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;IAUzE;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAUpD;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM;;;CAUhC"}
|
package/dist/session/errors.js
CHANGED
|
@@ -64,6 +64,19 @@ class SessionError {
|
|
|
64
64
|
{ sessionId, reason }
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Session already processing a run
|
|
69
|
+
*/
|
|
70
|
+
static busy(sessionId) {
|
|
71
|
+
return new DextoRuntimeError(
|
|
72
|
+
SessionErrorCode.SESSION_BUSY,
|
|
73
|
+
ErrorScope.SESSION,
|
|
74
|
+
ErrorType.CONFLICT,
|
|
75
|
+
`Session '${sessionId}' is already processing a message`,
|
|
76
|
+
{ sessionId },
|
|
77
|
+
"Wait for the current run to finish before starting another one"
|
|
78
|
+
);
|
|
79
|
+
}
|
|
67
80
|
}
|
|
68
81
|
export {
|
|
69
82
|
SessionError
|
|
@@ -2,13 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
export declare const SessionConfigSchema: z.ZodObject<{
|
|
3
3
|
maxSessions: z.ZodDefault<z.ZodNumber>;
|
|
4
4
|
sessionTTL: z.ZodDefault<z.ZodNumber>;
|
|
5
|
-
},
|
|
6
|
-
maxSessions: number;
|
|
7
|
-
sessionTTL: number;
|
|
8
|
-
}, {
|
|
9
|
-
maxSessions?: number | undefined;
|
|
10
|
-
sessionTTL?: number | undefined;
|
|
11
|
-
}>;
|
|
5
|
+
}, z.core.$strict>;
|
|
12
6
|
export type SessionConfig = z.input<typeof SessionConfigSchema>;
|
|
13
7
|
export type ValidatedSessionConfig = z.output<typeof SessionConfigSchema>;
|
|
14
8
|
//# sourceMappingURL=schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/session/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/session/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,mBAAmB;;;kBAgBiB,CAAC;AAElD,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAChE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -74,22 +74,14 @@ const FileContributorSchema = BaseContributorSchema.extend({
|
|
|
74
74
|
includeMetadata: import_zod.z.boolean().optional().default(false).describe(
|
|
75
75
|
"Whether to include file metadata (size, modification time) in the context"
|
|
76
76
|
)
|
|
77
|
-
}).strict().optional().
|
|
77
|
+
}).strict().optional().prefault({})
|
|
78
78
|
}).strict();
|
|
79
79
|
const ContributorConfigSchema = import_zod.z.discriminatedUnion(
|
|
80
80
|
"type",
|
|
81
81
|
// The field to discriminate on
|
|
82
82
|
[StaticContributorSchema, DynamicContributorSchema, FileContributorSchema],
|
|
83
83
|
{
|
|
84
|
-
|
|
85
|
-
errorMap: (issue, ctx) => {
|
|
86
|
-
if (issue.code === import_zod.z.ZodIssueCode.invalid_union_discriminator) {
|
|
87
|
-
return {
|
|
88
|
-
message: `Invalid contributor type. Expected 'static', 'dynamic', or 'file'. Note: memory contributors are now configured via the top-level 'memories' config.`
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return { message: ctx.defaultError };
|
|
92
|
-
}
|
|
84
|
+
error: `Invalid contributor type. Expected 'static', 'dynamic', or 'file'. Note: memory contributors are now configured via the top-level 'memories' config.`
|
|
93
85
|
}
|
|
94
86
|
).describe(
|
|
95
87
|
"Configuration for a system prompt contributor. Type 'static' requires 'content', type 'dynamic' requires 'source', type 'file' requires 'files'."
|