@constructive-io/express-context 0.2.1 → 0.3.1
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/esm/index.js +1 -1
- package/esm/loaders/agent-chat.js +36 -0
- package/esm/loaders/billing.js +37 -0
- package/esm/loaders/index.js +9 -0
- package/esm/loaders/inference-log.js +33 -0
- package/index.d.ts +2 -2
- package/index.js +4 -1
- package/loaders/agent-chat.d.ts +9 -0
- package/loaders/agent-chat.js +39 -0
- package/loaders/billing.d.ts +9 -0
- package/loaders/billing.js +40 -0
- package/loaders/index.d.ts +3 -0
- package/loaders/index.js +13 -1
- package/loaders/inference-log.d.ts +9 -0
- package/loaders/inference-log.js +36 -0
- package/package.json +9 -9
- package/types.d.ts +19 -0
package/esm/index.js
CHANGED
|
@@ -40,6 +40,6 @@ export { withPgClient } from './pg-client';
|
|
|
40
40
|
// Request ID middleware
|
|
41
41
|
export { requestIdMiddleware } from './request-id';
|
|
42
42
|
export { buildContext, createContextMiddleware } from './context';
|
|
43
|
-
export { authSettingsLoader, corsLoader, createDefaultRegistry, createLoaderRegistry, createModuleLoader, databaseSettingsLoader, pubkeyLoader, rlsLoader, webauthnLoader, } from './loaders';
|
|
43
|
+
export { agentChatLoader, authSettingsLoader, billingLoader, corsLoader, createDefaultRegistry, createLoaderRegistry, createModuleLoader, databaseSettingsLoader, inferenceLogLoader, pubkeyLoader, rlsLoader, webauthnLoader, } from './loaders';
|
|
44
44
|
// Side-effect: Express type augmentation
|
|
45
45
|
import './types';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Chat Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Resolves per-database agent chat config from metaschema_modules_public.agent_chat_module.
|
|
5
|
+
* Returns the schema and table names for threads, messages, and tasks.
|
|
6
|
+
*/
|
|
7
|
+
import { createModuleLoader } from './create-loader';
|
|
8
|
+
// ─── SQL ────────────────────────────────────────────────────────────────────
|
|
9
|
+
const AGENT_CHAT_MODULE_SQL = `
|
|
10
|
+
SELECT
|
|
11
|
+
s.schema_name,
|
|
12
|
+
acm.thread_table_name,
|
|
13
|
+
acm.message_table_name,
|
|
14
|
+
acm.task_table_name
|
|
15
|
+
FROM metaschema_modules_public.agent_chat_module acm
|
|
16
|
+
JOIN metaschema_public.schema s ON s.id = acm.schema_id
|
|
17
|
+
LIMIT 1
|
|
18
|
+
`;
|
|
19
|
+
// ─── Loader ─────────────────────────────────────────────────────────────────
|
|
20
|
+
export const agentChatLoader = createModuleLoader({
|
|
21
|
+
name: 'agentChat',
|
|
22
|
+
ttlMs: 60_000,
|
|
23
|
+
async resolve(ctx) {
|
|
24
|
+
const { tenantPool } = ctx;
|
|
25
|
+
const result = await tenantPool.query(AGENT_CHAT_MODULE_SQL);
|
|
26
|
+
const row = result.rows[0];
|
|
27
|
+
if (!row)
|
|
28
|
+
return undefined;
|
|
29
|
+
return {
|
|
30
|
+
schemaName: row.schema_name,
|
|
31
|
+
threadTableName: row.thread_table_name,
|
|
32
|
+
messageTableName: row.message_table_name,
|
|
33
|
+
taskTableName: row.task_table_name,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Resolves per-database billing config from metaschema_modules_public.billing_module.
|
|
5
|
+
* Returns schema names and function names needed for quota checks and usage recording.
|
|
6
|
+
*/
|
|
7
|
+
import { createModuleLoader } from './create-loader';
|
|
8
|
+
// ─── SQL ────────────────────────────────────────────────────────────────────
|
|
9
|
+
const BILLING_MODULE_SQL = `
|
|
10
|
+
SELECT
|
|
11
|
+
s.schema_name AS public_schema,
|
|
12
|
+
ps.schema_name AS private_schema,
|
|
13
|
+
bm.record_usage_function
|
|
14
|
+
FROM metaschema_modules_public.billing_module bm
|
|
15
|
+
JOIN metaschema_public.schema s ON bm.schema_id = s.id
|
|
16
|
+
JOIN metaschema_public.schema ps ON bm.private_schema_id = ps.id
|
|
17
|
+
WHERE bm.database_id = $1
|
|
18
|
+
LIMIT 1
|
|
19
|
+
`;
|
|
20
|
+
// ─── Loader ─────────────────────────────────────────────────────────────────
|
|
21
|
+
export const billingLoader = createModuleLoader({
|
|
22
|
+
name: 'billing',
|
|
23
|
+
ttlMs: 5 * 60_000,
|
|
24
|
+
async resolve(ctx) {
|
|
25
|
+
const { tenantPool, databaseId } = ctx;
|
|
26
|
+
const result = await tenantPool.query(BILLING_MODULE_SQL, [databaseId]);
|
|
27
|
+
const row = result.rows[0];
|
|
28
|
+
if (!row?.record_usage_function)
|
|
29
|
+
return undefined;
|
|
30
|
+
return {
|
|
31
|
+
publicSchema: row.public_schema,
|
|
32
|
+
privateSchema: row.private_schema,
|
|
33
|
+
recordUsageFunction: row.record_usage_function,
|
|
34
|
+
checkBillingQuotaFunction: 'check_billing_quota',
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
});
|
package/esm/loaders/index.js
CHANGED
|
@@ -34,6 +34,9 @@ export { databaseSettingsLoader } from './database-settings';
|
|
|
34
34
|
export { pubkeyLoader } from './pubkey';
|
|
35
35
|
export { webauthnLoader } from './webauthn';
|
|
36
36
|
export { authSettingsLoader } from './auth-settings';
|
|
37
|
+
export { billingLoader } from './billing';
|
|
38
|
+
export { inferenceLogLoader } from './inference-log';
|
|
39
|
+
export { agentChatLoader } from './agent-chat';
|
|
37
40
|
/**
|
|
38
41
|
* Convenience: create a registry pre-loaded with all built-in loaders.
|
|
39
42
|
*/
|
|
@@ -44,6 +47,9 @@ import { databaseSettingsLoader } from './database-settings';
|
|
|
44
47
|
import { pubkeyLoader } from './pubkey';
|
|
45
48
|
import { webauthnLoader } from './webauthn';
|
|
46
49
|
import { authSettingsLoader } from './auth-settings';
|
|
50
|
+
import { billingLoader } from './billing';
|
|
51
|
+
import { inferenceLogLoader } from './inference-log';
|
|
52
|
+
import { agentChatLoader } from './agent-chat';
|
|
47
53
|
export function createDefaultRegistry() {
|
|
48
54
|
const registry = createLoaderRegistry();
|
|
49
55
|
registry.register(rlsLoader);
|
|
@@ -52,5 +58,8 @@ export function createDefaultRegistry() {
|
|
|
52
58
|
registry.register(pubkeyLoader);
|
|
53
59
|
registry.register(webauthnLoader);
|
|
54
60
|
registry.register(authSettingsLoader);
|
|
61
|
+
registry.register(billingLoader);
|
|
62
|
+
registry.register(inferenceLogLoader);
|
|
63
|
+
registry.register(agentChatLoader);
|
|
55
64
|
return registry;
|
|
56
65
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inference Log Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Resolves per-database inference log config from metaschema_modules_public.inference_log_module.
|
|
5
|
+
* Returns the schema and table name for logging LLM inference usage.
|
|
6
|
+
*/
|
|
7
|
+
import { createModuleLoader } from './create-loader';
|
|
8
|
+
// ─── SQL ────────────────────────────────────────────────────────────────────
|
|
9
|
+
const INFERENCE_LOG_MODULE_SQL = `
|
|
10
|
+
SELECT
|
|
11
|
+
s.schema_name AS schema,
|
|
12
|
+
ilm.inference_log_table_name AS table_name
|
|
13
|
+
FROM metaschema_modules_public.inference_log_module ilm
|
|
14
|
+
JOIN metaschema_public.schema s ON ilm.schema_id = s.id
|
|
15
|
+
WHERE ilm.database_id = $1
|
|
16
|
+
LIMIT 1
|
|
17
|
+
`;
|
|
18
|
+
// ─── Loader ─────────────────────────────────────────────────────────────────
|
|
19
|
+
export const inferenceLogLoader = createModuleLoader({
|
|
20
|
+
name: 'inferenceLog',
|
|
21
|
+
ttlMs: 5 * 60_000,
|
|
22
|
+
async resolve(ctx) {
|
|
23
|
+
const { tenantPool, databaseId } = ctx;
|
|
24
|
+
const result = await tenantPool.query(INFERENCE_LOG_MODULE_SQL, [databaseId]);
|
|
25
|
+
const row = result.rows[0];
|
|
26
|
+
if (!row?.schema || !row?.table_name)
|
|
27
|
+
return undefined;
|
|
28
|
+
return {
|
|
29
|
+
schema: row.schema,
|
|
30
|
+
tableName: row.table_name,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
});
|
package/index.d.ts
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* });
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
export type { ApiConfigResult, ApiError, ApiModule, ApiStructure, AuthSettings, ConstructiveAPIToken, ConstructiveContext, CorsModuleData, DatabaseSettings, GenericModuleData, PublicKeyChallengeData, PubkeyChallengeSettings,
|
|
37
|
+
export type { AgentChatConfig, ApiConfigResult, ApiError, ApiModule, ApiStructure, AuthSettings, BillingConfig, BuiltinModuleMap, ConstructiveAPIToken, ConstructiveContext, CorsModuleData, DatabaseSettings, GenericModuleData, InferenceLogConfig, PublicKeyChallengeData, PubkeyChallengeSettings, RlsModule, WebauthnSettings, WithPgClient, } from './types';
|
|
38
38
|
export type { PgSettingsInput } from './pg-settings';
|
|
39
39
|
export { buildPgSettings } from './pg-settings';
|
|
40
40
|
export { withPgClient } from './pg-client';
|
|
@@ -42,5 +42,5 @@ export { requestIdMiddleware } from './request-id';
|
|
|
42
42
|
export type { ContextMiddlewareOptions } from './context';
|
|
43
43
|
export { buildContext, createContextMiddleware } from './context';
|
|
44
44
|
export type { CreateLoaderOptions, LoaderContext, LoaderRegistry, ModuleLoader, } from './loaders';
|
|
45
|
-
export { authSettingsLoader, corsLoader, createDefaultRegistry, createLoaderRegistry, createModuleLoader, databaseSettingsLoader, pubkeyLoader, rlsLoader, webauthnLoader, } from './loaders';
|
|
45
|
+
export { agentChatLoader, authSettingsLoader, billingLoader, corsLoader, createDefaultRegistry, createLoaderRegistry, createModuleLoader, databaseSettingsLoader, inferenceLogLoader, pubkeyLoader, rlsLoader, webauthnLoader, } from './loaders';
|
|
46
46
|
import './types';
|
package/index.js
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.webauthnLoader = exports.rlsLoader = exports.pubkeyLoader = exports.databaseSettingsLoader = exports.createModuleLoader = exports.createLoaderRegistry = exports.createDefaultRegistry = exports.corsLoader = exports.authSettingsLoader = exports.createContextMiddleware = exports.buildContext = exports.requestIdMiddleware = exports.withPgClient = exports.buildPgSettings = void 0;
|
|
39
|
+
exports.webauthnLoader = exports.rlsLoader = exports.pubkeyLoader = exports.inferenceLogLoader = exports.databaseSettingsLoader = exports.createModuleLoader = exports.createLoaderRegistry = exports.createDefaultRegistry = exports.corsLoader = exports.billingLoader = exports.authSettingsLoader = exports.agentChatLoader = exports.createContextMiddleware = exports.buildContext = exports.requestIdMiddleware = exports.withPgClient = exports.buildPgSettings = void 0;
|
|
40
40
|
var pg_settings_1 = require("./pg-settings");
|
|
41
41
|
Object.defineProperty(exports, "buildPgSettings", { enumerable: true, get: function () { return pg_settings_1.buildPgSettings; } });
|
|
42
42
|
// withPgClient helper
|
|
@@ -49,12 +49,15 @@ var context_1 = require("./context");
|
|
|
49
49
|
Object.defineProperty(exports, "buildContext", { enumerable: true, get: function () { return context_1.buildContext; } });
|
|
50
50
|
Object.defineProperty(exports, "createContextMiddleware", { enumerable: true, get: function () { return context_1.createContextMiddleware; } });
|
|
51
51
|
var loaders_1 = require("./loaders");
|
|
52
|
+
Object.defineProperty(exports, "agentChatLoader", { enumerable: true, get: function () { return loaders_1.agentChatLoader; } });
|
|
52
53
|
Object.defineProperty(exports, "authSettingsLoader", { enumerable: true, get: function () { return loaders_1.authSettingsLoader; } });
|
|
54
|
+
Object.defineProperty(exports, "billingLoader", { enumerable: true, get: function () { return loaders_1.billingLoader; } });
|
|
53
55
|
Object.defineProperty(exports, "corsLoader", { enumerable: true, get: function () { return loaders_1.corsLoader; } });
|
|
54
56
|
Object.defineProperty(exports, "createDefaultRegistry", { enumerable: true, get: function () { return loaders_1.createDefaultRegistry; } });
|
|
55
57
|
Object.defineProperty(exports, "createLoaderRegistry", { enumerable: true, get: function () { return loaders_1.createLoaderRegistry; } });
|
|
56
58
|
Object.defineProperty(exports, "createModuleLoader", { enumerable: true, get: function () { return loaders_1.createModuleLoader; } });
|
|
57
59
|
Object.defineProperty(exports, "databaseSettingsLoader", { enumerable: true, get: function () { return loaders_1.databaseSettingsLoader; } });
|
|
60
|
+
Object.defineProperty(exports, "inferenceLogLoader", { enumerable: true, get: function () { return loaders_1.inferenceLogLoader; } });
|
|
58
61
|
Object.defineProperty(exports, "pubkeyLoader", { enumerable: true, get: function () { return loaders_1.pubkeyLoader; } });
|
|
59
62
|
Object.defineProperty(exports, "rlsLoader", { enumerable: true, get: function () { return loaders_1.rlsLoader; } });
|
|
60
63
|
Object.defineProperty(exports, "webauthnLoader", { enumerable: true, get: function () { return loaders_1.webauthnLoader; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Chat Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Resolves per-database agent chat config from metaschema_modules_public.agent_chat_module.
|
|
5
|
+
* Returns the schema and table names for threads, messages, and tasks.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentChatConfig } from '../types';
|
|
8
|
+
import type { ModuleLoader } from './types';
|
|
9
|
+
export declare const agentChatLoader: ModuleLoader<AgentChatConfig>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent Chat Module Loader
|
|
4
|
+
*
|
|
5
|
+
* Resolves per-database agent chat config from metaschema_modules_public.agent_chat_module.
|
|
6
|
+
* Returns the schema and table names for threads, messages, and tasks.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.agentChatLoader = void 0;
|
|
10
|
+
const create_loader_1 = require("./create-loader");
|
|
11
|
+
// ─── SQL ────────────────────────────────────────────────────────────────────
|
|
12
|
+
const AGENT_CHAT_MODULE_SQL = `
|
|
13
|
+
SELECT
|
|
14
|
+
s.schema_name,
|
|
15
|
+
acm.thread_table_name,
|
|
16
|
+
acm.message_table_name,
|
|
17
|
+
acm.task_table_name
|
|
18
|
+
FROM metaschema_modules_public.agent_chat_module acm
|
|
19
|
+
JOIN metaschema_public.schema s ON s.id = acm.schema_id
|
|
20
|
+
LIMIT 1
|
|
21
|
+
`;
|
|
22
|
+
// ─── Loader ─────────────────────────────────────────────────────────────────
|
|
23
|
+
exports.agentChatLoader = (0, create_loader_1.createModuleLoader)({
|
|
24
|
+
name: 'agentChat',
|
|
25
|
+
ttlMs: 60_000,
|
|
26
|
+
async resolve(ctx) {
|
|
27
|
+
const { tenantPool } = ctx;
|
|
28
|
+
const result = await tenantPool.query(AGENT_CHAT_MODULE_SQL);
|
|
29
|
+
const row = result.rows[0];
|
|
30
|
+
if (!row)
|
|
31
|
+
return undefined;
|
|
32
|
+
return {
|
|
33
|
+
schemaName: row.schema_name,
|
|
34
|
+
threadTableName: row.thread_table_name,
|
|
35
|
+
messageTableName: row.message_table_name,
|
|
36
|
+
taskTableName: row.task_table_name,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Resolves per-database billing config from metaschema_modules_public.billing_module.
|
|
5
|
+
* Returns schema names and function names needed for quota checks and usage recording.
|
|
6
|
+
*/
|
|
7
|
+
import type { BillingConfig } from '../types';
|
|
8
|
+
import type { ModuleLoader } from './types';
|
|
9
|
+
export declare const billingLoader: ModuleLoader<BillingConfig>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Billing Module Loader
|
|
4
|
+
*
|
|
5
|
+
* Resolves per-database billing config from metaschema_modules_public.billing_module.
|
|
6
|
+
* Returns schema names and function names needed for quota checks and usage recording.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.billingLoader = void 0;
|
|
10
|
+
const create_loader_1 = require("./create-loader");
|
|
11
|
+
// ─── SQL ────────────────────────────────────────────────────────────────────
|
|
12
|
+
const BILLING_MODULE_SQL = `
|
|
13
|
+
SELECT
|
|
14
|
+
s.schema_name AS public_schema,
|
|
15
|
+
ps.schema_name AS private_schema,
|
|
16
|
+
bm.record_usage_function
|
|
17
|
+
FROM metaschema_modules_public.billing_module bm
|
|
18
|
+
JOIN metaschema_public.schema s ON bm.schema_id = s.id
|
|
19
|
+
JOIN metaschema_public.schema ps ON bm.private_schema_id = ps.id
|
|
20
|
+
WHERE bm.database_id = $1
|
|
21
|
+
LIMIT 1
|
|
22
|
+
`;
|
|
23
|
+
// ─── Loader ─────────────────────────────────────────────────────────────────
|
|
24
|
+
exports.billingLoader = (0, create_loader_1.createModuleLoader)({
|
|
25
|
+
name: 'billing',
|
|
26
|
+
ttlMs: 5 * 60_000,
|
|
27
|
+
async resolve(ctx) {
|
|
28
|
+
const { tenantPool, databaseId } = ctx;
|
|
29
|
+
const result = await tenantPool.query(BILLING_MODULE_SQL, [databaseId]);
|
|
30
|
+
const row = result.rows[0];
|
|
31
|
+
if (!row?.record_usage_function)
|
|
32
|
+
return undefined;
|
|
33
|
+
return {
|
|
34
|
+
publicSchema: row.public_schema,
|
|
35
|
+
privateSchema: row.private_schema,
|
|
36
|
+
recordUsageFunction: row.record_usage_function,
|
|
37
|
+
checkBillingQuotaFunction: 'check_billing_quota',
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
});
|
package/loaders/index.d.ts
CHANGED
|
@@ -36,4 +36,7 @@ export { databaseSettingsLoader } from './database-settings';
|
|
|
36
36
|
export { pubkeyLoader } from './pubkey';
|
|
37
37
|
export { webauthnLoader } from './webauthn';
|
|
38
38
|
export { authSettingsLoader } from './auth-settings';
|
|
39
|
+
export { billingLoader } from './billing';
|
|
40
|
+
export { inferenceLogLoader } from './inference-log';
|
|
41
|
+
export { agentChatLoader } from './agent-chat';
|
|
39
42
|
export declare function createDefaultRegistry(): import("./registry").LoaderRegistry;
|
package/loaders/index.js
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* registry.register(myLoader);
|
|
28
28
|
*/
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.authSettingsLoader = exports.webauthnLoader = exports.pubkeyLoader = exports.databaseSettingsLoader = exports.corsLoader = exports.rlsLoader = exports.createLoaderRegistry = exports.createModuleLoader = void 0;
|
|
30
|
+
exports.agentChatLoader = exports.inferenceLogLoader = exports.billingLoader = exports.authSettingsLoader = exports.webauthnLoader = exports.pubkeyLoader = exports.databaseSettingsLoader = exports.corsLoader = exports.rlsLoader = exports.createLoaderRegistry = exports.createModuleLoader = void 0;
|
|
31
31
|
exports.createDefaultRegistry = createDefaultRegistry;
|
|
32
32
|
var create_loader_1 = require("./create-loader");
|
|
33
33
|
Object.defineProperty(exports, "createModuleLoader", { enumerable: true, get: function () { return create_loader_1.createModuleLoader; } });
|
|
@@ -46,6 +46,12 @@ var webauthn_1 = require("./webauthn");
|
|
|
46
46
|
Object.defineProperty(exports, "webauthnLoader", { enumerable: true, get: function () { return webauthn_1.webauthnLoader; } });
|
|
47
47
|
var auth_settings_1 = require("./auth-settings");
|
|
48
48
|
Object.defineProperty(exports, "authSettingsLoader", { enumerable: true, get: function () { return auth_settings_1.authSettingsLoader; } });
|
|
49
|
+
var billing_1 = require("./billing");
|
|
50
|
+
Object.defineProperty(exports, "billingLoader", { enumerable: true, get: function () { return billing_1.billingLoader; } });
|
|
51
|
+
var inference_log_1 = require("./inference-log");
|
|
52
|
+
Object.defineProperty(exports, "inferenceLogLoader", { enumerable: true, get: function () { return inference_log_1.inferenceLogLoader; } });
|
|
53
|
+
var agent_chat_1 = require("./agent-chat");
|
|
54
|
+
Object.defineProperty(exports, "agentChatLoader", { enumerable: true, get: function () { return agent_chat_1.agentChatLoader; } });
|
|
49
55
|
/**
|
|
50
56
|
* Convenience: create a registry pre-loaded with all built-in loaders.
|
|
51
57
|
*/
|
|
@@ -56,6 +62,9 @@ const database_settings_2 = require("./database-settings");
|
|
|
56
62
|
const pubkey_2 = require("./pubkey");
|
|
57
63
|
const webauthn_2 = require("./webauthn");
|
|
58
64
|
const auth_settings_2 = require("./auth-settings");
|
|
65
|
+
const billing_2 = require("./billing");
|
|
66
|
+
const inference_log_2 = require("./inference-log");
|
|
67
|
+
const agent_chat_2 = require("./agent-chat");
|
|
59
68
|
function createDefaultRegistry() {
|
|
60
69
|
const registry = (0, registry_2.createLoaderRegistry)();
|
|
61
70
|
registry.register(rls_2.rlsLoader);
|
|
@@ -64,5 +73,8 @@ function createDefaultRegistry() {
|
|
|
64
73
|
registry.register(pubkey_2.pubkeyLoader);
|
|
65
74
|
registry.register(webauthn_2.webauthnLoader);
|
|
66
75
|
registry.register(auth_settings_2.authSettingsLoader);
|
|
76
|
+
registry.register(billing_2.billingLoader);
|
|
77
|
+
registry.register(inference_log_2.inferenceLogLoader);
|
|
78
|
+
registry.register(agent_chat_2.agentChatLoader);
|
|
67
79
|
return registry;
|
|
68
80
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inference Log Module Loader
|
|
3
|
+
*
|
|
4
|
+
* Resolves per-database inference log config from metaschema_modules_public.inference_log_module.
|
|
5
|
+
* Returns the schema and table name for logging LLM inference usage.
|
|
6
|
+
*/
|
|
7
|
+
import type { InferenceLogConfig } from '../types';
|
|
8
|
+
import type { ModuleLoader } from './types';
|
|
9
|
+
export declare const inferenceLogLoader: ModuleLoader<InferenceLogConfig>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Inference Log Module Loader
|
|
4
|
+
*
|
|
5
|
+
* Resolves per-database inference log config from metaschema_modules_public.inference_log_module.
|
|
6
|
+
* Returns the schema and table name for logging LLM inference usage.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.inferenceLogLoader = void 0;
|
|
10
|
+
const create_loader_1 = require("./create-loader");
|
|
11
|
+
// ─── SQL ────────────────────────────────────────────────────────────────────
|
|
12
|
+
const INFERENCE_LOG_MODULE_SQL = `
|
|
13
|
+
SELECT
|
|
14
|
+
s.schema_name AS schema,
|
|
15
|
+
ilm.inference_log_table_name AS table_name
|
|
16
|
+
FROM metaschema_modules_public.inference_log_module ilm
|
|
17
|
+
JOIN metaschema_public.schema s ON ilm.schema_id = s.id
|
|
18
|
+
WHERE ilm.database_id = $1
|
|
19
|
+
LIMIT 1
|
|
20
|
+
`;
|
|
21
|
+
// ─── Loader ─────────────────────────────────────────────────────────────────
|
|
22
|
+
exports.inferenceLogLoader = (0, create_loader_1.createModuleLoader)({
|
|
23
|
+
name: 'inferenceLog',
|
|
24
|
+
ttlMs: 5 * 60_000,
|
|
25
|
+
async resolve(ctx) {
|
|
26
|
+
const { tenantPool, databaseId } = ctx;
|
|
27
|
+
const result = await tenantPool.query(INFERENCE_LOG_MODULE_SQL, [databaseId]);
|
|
28
|
+
const row = result.rows[0];
|
|
29
|
+
if (!row?.schema || !row?.table_name)
|
|
30
|
+
return undefined;
|
|
31
|
+
return {
|
|
32
|
+
schema: row.schema,
|
|
33
|
+
tableName: row.table_name,
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/express-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Extractable Express middleware for Constructive tenant context — domain resolution, JWT auth, pgSettings, and withPgClient",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"homepage": "https://github.com/constructive-io/constructive",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"test:watch": "jest --watch"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@constructive-io/url-domains": "^2.16.
|
|
33
|
-
"@pgpmjs/env": "^2.24.
|
|
34
|
-
"@pgpmjs/logger": "^2.11.
|
|
35
|
-
"@pgpmjs/server-utils": "^3.12.
|
|
36
|
-
"@pgpmjs/types": "^2.28.
|
|
32
|
+
"@constructive-io/url-domains": "^2.16.1",
|
|
33
|
+
"@pgpmjs/env": "^2.24.1",
|
|
34
|
+
"@pgpmjs/logger": "^2.11.1",
|
|
35
|
+
"@pgpmjs/server-utils": "^3.12.1",
|
|
36
|
+
"@pgpmjs/types": "^2.28.1",
|
|
37
37
|
"lru-cache": "^11.2.7",
|
|
38
38
|
"pg": "^8.21.0",
|
|
39
|
-
"pg-cache": "^3.11.
|
|
40
|
-
"pg-query-context": "^2.16.
|
|
39
|
+
"pg-cache": "^3.11.1",
|
|
40
|
+
"pg-query-context": "^2.16.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/express": "^5.0.6",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"jwt",
|
|
60
60
|
"pgSettings"
|
|
61
61
|
],
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "423992019655cc1e780149ce3f7e6e8c9b1c6e80"
|
|
63
63
|
}
|
package/types.d.ts
CHANGED
|
@@ -119,6 +119,22 @@ export type ConstructiveAPIToken = {
|
|
|
119
119
|
kind?: string;
|
|
120
120
|
[key: string]: unknown;
|
|
121
121
|
};
|
|
122
|
+
export interface BillingConfig {
|
|
123
|
+
publicSchema: string;
|
|
124
|
+
privateSchema: string;
|
|
125
|
+
recordUsageFunction: string;
|
|
126
|
+
checkBillingQuotaFunction: string;
|
|
127
|
+
}
|
|
128
|
+
export interface InferenceLogConfig {
|
|
129
|
+
schema: string;
|
|
130
|
+
tableName: string;
|
|
131
|
+
}
|
|
132
|
+
export interface AgentChatConfig {
|
|
133
|
+
schemaName: string;
|
|
134
|
+
threadTableName: string | null;
|
|
135
|
+
messageTableName: string | null;
|
|
136
|
+
taskTableName: string | null;
|
|
137
|
+
}
|
|
122
138
|
/**
|
|
123
139
|
* Maps built-in loader names to their resolved types.
|
|
124
140
|
*
|
|
@@ -134,6 +150,9 @@ export interface BuiltinModuleMap {
|
|
|
134
150
|
authSettings: AuthSettings;
|
|
135
151
|
pubkeyChallengeSettings: PubkeyChallengeSettings;
|
|
136
152
|
webauthnSettings: WebauthnSettings;
|
|
153
|
+
billing: BillingConfig;
|
|
154
|
+
inferenceLog: InferenceLogConfig;
|
|
155
|
+
agentChat: AgentChatConfig;
|
|
137
156
|
}
|
|
138
157
|
/**
|
|
139
158
|
* Callback for executing queries within a tenant-scoped transaction
|