@pikku/kysely 0.12.5 → 0.12.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/CHANGELOG.md +15 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +1 -0
- package/dist/src/kysely-agent-run-service.js +59 -59
- package/dist/src/kysely-ai-storage-service.js +174 -174
- package/dist/src/kysely-channel-store.js +12 -12
- package/dist/src/kysely-credential-service.d.ts +30 -0
- package/dist/src/kysely-credential-service.js +188 -0
- package/dist/src/kysely-deployment-service.js +22 -22
- package/dist/src/kysely-eventhub-store.js +8 -8
- package/dist/src/kysely-secret-service.js +19 -19
- package/dist/src/kysely-tables.d.ts +100 -82
- package/dist/src/kysely-workflow-run-service.js +73 -73
- package/dist/src/kysely-workflow-service.js +127 -127
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/kysely-agent-run-service.ts +59 -59
- package/src/kysely-ai-storage-service.ts +174 -174
- package/src/kysely-channel-store.ts +12 -12
- package/src/kysely-credential-service.ts +252 -0
- package/src/kysely-deployment-service.ts +24 -24
- package/src/kysely-eventhub-store.ts +8 -8
- package/src/kysely-secret-service.ts +19 -19
- package/src/kysely-services.test.ts +67 -8
- package/src/kysely-tables.ts +102 -82
- package/src/kysely-workflow-run-service.ts +76 -76
- package/src/kysely-workflow-service.ts +129 -129
|
@@ -19,14 +19,14 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
19
19
|
const { agentName, limit = 50, offset = 0 } = options ?? {}
|
|
20
20
|
|
|
21
21
|
let query = this.db
|
|
22
|
-
.selectFrom('
|
|
22
|
+
.selectFrom('aiThreads as t')
|
|
23
23
|
.select([
|
|
24
24
|
't.id',
|
|
25
|
-
't.
|
|
25
|
+
't.resourceId',
|
|
26
26
|
't.title',
|
|
27
27
|
't.metadata',
|
|
28
|
-
't.
|
|
29
|
-
't.
|
|
28
|
+
't.createdAt',
|
|
29
|
+
't.updatedAt',
|
|
30
30
|
])
|
|
31
31
|
|
|
32
32
|
if (agentName) {
|
|
@@ -34,15 +34,15 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
34
34
|
't.id',
|
|
35
35
|
'in',
|
|
36
36
|
this.db
|
|
37
|
-
.selectFrom('
|
|
38
|
-
.select('
|
|
39
|
-
.where('
|
|
37
|
+
.selectFrom('aiRun')
|
|
38
|
+
.select('threadId')
|
|
39
|
+
.where('agentName', '=', agentName)
|
|
40
40
|
.distinct()
|
|
41
41
|
)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const result = await query
|
|
45
|
-
.orderBy('t.
|
|
45
|
+
.orderBy('t.updatedAt', 'desc')
|
|
46
46
|
.limit(limit)
|
|
47
47
|
.offset(offset)
|
|
48
48
|
.execute()
|
|
@@ -52,14 +52,14 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
52
52
|
|
|
53
53
|
async getThread(threadId: string): Promise<AIThread | null> {
|
|
54
54
|
const row = await this.db
|
|
55
|
-
.selectFrom('
|
|
55
|
+
.selectFrom('aiThreads')
|
|
56
56
|
.select([
|
|
57
57
|
'id',
|
|
58
|
-
'
|
|
58
|
+
'resourceId',
|
|
59
59
|
'title',
|
|
60
60
|
'metadata',
|
|
61
|
-
'
|
|
62
|
-
'
|
|
61
|
+
'createdAt',
|
|
62
|
+
'updatedAt',
|
|
63
63
|
])
|
|
64
64
|
.where('id', '=', threadId)
|
|
65
65
|
.executeTakeFirst()
|
|
@@ -71,22 +71,22 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
71
71
|
async getThreadMessages(threadId: string): Promise<AIMessage[]> {
|
|
72
72
|
const [msgResult, tcResult] = await Promise.all([
|
|
73
73
|
this.db
|
|
74
|
-
.selectFrom('
|
|
75
|
-
.select(['id', 'role', 'content', '
|
|
76
|
-
.where('
|
|
77
|
-
.orderBy('
|
|
74
|
+
.selectFrom('aiMessage')
|
|
75
|
+
.select(['id', 'role', 'content', 'createdAt'])
|
|
76
|
+
.where('threadId', '=', threadId)
|
|
77
|
+
.orderBy('createdAt', 'asc')
|
|
78
78
|
.execute(),
|
|
79
79
|
this.db
|
|
80
|
-
.selectFrom('
|
|
81
|
-
.select(['id', '
|
|
82
|
-
.where('
|
|
83
|
-
.orderBy('
|
|
80
|
+
.selectFrom('aiToolCall')
|
|
81
|
+
.select(['id', 'messageId', 'toolName', 'args', 'result'])
|
|
82
|
+
.where('threadId', '=', threadId)
|
|
83
|
+
.orderBy('createdAt', 'asc')
|
|
84
84
|
.execute(),
|
|
85
85
|
])
|
|
86
86
|
|
|
87
87
|
const tcByMessage = new Map<string, (typeof tcResult)[number][]>()
|
|
88
88
|
for (const tc of tcResult) {
|
|
89
|
-
const msgId = tc.
|
|
89
|
+
const msgId = tc.messageId
|
|
90
90
|
if (!tcByMessage.has(msgId)) tcByMessage.set(msgId, [])
|
|
91
91
|
tcByMessage.get(msgId)!.push(tc)
|
|
92
92
|
}
|
|
@@ -97,14 +97,14 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
97
97
|
id: row.id,
|
|
98
98
|
role: row.role as AIMessage['role'],
|
|
99
99
|
content: row.content ?? undefined,
|
|
100
|
-
createdAt: new Date(row.
|
|
100
|
+
createdAt: new Date(row.createdAt as unknown as string),
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
const tcs = tcByMessage.get(msg.id)
|
|
104
104
|
if (tcs?.length) {
|
|
105
105
|
msg.toolCalls = tcs.map((tc) => ({
|
|
106
106
|
id: tc.id,
|
|
107
|
-
name: tc.
|
|
107
|
+
name: tc.toolName,
|
|
108
108
|
args: parseJson(tc.args) as Record<string, unknown>,
|
|
109
109
|
}))
|
|
110
110
|
|
|
@@ -116,7 +116,7 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
116
116
|
role: 'tool',
|
|
117
117
|
toolResults: completed.map((tc) => ({
|
|
118
118
|
id: tc.id,
|
|
119
|
-
name: tc.
|
|
119
|
+
name: tc.toolName,
|
|
120
120
|
result: tc.result!,
|
|
121
121
|
})),
|
|
122
122
|
createdAt: msg.createdAt,
|
|
@@ -133,24 +133,24 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
133
133
|
|
|
134
134
|
async getThreadRuns(threadId: string): Promise<AgentRunRow[]> {
|
|
135
135
|
const result = await this.db
|
|
136
|
-
.selectFrom('
|
|
136
|
+
.selectFrom('aiRun')
|
|
137
137
|
.select([
|
|
138
|
-
'
|
|
139
|
-
'
|
|
140
|
-
'
|
|
141
|
-
'
|
|
138
|
+
'runId',
|
|
139
|
+
'agentName',
|
|
140
|
+
'threadId',
|
|
141
|
+
'resourceId',
|
|
142
142
|
'status',
|
|
143
|
-
'
|
|
144
|
-
'
|
|
145
|
-
'
|
|
146
|
-
'
|
|
147
|
-
'
|
|
148
|
-
'
|
|
149
|
-
'
|
|
150
|
-
'
|
|
143
|
+
'errorMessage',
|
|
144
|
+
'suspendReason',
|
|
145
|
+
'missingRpcs',
|
|
146
|
+
'usageInputTokens',
|
|
147
|
+
'usageOutputTokens',
|
|
148
|
+
'usageModel',
|
|
149
|
+
'createdAt',
|
|
150
|
+
'updatedAt',
|
|
151
151
|
])
|
|
152
|
-
.where('
|
|
153
|
-
.orderBy('
|
|
152
|
+
.where('threadId', '=', threadId)
|
|
153
|
+
.orderBy('createdAt', 'desc')
|
|
154
154
|
.execute()
|
|
155
155
|
|
|
156
156
|
return result.map((row) => this.mapRunRow(row))
|
|
@@ -158,7 +158,7 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
158
158
|
|
|
159
159
|
async deleteThread(threadId: string): Promise<boolean> {
|
|
160
160
|
const result = await this.db
|
|
161
|
-
.deleteFrom('
|
|
161
|
+
.deleteFrom('aiThreads')
|
|
162
162
|
.where('id', '=', threadId)
|
|
163
163
|
.executeTakeFirst()
|
|
164
164
|
|
|
@@ -167,41 +167,41 @@ export class KyselyAgentRunService implements AgentRunService {
|
|
|
167
167
|
|
|
168
168
|
async getDistinctAgentNames(): Promise<string[]> {
|
|
169
169
|
const result = await this.db
|
|
170
|
-
.selectFrom('
|
|
171
|
-
.select('
|
|
170
|
+
.selectFrom('aiRun')
|
|
171
|
+
.select('agentName')
|
|
172
172
|
.distinct()
|
|
173
|
-
.orderBy('
|
|
173
|
+
.orderBy('agentName')
|
|
174
174
|
.execute()
|
|
175
175
|
|
|
176
|
-
return result.map((row) => row.
|
|
176
|
+
return result.map((row) => row.agentName)
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
private mapThreadRow(row: any): AIThread {
|
|
180
180
|
return {
|
|
181
181
|
id: row.id as string,
|
|
182
|
-
resourceId: row.
|
|
182
|
+
resourceId: row.resourceId as string,
|
|
183
183
|
title: (row.title as string) ?? undefined,
|
|
184
184
|
metadata: parseJson(row.metadata),
|
|
185
|
-
createdAt: new Date(row.
|
|
186
|
-
updatedAt: new Date(row.
|
|
185
|
+
createdAt: new Date(row.createdAt as string),
|
|
186
|
+
updatedAt: new Date(row.updatedAt as string),
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
private mapRunRow(row: any): AgentRunRow {
|
|
191
191
|
return {
|
|
192
|
-
runId: row.
|
|
193
|
-
agentName: row.
|
|
194
|
-
threadId: row.
|
|
195
|
-
resourceId: row.
|
|
192
|
+
runId: row.runId as string,
|
|
193
|
+
agentName: row.agentName as string,
|
|
194
|
+
threadId: row.threadId as string,
|
|
195
|
+
resourceId: row.resourceId as string,
|
|
196
196
|
status: row.status as string,
|
|
197
|
-
errorMessage: (row.
|
|
198
|
-
suspendReason: (row.
|
|
199
|
-
missingRpcs: parseJson(row.
|
|
200
|
-
usageInputTokens: Number(row.
|
|
201
|
-
usageOutputTokens: Number(row.
|
|
202
|
-
usageModel: row.
|
|
203
|
-
createdAt: new Date(row.
|
|
204
|
-
updatedAt: new Date(row.
|
|
197
|
+
errorMessage: (row.errorMessage as string) ?? undefined,
|
|
198
|
+
suspendReason: (row.suspendReason as string) ?? undefined,
|
|
199
|
+
missingRpcs: parseJson(row.missingRpcs),
|
|
200
|
+
usageInputTokens: Number(row.usageInputTokens),
|
|
201
|
+
usageOutputTokens: Number(row.usageOutputTokens),
|
|
202
|
+
usageModel: row.usageModel as string,
|
|
203
|
+
createdAt: new Date(row.createdAt as string),
|
|
204
|
+
updatedAt: new Date(row.updatedAt as string),
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
}
|