@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.
- package/CHANGELOG.md +24 -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 +2 -0
- package/dist/src/kysely-credential-service.js +47 -29
- 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 +91 -91
- package/dist/src/kysely-workflow-run-service.js +73 -73
- package/dist/src/kysely-workflow-service.js +127 -127
- package/package.json +2 -2
- 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 +51 -29
- 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 +19 -18
- package/src/kysely-tables.ts +91 -91
- package/src/kysely-workflow-run-service.ts +76 -76
- package/src/kysely-workflow-service.ts +129 -129
|
@@ -143,14 +143,14 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
143
143
|
): Promise<string> {
|
|
144
144
|
const id = crypto.randomUUID()
|
|
145
145
|
await this.db
|
|
146
|
-
.insertInto('
|
|
146
|
+
.insertInto('workflowRuns')
|
|
147
147
|
.values({
|
|
148
|
-
|
|
148
|
+
workflowRunId: id,
|
|
149
149
|
workflow: workflowName,
|
|
150
150
|
status: 'running',
|
|
151
151
|
input: JSON.stringify(input),
|
|
152
152
|
inline,
|
|
153
|
-
|
|
153
|
+
graphHash: graphHash,
|
|
154
154
|
wire: JSON.stringify(wire),
|
|
155
155
|
})
|
|
156
156
|
.execute()
|
|
@@ -169,14 +169,14 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
169
169
|
error?: SerializedError
|
|
170
170
|
): Promise<void> {
|
|
171
171
|
await this.db
|
|
172
|
-
.updateTable('
|
|
172
|
+
.updateTable('workflowRuns')
|
|
173
173
|
.set({
|
|
174
174
|
status,
|
|
175
175
|
output: output ? JSON.stringify(output) : null,
|
|
176
176
|
error: error ? JSON.stringify(error) : null,
|
|
177
|
-
|
|
177
|
+
updatedAt: new Date(),
|
|
178
178
|
})
|
|
179
|
-
.where('
|
|
179
|
+
.where('workflowRunId', '=', id)
|
|
180
180
|
.execute()
|
|
181
181
|
}
|
|
182
182
|
|
|
@@ -191,18 +191,18 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
191
191
|
const now = new Date()
|
|
192
192
|
|
|
193
193
|
await this.db
|
|
194
|
-
.insertInto('
|
|
194
|
+
.insertInto('workflowStep')
|
|
195
195
|
.values({
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
workflowStepId: stepId,
|
|
197
|
+
workflowRunId: runId,
|
|
198
|
+
stepName: stepName,
|
|
199
|
+
rpcName: rpcName,
|
|
200
200
|
data: data != null ? JSON.stringify(data) : null,
|
|
201
201
|
status: 'pending',
|
|
202
202
|
retries: stepOptions?.retries ?? null,
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
retryDelay: stepOptions?.retryDelay?.toString() ?? null,
|
|
204
|
+
createdAt: now,
|
|
205
|
+
updatedAt: now,
|
|
206
206
|
})
|
|
207
207
|
.execute()
|
|
208
208
|
|
|
@@ -223,30 +223,30 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
223
223
|
|
|
224
224
|
async getStepState(runId: string, stepName: string): Promise<StepState> {
|
|
225
225
|
const row = await this.db
|
|
226
|
-
.selectFrom('
|
|
226
|
+
.selectFrom('workflowStep as s')
|
|
227
227
|
.select([
|
|
228
|
-
's.
|
|
228
|
+
's.workflowStepId',
|
|
229
229
|
's.status',
|
|
230
230
|
's.result',
|
|
231
231
|
's.error',
|
|
232
232
|
's.retries',
|
|
233
|
-
's.
|
|
234
|
-
's.
|
|
235
|
-
's.
|
|
233
|
+
's.retryDelay',
|
|
234
|
+
's.createdAt',
|
|
235
|
+
's.updatedAt',
|
|
236
236
|
])
|
|
237
237
|
.select((eb) =>
|
|
238
238
|
eb
|
|
239
|
-
.selectFrom('
|
|
239
|
+
.selectFrom('workflowStepHistory')
|
|
240
240
|
.select(eb.fn.countAll<number>().as('cnt'))
|
|
241
241
|
.whereRef(
|
|
242
|
-
'
|
|
242
|
+
'workflowStepHistory.workflowStepId',
|
|
243
243
|
'=',
|
|
244
|
-
's.
|
|
244
|
+
's.workflowStepId'
|
|
245
245
|
)
|
|
246
|
-
.as('
|
|
246
|
+
.as('attemptCount')
|
|
247
247
|
)
|
|
248
|
-
.where('s.
|
|
249
|
-
.where('s.
|
|
248
|
+
.where('s.workflowRunId', '=', runId)
|
|
249
|
+
.where('s.stepName', '=', stepName)
|
|
250
250
|
.executeTakeFirst()
|
|
251
251
|
|
|
252
252
|
if (!row) {
|
|
@@ -256,15 +256,15 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
return {
|
|
259
|
-
stepId: row.
|
|
259
|
+
stepId: row.workflowStepId,
|
|
260
260
|
status: row.status as StepState['status'],
|
|
261
261
|
result: parseJson(row.result),
|
|
262
262
|
error: parseJson(row.error),
|
|
263
|
-
attemptCount: Number(row.
|
|
263
|
+
attemptCount: Number(row.attemptCount),
|
|
264
264
|
retries: row.retries != null ? Number(row.retries) : undefined,
|
|
265
|
-
retryDelay: row.
|
|
266
|
-
createdAt: new Date(row.
|
|
267
|
-
updatedAt: new Date(row.
|
|
265
|
+
retryDelay: row.retryDelay ?? undefined,
|
|
266
|
+
createdAt: new Date(row.createdAt),
|
|
267
|
+
updatedAt: new Date(row.updatedAt),
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
|
|
@@ -276,33 +276,33 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
276
276
|
|
|
277
277
|
async setStepRunning(stepId: string): Promise<void> {
|
|
278
278
|
await this.db
|
|
279
|
-
.updateTable('
|
|
280
|
-
.set({ status: 'running',
|
|
281
|
-
.where('
|
|
279
|
+
.updateTable('workflowStep')
|
|
280
|
+
.set({ status: 'running', updatedAt: new Date() })
|
|
281
|
+
.where('workflowStepId', '=', stepId)
|
|
282
282
|
.execute()
|
|
283
283
|
|
|
284
284
|
const latestHistory = await this.db
|
|
285
|
-
.selectFrom('
|
|
286
|
-
.select('
|
|
287
|
-
.where('
|
|
288
|
-
.orderBy('
|
|
285
|
+
.selectFrom('workflowStepHistory')
|
|
286
|
+
.select('historyId')
|
|
287
|
+
.where('workflowStepId', '=', stepId)
|
|
288
|
+
.orderBy('createdAt', 'desc')
|
|
289
289
|
.limit(1)
|
|
290
290
|
.executeTakeFirst()
|
|
291
291
|
|
|
292
292
|
if (latestHistory) {
|
|
293
293
|
await this.db
|
|
294
|
-
.updateTable('
|
|
294
|
+
.updateTable('workflowStepHistory')
|
|
295
295
|
.set({ status: 'running' })
|
|
296
|
-
.where('
|
|
296
|
+
.where('historyId', '=', latestHistory.historyId)
|
|
297
297
|
.execute()
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
async setStepScheduled(stepId: string): Promise<void> {
|
|
302
302
|
await this.db
|
|
303
|
-
.updateTable('
|
|
304
|
-
.set({ status: 'scheduled',
|
|
305
|
-
.where('
|
|
303
|
+
.updateTable('workflowStep')
|
|
304
|
+
.set({ status: 'scheduled', updatedAt: new Date() })
|
|
305
|
+
.where('workflowStepId', '=', stepId)
|
|
306
306
|
.execute()
|
|
307
307
|
}
|
|
308
308
|
|
|
@@ -314,21 +314,21 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
314
314
|
): Promise<void> {
|
|
315
315
|
const now = new Date()
|
|
316
316
|
const values: Record<string, any> = {
|
|
317
|
-
|
|
318
|
-
|
|
317
|
+
historyId: crypto.randomUUID(),
|
|
318
|
+
workflowStepId: stepId,
|
|
319
319
|
status,
|
|
320
320
|
result: result != null ? JSON.stringify(result) : null,
|
|
321
321
|
error: error != null ? JSON.stringify(error) : null,
|
|
322
|
-
|
|
322
|
+
createdAt: now,
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
const timestampField = this.getTimestampFieldForStatus(status)
|
|
326
|
-
if (timestampField !== '
|
|
326
|
+
if (timestampField !== 'createdAt') {
|
|
327
327
|
values[timestampField] = now
|
|
328
328
|
}
|
|
329
329
|
|
|
330
330
|
await this.db
|
|
331
|
-
.insertInto('
|
|
331
|
+
.insertInto('workflowStepHistory')
|
|
332
332
|
.values(values as any)
|
|
333
333
|
.execute()
|
|
334
334
|
}
|
|
@@ -336,26 +336,26 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
336
336
|
private getTimestampFieldForStatus(status: string): string {
|
|
337
337
|
switch (status) {
|
|
338
338
|
case 'running':
|
|
339
|
-
return '
|
|
339
|
+
return 'runningAt'
|
|
340
340
|
case 'scheduled':
|
|
341
|
-
return '
|
|
341
|
+
return 'scheduledAt'
|
|
342
342
|
case 'succeeded':
|
|
343
|
-
return '
|
|
343
|
+
return 'succeededAt'
|
|
344
344
|
case 'failed':
|
|
345
|
-
return '
|
|
345
|
+
return 'failedAt'
|
|
346
346
|
default:
|
|
347
|
-
return '
|
|
347
|
+
return 'createdAt'
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
async setStepChildRunId(stepId: string, childRunId: string): Promise<void> {
|
|
352
352
|
await this.db
|
|
353
|
-
.updateTable('
|
|
353
|
+
.updateTable('workflowStep')
|
|
354
354
|
.set({
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
childRunId: childRunId,
|
|
356
|
+
updatedAt: new Date(),
|
|
357
357
|
})
|
|
358
|
-
.where('
|
|
358
|
+
.where('workflowStepId', '=', stepId)
|
|
359
359
|
.execute()
|
|
360
360
|
}
|
|
361
361
|
|
|
@@ -363,29 +363,29 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
363
363
|
const resultJson = JSON.stringify(result)
|
|
364
364
|
|
|
365
365
|
await this.db
|
|
366
|
-
.updateTable('
|
|
366
|
+
.updateTable('workflowStep')
|
|
367
367
|
.set({
|
|
368
368
|
status: 'succeeded',
|
|
369
369
|
result: resultJson,
|
|
370
370
|
error: null,
|
|
371
|
-
|
|
371
|
+
updatedAt: new Date(),
|
|
372
372
|
})
|
|
373
|
-
.where('
|
|
373
|
+
.where('workflowStepId', '=', stepId)
|
|
374
374
|
.execute()
|
|
375
375
|
|
|
376
376
|
const latestHistory = await this.db
|
|
377
|
-
.selectFrom('
|
|
378
|
-
.select('
|
|
379
|
-
.where('
|
|
380
|
-
.orderBy('
|
|
377
|
+
.selectFrom('workflowStepHistory')
|
|
378
|
+
.select('historyId')
|
|
379
|
+
.where('workflowStepId', '=', stepId)
|
|
380
|
+
.orderBy('createdAt', 'desc')
|
|
381
381
|
.limit(1)
|
|
382
382
|
.executeTakeFirst()
|
|
383
383
|
|
|
384
384
|
if (latestHistory) {
|
|
385
385
|
await this.db
|
|
386
|
-
.updateTable('
|
|
386
|
+
.updateTable('workflowStepHistory')
|
|
387
387
|
.set({ status: 'succeeded', result: resultJson })
|
|
388
|
-
.where('
|
|
388
|
+
.where('historyId', '=', latestHistory.historyId)
|
|
389
389
|
.execute()
|
|
390
390
|
}
|
|
391
391
|
}
|
|
@@ -399,29 +399,29 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
399
399
|
const errorJson = JSON.stringify(serializedError)
|
|
400
400
|
|
|
401
401
|
await this.db
|
|
402
|
-
.updateTable('
|
|
402
|
+
.updateTable('workflowStep')
|
|
403
403
|
.set({
|
|
404
404
|
status: 'failed',
|
|
405
405
|
error: errorJson,
|
|
406
406
|
result: null,
|
|
407
|
-
|
|
407
|
+
updatedAt: new Date(),
|
|
408
408
|
})
|
|
409
|
-
.where('
|
|
409
|
+
.where('workflowStepId', '=', stepId)
|
|
410
410
|
.execute()
|
|
411
411
|
|
|
412
412
|
const latestHistory = await this.db
|
|
413
|
-
.selectFrom('
|
|
414
|
-
.select('
|
|
415
|
-
.where('
|
|
416
|
-
.orderBy('
|
|
413
|
+
.selectFrom('workflowStepHistory')
|
|
414
|
+
.select('historyId')
|
|
415
|
+
.where('workflowStepId', '=', stepId)
|
|
416
|
+
.orderBy('createdAt', 'desc')
|
|
417
417
|
.limit(1)
|
|
418
418
|
.executeTakeFirst()
|
|
419
419
|
|
|
420
420
|
if (latestHistory) {
|
|
421
421
|
await this.db
|
|
422
|
-
.updateTable('
|
|
422
|
+
.updateTable('workflowStepHistory')
|
|
423
423
|
.set({ status: 'failed', error: errorJson })
|
|
424
|
-
.where('
|
|
424
|
+
.where('historyId', '=', latestHistory.historyId)
|
|
425
425
|
.execute()
|
|
426
426
|
}
|
|
427
427
|
}
|
|
@@ -431,49 +431,49 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
431
431
|
status: 'pending' | 'running'
|
|
432
432
|
): Promise<StepState> {
|
|
433
433
|
await this.db
|
|
434
|
-
.updateTable('
|
|
435
|
-
.set({ status, result: null, error: null,
|
|
436
|
-
.where('
|
|
434
|
+
.updateTable('workflowStep')
|
|
435
|
+
.set({ status, result: null, error: null, updatedAt: new Date() })
|
|
436
|
+
.where('workflowStepId', '=', stepId)
|
|
437
437
|
.execute()
|
|
438
438
|
|
|
439
439
|
await this.insertHistoryRecord(stepId, status)
|
|
440
440
|
|
|
441
441
|
const row = await this.db
|
|
442
|
-
.selectFrom('
|
|
442
|
+
.selectFrom('workflowStep as s')
|
|
443
443
|
.select([
|
|
444
|
-
's.
|
|
444
|
+
's.workflowStepId',
|
|
445
445
|
's.status',
|
|
446
446
|
's.result',
|
|
447
447
|
's.error',
|
|
448
448
|
's.retries',
|
|
449
|
-
's.
|
|
450
|
-
's.
|
|
451
|
-
's.
|
|
449
|
+
's.retryDelay',
|
|
450
|
+
's.createdAt',
|
|
451
|
+
's.updatedAt',
|
|
452
452
|
])
|
|
453
453
|
.select((eb) =>
|
|
454
454
|
eb
|
|
455
|
-
.selectFrom('
|
|
455
|
+
.selectFrom('workflowStepHistory')
|
|
456
456
|
.select(eb.fn.countAll<number>().as('cnt'))
|
|
457
457
|
.whereRef(
|
|
458
|
-
'
|
|
458
|
+
'workflowStepHistory.workflowStepId',
|
|
459
459
|
'=',
|
|
460
|
-
's.
|
|
460
|
+
's.workflowStepId'
|
|
461
461
|
)
|
|
462
|
-
.as('
|
|
462
|
+
.as('attemptCount')
|
|
463
463
|
)
|
|
464
|
-
.where('s.
|
|
464
|
+
.where('s.workflowStepId', '=', stepId)
|
|
465
465
|
.executeTakeFirstOrThrow()
|
|
466
466
|
|
|
467
467
|
return {
|
|
468
|
-
stepId: row.
|
|
468
|
+
stepId: row.workflowStepId,
|
|
469
469
|
status: row.status as StepState['status'],
|
|
470
470
|
result: parseJson(row.result),
|
|
471
471
|
error: parseJson(row.error),
|
|
472
|
-
attemptCount: Number(row.
|
|
472
|
+
attemptCount: Number(row.attemptCount),
|
|
473
473
|
retries: row.retries != null ? Number(row.retries) : undefined,
|
|
474
|
-
retryDelay: row.
|
|
475
|
-
createdAt: new Date(row.
|
|
476
|
-
updatedAt: new Date(row.
|
|
474
|
+
retryDelay: row.retryDelay ?? undefined,
|
|
475
|
+
createdAt: new Date(row.createdAt),
|
|
476
|
+
updatedAt: new Date(row.updatedAt),
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
479
|
|
|
@@ -495,16 +495,16 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
495
495
|
branchKeys: Record<string, string>
|
|
496
496
|
}> {
|
|
497
497
|
const results = await this.db
|
|
498
|
-
.selectFrom('
|
|
499
|
-
.select(['ws.
|
|
498
|
+
.selectFrom('workflowStep as ws')
|
|
499
|
+
.select(['ws.stepName', 'ws.status', 'ws.branchTaken', 'ws.retries'])
|
|
500
500
|
.select((eb) =>
|
|
501
501
|
eb
|
|
502
|
-
.selectFrom('
|
|
502
|
+
.selectFrom('workflowStepHistory as h')
|
|
503
503
|
.select(eb.fn.countAll<number>().as('cnt'))
|
|
504
|
-
.whereRef('h.
|
|
505
|
-
.as('
|
|
504
|
+
.whereRef('h.workflowStepId', '=', 'ws.workflowStepId')
|
|
505
|
+
.as('attemptCount')
|
|
506
506
|
)
|
|
507
|
-
.where('ws.
|
|
507
|
+
.where('ws.workflowRunId', '=', runId)
|
|
508
508
|
.where('ws.status', 'in', ['succeeded', 'failed'])
|
|
509
509
|
.execute()
|
|
510
510
|
|
|
@@ -513,16 +513,16 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
513
513
|
const branchKeys: Record<string, string> = {}
|
|
514
514
|
|
|
515
515
|
for (const row of results) {
|
|
516
|
-
const nodeId = row.
|
|
516
|
+
const nodeId = row.stepName
|
|
517
517
|
|
|
518
518
|
if (row.status === 'succeeded') {
|
|
519
519
|
completedNodeIds.push(nodeId)
|
|
520
|
-
if (row.
|
|
521
|
-
branchKeys[nodeId] = row.
|
|
520
|
+
if (row.branchTaken) {
|
|
521
|
+
branchKeys[nodeId] = row.branchTaken
|
|
522
522
|
}
|
|
523
523
|
} else if (row.status === 'failed') {
|
|
524
524
|
const maxAttempts = (row.retries ?? 0) + 1
|
|
525
|
-
if (Number(row.
|
|
525
|
+
if (Number(row.attemptCount) >= maxAttempts) {
|
|
526
526
|
failedNodeIds.push(nodeId)
|
|
527
527
|
}
|
|
528
528
|
}
|
|
@@ -538,13 +538,13 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
538
538
|
if (nodeIds.length === 0) return []
|
|
539
539
|
|
|
540
540
|
const result = await this.db
|
|
541
|
-
.selectFrom('
|
|
542
|
-
.select('
|
|
543
|
-
.where('
|
|
544
|
-
.where('
|
|
541
|
+
.selectFrom('workflowStep')
|
|
542
|
+
.select('stepName')
|
|
543
|
+
.where('workflowRunId', '=', runId)
|
|
544
|
+
.where('stepName', 'in', nodeIds)
|
|
545
545
|
.execute()
|
|
546
546
|
|
|
547
|
-
const existingStepNames = new Set(result.map((r) => r.
|
|
547
|
+
const existingStepNames = new Set(result.map((r) => r.stepName))
|
|
548
548
|
return nodeIds.filter((id) => !existingStepNames.has(id))
|
|
549
549
|
}
|
|
550
550
|
|
|
@@ -555,25 +555,25 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
555
555
|
if (nodeIds.length === 0) return {}
|
|
556
556
|
|
|
557
557
|
const result = await this.db
|
|
558
|
-
.selectFrom('
|
|
559
|
-
.select(['
|
|
560
|
-
.where('
|
|
561
|
-
.where('
|
|
558
|
+
.selectFrom('workflowStep')
|
|
559
|
+
.select(['stepName', 'result'])
|
|
560
|
+
.where('workflowRunId', '=', runId)
|
|
561
|
+
.where('stepName', 'in', nodeIds)
|
|
562
562
|
.where('status', '=', 'succeeded')
|
|
563
563
|
.execute()
|
|
564
564
|
|
|
565
565
|
const results: Record<string, any> = {}
|
|
566
566
|
for (const row of result) {
|
|
567
|
-
results[row.
|
|
567
|
+
results[row.stepName] = parseJson(row.result)
|
|
568
568
|
}
|
|
569
569
|
return results
|
|
570
570
|
}
|
|
571
571
|
|
|
572
572
|
async setBranchTaken(stepId: string, branchKey: string): Promise<void> {
|
|
573
573
|
await this.db
|
|
574
|
-
.updateTable('
|
|
575
|
-
.set({
|
|
576
|
-
.where('
|
|
574
|
+
.updateTable('workflowStep')
|
|
575
|
+
.set({ branchTaken: branchKey, updatedAt: new Date() })
|
|
576
|
+
.where('workflowStepId', '=', stepId)
|
|
577
577
|
.execute()
|
|
578
578
|
}
|
|
579
579
|
|
|
@@ -583,26 +583,26 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
583
583
|
value: unknown
|
|
584
584
|
): Promise<void> {
|
|
585
585
|
const row = await this.db
|
|
586
|
-
.selectFrom('
|
|
586
|
+
.selectFrom('workflowRuns')
|
|
587
587
|
.select('state')
|
|
588
|
-
.where('
|
|
588
|
+
.where('workflowRunId', '=', runId)
|
|
589
589
|
.executeTakeFirst()
|
|
590
590
|
|
|
591
591
|
const state: Record<string, unknown> = parseJson(row?.state) ?? {}
|
|
592
592
|
state[name] = value
|
|
593
593
|
|
|
594
594
|
await this.db
|
|
595
|
-
.updateTable('
|
|
596
|
-
.set({ state: JSON.stringify(state),
|
|
597
|
-
.where('
|
|
595
|
+
.updateTable('workflowRuns')
|
|
596
|
+
.set({ state: JSON.stringify(state), updatedAt: new Date() })
|
|
597
|
+
.where('workflowRunId', '=', runId)
|
|
598
598
|
.execute()
|
|
599
599
|
}
|
|
600
600
|
|
|
601
601
|
async getRunState(runId: string): Promise<Record<string, unknown>> {
|
|
602
602
|
const row = await this.db
|
|
603
|
-
.selectFrom('
|
|
603
|
+
.selectFrom('workflowRuns')
|
|
604
604
|
.select('state')
|
|
605
|
-
.where('
|
|
605
|
+
.where('workflowRunId', '=', runId)
|
|
606
606
|
.executeTakeFirst()
|
|
607
607
|
|
|
608
608
|
if (!row) return {}
|
|
@@ -617,16 +617,16 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
617
617
|
status?: WorkflowVersionStatus
|
|
618
618
|
): Promise<void> {
|
|
619
619
|
await this.db
|
|
620
|
-
.insertInto('
|
|
620
|
+
.insertInto('workflowVersions')
|
|
621
621
|
.values({
|
|
622
|
-
|
|
623
|
-
|
|
622
|
+
workflowName: name,
|
|
623
|
+
graphHash: graphHash,
|
|
624
624
|
graph: JSON.stringify(graph),
|
|
625
625
|
source,
|
|
626
626
|
status: status ?? 'active',
|
|
627
627
|
})
|
|
628
628
|
.onConflict((oc) =>
|
|
629
|
-
oc.columns(['
|
|
629
|
+
oc.columns(['workflowName', 'graphHash']).doNothing()
|
|
630
630
|
)
|
|
631
631
|
.execute()
|
|
632
632
|
}
|
|
@@ -637,10 +637,10 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
637
637
|
status: WorkflowVersionStatus
|
|
638
638
|
): Promise<void> {
|
|
639
639
|
await this.db
|
|
640
|
-
.updateTable('
|
|
640
|
+
.updateTable('workflowVersions')
|
|
641
641
|
.set({ status })
|
|
642
|
-
.where('
|
|
643
|
-
.where('
|
|
642
|
+
.where('workflowName', '=', name)
|
|
643
|
+
.where('graphHash', '=', graphHash)
|
|
644
644
|
.execute()
|
|
645
645
|
}
|
|
646
646
|
|