@frontal-labs/ontology 0.0.1
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 +32 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +468 -0
- package/dist/index.mjs +434 -0
- package/dist/keys.d.ts +6 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/schemas.d.ts +426 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/service.d.ts +139 -0
- package/dist/service.d.ts.map +1 -0
- package/package.json +80 -0
- package/src/constants.ts +9 -0
- package/src/index.ts +45 -0
- package/src/keys.ts +29 -0
- package/src/schemas.ts +191 -0
- package/src/service.ts +269 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FrontalClient, getDefaultClient, HttpClient } from "@frontal-labs/core";
|
|
2
|
+
import { OntologyService } from "./service";
|
|
3
|
+
|
|
4
|
+
/** Config for standalone usage without @frontal-labs/core */
|
|
5
|
+
export interface OntologyClientConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
timeout?: number;
|
|
9
|
+
maxRetries?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Create from a FrontalClient instance */
|
|
13
|
+
export function createOntologyClient(client: FrontalClient): OntologyService;
|
|
14
|
+
/** Create standalone with just config */
|
|
15
|
+
export function createOntologyClient(
|
|
16
|
+
config: OntologyClientConfig
|
|
17
|
+
): OntologyService;
|
|
18
|
+
export function createOntologyClient(
|
|
19
|
+
clientOrConfig: FrontalClient | OntologyClientConfig
|
|
20
|
+
): OntologyService {
|
|
21
|
+
if (clientOrConfig instanceof FrontalClient) {
|
|
22
|
+
return new OntologyService(clientOrConfig._http);
|
|
23
|
+
}
|
|
24
|
+
const http = new HttpClient({
|
|
25
|
+
apiKey: clientOrConfig.apiKey,
|
|
26
|
+
baseUrl:
|
|
27
|
+
clientOrConfig.baseUrl ??
|
|
28
|
+
process.env.FRONTAL_ONTOLOGY_API_URL ??
|
|
29
|
+
process.env.FRONTAL_API_URL ??
|
|
30
|
+
"https://api.frontal.dev/v1",
|
|
31
|
+
timeout: clientOrConfig.timeout ?? 30000,
|
|
32
|
+
maxRetries: clientOrConfig.maxRetries ?? 3,
|
|
33
|
+
retryDelay: 1000,
|
|
34
|
+
headers: {},
|
|
35
|
+
environment: "production",
|
|
36
|
+
debug: false,
|
|
37
|
+
});
|
|
38
|
+
return new OntologyService(http);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Default instance that works automatically with environment variables
|
|
42
|
+
export const ontology = new OntologyService(getDefaultClient()._http);
|
|
43
|
+
|
|
44
|
+
export * from "./schemas";
|
|
45
|
+
export { OntologyService } from "./service";
|
package/src/keys.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createEnv } from "@t3-oss/env-core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const env = createEnv({
|
|
5
|
+
server: {
|
|
6
|
+
NODE_ENV: z
|
|
7
|
+
.enum(["development", "test", "production"])
|
|
8
|
+
.default("development"),
|
|
9
|
+
FRONTAL_API_URL: z
|
|
10
|
+
.url()
|
|
11
|
+
.optional()
|
|
12
|
+
.refine((val) => !(process.env.NODE_ENV === "production") || !!val, {
|
|
13
|
+
message: "FRONTAL_API_URL is required in production",
|
|
14
|
+
}),
|
|
15
|
+
FRONTAL_API_KEY: z
|
|
16
|
+
.string()
|
|
17
|
+
.min(1)
|
|
18
|
+
.optional()
|
|
19
|
+
.refine((val) => !(process.env.NODE_ENV === "production") || !!val, {
|
|
20
|
+
message: "FRONTAL_API_KEY is required in production",
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
runtimeEnv: {
|
|
24
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
25
|
+
FRONTAL_API_URL: process.env.FRONTAL_API_URL,
|
|
26
|
+
FRONTAL_API_KEY: process.env.FRONTAL_API_KEY,
|
|
27
|
+
},
|
|
28
|
+
emptyStringAsUndefined: true,
|
|
29
|
+
});
|
package/src/schemas.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { timestampSchema } from "@frontal-labs/core";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const FieldTypeSchema = z.enum([
|
|
5
|
+
"string",
|
|
6
|
+
"integer",
|
|
7
|
+
"float",
|
|
8
|
+
"boolean",
|
|
9
|
+
"uuid",
|
|
10
|
+
"timestamp",
|
|
11
|
+
"currency",
|
|
12
|
+
"json",
|
|
13
|
+
"array",
|
|
14
|
+
"enum",
|
|
15
|
+
"vector",
|
|
16
|
+
"text",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
export const RelationshipTypeSchema = z.enum([
|
|
20
|
+
"hasOne",
|
|
21
|
+
"hasMany",
|
|
22
|
+
"belongsTo",
|
|
23
|
+
"manyToMany",
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
export const FieldDefinitionSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
type: FieldTypeSchema,
|
|
29
|
+
required: z.boolean().default(false),
|
|
30
|
+
primary: z.boolean().default(false),
|
|
31
|
+
unique: z.boolean().default(false),
|
|
32
|
+
default: z.unknown().optional(),
|
|
33
|
+
substrate: z.string().optional(),
|
|
34
|
+
computed: z.boolean().optional(),
|
|
35
|
+
derivedBy: z.string().optional(),
|
|
36
|
+
cache: z
|
|
37
|
+
.object({
|
|
38
|
+
ttl: z.string(),
|
|
39
|
+
})
|
|
40
|
+
.optional(),
|
|
41
|
+
auto: z.boolean().optional(),
|
|
42
|
+
enum: z.array(z.string()).optional(),
|
|
43
|
+
dimensions: z.number().int().optional(),
|
|
44
|
+
items: z.string().optional(),
|
|
45
|
+
description: z.string().optional(),
|
|
46
|
+
})
|
|
47
|
+
.passthrough();
|
|
48
|
+
|
|
49
|
+
export const RelationshipDefinitionSchema = z
|
|
50
|
+
.object({
|
|
51
|
+
name: z.string().optional(),
|
|
52
|
+
type: RelationshipTypeSchema,
|
|
53
|
+
targetEntity: z.string(),
|
|
54
|
+
foreignKey: z.string().optional(),
|
|
55
|
+
substrate: z.string().optional(),
|
|
56
|
+
cascade: z
|
|
57
|
+
.object({
|
|
58
|
+
delete: z.enum(["hard", "soft", "restrict", "nullify"]),
|
|
59
|
+
update: z.enum(["cascade", "restrict"]),
|
|
60
|
+
})
|
|
61
|
+
.optional(),
|
|
62
|
+
computed: z.record(z.string(), z.unknown()).optional(),
|
|
63
|
+
description: z.string().optional(),
|
|
64
|
+
})
|
|
65
|
+
.passthrough();
|
|
66
|
+
|
|
67
|
+
export const SubstrateRoutingSchema = z
|
|
68
|
+
.object({
|
|
69
|
+
operational: z.string().optional(),
|
|
70
|
+
analytical: z.string().optional(),
|
|
71
|
+
semantic: z.string().optional(),
|
|
72
|
+
cache: z.string().optional(),
|
|
73
|
+
})
|
|
74
|
+
.passthrough();
|
|
75
|
+
|
|
76
|
+
export const SemanticMetadataSchema = z
|
|
77
|
+
.object({
|
|
78
|
+
description: z.string().optional(),
|
|
79
|
+
lifecycle: z.array(z.string()).optional(),
|
|
80
|
+
criticalFields: z.array(z.string()).optional(),
|
|
81
|
+
significantEvents: z.array(z.string()).optional(),
|
|
82
|
+
tags: z.array(z.string()).optional(),
|
|
83
|
+
})
|
|
84
|
+
.passthrough();
|
|
85
|
+
|
|
86
|
+
export const IndexDefinitionSchema = z
|
|
87
|
+
.object({
|
|
88
|
+
name: z.string().optional(),
|
|
89
|
+
fields: z.array(z.string()).min(1),
|
|
90
|
+
substrate: z.string().optional(),
|
|
91
|
+
unique: z.boolean().default(false),
|
|
92
|
+
type: z.enum(["btree", "hash", "gin", "gist", "brin"]).default("btree"),
|
|
93
|
+
})
|
|
94
|
+
.passthrough();
|
|
95
|
+
|
|
96
|
+
export const ModelDefinitionSchema = z
|
|
97
|
+
.object({
|
|
98
|
+
name: z.string(),
|
|
99
|
+
displayName: z.string().optional(),
|
|
100
|
+
description: z.string().optional(),
|
|
101
|
+
extends: z.string().optional(),
|
|
102
|
+
mixins: z.array(z.string()).optional(),
|
|
103
|
+
fields: z.record(z.string(), FieldDefinitionSchema),
|
|
104
|
+
relationships: z
|
|
105
|
+
.record(z.string(), RelationshipDefinitionSchema)
|
|
106
|
+
.optional(),
|
|
107
|
+
substrates: SubstrateRoutingSchema.optional(),
|
|
108
|
+
semantics: SemanticMetadataSchema.optional(),
|
|
109
|
+
indexes: z.array(IndexDefinitionSchema).optional(),
|
|
110
|
+
status: z.enum(["draft", "active", "deprecated"]).default("draft"),
|
|
111
|
+
})
|
|
112
|
+
.strict();
|
|
113
|
+
|
|
114
|
+
export const ModelSchema = ModelDefinitionSchema.extend({
|
|
115
|
+
id: z.string(),
|
|
116
|
+
version: z.number().int(),
|
|
117
|
+
createdAt: timestampSchema,
|
|
118
|
+
updatedAt: timestampSchema,
|
|
119
|
+
entityCount: z.number().int().optional(),
|
|
120
|
+
}).passthrough();
|
|
121
|
+
|
|
122
|
+
export const MigrationPlanSchema = z
|
|
123
|
+
.object({
|
|
124
|
+
id: z.string(),
|
|
125
|
+
modelId: z.string(),
|
|
126
|
+
fromVersion: z.number().int(),
|
|
127
|
+
toVersion: z.number().int(),
|
|
128
|
+
changes: z.array(
|
|
129
|
+
z.object({
|
|
130
|
+
type: z.enum([
|
|
131
|
+
"add-field",
|
|
132
|
+
"remove-field",
|
|
133
|
+
"modify-field",
|
|
134
|
+
"add-relationship",
|
|
135
|
+
"remove-relationship",
|
|
136
|
+
]),
|
|
137
|
+
description: z.string(),
|
|
138
|
+
impact: z.enum(["breaking", "non-breaking", "data-loss"]),
|
|
139
|
+
sql: z.string().optional(),
|
|
140
|
+
})
|
|
141
|
+
),
|
|
142
|
+
riskLevel: z.enum(["low", "medium", "high", "critical"]),
|
|
143
|
+
estimatedDowntime: z.string().optional(),
|
|
144
|
+
rolloutStrategy: z.enum([
|
|
145
|
+
"zero-downtime",
|
|
146
|
+
"maintenance-window",
|
|
147
|
+
"immediate",
|
|
148
|
+
]),
|
|
149
|
+
createdAt: timestampSchema,
|
|
150
|
+
})
|
|
151
|
+
.passthrough();
|
|
152
|
+
|
|
153
|
+
export const RuleDefinitionSchema = z
|
|
154
|
+
.object({
|
|
155
|
+
name: z.string(),
|
|
156
|
+
description: z.string().optional(),
|
|
157
|
+
entityTypes: z.array(z.string()).min(1),
|
|
158
|
+
condition: z.string(),
|
|
159
|
+
action: z.enum(["validate", "transform", "notify"]),
|
|
160
|
+
severity: z.enum(["error", "warning", "info"]),
|
|
161
|
+
enabled: z.boolean().default(true),
|
|
162
|
+
})
|
|
163
|
+
.strict();
|
|
164
|
+
|
|
165
|
+
export const MixinDefinitionSchema = z
|
|
166
|
+
.object({
|
|
167
|
+
name: z.string(),
|
|
168
|
+
description: z.string().optional(),
|
|
169
|
+
fields: z.record(z.string(), FieldDefinitionSchema),
|
|
170
|
+
relationships: z
|
|
171
|
+
.record(z.string(), RelationshipDefinitionSchema)
|
|
172
|
+
.optional(),
|
|
173
|
+
appliesTo: z.array(z.string()).optional(),
|
|
174
|
+
})
|
|
175
|
+
.strict();
|
|
176
|
+
|
|
177
|
+
// Inferred types
|
|
178
|
+
export type FieldType = z.infer<typeof FieldTypeSchema>;
|
|
179
|
+
export type RelationshipType = z.infer<typeof RelationshipTypeSchema>;
|
|
180
|
+
export type FieldDefinition = z.infer<typeof FieldDefinitionSchema>;
|
|
181
|
+
export type RelationshipDefinition = z.infer<
|
|
182
|
+
typeof RelationshipDefinitionSchema
|
|
183
|
+
>;
|
|
184
|
+
export type SubstrateRouting = z.infer<typeof SubstrateRoutingSchema>;
|
|
185
|
+
export type SemanticMetadata = z.infer<typeof SemanticMetadataSchema>;
|
|
186
|
+
export type IndexDefinition = z.infer<typeof IndexDefinitionSchema>;
|
|
187
|
+
export type ModelDefinition = z.infer<typeof ModelDefinitionSchema>;
|
|
188
|
+
export type Model = z.infer<typeof ModelSchema>;
|
|
189
|
+
export type MigrationPlan = z.infer<typeof MigrationPlanSchema>;
|
|
190
|
+
export type RuleDefinition = z.infer<typeof RuleDefinitionSchema>;
|
|
191
|
+
export type MixinDefinition = z.infer<typeof MixinDefinitionSchema>;
|
package/src/service.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createPageResult,
|
|
3
|
+
type HttpClient,
|
|
4
|
+
type PageResult,
|
|
5
|
+
type PaginationMeta,
|
|
6
|
+
} from "@frontal-labs/core";
|
|
7
|
+
import type { z } from "zod";
|
|
8
|
+
import * as S from "./schemas";
|
|
9
|
+
|
|
10
|
+
const asPagePayload = <T>(
|
|
11
|
+
raw: unknown
|
|
12
|
+
): {
|
|
13
|
+
data: T[];
|
|
14
|
+
pagination: PaginationMeta;
|
|
15
|
+
meta?: unknown;
|
|
16
|
+
} =>
|
|
17
|
+
raw as {
|
|
18
|
+
data: T[];
|
|
19
|
+
pagination: PaginationMeta;
|
|
20
|
+
meta?: unknown;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export class OntologyService {
|
|
24
|
+
constructor(private readonly http: HttpClient) {}
|
|
25
|
+
|
|
26
|
+
use(name: string): ModelAccessor {
|
|
27
|
+
return new ModelAccessor(name, this.http);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async list(
|
|
31
|
+
opts: {
|
|
32
|
+
status?: z.infer<typeof S.ModelSchema>["status"];
|
|
33
|
+
substrate?: string;
|
|
34
|
+
limit?: number;
|
|
35
|
+
cursor?: string;
|
|
36
|
+
} = {}
|
|
37
|
+
): Promise<PageResult<S.Model>> {
|
|
38
|
+
const raw = await this.http.get("/ontology/engine/runs", opts);
|
|
39
|
+
return createPageResult(asPagePayload<S.Model>(raw), (cursor) =>
|
|
40
|
+
this.list({ ...opts, cursor })
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async create(definition: S.ModelDefinition): Promise<S.Model> {
|
|
45
|
+
const body = S.ModelDefinitionSchema.parse(definition);
|
|
46
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async validate(
|
|
50
|
+
definition: S.ModelDefinition
|
|
51
|
+
): Promise<{ valid: boolean; errors?: unknown[]; warnings?: unknown[] }> {
|
|
52
|
+
const body = S.ModelDefinitionSchema.parse(definition);
|
|
53
|
+
return this.http.post("/ontology/engine/ontologies/validate", body);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async checkIntegrity(): Promise<{ valid: boolean; violations?: unknown[] }> {
|
|
57
|
+
return this.http.get("/ontology/engine/health");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
readonly migrations = new MigrationsNamespace(this.http);
|
|
61
|
+
readonly rules = new RulesNamespace(this.http);
|
|
62
|
+
readonly mixins = new MixinsNamespace(this.http);
|
|
63
|
+
readonly generation = new GenerationNamespace(this.http);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class ModelAccessor {
|
|
67
|
+
constructor(
|
|
68
|
+
readonly _name: string,
|
|
69
|
+
private readonly http: HttpClient
|
|
70
|
+
) {}
|
|
71
|
+
|
|
72
|
+
async get(version?: number): Promise<S.Model> {
|
|
73
|
+
const params = version ? { version } : undefined;
|
|
74
|
+
return this.http.get("/ontology/engine/runs", params);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async update(definition: Partial<S.ModelDefinition>): Promise<S.Model> {
|
|
78
|
+
return this.http.post("/ontology/engine/runs", definition);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async delete(force = false): Promise<void> {
|
|
82
|
+
return this.http.post("/ontology/engine/runs", {
|
|
83
|
+
action: "delete-model",
|
|
84
|
+
force,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async relationships(): Promise<{ data: S.RelationshipDefinition[] }> {
|
|
89
|
+
return this.http.get("/ontology/engine/runs");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async addRelationship(
|
|
93
|
+
definition: S.RelationshipDefinition
|
|
94
|
+
): Promise<S.RelationshipDefinition> {
|
|
95
|
+
const body = S.RelationshipDefinitionSchema.parse(definition);
|
|
96
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async removeRelationship(relationshipId: string): Promise<void> {
|
|
100
|
+
return this.http.post("/ontology/engine/runs", {
|
|
101
|
+
action: "delete-relationship",
|
|
102
|
+
relationshipId,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async validateData(): Promise<{
|
|
107
|
+
entityType: string;
|
|
108
|
+
totalChecked: number;
|
|
109
|
+
violations: unknown[];
|
|
110
|
+
}> {
|
|
111
|
+
return this.http.post("/ontology/engine/ontologies/validate");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async versions(): Promise<{
|
|
115
|
+
data: Array<{
|
|
116
|
+
version: number;
|
|
117
|
+
createdAt: string;
|
|
118
|
+
changedBy: string;
|
|
119
|
+
changesSummary: string;
|
|
120
|
+
migrationId?: string;
|
|
121
|
+
}>;
|
|
122
|
+
}> {
|
|
123
|
+
return this.http.get("/ontology/engine/runs");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export class MigrationsNamespace {
|
|
128
|
+
constructor(private readonly http: HttpClient) {}
|
|
129
|
+
|
|
130
|
+
async plan(request: {
|
|
131
|
+
modelId?: string;
|
|
132
|
+
changes?: S.ModelDefinition[];
|
|
133
|
+
}): Promise<S.MigrationPlan> {
|
|
134
|
+
return this.http.post(
|
|
135
|
+
"/ontology/engine/ontologies/compare-versions",
|
|
136
|
+
request
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async apply(
|
|
141
|
+
planId: string,
|
|
142
|
+
strategy = "zero-downtime"
|
|
143
|
+
): Promise<{ id: string; status: string; appliedAt: string }> {
|
|
144
|
+
return this.http.post("/ontology/engine/runs", { planId, strategy });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async rollback(
|
|
148
|
+
_migrationId: string
|
|
149
|
+
): Promise<{ id: string; status: string; rolledBackAt: string }> {
|
|
150
|
+
return this.http.post("/ontology/engine/runs");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async history(opts: { limit?: number; cursor?: string } = {}): Promise<
|
|
154
|
+
PageResult<{
|
|
155
|
+
id: string;
|
|
156
|
+
modelId: string;
|
|
157
|
+
fromVersion: number;
|
|
158
|
+
toVersion: number;
|
|
159
|
+
status: string;
|
|
160
|
+
createdAt: string;
|
|
161
|
+
}>
|
|
162
|
+
> {
|
|
163
|
+
const raw = await this.http.get("/ontology/engine/runs", opts);
|
|
164
|
+
return createPageResult(
|
|
165
|
+
asPagePayload<{
|
|
166
|
+
id: string;
|
|
167
|
+
modelId: string;
|
|
168
|
+
fromVersion: number;
|
|
169
|
+
toVersion: number;
|
|
170
|
+
status: string;
|
|
171
|
+
createdAt: string;
|
|
172
|
+
}>(raw),
|
|
173
|
+
(cursor) => this.history({ ...opts, cursor })
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export class RulesNamespace {
|
|
179
|
+
constructor(private readonly http: HttpClient) {}
|
|
180
|
+
|
|
181
|
+
async list(): Promise<{ data: S.RuleDefinition[] }> {
|
|
182
|
+
return this.http.get("/ontology/engine/runs");
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async create(definition: S.RuleDefinition): Promise<S.RuleDefinition> {
|
|
186
|
+
const body = S.RuleDefinitionSchema.parse(definition);
|
|
187
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async update(
|
|
191
|
+
_ruleId: string,
|
|
192
|
+
definition: Partial<S.RuleDefinition>
|
|
193
|
+
): Promise<S.RuleDefinition> {
|
|
194
|
+
return this.http.post("/ontology/engine/runs", definition);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async delete(ruleId: string): Promise<void> {
|
|
198
|
+
return this.http.post("/ontology/engine/runs", {
|
|
199
|
+
action: "delete-rule",
|
|
200
|
+
ruleId,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async evaluate(opts: {
|
|
205
|
+
entityType?: string;
|
|
206
|
+
ruleIds?: string[];
|
|
207
|
+
sample?: number;
|
|
208
|
+
}): Promise<{ results: unknown[]; summary: unknown }> {
|
|
209
|
+
return this.http.post("/ontology/engine/ontologies/validate", opts);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export class MixinsNamespace {
|
|
214
|
+
constructor(private readonly http: HttpClient) {}
|
|
215
|
+
|
|
216
|
+
async list(): Promise<{ data: S.MixinDefinition[] }> {
|
|
217
|
+
return this.http.get("/ontology/engine/runs");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async create(definition: S.MixinDefinition): Promise<S.MixinDefinition> {
|
|
221
|
+
const body = S.MixinDefinitionSchema.parse(definition);
|
|
222
|
+
return this.http.post("/ontology/engine/runs", body);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export class GenerationNamespace {
|
|
227
|
+
constructor(private readonly http: HttpClient) {}
|
|
228
|
+
|
|
229
|
+
async generate(
|
|
230
|
+
description: string,
|
|
231
|
+
opts: { context?: { existingModels?: string[] }; substrates?: string[] }
|
|
232
|
+
): Promise<{
|
|
233
|
+
proposal: S.ModelDefinition;
|
|
234
|
+
confidence: number;
|
|
235
|
+
reasoning: string;
|
|
236
|
+
}> {
|
|
237
|
+
return this.http.post("/ontology/engine/ontologies/generate", {
|
|
238
|
+
description,
|
|
239
|
+
...opts,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async infer(opts: {
|
|
244
|
+
substrates?: string[];
|
|
245
|
+
confidence?: "low" | "medium" | "high";
|
|
246
|
+
merge?: boolean;
|
|
247
|
+
}): Promise<{ proposals: unknown[] }> {
|
|
248
|
+
return this.http.post("/ontology/engine/ontologies/infer-classes", opts);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async suggestions(
|
|
252
|
+
opts: { status?: "pending" | "accepted" | "rejected" } = {}
|
|
253
|
+
): Promise<{ data: unknown[] }> {
|
|
254
|
+
return this.http.get("/ontology/engine/runs", opts);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async acceptSuggestion(_suggestionId: string): Promise<unknown> {
|
|
258
|
+
return this.http.post("/ontology/engine/runs");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async rejectSuggestion(
|
|
262
|
+
_suggestionId: string,
|
|
263
|
+
reason?: string
|
|
264
|
+
): Promise<unknown> {
|
|
265
|
+
return this.http.post("/ontology/engine/runs", {
|
|
266
|
+
reason,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|