@m6d/cortex-server 1.1.2 → 1.2.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/dist/src/ai/interceptors/{resolve-captured-files.d.ts → request-interceptor.d.ts} +3 -2
- package/dist/src/config.d.ts +6 -3
- package/dist/src/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/adapters/mssql.ts +9 -13
- package/src/ai/index.ts +6 -2
- package/src/ai/interceptors/{resolve-captured-files.ts → request-interceptor.ts} +7 -3
- package/src/config.ts +6 -3
- package/src/index.ts +7 -0
|
@@ -4,8 +4,9 @@ export type ResolvedFile = {
|
|
|
4
4
|
name: string;
|
|
5
5
|
bytes: string;
|
|
6
6
|
};
|
|
7
|
-
export
|
|
7
|
+
export type RequestInterceptorOptions = {
|
|
8
8
|
transformFile?: (file: ResolvedFile) => unknown;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
|
+
export declare function createRequestInterceptor(db: DatabaseAdapter, storage: StorageAdapter, options?: RequestInterceptorOptions): (body: Record<string, unknown>, context: {
|
|
10
11
|
token: string;
|
|
11
12
|
}) => Promise<Record<string, unknown>>;
|
package/dist/src/config.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { UIMessage } from "ai";
|
|
1
|
+
import type { ToolSet, UIMessage } from "ai";
|
|
2
2
|
import type { DatabaseAdapter } from "./adapters/database";
|
|
3
3
|
import type { StorageAdapter } from "./adapters/storage";
|
|
4
4
|
import type { DomainDef } from "./graph/types.ts";
|
|
5
|
+
import type { RequestInterceptorOptions } from "./ai/interceptors/request-interceptor.ts";
|
|
5
6
|
export type KnowledgeConfig = {
|
|
6
7
|
swagger?: {
|
|
7
8
|
url: string;
|
|
@@ -22,7 +23,7 @@ export type StorageConfig = {
|
|
|
22
23
|
};
|
|
23
24
|
export type CortexAgentDefinition = {
|
|
24
25
|
systemPrompt: string | ((session: Record<string, unknown> | null) => string | Promise<string>);
|
|
25
|
-
tools?:
|
|
26
|
+
tools?: ToolSet;
|
|
26
27
|
backendFetch?: {
|
|
27
28
|
baseUrl: string;
|
|
28
29
|
apiKey: string;
|
|
@@ -30,6 +31,7 @@ export type CortexAgentDefinition = {
|
|
|
30
31
|
transformRequestBody?: (body: Record<string, unknown>, context: {
|
|
31
32
|
token: string;
|
|
32
33
|
}) => Promise<Record<string, unknown>>;
|
|
34
|
+
interceptor?: RequestInterceptorOptions;
|
|
33
35
|
};
|
|
34
36
|
loadSessionData?: (token: string) => Promise<Record<string, unknown>>;
|
|
35
37
|
onToolCall?: (toolCall: {
|
|
@@ -89,7 +91,7 @@ export type ResolvedCortexAgentConfig = {
|
|
|
89
91
|
apiKey: string;
|
|
90
92
|
};
|
|
91
93
|
systemPrompt: string | ((session: Record<string, unknown> | null) => string | Promise<string>);
|
|
92
|
-
tools?:
|
|
94
|
+
tools?: ToolSet;
|
|
93
95
|
backendFetch?: {
|
|
94
96
|
baseUrl: string;
|
|
95
97
|
apiKey: string;
|
|
@@ -97,6 +99,7 @@ export type ResolvedCortexAgentConfig = {
|
|
|
97
99
|
transformRequestBody?: (body: Record<string, unknown>, context: {
|
|
98
100
|
token: string;
|
|
99
101
|
}) => Promise<Record<string, unknown>>;
|
|
102
|
+
interceptor?: RequestInterceptorOptions;
|
|
100
103
|
};
|
|
101
104
|
loadSessionData?: (token: string) => Promise<Record<string, unknown>>;
|
|
102
105
|
onToolCall?: (toolCall: {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export type { CortexConfig, CortexAgentDefinition, KnowledgeConfig, DatabaseConf
|
|
|
2
2
|
export type { Thread, AppEnv } from "./types";
|
|
3
3
|
export type { CortexInstance } from "./factory";
|
|
4
4
|
export { createCortex } from "./factory";
|
|
5
|
+
export type { ResolvedFile, RequestInterceptorOptions, } from "./ai/interceptors/request-interceptor";
|
|
6
|
+
export { createRequestInterceptor } from "./ai/interceptors/request-interceptor";
|
|
5
7
|
export { captureFilesTool } from "./ai/tools/capture-files.tool";
|
|
6
8
|
export { createQueryGraphTool } from "./ai/tools/query-graph.tool";
|
|
7
9
|
export { createCallEndpointTool } from "./ai/tools/call-endpoint.tool";
|
package/package.json
CHANGED
package/src/adapters/mssql.ts
CHANGED
|
@@ -109,19 +109,15 @@ export function createMssqlAdapter(connectionString: string, storage: StorageAda
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
const existingMessages = messagesToInsert.filter((x) => existingIds.includes(x.id));
|
|
112
|
-
|
|
113
|
-
await db
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
.where(eq(messages.id, message.id))
|
|
122
|
-
.execute();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
112
|
+
for (const message of existingMessages) {
|
|
113
|
+
await db
|
|
114
|
+
.update(messages)
|
|
115
|
+
.set({
|
|
116
|
+
content: message,
|
|
117
|
+
text: message.parts.find((x) => x.type === "text")?.text,
|
|
118
|
+
})
|
|
119
|
+
.where(eq(messages.id, message.id))
|
|
120
|
+
.execute();
|
|
125
121
|
}
|
|
126
122
|
},
|
|
127
123
|
},
|
package/src/ai/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { createQueryGraphTool } from "./tools/query-graph.tool.ts";
|
|
|
15
15
|
import { createCallEndpointTool } from "./tools/call-endpoint.tool.ts";
|
|
16
16
|
import { createExecuteCodeTool } from "./tools/execute-code.tool.ts";
|
|
17
17
|
import { captureFilesTool } from "./tools/capture-files.tool.ts";
|
|
18
|
-
import {
|
|
18
|
+
import { createRequestInterceptor } from "./interceptors/request-interceptor.ts";
|
|
19
19
|
import { createNeo4jClient } from "../graph/neo4j.ts";
|
|
20
20
|
import { resolveFromGraph } from "../graph/resolver.ts";
|
|
21
21
|
import { notify } from "../ws/index.ts";
|
|
@@ -69,7 +69,11 @@ export async function stream(
|
|
|
69
69
|
...config.backendFetch,
|
|
70
70
|
transformRequestBody:
|
|
71
71
|
config.backendFetch.transformRequestBody ??
|
|
72
|
-
|
|
72
|
+
createRequestInterceptor(
|
|
73
|
+
config.db,
|
|
74
|
+
config.storage,
|
|
75
|
+
config.backendFetch.interceptor,
|
|
76
|
+
),
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
builtInTools["callEndpoint"] = createCallEndpointTool(backendFetchWithInterceptor, token);
|
|
@@ -7,14 +7,18 @@ export type ResolvedFile = {
|
|
|
7
7
|
bytes: string;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
export
|
|
10
|
+
export type RequestInterceptorOptions = {
|
|
11
|
+
transformFile?: (file: ResolvedFile) => unknown;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function createRequestInterceptor(
|
|
11
15
|
db: DatabaseAdapter,
|
|
12
16
|
storage: StorageAdapter,
|
|
13
|
-
options?:
|
|
17
|
+
options?: RequestInterceptorOptions,
|
|
14
18
|
) {
|
|
15
19
|
const transformFile = options?.transformFile ?? ((file: ResolvedFile) => file);
|
|
16
20
|
|
|
17
|
-
return async function
|
|
21
|
+
return async function resolveRequestBody(
|
|
18
22
|
body: Record<string, unknown>,
|
|
19
23
|
context: { token: string },
|
|
20
24
|
) {
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { UIMessage } from "ai";
|
|
1
|
+
import type { Tool, ToolSet, UIMessage } from "ai";
|
|
2
2
|
import type { DatabaseAdapter } from "./adapters/database";
|
|
3
3
|
import type { StorageAdapter } from "./adapters/storage";
|
|
4
4
|
import type { DomainDef } from "./graph/types.ts";
|
|
5
|
+
import type { RequestInterceptorOptions } from "./ai/interceptors/request-interceptor.ts";
|
|
5
6
|
|
|
6
7
|
export type KnowledgeConfig = {
|
|
7
8
|
swagger?: { url: string };
|
|
@@ -24,7 +25,7 @@ export type StorageConfig = {
|
|
|
24
25
|
|
|
25
26
|
export type CortexAgentDefinition = {
|
|
26
27
|
systemPrompt: string | ((session: Record<string, unknown> | null) => string | Promise<string>);
|
|
27
|
-
tools?:
|
|
28
|
+
tools?: ToolSet;
|
|
28
29
|
backendFetch?: {
|
|
29
30
|
baseUrl: string;
|
|
30
31
|
apiKey: string;
|
|
@@ -33,6 +34,7 @@ export type CortexAgentDefinition = {
|
|
|
33
34
|
body: Record<string, unknown>,
|
|
34
35
|
context: { token: string },
|
|
35
36
|
) => Promise<Record<string, unknown>>;
|
|
37
|
+
interceptor?: RequestInterceptorOptions;
|
|
36
38
|
};
|
|
37
39
|
loadSessionData?: (token: string) => Promise<Record<string, unknown>>;
|
|
38
40
|
onToolCall?: (toolCall: {
|
|
@@ -90,7 +92,7 @@ export type ResolvedCortexAgentConfig = {
|
|
|
90
92
|
apiKey: string;
|
|
91
93
|
};
|
|
92
94
|
systemPrompt: string | ((session: Record<string, unknown> | null) => string | Promise<string>);
|
|
93
|
-
tools?:
|
|
95
|
+
tools?: ToolSet;
|
|
94
96
|
backendFetch?: {
|
|
95
97
|
baseUrl: string;
|
|
96
98
|
apiKey: string;
|
|
@@ -99,6 +101,7 @@ export type ResolvedCortexAgentConfig = {
|
|
|
99
101
|
body: Record<string, unknown>,
|
|
100
102
|
context: { token: string },
|
|
101
103
|
) => Promise<Record<string, unknown>>;
|
|
104
|
+
interceptor?: RequestInterceptorOptions;
|
|
102
105
|
};
|
|
103
106
|
loadSessionData?: (token: string) => Promise<Record<string, unknown>>;
|
|
104
107
|
onToolCall?: (toolCall: {
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,13 @@ export type { Thread, AppEnv } from "./types";
|
|
|
14
14
|
export type { CortexInstance } from "./factory";
|
|
15
15
|
export { createCortex } from "./factory";
|
|
16
16
|
|
|
17
|
+
// Request interceptor (consumers may customize or replace the default)
|
|
18
|
+
export type {
|
|
19
|
+
ResolvedFile,
|
|
20
|
+
RequestInterceptorOptions,
|
|
21
|
+
} from "./ai/interceptors/request-interceptor";
|
|
22
|
+
export { createRequestInterceptor } from "./ai/interceptors/request-interceptor";
|
|
23
|
+
|
|
17
24
|
// Tools (consumers may register custom tools or use built-in ones)
|
|
18
25
|
export { captureFilesTool } from "./ai/tools/capture-files.tool";
|
|
19
26
|
export { createQueryGraphTool } from "./ai/tools/query-graph.tool";
|