@naisys/hub-database 3.0.0-beta.5 → 3.0.0-beta.7
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/dbConfig.js +1 -1
- package/dist/generated/prisma/browser.js +4 -4
- package/dist/generated/prisma/client.js +5 -5
- package/dist/generated/prisma/commonInputTypes.js +1 -1
- package/dist/generated/prisma/enums.js +34 -34
- package/dist/generated/prisma/internal/class.js +28 -36
- package/dist/generated/prisma/internal/prismaNamespace.js +147 -150
- package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +142 -142
- package/dist/hubDatabaseService.js +30 -30
- package/dist/hubSessionService.js +71 -59
- package/dist/index.js +2 -10
- package/dist/prismaClient.js +12 -12
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* !!! This is code generated by Prisma. Do not edit directly. !!! */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
// biome-ignore-all lint: generated file
|
|
4
|
-
// @ts-nocheck
|
|
4
|
+
// @ts-nocheck
|
|
5
5
|
/*
|
|
6
6
|
* WARNING: This is an internal file that is subject to change!
|
|
7
7
|
*
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
import * as runtime from "@prisma/client/runtime/index-browser";
|
|
17
17
|
export const Decimal = runtime.Decimal;
|
|
18
18
|
export const NullTypes = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
DbNull: runtime.NullTypes.DbNull,
|
|
20
|
+
JsonNull: runtime.NullTypes.JsonNull,
|
|
21
|
+
AnyNull: runtime.NullTypes.AnyNull,
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
24
|
* Helper for filtering JSON entries that have `null` on the database (empty on the db)
|
|
@@ -39,181 +39,181 @@ export const JsonNull = runtime.JsonNull;
|
|
|
39
39
|
*/
|
|
40
40
|
export const AnyNull = runtime.AnyNull;
|
|
41
41
|
export const ModelName = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
42
|
+
context_log: 'context_log',
|
|
43
|
+
costs: 'costs',
|
|
44
|
+
mail_messages: 'mail_messages',
|
|
45
|
+
attachments: 'attachments',
|
|
46
|
+
mail_attachments: 'mail_attachments',
|
|
47
|
+
mail_recipients: 'mail_recipients',
|
|
48
|
+
users: 'users',
|
|
49
|
+
user_notifications: 'user_notifications',
|
|
50
|
+
user_hosts: 'user_hosts',
|
|
51
|
+
run_session: 'run_session',
|
|
52
|
+
schema_version: 'schema_version',
|
|
53
|
+
hosts: 'hosts',
|
|
54
|
+
config_revisions: 'config_revisions',
|
|
55
|
+
variables: 'variables',
|
|
56
|
+
models: 'models'
|
|
57
57
|
};
|
|
58
58
|
/*
|
|
59
59
|
* Enums
|
|
60
60
|
*/
|
|
61
61
|
export const TransactionIsolationLevel = runtime.makeStrictEnum({
|
|
62
|
-
|
|
62
|
+
Serializable: 'Serializable'
|
|
63
63
|
});
|
|
64
64
|
export const Context_logScalarFieldEnum = {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
65
|
+
id: 'id',
|
|
66
|
+
user_id: 'user_id',
|
|
67
|
+
run_id: 'run_id',
|
|
68
|
+
session_id: 'session_id',
|
|
69
|
+
host_id: 'host_id',
|
|
70
|
+
role: 'role',
|
|
71
|
+
source: 'source',
|
|
72
|
+
type: 'type',
|
|
73
|
+
message: 'message',
|
|
74
|
+
attachment_id: 'attachment_id',
|
|
75
|
+
created_at: 'created_at'
|
|
76
76
|
};
|
|
77
77
|
export const CostsScalarFieldEnum = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
id: 'id',
|
|
79
|
+
user_id: 'user_id',
|
|
80
|
+
run_id: 'run_id',
|
|
81
|
+
session_id: 'session_id',
|
|
82
|
+
host_id: 'host_id',
|
|
83
|
+
source: 'source',
|
|
84
|
+
model: 'model',
|
|
85
|
+
cost: 'cost',
|
|
86
|
+
input_tokens: 'input_tokens',
|
|
87
|
+
output_tokens: 'output_tokens',
|
|
88
|
+
cache_write_tokens: 'cache_write_tokens',
|
|
89
|
+
cache_read_tokens: 'cache_read_tokens',
|
|
90
|
+
created_at: 'created_at'
|
|
91
91
|
};
|
|
92
92
|
export const Mail_messagesScalarFieldEnum = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
id: 'id',
|
|
94
|
+
from_user_id: 'from_user_id',
|
|
95
|
+
host_id: 'host_id',
|
|
96
|
+
kind: 'kind',
|
|
97
|
+
participants: 'participants',
|
|
98
|
+
subject: 'subject',
|
|
99
|
+
body: 'body',
|
|
100
|
+
created_at: 'created_at'
|
|
101
101
|
};
|
|
102
102
|
export const AttachmentsScalarFieldEnum = {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
id: 'id',
|
|
104
|
+
public_id: 'public_id',
|
|
105
|
+
filepath: 'filepath',
|
|
106
|
+
filename: 'filename',
|
|
107
|
+
file_size: 'file_size',
|
|
108
|
+
file_hash: 'file_hash',
|
|
109
|
+
purpose: 'purpose',
|
|
110
|
+
uploaded_by: 'uploaded_by',
|
|
111
|
+
created_at: 'created_at'
|
|
112
112
|
};
|
|
113
113
|
export const Mail_attachmentsScalarFieldEnum = {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
message_id: 'message_id',
|
|
115
|
+
attachment_id: 'attachment_id',
|
|
116
|
+
created_at: 'created_at'
|
|
117
117
|
};
|
|
118
118
|
export const Mail_recipientsScalarFieldEnum = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
id: 'id',
|
|
120
|
+
message_id: 'message_id',
|
|
121
|
+
user_id: 'user_id',
|
|
122
|
+
type: 'type',
|
|
123
|
+
read_at: 'read_at',
|
|
124
|
+
archived_at: 'archived_at',
|
|
125
|
+
created_at: 'created_at'
|
|
126
126
|
};
|
|
127
127
|
export const UsersScalarFieldEnum = {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
id: 'id',
|
|
129
|
+
uuid: 'uuid',
|
|
130
|
+
username: 'username',
|
|
131
|
+
title: 'title',
|
|
132
|
+
api_key: 'api_key',
|
|
133
|
+
lead_user_id: 'lead_user_id',
|
|
134
|
+
config: 'config',
|
|
135
|
+
created_at: 'created_at',
|
|
136
|
+
updated_at: 'updated_at',
|
|
137
|
+
enabled: 'enabled',
|
|
138
|
+
archived: 'archived'
|
|
139
139
|
};
|
|
140
140
|
export const User_notificationsScalarFieldEnum = {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
user_id: 'user_id',
|
|
142
|
+
latest_host_id: 'latest_host_id',
|
|
143
|
+
latest_log_id: 'latest_log_id',
|
|
144
|
+
latest_mail_id: 'latest_mail_id',
|
|
145
|
+
latest_chat_id: 'latest_chat_id',
|
|
146
|
+
last_active: 'last_active',
|
|
147
|
+
cost_suspended_reason: 'cost_suspended_reason',
|
|
148
|
+
spend_limit_reset_at: 'spend_limit_reset_at',
|
|
149
|
+
budget_left: 'budget_left',
|
|
150
|
+
updated_at: 'updated_at'
|
|
151
151
|
};
|
|
152
152
|
export const User_hostsScalarFieldEnum = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
user_id: 'user_id',
|
|
154
|
+
host_id: 'host_id',
|
|
155
|
+
created_at: 'created_at'
|
|
156
156
|
};
|
|
157
157
|
export const Run_sessionScalarFieldEnum = {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
158
|
+
user_id: 'user_id',
|
|
159
|
+
run_id: 'run_id',
|
|
160
|
+
session_id: 'session_id',
|
|
161
|
+
host_id: 'host_id',
|
|
162
|
+
last_active: 'last_active',
|
|
163
|
+
model_name: 'model_name',
|
|
164
|
+
latest_log_id: 'latest_log_id',
|
|
165
|
+
total_lines: 'total_lines',
|
|
166
|
+
total_cost: 'total_cost',
|
|
167
|
+
created_at: 'created_at',
|
|
168
|
+
updated_at: 'updated_at'
|
|
169
169
|
};
|
|
170
170
|
export const Schema_versionScalarFieldEnum = {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
id: 'id',
|
|
172
|
+
version: 'version',
|
|
173
|
+
updated: 'updated'
|
|
174
174
|
};
|
|
175
175
|
export const HostsScalarFieldEnum = {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
176
|
+
id: 'id',
|
|
177
|
+
name: 'name',
|
|
178
|
+
restricted: 'restricted',
|
|
179
|
+
host_type: 'host_type',
|
|
180
|
+
last_ip: 'last_ip',
|
|
181
|
+
last_active: 'last_active',
|
|
182
|
+
created_at: 'created_at'
|
|
183
183
|
};
|
|
184
184
|
export const Config_revisionsScalarFieldEnum = {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
id: 'id',
|
|
186
|
+
user_id: 'user_id',
|
|
187
|
+
config: 'config',
|
|
188
|
+
changed_by_id: 'changed_by_id',
|
|
189
|
+
created_at: 'created_at'
|
|
190
190
|
};
|
|
191
191
|
export const VariablesScalarFieldEnum = {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
192
|
+
key: 'key',
|
|
193
|
+
value: 'value',
|
|
194
|
+
export_to_shell: 'export_to_shell',
|
|
195
|
+
created_by: 'created_by',
|
|
196
|
+
updated_by: 'updated_by',
|
|
197
|
+
created_at: 'created_at',
|
|
198
|
+
updated_at: 'updated_at'
|
|
199
199
|
};
|
|
200
200
|
export const ModelsScalarFieldEnum = {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
201
|
+
id: 'id',
|
|
202
|
+
key: 'key',
|
|
203
|
+
type: 'type',
|
|
204
|
+
label: 'label',
|
|
205
|
+
version_name: 'version_name',
|
|
206
|
+
is_builtin: 'is_builtin',
|
|
207
|
+
is_custom: 'is_custom',
|
|
208
|
+
meta: 'meta',
|
|
209
|
+
created_at: 'created_at',
|
|
210
|
+
updated_at: 'updated_at'
|
|
211
211
|
};
|
|
212
212
|
export const SortOrder = {
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
asc: 'asc',
|
|
214
|
+
desc: 'desc'
|
|
215
215
|
};
|
|
216
216
|
export const NullsOrder = {
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
first: 'first',
|
|
218
|
+
last: 'last'
|
|
219
219
|
};
|
|
@@ -5,34 +5,34 @@ import { fileURLToPath } from "url";
|
|
|
5
5
|
import { hubDbPath } from "./dbConfig.js";
|
|
6
6
|
import { createPrismaClient } from "./prismaClient.js";
|
|
7
7
|
export async function createHubDatabaseService() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
8
|
+
/** We run migration scripts if this is greater than what's in the schema_version table */
|
|
9
|
+
const HUB_DB_VERSION = 34;
|
|
10
|
+
const dbPath = hubDbPath();
|
|
11
|
+
// Ensure database directory exists
|
|
12
|
+
const databaseDir = dirname(dbPath);
|
|
13
|
+
if (!existsSync(databaseDir)) {
|
|
14
|
+
mkdirSync(databaseDir, { recursive: true });
|
|
15
|
+
}
|
|
16
|
+
await runMigrations();
|
|
17
|
+
const prisma = await createPrismaClient(dbPath);
|
|
18
|
+
async function runMigrations() {
|
|
19
|
+
const currentFilePath = fileURLToPath(import.meta.url);
|
|
20
|
+
const databasePackageDir = dirname(dirname(currentFilePath));
|
|
21
|
+
await deployPrismaMigrations({
|
|
22
|
+
packageDir: databasePackageDir,
|
|
23
|
+
databasePath: dbPath,
|
|
24
|
+
expectedVersion: HUB_DB_VERSION,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function getSchemaVersion() {
|
|
28
|
+
return HUB_DB_VERSION;
|
|
29
|
+
}
|
|
30
|
+
async function disconnect() {
|
|
31
|
+
await prisma.$disconnect();
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
hubDb: prisma,
|
|
35
|
+
getSchemaVersion,
|
|
36
|
+
disconnect,
|
|
37
|
+
};
|
|
38
38
|
}
|
|
@@ -8,93 +8,105 @@ let prisma = null;
|
|
|
8
8
|
* No-ops gracefully if NAISYS_FOLDER is unset or the database doesn't exist.
|
|
9
9
|
*/
|
|
10
10
|
export async function createHubDatabaseClient() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
if (prisma)
|
|
12
|
+
return true;
|
|
13
|
+
const dbPath = hubDbPath();
|
|
14
|
+
if (!existsSync(dbPath))
|
|
15
|
+
return false;
|
|
16
|
+
prisma = await createPrismaClient(dbPath);
|
|
17
|
+
return true;
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* Find an agent (from the hub `users` table) by API key.
|
|
19
21
|
*/
|
|
20
22
|
export async function findAgentByApiKey(apiKey) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
if (!prisma)
|
|
24
|
+
return null;
|
|
25
|
+
const user = await prisma.users.findUnique({
|
|
26
|
+
where: { api_key: apiKey },
|
|
27
|
+
select: { uuid: true, username: true },
|
|
28
|
+
});
|
|
29
|
+
return user;
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* Find a hub agent by its numeric ID.
|
|
30
33
|
*/
|
|
31
34
|
export async function getHubAgentById(id) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
if (!prisma)
|
|
36
|
+
return null;
|
|
37
|
+
return prisma.users.findUnique({
|
|
38
|
+
where: { id },
|
|
39
|
+
select: { id: true, uuid: true, username: true },
|
|
40
|
+
});
|
|
37
41
|
}
|
|
38
42
|
/**
|
|
39
43
|
* Look up an agent's API key by UUID.
|
|
40
44
|
*/
|
|
41
45
|
export async function getAgentApiKeyByUuid(uuid) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
if (!prisma)
|
|
47
|
+
return null;
|
|
48
|
+
const user = await prisma.users.findFirst({
|
|
49
|
+
where: { uuid },
|
|
50
|
+
select: { api_key: true },
|
|
51
|
+
});
|
|
52
|
+
return user?.api_key ?? null;
|
|
48
53
|
}
|
|
49
54
|
/**
|
|
50
55
|
* Get the latest run_id and current session start time for a hub user by UUID.
|
|
51
56
|
*/
|
|
52
57
|
export async function getLatestRunInfoByUuid(uuid) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
if (!prisma)
|
|
59
|
+
return null;
|
|
60
|
+
const user = await prisma.users.findFirst({
|
|
61
|
+
where: { uuid },
|
|
62
|
+
select: { id: true },
|
|
63
|
+
});
|
|
64
|
+
if (!user)
|
|
65
|
+
return null;
|
|
66
|
+
const latest = await prisma.run_session.findFirst({
|
|
67
|
+
where: { user_id: user.id },
|
|
68
|
+
orderBy: [{ run_id: "desc" }, { session_id: "desc" }],
|
|
69
|
+
select: { run_id: true, created_at: true },
|
|
70
|
+
});
|
|
71
|
+
if (!latest)
|
|
72
|
+
return null;
|
|
73
|
+
return { runId: latest.run_id, sessionStart: latest.created_at };
|
|
66
74
|
}
|
|
67
75
|
/**
|
|
68
76
|
* Sum the cost of all cost entries for a hub user (by UUID) within a time range.
|
|
69
77
|
*/
|
|
70
78
|
export async function sumCostsByUuid(uuid, from, to) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
if (!prisma)
|
|
80
|
+
return 0;
|
|
81
|
+
const user = await prisma.users.findFirst({
|
|
82
|
+
where: { uuid },
|
|
83
|
+
select: { id: true },
|
|
84
|
+
});
|
|
85
|
+
if (!user)
|
|
86
|
+
return 0;
|
|
87
|
+
const result = await prisma.costs.aggregate({
|
|
88
|
+
_sum: { cost: true },
|
|
89
|
+
where: {
|
|
90
|
+
user_id: user.id,
|
|
91
|
+
created_at: { gte: from, lte: to },
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return result._sum.cost ?? 0;
|
|
85
95
|
}
|
|
86
96
|
/**
|
|
87
97
|
* Rotate an agent's API key by UUID.
|
|
88
98
|
*/
|
|
89
99
|
export async function rotateAgentApiKeyByUuid(uuid, newKey) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
if (!prisma)
|
|
101
|
+
throw new Error("Hub database not initialized");
|
|
102
|
+
const user = await prisma.users.findFirst({
|
|
103
|
+
where: { uuid },
|
|
104
|
+
select: { id: true },
|
|
105
|
+
});
|
|
106
|
+
if (!user)
|
|
107
|
+
throw new Error("Agent not found in hub database");
|
|
108
|
+
await prisma.users.update({
|
|
109
|
+
where: { id: user.id },
|
|
110
|
+
data: { api_key: newKey },
|
|
111
|
+
});
|
|
100
112
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
// Re-export Database Service
|
|
2
|
-
export { createHubDatabaseService } from "./hubDatabaseService.js";
|
|
2
|
+
export { createHubDatabaseService, } from "./hubDatabaseService.js";
|
|
3
3
|
// Re-export Migration Helper
|
|
4
4
|
export { deployPrismaMigrations } from "@naisys/common-node";
|
|
5
5
|
// Re-export Hub Session Service
|
|
6
|
-
export {
|
|
7
|
-
createHubDatabaseClient,
|
|
8
|
-
findAgentByApiKey,
|
|
9
|
-
getAgentApiKeyByUuid,
|
|
10
|
-
getHubAgentById,
|
|
11
|
-
getLatestRunInfoByUuid,
|
|
12
|
-
rotateAgentApiKeyByUuid,
|
|
13
|
-
sumCostsByUuid,
|
|
14
|
-
} from "./hubSessionService.js";
|
|
6
|
+
export { createHubDatabaseClient, findAgentByApiKey, getAgentApiKeyByUuid, getHubAgentById, getLatestRunInfoByUuid, rotateAgentApiKeyByUuid, sumCostsByUuid, } from "./hubSessionService.js";
|
|
15
7
|
// Re-export Prisma Client and all generated types
|
|
16
8
|
export * from "./generated/prisma/client.js";
|
|
17
9
|
export { PrismaClient } from "./generated/prisma/client.js";
|
package/dist/prismaClient.js
CHANGED
|
@@ -6,16 +6,16 @@ import { PrismaClient } from "./generated/prisma/client.js";
|
|
|
6
6
|
* @returns Configured PrismaClient instance
|
|
7
7
|
*/
|
|
8
8
|
export async function createPrismaClient(databasePath) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
const adapter = new PrismaBetterSqlite3({
|
|
10
|
+
url: `file:${databasePath}`,
|
|
11
|
+
timeout: 10_000, // Wait up to 10s for SQLite lock to be released
|
|
12
|
+
});
|
|
13
|
+
const prisma = new PrismaClient({ adapter });
|
|
14
|
+
// Enable WAL mode for better concurrent read/write performance
|
|
15
|
+
await prisma.$executeRawUnsafe("PRAGMA journal_mode=WAL");
|
|
16
|
+
// NORMAL is safe with WAL and avoids an extra fsync per commit
|
|
17
|
+
await prisma.$executeRawUnsafe("PRAGMA synchronous=NORMAL");
|
|
18
|
+
// SQLite doesn't enforce foreign keys by default — must be enabled per connection
|
|
19
|
+
await prisma.$executeRawUnsafe("PRAGMA foreign_keys=ON");
|
|
20
|
+
return prisma;
|
|
21
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naisys/hub-database",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "[internal] Hub database schema and Prisma client for NAISYS",
|
|
6
6
|
"files": [
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"typescript": "^5.9.3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@naisys/common": "3.0.0-beta.
|
|
30
|
-
"@naisys/common-node": "3.0.0-beta.
|
|
29
|
+
"@naisys/common": "3.0.0-beta.7",
|
|
30
|
+
"@naisys/common-node": "3.0.0-beta.7",
|
|
31
31
|
"@prisma/adapter-better-sqlite3": "^7.5.0",
|
|
32
32
|
"@prisma/client": "^7.5.0",
|
|
33
33
|
"better-sqlite3": "^12.6.2",
|