@dexto/core 1.6.17 → 1.6.19
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 +63 -9
- package/dist/agent/DextoAgent.d.ts +11 -1
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +56 -2
- package/dist/agent/runtime-config.d.ts +2 -0
- package/dist/agent/runtime-config.d.ts.map +1 -1
- package/dist/approval/index.cjs +6 -0
- package/dist/approval/index.d.ts +1 -1
- package/dist/approval/index.d.ts.map +1 -1
- package/dist/approval/index.js +11 -1
- package/dist/approval/schemas.cjs +3 -3
- package/dist/approval/schemas.d.ts +107 -108
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +4 -4
- package/dist/approval/types.cjs +75 -27
- package/dist/approval/types.d.ts +30 -21
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/approval/types.js +72 -27
- package/dist/index.browser.cjs +6 -0
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +11 -1
- package/dist/llm/executor/stream-processor.cjs +2 -2
- package/dist/llm/executor/stream-processor.d.ts +1 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +2 -2
- package/dist/llm/executor/turn-executor.cjs +3 -0
- package/dist/llm/executor/turn-executor.d.ts +1 -0
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +3 -0
- package/dist/llm/services/factory.cjs +12 -1
- package/dist/llm/services/factory.d.ts +10 -3
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +12 -1
- package/dist/llm/services/vercel.cjs +4 -1
- package/dist/llm/services/vercel.d.ts +2 -1
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +4 -1
- package/dist/llm/usage-scope.cjs +4 -13
- package/dist/llm/usage-scope.d.ts +3 -2
- package/dist/llm/usage-scope.d.ts.map +1 -1
- package/dist/llm/usage-scope.js +3 -11
- package/dist/mcp/bundled-config.cjs +206 -0
- package/dist/mcp/bundled-config.d.ts +10 -0
- package/dist/mcp/bundled-config.d.ts.map +1 -0
- package/dist/mcp/bundled-config.js +173 -0
- package/dist/mcp/index.cjs +43 -15
- package/dist/mcp/index.d.ts +11 -7
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +35 -7
- package/dist/prompts/providers/config-prompt-provider.cjs +15 -1
- package/dist/prompts/providers/config-prompt-provider.d.ts.map +1 -1
- package/dist/prompts/providers/config-prompt-provider.js +15 -1
- package/dist/session/chat-session.cjs +13 -4
- package/dist/session/chat-session.d.ts +1 -0
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +13 -4
- package/dist/session/session-manager.cjs +140 -67
- package/dist/session/session-manager.d.ts +8 -1
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +142 -67
- package/dist/systemPrompt/manager.cjs +7 -1
- package/dist/systemPrompt/manager.d.ts.map +1 -1
- package/dist/systemPrompt/manager.js +7 -1
- package/dist/systemPrompt/schemas.cjs +7 -0
- package/dist/systemPrompt/schemas.d.ts +14 -0
- package/dist/systemPrompt/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.js +6 -0
- package/dist/systemPrompt/types.d.ts +2 -0
- package/dist/systemPrompt/types.d.ts.map +1 -1
- package/dist/tools/tool-manager.cjs +20 -1
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +21 -2
- package/dist/utils/execution-context.cjs +26 -0
- package/dist/utils/execution-context.d.ts.map +1 -1
- package/dist/utils/execution-context.js +27 -1
- package/package.json +4 -3
|
@@ -7,6 +7,7 @@ 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
9
|
import { type CodexRateLimitSnapshot } from '../providers/codex-app-server.js';
|
|
10
|
+
import type { CompactionStrategy } from '../../context/compaction/types.js';
|
|
10
11
|
/**
|
|
11
12
|
* Context for model creation, including session info for usage tracking.
|
|
12
13
|
*/
|
|
@@ -15,9 +16,16 @@ export interface DextoProviderContext {
|
|
|
15
16
|
sessionId?: string;
|
|
16
17
|
/** Client source for usage attribution (cli, web, sdk) */
|
|
17
18
|
clientSource?: 'cli' | 'web' | 'sdk';
|
|
19
|
+
/** Working directory for providers that need an explicit workspace root. */
|
|
20
|
+
cwd?: string;
|
|
18
21
|
/** Optional callback for ChatGPT Login rate-limit status updates from Codex. */
|
|
19
22
|
onCodexRateLimitStatus?: (snapshot: CodexRateLimitSnapshot) => void;
|
|
20
23
|
}
|
|
24
|
+
export interface CreateLLMServiceOptions {
|
|
25
|
+
usageScopeId?: string | undefined;
|
|
26
|
+
compactionStrategy?: CompactionStrategy | null | undefined;
|
|
27
|
+
cwd?: string | undefined;
|
|
28
|
+
}
|
|
21
29
|
/**
|
|
22
30
|
* Create a Vercel AI SDK LanguageModel from config.
|
|
23
31
|
*
|
|
@@ -41,9 +49,8 @@ export declare function createVercelModel(llmConfig: ValidatedLLMConfig, context
|
|
|
41
49
|
* @param sessionId Session ID
|
|
42
50
|
* @param resourceManager Resource manager for blob storage and resource access
|
|
43
51
|
* @param logger Logger instance for dependency injection
|
|
44
|
-
* @param
|
|
45
|
-
* @param compactionConfig Optional compaction configuration for thresholds
|
|
52
|
+
* @param options Session-scoped runtime options
|
|
46
53
|
* @returns VercelLLMService instance
|
|
47
54
|
*/
|
|
48
|
-
export declare function createLLMService(config: ValidatedLLMConfig, toolManager: ToolManager, systemPromptManager: SystemPromptManager, historyProvider: ConversationHistoryProvider, sessionEventBus: SessionEventBus, sessionId: string, resourceManager: import('../../resources/index.js').ResourceManager, logger: Logger,
|
|
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?: CreateLLMServiceOptions): VercelLLMService;
|
|
49
56
|
//# 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;AAGvD,OAAO,EAEH,KAAK,sBAAsB,EAC9B,MAAM,kCAAkC,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,C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
21
|
import { isCodexBaseURL } from "../providers/codex-base-url.js";
|
|
22
|
+
import { findDextoProjectRoot } from "../../utils/execution-context.js";
|
|
22
23
|
import {
|
|
23
24
|
ANTHROPIC_BETA_HEADER,
|
|
24
25
|
ANTHROPIC_INTERLEAVED_THINKING_BETA
|
|
@@ -34,6 +35,12 @@ const DEXTO_GATEWAY_HEADERS = {
|
|
|
34
35
|
CLIENT_SOURCE: "X-Dexto-Source",
|
|
35
36
|
CLIENT_VERSION: "X-Dexto-Version"
|
|
36
37
|
};
|
|
38
|
+
function resolveProviderWorkingDirectory(explicitCwd) {
|
|
39
|
+
if (explicitCwd && explicitCwd.trim().length > 0) {
|
|
40
|
+
return explicitCwd;
|
|
41
|
+
}
|
|
42
|
+
return findDextoProjectRoot(process.cwd()) ?? process.cwd();
|
|
43
|
+
}
|
|
37
44
|
function createVercelModel(llmConfig, context) {
|
|
38
45
|
const { provider, model, baseURL } = llmConfig;
|
|
39
46
|
const apiKey = llmConfig.apiKey || resolveApiKeyForProvider(provider);
|
|
@@ -54,6 +61,7 @@ function createVercelModel(llmConfig, context) {
|
|
|
54
61
|
return createCodexLanguageModel({
|
|
55
62
|
modelId: model,
|
|
56
63
|
baseURL: compatibleBaseURL,
|
|
64
|
+
cwd: resolveProviderWorkingDirectory(context?.cwd),
|
|
57
65
|
...context?.onCodexRateLimitStatus ? { onRateLimitStatus: context.onCodexRateLimitStatus } : {}
|
|
58
66
|
});
|
|
59
67
|
}
|
|
@@ -193,9 +201,11 @@ function createVercelModel(llmConfig, context) {
|
|
|
193
201
|
throw LLMError.unsupportedProvider(provider);
|
|
194
202
|
}
|
|
195
203
|
}
|
|
196
|
-
function createLLMService(config, toolManager, systemPromptManager, historyProvider, sessionEventBus, sessionId, resourceManager, logger,
|
|
204
|
+
function createLLMService(config, toolManager, systemPromptManager, historyProvider, sessionEventBus, sessionId, resourceManager, logger, options = {}) {
|
|
205
|
+
const { usageScopeId, compactionStrategy } = options;
|
|
197
206
|
const model = createVercelModel(config, {
|
|
198
207
|
sessionId,
|
|
208
|
+
...options.cwd !== void 0 ? { cwd: options.cwd } : {},
|
|
199
209
|
onCodexRateLimitStatus: (snapshot) => {
|
|
200
210
|
sessionEventBus.emit("llm:rate-limit-status", {
|
|
201
211
|
provider: config.provider,
|
|
@@ -214,6 +224,7 @@ function createLLMService(config, toolManager, systemPromptManager, historyProvi
|
|
|
214
224
|
sessionId,
|
|
215
225
|
resourceManager,
|
|
216
226
|
logger,
|
|
227
|
+
usageScopeId,
|
|
217
228
|
compactionStrategy
|
|
218
229
|
);
|
|
219
230
|
}
|
|
@@ -93,13 +93,14 @@ class VercelLLMService {
|
|
|
93
93
|
messageQueue;
|
|
94
94
|
compactionStrategy;
|
|
95
95
|
modelLimits;
|
|
96
|
+
usageScopeId;
|
|
96
97
|
/**
|
|
97
98
|
* Helper to extract model ID from LanguageModel union type (string | LanguageModelV2)
|
|
98
99
|
*/
|
|
99
100
|
getModelId() {
|
|
100
101
|
return typeof this.model === "string" ? this.model : this.model.modelId;
|
|
101
102
|
}
|
|
102
|
-
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, compactionStrategy) {
|
|
103
|
+
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, usageScopeId, compactionStrategy) {
|
|
103
104
|
this.logger = logger.createChild(import_types2.DextoLogComponent.LLM);
|
|
104
105
|
this.model = model;
|
|
105
106
|
this.config = config;
|
|
@@ -107,6 +108,7 @@ class VercelLLMService {
|
|
|
107
108
|
this.sessionEventBus = sessionEventBus;
|
|
108
109
|
this.sessionId = sessionId;
|
|
109
110
|
this.resourceManager = resourceManager;
|
|
111
|
+
this.usageScopeId = usageScopeId;
|
|
110
112
|
this.compactionStrategy = compactionStrategy ?? null;
|
|
111
113
|
this.messageQueue = new import_message_queue.MessageQueueService(this.sessionEventBus, this.logger);
|
|
112
114
|
const formatter = new import_vercel.VercelMessageFormatter(this.logger);
|
|
@@ -150,6 +152,7 @@ class VercelLLMService {
|
|
|
150
152
|
maxOutputTokens: this.config.maxOutputTokens,
|
|
151
153
|
temperature: this.config.temperature,
|
|
152
154
|
baseURL: this.config.baseURL,
|
|
155
|
+
usageScopeId: this.usageScopeId,
|
|
153
156
|
// Provider-specific options
|
|
154
157
|
reasoning: this.config.reasoning
|
|
155
158
|
},
|
|
@@ -37,11 +37,12 @@ export declare class VercelLLMService {
|
|
|
37
37
|
private messageQueue;
|
|
38
38
|
private compactionStrategy;
|
|
39
39
|
private modelLimits?;
|
|
40
|
+
private readonly usageScopeId;
|
|
40
41
|
/**
|
|
41
42
|
* Helper to extract model ID from LanguageModel union type (string | LanguageModelV2)
|
|
42
43
|
*/
|
|
43
44
|
private getModelId;
|
|
44
|
-
constructor(toolManager: ToolManager, model: LanguageModel, systemPromptManager: SystemPromptManager, historyProvider: ConversationHistoryProvider, sessionEventBus: SessionEventBus, config: ValidatedLLMConfig, sessionId: string, resourceManager: ResourceManager, logger: Logger, compactionStrategy?: import('../../context/compaction/types.js').CompactionStrategy | null);
|
|
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);
|
|
45
46
|
getAllTools(): Promise<ToolSet>;
|
|
46
47
|
getEnabledTools(): Promise<ToolSet>;
|
|
47
48
|
/**
|
|
@@ -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;AAC9C,OAAO,KAAK,E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AAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,EACrB,kBAAkB,CAAC,EAAE,OAAO,mCAAmC,EAAE,kBAAkB,GAAG,IAAI;IAwC9F,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAI/B,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IAMnC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA0B1B;;OAEG;IACH,OAAc,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAE7C;;;;;;;OAOG;IACG,MAAM,CACR,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACnC,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IA0D5B;;;OAGG;IACH,SAAS,IAAI,gBAAgB;IA+B7B;;OAEG;IACH,iBAAiB,IAAI,cAAc,CAAC,OAAO,CAAC;IAI5C;;OAEG;IACH,eAAe,IAAI,mBAAmB;IAItC;;OAEG;IACH,qBAAqB,IAAI,OAAO,mCAAmC,EAAE,kBAAkB,GAAG,IAAI;IAI9F,gBAAgB,IAAI,aAAa;CAGpC"}
|
|
@@ -30,13 +30,14 @@ class VercelLLMService {
|
|
|
30
30
|
messageQueue;
|
|
31
31
|
compactionStrategy;
|
|
32
32
|
modelLimits;
|
|
33
|
+
usageScopeId;
|
|
33
34
|
/**
|
|
34
35
|
* Helper to extract model ID from LanguageModel union type (string | LanguageModelV2)
|
|
35
36
|
*/
|
|
36
37
|
getModelId() {
|
|
37
38
|
return typeof this.model === "string" ? this.model : this.model.modelId;
|
|
38
39
|
}
|
|
39
|
-
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, compactionStrategy) {
|
|
40
|
+
constructor(toolManager, model, systemPromptManager, historyProvider, sessionEventBus, config, sessionId, resourceManager, logger, usageScopeId, compactionStrategy) {
|
|
40
41
|
this.logger = logger.createChild(DextoLogComponent.LLM);
|
|
41
42
|
this.model = model;
|
|
42
43
|
this.config = config;
|
|
@@ -44,6 +45,7 @@ class VercelLLMService {
|
|
|
44
45
|
this.sessionEventBus = sessionEventBus;
|
|
45
46
|
this.sessionId = sessionId;
|
|
46
47
|
this.resourceManager = resourceManager;
|
|
48
|
+
this.usageScopeId = usageScopeId;
|
|
47
49
|
this.compactionStrategy = compactionStrategy ?? null;
|
|
48
50
|
this.messageQueue = new MessageQueueService(this.sessionEventBus, this.logger);
|
|
49
51
|
const formatter = new VercelMessageFormatter(this.logger);
|
|
@@ -87,6 +89,7 @@ class VercelLLMService {
|
|
|
87
89
|
maxOutputTokens: this.config.maxOutputTokens,
|
|
88
90
|
temperature: this.config.temperature,
|
|
89
91
|
baseURL: this.config.baseURL,
|
|
92
|
+
usageScopeId: this.usageScopeId,
|
|
90
93
|
// Provider-specific options
|
|
91
94
|
reasoning: this.config.reasoning
|
|
92
95
|
},
|
package/dist/llm/usage-scope.cjs
CHANGED
|
@@ -18,21 +18,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var usage_scope_exports = {};
|
|
20
20
|
__export(usage_scope_exports, {
|
|
21
|
-
|
|
22
|
-
getConfiguredUsageScopeId: () => getConfiguredUsageScopeId
|
|
21
|
+
UsageScopeIdSchema: () => UsageScopeIdSchema
|
|
23
22
|
});
|
|
24
23
|
module.exports = __toCommonJS(usage_scope_exports);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const value = process.env[DEXTO_USAGE_SCOPE_ID_ENV];
|
|
28
|
-
if (!value) {
|
|
29
|
-
return void 0;
|
|
30
|
-
}
|
|
31
|
-
const trimmedValue = value.trim();
|
|
32
|
-
return trimmedValue.length > 0 ? trimmedValue : void 0;
|
|
33
|
-
}
|
|
24
|
+
var import_zod = require("zod");
|
|
25
|
+
const UsageScopeIdSchema = import_zod.z.string().trim().min(1);
|
|
34
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
27
|
0 && (module.exports = {
|
|
36
|
-
|
|
37
|
-
getConfiguredUsageScopeId
|
|
28
|
+
UsageScopeIdSchema
|
|
38
29
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const UsageScopeIdSchema: z.ZodString;
|
|
3
|
+
export type UsageScopeId = z.output<typeof UsageScopeIdSchema>;
|
|
3
4
|
//# sourceMappingURL=usage-scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-scope.d.ts","sourceRoot":"","sources":["../../src/llm/usage-scope.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"usage-scope.d.ts","sourceRoot":"","sources":["../../src/llm/usage-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,kBAAkB,aAA2B,CAAC;AAE3D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
package/dist/llm/usage-scope.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import "../chunk-PTJYTZNU.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const value = process.env[DEXTO_USAGE_SCOPE_ID_ENV];
|
|
5
|
-
if (!value) {
|
|
6
|
-
return void 0;
|
|
7
|
-
}
|
|
8
|
-
const trimmedValue = value.trim();
|
|
9
|
-
return trimmedValue.length > 0 ? trimmedValue : void 0;
|
|
10
|
-
}
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const UsageScopeIdSchema = z.string().trim().min(1);
|
|
11
4
|
export {
|
|
12
|
-
|
|
13
|
-
getConfiguredUsageScopeId
|
|
5
|
+
UsageScopeIdSchema
|
|
14
6
|
};
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var bundled_config_exports = {};
|
|
30
|
+
__export(bundled_config_exports, {
|
|
31
|
+
loadBundledMcpConfigFromDirectory: () => loadBundledMcpConfigFromDirectory
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(bundled_config_exports);
|
|
34
|
+
var import_fs = require("fs");
|
|
35
|
+
var path = __toESM(require("path"), 1);
|
|
36
|
+
var import_schemas = require("./schemas.js");
|
|
37
|
+
function normalizeServerEntries(servers, inferTransportType) {
|
|
38
|
+
const normalized = {};
|
|
39
|
+
for (const [serverName, serverConfig] of Object.entries(servers)) {
|
|
40
|
+
if (typeof serverConfig !== "object" || serverConfig === null || Array.isArray(serverConfig)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const config = serverConfig;
|
|
44
|
+
if ("type" in config || !inferTransportType) {
|
|
45
|
+
normalized[serverName] = config;
|
|
46
|
+
} else if ("command" in config) {
|
|
47
|
+
normalized[serverName] = {
|
|
48
|
+
type: "stdio",
|
|
49
|
+
...config
|
|
50
|
+
};
|
|
51
|
+
} else if ("url" in config) {
|
|
52
|
+
const url = String(config.url || "");
|
|
53
|
+
normalized[serverName] = {
|
|
54
|
+
type: url.includes("/sse") ? "sse" : "http",
|
|
55
|
+
...config
|
|
56
|
+
};
|
|
57
|
+
} else {
|
|
58
|
+
normalized[serverName] = config;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return normalized;
|
|
62
|
+
}
|
|
63
|
+
function normalizeParsedMcpServers(parsed, ownerName, sourceLabel, warnings) {
|
|
64
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
65
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: expected an object`);
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
const parsedRecord = parsed;
|
|
69
|
+
const candidate = parsedRecord.mcpServers;
|
|
70
|
+
if (candidate !== void 0) {
|
|
71
|
+
if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
72
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: mcpServers must be an object`);
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
return normalizeServerEntries(candidate, true);
|
|
76
|
+
}
|
|
77
|
+
if (Object.values(parsedRecord).some(
|
|
78
|
+
(value) => typeof value === "object" && value !== null && !Array.isArray(value) && ("type" in value || "command" in value || "url" in value)
|
|
79
|
+
)) {
|
|
80
|
+
return normalizeServerEntries(parsedRecord, true);
|
|
81
|
+
}
|
|
82
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: no MCP servers found`);
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
function resolveSkillRelativeValue(bundleDirectory, value) {
|
|
86
|
+
if (value.length === 0 || path.isAbsolute(value)) {
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
const candidate = path.resolve(bundleDirectory, value);
|
|
90
|
+
return (0, import_fs.existsSync)(candidate) ? candidate : value;
|
|
91
|
+
}
|
|
92
|
+
function resolveServerRelativePaths(bundleDirectory, serverConfig) {
|
|
93
|
+
if (serverConfig.type !== "stdio") {
|
|
94
|
+
return serverConfig;
|
|
95
|
+
}
|
|
96
|
+
const resolvedConfig = { ...serverConfig };
|
|
97
|
+
if (typeof resolvedConfig.command === "string") {
|
|
98
|
+
resolvedConfig.command = resolveSkillRelativeValue(bundleDirectory, resolvedConfig.command);
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(resolvedConfig.args)) {
|
|
101
|
+
resolvedConfig.args = resolvedConfig.args.map(
|
|
102
|
+
(arg) => typeof arg === "string" ? resolveSkillRelativeValue(bundleDirectory, arg) : arg
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return resolvedConfig;
|
|
106
|
+
}
|
|
107
|
+
function validateBundledMcpServers(bundleDirectory, parsedServers, ownerName, sourceLabel, warnings) {
|
|
108
|
+
const resolvedServers = Object.fromEntries(
|
|
109
|
+
Object.entries(parsedServers).map(([serverName, serverConfig]) => {
|
|
110
|
+
if (typeof serverConfig !== "object" || serverConfig === null || Array.isArray(serverConfig)) {
|
|
111
|
+
return [serverName, serverConfig];
|
|
112
|
+
}
|
|
113
|
+
return [
|
|
114
|
+
serverName,
|
|
115
|
+
resolveServerRelativePaths(
|
|
116
|
+
bundleDirectory,
|
|
117
|
+
serverConfig
|
|
118
|
+
)
|
|
119
|
+
];
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
const result = import_schemas.ServersConfigSchema.safeParse(resolvedServers);
|
|
123
|
+
if (!result.success) {
|
|
124
|
+
const issues = result.error.issues.map((issue) => issue.message).join(", ");
|
|
125
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: ${issues}`);
|
|
126
|
+
return void 0;
|
|
127
|
+
}
|
|
128
|
+
return result.data;
|
|
129
|
+
}
|
|
130
|
+
function mergeBundledMcpServers(current, incoming) {
|
|
131
|
+
if (!incoming) {
|
|
132
|
+
return current;
|
|
133
|
+
}
|
|
134
|
+
if (!current) {
|
|
135
|
+
return incoming;
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...current,
|
|
139
|
+
...incoming
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function loadBundledMcpConfigFile(filePath, bundleDirectory, ownerName, sourceLabel, warnings) {
|
|
143
|
+
if (!(0, import_fs.existsSync)(filePath)) {
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const content = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
148
|
+
const parsed = JSON.parse(content);
|
|
149
|
+
const parsedServers = normalizeParsedMcpServers(parsed, ownerName, sourceLabel, warnings);
|
|
150
|
+
if (!parsedServers) {
|
|
151
|
+
return void 0;
|
|
152
|
+
}
|
|
153
|
+
return validateBundledMcpServers(
|
|
154
|
+
bundleDirectory,
|
|
155
|
+
parsedServers,
|
|
156
|
+
ownerName,
|
|
157
|
+
sourceLabel,
|
|
158
|
+
warnings
|
|
159
|
+
);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (error instanceof SyntaxError) {
|
|
162
|
+
warnings.push(`[${ownerName}] Failed to parse ${sourceLabel}: invalid JSON`);
|
|
163
|
+
} else {
|
|
164
|
+
warnings.push(`[${ownerName}] Failed to load ${sourceLabel}: ${String(error)}`);
|
|
165
|
+
}
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function loadBundledMcpConfigFromDirectory(bundleDirectory, ownerName, options = {}) {
|
|
170
|
+
const warnings = [];
|
|
171
|
+
let mcpServers = loadBundledMcpConfigFile(
|
|
172
|
+
path.join(bundleDirectory, ".mcp.json"),
|
|
173
|
+
bundleDirectory,
|
|
174
|
+
ownerName,
|
|
175
|
+
".mcp.json",
|
|
176
|
+
warnings
|
|
177
|
+
);
|
|
178
|
+
if (options.scanNestedMcps) {
|
|
179
|
+
const mcpsDirectory = path.join(bundleDirectory, "mcps");
|
|
180
|
+
if ((0, import_fs.existsSync)(mcpsDirectory)) {
|
|
181
|
+
try {
|
|
182
|
+
const entries = (0, import_fs.readdirSync)(mcpsDirectory, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).sort((left, right) => left.name.localeCompare(right.name));
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
const nestedServers = loadBundledMcpConfigFile(
|
|
185
|
+
path.join(mcpsDirectory, entry.name),
|
|
186
|
+
bundleDirectory,
|
|
187
|
+
ownerName,
|
|
188
|
+
`mcps/${entry.name}`,
|
|
189
|
+
warnings
|
|
190
|
+
);
|
|
191
|
+
mcpServers = mergeBundledMcpServers(mcpServers, nestedServers);
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
warnings.push(`[${ownerName}] Failed to read mcps/: ${String(error)}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
...mcpServers ? { mcpServers } : {},
|
|
200
|
+
warnings
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
loadBundledMcpConfigFromDirectory
|
|
206
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ValidatedServersConfig } from './schemas.js';
|
|
2
|
+
export interface LoadBundledMcpConfigOptions {
|
|
3
|
+
scanNestedMcps?: boolean | undefined;
|
|
4
|
+
}
|
|
5
|
+
export interface LoadBundledMcpConfigResult {
|
|
6
|
+
mcpServers?: ValidatedServersConfig | undefined;
|
|
7
|
+
warnings: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function loadBundledMcpConfigFromDirectory(bundleDirectory: string, ownerName: string, options?: LoadBundledMcpConfigOptions): LoadBundledMcpConfigResult;
|
|
10
|
+
//# sourceMappingURL=bundled-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundled-config.d.ts","sourceRoot":"","sources":["../../src/mcp/bundled-config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAuB,KAAK,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEhF,MAAM,WAAW,2BAA2B;IACxC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACxC;AAED,MAAM,WAAW,0BAA0B;IACvC,UAAU,CAAC,EAAE,sBAAsB,GAAG,SAAS,CAAC;IAChD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB;AAwMD,wBAAgB,iCAAiC,CAC7C,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,2BAAgC,GAC1C,0BAA0B,CAsC5B"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import "../chunk-PTJYTZNU.js";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync } from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { ServersConfigSchema } from "./schemas.js";
|
|
5
|
+
function normalizeServerEntries(servers, inferTransportType) {
|
|
6
|
+
const normalized = {};
|
|
7
|
+
for (const [serverName, serverConfig] of Object.entries(servers)) {
|
|
8
|
+
if (typeof serverConfig !== "object" || serverConfig === null || Array.isArray(serverConfig)) {
|
|
9
|
+
continue;
|
|
10
|
+
}
|
|
11
|
+
const config = serverConfig;
|
|
12
|
+
if ("type" in config || !inferTransportType) {
|
|
13
|
+
normalized[serverName] = config;
|
|
14
|
+
} else if ("command" in config) {
|
|
15
|
+
normalized[serverName] = {
|
|
16
|
+
type: "stdio",
|
|
17
|
+
...config
|
|
18
|
+
};
|
|
19
|
+
} else if ("url" in config) {
|
|
20
|
+
const url = String(config.url || "");
|
|
21
|
+
normalized[serverName] = {
|
|
22
|
+
type: url.includes("/sse") ? "sse" : "http",
|
|
23
|
+
...config
|
|
24
|
+
};
|
|
25
|
+
} else {
|
|
26
|
+
normalized[serverName] = config;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
function normalizeParsedMcpServers(parsed, ownerName, sourceLabel, warnings) {
|
|
32
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
33
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: expected an object`);
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
const parsedRecord = parsed;
|
|
37
|
+
const candidate = parsedRecord.mcpServers;
|
|
38
|
+
if (candidate !== void 0) {
|
|
39
|
+
if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
40
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: mcpServers must be an object`);
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
return normalizeServerEntries(candidate, true);
|
|
44
|
+
}
|
|
45
|
+
if (Object.values(parsedRecord).some(
|
|
46
|
+
(value) => typeof value === "object" && value !== null && !Array.isArray(value) && ("type" in value || "command" in value || "url" in value)
|
|
47
|
+
)) {
|
|
48
|
+
return normalizeServerEntries(parsedRecord, true);
|
|
49
|
+
}
|
|
50
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: no MCP servers found`);
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
function resolveSkillRelativeValue(bundleDirectory, value) {
|
|
54
|
+
if (value.length === 0 || path.isAbsolute(value)) {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
const candidate = path.resolve(bundleDirectory, value);
|
|
58
|
+
return existsSync(candidate) ? candidate : value;
|
|
59
|
+
}
|
|
60
|
+
function resolveServerRelativePaths(bundleDirectory, serverConfig) {
|
|
61
|
+
if (serverConfig.type !== "stdio") {
|
|
62
|
+
return serverConfig;
|
|
63
|
+
}
|
|
64
|
+
const resolvedConfig = { ...serverConfig };
|
|
65
|
+
if (typeof resolvedConfig.command === "string") {
|
|
66
|
+
resolvedConfig.command = resolveSkillRelativeValue(bundleDirectory, resolvedConfig.command);
|
|
67
|
+
}
|
|
68
|
+
if (Array.isArray(resolvedConfig.args)) {
|
|
69
|
+
resolvedConfig.args = resolvedConfig.args.map(
|
|
70
|
+
(arg) => typeof arg === "string" ? resolveSkillRelativeValue(bundleDirectory, arg) : arg
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return resolvedConfig;
|
|
74
|
+
}
|
|
75
|
+
function validateBundledMcpServers(bundleDirectory, parsedServers, ownerName, sourceLabel, warnings) {
|
|
76
|
+
const resolvedServers = Object.fromEntries(
|
|
77
|
+
Object.entries(parsedServers).map(([serverName, serverConfig]) => {
|
|
78
|
+
if (typeof serverConfig !== "object" || serverConfig === null || Array.isArray(serverConfig)) {
|
|
79
|
+
return [serverName, serverConfig];
|
|
80
|
+
}
|
|
81
|
+
return [
|
|
82
|
+
serverName,
|
|
83
|
+
resolveServerRelativePaths(
|
|
84
|
+
bundleDirectory,
|
|
85
|
+
serverConfig
|
|
86
|
+
)
|
|
87
|
+
];
|
|
88
|
+
})
|
|
89
|
+
);
|
|
90
|
+
const result = ServersConfigSchema.safeParse(resolvedServers);
|
|
91
|
+
if (!result.success) {
|
|
92
|
+
const issues = result.error.issues.map((issue) => issue.message).join(", ");
|
|
93
|
+
warnings.push(`[${ownerName}] Invalid ${sourceLabel}: ${issues}`);
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
return result.data;
|
|
97
|
+
}
|
|
98
|
+
function mergeBundledMcpServers(current, incoming) {
|
|
99
|
+
if (!incoming) {
|
|
100
|
+
return current;
|
|
101
|
+
}
|
|
102
|
+
if (!current) {
|
|
103
|
+
return incoming;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
...current,
|
|
107
|
+
...incoming
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function loadBundledMcpConfigFile(filePath, bundleDirectory, ownerName, sourceLabel, warnings) {
|
|
111
|
+
if (!existsSync(filePath)) {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const content = readFileSync(filePath, "utf-8");
|
|
116
|
+
const parsed = JSON.parse(content);
|
|
117
|
+
const parsedServers = normalizeParsedMcpServers(parsed, ownerName, sourceLabel, warnings);
|
|
118
|
+
if (!parsedServers) {
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
return validateBundledMcpServers(
|
|
122
|
+
bundleDirectory,
|
|
123
|
+
parsedServers,
|
|
124
|
+
ownerName,
|
|
125
|
+
sourceLabel,
|
|
126
|
+
warnings
|
|
127
|
+
);
|
|
128
|
+
} catch (error) {
|
|
129
|
+
if (error instanceof SyntaxError) {
|
|
130
|
+
warnings.push(`[${ownerName}] Failed to parse ${sourceLabel}: invalid JSON`);
|
|
131
|
+
} else {
|
|
132
|
+
warnings.push(`[${ownerName}] Failed to load ${sourceLabel}: ${String(error)}`);
|
|
133
|
+
}
|
|
134
|
+
return void 0;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function loadBundledMcpConfigFromDirectory(bundleDirectory, ownerName, options = {}) {
|
|
138
|
+
const warnings = [];
|
|
139
|
+
let mcpServers = loadBundledMcpConfigFile(
|
|
140
|
+
path.join(bundleDirectory, ".mcp.json"),
|
|
141
|
+
bundleDirectory,
|
|
142
|
+
ownerName,
|
|
143
|
+
".mcp.json",
|
|
144
|
+
warnings
|
|
145
|
+
);
|
|
146
|
+
if (options.scanNestedMcps) {
|
|
147
|
+
const mcpsDirectory = path.join(bundleDirectory, "mcps");
|
|
148
|
+
if (existsSync(mcpsDirectory)) {
|
|
149
|
+
try {
|
|
150
|
+
const entries = readdirSync(mcpsDirectory, { withFileTypes: true }).filter((entry) => entry.isFile() && entry.name.endsWith(".json")).sort((left, right) => left.name.localeCompare(right.name));
|
|
151
|
+
for (const entry of entries) {
|
|
152
|
+
const nestedServers = loadBundledMcpConfigFile(
|
|
153
|
+
path.join(mcpsDirectory, entry.name),
|
|
154
|
+
bundleDirectory,
|
|
155
|
+
ownerName,
|
|
156
|
+
`mcps/${entry.name}`,
|
|
157
|
+
warnings
|
|
158
|
+
);
|
|
159
|
+
mcpServers = mergeBundledMcpServers(mcpServers, nestedServers);
|
|
160
|
+
}
|
|
161
|
+
} catch (error) {
|
|
162
|
+
warnings.push(`[${ownerName}] Failed to read mcps/: ${String(error)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
...mcpServers ? { mcpServers } : {},
|
|
168
|
+
warnings
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
export {
|
|
172
|
+
loadBundledMcpConfigFromDirectory
|
|
173
|
+
};
|