@apart-tech/intelligence-core 1.21.0 → 1.21.2
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/db/tenant.d.ts.map +1 -1
- package/dist/db/tenant.js +2 -0
- package/dist/db/tenant.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/services/__tests__/node-service.test.js +3 -3
- package/dist/services/__tests__/node-service.test.js.map +1 -1
- package/dist/services/__tests__/search-service.test.js +3 -0
- package/dist/services/__tests__/search-service.test.js.map +1 -1
- package/dist/services/agent-cli-reference.d.ts +1 -1
- package/dist/services/agent-cli-reference.d.ts.map +1 -1
- package/dist/services/agent-cli-reference.js +2 -2
- package/dist/services/chat-capture-service.d.ts +6 -2
- package/dist/services/chat-capture-service.d.ts.map +1 -1
- package/dist/services/chat-capture-service.js +56 -19
- package/dist/services/chat-capture-service.js.map +1 -1
- package/dist/services/chat-context-service.d.ts.map +1 -1
- package/dist/services/chat-context-service.js +5 -0
- package/dist/services/chat-context-service.js.map +1 -1
- package/dist/services/chat-tool-definitions.d.ts +178 -0
- package/dist/services/chat-tool-definitions.d.ts.map +1 -0
- package/dist/services/chat-tool-definitions.js +120 -0
- package/dist/services/chat-tool-definitions.js.map +1 -0
- package/dist/services/chat-tool-definitions.test.d.ts +2 -0
- package/dist/services/chat-tool-definitions.test.d.ts.map +1 -0
- package/dist/services/chat-tool-definitions.test.js +150 -0
- package/dist/services/chat-tool-definitions.test.js.map +1 -0
- package/dist/services/dedup-service.d.ts +132 -0
- package/dist/services/dedup-service.d.ts.map +1 -0
- package/dist/services/dedup-service.js +434 -0
- package/dist/services/dedup-service.js.map +1 -0
- package/dist/services/dedup-service.test.d.ts +2 -0
- package/dist/services/dedup-service.test.d.ts.map +1 -0
- package/dist/services/dedup-service.test.js +160 -0
- package/dist/services/dedup-service.test.js.map +1 -0
- package/dist/services/document-post-check-service.d.ts +47 -0
- package/dist/services/document-post-check-service.d.ts.map +1 -0
- package/dist/services/document-post-check-service.js +130 -0
- package/dist/services/document-post-check-service.js.map +1 -0
- package/dist/services/document-post-check-service.test.d.ts +2 -0
- package/dist/services/document-post-check-service.test.d.ts.map +1 -0
- package/dist/services/document-post-check-service.test.js +150 -0
- package/dist/services/document-post-check-service.test.js.map +1 -0
- package/dist/services/document-render-service.d.ts +27 -0
- package/dist/services/document-render-service.d.ts.map +1 -0
- package/dist/services/document-render-service.js +186 -0
- package/dist/services/document-render-service.js.map +1 -0
- package/dist/services/document-render-service.test.d.ts +2 -0
- package/dist/services/document-render-service.test.d.ts.map +1 -0
- package/dist/services/document-render-service.test.js +144 -0
- package/dist/services/document-render-service.test.js.map +1 -0
- package/dist/services/document-service.d.ts +4 -1
- package/dist/services/document-service.d.ts.map +1 -1
- package/dist/services/document-service.js +24 -1
- package/dist/services/document-service.js.map +1 -1
- package/dist/services/document-tool-handler.d.ts +44 -0
- package/dist/services/document-tool-handler.d.ts.map +1 -0
- package/dist/services/document-tool-handler.js +179 -0
- package/dist/services/document-tool-handler.js.map +1 -0
- package/dist/services/document-tool-handler.test.d.ts +2 -0
- package/dist/services/document-tool-handler.test.d.ts.map +1 -0
- package/dist/services/document-tool-handler.test.js +149 -0
- package/dist/services/document-tool-handler.test.js.map +1 -0
- package/dist/services/edge-service.d.ts +1 -0
- package/dist/services/edge-service.d.ts.map +1 -1
- package/dist/services/edge-service.js +9 -0
- package/dist/services/edge-service.js.map +1 -1
- package/dist/services/node-service.js +2 -2
- package/dist/services/node-service.js.map +1 -1
- package/dist/services/quota-service.d.ts +2 -0
- package/dist/services/quota-service.d.ts.map +1 -1
- package/dist/services/quota-service.js +17 -1
- package/dist/services/quota-service.js.map +1 -1
- package/dist/services/search-service.d.ts.map +1 -1
- package/dist/services/search-service.js +34 -2
- package/dist/services/search-service.js.map +1 -1
- package/dist/services/usage-service.d.ts +21 -1
- package/dist/services/usage-service.d.ts.map +1 -1
- package/dist/services/usage-service.js +37 -1
- package/dist/services/usage-service.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +11 -1
- package/prisma/schema.prisma +48 -18
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CreateSpreadsheetSchema: z.ZodObject<{
|
|
3
|
+
fileName: z.ZodString;
|
|
4
|
+
sheets: z.ZodArray<z.ZodObject<{
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
columns: z.ZodArray<z.ZodObject<{
|
|
7
|
+
header: z.ZodString;
|
|
8
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
header: string;
|
|
11
|
+
width?: number | undefined;
|
|
12
|
+
}, {
|
|
13
|
+
header: string;
|
|
14
|
+
width?: number | undefined;
|
|
15
|
+
}>, "many">;
|
|
16
|
+
rows: z.ZodArray<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">, "many">;
|
|
17
|
+
formulas: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
18
|
+
cell: z.ZodString;
|
|
19
|
+
formula: z.ZodString;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
cell: string;
|
|
22
|
+
formula: string;
|
|
23
|
+
}, {
|
|
24
|
+
cell: string;
|
|
25
|
+
formula: string;
|
|
26
|
+
}>, "many">>;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
name: string;
|
|
29
|
+
rows: (string | number | boolean | null)[][];
|
|
30
|
+
columns: {
|
|
31
|
+
header: string;
|
|
32
|
+
width?: number | undefined;
|
|
33
|
+
}[];
|
|
34
|
+
formulas?: {
|
|
35
|
+
cell: string;
|
|
36
|
+
formula: string;
|
|
37
|
+
}[] | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
name: string;
|
|
40
|
+
rows: (string | number | boolean | null)[][];
|
|
41
|
+
columns: {
|
|
42
|
+
header: string;
|
|
43
|
+
width?: number | undefined;
|
|
44
|
+
}[];
|
|
45
|
+
formulas?: {
|
|
46
|
+
cell: string;
|
|
47
|
+
formula: string;
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
}>, "many">;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
fileName: string;
|
|
52
|
+
sheets: {
|
|
53
|
+
name: string;
|
|
54
|
+
rows: (string | number | boolean | null)[][];
|
|
55
|
+
columns: {
|
|
56
|
+
header: string;
|
|
57
|
+
width?: number | undefined;
|
|
58
|
+
}[];
|
|
59
|
+
formulas?: {
|
|
60
|
+
cell: string;
|
|
61
|
+
formula: string;
|
|
62
|
+
}[] | undefined;
|
|
63
|
+
}[];
|
|
64
|
+
}, {
|
|
65
|
+
fileName: string;
|
|
66
|
+
sheets: {
|
|
67
|
+
name: string;
|
|
68
|
+
rows: (string | number | boolean | null)[][];
|
|
69
|
+
columns: {
|
|
70
|
+
header: string;
|
|
71
|
+
width?: number | undefined;
|
|
72
|
+
}[];
|
|
73
|
+
formulas?: {
|
|
74
|
+
cell: string;
|
|
75
|
+
formula: string;
|
|
76
|
+
}[] | undefined;
|
|
77
|
+
}[];
|
|
78
|
+
}>;
|
|
79
|
+
export declare const CreatePresentationSchema: z.ZodObject<{
|
|
80
|
+
fileName: z.ZodString;
|
|
81
|
+
slides: z.ZodArray<z.ZodObject<{
|
|
82
|
+
layout: z.ZodEnum<["title", "content", "two-column", "blank"]>;
|
|
83
|
+
title: z.ZodOptional<z.ZodString>;
|
|
84
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
85
|
+
body: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
86
|
+
leftColumn: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
87
|
+
rightColumn: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
88
|
+
notes: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, "strip", z.ZodTypeAny, {
|
|
90
|
+
layout: "title" | "content" | "two-column" | "blank";
|
|
91
|
+
title?: string | undefined;
|
|
92
|
+
subtitle?: string | undefined;
|
|
93
|
+
body?: string[] | undefined;
|
|
94
|
+
leftColumn?: string[] | undefined;
|
|
95
|
+
rightColumn?: string[] | undefined;
|
|
96
|
+
notes?: string | undefined;
|
|
97
|
+
}, {
|
|
98
|
+
layout: "title" | "content" | "two-column" | "blank";
|
|
99
|
+
title?: string | undefined;
|
|
100
|
+
subtitle?: string | undefined;
|
|
101
|
+
body?: string[] | undefined;
|
|
102
|
+
leftColumn?: string[] | undefined;
|
|
103
|
+
rightColumn?: string[] | undefined;
|
|
104
|
+
notes?: string | undefined;
|
|
105
|
+
}>, "many">;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
fileName: string;
|
|
108
|
+
slides: {
|
|
109
|
+
layout: "title" | "content" | "two-column" | "blank";
|
|
110
|
+
title?: string | undefined;
|
|
111
|
+
subtitle?: string | undefined;
|
|
112
|
+
body?: string[] | undefined;
|
|
113
|
+
leftColumn?: string[] | undefined;
|
|
114
|
+
rightColumn?: string[] | undefined;
|
|
115
|
+
notes?: string | undefined;
|
|
116
|
+
}[];
|
|
117
|
+
}, {
|
|
118
|
+
fileName: string;
|
|
119
|
+
slides: {
|
|
120
|
+
layout: "title" | "content" | "two-column" | "blank";
|
|
121
|
+
title?: string | undefined;
|
|
122
|
+
subtitle?: string | undefined;
|
|
123
|
+
body?: string[] | undefined;
|
|
124
|
+
leftColumn?: string[] | undefined;
|
|
125
|
+
rightColumn?: string[] | undefined;
|
|
126
|
+
notes?: string | undefined;
|
|
127
|
+
}[];
|
|
128
|
+
}>;
|
|
129
|
+
export declare const CreateDocumentSchema: z.ZodObject<{
|
|
130
|
+
fileName: z.ZodString;
|
|
131
|
+
content: z.ZodString;
|
|
132
|
+
}, "strip", z.ZodTypeAny, {
|
|
133
|
+
content: string;
|
|
134
|
+
fileName: string;
|
|
135
|
+
}, {
|
|
136
|
+
content: string;
|
|
137
|
+
fileName: string;
|
|
138
|
+
}>;
|
|
139
|
+
export declare const CreateCsvSchema: z.ZodObject<{
|
|
140
|
+
fileName: z.ZodString;
|
|
141
|
+
headers: z.ZodArray<z.ZodString, "many">;
|
|
142
|
+
rows: z.ZodArray<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">, "many">;
|
|
143
|
+
delimiter: z.ZodDefault<z.ZodEnum<[",", ";", "\t"]>>;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
fileName: string;
|
|
146
|
+
rows: (string | number | boolean | null)[][];
|
|
147
|
+
headers: string[];
|
|
148
|
+
delimiter: "," | ";" | "\t";
|
|
149
|
+
}, {
|
|
150
|
+
fileName: string;
|
|
151
|
+
rows: (string | number | boolean | null)[][];
|
|
152
|
+
headers: string[];
|
|
153
|
+
delimiter?: "," | ";" | "\t" | undefined;
|
|
154
|
+
}>;
|
|
155
|
+
export declare const EditDocumentSchema: z.ZodObject<{
|
|
156
|
+
sourceDocumentId: z.ZodString;
|
|
157
|
+
fileName: z.ZodString;
|
|
158
|
+
instructions: z.ZodString;
|
|
159
|
+
}, "strip", z.ZodTypeAny, {
|
|
160
|
+
fileName: string;
|
|
161
|
+
sourceDocumentId: string;
|
|
162
|
+
instructions: string;
|
|
163
|
+
}, {
|
|
164
|
+
fileName: string;
|
|
165
|
+
sourceDocumentId: string;
|
|
166
|
+
instructions: string;
|
|
167
|
+
}>;
|
|
168
|
+
export type CreateSpreadsheetArgs = z.infer<typeof CreateSpreadsheetSchema>;
|
|
169
|
+
export type CreatePresentationArgs = z.infer<typeof CreatePresentationSchema>;
|
|
170
|
+
export type CreateDocumentArgs = z.infer<typeof CreateDocumentSchema>;
|
|
171
|
+
export type CreateCsvArgs = z.infer<typeof CreateCsvSchema>;
|
|
172
|
+
export type EditDocumentArgs = z.infer<typeof EditDocumentSchema>;
|
|
173
|
+
/**
|
|
174
|
+
* Serialize all user-visible text fields from tool call arguments
|
|
175
|
+
* into a single string for content policy and PII evaluation.
|
|
176
|
+
*/
|
|
177
|
+
export declare function extractTextFromToolArgs(toolName: string, args: unknown): string;
|
|
178
|
+
//# sourceMappingURL=chat-tool-definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-tool-definitions.d.ts","sourceRoot":"","sources":["../../src/services/chat-tool-definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsBlC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAanC,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;EAG/B,CAAC;AAEH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;EAK1B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;EAI7B,CAAC;AAIH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAC5E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC9E,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACtE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC5D,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAIlE;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,GACZ,MAAM,CA6DR"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
// ── Tool parameter schemas ──────────────────────────────────────────────
|
|
3
|
+
export const CreateSpreadsheetSchema = z.object({
|
|
4
|
+
fileName: z.string().describe("File name without extension"),
|
|
5
|
+
sheets: z.array(z.object({
|
|
6
|
+
name: z.string().describe("Sheet/tab name"),
|
|
7
|
+
columns: z.array(z.object({
|
|
8
|
+
header: z.string(),
|
|
9
|
+
width: z.number().optional(),
|
|
10
|
+
})),
|
|
11
|
+
rows: z.array(z.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))),
|
|
12
|
+
formulas: z
|
|
13
|
+
.array(z.object({
|
|
14
|
+
cell: z.string().describe("Cell reference like A1, B2"),
|
|
15
|
+
formula: z.string().describe("Excel formula like =SUM(B2:B10)"),
|
|
16
|
+
}))
|
|
17
|
+
.optional(),
|
|
18
|
+
})),
|
|
19
|
+
});
|
|
20
|
+
export const CreatePresentationSchema = z.object({
|
|
21
|
+
fileName: z.string().describe("File name without extension"),
|
|
22
|
+
slides: z.array(z.object({
|
|
23
|
+
layout: z.enum(["title", "content", "two-column", "blank"]),
|
|
24
|
+
title: z.string().optional(),
|
|
25
|
+
subtitle: z.string().optional(),
|
|
26
|
+
body: z.array(z.string()).optional().describe("Bullet points or paragraphs"),
|
|
27
|
+
leftColumn: z.array(z.string()).optional(),
|
|
28
|
+
rightColumn: z.array(z.string()).optional(),
|
|
29
|
+
notes: z.string().optional().describe("Speaker notes"),
|
|
30
|
+
})),
|
|
31
|
+
});
|
|
32
|
+
export const CreateDocumentSchema = z.object({
|
|
33
|
+
fileName: z.string().describe("File name without extension"),
|
|
34
|
+
content: z.string().describe("Document content in markdown format"),
|
|
35
|
+
});
|
|
36
|
+
export const CreateCsvSchema = z.object({
|
|
37
|
+
fileName: z.string().describe("File name without extension"),
|
|
38
|
+
headers: z.array(z.string()),
|
|
39
|
+
rows: z.array(z.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))),
|
|
40
|
+
delimiter: z.enum([",", ";", "\t"]).default(","),
|
|
41
|
+
});
|
|
42
|
+
export const EditDocumentSchema = z.object({
|
|
43
|
+
sourceDocumentId: z.string().uuid().describe("Document ID of the uploaded file to edit"),
|
|
44
|
+
fileName: z.string().describe("Output file name without extension"),
|
|
45
|
+
instructions: z.string().describe("Detailed description of what changes to make"),
|
|
46
|
+
});
|
|
47
|
+
// ── Text extraction for policy/PII scanning ─────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* Serialize all user-visible text fields from tool call arguments
|
|
50
|
+
* into a single string for content policy and PII evaluation.
|
|
51
|
+
*/
|
|
52
|
+
export function extractTextFromToolArgs(toolName, args) {
|
|
53
|
+
const parts = [];
|
|
54
|
+
switch (toolName) {
|
|
55
|
+
case "create_spreadsheet": {
|
|
56
|
+
const a = args;
|
|
57
|
+
parts.push(a.fileName);
|
|
58
|
+
for (const sheet of a.sheets) {
|
|
59
|
+
parts.push(sheet.name);
|
|
60
|
+
for (const col of sheet.columns) {
|
|
61
|
+
parts.push(col.header);
|
|
62
|
+
}
|
|
63
|
+
for (const row of sheet.rows) {
|
|
64
|
+
for (const cell of row) {
|
|
65
|
+
if (cell != null)
|
|
66
|
+
parts.push(String(cell));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case "create_presentation": {
|
|
73
|
+
const a = args;
|
|
74
|
+
parts.push(a.fileName);
|
|
75
|
+
for (const slide of a.slides) {
|
|
76
|
+
if (slide.title)
|
|
77
|
+
parts.push(slide.title);
|
|
78
|
+
if (slide.subtitle)
|
|
79
|
+
parts.push(slide.subtitle);
|
|
80
|
+
if (slide.body)
|
|
81
|
+
parts.push(...slide.body);
|
|
82
|
+
if (slide.leftColumn)
|
|
83
|
+
parts.push(...slide.leftColumn);
|
|
84
|
+
if (slide.rightColumn)
|
|
85
|
+
parts.push(...slide.rightColumn);
|
|
86
|
+
if (slide.notes)
|
|
87
|
+
parts.push(slide.notes);
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case "create_document": {
|
|
92
|
+
const a = args;
|
|
93
|
+
parts.push(a.fileName);
|
|
94
|
+
parts.push(a.content);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "create_csv": {
|
|
98
|
+
const a = args;
|
|
99
|
+
parts.push(a.fileName);
|
|
100
|
+
parts.push(...a.headers);
|
|
101
|
+
for (const row of a.rows) {
|
|
102
|
+
for (const cell of row) {
|
|
103
|
+
if (cell != null)
|
|
104
|
+
parts.push(String(cell));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case "edit_document": {
|
|
110
|
+
const a = args;
|
|
111
|
+
parts.push(a.fileName);
|
|
112
|
+
parts.push(a.instructions);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
return parts.join(" ");
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=chat-tool-definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-tool-definitions.js","sourceRoot":"","sources":["../../src/services/chat-tool-definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,2EAA2E;AAE3E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;IAC5D,MAAM,EAAE,CAAC,CAAC,KAAK,CACb,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC3C,OAAO,EAAE,CAAC,CAAC,KAAK,CACd,C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AAC,CAAC;gBAC7C,CAAC;YACH,CAAC;YACD,MAAM;QACR,CAAC;QACD,KAAK,eAAe,CAAC,CAAC,CAAC;YACrB,MAAM,CAAC,GAAG,IAAwB,CAAC;YACnC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACvB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;YAC3B,MAAM;QACR,CAAC;QACD;YACE,MAAM;IACV,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-tool-definitions.test.d.ts","sourceRoot":"","sources":["../../src/services/chat-tool-definitions.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { CreateSpreadsheetSchema, CreatePresentationSchema, CreateDocumentSchema, CreateCsvSchema, extractTextFromToolArgs, } from "./chat-tool-definitions.js";
|
|
3
|
+
describe("CreateSpreadsheetSchema", () => {
|
|
4
|
+
it("accepts valid input", () => {
|
|
5
|
+
const input = {
|
|
6
|
+
fileName: "report",
|
|
7
|
+
sheets: [
|
|
8
|
+
{
|
|
9
|
+
name: "Q1",
|
|
10
|
+
columns: [{ header: "Name" }, { header: "Revenue", width: 15 }],
|
|
11
|
+
rows: [["Acme", 1000, true, null]],
|
|
12
|
+
formulas: [{ cell: "B3", formula: "=SUM(B1:B2)" }],
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
expect(CreateSpreadsheetSchema.safeParse(input).success).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it("rejects missing fileName", () => {
|
|
19
|
+
const input = { sheets: [] };
|
|
20
|
+
expect(CreateSpreadsheetSchema.safeParse(input).success).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
it("rejects invalid row cell type", () => {
|
|
23
|
+
const input = {
|
|
24
|
+
fileName: "x",
|
|
25
|
+
sheets: [
|
|
26
|
+
{
|
|
27
|
+
name: "S1",
|
|
28
|
+
columns: [{ header: "A" }],
|
|
29
|
+
rows: [[{ nested: true }]],
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
expect(CreateSpreadsheetSchema.safeParse(input).success).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
describe("CreatePresentationSchema", () => {
|
|
37
|
+
it("accepts valid input with all layout types", () => {
|
|
38
|
+
const input = {
|
|
39
|
+
fileName: "deck",
|
|
40
|
+
slides: [
|
|
41
|
+
{ layout: "title", title: "Hello", subtitle: "World" },
|
|
42
|
+
{ layout: "content", title: "Details", body: ["Point 1", "Point 2"] },
|
|
43
|
+
{ layout: "two-column", leftColumn: ["L1"], rightColumn: ["R1"] },
|
|
44
|
+
{ layout: "blank" },
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
expect(CreatePresentationSchema.safeParse(input).success).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it("rejects invalid layout", () => {
|
|
50
|
+
const input = {
|
|
51
|
+
fileName: "deck",
|
|
52
|
+
slides: [{ layout: "invalid" }],
|
|
53
|
+
};
|
|
54
|
+
expect(CreatePresentationSchema.safeParse(input).success).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe("CreateDocumentSchema", () => {
|
|
58
|
+
it("accepts valid markdown content", () => {
|
|
59
|
+
const input = { fileName: "notes", content: "# Hello\n\nSome text" };
|
|
60
|
+
expect(CreateDocumentSchema.safeParse(input).success).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
it("rejects missing content", () => {
|
|
63
|
+
const input = { fileName: "notes" };
|
|
64
|
+
expect(CreateDocumentSchema.safeParse(input).success).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe("CreateCsvSchema", () => {
|
|
68
|
+
it("accepts valid input with default delimiter", () => {
|
|
69
|
+
const input = {
|
|
70
|
+
fileName: "data",
|
|
71
|
+
headers: ["Name", "Age"],
|
|
72
|
+
rows: [["Alice", 30]],
|
|
73
|
+
};
|
|
74
|
+
const result = CreateCsvSchema.safeParse(input);
|
|
75
|
+
expect(result.success).toBe(true);
|
|
76
|
+
if (result.success) {
|
|
77
|
+
expect(result.data.delimiter).toBe(",");
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
it("accepts custom delimiter", () => {
|
|
81
|
+
const input = {
|
|
82
|
+
fileName: "data",
|
|
83
|
+
headers: ["A"],
|
|
84
|
+
rows: [["x"]],
|
|
85
|
+
delimiter: ";",
|
|
86
|
+
};
|
|
87
|
+
expect(CreateCsvSchema.safeParse(input).success).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe("extractTextFromToolArgs", () => {
|
|
91
|
+
it("extracts text from spreadsheet args", () => {
|
|
92
|
+
const args = {
|
|
93
|
+
fileName: "report",
|
|
94
|
+
sheets: [
|
|
95
|
+
{
|
|
96
|
+
name: "Sheet1",
|
|
97
|
+
columns: [{ header: "Name" }, { header: "Value" }],
|
|
98
|
+
rows: [["Alice", 100], ["Bob", null]],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
const text = extractTextFromToolArgs("create_spreadsheet", args);
|
|
103
|
+
expect(text).toContain("report");
|
|
104
|
+
expect(text).toContain("Sheet1");
|
|
105
|
+
expect(text).toContain("Name");
|
|
106
|
+
expect(text).toContain("Alice");
|
|
107
|
+
expect(text).toContain("100");
|
|
108
|
+
expect(text).not.toContain("null");
|
|
109
|
+
});
|
|
110
|
+
it("extracts text from presentation args", () => {
|
|
111
|
+
const args = {
|
|
112
|
+
fileName: "deck",
|
|
113
|
+
slides: [
|
|
114
|
+
{ layout: "title", title: "Welcome", subtitle: "Intro", notes: "Speaker note" },
|
|
115
|
+
{ layout: "two-column", leftColumn: ["Left item"], rightColumn: ["Right item"] },
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
const text = extractTextFromToolArgs("create_presentation", args);
|
|
119
|
+
expect(text).toContain("deck");
|
|
120
|
+
expect(text).toContain("Welcome");
|
|
121
|
+
expect(text).toContain("Intro");
|
|
122
|
+
expect(text).toContain("Speaker note");
|
|
123
|
+
expect(text).toContain("Left item");
|
|
124
|
+
expect(text).toContain("Right item");
|
|
125
|
+
});
|
|
126
|
+
it("extracts text from document args", () => {
|
|
127
|
+
const args = { fileName: "notes", content: "# Heading\n\nParagraph text" };
|
|
128
|
+
const text = extractTextFromToolArgs("create_document", args);
|
|
129
|
+
expect(text).toContain("notes");
|
|
130
|
+
expect(text).toContain("# Heading");
|
|
131
|
+
expect(text).toContain("Paragraph text");
|
|
132
|
+
});
|
|
133
|
+
it("extracts text from CSV args", () => {
|
|
134
|
+
const args = {
|
|
135
|
+
fileName: "export",
|
|
136
|
+
headers: ["City", "Pop"],
|
|
137
|
+
rows: [["London", 9000000], ["Paris", null]],
|
|
138
|
+
delimiter: ",",
|
|
139
|
+
};
|
|
140
|
+
const text = extractTextFromToolArgs("create_csv", args);
|
|
141
|
+
expect(text).toContain("export");
|
|
142
|
+
expect(text).toContain("City");
|
|
143
|
+
expect(text).toContain("London");
|
|
144
|
+
expect(text).toContain("9000000");
|
|
145
|
+
});
|
|
146
|
+
it("returns empty string for unknown tool", () => {
|
|
147
|
+
expect(extractTextFromToolArgs("unknown_tool", {})).toBe("");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=chat-tool-definitions.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-tool-definitions.test.js","sourceRoot":"","sources":["../../src/services/chat-tool-definitions.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,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,CAAC,MAAM,EAAE,KAAK,CAAC;YACxB,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC5C,SAAS,EAAE,GAAG;SACf,CAAC;QACF,MAAM,IAAI,GAAG,uBAAuB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QACzD,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,CAAC,uBAAuB,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { PrismaClient } from "@prisma/client";
|
|
2
|
+
import { type TenantContext } from "../db/tenant.js";
|
|
3
|
+
import type { NodeService } from "./node-service.js";
|
|
4
|
+
import type { EdgeService } from "./edge-service.js";
|
|
5
|
+
import type { TagService } from "./tag-service.js";
|
|
6
|
+
export interface SimilarityPair {
|
|
7
|
+
nodeAId: string;
|
|
8
|
+
nodeBId: string;
|
|
9
|
+
similarity: number;
|
|
10
|
+
}
|
|
11
|
+
export interface MergeCluster {
|
|
12
|
+
nodeIds: string[];
|
|
13
|
+
minSimilarity: number;
|
|
14
|
+
avgSimilarity: number;
|
|
15
|
+
topicLabel: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ScanResult {
|
|
18
|
+
proposalIds: string[];
|
|
19
|
+
clustersFound: number;
|
|
20
|
+
nodesScanned: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MergeResult {
|
|
23
|
+
mergedNodeId: string;
|
|
24
|
+
archivedNodeIds: string[];
|
|
25
|
+
edgesTransferred: number;
|
|
26
|
+
}
|
|
27
|
+
export declare class DedupService {
|
|
28
|
+
private db;
|
|
29
|
+
private tenantCtx;
|
|
30
|
+
constructor(db: PrismaClient, tenantCtx?: TenantContext);
|
|
31
|
+
/**
|
|
32
|
+
* Scan chat nodes for similarity clusters and create merge proposals.
|
|
33
|
+
*/
|
|
34
|
+
scanChatNodes(opts: {
|
|
35
|
+
threshold?: number;
|
|
36
|
+
limit?: number;
|
|
37
|
+
createdBy: string;
|
|
38
|
+
llmLabeler?: (titles: string[]) => Promise<string>;
|
|
39
|
+
}): Promise<ScanResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Union-find clustering of similarity pairs.
|
|
42
|
+
* Returns clusters with min/avg similarity.
|
|
43
|
+
*/
|
|
44
|
+
computeClusters(pairs: SimilarityPair[]): MergeCluster[];
|
|
45
|
+
/**
|
|
46
|
+
* List merge proposals with optional status filter and pagination.
|
|
47
|
+
*/
|
|
48
|
+
listProposals(opts?: {
|
|
49
|
+
status?: string;
|
|
50
|
+
limit?: number;
|
|
51
|
+
offset?: number;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
proposals: any[];
|
|
54
|
+
total: number;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Get a single proposal with full source node data.
|
|
58
|
+
*/
|
|
59
|
+
getProposal(id: string): Promise<{
|
|
60
|
+
sourceNodes: {
|
|
61
|
+
id: string;
|
|
62
|
+
metadata: import("@prisma/client/runtime/library").JsonValue;
|
|
63
|
+
createdAt: Date;
|
|
64
|
+
type: string;
|
|
65
|
+
title: string;
|
|
66
|
+
content: string;
|
|
67
|
+
status: string;
|
|
68
|
+
createdBy: string;
|
|
69
|
+
updatedAt: Date;
|
|
70
|
+
version: number;
|
|
71
|
+
hasPii: boolean;
|
|
72
|
+
embeddingPiiMode: string | null;
|
|
73
|
+
domainId: string | null;
|
|
74
|
+
organizationId: string;
|
|
75
|
+
}[];
|
|
76
|
+
id: string;
|
|
77
|
+
metadata: import("@prisma/client/runtime/library").JsonValue;
|
|
78
|
+
createdAt: Date;
|
|
79
|
+
status: string;
|
|
80
|
+
createdBy: string;
|
|
81
|
+
organizationId: string;
|
|
82
|
+
topicLabel: string;
|
|
83
|
+
sourceNodeIds: string[];
|
|
84
|
+
mergedNodeId: string | null;
|
|
85
|
+
similarity: number;
|
|
86
|
+
resolvedBy: string | null;
|
|
87
|
+
resolvedAt: Date | null;
|
|
88
|
+
} | null>;
|
|
89
|
+
/**
|
|
90
|
+
* Update proposal status with transition validation.
|
|
91
|
+
* Allowed: pending→approved, pending→rejected, approved→merged.
|
|
92
|
+
*/
|
|
93
|
+
updateProposalStatus(id: string, status: string, resolvedBy: string): Promise<{
|
|
94
|
+
id: string;
|
|
95
|
+
metadata: import("@prisma/client/runtime/library").JsonValue;
|
|
96
|
+
createdAt: Date;
|
|
97
|
+
status: string;
|
|
98
|
+
createdBy: string;
|
|
99
|
+
organizationId: string;
|
|
100
|
+
topicLabel: string;
|
|
101
|
+
sourceNodeIds: string[];
|
|
102
|
+
mergedNodeId: string | null;
|
|
103
|
+
similarity: number;
|
|
104
|
+
resolvedBy: string | null;
|
|
105
|
+
resolvedAt: Date | null;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* Execute a merge: create merged node, transfer edges, archive sources.
|
|
109
|
+
*/
|
|
110
|
+
executeMerge(proposalId: string, opts: {
|
|
111
|
+
mergedBy: string;
|
|
112
|
+
nodeService: NodeService;
|
|
113
|
+
edgeService: EdgeService;
|
|
114
|
+
title?: string;
|
|
115
|
+
content?: string;
|
|
116
|
+
llmSummarizer?: (contents: string[]) => Promise<string>;
|
|
117
|
+
}): Promise<MergeResult>;
|
|
118
|
+
/**
|
|
119
|
+
* Mark a node as canonical by applying the `canonical` tag.
|
|
120
|
+
*/
|
|
121
|
+
markCanonical(nodeId: string, tagService: TagService, taggedBy: string): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Remove canonical tag from a node.
|
|
124
|
+
*/
|
|
125
|
+
removeCanonical(nodeId: string): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Find similarity pairs among chat nodes using the embedding self-join.
|
|
128
|
+
* Scoped to nodes with capturedFromSession metadata.
|
|
129
|
+
*/
|
|
130
|
+
private findChatSimilarityPairs;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=dedup-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedup-service.d.ts","sourceRoot":"","sources":["../../src/services/dedup-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EA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