@pikku/kysely 0.12.6 → 0.12.8

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