@pikku/kysely 0.12.6 → 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.
@@ -6,21 +6,21 @@ import type {
6
6
  } from '@pikku/core/workflow'
7
7
 
8
8
  export interface ChannelsTable {
9
- channel_id: string
10
- channel_name: string
11
- created_at: Generated<Date>
12
- opening_data: string
13
- user_session: string | null
14
- last_wire: Generated<Date>
9
+ channelId: string
10
+ channelName: string
11
+ createdAt: Generated<Date>
12
+ openingData: string
13
+ userSession: string | null
14
+ lastWire: Generated<Date>
15
15
  }
16
16
 
17
17
  export interface ChannelSubscriptionsTable {
18
- channel_id: string
18
+ channelId: string
19
19
  topic: string
20
20
  }
21
21
 
22
22
  export interface WorkflowRunsTable {
23
- workflow_run_id: Generated<string>
23
+ workflowRunId: Generated<string>
24
24
  workflow: string
25
25
  status: WorkflowStatus
26
26
  input: string
@@ -28,169 +28,169 @@ export interface WorkflowRunsTable {
28
28
  error: string | null
29
29
  state: Generated<string>
30
30
  inline: Generated<boolean>
31
- graph_hash: string | null
31
+ graphHash: string | null
32
32
  wire: string | null
33
- created_at: Generated<Date>
34
- updated_at: Generated<Date>
33
+ createdAt: Generated<Date>
34
+ updatedAt: Generated<Date>
35
35
  }
36
36
 
37
37
  export interface WorkflowStepTable {
38
- workflow_step_id: Generated<string>
39
- workflow_run_id: string
40
- step_name: string
41
- rpc_name: string | null
38
+ workflowStepId: Generated<string>
39
+ workflowRunId: string
40
+ stepName: string
41
+ rpcName: string | null
42
42
  data: string | null
43
43
  status: Generated<StepStatus>
44
44
  result: string | null
45
45
  error: string | null
46
- child_run_id: string | null
47
- branch_taken: string | null
46
+ childRunId: string | null
47
+ branchTaken: string | null
48
48
  retries: number | null
49
- retry_delay: string | null
50
- created_at: Generated<Date>
51
- updated_at: Generated<Date>
49
+ retryDelay: string | null
50
+ createdAt: Generated<Date>
51
+ updatedAt: Generated<Date>
52
52
  }
53
53
 
54
54
  export interface WorkflowStepHistoryTable {
55
- history_id: Generated<string>
56
- workflow_step_id: string
55
+ historyId: Generated<string>
56
+ workflowStepId: string
57
57
  status: StepStatus
58
58
  result: string | null
59
59
  error: string | null
60
- created_at: Generated<Date>
61
- running_at: Date | null
62
- scheduled_at: Date | null
63
- succeeded_at: Date | null
64
- failed_at: Date | null
60
+ createdAt: Generated<Date>
61
+ runningAt: Date | null
62
+ scheduledAt: Date | null
63
+ succeededAt: Date | null
64
+ failedAt: Date | null
65
65
  }
66
66
 
67
67
  export interface WorkflowVersionsTable {
68
- workflow_name: string
69
- graph_hash: string
68
+ workflowName: string
69
+ graphHash: string
70
70
  graph: string
71
71
  source: string
72
72
  status: Generated<WorkflowVersionStatus>
73
- created_at: Generated<Date>
73
+ createdAt: Generated<Date>
74
74
  }
75
75
 
76
76
  export interface AIThreadsTable {
77
77
  id: string
78
- resource_id: string
78
+ resourceId: string
79
79
  title: string | null
80
80
  metadata: string | null
81
- created_at: Generated<Date>
82
- updated_at: Generated<Date>
81
+ createdAt: Generated<Date>
82
+ updatedAt: Generated<Date>
83
83
  }
84
84
 
85
85
  export interface AIMessageTable {
86
86
  id: string
87
- thread_id: string
87
+ threadId: string
88
88
  role: 'system' | 'user' | 'assistant' | 'tool'
89
89
  content: string | null
90
- created_at: Generated<Date>
90
+ createdAt: Generated<Date>
91
91
  }
92
92
 
93
93
  export interface AIToolCallTable {
94
94
  id: string
95
- thread_id: string
96
- message_id: string
97
- run_id: string | null
98
- tool_name: string
95
+ threadId: string
96
+ messageId: string
97
+ runId: string | null
98
+ toolName: string
99
99
  args: string
100
100
  result: string | null
101
- approval_status: 'approved' | 'denied' | 'pending' | null
102
- approval_type: 'agent-call' | 'tool-call' | null
103
- agent_run_id: string | null
104
- display_tool_name: string | null
105
- display_args: string | null
106
- created_at: Generated<Date>
101
+ approvalStatus: 'approved' | 'denied' | 'pending' | null
102
+ approvalType: 'agent-call' | 'tool-call' | null
103
+ agentRunId: string | null
104
+ displayToolName: string | null
105
+ displayArgs: string | null
106
+ createdAt: Generated<Date>
107
107
  }
108
108
 
109
109
  export interface AIWorkingMemoryTable {
110
110
  id: string
111
111
  scope: string
112
112
  data: string
113
- updated_at: Generated<Date>
113
+ updatedAt: Generated<Date>
114
114
  }
115
115
 
116
116
  export interface AIRunTable {
117
- run_id: Generated<string>
118
- agent_name: string
119
- thread_id: string
120
- resource_id: string
117
+ runId: Generated<string>
118
+ agentName: string
119
+ threadId: string
120
+ resourceId: string
121
121
  status: Generated<'running' | 'suspended' | 'completed' | 'failed'>
122
- error_message: string | null
123
- suspend_reason: 'approval' | 'rpc-missing' | null
124
- missing_rpcs: string | null
125
- usage_input_tokens: Generated<number>
126
- usage_output_tokens: Generated<number>
127
- usage_model: Generated<string>
128
- created_at: Generated<Date>
129
- updated_at: Generated<Date>
122
+ errorMessage: string | null
123
+ suspendReason: 'approval' | 'rpc-missing' | null
124
+ missingRpcs: string | null
125
+ usageInputTokens: Generated<number>
126
+ usageOutputTokens: Generated<number>
127
+ usageModel: Generated<string>
128
+ createdAt: Generated<Date>
129
+ updatedAt: Generated<Date>
130
130
  }
131
131
 
132
132
  export interface PikkuDeploymentsTable {
133
- deployment_id: string
133
+ deploymentId: string
134
134
  endpoint: string
135
- last_heartbeat: Generated<Date>
136
- created_at: Generated<Date>
135
+ lastHeartbeat: Generated<Date>
136
+ createdAt: Generated<Date>
137
137
  }
138
138
 
139
139
  export interface PikkuDeploymentFunctionsTable {
140
- deployment_id: string
141
- function_name: string
140
+ deploymentId: string
141
+ functionName: string
142
142
  }
143
143
 
144
144
  export interface SecretsTable {
145
145
  key: string
146
146
  ciphertext: string
147
- wrapped_dek: string
148
- key_version: number
149
- created_at: Generated<Date>
150
- updated_at: Generated<Date>
147
+ wrappedDek: string
148
+ keyVersion: number
149
+ createdAt: Generated<Date>
150
+ updatedAt: Generated<Date>
151
151
  }
152
152
 
153
153
  export interface SecretsAuditTable {
154
154
  id: string
155
- secret_key: string
155
+ secretKey: string
156
156
  action: string
157
- performed_at: Generated<Date>
157
+ performedAt: Generated<Date>
158
158
  }
159
159
 
160
160
  export interface CredentialsTable {
161
161
  name: string
162
- user_id: string | null
162
+ userId: string | null
163
163
  ciphertext: string
164
- wrapped_dek: string
165
- key_version: number
166
- created_at: Generated<Date>
167
- updated_at: Generated<Date>
164
+ wrappedDek: string
165
+ keyVersion: number
166
+ createdAt: Generated<Date>
167
+ updatedAt: Generated<Date>
168
168
  }
169
169
 
170
170
  export interface CredentialsAuditTable {
171
171
  id: string
172
- credential_name: string
173
- user_id: string | null
172
+ credentialName: string
173
+ userId: string | null
174
174
  action: string
175
- performed_at: Generated<Date>
175
+ performedAt: Generated<Date>
176
176
  }
177
177
 
178
178
  export interface KyselyPikkuDB {
179
179
  channels: ChannelsTable
180
- channel_subscriptions: ChannelSubscriptionsTable
181
- workflow_runs: WorkflowRunsTable
182
- workflow_step: WorkflowStepTable
183
- workflow_step_history: WorkflowStepHistoryTable
184
- workflow_versions: WorkflowVersionsTable
185
- ai_threads: AIThreadsTable
186
- ai_message: AIMessageTable
187
- ai_tool_call: AIToolCallTable
188
- ai_working_memory: AIWorkingMemoryTable
189
- ai_run: AIRunTable
190
- pikku_deployments: PikkuDeploymentsTable
191
- pikku_deployment_functions: PikkuDeploymentFunctionsTable
180
+ channelSubscriptions: ChannelSubscriptionsTable
181
+ workflowRuns: WorkflowRunsTable
182
+ workflowStep: WorkflowStepTable
183
+ workflowStepHistory: WorkflowStepHistoryTable
184
+ workflowVersions: WorkflowVersionsTable
185
+ aiThreads: AIThreadsTable
186
+ aiMessage: AIMessageTable
187
+ aiToolCall: AIToolCallTable
188
+ aiWorkingMemory: AIWorkingMemoryTable
189
+ aiRun: AIRunTable
190
+ pikkuDeployments: PikkuDeploymentsTable
191
+ pikkuDeploymentFunctions: PikkuDeploymentFunctionsTable
192
192
  secrets: SecretsTable
193
- secrets_audit: SecretsAuditTable
193
+ secretsAudit: SecretsAuditTable
194
194
  credentials: CredentialsTable
195
- credentials_audit: CredentialsAuditTable
195
+ credentialsAudit: CredentialsAuditTable
196
196
  }
@@ -20,19 +20,19 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
20
20
  const { workflowName, status, limit = 50, offset = 0 } = options ?? {}
21
21
 
22
22
  let query = this.db
23
- .selectFrom('workflow_runs')
23
+ .selectFrom('workflowRuns')
24
24
  .select([
25
- 'workflow_run_id',
25
+ 'workflowRunId',
26
26
  'workflow',
27
27
  'status',
28
28
  'input',
29
29
  'output',
30
30
  'error',
31
31
  'inline',
32
- 'graph_hash',
32
+ 'graphHash',
33
33
  'wire',
34
- 'created_at',
35
- 'updated_at',
34
+ 'createdAt',
35
+ 'updatedAt',
36
36
  ])
37
37
 
38
38
  if (workflowName) {
@@ -44,7 +44,7 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
44
44
  }
45
45
 
46
46
  const result = await query
47
- .orderBy('created_at', 'desc')
47
+ .orderBy('createdAt', 'desc')
48
48
  .limit(limit)
49
49
  .offset(offset)
50
50
  .execute()
@@ -54,21 +54,21 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
54
54
 
55
55
  async getRun(id: string): Promise<WorkflowRun | null> {
56
56
  const row = await this.db
57
- .selectFrom('workflow_runs')
57
+ .selectFrom('workflowRuns')
58
58
  .select([
59
- 'workflow_run_id',
59
+ 'workflowRunId',
60
60
  'workflow',
61
61
  'status',
62
62
  'input',
63
63
  'output',
64
64
  'error',
65
65
  'inline',
66
- 'graph_hash',
66
+ 'graphHash',
67
67
  'wire',
68
- 'created_at',
69
- 'updated_at',
68
+ 'createdAt',
69
+ 'updatedAt',
70
70
  ])
71
- .where('workflow_run_id', '=', id)
71
+ .where('workflowRunId', '=', id)
72
72
  .executeTakeFirst()
73
73
 
74
74
  if (!row) return null
@@ -81,50 +81,50 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
81
81
  Array<StepState & { stepName: string; rpcName?: string; data?: any }>
82
82
  > {
83
83
  const result = await this.db
84
- .selectFrom('workflow_step as s')
84
+ .selectFrom('workflowStep as s')
85
85
  .select([
86
- 's.workflow_step_id',
87
- 's.step_name',
88
- 's.rpc_name',
86
+ 's.workflowStepId',
87
+ 's.stepName',
88
+ 's.rpcName',
89
89
  's.data',
90
90
  's.status',
91
91
  's.result',
92
92
  's.error',
93
- 's.child_run_id',
93
+ 's.childRunId',
94
94
  's.retries',
95
- 's.retry_delay',
96
- 's.created_at',
97
- 's.updated_at',
95
+ 's.retryDelay',
96
+ 's.createdAt',
97
+ 's.updatedAt',
98
98
  ])
99
99
  .select((eb) =>
100
100
  eb
101
- .selectFrom('workflow_step_history')
101
+ .selectFrom('workflowStepHistory')
102
102
  .select(eb.fn.countAll<number>().as('cnt'))
103
103
  .whereRef(
104
- 'workflow_step_history.workflow_step_id',
104
+ 'workflowStepHistory.workflowStepId',
105
105
  '=',
106
- 's.workflow_step_id'
106
+ 's.workflowStepId'
107
107
  )
108
- .as('attempt_count')
108
+ .as('attemptCount')
109
109
  )
110
- .where('s.workflow_run_id', '=', runId)
111
- .orderBy('s.created_at', 'asc')
110
+ .where('s.workflowRunId', '=', runId)
111
+ .orderBy('s.createdAt', 'asc')
112
112
  .execute()
113
113
 
114
114
  return result.map((row) => ({
115
- stepId: row.workflow_step_id,
116
- stepName: row.step_name,
117
- rpcName: row.rpc_name ?? undefined,
115
+ stepId: row.workflowStepId,
116
+ stepName: row.stepName,
117
+ rpcName: row.rpcName ?? undefined,
118
118
  data: parseJson(row.data),
119
119
  status: row.status as StepState['status'],
120
120
  result: parseJson(row.result),
121
121
  error: parseJson(row.error),
122
- childRunId: row.child_run_id ?? undefined,
123
- attemptCount: Number(row.attempt_count || 1),
122
+ childRunId: row.childRunId ?? undefined,
123
+ attemptCount: Number(row.attemptCount || 1),
124
124
  retries: row.retries != null ? Number(row.retries) : undefined,
125
- retryDelay: row.retry_delay ?? undefined,
126
- createdAt: new Date(row.created_at as unknown as string),
127
- updatedAt: new Date(row.updated_at as unknown as string),
125
+ retryDelay: row.retryDelay ?? undefined,
126
+ createdAt: new Date(row.createdAt as unknown as string),
127
+ updatedAt: new Date(row.updatedAt as unknown as string),
128
128
  }))
129
129
  }
130
130
 
@@ -132,57 +132,57 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
132
132
  runId: string
133
133
  ): Promise<Array<StepState & { stepName: string }>> {
134
134
  const result = await this.db
135
- .selectFrom('workflow_step as s')
135
+ .selectFrom('workflowStep as s')
136
136
  .innerJoin(
137
- 'workflow_step_history as h',
138
- 'h.workflow_step_id',
139
- 's.workflow_step_id'
137
+ 'workflowStepHistory as h',
138
+ 'h.workflowStepId',
139
+ 's.workflowStepId'
140
140
  )
141
141
  .select([
142
- 's.workflow_step_id',
143
- 's.step_name',
142
+ 's.workflowStepId',
143
+ 's.stepName',
144
144
  's.retries',
145
- 's.retry_delay',
145
+ 's.retryDelay',
146
146
  'h.status',
147
147
  'h.result',
148
148
  'h.error',
149
- 'h.created_at',
150
- 'h.running_at',
151
- 'h.scheduled_at',
152
- 'h.succeeded_at',
153
- 'h.failed_at',
149
+ 'h.createdAt',
150
+ 'h.runningAt',
151
+ 'h.scheduledAt',
152
+ 'h.succeededAt',
153
+ 'h.failedAt',
154
154
  ])
155
- .where('s.workflow_run_id', '=', runId)
156
- .orderBy('h.created_at', 'asc')
155
+ .where('s.workflowRunId', '=', runId)
156
+ .orderBy('h.createdAt', 'asc')
157
157
  .execute()
158
158
 
159
159
  let attemptCounters: Record<string, number> = {}
160
160
  return result.map((row) => {
161
- const stepId = row.workflow_step_id
161
+ const stepId = row.workflowStepId
162
162
  attemptCounters[stepId] = (attemptCounters[stepId] ?? 0) + 1
163
163
 
164
164
  return {
165
165
  stepId,
166
- stepName: row.step_name,
166
+ stepName: row.stepName,
167
167
  status: row.status as StepState['status'],
168
168
  result: parseJson(row.result),
169
169
  error: parseJson(row.error),
170
170
  attemptCount: attemptCounters[stepId]!,
171
171
  retries: row.retries != null ? Number(row.retries) : undefined,
172
- retryDelay: row.retry_delay ?? undefined,
173
- createdAt: new Date(row.created_at as unknown as string),
174
- updatedAt: new Date(row.created_at as unknown as string),
175
- runningAt: row.running_at
176
- ? new Date(row.running_at as unknown as string)
172
+ retryDelay: row.retryDelay ?? undefined,
173
+ createdAt: new Date(row.createdAt as unknown as string),
174
+ updatedAt: new Date(row.createdAt as unknown as string),
175
+ runningAt: row.runningAt
176
+ ? new Date(row.runningAt as unknown as string)
177
177
  : undefined,
178
- scheduledAt: row.scheduled_at
179
- ? new Date(row.scheduled_at as unknown as string)
178
+ scheduledAt: row.scheduledAt
179
+ ? new Date(row.scheduledAt as unknown as string)
180
180
  : undefined,
181
- succeededAt: row.succeeded_at
182
- ? new Date(row.succeeded_at as unknown as string)
181
+ succeededAt: row.succeededAt
182
+ ? new Date(row.succeededAt as unknown as string)
183
183
  : undefined,
184
- failedAt: row.failed_at
185
- ? new Date(row.failed_at as unknown as string)
184
+ failedAt: row.failedAt
185
+ ? new Date(row.failedAt as unknown as string)
186
186
  : undefined,
187
187
  }
188
188
  })
@@ -190,7 +190,7 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
190
190
 
191
191
  async getDistinctWorkflowNames(): Promise<string[]> {
192
192
  const result = await this.db
193
- .selectFrom('workflow_runs')
193
+ .selectFrom('workflowRuns')
194
194
  .select('workflow')
195
195
  .distinct()
196
196
  .orderBy('workflow')
@@ -204,10 +204,10 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
204
204
  graphHash: string
205
205
  ): Promise<{ graph: any; source: string } | null> {
206
206
  const row = await this.db
207
- .selectFrom('workflow_versions')
207
+ .selectFrom('workflowVersions')
208
208
  .select(['graph', 'source'])
209
- .where('workflow_name', '=', name)
210
- .where('graph_hash', '=', graphHash)
209
+ .where('workflowName', '=', name)
210
+ .where('graphHash', '=', graphHash)
211
211
  .executeTakeFirst()
212
212
 
213
213
  if (!row) return null
@@ -221,25 +221,25 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
221
221
  agentName?: string
222
222
  ): Promise<Array<{ workflowName: string; graphHash: string; graph: any }>> {
223
223
  let query = this.db
224
- .selectFrom('workflow_versions')
225
- .select(['workflow_name', 'graph_hash', 'graph'])
224
+ .selectFrom('workflowVersions')
225
+ .select(['workflowName', 'graphHash', 'graph'])
226
226
  .where('source', '=', 'ai-agent')
227
227
  .where('status', '=', 'active')
228
228
  if (agentName) {
229
- query = query.where('workflow_name', 'like', `ai:${agentName}:%`)
229
+ query = query.where('workflowName', 'like', `ai:${agentName}:%`)
230
230
  }
231
231
  const rows = await query.execute()
232
232
  return rows.map((row) => ({
233
- workflowName: row.workflow_name,
234
- graphHash: row.graph_hash,
233
+ workflowName: row.workflowName,
234
+ graphHash: row.graphHash,
235
235
  graph: parseJson(row.graph),
236
236
  }))
237
237
  }
238
238
 
239
239
  async deleteRun(id: string): Promise<boolean> {
240
240
  const result = await this.db
241
- .deleteFrom('workflow_runs')
242
- .where('workflow_run_id', '=', id)
241
+ .deleteFrom('workflowRuns')
242
+ .where('workflowRunId', '=', id)
243
243
  .executeTakeFirst()
244
244
 
245
245
  return BigInt(result.numDeletedRows) > 0n
@@ -247,17 +247,17 @@ export class KyselyWorkflowRunService implements WorkflowRunService {
247
247
 
248
248
  private mapRunRow(row: any): WorkflowRun {
249
249
  return {
250
- id: row.workflow_run_id as string,
250
+ id: row.workflowRunId as string,
251
251
  workflow: row.workflow as string,
252
252
  status: row.status as WorkflowStatus,
253
253
  input: parseJson(row.input),
254
254
  output: parseJson(row.output),
255
255
  error: parseJson(row.error),
256
256
  inline: row.inline as boolean | undefined,
257
- graphHash: row.graph_hash as string | undefined,
257
+ graphHash: row.graphHash as string | undefined,
258
258
  wire: parseJson(row.wire) ?? { type: 'unknown' },
259
- createdAt: new Date(row.created_at as string),
260
- updatedAt: new Date(row.updated_at as string),
259
+ createdAt: new Date(row.createdAt as string),
260
+ updatedAt: new Date(row.updatedAt as string),
261
261
  }
262
262
  }
263
263
  }