@ordinatio/entities 1.0.3 → 1.1.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/README.md +4 -0
- package/dist/{chunk-QXBSEBJW.mjs → chunk-WWGAALKG.mjs} +32 -26
- package/dist/index.d.mts +1509 -0
- package/dist/index.mjs +51 -6
- package/dist/{observer-YUTEGG4S.mjs → observer-2GIY55TX.mjs} +1 -1
- package/dist/tags/index.d.mts +78 -0
- package/dist/tags/index.mjs +66 -0
- package/package.json +19 -21
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1509 @@
|
|
|
1
|
+
import * as _ordinatio_errors from '@ordinatio/errors';
|
|
2
|
+
import * as _prisma_client from '@prisma/client';
|
|
3
|
+
import { PrismaClient, Prisma, ContactSource } from '@prisma/client';
|
|
4
|
+
export { ContactSource, PrismaClient } from '@prisma/client';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import * as _prisma_client_runtime_client from '@prisma/client/runtime/client';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Callbacks injected by the consuming app for side effects.
|
|
10
|
+
* All optional — package works without them.
|
|
11
|
+
*/
|
|
12
|
+
interface MutationCallbacks {
|
|
13
|
+
logActivity?: (action: string, description: string, data?: Record<string, unknown>) => Promise<void>;
|
|
14
|
+
emitEvent?: (type: string, data: unknown) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Provides seed data for the agent knowledge base.
|
|
18
|
+
* Passed by the app so the package doesn't need app-specific data.
|
|
19
|
+
*/
|
|
20
|
+
interface SeedDataProvider {
|
|
21
|
+
getKnowledgeSeedData?: () => Array<{
|
|
22
|
+
entity: string;
|
|
23
|
+
field: string;
|
|
24
|
+
value: string;
|
|
25
|
+
label: string;
|
|
26
|
+
aliases: string[];
|
|
27
|
+
category: string | null;
|
|
28
|
+
metadata: Record<string, unknown> | null;
|
|
29
|
+
sortOrder: number;
|
|
30
|
+
source: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Callback for writing structured knowledge fields from notes.
|
|
35
|
+
*/
|
|
36
|
+
interface NoteKnowledgeCallbacks extends MutationCallbacks {
|
|
37
|
+
setEntityFields?: (entityType: string, entityId: string, fields: Record<string, unknown>, source: string, sourceId?: string, confidence?: number, setBy?: string) => Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Callback for human-in-the-loop validation of low-confidence writes.
|
|
41
|
+
*/
|
|
42
|
+
interface ValidationCallbacks {
|
|
43
|
+
requestValidation?: (entityType: string, entityId: string, field: string, value: unknown, confidence: number, existingValue?: unknown, existingConfidence?: number) => Promise<'accept' | 'reject' | 'defer'>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Constraint declared on a field definition.
|
|
47
|
+
* Evaluated after every setEntityFields(). Advisory only — writes not blocked.
|
|
48
|
+
*/
|
|
49
|
+
interface FieldConstraint {
|
|
50
|
+
targetField: string;
|
|
51
|
+
operator: 'not_in' | 'in' | 'not_equal' | 'less_than' | 'greater_than' | 'regex';
|
|
52
|
+
values?: unknown[];
|
|
53
|
+
value?: unknown;
|
|
54
|
+
pattern?: string;
|
|
55
|
+
message: string;
|
|
56
|
+
severity: 'warning' | 'error';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Result of a constraint violation check.
|
|
60
|
+
*/
|
|
61
|
+
interface ConstraintViolation {
|
|
62
|
+
fieldKey: string;
|
|
63
|
+
constraintField: string;
|
|
64
|
+
operator: string;
|
|
65
|
+
actualValue: unknown;
|
|
66
|
+
constraintValue: unknown;
|
|
67
|
+
message: string;
|
|
68
|
+
severity: 'warning' | 'error';
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Extended callbacks for observer-aware mutations.
|
|
72
|
+
*/
|
|
73
|
+
interface ObserverCallbacks extends MutationCallbacks {
|
|
74
|
+
onConstraintViolation?: (entityType: string, entityId: string, violations: ConstraintViolation[]) => Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Entity health report — aggregates completeness, freshness, conflicts, truth.
|
|
78
|
+
*/
|
|
79
|
+
interface EntityHealthReport {
|
|
80
|
+
entityType: string;
|
|
81
|
+
entityId: string;
|
|
82
|
+
completeness: number;
|
|
83
|
+
freshness: number;
|
|
84
|
+
conflictRate: number;
|
|
85
|
+
truthAverage: number;
|
|
86
|
+
overallScore: number;
|
|
87
|
+
staleFieldCount: number;
|
|
88
|
+
conflictCount: number;
|
|
89
|
+
filledFieldCount: number;
|
|
90
|
+
totalFieldCount: number;
|
|
91
|
+
warnings: string[];
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Summary of health across all entities of a type.
|
|
95
|
+
*/
|
|
96
|
+
interface EntityTypeHealthSummary {
|
|
97
|
+
entityType: string;
|
|
98
|
+
entityCount: number;
|
|
99
|
+
avgCompleteness: number;
|
|
100
|
+
avgFreshness: number;
|
|
101
|
+
avgConflictRate: number;
|
|
102
|
+
avgOverallScore: number;
|
|
103
|
+
worstEntities: Array<{
|
|
104
|
+
entityId: string;
|
|
105
|
+
overallScore: number;
|
|
106
|
+
}>;
|
|
107
|
+
bestEntities: Array<{
|
|
108
|
+
entityId: string;
|
|
109
|
+
overallScore: number;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface ErrorDiagnosis {
|
|
114
|
+
step: string;
|
|
115
|
+
check: string;
|
|
116
|
+
}
|
|
117
|
+
interface KnowledgeErrorDef {
|
|
118
|
+
code: string;
|
|
119
|
+
file: string;
|
|
120
|
+
function: string;
|
|
121
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
122
|
+
recoverable: boolean;
|
|
123
|
+
description: string;
|
|
124
|
+
diagnosis: ErrorDiagnosis[];
|
|
125
|
+
}
|
|
126
|
+
interface AgentKnowledgeErrorEntry {
|
|
127
|
+
code: string;
|
|
128
|
+
file: string;
|
|
129
|
+
function: string;
|
|
130
|
+
httpStatus: number;
|
|
131
|
+
severity: 'warning' | 'error' | 'critical';
|
|
132
|
+
recoverable: boolean;
|
|
133
|
+
description: string;
|
|
134
|
+
diagnosis: string[];
|
|
135
|
+
}
|
|
136
|
+
declare const KNOWLEDGE_ERRORS: Record<string, KnowledgeErrorDef>;
|
|
137
|
+
declare const AGENTKNOW_ERRORS: Record<string, AgentKnowledgeErrorEntry>;
|
|
138
|
+
|
|
139
|
+
declare function knowledgeError(code: string, context?: Record<string, unknown>): _ordinatio_errors.OrdinatioError;
|
|
140
|
+
declare function agentKnowledgeError(code: string, context?: Record<string, unknown>): _ordinatio_errors.OrdinatioError;
|
|
141
|
+
declare class ContactNotFoundError extends Error {
|
|
142
|
+
constructor(id: string);
|
|
143
|
+
}
|
|
144
|
+
declare class ContactExistsError extends Error {
|
|
145
|
+
constructor(email: string);
|
|
146
|
+
}
|
|
147
|
+
declare class ContactAlreadyConvertedError extends Error {
|
|
148
|
+
constructor(id: string);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
declare const ENTITY_TYPES: readonly ["client", "contact", "order"];
|
|
152
|
+
declare const FIELD_DATA_TYPES: readonly ["text", "number", "date", "boolean", "enum", "multi-select"];
|
|
153
|
+
declare const FIELD_STATUSES: readonly ["suggested", "approved", "dismissed", "merged"];
|
|
154
|
+
declare const LEDGER_SOURCES: readonly ["manual", "note", "email", "agent", "ai-batch", "predicted"];
|
|
155
|
+
declare const SEARCH_SOURCES: readonly ["search_bar", "agent_chat", "api"];
|
|
156
|
+
declare const CreateFieldDefinitionSchema: z.ZodObject<{
|
|
157
|
+
entityType: z.ZodEnum<{
|
|
158
|
+
client: "client";
|
|
159
|
+
contact: "contact";
|
|
160
|
+
order: "order";
|
|
161
|
+
}>;
|
|
162
|
+
key: z.ZodString;
|
|
163
|
+
label: z.ZodString;
|
|
164
|
+
dataType: z.ZodEnum<{
|
|
165
|
+
number: "number";
|
|
166
|
+
boolean: "boolean";
|
|
167
|
+
text: "text";
|
|
168
|
+
date: "date";
|
|
169
|
+
enum: "enum";
|
|
170
|
+
"multi-select": "multi-select";
|
|
171
|
+
}>;
|
|
172
|
+
category: z.ZodString;
|
|
173
|
+
enumOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
174
|
+
extractionHint: z.ZodOptional<z.ZodString>;
|
|
175
|
+
sortOrder: z.ZodDefault<z.ZodNumber>;
|
|
176
|
+
halfLifeDays: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
177
|
+
}, z.core.$strip>;
|
|
178
|
+
type CreateFieldDefinitionInput = z.infer<typeof CreateFieldDefinitionSchema>;
|
|
179
|
+
declare const UpdateFieldDefinitionSchema: z.ZodObject<{
|
|
180
|
+
label: z.ZodOptional<z.ZodString>;
|
|
181
|
+
category: z.ZodOptional<z.ZodString>;
|
|
182
|
+
enumOptions: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
183
|
+
extractionHint: z.ZodOptional<z.ZodString>;
|
|
184
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
185
|
+
suggested: "suggested";
|
|
186
|
+
approved: "approved";
|
|
187
|
+
dismissed: "dismissed";
|
|
188
|
+
merged: "merged";
|
|
189
|
+
}>>;
|
|
190
|
+
mergedIntoId: z.ZodOptional<z.ZodString>;
|
|
191
|
+
sortOrder: z.ZodOptional<z.ZodNumber>;
|
|
192
|
+
isActive: z.ZodOptional<z.ZodBoolean>;
|
|
193
|
+
halfLifeDays: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
194
|
+
constraints: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
195
|
+
targetField: z.ZodString;
|
|
196
|
+
operator: z.ZodEnum<{
|
|
197
|
+
not_in: "not_in";
|
|
198
|
+
in: "in";
|
|
199
|
+
not_equal: "not_equal";
|
|
200
|
+
less_than: "less_than";
|
|
201
|
+
greater_than: "greater_than";
|
|
202
|
+
regex: "regex";
|
|
203
|
+
}>;
|
|
204
|
+
values: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
205
|
+
value: z.ZodOptional<z.ZodUnknown>;
|
|
206
|
+
pattern: z.ZodOptional<z.ZodString>;
|
|
207
|
+
message: z.ZodString;
|
|
208
|
+
severity: z.ZodEnum<{
|
|
209
|
+
warning: "warning";
|
|
210
|
+
error: "error";
|
|
211
|
+
}>;
|
|
212
|
+
}, z.core.$strip>>>>;
|
|
213
|
+
}, z.core.$strip>;
|
|
214
|
+
type UpdateFieldDefinitionInput = z.infer<typeof UpdateFieldDefinitionSchema>;
|
|
215
|
+
declare const ListFieldDefinitionsQuery: z.ZodObject<{
|
|
216
|
+
entityType: z.ZodOptional<z.ZodEnum<{
|
|
217
|
+
client: "client";
|
|
218
|
+
contact: "contact";
|
|
219
|
+
order: "order";
|
|
220
|
+
}>>;
|
|
221
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
222
|
+
suggested: "suggested";
|
|
223
|
+
approved: "approved";
|
|
224
|
+
dismissed: "dismissed";
|
|
225
|
+
merged: "merged";
|
|
226
|
+
}>>;
|
|
227
|
+
}, z.core.$strip>;
|
|
228
|
+
type ListFieldDefinitionsQueryInput = z.infer<typeof ListFieldDefinitionsQuery>;
|
|
229
|
+
declare const SetEntityFieldsSchema: z.ZodObject<{
|
|
230
|
+
fields: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
231
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
232
|
+
manual: "manual";
|
|
233
|
+
note: "note";
|
|
234
|
+
email: "email";
|
|
235
|
+
agent: "agent";
|
|
236
|
+
"ai-batch": "ai-batch";
|
|
237
|
+
predicted: "predicted";
|
|
238
|
+
}>>;
|
|
239
|
+
sourceId: z.ZodOptional<z.ZodString>;
|
|
240
|
+
confidence: z.ZodDefault<z.ZodNumber>;
|
|
241
|
+
}, z.core.$strip>;
|
|
242
|
+
type SetEntityFieldsInput = z.infer<typeof SetEntityFieldsSchema>;
|
|
243
|
+
declare const SearchByFieldsSchema: z.ZodObject<{
|
|
244
|
+
entityType: z.ZodEnum<{
|
|
245
|
+
client: "client";
|
|
246
|
+
contact: "contact";
|
|
247
|
+
order: "order";
|
|
248
|
+
}>;
|
|
249
|
+
filters: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
250
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
251
|
+
}, z.core.$strip>;
|
|
252
|
+
type SearchByFieldsInput = z.infer<typeof SearchByFieldsSchema>;
|
|
253
|
+
declare const LogSearchQuerySchema: z.ZodObject<{
|
|
254
|
+
query: z.ZodString;
|
|
255
|
+
source: z.ZodEnum<{
|
|
256
|
+
search_bar: "search_bar";
|
|
257
|
+
agent_chat: "agent_chat";
|
|
258
|
+
api: "api";
|
|
259
|
+
}>;
|
|
260
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
261
|
+
entityType: z.ZodOptional<z.ZodEnum<{
|
|
262
|
+
client: "client";
|
|
263
|
+
contact: "contact";
|
|
264
|
+
order: "order";
|
|
265
|
+
}>>;
|
|
266
|
+
resultCount: z.ZodOptional<z.ZodNumber>;
|
|
267
|
+
}, z.core.$strip>;
|
|
268
|
+
type LogSearchQueryInput = z.infer<typeof LogSearchQuerySchema>;
|
|
269
|
+
declare const FieldHistoryQuery: z.ZodObject<{
|
|
270
|
+
fieldId: z.ZodOptional<z.ZodString>;
|
|
271
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
272
|
+
}, z.core.$strip>;
|
|
273
|
+
type FieldHistoryQueryInput = z.infer<typeof FieldHistoryQuery>;
|
|
274
|
+
|
|
275
|
+
declare function getFieldDefinitions(db: PrismaClient, entityType?: string, status?: string): Promise<{
|
|
276
|
+
fields: {
|
|
277
|
+
entityType: string;
|
|
278
|
+
key: string;
|
|
279
|
+
label: string;
|
|
280
|
+
dataType: string;
|
|
281
|
+
category: string;
|
|
282
|
+
enumOptions: Prisma.JsonValue | null;
|
|
283
|
+
extractionHint: string | null;
|
|
284
|
+
sortOrder: number;
|
|
285
|
+
halfLifeDays: number | null;
|
|
286
|
+
status: string;
|
|
287
|
+
mergedIntoId: string | null;
|
|
288
|
+
isActive: boolean;
|
|
289
|
+
constraints: Prisma.JsonValue | null;
|
|
290
|
+
id: string;
|
|
291
|
+
suggestedFrom: string | null;
|
|
292
|
+
occurrenceCount: number;
|
|
293
|
+
createdAt: Date;
|
|
294
|
+
updatedAt: Date;
|
|
295
|
+
}[];
|
|
296
|
+
grouped: Record<string, {
|
|
297
|
+
entityType: string;
|
|
298
|
+
key: string;
|
|
299
|
+
label: string;
|
|
300
|
+
dataType: string;
|
|
301
|
+
category: string;
|
|
302
|
+
enumOptions: Prisma.JsonValue | null;
|
|
303
|
+
extractionHint: string | null;
|
|
304
|
+
sortOrder: number;
|
|
305
|
+
halfLifeDays: number | null;
|
|
306
|
+
status: string;
|
|
307
|
+
mergedIntoId: string | null;
|
|
308
|
+
isActive: boolean;
|
|
309
|
+
constraints: Prisma.JsonValue | null;
|
|
310
|
+
id: string;
|
|
311
|
+
suggestedFrom: string | null;
|
|
312
|
+
occurrenceCount: number;
|
|
313
|
+
createdAt: Date;
|
|
314
|
+
updatedAt: Date;
|
|
315
|
+
}[]>;
|
|
316
|
+
}>;
|
|
317
|
+
declare function createFieldDefinition(db: PrismaClient, input: CreateFieldDefinitionInput, callbacks?: MutationCallbacks): Promise<{
|
|
318
|
+
entityType: string;
|
|
319
|
+
key: string;
|
|
320
|
+
label: string;
|
|
321
|
+
dataType: string;
|
|
322
|
+
category: string;
|
|
323
|
+
enumOptions: Prisma.JsonValue | null;
|
|
324
|
+
extractionHint: string | null;
|
|
325
|
+
sortOrder: number;
|
|
326
|
+
halfLifeDays: number | null;
|
|
327
|
+
status: string;
|
|
328
|
+
mergedIntoId: string | null;
|
|
329
|
+
isActive: boolean;
|
|
330
|
+
constraints: Prisma.JsonValue | null;
|
|
331
|
+
id: string;
|
|
332
|
+
suggestedFrom: string | null;
|
|
333
|
+
occurrenceCount: number;
|
|
334
|
+
createdAt: Date;
|
|
335
|
+
updatedAt: Date;
|
|
336
|
+
}>;
|
|
337
|
+
declare function updateFieldDefinition(db: PrismaClient, id: string, input: UpdateFieldDefinitionInput, callbacks?: MutationCallbacks): Promise<{
|
|
338
|
+
entityType: string;
|
|
339
|
+
key: string;
|
|
340
|
+
label: string;
|
|
341
|
+
dataType: string;
|
|
342
|
+
category: string;
|
|
343
|
+
enumOptions: Prisma.JsonValue | null;
|
|
344
|
+
extractionHint: string | null;
|
|
345
|
+
sortOrder: number;
|
|
346
|
+
halfLifeDays: number | null;
|
|
347
|
+
status: string;
|
|
348
|
+
mergedIntoId: string | null;
|
|
349
|
+
isActive: boolean;
|
|
350
|
+
constraints: Prisma.JsonValue | null;
|
|
351
|
+
id: string;
|
|
352
|
+
suggestedFrom: string | null;
|
|
353
|
+
occurrenceCount: number;
|
|
354
|
+
createdAt: Date;
|
|
355
|
+
updatedAt: Date;
|
|
356
|
+
} | null>;
|
|
357
|
+
declare function getFieldDefinitionById(db: PrismaClient, id: string): Promise<{
|
|
358
|
+
entityType: string;
|
|
359
|
+
key: string;
|
|
360
|
+
label: string;
|
|
361
|
+
dataType: string;
|
|
362
|
+
category: string;
|
|
363
|
+
enumOptions: Prisma.JsonValue | null;
|
|
364
|
+
extractionHint: string | null;
|
|
365
|
+
sortOrder: number;
|
|
366
|
+
halfLifeDays: number | null;
|
|
367
|
+
status: string;
|
|
368
|
+
mergedIntoId: string | null;
|
|
369
|
+
isActive: boolean;
|
|
370
|
+
constraints: Prisma.JsonValue | null;
|
|
371
|
+
id: string;
|
|
372
|
+
suggestedFrom: string | null;
|
|
373
|
+
occurrenceCount: number;
|
|
374
|
+
createdAt: Date;
|
|
375
|
+
updatedAt: Date;
|
|
376
|
+
} | null>;
|
|
377
|
+
|
|
378
|
+
declare function getEntityFields(db: PrismaClient, entityType: string, entityId: string): Promise<{
|
|
379
|
+
entries: ({
|
|
380
|
+
field: {
|
|
381
|
+
entityType: string;
|
|
382
|
+
key: string;
|
|
383
|
+
label: string;
|
|
384
|
+
dataType: string;
|
|
385
|
+
category: string;
|
|
386
|
+
enumOptions: _prisma_client_runtime_client.JsonValue | null;
|
|
387
|
+
extractionHint: string | null;
|
|
388
|
+
sortOrder: number;
|
|
389
|
+
halfLifeDays: number | null;
|
|
390
|
+
status: string;
|
|
391
|
+
mergedIntoId: string | null;
|
|
392
|
+
isActive: boolean;
|
|
393
|
+
constraints: _prisma_client_runtime_client.JsonValue | null;
|
|
394
|
+
id: string;
|
|
395
|
+
suggestedFrom: string | null;
|
|
396
|
+
occurrenceCount: number;
|
|
397
|
+
createdAt: Date;
|
|
398
|
+
updatedAt: Date;
|
|
399
|
+
};
|
|
400
|
+
} & {
|
|
401
|
+
entityType: string;
|
|
402
|
+
value: _prisma_client_runtime_client.JsonValue;
|
|
403
|
+
source: string;
|
|
404
|
+
sourceId: string | null;
|
|
405
|
+
confidence: _prisma_client_runtime_client.Decimal;
|
|
406
|
+
fieldId: string;
|
|
407
|
+
id: string;
|
|
408
|
+
createdAt: Date;
|
|
409
|
+
entityId: string;
|
|
410
|
+
setBy: string | null;
|
|
411
|
+
supersededAt: Date | null;
|
|
412
|
+
})[];
|
|
413
|
+
grouped: Record<string, {
|
|
414
|
+
fieldId: string;
|
|
415
|
+
key: string;
|
|
416
|
+
label: string;
|
|
417
|
+
dataType: string;
|
|
418
|
+
category: string;
|
|
419
|
+
value: unknown;
|
|
420
|
+
confidence: number;
|
|
421
|
+
source: string;
|
|
422
|
+
updatedAt: Date;
|
|
423
|
+
}[]>;
|
|
424
|
+
}>;
|
|
425
|
+
declare function setEntityFields(db: PrismaClient, entityType: string, entityId: string, fields: Record<string, unknown>, source: string, sourceId?: string, confidence?: number, setBy?: string, callbacks?: MutationCallbacks): Promise<{
|
|
426
|
+
written: {
|
|
427
|
+
key: string;
|
|
428
|
+
entryId: string;
|
|
429
|
+
}[];
|
|
430
|
+
skipped: string[];
|
|
431
|
+
}>;
|
|
432
|
+
declare function getFieldHistory(db: PrismaClient, entityType: string, entityId: string, fieldId?: string, limit?: number): Promise<({
|
|
433
|
+
field: {
|
|
434
|
+
entityType: string;
|
|
435
|
+
key: string;
|
|
436
|
+
label: string;
|
|
437
|
+
dataType: string;
|
|
438
|
+
category: string;
|
|
439
|
+
enumOptions: _prisma_client_runtime_client.JsonValue | null;
|
|
440
|
+
extractionHint: string | null;
|
|
441
|
+
sortOrder: number;
|
|
442
|
+
halfLifeDays: number | null;
|
|
443
|
+
status: string;
|
|
444
|
+
mergedIntoId: string | null;
|
|
445
|
+
isActive: boolean;
|
|
446
|
+
constraints: _prisma_client_runtime_client.JsonValue | null;
|
|
447
|
+
id: string;
|
|
448
|
+
suggestedFrom: string | null;
|
|
449
|
+
occurrenceCount: number;
|
|
450
|
+
createdAt: Date;
|
|
451
|
+
updatedAt: Date;
|
|
452
|
+
};
|
|
453
|
+
} & {
|
|
454
|
+
entityType: string;
|
|
455
|
+
value: _prisma_client_runtime_client.JsonValue;
|
|
456
|
+
source: string;
|
|
457
|
+
sourceId: string | null;
|
|
458
|
+
confidence: _prisma_client_runtime_client.Decimal;
|
|
459
|
+
fieldId: string;
|
|
460
|
+
id: string;
|
|
461
|
+
createdAt: Date;
|
|
462
|
+
entityId: string;
|
|
463
|
+
setBy: string | null;
|
|
464
|
+
supersededAt: Date | null;
|
|
465
|
+
})[]>;
|
|
466
|
+
|
|
467
|
+
declare function searchByFields(db: PrismaClient, entityType: string, filters: Record<string, unknown>, limit?: number): Promise<{
|
|
468
|
+
entityIds: string[];
|
|
469
|
+
total: number;
|
|
470
|
+
}>;
|
|
471
|
+
declare function logSearchQuery(db: PrismaClient, input: LogSearchQueryInput): Promise<void>;
|
|
472
|
+
declare function getWeekOfYear(date: Date): number;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Reconstruct entity state at a point in time.
|
|
476
|
+
* Finds entries that were active at `timestamp`:
|
|
477
|
+
* createdAt <= timestamp AND (supersededAt IS NULL OR supersededAt > timestamp)
|
|
478
|
+
* Groups by field key, takes most recent entry per field.
|
|
479
|
+
*/
|
|
480
|
+
declare function getKnowledgeAt(db: PrismaClient, entityType: string, entityId: string, timestamp: Date): Promise<{
|
|
481
|
+
fields: Record<string, {
|
|
482
|
+
value: unknown;
|
|
483
|
+
confidence: number;
|
|
484
|
+
source: string;
|
|
485
|
+
setAt: Date;
|
|
486
|
+
}>;
|
|
487
|
+
}>;
|
|
488
|
+
/**
|
|
489
|
+
* Single field value at a point in time.
|
|
490
|
+
*/
|
|
491
|
+
declare function getFieldValueAt(db: PrismaClient, entityType: string, entityId: string, fieldKey: string, timestamp: Date): Promise<{
|
|
492
|
+
value: unknown;
|
|
493
|
+
confidence: number;
|
|
494
|
+
source: string;
|
|
495
|
+
setAt: Date;
|
|
496
|
+
} | null>;
|
|
497
|
+
/**
|
|
498
|
+
* Timeline of all changes within a date range.
|
|
499
|
+
*/
|
|
500
|
+
declare function getKnowledgeTimeline(db: PrismaClient, entityType: string, entityId: string, from: Date, to: Date, limit?: number): Promise<Array<{
|
|
501
|
+
fieldKey: string;
|
|
502
|
+
value: unknown;
|
|
503
|
+
confidence: number;
|
|
504
|
+
source: string;
|
|
505
|
+
createdAt: Date;
|
|
506
|
+
supersededAt: Date | null;
|
|
507
|
+
}>>;
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Source reliability weights.
|
|
511
|
+
* Higher = more trustworthy.
|
|
512
|
+
*/
|
|
513
|
+
declare const SOURCE_RELIABILITY: Record<string, number>;
|
|
514
|
+
/**
|
|
515
|
+
* Recency factor: 1.0 for today, decays exponentially toward 0.
|
|
516
|
+
* Uses formula: exp(-age_days / maxAgeDays × 3) — reaches ~0.05 at maxAgeDays.
|
|
517
|
+
*/
|
|
518
|
+
declare function computeRecencyFactor(createdAt: Date, now?: Date, maxAgeDays?: number): number;
|
|
519
|
+
/**
|
|
520
|
+
* Truth Score: weighted average of assertions.
|
|
521
|
+
* T_v = Σ(C_i × R_i × T_i) / Σ(C_i × R_i)
|
|
522
|
+
* where C_i = confidence, R_i = source reliability, T_i = recency
|
|
523
|
+
*
|
|
524
|
+
* Returns 0 if no assertions.
|
|
525
|
+
*/
|
|
526
|
+
declare function computeTruthScore(assertions: Array<{
|
|
527
|
+
confidence: number;
|
|
528
|
+
source: string;
|
|
529
|
+
createdAt: Date;
|
|
530
|
+
supersededAt: Date | null;
|
|
531
|
+
}>, now?: Date): number;
|
|
532
|
+
/**
|
|
533
|
+
* Entity complexity score: how "filled" is the entity's knowledge.
|
|
534
|
+
* Weighted: 60% category coverage + 40% field coverage.
|
|
535
|
+
*/
|
|
536
|
+
declare function computeComplexityScore(fieldsUsed: number, fieldsAvailable: number, categoriesUsed: number, maxCategories: number): number;
|
|
537
|
+
/**
|
|
538
|
+
* Compute truth scores for all current (non-superseded) fields on an entity.
|
|
539
|
+
* DB wrapper that reads ledger entries + their history for truth calculation.
|
|
540
|
+
*/
|
|
541
|
+
declare function computeEntityTruthScores(db: PrismaClient, entityType: string, entityId: string): Promise<Record<string, {
|
|
542
|
+
truthScore: number;
|
|
543
|
+
confidence: number;
|
|
544
|
+
source: string;
|
|
545
|
+
assertions: number;
|
|
546
|
+
}>>;
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Pure exponential decay: C_decayed = C_original × 0.5^(age_days / halfLifeDays)
|
|
550
|
+
*/
|
|
551
|
+
declare function computeDecayedConfidence(originalConfidence: number, createdAt: Date, halfLifeDays: number, now?: Date): number;
|
|
552
|
+
/**
|
|
553
|
+
* Is the decayed confidence below threshold?
|
|
554
|
+
*/
|
|
555
|
+
declare function isStale(originalConfidence: number, createdAt: Date, halfLifeDays: number, threshold?: number, now?: Date): boolean;
|
|
556
|
+
/**
|
|
557
|
+
* Get all stale fields for an entity.
|
|
558
|
+
* Only checks fields whose definitions have a non-null halfLifeDays.
|
|
559
|
+
*/
|
|
560
|
+
declare function getStaleFields(db: PrismaClient, entityType: string, entityId: string, threshold?: number): Promise<Array<{
|
|
561
|
+
fieldKey: string;
|
|
562
|
+
label: string;
|
|
563
|
+
originalConfidence: number;
|
|
564
|
+
decayedConfidence: number;
|
|
565
|
+
halfLifeDays: number;
|
|
566
|
+
lastUpdated: Date;
|
|
567
|
+
staleSinceDays: number;
|
|
568
|
+
}>>;
|
|
569
|
+
/**
|
|
570
|
+
* Agent-friendly staleness warnings.
|
|
571
|
+
*/
|
|
572
|
+
declare function formatStalenessWarnings(staleFields: Array<{
|
|
573
|
+
fieldKey: string;
|
|
574
|
+
label: string;
|
|
575
|
+
decayedConfidence: number;
|
|
576
|
+
staleSinceDays: number;
|
|
577
|
+
}>): string[];
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Should this write be validated?
|
|
581
|
+
* Returns 'validate' when confidence is below threshold
|
|
582
|
+
* AND there's an existing higher-confidence value.
|
|
583
|
+
*/
|
|
584
|
+
declare function shouldBranch(newConfidence: number, existingConfidence?: number, threshold?: number): 'proceed' | 'validate';
|
|
585
|
+
/**
|
|
586
|
+
* Set fields with branching logic.
|
|
587
|
+
* When confidence is low and existing data has higher confidence,
|
|
588
|
+
* requests human validation before writing.
|
|
589
|
+
*/
|
|
590
|
+
declare function setEntityFieldsWithBranching(db: PrismaClient, entityType: string, entityId: string, fields: Record<string, unknown>, source: string, confidence: number, options?: {
|
|
591
|
+
sourceId?: string;
|
|
592
|
+
setBy?: string;
|
|
593
|
+
branchingThreshold?: number;
|
|
594
|
+
callbacks?: MutationCallbacks;
|
|
595
|
+
validationCallbacks?: ValidationCallbacks;
|
|
596
|
+
}): Promise<{
|
|
597
|
+
written: Array<{
|
|
598
|
+
key: string;
|
|
599
|
+
entryId: string;
|
|
600
|
+
}>;
|
|
601
|
+
skipped: string[];
|
|
602
|
+
deferred: Array<{
|
|
603
|
+
key: string;
|
|
604
|
+
reason: string;
|
|
605
|
+
}>;
|
|
606
|
+
validationRequested: Array<{
|
|
607
|
+
key: string;
|
|
608
|
+
value: unknown;
|
|
609
|
+
confidence: number;
|
|
610
|
+
}>;
|
|
611
|
+
}>;
|
|
612
|
+
|
|
613
|
+
interface EntityRelationship {
|
|
614
|
+
sourceEntityType: string;
|
|
615
|
+
sourceEntityId: string;
|
|
616
|
+
targetEntityType: string;
|
|
617
|
+
targetEntityId: string;
|
|
618
|
+
sharedFields: Array<{
|
|
619
|
+
fieldKey: string;
|
|
620
|
+
value: unknown;
|
|
621
|
+
sourceConfidence: number;
|
|
622
|
+
targetConfidence: number;
|
|
623
|
+
}>;
|
|
624
|
+
strength: number;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Pure: compute relationship strength from shared fields.
|
|
628
|
+
* strength = avg(srcConf × tgtConf) × (sharedCount / totalSourceFields)
|
|
629
|
+
*/
|
|
630
|
+
declare function computeRelationshipStrength(sharedFields: Array<{
|
|
631
|
+
sourceConfidence: number;
|
|
632
|
+
targetConfidence: number;
|
|
633
|
+
}>, totalFieldsOnSource: number): number;
|
|
634
|
+
/**
|
|
635
|
+
* Find entities related to a given entity via shared field values.
|
|
636
|
+
*/
|
|
637
|
+
declare function findRelatedEntities(db: PrismaClient, entityType: string, entityId: string, options?: {
|
|
638
|
+
targetEntityType?: string;
|
|
639
|
+
minSharedFields?: number;
|
|
640
|
+
minStrength?: number;
|
|
641
|
+
limit?: number;
|
|
642
|
+
}): Promise<EntityRelationship[]>;
|
|
643
|
+
/**
|
|
644
|
+
* Get all relationships for an entity (alias for findRelatedEntities with defaults).
|
|
645
|
+
*/
|
|
646
|
+
declare function getEntityRelationships(db: PrismaClient, entityType: string, entityId: string, limit?: number): Promise<EntityRelationship[]>;
|
|
647
|
+
|
|
648
|
+
interface ConflictRule {
|
|
649
|
+
type: 'mutual_exclusion' | 'range_violation' | 'temporal_impossibility' | 'value_contradiction';
|
|
650
|
+
description: string;
|
|
651
|
+
fieldA: string;
|
|
652
|
+
fieldB?: string;
|
|
653
|
+
check: (valueA: unknown, valueB?: unknown) => boolean;
|
|
654
|
+
}
|
|
655
|
+
interface DetectedConflict {
|
|
656
|
+
rule: ConflictRule;
|
|
657
|
+
entityType: string;
|
|
658
|
+
entityId: string;
|
|
659
|
+
fieldA: {
|
|
660
|
+
key: string;
|
|
661
|
+
value: unknown;
|
|
662
|
+
confidence: number;
|
|
663
|
+
truthScore: number;
|
|
664
|
+
};
|
|
665
|
+
fieldB?: {
|
|
666
|
+
key: string;
|
|
667
|
+
value: unknown;
|
|
668
|
+
confidence: number;
|
|
669
|
+
truthScore: number;
|
|
670
|
+
};
|
|
671
|
+
severity: 'low' | 'medium' | 'high';
|
|
672
|
+
suggestion: string;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Default conflict rules — minimal starter set.
|
|
676
|
+
* App provides domain-specific rules via the `rules` parameter.
|
|
677
|
+
*/
|
|
678
|
+
declare const DEFAULT_CONFLICT_RULES: ConflictRule[];
|
|
679
|
+
/**
|
|
680
|
+
* Pure: evaluate a single rule against field values.
|
|
681
|
+
*/
|
|
682
|
+
declare function evaluateConflictRule(rule: ConflictRule, fields: Record<string, {
|
|
683
|
+
value: unknown;
|
|
684
|
+
confidence: number;
|
|
685
|
+
truthScore: number;
|
|
686
|
+
}>): DetectedConflict | null;
|
|
687
|
+
/**
|
|
688
|
+
* Check entity for contradictions using provided rules.
|
|
689
|
+
*/
|
|
690
|
+
declare function detectConflicts(db: PrismaClient, entityType: string, entityId: string, rules?: ConflictRule[]): Promise<DetectedConflict[]>;
|
|
691
|
+
/**
|
|
692
|
+
* Batch scan across all entities of a type for contradictions.
|
|
693
|
+
*/
|
|
694
|
+
declare function scanForConflicts(db: PrismaClient, entityType: string, rules?: ConflictRule[], limit?: number): Promise<Array<{
|
|
695
|
+
entityId: string;
|
|
696
|
+
conflicts: DetectedConflict[];
|
|
697
|
+
}>>;
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Evaluate a single constraint against current entity state.
|
|
701
|
+
*/
|
|
702
|
+
declare function evaluateConstraint(constraint: FieldConstraint, entityFields: Record<string, unknown>): ConstraintViolation | null;
|
|
703
|
+
/**
|
|
704
|
+
* Check all constraints for an entity by reading field definitions with constraints.
|
|
705
|
+
*/
|
|
706
|
+
declare function checkConstraints(db: PrismaClient, entityType: string, entityId: string): Promise<ConstraintViolation[]>;
|
|
707
|
+
/**
|
|
708
|
+
* Fire observers after setEntityFields — check constraints and notify.
|
|
709
|
+
* Best-effort: never blocks the original write.
|
|
710
|
+
*/
|
|
711
|
+
declare function fireObservers(db: PrismaClient, entityType: string, entityId: string, writtenFields: string[], callbacks?: ObserverCallbacks): Promise<ConstraintViolation[]>;
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Analyze co-occurrence patterns across all entities of a type.
|
|
715
|
+
* For each value of fieldKeyA, what values of fieldKeyB co-occur?
|
|
716
|
+
*
|
|
717
|
+
* Returns: Map<valueA, Map<valueB, { count, total, rate }>>
|
|
718
|
+
*/
|
|
719
|
+
declare function buildCoOccurrenceMap(db: PrismaClient, entityType: string, fieldKeyA: string, fieldKeyB: string, minOccurrences?: number): Promise<Map<string, Map<string, {
|
|
720
|
+
count: number;
|
|
721
|
+
total: number;
|
|
722
|
+
rate: number;
|
|
723
|
+
}>>>;
|
|
724
|
+
|
|
725
|
+
interface GhostFieldPrediction {
|
|
726
|
+
fieldKey: string;
|
|
727
|
+
label: string;
|
|
728
|
+
predictedValue: unknown;
|
|
729
|
+
confidence: number;
|
|
730
|
+
basedOn: Array<{
|
|
731
|
+
fieldKey: string;
|
|
732
|
+
value: unknown;
|
|
733
|
+
coOccurrenceRate: number;
|
|
734
|
+
}>;
|
|
735
|
+
source: 'predicted';
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Predict missing fields based on co-occurrence patterns.
|
|
739
|
+
* Finds fields the entity doesn't have yet, predicts values from correlated fields.
|
|
740
|
+
*/
|
|
741
|
+
declare function predictGhostFields(db: PrismaClient, entityType: string, entityId: string, options?: {
|
|
742
|
+
minConfidence?: number;
|
|
743
|
+
maxPredictions?: number;
|
|
744
|
+
}): Promise<GhostFieldPrediction[]>;
|
|
745
|
+
/**
|
|
746
|
+
* Write predictions to ledger with source='predicted', low confidence.
|
|
747
|
+
* Skips fields that already have a non-predicted value.
|
|
748
|
+
*/
|
|
749
|
+
declare function writeGhostFields(db: PrismaClient, entityType: string, entityId: string, predictions: GhostFieldPrediction[], callbacks?: MutationCallbacks): Promise<{
|
|
750
|
+
written: number;
|
|
751
|
+
skipped: number;
|
|
752
|
+
}>;
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Pure: compute overall score from components.
|
|
756
|
+
* 0.4 × completeness + 0.3 × freshness + 0.2 × (1 - conflictRate) + 0.1 × truthAverage
|
|
757
|
+
*/
|
|
758
|
+
declare function computeOverallScore(completeness: number, freshness: number, conflictRate: number, truthAverage: number): number;
|
|
759
|
+
/**
|
|
760
|
+
* Compute health for one entity.
|
|
761
|
+
*/
|
|
762
|
+
declare function computeEntityHealth(db: PrismaClient, entityType: string, entityId: string, conflictRules?: ConflictRule[]): Promise<EntityHealthReport>;
|
|
763
|
+
/**
|
|
764
|
+
* Aggregate health across all entities of a type.
|
|
765
|
+
*/
|
|
766
|
+
declare function getEntityTypeHealth(db: PrismaClient, entityType: string, options?: {
|
|
767
|
+
limit?: number;
|
|
768
|
+
worstN?: number;
|
|
769
|
+
bestN?: number;
|
|
770
|
+
}): Promise<EntityTypeHealthSummary>;
|
|
771
|
+
|
|
772
|
+
declare const QueryKnowledgeSchema: z.ZodObject<{
|
|
773
|
+
entity: z.ZodString;
|
|
774
|
+
field: z.ZodOptional<z.ZodString>;
|
|
775
|
+
search: z.ZodOptional<z.ZodString>;
|
|
776
|
+
category: z.ZodOptional<z.ZodString>;
|
|
777
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
778
|
+
}, z.core.$strip>;
|
|
779
|
+
type QueryKnowledgeInput = z.infer<typeof QueryKnowledgeSchema>;
|
|
780
|
+
declare const CreateKnowledgeEntrySchema: z.ZodObject<{
|
|
781
|
+
entity: z.ZodString;
|
|
782
|
+
field: z.ZodString;
|
|
783
|
+
value: z.ZodString;
|
|
784
|
+
label: z.ZodString;
|
|
785
|
+
aliases: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
786
|
+
category: z.ZodOptional<z.ZodString>;
|
|
787
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
788
|
+
sortOrder: z.ZodDefault<z.ZodNumber>;
|
|
789
|
+
}, z.core.$strip>;
|
|
790
|
+
type CreateKnowledgeEntryInput = z.infer<typeof CreateKnowledgeEntrySchema>;
|
|
791
|
+
declare const UpdateKnowledgeEntrySchema: z.ZodObject<{
|
|
792
|
+
label: z.ZodOptional<z.ZodString>;
|
|
793
|
+
aliases: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
794
|
+
category: z.ZodOptional<z.ZodString>;
|
|
795
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
796
|
+
sortOrder: z.ZodOptional<z.ZodNumber>;
|
|
797
|
+
isActive: z.ZodOptional<z.ZodBoolean>;
|
|
798
|
+
}, z.core.$strip>;
|
|
799
|
+
type UpdateKnowledgeEntryInput = z.infer<typeof UpdateKnowledgeEntrySchema>;
|
|
800
|
+
declare const GetPreferencesSchema: z.ZodObject<{
|
|
801
|
+
entity: z.ZodString;
|
|
802
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
803
|
+
field: z.ZodOptional<z.ZodString>;
|
|
804
|
+
}, z.core.$strip>;
|
|
805
|
+
type GetPreferencesInput = z.infer<typeof GetPreferencesSchema>;
|
|
806
|
+
declare const SetPreferenceSchema: z.ZodObject<{
|
|
807
|
+
entity: z.ZodString;
|
|
808
|
+
field: z.ZodString;
|
|
809
|
+
value: z.ZodString;
|
|
810
|
+
label: z.ZodString;
|
|
811
|
+
conditions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
812
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
813
|
+
priority: z.ZodDefault<z.ZodNumber>;
|
|
814
|
+
}, z.core.$strip>;
|
|
815
|
+
type SetPreferenceInput = z.infer<typeof SetPreferenceSchema>;
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Query knowledge entries by entity, field, and optional NL search.
|
|
819
|
+
* Auto-seeds on first access if table is empty.
|
|
820
|
+
*/
|
|
821
|
+
declare function queryKnowledge(db: PrismaClient, input: QueryKnowledgeInput, seedProvider?: SeedDataProvider): Promise<{
|
|
822
|
+
label: string;
|
|
823
|
+
category: string | null;
|
|
824
|
+
value: string;
|
|
825
|
+
sortOrder: number;
|
|
826
|
+
isActive: boolean;
|
|
827
|
+
source: string;
|
|
828
|
+
id: string;
|
|
829
|
+
createdAt: Date;
|
|
830
|
+
updatedAt: Date;
|
|
831
|
+
field: string;
|
|
832
|
+
entity: string;
|
|
833
|
+
aliases: string[];
|
|
834
|
+
metadata: Prisma.JsonValue | null;
|
|
835
|
+
}[]>;
|
|
836
|
+
declare function createKnowledgeEntry(db: PrismaClient, input: CreateKnowledgeEntryInput): Promise<{
|
|
837
|
+
label: string;
|
|
838
|
+
category: string | null;
|
|
839
|
+
value: string;
|
|
840
|
+
sortOrder: number;
|
|
841
|
+
isActive: boolean;
|
|
842
|
+
source: string;
|
|
843
|
+
id: string;
|
|
844
|
+
createdAt: Date;
|
|
845
|
+
updatedAt: Date;
|
|
846
|
+
field: string;
|
|
847
|
+
entity: string;
|
|
848
|
+
aliases: string[];
|
|
849
|
+
metadata: Prisma.JsonValue | null;
|
|
850
|
+
}>;
|
|
851
|
+
declare function updateKnowledgeEntry(db: PrismaClient, id: string, input: UpdateKnowledgeEntryInput): Promise<{
|
|
852
|
+
label: string;
|
|
853
|
+
category: string | null;
|
|
854
|
+
value: string;
|
|
855
|
+
sortOrder: number;
|
|
856
|
+
isActive: boolean;
|
|
857
|
+
source: string;
|
|
858
|
+
id: string;
|
|
859
|
+
createdAt: Date;
|
|
860
|
+
updatedAt: Date;
|
|
861
|
+
field: string;
|
|
862
|
+
entity: string;
|
|
863
|
+
aliases: string[];
|
|
864
|
+
metadata: Prisma.JsonValue | null;
|
|
865
|
+
}>;
|
|
866
|
+
declare function deleteKnowledgeEntry(db: PrismaClient, id: string): Promise<{
|
|
867
|
+
label: string;
|
|
868
|
+
category: string | null;
|
|
869
|
+
value: string;
|
|
870
|
+
sortOrder: number;
|
|
871
|
+
isActive: boolean;
|
|
872
|
+
source: string;
|
|
873
|
+
id: string;
|
|
874
|
+
createdAt: Date;
|
|
875
|
+
updatedAt: Date;
|
|
876
|
+
field: string;
|
|
877
|
+
entity: string;
|
|
878
|
+
aliases: string[];
|
|
879
|
+
metadata: Prisma.JsonValue | null;
|
|
880
|
+
}>;
|
|
881
|
+
/**
|
|
882
|
+
* Seeds the AgentKnowledge table with default data if empty.
|
|
883
|
+
* Uses SeedDataProvider callback so package doesn't need app-specific data.
|
|
884
|
+
*/
|
|
885
|
+
declare function ensureKnowledgeDefaults(db: PrismaClient, seedProvider?: SeedDataProvider): Promise<void>;
|
|
886
|
+
/**
|
|
887
|
+
* Reset knowledge to defaults: delete all seed entries and re-seed.
|
|
888
|
+
*/
|
|
889
|
+
declare function resetKnowledgeDefaults(db: PrismaClient, seedProvider?: SeedDataProvider): Promise<void>;
|
|
890
|
+
/**
|
|
891
|
+
* Reset the seed-checked flag (for testing).
|
|
892
|
+
*/
|
|
893
|
+
declare function resetSeedCheck(): void;
|
|
894
|
+
|
|
895
|
+
/**
|
|
896
|
+
* Get preferences for an entity, optionally filtered by userId.
|
|
897
|
+
* Returns org-wide (userId=null) + user-specific, sorted by priority desc.
|
|
898
|
+
*/
|
|
899
|
+
declare function getPreferences(db: PrismaClient, input: GetPreferencesInput): Promise<{
|
|
900
|
+
label: string;
|
|
901
|
+
value: string;
|
|
902
|
+
isActive: boolean;
|
|
903
|
+
userId: string | null;
|
|
904
|
+
id: string;
|
|
905
|
+
createdAt: Date;
|
|
906
|
+
updatedAt: Date;
|
|
907
|
+
field: string;
|
|
908
|
+
entity: string;
|
|
909
|
+
conditions: Prisma.JsonValue | null;
|
|
910
|
+
priority: number;
|
|
911
|
+
}[]>;
|
|
912
|
+
declare function setPreference(db: PrismaClient, input: SetPreferenceInput): Promise<{
|
|
913
|
+
label: string;
|
|
914
|
+
value: string;
|
|
915
|
+
isActive: boolean;
|
|
916
|
+
userId: string | null;
|
|
917
|
+
id: string;
|
|
918
|
+
createdAt: Date;
|
|
919
|
+
updatedAt: Date;
|
|
920
|
+
field: string;
|
|
921
|
+
entity: string;
|
|
922
|
+
conditions: Prisma.JsonValue | null;
|
|
923
|
+
priority: number;
|
|
924
|
+
}>;
|
|
925
|
+
declare function deletePreference(db: PrismaClient, id: string): Promise<{
|
|
926
|
+
label: string;
|
|
927
|
+
value: string;
|
|
928
|
+
isActive: boolean;
|
|
929
|
+
userId: string | null;
|
|
930
|
+
id: string;
|
|
931
|
+
createdAt: Date;
|
|
932
|
+
updatedAt: Date;
|
|
933
|
+
field: string;
|
|
934
|
+
entity: string;
|
|
935
|
+
conditions: Prisma.JsonValue | null;
|
|
936
|
+
priority: number;
|
|
937
|
+
}>;
|
|
938
|
+
|
|
939
|
+
interface LogInteractionInput {
|
|
940
|
+
userId: string;
|
|
941
|
+
query: string;
|
|
942
|
+
toolsUsed?: string[];
|
|
943
|
+
sessionId?: string;
|
|
944
|
+
}
|
|
945
|
+
declare function logInteraction(db: PrismaClient, input: LogInteractionInput): Promise<{
|
|
946
|
+
query: string;
|
|
947
|
+
userId: string;
|
|
948
|
+
id: string;
|
|
949
|
+
createdAt: Date;
|
|
950
|
+
intent: string | null;
|
|
951
|
+
topic: string | null;
|
|
952
|
+
modules: string[];
|
|
953
|
+
toolsUsed: string[];
|
|
954
|
+
satisfied: boolean | null;
|
|
955
|
+
sessionId: string | null;
|
|
956
|
+
}>;
|
|
957
|
+
declare function markSatisfied(db: PrismaClient, id: string, satisfied: boolean): Promise<{
|
|
958
|
+
query: string;
|
|
959
|
+
userId: string;
|
|
960
|
+
id: string;
|
|
961
|
+
createdAt: Date;
|
|
962
|
+
intent: string | null;
|
|
963
|
+
topic: string | null;
|
|
964
|
+
modules: string[];
|
|
965
|
+
toolsUsed: string[];
|
|
966
|
+
satisfied: boolean | null;
|
|
967
|
+
sessionId: string | null;
|
|
968
|
+
}>;
|
|
969
|
+
declare function getTopicDistribution(db: PrismaClient, days?: number): Promise<{
|
|
970
|
+
topic: string;
|
|
971
|
+
count: number;
|
|
972
|
+
modules: string[];
|
|
973
|
+
tools: string[];
|
|
974
|
+
}[]>;
|
|
975
|
+
declare function getRecentInteractions(db: PrismaClient, userId: string, limit?: number): Promise<{
|
|
976
|
+
query: string;
|
|
977
|
+
userId: string;
|
|
978
|
+
id: string;
|
|
979
|
+
createdAt: Date;
|
|
980
|
+
intent: string | null;
|
|
981
|
+
topic: string | null;
|
|
982
|
+
modules: string[];
|
|
983
|
+
toolsUsed: string[];
|
|
984
|
+
satisfied: boolean | null;
|
|
985
|
+
sessionId: string | null;
|
|
986
|
+
}[]>;
|
|
987
|
+
declare function getInteractionCount(db: PrismaClient, days?: number): Promise<number>;
|
|
988
|
+
|
|
989
|
+
declare function classifyIntent(query: string): string;
|
|
990
|
+
declare function extractTopic(query: string): string | null;
|
|
991
|
+
declare function extractModules(toolNames: string[]): string[];
|
|
992
|
+
|
|
993
|
+
declare function analyzeAndSuggest(db: PrismaClient): Promise<number>;
|
|
994
|
+
declare function getSuggestions(db: PrismaClient, status?: string): Promise<{
|
|
995
|
+
category: string;
|
|
996
|
+
status: string;
|
|
997
|
+
confidence: number;
|
|
998
|
+
id: string;
|
|
999
|
+
createdAt: Date;
|
|
1000
|
+
updatedAt: Date;
|
|
1001
|
+
name: string;
|
|
1002
|
+
description: string;
|
|
1003
|
+
evidence: string;
|
|
1004
|
+
suggestedTools: string[];
|
|
1005
|
+
queryCount: number;
|
|
1006
|
+
dismissedBy: string | null;
|
|
1007
|
+
dismissedAt: Date | null;
|
|
1008
|
+
}[]>;
|
|
1009
|
+
declare function dismissSuggestion(db: PrismaClient, id: string, userId: string): Promise<{
|
|
1010
|
+
category: string;
|
|
1011
|
+
status: string;
|
|
1012
|
+
confidence: number;
|
|
1013
|
+
id: string;
|
|
1014
|
+
createdAt: Date;
|
|
1015
|
+
updatedAt: Date;
|
|
1016
|
+
name: string;
|
|
1017
|
+
description: string;
|
|
1018
|
+
evidence: string;
|
|
1019
|
+
suggestedTools: string[];
|
|
1020
|
+
queryCount: number;
|
|
1021
|
+
dismissedBy: string | null;
|
|
1022
|
+
dismissedAt: Date | null;
|
|
1023
|
+
}>;
|
|
1024
|
+
declare function approveSuggestion(db: PrismaClient, id: string): Promise<{
|
|
1025
|
+
category: string;
|
|
1026
|
+
status: string;
|
|
1027
|
+
confidence: number;
|
|
1028
|
+
id: string;
|
|
1029
|
+
createdAt: Date;
|
|
1030
|
+
updatedAt: Date;
|
|
1031
|
+
name: string;
|
|
1032
|
+
description: string;
|
|
1033
|
+
evidence: string;
|
|
1034
|
+
suggestedTools: string[];
|
|
1035
|
+
queryCount: number;
|
|
1036
|
+
dismissedBy: string | null;
|
|
1037
|
+
dismissedAt: Date | null;
|
|
1038
|
+
}>;
|
|
1039
|
+
|
|
1040
|
+
declare const AttachmentSchema: z.ZodObject<{
|
|
1041
|
+
filename: z.ZodString;
|
|
1042
|
+
mimeType: z.ZodString;
|
|
1043
|
+
size: z.ZodNumber;
|
|
1044
|
+
storagePath: z.ZodString;
|
|
1045
|
+
}, z.core.$strip>;
|
|
1046
|
+
type AttachmentInput = z.infer<typeof AttachmentSchema>;
|
|
1047
|
+
declare const CreateNoteSchema: z.ZodObject<{
|
|
1048
|
+
content: z.ZodString;
|
|
1049
|
+
contentHtml: z.ZodOptional<z.ZodString>;
|
|
1050
|
+
isDraft: z.ZodDefault<z.ZodBoolean>;
|
|
1051
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
1052
|
+
MANUAL: "MANUAL";
|
|
1053
|
+
AGENT: "AGENT";
|
|
1054
|
+
SYSTEM: "SYSTEM";
|
|
1055
|
+
QUOTE: "QUOTE";
|
|
1056
|
+
}>>;
|
|
1057
|
+
attachments: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
1058
|
+
filename: z.ZodString;
|
|
1059
|
+
mimeType: z.ZodString;
|
|
1060
|
+
size: z.ZodNumber;
|
|
1061
|
+
storagePath: z.ZodString;
|
|
1062
|
+
}, z.core.$strip>>>;
|
|
1063
|
+
fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1064
|
+
}, z.core.$strip>;
|
|
1065
|
+
type CreateNoteInput$1 = z.infer<typeof CreateNoteSchema>;
|
|
1066
|
+
declare const UpdateNoteSchema: z.ZodObject<{
|
|
1067
|
+
content: z.ZodOptional<z.ZodString>;
|
|
1068
|
+
contentHtml: z.ZodOptional<z.ZodString>;
|
|
1069
|
+
isDraft: z.ZodOptional<z.ZodBoolean>;
|
|
1070
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
1071
|
+
filename: z.ZodString;
|
|
1072
|
+
mimeType: z.ZodString;
|
|
1073
|
+
size: z.ZodNumber;
|
|
1074
|
+
storagePath: z.ZodString;
|
|
1075
|
+
}, z.core.$strip>>>;
|
|
1076
|
+
}, z.core.$strip>;
|
|
1077
|
+
type UpdateNoteInput$1 = z.infer<typeof UpdateNoteSchema>;
|
|
1078
|
+
declare const ListNotesQuery: z.ZodObject<{
|
|
1079
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
1080
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
1081
|
+
isDraft: z.ZodOptional<z.ZodEnum<{
|
|
1082
|
+
true: "true";
|
|
1083
|
+
false: "false";
|
|
1084
|
+
}>>;
|
|
1085
|
+
}, z.core.$strip>;
|
|
1086
|
+
type ListNotesQueryInput = z.infer<typeof ListNotesQuery>;
|
|
1087
|
+
|
|
1088
|
+
interface CreateNoteInput {
|
|
1089
|
+
entityType: string;
|
|
1090
|
+
entityId: string;
|
|
1091
|
+
content: string;
|
|
1092
|
+
contentHtml?: string;
|
|
1093
|
+
isDraft?: boolean;
|
|
1094
|
+
authorId?: string | null;
|
|
1095
|
+
source?: string;
|
|
1096
|
+
attachments?: AttachmentInput[];
|
|
1097
|
+
fields?: Record<string, unknown>;
|
|
1098
|
+
metadata?: Record<string, unknown>;
|
|
1099
|
+
}
|
|
1100
|
+
interface UpdateNoteInput {
|
|
1101
|
+
content?: string;
|
|
1102
|
+
contentHtml?: string;
|
|
1103
|
+
isDraft?: boolean;
|
|
1104
|
+
attachments?: AttachmentInput[];
|
|
1105
|
+
/** User ID performing the edit — recorded on the revision for audit. */
|
|
1106
|
+
editedBy?: string;
|
|
1107
|
+
}
|
|
1108
|
+
interface ListNotesOptions {
|
|
1109
|
+
entityType: string;
|
|
1110
|
+
entityId: string;
|
|
1111
|
+
limit?: number;
|
|
1112
|
+
cursor?: string;
|
|
1113
|
+
isDraft?: boolean;
|
|
1114
|
+
}
|
|
1115
|
+
declare function createNote(db: PrismaClient, input: CreateNoteInput, callbacks?: NoteKnowledgeCallbacks): Promise<{
|
|
1116
|
+
attachments: {
|
|
1117
|
+
id: string;
|
|
1118
|
+
createdAt: Date;
|
|
1119
|
+
size: number;
|
|
1120
|
+
filename: string;
|
|
1121
|
+
mimeType: string;
|
|
1122
|
+
storagePath: string;
|
|
1123
|
+
noteId: string;
|
|
1124
|
+
}[];
|
|
1125
|
+
author: {
|
|
1126
|
+
id: string;
|
|
1127
|
+
name: string;
|
|
1128
|
+
} | null;
|
|
1129
|
+
} & {
|
|
1130
|
+
source: string;
|
|
1131
|
+
id: string;
|
|
1132
|
+
createdAt: Date;
|
|
1133
|
+
updatedAt: Date;
|
|
1134
|
+
clientId: string;
|
|
1135
|
+
metadata: Prisma.JsonValue | null;
|
|
1136
|
+
content: string;
|
|
1137
|
+
contentHtml: string | null;
|
|
1138
|
+
isDraft: boolean;
|
|
1139
|
+
authorId: string | null;
|
|
1140
|
+
}>;
|
|
1141
|
+
declare function updateNote(db: PrismaClient, noteId: string, entityId: string, input: UpdateNoteInput, callbacks?: NoteKnowledgeCallbacks): Promise<({
|
|
1142
|
+
attachments: {
|
|
1143
|
+
id: string;
|
|
1144
|
+
createdAt: Date;
|
|
1145
|
+
size: number;
|
|
1146
|
+
filename: string;
|
|
1147
|
+
mimeType: string;
|
|
1148
|
+
storagePath: string;
|
|
1149
|
+
noteId: string;
|
|
1150
|
+
}[];
|
|
1151
|
+
author: {
|
|
1152
|
+
id: string;
|
|
1153
|
+
name: string;
|
|
1154
|
+
} | null;
|
|
1155
|
+
revisions: {
|
|
1156
|
+
id: string;
|
|
1157
|
+
content: string;
|
|
1158
|
+
editedAt: Date;
|
|
1159
|
+
editedBy: string | null;
|
|
1160
|
+
}[];
|
|
1161
|
+
} & {
|
|
1162
|
+
source: string;
|
|
1163
|
+
id: string;
|
|
1164
|
+
createdAt: Date;
|
|
1165
|
+
updatedAt: Date;
|
|
1166
|
+
clientId: string;
|
|
1167
|
+
metadata: Prisma.JsonValue | null;
|
|
1168
|
+
content: string;
|
|
1169
|
+
contentHtml: string | null;
|
|
1170
|
+
isDraft: boolean;
|
|
1171
|
+
authorId: string | null;
|
|
1172
|
+
}) | null>;
|
|
1173
|
+
declare function getNotes(db: PrismaClient, { entityId, limit, cursor, isDraft }: Omit<ListNotesOptions, 'entityType'> & {
|
|
1174
|
+
entityId: string;
|
|
1175
|
+
}): Promise<{
|
|
1176
|
+
items: ({
|
|
1177
|
+
attachments: {
|
|
1178
|
+
id: string;
|
|
1179
|
+
createdAt: Date;
|
|
1180
|
+
size: number;
|
|
1181
|
+
filename: string;
|
|
1182
|
+
mimeType: string;
|
|
1183
|
+
storagePath: string;
|
|
1184
|
+
noteId: string;
|
|
1185
|
+
}[];
|
|
1186
|
+
author: {
|
|
1187
|
+
id: string;
|
|
1188
|
+
name: string;
|
|
1189
|
+
} | null;
|
|
1190
|
+
} & {
|
|
1191
|
+
source: string;
|
|
1192
|
+
id: string;
|
|
1193
|
+
createdAt: Date;
|
|
1194
|
+
updatedAt: Date;
|
|
1195
|
+
clientId: string;
|
|
1196
|
+
metadata: Prisma.JsonValue | null;
|
|
1197
|
+
content: string;
|
|
1198
|
+
contentHtml: string | null;
|
|
1199
|
+
isDraft: boolean;
|
|
1200
|
+
authorId: string | null;
|
|
1201
|
+
})[];
|
|
1202
|
+
nextCursor: string | undefined;
|
|
1203
|
+
hasMore: boolean;
|
|
1204
|
+
}>;
|
|
1205
|
+
declare function deleteNote(db: PrismaClient, noteId: string, entityId: string): Promise<{
|
|
1206
|
+
source: string;
|
|
1207
|
+
id: string;
|
|
1208
|
+
createdAt: Date;
|
|
1209
|
+
updatedAt: Date;
|
|
1210
|
+
clientId: string;
|
|
1211
|
+
metadata: Prisma.JsonValue | null;
|
|
1212
|
+
content: string;
|
|
1213
|
+
contentHtml: string | null;
|
|
1214
|
+
isDraft: boolean;
|
|
1215
|
+
authorId: string | null;
|
|
1216
|
+
} | null>;
|
|
1217
|
+
|
|
1218
|
+
declare function getAllContacts(db: PrismaClient, options?: {
|
|
1219
|
+
limit?: number;
|
|
1220
|
+
offset?: number;
|
|
1221
|
+
source?: ContactSource;
|
|
1222
|
+
search?: string;
|
|
1223
|
+
excludeConverted?: boolean;
|
|
1224
|
+
}): Promise<{
|
|
1225
|
+
contacts: ({
|
|
1226
|
+
_count: {
|
|
1227
|
+
linkedEmails: number;
|
|
1228
|
+
};
|
|
1229
|
+
tags: ({
|
|
1230
|
+
tag: {
|
|
1231
|
+
id: string;
|
|
1232
|
+
createdAt: Date;
|
|
1233
|
+
updatedAt: Date;
|
|
1234
|
+
name: string;
|
|
1235
|
+
color: string;
|
|
1236
|
+
};
|
|
1237
|
+
} & {
|
|
1238
|
+
id: string;
|
|
1239
|
+
contactId: string;
|
|
1240
|
+
tagId: string;
|
|
1241
|
+
addedAt: Date;
|
|
1242
|
+
addedBy: string | null;
|
|
1243
|
+
})[];
|
|
1244
|
+
} & {
|
|
1245
|
+
email: string;
|
|
1246
|
+
mergedIntoId: string | null;
|
|
1247
|
+
source: _prisma_client.$Enums.ContactSource;
|
|
1248
|
+
id: string;
|
|
1249
|
+
createdAt: Date;
|
|
1250
|
+
updatedAt: Date;
|
|
1251
|
+
name: string | null;
|
|
1252
|
+
phone: string | null;
|
|
1253
|
+
convertedToClientId: string | null;
|
|
1254
|
+
notes: string | null;
|
|
1255
|
+
convertedAt: Date | null;
|
|
1256
|
+
convertedBy: string | null;
|
|
1257
|
+
mergedAt: Date | null;
|
|
1258
|
+
mergedBy: string | null;
|
|
1259
|
+
})[];
|
|
1260
|
+
total: number;
|
|
1261
|
+
limit: number;
|
|
1262
|
+
offset: number;
|
|
1263
|
+
}>;
|
|
1264
|
+
declare function getContactById(db: PrismaClient, id: string): Promise<{
|
|
1265
|
+
_count: {
|
|
1266
|
+
linkedEmails: number;
|
|
1267
|
+
};
|
|
1268
|
+
tags: ({
|
|
1269
|
+
tag: {
|
|
1270
|
+
id: string;
|
|
1271
|
+
createdAt: Date;
|
|
1272
|
+
updatedAt: Date;
|
|
1273
|
+
name: string;
|
|
1274
|
+
color: string;
|
|
1275
|
+
};
|
|
1276
|
+
} & {
|
|
1277
|
+
id: string;
|
|
1278
|
+
contactId: string;
|
|
1279
|
+
tagId: string;
|
|
1280
|
+
addedAt: Date;
|
|
1281
|
+
addedBy: string | null;
|
|
1282
|
+
})[];
|
|
1283
|
+
linkedEmails: {
|
|
1284
|
+
status: _prisma_client.$Enums.EmailStatus;
|
|
1285
|
+
id: string;
|
|
1286
|
+
emailDate: Date;
|
|
1287
|
+
subject: string;
|
|
1288
|
+
snippet: string;
|
|
1289
|
+
}[];
|
|
1290
|
+
} & {
|
|
1291
|
+
email: string;
|
|
1292
|
+
mergedIntoId: string | null;
|
|
1293
|
+
source: _prisma_client.$Enums.ContactSource;
|
|
1294
|
+
id: string;
|
|
1295
|
+
createdAt: Date;
|
|
1296
|
+
updatedAt: Date;
|
|
1297
|
+
name: string | null;
|
|
1298
|
+
phone: string | null;
|
|
1299
|
+
convertedToClientId: string | null;
|
|
1300
|
+
notes: string | null;
|
|
1301
|
+
convertedAt: Date | null;
|
|
1302
|
+
convertedBy: string | null;
|
|
1303
|
+
mergedAt: Date | null;
|
|
1304
|
+
mergedBy: string | null;
|
|
1305
|
+
}>;
|
|
1306
|
+
declare function getContactByEmail(db: PrismaClient, email: string): Promise<{
|
|
1307
|
+
email: string;
|
|
1308
|
+
mergedIntoId: string | null;
|
|
1309
|
+
source: _prisma_client.$Enums.ContactSource;
|
|
1310
|
+
id: string;
|
|
1311
|
+
createdAt: Date;
|
|
1312
|
+
updatedAt: Date;
|
|
1313
|
+
name: string | null;
|
|
1314
|
+
phone: string | null;
|
|
1315
|
+
convertedToClientId: string | null;
|
|
1316
|
+
notes: string | null;
|
|
1317
|
+
convertedAt: Date | null;
|
|
1318
|
+
convertedBy: string | null;
|
|
1319
|
+
mergedAt: Date | null;
|
|
1320
|
+
mergedBy: string | null;
|
|
1321
|
+
} | null>;
|
|
1322
|
+
declare function createContact(db: PrismaClient, params: {
|
|
1323
|
+
email: string;
|
|
1324
|
+
name?: string | null;
|
|
1325
|
+
notes?: string | null;
|
|
1326
|
+
source?: ContactSource;
|
|
1327
|
+
fields?: Record<string, unknown>;
|
|
1328
|
+
}, callbacks?: NoteKnowledgeCallbacks): Promise<{
|
|
1329
|
+
email: string;
|
|
1330
|
+
mergedIntoId: string | null;
|
|
1331
|
+
source: _prisma_client.$Enums.ContactSource;
|
|
1332
|
+
id: string;
|
|
1333
|
+
createdAt: Date;
|
|
1334
|
+
updatedAt: Date;
|
|
1335
|
+
name: string | null;
|
|
1336
|
+
phone: string | null;
|
|
1337
|
+
convertedToClientId: string | null;
|
|
1338
|
+
notes: string | null;
|
|
1339
|
+
convertedAt: Date | null;
|
|
1340
|
+
convertedBy: string | null;
|
|
1341
|
+
mergedAt: Date | null;
|
|
1342
|
+
mergedBy: string | null;
|
|
1343
|
+
}>;
|
|
1344
|
+
declare function updateContact(db: PrismaClient, id: string, data: {
|
|
1345
|
+
name?: string | null;
|
|
1346
|
+
notes?: string | null;
|
|
1347
|
+
}): Promise<{
|
|
1348
|
+
tags: ({
|
|
1349
|
+
tag: {
|
|
1350
|
+
id: string;
|
|
1351
|
+
createdAt: Date;
|
|
1352
|
+
updatedAt: Date;
|
|
1353
|
+
name: string;
|
|
1354
|
+
color: string;
|
|
1355
|
+
};
|
|
1356
|
+
} & {
|
|
1357
|
+
id: string;
|
|
1358
|
+
contactId: string;
|
|
1359
|
+
tagId: string;
|
|
1360
|
+
addedAt: Date;
|
|
1361
|
+
addedBy: string | null;
|
|
1362
|
+
})[];
|
|
1363
|
+
} & {
|
|
1364
|
+
email: string;
|
|
1365
|
+
mergedIntoId: string | null;
|
|
1366
|
+
source: _prisma_client.$Enums.ContactSource;
|
|
1367
|
+
id: string;
|
|
1368
|
+
createdAt: Date;
|
|
1369
|
+
updatedAt: Date;
|
|
1370
|
+
name: string | null;
|
|
1371
|
+
phone: string | null;
|
|
1372
|
+
convertedToClientId: string | null;
|
|
1373
|
+
notes: string | null;
|
|
1374
|
+
convertedAt: Date | null;
|
|
1375
|
+
convertedBy: string | null;
|
|
1376
|
+
mergedAt: Date | null;
|
|
1377
|
+
mergedBy: string | null;
|
|
1378
|
+
}>;
|
|
1379
|
+
declare function deleteContact(db: PrismaClient, id: string): Promise<{
|
|
1380
|
+
success: boolean;
|
|
1381
|
+
}>;
|
|
1382
|
+
declare function findOrCreateContact(db: PrismaClient, email: string, name?: string | null, source?: ContactSource): Promise<{
|
|
1383
|
+
email: string;
|
|
1384
|
+
mergedIntoId: string | null;
|
|
1385
|
+
source: _prisma_client.$Enums.ContactSource;
|
|
1386
|
+
id: string;
|
|
1387
|
+
createdAt: Date;
|
|
1388
|
+
updatedAt: Date;
|
|
1389
|
+
name: string | null;
|
|
1390
|
+
phone: string | null;
|
|
1391
|
+
convertedToClientId: string | null;
|
|
1392
|
+
notes: string | null;
|
|
1393
|
+
convertedAt: Date | null;
|
|
1394
|
+
convertedBy: string | null;
|
|
1395
|
+
mergedAt: Date | null;
|
|
1396
|
+
mergedBy: string | null;
|
|
1397
|
+
}>;
|
|
1398
|
+
|
|
1399
|
+
declare const CONTACT_FIELD_DEFINITIONS: readonly [{
|
|
1400
|
+
readonly entityType: "contact";
|
|
1401
|
+
readonly key: "preferred_contact_method";
|
|
1402
|
+
readonly label: "Preferred Contact Method";
|
|
1403
|
+
readonly dataType: "enum";
|
|
1404
|
+
readonly category: "communication";
|
|
1405
|
+
readonly enumOptions: readonly ["email", "phone", "text", "in-person"];
|
|
1406
|
+
readonly sortOrder: 0;
|
|
1407
|
+
}, {
|
|
1408
|
+
readonly entityType: "contact";
|
|
1409
|
+
readonly key: "preferred_contact_time";
|
|
1410
|
+
readonly label: "Preferred Contact Time";
|
|
1411
|
+
readonly dataType: "text";
|
|
1412
|
+
readonly category: "communication";
|
|
1413
|
+
readonly extractionHint: "Time of day or day of week the contact prefers to be reached";
|
|
1414
|
+
readonly sortOrder: 1;
|
|
1415
|
+
}, {
|
|
1416
|
+
readonly entityType: "contact";
|
|
1417
|
+
readonly key: "timezone";
|
|
1418
|
+
readonly label: "Timezone";
|
|
1419
|
+
readonly dataType: "text";
|
|
1420
|
+
readonly category: "communication";
|
|
1421
|
+
readonly sortOrder: 2;
|
|
1422
|
+
}, {
|
|
1423
|
+
readonly entityType: "contact";
|
|
1424
|
+
readonly key: "company";
|
|
1425
|
+
readonly label: "Company";
|
|
1426
|
+
readonly dataType: "text";
|
|
1427
|
+
readonly category: "professional";
|
|
1428
|
+
readonly sortOrder: 0;
|
|
1429
|
+
}, {
|
|
1430
|
+
readonly entityType: "contact";
|
|
1431
|
+
readonly key: "title";
|
|
1432
|
+
readonly label: "Job Title";
|
|
1433
|
+
readonly dataType: "text";
|
|
1434
|
+
readonly category: "professional";
|
|
1435
|
+
readonly sortOrder: 1;
|
|
1436
|
+
}, {
|
|
1437
|
+
readonly entityType: "contact";
|
|
1438
|
+
readonly key: "industry";
|
|
1439
|
+
readonly label: "Industry";
|
|
1440
|
+
readonly dataType: "text";
|
|
1441
|
+
readonly category: "professional";
|
|
1442
|
+
readonly sortOrder: 2;
|
|
1443
|
+
}, {
|
|
1444
|
+
readonly entityType: "contact";
|
|
1445
|
+
readonly key: "referral_source";
|
|
1446
|
+
readonly label: "Referral Source";
|
|
1447
|
+
readonly dataType: "text";
|
|
1448
|
+
readonly category: "relationship";
|
|
1449
|
+
readonly sortOrder: 0;
|
|
1450
|
+
}, {
|
|
1451
|
+
readonly entityType: "contact";
|
|
1452
|
+
readonly key: "relationship_type";
|
|
1453
|
+
readonly label: "Relationship Type";
|
|
1454
|
+
readonly dataType: "enum";
|
|
1455
|
+
readonly category: "relationship";
|
|
1456
|
+
readonly enumOptions: readonly ["prospect", "vendor", "partner", "personal", "other"];
|
|
1457
|
+
readonly sortOrder: 1;
|
|
1458
|
+
}, {
|
|
1459
|
+
readonly entityType: "contact";
|
|
1460
|
+
readonly key: "last_interaction_notes";
|
|
1461
|
+
readonly label: "Last Interaction Notes";
|
|
1462
|
+
readonly dataType: "text";
|
|
1463
|
+
readonly category: "relationship";
|
|
1464
|
+
readonly extractionHint: "Brief summary of last meaningful interaction";
|
|
1465
|
+
readonly sortOrder: 2;
|
|
1466
|
+
}];
|
|
1467
|
+
/**
|
|
1468
|
+
* Seed contact field definitions into the database.
|
|
1469
|
+
* Idempotent — skips existing keys via skipDuplicates.
|
|
1470
|
+
* Returns the number of new definitions created.
|
|
1471
|
+
*/
|
|
1472
|
+
declare function seedContactFieldDefinitions(db: PrismaClient): Promise<number>;
|
|
1473
|
+
|
|
1474
|
+
declare const CreateContactSchema: z.ZodObject<{
|
|
1475
|
+
email: z.ZodString;
|
|
1476
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1477
|
+
notes: z.ZodOptional<z.ZodString>;
|
|
1478
|
+
source: z.ZodDefault<z.ZodEnum<{
|
|
1479
|
+
MANUAL: "MANUAL";
|
|
1480
|
+
EMAIL_SYNC: "EMAIL_SYNC";
|
|
1481
|
+
AUTOMATION: "AUTOMATION";
|
|
1482
|
+
IMPORT: "IMPORT";
|
|
1483
|
+
}>>;
|
|
1484
|
+
fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1485
|
+
}, z.core.$strip>;
|
|
1486
|
+
type CreateContactInput = z.infer<typeof CreateContactSchema>;
|
|
1487
|
+
declare const UpdateContactSchema: z.ZodObject<{
|
|
1488
|
+
name: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
1489
|
+
notes: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
1490
|
+
}, z.core.$strip>;
|
|
1491
|
+
type UpdateContactInput = z.infer<typeof UpdateContactSchema>;
|
|
1492
|
+
declare const ListContactsQuery: z.ZodObject<{
|
|
1493
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
1494
|
+
offset: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
1495
|
+
source: z.ZodOptional<z.ZodEnum<{
|
|
1496
|
+
MANUAL: "MANUAL";
|
|
1497
|
+
EMAIL_SYNC: "EMAIL_SYNC";
|
|
1498
|
+
AUTOMATION: "AUTOMATION";
|
|
1499
|
+
IMPORT: "IMPORT";
|
|
1500
|
+
}>>;
|
|
1501
|
+
search: z.ZodOptional<z.ZodString>;
|
|
1502
|
+
excludeConverted: z.ZodDefault<z.ZodEnum<{
|
|
1503
|
+
true: "true";
|
|
1504
|
+
false: "false";
|
|
1505
|
+
}>>;
|
|
1506
|
+
}, z.core.$strip>;
|
|
1507
|
+
type ListContactsQueryInput = z.infer<typeof ListContactsQuery>;
|
|
1508
|
+
|
|
1509
|
+
export { AGENTKNOW_ERRORS, type AgentKnowledgeErrorEntry, type AttachmentInput, AttachmentSchema, CONTACT_FIELD_DEFINITIONS, type ConflictRule, type ConstraintViolation, ContactAlreadyConvertedError, ContactExistsError, ContactNotFoundError, type CreateContactInput, CreateContactSchema, type CreateFieldDefinitionInput, CreateFieldDefinitionSchema, type CreateKnowledgeEntryInput, CreateKnowledgeEntrySchema, type CreateNoteInput$1 as CreateNoteInput, CreateNoteSchema, DEFAULT_CONFLICT_RULES, type DetectedConflict, ENTITY_TYPES, type EntityHealthReport, type EntityRelationship, type EntityTypeHealthSummary, FIELD_DATA_TYPES, FIELD_STATUSES, type FieldConstraint, FieldHistoryQuery, type FieldHistoryQueryInput, type GetPreferencesInput, GetPreferencesSchema, type GhostFieldPrediction, KNOWLEDGE_ERRORS, type KnowledgeErrorDef, LEDGER_SOURCES, ListContactsQuery, type ListContactsQueryInput, ListFieldDefinitionsQuery, type ListFieldDefinitionsQueryInput, ListNotesQuery, type ListNotesQueryInput, type LogSearchQueryInput, LogSearchQuerySchema, type MutationCallbacks, type NoteKnowledgeCallbacks, type ObserverCallbacks, type QueryKnowledgeInput, QueryKnowledgeSchema, SEARCH_SOURCES, SOURCE_RELIABILITY, type SearchByFieldsInput, SearchByFieldsSchema, type SeedDataProvider, type SetEntityFieldsInput, SetEntityFieldsSchema, type SetPreferenceInput, SetPreferenceSchema, type UpdateContactInput, UpdateContactSchema, type UpdateFieldDefinitionInput, UpdateFieldDefinitionSchema, type UpdateKnowledgeEntryInput, UpdateKnowledgeEntrySchema, type UpdateNoteInput$1 as UpdateNoteInput, UpdateNoteSchema, type ValidationCallbacks, agentKnowledgeError, analyzeAndSuggest, approveSuggestion, buildCoOccurrenceMap, checkConstraints, classifyIntent, computeComplexityScore, computeDecayedConfidence, computeEntityHealth, computeEntityTruthScores, computeOverallScore, computeRecencyFactor, computeRelationshipStrength, computeTruthScore, createContact, createFieldDefinition, createKnowledgeEntry, createNote, deleteContact, deleteKnowledgeEntry, deleteNote, deletePreference, detectConflicts, dismissSuggestion, ensureKnowledgeDefaults, evaluateConflictRule, evaluateConstraint, extractModules, extractTopic, findOrCreateContact, findRelatedEntities, fireObservers, formatStalenessWarnings, getAllContacts, getContactByEmail, getContactById, getEntityFields, getEntityRelationships, getEntityTypeHealth, getFieldDefinitionById, getFieldDefinitions, getFieldHistory, getFieldValueAt, getInteractionCount, getKnowledgeAt, getKnowledgeTimeline, getNotes, getPreferences, getRecentInteractions, getStaleFields, getSuggestions, getTopicDistribution, getWeekOfYear, isStale, knowledgeError, logInteraction, logSearchQuery, markSatisfied, predictGhostFields, queryKnowledge, resetKnowledgeDefaults, resetSeedCheck, scanForConflicts, searchByFields, seedContactFieldDefinitions, setEntityFields, setEntityFieldsWithBranching, setPreference, shouldBranch, updateContact, updateFieldDefinition, updateKnowledgeEntry, updateNote, writeGhostFields };
|