apcore-mcp 0.2.0 → 0.4.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/adapters/annotations.d.ts +6 -2
- package/dist/adapters/annotations.d.ts.map +1 -1
- package/dist/adapters/annotations.js +27 -9
- package/dist/adapters/annotations.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -5
- package/dist/cli.js.map +1 -1
- package/dist/helpers.d.ts +44 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +45 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +37 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +91 -19
- package/dist/index.js.map +1 -1
- package/dist/server/context.d.ts +31 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +39 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/factory.d.ts +12 -0
- package/dist/server/factory.d.ts.map +1 -1
- package/dist/server/factory.js +97 -15
- package/dist/server/factory.js.map +1 -1
- package/dist/server/router.d.ts +35 -3
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/router.js +147 -7
- package/dist/server/router.js.map +1 -1
- package/dist/server/transport.d.ts +37 -0
- package/dist/server/transport.d.ts.map +1 -1
- package/dist/server/transport.js +73 -0
- package/dist/server/transport.js.map +1 -1
- package/dist/types.d.ts +8 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +19 -2
|
@@ -21,10 +21,14 @@ export declare class AnnotationMapper {
|
|
|
21
21
|
/**
|
|
22
22
|
* Generate a description suffix string from annotations.
|
|
23
23
|
*
|
|
24
|
+
* Only includes annotation fields that differ from their default values:
|
|
25
|
+
* readonly=false, destructive=false, idempotent=false,
|
|
26
|
+
* requires_approval=false, open_world=true
|
|
27
|
+
*
|
|
24
28
|
* Returns a formatted string like:
|
|
25
|
-
* `\n\n[Annotations: readonly=true,
|
|
29
|
+
* `\n\n[Annotations: readonly=true, idempotent=true]`
|
|
26
30
|
*
|
|
27
|
-
* Returns an empty string if annotations are null.
|
|
31
|
+
* Returns an empty string if annotations are null or all fields are defaults.
|
|
28
32
|
*/
|
|
29
33
|
toDescriptionSuffix(annotations: ModuleAnnotations | null): string;
|
|
30
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/adapters/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEzE,qBAAa,gBAAgB;IAC3B;;;;;;;;;OASG;IACH,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,kBAAkB;IAoB3E
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/adapters/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEzE,qBAAa,gBAAgB;IAC3B;;;;;;;;;OASG;IACH,gBAAgB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,kBAAkB;IAoB3E;;;;;;;;;;;OAWG;IACH,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,MAAM;IAgClE;;;;OAIG;IACH,mBAAmB,CAAC,WAAW,EAAE,iBAAiB,GAAG,IAAI,GAAG,OAAO;CAOpE"}
|
|
@@ -37,22 +37,40 @@ export class AnnotationMapper {
|
|
|
37
37
|
/**
|
|
38
38
|
* Generate a description suffix string from annotations.
|
|
39
39
|
*
|
|
40
|
+
* Only includes annotation fields that differ from their default values:
|
|
41
|
+
* readonly=false, destructive=false, idempotent=false,
|
|
42
|
+
* requires_approval=false, open_world=true
|
|
43
|
+
*
|
|
40
44
|
* Returns a formatted string like:
|
|
41
|
-
* `\n\n[Annotations: readonly=true,
|
|
45
|
+
* `\n\n[Annotations: readonly=true, idempotent=true]`
|
|
42
46
|
*
|
|
43
|
-
* Returns an empty string if annotations are null.
|
|
47
|
+
* Returns an empty string if annotations are null or all fields are defaults.
|
|
44
48
|
*/
|
|
45
49
|
toDescriptionSuffix(annotations) {
|
|
46
50
|
if (annotations === null) {
|
|
47
51
|
return "";
|
|
48
52
|
}
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const DEFAULTS = {
|
|
54
|
+
readonly: false,
|
|
55
|
+
destructive: false,
|
|
56
|
+
idempotent: false,
|
|
57
|
+
requires_approval: false,
|
|
58
|
+
open_world: true,
|
|
59
|
+
};
|
|
60
|
+
const parts = [];
|
|
61
|
+
if (annotations.readonly !== DEFAULTS.readonly)
|
|
62
|
+
parts.push(`readonly=${annotations.readonly}`);
|
|
63
|
+
if (annotations.destructive !== DEFAULTS.destructive)
|
|
64
|
+
parts.push(`destructive=${annotations.destructive}`);
|
|
65
|
+
if (annotations.idempotent !== DEFAULTS.idempotent)
|
|
66
|
+
parts.push(`idempotent=${annotations.idempotent}`);
|
|
67
|
+
if (annotations.requiresApproval !== DEFAULTS.requires_approval)
|
|
68
|
+
parts.push(`requires_approval=${annotations.requiresApproval}`);
|
|
69
|
+
if (annotations.openWorld !== DEFAULTS.open_world)
|
|
70
|
+
parts.push(`open_world=${annotations.openWorld}`);
|
|
71
|
+
if (parts.length === 0) {
|
|
72
|
+
return "";
|
|
73
|
+
}
|
|
56
74
|
return `\n\n[Annotations: ${parts.join(", ")}]`;
|
|
57
75
|
}
|
|
58
76
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.js","sourceRoot":"","sources":["../../src/adapters/annotations.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,OAAO,gBAAgB;IAC3B;;;;;;;;;OASG;IACH,gBAAgB,CAAC,WAAqC;QACpD,I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IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AAiCH,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA4G1C"}
|
package/dist/cli.js
CHANGED
|
@@ -93,22 +93,27 @@ export async function main() {
|
|
|
93
93
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
94
|
let Registry;
|
|
95
95
|
try {
|
|
96
|
-
|
|
97
|
-
const apcore = await import("apcore");
|
|
96
|
+
const apcore = await import("apcore-js");
|
|
98
97
|
Registry = apcore.Registry;
|
|
99
98
|
}
|
|
100
99
|
catch {
|
|
101
|
-
fail("Failed to import 'apcore' package. Install it with: npm install apcore");
|
|
100
|
+
fail("Failed to import 'apcore-js' package. Install it with: npm install apcore-js");
|
|
102
101
|
}
|
|
103
102
|
// Create Registry and discover modules
|
|
104
|
-
const registry = new Registry({
|
|
105
|
-
const numModules = registry.discover();
|
|
103
|
+
const registry = new Registry({ extensionsDir: resolvedDir });
|
|
104
|
+
const numModules = await registry.discover();
|
|
106
105
|
if (numModules === 0) {
|
|
107
106
|
console.warn(`Warning: No modules discovered in '${extensionsDir}'.`);
|
|
108
107
|
}
|
|
109
108
|
else {
|
|
110
109
|
console.info(`Discovered ${numModules} module(s) in '${extensionsDir}'.`);
|
|
111
110
|
}
|
|
111
|
+
// Validate log-level
|
|
112
|
+
const logLevel = values["log-level"];
|
|
113
|
+
const validLogLevels = ["DEBUG", "INFO", "WARNING", "ERROR"];
|
|
114
|
+
if (logLevel && !validLogLevels.includes(logLevel)) {
|
|
115
|
+
fail(`--log-level must be one of: ${validLogLevels.join(", ")}. Got '${logLevel}'.`);
|
|
116
|
+
}
|
|
112
117
|
// Launch the MCP server
|
|
113
118
|
try {
|
|
114
119
|
await serve(registry, {
|
|
@@ -117,6 +122,7 @@ export async function main() {
|
|
|
117
122
|
port,
|
|
118
123
|
name,
|
|
119
124
|
version: values.version ?? undefined,
|
|
125
|
+
logLevel: logLevel,
|
|
120
126
|
});
|
|
121
127
|
}
|
|
122
128
|
catch (error) {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5C,SAAS,UAAU;IACjB,OAAO,CAAC,GAAG,CAAC;cACA,OAAO;;;;;;;;;;;;;;;;CAgBpB,CAAC,CAAC;AACH,CAAC;AAED,SAAS,IAAI,CAAC,OAAe,EAAE,WAAmB,CAAC;IACjD,OAAO,CAAC,KAAK,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI;IACxB,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,SAAS,CAAC;YACjB,OAAO,EAAE;gBACP,gBAAgB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACpC,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE;gBAC/C,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE;gBAC9C,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE;gBACzC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE;gBAC/C,OA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AC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP extension helpers for apcore modules.
|
|
3
|
+
*
|
|
4
|
+
* Provides reportProgress() and elicit() that modules can call during execute().
|
|
5
|
+
* Both read callbacks injected into context.data by the ExecutionRouter.
|
|
6
|
+
* Gracefully no-op when callbacks are absent (non-MCP execution paths).
|
|
7
|
+
*/
|
|
8
|
+
/** Structural type for any object carrying a `data` dict (duck-typed Context). */
|
|
9
|
+
interface HasData {
|
|
10
|
+
data: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/** Key under context.data where the progress callback is stored. */
|
|
13
|
+
export declare const MCP_PROGRESS_KEY = "_mcp_progress";
|
|
14
|
+
/** Key under context.data where the elicitation callback is stored. */
|
|
15
|
+
export declare const MCP_ELICIT_KEY = "_mcp_elicit";
|
|
16
|
+
/** Result returned from an elicitation request. */
|
|
17
|
+
export interface ElicitResult {
|
|
18
|
+
action: "accept" | "decline" | "cancel";
|
|
19
|
+
content?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Report execution progress to the MCP client.
|
|
23
|
+
*
|
|
24
|
+
* No-ops silently when called outside an MCP context (no callback injected).
|
|
25
|
+
*
|
|
26
|
+
* @param context - Object with a `data` dict (apcore Context or BridgeContext)
|
|
27
|
+
* @param progress - Current progress value
|
|
28
|
+
* @param total - Optional total for percentage calculation
|
|
29
|
+
* @param message - Optional human-readable progress message
|
|
30
|
+
*/
|
|
31
|
+
export declare function reportProgress(context: HasData, progress: number, total?: number, message?: string): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Ask the MCP client for user input via the elicitation protocol.
|
|
34
|
+
*
|
|
35
|
+
* Returns null when called outside an MCP context (no callback injected).
|
|
36
|
+
*
|
|
37
|
+
* @param context - Object with a `data` dict (apcore Context or BridgeContext)
|
|
38
|
+
* @param message - Message to display to the user
|
|
39
|
+
* @param requestedSchema - Optional JSON Schema describing the expected input
|
|
40
|
+
* @returns ElicitResult with the user's action and optional content, or null
|
|
41
|
+
*/
|
|
42
|
+
export declare function elicit(context: HasData, message: string, requestedSchema?: Record<string, unknown>): Promise<ElicitResult | null>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,kFAAkF;AAClF,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,oEAAoE;AACpE,eAAO,MAAM,gBAAgB,kBAAkB,CAAC;AAEhD,uEAAuE;AACvE,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C,mDAAmD;AACnD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAQ9B"}
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP extension helpers for apcore modules.
|
|
3
|
+
*
|
|
4
|
+
* Provides reportProgress() and elicit() that modules can call during execute().
|
|
5
|
+
* Both read callbacks injected into context.data by the ExecutionRouter.
|
|
6
|
+
* Gracefully no-op when callbacks are absent (non-MCP execution paths).
|
|
7
|
+
*/
|
|
8
|
+
/** Key under context.data where the progress callback is stored. */
|
|
9
|
+
export const MCP_PROGRESS_KEY = "_mcp_progress";
|
|
10
|
+
/** Key under context.data where the elicitation callback is stored. */
|
|
11
|
+
export const MCP_ELICIT_KEY = "_mcp_elicit";
|
|
12
|
+
/**
|
|
13
|
+
* Report execution progress to the MCP client.
|
|
14
|
+
*
|
|
15
|
+
* No-ops silently when called outside an MCP context (no callback injected).
|
|
16
|
+
*
|
|
17
|
+
* @param context - Object with a `data` dict (apcore Context or BridgeContext)
|
|
18
|
+
* @param progress - Current progress value
|
|
19
|
+
* @param total - Optional total for percentage calculation
|
|
20
|
+
* @param message - Optional human-readable progress message
|
|
21
|
+
*/
|
|
22
|
+
export async function reportProgress(context, progress, total, message) {
|
|
23
|
+
const callback = context.data[MCP_PROGRESS_KEY];
|
|
24
|
+
if (callback) {
|
|
25
|
+
await callback(progress, total, message);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ask the MCP client for user input via the elicitation protocol.
|
|
30
|
+
*
|
|
31
|
+
* Returns null when called outside an MCP context (no callback injected).
|
|
32
|
+
*
|
|
33
|
+
* @param context - Object with a `data` dict (apcore Context or BridgeContext)
|
|
34
|
+
* @param message - Message to display to the user
|
|
35
|
+
* @param requestedSchema - Optional JSON Schema describing the expected input
|
|
36
|
+
* @returns ElicitResult with the user's action and optional content, or null
|
|
37
|
+
*/
|
|
38
|
+
export async function elicit(context, message, requestedSchema) {
|
|
39
|
+
const callback = context.data[MCP_ELICIT_KEY];
|
|
40
|
+
if (callback) {
|
|
41
|
+
return callback(message, requestedSchema);
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,oEAAoE;AACpE,MAAM,CAAC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AAEhD,uEAAuE;AACvE,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAQ5C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAgB,EAChB,QAAgB,EAChB,KAAc,EACd,OAAgB;IAEhB,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAEjC,CAAC;IACd,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAgB,EAChB,OAAe,EACf,eAAyC;IAEzC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,cAAc,CAE/B,CAAC;IACd,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,16 +6,22 @@
|
|
|
6
6
|
* - toOpenaiTools(registryOrExecutor, options?) - Export OpenAI tool definitions
|
|
7
7
|
*/
|
|
8
8
|
import type { ConvertRegistryOptions } from "./converters/openai.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { MetricsExporter } from "./server/transport.js";
|
|
10
|
+
import type { RegistryOrExecutor, Registry, Executor, OpenAIToolDef } from "./types.js";
|
|
10
11
|
export declare const VERSION: string;
|
|
11
12
|
export type { Registry, Executor, RegistryOrExecutor, OpenAIToolDef } from "./types.js";
|
|
12
13
|
export type { ModuleDescriptor, ModuleAnnotations, JsonSchema, ModuleError, McpAnnotationsDict, McpErrorResponse, TextContentDict, } from "./types.js";
|
|
13
14
|
export { REGISTRY_EVENTS, ErrorCodes, MODULE_ID_PATTERN } from "./types.js";
|
|
15
|
+
export { reportProgress, elicit, MCP_PROGRESS_KEY, MCP_ELICIT_KEY } from "./helpers.js";
|
|
16
|
+
export type { ElicitResult } from "./helpers.js";
|
|
17
|
+
export { createBridgeContext } from "./server/context.js";
|
|
18
|
+
export type { BridgeContext } from "./server/context.js";
|
|
14
19
|
export { MCPServerFactory } from "./server/factory.js";
|
|
15
20
|
export { ExecutionRouter } from "./server/router.js";
|
|
16
|
-
export type { CallResult } from "./server/router.js";
|
|
21
|
+
export type { CallResult, HandleCallExtra, ExecutionRouterOptions } from "./server/router.js";
|
|
17
22
|
export { RegistryListener } from "./server/listener.js";
|
|
18
23
|
export { TransportManager } from "./server/transport.js";
|
|
24
|
+
export type { MetricsExporter } from "./server/transport.js";
|
|
19
25
|
export { AnnotationMapper } from "./adapters/annotations.js";
|
|
20
26
|
export { SchemaConverter } from "./adapters/schema.js";
|
|
21
27
|
export { ErrorMapper } from "./adapters/errors.js";
|
|
@@ -23,6 +29,23 @@ export { ModuleIDNormalizer } from "./adapters/idNormalizer.js";
|
|
|
23
29
|
export { OpenAIConverter } from "./converters/openai.js";
|
|
24
30
|
export type { ConvertOptions, ConvertRegistryOptions } from "./converters/openai.js";
|
|
25
31
|
export type { BuildToolsOptions } from "./server/factory.js";
|
|
32
|
+
/**
|
|
33
|
+
* Extract Registry from either a Registry or Executor instance.
|
|
34
|
+
*
|
|
35
|
+
* If the argument has a `registry` property (i.e. it's an Executor),
|
|
36
|
+
* returns that property. Otherwise assumes it's a Registry and returns it directly.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveRegistry(registryOrExecutor: RegistryOrExecutor): Registry;
|
|
39
|
+
/**
|
|
40
|
+
* Get or create an Executor from either a Registry or Executor instance.
|
|
41
|
+
*
|
|
42
|
+
* If the argument already has `call` or `callAsync`, returns it directly.
|
|
43
|
+
* If a bare Registry is passed, attempts to dynamically import the Executor
|
|
44
|
+
* from apcore-js and create a default instance (matching Python's resolve_executor).
|
|
45
|
+
*
|
|
46
|
+
* @throws {Error} If the argument is a Registry and apcore-js is not installed.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveExecutor(registryOrExecutor: RegistryOrExecutor): Executor;
|
|
26
49
|
/** Options for serve() */
|
|
27
50
|
export interface ServeOptions {
|
|
28
51
|
/** Transport type. Default: "stdio" */
|
|
@@ -39,6 +62,18 @@ export interface ServeOptions {
|
|
|
39
62
|
dynamic?: boolean;
|
|
40
63
|
/** Enable input validation against schemas. Default: false */
|
|
41
64
|
validateInputs?: boolean;
|
|
65
|
+
/** Filter modules by tags. Default: null (no filtering) */
|
|
66
|
+
tags?: string[] | null;
|
|
67
|
+
/** Filter modules by prefix. Default: null (no filtering) */
|
|
68
|
+
prefix?: string | null;
|
|
69
|
+
/** Minimum log level. Suppresses console methods below this level. Default: undefined (no suppression) */
|
|
70
|
+
logLevel?: "DEBUG" | "INFO" | "WARNING" | "ERROR" | "CRITICAL";
|
|
71
|
+
/** Callback invoked before the server starts. */
|
|
72
|
+
onStartup?: () => void | Promise<void>;
|
|
73
|
+
/** Callback invoked after the server stops (or on error). */
|
|
74
|
+
onShutdown?: () => void | Promise<void>;
|
|
75
|
+
/** Optional MetricsCollector for Prometheus /metrics endpoint. */
|
|
76
|
+
metricsCollector?: MetricsExporter;
|
|
42
77
|
}
|
|
43
78
|
/**
|
|
44
79
|
* Launch an MCP Server that exposes all apcore modules as tools.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAIrE,OAAO,KAAK,EACV,kBAAkB,
|
|
1
|
+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AAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,eAAe,CAAC;CACpC;AAED;;;;;GAKG;AACH,wBAAsB,KAAK,CACzB,kBAAkB,EAAE,kBAAkB,EACtC,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CA8Ff;AAED,kCAAkC;AAClC,MAAM,WAAW,oBAAqB,SAAQ,sBAAsB;CAAG;AAEvE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,kBAAkB,EACtC,OAAO,GAAE,oBAAyB,GACjC,aAAa,EAAE,CAKjB"}
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,9 @@ const require = createRequire(import.meta.url);
|
|
|
14
14
|
const pkg = require("../package.json");
|
|
15
15
|
export const VERSION = pkg.version;
|
|
16
16
|
export { REGISTRY_EVENTS, ErrorCodes, MODULE_ID_PATTERN } from "./types.js";
|
|
17
|
+
// ─── Extension Helpers ───────────────────────────────────────────────────────
|
|
18
|
+
export { reportProgress, elicit, MCP_PROGRESS_KEY, MCP_ELICIT_KEY } from "./helpers.js";
|
|
19
|
+
export { createBridgeContext } from "./server/context.js";
|
|
17
20
|
// ─── Building Block Exports ──────────────────────────────────────────────────
|
|
18
21
|
export { MCPServerFactory } from "./server/factory.js";
|
|
19
22
|
export { ExecutionRouter } from "./server/router.js";
|
|
@@ -26,8 +29,11 @@ export { ModuleIDNormalizer } from "./adapters/idNormalizer.js";
|
|
|
26
29
|
export { OpenAIConverter } from "./converters/openai.js";
|
|
27
30
|
/**
|
|
28
31
|
* Extract Registry from either a Registry or Executor instance.
|
|
32
|
+
*
|
|
33
|
+
* If the argument has a `registry` property (i.e. it's an Executor),
|
|
34
|
+
* returns that property. Otherwise assumes it's a Registry and returns it directly.
|
|
29
35
|
*/
|
|
30
|
-
function resolveRegistry(registryOrExecutor) {
|
|
36
|
+
export function resolveRegistry(registryOrExecutor) {
|
|
31
37
|
if ("registry" in registryOrExecutor) {
|
|
32
38
|
// It's an Executor — get its registry
|
|
33
39
|
return registryOrExecutor.registry;
|
|
@@ -37,16 +43,31 @@ function resolveRegistry(registryOrExecutor) {
|
|
|
37
43
|
}
|
|
38
44
|
/**
|
|
39
45
|
* Get or create an Executor from either a Registry or Executor instance.
|
|
46
|
+
*
|
|
47
|
+
* If the argument already has `call` or `callAsync`, returns it directly.
|
|
48
|
+
* If a bare Registry is passed, attempts to dynamically import the Executor
|
|
49
|
+
* from apcore-js and create a default instance (matching Python's resolve_executor).
|
|
50
|
+
*
|
|
51
|
+
* @throws {Error} If the argument is a Registry and apcore-js is not installed.
|
|
40
52
|
*/
|
|
41
|
-
function resolveExecutor(registryOrExecutor) {
|
|
53
|
+
export function resolveExecutor(registryOrExecutor) {
|
|
42
54
|
if ("call" in registryOrExecutor || "callAsync" in registryOrExecutor) {
|
|
43
55
|
// Already an Executor
|
|
44
56
|
return registryOrExecutor;
|
|
45
57
|
}
|
|
46
|
-
// It's a Registry —
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
// It's a bare Registry — create a default Executor
|
|
59
|
+
try {
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
61
|
+
const apcore = require("apcore-js");
|
|
62
|
+
const ExecutorClass = apcore.Executor ?? apcore.default?.Executor;
|
|
63
|
+
if (ExecutorClass) {
|
|
64
|
+
return new ExecutorClass({ registry: registryOrExecutor });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// apcore-js not installed — fall through to error
|
|
69
|
+
}
|
|
70
|
+
throw new Error("serve() requires an Executor instance, or apcore-js must be installed to auto-create one from a Registry.");
|
|
50
71
|
}
|
|
51
72
|
/**
|
|
52
73
|
* Launch an MCP Server that exposes all apcore modules as tools.
|
|
@@ -55,29 +76,80 @@ function resolveExecutor(registryOrExecutor) {
|
|
|
55
76
|
* @param options - Server configuration options.
|
|
56
77
|
*/
|
|
57
78
|
export async function serve(registryOrExecutor, options = {}) {
|
|
58
|
-
const { transport = "stdio", host = "127.0.0.1", port = 8000, name = "apcore-mcp", version = VERSION, } = options;
|
|
79
|
+
const { transport = "stdio", host = "127.0.0.1", port = 8000, name = "apcore-mcp", version = VERSION, validateInputs, tags, prefix, logLevel, onStartup, onShutdown, metricsCollector, } = options;
|
|
80
|
+
// Input validation (matching Python's checks)
|
|
81
|
+
if (!name || name.length === 0) {
|
|
82
|
+
throw new Error("name must not be empty");
|
|
83
|
+
}
|
|
84
|
+
if (name.length > 255) {
|
|
85
|
+
throw new Error("name must not exceed 255 characters");
|
|
86
|
+
}
|
|
87
|
+
if (tags) {
|
|
88
|
+
for (const tag of tags) {
|
|
89
|
+
if (!tag || tag.length === 0) {
|
|
90
|
+
throw new Error("tags must not contain empty strings");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (prefix !== undefined && prefix !== null && prefix.length === 0) {
|
|
95
|
+
throw new Error("prefix must not be empty if provided");
|
|
96
|
+
}
|
|
97
|
+
// Save original console methods before suppression
|
|
98
|
+
const origDebug = console.debug;
|
|
99
|
+
const origInfo = console.info;
|
|
100
|
+
const origWarn = console.warn;
|
|
101
|
+
const origError = console.error;
|
|
102
|
+
// Apply log-level suppression
|
|
103
|
+
if (logLevel) {
|
|
104
|
+
const levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"];
|
|
105
|
+
const minLevel = levels.indexOf(logLevel);
|
|
106
|
+
if (minLevel > 0)
|
|
107
|
+
console.debug = () => { };
|
|
108
|
+
if (minLevel > 1)
|
|
109
|
+
console.info = () => { };
|
|
110
|
+
if (minLevel > 2)
|
|
111
|
+
console.warn = () => { };
|
|
112
|
+
if (minLevel > 3)
|
|
113
|
+
console.error = () => { };
|
|
114
|
+
}
|
|
59
115
|
const registry = resolveRegistry(registryOrExecutor);
|
|
60
116
|
const executor = resolveExecutor(registryOrExecutor);
|
|
61
117
|
// Build MCP server components
|
|
62
118
|
const factory = new MCPServerFactory();
|
|
63
119
|
const server = factory.createServer(name, version);
|
|
64
|
-
const tools = factory.buildTools(registry);
|
|
65
|
-
const router = new ExecutionRouter(executor);
|
|
120
|
+
const tools = factory.buildTools(registry, { tags, prefix });
|
|
121
|
+
const router = new ExecutionRouter(executor, { validateInputs });
|
|
66
122
|
factory.registerHandlers(server, tools, router);
|
|
67
|
-
|
|
123
|
+
factory.registerResourceHandlers(server, registry);
|
|
124
|
+
origInfo(`Starting MCP server '${name}' v${version} with ${tools.length} tools via ${transport}`);
|
|
125
|
+
// Invoke startup callback
|
|
126
|
+
await onStartup?.();
|
|
68
127
|
// Select and run transport
|
|
69
128
|
const transportManager = new TransportManager();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
else if (transport === "streamable-http") {
|
|
74
|
-
await transportManager.runStreamableHttp(server, { host, port });
|
|
129
|
+
transportManager.setModuleCount(tools.length);
|
|
130
|
+
if (metricsCollector) {
|
|
131
|
+
transportManager.setMetricsCollector(metricsCollector);
|
|
75
132
|
}
|
|
76
|
-
|
|
77
|
-
|
|
133
|
+
try {
|
|
134
|
+
if (transport === "stdio") {
|
|
135
|
+
await transportManager.runStdio(server);
|
|
136
|
+
}
|
|
137
|
+
else if (transport === "streamable-http") {
|
|
138
|
+
await transportManager.runStreamableHttp(server, { host, port });
|
|
139
|
+
}
|
|
140
|
+
else if (transport === "sse") {
|
|
141
|
+
await transportManager.runSse(server, { host, port });
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
throw new Error(`Unknown transport: '${transport}'. Expected 'stdio', 'streamable-http', or 'sse'.`);
|
|
145
|
+
}
|
|
78
146
|
}
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
finally {
|
|
148
|
+
console.debug = origDebug;
|
|
149
|
+
console.info = origInfo;
|
|
150
|
+
console.warn = origWarn;
|
|
151
|
+
console.error = origError;
|
|
152
|
+
await onShutdown?.();
|
|
81
153
|
}
|
|
82
154
|
}
|
|
83
155
|
/**
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AASzD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAC9D,MAAM,CAAC,MAAM,OAAO,GAAW,GAAG,CAAC,OAAO,CAAC;AAa3C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE5E,gFAAgF;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAExF,OAAO,EAAE,mBAAmB,EAAE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ACtC,UAAgC,EAAE;IAElC,MAAM,QAAQ,GAAG,eAAe,CAAC,kBAAkB,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;IACxC,MAAM,KAAK,GAAG,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3D,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BridgeContext — minimal duck-typed context for apcore executors.
|
|
3
|
+
*
|
|
4
|
+
* Since apcore-mcp-typescript does NOT depend on apcore-js, we create a
|
|
5
|
+
* structural stand-in that satisfies the executor's context contract:
|
|
6
|
+
*
|
|
7
|
+
* if (context == null) { return Context.create(this).child(moduleId); }
|
|
8
|
+
* return context.child(moduleId);
|
|
9
|
+
*
|
|
10
|
+
* The key requirement: child() returns a new context that shares the same
|
|
11
|
+
* `data` reference so MCP callbacks remain accessible throughout the call chain.
|
|
12
|
+
*/
|
|
13
|
+
/** Shape of the bridge context object. */
|
|
14
|
+
export interface BridgeContext {
|
|
15
|
+
readonly traceId: string;
|
|
16
|
+
readonly callerId: string | null;
|
|
17
|
+
readonly callChain: readonly string[];
|
|
18
|
+
readonly executor: unknown;
|
|
19
|
+
readonly identity: Record<string, unknown> | null;
|
|
20
|
+
redactedInputs: Record<string, unknown> | null;
|
|
21
|
+
readonly data: Record<string, unknown>;
|
|
22
|
+
child(moduleId: string): BridgeContext;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a minimal bridge context that carries `data` through executor call chains.
|
|
26
|
+
*
|
|
27
|
+
* @param data - Shared data dict (MCP callbacks are injected here)
|
|
28
|
+
* @returns A BridgeContext with a working child() method
|
|
29
|
+
*/
|
|
30
|
+
export declare function createBridgeContext(data: Record<string, unknown>): BridgeContext;
|
|
31
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,0CAA0C;AAC1C,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAClD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAAC;CACxC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAEhF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BridgeContext — minimal duck-typed context for apcore executors.
|
|
3
|
+
*
|
|
4
|
+
* Since apcore-mcp-typescript does NOT depend on apcore-js, we create a
|
|
5
|
+
* structural stand-in that satisfies the executor's context contract:
|
|
6
|
+
*
|
|
7
|
+
* if (context == null) { return Context.create(this).child(moduleId); }
|
|
8
|
+
* return context.child(moduleId);
|
|
9
|
+
*
|
|
10
|
+
* The key requirement: child() returns a new context that shares the same
|
|
11
|
+
* `data` reference so MCP callbacks remain accessible throughout the call chain.
|
|
12
|
+
*/
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
/**
|
|
15
|
+
* Create a minimal bridge context that carries `data` through executor call chains.
|
|
16
|
+
*
|
|
17
|
+
* @param data - Shared data dict (MCP callbacks are injected here)
|
|
18
|
+
* @returns A BridgeContext with a working child() method
|
|
19
|
+
*/
|
|
20
|
+
export function createBridgeContext(data) {
|
|
21
|
+
return _buildContext(data, randomUUID(), null, []);
|
|
22
|
+
}
|
|
23
|
+
function _buildContext(data, traceId, callerId, callChain) {
|
|
24
|
+
return {
|
|
25
|
+
traceId,
|
|
26
|
+
callerId,
|
|
27
|
+
callChain,
|
|
28
|
+
executor: null,
|
|
29
|
+
identity: null,
|
|
30
|
+
redactedInputs: null,
|
|
31
|
+
data,
|
|
32
|
+
child(moduleId) {
|
|
33
|
+
// Match real Context.child(): callerId = last element of current callChain
|
|
34
|
+
const newCallerId = callChain.length > 0 ? callChain[callChain.length - 1] : null;
|
|
35
|
+
return _buildContext(data, traceId, newCallerId, [...callChain, moduleId]);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAczC;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAA6B;IAC/D,OAAO,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,aAAa,CACpB,IAA6B,EAC7B,OAAe,EACf,QAAuB,EACvB,SAAmB;IAEnB,OAAO;QACL,OAAO;QACP,QAAQ;QACR,SAAS;QACT,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,IAAI;QACpB,IAAI;QACJ,KAAK,CAAC,QAAgB;YACpB,2EAA2E;YAC3E,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAClF,OAAO,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC7E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/server/factory.d.ts
CHANGED
|
@@ -44,6 +44,18 @@ export declare class MCPServerFactory {
|
|
|
44
44
|
* Skips modules that return null definitions or throw errors (with console.warn).
|
|
45
45
|
*/
|
|
46
46
|
buildTools(registry: Registry, options?: BuildToolsOptions): Tool[];
|
|
47
|
+
/**
|
|
48
|
+
* Register resources/list and resources/read handlers for modules with documentation.
|
|
49
|
+
*
|
|
50
|
+
* Iterates over registry.list(), gets each definition, and filters for
|
|
51
|
+
* descriptors that have a non-null `documentation` field. Registers:
|
|
52
|
+
* - resources/list: returns Resource objects with URI docs://{module_id}
|
|
53
|
+
* - resources/read: returns documentation text for the requested module
|
|
54
|
+
*
|
|
55
|
+
* @param server - The MCP Server to register handlers on
|
|
56
|
+
* @param registry - Registry to discover modules with documentation
|
|
57
|
+
*/
|
|
58
|
+
registerResourceHandlers(server: Server, registry: Registry): void;
|
|
47
59
|
/**
|
|
48
60
|
* Register tools/list and tools/call request handlers on a Server instance.
|
|
49
61
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/server/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/server/factory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAOnE,OAAO,KAAK,EACV,IAAI,EAIL,MAAM,oCAAoC,CAAC;AAI5C,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnD,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;;IAOrD;;;;;;OAMG;IACH,YAAY,CACV,IAAI,GAAE,MAAqB,EAC3B,OAAO,GAAE,MAAgB,GACxB,MAAM;IAOT;;;;;;;;OAQG;IACH,SAAS,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI;IA+C7C;;;;;OAKG;IACH,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,EAAE;IA2BnE;;;;;;;;;;OAUG;IACH,wBAAwB,CACtB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,GACjB,IAAI;IAsDP;;;;;;OAMG;IACH,gBAAgB,CACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,IAAI,EAAE,EACb,MAAM,EAAE,eAAe,GACtB,IAAI;CA0CR"}
|