@vinkius-core/mcp-fusion 2.5.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/FusionClient.d.ts +122 -1
- package/dist/client/FusionClient.d.ts.map +1 -1
- package/dist/client/FusionClient.js +173 -11
- package/dist/client/FusionClient.js.map +1 -1
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/core/StandardSchema.d.ts +178 -0
- package/dist/core/StandardSchema.d.ts.map +1 -0
- package/dist/core/StandardSchema.js +166 -0
- package/dist/core/StandardSchema.js.map +1 -0
- package/dist/core/createGroup.d.ts +140 -0
- package/dist/core/createGroup.d.ts.map +1 -0
- package/dist/core/createGroup.js +133 -0
- package/dist/core/createGroup.js.map +1 -0
- package/dist/core/execution/ExecutionPipeline.d.ts.map +1 -1
- package/dist/core/execution/ExecutionPipeline.js +6 -2
- package/dist/core/execution/ExecutionPipeline.js.map +1 -1
- package/dist/core/index.d.ts +7 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/initFusion.d.ts +201 -0
- package/dist/core/initFusion.d.ts.map +1 -0
- package/dist/core/initFusion.js +134 -0
- package/dist/core/initFusion.js.map +1 -0
- package/dist/core/response.d.ts +49 -2
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +27 -5
- package/dist/core/response.js.map +1 -1
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/presenter/ZodDescriptionExtractor.d.ts +54 -0
- package/dist/presenter/ZodDescriptionExtractor.d.ts.map +1 -0
- package/dist/presenter/ZodDescriptionExtractor.js +131 -0
- package/dist/presenter/ZodDescriptionExtractor.js.map +1 -0
- package/dist/presenter/definePresenter.d.ts +172 -0
- package/dist/presenter/definePresenter.d.ts.map +1 -0
- package/dist/presenter/definePresenter.js +96 -0
- package/dist/presenter/definePresenter.js.map +1 -0
- package/dist/presenter/index.d.ts +3 -0
- package/dist/presenter/index.d.ts.map +1 -1
- package/dist/presenter/index.js +4 -0
- package/dist/presenter/index.js.map +1 -1
- package/dist/server/DevServer.d.ts +96 -0
- package/dist/server/DevServer.d.ts.map +1 -0
- package/dist/server/DevServer.js +187 -0
- package/dist/server/DevServer.js.map +1 -0
- package/dist/server/autoDiscover.d.ts +63 -0
- package/dist/server/autoDiscover.d.ts.map +1 -0
- package/dist/server/autoDiscover.js +157 -0
- package/dist/server/autoDiscover.js.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -0
- package/dist/server/index.js.map +1 -1
- package/dist/state-sync/PolicyValidator.d.ts +36 -0
- package/dist/state-sync/PolicyValidator.d.ts.map +1 -1
- package/dist/state-sync/PolicyValidator.js +35 -0
- package/dist/state-sync/PolicyValidator.js.map +1 -1
- package/dist/state-sync/ResponseDecorator.d.ts.map +1 -1
- package/dist/state-sync/ResponseDecorator.js +2 -1
- package/dist/state-sync/ResponseDecorator.js.map +1 -1
- package/dist/state-sync/StateSyncLayer.d.ts +5 -4
- package/dist/state-sync/StateSyncLayer.d.ts.map +1 -1
- package/dist/state-sync/StateSyncLayer.js +35 -4
- package/dist/state-sync/StateSyncLayer.js.map +1 -1
- package/dist/state-sync/index.d.ts +3 -1
- package/dist/state-sync/index.d.ts.map +1 -1
- package/dist/state-sync/index.js +1 -0
- package/dist/state-sync/index.js.map +1 -1
- package/dist/state-sync/types.d.ts +62 -0
- package/dist/state-sync/types.d.ts.map +1 -1
- package/package.json +39 -2
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StandardSchema — Universal Schema Abstraction Layer
|
|
3
|
+
*
|
|
4
|
+
* Decouples the MCP Fusion validation engine from Zod specifically,
|
|
5
|
+
* enabling support for any validator that implements the Standard Schema
|
|
6
|
+
* specification (`@standard-schema/spec`).
|
|
7
|
+
*
|
|
8
|
+
* This allows users to choose lighter alternatives:
|
|
9
|
+
* - **Zod** (~14kb min): Full-featured, most popular
|
|
10
|
+
* - **Valibot** (~1kb min via tree-shaking): Ultra-lightweight
|
|
11
|
+
* - **ArkType** (~5kb min): Fastest runtime validation
|
|
12
|
+
* - **TypeBox** (~4kb min): JSON Schema native
|
|
13
|
+
*
|
|
14
|
+
* ## Standard Schema Spec
|
|
15
|
+
*
|
|
16
|
+
* Any object with `~standard` property conforming to:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* interface StandardSchema {
|
|
19
|
+
* '~standard': {
|
|
20
|
+
* version: 1;
|
|
21
|
+
* vendor: string;
|
|
22
|
+
* validate: (value: unknown) => { value: T } | { issues: Issue[] };
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see https://github.com/standard-schema/standard-schema
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { toStandardValidator } from '@vinkius-core/mcp-fusion';
|
|
32
|
+
* import * as v from 'valibot';
|
|
33
|
+
*
|
|
34
|
+
* // Valibot schemas work natively via Standard Schema
|
|
35
|
+
* const schema = v.object({ name: v.string(), age: v.number() });
|
|
36
|
+
* const validator = toStandardValidator(schema);
|
|
37
|
+
*
|
|
38
|
+
* const result = validator.validate({ name: 'Alice', age: 30 });
|
|
39
|
+
* // { success: true, data: { name: 'Alice', age: 30 } }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @module
|
|
43
|
+
*/
|
|
44
|
+
// ── Adapters ─────────────────────────────────────────────
|
|
45
|
+
/**
|
|
46
|
+
* Create a FusionValidator from a Standard Schema v1 compatible schema.
|
|
47
|
+
*
|
|
48
|
+
* This is the primary entry point for non-Zod validators. Any schema
|
|
49
|
+
* library implementing the Standard Schema spec can be used directly.
|
|
50
|
+
*
|
|
51
|
+
* @param schema - A Standard Schema v1 compatible schema
|
|
52
|
+
* @returns A {@link FusionValidator} wrapping the schema
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import * as v from 'valibot'; // ~1kb tree-shaken
|
|
57
|
+
*
|
|
58
|
+
* const schema = v.object({ name: v.string() });
|
|
59
|
+
* const validator = toStandardValidator(schema);
|
|
60
|
+
*
|
|
61
|
+
* const ok = validator.validate({ name: 'Alice' });
|
|
62
|
+
* // { success: true, data: { name: 'Alice' } }
|
|
63
|
+
*
|
|
64
|
+
* const err = validator.validate({ name: 42 });
|
|
65
|
+
* // { success: false, issues: [{ message: 'Expected string', path: ['name'] }] }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function toStandardValidator(schema) {
|
|
69
|
+
const spec = schema['~standard'];
|
|
70
|
+
return {
|
|
71
|
+
validate(value) {
|
|
72
|
+
const result = spec.validate(value);
|
|
73
|
+
if ('value' in result) {
|
|
74
|
+
return { success: true, data: result.value };
|
|
75
|
+
}
|
|
76
|
+
return { success: false, issues: result.issues };
|
|
77
|
+
},
|
|
78
|
+
vendor: spec.vendor,
|
|
79
|
+
schema,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a FusionValidator from a raw Zod schema.
|
|
84
|
+
*
|
|
85
|
+
* This adapter uses Zod's `.safeParse()` method and maps the result
|
|
86
|
+
* to the standard FusionValidator interface.
|
|
87
|
+
*
|
|
88
|
+
* @param schema - A Zod schema (z.object, z.string, etc.)
|
|
89
|
+
* @returns A {@link FusionValidator} wrapping the Zod schema
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* import { z } from 'zod';
|
|
94
|
+
*
|
|
95
|
+
* const schema = z.object({ name: z.string() });
|
|
96
|
+
* const validator = fromZodSchema(schema);
|
|
97
|
+
*
|
|
98
|
+
* const ok = validator.validate({ name: 'Alice' });
|
|
99
|
+
* // { success: true, data: { name: 'Alice' } }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function fromZodSchema(schema) {
|
|
103
|
+
return {
|
|
104
|
+
validate(value) {
|
|
105
|
+
const result = schema.safeParse(value);
|
|
106
|
+
if (result.success) {
|
|
107
|
+
return { success: true, data: result.data };
|
|
108
|
+
}
|
|
109
|
+
// Map Zod errors to StandardSchemaIssue
|
|
110
|
+
const issues = (result.error?.issues ?? []).map((issue) => {
|
|
111
|
+
const mapped = { message: issue.message };
|
|
112
|
+
if (issue.path) {
|
|
113
|
+
mapped.path = issue.path;
|
|
114
|
+
}
|
|
115
|
+
return mapped;
|
|
116
|
+
});
|
|
117
|
+
return { success: false, issues };
|
|
118
|
+
},
|
|
119
|
+
vendor: 'zod',
|
|
120
|
+
schema,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if a value implements the Standard Schema v1 spec.
|
|
125
|
+
*
|
|
126
|
+
* @param value - Any value to check
|
|
127
|
+
* @returns `true` if the value has a valid `~standard` property
|
|
128
|
+
*/
|
|
129
|
+
export function isStandardSchema(value) {
|
|
130
|
+
return (typeof value === 'object' &&
|
|
131
|
+
value !== null &&
|
|
132
|
+
'~standard' in value &&
|
|
133
|
+
typeof value['~standard'] === 'object' &&
|
|
134
|
+
value['~standard'] !== null &&
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
136
|
+
value['~standard'].version === 1);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Auto-detect and create a FusionValidator from any supported schema.
|
|
140
|
+
*
|
|
141
|
+
* Detection order:
|
|
142
|
+
* 1. Standard Schema v1 (Valibot, ArkType, etc.)
|
|
143
|
+
* 2. Zod-like (has `.safeParse()`)
|
|
144
|
+
* 3. Throws if unrecognized
|
|
145
|
+
*
|
|
146
|
+
* @param schema - Any supported schema
|
|
147
|
+
* @returns A {@link FusionValidator}
|
|
148
|
+
* @throws If the schema type is not recognized
|
|
149
|
+
*/
|
|
150
|
+
export function autoValidator(schema) {
|
|
151
|
+
if (isStandardSchema(schema)) {
|
|
152
|
+
return toStandardValidator(schema);
|
|
153
|
+
}
|
|
154
|
+
if (isZodLike(schema)) {
|
|
155
|
+
return fromZodSchema(schema);
|
|
156
|
+
}
|
|
157
|
+
throw new Error('Unsupported schema type. Expected a Standard Schema v1 (' +
|
|
158
|
+
'Valibot, ArkType) or Zod schema. See: https://mcp-fusion.vinkius.com/docs/standard-schema');
|
|
159
|
+
}
|
|
160
|
+
/** Duck-type check for Zod-like schemas */
|
|
161
|
+
function isZodLike(value) {
|
|
162
|
+
return (typeof value === 'object' &&
|
|
163
|
+
value !== null &&
|
|
164
|
+
typeof value.safeParse === 'function');
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=StandardSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardSchema.js","sourceRoot":"","sources":["../../src/core/StandardSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAyDH,4DAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,mBAAmB,CAC/B,MAAoC;IAEpC,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAEjC,OAAO;QACH,QAAQ,CAAC,KAAc;YACnB,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAEpC,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;gBACpB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;YACjD,CAAC;YAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;QACrD,CAAC;QACD,MAAM,EAAE,IAAI,CAAC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CAAc,MAAe;IACtD,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,OAAO,mBAAmB,CAAC,MAAsC,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QACpB,OAAO,aAAa,CAAC,MAA0B,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,IAAI,KAAK,CACX,0DAA0D;QAC1D,2FAA2F,CAC9F,CAAC;AACN,CAAC;AAUD,2CAA2C;AAC3C,SAAS,SAAS,CAAC,KAAc;IAC7B,OAAO,CACH,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAuB,CAAC,SAAS,KAAK,UAAU,CAC3D,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createGroup() — Functional Tool Group Compiler
|
|
3
|
+
*
|
|
4
|
+
* A lightweight, closure-based alternative to the class-heavy
|
|
5
|
+
* `GroupedToolBuilder`. Instead of maintaining internal state via `this._x`,
|
|
6
|
+
* it compiles a group config into a frozen object with pre-composed
|
|
7
|
+
* middleware and an O(1) dispatch function.
|
|
8
|
+
*
|
|
9
|
+
* **Why Functional?**
|
|
10
|
+
* - Closures minify 30-40% better than class methods (Terser can rename local vars)
|
|
11
|
+
* - No prototype chain overhead — zero `this` binding issues
|
|
12
|
+
* - Frozen return type prevents accidental mutation
|
|
13
|
+
* - Compatible with Edge Runtimes (Cloudflare Workers, Deno Deploy)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { createGroup, success } from '@vinkius-core/mcp-fusion';
|
|
18
|
+
*
|
|
19
|
+
* const billing = createGroup({
|
|
20
|
+
* name: 'billing',
|
|
21
|
+
* description: 'Invoice management',
|
|
22
|
+
* middleware: [requireAuth],
|
|
23
|
+
* actions: {
|
|
24
|
+
* get_invoice: {
|
|
25
|
+
* schema: z.object({ id: z.string() }),
|
|
26
|
+
* readOnly: true,
|
|
27
|
+
* handler: async (ctx, args) => success(await ctx.db.invoices.get(args.id)),
|
|
28
|
+
* },
|
|
29
|
+
* pay: {
|
|
30
|
+
* schema: z.object({ invoice_id: z.string(), amount: z.number() }),
|
|
31
|
+
* destructive: true,
|
|
32
|
+
* handler: async (ctx, args) => success(await ctx.db.payments.create(args)),
|
|
33
|
+
* },
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // billing.execute(ctx, 'get_invoice', { id: '123' })
|
|
38
|
+
* // billing.name === 'billing'
|
|
39
|
+
* // billing.actionNames === ['get_invoice', 'pay']
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @module
|
|
43
|
+
*/
|
|
44
|
+
import { type ZodObject, type ZodRawShape } from 'zod';
|
|
45
|
+
import { type ToolResponse } from '../core/response.js';
|
|
46
|
+
import { type MiddlewareFn } from '../core/types.js';
|
|
47
|
+
/**
|
|
48
|
+
* A single action definition within a group.
|
|
49
|
+
*/
|
|
50
|
+
export interface GroupAction<TContext> {
|
|
51
|
+
/** Human-readable description for the LLM */
|
|
52
|
+
readonly description?: string;
|
|
53
|
+
/** Zod schema for input validation */
|
|
54
|
+
readonly schema?: ZodObject<ZodRawShape>;
|
|
55
|
+
/** Mark as read-only */
|
|
56
|
+
readonly readOnly?: boolean;
|
|
57
|
+
/** Mark as destructive */
|
|
58
|
+
readonly destructive?: boolean;
|
|
59
|
+
/** Mark as idempotent */
|
|
60
|
+
readonly idempotent?: boolean;
|
|
61
|
+
/** Per-action middleware */
|
|
62
|
+
readonly middleware?: MiddlewareFn<TContext>[];
|
|
63
|
+
/** Handler function */
|
|
64
|
+
readonly handler: (ctx: TContext, args: Record<string, unknown>) => Promise<ToolResponse>;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Full configuration for `createGroup()`.
|
|
68
|
+
*/
|
|
69
|
+
export interface GroupConfig<TContext> {
|
|
70
|
+
/** Group/tool name */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** Description for the LLM */
|
|
73
|
+
readonly description?: string;
|
|
74
|
+
/** Capability tags */
|
|
75
|
+
readonly tags?: string[];
|
|
76
|
+
/** Shared middleware applied to ALL actions (outermost layer) */
|
|
77
|
+
readonly middleware?: MiddlewareFn<TContext>[];
|
|
78
|
+
/** Action definitions keyed by action name */
|
|
79
|
+
readonly actions: Record<string, GroupAction<TContext>>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A compiled, frozen group ready for execution.
|
|
83
|
+
*/
|
|
84
|
+
export interface CompiledGroup<TContext> {
|
|
85
|
+
/** Group/tool name */
|
|
86
|
+
readonly name: string;
|
|
87
|
+
/** Description */
|
|
88
|
+
readonly description: string | undefined;
|
|
89
|
+
/** Tags */
|
|
90
|
+
readonly tags: readonly string[];
|
|
91
|
+
/** List of action names */
|
|
92
|
+
readonly actionNames: readonly string[];
|
|
93
|
+
/**
|
|
94
|
+
* Execute an action by name.
|
|
95
|
+
*
|
|
96
|
+
* @param ctx - Application context
|
|
97
|
+
* @param action - Action name
|
|
98
|
+
* @param args - Input arguments
|
|
99
|
+
* @returns Tool response
|
|
100
|
+
* @throws If action name is unknown
|
|
101
|
+
*/
|
|
102
|
+
readonly execute: (ctx: TContext, action: string, args: Record<string, unknown>) => Promise<ToolResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Get metadata for a specific action.
|
|
105
|
+
*/
|
|
106
|
+
readonly getAction: (name: string) => Readonly<GroupAction<TContext>> | undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Create a compiled, frozen tool group from a declarative config.
|
|
110
|
+
*
|
|
111
|
+
* The returned object has O(1) action dispatch via a pre-built Map.
|
|
112
|
+
* All middleware chains are pre-composed at creation time — zero
|
|
113
|
+
* runtime overhead on each call.
|
|
114
|
+
*
|
|
115
|
+
* @typeParam TContext - Application context type
|
|
116
|
+
* @param config - Group configuration with actions
|
|
117
|
+
* @returns A frozen {@link CompiledGroup} ready for execution
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const tasks = createGroup({
|
|
122
|
+
* name: 'tasks',
|
|
123
|
+
* middleware: [logMiddleware],
|
|
124
|
+
* actions: {
|
|
125
|
+
* list: {
|
|
126
|
+
* readOnly: true,
|
|
127
|
+
* handler: async (ctx) => success(await ctx.db.tasks.findMany()),
|
|
128
|
+
* },
|
|
129
|
+
* create: {
|
|
130
|
+
* schema: z.object({ title: z.string() }),
|
|
131
|
+
* handler: async (ctx, args) => success(await ctx.db.tasks.create(args)),
|
|
132
|
+
* },
|
|
133
|
+
* },
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* const result = await tasks.execute(ctx, 'create', { title: 'Buy milk' });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function createGroup<TContext = void>(config: GroupConfig<TContext>): CompiledGroup<TContext>;
|
|
140
|
+
//# sourceMappingURL=createGroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGroup.d.ts","sourceRoot":"","sources":["../../src/core/createGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIrD;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,QAAQ;IACjC,6CAA6C;IAC7C,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,sCAAsC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IACzC,wBAAwB;IACxB,QAAQ,CAAC,QAAQ,CA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AAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1G;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,CAAC;CACrF;AA+BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,WAAW,CAAC,QAAQ,GAAG,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,CAmDnG"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createGroup() — Functional Tool Group Compiler
|
|
3
|
+
*
|
|
4
|
+
* A lightweight, closure-based alternative to the class-heavy
|
|
5
|
+
* `GroupedToolBuilder`. Instead of maintaining internal state via `this._x`,
|
|
6
|
+
* it compiles a group config into a frozen object with pre-composed
|
|
7
|
+
* middleware and an O(1) dispatch function.
|
|
8
|
+
*
|
|
9
|
+
* **Why Functional?**
|
|
10
|
+
* - Closures minify 30-40% better than class methods (Terser can rename local vars)
|
|
11
|
+
* - No prototype chain overhead — zero `this` binding issues
|
|
12
|
+
* - Frozen return type prevents accidental mutation
|
|
13
|
+
* - Compatible with Edge Runtimes (Cloudflare Workers, Deno Deploy)
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { createGroup, success } from '@vinkius-core/mcp-fusion';
|
|
18
|
+
*
|
|
19
|
+
* const billing = createGroup({
|
|
20
|
+
* name: 'billing',
|
|
21
|
+
* description: 'Invoice management',
|
|
22
|
+
* middleware: [requireAuth],
|
|
23
|
+
* actions: {
|
|
24
|
+
* get_invoice: {
|
|
25
|
+
* schema: z.object({ id: z.string() }),
|
|
26
|
+
* readOnly: true,
|
|
27
|
+
* handler: async (ctx, args) => success(await ctx.db.invoices.get(args.id)),
|
|
28
|
+
* },
|
|
29
|
+
* pay: {
|
|
30
|
+
* schema: z.object({ invoice_id: z.string(), amount: z.number() }),
|
|
31
|
+
* destructive: true,
|
|
32
|
+
* handler: async (ctx, args) => success(await ctx.db.payments.create(args)),
|
|
33
|
+
* },
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // billing.execute(ctx, 'get_invoice', { id: '123' })
|
|
38
|
+
* // billing.name === 'billing'
|
|
39
|
+
* // billing.actionNames === ['get_invoice', 'pay']
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @module
|
|
43
|
+
*/
|
|
44
|
+
import {} from 'zod';
|
|
45
|
+
import {} from '../core/response.js';
|
|
46
|
+
import {} from '../core/types.js';
|
|
47
|
+
// ── Middleware Composition ────────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* Compose an array of middleware into a single function.
|
|
50
|
+
* Right-to-left composition: last middleware is innermost (closest to handler).
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
function composeMiddleware(globalMiddleware, actionMiddleware, handler) {
|
|
54
|
+
const allMiddleware = [...globalMiddleware, ...actionMiddleware];
|
|
55
|
+
if (allMiddleware.length === 0) {
|
|
56
|
+
return handler;
|
|
57
|
+
}
|
|
58
|
+
// Build the chain from right to left
|
|
59
|
+
return allMiddleware.reduceRight((next, mw) => (ctx, args) => mw(ctx, args, () => next(ctx, args)), handler);
|
|
60
|
+
}
|
|
61
|
+
// ── Factory ──────────────────────────────────────────────
|
|
62
|
+
/**
|
|
63
|
+
* Create a compiled, frozen tool group from a declarative config.
|
|
64
|
+
*
|
|
65
|
+
* The returned object has O(1) action dispatch via a pre-built Map.
|
|
66
|
+
* All middleware chains are pre-composed at creation time — zero
|
|
67
|
+
* runtime overhead on each call.
|
|
68
|
+
*
|
|
69
|
+
* @typeParam TContext - Application context type
|
|
70
|
+
* @param config - Group configuration with actions
|
|
71
|
+
* @returns A frozen {@link CompiledGroup} ready for execution
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const tasks = createGroup({
|
|
76
|
+
* name: 'tasks',
|
|
77
|
+
* middleware: [logMiddleware],
|
|
78
|
+
* actions: {
|
|
79
|
+
* list: {
|
|
80
|
+
* readOnly: true,
|
|
81
|
+
* handler: async (ctx) => success(await ctx.db.tasks.findMany()),
|
|
82
|
+
* },
|
|
83
|
+
* create: {
|
|
84
|
+
* schema: z.object({ title: z.string() }),
|
|
85
|
+
* handler: async (ctx, args) => success(await ctx.db.tasks.create(args)),
|
|
86
|
+
* },
|
|
87
|
+
* },
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* const result = await tasks.execute(ctx, 'create', { title: 'Buy milk' });
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export function createGroup(config) {
|
|
94
|
+
const globalMiddleware = config.middleware ?? [];
|
|
95
|
+
const actionNames = Object.keys(config.actions);
|
|
96
|
+
// Pre-compose middleware chains for each action (O(1) dispatch)
|
|
97
|
+
const dispatchMap = new Map();
|
|
98
|
+
for (const [name, action] of Object.entries(config.actions)) {
|
|
99
|
+
const compiled = composeMiddleware(globalMiddleware, action.middleware ?? [], action.handler);
|
|
100
|
+
dispatchMap.set(name, compiled);
|
|
101
|
+
}
|
|
102
|
+
// Pre-validate action args using Zod schemas
|
|
103
|
+
const schemaMap = new Map();
|
|
104
|
+
for (const [name, action] of Object.entries(config.actions)) {
|
|
105
|
+
if (action.schema) {
|
|
106
|
+
schemaMap.set(name, action.schema);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const execute = async (ctx, action, args) => {
|
|
110
|
+
const chain = dispatchMap.get(action);
|
|
111
|
+
if (!chain) {
|
|
112
|
+
throw new Error(`Unknown action "${action}" in group "${config.name}". Available: ${actionNames.join(', ')}`);
|
|
113
|
+
}
|
|
114
|
+
// Validate with Zod if schema is defined
|
|
115
|
+
const schema = schemaMap.get(action);
|
|
116
|
+
if (schema) {
|
|
117
|
+
schema.strict().parse(args);
|
|
118
|
+
}
|
|
119
|
+
return chain(ctx, args);
|
|
120
|
+
};
|
|
121
|
+
const getAction = (name) => {
|
|
122
|
+
return config.actions[name];
|
|
123
|
+
};
|
|
124
|
+
return Object.freeze({
|
|
125
|
+
name: config.name,
|
|
126
|
+
description: config.description,
|
|
127
|
+
tags: Object.freeze(config.tags ?? []),
|
|
128
|
+
actionNames: Object.freeze(actionNames),
|
|
129
|
+
execute,
|
|
130
|
+
getAction,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=createGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createGroup.js","sourceRoot":"","sources":["../../src/core/createGroup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,OAAO,EAAoC,MAAM,KAAK,CAAC;AACvD,OAAO,EAAqB,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAqB,MAAM,kBAAkB,CAAC;AAoErD,6DAA6D;AAE7D;;;;GAIG;AACH,SAAS,iBAAiB,CACtB,gBAA0C,EAC1C,gBAA0C,EAC1C,OAAgF;IAEhF,MAAM,aAAa,GAAG,CAAC,GAAG,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,CAAC;IAEjE,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,qCAAqC;IACrC,OAAO,aAAa,CAAC,WAAW,CAC5B,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CACT,CAAC,GAAa,EAAE,IAA6B,EAAE,EAAE,CAC7C,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,EAC5C,OAAO,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I,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClH,CAAC;QAED,yCAAyC;QACzC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,IAAY,EAA+C,EAAE;QAC5E,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACtC,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;QACvC,OAAO;QACP,SAAS;KACZ,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionPipeline.d.ts","sourceRoot":"","sources":["../../../src/core/execution/ExecutionPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"ExecutionPipeline.d.ts","sourceRoot":"","sources":["../../../src/core/execution/ExecutionPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AACvD,OAAO,EAAE,KAAK,YAAY,EAA+B,MAAM,gBAAgB,CAAC;AAEhF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,YAAY,CAAC,QAAQ,EACjC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EACnC,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,EAClC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA0BjC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,QAAQ,EACnC,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EACnC,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC,EAClC,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,YAAY,CAAC,EAAE,YAAY,EAC3B,OAAO,UAAQ,EACf,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,YAAY,CAAC,CA8BvB;AAQD;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACpC,QAAQ,CAAC,OAAO,EAAE,yBAAyB,CAAC;IAC5C,QAAQ,CAAC,SAAS,EAAE,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;CACxE"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Pipeline: ensureBuilt → parseDiscriminator → resolveAction → validateArgs → runChain
|
|
11
11
|
*/
|
|
12
12
|
import {} from 'zod';
|
|
13
|
-
import { error, escapeXml } from '../response.js';
|
|
13
|
+
import { error, escapeXml, toolError } from '../response.js';
|
|
14
14
|
import { formatValidationError } from './ValidationErrorFormatter.js';
|
|
15
15
|
import { succeed, fail } from '../result.js';
|
|
16
16
|
import {} from '../types.js';
|
|
@@ -102,7 +102,11 @@ export async function runChain(execCtx, resolved, ctx, args, progressSink, rethr
|
|
|
102
102
|
if (rethrow)
|
|
103
103
|
throw err;
|
|
104
104
|
const message = err instanceof Error ? err.message : String(err);
|
|
105
|
-
return
|
|
105
|
+
return toolError('INTERNAL_ERROR', {
|
|
106
|
+
message: `[${execCtx.toolName}/${resolved.discriminatorValue}] ${message}`,
|
|
107
|
+
suggestion: 'This may be a transient error. Retry the same call with identical parameters.',
|
|
108
|
+
severity: 'error',
|
|
109
|
+
});
|
|
106
110
|
}
|
|
107
111
|
}
|
|
108
112
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExecutionPipeline.js","sourceRoot":"","sources":["../../../src/core/execution/ExecutionPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAoC,MAAM,KAAK,CAAC;AACvD,OAAO,EAAqB,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ExecutionPipeline.js","sourceRoot":"","sources":["../../../src/core/execution/ExecutionPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAoC,MAAM,KAAK,CAAC;AACvD,OAAO,EAAqB,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAe,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAuB,MAAM,aAAa,CAAC;AAClD,OAAO,EAAsB,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAqB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAoBrE,4DAA4D;AAE5D,sDAAsD;AACtD,MAAM,UAAU,kBAAkB,CAC9B,OAAmC,EACnC,IAA6B;IAE7B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC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BAAgB;AAChB,SAAS,yBAAyB,CAAC,KAAc;IAC7C,OAAO,CACH,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QACjB,KAA8B,CAAC,OAAO,KAAK,yBAAyB,CACxE,CAAC;AACN,CAAC;AAED;;;;;;;;;;GAUG;AACH,KAAK,UAAU,cAAc,CACzB,GAAqD,EACrD,YAA2B,EAC3B,MAAoB;IAEpB,IAAI,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAE9B,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,sDAAsD;QACtD,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YAClB,qDAAqD;YACrD,MAAM,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAC9C,OAAO,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,YAAY,IAAI,eAAe,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC;QACD,MAAM,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC;AACxB,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* barrel files and re-aggregated in src/index.ts.
|
|
11
11
|
*/
|
|
12
12
|
export { success, error, required, toonSuccess, toolError } from './response.js';
|
|
13
|
-
export type { ToolResponse, ToolErrorOptions } from './response.js';
|
|
13
|
+
export type { ToolResponse, ToolErrorOptions, ErrorCode, ErrorSeverity } from './response.js';
|
|
14
14
|
export { succeed, fail } from './result.js';
|
|
15
15
|
export type { Result, Success, Failure } from './result.js';
|
|
16
16
|
export type { ToolBuilder, ActionMetadata, InternalAction, MiddlewareFn, ActionConfig, } from './types.js';
|
|
@@ -26,4 +26,10 @@ export type { ConcurrencyConfig } from './execution/index.js';
|
|
|
26
26
|
export type { EgressConfig } from './execution/index.js';
|
|
27
27
|
export { defineMiddleware, resolveMiddleware } from './middleware/index.js';
|
|
28
28
|
export type { MiddlewareDefinition, MergeContext, InferContextOut } from './middleware/index.js';
|
|
29
|
+
export { initFusion } from './initFusion.js';
|
|
30
|
+
export type { FusionInstance, FusionToolConfig } from './initFusion.js';
|
|
31
|
+
export { createGroup } from './createGroup.js';
|
|
32
|
+
export type { GroupConfig, GroupAction, CompiledGroup } from './createGroup.js';
|
|
33
|
+
export { toStandardValidator, fromZodSchema, isStandardSchema, autoValidator, } from './StandardSchema.js';
|
|
34
|
+
export type { StandardSchemaV1, StandardSchemaIssue, InferStandardOutput, FusionValidator, ValidationResult, } from './StandardSchema.js';
|
|
29
35
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjF,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjF,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EAAE,MAAM,EAAE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AGhF,OAAO,EACH,mBAAmB,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,GACtE,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACR,gBAAgB,EAAE,mBAAmB,EAAE,mBAAmB,EAC1D,eAAe,EAAE,gBAAgB,GACpC,MAAM,qBAAqB,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -22,4 +22,10 @@ export { generateToonDescription } from './schema/index.js';
|
|
|
22
22
|
export { progress } from './execution/index.js';
|
|
23
23
|
// ── Middleware (context derivation) ──────────────────────
|
|
24
24
|
export { defineMiddleware, resolveMiddleware } from './middleware/index.js';
|
|
25
|
+
// ── Fusion Initializer (tRPC-style) ─────────────────────
|
|
26
|
+
export { initFusion } from './initFusion.js';
|
|
27
|
+
// ── Functional Core ──────────────────────────────────────
|
|
28
|
+
export { createGroup } from './createGroup.js';
|
|
29
|
+
// ── Standard Schema ──────────────────────────────────────
|
|
30
|
+
export { toStandardValidator, fromZodSchema, isStandardSchema, autoValidator, } from './StandardSchema.js';
|
|
25
31
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4DAA4D;AAC5D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAU5C,4DAA4D;AAC5D,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQpG,4DAA4D;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,4DAA4D;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AA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