@dyrected/core 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-P6Z2XAFS.js +10 -0
- package/dist/ai-X3M2SE5A.js +17 -0
- package/dist/ai-tools-UPKJY3TX.js +14 -0
- package/dist/{app-config-6U_Kum-Z.d.cts → app-D_ODsBWA.d.cts} +524 -5
- package/dist/{app-config-6U_Kum-Z.d.ts → app-D_ODsBWA.d.ts} +524 -5
- package/dist/chunk-254THFDS.js +202 -0
- package/dist/chunk-27YRIGK5.js +1758 -0
- package/dist/chunk-4RAQJVJM.js +18 -0
- package/dist/{chunk-H7DVVW2P.js → chunk-DZMBVIMN.js} +285 -1760
- package/dist/chunk-HRRJ3RYT.js +70 -0
- package/dist/chunk-W7GKJM2X.js +1136 -0
- package/dist/chunk-ZYYDTHF3.js +635 -0
- package/dist/index.cjs +634 -588
- package/dist/index.d.cts +180 -46
- package/dist/index.d.ts +180 -46
- package/dist/index.js +148 -60
- package/dist/rag.service-YDGEYTXS.js +11 -0
- package/dist/server.cjs +5127 -1135
- package/dist/server.d.cts +371 -329
- package/dist/server.d.ts +371 -329
- package/dist/server.js +2416 -273
- package/dist/{where-sanitizer-47QPJQ6O.js → where-sanitizer-CAAIYSSK.js} +20 -1
- package/package.json +12 -9
- package/LICENSE.md +0 -50
- package/dist/chunk-FRSJJO27.js +0 -519
- package/dist/observability-HQF4EUSV.js +0 -35
package/dist/server.d.ts
CHANGED
|
@@ -1,160 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { J as DyrectedContext, D as DyrectedConfig, C as CollectionConfig, G as GlobalConfig, bf as DatabaseAdapter, b as AuthenticatedUser, bt as DyrectedAIContext, al as AIThread, ah as AIMessage, ck as RAGSearchResult, ak as AIRateLimitStore, aj as AIRateLimitResult } from './app-D_ODsBWA.js';
|
|
2
|
+
export { cV as DyrectedObservabilityRuntime, cW as RequestBodyCapture, cX as RequestTraceContext, cY as ResolvedObservabilityConfig, cZ as attachRequestMetrics, c_ as bindObservabilityRuntime, c$ as buildRequestLogger, d0 as captureRequestBody, d1 as createDyrectedApp, d2 as createObservabilityRuntime, d3 as createRequestSpan, d4 as endRequestSpan, d5 as getConfigLogger, d6 as getObservabilityRuntime, d7 as getRequestLogger, d8 as redactBody, d9 as redactHeaders, da as renderPrometheusMetrics, db as resolveObservabilityConfig, dc as shouldSampleRequest } from './app-D_ODsBWA.js';
|
|
2
3
|
import * as hono from 'hono';
|
|
3
|
-
import { Context,
|
|
4
|
-
import { Logger } from 'pino';
|
|
5
|
-
import { D as DyrectedConfig, b5 as DyrectedObservabilityConfig, C as CollectionConfig, G as GlobalConfig } from './app-config-6U_Kum-Z.js';
|
|
6
|
-
import { JWTPayload } from 'jose';
|
|
7
|
-
import { Tracer, Counter, Attributes, Histogram, Span } from '@opentelemetry/api';
|
|
8
|
-
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
|
|
4
|
+
import { Hono, Context, Next } from 'hono';
|
|
9
5
|
import * as hono_utils_types from 'hono/utils/types';
|
|
10
6
|
import * as hono_utils_http_status from 'hono/utils/http-status';
|
|
7
|
+
import { LanguageModel, EmbeddingModel } from 'ai';
|
|
8
|
+
import 'hono/types';
|
|
9
|
+
import 'pino';
|
|
11
10
|
import 'lucide-react';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
collection: string;
|
|
17
|
-
sid?: string;
|
|
18
|
-
purpose?: 'invite' | 'reset';
|
|
19
|
-
providerId?: string;
|
|
20
|
-
authSource?: 'local' | 'external';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type RequestVars = DyrectedContext["Variables"];
|
|
24
|
-
interface ResolvedObservabilityConfig {
|
|
25
|
-
requestLogging: {
|
|
26
|
-
enabled: boolean;
|
|
27
|
-
logBodies: boolean;
|
|
28
|
-
maxBodyBytes: number;
|
|
29
|
-
redactPaths: string[];
|
|
30
|
-
includeHeaders: string[];
|
|
31
|
-
redactHeaders: string[];
|
|
32
|
-
};
|
|
33
|
-
sampling: {
|
|
34
|
-
successRate: number;
|
|
35
|
-
traceSuccessRate: number;
|
|
36
|
-
bodySuccessRate: number;
|
|
37
|
-
alwaysKeep4xx: boolean;
|
|
38
|
-
alwaysKeep5xx: boolean;
|
|
39
|
-
};
|
|
40
|
-
tracing: {
|
|
41
|
-
enabled: boolean;
|
|
42
|
-
serviceName: string;
|
|
43
|
-
exporter: "otlp" | "console" | "none";
|
|
44
|
-
headers: Record<string, string>;
|
|
45
|
-
endpoint?: string;
|
|
46
|
-
};
|
|
47
|
-
metrics: {
|
|
48
|
-
enabled: boolean;
|
|
49
|
-
exporter: "otlp" | "prometheus" | "none";
|
|
50
|
-
endpoint?: string;
|
|
51
|
-
path: string;
|
|
52
|
-
};
|
|
53
|
-
transports: {
|
|
54
|
-
targets: Array<{
|
|
55
|
-
type: "stdout";
|
|
56
|
-
} | {
|
|
57
|
-
type: "stderr";
|
|
58
|
-
} | {
|
|
59
|
-
type: "file";
|
|
60
|
-
path: string;
|
|
61
|
-
} | {
|
|
62
|
-
type: "otlp";
|
|
63
|
-
endpoint: string;
|
|
64
|
-
headers?: Record<string, string>;
|
|
65
|
-
}>;
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
interface RequestTraceContext {
|
|
69
|
-
span: Span;
|
|
70
|
-
traceId: string;
|
|
71
|
-
spanId: string;
|
|
72
|
-
sampled: boolean;
|
|
73
|
-
}
|
|
74
|
-
interface RequestBodyCapture {
|
|
75
|
-
attempted: boolean;
|
|
76
|
-
contentType?: string;
|
|
77
|
-
contentLength?: number;
|
|
78
|
-
truncated?: boolean;
|
|
79
|
-
parseFailed?: boolean;
|
|
80
|
-
body?: unknown;
|
|
81
|
-
}
|
|
82
|
-
interface MetricsRuntime {
|
|
83
|
-
requestCount: Counter<Attributes>;
|
|
84
|
-
authFailureCount: Counter<Attributes>;
|
|
85
|
-
uncaughtErrorCount: Counter<Attributes>;
|
|
86
|
-
auditWriteFailureCount: Counter<Attributes>;
|
|
87
|
-
emailSendFailureCount: Counter<Attributes>;
|
|
88
|
-
workflowHookFailureCount: Counter<Attributes>;
|
|
89
|
-
requestDuration: Histogram<Attributes>;
|
|
90
|
-
}
|
|
91
|
-
interface DyrectedObservabilityRuntime {
|
|
92
|
-
logger: Logger;
|
|
93
|
-
config: ResolvedObservabilityConfig;
|
|
94
|
-
tracer?: Tracer;
|
|
95
|
-
metrics?: MetricsRuntime;
|
|
96
|
-
prometheusExporter?: PrometheusExporter;
|
|
97
|
-
shutdown: () => Promise<void>;
|
|
98
|
-
recordAuthFailure: (attributes?: Attributes) => void;
|
|
99
|
-
recordUncaughtError: (attributes?: Attributes) => void;
|
|
100
|
-
recordAuditWriteFailure: (attributes?: Attributes) => void;
|
|
101
|
-
recordEmailSendFailure: (attributes?: Attributes) => void;
|
|
102
|
-
recordWorkflowHookFailure: (attributes?: Attributes) => void;
|
|
103
|
-
}
|
|
104
|
-
declare function resolveObservabilityConfig(config?: DyrectedObservabilityConfig): ResolvedObservabilityConfig;
|
|
105
|
-
declare function createObservabilityRuntime(config: DyrectedConfig): DyrectedObservabilityRuntime;
|
|
106
|
-
declare function bindObservabilityRuntime(config: DyrectedConfig, runtime: DyrectedObservabilityRuntime): void;
|
|
107
|
-
declare function getObservabilityRuntime(config: Pick<DyrectedConfig, "logger"> | undefined): DyrectedObservabilityRuntime | undefined;
|
|
108
|
-
declare function getConfigLogger(config: Pick<DyrectedConfig, "logger"> | undefined, component: string): Logger;
|
|
109
|
-
declare function getRequestLogger(c: Context<DyrectedContext>, component?: string): Logger;
|
|
110
|
-
declare function buildRequestLogger(runtime: DyrectedObservabilityRuntime, vars: RequestVars, requestId?: string): Logger;
|
|
111
|
-
declare function shouldSampleRequest(requestId: string | undefined, statusCode: number, sampling: ResolvedObservabilityConfig["sampling"], kind: "log" | "trace" | "body"): boolean;
|
|
112
|
-
declare function redactHeaders(headers: Record<string, string>, observability: ResolvedObservabilityConfig): Record<string, string>;
|
|
113
|
-
declare function captureRequestBody(request: Request, observability: ResolvedObservabilityConfig): Promise<RequestBodyCapture>;
|
|
114
|
-
declare function redactBody(value: unknown, redactPaths: string[]): unknown;
|
|
115
|
-
declare function createRequestSpan(runtime: DyrectedObservabilityRuntime, name: string, attributes: Attributes): RequestTraceContext | undefined;
|
|
116
|
-
declare function endRequestSpan(requestTrace: RequestTraceContext | undefined, statusCode: number, error?: unknown): void;
|
|
117
|
-
declare function attachRequestMetrics(runtime: DyrectedObservabilityRuntime, args: {
|
|
118
|
-
method: string;
|
|
119
|
-
route: string;
|
|
120
|
-
statusCode: number;
|
|
121
|
-
durationMs: number;
|
|
122
|
-
}): void;
|
|
123
|
-
declare function renderPrometheusMetrics(exporter: PrometheusExporter): Promise<{
|
|
124
|
-
body: string;
|
|
125
|
-
headers: Record<string, string>;
|
|
126
|
-
statusCode: number;
|
|
127
|
-
}>;
|
|
128
|
-
|
|
129
|
-
interface DyrectedContext {
|
|
130
|
-
Variables: {
|
|
131
|
-
config: DyrectedConfig;
|
|
132
|
-
logger?: Logger;
|
|
133
|
-
observability?: DyrectedObservabilityRuntime;
|
|
134
|
-
siteId?: string;
|
|
135
|
-
workspaceId?: string;
|
|
136
|
-
requestBodyCapture?: RequestBodyCapture;
|
|
137
|
-
requestTrace?: RequestTraceContext;
|
|
138
|
-
/**
|
|
139
|
-
* The authenticated user set by requireAuth() or optionalAuth() middleware.
|
|
140
|
-
* Hydrated from the full user record (minus password) when a db adapter is
|
|
141
|
-
* configured, so collection fields like `roles` are available; falls back to
|
|
142
|
-
* the token's identity claims otherwise.
|
|
143
|
-
*/
|
|
144
|
-
user?: {
|
|
145
|
-
sub: string;
|
|
146
|
-
email?: string;
|
|
147
|
-
collection: string;
|
|
148
|
-
[key: string]: any;
|
|
149
|
-
};
|
|
150
|
-
clientIp?: string;
|
|
151
|
-
authTokenPayload?: CollectionTokenPayload;
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Create the main Dyrected Hono application.
|
|
156
|
-
*/
|
|
157
|
-
declare function createDyrectedApp(rawConfig: DyrectedConfig | any): Promise<Hono<DyrectedContext, hono_types.BlankSchema, "/">>;
|
|
11
|
+
import 'zod';
|
|
12
|
+
import 'jose';
|
|
13
|
+
import '@opentelemetry/api';
|
|
14
|
+
import '@opentelemetry/exporter-prometheus';
|
|
158
15
|
|
|
159
16
|
declare function serializeDetailForApi(detail?: any): any;
|
|
160
17
|
/**
|
|
@@ -311,76 +168,16 @@ declare class AuthController {
|
|
|
311
168
|
declare class CollectionController {
|
|
312
169
|
private collection;
|
|
313
170
|
constructor(collection: CollectionConfig);
|
|
171
|
+
private checkTenantAccess;
|
|
314
172
|
private getDelegatedProvider;
|
|
315
173
|
private toHookRequestContext;
|
|
316
174
|
private sanitizeDoc;
|
|
317
175
|
private evaluateAccess;
|
|
318
|
-
find(c: Context<DyrectedContext>): Promise<
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
externalSubject: string;
|
|
324
|
-
email: string;
|
|
325
|
-
name?: string | undefined;
|
|
326
|
-
roles: string[];
|
|
327
|
-
siteAccess?: string[] | undefined;
|
|
328
|
-
status?: "active" | "pending" | undefined;
|
|
329
|
-
}[];
|
|
330
|
-
totalDocs: number;
|
|
331
|
-
limit: number;
|
|
332
|
-
page: number;
|
|
333
|
-
totalPages: number;
|
|
334
|
-
hasNextPage: boolean;
|
|
335
|
-
hasPrevPage: boolean;
|
|
336
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">) | (Response & hono.TypedResponse<{
|
|
337
|
-
error: true;
|
|
338
|
-
message: string;
|
|
339
|
-
}, 403, "json">) | (Response & hono.TypedResponse<{
|
|
340
|
-
docs: {
|
|
341
|
-
[x: string]: any;
|
|
342
|
-
}[];
|
|
343
|
-
total: number;
|
|
344
|
-
limit: number;
|
|
345
|
-
page: number;
|
|
346
|
-
totalPages: number;
|
|
347
|
-
hasNextPage: boolean;
|
|
348
|
-
hasPrevPage: boolean;
|
|
349
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
350
|
-
findOne(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<any, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
351
|
-
create(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
352
|
-
message: string;
|
|
353
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
354
|
-
message: string;
|
|
355
|
-
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
356
|
-
message: string;
|
|
357
|
-
}, 413 | 415, "json">) | (Response & hono.TypedResponse<{
|
|
358
|
-
error: true;
|
|
359
|
-
message: string;
|
|
360
|
-
}, 403, "json">) | (Response & hono.TypedResponse<{
|
|
361
|
-
[x: string]: hono_utils_types.JSONValue;
|
|
362
|
-
}, 201, "json">) | (Response & hono.TypedResponse<{
|
|
363
|
-
id: string;
|
|
364
|
-
externalSubject: string;
|
|
365
|
-
email: string;
|
|
366
|
-
name?: string | undefined;
|
|
367
|
-
roles: string[];
|
|
368
|
-
siteAccess?: string[] | undefined;
|
|
369
|
-
status?: "active" | "pending" | undefined;
|
|
370
|
-
}, 201, "json">)>;
|
|
371
|
-
upload(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
372
|
-
message: string;
|
|
373
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
374
|
-
message: string;
|
|
375
|
-
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
376
|
-
message: string;
|
|
377
|
-
}, 413 | 415, "json">) | (Response & hono.TypedResponse<{
|
|
378
|
-
error: true;
|
|
379
|
-
message: string;
|
|
380
|
-
}, 403, "json">) | (Response & hono.TypedResponse<{
|
|
381
|
-
[x: string]: hono_utils_types.JSONValue;
|
|
382
|
-
}, 201, "json">)>;
|
|
383
|
-
update(c: Context<DyrectedContext>): Promise<Response>;
|
|
176
|
+
find(c: Context<DyrectedContext>): Promise<any>;
|
|
177
|
+
findOne(c: Context<DyrectedContext>): Promise<any>;
|
|
178
|
+
create(c: Context<DyrectedContext>): Promise<any>;
|
|
179
|
+
upload(c: Context<DyrectedContext>): Promise<any>;
|
|
180
|
+
update(c: Context<DyrectedContext>): Promise<any>;
|
|
384
181
|
/**
|
|
385
182
|
* Core update pipeline shared by PATCH requests and operational actions:
|
|
386
183
|
* auth-field stripping, timestamps, access enforcement, field write access,
|
|
@@ -394,59 +191,9 @@ declare class CollectionController {
|
|
|
394
191
|
* and every write flows through the standard update pipeline so the
|
|
395
192
|
* collection's lifecycle hooks and audit trail still apply.
|
|
396
193
|
*/
|
|
397
|
-
runViewAction(c: Context<DyrectedContext>): Promise<
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
error: true;
|
|
401
|
-
message: string;
|
|
402
|
-
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
403
|
-
error: true;
|
|
404
|
-
message: string;
|
|
405
|
-
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
406
|
-
error: true;
|
|
407
|
-
message: string;
|
|
408
|
-
}, 403, "json">) | (Response & hono.TypedResponse<never, any, "json">) | (Response & hono.TypedResponse<hono_utils_types.JSONValue, hono_utils_http_status.ContentfulStatusCode, "json">) | (Response & hono.TypedResponse<{
|
|
409
|
-
updated: number;
|
|
410
|
-
failed: number;
|
|
411
|
-
results: {
|
|
412
|
-
id: string;
|
|
413
|
-
ok: boolean;
|
|
414
|
-
status?: number | undefined;
|
|
415
|
-
doc?: hono_utils_types.JSONValue | undefined;
|
|
416
|
-
error?: hono_utils_types.JSONValue | undefined;
|
|
417
|
-
}[];
|
|
418
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
419
|
-
transition(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
420
|
-
message: string;
|
|
421
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
422
|
-
message: string;
|
|
423
|
-
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
424
|
-
[x: string]: any;
|
|
425
|
-
id: string;
|
|
426
|
-
} | null, hono_utils_http_status.ContentfulStatusCode, "json">) | (Response & hono.TypedResponse<{
|
|
427
|
-
error: true;
|
|
428
|
-
message: string;
|
|
429
|
-
}, 400, "json">)>;
|
|
430
|
-
workflowHistory(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
431
|
-
docs: {
|
|
432
|
-
[x: string]: any;
|
|
433
|
-
}[];
|
|
434
|
-
total: number;
|
|
435
|
-
limit: number;
|
|
436
|
-
page: number;
|
|
437
|
-
totalPages: number;
|
|
438
|
-
hasNextPage: boolean;
|
|
439
|
-
hasPrevPage: boolean;
|
|
440
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">) | (Response & hono.TypedResponse<{
|
|
441
|
-
message: string;
|
|
442
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
443
|
-
message: string;
|
|
444
|
-
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
445
|
-
message: string;
|
|
446
|
-
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
447
|
-
error: true;
|
|
448
|
-
message: string;
|
|
449
|
-
}, 403, "json">)>;
|
|
194
|
+
runViewAction(c: Context<DyrectedContext>): Promise<any>;
|
|
195
|
+
transition(c: Context<DyrectedContext>): Promise<any>;
|
|
196
|
+
workflowHistory(c: Context<DyrectedContext>): Promise<any>;
|
|
450
197
|
/**
|
|
451
198
|
* POST /api/collections/:slug/:id/change-password
|
|
452
199
|
*
|
|
@@ -458,69 +205,21 @@ declare class CollectionController {
|
|
|
458
205
|
* - Non-admin callers MUST provide a valid oldPassword.
|
|
459
206
|
* - newPassword and confirmPassword must match.
|
|
460
207
|
*/
|
|
461
|
-
changePassword(c: Context<DyrectedContext>): Promise<
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
message: string;
|
|
465
|
-
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
466
|
-
message: string;
|
|
467
|
-
}, 401, "json">) | (Response & hono.TypedResponse<{
|
|
468
|
-
message: string;
|
|
469
|
-
}, 403, "json">) | (Response & hono.TypedResponse<{
|
|
470
|
-
message: string;
|
|
471
|
-
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
472
|
-
success: true;
|
|
473
|
-
message: string;
|
|
474
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
475
|
-
delete(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
476
|
-
message: string;
|
|
477
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
478
|
-
deleteMany(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
479
|
-
message: string;
|
|
480
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
481
|
-
message: string;
|
|
482
|
-
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
483
|
-
failed?: {
|
|
484
|
-
id: string;
|
|
485
|
-
error: string;
|
|
486
|
-
}[] | undefined;
|
|
487
|
-
message: string;
|
|
488
|
-
deleted: string[];
|
|
489
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
208
|
+
changePassword(c: Context<DyrectedContext>): Promise<any>;
|
|
209
|
+
delete(c: Context<DyrectedContext>): Promise<any>;
|
|
210
|
+
deleteMany(c: Context<DyrectedContext>): Promise<any>;
|
|
490
211
|
seed(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
491
212
|
message: string;
|
|
492
213
|
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
493
|
-
aggregate(c: Context<DyrectedContext>): Promise<
|
|
494
|
-
message: string;
|
|
495
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
496
|
-
error: true;
|
|
497
|
-
message: string;
|
|
498
|
-
}, 403, "json">) | (Response & hono.TypedResponse<{
|
|
499
|
-
message: string;
|
|
500
|
-
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
501
|
-
[x: string]: any;
|
|
502
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
214
|
+
aggregate(c: Context<DyrectedContext>): Promise<any>;
|
|
503
215
|
}
|
|
504
216
|
|
|
505
217
|
declare class GlobalController {
|
|
506
218
|
private global;
|
|
507
219
|
constructor(global: GlobalConfig);
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
message: string;
|
|
512
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
513
|
-
error: true;
|
|
514
|
-
message: string;
|
|
515
|
-
}, 403, "json">)>;
|
|
516
|
-
update(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
517
|
-
[x: string]: hono_utils_types.JSONValue;
|
|
518
|
-
}, hono_utils_http_status.ContentfulStatusCode, "json">) | (Response & hono.TypedResponse<{
|
|
519
|
-
message: string;
|
|
520
|
-
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
521
|
-
error: true;
|
|
522
|
-
message: string;
|
|
523
|
-
}, 403, "json">)>;
|
|
220
|
+
private checkTenantAccess;
|
|
221
|
+
get(c: Context<DyrectedContext>): Promise<any>;
|
|
222
|
+
update(c: Context<DyrectedContext>): Promise<any>;
|
|
524
223
|
seed(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
525
224
|
message: string;
|
|
526
225
|
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
@@ -540,6 +239,18 @@ declare class MediaController {
|
|
|
540
239
|
[x: string]: any;
|
|
541
240
|
id: string;
|
|
542
241
|
}, 201, "json">)>;
|
|
242
|
+
replace(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
243
|
+
message: string;
|
|
244
|
+
}, 500, "json">) | (Response & hono.TypedResponse<{
|
|
245
|
+
message: string;
|
|
246
|
+
}, 400, "json">) | (Response & hono.TypedResponse<{
|
|
247
|
+
message: string;
|
|
248
|
+
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
249
|
+
message: string;
|
|
250
|
+
}, 413 | 415, "json">) | (Response & hono.TypedResponse<{
|
|
251
|
+
[x: string]: any;
|
|
252
|
+
id: string;
|
|
253
|
+
}, 200, "json">)>;
|
|
543
254
|
find(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
544
255
|
docs: {
|
|
545
256
|
[x: string]: any;
|
|
@@ -560,7 +271,7 @@ declare class MediaController {
|
|
|
560
271
|
message: string;
|
|
561
272
|
}, 404, "json">) | (Response & hono.TypedResponse<{
|
|
562
273
|
message: string;
|
|
563
|
-
}, 400, "json">) | (Response & hono.TypedResponse<any, hono_utils_http_status.ContentfulStatusCode, "body">)>;
|
|
274
|
+
}, 400, "json">) | (Response & hono.TypedResponse<undefined, 302, "redirect">) | (Response & hono.TypedResponse<any, hono_utils_http_status.ContentfulStatusCode, "body">)>;
|
|
564
275
|
}
|
|
565
276
|
|
|
566
277
|
declare class PreviewController {
|
|
@@ -598,4 +309,335 @@ declare class PreviewController {
|
|
|
598
309
|
}, 401, "json">)>;
|
|
599
310
|
}
|
|
600
311
|
|
|
601
|
-
|
|
312
|
+
declare class AIController {
|
|
313
|
+
private config;
|
|
314
|
+
constructor(config: DyrectedConfig);
|
|
315
|
+
private getAgent;
|
|
316
|
+
chat(c: Context<DyrectedContext>): Promise<Response>;
|
|
317
|
+
createThread(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
318
|
+
thread: {
|
|
319
|
+
[x: string]: hono_utils_types.JSONValue;
|
|
320
|
+
id: string;
|
|
321
|
+
projectId: string;
|
|
322
|
+
userId: string;
|
|
323
|
+
title?: string | undefined;
|
|
324
|
+
summary?: string | undefined;
|
|
325
|
+
createdAt: string;
|
|
326
|
+
updatedAt: string;
|
|
327
|
+
};
|
|
328
|
+
}, 201, "json">>;
|
|
329
|
+
listThreads(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
330
|
+
threads: {
|
|
331
|
+
[x: string]: hono_utils_types.JSONValue;
|
|
332
|
+
id: string;
|
|
333
|
+
projectId: string;
|
|
334
|
+
userId: string;
|
|
335
|
+
title?: string | undefined;
|
|
336
|
+
summary?: string | undefined;
|
|
337
|
+
createdAt: string;
|
|
338
|
+
updatedAt: string;
|
|
339
|
+
}[];
|
|
340
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
341
|
+
getThread(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
342
|
+
thread: {
|
|
343
|
+
[x: string]: hono_utils_types.JSONValue;
|
|
344
|
+
id: string;
|
|
345
|
+
projectId: string;
|
|
346
|
+
userId: string;
|
|
347
|
+
title?: string | undefined;
|
|
348
|
+
summary?: string | undefined;
|
|
349
|
+
createdAt: string;
|
|
350
|
+
updatedAt: string;
|
|
351
|
+
};
|
|
352
|
+
messages: {
|
|
353
|
+
[x: string]: hono_utils_types.JSONValue;
|
|
354
|
+
id: string;
|
|
355
|
+
threadId: string;
|
|
356
|
+
role: "user" | "assistant" | "system";
|
|
357
|
+
content: string;
|
|
358
|
+
parts?: any[] | undefined;
|
|
359
|
+
createdAt: string;
|
|
360
|
+
metadata?: {
|
|
361
|
+
[x: string]: hono_utils_types.JSONValue;
|
|
362
|
+
} | undefined;
|
|
363
|
+
}[];
|
|
364
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
365
|
+
postMessage(c: Context<DyrectedContext>): Promise<Response>;
|
|
366
|
+
deleteThread(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
367
|
+
success: true;
|
|
368
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
369
|
+
clearThreads(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
370
|
+
success: true;
|
|
371
|
+
count: number;
|
|
372
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
373
|
+
reindex(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
374
|
+
success: true;
|
|
375
|
+
collections: {
|
|
376
|
+
collection: string;
|
|
377
|
+
totalDocs: number;
|
|
378
|
+
indexedChunks: number;
|
|
379
|
+
}[];
|
|
380
|
+
totalChunks: number;
|
|
381
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
382
|
+
searchRAG(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
383
|
+
query: string;
|
|
384
|
+
resultsCount: number;
|
|
385
|
+
sources: {
|
|
386
|
+
id: string;
|
|
387
|
+
collection: string;
|
|
388
|
+
documentId: string;
|
|
389
|
+
title: string;
|
|
390
|
+
field: string;
|
|
391
|
+
score: number;
|
|
392
|
+
text: string;
|
|
393
|
+
url: string;
|
|
394
|
+
metadata?: {
|
|
395
|
+
[x: string]: hono_utils_types.JSONValue;
|
|
396
|
+
} | undefined;
|
|
397
|
+
}[];
|
|
398
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
399
|
+
getAction(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
400
|
+
action: {
|
|
401
|
+
[x: string]: any;
|
|
402
|
+
id: string;
|
|
403
|
+
};
|
|
404
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
405
|
+
executeAction(c: Context<DyrectedContext>): Promise<(Response & hono.TypedResponse<{
|
|
406
|
+
success: true;
|
|
407
|
+
message: string;
|
|
408
|
+
action: {
|
|
409
|
+
[x: string]: any;
|
|
410
|
+
id: string;
|
|
411
|
+
};
|
|
412
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">) | (Response & hono.TypedResponse<{
|
|
413
|
+
success: true;
|
|
414
|
+
action: {
|
|
415
|
+
[x: string]: any;
|
|
416
|
+
id: string;
|
|
417
|
+
};
|
|
418
|
+
result: any;
|
|
419
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">)>;
|
|
420
|
+
rejectAction(c: Context<DyrectedContext>): Promise<Response & hono.TypedResponse<{
|
|
421
|
+
success: true;
|
|
422
|
+
action: {
|
|
423
|
+
[x: string]: any;
|
|
424
|
+
id: string;
|
|
425
|
+
};
|
|
426
|
+
}, hono_utils_http_status.ContentfulStatusCode, "json">>;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
declare function getAIModel(config?: DyrectedConfig): LanguageModel;
|
|
430
|
+
declare function formatAIErrorMessage(error: any): string;
|
|
431
|
+
declare function buildDyrectedSystemPrompt(context: DyrectedAIContext): string;
|
|
432
|
+
interface AIAgentOptions {
|
|
433
|
+
db: DatabaseAdapter;
|
|
434
|
+
config: DyrectedConfig;
|
|
435
|
+
projectId: string;
|
|
436
|
+
userId: string;
|
|
437
|
+
userName?: string;
|
|
438
|
+
userRole?: string;
|
|
439
|
+
user?: AuthenticatedUser;
|
|
440
|
+
}
|
|
441
|
+
declare class AIAgent {
|
|
442
|
+
private db;
|
|
443
|
+
private config;
|
|
444
|
+
private projectId;
|
|
445
|
+
private userId;
|
|
446
|
+
private userName?;
|
|
447
|
+
private userRole?;
|
|
448
|
+
private user?;
|
|
449
|
+
private contextCache;
|
|
450
|
+
constructor(options: AIAgentOptions);
|
|
451
|
+
getContext(): Promise<DyrectedAIContext>;
|
|
452
|
+
getThread(threadId: string): Promise<AIThread | null>;
|
|
453
|
+
updateThreadTitle(threadId: string, title: string): Promise<void>;
|
|
454
|
+
createThread(title?: string, id?: string): Promise<AIThread>;
|
|
455
|
+
getOrCreateThread(threadId?: string, title?: string): Promise<AIThread>;
|
|
456
|
+
listThreads(limit?: number): Promise<AIThread[]>;
|
|
457
|
+
deleteThread(threadId: string): Promise<boolean>;
|
|
458
|
+
clearAllThreads(): Promise<number>;
|
|
459
|
+
getMessages(threadId: string): Promise<AIMessage[]>;
|
|
460
|
+
persistUserMessage(threadId: string, content: string): Promise<AIMessage>;
|
|
461
|
+
persistAssistantMessage(threadId: string, content: string, metadata?: Record<string, unknown>, parts?: any[]): Promise<AIMessage>;
|
|
462
|
+
generateTitle(userMessage: string): Promise<string>;
|
|
463
|
+
compactMessages(messages: Array<{
|
|
464
|
+
role: 'user' | 'assistant';
|
|
465
|
+
content: string;
|
|
466
|
+
}>): Array<{
|
|
467
|
+
role: 'user' | 'assistant';
|
|
468
|
+
content: string;
|
|
469
|
+
}>;
|
|
470
|
+
streamReply(threadId: string, userMessage: string): AsyncGenerator<string, {
|
|
471
|
+
text: string;
|
|
472
|
+
usage?: any;
|
|
473
|
+
finishReason: string;
|
|
474
|
+
}, void>;
|
|
475
|
+
createStreamResponse(threadId: string, userMessage: string, clientMessages?: any[], abortSignal?: AbortSignal, requestId?: string): Promise<Response>;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
declare function validatePayloadAgainstFields(fields: Array<{
|
|
479
|
+
name: string;
|
|
480
|
+
type: string;
|
|
481
|
+
required?: boolean;
|
|
482
|
+
}>, data: Record<string, unknown>, isPartial?: boolean): {
|
|
483
|
+
valid: boolean;
|
|
484
|
+
error?: string;
|
|
485
|
+
};
|
|
486
|
+
declare function createDyrectedAITools({ db, config, user, projectId, }: {
|
|
487
|
+
db: DatabaseAdapter;
|
|
488
|
+
config: DyrectedConfig;
|
|
489
|
+
user?: AuthenticatedUser;
|
|
490
|
+
projectId: string;
|
|
491
|
+
}): Record<string, any>;
|
|
492
|
+
|
|
493
|
+
interface IndexDocumentOptions {
|
|
494
|
+
db: DatabaseAdapter;
|
|
495
|
+
config: DyrectedConfig;
|
|
496
|
+
collection: string;
|
|
497
|
+
doc: Record<string, unknown>;
|
|
498
|
+
projectId: string;
|
|
499
|
+
force?: boolean;
|
|
500
|
+
}
|
|
501
|
+
interface DeleteDocumentChunksOptions {
|
|
502
|
+
db: DatabaseAdapter;
|
|
503
|
+
collection: string;
|
|
504
|
+
documentId: string;
|
|
505
|
+
projectId: string;
|
|
506
|
+
}
|
|
507
|
+
interface ReindexCollectionOptions {
|
|
508
|
+
db: DatabaseAdapter;
|
|
509
|
+
config: DyrectedConfig;
|
|
510
|
+
collection: string;
|
|
511
|
+
projectId: string;
|
|
512
|
+
force?: boolean;
|
|
513
|
+
}
|
|
514
|
+
interface ReindexAllOptions {
|
|
515
|
+
db: DatabaseAdapter;
|
|
516
|
+
config: DyrectedConfig;
|
|
517
|
+
projectId: string;
|
|
518
|
+
force?: boolean;
|
|
519
|
+
}
|
|
520
|
+
interface RAGSearchOptions {
|
|
521
|
+
db: DatabaseAdapter;
|
|
522
|
+
config: DyrectedConfig;
|
|
523
|
+
query: string;
|
|
524
|
+
projectId: string;
|
|
525
|
+
collections?: string[];
|
|
526
|
+
limit?: number;
|
|
527
|
+
minScore?: number;
|
|
528
|
+
user?: AuthenticatedUser;
|
|
529
|
+
}
|
|
530
|
+
declare class RAGService {
|
|
531
|
+
private static embeddingServiceCache;
|
|
532
|
+
private static getEmbeddingService;
|
|
533
|
+
/**
|
|
534
|
+
* Determines whether RAG indexing is enabled for a given collection.
|
|
535
|
+
*/
|
|
536
|
+
static isCollectionRAGEnabled(config: DyrectedConfig, col: CollectionConfig): boolean;
|
|
537
|
+
/**
|
|
538
|
+
* Indexes a single document's text fields into `_dyrected_ai_chunks`.
|
|
539
|
+
*/
|
|
540
|
+
static indexDocument(options: IndexDocumentOptions): Promise<{
|
|
541
|
+
indexed: number;
|
|
542
|
+
skipped: number;
|
|
543
|
+
}>;
|
|
544
|
+
/**
|
|
545
|
+
* Deletes all vector chunks associated with a specific document.
|
|
546
|
+
*/
|
|
547
|
+
static deleteDocumentChunks(options: DeleteDocumentChunksOptions): Promise<number>;
|
|
548
|
+
/**
|
|
549
|
+
* Reindexes all documents in a specific collection.
|
|
550
|
+
*/
|
|
551
|
+
static reindexCollection(options: ReindexCollectionOptions): Promise<{
|
|
552
|
+
collection: string;
|
|
553
|
+
totalDocs: number;
|
|
554
|
+
indexedChunks: number;
|
|
555
|
+
}>;
|
|
556
|
+
/**
|
|
557
|
+
* Reindexes all RAG-enabled collections across the project.
|
|
558
|
+
*/
|
|
559
|
+
static reindexAll(options: ReindexAllOptions): Promise<{
|
|
560
|
+
collections: Array<{
|
|
561
|
+
collection: string;
|
|
562
|
+
totalDocs: number;
|
|
563
|
+
indexedChunks: number;
|
|
564
|
+
}>;
|
|
565
|
+
totalChunks: number;
|
|
566
|
+
}>;
|
|
567
|
+
/**
|
|
568
|
+
* Performs semantic vector search over project chunks with access filtering.
|
|
569
|
+
*/
|
|
570
|
+
static search(options: RAGSearchOptions): Promise<{
|
|
571
|
+
query: string;
|
|
572
|
+
resultsCount: number;
|
|
573
|
+
sources: RAGSearchResult[];
|
|
574
|
+
}>;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Content normalizer for Dyrected CMS fields before chunking and embedding.
|
|
579
|
+
* Converts raw rich-text ASTs (Lexical, Slate, TipTap, custom blocks), HTML,
|
|
580
|
+
* JSON objects, and arrays into clean, structured Markdown.
|
|
581
|
+
*/
|
|
582
|
+
/**
|
|
583
|
+
* Normalizes an unknown field value into clean Markdown/text.
|
|
584
|
+
*/
|
|
585
|
+
declare function normalizeFieldValue(value: unknown, _fieldType?: string): string;
|
|
586
|
+
/**
|
|
587
|
+
* Extracts searchable text from target fields of a document.
|
|
588
|
+
*/
|
|
589
|
+
declare function extractTextFromDoc(doc: Record<string, unknown>, targetFields?: string[]): Array<{
|
|
590
|
+
field: string;
|
|
591
|
+
text: string;
|
|
592
|
+
}>;
|
|
593
|
+
|
|
594
|
+
interface ChunkOptions {
|
|
595
|
+
/** Maximum target characters per chunk. Defaults to 1500 (~375-500 tokens). */
|
|
596
|
+
maxChunkSize?: number;
|
|
597
|
+
/** Overlap in characters between consecutive chunks. Defaults to 150. */
|
|
598
|
+
chunkOverlap?: number;
|
|
599
|
+
/** Hierarchy of string separators for recursive splitting. */
|
|
600
|
+
separators?: string[];
|
|
601
|
+
}
|
|
602
|
+
interface ChunkResult {
|
|
603
|
+
text: string;
|
|
604
|
+
tokenCount: number;
|
|
605
|
+
index: number;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Computes a fast, collision-resistant 53-bit hex hash of a string.
|
|
609
|
+
* 100% isomorphic and pure JavaScript (safe across Node.js, Vite, Nuxt, and browsers).
|
|
610
|
+
*/
|
|
611
|
+
declare function hashContent(content: string, seed?: number): string;
|
|
612
|
+
/**
|
|
613
|
+
* Estimates token count based on standard ~4 characters per token heuristic.
|
|
614
|
+
*/
|
|
615
|
+
declare function estimateTokens(text: string): number;
|
|
616
|
+
/**
|
|
617
|
+
* Recursively splits a text into coherent chunks with overlap.
|
|
618
|
+
*/
|
|
619
|
+
declare function chunkText(text: string, options?: ChunkOptions): ChunkResult[];
|
|
620
|
+
|
|
621
|
+
declare function getEmbeddingModel(config?: DyrectedConfig): EmbeddingModel;
|
|
622
|
+
declare class EmbeddingService {
|
|
623
|
+
private config?;
|
|
624
|
+
private model;
|
|
625
|
+
constructor(config?: DyrectedConfig);
|
|
626
|
+
embedText(text: string): Promise<number[]>;
|
|
627
|
+
embedBatch(texts: string[]): Promise<number[][]>;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Computes cosine similarity between two float vector arrays.
|
|
631
|
+
* Returns a value between -1.0 and 1.0 (typically 0.0 to 1.0 for normalized text embeddings).
|
|
632
|
+
*/
|
|
633
|
+
declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
634
|
+
|
|
635
|
+
declare class InMemoryRateLimitStore implements AIRateLimitStore {
|
|
636
|
+
private windows;
|
|
637
|
+
constructor();
|
|
638
|
+
consume(key: string, limit: number, windowMs: number): Promise<AIRateLimitResult>;
|
|
639
|
+
clear(): void;
|
|
640
|
+
}
|
|
641
|
+
declare function aiRateLimit(config?: DyrectedConfig): (c: Context<DyrectedContext>, next: Next) => Promise<void>;
|
|
642
|
+
|
|
643
|
+
export { AIAgent, type AIAgentOptions, AIController, AuthController, type ChunkOptions, type ChunkResult, CollectionController, type DeleteDocumentChunksOptions, DyrectedContext, EmbeddingService, GlobalController, InMemoryRateLimitStore, type IndexDocumentOptions, MediaController, PreviewController, type RAGSearchOptions, RAGService, type ReindexAllOptions, type ReindexCollectionOptions, aiRateLimit, buildDyrectedSystemPrompt, chunkText, cosineSimilarity, createDyrectedAITools, estimateTokens, extractTextFromDoc, formatAIErrorMessage, getAIModel, getEmbeddingModel, hashContent, normalizeFieldValue, registerRoutes, serializeDetailForApi, serializeViewForApi, validatePayloadAgainstFields };
|