@vinkius-core/mcp-fusion 2.6.0 → 2.8.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.
Files changed (140) hide show
  1. package/dist/cli/fusion.d.ts +101 -0
  2. package/dist/cli/fusion.d.ts.map +1 -0
  3. package/dist/cli/fusion.js +333 -0
  4. package/dist/cli/fusion.js.map +1 -0
  5. package/dist/client/FusionClient.d.ts +122 -1
  6. package/dist/client/FusionClient.d.ts.map +1 -1
  7. package/dist/client/FusionClient.js +173 -11
  8. package/dist/client/FusionClient.js.map +1 -1
  9. package/dist/client/index.d.ts +2 -2
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +1 -1
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/core/StandardSchema.d.ts +178 -0
  14. package/dist/core/StandardSchema.d.ts.map +1 -0
  15. package/dist/core/StandardSchema.js +166 -0
  16. package/dist/core/StandardSchema.js.map +1 -0
  17. package/dist/core/createGroup.d.ts +140 -0
  18. package/dist/core/createGroup.d.ts.map +1 -0
  19. package/dist/core/createGroup.js +133 -0
  20. package/dist/core/createGroup.js.map +1 -0
  21. package/dist/core/execution/ExecutionPipeline.d.ts.map +1 -1
  22. package/dist/core/execution/ExecutionPipeline.js +6 -2
  23. package/dist/core/execution/ExecutionPipeline.js.map +1 -1
  24. package/dist/core/index.d.ts +7 -1
  25. package/dist/core/index.d.ts.map +1 -1
  26. package/dist/core/index.js +6 -0
  27. package/dist/core/index.js.map +1 -1
  28. package/dist/core/initFusion.d.ts +201 -0
  29. package/dist/core/initFusion.d.ts.map +1 -0
  30. package/dist/core/initFusion.js +134 -0
  31. package/dist/core/initFusion.js.map +1 -0
  32. package/dist/core/response.d.ts +49 -2
  33. package/dist/core/response.d.ts.map +1 -1
  34. package/dist/core/response.js +27 -5
  35. package/dist/core/response.js.map +1 -1
  36. package/dist/index.d.ts +57 -9
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +30 -4
  39. package/dist/index.js.map +1 -1
  40. package/dist/introspection/BehaviorDigest.d.ts +112 -0
  41. package/dist/introspection/BehaviorDigest.d.ts.map +1 -0
  42. package/dist/introspection/BehaviorDigest.js +146 -0
  43. package/dist/introspection/BehaviorDigest.js.map +1 -0
  44. package/dist/introspection/CapabilityLockfile.d.ts +259 -0
  45. package/dist/introspection/CapabilityLockfile.d.ts.map +1 -0
  46. package/dist/introspection/CapabilityLockfile.js +391 -0
  47. package/dist/introspection/CapabilityLockfile.js.map +1 -0
  48. package/dist/introspection/ContractAwareSelfHealing.d.ts +90 -0
  49. package/dist/introspection/ContractAwareSelfHealing.d.ts.map +1 -0
  50. package/dist/introspection/ContractAwareSelfHealing.js +132 -0
  51. package/dist/introspection/ContractAwareSelfHealing.js.map +1 -0
  52. package/dist/introspection/ContractDiff.d.ts +91 -0
  53. package/dist/introspection/ContractDiff.d.ts.map +1 -0
  54. package/dist/introspection/ContractDiff.js +466 -0
  55. package/dist/introspection/ContractDiff.js.map +1 -0
  56. package/dist/introspection/CryptoAttestation.d.ts +143 -0
  57. package/dist/introspection/CryptoAttestation.d.ts.map +1 -0
  58. package/dist/introspection/CryptoAttestation.js +194 -0
  59. package/dist/introspection/CryptoAttestation.js.map +1 -0
  60. package/dist/introspection/EntitlementScanner.d.ts +124 -0
  61. package/dist/introspection/EntitlementScanner.d.ts.map +1 -0
  62. package/dist/introspection/EntitlementScanner.js +244 -0
  63. package/dist/introspection/EntitlementScanner.js.map +1 -0
  64. package/dist/introspection/GovernanceObserver.d.ts +88 -0
  65. package/dist/introspection/GovernanceObserver.d.ts.map +1 -0
  66. package/dist/introspection/GovernanceObserver.js +132 -0
  67. package/dist/introspection/GovernanceObserver.js.map +1 -0
  68. package/dist/introspection/SemanticProbe.d.ts +207 -0
  69. package/dist/introspection/SemanticProbe.d.ts.map +1 -0
  70. package/dist/introspection/SemanticProbe.js +255 -0
  71. package/dist/introspection/SemanticProbe.js.map +1 -0
  72. package/dist/introspection/TokenEconomics.d.ts +210 -0
  73. package/dist/introspection/TokenEconomics.d.ts.map +1 -0
  74. package/dist/introspection/TokenEconomics.js +286 -0
  75. package/dist/introspection/TokenEconomics.js.map +1 -0
  76. package/dist/introspection/ToolContract.d.ts +159 -0
  77. package/dist/introspection/ToolContract.d.ts.map +1 -0
  78. package/dist/introspection/ToolContract.js +191 -0
  79. package/dist/introspection/ToolContract.js.map +1 -0
  80. package/dist/introspection/canonicalize.d.ts +20 -0
  81. package/dist/introspection/canonicalize.d.ts.map +1 -0
  82. package/dist/introspection/canonicalize.js +51 -0
  83. package/dist/introspection/canonicalize.js.map +1 -0
  84. package/dist/introspection/index.d.ts +20 -0
  85. package/dist/introspection/index.d.ts.map +1 -1
  86. package/dist/introspection/index.js +20 -0
  87. package/dist/introspection/index.js.map +1 -1
  88. package/dist/observability/DebugObserver.d.ts +26 -1
  89. package/dist/observability/DebugObserver.d.ts.map +1 -1
  90. package/dist/observability/DebugObserver.js +8 -1
  91. package/dist/observability/DebugObserver.js.map +1 -1
  92. package/dist/observability/index.d.ts +1 -1
  93. package/dist/observability/index.d.ts.map +1 -1
  94. package/dist/observability/index.js.map +1 -1
  95. package/dist/presenter/ZodDescriptionExtractor.d.ts +54 -0
  96. package/dist/presenter/ZodDescriptionExtractor.d.ts.map +1 -0
  97. package/dist/presenter/ZodDescriptionExtractor.js +131 -0
  98. package/dist/presenter/ZodDescriptionExtractor.js.map +1 -0
  99. package/dist/presenter/definePresenter.d.ts +172 -0
  100. package/dist/presenter/definePresenter.d.ts.map +1 -0
  101. package/dist/presenter/definePresenter.js +96 -0
  102. package/dist/presenter/definePresenter.js.map +1 -0
  103. package/dist/presenter/index.d.ts +3 -0
  104. package/dist/presenter/index.d.ts.map +1 -1
  105. package/dist/presenter/index.js +4 -0
  106. package/dist/presenter/index.js.map +1 -1
  107. package/dist/server/DevServer.d.ts +96 -0
  108. package/dist/server/DevServer.d.ts.map +1 -0
  109. package/dist/server/DevServer.js +187 -0
  110. package/dist/server/DevServer.js.map +1 -0
  111. package/dist/server/ServerAttachment.d.ts +41 -0
  112. package/dist/server/ServerAttachment.d.ts.map +1 -1
  113. package/dist/server/ServerAttachment.js +25 -1
  114. package/dist/server/ServerAttachment.js.map +1 -1
  115. package/dist/server/autoDiscover.d.ts +63 -0
  116. package/dist/server/autoDiscover.d.ts.map +1 -0
  117. package/dist/server/autoDiscover.js +157 -0
  118. package/dist/server/autoDiscover.js.map +1 -0
  119. package/dist/server/index.d.ts +4 -0
  120. package/dist/server/index.d.ts.map +1 -1
  121. package/dist/server/index.js +4 -0
  122. package/dist/server/index.js.map +1 -1
  123. package/dist/state-sync/PolicyValidator.d.ts +36 -0
  124. package/dist/state-sync/PolicyValidator.d.ts.map +1 -1
  125. package/dist/state-sync/PolicyValidator.js +35 -0
  126. package/dist/state-sync/PolicyValidator.js.map +1 -1
  127. package/dist/state-sync/ResponseDecorator.d.ts.map +1 -1
  128. package/dist/state-sync/ResponseDecorator.js +2 -1
  129. package/dist/state-sync/ResponseDecorator.js.map +1 -1
  130. package/dist/state-sync/StateSyncLayer.d.ts +5 -4
  131. package/dist/state-sync/StateSyncLayer.d.ts.map +1 -1
  132. package/dist/state-sync/StateSyncLayer.js +35 -4
  133. package/dist/state-sync/StateSyncLayer.js.map +1 -1
  134. package/dist/state-sync/index.d.ts +3 -1
  135. package/dist/state-sync/index.d.ts.map +1 -1
  136. package/dist/state-sync/index.js +1 -0
  137. package/dist/state-sync/index.js.map +1 -1
  138. package/dist/state-sync/types.d.ts +62 -0
  139. package/dist/state-sync/types.d.ts.map +1 -1
  140. package/package.json +45 -1
@@ -27,6 +27,110 @@
27
27
  */
28
28
  import {} from '../core/response.js';
29
29
  // ============================================================================
30
+ // Structured Client Error
31
+ // ============================================================================
32
+ /**
33
+ * Structured error parsed from a `<tool_error>` XML envelope.
34
+ *
35
+ * Provides typed access to self-healing fields so client code
36
+ * can programmatically react to server errors without regex parsing.
37
+ */
38
+ export class FusionClientError extends Error {
39
+ /** Error code from the `code` attribute (e.g. `'NOT_FOUND'`). */
40
+ code;
41
+ /** Recovery suggestion from `<recovery>` element. */
42
+ recovery;
43
+ /** Available actions from `<available_actions>` children. */
44
+ availableActions;
45
+ /** Error severity from the `severity` attribute. */
46
+ severity;
47
+ /** Raw ToolResponse that caused the error. */
48
+ raw;
49
+ constructor(message, code, raw, options) {
50
+ super(message);
51
+ this.name = 'FusionClientError';
52
+ this.code = code;
53
+ this.raw = raw;
54
+ this.recovery = options?.recovery;
55
+ this.availableActions = Object.freeze(options?.availableActions ?? []);
56
+ this.severity = options?.severity ?? 'error';
57
+ }
58
+ }
59
+ // ============================================================================
60
+ // XML Error Parser (Internal)
61
+ // ============================================================================
62
+ /**
63
+ * Decode XML entities back to their original characters.
64
+ *
65
+ * Reverses the escaping applied by `escapeXml()` and `escapeXmlAttr()`
66
+ * so that parsed error messages are human-readable.
67
+ *
68
+ * @internal
69
+ */
70
+ function unescapeXml(str) {
71
+ return str
72
+ .replace(/&lt;/g, '<')
73
+ .replace(/&gt;/g, '>')
74
+ .replace(/&quot;/g, '"')
75
+ .replace(/&apos;/g, "'")
76
+ .replace(/&amp;/g, '&'); // &amp; must be last to avoid double-decode
77
+ }
78
+ /**
79
+ * Parse a `<tool_error>` XML envelope into structured fields.
80
+ *
81
+ * Coupled to the output format of `toolError()` from `response.ts`.
82
+ * Uses regex for lightweight parsing — acceptable since the XML is
83
+ * self-produced by the framework, not user-authored.
84
+ *
85
+ * @internal
86
+ */
87
+ function parseToolErrorXml(text) {
88
+ const codeMatch = text.match(/<tool_error\s[^>]*code="([^"]+)"/);
89
+ const severityMatch = text.match(/<tool_error\s[^>]*severity="([^"]+)"/);
90
+ const messageMatch = text.match(/<message>([\s\S]*?)<\/message>/);
91
+ const recoveryMatch = text.match(/<recovery>([\s\S]*?)<\/recovery>/);
92
+ if (!messageMatch)
93
+ return null;
94
+ const actions = [];
95
+ const actionMatches = text.matchAll(/<action>([\s\S]*?)<\/action>/g);
96
+ for (const m of actionMatches) {
97
+ if (m[1])
98
+ actions.push(unescapeXml(m[1].trim()));
99
+ }
100
+ // Fallback: legacy comma-separated format
101
+ if (actions.length === 0) {
102
+ const legacyMatch = text.match(/<available_actions>([\s\S]*?)<\/available_actions>/);
103
+ if (legacyMatch?.[1]) {
104
+ actions.push(...legacyMatch[1].split(',').map(a => unescapeXml(a.trim())).filter(Boolean));
105
+ }
106
+ }
107
+ const recovery = recoveryMatch?.[1] != null ? unescapeXml(recoveryMatch[1].trim()) : undefined;
108
+ const result = {
109
+ code: codeMatch?.[1] != null ? unescapeXml(codeMatch[1]) : 'UNKNOWN',
110
+ message: unescapeXml(messageMatch[1].trim()),
111
+ availableActions: actions,
112
+ severity: severityMatch?.[1] ?? 'error',
113
+ };
114
+ if (recovery !== undefined) {
115
+ result.recovery = recovery;
116
+ }
117
+ return result;
118
+ }
119
+ // ============================================================================
120
+ // Middleware Chain Compiler (Internal)
121
+ // ============================================================================
122
+ /** @internal */
123
+ function compileClientMiddleware(middleware, terminal) {
124
+ let chain = terminal;
125
+ // Wrap from right to left: first middleware in array = outermost
126
+ for (let i = middleware.length - 1; i >= 0; i--) {
127
+ const mw = middleware[i];
128
+ const next = chain;
129
+ chain = (action, args) => mw(action, args, next);
130
+ }
131
+ return chain;
132
+ }
133
+ // ============================================================================
30
134
  // Factory
31
135
  // ============================================================================
32
136
  /**
@@ -38,6 +142,7 @@ import {} from '../core/response.js';
38
142
  *
39
143
  * @typeParam TRouter - The router map (use `InferRouter<typeof registry>`)
40
144
  * @param transport - The MCP transport layer
145
+ * @param options - Client options (middleware, error handling)
41
146
  * @returns A typed {@link FusionClient}
42
147
  *
43
148
  * @example
@@ -55,21 +160,78 @@ import {} from '../core/response.js';
55
160
  * // TS error: missing required arg 'name'
56
161
  * await client.execute('projects.create', {});
57
162
  * ```
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * // With client middleware and throwOnError
167
+ * const client = createFusionClient<AppRouter>(transport, {
168
+ * throwOnError: true,
169
+ * middleware: [
170
+ * async (action, args, next) => {
171
+ * console.log(`[Client] calling ${action}`);
172
+ * const result = await next(action, args);
173
+ * console.log(`[Client] ${action} done`);
174
+ * return result;
175
+ * },
176
+ * ],
177
+ * });
178
+ * ```
58
179
  */
59
- export function createFusionClient(transport) {
180
+ export function createFusionClient(transport, options) {
181
+ const throwOnError = options?.throwOnError ?? false;
182
+ /** Terminal function: builds the MCP call from the dotted action path */
183
+ function terminalCall(action, args) {
184
+ const dotIndex = action.indexOf('.');
185
+ if (dotIndex === -1) {
186
+ return transport.callTool(action, args);
187
+ }
188
+ const toolName = action.substring(0, dotIndex);
189
+ const actionName = action.substring(dotIndex + 1);
190
+ return transport.callTool(toolName, {
191
+ action: actionName,
192
+ ...args,
193
+ });
194
+ }
195
+ // Compile middleware chain once at creation time
196
+ const dispatch = (options?.middleware != null && options.middleware.length > 0)
197
+ ? compileClientMiddleware(options.middleware, terminalCall)
198
+ : terminalCall;
199
+ /** Post-process: handle throwOnError */
200
+ async function executeInternal(action, args) {
201
+ const result = await dispatch(action, args);
202
+ if (throwOnError && result.isError) {
203
+ const text = result.content
204
+ .map(c => c.text)
205
+ .join('\n');
206
+ const parsed = parseToolErrorXml(text);
207
+ if (parsed) {
208
+ const opts = {
209
+ availableActions: parsed.availableActions,
210
+ severity: parsed.severity,
211
+ };
212
+ if (parsed.recovery !== undefined) {
213
+ opts.recovery = parsed.recovery;
214
+ }
215
+ throw new FusionClientError(parsed.message, parsed.code, result, opts);
216
+ }
217
+ throw new FusionClientError(text || 'Unknown error', 'UNKNOWN', result);
218
+ }
219
+ return result;
220
+ }
60
221
  return {
61
222
  async execute(action, args) {
62
- // Parse "toolName.actionName" from the action path
63
- const dotIndex = action.indexOf('.');
64
- if (dotIndex === -1) {
65
- return transport.callTool(action, args);
223
+ return executeInternal(action, args);
224
+ },
225
+ async executeBatch(calls, batchOptions) {
226
+ const items = calls;
227
+ if (batchOptions?.sequential) {
228
+ const results = [];
229
+ for (const call of items) {
230
+ results.push(await executeInternal(call.action, call.args));
231
+ }
232
+ return results;
66
233
  }
67
- const toolName = action.substring(0, dotIndex);
68
- const actionName = action.substring(dotIndex + 1);
69
- return transport.callTool(toolName, {
70
- action: actionName,
71
- ...args,
72
- });
234
+ return Promise.all(items.map(call => executeInternal(call.action, call.args)));
73
235
  },
74
236
  };
75
237
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FusionClient.js","sourceRoot":"","sources":["../../src/client/FusionClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAqB,MAAM,qBAAqB,CAAC;AAoDxD,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,kBAAkB,CAC9B,SAA0B;IAE1B,OAAO;QACH,KAAK,CAAC,OAAO,CACT,MAAe,EACf,IAAsB;YAEtB,mDAAmD;YACnD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACrC,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;gBAClB,OAAO,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC5C,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;YAC/C,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;YAElD,OAAO,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE;gBAChC,MAAM,EAAE,UAAU;gBAClB,GAAG,IAAI;aACV,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;AACN,CAAC"}
1
+ {"version":3,"file":"FusionClient.js","sourceRoot":"","sources":["../../src/client/FusionClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAqB,MAAM,qBAAqB,CAAC;A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iBAC5B,CAAC;gBACF,IAAI,MAAM,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;oBAChC,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;gBACpC,CAAC;gBACD,MAAM,IAAI,iBAAiB,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YAC3E,CAAC;YAED,MAAM,IAAI,iBAAiB,CAAC,IAAI,IAAI,eAAe,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC5E,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,OAAO;QACH,KAAK,CAAC,OAAO,CACT,MAAe,EACf,IAAsB;YAEtB,OAAO,eAAe,CAAC,MAAM,EAAE,IAA+B,CAAC,CAAC;QACpE,CAAC;QAED,KAAK,CAAC,YAAY,CACd,KAAqG,EACrG,YAA+D;YAE/D,MAAM,KAAK,GAAG,KAA4E,CAAC;YAC3F,IAAI,YAAY,EAAE,UAAU,EAAE,CAAC;gBAC3B,MAAM,OAAO,GAAmB,EAAE,CAAC;gBACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACvB,OAAO,CAAC,IAAI,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBAChE,CAAC;gBACD,OAAO,OAAO,CAAC;YACnB,CAAC;YAED,OAAO,OAAO,CAAC,GAAG,CACd,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAC7D,CAAC;QACN,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -1,6 +1,6 @@
1
1
  /** Client Bounded Context — Barrel Export */
2
- export { createFusionClient } from './FusionClient.js';
3
- export type { FusionClient, FusionTransport, RouterMap, } from './FusionClient.js';
2
+ export { createFusionClient, FusionClientError } from './FusionClient.js';
3
+ export type { FusionClient, FusionTransport, RouterMap, ClientMiddleware, FusionClientOptions, } from './FusionClient.js';
4
4
  export { createTypedRegistry } from './createTypedRegistry.js';
5
5
  export type { InferRouter, TypedToolRegistry } from './InferRouter.js';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EACR,YAAY,EACZ,eAAe,EACf,SAAS,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,YAAY,EACR,YAAY,EACZ,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,mBAAmB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,4 +1,4 @@
1
1
  /** Client Bounded Context — Barrel Export */
2
- export { createFusionClient } from './FusionClient.js';
2
+ export { createFusionClient, FusionClientError } from './FusionClient.js';
3
3
  export { createTypedRegistry } from './createTypedRegistry.js';
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAMvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAQ1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,178 @@
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
+ /**
45
+ * Issue reported by a Standard Schema validator.
46
+ */
47
+ export interface StandardSchemaIssue {
48
+ readonly message: string;
49
+ readonly path?: readonly (string | number | symbol)[];
50
+ }
51
+ /**
52
+ * Standard Schema v1 spec — the universal validator contract.
53
+ *
54
+ * Any schema library implementing this interface can be used with
55
+ * MCP Fusion's validation pipeline.
56
+ */
57
+ export interface StandardSchemaV1<TInput = unknown, TOutput = TInput> {
58
+ readonly '~standard': {
59
+ readonly version: 1;
60
+ readonly vendor: string;
61
+ readonly validate: (value: TInput) => {
62
+ readonly value: TOutput;
63
+ } | {
64
+ readonly issues: readonly StandardSchemaIssue[];
65
+ };
66
+ };
67
+ }
68
+ /**
69
+ * Infer the output type from a Standard Schema.
70
+ */
71
+ export type InferStandardOutput<T> = T extends StandardSchemaV1<unknown, infer O> ? O : never;
72
+ /**
73
+ * Fusion's internal validation result.
74
+ */
75
+ export type ValidationResult<T> = {
76
+ readonly success: true;
77
+ readonly data: T;
78
+ } | {
79
+ readonly success: false;
80
+ readonly issues: readonly StandardSchemaIssue[];
81
+ };
82
+ /**
83
+ * Universal validator interface used internally by MCP Fusion.
84
+ *
85
+ * Wraps any schema library (Zod, Valibot, ArkType, etc.) into
86
+ * a consistent validation contract.
87
+ */
88
+ export interface FusionValidator<T = unknown> {
89
+ /** Run validation and return a result (never throws) */
90
+ validate(value: unknown): ValidationResult<T>;
91
+ /** Vendor identifier (e.g. 'zod', 'valibot', 'arktype') */
92
+ readonly vendor: string;
93
+ /** Original schema reference (for introspection) */
94
+ readonly schema: unknown;
95
+ }
96
+ /**
97
+ * Create a FusionValidator from a Standard Schema v1 compatible schema.
98
+ *
99
+ * This is the primary entry point for non-Zod validators. Any schema
100
+ * library implementing the Standard Schema spec can be used directly.
101
+ *
102
+ * @param schema - A Standard Schema v1 compatible schema
103
+ * @returns A {@link FusionValidator} wrapping the schema
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import * as v from 'valibot'; // ~1kb tree-shaken
108
+ *
109
+ * const schema = v.object({ name: v.string() });
110
+ * const validator = toStandardValidator(schema);
111
+ *
112
+ * const ok = validator.validate({ name: 'Alice' });
113
+ * // { success: true, data: { name: 'Alice' } }
114
+ *
115
+ * const err = validator.validate({ name: 42 });
116
+ * // { success: false, issues: [{ message: 'Expected string', path: ['name'] }] }
117
+ * ```
118
+ */
119
+ export declare function toStandardValidator<T>(schema: StandardSchemaV1<unknown, T>): FusionValidator<T>;
120
+ /**
121
+ * Create a FusionValidator from a raw Zod schema.
122
+ *
123
+ * This adapter uses Zod's `.safeParse()` method and maps the result
124
+ * to the standard FusionValidator interface.
125
+ *
126
+ * @param schema - A Zod schema (z.object, z.string, etc.)
127
+ * @returns A {@link FusionValidator} wrapping the Zod schema
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * import { z } from 'zod';
132
+ *
133
+ * const schema = z.object({ name: z.string() });
134
+ * const validator = fromZodSchema(schema);
135
+ *
136
+ * const ok = validator.validate({ name: 'Alice' });
137
+ * // { success: true, data: { name: 'Alice' } }
138
+ * ```
139
+ */
140
+ export declare function fromZodSchema<T>(schema: ZodSchemaLike<T>): FusionValidator<T>;
141
+ /**
142
+ * Check if a value implements the Standard Schema v1 spec.
143
+ *
144
+ * @param value - Any value to check
145
+ * @returns `true` if the value has a valid `~standard` property
146
+ */
147
+ export declare function isStandardSchema(value: unknown): value is StandardSchemaV1;
148
+ /**
149
+ * Auto-detect and create a FusionValidator from any supported schema.
150
+ *
151
+ * Detection order:
152
+ * 1. Standard Schema v1 (Valibot, ArkType, etc.)
153
+ * 2. Zod-like (has `.safeParse()`)
154
+ * 3. Throws if unrecognized
155
+ *
156
+ * @param schema - Any supported schema
157
+ * @returns A {@link FusionValidator}
158
+ * @throws If the schema type is not recognized
159
+ */
160
+ export declare function autoValidator<T = unknown>(schema: unknown): FusionValidator<T>;
161
+ /** Duck-typed Zod schema interface */
162
+ interface ZodSchemaLike<T = unknown> {
163
+ safeParse(value: unknown): {
164
+ success: true;
165
+ data: unknown;
166
+ } | {
167
+ success: false;
168
+ error: {
169
+ issues: Array<{
170
+ message: string;
171
+ path?: (string | number)[];
172
+ }>;
173
+ };
174
+ };
175
+ parse?(value: unknown): T;
176
+ }
177
+ export {};
178
+ //# sourceMappingURL=StandardSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StandardSchema.d.ts","sourceRoot":"","sources":["../../src/core/StandardSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAIH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,MAAM,GAAG,OAAO,EAAE,OAAO,GAAG,MAAM;IAChE,QAAQ,CAAC,WAAW,EAAE;QAClB,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAC3B;YAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;SAAE,GAC3B;YAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,mBAAmB,EAAE,CAAA;SAAE,CAAC;KAC7D,CAAC;CACL;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAI9F;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IACxB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GAC5C;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,mBAAmB,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5J,KAAK,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC;CAC7B"}
@@ -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,E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