@nacre.work/api 0.7.0 → 0.10.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/adapters.d.ts +29 -1
- package/dist/adapters.d.ts.map +1 -1
- package/dist/adapters.js +135 -8
- package/dist/adapters.js.map +1 -1
- package/dist/auth.d.ts +36 -3
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +27 -2
- package/dist/auth.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +11 -57
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +18 -168
- package/dist/init.js.map +1 -1
- package/dist/main.js +4 -5
- package/dist/main.js.map +1 -1
- package/dist/oauth-store.d.ts +16 -4
- package/dist/oauth-store.d.ts.map +1 -1
- package/dist/oauth-store.js +42 -9
- package/dist/oauth-store.js.map +1 -1
- package/dist/principals.d.ts +0 -1
- package/dist/principals.d.ts.map +1 -1
- package/dist/principals.js +1 -25
- package/dist/principals.js.map +1 -1
- package/dist/rebuild-collection.js +2 -4
- package/dist/rebuild-collection.js.map +1 -1
- package/dist/server.d.ts +114 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +182 -5
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
package/dist/auth.d.ts
CHANGED
|
@@ -20,7 +20,18 @@ export interface AuthContext {
|
|
|
20
20
|
*/
|
|
21
21
|
readonly delegation?: {
|
|
22
22
|
readonly id: string;
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The narrowing, and each layer's own ceiling where the person set one.
|
|
25
|
+
*
|
|
26
|
+
* `undefined` means no narrowing — never "narrowed to nothing", which is a
|
|
27
|
+
* different state and is deliberately not expressible. A layer with no
|
|
28
|
+
* `permissions` of its own inherits the connection's, which is what every
|
|
29
|
+
* narrowing written before per-layer ceilings meant and still means.
|
|
30
|
+
*/
|
|
31
|
+
readonly layers?: readonly {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly permissions?: readonly Permission[];
|
|
34
|
+
}[];
|
|
24
35
|
/**
|
|
25
36
|
* The permissions this token may exercise. Absent means no ceiling.
|
|
26
37
|
*
|
|
@@ -49,7 +60,11 @@ export interface Delegations {
|
|
|
49
60
|
resolve(orgId: string, id: string): Promise<{
|
|
50
61
|
userId: string;
|
|
51
62
|
role: OrgRole;
|
|
52
|
-
|
|
63
|
+
/** The narrowing, each layer carrying its own ceiling where one was set. */
|
|
64
|
+
layers?: readonly {
|
|
65
|
+
readonly id: string;
|
|
66
|
+
readonly permissions?: readonly Permission[];
|
|
67
|
+
}[];
|
|
53
68
|
permissions?: readonly Permission[];
|
|
54
69
|
} | undefined>;
|
|
55
70
|
}
|
|
@@ -160,7 +175,25 @@ export declare function administersTenants(auth: AuthContext): boolean;
|
|
|
160
175
|
* its target — where the same restriction has to hold and there is no traversal
|
|
161
176
|
* to put it inside of.
|
|
162
177
|
*/
|
|
163
|
-
export declare function withinDelegation(auth: AuthContext, layerId: string): boolean;
|
|
178
|
+
export declare function withinDelegation(auth: AuthContext, layerId: string, permission: Permission): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* The layers this delegation admits for one permission, or `undefined` for no
|
|
181
|
+
* narrowing at all.
|
|
182
|
+
*
|
|
183
|
+
* The permission argument is the whole of per-layer ceilings: a narrowing used
|
|
184
|
+
* to be one set of layer ids and is now one set *per permission*, because
|
|
185
|
+
* "read the handbook, write to scratch" is what a person means and a single set
|
|
186
|
+
* cannot say it.
|
|
187
|
+
*
|
|
188
|
+
* Required rather than optional, so every existing call site is a compile error
|
|
189
|
+
* until it says which permission it is asking about. That is the check here —
|
|
190
|
+
* the rule has to hold in five places and nothing else knows five.
|
|
191
|
+
*
|
|
192
|
+
* An empty result is a real answer and not the same as `undefined`: it means
|
|
193
|
+
* the narrowing exists and no layer in it admits this permission, which every
|
|
194
|
+
* caller turns into the same nothing an unreachable object gets.
|
|
195
|
+
*/
|
|
196
|
+
export declare function delegatedLayers(auth: AuthContext, permission: Permission): readonly string[] | undefined;
|
|
164
197
|
export declare function findTenantOverride(value: unknown, path?: string[]): string | undefined;
|
|
165
198
|
/**
|
|
166
199
|
* T2. A body, path, or header naming an organization is refused with 403.
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,SAAS,EAEf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,MAAM,CAAA;AAEjE,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,aAAa,CAAA;AAEnE,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE;QACpB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,SAAS,EAEf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,MAAM,CAAA;AAEjE,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,aAAa,CAAA;AAEnE,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,SAAS,EAAE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AAM,GAAG,SAAS,EACjC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,WAAW,GAAG,OAAO,CAAC,CAkIhC"}
|
package/dist/auth.js
CHANGED
|
@@ -60,9 +60,34 @@ export function administersTenants(auth) {
|
|
|
60
60
|
* its target — where the same restriction has to hold and there is no traversal
|
|
61
61
|
* to put it inside of.
|
|
62
62
|
*/
|
|
63
|
-
export function withinDelegation(auth, layerId) {
|
|
63
|
+
export function withinDelegation(auth, layerId, permission) {
|
|
64
|
+
const admitted = delegatedLayers(auth, permission);
|
|
65
|
+
return admitted === undefined || admitted.includes(layerId);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The layers this delegation admits for one permission, or `undefined` for no
|
|
69
|
+
* narrowing at all.
|
|
70
|
+
*
|
|
71
|
+
* The permission argument is the whole of per-layer ceilings: a narrowing used
|
|
72
|
+
* to be one set of layer ids and is now one set *per permission*, because
|
|
73
|
+
* "read the handbook, write to scratch" is what a person means and a single set
|
|
74
|
+
* cannot say it.
|
|
75
|
+
*
|
|
76
|
+
* Required rather than optional, so every existing call site is a compile error
|
|
77
|
+
* until it says which permission it is asking about. That is the check here —
|
|
78
|
+
* the rule has to hold in five places and nothing else knows five.
|
|
79
|
+
*
|
|
80
|
+
* An empty result is a real answer and not the same as `undefined`: it means
|
|
81
|
+
* the narrowing exists and no layer in it admits this permission, which every
|
|
82
|
+
* caller turns into the same nothing an unreachable object gets.
|
|
83
|
+
*/
|
|
84
|
+
export function delegatedLayers(auth, permission) {
|
|
64
85
|
const narrowing = auth.delegation?.layers;
|
|
65
|
-
|
|
86
|
+
if (narrowing === undefined)
|
|
87
|
+
return undefined;
|
|
88
|
+
return narrowing
|
|
89
|
+
.filter((l) => l.permissions === undefined || l.permissions.includes(permission))
|
|
90
|
+
.map((l) => l.id);
|
|
66
91
|
}
|
|
67
92
|
/**
|
|
68
93
|
* Fields a request body, path, or query string may never carry.
|
package/dist/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAKd,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,SAAS,EAAmC,MAAM,MAAM,CAAA;AAEjE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,GAKd,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,SAAS,EAAmC,MAAM,MAAM,CAAA;AAEjE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAgB,MAAM,aAAa,CAAA;AAkInE;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAiB,EAAE,UAAsB;IACzE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,EAAE,WAAW,CAAA;IAC5C,OAAO,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;AAC9D,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,WAAW,CAAC,IAAiB;IAC3C,OAAO,IAAI,CAAC,IAAI,KAAK,WAAW,IAAI,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACtE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAiB;IAClD,OAAO,IAAI,CAAC,IAAI,KAAK,gBAAgB,CAAA;AACvC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAC9B,IAAiB,EACjB,OAAe,EACf,UAAsB;IAEtB,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAClD,OAAO,QAAQ,KAAK,SAAS,IAAI,QAA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G,CAAC,UAAU,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,CAAC;SACzF;KACF,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export { createApi } from './server.js';
|
|
2
2
|
export type { ApiOptions, AuditEvent, AuditQuery, AuditReader, AuditRecord, Reindex, ReindexOutcome, ReindexStatus, ReferenceQueries, ReferenceQuery, RecallCheck, AuditWriter, DocumentView, Documents, GrantInput, GrantRecord, Grants, Ingest, IngestOutcome, IngestRequest, Job, Jobs, Layer, LayerOutcome, Layers, SearchHit, SearchOptions, SearchService, ServiceAccountPort, ServiceAccountView, } from './server.js';
|
|
3
|
-
export { administers, administersTenants, authenticate, delegationPermits, findTenantOverride, rejectTenantOverride, withinDelegation, } from './auth.js';
|
|
3
|
+
export { administers, administersTenants, authenticate, delegationPermits, findTenantOverride, rejectTenantOverride, delegatedLayers, withinDelegation, } from './auth.js';
|
|
4
4
|
export type { AuthContext, Delegations, VerifyOptions } from './auth.js';
|
|
5
5
|
export { postgresVerification } from './verification.js';
|
|
6
6
|
export { PostgresDelegations, PostgresOAuthAuthorizations, PostgresOAuthClients, PostgresOAuthConsents, PostgresOAuthRefreshTokens, } from './oauth-store.js';
|
|
7
7
|
export type { Consent, ConsentSubject, MintRequest, OAuthAuthorizations, OAuthClients, OAuthConsents, OAuthRefreshTokens, PendingAuthorization, RegisteredClient, } from './oauth-store.js';
|
|
8
8
|
export { Problem, badRequest, forbidden, internal, notFound, unauthorized } from './errors.js';
|
|
9
|
-
export { HttpEmbedder, NacreIngest, NacreSearchService, PostgresAudit, PostgresAuditReader, PostgresDocuments, PostgresGrants, PostgresJobs, PostgresLayers, PostgresWorkspaces, PostgresReferenceQueries, PostgresReindex, } from './adapters.js';
|
|
9
|
+
export { HttpEmbedder, NacreIngest, NacreSearchService, PostgresAudit, PostgresAuditReader, PostgresDocuments, PostgresGrants, PostgresJobs, PostgresEmbeddingProviders, PostgresLayers, PostgresWorkspaces, PostgresReferenceQueries, PostgresReindex, } from './adapters.js';
|
|
10
10
|
export type { DocumentTombstone, Embedder, IngestDeps, ObjectStore, PrincipalsCache, SearchDeps, } from './adapters.js';
|
|
11
|
-
export { PostgresGroups, PostgresUsers,
|
|
11
|
+
export { PostgresGroups, PostgresUsers, looksLikeEmail } from './principals.js';
|
|
12
|
+
export { generatePassword } from '@nacre.work/core';
|
|
12
13
|
export type { GroupMember, Groups, GroupView, Users, UserView } from './principals.js';
|
|
13
14
|
export { applyRanking, HttpReranker, rerankerFor } from './rerank.js';
|
|
14
15
|
export type { Reranker } from './rerank.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,YAAY,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,MAAM,EACN,aAAa,EACb,aAAa,EACb,GAAG,EACH,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,MAAM,EACN,SAAS,EACT,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,WAAW,CAAA;AAClB,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAA;AACzB,YAAY,EACV,OAAO,EACP,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC9F,OAAO,EACL,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,GAChB,MAAM,eAAe,CAAA;AACtB,YAAY,EACV,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,eAAe,EACf,UAAU,GACX,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,YAAY,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,EACV,WAAW,EACX,MAAM,EACN,MAAM,EACN,aAAa,EACb,aAAa,EACb,GAAG,EACH,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,MAAM,EACN,SAAS,EACT,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,O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a,CAAA;AACrE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EACL,WAAW,EACX,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,GACT,MAAM,mBAAmB,CAAA;AAC1B,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAK5F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3F,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACvD,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export { createApi } from './server.js';
|
|
2
|
-
export { administers, administersTenants, authenticate, delegationPermits, findTenantOverride, rejectTenantOverride, withinDelegation, } from './auth.js';
|
|
2
|
+
export { administers, administersTenants, authenticate, delegationPermits, findTenantOverride, rejectTenantOverride, delegatedLayers, withinDelegation, } from './auth.js';
|
|
3
3
|
export { postgresVerification } from './verification.js';
|
|
4
4
|
export { PostgresDelegations, PostgresOAuthAuthorizations, PostgresOAuthClients, PostgresOAuthConsents, PostgresOAuthRefreshTokens, } from './oauth-store.js';
|
|
5
5
|
export { Problem, badRequest, forbidden, internal, notFound, unauthorized } from './errors.js';
|
|
6
|
-
export { HttpEmbedder, NacreIngest, NacreSearchService, PostgresAudit, PostgresAuditReader, PostgresDocuments, PostgresGrants, PostgresJobs, PostgresLayers, PostgresWorkspaces, PostgresReferenceQueries, PostgresReindex, } from './adapters.js';
|
|
7
|
-
export { PostgresGroups, PostgresUsers,
|
|
6
|
+
export { HttpEmbedder, NacreIngest, NacreSearchService, PostgresAudit, PostgresAuditReader, PostgresDocuments, PostgresGrants, PostgresJobs, PostgresEmbeddingProviders, PostgresLayers, PostgresWorkspaces, PostgresReferenceQueries, PostgresReindex, } from './adapters.js';
|
|
7
|
+
export { PostgresGroups, PostgresUsers, looksLikeEmail } from './principals.js';
|
|
8
|
+
// Re-exported rather than defined here. It moved to the core when the second
|
|
9
|
+
// copy of its word list was found; this keeps an existing importer working and
|
|
10
|
+
// makes it visibly one function rather than two agreeing.
|
|
11
|
+
export { generatePassword } from '@nacre.work/core';
|
|
8
12
|
export { applyRanking, HttpReranker, rerankerFor } from './rerank.js';
|
|
9
13
|
export { generateKey, hashOf, KEY_PREFIX, looksLikeServiceKey, PostgresServiceAccounts, PostgresServiceKeys, prefixOf, } from './service-keys.js';
|
|
10
14
|
// The limiter, so the MCP transport can share it rather than growing a second
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAiCvC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,kBAAkB,CAAA;AAYzB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAA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A;AAErE,OAAO,EACL,WAAW,EACX,MAAM,EACN,UAAU,EACV,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,GACT,MAAM,mBAAmB,CAAA;AAE1B,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,+CAA+C;AAC/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3F,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/init.d.ts
CHANGED
|
@@ -1,68 +1,22 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProvisionOptions } from '@nacre.work/core';
|
|
2
2
|
/**
|
|
3
|
-
* Create the first organization.
|
|
3
|
+
* Create the first organization — the command, not the provisioning.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* installation begins.
|
|
5
|
+
* What a new organization is made of lives in `provisionOrganization`, in the
|
|
6
|
+
* core, because this command is one caller and not the definition. Everything
|
|
7
|
+
* here is what a *terminal* needs and an API caller does not: parsing
|
|
8
|
+
* arguments, generating a password that must never come from one, minting a
|
|
9
|
+
* token to get through the quickstart, and printing all of it.
|
|
11
10
|
*
|
|
12
11
|
* A one-shot command rather than an endpoint, because an HTTP route that
|
|
13
|
-
* creates the first organization has to be reachable before any organization
|
|
12
|
+
* creates the *first* organization has to be reachable before any organization
|
|
14
13
|
* exists, which means unauthenticated, which means it has to be disabled again
|
|
15
14
|
* afterwards. Every version of that is a race between the first deploy and the
|
|
16
15
|
* internet. A command runs where the operator already has credentials.
|
|
17
16
|
*
|
|
18
|
-
* Idempotent: run it twice and the second run
|
|
19
|
-
*
|
|
20
|
-
* install — the collection created, the process killed before the workspace —
|
|
21
|
-
* and refusing to continue from it would leave no way forward but manual SQL.
|
|
17
|
+
* Idempotent, because the function it calls is: run it twice and the second run
|
|
18
|
+
* reports what already existed and changes nothing.
|
|
22
19
|
*/
|
|
23
|
-
export
|
|
24
|
-
readonly slug: string;
|
|
25
|
-
readonly name: string;
|
|
26
|
-
readonly email: string;
|
|
27
|
-
readonly workspace: string;
|
|
28
|
-
/**
|
|
29
|
-
* Set on the administrator, when there is one to set.
|
|
30
|
-
*
|
|
31
|
-
* Passed in already hashed rather than as a plaintext to hash here: `init`
|
|
32
|
-
* runs in a terminal and its arguments end up in a shell history and in
|
|
33
|
-
* `ps`, so the password is generated rather than accepted, and the plaintext
|
|
34
|
-
* exists in exactly one place — the line printed at the end.
|
|
35
|
-
*/
|
|
36
|
-
readonly passwordHash?: string;
|
|
37
|
-
}
|
|
20
|
+
export type Options = ProvisionOptions;
|
|
38
21
|
export declare function parseArgs(argv: readonly string[]): Options | string;
|
|
39
|
-
export interface InitResult {
|
|
40
|
-
readonly orgId: string;
|
|
41
|
-
readonly userId: string;
|
|
42
|
-
readonly workspaceId: string;
|
|
43
|
-
/** False when the organization was already there — the run changed nothing. */
|
|
44
|
-
readonly created: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Whether **this run** set the administrator's password.
|
|
47
|
-
*
|
|
48
|
-
* False on every re-run, because the upsert deliberately leaves an existing
|
|
49
|
-
* hash alone. The caller needs to know because it generated a plaintext
|
|
50
|
-
* before calling, and printing one the database did not accept is worse than
|
|
51
|
-
* printing nothing: an operator writes it down, discards the real one, and
|
|
52
|
-
* finds out an hour later when the token from the first run expires.
|
|
53
|
-
*/
|
|
54
|
-
readonly passwordSet: boolean;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The database half, in one transaction.
|
|
58
|
-
*
|
|
59
|
-
* Separate from `main` so it can be tested: idempotency is the property that
|
|
60
|
-
* matters here and the one that regresses silently, because the second run of
|
|
61
|
-
* something non-idempotent usually still exits zero.
|
|
62
|
-
*/
|
|
63
|
-
export declare function initialize(pool: Pool, options: Options, provider: {
|
|
64
|
-
endpoint: string;
|
|
65
|
-
model: string;
|
|
66
|
-
dimensions: number;
|
|
67
|
-
}, collection: string, log?: (msg: string, extra?: Record<string, unknown>) => void): Promise<InitResult>;
|
|
68
22
|
//# sourceMappingURL=init.d.ts.map
|
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAIxD;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,MAAM,OAAO,GAAG,gBAAgB,CAAA;AAEtC,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,GAAG,MAAM,CA6BnE"}
|
package/dist/init.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConfigError, createPool, generatePassword, hashPassword, loadConfig, loadJwtKeys, organizationSlugError, provisionOrganization, VectorStore, vectorStoreOptions, } from '@nacre.work/core';
|
|
2
2
|
import { SignJWT } from 'jose';
|
|
3
|
-
import { randomInt } from 'node:crypto';
|
|
4
3
|
import { pathToFileURL } from 'node:url';
|
|
5
4
|
export function parseArgs(argv) {
|
|
6
5
|
const values = new Map();
|
|
@@ -17,11 +16,12 @@ export function parseArgs(argv) {
|
|
|
17
16
|
if (slug === undefined || email === undefined) {
|
|
18
17
|
return 'usage: nacre-init --org <slug> --email <address> [--name <display name>] [--workspace <slug>]';
|
|
19
18
|
}
|
|
20
|
-
// The
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
// The same rule `provisionOrganization` applies, asked here only to turn it
|
|
20
|
+
// into a usage message. The function refuses regardless, which is what keeps
|
|
21
|
+
// this from being the copy that drifts.
|
|
22
|
+
const wrong = organizationSlugError(slug);
|
|
23
|
+
if (wrong !== undefined)
|
|
24
|
+
return `--org ${wrong}`;
|
|
25
25
|
if (!email.includes('@'))
|
|
26
26
|
return `--email does not look like an address: ${email}`;
|
|
27
27
|
return {
|
|
@@ -34,147 +34,6 @@ export function parseArgs(argv) {
|
|
|
34
34
|
const say = (msg, extra = {}) => {
|
|
35
35
|
console.log(JSON.stringify({ msg, ...extra }));
|
|
36
36
|
};
|
|
37
|
-
/**
|
|
38
|
-
* The database half, in one transaction.
|
|
39
|
-
*
|
|
40
|
-
* Separate from `main` so it can be tested: idempotency is the property that
|
|
41
|
-
* matters here and the one that regresses silently, because the second run of
|
|
42
|
-
* something non-idempotent usually still exits zero.
|
|
43
|
-
*/
|
|
44
|
-
export async function initialize(pool, options, provider, collection, log = () => undefined) {
|
|
45
|
-
const client = await pool.connect();
|
|
46
|
-
try {
|
|
47
|
-
await client.query('BEGIN');
|
|
48
|
-
const { rows: orgs } = await client.query(`WITH ins AS (
|
|
49
|
-
INSERT INTO organizations (slug, name, vector_collection)
|
|
50
|
-
VALUES ($1,$2,$3) ON CONFLICT (slug) DO NOTHING
|
|
51
|
-
RETURNING id
|
|
52
|
-
)
|
|
53
|
-
SELECT id, false AS existed FROM ins
|
|
54
|
-
UNION ALL
|
|
55
|
-
SELECT id, true AS existed FROM organizations WHERE slug = $1
|
|
56
|
-
LIMIT 1`, [options.slug, options.name, collection]);
|
|
57
|
-
const org = orgs[0];
|
|
58
|
-
if (org === undefined)
|
|
59
|
-
throw new Error('the organization insert returned no row');
|
|
60
|
-
log(org.existed ? 'organization already existed' : 'organization created', {
|
|
61
|
-
org_id: org.id,
|
|
62
|
-
slug: options.slug,
|
|
63
|
-
});
|
|
64
|
-
// RLS is forced on every tenant table, so everything below this line needs
|
|
65
|
-
// the organization in the transaction-local setting. The organizations row
|
|
66
|
-
// itself is not covered — it is the tenant registry, not tenant data.
|
|
67
|
-
await client.query('SELECT set_config($1, $2, true)', ['app.current_org', org.id]);
|
|
68
|
-
const { rows: users } = await client.query(
|
|
69
|
-
// The password is set only when this run generated one — re-running init
|
|
70
|
-
// against an existing organization must not silently reset the
|
|
71
|
-
// administrator's password and lock them out of their own installation.
|
|
72
|
-
//
|
|
73
|
-
// `password_set` reports whether the COALESCE above took this run's value
|
|
74
|
-
// or kept the stored one, by comparing the row as written against what
|
|
75
|
-
// was offered. The caller has a plaintext in hand either way and must not
|
|
76
|
-
// print it when the answer is no: the hash carries its own salt, so two
|
|
77
|
-
// hashes of the same password differ, and equality here can only mean
|
|
78
|
-
// this statement is what put it there.
|
|
79
|
-
`INSERT INTO users (org_id, email, role, password_hash) VALUES ($1,$2,'org_admin',$3)
|
|
80
|
-
ON CONFLICT (org_id, email) DO UPDATE
|
|
81
|
-
SET email = EXCLUDED.email,
|
|
82
|
-
password_hash = COALESCE(users.password_hash, EXCLUDED.password_hash)
|
|
83
|
-
RETURNING id, ($3 IS NOT NULL AND password_hash IS NOT DISTINCT FROM $3) AS password_set`, [org.id, options.email, options.passwordHash ?? null]);
|
|
84
|
-
const userId = users[0]?.id;
|
|
85
|
-
if (userId === undefined)
|
|
86
|
-
throw new Error('the user insert returned no row');
|
|
87
|
-
log('admin user ready', {
|
|
88
|
-
user_id: userId,
|
|
89
|
-
email: options.email,
|
|
90
|
-
password_set: users[0]?.password_set === true,
|
|
91
|
-
});
|
|
92
|
-
// Shared across organizations by default: one endpoint serves every tenant
|
|
93
|
-
// in a self-hosted install, and a per-organization provider is the
|
|
94
|
-
// exception rather than the shape to create on day one.
|
|
95
|
-
//
|
|
96
|
-
// This row carries `org_id = NULL`, and since 0019 a tenant-scoped role
|
|
97
|
-
// cannot write one — the RESTRICTIVE policies on `embedding_providers`
|
|
98
|
-
// require `org_id = current_setting('app.current_org')`, which NULL fails.
|
|
99
|
-
// That is the point: the installation default is not a tenant's to change.
|
|
100
|
-
// Writing it is a bootstrap act, so this one statement runs under
|
|
101
|
-
// `nacre_worker`, the BYPASSRLS role the worker's queue already uses;
|
|
102
|
-
// `nacre_app` is a member of it (migration 0008), so the switch is
|
|
103
|
-
// available wherever init connects. `SET LOCAL` reverts at COMMIT, and it
|
|
104
|
-
// is reset immediately below so nothing after it bypasses RLS.
|
|
105
|
-
await client.query('SET LOCAL ROLE nacre_worker');
|
|
106
|
-
const { rows: providers } = await client.query(`WITH ins AS (
|
|
107
|
-
INSERT INTO embedding_providers (org_id, name, endpoint, model, dimensions)
|
|
108
|
-
SELECT NULL,'default',$1,$2,$3
|
|
109
|
-
WHERE NOT EXISTS (SELECT 1 FROM embedding_providers WHERE org_id IS NULL)
|
|
110
|
-
RETURNING id
|
|
111
|
-
)
|
|
112
|
-
SELECT id FROM ins
|
|
113
|
-
UNION ALL
|
|
114
|
-
SELECT id FROM embedding_providers WHERE org_id IS NULL
|
|
115
|
-
LIMIT 1`, [provider.endpoint, provider.model, provider.dimensions]);
|
|
116
|
-
await client.query('RESET ROLE');
|
|
117
|
-
const providerId = providers[0]?.id;
|
|
118
|
-
if (providerId === undefined)
|
|
119
|
-
throw new Error('the embedding provider insert returned no row');
|
|
120
|
-
log('embedding provider ready', { provider_id: providerId, model: provider.model });
|
|
121
|
-
const { rows: workspaces } = await client.query(`WITH ins AS (
|
|
122
|
-
-- slug and name take separate parameters despite the same value: slug
|
|
123
|
-
-- is citext, name is text, and Postgres refuses to deduce one type for
|
|
124
|
-
-- a parameter feeding both.
|
|
125
|
-
INSERT INTO workspaces (org_id, slug, name) VALUES ($1,$2,$3)
|
|
126
|
-
ON CONFLICT (org_id, slug) DO NOTHING
|
|
127
|
-
RETURNING id
|
|
128
|
-
)
|
|
129
|
-
SELECT id FROM ins
|
|
130
|
-
UNION ALL
|
|
131
|
-
SELECT id FROM workspaces WHERE org_id = $1 AND slug = $2
|
|
132
|
-
LIMIT 1`, [org.id, options.workspace, options.workspace]);
|
|
133
|
-
const workspaceId = workspaces[0]?.id;
|
|
134
|
-
if (workspaceId === undefined)
|
|
135
|
-
throw new Error('the workspace insert returned no row');
|
|
136
|
-
log('workspace ready', { workspace_id: workspaceId, slug: options.workspace });
|
|
137
|
-
await client.query('COMMIT');
|
|
138
|
-
return {
|
|
139
|
-
orgId: org.id,
|
|
140
|
-
userId,
|
|
141
|
-
workspaceId,
|
|
142
|
-
created: !org.existed,
|
|
143
|
-
passwordSet: users[0]?.password_set === true,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
await client.query('ROLLBACK').catch(() => { });
|
|
148
|
-
throw error;
|
|
149
|
-
}
|
|
150
|
-
finally {
|
|
151
|
-
client.release();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Six words and a number, from the CSPRNG.
|
|
156
|
-
*
|
|
157
|
-
* Roughly 70 bits with this list, which is more than a person would choose and
|
|
158
|
-
* still something they can read off a terminal and type into a form once. A
|
|
159
|
-
* base64 string of the same strength gets copied wrong, and the recovery from
|
|
160
|
-
* that is re-running init against a live installation.
|
|
161
|
-
*/
|
|
162
|
-
function generatePassword() {
|
|
163
|
-
const words = [
|
|
164
|
-
'abalone', 'anchor', 'aurora', 'basalt', 'beacon', 'bramble', 'cinder', 'clover',
|
|
165
|
-
'compass', 'coral', 'crest', 'current', 'delta', 'drift', 'ember', 'estuary',
|
|
166
|
-
'fathom', 'ferry', 'fjord', 'granite', 'harbor', 'haven', 'iris', 'kelp',
|
|
167
|
-
'lantern', 'ledger', 'lichen', 'mantle', 'marlin', 'meadow', 'mica', 'nacre',
|
|
168
|
-
'nautilus', 'obsidian', 'onyx', 'opal', 'orbit', 'pearl', 'pelagic', 'pillar',
|
|
169
|
-
'plover', 'quarry', 'quartz', 'reef', 'ripple', 'salt', 'sextant', 'shale',
|
|
170
|
-
'shoal', 'silt', 'slate', 'spindrift', 'stratum', 'tide', 'trawler', 'trench',
|
|
171
|
-
'vellum', 'wharf', 'willow', 'zephyr',
|
|
172
|
-
];
|
|
173
|
-
// randomInt rather than Math.random or a modulo of randomBytes: one is not a
|
|
174
|
-
// CSPRNG and the other is biased unless the range divides evenly.
|
|
175
|
-
const chosen = Array.from({ length: 6 }, () => words[randomInt(words.length)]);
|
|
176
|
-
return `${chosen.join('-')}-${String(randomInt(10, 100))}`;
|
|
177
|
-
}
|
|
178
37
|
async function main() {
|
|
179
38
|
const parsed = parseArgs(process.argv.slice(2));
|
|
180
39
|
if (typeof parsed === 'string')
|
|
@@ -192,26 +51,17 @@ async function main() {
|
|
|
192
51
|
const password = generatePassword();
|
|
193
52
|
const passwordHash = await hashPassword(password);
|
|
194
53
|
const pool = createPool({ connectionString: config.pgUrl, max: 2 });
|
|
195
|
-
const
|
|
196
|
-
const collection = collectionName(parsed.slug);
|
|
54
|
+
const vectors = new VectorStore(vectorStoreOptions(config));
|
|
197
55
|
try {
|
|
198
|
-
|
|
56
|
+
// Both stores, in the order that survives a failure between them, and with
|
|
57
|
+
// the collection's slot named after the provider that was actually
|
|
58
|
+
// resolved rather than after this process's configuration. See
|
|
59
|
+
// `provisionOrganization`.
|
|
60
|
+
const ids = await provisionOrganization(pool, vectors, { ...parsed, passwordHash }, {
|
|
199
61
|
endpoint: config.embeddingEndpoint,
|
|
200
62
|
model: config.embeddingModel,
|
|
201
63
|
dimensions: config.embeddingDim,
|
|
202
|
-
},
|
|
203
|
-
// Qdrant after Postgres commits. The reverse order can leave a collection
|
|
204
|
-
// belonging to an organization that was rolled back, and the next run with
|
|
205
|
-
// the same slug would then adopt it.
|
|
206
|
-
//
|
|
207
|
-
// `ensureCollection` is already idempotent and already creates the payload
|
|
208
|
-
// indexes, which is the part worth not reimplementing: a filter that falls
|
|
209
|
-
// back to a scan is a latency problem that only appears at volume.
|
|
210
|
-
const vectors = new VectorStore(config.qdrantApiKey === undefined
|
|
211
|
-
? { url: config.qdrantUrl }
|
|
212
|
-
: { url: config.qdrantUrl, apiKey: config.qdrantApiKey });
|
|
213
|
-
await vectors.ensureCollection(parsed.slug, vector, config.embeddingDim);
|
|
214
|
-
say('collection ready', { collection, vector, dimensions: config.embeddingDim });
|
|
64
|
+
}, say);
|
|
215
65
|
// A short life on purpose. It is signed by the same key the API verifies
|
|
216
66
|
// with, printed to a terminal and probably into a shell history; it exists
|
|
217
67
|
// to get through the quickstart, not to be the credential an installation
|
|
@@ -276,10 +126,10 @@ async function main() {
|
|
|
276
126
|
await pool.end();
|
|
277
127
|
}
|
|
278
128
|
}
|
|
279
|
-
// Only when run as a command. This module is also imported — `
|
|
280
|
-
//
|
|
281
|
-
//
|
|
282
|
-
//
|
|
129
|
+
// Only when run as a command. This module is also imported — `parseArgs` is the
|
|
130
|
+
// part with a test on it — and an unguarded call here runs the whole command on
|
|
131
|
+
// import, which under a test runner means `process.exit(2)` in the middle of
|
|
132
|
+
// somebody else's suite.
|
|
283
133
|
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
284
134
|
main().catch((error) => {
|
|
285
135
|
if (error instanceof ConfigError) {
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EACX,kBAAkB,GACnB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAuBxC,MAAM,UAAU,SAAS,CAAC,IAAuB;IAC/C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;IACxC,KAAK,IAAI,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AAA;IAClB,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,gFAAgF;AAChF,6EAA6E;AAC7E,yBAAyB;AACzB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7F,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAC9B,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAA;QAC3E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/main.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { configureLogging, collectDatabaseGauges, createMetrics, createPool, loadConfig, loadedExtensions, loadModules, logger, loadJwtKeys, keyFingerprint, protectedResourceMetadata, Redis, RedisCache, Registry, S3, VectorStore, pendingMigrations, withOrg, ConfigError, installGuards, onListenError, } from '@nacre.work/core';
|
|
2
|
-
import { HttpEmbedder, NacreIngest, NacreSearchService, PostgresAudit, PostgresAuditReader, PostgresDocuments, PostgresGrants, PostgresJobs, PostgresLayers, PostgresReferenceQueries, PostgresReindex, PostgresWorkspaces, } from './adapters.js';
|
|
1
|
+
import { configureLogging, collectDatabaseGauges, createMetrics, createPool, loadConfig, loadedExtensions, loadModules, logger, loadJwtKeys, keyFingerprint, protectedResourceMetadata, Redis, RedisCache, Registry, S3, VectorStore, vectorStoreOptions, pendingMigrations, withOrg, ConfigError, installGuards, onListenError, } from '@nacre.work/core';
|
|
2
|
+
import { HttpEmbedder, NacreIngest, NacreSearchService, PostgresAudit, PostgresAuditReader, PostgresDocuments, PostgresGrants, PostgresJobs, PostgresLayers, PostgresReferenceQueries, PostgresReindex, PostgresEmbeddingProviders, PostgresWorkspaces, } from './adapters.js';
|
|
3
3
|
import { SignJWT } from 'jose';
|
|
4
4
|
import { Idempotency } from './idempotency.js';
|
|
5
5
|
import { Login } from './login.js';
|
|
@@ -31,9 +31,7 @@ async function main() {
|
|
|
31
31
|
await loadModules(config.modules);
|
|
32
32
|
const jwt = loadJwtKeys();
|
|
33
33
|
const pool = createPool({ connectionString: config.pgUrl, max: config.pgPoolMax });
|
|
34
|
-
const vectors = new VectorStore(config
|
|
35
|
-
? { url: config.qdrantUrl }
|
|
36
|
-
: { url: config.qdrantUrl, apiKey: config.qdrantApiKey });
|
|
34
|
+
const vectors = new VectorStore(vectorStoreOptions(config));
|
|
37
35
|
// Absent when a deployment has none, which is supported and is the default:
|
|
38
36
|
// document bytes then live in `documents.source_ref`. `loadConfig` refuses a
|
|
39
37
|
// half-configured block, so this is either fully usable or not there at all.
|
|
@@ -258,6 +256,7 @@ async function main() {
|
|
|
258
256
|
jobs: new PostgresJobs(pool, APP_ROLE, principalsCache),
|
|
259
257
|
layers: new PostgresLayers(pool, vectors, APP_ROLE, principalsCache),
|
|
260
258
|
workspaces: new PostgresWorkspaces(pool, APP_ROLE, principalsCache),
|
|
259
|
+
embeddingProviders: new PostgresEmbeddingProviders(pool, APP_ROLE),
|
|
261
260
|
grants: new PostgresGrants(pool, APP_ROLE, principalsCache),
|
|
262
261
|
serviceAccounts: new PostgresServiceAccounts(pool, APP_ROLE),
|
|
263
262
|
users: new PostgresUsers(pool, APP_ROLE),
|