ont-run 0.0.3 → 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 +77 -6
- package/dist/bin/ont.js +303 -10
- package/dist/index.js +21 -56
- package/dist/src/browser/server.d.ts +2 -0
- package/dist/src/browser/transform.d.ts +1 -1
- package/dist/src/config/categorical.d.ts +3 -0
- 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 +234 -2
- package/src/browser/transform.ts +6 -2
- package/src/cli/commands/review.ts +2 -1
- package/src/cli/index.ts +2 -1
- package/src/config/categorical.ts +7 -2
- 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/dist/index.js
CHANGED
|
@@ -4017,8 +4017,9 @@ function hasUserContextMetadata(schema) {
|
|
|
4017
4017
|
}
|
|
4018
4018
|
function getUserContextFields(schema) {
|
|
4019
4019
|
const fields = [];
|
|
4020
|
-
|
|
4021
|
-
|
|
4020
|
+
const def = schema._def;
|
|
4021
|
+
if (def?.typeName === "ZodObject" && typeof def.shape === "function") {
|
|
4022
|
+
const shape = def.shape();
|
|
4022
4023
|
for (const [key, value] of Object.entries(shape)) {
|
|
4023
4024
|
if (hasUserContextMetadata(value)) {
|
|
4024
4025
|
fields.push(key);
|
|
@@ -13488,7 +13489,7 @@ var FunctionDefinitionSchema = exports_external.object({
|
|
|
13488
13489
|
outputs: exports_external.custom(isZodSchema, {
|
|
13489
13490
|
message: "outputs must be a Zod schema"
|
|
13490
13491
|
}).optional(),
|
|
13491
|
-
resolver: exports_external.
|
|
13492
|
+
resolver: exports_external.function()
|
|
13492
13493
|
});
|
|
13493
13494
|
var AuthFunctionSchema = exports_external.function().args(exports_external.custom()).returns(exports_external.union([exports_external.array(exports_external.string()), exports_external.promise(exports_external.array(exports_external.string()))]));
|
|
13494
13495
|
var OntologyConfigSchema = exports_external.object({
|
|
@@ -13605,6 +13606,13 @@ function defineOntology(config) {
|
|
|
13605
13606
|
validateFieldFromReferences(parsed);
|
|
13606
13607
|
return config;
|
|
13607
13608
|
}
|
|
13609
|
+
function defineFunction(config) {
|
|
13610
|
+
return {
|
|
13611
|
+
...config,
|
|
13612
|
+
access: [...config.access],
|
|
13613
|
+
entities: [...config.entities]
|
|
13614
|
+
};
|
|
13615
|
+
}
|
|
13608
13616
|
|
|
13609
13617
|
// src/index.ts
|
|
13610
13618
|
init_categorical();
|
|
@@ -16300,39 +16308,6 @@ var Factory = class {
|
|
|
16300
16308
|
var createMiddleware = (middleware) => middleware;
|
|
16301
16309
|
|
|
16302
16310
|
// src/server/resolver.ts
|
|
16303
|
-
import { join as join3, isAbsolute } from "path";
|
|
16304
|
-
import { existsSync as existsSync3 } from "fs";
|
|
16305
|
-
var resolverCache = new Map;
|
|
16306
|
-
async function loadResolver(resolverPath, configDir) {
|
|
16307
|
-
const fullPath = isAbsolute(resolverPath) ? resolverPath : join3(configDir, resolverPath);
|
|
16308
|
-
if (resolverCache.has(fullPath)) {
|
|
16309
|
-
return resolverCache.get(fullPath);
|
|
16310
|
-
}
|
|
16311
|
-
try {
|
|
16312
|
-
const module = await import(fullPath);
|
|
16313
|
-
const resolver = module.default;
|
|
16314
|
-
if (typeof resolver !== "function") {
|
|
16315
|
-
throw new Error(`Resolver at ${resolverPath} must export a default function`);
|
|
16316
|
-
}
|
|
16317
|
-
resolverCache.set(fullPath, resolver);
|
|
16318
|
-
return resolver;
|
|
16319
|
-
} catch (error) {
|
|
16320
|
-
if (error.code === "ERR_MODULE_NOT_FOUND") {
|
|
16321
|
-
throw new Error(`Resolver not found: ${resolverPath}`);
|
|
16322
|
-
}
|
|
16323
|
-
throw error;
|
|
16324
|
-
}
|
|
16325
|
-
}
|
|
16326
|
-
function findMissingResolvers(config, configDir) {
|
|
16327
|
-
const missing = [];
|
|
16328
|
-
for (const [name, fn] of Object.entries(config.functions)) {
|
|
16329
|
-
const fullPath = isAbsolute(fn.resolver) ? fn.resolver : join3(configDir, fn.resolver);
|
|
16330
|
-
if (!existsSync3(fullPath)) {
|
|
16331
|
-
missing.push(fn.resolver);
|
|
16332
|
-
}
|
|
16333
|
-
}
|
|
16334
|
-
return missing;
|
|
16335
|
-
}
|
|
16336
16311
|
function createLogger(debug = false) {
|
|
16337
16312
|
return {
|
|
16338
16313
|
info: (message, ...args) => {
|
|
@@ -16421,7 +16396,7 @@ function errorHandler2() {
|
|
|
16421
16396
|
|
|
16422
16397
|
// src/server/api/router.ts
|
|
16423
16398
|
init_categorical();
|
|
16424
|
-
function createApiRoutes(config
|
|
16399
|
+
function createApiRoutes(config) {
|
|
16425
16400
|
const router = new Hono2;
|
|
16426
16401
|
for (const [name, fn] of Object.entries(config.functions)) {
|
|
16427
16402
|
const path = `/${name}`;
|
|
@@ -16464,8 +16439,7 @@ function createApiRoutes(config, configDir) {
|
|
|
16464
16439
|
args = parsed.data;
|
|
16465
16440
|
}
|
|
16466
16441
|
try {
|
|
16467
|
-
const
|
|
16468
|
-
const result = await resolver(resolverContext, args);
|
|
16442
|
+
const result = await fn.resolver(resolverContext, args);
|
|
16469
16443
|
return c3.json(result);
|
|
16470
16444
|
} catch (error) {
|
|
16471
16445
|
console.error(`Error in resolver ${name}:`, error);
|
|
@@ -16489,18 +16463,11 @@ function getFunctionsInfo(config) {
|
|
|
16489
16463
|
|
|
16490
16464
|
// src/server/api/index.ts
|
|
16491
16465
|
function createApiApp(options) {
|
|
16492
|
-
const { config,
|
|
16466
|
+
const { config, env: env2, cors: enableCors = true } = options;
|
|
16493
16467
|
const envConfig = config.environments[env2];
|
|
16494
16468
|
if (!envConfig) {
|
|
16495
16469
|
throw new Error(`Unknown environment "${env2}". Available: ${Object.keys(config.environments).join(", ")}`);
|
|
16496
16470
|
}
|
|
16497
|
-
const missingResolvers = findMissingResolvers(config, configDir);
|
|
16498
|
-
if (missingResolvers.length > 0) {
|
|
16499
|
-
consola.warn(`Missing resolvers (${missingResolvers.length}):`);
|
|
16500
|
-
for (const resolver of missingResolvers) {
|
|
16501
|
-
consola.warn(` - ${resolver}`);
|
|
16502
|
-
}
|
|
16503
|
-
}
|
|
16504
16471
|
const app = new Hono2;
|
|
16505
16472
|
if (enableCors) {
|
|
16506
16473
|
app.use("*", cors());
|
|
@@ -16526,7 +16493,7 @@ function createApiApp(options) {
|
|
|
16526
16493
|
functions: accessibleFunctions
|
|
16527
16494
|
});
|
|
16528
16495
|
});
|
|
16529
|
-
const apiRoutes = createApiRoutes(config
|
|
16496
|
+
const apiRoutes = createApiRoutes(config);
|
|
16530
16497
|
app.route("/api", apiRoutes);
|
|
16531
16498
|
return app;
|
|
16532
16499
|
}
|
|
@@ -23016,7 +22983,7 @@ function generateMcpTools(config2) {
|
|
|
23016
22983
|
function filterToolsByAccess(tools, accessGroups) {
|
|
23017
22984
|
return tools.filter((tool) => tool.access.some((group) => accessGroups.includes(group)));
|
|
23018
22985
|
}
|
|
23019
|
-
function createToolExecutor(config2,
|
|
22986
|
+
function createToolExecutor(config2, env2, envConfig, logger) {
|
|
23020
22987
|
const userContextFieldsCache = new Map;
|
|
23021
22988
|
for (const [name, fn] of Object.entries(config2.functions)) {
|
|
23022
22989
|
userContextFieldsCache.set(name, getUserContextFields(fn.inputs));
|
|
@@ -23048,8 +23015,7 @@ function createToolExecutor(config2, configDir, env2, envConfig, logger) {
|
|
|
23048
23015
|
logger,
|
|
23049
23016
|
accessGroups: authResult.groups
|
|
23050
23017
|
};
|
|
23051
|
-
|
|
23052
|
-
return resolver(resolverContext, parsed.data);
|
|
23018
|
+
return fn.resolver(resolverContext, parsed.data);
|
|
23053
23019
|
};
|
|
23054
23020
|
}
|
|
23055
23021
|
|
|
@@ -23102,14 +23068,14 @@ function getAuthResult(authInfo) {
|
|
|
23102
23068
|
return authInfo.extra.authResult;
|
|
23103
23069
|
}
|
|
23104
23070
|
function createMcpServer(options) {
|
|
23105
|
-
const { config: config2,
|
|
23071
|
+
const { config: config2, env: env2 } = options;
|
|
23106
23072
|
const envConfig = config2.environments[env2];
|
|
23107
23073
|
if (!envConfig) {
|
|
23108
23074
|
throw new Error(`Unknown environment "${env2}". Available: ${Object.keys(config2.environments).join(", ")}`);
|
|
23109
23075
|
}
|
|
23110
23076
|
const logger = createLogger(envConfig.debug);
|
|
23111
23077
|
const allTools = generateMcpTools(config2);
|
|
23112
|
-
const executeToolWithAccess = createToolExecutor(config2,
|
|
23078
|
+
const executeToolWithAccess = createToolExecutor(config2, env2, envConfig, logger);
|
|
23113
23079
|
const server = new Server({
|
|
23114
23080
|
name: config2.name,
|
|
23115
23081
|
version: "1.0.0"
|
|
@@ -23266,7 +23232,6 @@ Run \`bun run review\` to approve the changes.`;
|
|
|
23266
23232
|
if (!mcpOnly) {
|
|
23267
23233
|
const api2 = createApiApp({
|
|
23268
23234
|
config: config2,
|
|
23269
|
-
configDir,
|
|
23270
23235
|
env: env2
|
|
23271
23236
|
});
|
|
23272
23237
|
const server = await serve2(api2, port);
|
|
@@ -23285,7 +23250,6 @@ Run \`bun run review\` to approve the changes.`;
|
|
|
23285
23250
|
if (!apiOnly) {
|
|
23286
23251
|
const mcpServer = await startMcpServer({
|
|
23287
23252
|
config: config2,
|
|
23288
|
-
configDir,
|
|
23289
23253
|
env: env2,
|
|
23290
23254
|
port: mcpPort
|
|
23291
23255
|
});
|
|
@@ -23304,5 +23268,6 @@ export {
|
|
|
23304
23268
|
userContext,
|
|
23305
23269
|
startOnt,
|
|
23306
23270
|
fieldFrom,
|
|
23307
|
-
defineOntology
|
|
23271
|
+
defineOntology,
|
|
23272
|
+
defineFunction
|
|
23308
23273
|
};
|
|
@@ -11,7 +11,6 @@ export interface GraphNode {
|
|
|
11
11
|
metadata: {
|
|
12
12
|
inputs?: Record<string, unknown>;
|
|
13
13
|
outputs?: Record<string, unknown>;
|
|
14
|
-
resolver?: string;
|
|
15
14
|
functionCount?: number;
|
|
16
15
|
usesUserContext?: boolean;
|
|
17
16
|
};
|
|
@@ -31,6 +30,7 @@ export interface GraphData {
|
|
|
31
30
|
totalFunctions: number;
|
|
32
31
|
totalEntities: number;
|
|
33
32
|
totalAccessGroups: number;
|
|
33
|
+
totalUserContextFunctions: number;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
export interface EnhancedGraphNode extends GraphNode {
|
|
@@ -131,5 +131,8 @@ export declare function userContext<T extends z.ZodType>(schema: T): UserContext
|
|
|
131
131
|
export declare function hasUserContextMetadata(schema: unknown): schema is UserContextSchema<z.ZodType>;
|
|
132
132
|
/**
|
|
133
133
|
* Get all userContext field names from a Zod object schema
|
|
134
|
+
*
|
|
135
|
+
* Note: Uses _def.typeName check instead of instanceof to work across
|
|
136
|
+
* module boundaries in bundled CLI.
|
|
134
137
|
*/
|
|
135
138
|
export declare function getUserContextFields(schema: z.ZodType): string[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { OntologyConfig, FunctionDefinition, AccessGroupConfig, EnvironmentConfig, EntityDefinition, AuthFunction, ResolverFunction } from "./types.js";
|
|
2
3
|
/**
|
|
3
4
|
* Define an Ontology configuration with full type inference.
|
|
4
5
|
*
|
|
@@ -6,6 +7,7 @@ import type { OntologyConfig, FunctionDefinition, AccessGroupConfig, Environment
|
|
|
6
7
|
* ```ts
|
|
7
8
|
* import { defineOntology, fieldFrom } from 'ont-run';
|
|
8
9
|
* import { z } from 'zod';
|
|
10
|
+
* import { getUser } from './resolvers/getUser.js';
|
|
9
11
|
*
|
|
10
12
|
* export default defineOntology({
|
|
11
13
|
* name: 'my-api',
|
|
@@ -30,7 +32,7 @@ import type { OntologyConfig, FunctionDefinition, AccessGroupConfig, Environment
|
|
|
30
32
|
* access: ['public', 'admin'],
|
|
31
33
|
* entities: ['User'],
|
|
32
34
|
* inputs: z.object({ id: z.string() }),
|
|
33
|
-
* resolver:
|
|
35
|
+
* resolver: getUser, // Direct function reference for type safety
|
|
34
36
|
* },
|
|
35
37
|
* },
|
|
36
38
|
* });
|
|
@@ -44,3 +46,36 @@ export declare function defineOntology<TGroups extends string, TEntities extends
|
|
|
44
46
|
entities?: Record<TEntities, EntityDefinition>;
|
|
45
47
|
functions: TFunctions;
|
|
46
48
|
}): OntologyConfig<TGroups, TEntities, TFunctions>;
|
|
49
|
+
/**
|
|
50
|
+
* Define a function with full type inference for resolver type safety.
|
|
51
|
+
*
|
|
52
|
+
* This helper ensures that the resolver function's return type matches
|
|
53
|
+
* the outputs Zod schema at compile time.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { defineFunction, z } from 'ont-run';
|
|
58
|
+
* import type { ResolverContext } from 'ont-run';
|
|
59
|
+
*
|
|
60
|
+
* const getUser = defineFunction({
|
|
61
|
+
* description: 'Get a user by ID',
|
|
62
|
+
* access: ['public', 'admin'] as const,
|
|
63
|
+
* entities: ['User'] as const,
|
|
64
|
+
* inputs: z.object({ id: z.string() }),
|
|
65
|
+
* outputs: z.object({ id: z.string(), name: z.string() }),
|
|
66
|
+
* resolver: async (ctx, args) => {
|
|
67
|
+
* // TypeScript knows args is { id: string }
|
|
68
|
+
* // TypeScript enforces return type is { id: string, name: string }
|
|
69
|
+
* return { id: args.id, name: 'Example User' };
|
|
70
|
+
* },
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function defineFunction<TGroups extends string, TEntities extends string, TInputs extends z.ZodType, TOutputs extends z.ZodType>(config: {
|
|
75
|
+
description: string;
|
|
76
|
+
access: readonly TGroups[];
|
|
77
|
+
entities: readonly TEntities[];
|
|
78
|
+
inputs: TInputs;
|
|
79
|
+
outputs?: TOutputs;
|
|
80
|
+
resolver: ResolverFunction<z.infer<TInputs>, z.infer<TOutputs>>;
|
|
81
|
+
}): FunctionDefinition<TGroups, TEntities, TInputs, TOutputs>;
|
|
@@ -39,20 +39,20 @@ export declare const FunctionDefinitionSchema: z.ZodObject<{
|
|
|
39
39
|
entities: z.ZodArray<z.ZodString, "many">;
|
|
40
40
|
inputs: z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>;
|
|
41
41
|
outputs: z.ZodOptional<z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>>;
|
|
42
|
-
resolver: z.
|
|
42
|
+
resolver: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
|
|
43
43
|
}, "strip", z.ZodTypeAny, {
|
|
44
44
|
description: string;
|
|
45
45
|
access: string[];
|
|
46
46
|
entities: string[];
|
|
47
47
|
inputs: z.ZodType<any, z.ZodTypeDef, any>;
|
|
48
|
-
resolver:
|
|
48
|
+
resolver: (...args: unknown[]) => unknown;
|
|
49
49
|
outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
|
|
50
50
|
}, {
|
|
51
51
|
description: string;
|
|
52
52
|
access: string[];
|
|
53
53
|
entities: string[];
|
|
54
54
|
inputs: z.ZodType<any, z.ZodTypeDef, any>;
|
|
55
|
-
resolver:
|
|
55
|
+
resolver: (...args: unknown[]) => unknown;
|
|
56
56
|
outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
|
|
57
57
|
}>;
|
|
58
58
|
/**
|
|
@@ -92,20 +92,20 @@ export declare const OntologyConfigSchema: z.ZodObject<{
|
|
|
92
92
|
entities: z.ZodArray<z.ZodString, "many">;
|
|
93
93
|
inputs: z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>;
|
|
94
94
|
outputs: z.ZodOptional<z.ZodType<z.ZodType<any, z.ZodTypeDef, any>, z.ZodTypeDef, z.ZodType<any, z.ZodTypeDef, any>>>;
|
|
95
|
-
resolver: z.
|
|
95
|
+
resolver: z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>;
|
|
96
96
|
}, "strip", z.ZodTypeAny, {
|
|
97
97
|
description: string;
|
|
98
98
|
access: string[];
|
|
99
99
|
entities: string[];
|
|
100
100
|
inputs: z.ZodType<any, z.ZodTypeDef, any>;
|
|
101
|
-
resolver:
|
|
101
|
+
resolver: (...args: unknown[]) => unknown;
|
|
102
102
|
outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
|
|
103
103
|
}, {
|
|
104
104
|
description: string;
|
|
105
105
|
access: string[];
|
|
106
106
|
entities: string[];
|
|
107
107
|
inputs: z.ZodType<any, z.ZodTypeDef, any>;
|
|
108
|
-
resolver:
|
|
108
|
+
resolver: (...args: unknown[]) => unknown;
|
|
109
109
|
outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
|
|
110
110
|
}>>;
|
|
111
111
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -122,7 +122,7 @@ export declare const OntologyConfigSchema: z.ZodObject<{
|
|
|
122
122
|
access: string[];
|
|
123
123
|
entities: string[];
|
|
124
124
|
inputs: z.ZodType<any, z.ZodTypeDef, any>;
|
|
125
|
-
resolver:
|
|
125
|
+
resolver: (...args: unknown[]) => unknown;
|
|
126
126
|
outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
|
|
127
127
|
}>;
|
|
128
128
|
entities?: Record<string, {
|
|
@@ -142,7 +142,7 @@ export declare const OntologyConfigSchema: z.ZodObject<{
|
|
|
142
142
|
access: string[];
|
|
143
143
|
entities: string[];
|
|
144
144
|
inputs: z.ZodType<any, z.ZodTypeDef, any>;
|
|
145
|
-
resolver:
|
|
145
|
+
resolver: (...args: unknown[]) => unknown;
|
|
146
146
|
outputs?: z.ZodType<any, z.ZodTypeDef, any> | undefined;
|
|
147
147
|
}>;
|
|
148
148
|
entities?: Record<string, {
|
|
@@ -32,10 +32,32 @@ export interface FieldOption {
|
|
|
32
32
|
/** Human-readable label for display */
|
|
33
33
|
label: string;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Context passed to resolvers
|
|
37
|
+
*/
|
|
38
|
+
export interface ResolverContext {
|
|
39
|
+
/** Current environment name */
|
|
40
|
+
env: string;
|
|
41
|
+
/** Environment configuration */
|
|
42
|
+
envConfig: EnvironmentConfig;
|
|
43
|
+
/** Logger instance */
|
|
44
|
+
logger: {
|
|
45
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
46
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
47
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
48
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
49
|
+
};
|
|
50
|
+
/** Access groups for the current request */
|
|
51
|
+
accessGroups: string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolver function signature
|
|
55
|
+
*/
|
|
56
|
+
export type ResolverFunction<TArgs = unknown, TResult = unknown> = (ctx: ResolverContext, args: TArgs) => Promise<TResult> | TResult;
|
|
35
57
|
/**
|
|
36
58
|
* Definition of a function in the ontology
|
|
37
59
|
*/
|
|
38
|
-
export interface FunctionDefinition<TGroups extends string = string, TEntities extends string = string
|
|
60
|
+
export interface FunctionDefinition<TGroups extends string = string, TEntities extends string = string, TInputs extends z.ZodType = z.ZodType<unknown>, TOutputs extends z.ZodType = z.ZodType<unknown>> {
|
|
39
61
|
/** Human-readable description of what this function does */
|
|
40
62
|
description: string;
|
|
41
63
|
/** Which access groups can call this function */
|
|
@@ -43,11 +65,11 @@ export interface FunctionDefinition<TGroups extends string = string, TEntities e
|
|
|
43
65
|
/** Which entities this function relates to (use empty array [] if none) */
|
|
44
66
|
entities: TEntities[];
|
|
45
67
|
/** Zod schema for input validation */
|
|
46
|
-
inputs:
|
|
68
|
+
inputs: TInputs;
|
|
47
69
|
/** Zod schema for output validation/documentation */
|
|
48
|
-
outputs?:
|
|
49
|
-
/**
|
|
50
|
-
resolver:
|
|
70
|
+
outputs?: TOutputs;
|
|
71
|
+
/** Resolver function that handles this function's logic */
|
|
72
|
+
resolver: ResolverFunction<z.infer<TInputs>, z.infer<TOutputs>>;
|
|
51
73
|
}
|
|
52
74
|
/**
|
|
53
75
|
* Result returned by the auth function
|
|
@@ -82,25 +104,3 @@ export interface OntologyConfig<TGroups extends string = string, TEntities exten
|
|
|
82
104
|
/** Function definitions */
|
|
83
105
|
functions: TFunctions;
|
|
84
106
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Context passed to resolvers
|
|
87
|
-
*/
|
|
88
|
-
export interface ResolverContext {
|
|
89
|
-
/** Current environment name */
|
|
90
|
-
env: string;
|
|
91
|
-
/** Environment configuration */
|
|
92
|
-
envConfig: EnvironmentConfig;
|
|
93
|
-
/** Logger instance */
|
|
94
|
-
logger: {
|
|
95
|
-
info: (message: string, ...args: unknown[]) => void;
|
|
96
|
-
warn: (message: string, ...args: unknown[]) => void;
|
|
97
|
-
error: (message: string, ...args: unknown[]) => void;
|
|
98
|
-
debug: (message: string, ...args: unknown[]) => void;
|
|
99
|
-
};
|
|
100
|
-
/** Access groups for the current request */
|
|
101
|
-
accessGroups: string[];
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Resolver function signature
|
|
105
|
-
*/
|
|
106
|
-
export type ResolverFunction<TArgs = unknown, TResult = unknown> = (ctx: ResolverContext, args: TArgs) => Promise<TResult> | TResult;
|
package/dist/src/index.d.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,13 +24,13 @@
|
|
|
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
|
* });
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
|
-
export { defineOntology } from "./config/define.js";
|
|
33
|
+
export { defineOntology, defineFunction } from "./config/define.js";
|
|
33
34
|
export { fieldFrom, userContext } from "./config/categorical.js";
|
|
34
35
|
export { startOnt } from "./server/start.js";
|
|
35
36
|
export type { StartOntOptions, StartOntResult } from "./server/start.js";
|
|
@@ -4,8 +4,6 @@ import { type OntologyVariables } from "./middleware.js";
|
|
|
4
4
|
export interface ApiServerOptions {
|
|
5
5
|
/** The ontology configuration */
|
|
6
6
|
config: OntologyConfig;
|
|
7
|
-
/** Directory containing the ontology.config.ts (for resolving resolver paths) */
|
|
8
|
-
configDir: string;
|
|
9
7
|
/** Environment to use (e.g., 'dev', 'prod') */
|
|
10
8
|
env: string;
|
|
11
9
|
/** Enable CORS (default: true) */
|
|
@@ -4,7 +4,7 @@ import { type OntologyVariables } from "./middleware.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Create API routes from function definitions
|
|
6
6
|
*/
|
|
7
|
-
export declare function createApiRoutes(config: OntologyConfig
|
|
7
|
+
export declare function createApiRoutes(config: OntologyConfig): Hono<{
|
|
8
8
|
Variables: OntologyVariables;
|
|
9
9
|
}>;
|
|
10
10
|
/**
|
|
@@ -3,8 +3,6 @@ import type { OntologyConfig } from "../../config/types.js";
|
|
|
3
3
|
export interface McpServerOptions {
|
|
4
4
|
/** The ontology configuration */
|
|
5
5
|
config: OntologyConfig;
|
|
6
|
-
/** Directory containing the ontology.config.ts */
|
|
7
|
-
configDir: string;
|
|
8
6
|
/** Environment to use */
|
|
9
7
|
env: string;
|
|
10
8
|
/** Port for the MCP HTTP server */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OntologyConfig, EnvironmentConfig, AuthResult } from "../../config/types.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { Logger } from "../resolver.js";
|
|
3
3
|
/**
|
|
4
4
|
* Field reference info for MCP tools
|
|
5
5
|
*/
|
|
@@ -32,4 +32,4 @@ export declare function filterToolsByAccess(tools: McpTool[], accessGroups: stri
|
|
|
32
32
|
/**
|
|
33
33
|
* Create a tool executor function that accepts per-request auth result
|
|
34
34
|
*/
|
|
35
|
-
export declare function createToolExecutor(config: OntologyConfig,
|
|
35
|
+
export declare function createToolExecutor(config: OntologyConfig, env: string, envConfig: EnvironmentConfig, logger: Logger): (toolName: string, args: unknown, authResult: AuthResult) => Promise<unknown>;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import type { ResolverFunction
|
|
1
|
+
import type { ResolverFunction } from "../config/types.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* @param resolverPath - Path to the resolver file (relative to configDir)
|
|
7
|
-
* @param configDir - Directory containing the ontology.config.ts
|
|
3
|
+
* Get a resolver function. Since resolvers are now passed directly as functions,
|
|
4
|
+
* this is a simple passthrough that could be removed in the future.
|
|
8
5
|
*/
|
|
9
|
-
export declare function loadResolver(
|
|
10
|
-
/**
|
|
11
|
-
* Clear the resolver cache (useful for hot reloading)
|
|
12
|
-
*/
|
|
13
|
-
export declare function clearResolverCache(): void;
|
|
14
|
-
/**
|
|
15
|
-
* Check which resolvers are missing and return their paths
|
|
16
|
-
*/
|
|
17
|
-
export declare function findMissingResolvers(config: OntologyConfig, configDir: string): string[];
|
|
6
|
+
export declare function loadResolver(resolver: ResolverFunction): ResolverFunction;
|
|
18
7
|
/**
|
|
19
8
|
* Logger type returned by createLogger
|
|
20
9
|
*/
|