@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
|
@@ -22,7 +22,7 @@ import { isCodexBaseURL } from "../providers/codex-base-url.js";
|
|
|
22
22
|
const toolSupportCache = /* @__PURE__ */ new Map();
|
|
23
23
|
const LOCAL_PROVIDERS = ["ollama", "local"];
|
|
24
24
|
class TurnExecutor {
|
|
25
|
-
constructor(model, toolManager, contextManager, eventBus, resourceManager, sessionId, config, llmContext, logger, messageQueue, modelLimits, externalSignal, compactionStrategy = null) {
|
|
25
|
+
constructor(model, toolManager, contextManager, eventBus, resourceManager, sessionId, config, llmContext, logger, messageQueue, modelLimits, externalSignal, compactionStrategy = null, runContext) {
|
|
26
26
|
this.model = model;
|
|
27
27
|
this.toolManager = toolManager;
|
|
28
28
|
this.contextManager = contextManager;
|
|
@@ -34,6 +34,7 @@ class TurnExecutor {
|
|
|
34
34
|
this.messageQueue = messageQueue;
|
|
35
35
|
this.modelLimits = modelLimits;
|
|
36
36
|
this.externalSignal = externalSignal;
|
|
37
|
+
this.runContext = runContext;
|
|
37
38
|
this.logger = logger.createChild(DextoLogComponent.EXECUTOR);
|
|
38
39
|
this.stepAbortController = new AbortController();
|
|
39
40
|
this.compactionStrategy = compactionStrategy;
|
|
@@ -86,7 +87,7 @@ class TurnExecutor {
|
|
|
86
87
|
let lastStepTokens = null;
|
|
87
88
|
let lastFinishReason = "unknown";
|
|
88
89
|
let lastText = "";
|
|
89
|
-
this.eventBus.emit("llm:thinking");
|
|
90
|
+
this.eventBus.emit("llm:thinking", {});
|
|
90
91
|
const supportsTools = await this.validateToolSupport();
|
|
91
92
|
if (!supportsTools) {
|
|
92
93
|
const modelKey = `${this.llmContext.provider}:${this.llmContext.model}`;
|
|
@@ -119,7 +120,7 @@ class TurnExecutor {
|
|
|
119
120
|
once: true
|
|
120
121
|
});
|
|
121
122
|
}
|
|
122
|
-
const coalesced = this.messageQueue.dequeueAll();
|
|
123
|
+
const coalesced = await this.messageQueue.dequeueAll();
|
|
123
124
|
if (coalesced) {
|
|
124
125
|
await this.injectQueuedMessages(coalesced);
|
|
125
126
|
}
|
|
@@ -252,7 +253,7 @@ class TurnExecutor {
|
|
|
252
253
|
);
|
|
253
254
|
}
|
|
254
255
|
if (result.finishReason !== "tool-calls") {
|
|
255
|
-
const queuedOnTerminate = this.messageQueue.dequeueAll();
|
|
256
|
+
const queuedOnTerminate = await this.messageQueue.dequeueAll();
|
|
256
257
|
if (queuedOnTerminate) {
|
|
257
258
|
this.logger.debug(
|
|
258
259
|
`Continuing: ${queuedOnTerminate.messages.length} queued message(s) to process`
|
|
@@ -463,8 +464,11 @@ class TurnExecutor {
|
|
|
463
464
|
name,
|
|
464
465
|
args,
|
|
465
466
|
options.toolCallId,
|
|
466
|
-
|
|
467
|
-
|
|
467
|
+
{
|
|
468
|
+
sessionId: this.sessionId,
|
|
469
|
+
abortSignal,
|
|
470
|
+
...this.runContext !== void 0 ? { runContext: this.runContext } : {}
|
|
471
|
+
}
|
|
468
472
|
);
|
|
469
473
|
const metadata = (() => {
|
|
470
474
|
const meta = {};
|
|
@@ -689,7 +693,11 @@ class TurnExecutor {
|
|
|
689
693
|
if (!this.stepAbortController.signal.aborted) {
|
|
690
694
|
this.stepAbortController.abort();
|
|
691
695
|
}
|
|
692
|
-
this.messageQueue.clear()
|
|
696
|
+
void this.messageQueue.clear().catch((error) => {
|
|
697
|
+
this.logger.warn(
|
|
698
|
+
`Failed to clear queued follow-up messages during cleanup: ${error instanceof Error ? error.message : String(error)}`
|
|
699
|
+
);
|
|
700
|
+
});
|
|
693
701
|
}
|
|
694
702
|
/**
|
|
695
703
|
* Check if context should be compacted based on estimated token count.
|
|
@@ -237,9 +237,9 @@ function createVercelModel(llmConfig, context) {
|
|
|
237
237
|
throw import_errors.LLMError.unsupportedProvider(provider);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function createLLMService(config, toolManager, systemPromptManager, historyProvider, sessionEventBus, sessionId, resourceManager, logger, options
|
|
241
|
-
const { usageScopeId, compactionStrategy } = options;
|
|
242
|
-
const
|
|
240
|
+
function createLLMService(config, toolManager, systemPromptManager, historyProvider, sessionEventBus, sessionId, resourceManager, logger, options, languageModelFactory) {
|
|
241
|
+
const { usageScopeId, compactionStrategy, messageQueue } = options;
|
|
242
|
+
const providerContext = {
|
|
243
243
|
sessionId,
|
|
244
244
|
...options.cwd !== void 0 ? { cwd: options.cwd } : {},
|
|
245
245
|
onCodexRateLimitStatus: (snapshot) => {
|
|
@@ -249,7 +249,12 @@ function createLLMService(config, toolManager, systemPromptManager, historyProvi
|
|
|
249
249
|
snapshot
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
}
|
|
252
|
+
};
|
|
253
|
+
const model = languageModelFactory?.({
|
|
254
|
+
config,
|
|
255
|
+
context: providerContext,
|
|
256
|
+
createDefaultLanguageModel: () => createVercelModel(config, providerContext)
|
|
257
|
+
}) ?? createVercelModel(config, providerContext);
|
|
253
258
|
return new import_vercel.VercelLLMService(
|
|
254
259
|
toolManager,
|
|
255
260
|
model,
|
|
@@ -260,6 +265,7 @@ function createLLMService(config, toolManager, systemPromptManager, historyProvi
|
|
|
260
265
|
sessionId,
|
|
261
266
|
resourceManager,
|
|
262
267
|
logger,
|
|
268
|
+
messageQueue,
|
|
263
269
|
usageScopeId,
|
|
264
270
|
compactionStrategy
|
|
265
271
|
);
|
|
@@ -6,26 +6,7 @@ import { SessionEventBus } from '../../events/index.js';
|
|
|
6
6
|
import type { ConversationHistoryProvider } from '../../session/history/types.js';
|
|
7
7
|
import type { SystemPromptManager } from '../../systemPrompt/manager.js';
|
|
8
8
|
import type { Logger } from '../../logger/v2/types.js';
|
|
9
|
-
import {
|
|
10
|
-
import type { CompactionStrategy } from '../../context/compaction/types.js';
|
|
11
|
-
/**
|
|
12
|
-
* Context for model creation, including session info for usage tracking.
|
|
13
|
-
*/
|
|
14
|
-
export interface DextoProviderContext {
|
|
15
|
-
/** Session ID for usage tracking */
|
|
16
|
-
sessionId?: string;
|
|
17
|
-
/** Client source for usage attribution (cli, web, sdk) */
|
|
18
|
-
clientSource?: 'cli' | 'web' | 'sdk';
|
|
19
|
-
/** Working directory for providers that need an explicit workspace root. */
|
|
20
|
-
cwd?: string;
|
|
21
|
-
/** Optional callback for ChatGPT Login rate-limit status updates from Codex. */
|
|
22
|
-
onCodexRateLimitStatus?: (snapshot: CodexRateLimitSnapshot) => void;
|
|
23
|
-
}
|
|
24
|
-
export interface CreateLLMServiceOptions {
|
|
25
|
-
usageScopeId?: string | undefined;
|
|
26
|
-
compactionStrategy?: CompactionStrategy | null | undefined;
|
|
27
|
-
cwd?: string | undefined;
|
|
28
|
-
}
|
|
9
|
+
import type { CreateLLMServiceOptions, DextoProviderContext, LanguageModelFactory } from './types.js';
|
|
29
10
|
/**
|
|
30
11
|
* Create a Vercel AI SDK LanguageModel from config.
|
|
31
12
|
*
|
|
@@ -52,5 +33,5 @@ export declare function createVercelModel(llmConfig: ValidatedLLMConfig, context
|
|
|
52
33
|
* @param options Session-scoped runtime options
|
|
53
34
|
* @returns VercelLLMService instance
|
|
54
35
|
*/
|
|
55
|
-
export declare function createLLMService(config: ValidatedLLMConfig, toolManager: ToolManager, systemPromptManager: SystemPromptManager, historyProvider: ConversationHistoryProvider, sessionEventBus: SessionEventBus, sessionId: string, resourceManager: import('../../resources/index.js').ResourceManager, logger: Logger, options?:
|
|
36
|
+
export declare function createLLMService(config: ValidatedLLMConfig, toolManager: ToolManager, systemPromptManager: SystemPromptManager, historyProvider: ConversationHistoryProvider, sessionEventBus: SessionEventBus, sessionId: string, resourceManager: import('../../resources/index.js').ResourceManager, logger: Logger, options: CreateLLMServiceOptions, languageModelFactory?: LanguageModelFactory): VercelLLMService;
|
|
56
37
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/llm/services/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAYnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/llm/services/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAYnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAClF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EACR,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,YAAY,CAAC;AA6DpB;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC7B,SAAS,EAAE,kBAAkB,EAC7B,OAAO,CAAC,EAAE,oBAAoB,GAC/B,aAAa,CAyOf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,kBAAkB,EAC1B,WAAW,EAAE,WAAW,EACxB,mBAAmB,EAAE,mBAAmB,EACxC,eAAe,EAAE,2BAA2B,EAC5C,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,OAAO,0BAA0B,EAAE,eAAe,EACnE,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,uBAAuB,EAChC,oBAAoB,CAAC,EAAE,oBAAoB,GAC5C,gBAAgB,CAoClB"}
|
|
@@ -15,9 +15,7 @@ import { createCohere } from "@ai-sdk/cohere";
|
|
|
15
15
|
import { createLocalLanguageModel } from "../providers/local/ai-sdk-adapter.js";
|
|
16
16
|
import { requiresApiKey } from "../registry/index.js";
|
|
17
17
|
import { getPrimaryApiKeyEnvVar, resolveApiKeyForProvider } from "../../utils/api-key-resolver.js";
|
|
18
|
-
import {
|
|
19
|
-
createCodexLanguageModel
|
|
20
|
-
} from "../providers/codex-app-server.js";
|
|
18
|
+
import { createCodexLanguageModel } from "../providers/codex-app-server.js";
|
|
21
19
|
import { isCodexBaseURL } from "../providers/codex-base-url.js";
|
|
22
20
|
import { findDextoProjectRoot } from "../../utils/execution-context.js";
|
|
23
21
|
import {
|
|
@@ -219,9 +217,9 @@ function createVercelModel(llmConfig, context) {
|
|
|
219
217
|
throw LLMError.unsupportedProvider(provider);
|
|
220
218
|
}
|
|
221
219
|
}
|
|
222
|
-
function createLLMService(config, toolManager, systemPromptManager, historyProvider, sessionEventBus, sessionId, resourceManager, logger, options
|
|
223
|
-
const { usageScopeId, compactionStrategy } = options;
|
|
224
|
-
const
|
|
220
|
+
function createLLMService(config, toolManager, systemPromptManager, historyProvider, sessionEventBus, sessionId, resourceManager, logger, options, languageModelFactory) {
|
|
221
|
+
const { usageScopeId, compactionStrategy, messageQueue } = options;
|
|
222
|
+
const providerContext = {
|
|
225
223
|
sessionId,
|
|
226
224
|
...options.cwd !== void 0 ? { cwd: options.cwd } : {},
|
|
227
225
|
onCodexRateLimitStatus: (snapshot) => {
|
|
@@ -231,7 +229,12 @@ function createLLMService(config, toolManager, systemPromptManager, historyProvi
|
|
|
231
229
|
snapshot
|
|
232
230
|
});
|
|
233
231
|
}
|
|
234
|
-
}
|
|
232
|
+
};
|
|
233
|
+
const model = languageModelFactory?.({
|
|
234
|
+
config,
|
|
235
|
+
context: providerContext,
|
|
236
|
+
createDefaultLanguageModel: () => createVercelModel(config, providerContext)
|
|
237
|
+
}) ?? createVercelModel(config, providerContext);
|
|
235
238
|
return new VercelLLMService(
|
|
236
239
|
toolManager,
|
|
237
240
|
model,
|
|
@@ -242,6 +245,7 @@ function createLLMService(config, toolManager, systemPromptManager, historyProvi
|
|
|
242
245
|
sessionId,
|
|
243
246
|
resourceManager,
|
|
244
247
|
logger,
|
|
248
|
+
messageQueue,
|
|
245
249
|
usageScopeId,
|
|
246
250
|
compactionStrategy
|
|
247
251
|
);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CompactionStrategy } from '../../context/compaction/types.js';
|
|
2
|
+
import type { LanguageModel } from 'ai';
|
|
3
|
+
import type { CodexRateLimitSnapshot } from '../providers/codex-app-server.js';
|
|
4
|
+
import type { ValidatedLLMConfig } from '../schemas.js';
|
|
2
5
|
import type { LLMProvider } from '../types.js';
|
|
6
|
+
import type { MessageQueueService } from '../../session/message-queue.js';
|
|
3
7
|
/**
|
|
4
|
-
* Configuration object returned by
|
|
8
|
+
* Configuration object returned by the default session LLM service.
|
|
5
9
|
*/
|
|
6
10
|
export type LLMServiceConfig = {
|
|
7
11
|
provider: LLMProvider;
|
|
@@ -9,6 +13,33 @@ export type LLMServiceConfig = {
|
|
|
9
13
|
configuredMaxInputTokens?: number | null;
|
|
10
14
|
modelMaxInputTokens?: number | null;
|
|
11
15
|
};
|
|
16
|
+
export interface CreateLLMServiceOptions {
|
|
17
|
+
usageScopeId?: string | undefined;
|
|
18
|
+
compactionStrategy?: CompactionStrategy | null | undefined;
|
|
19
|
+
cwd?: string | undefined;
|
|
20
|
+
messageQueue: MessageQueueService;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Context for model creation, including session info for usage tracking.
|
|
24
|
+
*/
|
|
25
|
+
export interface DextoProviderContext {
|
|
26
|
+
/** Session ID for usage tracking */
|
|
27
|
+
sessionId?: string;
|
|
28
|
+
/** Client source for usage attribution (cli, web, sdk) */
|
|
29
|
+
clientSource?: 'cli' | 'web' | 'sdk';
|
|
30
|
+
/** Working directory for providers that need an explicit workspace root. */
|
|
31
|
+
cwd?: string;
|
|
32
|
+
/** Optional callback for ChatGPT Login rate-limit status updates from Codex. */
|
|
33
|
+
onCodexRateLimitStatus?: (snapshot: CodexRateLimitSnapshot) => void;
|
|
34
|
+
}
|
|
35
|
+
export interface LanguageModelFactoryInput {
|
|
36
|
+
config: ValidatedLLMConfig;
|
|
37
|
+
context: DextoProviderContext;
|
|
38
|
+
}
|
|
39
|
+
export interface LanguageModelFactoryContext extends LanguageModelFactoryInput {
|
|
40
|
+
createDefaultLanguageModel: () => LanguageModel;
|
|
41
|
+
}
|
|
42
|
+
export type LanguageModelFactory = (context: LanguageModelFactoryContext) => LanguageModel;
|
|
12
43
|
/**
|
|
13
44
|
* Token usage statistics from LLM
|
|
14
45
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/llm/services/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/llm/services/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,aAAa,CAAC;IACrB,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,mBAAmB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACpC,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,kBAAkB,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3D,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,YAAY,EAAE,mBAAmB,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;IACrC,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,sBAAsB,CAAC,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,IAAI,CAAC;CACvE;AAED,MAAM,WAAW,yBAAyB;IACtC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,EAAE,oBAAoB,CAAC;CACjC;AAED,MAAM,WAAW,2BAA4B,SAAQ,yBAAyB;IAC1E,0BAA0B,EAAE,MAAM,aAAa,CAAC;CACnD;AAED,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,2BAA2B,KAAK,aAAa,CAAC;AAE3F;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B"}
|
|
@@ -63,20 +63,36 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
63
63
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
64
64
|
var vercel_exports = {};
|
|
65
65
|
__export(vercel_exports, {
|
|
66
|
-
VercelLLMService: () => VercelLLMService
|
|
66
|
+
VercelLLMService: () => VercelLLMService,
|
|
67
|
+
ensureRunContextMatchesServiceSession: () => ensureRunContextMatchesServiceSession
|
|
67
68
|
});
|
|
68
69
|
module.exports = __toCommonJS(vercel_exports);
|
|
69
|
-
var
|
|
70
|
+
var import_types = require("../../logger/v2/types.js");
|
|
70
71
|
var import_manager = require("../../context/manager.js");
|
|
71
72
|
var import_registry = require("../registry/index.js");
|
|
72
73
|
var import_vercel = require("../formatters/vercel.js");
|
|
73
74
|
var import_decorators = require("../../telemetry/decorators.js");
|
|
74
75
|
var import_api = require("@opentelemetry/api");
|
|
75
76
|
var import_turn_executor = require("../executor/turn-executor.js");
|
|
76
|
-
var import_message_queue = require("../../session/message-queue.js");
|
|
77
77
|
var import_DextoRuntimeError = require("../../errors/DextoRuntimeError.js");
|
|
78
|
+
var import_types4 = require("../../errors/types.js");
|
|
78
79
|
var import_error_codes = require("../error-codes.js");
|
|
79
80
|
var _VercelLLMService_decorators, _init;
|
|
81
|
+
function ensureRunContextMatchesServiceSession(serviceSessionId, runContext) {
|
|
82
|
+
if (runContext !== void 0 && runContext.sessionId !== serviceSessionId) {
|
|
83
|
+
throw new import_DextoRuntimeError.DextoRuntimeError(
|
|
84
|
+
import_error_codes.LLMErrorCode.GENERATION_FAILED,
|
|
85
|
+
import_types4.ErrorScope.LLM,
|
|
86
|
+
import_types4.ErrorType.SYSTEM,
|
|
87
|
+
`Run context session '${runContext.sessionId}' does not match LLM service session '${serviceSessionId}'`,
|
|
88
|
+
{
|
|
89
|
+
serviceSessionId,
|
|
90
|
+
runContextSessionId: runContext.sessionId
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return serviceSessionId;
|
|
95
|
+
}
|
|
80
96
|
_VercelLLMService_decorators = [(0, import_decorators.InstrumentClass)({
|
|
81
97
|
prefix: "llm.vercel",
|
|
82
98
|
excludeMethods: ["getModelId", "getAllTools", "createTurnExecutor"]
|
|
@@ -100,8 +116,8 @@ class VercelLLMService {
|
|
|
100
116
|
getModelId() {
|
|
101
117
|
return typeof this.model === "string" ? this.model : this.model.modelId;
|
|
102
118
|
}
|
|
103
|
-
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, usageScopeId, compactionStrategy) {
|
|
104
|
-
this.logger = logger.createChild(
|
|
119
|
+
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, messageQueue, usageScopeId, compactionStrategy) {
|
|
120
|
+
this.logger = logger.createChild(import_types.DextoLogComponent.LLM);
|
|
105
121
|
this.model = model;
|
|
106
122
|
this.config = config;
|
|
107
123
|
this.toolManager = toolManager;
|
|
@@ -110,7 +126,7 @@ class VercelLLMService {
|
|
|
110
126
|
this.resourceManager = resourceManager;
|
|
111
127
|
this.usageScopeId = usageScopeId;
|
|
112
128
|
this.compactionStrategy = compactionStrategy ?? null;
|
|
113
|
-
this.messageQueue =
|
|
129
|
+
this.messageQueue = messageQueue;
|
|
114
130
|
const formatter = new import_vercel.VercelMessageFormatter(this.logger);
|
|
115
131
|
const maxInputTokens = (0, import_registry.getEffectiveMaxInputTokens)(config, this.logger);
|
|
116
132
|
if (this.compactionStrategy) {
|
|
@@ -139,7 +155,7 @@ class VercelLLMService {
|
|
|
139
155
|
/**
|
|
140
156
|
* Create a TurnExecutor instance for executing the agent loop.
|
|
141
157
|
*/
|
|
142
|
-
createTurnExecutor(externalSignal) {
|
|
158
|
+
createTurnExecutor(externalSignal, runContext) {
|
|
143
159
|
return new import_turn_executor.TurnExecutor(
|
|
144
160
|
this.model,
|
|
145
161
|
this.toolManager,
|
|
@@ -161,7 +177,8 @@ class VercelLLMService {
|
|
|
161
177
|
this.messageQueue,
|
|
162
178
|
this.modelLimits,
|
|
163
179
|
externalSignal,
|
|
164
|
-
this.compactionStrategy
|
|
180
|
+
this.compactionStrategy,
|
|
181
|
+
runContext
|
|
165
182
|
);
|
|
166
183
|
}
|
|
167
184
|
/**
|
|
@@ -177,6 +194,10 @@ class VercelLLMService {
|
|
|
177
194
|
* @returns Object with text response
|
|
178
195
|
*/
|
|
179
196
|
async stream(content, options) {
|
|
197
|
+
const sessionId = ensureRunContextMatchesServiceSession(
|
|
198
|
+
this.sessionId,
|
|
199
|
+
options?.runContext
|
|
200
|
+
);
|
|
180
201
|
const activeSpan = import_api.trace.getActiveSpan();
|
|
181
202
|
const currentContext = import_api.context.active();
|
|
182
203
|
const provider = this.config.provider;
|
|
@@ -201,9 +222,9 @@ class VercelLLMService {
|
|
|
201
222
|
return await import_api.context.with(updatedContext, async () => {
|
|
202
223
|
const parts = typeof content === "string" ? [{ type: "text", text: content }] : content;
|
|
203
224
|
await this.contextManager.addUserMessage(parts);
|
|
204
|
-
const executor = this.createTurnExecutor(options?.signal);
|
|
225
|
+
const executor = this.createTurnExecutor(options?.signal, options?.runContext);
|
|
205
226
|
const contributorContext = await this.toolManager.buildContributorContext({
|
|
206
|
-
sessionId
|
|
227
|
+
sessionId
|
|
207
228
|
});
|
|
208
229
|
const result = await executor.execute(contributorContext, true);
|
|
209
230
|
return {
|
|
@@ -268,5 +289,6 @@ VercelLLMService = __decorateElement(_init, 0, "VercelLLMService", _VercelLLMSer
|
|
|
268
289
|
__runInitializers(_init, 1, VercelLLMService);
|
|
269
290
|
// Annotate the CommonJS export names for ESM import in node:
|
|
270
291
|
0 && (module.exports = {
|
|
271
|
-
VercelLLMService
|
|
292
|
+
VercelLLMService,
|
|
293
|
+
ensureRunContextMatchesServiceSession
|
|
272
294
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LanguageModel } from 'ai';
|
|
2
2
|
import { ToolManager } from '../../tools/tool-manager.js';
|
|
3
|
-
import { LLMServiceConfig } from './types.js';
|
|
3
|
+
import type { LLMServiceConfig } from './types.js';
|
|
4
4
|
import type { Logger } from '../../logger/v2/types.js';
|
|
5
5
|
import { ToolSet } from '../../tools/types.js';
|
|
6
6
|
import { ContextManager } from '../../context/manager.js';
|
|
@@ -11,8 +11,10 @@ import type { ValidatedLLMConfig } from '../schemas.js';
|
|
|
11
11
|
import { MessageQueueService } from '../../session/message-queue.js';
|
|
12
12
|
import type { ResourceManager } from '../../resources/index.js';
|
|
13
13
|
import type { ContentInput } from '../../agent/types.js';
|
|
14
|
+
import type { AgentRunContext } from '../../runtime/run-context.js';
|
|
15
|
+
export declare function ensureRunContextMatchesServiceSession(serviceSessionId: string, runContext?: AgentRunContext): string;
|
|
14
16
|
/**
|
|
15
|
-
* Vercel AI SDK implementation of
|
|
17
|
+
* Vercel AI SDK implementation of the core session LLM runtime
|
|
16
18
|
*
|
|
17
19
|
* This service delegates actual LLM execution to TurnExecutor, which handles:
|
|
18
20
|
* - Tool execution with multimodal support
|
|
@@ -42,7 +44,7 @@ export declare class VercelLLMService {
|
|
|
42
44
|
* Helper to extract model ID from LanguageModel union type (string | LanguageModelV2)
|
|
43
45
|
*/
|
|
44
46
|
private getModelId;
|
|
45
|
-
constructor(toolManager: ToolManager, model: LanguageModel, systemPromptManager: SystemPromptManager, historyProvider: ConversationHistoryProvider, sessionEventBus: SessionEventBus, config: ValidatedLLMConfig, sessionId: string, resourceManager: ResourceManager, logger: Logger, usageScopeId?: string, compactionStrategy?: import('../../context/compaction/types.js').CompactionStrategy | null);
|
|
47
|
+
constructor(toolManager: ToolManager, model: LanguageModel, systemPromptManager: SystemPromptManager, historyProvider: ConversationHistoryProvider, sessionEventBus: SessionEventBus, config: ValidatedLLMConfig, sessionId: string, resourceManager: ResourceManager, logger: Logger, messageQueue: MessageQueueService, usageScopeId?: string, compactionStrategy?: import('../../context/compaction/types.js').CompactionStrategy | null);
|
|
46
48
|
getAllTools(): Promise<ToolSet>;
|
|
47
49
|
getEnabledTools(): Promise<ToolSet>;
|
|
48
50
|
/**
|
|
@@ -65,6 +67,7 @@ export declare class VercelLLMService {
|
|
|
65
67
|
*/
|
|
66
68
|
stream(content: ContentInput, options?: {
|
|
67
69
|
signal?: AbortSignal;
|
|
70
|
+
runContext?: AgentRunContext;
|
|
68
71
|
}): Promise<{
|
|
69
72
|
text: string;
|
|
70
73
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../src/llm/services/vercel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAqB,MAAM,IAAI,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"vercel.d.ts","sourceRoot":"","sources":["../../../src/llm/services/vercel.ts"],"names":[],"mappings":"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"}
|
|
@@ -11,9 +11,24 @@ import { VercelMessageFormatter } from "../formatters/vercel.js";
|
|
|
11
11
|
import { InstrumentClass } from "../../telemetry/decorators.js";
|
|
12
12
|
import { trace, context, propagation } from "@opentelemetry/api";
|
|
13
13
|
import { TurnExecutor } from "../executor/turn-executor.js";
|
|
14
|
-
import { MessageQueueService } from "../../session/message-queue.js";
|
|
15
14
|
import { DextoRuntimeError } from "../../errors/DextoRuntimeError.js";
|
|
15
|
+
import { ErrorScope, ErrorType } from "../../errors/types.js";
|
|
16
16
|
import { LLMErrorCode } from "../error-codes.js";
|
|
17
|
+
function ensureRunContextMatchesServiceSession(serviceSessionId, runContext) {
|
|
18
|
+
if (runContext !== void 0 && runContext.sessionId !== serviceSessionId) {
|
|
19
|
+
throw new DextoRuntimeError(
|
|
20
|
+
LLMErrorCode.GENERATION_FAILED,
|
|
21
|
+
ErrorScope.LLM,
|
|
22
|
+
ErrorType.SYSTEM,
|
|
23
|
+
`Run context session '${runContext.sessionId}' does not match LLM service session '${serviceSessionId}'`,
|
|
24
|
+
{
|
|
25
|
+
serviceSessionId,
|
|
26
|
+
runContextSessionId: runContext.sessionId
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return serviceSessionId;
|
|
31
|
+
}
|
|
17
32
|
_VercelLLMService_decorators = [InstrumentClass({
|
|
18
33
|
prefix: "llm.vercel",
|
|
19
34
|
excludeMethods: ["getModelId", "getAllTools", "createTurnExecutor"]
|
|
@@ -37,7 +52,7 @@ class VercelLLMService {
|
|
|
37
52
|
getModelId() {
|
|
38
53
|
return typeof this.model === "string" ? this.model : this.model.modelId;
|
|
39
54
|
}
|
|
40
|
-
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, usageScopeId, compactionStrategy) {
|
|
55
|
+
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, messageQueue, usageScopeId, compactionStrategy) {
|
|
41
56
|
this.logger = logger.createChild(DextoLogComponent.LLM);
|
|
42
57
|
this.model = model;
|
|
43
58
|
this.config = config;
|
|
@@ -47,7 +62,7 @@ class VercelLLMService {
|
|
|
47
62
|
this.resourceManager = resourceManager;
|
|
48
63
|
this.usageScopeId = usageScopeId;
|
|
49
64
|
this.compactionStrategy = compactionStrategy ?? null;
|
|
50
|
-
this.messageQueue =
|
|
65
|
+
this.messageQueue = messageQueue;
|
|
51
66
|
const formatter = new VercelMessageFormatter(this.logger);
|
|
52
67
|
const maxInputTokens = getEffectiveMaxInputTokens(config, this.logger);
|
|
53
68
|
if (this.compactionStrategy) {
|
|
@@ -76,7 +91,7 @@ class VercelLLMService {
|
|
|
76
91
|
/**
|
|
77
92
|
* Create a TurnExecutor instance for executing the agent loop.
|
|
78
93
|
*/
|
|
79
|
-
createTurnExecutor(externalSignal) {
|
|
94
|
+
createTurnExecutor(externalSignal, runContext) {
|
|
80
95
|
return new TurnExecutor(
|
|
81
96
|
this.model,
|
|
82
97
|
this.toolManager,
|
|
@@ -98,7 +113,8 @@ class VercelLLMService {
|
|
|
98
113
|
this.messageQueue,
|
|
99
114
|
this.modelLimits,
|
|
100
115
|
externalSignal,
|
|
101
|
-
this.compactionStrategy
|
|
116
|
+
this.compactionStrategy,
|
|
117
|
+
runContext
|
|
102
118
|
);
|
|
103
119
|
}
|
|
104
120
|
/**
|
|
@@ -114,6 +130,10 @@ class VercelLLMService {
|
|
|
114
130
|
* @returns Object with text response
|
|
115
131
|
*/
|
|
116
132
|
async stream(content, options) {
|
|
133
|
+
const sessionId = ensureRunContextMatchesServiceSession(
|
|
134
|
+
this.sessionId,
|
|
135
|
+
options?.runContext
|
|
136
|
+
);
|
|
117
137
|
const activeSpan = trace.getActiveSpan();
|
|
118
138
|
const currentContext = context.active();
|
|
119
139
|
const provider = this.config.provider;
|
|
@@ -138,9 +158,9 @@ class VercelLLMService {
|
|
|
138
158
|
return await context.with(updatedContext, async () => {
|
|
139
159
|
const parts = typeof content === "string" ? [{ type: "text", text: content }] : content;
|
|
140
160
|
await this.contextManager.addUserMessage(parts);
|
|
141
|
-
const executor = this.createTurnExecutor(options?.signal);
|
|
161
|
+
const executor = this.createTurnExecutor(options?.signal, options?.runContext);
|
|
142
162
|
const contributorContext = await this.toolManager.buildContributorContext({
|
|
143
|
-
sessionId
|
|
163
|
+
sessionId
|
|
144
164
|
});
|
|
145
165
|
const result = await executor.execute(contributorContext, true);
|
|
146
166
|
return {
|
|
@@ -204,5 +224,6 @@ _init = __decoratorStart(null);
|
|
|
204
224
|
VercelLLMService = __decorateElement(_init, 0, "VercelLLMService", _VercelLLMService_decorators, VercelLLMService);
|
|
205
225
|
__runInitializers(_init, 1, VercelLLMService);
|
|
206
226
|
export {
|
|
207
|
-
VercelLLMService
|
|
227
|
+
VercelLLMService,
|
|
228
|
+
ensureRunContextMatchesServiceSession
|
|
208
229
|
};
|
|
@@ -27,13 +27,13 @@ export declare const DefaultLoggerFactoryConfigSchema: z.ZodObject<{
|
|
|
27
27
|
}, "strict", z.ZodTypeAny, {
|
|
28
28
|
path: string;
|
|
29
29
|
type: "file";
|
|
30
|
-
maxFiles: number;
|
|
31
30
|
maxSize: number;
|
|
31
|
+
maxFiles: number;
|
|
32
32
|
}, {
|
|
33
33
|
path: string;
|
|
34
34
|
type: "file";
|
|
35
|
-
maxFiles?: number | undefined;
|
|
36
35
|
maxSize?: number | undefined;
|
|
36
|
+
maxFiles?: number | undefined;
|
|
37
37
|
}>, z.ZodObject<{
|
|
38
38
|
type: z.ZodLiteral<"upstash">;
|
|
39
39
|
url: z.ZodString;
|
|
@@ -66,8 +66,8 @@ export declare const DefaultLoggerFactoryConfigSchema: z.ZodObject<{
|
|
|
66
66
|
} | {
|
|
67
67
|
path: string;
|
|
68
68
|
type: "file";
|
|
69
|
-
maxFiles: number;
|
|
70
69
|
maxSize: number;
|
|
70
|
+
maxFiles: number;
|
|
71
71
|
} | {
|
|
72
72
|
token: string;
|
|
73
73
|
type: "upstash";
|
|
@@ -86,8 +86,8 @@ export declare const DefaultLoggerFactoryConfigSchema: z.ZodObject<{
|
|
|
86
86
|
} | {
|
|
87
87
|
path: string;
|
|
88
88
|
type: "file";
|
|
89
|
-
maxFiles?: number | undefined;
|
|
90
89
|
maxSize?: number | undefined;
|
|
90
|
+
maxFiles?: number | undefined;
|
|
91
91
|
} | {
|
|
92
92
|
token: string;
|
|
93
93
|
type: "upstash";
|
|
@@ -108,8 +108,8 @@ export declare const DefaultLoggerFactoryConfigSchema: z.ZodObject<{
|
|
|
108
108
|
} | {
|
|
109
109
|
path: string;
|
|
110
110
|
type: "file";
|
|
111
|
-
maxFiles: number;
|
|
112
111
|
maxSize: number;
|
|
112
|
+
maxFiles: number;
|
|
113
113
|
} | {
|
|
114
114
|
token: string;
|
|
115
115
|
type: "upstash";
|
|
@@ -131,8 +131,8 @@ export declare const DefaultLoggerFactoryConfigSchema: z.ZodObject<{
|
|
|
131
131
|
} | {
|
|
132
132
|
path: string;
|
|
133
133
|
type: "file";
|
|
134
|
-
maxFiles?: number | undefined;
|
|
135
134
|
maxSize?: number | undefined;
|
|
135
|
+
maxFiles?: number | undefined;
|
|
136
136
|
} | {
|
|
137
137
|
token: string;
|
|
138
138
|
type: "upstash";
|
|
@@ -179,13 +179,13 @@ export declare const defaultLoggerFactory: {
|
|
|
179
179
|
}, "strict", z.ZodTypeAny, {
|
|
180
180
|
path: string;
|
|
181
181
|
type: "file";
|
|
182
|
-
maxFiles: number;
|
|
183
182
|
maxSize: number;
|
|
183
|
+
maxFiles: number;
|
|
184
184
|
}, {
|
|
185
185
|
path: string;
|
|
186
186
|
type: "file";
|
|
187
|
-
maxFiles?: number | undefined;
|
|
188
187
|
maxSize?: number | undefined;
|
|
188
|
+
maxFiles?: number | undefined;
|
|
189
189
|
}>, z.ZodObject<{
|
|
190
190
|
type: z.ZodLiteral<"upstash">;
|
|
191
191
|
url: z.ZodString;
|
|
@@ -218,8 +218,8 @@ export declare const defaultLoggerFactory: {
|
|
|
218
218
|
} | {
|
|
219
219
|
path: string;
|
|
220
220
|
type: "file";
|
|
221
|
-
maxFiles: number;
|
|
222
221
|
maxSize: number;
|
|
222
|
+
maxFiles: number;
|
|
223
223
|
} | {
|
|
224
224
|
token: string;
|
|
225
225
|
type: "upstash";
|
|
@@ -238,8 +238,8 @@ export declare const defaultLoggerFactory: {
|
|
|
238
238
|
} | {
|
|
239
239
|
path: string;
|
|
240
240
|
type: "file";
|
|
241
|
-
maxFiles?: number | undefined;
|
|
242
241
|
maxSize?: number | undefined;
|
|
242
|
+
maxFiles?: number | undefined;
|
|
243
243
|
} | {
|
|
244
244
|
token: string;
|
|
245
245
|
type: "upstash";
|
|
@@ -260,8 +260,8 @@ export declare const defaultLoggerFactory: {
|
|
|
260
260
|
} | {
|
|
261
261
|
path: string;
|
|
262
262
|
type: "file";
|
|
263
|
-
maxFiles: number;
|
|
264
263
|
maxSize: number;
|
|
264
|
+
maxFiles: number;
|
|
265
265
|
} | {
|
|
266
266
|
token: string;
|
|
267
267
|
type: "upstash";
|
|
@@ -283,8 +283,8 @@ export declare const defaultLoggerFactory: {
|
|
|
283
283
|
} | {
|
|
284
284
|
path: string;
|
|
285
285
|
type: "file";
|
|
286
|
-
maxFiles?: number | undefined;
|
|
287
286
|
maxSize?: number | undefined;
|
|
287
|
+
maxFiles?: number | undefined;
|
|
288
288
|
} | {
|
|
289
289
|
token: string;
|
|
290
290
|
type: "upstash";
|
|
@@ -31,13 +31,13 @@ export declare const LoggerTransportSchema: z.ZodDiscriminatedUnion<"type", [z.Z
|
|
|
31
31
|
}, "strict", z.ZodTypeAny, {
|
|
32
32
|
path: string;
|
|
33
33
|
type: "file";
|
|
34
|
-
maxFiles: number;
|
|
35
34
|
maxSize: number;
|
|
35
|
+
maxFiles: number;
|
|
36
36
|
}, {
|
|
37
37
|
path: string;
|
|
38
38
|
type: "file";
|
|
39
|
-
maxFiles?: number | undefined;
|
|
40
39
|
maxSize?: number | undefined;
|
|
40
|
+
maxFiles?: number | undefined;
|
|
41
41
|
}>, z.ZodObject<{
|
|
42
42
|
type: z.ZodLiteral<"upstash">;
|
|
43
43
|
url: z.ZodString;
|
|
@@ -89,13 +89,13 @@ export declare const LoggerConfigSchema: z.ZodObject<{
|
|
|
89
89
|
}, "strict", z.ZodTypeAny, {
|
|
90
90
|
path: string;
|
|
91
91
|
type: "file";
|
|
92
|
-
maxFiles: number;
|
|
93
92
|
maxSize: number;
|
|
93
|
+
maxFiles: number;
|
|
94
94
|
}, {
|
|
95
95
|
path: string;
|
|
96
96
|
type: "file";
|
|
97
|
-
maxFiles?: number | undefined;
|
|
98
97
|
maxSize?: number | undefined;
|
|
98
|
+
maxFiles?: number | undefined;
|
|
99
99
|
}>, z.ZodObject<{
|
|
100
100
|
type: z.ZodLiteral<"upstash">;
|
|
101
101
|
url: z.ZodString;
|
|
@@ -128,8 +128,8 @@ export declare const LoggerConfigSchema: z.ZodObject<{
|
|
|
128
128
|
} | {
|
|
129
129
|
path: string;
|
|
130
130
|
type: "file";
|
|
131
|
-
maxFiles: number;
|
|
132
131
|
maxSize: number;
|
|
132
|
+
maxFiles: number;
|
|
133
133
|
} | {
|
|
134
134
|
token: string;
|
|
135
135
|
type: "upstash";
|
|
@@ -148,8 +148,8 @@ export declare const LoggerConfigSchema: z.ZodObject<{
|
|
|
148
148
|
} | {
|
|
149
149
|
path: string;
|
|
150
150
|
type: "file";
|
|
151
|
-
maxFiles?: number | undefined;
|
|
152
151
|
maxSize?: number | undefined;
|
|
152
|
+
maxFiles?: number | undefined;
|
|
153
153
|
} | {
|
|
154
154
|
token: string;
|
|
155
155
|
type: "upstash";
|