@m6d/cortex-server 1.0.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 (82) hide show
  1. package/README.md +64 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/src/adapters/database.d.ts +27 -0
  4. package/dist/src/adapters/minio.d.ts +10 -0
  5. package/dist/src/adapters/mssql.d.ts +3 -0
  6. package/dist/src/adapters/storage.d.ts +6 -0
  7. package/dist/src/ai/fetch.d.ts +2 -0
  8. package/dist/src/ai/helpers.d.ts +5 -0
  9. package/dist/src/ai/index.d.ts +4 -0
  10. package/dist/src/ai/interceptors/resolve-captured-files.d.ts +11 -0
  11. package/dist/src/ai/prompt.d.ts +4 -0
  12. package/dist/src/ai/tools/call-endpoint.tool.d.ts +7 -0
  13. package/dist/src/ai/tools/capture-files.tool.d.ts +6 -0
  14. package/dist/src/ai/tools/execute-code.tool.d.ts +4 -0
  15. package/dist/src/ai/tools/query-graph.tool.d.ts +5 -0
  16. package/dist/src/auth/middleware.d.ts +4 -0
  17. package/dist/src/cli/extract-endpoints.d.ts +6 -0
  18. package/dist/src/config.d.ts +145 -0
  19. package/dist/src/db/migrate.d.ts +1 -0
  20. package/dist/src/db/schema.d.ts +345 -0
  21. package/dist/src/factory.d.ts +17 -0
  22. package/dist/src/graph/generate-cypher.d.ts +22 -0
  23. package/dist/src/graph/helpers.d.ts +60 -0
  24. package/dist/src/graph/index.d.ts +11 -0
  25. package/dist/src/graph/neo4j.d.ts +18 -0
  26. package/dist/src/graph/resolver.d.ts +51 -0
  27. package/dist/src/graph/seed.d.ts +19 -0
  28. package/dist/src/graph/types.d.ts +104 -0
  29. package/dist/src/graph/validate.d.ts +2 -0
  30. package/dist/src/index.d.ts +10 -0
  31. package/dist/src/routes/chat.d.ts +3 -0
  32. package/dist/src/routes/files.d.ts +3 -0
  33. package/dist/src/routes/index.d.ts +4 -0
  34. package/dist/src/routes/threads.d.ts +3 -0
  35. package/dist/src/routes/ws.d.ts +3 -0
  36. package/dist/src/types.d.ts +56 -0
  37. package/dist/src/ws/connections.d.ts +4 -0
  38. package/dist/src/ws/events.d.ts +8 -0
  39. package/dist/src/ws/index.d.ts +3 -0
  40. package/dist/src/ws/notify.d.ts +2 -0
  41. package/index.ts +1 -0
  42. package/package.json +57 -0
  43. package/src/adapters/database.ts +33 -0
  44. package/src/adapters/minio.ts +89 -0
  45. package/src/adapters/mssql.ts +203 -0
  46. package/src/adapters/storage.ts +6 -0
  47. package/src/ai/fetch.ts +39 -0
  48. package/src/ai/helpers.ts +36 -0
  49. package/src/ai/index.ts +145 -0
  50. package/src/ai/interceptors/resolve-captured-files.ts +64 -0
  51. package/src/ai/prompt.ts +120 -0
  52. package/src/ai/tools/call-endpoint.tool.ts +96 -0
  53. package/src/ai/tools/capture-files.tool.ts +22 -0
  54. package/src/ai/tools/execute-code.tool.ts +108 -0
  55. package/src/ai/tools/query-graph.tool.ts +35 -0
  56. package/src/auth/middleware.ts +63 -0
  57. package/src/cli/extract-endpoints.ts +588 -0
  58. package/src/config.ts +155 -0
  59. package/src/db/migrate.ts +21 -0
  60. package/src/db/migrations/20260309012148_cloudy_maria_hill/migration.sql +36 -0
  61. package/src/db/migrations/20260309012148_cloudy_maria_hill/snapshot.json +305 -0
  62. package/src/db/schema.ts +77 -0
  63. package/src/factory.ts +159 -0
  64. package/src/graph/generate-cypher.ts +179 -0
  65. package/src/graph/helpers.ts +68 -0
  66. package/src/graph/index.ts +47 -0
  67. package/src/graph/neo4j.ts +117 -0
  68. package/src/graph/resolver.ts +357 -0
  69. package/src/graph/seed.ts +172 -0
  70. package/src/graph/types.ts +152 -0
  71. package/src/graph/validate.ts +80 -0
  72. package/src/index.ts +27 -0
  73. package/src/routes/chat.ts +38 -0
  74. package/src/routes/files.ts +105 -0
  75. package/src/routes/index.ts +4 -0
  76. package/src/routes/threads.ts +69 -0
  77. package/src/routes/ws.ts +33 -0
  78. package/src/types.ts +50 -0
  79. package/src/ws/connections.ts +23 -0
  80. package/src/ws/events.ts +6 -0
  81. package/src/ws/index.ts +7 -0
  82. package/src/ws/notify.ts +9 -0
@@ -0,0 +1,345 @@
1
+ import type { UIMessage } from "ai";
2
+ export declare const aiSchema: import("drizzle-orm/mssql-core").MsSqlSchema<"ai">;
3
+ export declare const threads: import("drizzle-orm/mssql-core").MsSqlTableWithColumns<{
4
+ name: "threads";
5
+ schema: "ai";
6
+ columns: {
7
+ createdAt: import("drizzle-orm/mssql-core").MsSqlColumn<{
8
+ name: string;
9
+ tableName: "threads";
10
+ dataType: "object date";
11
+ data: Date;
12
+ driverParam: string | Date;
13
+ notNull: true;
14
+ hasDefault: true;
15
+ isPrimaryKey: false;
16
+ isAutoincrement: false;
17
+ hasRuntimeDefault: true;
18
+ enumValues: undefined;
19
+ baseColumn: never;
20
+ identity: undefined;
21
+ generated: undefined;
22
+ }, {}>;
23
+ updatedAt: import("drizzle-orm/mssql-core").MsSqlColumn<{
24
+ name: string;
25
+ tableName: "threads";
26
+ dataType: "object date";
27
+ data: Date;
28
+ driverParam: string | Date;
29
+ notNull: true;
30
+ hasDefault: true;
31
+ isPrimaryKey: false;
32
+ isAutoincrement: false;
33
+ hasRuntimeDefault: true;
34
+ enumValues: undefined;
35
+ baseColumn: never;
36
+ identity: undefined;
37
+ generated: undefined;
38
+ }, {}>;
39
+ id: import("drizzle-orm/mssql-core").MsSqlColumn<{
40
+ name: string;
41
+ tableName: "threads";
42
+ dataType: "custom";
43
+ data: string;
44
+ driverParam: unknown;
45
+ notNull: true;
46
+ hasDefault: true;
47
+ isPrimaryKey: true;
48
+ isAutoincrement: false;
49
+ hasRuntimeDefault: false;
50
+ enumValues: undefined;
51
+ baseColumn: never;
52
+ identity: undefined;
53
+ generated: undefined;
54
+ }, {}>;
55
+ userId: import("drizzle-orm/mssql-core").MsSqlColumn<{
56
+ name: string;
57
+ tableName: "threads";
58
+ dataType: "custom";
59
+ data: string;
60
+ driverParam: unknown;
61
+ notNull: true;
62
+ hasDefault: false;
63
+ isPrimaryKey: false;
64
+ isAutoincrement: false;
65
+ hasRuntimeDefault: false;
66
+ enumValues: undefined;
67
+ baseColumn: never;
68
+ identity: undefined;
69
+ generated: undefined;
70
+ }, {}>;
71
+ agentId: import("drizzle-orm/mssql-core").MsSqlColumn<{
72
+ name: string;
73
+ tableName: "threads";
74
+ dataType: "string";
75
+ data: string;
76
+ driverParam: string | number;
77
+ notNull: true;
78
+ hasDefault: true;
79
+ isPrimaryKey: false;
80
+ isAutoincrement: false;
81
+ hasRuntimeDefault: false;
82
+ enumValues: [string, ...string[]];
83
+ baseColumn: never;
84
+ identity: undefined;
85
+ generated: undefined;
86
+ }, {}>;
87
+ title: import("drizzle-orm/mssql-core").MsSqlColumn<{
88
+ name: string;
89
+ tableName: "threads";
90
+ dataType: "string";
91
+ data: string;
92
+ driverParam: string | number;
93
+ notNull: false;
94
+ hasDefault: false;
95
+ isPrimaryKey: false;
96
+ isAutoincrement: false;
97
+ hasRuntimeDefault: false;
98
+ enumValues: [string, ...string[]];
99
+ baseColumn: never;
100
+ identity: undefined;
101
+ generated: undefined;
102
+ }, {}>;
103
+ session: import("drizzle-orm/mssql-core").MsSqlColumn<{
104
+ name: string;
105
+ tableName: "threads";
106
+ dataType: "object json";
107
+ data: Record<string, unknown>;
108
+ driverParam: string;
109
+ notNull: false;
110
+ hasDefault: false;
111
+ isPrimaryKey: false;
112
+ isAutoincrement: false;
113
+ hasRuntimeDefault: false;
114
+ enumValues: undefined;
115
+ baseColumn: never;
116
+ identity: undefined;
117
+ generated: undefined;
118
+ }, {}>;
119
+ };
120
+ dialect: "mssql";
121
+ }>;
122
+ export declare const messages: import("drizzle-orm/mssql-core").MsSqlTableWithColumns<{
123
+ name: "messages";
124
+ schema: "ai";
125
+ columns: {
126
+ createdAt: import("drizzle-orm/mssql-core").MsSqlColumn<{
127
+ name: string;
128
+ tableName: "messages";
129
+ dataType: "object date";
130
+ data: Date;
131
+ driverParam: string | Date;
132
+ notNull: true;
133
+ hasDefault: true;
134
+ isPrimaryKey: false;
135
+ isAutoincrement: false;
136
+ hasRuntimeDefault: true;
137
+ enumValues: undefined;
138
+ baseColumn: never;
139
+ identity: undefined;
140
+ generated: undefined;
141
+ }, {}>;
142
+ updatedAt: import("drizzle-orm/mssql-core").MsSqlColumn<{
143
+ name: string;
144
+ tableName: "messages";
145
+ dataType: "object date";
146
+ data: Date;
147
+ driverParam: string | Date;
148
+ notNull: true;
149
+ hasDefault: true;
150
+ isPrimaryKey: false;
151
+ isAutoincrement: false;
152
+ hasRuntimeDefault: true;
153
+ enumValues: undefined;
154
+ baseColumn: never;
155
+ identity: undefined;
156
+ generated: undefined;
157
+ }, {}>;
158
+ id: import("drizzle-orm/mssql-core").MsSqlColumn<{
159
+ name: string;
160
+ tableName: "messages";
161
+ dataType: "string";
162
+ data: string;
163
+ driverParam: string | number;
164
+ notNull: true;
165
+ hasDefault: false;
166
+ isPrimaryKey: true;
167
+ isAutoincrement: false;
168
+ hasRuntimeDefault: false;
169
+ enumValues: [string, ...string[]];
170
+ baseColumn: never;
171
+ identity: undefined;
172
+ generated: undefined;
173
+ }, {}>;
174
+ threadId: import("drizzle-orm/mssql-core").MsSqlColumn<{
175
+ name: string;
176
+ tableName: "messages";
177
+ dataType: "custom";
178
+ data: string;
179
+ driverParam: unknown;
180
+ notNull: true;
181
+ hasDefault: false;
182
+ isPrimaryKey: false;
183
+ isAutoincrement: false;
184
+ hasRuntimeDefault: false;
185
+ enumValues: undefined;
186
+ baseColumn: never;
187
+ identity: undefined;
188
+ generated: undefined;
189
+ }, {}>;
190
+ text: import("drizzle-orm/mssql-core").MsSqlColumn<{
191
+ name: string;
192
+ tableName: "messages";
193
+ dataType: "string";
194
+ data: string;
195
+ driverParam: string | number;
196
+ notNull: false;
197
+ hasDefault: false;
198
+ isPrimaryKey: false;
199
+ isAutoincrement: false;
200
+ hasRuntimeDefault: false;
201
+ enumValues: [string, ...string[]];
202
+ baseColumn: never;
203
+ identity: undefined;
204
+ generated: undefined;
205
+ }, {}>;
206
+ content: import("drizzle-orm/mssql-core").MsSqlColumn<{
207
+ name: string;
208
+ tableName: "messages";
209
+ dataType: "object json";
210
+ data: UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>;
211
+ driverParam: string;
212
+ notNull: true;
213
+ hasDefault: false;
214
+ isPrimaryKey: false;
215
+ isAutoincrement: false;
216
+ hasRuntimeDefault: false;
217
+ enumValues: undefined;
218
+ baseColumn: never;
219
+ identity: undefined;
220
+ generated: undefined;
221
+ }, {}>;
222
+ role: import("drizzle-orm/mssql-core").MsSqlColumn<{
223
+ name: string;
224
+ tableName: "messages";
225
+ dataType: "string enum";
226
+ data: "system" | "user" | "assistant" | "tool";
227
+ driverParam: string | number;
228
+ notNull: true;
229
+ hasDefault: false;
230
+ isPrimaryKey: false;
231
+ isAutoincrement: false;
232
+ hasRuntimeDefault: false;
233
+ enumValues: ["system", "user", "assistant", "tool"];
234
+ baseColumn: never;
235
+ identity: undefined;
236
+ generated: undefined;
237
+ }, {}>;
238
+ };
239
+ dialect: "mssql";
240
+ }>;
241
+ export declare const capturedFiles: import("drizzle-orm/mssql-core").MsSqlTableWithColumns<{
242
+ name: "captured_files";
243
+ schema: "ai";
244
+ columns: {
245
+ id: import("drizzle-orm/mssql-core").MsSqlColumn<{
246
+ name: string;
247
+ tableName: "captured_files";
248
+ dataType: "custom";
249
+ data: string;
250
+ driverParam: unknown;
251
+ notNull: true;
252
+ hasDefault: true;
253
+ isPrimaryKey: true;
254
+ isAutoincrement: false;
255
+ hasRuntimeDefault: false;
256
+ enumValues: undefined;
257
+ baseColumn: never;
258
+ identity: undefined;
259
+ generated: undefined;
260
+ }, {}>;
261
+ name: import("drizzle-orm/mssql-core").MsSqlColumn<{
262
+ name: string;
263
+ tableName: "captured_files";
264
+ dataType: "string";
265
+ data: string;
266
+ driverParam: string | number;
267
+ notNull: true;
268
+ hasDefault: false;
269
+ isPrimaryKey: false;
270
+ isAutoincrement: false;
271
+ hasRuntimeDefault: false;
272
+ enumValues: [string, ...string[]];
273
+ baseColumn: never;
274
+ identity: undefined;
275
+ generated: undefined;
276
+ }, {}>;
277
+ userId: import("drizzle-orm/mssql-core").MsSqlColumn<{
278
+ name: string;
279
+ tableName: "captured_files";
280
+ dataType: "custom";
281
+ data: string;
282
+ driverParam: unknown;
283
+ notNull: true;
284
+ hasDefault: false;
285
+ isPrimaryKey: false;
286
+ isAutoincrement: false;
287
+ hasRuntimeDefault: false;
288
+ enumValues: undefined;
289
+ baseColumn: never;
290
+ identity: undefined;
291
+ generated: undefined;
292
+ }, {}>;
293
+ agentGeneratedId: import("drizzle-orm/mssql-core").MsSqlColumn<{
294
+ name: string;
295
+ tableName: "captured_files";
296
+ dataType: "string";
297
+ data: string;
298
+ driverParam: string | number;
299
+ notNull: true;
300
+ hasDefault: false;
301
+ isPrimaryKey: false;
302
+ isAutoincrement: false;
303
+ hasRuntimeDefault: false;
304
+ enumValues: [string, ...string[]];
305
+ baseColumn: never;
306
+ identity: undefined;
307
+ generated: undefined;
308
+ }, {}>;
309
+ messageId: import("drizzle-orm/mssql-core").MsSqlColumn<{
310
+ name: string;
311
+ tableName: "captured_files";
312
+ dataType: "string";
313
+ data: string;
314
+ driverParam: string | number;
315
+ notNull: true;
316
+ hasDefault: false;
317
+ isPrimaryKey: false;
318
+ isAutoincrement: false;
319
+ hasRuntimeDefault: false;
320
+ enumValues: [string, ...string[]];
321
+ baseColumn: never;
322
+ identity: undefined;
323
+ generated: undefined;
324
+ }, {}>;
325
+ toolPart: import("drizzle-orm/mssql-core").MsSqlColumn<{
326
+ name: string;
327
+ tableName: "captured_files";
328
+ dataType: "object json";
329
+ data: {
330
+ type: `tool-${string}`;
331
+ } & import("ai").UIToolInvocation<import("ai").UITool>;
332
+ driverParam: string;
333
+ notNull: true;
334
+ hasDefault: false;
335
+ isPrimaryKey: false;
336
+ isAutoincrement: false;
337
+ hasRuntimeDefault: false;
338
+ enumValues: undefined;
339
+ baseColumn: never;
340
+ identity: undefined;
341
+ generated: undefined;
342
+ }, {}>;
343
+ };
344
+ dialect: "mssql";
345
+ }>;
@@ -0,0 +1,17 @@
1
+ import { Hono } from "hono";
2
+ import { websocket } from "hono/bun";
3
+ import type { CortexConfig } from "./config.ts";
4
+ import type { AppEnv } from "./types.ts";
5
+ export type CortexInstance = {
6
+ serve(): Promise<{
7
+ app: Hono<AppEnv>;
8
+ fetch: Hono<AppEnv>["fetch"];
9
+ websocket: typeof websocket;
10
+ }>;
11
+ seedGraph(): Promise<void>;
12
+ extractEndpoints(options: {
13
+ domainsDir: string;
14
+ write?: boolean;
15
+ }): Promise<void>;
16
+ };
17
+ export declare function createCortex(config: CortexConfig): CortexInstance;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Transforms declarative DomainDef into idempotent MERGE-based Cypher.
3
+ *
4
+ * Returns two phases:
5
+ * - `nodes` -- MERGE statements that create/update Domain, Concept, Endpoint,
6
+ * Service, and Rule nodes.
7
+ * - `edges` -- MATCH+MERGE statements that wire up relationships between nodes.
8
+ *
9
+ * The caller MUST run all `nodes` from every module before running any `edges`,
10
+ * because edges may reference nodes defined in a different module (e.g. a Rule
11
+ * in the leaves module that GOVERNS a Concept created by the servicing module).
12
+ */
13
+ import type { DomainDef } from "./types.ts";
14
+ export type GeneratedCypher = {
15
+ nodes: string[];
16
+ edges: string[];
17
+ };
18
+ export declare function generateCypher(data: DomainDef): {
19
+ nodes: string[];
20
+ edges: string[];
21
+ };
22
+ export declare function toCypherScript(data: DomainDef): string;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Helper functions for building knowledge graph seed data.
3
+ */
4
+ import type { ConceptDef, DomainDef, EndpointDef, EndpointInput, RuleDef, ServiceDef } from "./types.ts";
5
+ export declare function defineConcept(def: Omit<ConceptDef, "__brand">): {
6
+ name: string;
7
+ description: string;
8
+ aliases?: string[] | undefined;
9
+ parentConcept?: ConceptDef | undefined;
10
+ governedBy?: RuleDef[] | undefined;
11
+ __brand: "concept";
12
+ };
13
+ export declare function defineRule(def: Omit<RuleDef, "__brand">): {
14
+ name: string;
15
+ description: string;
16
+ __brand: "rule";
17
+ };
18
+ export declare function defineService(def: Omit<ServiceDef, "__brand">): {
19
+ name: string;
20
+ description: string;
21
+ governedBy?: RuleDef[] | undefined;
22
+ builtInId: string;
23
+ belongsTo: ConceptDef;
24
+ __brand: "service";
25
+ };
26
+ export declare function defineDomain(def: Omit<DomainDef, "__brand">): {
27
+ name: string;
28
+ description: string;
29
+ concepts?: ConceptDef[] | undefined;
30
+ endpoints?: EndpointDef[] | undefined;
31
+ services?: ServiceDef[] | undefined;
32
+ rules?: RuleDef[] | undefined;
33
+ __brand: "domain";
34
+ };
35
+ export declare function defineEndpoint(input: EndpointInput): {
36
+ __brand: "endpoint";
37
+ name: string;
38
+ description: string;
39
+ path: string;
40
+ method: "GET" | "POST" | "PUT" | "DELETE";
41
+ propertiesDescriptions: Record<string, string>;
42
+ params: import("./types.ts").EndpointProperty[];
43
+ body: import("./types.ts").EndpointProperty[];
44
+ response: import("./types.ts").EndpointProperty[];
45
+ successStatus: number;
46
+ errorStatuses: number[];
47
+ responseKind: import("./types.ts").ResponseKind;
48
+ queries: ConceptDef[] | undefined;
49
+ mutates: ConceptDef[] | undefined;
50
+ returns: {
51
+ concept: ConceptDef;
52
+ field?: string;
53
+ }[] | undefined;
54
+ dependsOn: {
55
+ endpoint: EndpointDef;
56
+ paramName: string;
57
+ fromField: string;
58
+ }[] | undefined;
59
+ governedBy: RuleDef[] | undefined;
60
+ };
@@ -0,0 +1,11 @@
1
+ export type { EndpointScalarType, EndpointProperty, ResponseKind, AutoGenerated, ConceptDef, EndpointDef, EndpointInput, ServiceDef, RuleDef, DomainDef, } from "./types.ts";
2
+ export { defineConcept, defineRule, defineService, defineDomain, defineEndpoint, } from "./helpers.ts";
3
+ export type { GeneratedCypher } from "./generate-cypher.ts";
4
+ export { generateCypher, toCypherScript } from "./generate-cypher.ts";
5
+ export { validateDomain } from "./validate.ts";
6
+ export type { Neo4jConfig, Neo4jClient } from "./neo4j.ts";
7
+ export { createNeo4jClient } from "./neo4j.ts";
8
+ export type { EmbeddingConfig, SeedGraphConfig } from "./seed.ts";
9
+ export { seedGraph } from "./seed.ts";
10
+ export type { RerankerConfig, ResolverConfig, ResolvedEndpoint, ResolvedService, ResolvedContext, } from "./resolver.ts";
11
+ export { resolveFromGraph } from "./resolver.ts";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Configurable Neo4j HTTP client.
3
+ *
4
+ * Replaces the hardcoded process.env-based client from packages/sample-backend.
5
+ * All configuration is passed explicitly — no environment variables are read.
6
+ */
7
+ import type { EmbeddingModel } from "ai";
8
+ export type Neo4jConfig = {
9
+ url: string;
10
+ user: string;
11
+ password: string;
12
+ };
13
+ export type Neo4jClient = {
14
+ query(cypher: string, parameters?: Record<string, unknown>): Promise<string>;
15
+ };
16
+ export declare function createNeo4jClient(config: Neo4jConfig, embeddingModel?: EmbeddingModel): {
17
+ query: (cypher: string, parameters?: Record<string, unknown>) => Promise<string>;
18
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Pre-resolves relevant API endpoints from the Neo4j knowledge graph
3
+ * using vector similarity search on concept descriptions.
4
+ *
5
+ * All configuration is passed explicitly — no hardcoded model references
6
+ * or environment variables.
7
+ */
8
+ import type { EmbeddingModel } from "ai";
9
+ import type { Neo4jClient } from "./neo4j.ts";
10
+ export type RerankerConfig = {
11
+ url: string;
12
+ apiKey: string;
13
+ };
14
+ export type ResolverConfig = {
15
+ neo4j: Neo4jClient;
16
+ embeddingModel: EmbeddingModel;
17
+ reranker?: RerankerConfig;
18
+ };
19
+ type EndpointDependency = {
20
+ depPath: string;
21
+ depMethod: string;
22
+ paramName: string;
23
+ fromField: string;
24
+ };
25
+ type EndpointRelation = "read" | "write";
26
+ export type ResolvedEndpoint = {
27
+ concept: string;
28
+ relation: EndpointRelation;
29
+ name: string;
30
+ path: string;
31
+ method: string;
32
+ params: string;
33
+ body: string;
34
+ response: string;
35
+ dependencies: EndpointDependency[];
36
+ rules: string[];
37
+ };
38
+ export type ResolvedService = {
39
+ concept: string;
40
+ serviceName: string;
41
+ builtInId: string;
42
+ description: string;
43
+ rules: string[];
44
+ };
45
+ export type ResolvedContext = {
46
+ readEndpoints: ResolvedEndpoint[];
47
+ writeEndpoints: ResolvedEndpoint[];
48
+ services: ResolvedService[];
49
+ };
50
+ export declare function resolveFromGraph(prompt: string, config: ResolverConfig): Promise<ResolvedContext>;
51
+ export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Seed orchestrator for the knowledge graph.
3
+ *
4
+ * Validates domains, generates Cypher, executes against Neo4j,
5
+ * and generates concept embeddings. All configuration is passed
6
+ * explicitly — no environment variables or Convex dependencies.
7
+ */
8
+ import type { EmbeddingModel } from "ai";
9
+ import type { Neo4jConfig } from "./neo4j.ts";
10
+ import type { DomainDef } from "./types.ts";
11
+ export type EmbeddingConfig = {
12
+ model: EmbeddingModel;
13
+ dimension: number;
14
+ };
15
+ export type SeedGraphConfig = {
16
+ neo4j: Neo4jConfig;
17
+ embedding: EmbeddingConfig;
18
+ };
19
+ export declare function seedGraph(config: SeedGraphConfig, domains: Record<string, DomainDef>): Promise<void>;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Declarative types for knowledge graph seed data.
3
+ *
4
+ * This is the v2 schema:
5
+ * - Endpoints use params/body/response EndpointProperty arrays.
6
+ * - Source/default mappings are intentionally removed.
7
+ * - Services are concept associations (no hardcoded endpoint steps).
8
+ */
9
+ export type EndpointScalarType = "uuid" | "number" | "date" | "datetime" | "string" | "boolean" | "any" | "object";
10
+ export type EndpointProperty = {
11
+ readonly name: string;
12
+ readonly required: boolean;
13
+ readonly type: EndpointScalarType | string;
14
+ readonly isArray?: boolean;
15
+ readonly properties?: readonly EndpointProperty[];
16
+ readonly description?: string;
17
+ };
18
+ export type ResponseKind = "object" | "array" | "paginated" | "file" | "none";
19
+ export type AutoGenerated = {
20
+ readonly params: readonly EndpointProperty[];
21
+ readonly body: readonly EndpointProperty[];
22
+ readonly response: readonly EndpointProperty[];
23
+ readonly successStatus: number;
24
+ readonly errorStatuses: readonly number[];
25
+ readonly responseKind?: ResponseKind;
26
+ };
27
+ export type ConceptDef = {
28
+ readonly __brand: "concept";
29
+ name: string;
30
+ description: string;
31
+ aliases?: string[];
32
+ parentConcept?: ConceptDef;
33
+ governedBy?: RuleDef[];
34
+ };
35
+ export type EndpointDef = {
36
+ readonly __brand: "endpoint";
37
+ name: string;
38
+ description: string;
39
+ path: string;
40
+ method: "GET" | "POST" | "PUT" | "DELETE";
41
+ propertiesDescriptions: Record<string, string>;
42
+ params: EndpointProperty[];
43
+ body: EndpointProperty[];
44
+ response: EndpointProperty[];
45
+ successStatus: number;
46
+ errorStatuses: number[];
47
+ responseKind: ResponseKind;
48
+ queries?: ConceptDef[];
49
+ mutates?: ConceptDef[];
50
+ returns?: {
51
+ concept: ConceptDef;
52
+ field?: string;
53
+ }[];
54
+ dependsOn?: {
55
+ endpoint: EndpointDef;
56
+ paramName: string;
57
+ fromField: string;
58
+ }[];
59
+ governedBy?: RuleDef[];
60
+ };
61
+ export type EndpointInput = {
62
+ name: string;
63
+ path: string;
64
+ method: "GET" | "POST" | "PUT" | "DELETE";
65
+ description?: string;
66
+ autoGenerated?: AutoGenerated;
67
+ propertiesDescriptions?: Record<string, string>;
68
+ queries?: ConceptDef[];
69
+ mutates?: ConceptDef[];
70
+ paramDescriptions?: Partial<Record<string, string>>;
71
+ responseDescriptions?: Partial<Record<string, string>>;
72
+ returns?: {
73
+ concept: ConceptDef;
74
+ field?: string;
75
+ }[];
76
+ dependsOn?: {
77
+ endpoint: EndpointDef;
78
+ paramName: string;
79
+ fromField: string;
80
+ }[];
81
+ governedBy?: RuleDef[];
82
+ };
83
+ export type ServiceDef = {
84
+ readonly __brand: "service";
85
+ name: string;
86
+ description: string;
87
+ builtInId: string;
88
+ belongsTo: ConceptDef;
89
+ governedBy?: RuleDef[];
90
+ };
91
+ export type RuleDef = {
92
+ readonly __brand: "rule";
93
+ name: string;
94
+ description: string;
95
+ };
96
+ export type DomainDef = {
97
+ readonly __brand: "domain";
98
+ name: string;
99
+ description: string;
100
+ concepts?: ConceptDef[];
101
+ endpoints?: EndpointDef[];
102
+ services?: ServiceDef[];
103
+ rules?: RuleDef[];
104
+ };
@@ -0,0 +1,2 @@
1
+ import type { DomainDef } from "./types.ts";
2
+ export declare function validateDomain(data: DomainDef): string[];
@@ -0,0 +1,10 @@
1
+ export type { CortexConfig, CortexAgentDefinition, KnowledgeConfig, DatabaseConfig, StorageConfig, } from "./config";
2
+ export type { Thread, AppEnv } from "./types";
3
+ export type { CortexInstance } from "./factory";
4
+ export { createCortex } from "./factory";
5
+ export { captureFilesTool } from "./ai/tools/capture-files.tool";
6
+ export { createQueryGraphTool } from "./ai/tools/query-graph.tool";
7
+ export { createCallEndpointTool } from "./ai/tools/call-endpoint.tool";
8
+ export { createExecuteCodeTool } from "./ai/tools/execute-code.tool";
9
+ export * from "./graph/index";
10
+ export type { WsEvent, ThreadTitleUpdatedEvent } from "./ws/index";
@@ -0,0 +1,3 @@
1
+ import { Hono } from "hono";
2
+ import type { CortexAppEnv } from "../types.ts";
3
+ export declare function createChatRoutes(): Hono<CortexAppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from "hono";
2
+ import type { CortexAppEnv } from "../types.ts";
3
+ export declare function createFileRoutes(): Hono<CortexAppEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,4 @@
1
+ export { createThreadRoutes } from "./threads.ts";
2
+ export { createChatRoutes } from "./chat.ts";
3
+ export { createFileRoutes } from "./files.ts";
4
+ export { createWsRoute } from "./ws.ts";