ont-run 0.0.4 → 0.0.5
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 +8 -4
- package/dist/bin/ont.js +202 -6
- package/dist/index.js +18 -54
- package/dist/src/browser/server.d.ts +2 -0
- package/dist/src/browser/transform.d.ts +0 -1
- package/dist/src/config/define.d.ts +37 -2
- package/dist/src/config/schema.d.ts +8 -8
- package/dist/src/config/types.d.ts +27 -27
- package/dist/src/index.d.ts +3 -2
- package/dist/src/server/api/index.d.ts +0 -2
- package/dist/src/server/api/router.d.ts +1 -1
- package/dist/src/server/mcp/index.d.ts +0 -2
- package/dist/src/server/mcp/tools.d.ts +2 -2
- package/dist/src/server/resolver.d.ts +4 -15
- package/package.json +1 -1
- package/src/browser/server.ts +203 -2
- package/src/browser/transform.ts +0 -2
- package/src/cli/commands/review.ts +2 -1
- package/src/config/define.ts +49 -1
- package/src/config/schema.ts +1 -1
- package/src/config/types.ts +33 -31
- package/src/index.ts +3 -2
- package/src/server/api/index.ts +2 -15
- package/src/server/api/router.ts +3 -6
- package/src/server/mcp/index.ts +2 -4
- package/src/server/mcp/tools.ts +3 -5
- package/src/server/resolver.ts +5 -78
- package/src/server/start.ts +0 -2
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* ```ts
|
|
6
6
|
* import { defineOntology, fieldFrom } from 'ont-run';
|
|
7
7
|
* import { z } from 'zod';
|
|
8
|
+
* import { hello } from './resolvers/hello.js';
|
|
8
9
|
*
|
|
9
10
|
* export default defineOntology({
|
|
10
11
|
* name: 'my-api',
|
|
@@ -23,7 +24,7 @@
|
|
|
23
24
|
* access: ['public'],
|
|
24
25
|
* entities: [],
|
|
25
26
|
* inputs: z.object({ name: z.string() }),
|
|
26
|
-
* resolver:
|
|
27
|
+
* resolver: hello, // Direct function reference for type safety
|
|
27
28
|
* },
|
|
28
29
|
* },
|
|
29
30
|
* });
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
*/
|
|
32
33
|
|
|
33
34
|
// Main API
|
|
34
|
-
export { defineOntology } from "./config/define.js";
|
|
35
|
+
export { defineOntology, defineFunction } from "./config/define.js";
|
|
35
36
|
export { fieldFrom, userContext } from "./config/categorical.js";
|
|
36
37
|
export { startOnt } from "./server/start.js";
|
|
37
38
|
export type { StartOntOptions, StartOntResult } from "./server/start.js";
|
package/src/server/api/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
2
|
import { cors } from "hono/cors";
|
|
3
|
-
import consola from "consola";
|
|
4
3
|
import type { OntologyConfig } from "../../config/types.js";
|
|
5
4
|
import {
|
|
6
5
|
createAuthMiddleware,
|
|
@@ -9,13 +8,10 @@ import {
|
|
|
9
8
|
type OntologyVariables,
|
|
10
9
|
} from "./middleware.js";
|
|
11
10
|
import { createApiRoutes, getFunctionsInfo } from "./router.js";
|
|
12
|
-
import { findMissingResolvers } from "../resolver.js";
|
|
13
11
|
|
|
14
12
|
export interface ApiServerOptions {
|
|
15
13
|
/** The ontology configuration */
|
|
16
14
|
config: OntologyConfig;
|
|
17
|
-
/** Directory containing the ontology.config.ts (for resolving resolver paths) */
|
|
18
|
-
configDir: string;
|
|
19
15
|
/** Environment to use (e.g., 'dev', 'prod') */
|
|
20
16
|
env: string;
|
|
21
17
|
/** Enable CORS (default: true) */
|
|
@@ -26,7 +22,7 @@ export interface ApiServerOptions {
|
|
|
26
22
|
* Create the Hono API app from an OntologyConfig
|
|
27
23
|
*/
|
|
28
24
|
export function createApiApp(options: ApiServerOptions): Hono<{ Variables: OntologyVariables }> {
|
|
29
|
-
const { config,
|
|
25
|
+
const { config, env, cors: enableCors = true } = options;
|
|
30
26
|
|
|
31
27
|
// Get environment config
|
|
32
28
|
const envConfig = config.environments[env];
|
|
@@ -36,15 +32,6 @@ export function createApiApp(options: ApiServerOptions): Hono<{ Variables: Ontol
|
|
|
36
32
|
);
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
// Check for missing resolvers
|
|
40
|
-
const missingResolvers = findMissingResolvers(config, configDir);
|
|
41
|
-
if (missingResolvers.length > 0) {
|
|
42
|
-
consola.warn(`Missing resolvers (${missingResolvers.length}):`);
|
|
43
|
-
for (const resolver of missingResolvers) {
|
|
44
|
-
consola.warn(` - ${resolver}`);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
35
|
const app = new Hono<{ Variables: OntologyVariables }>();
|
|
49
36
|
|
|
50
37
|
// Global middleware
|
|
@@ -83,7 +70,7 @@ export function createApiApp(options: ApiServerOptions): Hono<{ Variables: Ontol
|
|
|
83
70
|
});
|
|
84
71
|
|
|
85
72
|
// Mount function routes under /api
|
|
86
|
-
const apiRoutes = createApiRoutes(config
|
|
73
|
+
const apiRoutes = createApiRoutes(config);
|
|
87
74
|
app.route("/api", apiRoutes);
|
|
88
75
|
|
|
89
76
|
return app;
|
package/src/server/api/router.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Hono } from "hono";
|
|
2
2
|
import type { OntologyConfig, FunctionDefinition } from "../../config/types.js";
|
|
3
|
-
import { loadResolver } from "../resolver.js";
|
|
4
3
|
import { getUserContextFields } from "../../config/categorical.js";
|
|
5
4
|
import {
|
|
6
5
|
createAccessControlMiddleware,
|
|
@@ -11,8 +10,7 @@ import {
|
|
|
11
10
|
* Create API routes from function definitions
|
|
12
11
|
*/
|
|
13
12
|
export function createApiRoutes(
|
|
14
|
-
config: OntologyConfig
|
|
15
|
-
configDir: string
|
|
13
|
+
config: OntologyConfig
|
|
16
14
|
): Hono<{ Variables: OntologyVariables }> {
|
|
17
15
|
const router = new Hono<{ Variables: OntologyVariables }>();
|
|
18
16
|
|
|
@@ -83,10 +81,9 @@ export function createApiRoutes(
|
|
|
83
81
|
args = parsed.data;
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
//
|
|
84
|
+
// Execute resolver
|
|
87
85
|
try {
|
|
88
|
-
const
|
|
89
|
-
const result = await resolver(resolverContext, args);
|
|
86
|
+
const result = await fn.resolver(resolverContext, args);
|
|
90
87
|
return c.json(result);
|
|
91
88
|
} catch (error) {
|
|
92
89
|
console.error(`Error in resolver ${name}:`, error);
|
package/src/server/mcp/index.ts
CHANGED
|
@@ -39,8 +39,6 @@ function getAuthResult(authInfo?: AuthInfo): AuthResult {
|
|
|
39
39
|
export interface McpServerOptions {
|
|
40
40
|
/** The ontology configuration */
|
|
41
41
|
config: OntologyConfig;
|
|
42
|
-
/** Directory containing the ontology.config.ts */
|
|
43
|
-
configDir: string;
|
|
44
42
|
/** Environment to use */
|
|
45
43
|
env: string;
|
|
46
44
|
/** Port for the MCP HTTP server */
|
|
@@ -51,7 +49,7 @@ export interface McpServerOptions {
|
|
|
51
49
|
* Create the MCP server instance with per-request authentication
|
|
52
50
|
*/
|
|
53
51
|
export function createMcpServer(options: McpServerOptions): Server {
|
|
54
|
-
const { config,
|
|
52
|
+
const { config, env } = options;
|
|
55
53
|
|
|
56
54
|
// Get environment config
|
|
57
55
|
const envConfig = config.environments[env];
|
|
@@ -67,7 +65,7 @@ export function createMcpServer(options: McpServerOptions): Server {
|
|
|
67
65
|
const allTools = generateMcpTools(config);
|
|
68
66
|
|
|
69
67
|
// Create tool executor factory that accepts per-request access groups
|
|
70
|
-
const executeToolWithAccess = createToolExecutor(config,
|
|
68
|
+
const executeToolWithAccess = createToolExecutor(config, env, envConfig, logger);
|
|
71
69
|
|
|
72
70
|
// Create MCP server
|
|
73
71
|
const server = new Server(
|
package/src/server/mcp/tools.ts
CHANGED
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
AuthResult,
|
|
9
9
|
} from "../../config/types.js";
|
|
10
10
|
import { getFieldFromMetadata, getUserContextFields, hasUserContextMetadata } from "../../config/categorical.js";
|
|
11
|
-
import {
|
|
11
|
+
import type { Logger } from "../resolver.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Field reference info for MCP tools
|
|
@@ -198,7 +198,6 @@ export function filterToolsByAccess(
|
|
|
198
198
|
*/
|
|
199
199
|
export function createToolExecutor(
|
|
200
200
|
config: OntologyConfig,
|
|
201
|
-
configDir: string,
|
|
202
201
|
env: string,
|
|
203
202
|
envConfig: EnvironmentConfig,
|
|
204
203
|
logger: Logger
|
|
@@ -253,8 +252,7 @@ export function createToolExecutor(
|
|
|
253
252
|
accessGroups: authResult.groups,
|
|
254
253
|
};
|
|
255
254
|
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
return resolver(resolverContext, parsed.data);
|
|
255
|
+
// Execute resolver
|
|
256
|
+
return fn.resolver(resolverContext, parsed.data);
|
|
259
257
|
};
|
|
260
258
|
}
|
package/src/server/resolver.ts
CHANGED
|
@@ -1,84 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import type { ResolverFunction, ResolverContext, OntologyConfig } from "../config/types.js";
|
|
1
|
+
import type { ResolverFunction } from "../config/types.js";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
4
|
+
* Get a resolver function. Since resolvers are now passed directly as functions,
|
|
5
|
+
* this is a simple passthrough that could be removed in the future.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Load a resolver from a file path.
|
|
12
|
-
* The path is relative to the config file location.
|
|
13
|
-
*
|
|
14
|
-
* @param resolverPath - Path to the resolver file (relative to configDir)
|
|
15
|
-
* @param configDir - Directory containing the ontology.config.ts
|
|
16
|
-
*/
|
|
17
|
-
export async function loadResolver(
|
|
18
|
-
resolverPath: string,
|
|
19
|
-
configDir: string
|
|
20
|
-
): Promise<ResolverFunction> {
|
|
21
|
-
// Resolve the full path
|
|
22
|
-
const fullPath = isAbsolute(resolverPath)
|
|
23
|
-
? resolverPath
|
|
24
|
-
: join(configDir, resolverPath);
|
|
25
|
-
|
|
26
|
-
// Check cache
|
|
27
|
-
if (resolverCache.has(fullPath)) {
|
|
28
|
-
return resolverCache.get(fullPath)!;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
// Dynamic import the resolver
|
|
33
|
-
const module = await import(fullPath);
|
|
34
|
-
|
|
35
|
-
// Expect default export to be the resolver function
|
|
36
|
-
const resolver = module.default;
|
|
37
|
-
|
|
38
|
-
if (typeof resolver !== "function") {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Resolver at ${resolverPath} must export a default function`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Cache and return
|
|
45
|
-
resolverCache.set(fullPath, resolver);
|
|
46
|
-
return resolver;
|
|
47
|
-
} catch (error) {
|
|
48
|
-
if ((error as NodeJS.ErrnoException).code === "ERR_MODULE_NOT_FOUND") {
|
|
49
|
-
throw new Error(`Resolver not found: ${resolverPath}`);
|
|
50
|
-
}
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Clear the resolver cache (useful for hot reloading)
|
|
57
|
-
*/
|
|
58
|
-
export function clearResolverCache(): void {
|
|
59
|
-
resolverCache.clear();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Check which resolvers are missing and return their paths
|
|
64
|
-
*/
|
|
65
|
-
export function findMissingResolvers(
|
|
66
|
-
config: OntologyConfig,
|
|
67
|
-
configDir: string
|
|
68
|
-
): string[] {
|
|
69
|
-
const missing: string[] = [];
|
|
70
|
-
|
|
71
|
-
for (const [name, fn] of Object.entries(config.functions)) {
|
|
72
|
-
const fullPath = isAbsolute(fn.resolver)
|
|
73
|
-
? fn.resolver
|
|
74
|
-
: join(configDir, fn.resolver);
|
|
75
|
-
|
|
76
|
-
if (!existsSync(fullPath)) {
|
|
77
|
-
missing.push(fn.resolver);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return missing;
|
|
7
|
+
export function loadResolver(resolver: ResolverFunction): ResolverFunction {
|
|
8
|
+
return resolver;
|
|
82
9
|
}
|
|
83
10
|
|
|
84
11
|
/**
|
package/src/server/start.ts
CHANGED
|
@@ -121,7 +121,6 @@ export async function startOnt(options: StartOntOptions = {}): Promise<StartOntR
|
|
|
121
121
|
if (!mcpOnly) {
|
|
122
122
|
const api = createApiApp({
|
|
123
123
|
config,
|
|
124
|
-
configDir,
|
|
125
124
|
env,
|
|
126
125
|
});
|
|
127
126
|
|
|
@@ -144,7 +143,6 @@ export async function startOnt(options: StartOntOptions = {}): Promise<StartOntR
|
|
|
144
143
|
if (!apiOnly) {
|
|
145
144
|
const mcpServer = await startMcpServer({
|
|
146
145
|
config,
|
|
147
|
-
configDir,
|
|
148
146
|
env,
|
|
149
147
|
port: mcpPort,
|
|
150
148
|
});
|