@vinkius-core/mcp-fusion 1.4.0 → 1.5.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/README.md +2 -0
- package/dist/framework/index.d.ts +6 -0
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js +5 -0
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/prompt/PromptExecutionPipeline.d.ts +61 -0
- package/dist/framework/prompt/PromptExecutionPipeline.d.ts.map +1 -0
- package/dist/framework/prompt/PromptExecutionPipeline.js +191 -0
- package/dist/framework/prompt/PromptExecutionPipeline.js.map +1 -0
- package/dist/framework/prompt/PromptMessage.d.ts +90 -0
- package/dist/framework/prompt/PromptMessage.d.ts.map +1 -0
- package/dist/framework/prompt/PromptMessage.js +104 -0
- package/dist/framework/prompt/PromptMessage.js.map +1 -0
- package/dist/framework/prompt/PromptTypes.d.ts +226 -0
- package/dist/framework/prompt/PromptTypes.d.ts.map +1 -0
- package/dist/framework/prompt/PromptTypes.js +18 -0
- package/dist/framework/prompt/PromptTypes.js.map +1 -0
- package/dist/framework/prompt/definePrompt.d.ts +107 -0
- package/dist/framework/prompt/definePrompt.d.ts.map +1 -0
- package/dist/framework/prompt/definePrompt.js +134 -0
- package/dist/framework/prompt/definePrompt.js.map +1 -0
- package/dist/framework/prompt/index.d.ts +11 -0
- package/dist/framework/prompt/index.d.ts.map +1 -0
- package/dist/framework/prompt/index.js +12 -0
- package/dist/framework/prompt/index.js.map +1 -0
- package/dist/framework/registry/PromptRegistry.d.ts +143 -0
- package/dist/framework/registry/PromptRegistry.d.ts.map +1 -0
- package/dist/framework/registry/PromptRegistry.js +216 -0
- package/dist/framework/registry/PromptRegistry.js.map +1 -0
- package/dist/framework/registry/index.d.ts +3 -1
- package/dist/framework/registry/index.d.ts.map +1 -1
- package/dist/framework/registry/index.js +1 -1
- package/dist/framework/registry/index.js.map +1 -1
- package/dist/framework/server/ServerAttachment.d.ts +25 -0
- package/dist/framework/server/ServerAttachment.d.ts.map +1 -1
- package/dist/framework/server/ServerAttachment.js +36 -2
- package/dist/framework/server/ServerAttachment.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -391,6 +391,7 @@ After `buildToolDefinition()`, the builder is permanently frozen. `Object.freeze
|
|
|
391
391
|
| **Streaming Progress** | Generator handlers yield `progress()` events |
|
|
392
392
|
| **Type-Safe Client** | `createFusionClient()` with autocomplete and typed args |
|
|
393
393
|
| **State Sync** | RFC 7234 cache-control prevents temporal blindness |
|
|
394
|
+
| **Prompt Engine** | `definePrompt()` — server-side hydrated templates with flat schema constraint |
|
|
394
395
|
| **TOON Encoding** | Token-optimized descriptions and responses |
|
|
395
396
|
| **Tag Filtering** | Context gating — control what the LLM sees per session |
|
|
396
397
|
| **Observability** | Debug observers with zero-overhead typed event system |
|
|
@@ -415,6 +416,7 @@ After `buildToolDefinition()`, the builder is permanently frozen. `Object.freeze
|
|
|
415
416
|
| 🛡️ **[Middleware](docs/middleware.md)** | Context derivation, authentication, pre-compiled chains |
|
|
416
417
|
| 📈 **[Scaling](docs/scaling.md)** | Tag filtering, TOON, hierarchical groups at scale |
|
|
417
418
|
| 🧠 **[State Sync](docs/state-sync.md)** | Prevent temporal blindness with cache signals |
|
|
419
|
+
| 💬 **[Prompt Engine](docs/prompts.md)** | Server-side hydrated prompts with coercion and lifecycle sync |
|
|
418
420
|
| 🔭 **[Observability](docs/observability.md)** | Zero-overhead debug observers with typed event system |
|
|
419
421
|
| 🔀 **[Tool Exposition](docs/tool-exposition.md)** | Flat vs grouped wire strategies — per-action isolation |
|
|
420
422
|
| 📖 **[API Reference](docs/api-reference.md)** | Complete typings and method reference |
|
|
@@ -13,7 +13,9 @@ export { GroupedToolBuilder, ActionGroupBuilder, createTool, defineTool } from '
|
|
|
13
13
|
export type { GroupConfigurator, ToolConfig, ActionDef, GroupDef } from './builder/index.js';
|
|
14
14
|
export type { ParamDef, ParamsMap, InferParams, StringParamDef, NumberParamDef, BooleanParamDef, EnumParamDef, ArrayParamDef, } from './builder/index.js';
|
|
15
15
|
export { ToolRegistry } from './registry/index.js';
|
|
16
|
+
export { PromptRegistry } from './registry/index.js';
|
|
16
17
|
export type { ToolFilter } from './registry/index.js';
|
|
18
|
+
export type { McpPromptDef, PromptFilter } from './registry/index.js';
|
|
17
19
|
export type { AttachOptions, DetachFn, ToolExposition, ExpositionConfig } from './server/index.js';
|
|
18
20
|
export { generateToonDescription } from './schema/index.js';
|
|
19
21
|
export { progress } from './execution/index.js';
|
|
@@ -35,4 +37,8 @@ export { Presenter, createPresenter, isPresenter } from './presenter/index.js';
|
|
|
35
37
|
export { PresenterValidationError } from './presenter/index.js';
|
|
36
38
|
export { compileManifest, cloneManifest, registerIntrospectionResource } from './introspection/index.js';
|
|
37
39
|
export type { IntrospectionConfig, ManifestPayload, ManifestCapabilities, ManifestTool, ManifestAction, ManifestPresenter, IntrospectionRegistryDelegate, } from './introspection/index.js';
|
|
40
|
+
export { definePrompt } from './prompt/index.js';
|
|
41
|
+
export { PromptMessage } from './prompt/index.js';
|
|
42
|
+
export { assertFlatSchema, coercePromptArgs } from './prompt/index.js';
|
|
43
|
+
export type { PromptMessagePayload, PromptResult, PromptParamDef, PromptParamsMap, PromptBuilder, PromptConfig, } from './prompt/index.js';
|
|
38
44
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/framework/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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;AACpE,OAAO,EAAE,OAAO,EAAE,IAA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BAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACvE,YAAY,EACR,oBAAoB,EAAE,YAAY,EAClC,cAAc,EAAE,eAAe,EAC/B,aAAa,EAAE,YAAY,GAC9B,MAAM,mBAAmB,CAAC"}
|
package/dist/framework/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { succeed, fail } from './result.js';
|
|
|
11
11
|
export { GroupedToolBuilder, ActionGroupBuilder, createTool, defineTool } from './builder/index.js';
|
|
12
12
|
// ── Registry ─────────────────────────────────────────────
|
|
13
13
|
export { ToolRegistry } from './registry/index.js';
|
|
14
|
+
export { PromptRegistry } from './registry/index.js';
|
|
14
15
|
// ── Schema (public strategies) ───────────────────────────
|
|
15
16
|
export { generateToonDescription } from './schema/index.js';
|
|
16
17
|
// ── Progress (streaming) ─────────────────────────────────
|
|
@@ -31,4 +32,8 @@ export { Presenter, createPresenter, isPresenter } from './presenter/index.js';
|
|
|
31
32
|
export { PresenterValidationError } from './presenter/index.js';
|
|
32
33
|
// ── Introspection (Dynamic Manifest) ─────────────────────
|
|
33
34
|
export { compileManifest, cloneManifest, registerIntrospectionResource } from './introspection/index.js';
|
|
35
|
+
// ── Prompt Engine ────────────────────────────────────────
|
|
36
|
+
export { definePrompt } from './prompt/index.js';
|
|
37
|
+
export { PromptMessage } from './prompt/index.js';
|
|
38
|
+
export { assertFlatSchema, coercePromptArgs } from './prompt/index.js';
|
|
34
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/framework/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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,kB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BAAsB,CAAC;AACpF,OAAO,EAAE,EAAE,EAAE,MAAM,sBAAsB,CAAC;AAE1C,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAEhE,4DAA4D;AAC5D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AAQzG,4DAA4D;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptExecutionPipeline — Prompt Hydration Pipeline
|
|
3
|
+
*
|
|
4
|
+
* Handles the complete lifecycle of a `prompts/get` request:
|
|
5
|
+
*
|
|
6
|
+
* 1. Schema-Informed Coercion (string → typed values)
|
|
7
|
+
* 2. Zod Validation (.strict() + coaching errors)
|
|
8
|
+
* 3. Middleware Chain execution
|
|
9
|
+
* 4. Handler invocation
|
|
10
|
+
*
|
|
11
|
+
* Key feature: **Schema-Informed Boundary Coercion**
|
|
12
|
+
* MCP transmits ALL prompt arguments as `Record<string, string>`.
|
|
13
|
+
* This module reads the Zod schema AST to determine expected types
|
|
14
|
+
* and coerces string values deterministically — no guessing.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import { type ZodObject, type ZodRawShape } from 'zod';
|
|
19
|
+
import { type PromptResult } from './PromptTypes.js';
|
|
20
|
+
import { type MiddlewareFn } from '../types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Assert that a Zod schema only contains flat primitive fields.
|
|
23
|
+
*
|
|
24
|
+
* Throws a descriptive error if any field uses arrays, objects,
|
|
25
|
+
* tuples, records, maps, or sets — types that MCP clients cannot
|
|
26
|
+
* render as visual form fields.
|
|
27
|
+
*
|
|
28
|
+
* Called at **definition time** (in `definePrompt()`) to fail fast
|
|
29
|
+
* and prevent runtime surprises.
|
|
30
|
+
*
|
|
31
|
+
* @param schema - The Zod schema to validate
|
|
32
|
+
* @throws Error with coaching message if nested types are found
|
|
33
|
+
*/
|
|
34
|
+
export declare function assertFlatSchema(schema: ZodObject<ZodRawShape>): void;
|
|
35
|
+
/**
|
|
36
|
+
* Schema-Informed Boundary Coercion.
|
|
37
|
+
*
|
|
38
|
+
* Reads the Zod schema AST to determine expected types,
|
|
39
|
+
* then coerces string values from the MCP wire format.
|
|
40
|
+
*
|
|
41
|
+
* This is NOT guessing. The coercion is derived from the
|
|
42
|
+
* developer's declared schema — it's deterministic.
|
|
43
|
+
*
|
|
44
|
+
* @param rawArgs - Raw string arguments from the MCP client
|
|
45
|
+
* @param zodSchema - The validated Zod schema for this prompt
|
|
46
|
+
* @returns Coerced argument values ready for Zod validation
|
|
47
|
+
*/
|
|
48
|
+
export declare function coercePromptArgs(rawArgs: Record<string, string>, zodSchema: ZodObject<ZodRawShape>): Record<string, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Execute the full prompt hydration pipeline.
|
|
51
|
+
*
|
|
52
|
+
* Steps:
|
|
53
|
+
* 1. Coerce string args to typed values using schema AST
|
|
54
|
+
* 2. Validate with Zod (.strict() enforced)
|
|
55
|
+
* 3. Run middleware chain
|
|
56
|
+
* 4. Execute handler
|
|
57
|
+
*
|
|
58
|
+
* @returns Either a `PromptResult` or an error `PromptResult` with coaching
|
|
59
|
+
*/
|
|
60
|
+
export declare function executePromptPipeline<TContext>(ctx: TContext, rawArgs: Record<string, string>, schema: ZodObject<ZodRawShape> | undefined, middlewares: readonly MiddlewareFn<TContext>[], handler: (ctx: TContext, args: Record<string, unknown>) => Promise<PromptResult>): Promise<PromptResult>;
|
|
61
|
+
//# sourceMappingURL=PromptExecutionPipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptExecutionPipeline.d.ts","sourceRoot":"","sources":["../../../src/framework/prompt/PromptExecutionPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAmB,MAAM,KAAK,CAAC;AACxE,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAoChD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,IAAI,CAYrE;AAID;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,SAAS,EAAE,SAAS,CAAC,WAAW,CAAC,GAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA8BzB;AAoDD;;;;;;;;;;GAUG;AACH,wBAAsB,qBAAqB,CAAC,QAAQ,EAChD,GAAG,EAAE,QAAQ,EACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,MAAM,EAAE,SAAS,CAAC,WAAW,CAAC,GAAG,SAAS,EAC1C,WAAW,EAAE,SAAS,YAAY,CAAC,QAAQ,CAAC,EAAE,EAC9C,OAAO,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,GACjF,OAAO,CAAC,YAAY,CAAC,CAgCvB"}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptExecutionPipeline — Prompt Hydration Pipeline
|
|
3
|
+
*
|
|
4
|
+
* Handles the complete lifecycle of a `prompts/get` request:
|
|
5
|
+
*
|
|
6
|
+
* 1. Schema-Informed Coercion (string → typed values)
|
|
7
|
+
* 2. Zod Validation (.strict() + coaching errors)
|
|
8
|
+
* 3. Middleware Chain execution
|
|
9
|
+
* 4. Handler invocation
|
|
10
|
+
*
|
|
11
|
+
* Key feature: **Schema-Informed Boundary Coercion**
|
|
12
|
+
* MCP transmits ALL prompt arguments as `Record<string, string>`.
|
|
13
|
+
* This module reads the Zod schema AST to determine expected types
|
|
14
|
+
* and coerces string values deterministically — no guessing.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import {} from 'zod';
|
|
19
|
+
import {} from './PromptTypes.js';
|
|
20
|
+
import {} from '../types.js';
|
|
21
|
+
// ── Flat Schema Guard ────────────────────────────────────
|
|
22
|
+
/** Zod type names that are NOT allowed in prompt argument schemas */
|
|
23
|
+
const FORBIDDEN_ZOD_TYPES = new Set([
|
|
24
|
+
'ZodArray', 'ZodObject', 'ZodTuple', 'ZodRecord', 'ZodMap', 'ZodSet',
|
|
25
|
+
]);
|
|
26
|
+
/**
|
|
27
|
+
* Get the base Zod type name, unwrapping Optional/Default/Nullable wrappers.
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
function getZodBaseTypeName(schema) {
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
const def = schema._def;
|
|
33
|
+
if (!def)
|
|
34
|
+
return 'Unknown';
|
|
35
|
+
const typeName = def.typeName ?? '';
|
|
36
|
+
// Unwrap Optional, Default, Nullable, Effects to find the inner type
|
|
37
|
+
if (typeName === 'ZodOptional' ||
|
|
38
|
+
typeName === 'ZodDefault' ||
|
|
39
|
+
typeName === 'ZodNullable') {
|
|
40
|
+
return getZodBaseTypeName(def.innerType);
|
|
41
|
+
}
|
|
42
|
+
if (typeName === 'ZodEffects') {
|
|
43
|
+
return getZodBaseTypeName(def.schema);
|
|
44
|
+
}
|
|
45
|
+
return typeName;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Assert that a Zod schema only contains flat primitive fields.
|
|
49
|
+
*
|
|
50
|
+
* Throws a descriptive error if any field uses arrays, objects,
|
|
51
|
+
* tuples, records, maps, or sets — types that MCP clients cannot
|
|
52
|
+
* render as visual form fields.
|
|
53
|
+
*
|
|
54
|
+
* Called at **definition time** (in `definePrompt()`) to fail fast
|
|
55
|
+
* and prevent runtime surprises.
|
|
56
|
+
*
|
|
57
|
+
* @param schema - The Zod schema to validate
|
|
58
|
+
* @throws Error with coaching message if nested types are found
|
|
59
|
+
*/
|
|
60
|
+
export function assertFlatSchema(schema) {
|
|
61
|
+
for (const [key, field] of Object.entries(schema.shape)) {
|
|
62
|
+
const typeName = getZodBaseTypeName(field);
|
|
63
|
+
if (FORBIDDEN_ZOD_TYPES.has(typeName)) {
|
|
64
|
+
throw new Error(`[definePrompt] Argument '${key}' uses type '${typeName}', which is not supported ` +
|
|
65
|
+
`in MCP prompt arguments. MCP clients render prompt args as visual forms — only ` +
|
|
66
|
+
`flat primitives (string, number, boolean, enum) are supported.\n` +
|
|
67
|
+
`💡 If you need complex data, fetch it server-side inside the handler instead.`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// ── Schema-Informed Coercion ─────────────────────────────
|
|
72
|
+
/**
|
|
73
|
+
* Schema-Informed Boundary Coercion.
|
|
74
|
+
*
|
|
75
|
+
* Reads the Zod schema AST to determine expected types,
|
|
76
|
+
* then coerces string values from the MCP wire format.
|
|
77
|
+
*
|
|
78
|
+
* This is NOT guessing. The coercion is derived from the
|
|
79
|
+
* developer's declared schema — it's deterministic.
|
|
80
|
+
*
|
|
81
|
+
* @param rawArgs - Raw string arguments from the MCP client
|
|
82
|
+
* @param zodSchema - The validated Zod schema for this prompt
|
|
83
|
+
* @returns Coerced argument values ready for Zod validation
|
|
84
|
+
*/
|
|
85
|
+
export function coercePromptArgs(rawArgs, zodSchema) {
|
|
86
|
+
const coerced = {};
|
|
87
|
+
const shape = zodSchema.shape;
|
|
88
|
+
for (const [key, value] of Object.entries(rawArgs)) {
|
|
89
|
+
const fieldSchema = shape[key];
|
|
90
|
+
if (!fieldSchema) {
|
|
91
|
+
// Unknown field — pass through, let Zod .strict() reject it
|
|
92
|
+
coerced[key] = value;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const typeName = getZodBaseTypeName(fieldSchema);
|
|
96
|
+
switch (typeName) {
|
|
97
|
+
case 'ZodBoolean':
|
|
98
|
+
coerced[key] = value === 'true';
|
|
99
|
+
break;
|
|
100
|
+
case 'ZodNumber':
|
|
101
|
+
coerced[key] = Number(value);
|
|
102
|
+
break;
|
|
103
|
+
case 'ZodEnum':
|
|
104
|
+
case 'ZodString':
|
|
105
|
+
default:
|
|
106
|
+
coerced[key] = value;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return coerced;
|
|
111
|
+
}
|
|
112
|
+
// ── Validation ───────────────────────────────────────────
|
|
113
|
+
/**
|
|
114
|
+
* Format a Zod validation error into a coaching prompt.
|
|
115
|
+
*
|
|
116
|
+
* Returns a human+LLM readable error that guides the agent
|
|
117
|
+
* (or the user via the MCP client) to correct the input.
|
|
118
|
+
*/
|
|
119
|
+
function formatPromptValidationError(issues) {
|
|
120
|
+
const lines = ['⚠️ PROMPT ARGUMENT VALIDATION FAILED:', ''];
|
|
121
|
+
for (const issue of issues) {
|
|
122
|
+
const field = issue.path.join('.') || '(root)';
|
|
123
|
+
lines.push(` • ${field} — ${issue.message}`);
|
|
124
|
+
}
|
|
125
|
+
lines.push('', '💡 Check the prompt definition for valid argument types and values.');
|
|
126
|
+
return lines.join('\n');
|
|
127
|
+
}
|
|
128
|
+
// ── Middleware Compiler ──────────────────────────────────
|
|
129
|
+
/**
|
|
130
|
+
* Compile middleware chain for a prompt handler.
|
|
131
|
+
*
|
|
132
|
+
* Wraps middlewares right-to-left around the handler function,
|
|
133
|
+
* producing a ready-to-execute chain. Same pattern as tool
|
|
134
|
+
* middleware compilation.
|
|
135
|
+
*
|
|
136
|
+
* @param handler - The prompt handler function
|
|
137
|
+
* @param middlewares - Middleware stack (outermost first)
|
|
138
|
+
* @returns The compiled chain function
|
|
139
|
+
*/
|
|
140
|
+
function compilePromptChain(handler, middlewares) {
|
|
141
|
+
let chain = handler;
|
|
142
|
+
for (let i = middlewares.length - 1; i >= 0; i--) {
|
|
143
|
+
const mw = middlewares[i];
|
|
144
|
+
if (!mw)
|
|
145
|
+
continue;
|
|
146
|
+
const nextFn = chain;
|
|
147
|
+
chain = (ctx, args) => mw(ctx, args, () => nextFn(ctx, args));
|
|
148
|
+
}
|
|
149
|
+
return chain;
|
|
150
|
+
}
|
|
151
|
+
// ── Pipeline ─────────────────────────────────────────────
|
|
152
|
+
/**
|
|
153
|
+
* Execute the full prompt hydration pipeline.
|
|
154
|
+
*
|
|
155
|
+
* Steps:
|
|
156
|
+
* 1. Coerce string args to typed values using schema AST
|
|
157
|
+
* 2. Validate with Zod (.strict() enforced)
|
|
158
|
+
* 3. Run middleware chain
|
|
159
|
+
* 4. Execute handler
|
|
160
|
+
*
|
|
161
|
+
* @returns Either a `PromptResult` or an error `PromptResult` with coaching
|
|
162
|
+
*/
|
|
163
|
+
export async function executePromptPipeline(ctx, rawArgs, schema, middlewares, handler) {
|
|
164
|
+
// Step 1 + 2: Coerce and validate
|
|
165
|
+
let validatedArgs = rawArgs;
|
|
166
|
+
if (schema) {
|
|
167
|
+
const coerced = coercePromptArgs(rawArgs, schema);
|
|
168
|
+
const result = schema.strict().safeParse(coerced);
|
|
169
|
+
if (!result.success) {
|
|
170
|
+
// Return a validation error as a user message
|
|
171
|
+
return {
|
|
172
|
+
messages: [{
|
|
173
|
+
role: 'user',
|
|
174
|
+
content: {
|
|
175
|
+
type: 'text',
|
|
176
|
+
text: formatPromptValidationError(result.error.issues),
|
|
177
|
+
},
|
|
178
|
+
}],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
validatedArgs = result.data;
|
|
182
|
+
}
|
|
183
|
+
// Step 3 + 4: Middleware chain → handler
|
|
184
|
+
if (middlewares.length > 0) {
|
|
185
|
+
const chain = compilePromptChain(handler, middlewares);
|
|
186
|
+
const result = await chain(ctx, validatedArgs);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
return handler(ctx, validatedArgs);
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=PromptExecutionPipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptExecutionPipeline.js","sourceRoot":"","sources":["../../../src/framework/prompt/PromptExecutionPipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAqD,MAAM,KAAK,CAAC;AACxE,OAAO,EAAqB,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAqB,MAAM,aAAa,CAAC;AAEhD,4DAA4D;AAE5D,qEAAqE;AACrE,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAChC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ;CACvE,CAAC,CAAC;AAEH;;;GAGG;AACH,SAAS,kBAAkB,CAAC,MAAkB;IAC1C,8DAA8D;IAC9D,MAAM,GAAG,GAAI,MAAc,CAAC,IAAI,CAAC;IACjC,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAE3B,MAAM,QAAQ,GAAW,GAAG,CAAC,QAAQ,IAAI,EAAE,CAAC;IAE5C,qEAAqE;IACrE,IACI,QAAQ,KAAK,aAAa;QAC1B,QAAQ,KAAK,YAAY;QACzB,QAAQ,KAAK,aAAa,EAC5B,CAAC;QACC,OAAO,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC5B,OAAO,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,QAAQ,C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AA4D;AAE5D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACvC,GAAa,EACb,OAA+B,EAC/B,MAA0C,EAC1C,WAA8C,EAC9C,OAAgF;IAEhF,kCAAkC;IAClC,IAAI,aAAa,GAA4B,OAAO,CAAC;IAErD,IAAI,MAAM,EAAE,CAAC;QACT,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAElD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAClB,8CAA8C;YAC9C,OAAO;gBACH,QAAQ,EAAE,CAAC;wBACP,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE;4BACL,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,2BAA2B,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;yBACzD;qBACJ,CAAC;aACL,CAAC;QACN,CAAC;QAED,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,yCAAyC;IACzC,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QAC/C,OAAO,MAAsB,CAAC;IAClC,CAAC;IAED,OAAO,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptMessage — Factory Helpers for Prompt Messages
|
|
3
|
+
*
|
|
4
|
+
* Provides ergonomic factory methods for creating `PromptMessagePayload`
|
|
5
|
+
* objects used in `PromptResult.messages`.
|
|
6
|
+
*
|
|
7
|
+
* These helpers encode the MCP wire format so developers never deal
|
|
8
|
+
* with `{ role: 'user', content: { type: 'text', text: '...' } }`
|
|
9
|
+
* manually.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { PromptMessage } from '@vinkius-core/mcp-fusion';
|
|
14
|
+
*
|
|
15
|
+
* return {
|
|
16
|
+
* messages: [
|
|
17
|
+
* PromptMessage.system('You are a Senior Auditor.'),
|
|
18
|
+
* PromptMessage.user('Begin the audit.'),
|
|
19
|
+
* PromptMessage.assistant('Analyzing invoices...'),
|
|
20
|
+
* ],
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import { type PromptMessagePayload } from './PromptTypes.js';
|
|
27
|
+
/**
|
|
28
|
+
* Factory for creating MCP prompt messages.
|
|
29
|
+
*
|
|
30
|
+
* **Note on `system()`:** The MCP protocol only supports `user` and
|
|
31
|
+
* `assistant` roles in `PromptMessage`. System instructions are encoded
|
|
32
|
+
* as a `user` message (the first message) by convention — the MCP client
|
|
33
|
+
* prepends it to the conversation context.
|
|
34
|
+
*/
|
|
35
|
+
export declare const PromptMessage: {
|
|
36
|
+
/**
|
|
37
|
+
* Create a system instruction message.
|
|
38
|
+
*
|
|
39
|
+
* Encoded as `role: 'user'` per MCP spec (MCP does not have
|
|
40
|
+
* a `system` role in PromptMessage — system instructions are
|
|
41
|
+
* conveyed as the first `user` message by convention).
|
|
42
|
+
*
|
|
43
|
+
* @param text - System instruction text
|
|
44
|
+
*/
|
|
45
|
+
readonly system: (text: string) => PromptMessagePayload;
|
|
46
|
+
/**
|
|
47
|
+
* Create a user message.
|
|
48
|
+
*
|
|
49
|
+
* @param text - User message text
|
|
50
|
+
*/
|
|
51
|
+
readonly user: (text: string) => PromptMessagePayload;
|
|
52
|
+
/**
|
|
53
|
+
* Create an assistant message (for multi-turn seeding).
|
|
54
|
+
*
|
|
55
|
+
* Use this to pre-seed the assistant's initial response,
|
|
56
|
+
* guiding the LLM's first reasoning step.
|
|
57
|
+
*
|
|
58
|
+
* @param text - Assistant message text
|
|
59
|
+
*/
|
|
60
|
+
readonly assistant: (text: string) => PromptMessagePayload;
|
|
61
|
+
/**
|
|
62
|
+
* Create a message with an embedded image.
|
|
63
|
+
*
|
|
64
|
+
* @param role - Message role ('user' or 'assistant')
|
|
65
|
+
* @param data - Base64-encoded image data
|
|
66
|
+
* @param mimeType - MIME type (e.g., 'image/png', 'image/jpeg')
|
|
67
|
+
*/
|
|
68
|
+
readonly image: (role: "user" | "assistant", data: string, mimeType: string) => PromptMessagePayload;
|
|
69
|
+
/**
|
|
70
|
+
* Create a message with embedded audio.
|
|
71
|
+
*
|
|
72
|
+
* @param role - Message role ('user' or 'assistant')
|
|
73
|
+
* @param data - Base64-encoded audio data
|
|
74
|
+
* @param mimeType - MIME type (e.g., 'audio/wav', 'audio/mp3')
|
|
75
|
+
*/
|
|
76
|
+
readonly audio: (role: "user" | "assistant", data: string, mimeType: string) => PromptMessagePayload;
|
|
77
|
+
/**
|
|
78
|
+
* Create a message with an embedded resource reference.
|
|
79
|
+
*
|
|
80
|
+
* @param role - Message role ('user' or 'assistant')
|
|
81
|
+
* @param uri - Resource URI
|
|
82
|
+
* @param options - Optional mime type, text, or blob data
|
|
83
|
+
*/
|
|
84
|
+
readonly resource: (role: "user" | "assistant", uri: string, options?: {
|
|
85
|
+
mimeType?: string;
|
|
86
|
+
text?: string;
|
|
87
|
+
blob?: string;
|
|
88
|
+
}) => PromptMessagePayload;
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=PromptMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptMessage.d.ts","sourceRoot":"","sources":["../../../src/framework/prompt/PromptMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;IACtB;;;;;;;;OAQG;4BACU,MAAM,KAAG,oBAAoB;IAI1C;;;;OAIG;0BACQ,MAAM,KAAG,oBAAoB;IAIxC;;;;;;;OAOG;+BACa,MAAM,KAAG,oBAAoB;IAI7C;;;;;;OAMG;2BACS,MAAM,GAAG,WAAW,QAAQ,MAAM,YAAY,MAAM,KAAG,oBAAoB;IAIvF;;;;;;OAMG;2BACS,MAAM,GAAG,WAAW,QAAQ,MAAM,YAAY,MAAM,KAAG,oBAAoB;IAIvF;;;;;;OAMG;8BAEO,MAAM,GAAG,WAAW,OACrB,MAAM,YACD;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAC9D,oBAAoB;CASjB,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptMessage — Factory Helpers for Prompt Messages
|
|
3
|
+
*
|
|
4
|
+
* Provides ergonomic factory methods for creating `PromptMessagePayload`
|
|
5
|
+
* objects used in `PromptResult.messages`.
|
|
6
|
+
*
|
|
7
|
+
* These helpers encode the MCP wire format so developers never deal
|
|
8
|
+
* with `{ role: 'user', content: { type: 'text', text: '...' } }`
|
|
9
|
+
* manually.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { PromptMessage } from '@vinkius-core/mcp-fusion';
|
|
14
|
+
*
|
|
15
|
+
* return {
|
|
16
|
+
* messages: [
|
|
17
|
+
* PromptMessage.system('You are a Senior Auditor.'),
|
|
18
|
+
* PromptMessage.user('Begin the audit.'),
|
|
19
|
+
* PromptMessage.assistant('Analyzing invoices...'),
|
|
20
|
+
* ],
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @module
|
|
25
|
+
*/
|
|
26
|
+
import {} from './PromptTypes.js';
|
|
27
|
+
/**
|
|
28
|
+
* Factory for creating MCP prompt messages.
|
|
29
|
+
*
|
|
30
|
+
* **Note on `system()`:** The MCP protocol only supports `user` and
|
|
31
|
+
* `assistant` roles in `PromptMessage`. System instructions are encoded
|
|
32
|
+
* as a `user` message (the first message) by convention — the MCP client
|
|
33
|
+
* prepends it to the conversation context.
|
|
34
|
+
*/
|
|
35
|
+
export const PromptMessage = {
|
|
36
|
+
/**
|
|
37
|
+
* Create a system instruction message.
|
|
38
|
+
*
|
|
39
|
+
* Encoded as `role: 'user'` per MCP spec (MCP does not have
|
|
40
|
+
* a `system` role in PromptMessage — system instructions are
|
|
41
|
+
* conveyed as the first `user` message by convention).
|
|
42
|
+
*
|
|
43
|
+
* @param text - System instruction text
|
|
44
|
+
*/
|
|
45
|
+
system(text) {
|
|
46
|
+
return { role: 'user', content: { type: 'text', text } };
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Create a user message.
|
|
50
|
+
*
|
|
51
|
+
* @param text - User message text
|
|
52
|
+
*/
|
|
53
|
+
user(text) {
|
|
54
|
+
return { role: 'user', content: { type: 'text', text } };
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Create an assistant message (for multi-turn seeding).
|
|
58
|
+
*
|
|
59
|
+
* Use this to pre-seed the assistant's initial response,
|
|
60
|
+
* guiding the LLM's first reasoning step.
|
|
61
|
+
*
|
|
62
|
+
* @param text - Assistant message text
|
|
63
|
+
*/
|
|
64
|
+
assistant(text) {
|
|
65
|
+
return { role: 'assistant', content: { type: 'text', text } };
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Create a message with an embedded image.
|
|
69
|
+
*
|
|
70
|
+
* @param role - Message role ('user' or 'assistant')
|
|
71
|
+
* @param data - Base64-encoded image data
|
|
72
|
+
* @param mimeType - MIME type (e.g., 'image/png', 'image/jpeg')
|
|
73
|
+
*/
|
|
74
|
+
image(role, data, mimeType) {
|
|
75
|
+
return { role, content: { type: 'image', data, mimeType } };
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Create a message with embedded audio.
|
|
79
|
+
*
|
|
80
|
+
* @param role - Message role ('user' or 'assistant')
|
|
81
|
+
* @param data - Base64-encoded audio data
|
|
82
|
+
* @param mimeType - MIME type (e.g., 'audio/wav', 'audio/mp3')
|
|
83
|
+
*/
|
|
84
|
+
audio(role, data, mimeType) {
|
|
85
|
+
return { role, content: { type: 'audio', data, mimeType } };
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Create a message with an embedded resource reference.
|
|
89
|
+
*
|
|
90
|
+
* @param role - Message role ('user' or 'assistant')
|
|
91
|
+
* @param uri - Resource URI
|
|
92
|
+
* @param options - Optional mime type, text, or blob data
|
|
93
|
+
*/
|
|
94
|
+
resource(role, uri, options) {
|
|
95
|
+
return {
|
|
96
|
+
role,
|
|
97
|
+
content: {
|
|
98
|
+
type: 'resource',
|
|
99
|
+
resource: { uri, ...options },
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=PromptMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromptMessage.js","sourceRoot":"","sources":["../../../src/framework/prompt/PromptMessage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,EAA6B,MAAM,kBAAkB,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IACzB;;;;;;;;OAQG;IACH,MAAM,CAAC,IAAY;QACf,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;IAC7D,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,IAAY;QACb,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,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