@pikku/kysely 0.13.13 → 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.
Files changed (60) hide show
  1. package/CHANGELOG.md +128 -0
  2. package/dist/src/index.d.ts +8 -11
  3. package/dist/src/index.js +5 -6
  4. package/dist/src/kysely-agent-run-scores.d.ts +10 -0
  5. package/dist/src/kysely-agent-run-scores.js +34 -0
  6. package/dist/src/kysely-agent-run-service.d.ts +22 -0
  7. package/dist/src/kysely-agent-run-service.js +190 -0
  8. package/dist/src/kysely-agent-run-state-service.d.ts +24 -0
  9. package/dist/src/kysely-agent-run-state-service.js +169 -0
  10. package/dist/src/kysely-agent-storage-service.d.ts +40 -0
  11. package/dist/src/kysely-agent-storage-service.js +533 -0
  12. package/dist/src/kysely-ai-agent-run-service.d.ts +2 -1
  13. package/dist/src/kysely-ai-run-scores.d.ts +10 -0
  14. package/dist/src/kysely-ai-run-scores.js +34 -0
  15. package/dist/src/kysely-ai-run-state-service.d.ts +6 -2
  16. package/dist/src/kysely-ai-run-state-service.js +7 -0
  17. package/dist/src/kysely-ai-storage-service.d.ts +4 -1
  18. package/dist/src/kysely-ai-storage-service.js +7 -0
  19. package/dist/src/kysely-audit-service.d.ts +3 -1
  20. package/dist/src/kysely-deployment-service.d.ts +1 -1
  21. package/dist/src/kysely-deployment-service.js +2 -2
  22. package/dist/src/kysely-eventhub-store.d.ts +1 -1
  23. package/dist/src/kysely-eventhub-store.js +1 -1
  24. package/dist/src/kysely-scope-service.d.ts +4 -3
  25. package/dist/src/kysely-tables.d.ts +23 -11
  26. package/dist/src/kysely-virtual-user-run-store.d.ts +1 -1
  27. package/dist/src/kysely-webhook-service.d.ts +2 -1
  28. package/dist/src/kysely-webhook-service.js +2 -1
  29. package/dist/src/kysely-workflow-mirror.d.ts +2 -2
  30. package/dist/src/kysely-workflow-run-service.d.ts +1 -1
  31. package/dist/src/kysely-workflow-service.d.ts +3 -2
  32. package/dist/src/kysely-workflow-service.js +1 -1
  33. package/dist/src/schema/agent.schema.d.ts +12 -0
  34. package/dist/src/schema/agent.schema.js +102 -0
  35. package/dist/src/schema/ai.schema.js +13 -0
  36. package/dist/src/schema/index.js +4 -4
  37. package/dist/src/serialize-plugin.d.ts +0 -4
  38. package/dist/src/serialize-plugin.js +0 -4
  39. package/dist/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +2 -2
  41. package/src/index.ts +9 -22
  42. package/src/kysely-agent-run-scores.ts +47 -0
  43. package/src/{kysely-ai-agent-run-service.ts → kysely-agent-run-service.ts} +17 -18
  44. package/src/{kysely-ai-run-state-service.ts → kysely-agent-run-state-service.ts} +27 -12
  45. package/src/{kysely-ai-storage-service.ts → kysely-agent-storage-service.ts} +61 -40
  46. package/src/kysely-audit-service.ts +4 -2
  47. package/src/kysely-deployment-service.ts +3 -3
  48. package/src/kysely-eventhub-store.ts +1 -1
  49. package/src/kysely-scope-service.ts +7 -4
  50. package/src/kysely-services.test.ts +11 -10
  51. package/src/kysely-tables.ts +24 -11
  52. package/src/kysely-virtual-user-run-store.ts +2 -2
  53. package/src/kysely-webhook-service.ts +2 -2
  54. package/src/kysely-workflow-mirror.ts +2 -2
  55. package/src/kysely-workflow-run-service.ts +1 -1
  56. package/src/kysely-workflow-service.ts +3 -12
  57. package/src/schema/{ai.schema.ts → agent.schema.ts} +46 -25
  58. package/src/schema/index.ts +4 -4
  59. package/src/schema/schema.test.ts +6 -6
  60. package/src/serialize-plugin.ts +0 -5
@@ -1,4 +1,5 @@
1
1
  import { parseJson } from './kysely-json.js';
2
+ import { getRunScores, saveRunScore } from './kysely-ai-run-scores.js';
2
3
  import { ensurePikkuSchema } from './schema/index.js';
3
4
  import { aiSchema } from './schema/ai.schema.js';
4
5
  export class KyselyAIStorageService {
@@ -519,5 +520,11 @@ export class KyselyAIStorageService {
519
520
  .executeTakeFirst();
520
521
  return Number(result?.numUpdatedRows ?? 0) > 0;
521
522
  }
523
+ async saveScore(score) {
524
+ await saveRunScore(this.db, score);
525
+ }
526
+ async getScores(runId) {
527
+ return getRunScores(this.db, runId);
528
+ }
522
529
  async close() { }
523
530
  }
@@ -1,4 +1,6 @@
1
- import type { AuditEvent, AuditEventBatch, AuditFacets, AuditQuery, AuditQueryResult, AuditService } from '@pikku/core';
1
+ import type { AuditService } from '@pikku/core';
2
+ import type { AuditEvent, AuditEventBatch } from '@pikku/core/ecosystem/services';
3
+ import type { AuditFacets, AuditQuery, AuditQueryResult } from '@pikku/core/ecosystem/types';
2
4
  import type { Kysely } from 'kysely';
3
5
  /**
4
6
  * Durable {@link AuditService} that persists AuditEvents to an `audit` table
@@ -1,4 +1,4 @@
1
- import type { DeploymentService, DeploymentServiceConfig, DeploymentConfig } from '@pikku/core/services';
1
+ import type { DeploymentService, DeploymentServiceConfig, DeploymentConfig } from '@pikku/core/ecosystem/services';
2
2
  import type { JWTService, SecretService } from '@pikku/core/services';
3
3
  import type { Kysely } from 'kysely';
4
4
  import type { KyselyPikkuDB } from './kysely-tables.js';
@@ -1,5 +1,5 @@
1
- import { buildRemoteHeaders } from '@pikku/core/remote';
2
- import { getAllFunctionNames } from '@pikku/core/function';
1
+ import { buildRemoteHeaders } from '@pikku/core/ecosystem/remote';
2
+ import { getAllFunctionNames } from '@pikku/core/ecosystem/function';
3
3
  import { ensurePikkuSchema } from './schema/index.js';
4
4
  import { deploymentSchema } from './schema/deployment.schema.js';
5
5
  export class KyselyDeploymentService {
@@ -1,4 +1,4 @@
1
- import { EventHubStore } from '@pikku/core/channel';
1
+ import { EventHubStore } from '@pikku/core/ecosystem/channel';
2
2
  import type { Kysely } from 'kysely';
3
3
  import type { KyselyPikkuDB } from './kysely-tables.js';
4
4
  export declare class KyselyEventHubStore extends EventHubStore {
@@ -1,4 +1,4 @@
1
- import { EventHubStore } from '@pikku/core/channel';
1
+ import { EventHubStore } from '@pikku/core/ecosystem/channel';
2
2
  export class KyselyEventHubStore extends EventHubStore {
3
3
  db;
4
4
  initialized = false;
@@ -1,6 +1,7 @@
1
- import type { Role, ScopeService } from '@pikku/core/services';
2
- import type { FlatScope } from '@pikku/core/scope';
3
- import type { SystemRole } from '@pikku/core/role';
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 type { Kysely } from 'kysely';
5
6
  import type { KyselyPikkuDB } from './kysely-tables.js';
6
7
  /**
@@ -1,5 +1,5 @@
1
1
  import type { Generated } from 'kysely';
2
- import type { WorkflowStatus, StepStatus, WorkflowVersionStatus } from '@pikku/core/workflow';
2
+ import type { WorkflowStatus, StepStatus, WorkflowVersionStatus } from '@pikku/core/ecosystem/workflow';
3
3
  export interface ChannelsTable {
4
4
  channelId: string;
5
5
  channelName: string;
@@ -75,7 +75,7 @@ export interface WorkflowVersionsTable {
75
75
  status: Generated<WorkflowVersionStatus>;
76
76
  createdAt: Generated<Date>;
77
77
  }
78
- export interface AIThreadsTable {
78
+ export interface AgentThreadsTable {
79
79
  id: string;
80
80
  resourceId: string;
81
81
  title: string | null;
@@ -83,14 +83,14 @@ export interface AIThreadsTable {
83
83
  createdAt: Generated<Date>;
84
84
  updatedAt: Generated<Date>;
85
85
  }
86
- export interface AIMessageTable {
86
+ export interface AgentMessageTable {
87
87
  id: string;
88
88
  threadId: string;
89
89
  role: 'system' | 'user' | 'assistant' | 'tool';
90
90
  content: string | null;
91
91
  createdAt: Generated<Date>;
92
92
  }
93
- export interface AIToolCallTable {
93
+ export interface AgentToolCallTable {
94
94
  id: string;
95
95
  threadId: string;
96
96
  messageId: string;
@@ -105,13 +105,13 @@ export interface AIToolCallTable {
105
105
  displayArgs: string | null;
106
106
  createdAt: Generated<Date>;
107
107
  }
108
- export interface AIWorkingMemoryTable {
108
+ export interface AgentWorkingMemoryTable {
109
109
  id: string;
110
110
  scope: string;
111
111
  data: string;
112
112
  updatedAt: Generated<Date>;
113
113
  }
114
- export interface AIRunTable {
114
+ export interface AgentRunTable {
115
115
  runId: Generated<string>;
116
116
  agentName: string;
117
117
  threadId: string;
@@ -133,6 +133,17 @@ export interface AIRunTable {
133
133
  createdAt: Generated<Date>;
134
134
  updatedAt: Generated<Date>;
135
135
  }
136
+ export interface AgentRunScoreTable {
137
+ id: string;
138
+ runId: string;
139
+ scorerName: string;
140
+ /** 0..1, so grades are comparable across scorers. */
141
+ score: number;
142
+ reason: string | null;
143
+ /** JSON-serialized structured detail the scorer returned alongside the score. */
144
+ metadata: string | null;
145
+ createdAt: Generated<Date>;
146
+ }
136
147
  export interface PikkuDeploymentsTable {
137
148
  deploymentId: string;
138
149
  endpoint: string;
@@ -290,11 +301,12 @@ export interface KyselyPikkuDB {
290
301
  workflowStep: WorkflowStepTable;
291
302
  workflowStepHistory: WorkflowStepHistoryTable;
292
303
  workflowVersions: WorkflowVersionsTable;
293
- aiThreads: AIThreadsTable;
294
- aiMessage: AIMessageTable;
295
- aiToolCall: AIToolCallTable;
296
- aiWorkingMemory: AIWorkingMemoryTable;
297
- aiRun: AIRunTable;
304
+ agentThreads: AgentThreadsTable;
305
+ agentMessage: AgentMessageTable;
306
+ agentToolCall: AgentToolCallTable;
307
+ agentWorkingMemory: AgentWorkingMemoryTable;
308
+ agentRun: AgentRunTable;
309
+ agentRunScore: AgentRunScoreTable;
298
310
  pikkuDeployments: PikkuDeploymentsTable;
299
311
  pikkuDeploymentFunctions: PikkuDeploymentFunctionsTable;
300
312
  secrets: SecretsTable;
@@ -1,5 +1,5 @@
1
1
  import type { Kysely } from 'kysely';
2
- import type { VirtualUserRunOutcome, VirtualUserRunRecord, VirtualUserRunStart, VirtualUserRunStore } from '@pikku/core/virtual-user';
2
+ import type { VirtualUserRunOutcome, VirtualUserRunRecord, VirtualUserRunStart, VirtualUserRunStore } from '@pikku/core/ecosystem/virtual-user';
3
3
  import type { KyselyPikkuDB } from './kysely-tables.js';
4
4
  /**
5
5
  * Records virtual-user runs in a `virtualUserRun` table.
@@ -1,4 +1,5 @@
1
- import { QueueWebhookService, type SendWebhookInput, type SendWebhookResult, type WebhookAttemptResult, type WebhookDeliveryRecord, type WebhookDeliveryWithAttempts } from '@pikku/core/services';
1
+ import { QueueWebhookService } from '@pikku/core/services';
2
+ import { type SendWebhookInput, type SendWebhookResult, type WebhookAttemptResult, type WebhookDeliveryRecord, type WebhookDeliveryWithAttempts } from '@pikku/core/ecosystem/services';
2
3
  import type { QueueService } from '@pikku/core/queue';
3
4
  import type { Kysely } from 'kysely';
4
5
  import type { KyselyPikkuDB } from './kysely-tables.js';
@@ -1,4 +1,5 @@
1
- import { PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME, QueueWebhookService, } from '@pikku/core/services';
1
+ import { QueueWebhookService } from '@pikku/core/services';
2
+ import { PIKKU_OUTGOING_WEBHOOK_QUEUE_NAME, } from '@pikku/core/ecosystem/services';
2
3
  import { ensurePikkuSchema } from './schema/index.js';
3
4
  import { webhookSchema } from './schema/webhook.schema.js';
4
5
  /**
@@ -1,5 +1,5 @@
1
- import type { SerializedError } from '@pikku/core';
2
- import type { StepState, WorkflowRunMirror, WorkflowRunWire, WorkflowStatus, WorkflowPlannedStep, WorkflowVersionStatus } from '@pikku/core/workflow';
1
+ import type { SerializedError } from '@pikku/core/ecosystem/types';
2
+ import type { StepState, WorkflowRunMirror, WorkflowRunWire, WorkflowStatus, WorkflowPlannedStep, WorkflowVersionStatus } from '@pikku/core/ecosystem/workflow';
3
3
  import type { Kysely } from 'kysely';
4
4
  import type { KyselyPikkuDB } from './kysely-tables.js';
5
5
  /**
@@ -1,4 +1,4 @@
1
- import type { WorkflowRun, StepState, WorkflowRunService } from '@pikku/core/workflow';
1
+ import type { WorkflowRun, StepState, WorkflowRunService } from '@pikku/core/ecosystem/workflow';
2
2
  import type { Kysely } from 'kysely';
3
3
  import type { KyselyPikkuDB } from './kysely-tables.js';
4
4
  export declare class KyselyWorkflowRunService implements WorkflowRunService {
@@ -1,5 +1,6 @@
1
- import type { SerializedError } from '@pikku/core';
2
- import { PikkuWorkflowService, type WorkflowPlannedStep, type WorkflowQueueOptions, type WorkflowRun, type WorkflowRunWire, type StepState, type StepStatus, type WorkflowStatus, type WorkflowVersionStatus } 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';
3
4
  import { type Kysely } from 'kysely';
4
5
  import type { KyselyPikkuDB } from './kysely-tables.js';
5
6
  export declare class KyselyWorkflowService extends PikkuWorkflowService {
@@ -1,4 +1,4 @@
1
- import { PikkuWorkflowService, } from '@pikku/core/workflow';
1
+ import { PikkuWorkflowService } from '@pikku/core/workflow';
2
2
  import { sql } from 'kysely';
3
3
  import { KyselyWorkflowRunService } from './kysely-workflow-run-service.js';
4
4
  import { parseJson } from './kysely-json.js';
@@ -0,0 +1,12 @@
1
+ import type { PikkuSchema } from './pikku-schema.types.js';
2
+ /**
3
+ * Threads, messages, tool calls, working memory and agent runs.
4
+ *
5
+ * `agentRun` carries `pendingApprovals` even though the two services that used to
6
+ * create this table disagreed about it: `KyselyAgentStorageService` omitted the
7
+ * column while `KyselyAgentRunStateService` declared it and read it back through
8
+ * casts. Whichever service happened to run first decided the shape, and on a
9
+ * database where the storage service won, resolving an approval failed. One
10
+ * declaration ends that — the column is here because live code reads it.
11
+ */
12
+ export declare const agentSchema: PikkuSchema;
@@ -0,0 +1,102 @@
1
+ import { sql } from 'kysely';
2
+ /**
3
+ * Threads, messages, tool calls, working memory and agent runs.
4
+ *
5
+ * `agentRun` carries `pendingApprovals` even though the two services that used to
6
+ * create this table disagreed about it: `KyselyAgentStorageService` omitted the
7
+ * column while `KyselyAgentRunStateService` declared it and read it back through
8
+ * casts. Whichever service happened to run first decided the shape, and on a
9
+ * database where the storage service won, resolving an approval failed. One
10
+ * declaration ends that — the column is here because live code reads it.
11
+ */
12
+ export const agentSchema = {
13
+ name: 'agent',
14
+ statements: [
15
+ (db) => db.schema
16
+ .createTable('agentThreads')
17
+ .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
18
+ .addColumn('resourceId', 'varchar(255)', (col) => col.notNull())
19
+ .addColumn('title', 'text')
20
+ .addColumn('metadata', 'text')
21
+ .addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
22
+ .addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
23
+ (db) => db.schema
24
+ .createIndex('idx_agent_threads_resource')
25
+ .on('agentThreads')
26
+ .column('resourceId'),
27
+ (db) => db.schema
28
+ .createTable('agentMessage')
29
+ .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
30
+ .addColumn('threadId', 'varchar(36)', (col) => col.notNull().references('agentThreads.id').onDelete('cascade'))
31
+ .addColumn('role', 'varchar(50)', (col) => col.notNull())
32
+ .addColumn('content', 'text')
33
+ .addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
34
+ (db) => db.schema
35
+ .createIndex('idx_agent_message_thread')
36
+ .on('agentMessage')
37
+ .columns(['threadId', 'createdAt']),
38
+ (db) => db.schema
39
+ .createTable('agentToolCall')
40
+ .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
41
+ .addColumn('threadId', 'varchar(36)', (col) => col.notNull().references('agentThreads.id').onDelete('cascade'))
42
+ .addColumn('messageId', 'varchar(36)', (col) => col.notNull().references('agentMessage.id').onDelete('cascade'))
43
+ .addColumn('runId', 'varchar(36)')
44
+ .addColumn('toolName', 'varchar(255)', (col) => col.notNull())
45
+ .addColumn('args', 'text', (col) => col.notNull())
46
+ .addColumn('result', 'text')
47
+ .addColumn('approvalStatus', 'varchar(50)')
48
+ .addColumn('approvalType', 'varchar(50)')
49
+ .addColumn('agentRunId', 'varchar(36)')
50
+ .addColumn('displayToolName', 'varchar(255)')
51
+ .addColumn('displayArgs', 'text')
52
+ .addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
53
+ (db) => db.schema
54
+ .createIndex('idx_agent_tool_call_thread')
55
+ .on('agentToolCall')
56
+ .column('threadId'),
57
+ (db) => db.schema
58
+ .createIndex('idx_agent_tool_call_message')
59
+ .on('agentToolCall')
60
+ .column('messageId'),
61
+ (db) => db.schema
62
+ .createTable('agentWorkingMemory')
63
+ .addColumn('id', 'varchar(255)', (col) => col.notNull())
64
+ .addColumn('scope', 'varchar(50)', (col) => col.notNull())
65
+ .addColumn('data', 'text', (col) => col.notNull())
66
+ .addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
67
+ .addPrimaryKeyConstraint('agent_working_memory_pk', ['id', 'scope']),
68
+ (db) => db.schema
69
+ .createTable('agentRun')
70
+ .addColumn('runId', 'varchar(36)', (col) => col.primaryKey())
71
+ .addColumn('agentName', 'varchar(255)', (col) => col.notNull())
72
+ .addColumn('threadId', 'varchar(36)', (col) => col.notNull().references('agentThreads.id').onDelete('cascade'))
73
+ .addColumn('resourceId', 'varchar(255)', (col) => col.notNull())
74
+ .addColumn('status', 'varchar(50)', (col) => col.notNull().defaultTo('running'))
75
+ .addColumn('errorMessage', 'text')
76
+ .addColumn('suspendReason', 'text')
77
+ .addColumn('missingRpcs', 'text')
78
+ .addColumn('pendingApprovals', 'text')
79
+ .addColumn('usageInputTokens', 'integer', (col) => col.notNull().defaultTo(0))
80
+ .addColumn('usageOutputTokens', 'integer', (col) => col.notNull().defaultTo(0))
81
+ .addColumn('usageModel', 'varchar(255)', (col) => col.notNull().defaultTo(''))
82
+ .addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
83
+ .addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
84
+ (db) => db.schema
85
+ .createIndex('idx_agent_run_thread')
86
+ .on('agentRun')
87
+ .columns(['threadId', 'createdAt']),
88
+ (db) => db.schema
89
+ .createTable('agentRunScore')
90
+ .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
91
+ .addColumn('runId', 'varchar(36)', (col) => col.notNull().references('agentRun.runId').onDelete('cascade'))
92
+ .addColumn('scorerName', 'varchar(255)', (col) => col.notNull())
93
+ .addColumn('score', 'real', (col) => col.notNull())
94
+ .addColumn('reason', 'text')
95
+ .addColumn('metadata', 'text')
96
+ .addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
97
+ (db) => db.schema
98
+ .createIndex('idx_agent_run_score_run')
99
+ .on('agentRunScore')
100
+ .columns(['runId', 'createdAt']),
101
+ ],
102
+ };
@@ -85,5 +85,18 @@ export const aiSchema = {
85
85
  .createIndex('idx_ai_run_thread')
86
86
  .on('aiRun')
87
87
  .columns(['threadId', 'createdAt']),
88
+ (db) => db.schema
89
+ .createTable('aiRunScore')
90
+ .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
91
+ .addColumn('runId', 'varchar(36)', (col) => col.notNull().references('aiRun.runId').onDelete('cascade'))
92
+ .addColumn('scorerName', 'varchar(255)', (col) => col.notNull())
93
+ .addColumn('score', 'real', (col) => col.notNull())
94
+ .addColumn('reason', 'text')
95
+ .addColumn('metadata', 'text')
96
+ .addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
97
+ (db) => db.schema
98
+ .createIndex('idx_ai_run_score_run')
99
+ .on('aiRunScore')
100
+ .columns(['runId', 'createdAt']),
88
101
  ],
89
102
  };
@@ -1,6 +1,6 @@
1
1
  import { CamelCasePlugin } from 'kysely';
2
2
  import { schemaContext, } from './pikku-schema.types.js';
3
- import { aiSchema } from './ai.schema.js';
3
+ import { agentSchema } from './agent.schema.js';
4
4
  import { channelSchema } from './channel.schema.js';
5
5
  import { credentialSchema } from './credential.schema.js';
6
6
  import { deploymentSchema } from './deployment.schema.js';
@@ -31,7 +31,7 @@ export const pikkuSchemas = [
31
31
  deploymentSchema,
32
32
  webhookSchema,
33
33
  workflowSchema,
34
- aiSchema,
34
+ agentSchema,
35
35
  scopeSchema,
36
36
  ];
37
37
  /**
@@ -39,8 +39,8 @@ export const pikkuSchemas = [
39
39
  *
40
40
  * The plugin is applied here rather than trusted to the caller. Declarations
41
41
  * name tables and columns the way the rest of the codebase queries them
42
- * (`aiThreads.resourceId`), and it is `CamelCasePlugin` that turns those into
43
- * the physical `ai_threads.resource_id`. Without it the same declaration
42
+ * (`agentThreads.resourceId`), and it is `CamelCasePlugin` that turns those into
43
+ * the physical `agent_threads.resource_id`. Without it the same declaration
44
44
  * silently creates quoted camelCase tables that nothing can read.
45
45
  */
46
46
  const bind = (db) => db.withPlugin(new CamelCasePlugin());
@@ -69,7 +69,3 @@ export declare class SerializePlugin extends BaseSerializePlugin {
69
69
  */
70
70
  constructor(options?: SerializePluginOptions);
71
71
  }
72
- /**
73
- * @deprecated use {@link SerializePlugin} instead
74
- */
75
- export declare const SqliteSerializePlugin: typeof SerializePlugin;
@@ -171,7 +171,3 @@ export class SerializePlugin extends BaseSerializePlugin {
171
171
  super(serializer, deserializer, skipNodeKind);
172
172
  }
173
173
  }
174
- /**
175
- * @deprecated use {@link SerializePlugin} instead
176
- */
177
- export const SqliteSerializePlugin = SerializePlugin;
@@ -1 +1 @@
1
- {"root":["../src/create-audited-kysely.ts","../src/index.ts","../src/kysely-ai-agent-run-service.ts","../src/kysely-ai-run-state-service.ts","../src/kysely-ai-storage-service.ts","../src/kysely-audit-service.ts","../src/kysely-channel-store.ts","../src/kysely-credential-service.ts","../src/kysely-deployment-service.ts","../src/kysely-eventhub-store.ts","../src/kysely-json.ts","../src/kysely-scope-service.ts","../src/kysely-secret-service.ts","../src/kysely-session-store.ts","../src/kysely-tables.ts","../src/kysely-virtual-user-run-store.ts","../src/kysely-webhook-service.ts","../src/kysely-workflow-mirror.ts","../src/kysely-workflow-run-service.ts","../src/kysely-workflow-service.ts","../src/serialize-plugin.ts","../src/schema/ai.schema.ts","../src/schema/audit.schema.ts","../src/schema/channel.schema.ts","../src/schema/credential.schema.ts","../src/schema/deployment.schema.ts","../src/schema/index.ts","../src/schema/pikku-schema.types.ts","../src/schema/scope.schema.ts","../src/schema/secret.schema.ts","../src/schema/session.schema.ts","../src/schema/virtual-user.schema.ts","../src/schema/webhook.schema.ts","../src/schema/workflow.schema.ts","../bin/pikku-kysely-pure.ts"],"version":"6.0.3"}
1
+ {"root":["../src/create-audited-kysely.ts","../src/index.ts","../src/kysely-agent-run-scores.ts","../src/kysely-agent-run-service.ts","../src/kysely-agent-run-state-service.ts","../src/kysely-agent-storage-service.ts","../src/kysely-audit-service.ts","../src/kysely-channel-store.ts","../src/kysely-credential-service.ts","../src/kysely-deployment-service.ts","../src/kysely-eventhub-store.ts","../src/kysely-json.ts","../src/kysely-scope-service.ts","../src/kysely-secret-service.ts","../src/kysely-session-store.ts","../src/kysely-tables.ts","../src/kysely-virtual-user-run-store.ts","../src/kysely-webhook-service.ts","../src/kysely-workflow-mirror.ts","../src/kysely-workflow-run-service.ts","../src/kysely-workflow-service.ts","../src/serialize-plugin.ts","../src/schema/agent.schema.ts","../src/schema/audit.schema.ts","../src/schema/channel.schema.ts","../src/schema/credential.schema.ts","../src/schema/deployment.schema.ts","../src/schema/index.ts","../src/schema/pikku-schema.types.ts","../src/schema/scope.schema.ts","../src/schema/secret.schema.ts","../src/schema/session.schema.ts","../src/schema/virtual-user.schema.ts","../src/schema/webhook.schema.ts","../src/schema/workflow.schema.ts","../bin/pikku-kysely-pure.ts"],"version":"6.0.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/kysely",
3
- "version": "0.13.13",
3
+ "version": "0.13.16",
4
4
  "description": "Kysely-backed Pikku services — workflow state, secrets, sessions, scopes and audit",
5
5
  "author": "yasser.fadl@gmail.com",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "prepublishOnly": "yarn build"
22
22
  },
23
23
  "peerDependencies": {
24
- "@pikku/core": "^0.12.80"
24
+ "@pikku/core": "^0.12.84"
25
25
  },
26
26
  "dependencies": {
27
27
  "kysely": "^0.29.0"
package/src/index.ts CHANGED
@@ -4,13 +4,11 @@ export { KyselyWorkflowService } from './kysely-workflow-service.js'
4
4
  export { KyselyWorkflowRunService } from './kysely-workflow-run-service.js'
5
5
  export { KyselyWorkflowMirror } from './kysely-workflow-mirror.js'
6
6
  export { KyselyDeploymentService } from './kysely-deployment-service.js'
7
- export { KyselyAIStorageService } from './kysely-ai-storage-service.js'
8
- export { KyselyAgentRunService } from './kysely-ai-agent-run-service.js'
9
- export { KyselyAIRunStateService } from './kysely-ai-run-state-service.js'
7
+ export { KyselyAgentStorageService } from './kysely-agent-storage-service.js'
8
+ export { KyselyAgentRunService } from './kysely-agent-run-service.js'
9
+ export { KyselyAgentRunStateService } from './kysely-agent-run-state-service.js'
10
10
  export { KyselySecretService } from './kysely-secret-service.js'
11
- export type { KyselySecretServiceConfig } from './kysely-secret-service.js'
12
11
  export { KyselyCredentialService } from './kysely-credential-service.js'
13
- export type { KyselyCredentialServiceConfig } from './kysely-credential-service.js'
14
12
  export { KyselySessionStore } from './kysely-session-store.js'
15
13
  export { KyselyScopeService } from './kysely-scope-service.js'
16
14
  export { KyselyWebhookService } from './kysely-webhook-service.js'
@@ -23,19 +21,10 @@ export { KyselyVirtualUserRunStore } from './kysely-virtual-user-run-store.js'
23
21
 
24
22
  export {
25
23
  SerializePlugin,
26
- SqliteSerializePlugin,
27
24
  BaseSerializePlugin,
28
- defaultSerializer,
29
- defaultDeserializer,
30
- maybeJson,
31
- skipTransform,
32
- dateRegex,
33
25
  type Serializer,
34
26
  type Deserializer,
35
- type SerializePluginOptions,
36
27
  } from './serialize-plugin.js'
37
-
38
- export { virtualUserSchema } from './schema/virtual-user.schema.js'
39
28
  export {
40
29
  auditSchema,
41
30
  pikkuSchemas,
@@ -44,21 +33,19 @@ export {
44
33
  ensurePikkuSchema,
45
34
  type EnsureOutcome,
46
35
  resolveRequirements,
47
- unsatisfiedRequirements,
48
- rawStatement,
49
- requiredType,
50
36
  type PikkuSchema,
51
37
  type RequiredTypes,
52
- type SchemaRequirement,
53
38
  type UnmetRequirement,
54
- type SchemaStatement,
55
39
  type SchemaStatementFactory,
56
40
  } from './schema/index.js'
57
41
 
58
42
  export type { KyselyPikkuDB } from './kysely-tables.js'
59
- export type { WorkflowRunService } from '@pikku/core/workflow'
60
- export type { AgentRunService, AgentRunRow } from '@pikku/core/ai-agent'
43
+ export type { WorkflowRunService } from '@pikku/core/ecosystem/workflow'
44
+ export type {
45
+ AgentRunService,
46
+ AgentRunRow,
47
+ } from '@pikku/core/ecosystem/agent'
61
48
  export type {
62
49
  VirtualUserRunStore,
63
50
  VirtualUserRunRecord,
64
- } from '@pikku/core/virtual-user'
51
+ } from '@pikku/core/ecosystem/virtual-user'
@@ -0,0 +1,47 @@
1
+ import type { Kysely } from 'kysely'
2
+ import type { KyselyPikkuDB } from './kysely-tables.js'
3
+ import type { SaveScoreInput } from '@pikku/core/services'
4
+ import type { AgentRunScore } from '@pikku/core/agent-scorer'
5
+ import { parseJson } from './kysely-json.js'
6
+
7
+ /**
8
+ * Shared by the two Kysely services that implement `AgentRunStateService` — they
9
+ * differ in how they store approvals, not in how they store grades.
10
+ */
11
+ export const saveRunScore = async (
12
+ db: Kysely<KyselyPikkuDB>,
13
+ score: SaveScoreInput
14
+ ): Promise<void> => {
15
+ await db
16
+ .insertInto('agentRunScore')
17
+ .values({
18
+ id: crypto.randomUUID(),
19
+ runId: score.runId,
20
+ scorerName: score.scorerName,
21
+ score: score.score,
22
+ reason: score.reason ?? null,
23
+ metadata: score.metadata ? JSON.stringify(score.metadata) : null,
24
+ })
25
+ .execute()
26
+ }
27
+
28
+ export const getRunScores = async (
29
+ db: Kysely<KyselyPikkuDB>,
30
+ runId: string
31
+ ): Promise<AgentRunScore[]> => {
32
+ const rows = await db
33
+ .selectFrom('agentRunScore')
34
+ .selectAll()
35
+ .where('runId', '=', runId)
36
+ .orderBy('createdAt', 'asc')
37
+ .execute()
38
+
39
+ return rows.map((row) => ({
40
+ runId: row.runId,
41
+ scorerName: row.scorerName,
42
+ score: Number(row.score),
43
+ reason: row.reason ?? undefined,
44
+ metadata: parseJson(row.metadata),
45
+ createdAt: new Date(row.createdAt),
46
+ }))
47
+ }