weave-typescript 0.42.8 → 0.44.0

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,38 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.listWorkflowStageStatesQuery = exports.getWorkflowStageStateQuery = exports.upsertWorkflowStageStateQuery = exports.deleteWorkflowQuery = exports.archiveWorkflowQuery = exports.updateWorkflowQuery = exports.listWorkflowsByProjectQuery = exports.getWorkflowBySlugQuery = exports.getWorkflowQuery = exports.createWorkflowQuery = void 0;
4
- exports.createWorkflow = createWorkflow;
5
- exports.getWorkflow = getWorkflow;
6
- exports.getWorkflowBySlug = getWorkflowBySlug;
7
- exports.listWorkflowsByProject = listWorkflowsByProject;
8
- exports.updateWorkflow = updateWorkflow;
9
- exports.archiveWorkflow = archiveWorkflow;
10
- exports.deleteWorkflow = deleteWorkflow;
11
- exports.upsertWorkflowStageState = upsertWorkflowStageState;
12
- exports.getWorkflowStageState = getWorkflowStageState;
13
- exports.listWorkflowStageStates = listWorkflowStageStates;
14
- exports.createWorkflowQuery = `-- name: CreateWorkflow :one
15
- INSERT INTO weave_v1.workflow (
3
+ exports.listToolCallEventsQuery = exports.insertToolCallEventQuery = exports.listWorkflowRunEventsQuery = exports.insertWorkflowRunEventQuery = exports.updateWorkflowStepRunStatusQuery = exports.listWorkflowStepRunsQuery = exports.createWorkflowStepRunQuery = exports.updateWorkflowRunStatusQuery = exports.listWorkflowRunsQuery = exports.getWorkflowRunQuery = exports.createWorkflowRunQuery = exports.listWorkflowTemplateVersionsQuery = exports.getWorkflowTemplateVersionByIDQuery = exports.getWorkflowTemplateVersionByNumberQuery = exports.setWorkflowTemplateLatestVersionQuery = exports.insertWorkflowTemplateVersionQuery = exports.insertWorkflowDraftPatchQuery = exports.updateWorkflowDraftQuery = exports.updateWorkflowTemplateStatusQuery = exports.updateWorkflowTemplateDraftMetadataQuery = exports.listWorkflowTemplatesQuery = exports.getWorkflowTemplateDraftQuery = exports.getWorkflowTemplateBySlugQuery = exports.getWorkflowTemplateByIDQuery = exports.createWorkflowTemplateDraftQuery = exports.createWorkflowTemplateQuery = void 0;
4
+ exports.createWorkflowTemplate = createWorkflowTemplate;
5
+ exports.createWorkflowTemplateDraft = createWorkflowTemplateDraft;
6
+ exports.getWorkflowTemplateByID = getWorkflowTemplateByID;
7
+ exports.getWorkflowTemplateBySlug = getWorkflowTemplateBySlug;
8
+ exports.getWorkflowTemplateDraft = getWorkflowTemplateDraft;
9
+ exports.listWorkflowTemplates = listWorkflowTemplates;
10
+ exports.updateWorkflowTemplateDraftMetadata = updateWorkflowTemplateDraftMetadata;
11
+ exports.updateWorkflowTemplateStatus = updateWorkflowTemplateStatus;
12
+ exports.updateWorkflowDraft = updateWorkflowDraft;
13
+ exports.insertWorkflowDraftPatch = insertWorkflowDraftPatch;
14
+ exports.insertWorkflowTemplateVersion = insertWorkflowTemplateVersion;
15
+ exports.setWorkflowTemplateLatestVersion = setWorkflowTemplateLatestVersion;
16
+ exports.getWorkflowTemplateVersionByNumber = getWorkflowTemplateVersionByNumber;
17
+ exports.getWorkflowTemplateVersionByID = getWorkflowTemplateVersionByID;
18
+ exports.listWorkflowTemplateVersions = listWorkflowTemplateVersions;
19
+ exports.createWorkflowRun = createWorkflowRun;
20
+ exports.getWorkflowRun = getWorkflowRun;
21
+ exports.listWorkflowRuns = listWorkflowRuns;
22
+ exports.updateWorkflowRunStatus = updateWorkflowRunStatus;
23
+ exports.createWorkflowStepRun = createWorkflowStepRun;
24
+ exports.listWorkflowStepRuns = listWorkflowStepRuns;
25
+ exports.updateWorkflowStepRunStatus = updateWorkflowStepRunStatus;
26
+ exports.insertWorkflowRunEvent = insertWorkflowRunEvent;
27
+ exports.listWorkflowRunEvents = listWorkflowRunEvents;
28
+ exports.insertToolCallEvent = insertToolCallEvent;
29
+ exports.listToolCallEvents = listToolCallEvents;
30
+ exports.createWorkflowTemplateQuery = `-- name: CreateWorkflowTemplate :one
31
+ INSERT INTO weave.workflow_templates (
16
32
  id,
17
- project_id,
18
- name,
33
+ organization_id,
19
34
  slug,
35
+ name,
20
36
  description,
21
- status
22
- )
23
- VALUES (
37
+ status,
38
+ created_by_user_id
39
+ ) VALUES (
24
40
  $1,
25
41
  $2,
26
42
  $3,
27
43
  $4,
28
44
  $5,
29
- $6
45
+ $6,
46
+ $7
30
47
  )
31
- RETURNING id, project_id, name, slug, description, status, created_at, updated_at, archived_at`;
32
- async function createWorkflow(client, args) {
48
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
49
+ async function createWorkflowTemplate(client, args) {
33
50
  const result = await client.query({
34
- text: exports.createWorkflowQuery,
35
- values: [args.id, args.projectId, args.name, args.slug, args.description, args.status],
51
+ text: exports.createWorkflowTemplateQuery,
52
+ values: [args.id, args.organizationId, args.slug, args.name, args.description, args.status, args.createdByUserId],
36
53
  rowMode: "array"
37
54
  });
38
55
  if (result.rows.length !== 1) {
@@ -41,25 +58,83 @@ async function createWorkflow(client, args) {
41
58
  const row = result.rows[0];
42
59
  return {
43
60
  id: row[0],
44
- projectId: row[1],
45
- name: row[2],
46
- slug: row[3],
61
+ organizationId: row[1],
62
+ slug: row[2],
63
+ name: row[3],
47
64
  description: row[4],
48
65
  status: row[5],
49
- createdAt: row[6],
50
- updatedAt: row[7],
51
- archivedAt: row[8]
66
+ createdByUserId: row[6],
67
+ draftRevision: row[7],
68
+ latestVersionId: row[8],
69
+ latestVersion: row[9],
70
+ createdAt: row[10],
71
+ updatedAt: row[11]
72
+ };
73
+ }
74
+ exports.createWorkflowTemplateDraftQuery = `-- name: CreateWorkflowTemplateDraft :one
75
+ INSERT INTO weave.workflow_template_drafts (
76
+ id,
77
+ template_id,
78
+ organization_id,
79
+ base_version_id,
80
+ revision,
81
+ name,
82
+ description,
83
+ definition,
84
+ input_schema,
85
+ output_schema,
86
+ metadata,
87
+ updated_by_user_id
88
+ ) VALUES (
89
+ $1,
90
+ $2,
91
+ $3,
92
+ $4::uuid,
93
+ $5,
94
+ $6,
95
+ $7,
96
+ $8,
97
+ $9,
98
+ $10,
99
+ $11,
100
+ $12
101
+ )
102
+ RETURNING id, template_id, organization_id, base_version_id, revision, name, description, definition, input_schema, output_schema, metadata, updated_by_user_id, created_at, updated_at`;
103
+ async function createWorkflowTemplateDraft(client, args) {
104
+ const result = await client.query({
105
+ text: exports.createWorkflowTemplateDraftQuery,
106
+ values: [args.id, args.templateId, args.organizationId, args.baseVersionId, args.revision, args.name, args.description, args.definition, args.inputSchema, args.outputSchema, args.metadata, args.updatedByUserId],
107
+ rowMode: "array"
108
+ });
109
+ if (result.rows.length !== 1) {
110
+ return null;
111
+ }
112
+ const row = result.rows[0];
113
+ return {
114
+ id: row[0],
115
+ templateId: row[1],
116
+ organizationId: row[2],
117
+ baseVersionId: row[3],
118
+ revision: row[4],
119
+ name: row[5],
120
+ description: row[6],
121
+ definition: row[7],
122
+ inputSchema: row[8],
123
+ outputSchema: row[9],
124
+ metadata: row[10],
125
+ updatedByUserId: row[11],
126
+ createdAt: row[12],
127
+ updatedAt: row[13]
52
128
  };
53
129
  }
54
- exports.getWorkflowQuery = `-- name: GetWorkflow :one
55
- SELECT id, project_id, name, slug, description, status, created_at, updated_at, archived_at
56
- FROM weave_v1.workflow
57
- WHERE id = $1
58
- AND project_id = $2`;
59
- async function getWorkflow(client, args) {
130
+ exports.getWorkflowTemplateByIDQuery = `-- name: GetWorkflowTemplateByID :one
131
+ SELECT id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at FROM weave.workflow_templates
132
+ WHERE organization_id = $1
133
+ AND id = $2`;
134
+ async function getWorkflowTemplateByID(client, args) {
60
135
  const result = await client.query({
61
- text: exports.getWorkflowQuery,
62
- values: [args.id, args.projectId],
136
+ text: exports.getWorkflowTemplateByIDQuery,
137
+ values: [args.organizationId, args.templateId],
63
138
  rowMode: "array"
64
139
  });
65
140
  if (result.rows.length !== 1) {
@@ -68,27 +143,27 @@ async function getWorkflow(client, args) {
68
143
  const row = result.rows[0];
69
144
  return {
70
145
  id: row[0],
71
- projectId: row[1],
72
- name: row[2],
73
- slug: row[3],
146
+ organizationId: row[1],
147
+ slug: row[2],
148
+ name: row[3],
74
149
  description: row[4],
75
150
  status: row[5],
76
- createdAt: row[6],
77
- updatedAt: row[7],
78
- archivedAt: row[8]
151
+ createdByUserId: row[6],
152
+ draftRevision: row[7],
153
+ latestVersionId: row[8],
154
+ latestVersion: row[9],
155
+ createdAt: row[10],
156
+ updatedAt: row[11]
79
157
  };
80
158
  }
81
- exports.getWorkflowBySlugQuery = `-- name: GetWorkflowBySlug :one
82
- SELECT w.id, w.project_id, w.name, w.slug, w.description, w.status, w.created_at, w.updated_at, w.archived_at
83
- FROM weave_v1.workflow w
84
- INNER JOIN weave_v1.project p ON p.id = w.project_id
85
- WHERE p.organization_id = $1
86
- AND p.slug = $2
87
- AND w.slug = $3`;
88
- async function getWorkflowBySlug(client, args) {
159
+ exports.getWorkflowTemplateBySlugQuery = `-- name: GetWorkflowTemplateBySlug :one
160
+ SELECT id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at FROM weave.workflow_templates
161
+ WHERE organization_id = $1
162
+ AND slug = $2`;
163
+ async function getWorkflowTemplateBySlug(client, args) {
89
164
  const result = await client.query({
90
- text: exports.getWorkflowBySlugQuery,
91
- values: [args.organizationId, args.projectSlug, args.slug],
165
+ text: exports.getWorkflowTemplateBySlugQuery,
166
+ values: [args.organizationId, args.slug],
92
167
  rowMode: "array"
93
168
  });
94
169
  if (result.rows.length !== 1) {
@@ -97,58 +172,96 @@ async function getWorkflowBySlug(client, args) {
97
172
  const row = result.rows[0];
98
173
  return {
99
174
  id: row[0],
100
- projectId: row[1],
101
- name: row[2],
102
- slug: row[3],
175
+ organizationId: row[1],
176
+ slug: row[2],
177
+ name: row[3],
103
178
  description: row[4],
104
179
  status: row[5],
105
- createdAt: row[6],
106
- updatedAt: row[7],
107
- archivedAt: row[8]
180
+ createdByUserId: row[6],
181
+ draftRevision: row[7],
182
+ latestVersionId: row[8],
183
+ latestVersion: row[9],
184
+ createdAt: row[10],
185
+ updatedAt: row[11]
108
186
  };
109
187
  }
110
- exports.listWorkflowsByProjectQuery = `-- name: ListWorkflowsByProject :many
111
- SELECT id, project_id, name, slug, description, status, created_at, updated_at, archived_at
112
- FROM weave_v1.workflow
113
- WHERE project_id = $1
114
- AND ($2::BOOLEAN OR archived_at IS NULL)
115
- ORDER BY updated_at DESC
116
- LIMIT $4
117
- OFFSET $3`;
118
- async function listWorkflowsByProject(client, args) {
188
+ exports.getWorkflowTemplateDraftQuery = `-- name: GetWorkflowTemplateDraft :one
189
+ SELECT id, template_id, organization_id, base_version_id, revision, name, description, definition, input_schema, output_schema, metadata, updated_by_user_id, created_at, updated_at FROM weave.workflow_template_drafts
190
+ WHERE organization_id = $1
191
+ AND template_id = $2`;
192
+ async function getWorkflowTemplateDraft(client, args) {
119
193
  const result = await client.query({
120
- text: exports.listWorkflowsByProjectQuery,
121
- values: [args.projectId, args.includeArchived, args.pageOffset, args.pageSize],
194
+ text: exports.getWorkflowTemplateDraftQuery,
195
+ values: [args.organizationId, args.templateId],
196
+ rowMode: "array"
197
+ });
198
+ if (result.rows.length !== 1) {
199
+ return null;
200
+ }
201
+ const row = result.rows[0];
202
+ return {
203
+ id: row[0],
204
+ templateId: row[1],
205
+ organizationId: row[2],
206
+ baseVersionId: row[3],
207
+ revision: row[4],
208
+ name: row[5],
209
+ description: row[6],
210
+ definition: row[7],
211
+ inputSchema: row[8],
212
+ outputSchema: row[9],
213
+ metadata: row[10],
214
+ updatedByUserId: row[11],
215
+ createdAt: row[12],
216
+ updatedAt: row[13]
217
+ };
218
+ }
219
+ exports.listWorkflowTemplatesQuery = `-- name: ListWorkflowTemplates :many
220
+ SELECT id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at FROM weave.workflow_templates
221
+ WHERE organization_id = $1
222
+ AND (
223
+ $2::text IS NULL
224
+ OR status = $2::text
225
+ )
226
+ ORDER BY updated_at DESC, created_at DESC
227
+ LIMIT $4 OFFSET $3`;
228
+ async function listWorkflowTemplates(client, args) {
229
+ const result = await client.query({
230
+ text: exports.listWorkflowTemplatesQuery,
231
+ values: [args.organizationId, args.status, args.pageOffset, args.pageSize],
122
232
  rowMode: "array"
123
233
  });
124
234
  return result.rows.map(row => {
125
235
  return {
126
236
  id: row[0],
127
- projectId: row[1],
128
- name: row[2],
129
- slug: row[3],
237
+ organizationId: row[1],
238
+ slug: row[2],
239
+ name: row[3],
130
240
  description: row[4],
131
241
  status: row[5],
132
- createdAt: row[6],
133
- updatedAt: row[7],
134
- archivedAt: row[8]
242
+ createdByUserId: row[6],
243
+ draftRevision: row[7],
244
+ latestVersionId: row[8],
245
+ latestVersion: row[9],
246
+ createdAt: row[10],
247
+ updatedAt: row[11]
135
248
  };
136
249
  });
137
250
  }
138
- exports.updateWorkflowQuery = `-- name: UpdateWorkflow :one
139
- UPDATE weave_v1.workflow
140
- SET name = $1,
141
- slug = $2,
142
- description = $3,
143
- status = $4,
144
- updated_at = NOW()
145
- WHERE id = $5
146
- AND project_id = $6
147
- RETURNING id, project_id, name, slug, description, status, created_at, updated_at, archived_at`;
148
- async function updateWorkflow(client, args) {
251
+ exports.updateWorkflowTemplateDraftMetadataQuery = `-- name: UpdateWorkflowTemplateDraftMetadata :one
252
+ UPDATE weave.workflow_templates
253
+ SET
254
+ name = $1,
255
+ description = $2,
256
+ draft_revision = $3,
257
+ updated_at = now()
258
+ WHERE organization_id = $4
259
+ AND id = $5
260
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
261
+ async function updateWorkflowTemplateDraftMetadata(client, args) {
149
262
  const result = await client.query({
150
- text: exports.updateWorkflowQuery,
151
- values: [args.name, args.slug, args.description, args.status, args.id, args.projectId],
263
+ text: exports.updateWorkflowTemplateDraftMetadataQuery,
264
+ values: [args.name, args.description, args.draftRevision, args.organizationId, args.templateId],
152
265
  rowMode: "array"
153
266
  });
154
267
  if (result.rows.length !== 1) {
@@ -157,28 +270,166 @@ async function updateWorkflow(client, args) {
157
270
  const row = result.rows[0];
158
271
  return {
159
272
  id: row[0],
160
- projectId: row[1],
161
- name: row[2],
162
- slug: row[3],
273
+ organizationId: row[1],
274
+ slug: row[2],
275
+ name: row[3],
163
276
  description: row[4],
164
277
  status: row[5],
165
- createdAt: row[6],
166
- updatedAt: row[7],
167
- archivedAt: row[8]
278
+ createdByUserId: row[6],
279
+ draftRevision: row[7],
280
+ latestVersionId: row[8],
281
+ latestVersion: row[9],
282
+ createdAt: row[10],
283
+ updatedAt: row[11]
284
+ };
285
+ }
286
+ exports.updateWorkflowTemplateStatusQuery = `-- name: UpdateWorkflowTemplateStatus :one
287
+ UPDATE weave.workflow_templates
288
+ SET
289
+ status = $1,
290
+ updated_at = now()
291
+ WHERE organization_id = $2
292
+ AND id = $3
293
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
294
+ async function updateWorkflowTemplateStatus(client, args) {
295
+ const result = await client.query({
296
+ text: exports.updateWorkflowTemplateStatusQuery,
297
+ values: [args.status, args.organizationId, args.templateId],
298
+ rowMode: "array"
299
+ });
300
+ if (result.rows.length !== 1) {
301
+ return null;
302
+ }
303
+ const row = result.rows[0];
304
+ return {
305
+ id: row[0],
306
+ organizationId: row[1],
307
+ slug: row[2],
308
+ name: row[3],
309
+ description: row[4],
310
+ status: row[5],
311
+ createdByUserId: row[6],
312
+ draftRevision: row[7],
313
+ latestVersionId: row[8],
314
+ latestVersion: row[9],
315
+ createdAt: row[10],
316
+ updatedAt: row[11]
317
+ };
318
+ }
319
+ exports.updateWorkflowDraftQuery = `-- name: UpdateWorkflowDraft :one
320
+ UPDATE weave.workflow_template_drafts
321
+ SET
322
+ base_version_id = $1::uuid,
323
+ revision = revision + 1,
324
+ name = $2,
325
+ description = $3,
326
+ definition = $4,
327
+ input_schema = $5,
328
+ output_schema = $6,
329
+ metadata = $7,
330
+ updated_by_user_id = $8,
331
+ updated_at = now()
332
+ WHERE organization_id = $9
333
+ AND template_id = $10
334
+ AND revision = $11
335
+ RETURNING id, template_id, organization_id, base_version_id, revision, name, description, definition, input_schema, output_schema, metadata, updated_by_user_id, created_at, updated_at`;
336
+ async function updateWorkflowDraft(client, args) {
337
+ const result = await client.query({
338
+ text: exports.updateWorkflowDraftQuery,
339
+ values: [args.baseVersionId, args.name, args.description, args.definition, args.inputSchema, args.outputSchema, args.metadata, args.updatedByUserId, args.organizationId, args.templateId, args.expectedRevision],
340
+ rowMode: "array"
341
+ });
342
+ if (result.rows.length !== 1) {
343
+ return null;
344
+ }
345
+ const row = result.rows[0];
346
+ return {
347
+ id: row[0],
348
+ templateId: row[1],
349
+ organizationId: row[2],
350
+ baseVersionId: row[3],
351
+ revision: row[4],
352
+ name: row[5],
353
+ description: row[6],
354
+ definition: row[7],
355
+ inputSchema: row[8],
356
+ outputSchema: row[9],
357
+ metadata: row[10],
358
+ updatedByUserId: row[11],
359
+ createdAt: row[12],
360
+ updatedAt: row[13]
361
+ };
362
+ }
363
+ exports.insertWorkflowDraftPatchQuery = `-- name: InsertWorkflowDraftPatch :one
364
+ INSERT INTO weave.workflow_template_draft_patches (
365
+ id,
366
+ template_id,
367
+ organization_id,
368
+ revision,
369
+ patch,
370
+ created_by_user_id
371
+ ) VALUES (
372
+ $1,
373
+ $2,
374
+ $3,
375
+ $4,
376
+ $5,
377
+ $6
378
+ )
379
+ RETURNING id, template_id, organization_id, revision, patch, created_by_user_id, created_at`;
380
+ async function insertWorkflowDraftPatch(client, args) {
381
+ const result = await client.query({
382
+ text: exports.insertWorkflowDraftPatchQuery,
383
+ values: [args.id, args.templateId, args.organizationId, args.revision, args.patch, args.createdByUserId],
384
+ rowMode: "array"
385
+ });
386
+ if (result.rows.length !== 1) {
387
+ return null;
388
+ }
389
+ const row = result.rows[0];
390
+ return {
391
+ id: row[0],
392
+ templateId: row[1],
393
+ organizationId: row[2],
394
+ revision: row[3],
395
+ patch: row[4],
396
+ createdByUserId: row[5],
397
+ createdAt: row[6]
168
398
  };
169
399
  }
170
- exports.archiveWorkflowQuery = `-- name: ArchiveWorkflow :one
171
- UPDATE weave_v1.workflow
172
- SET status = 'archived',
173
- archived_at = NOW(),
174
- updated_at = NOW()
175
- WHERE id = $1
176
- AND project_id = $2
177
- RETURNING id, project_id, name, slug, description, status, created_at, updated_at, archived_at`;
178
- async function archiveWorkflow(client, args) {
400
+ exports.insertWorkflowTemplateVersionQuery = `-- name: InsertWorkflowTemplateVersion :one
401
+ INSERT INTO weave.workflow_template_versions (
402
+ id,
403
+ template_id,
404
+ organization_id,
405
+ version,
406
+ source_draft_revision,
407
+ name,
408
+ description,
409
+ definition,
410
+ input_schema,
411
+ output_schema,
412
+ metadata,
413
+ published_by_user_id
414
+ ) VALUES (
415
+ $1,
416
+ $2,
417
+ $3,
418
+ $4,
419
+ $5,
420
+ $6,
421
+ $7,
422
+ $8,
423
+ $9,
424
+ $10,
425
+ $11,
426
+ $12
427
+ )
428
+ RETURNING id, template_id, organization_id, version, source_draft_revision, name, description, definition, input_schema, output_schema, metadata, published_by_user_id, published_at`;
429
+ async function insertWorkflowTemplateVersion(client, args) {
179
430
  const result = await client.query({
180
- text: exports.archiveWorkflowQuery,
181
- values: [args.id, args.projectId],
431
+ text: exports.insertWorkflowTemplateVersionQuery,
432
+ values: [args.id, args.templateId, args.organizationId, args.version, args.sourceDraftRevision, args.name, args.description, args.definition, args.inputSchema, args.outputSchema, args.metadata, args.publishedByUserId],
182
433
  rowMode: "array"
183
434
  });
184
435
  if (result.rows.length !== 1) {
@@ -187,53 +438,326 @@ async function archiveWorkflow(client, args) {
187
438
  const row = result.rows[0];
188
439
  return {
189
440
  id: row[0],
190
- projectId: row[1],
191
- name: row[2],
192
- slug: row[3],
441
+ templateId: row[1],
442
+ organizationId: row[2],
443
+ version: row[3],
444
+ sourceDraftRevision: row[4],
445
+ name: row[5],
446
+ description: row[6],
447
+ definition: row[7],
448
+ inputSchema: row[8],
449
+ outputSchema: row[9],
450
+ metadata: row[10],
451
+ publishedByUserId: row[11],
452
+ publishedAt: row[12]
453
+ };
454
+ }
455
+ exports.setWorkflowTemplateLatestVersionQuery = `-- name: SetWorkflowTemplateLatestVersion :one
456
+ UPDATE weave.workflow_templates
457
+ SET
458
+ latest_version_id = $1,
459
+ latest_version = $2,
460
+ updated_at = now()
461
+ WHERE organization_id = $3
462
+ AND id = $4
463
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
464
+ async function setWorkflowTemplateLatestVersion(client, args) {
465
+ const result = await client.query({
466
+ text: exports.setWorkflowTemplateLatestVersionQuery,
467
+ values: [args.versionId, args.version, args.organizationId, args.templateId],
468
+ rowMode: "array"
469
+ });
470
+ if (result.rows.length !== 1) {
471
+ return null;
472
+ }
473
+ const row = result.rows[0];
474
+ return {
475
+ id: row[0],
476
+ organizationId: row[1],
477
+ slug: row[2],
478
+ name: row[3],
193
479
  description: row[4],
194
480
  status: row[5],
195
- createdAt: row[6],
196
- updatedAt: row[7],
197
- archivedAt: row[8]
481
+ createdByUserId: row[6],
482
+ draftRevision: row[7],
483
+ latestVersionId: row[8],
484
+ latestVersion: row[9],
485
+ createdAt: row[10],
486
+ updatedAt: row[11]
487
+ };
488
+ }
489
+ exports.getWorkflowTemplateVersionByNumberQuery = `-- name: GetWorkflowTemplateVersionByNumber :one
490
+ SELECT id, template_id, organization_id, version, source_draft_revision, name, description, definition, input_schema, output_schema, metadata, published_by_user_id, published_at FROM weave.workflow_template_versions
491
+ WHERE organization_id = $1
492
+ AND template_id = $2
493
+ AND version = $3`;
494
+ async function getWorkflowTemplateVersionByNumber(client, args) {
495
+ const result = await client.query({
496
+ text: exports.getWorkflowTemplateVersionByNumberQuery,
497
+ values: [args.organizationId, args.templateId, args.version],
498
+ rowMode: "array"
499
+ });
500
+ if (result.rows.length !== 1) {
501
+ return null;
502
+ }
503
+ const row = result.rows[0];
504
+ return {
505
+ id: row[0],
506
+ templateId: row[1],
507
+ organizationId: row[2],
508
+ version: row[3],
509
+ sourceDraftRevision: row[4],
510
+ name: row[5],
511
+ description: row[6],
512
+ definition: row[7],
513
+ inputSchema: row[8],
514
+ outputSchema: row[9],
515
+ metadata: row[10],
516
+ publishedByUserId: row[11],
517
+ publishedAt: row[12]
518
+ };
519
+ }
520
+ exports.getWorkflowTemplateVersionByIDQuery = `-- name: GetWorkflowTemplateVersionByID :one
521
+ SELECT id, template_id, organization_id, version, source_draft_revision, name, description, definition, input_schema, output_schema, metadata, published_by_user_id, published_at FROM weave.workflow_template_versions
522
+ WHERE organization_id = $1
523
+ AND id = $2`;
524
+ async function getWorkflowTemplateVersionByID(client, args) {
525
+ const result = await client.query({
526
+ text: exports.getWorkflowTemplateVersionByIDQuery,
527
+ values: [args.organizationId, args.versionId],
528
+ rowMode: "array"
529
+ });
530
+ if (result.rows.length !== 1) {
531
+ return null;
532
+ }
533
+ const row = result.rows[0];
534
+ return {
535
+ id: row[0],
536
+ templateId: row[1],
537
+ organizationId: row[2],
538
+ version: row[3],
539
+ sourceDraftRevision: row[4],
540
+ name: row[5],
541
+ description: row[6],
542
+ definition: row[7],
543
+ inputSchema: row[8],
544
+ outputSchema: row[9],
545
+ metadata: row[10],
546
+ publishedByUserId: row[11],
547
+ publishedAt: row[12]
198
548
  };
199
549
  }
200
- exports.deleteWorkflowQuery = `-- name: DeleteWorkflow :exec
201
- DELETE
202
- FROM weave_v1.workflow
203
- WHERE id = $1
204
- AND project_id = $2`;
205
- async function deleteWorkflow(client, args) {
206
- await client.query({
207
- text: exports.deleteWorkflowQuery,
208
- values: [args.id, args.projectId],
550
+ exports.listWorkflowTemplateVersionsQuery = `-- name: ListWorkflowTemplateVersions :many
551
+ SELECT id, template_id, organization_id, version, source_draft_revision, name, description, definition, input_schema, output_schema, metadata, published_by_user_id, published_at FROM weave.workflow_template_versions
552
+ WHERE organization_id = $1
553
+ AND template_id = $2
554
+ ORDER BY version DESC
555
+ LIMIT $4 OFFSET $3`;
556
+ async function listWorkflowTemplateVersions(client, args) {
557
+ const result = await client.query({
558
+ text: exports.listWorkflowTemplateVersionsQuery,
559
+ values: [args.organizationId, args.templateId, args.pageOffset, args.pageSize],
560
+ rowMode: "array"
561
+ });
562
+ return result.rows.map(row => {
563
+ return {
564
+ id: row[0],
565
+ templateId: row[1],
566
+ organizationId: row[2],
567
+ version: row[3],
568
+ sourceDraftRevision: row[4],
569
+ name: row[5],
570
+ description: row[6],
571
+ definition: row[7],
572
+ inputSchema: row[8],
573
+ outputSchema: row[9],
574
+ metadata: row[10],
575
+ publishedByUserId: row[11],
576
+ publishedAt: row[12]
577
+ };
578
+ });
579
+ }
580
+ exports.createWorkflowRunQuery = `-- name: CreateWorkflowRun :one
581
+ INSERT INTO weave.workflow_runs (
582
+ id,
583
+ organization_id,
584
+ workflow_template_id,
585
+ workflow_version_id,
586
+ status,
587
+ created_by_user_id,
588
+ chat_session_id,
589
+ input
590
+ ) VALUES (
591
+ $1,
592
+ $2,
593
+ $3,
594
+ $4,
595
+ $5,
596
+ $6,
597
+ $7::uuid,
598
+ $8
599
+ )
600
+ RETURNING id, organization_id, workflow_template_id, workflow_version_id, status, created_by_user_id, chat_session_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at`;
601
+ async function createWorkflowRun(client, args) {
602
+ const result = await client.query({
603
+ text: exports.createWorkflowRunQuery,
604
+ values: [args.id, args.organizationId, args.workflowTemplateId, args.workflowVersionId, args.status, args.createdByUserId, args.chatSessionId, args.input],
209
605
  rowMode: "array"
210
606
  });
607
+ if (result.rows.length !== 1) {
608
+ return null;
609
+ }
610
+ const row = result.rows[0];
611
+ return {
612
+ id: row[0],
613
+ organizationId: row[1],
614
+ workflowTemplateId: row[2],
615
+ workflowVersionId: row[3],
616
+ status: row[4],
617
+ createdByUserId: row[5],
618
+ chatSessionId: row[6],
619
+ input: row[7],
620
+ output: row[8],
621
+ errorCode: row[9],
622
+ safeErrorMessage: row[10],
623
+ createdAt: row[11],
624
+ startedAt: row[12],
625
+ finishedAt: row[13]
626
+ };
627
+ }
628
+ exports.getWorkflowRunQuery = `-- name: GetWorkflowRun :one
629
+ SELECT id, organization_id, workflow_template_id, workflow_version_id, status, created_by_user_id, chat_session_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at FROM weave.workflow_runs
630
+ WHERE organization_id = $1
631
+ AND id = $2`;
632
+ async function getWorkflowRun(client, args) {
633
+ const result = await client.query({
634
+ text: exports.getWorkflowRunQuery,
635
+ values: [args.organizationId, args.workflowRunId],
636
+ rowMode: "array"
637
+ });
638
+ if (result.rows.length !== 1) {
639
+ return null;
640
+ }
641
+ const row = result.rows[0];
642
+ return {
643
+ id: row[0],
644
+ organizationId: row[1],
645
+ workflowTemplateId: row[2],
646
+ workflowVersionId: row[3],
647
+ status: row[4],
648
+ createdByUserId: row[5],
649
+ chatSessionId: row[6],
650
+ input: row[7],
651
+ output: row[8],
652
+ errorCode: row[9],
653
+ safeErrorMessage: row[10],
654
+ createdAt: row[11],
655
+ startedAt: row[12],
656
+ finishedAt: row[13]
657
+ };
658
+ }
659
+ exports.listWorkflowRunsQuery = `-- name: ListWorkflowRuns :many
660
+ SELECT id, organization_id, workflow_template_id, workflow_version_id, status, created_by_user_id, chat_session_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at FROM weave.workflow_runs
661
+ WHERE organization_id = $1
662
+ AND (
663
+ $2::uuid IS NULL
664
+ OR workflow_template_id = $2::uuid
665
+ )
666
+ AND (
667
+ $3::text IS NULL
668
+ OR status = $3::text
669
+ )
670
+ ORDER BY created_at DESC
671
+ LIMIT $5 OFFSET $4`;
672
+ async function listWorkflowRuns(client, args) {
673
+ const result = await client.query({
674
+ text: exports.listWorkflowRunsQuery,
675
+ values: [args.organizationId, args.workflowTemplateId, args.status, args.pageOffset, args.pageSize],
676
+ rowMode: "array"
677
+ });
678
+ return result.rows.map(row => {
679
+ return {
680
+ id: row[0],
681
+ organizationId: row[1],
682
+ workflowTemplateId: row[2],
683
+ workflowVersionId: row[3],
684
+ status: row[4],
685
+ createdByUserId: row[5],
686
+ chatSessionId: row[6],
687
+ input: row[7],
688
+ output: row[8],
689
+ errorCode: row[9],
690
+ safeErrorMessage: row[10],
691
+ createdAt: row[11],
692
+ startedAt: row[12],
693
+ finishedAt: row[13]
694
+ };
695
+ });
696
+ }
697
+ exports.updateWorkflowRunStatusQuery = `-- name: UpdateWorkflowRunStatus :one
698
+ UPDATE weave.workflow_runs
699
+ SET
700
+ status = $1,
701
+ output = $2,
702
+ error_code = $3,
703
+ safe_error_message = $4,
704
+ started_at = COALESCE(started_at, $5::timestamptz),
705
+ finished_at = $6::timestamptz
706
+ WHERE organization_id = $7
707
+ AND id = $8
708
+ RETURNING id, organization_id, workflow_template_id, workflow_version_id, status, created_by_user_id, chat_session_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at`;
709
+ async function updateWorkflowRunStatus(client, args) {
710
+ const result = await client.query({
711
+ text: exports.updateWorkflowRunStatusQuery,
712
+ values: [args.status, args.output, args.errorCode, args.safeErrorMessage, args.startedAt, args.finishedAt, args.organizationId, args.workflowRunId],
713
+ rowMode: "array"
714
+ });
715
+ if (result.rows.length !== 1) {
716
+ return null;
717
+ }
718
+ const row = result.rows[0];
719
+ return {
720
+ id: row[0],
721
+ organizationId: row[1],
722
+ workflowTemplateId: row[2],
723
+ workflowVersionId: row[3],
724
+ status: row[4],
725
+ createdByUserId: row[5],
726
+ chatSessionId: row[6],
727
+ input: row[7],
728
+ output: row[8],
729
+ errorCode: row[9],
730
+ safeErrorMessage: row[10],
731
+ createdAt: row[11],
732
+ startedAt: row[12],
733
+ finishedAt: row[13]
734
+ };
211
735
  }
212
- exports.upsertWorkflowStageStateQuery = `-- name: UpsertWorkflowStageState :one
213
- INSERT INTO weave_v1.workflow_stage_state (
214
- workflow_id,
215
- stage,
736
+ exports.createWorkflowStepRunQuery = `-- name: CreateWorkflowStepRun :one
737
+ INSERT INTO weave.workflow_step_runs (
738
+ id,
739
+ organization_id,
740
+ workflow_run_id,
741
+ step_key,
742
+ step_name,
743
+ step_kind,
216
744
  status,
217
- blocked_reason,
218
- updated_at
745
+ input
746
+ ) VALUES (
747
+ $1,
748
+ $2,
749
+ $3,
750
+ $4,
751
+ $5,
752
+ $6,
753
+ $7,
754
+ $8
219
755
  )
220
- SELECT w.id,
221
- $1,
222
- $2,
223
- $3,
224
- NOW()
225
- FROM weave_v1.workflow w
226
- WHERE w.id = $4
227
- AND w.project_id = $5
228
- ON CONFLICT (workflow_id, stage) DO UPDATE
229
- SET status = EXCLUDED.status,
230
- blocked_reason = EXCLUDED.blocked_reason,
231
- updated_at = NOW()
232
- RETURNING workflow_id, stage, status, blocked_reason, updated_at`;
233
- async function upsertWorkflowStageState(client, args) {
756
+ RETURNING id, organization_id, workflow_run_id, step_key, step_name, step_kind, status, agent_run_id, child_workflow_run_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at`;
757
+ async function createWorkflowStepRun(client, args) {
234
758
  const result = await client.query({
235
- text: exports.upsertWorkflowStageStateQuery,
236
- values: [args.stage, args.status, args.blockedReason, args.workflowId, args.projectId],
759
+ text: exports.createWorkflowStepRunQuery,
760
+ values: [args.id, args.organizationId, args.workflowRunId, args.stepKey, args.stepName, args.stepKind, args.status, args.input],
237
761
  rowMode: "array"
238
762
  });
239
763
  if (result.rows.length !== 1) {
@@ -241,24 +765,74 @@ async function upsertWorkflowStageState(client, args) {
241
765
  }
242
766
  const row = result.rows[0];
243
767
  return {
244
- workflowId: row[0],
245
- stage: row[1],
246
- status: row[2],
247
- blockedReason: row[3],
248
- updatedAt: row[4]
768
+ id: row[0],
769
+ organizationId: row[1],
770
+ workflowRunId: row[2],
771
+ stepKey: row[3],
772
+ stepName: row[4],
773
+ stepKind: row[5],
774
+ status: row[6],
775
+ agentRunId: row[7],
776
+ childWorkflowRunId: row[8],
777
+ input: row[9],
778
+ output: row[10],
779
+ errorCode: row[11],
780
+ safeErrorMessage: row[12],
781
+ createdAt: row[13],
782
+ startedAt: row[14],
783
+ finishedAt: row[15]
249
784
  };
250
785
  }
251
- exports.getWorkflowStageStateQuery = `-- name: GetWorkflowStageState :one
252
- SELECT s.workflow_id, s.stage, s.status, s.blocked_reason, s.updated_at
253
- FROM weave_v1.workflow_stage_state s
254
- INNER JOIN weave_v1.workflow w ON w.id = s.workflow_id
255
- WHERE s.workflow_id = $1
256
- AND w.project_id = $2
257
- AND s.stage = $3`;
258
- async function getWorkflowStageState(client, args) {
786
+ exports.listWorkflowStepRunsQuery = `-- name: ListWorkflowStepRuns :many
787
+ SELECT id, organization_id, workflow_run_id, step_key, step_name, step_kind, status, agent_run_id, child_workflow_run_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at FROM weave.workflow_step_runs
788
+ WHERE organization_id = $1
789
+ AND workflow_run_id = $2
790
+ ORDER BY created_at, step_key`;
791
+ async function listWorkflowStepRuns(client, args) {
792
+ const result = await client.query({
793
+ text: exports.listWorkflowStepRunsQuery,
794
+ values: [args.organizationId, args.workflowRunId],
795
+ rowMode: "array"
796
+ });
797
+ return result.rows.map(row => {
798
+ return {
799
+ id: row[0],
800
+ organizationId: row[1],
801
+ workflowRunId: row[2],
802
+ stepKey: row[3],
803
+ stepName: row[4],
804
+ stepKind: row[5],
805
+ status: row[6],
806
+ agentRunId: row[7],
807
+ childWorkflowRunId: row[8],
808
+ input: row[9],
809
+ output: row[10],
810
+ errorCode: row[11],
811
+ safeErrorMessage: row[12],
812
+ createdAt: row[13],
813
+ startedAt: row[14],
814
+ finishedAt: row[15]
815
+ };
816
+ });
817
+ }
818
+ exports.updateWorkflowStepRunStatusQuery = `-- name: UpdateWorkflowStepRunStatus :one
819
+ UPDATE weave.workflow_step_runs
820
+ SET
821
+ status = $1,
822
+ agent_run_id = $2::uuid,
823
+ child_workflow_run_id = $3::uuid,
824
+ output = $4,
825
+ error_code = $5,
826
+ safe_error_message = $6,
827
+ started_at = COALESCE(started_at, $7::timestamptz),
828
+ finished_at = $8::timestamptz
829
+ WHERE organization_id = $9
830
+ AND id = $10
831
+ RETURNING id, organization_id, workflow_run_id, step_key, step_name, step_kind, status, agent_run_id, child_workflow_run_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at`;
832
+ async function updateWorkflowStepRunStatus(client, args) {
259
833
  const result = await client.query({
260
- text: exports.getWorkflowStageStateQuery,
261
- values: [args.workflowId, args.projectId, args.stage],
834
+ text: exports.updateWorkflowStepRunStatusQuery,
835
+ values: [args.status, args.agentRunId, args.childWorkflowRunId, args.output, args.errorCode, args.safeErrorMessage, args.startedAt, args.finishedAt, args.organizationId, args.workflowStepRunId],
262
836
  rowMode: "array"
263
837
  });
264
838
  if (result.rows.length !== 1) {
@@ -266,33 +840,187 @@ async function getWorkflowStageState(client, args) {
266
840
  }
267
841
  const row = result.rows[0];
268
842
  return {
269
- workflowId: row[0],
270
- stage: row[1],
271
- status: row[2],
272
- blockedReason: row[3],
273
- updatedAt: row[4]
843
+ id: row[0],
844
+ organizationId: row[1],
845
+ workflowRunId: row[2],
846
+ stepKey: row[3],
847
+ stepName: row[4],
848
+ stepKind: row[5],
849
+ status: row[6],
850
+ agentRunId: row[7],
851
+ childWorkflowRunId: row[8],
852
+ input: row[9],
853
+ output: row[10],
854
+ errorCode: row[11],
855
+ safeErrorMessage: row[12],
856
+ createdAt: row[13],
857
+ startedAt: row[14],
858
+ finishedAt: row[15]
274
859
  };
275
860
  }
276
- exports.listWorkflowStageStatesQuery = `-- name: ListWorkflowStageStates :many
277
- SELECT s.workflow_id, s.stage, s.status, s.blocked_reason, s.updated_at
278
- FROM weave_v1.workflow_stage_state s
279
- INNER JOIN weave_v1.workflow w ON w.id = s.workflow_id
280
- WHERE s.workflow_id = $1
281
- AND w.project_id = $2
282
- ORDER BY s.stage`;
283
- async function listWorkflowStageStates(client, args) {
861
+ exports.insertWorkflowRunEventQuery = `-- name: InsertWorkflowRunEvent :one
862
+ INSERT INTO weave.workflow_run_events (
863
+ id,
864
+ organization_id,
865
+ workflow_run_id,
866
+ workflow_step_run_id,
867
+ agent_run_id,
868
+ sequence,
869
+ kind,
870
+ message,
871
+ payload
872
+ ) VALUES (
873
+ $1,
874
+ $2,
875
+ $3,
876
+ $4::uuid,
877
+ $5::uuid,
878
+ $6,
879
+ $7,
880
+ $8,
881
+ $9
882
+ )
883
+ RETURNING id, organization_id, workflow_run_id, workflow_step_run_id, agent_run_id, sequence, kind, message, payload, created_at`;
884
+ async function insertWorkflowRunEvent(client, args) {
284
885
  const result = await client.query({
285
- text: exports.listWorkflowStageStatesQuery,
286
- values: [args.workflowId, args.projectId],
886
+ text: exports.insertWorkflowRunEventQuery,
887
+ values: [args.id, args.organizationId, args.workflowRunId, args.workflowStepRunId, args.agentRunId, args.sequence, args.kind, args.message, args.payload],
888
+ rowMode: "array"
889
+ });
890
+ if (result.rows.length !== 1) {
891
+ return null;
892
+ }
893
+ const row = result.rows[0];
894
+ return {
895
+ id: row[0],
896
+ organizationId: row[1],
897
+ workflowRunId: row[2],
898
+ workflowStepRunId: row[3],
899
+ agentRunId: row[4],
900
+ sequence: row[5],
901
+ kind: row[6],
902
+ message: row[7],
903
+ payload: row[8],
904
+ createdAt: row[9]
905
+ };
906
+ }
907
+ exports.listWorkflowRunEventsQuery = `-- name: ListWorkflowRunEvents :many
908
+ SELECT id, organization_id, workflow_run_id, workflow_step_run_id, agent_run_id, sequence, kind, message, payload, created_at FROM weave.workflow_run_events
909
+ WHERE organization_id = $1
910
+ AND workflow_run_id = $2
911
+ AND sequence > $3
912
+ ORDER BY sequence
913
+ LIMIT $4`;
914
+ async function listWorkflowRunEvents(client, args) {
915
+ const result = await client.query({
916
+ text: exports.listWorkflowRunEventsQuery,
917
+ values: [args.organizationId, args.workflowRunId, args.afterSequence, args.pageSize],
287
918
  rowMode: "array"
288
919
  });
289
920
  return result.rows.map(row => {
290
921
  return {
291
- workflowId: row[0],
292
- stage: row[1],
293
- status: row[2],
294
- blockedReason: row[3],
295
- updatedAt: row[4]
922
+ id: row[0],
923
+ organizationId: row[1],
924
+ workflowRunId: row[2],
925
+ workflowStepRunId: row[3],
926
+ agentRunId: row[4],
927
+ sequence: row[5],
928
+ kind: row[6],
929
+ message: row[7],
930
+ payload: row[8],
931
+ createdAt: row[9]
932
+ };
933
+ });
934
+ }
935
+ exports.insertToolCallEventQuery = `-- name: InsertToolCallEvent :one
936
+ INSERT INTO weave.tool_call_events (
937
+ id,
938
+ organization_id,
939
+ workflow_run_id,
940
+ workflow_step_run_id,
941
+ agent_run_id,
942
+ tool_call_id,
943
+ tool_name,
944
+ state,
945
+ arguments,
946
+ result,
947
+ error_code,
948
+ safe_error_message
949
+ ) VALUES (
950
+ $1,
951
+ $2,
952
+ $3::uuid,
953
+ $4::uuid,
954
+ $5::uuid,
955
+ $6,
956
+ $7,
957
+ $8,
958
+ $9,
959
+ $10,
960
+ $11,
961
+ $12
962
+ )
963
+ RETURNING id, organization_id, workflow_run_id, workflow_step_run_id, agent_run_id, tool_call_id, tool_name, state, arguments, result, error_code, safe_error_message, created_at`;
964
+ async function insertToolCallEvent(client, args) {
965
+ const result = await client.query({
966
+ text: exports.insertToolCallEventQuery,
967
+ values: [args.id, args.organizationId, args.workflowRunId, args.workflowStepRunId, args.agentRunId, args.toolCallId, args.toolName, args.state, args.arguments, args.result, args.errorCode, args.safeErrorMessage],
968
+ rowMode: "array"
969
+ });
970
+ if (result.rows.length !== 1) {
971
+ return null;
972
+ }
973
+ const row = result.rows[0];
974
+ return {
975
+ id: row[0],
976
+ organizationId: row[1],
977
+ workflowRunId: row[2],
978
+ workflowStepRunId: row[3],
979
+ agentRunId: row[4],
980
+ toolCallId: row[5],
981
+ toolName: row[6],
982
+ state: row[7],
983
+ arguments: row[8],
984
+ result: row[9],
985
+ errorCode: row[10],
986
+ safeErrorMessage: row[11],
987
+ createdAt: row[12]
988
+ };
989
+ }
990
+ exports.listToolCallEventsQuery = `-- name: ListToolCallEvents :many
991
+ SELECT id, organization_id, workflow_run_id, workflow_step_run_id, agent_run_id, tool_call_id, tool_name, state, arguments, result, error_code, safe_error_message, created_at FROM weave.tool_call_events
992
+ WHERE organization_id = $1
993
+ AND (
994
+ $2::uuid IS NULL
995
+ OR workflow_run_id = $2::uuid
996
+ )
997
+ AND (
998
+ $3::uuid IS NULL
999
+ OR agent_run_id = $3::uuid
1000
+ )
1001
+ ORDER BY created_at
1002
+ LIMIT $5 OFFSET $4`;
1003
+ async function listToolCallEvents(client, args) {
1004
+ const result = await client.query({
1005
+ text: exports.listToolCallEventsQuery,
1006
+ values: [args.organizationId, args.workflowRunId, args.agentRunId, args.pageOffset, args.pageSize],
1007
+ rowMode: "array"
1008
+ });
1009
+ return result.rows.map(row => {
1010
+ return {
1011
+ id: row[0],
1012
+ organizationId: row[1],
1013
+ workflowRunId: row[2],
1014
+ workflowStepRunId: row[3],
1015
+ agentRunId: row[4],
1016
+ toolCallId: row[5],
1017
+ toolName: row[6],
1018
+ state: row[7],
1019
+ arguments: row[8],
1020
+ result: row[9],
1021
+ errorCode: row[10],
1022
+ safeErrorMessage: row[11],
1023
+ createdAt: row[12]
296
1024
  };
297
1025
  });
298
1026
  }