@pikku/kysely 0.13.15 → 0.13.16
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/CHANGELOG.md +94 -0
- package/dist/src/index.d.ts +7 -7
- package/dist/src/index.js +4 -4
- package/dist/src/kysely-agent-run-scores.d.ts +10 -0
- package/dist/src/kysely-agent-run-scores.js +34 -0
- package/dist/src/kysely-agent-run-service.d.ts +22 -0
- package/dist/src/kysely-agent-run-service.js +190 -0
- package/dist/src/kysely-agent-run-state-service.d.ts +24 -0
- package/dist/src/kysely-agent-run-state-service.js +169 -0
- package/dist/src/kysely-agent-storage-service.d.ts +40 -0
- package/dist/src/kysely-agent-storage-service.js +533 -0
- package/dist/src/kysely-ai-agent-run-service.d.ts +2 -1
- package/dist/src/kysely-ai-run-state-service.d.ts +2 -1
- package/dist/src/kysely-audit-service.d.ts +3 -1
- package/dist/src/kysely-deployment-service.d.ts +1 -1
- package/dist/src/kysely-deployment-service.js +2 -2
- package/dist/src/kysely-eventhub-store.d.ts +1 -1
- package/dist/src/kysely-eventhub-store.js +1 -1
- package/dist/src/kysely-scope-service.d.ts +4 -3
- package/dist/src/kysely-tables.d.ts +13 -13
- package/dist/src/kysely-virtual-user-run-store.d.ts +1 -1
- package/dist/src/kysely-webhook-service.d.ts +2 -1
- package/dist/src/kysely-webhook-service.js +2 -1
- package/dist/src/kysely-workflow-mirror.d.ts +2 -2
- package/dist/src/kysely-workflow-run-service.d.ts +1 -1
- package/dist/src/kysely-workflow-service.d.ts +3 -2
- package/dist/src/kysely-workflow-service.js +1 -1
- package/dist/src/schema/agent.schema.d.ts +12 -0
- package/dist/src/schema/agent.schema.js +102 -0
- package/dist/src/schema/index.js +4 -4
- package/dist/src/serialize-plugin.d.ts +0 -4
- package/dist/src/serialize-plugin.js +0 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/index.ts +9 -7
- package/src/{kysely-ai-run-scores.ts → kysely-agent-run-scores.ts} +5 -5
- package/src/{kysely-ai-agent-run-service.ts → kysely-agent-run-service.ts} +17 -18
- package/src/{kysely-ai-run-state-service.ts → kysely-agent-run-state-service.ts} +16 -15
- package/src/{kysely-ai-storage-service.ts → kysely-agent-storage-service.ts} +53 -43
- package/src/kysely-audit-service.ts +4 -2
- package/src/kysely-deployment-service.ts +3 -3
- package/src/kysely-eventhub-store.ts +1 -1
- package/src/kysely-scope-service.ts +7 -4
- package/src/kysely-services.test.ts +11 -11
- package/src/kysely-tables.ts +13 -13
- package/src/kysely-virtual-user-run-store.ts +2 -2
- package/src/kysely-webhook-service.ts +2 -2
- package/src/kysely-workflow-mirror.ts +2 -2
- package/src/kysely-workflow-run-service.ts +1 -1
- package/src/kysely-workflow-service.ts +3 -12
- package/src/schema/{ai.schema.ts → agent.schema.ts} +29 -29
- package/src/schema/index.ts +4 -4
- package/src/schema/schema.test.ts +6 -6
- package/src/serialize-plugin.ts +0 -5
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AgentStorageService,
|
|
3
|
+
AgentRunStateService,
|
|
4
4
|
CreateRunInput,
|
|
5
5
|
SaveScoreInput,
|
|
6
6
|
} from '@pikku/core/services'
|
|
7
|
-
import type {
|
|
8
|
-
|
|
7
|
+
import type {
|
|
8
|
+
AgentThread,
|
|
9
|
+
AgentMessage,
|
|
10
|
+
AgentRunState,
|
|
11
|
+
} from '@pikku/core/agent'
|
|
12
|
+
import type { AgentRunScore } from '@pikku/core/agent-scorer'
|
|
9
13
|
import type { Kysely } from 'kysely'
|
|
10
14
|
import type { KyselyPikkuDB } from './kysely-tables.js'
|
|
11
15
|
import { parseJson } from './kysely-json.js'
|
|
12
|
-
import { getRunScores, saveRunScore } from './kysely-
|
|
16
|
+
import { getRunScores, saveRunScore } from './kysely-agent-run-scores.js'
|
|
13
17
|
import { ensurePikkuSchema } from './schema/index.js'
|
|
14
|
-
import {
|
|
18
|
+
import { agentSchema } from './schema/agent.schema.js'
|
|
15
19
|
|
|
16
|
-
export class
|
|
17
|
-
implements
|
|
20
|
+
export class KyselyAgentStorageService
|
|
21
|
+
implements AgentStorageService, AgentRunStateService
|
|
18
22
|
{
|
|
19
23
|
private initialized = false
|
|
20
24
|
|
|
@@ -22,7 +26,7 @@ export class KyselyAIStorageService
|
|
|
22
26
|
|
|
23
27
|
public async init(): Promise<void> {
|
|
24
28
|
if (this.initialized) return
|
|
25
|
-
await ensurePikkuSchema(this.db,
|
|
29
|
+
await ensurePikkuSchema(this.db, agentSchema)
|
|
26
30
|
this.initialized = true
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -33,12 +37,12 @@ export class KyselyAIStorageService
|
|
|
33
37
|
title?: string
|
|
34
38
|
metadata?: Record<string, unknown>
|
|
35
39
|
}
|
|
36
|
-
): Promise<
|
|
40
|
+
): Promise<AgentThread> {
|
|
37
41
|
const id = options?.threadId ?? crypto.randomUUID()
|
|
38
42
|
const now = new Date()
|
|
39
43
|
|
|
40
44
|
await this.db
|
|
41
|
-
.insertInto('
|
|
45
|
+
.insertInto('agentThreads')
|
|
42
46
|
.values({
|
|
43
47
|
id,
|
|
44
48
|
resourceId: resourceId,
|
|
@@ -59,9 +63,9 @@ export class KyselyAIStorageService
|
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
async getThread(threadId: string): Promise<
|
|
66
|
+
async getThread(threadId: string): Promise<AgentThread> {
|
|
63
67
|
const row = await this.db
|
|
64
|
-
.selectFrom('
|
|
68
|
+
.selectFrom('agentThreads')
|
|
65
69
|
.select([
|
|
66
70
|
'id',
|
|
67
71
|
'resourceId',
|
|
@@ -87,9 +91,9 @@ export class KyselyAIStorageService
|
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
async getThreads(resourceId: string): Promise<
|
|
94
|
+
async getThreads(resourceId: string): Promise<AgentThread[]> {
|
|
91
95
|
const result = await this.db
|
|
92
|
-
.selectFrom('
|
|
96
|
+
.selectFrom('agentThreads')
|
|
93
97
|
.select([
|
|
94
98
|
'id',
|
|
95
99
|
'resourceId',
|
|
@@ -113,21 +117,24 @@ export class KyselyAIStorageService
|
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
async deleteThread(threadId: string): Promise<void> {
|
|
116
|
-
await this.db
|
|
120
|
+
await this.db
|
|
121
|
+
.deleteFrom('agentThreads')
|
|
122
|
+
.where('id', '=', threadId)
|
|
123
|
+
.execute()
|
|
117
124
|
}
|
|
118
125
|
|
|
119
126
|
async getMessages(
|
|
120
127
|
threadId: string,
|
|
121
128
|
options?: { lastN?: number; cursor?: string }
|
|
122
|
-
): Promise<
|
|
129
|
+
): Promise<AgentMessage[]> {
|
|
123
130
|
let msgQuery = this.db
|
|
124
|
-
.selectFrom('
|
|
131
|
+
.selectFrom('agentMessage')
|
|
125
132
|
.select(['id', 'role', 'content', 'createdAt'])
|
|
126
133
|
.where('threadId', '=', threadId)
|
|
127
134
|
|
|
128
135
|
if (options?.cursor) {
|
|
129
136
|
const cursorRow = await this.db
|
|
130
|
-
.selectFrom('
|
|
137
|
+
.selectFrom('agentMessage')
|
|
131
138
|
.select('createdAt')
|
|
132
139
|
.where('id', '=', options.cursor)
|
|
133
140
|
.executeTakeFirst()
|
|
@@ -150,7 +157,7 @@ export class KyselyAIStorageService
|
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
const tcResult = await this.db
|
|
153
|
-
.selectFrom('
|
|
160
|
+
.selectFrom('agentToolCall')
|
|
154
161
|
.select(['id', 'messageId', 'toolName', 'args', 'result'])
|
|
155
162
|
.where('threadId', '=', threadId)
|
|
156
163
|
.orderBy('createdAt', 'asc')
|
|
@@ -163,10 +170,10 @@ export class KyselyAIStorageService
|
|
|
163
170
|
tcByMessage.get(msgId)!.push(tc)
|
|
164
171
|
}
|
|
165
172
|
|
|
166
|
-
const messages:
|
|
173
|
+
const messages: AgentMessage[] = []
|
|
167
174
|
for (const row of msgResult) {
|
|
168
175
|
const rawContent = row.content as string | undefined
|
|
169
|
-
let parsedContent:
|
|
176
|
+
let parsedContent: AgentMessage['content'] = rawContent ?? undefined
|
|
170
177
|
if (rawContent) {
|
|
171
178
|
try {
|
|
172
179
|
const parsed = JSON.parse(rawContent)
|
|
@@ -179,9 +186,9 @@ export class KyselyAIStorageService
|
|
|
179
186
|
// Not JSON, use raw string
|
|
180
187
|
}
|
|
181
188
|
}
|
|
182
|
-
const msg:
|
|
189
|
+
const msg: AgentMessage = {
|
|
183
190
|
id: row.id,
|
|
184
|
-
role: row.role as
|
|
191
|
+
role: row.role as AgentMessage['role'],
|
|
185
192
|
content: parsedContent,
|
|
186
193
|
createdAt: new Date(row.createdAt),
|
|
187
194
|
}
|
|
@@ -217,7 +224,10 @@ export class KyselyAIStorageService
|
|
|
217
224
|
return messages
|
|
218
225
|
}
|
|
219
226
|
|
|
220
|
-
async saveMessages(
|
|
227
|
+
async saveMessages(
|
|
228
|
+
threadId: string,
|
|
229
|
+
messages: AgentMessage[]
|
|
230
|
+
): Promise<void> {
|
|
221
231
|
if (messages.length === 0) return
|
|
222
232
|
|
|
223
233
|
const toolMessages = messages.filter((m) => m.role === 'tool')
|
|
@@ -225,7 +235,7 @@ export class KyselyAIStorageService
|
|
|
225
235
|
|
|
226
236
|
if (nonToolMessages.length > 0) {
|
|
227
237
|
await this.db
|
|
228
|
-
.insertInto('
|
|
238
|
+
.insertInto('agentMessage')
|
|
229
239
|
.values(
|
|
230
240
|
nonToolMessages.map((msg) => ({
|
|
231
241
|
id: msg.id,
|
|
@@ -243,7 +253,7 @@ export class KyselyAIStorageService
|
|
|
243
253
|
)
|
|
244
254
|
if (toolCalls.length > 0) {
|
|
245
255
|
await this.db
|
|
246
|
-
.insertInto('
|
|
256
|
+
.insertInto('agentToolCall')
|
|
247
257
|
.values(
|
|
248
258
|
toolCalls.map((tc) => ({
|
|
249
259
|
id: tc.id,
|
|
@@ -260,7 +270,7 @@ export class KyselyAIStorageService
|
|
|
260
270
|
if (!toolMsg.toolResults) continue
|
|
261
271
|
for (const tr of toolMsg.toolResults) {
|
|
262
272
|
await this.db
|
|
263
|
-
.updateTable('
|
|
273
|
+
.updateTable('agentToolCall')
|
|
264
274
|
.set({ result: tr.result })
|
|
265
275
|
.where('id', '=', tr.id)
|
|
266
276
|
.execute()
|
|
@@ -268,7 +278,7 @@ export class KyselyAIStorageService
|
|
|
268
278
|
}
|
|
269
279
|
|
|
270
280
|
await this.db
|
|
271
|
-
.updateTable('
|
|
281
|
+
.updateTable('agentThreads')
|
|
272
282
|
.set({ updatedAt: new Date() })
|
|
273
283
|
.where('id', '=', threadId)
|
|
274
284
|
.execute()
|
|
@@ -279,7 +289,7 @@ export class KyselyAIStorageService
|
|
|
279
289
|
scope: 'resource' | 'thread'
|
|
280
290
|
): Promise<Record<string, unknown> | null> {
|
|
281
291
|
const row = await this.db
|
|
282
|
-
.selectFrom('
|
|
292
|
+
.selectFrom('agentWorkingMemory')
|
|
283
293
|
.select('data')
|
|
284
294
|
.where('id', '=', id)
|
|
285
295
|
.where('scope', '=', scope)
|
|
@@ -295,7 +305,7 @@ export class KyselyAIStorageService
|
|
|
295
305
|
data: Record<string, unknown>
|
|
296
306
|
): Promise<void> {
|
|
297
307
|
await this.db
|
|
298
|
-
.insertInto('
|
|
308
|
+
.insertInto('agentWorkingMemory')
|
|
299
309
|
.values({
|
|
300
310
|
id,
|
|
301
311
|
scope,
|
|
@@ -315,7 +325,7 @@ export class KyselyAIStorageService
|
|
|
315
325
|
const runId = crypto.randomUUID()
|
|
316
326
|
|
|
317
327
|
await this.db
|
|
318
|
-
.insertInto('
|
|
328
|
+
.insertInto('agentRun')
|
|
319
329
|
.values({
|
|
320
330
|
runId: runId,
|
|
321
331
|
agentName: run.agentName,
|
|
@@ -365,14 +375,14 @@ export class KyselyAIStorageService
|
|
|
365
375
|
}
|
|
366
376
|
|
|
367
377
|
await this.db
|
|
368
|
-
.updateTable('
|
|
378
|
+
.updateTable('agentRun')
|
|
369
379
|
.set(setValues)
|
|
370
380
|
.where('runId', '=', runId)
|
|
371
381
|
.execute()
|
|
372
382
|
|
|
373
383
|
if (updates.pendingApprovals !== undefined) {
|
|
374
384
|
await this.db
|
|
375
|
-
.updateTable('
|
|
385
|
+
.updateTable('agentToolCall')
|
|
376
386
|
.set({
|
|
377
387
|
approvalStatus: null,
|
|
378
388
|
runId: null,
|
|
@@ -393,7 +403,7 @@ export class KyselyAIStorageService
|
|
|
393
403
|
|
|
394
404
|
async getRun(runId: string): Promise<AgentRunState | null> {
|
|
395
405
|
const row = await this.db
|
|
396
|
-
.selectFrom('
|
|
406
|
+
.selectFrom('agentRun')
|
|
397
407
|
.select([
|
|
398
408
|
'runId',
|
|
399
409
|
'agentName',
|
|
@@ -415,7 +425,7 @@ export class KyselyAIStorageService
|
|
|
415
425
|
if (!row) return null
|
|
416
426
|
|
|
417
427
|
const approvals = await this.db
|
|
418
|
-
.selectFrom('
|
|
428
|
+
.selectFrom('agentToolCall')
|
|
419
429
|
.select([
|
|
420
430
|
'id',
|
|
421
431
|
'toolName',
|
|
@@ -434,7 +444,7 @@ export class KyselyAIStorageService
|
|
|
434
444
|
|
|
435
445
|
async getRunsByThread(threadId: string): Promise<AgentRunState[]> {
|
|
436
446
|
const result = await this.db
|
|
437
|
-
.selectFrom('
|
|
447
|
+
.selectFrom('agentRun')
|
|
438
448
|
.select([
|
|
439
449
|
'runId',
|
|
440
450
|
'agentName',
|
|
@@ -457,7 +467,7 @@ export class KyselyAIStorageService
|
|
|
457
467
|
const runs: AgentRunState[] = []
|
|
458
468
|
for (const row of result) {
|
|
459
469
|
const approvals = await this.db
|
|
460
|
-
.selectFrom('
|
|
470
|
+
.selectFrom('agentToolCall')
|
|
461
471
|
.select([
|
|
462
472
|
'id',
|
|
463
473
|
'toolName',
|
|
@@ -482,7 +492,7 @@ export class KyselyAIStorageService
|
|
|
482
492
|
for (const a of approvals) {
|
|
483
493
|
if (a.type === 'agent-call') {
|
|
484
494
|
await this.db
|
|
485
|
-
.updateTable('
|
|
495
|
+
.updateTable('agentToolCall')
|
|
486
496
|
.set({
|
|
487
497
|
approvalStatus: 'pending',
|
|
488
498
|
runId: runId,
|
|
@@ -495,7 +505,7 @@ export class KyselyAIStorageService
|
|
|
495
505
|
.execute()
|
|
496
506
|
} else {
|
|
497
507
|
await this.db
|
|
498
|
-
.updateTable('
|
|
508
|
+
.updateTable('agentToolCall')
|
|
499
509
|
.set({
|
|
500
510
|
approvalStatus: 'pending',
|
|
501
511
|
runId: runId,
|
|
@@ -554,7 +564,7 @@ export class KyselyAIStorageService
|
|
|
554
564
|
approval: NonNullable<AgentRunState['pendingApprovals']>[number]
|
|
555
565
|
} | null> {
|
|
556
566
|
const tc = await this.db
|
|
557
|
-
.selectFrom('
|
|
567
|
+
.selectFrom('agentToolCall')
|
|
558
568
|
.select([
|
|
559
569
|
'id',
|
|
560
570
|
'toolName',
|
|
@@ -602,7 +612,7 @@ export class KyselyAIStorageService
|
|
|
602
612
|
): Promise<boolean> {
|
|
603
613
|
// Only the caller that moves the tool call off 'pending' has claimed it.
|
|
604
614
|
const result = await this.db
|
|
605
|
-
.updateTable('
|
|
615
|
+
.updateTable('agentToolCall')
|
|
606
616
|
.set({ approvalStatus: status })
|
|
607
617
|
.where('id', '=', toolCallId)
|
|
608
618
|
.where('approvalStatus', '=', 'pending')
|
|
@@ -614,7 +624,7 @@ export class KyselyAIStorageService
|
|
|
614
624
|
await saveRunScore(this.db, score)
|
|
615
625
|
}
|
|
616
626
|
|
|
617
|
-
async getScores(runId: string): Promise<
|
|
627
|
+
async getScores(runId: string): Promise<AgentRunScore[]> {
|
|
618
628
|
return getRunScores(this.db, runId)
|
|
619
629
|
}
|
|
620
630
|
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import type { AuditService } from '@pikku/core'
|
|
1
2
|
import type {
|
|
2
3
|
AuditEvent,
|
|
3
4
|
AuditEventBatch,
|
|
5
|
+
} from '@pikku/core/ecosystem/services'
|
|
6
|
+
import type {
|
|
4
7
|
AuditFacets,
|
|
5
8
|
AuditQuery,
|
|
6
9
|
AuditQueryResult,
|
|
7
|
-
|
|
8
|
-
} from '@pikku/core'
|
|
10
|
+
} from '@pikku/core/ecosystem/types'
|
|
9
11
|
import type { Kysely } from 'kysely'
|
|
10
12
|
import { ensurePikkuSchema } from './schema/index.js'
|
|
11
13
|
import { auditSchema } from './schema/audit.schema.js'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { buildRemoteHeaders } from '@pikku/core/remote'
|
|
1
|
+
import { buildRemoteHeaders } from '@pikku/core/ecosystem/remote'
|
|
2
2
|
import type {
|
|
3
3
|
DeploymentService,
|
|
4
4
|
DeploymentServiceConfig,
|
|
5
5
|
DeploymentConfig,
|
|
6
|
-
} from '@pikku/core/services'
|
|
6
|
+
} from '@pikku/core/ecosystem/services'
|
|
7
7
|
import type { JWTService, SecretService } from '@pikku/core/services'
|
|
8
|
-
import { getAllFunctionNames } from '@pikku/core/function'
|
|
8
|
+
import { getAllFunctionNames } from '@pikku/core/ecosystem/function'
|
|
9
9
|
import type { Kysely } from 'kysely'
|
|
10
10
|
import type { KyselyPikkuDB } from './kysely-tables.js'
|
|
11
11
|
import { ensurePikkuSchema } from './schema/index.js'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { ScopeService } from '@pikku/core/services'
|
|
2
|
+
import type { Role } from '@pikku/core/ecosystem/services'
|
|
3
|
+
import type { FlatScope } from '@pikku/core/ecosystem/scope'
|
|
4
|
+
import type { SystemRole } from '@pikku/core/ecosystem/role'
|
|
4
5
|
import {
|
|
5
6
|
SystemRoleImmutableError,
|
|
6
7
|
SystemRoleShadowedError,
|
|
@@ -378,7 +379,9 @@ export class KyselyScopeService implements ScopeService {
|
|
|
378
379
|
* different decisions, and the number is what makes pruning a choice rather
|
|
379
380
|
* than a formality.
|
|
380
381
|
*/
|
|
381
|
-
async findStaleSystemRoles(): Promise<
|
|
382
|
+
async findStaleSystemRoles(): Promise<
|
|
383
|
+
Array<{ role: string; users: number }>
|
|
384
|
+
> {
|
|
382
385
|
const stale = await this.db
|
|
383
386
|
.selectFrom('pikkuRoles')
|
|
384
387
|
.leftJoin('pikkuUserRole', 'pikkuUserRole.role', 'pikkuRoles.name')
|
|
@@ -5,7 +5,7 @@ import { SerializePlugin } from './serialize-plugin.js'
|
|
|
5
5
|
import Database from 'better-sqlite3'
|
|
6
6
|
import { PostgresJSDialect } from 'kysely-postgres-js'
|
|
7
7
|
import postgres from 'postgres'
|
|
8
|
-
import { defineServiceTests } from '@pikku/core/testing'
|
|
8
|
+
import { defineServiceTests } from '@pikku/core/ecosystem/testing'
|
|
9
9
|
|
|
10
10
|
import type { KyselyPikkuDB } from './kysely-tables.js'
|
|
11
11
|
import { KyselyChannelStore } from './kysely-channel-store.js'
|
|
@@ -13,8 +13,8 @@ import { KyselyEventHubStore } from './kysely-eventhub-store.js'
|
|
|
13
13
|
import { KyselyWorkflowService } from './kysely-workflow-service.js'
|
|
14
14
|
import { KyselyWorkflowRunService } from './kysely-workflow-run-service.js'
|
|
15
15
|
import { KyselyDeploymentService } from './kysely-deployment-service.js'
|
|
16
|
-
import {
|
|
17
|
-
import { KyselyAgentRunService } from './kysely-
|
|
16
|
+
import { KyselyAgentStorageService } from './kysely-agent-storage-service.js'
|
|
17
|
+
import { KyselyAgentRunService } from './kysely-agent-run-service.js'
|
|
18
18
|
import { KyselySecretService } from './kysely-secret-service.js'
|
|
19
19
|
import { KyselyCredentialService } from './kysely-credential-service.js'
|
|
20
20
|
import { KyselySessionStore } from './kysely-session-store.js'
|
|
@@ -42,12 +42,12 @@ async function dropAllTables(db: Kysely<KyselyPikkuDB>): Promise<void> {
|
|
|
42
42
|
const tables = [
|
|
43
43
|
'pikku_deployment_functions',
|
|
44
44
|
'pikku_deployments',
|
|
45
|
-
'
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
45
|
+
'agent_tool_call',
|
|
46
|
+
'agent_message',
|
|
47
|
+
'agent_run_score',
|
|
48
|
+
'agent_run',
|
|
49
|
+
'agent_working_memory',
|
|
50
|
+
'agent_threads',
|
|
51
51
|
'channel_subscriptions',
|
|
52
52
|
'channels',
|
|
53
53
|
'workflow_step_history',
|
|
@@ -97,8 +97,8 @@ function registerTests(
|
|
|
97
97
|
await s.init()
|
|
98
98
|
return s
|
|
99
99
|
},
|
|
100
|
-
|
|
101
|
-
const s = new
|
|
100
|
+
agentStorageService: async () => {
|
|
101
|
+
const s = new KyselyAgentStorageService(getDb())
|
|
102
102
|
await s.init()
|
|
103
103
|
return s
|
|
104
104
|
},
|
package/src/kysely-tables.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
WorkflowStatus,
|
|
4
4
|
StepStatus,
|
|
5
5
|
WorkflowVersionStatus,
|
|
6
|
-
} from '@pikku/core/workflow'
|
|
6
|
+
} from '@pikku/core/ecosystem/workflow'
|
|
7
7
|
|
|
8
8
|
export interface ChannelsTable {
|
|
9
9
|
channelId: string
|
|
@@ -86,7 +86,7 @@ export interface WorkflowVersionsTable {
|
|
|
86
86
|
createdAt: Generated<Date>
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export interface
|
|
89
|
+
export interface AgentThreadsTable {
|
|
90
90
|
id: string
|
|
91
91
|
resourceId: string
|
|
92
92
|
title: string | null
|
|
@@ -95,7 +95,7 @@ export interface AIThreadsTable {
|
|
|
95
95
|
updatedAt: Generated<Date>
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
export interface
|
|
98
|
+
export interface AgentMessageTable {
|
|
99
99
|
id: string
|
|
100
100
|
threadId: string
|
|
101
101
|
role: 'system' | 'user' | 'assistant' | 'tool'
|
|
@@ -103,7 +103,7 @@ export interface AIMessageTable {
|
|
|
103
103
|
createdAt: Generated<Date>
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
export interface
|
|
106
|
+
export interface AgentToolCallTable {
|
|
107
107
|
id: string
|
|
108
108
|
threadId: string
|
|
109
109
|
messageId: string
|
|
@@ -119,14 +119,14 @@ export interface AIToolCallTable {
|
|
|
119
119
|
createdAt: Generated<Date>
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
export interface
|
|
122
|
+
export interface AgentWorkingMemoryTable {
|
|
123
123
|
id: string
|
|
124
124
|
scope: string
|
|
125
125
|
data: string
|
|
126
126
|
updatedAt: Generated<Date>
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
export interface
|
|
129
|
+
export interface AgentRunTable {
|
|
130
130
|
runId: Generated<string>
|
|
131
131
|
agentName: string
|
|
132
132
|
threadId: string
|
|
@@ -151,7 +151,7 @@ export interface AIRunTable {
|
|
|
151
151
|
updatedAt: Generated<Date>
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
export interface
|
|
154
|
+
export interface AgentRunScoreTable {
|
|
155
155
|
id: string
|
|
156
156
|
runId: string
|
|
157
157
|
scorerName: string
|
|
@@ -336,12 +336,12 @@ export interface KyselyPikkuDB {
|
|
|
336
336
|
workflowStep: WorkflowStepTable
|
|
337
337
|
workflowStepHistory: WorkflowStepHistoryTable
|
|
338
338
|
workflowVersions: WorkflowVersionsTable
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
339
|
+
agentThreads: AgentThreadsTable
|
|
340
|
+
agentMessage: AgentMessageTable
|
|
341
|
+
agentToolCall: AgentToolCallTable
|
|
342
|
+
agentWorkingMemory: AgentWorkingMemoryTable
|
|
343
|
+
agentRun: AgentRunTable
|
|
344
|
+
agentRunScore: AgentRunScoreTable
|
|
345
345
|
pikkuDeployments: PikkuDeploymentsTable
|
|
346
346
|
pikkuDeploymentFunctions: PikkuDeploymentFunctionsTable
|
|
347
347
|
secrets: SecretsTable
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Kysely, Selectable } from 'kysely'
|
|
2
2
|
import { randomUUID } from 'node:crypto'
|
|
3
|
+
import type { VirtualUserDisposition } from '@pikku/core/virtual-user'
|
|
3
4
|
import type {
|
|
4
|
-
VirtualUserDisposition,
|
|
5
5
|
VirtualUserRunOutcome,
|
|
6
6
|
VirtualUserRunRecord,
|
|
7
7
|
VirtualUserRunStart,
|
|
8
8
|
VirtualUserRunStore,
|
|
9
|
-
} from '@pikku/core/virtual-user'
|
|
9
|
+
} from '@pikku/core/ecosystem/virtual-user'
|
|
10
10
|
import type { KyselyPikkuDB, VirtualUserRunTable } from './kysely-tables.js'
|
|
11
11
|
import { parseJson } from './kysely-json.js'
|
|
12
12
|
import { ensurePikkuSchema } from './schema/index.js'
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { QueueWebhookService } from '@pikku/core/services'
|
|
1
2
|
import {
|
|
2
3
|
PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME,
|
|
3
|
-
QueueWebhookService,
|
|
4
4
|
type SendWebhookInput,
|
|
5
5
|
type SendWebhookResult,
|
|
6
6
|
type WebhookAttemptResult,
|
|
7
7
|
type WebhookDeliveryRecord,
|
|
8
8
|
type WebhookDeliveryWithAttempts,
|
|
9
|
-
} from '@pikku/core/services'
|
|
9
|
+
} from '@pikku/core/ecosystem/services'
|
|
10
10
|
import type { QueueService } from '@pikku/core/queue'
|
|
11
11
|
import type { Kysely } from 'kysely'
|
|
12
12
|
import type { KyselyPikkuDB } from './kysely-tables.js'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SerializedError } from '@pikku/core'
|
|
1
|
+
import type { SerializedError } from '@pikku/core/ecosystem/types'
|
|
2
2
|
import type {
|
|
3
3
|
StepState,
|
|
4
4
|
WorkflowRunMirror,
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
WorkflowStatus,
|
|
7
7
|
WorkflowPlannedStep,
|
|
8
8
|
WorkflowVersionStatus,
|
|
9
|
-
} from '@pikku/core/workflow'
|
|
9
|
+
} from '@pikku/core/ecosystem/workflow'
|
|
10
10
|
import type { Kysely } from 'kysely'
|
|
11
11
|
import type { KyselyPikkuDB } from './kysely-tables.js'
|
|
12
12
|
import { ensurePikkuSchema } from './schema/index.js'
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
StepState,
|
|
4
4
|
WorkflowStatus,
|
|
5
5
|
WorkflowRunService,
|
|
6
|
-
} from '@pikku/core/workflow'
|
|
6
|
+
} from '@pikku/core/ecosystem/workflow'
|
|
7
7
|
import type { Kysely } from 'kysely'
|
|
8
8
|
import type { KyselyPikkuDB } from './kysely-tables.js'
|
|
9
9
|
import { parseJson } from './kysely-json.js'
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import type { SerializedError } from '@pikku/core'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type WorkflowPlannedStep,
|
|
5
|
-
type WorkflowQueueOptions,
|
|
6
|
-
type WorkflowRun,
|
|
7
|
-
type WorkflowRunWire,
|
|
8
|
-
type StepState,
|
|
9
|
-
type StepStatus,
|
|
10
|
-
type WorkflowStatus,
|
|
11
|
-
type WorkflowVersionStatus,
|
|
12
|
-
} from '@pikku/core/workflow'
|
|
1
|
+
import type { SerializedError } from '@pikku/core/ecosystem/types'
|
|
2
|
+
import { PikkuWorkflowService } from '@pikku/core/workflow'
|
|
3
|
+
import type { WorkflowPlannedStep, WorkflowQueueOptions, WorkflowRun, WorkflowRunWire, StepState, StepStatus, WorkflowStatus, WorkflowVersionStatus } from '@pikku/core/ecosystem/workflow'
|
|
13
4
|
import { sql, type Kysely } from 'kysely'
|
|
14
5
|
import type { KyselyPikkuDB } from './kysely-tables.js'
|
|
15
6
|
import { KyselyWorkflowRunService } from './kysely-workflow-run-service.js'
|