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.
@@ -0,0 +1,844 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listAgentRunEventsQuery = exports.insertAgentRunEventQuery = exports.updateAgentRunStatusQuery = exports.listAgentRunsQuery = exports.getAgentRunQuery = exports.createAgentRunQuery = exports.listAgentTemplateVersionsQuery = exports.getAgentTemplateVersionByIDQuery = exports.getAgentTemplateVersionByNumberQuery = exports.setAgentTemplateLatestVersionQuery = exports.insertAgentTemplateVersionQuery = exports.insertAgentDraftPatchQuery = exports.updateAgentDraftQuery = exports.updateAgentTemplateStatusQuery = exports.updateAgentTemplateDraftMetadataQuery = exports.listAgentTemplatesQuery = exports.getAgentTemplateDraftQuery = exports.getAgentTemplateBySlugQuery = exports.getAgentTemplateByIDQuery = exports.createAgentTemplateDraftQuery = exports.createAgentTemplateQuery = void 0;
4
+ exports.createAgentTemplate = createAgentTemplate;
5
+ exports.createAgentTemplateDraft = createAgentTemplateDraft;
6
+ exports.getAgentTemplateByID = getAgentTemplateByID;
7
+ exports.getAgentTemplateBySlug = getAgentTemplateBySlug;
8
+ exports.getAgentTemplateDraft = getAgentTemplateDraft;
9
+ exports.listAgentTemplates = listAgentTemplates;
10
+ exports.updateAgentTemplateDraftMetadata = updateAgentTemplateDraftMetadata;
11
+ exports.updateAgentTemplateStatus = updateAgentTemplateStatus;
12
+ exports.updateAgentDraft = updateAgentDraft;
13
+ exports.insertAgentDraftPatch = insertAgentDraftPatch;
14
+ exports.insertAgentTemplateVersion = insertAgentTemplateVersion;
15
+ exports.setAgentTemplateLatestVersion = setAgentTemplateLatestVersion;
16
+ exports.getAgentTemplateVersionByNumber = getAgentTemplateVersionByNumber;
17
+ exports.getAgentTemplateVersionByID = getAgentTemplateVersionByID;
18
+ exports.listAgentTemplateVersions = listAgentTemplateVersions;
19
+ exports.createAgentRun = createAgentRun;
20
+ exports.getAgentRun = getAgentRun;
21
+ exports.listAgentRuns = listAgentRuns;
22
+ exports.updateAgentRunStatus = updateAgentRunStatus;
23
+ exports.insertAgentRunEvent = insertAgentRunEvent;
24
+ exports.listAgentRunEvents = listAgentRunEvents;
25
+ exports.createAgentTemplateQuery = `-- name: CreateAgentTemplate :one
26
+ INSERT INTO weave.agent_templates (
27
+ id,
28
+ organization_id,
29
+ slug,
30
+ name,
31
+ description,
32
+ status,
33
+ created_by_user_id
34
+ ) VALUES (
35
+ $1,
36
+ $2,
37
+ $3,
38
+ $4,
39
+ $5,
40
+ $6,
41
+ $7
42
+ )
43
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
44
+ async function createAgentTemplate(client, args) {
45
+ const result = await client.query({
46
+ text: exports.createAgentTemplateQuery,
47
+ values: [args.id, args.organizationId, args.slug, args.name, args.description, args.status, args.createdByUserId],
48
+ rowMode: "array"
49
+ });
50
+ if (result.rows.length !== 1) {
51
+ return null;
52
+ }
53
+ const row = result.rows[0];
54
+ return {
55
+ id: row[0],
56
+ organizationId: row[1],
57
+ slug: row[2],
58
+ name: row[3],
59
+ description: row[4],
60
+ status: row[5],
61
+ createdByUserId: row[6],
62
+ draftRevision: row[7],
63
+ latestVersionId: row[8],
64
+ latestVersion: row[9],
65
+ createdAt: row[10],
66
+ updatedAt: row[11]
67
+ };
68
+ }
69
+ exports.createAgentTemplateDraftQuery = `-- name: CreateAgentTemplateDraft :one
70
+ INSERT INTO weave.agent_template_drafts (
71
+ id,
72
+ template_id,
73
+ organization_id,
74
+ base_version_id,
75
+ revision,
76
+ name,
77
+ description,
78
+ instructions,
79
+ model_id,
80
+ provider_configuration_id,
81
+ tool_descriptors,
82
+ input_schema,
83
+ output_schema,
84
+ metadata,
85
+ updated_by_user_id
86
+ ) VALUES (
87
+ $1,
88
+ $2,
89
+ $3,
90
+ $4::uuid,
91
+ $5,
92
+ $6,
93
+ $7,
94
+ $8,
95
+ $9,
96
+ $10::uuid,
97
+ $11,
98
+ $12,
99
+ $13,
100
+ $14,
101
+ $15
102
+ )
103
+ RETURNING id, template_id, organization_id, base_version_id, revision, name, description, instructions, model_id, provider_configuration_id, tool_descriptors, input_schema, output_schema, metadata, updated_by_user_id, created_at, updated_at`;
104
+ async function createAgentTemplateDraft(client, args) {
105
+ const result = await client.query({
106
+ text: exports.createAgentTemplateDraftQuery,
107
+ values: [args.id, args.templateId, args.organizationId, args.baseVersionId, args.revision, args.name, args.description, args.instructions, args.modelId, args.providerConfigurationId, args.toolDescriptors, args.inputSchema, args.outputSchema, args.metadata, args.updatedByUserId],
108
+ rowMode: "array"
109
+ });
110
+ if (result.rows.length !== 1) {
111
+ return null;
112
+ }
113
+ const row = result.rows[0];
114
+ return {
115
+ id: row[0],
116
+ templateId: row[1],
117
+ organizationId: row[2],
118
+ baseVersionId: row[3],
119
+ revision: row[4],
120
+ name: row[5],
121
+ description: row[6],
122
+ instructions: row[7],
123
+ modelId: row[8],
124
+ providerConfigurationId: row[9],
125
+ toolDescriptors: row[10],
126
+ inputSchema: row[11],
127
+ outputSchema: row[12],
128
+ metadata: row[13],
129
+ updatedByUserId: row[14],
130
+ createdAt: row[15],
131
+ updatedAt: row[16]
132
+ };
133
+ }
134
+ exports.getAgentTemplateByIDQuery = `-- name: GetAgentTemplateByID :one
135
+ 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.agent_templates
136
+ WHERE organization_id = $1
137
+ AND id = $2`;
138
+ async function getAgentTemplateByID(client, args) {
139
+ const result = await client.query({
140
+ text: exports.getAgentTemplateByIDQuery,
141
+ values: [args.organizationId, args.templateId],
142
+ rowMode: "array"
143
+ });
144
+ if (result.rows.length !== 1) {
145
+ return null;
146
+ }
147
+ const row = result.rows[0];
148
+ return {
149
+ id: row[0],
150
+ organizationId: row[1],
151
+ slug: row[2],
152
+ name: row[3],
153
+ description: row[4],
154
+ status: row[5],
155
+ createdByUserId: row[6],
156
+ draftRevision: row[7],
157
+ latestVersionId: row[8],
158
+ latestVersion: row[9],
159
+ createdAt: row[10],
160
+ updatedAt: row[11]
161
+ };
162
+ }
163
+ exports.getAgentTemplateBySlugQuery = `-- name: GetAgentTemplateBySlug :one
164
+ 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.agent_templates
165
+ WHERE organization_id = $1
166
+ AND slug = $2`;
167
+ async function getAgentTemplateBySlug(client, args) {
168
+ const result = await client.query({
169
+ text: exports.getAgentTemplateBySlugQuery,
170
+ values: [args.organizationId, args.slug],
171
+ rowMode: "array"
172
+ });
173
+ if (result.rows.length !== 1) {
174
+ return null;
175
+ }
176
+ const row = result.rows[0];
177
+ return {
178
+ id: row[0],
179
+ organizationId: row[1],
180
+ slug: row[2],
181
+ name: row[3],
182
+ description: row[4],
183
+ status: row[5],
184
+ createdByUserId: row[6],
185
+ draftRevision: row[7],
186
+ latestVersionId: row[8],
187
+ latestVersion: row[9],
188
+ createdAt: row[10],
189
+ updatedAt: row[11]
190
+ };
191
+ }
192
+ exports.getAgentTemplateDraftQuery = `-- name: GetAgentTemplateDraft :one
193
+ SELECT id, template_id, organization_id, base_version_id, revision, name, description, instructions, model_id, provider_configuration_id, tool_descriptors, input_schema, output_schema, metadata, updated_by_user_id, created_at, updated_at FROM weave.agent_template_drafts
194
+ WHERE organization_id = $1
195
+ AND template_id = $2`;
196
+ async function getAgentTemplateDraft(client, args) {
197
+ const result = await client.query({
198
+ text: exports.getAgentTemplateDraftQuery,
199
+ values: [args.organizationId, args.templateId],
200
+ rowMode: "array"
201
+ });
202
+ if (result.rows.length !== 1) {
203
+ return null;
204
+ }
205
+ const row = result.rows[0];
206
+ return {
207
+ id: row[0],
208
+ templateId: row[1],
209
+ organizationId: row[2],
210
+ baseVersionId: row[3],
211
+ revision: row[4],
212
+ name: row[5],
213
+ description: row[6],
214
+ instructions: row[7],
215
+ modelId: row[8],
216
+ providerConfigurationId: row[9],
217
+ toolDescriptors: row[10],
218
+ inputSchema: row[11],
219
+ outputSchema: row[12],
220
+ metadata: row[13],
221
+ updatedByUserId: row[14],
222
+ createdAt: row[15],
223
+ updatedAt: row[16]
224
+ };
225
+ }
226
+ exports.listAgentTemplatesQuery = `-- name: ListAgentTemplates :many
227
+ 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.agent_templates
228
+ WHERE organization_id = $1
229
+ AND (
230
+ $2::text IS NULL
231
+ OR status = $2::text
232
+ )
233
+ ORDER BY updated_at DESC, created_at DESC
234
+ LIMIT $4 OFFSET $3`;
235
+ async function listAgentTemplates(client, args) {
236
+ const result = await client.query({
237
+ text: exports.listAgentTemplatesQuery,
238
+ values: [args.organizationId, args.status, args.pageOffset, args.pageSize],
239
+ rowMode: "array"
240
+ });
241
+ return result.rows.map(row => {
242
+ return {
243
+ id: row[0],
244
+ organizationId: row[1],
245
+ slug: row[2],
246
+ name: row[3],
247
+ description: row[4],
248
+ status: row[5],
249
+ createdByUserId: row[6],
250
+ draftRevision: row[7],
251
+ latestVersionId: row[8],
252
+ latestVersion: row[9],
253
+ createdAt: row[10],
254
+ updatedAt: row[11]
255
+ };
256
+ });
257
+ }
258
+ exports.updateAgentTemplateDraftMetadataQuery = `-- name: UpdateAgentTemplateDraftMetadata :one
259
+ UPDATE weave.agent_templates
260
+ SET
261
+ name = $1,
262
+ description = $2,
263
+ draft_revision = $3,
264
+ updated_at = now()
265
+ WHERE organization_id = $4
266
+ AND id = $5
267
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
268
+ async function updateAgentTemplateDraftMetadata(client, args) {
269
+ const result = await client.query({
270
+ text: exports.updateAgentTemplateDraftMetadataQuery,
271
+ values: [args.name, args.description, args.draftRevision, args.organizationId, args.templateId],
272
+ rowMode: "array"
273
+ });
274
+ if (result.rows.length !== 1) {
275
+ return null;
276
+ }
277
+ const row = result.rows[0];
278
+ return {
279
+ id: row[0],
280
+ organizationId: row[1],
281
+ slug: row[2],
282
+ name: row[3],
283
+ description: row[4],
284
+ status: row[5],
285
+ createdByUserId: row[6],
286
+ draftRevision: row[7],
287
+ latestVersionId: row[8],
288
+ latestVersion: row[9],
289
+ createdAt: row[10],
290
+ updatedAt: row[11]
291
+ };
292
+ }
293
+ exports.updateAgentTemplateStatusQuery = `-- name: UpdateAgentTemplateStatus :one
294
+ UPDATE weave.agent_templates
295
+ SET
296
+ status = $1,
297
+ updated_at = now()
298
+ WHERE organization_id = $2
299
+ AND id = $3
300
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
301
+ async function updateAgentTemplateStatus(client, args) {
302
+ const result = await client.query({
303
+ text: exports.updateAgentTemplateStatusQuery,
304
+ values: [args.status, args.organizationId, args.templateId],
305
+ rowMode: "array"
306
+ });
307
+ if (result.rows.length !== 1) {
308
+ return null;
309
+ }
310
+ const row = result.rows[0];
311
+ return {
312
+ id: row[0],
313
+ organizationId: row[1],
314
+ slug: row[2],
315
+ name: row[3],
316
+ description: row[4],
317
+ status: row[5],
318
+ createdByUserId: row[6],
319
+ draftRevision: row[7],
320
+ latestVersionId: row[8],
321
+ latestVersion: row[9],
322
+ createdAt: row[10],
323
+ updatedAt: row[11]
324
+ };
325
+ }
326
+ exports.updateAgentDraftQuery = `-- name: UpdateAgentDraft :one
327
+ UPDATE weave.agent_template_drafts
328
+ SET
329
+ base_version_id = $1::uuid,
330
+ revision = revision + 1,
331
+ name = $2,
332
+ description = $3,
333
+ instructions = $4,
334
+ model_id = $5,
335
+ provider_configuration_id = $6::uuid,
336
+ tool_descriptors = $7,
337
+ input_schema = $8,
338
+ output_schema = $9,
339
+ metadata = $10,
340
+ updated_by_user_id = $11,
341
+ updated_at = now()
342
+ WHERE organization_id = $12
343
+ AND template_id = $13
344
+ AND revision = $14
345
+ RETURNING id, template_id, organization_id, base_version_id, revision, name, description, instructions, model_id, provider_configuration_id, tool_descriptors, input_schema, output_schema, metadata, updated_by_user_id, created_at, updated_at`;
346
+ async function updateAgentDraft(client, args) {
347
+ const result = await client.query({
348
+ text: exports.updateAgentDraftQuery,
349
+ values: [args.baseVersionId, args.name, args.description, args.instructions, args.modelId, args.providerConfigurationId, args.toolDescriptors, args.inputSchema, args.outputSchema, args.metadata, args.updatedByUserId, args.organizationId, args.templateId, args.expectedRevision],
350
+ rowMode: "array"
351
+ });
352
+ if (result.rows.length !== 1) {
353
+ return null;
354
+ }
355
+ const row = result.rows[0];
356
+ return {
357
+ id: row[0],
358
+ templateId: row[1],
359
+ organizationId: row[2],
360
+ baseVersionId: row[3],
361
+ revision: row[4],
362
+ name: row[5],
363
+ description: row[6],
364
+ instructions: row[7],
365
+ modelId: row[8],
366
+ providerConfigurationId: row[9],
367
+ toolDescriptors: row[10],
368
+ inputSchema: row[11],
369
+ outputSchema: row[12],
370
+ metadata: row[13],
371
+ updatedByUserId: row[14],
372
+ createdAt: row[15],
373
+ updatedAt: row[16]
374
+ };
375
+ }
376
+ exports.insertAgentDraftPatchQuery = `-- name: InsertAgentDraftPatch :one
377
+ INSERT INTO weave.agent_template_draft_patches (
378
+ id,
379
+ template_id,
380
+ organization_id,
381
+ revision,
382
+ patch,
383
+ created_by_user_id
384
+ ) VALUES (
385
+ $1,
386
+ $2,
387
+ $3,
388
+ $4,
389
+ $5,
390
+ $6
391
+ )
392
+ RETURNING id, template_id, organization_id, revision, patch, created_by_user_id, created_at`;
393
+ async function insertAgentDraftPatch(client, args) {
394
+ const result = await client.query({
395
+ text: exports.insertAgentDraftPatchQuery,
396
+ values: [args.id, args.templateId, args.organizationId, args.revision, args.patch, args.createdByUserId],
397
+ rowMode: "array"
398
+ });
399
+ if (result.rows.length !== 1) {
400
+ return null;
401
+ }
402
+ const row = result.rows[0];
403
+ return {
404
+ id: row[0],
405
+ templateId: row[1],
406
+ organizationId: row[2],
407
+ revision: row[3],
408
+ patch: row[4],
409
+ createdByUserId: row[5],
410
+ createdAt: row[6]
411
+ };
412
+ }
413
+ exports.insertAgentTemplateVersionQuery = `-- name: InsertAgentTemplateVersion :one
414
+ INSERT INTO weave.agent_template_versions (
415
+ id,
416
+ template_id,
417
+ organization_id,
418
+ version,
419
+ source_draft_revision,
420
+ name,
421
+ description,
422
+ instructions,
423
+ model_id,
424
+ provider_configuration_id,
425
+ tool_descriptors,
426
+ input_schema,
427
+ output_schema,
428
+ metadata,
429
+ published_by_user_id
430
+ ) VALUES (
431
+ $1,
432
+ $2,
433
+ $3,
434
+ $4,
435
+ $5,
436
+ $6,
437
+ $7,
438
+ $8,
439
+ $9,
440
+ $10::uuid,
441
+ $11,
442
+ $12,
443
+ $13,
444
+ $14,
445
+ $15
446
+ )
447
+ RETURNING id, template_id, organization_id, version, source_draft_revision, name, description, instructions, model_id, provider_configuration_id, tool_descriptors, input_schema, output_schema, metadata, published_by_user_id, published_at`;
448
+ async function insertAgentTemplateVersion(client, args) {
449
+ const result = await client.query({
450
+ text: exports.insertAgentTemplateVersionQuery,
451
+ values: [args.id, args.templateId, args.organizationId, args.version, args.sourceDraftRevision, args.name, args.description, args.instructions, args.modelId, args.providerConfigurationId, args.toolDescriptors, args.inputSchema, args.outputSchema, args.metadata, args.publishedByUserId],
452
+ rowMode: "array"
453
+ });
454
+ if (result.rows.length !== 1) {
455
+ return null;
456
+ }
457
+ const row = result.rows[0];
458
+ return {
459
+ id: row[0],
460
+ templateId: row[1],
461
+ organizationId: row[2],
462
+ version: row[3],
463
+ sourceDraftRevision: row[4],
464
+ name: row[5],
465
+ description: row[6],
466
+ instructions: row[7],
467
+ modelId: row[8],
468
+ providerConfigurationId: row[9],
469
+ toolDescriptors: row[10],
470
+ inputSchema: row[11],
471
+ outputSchema: row[12],
472
+ metadata: row[13],
473
+ publishedByUserId: row[14],
474
+ publishedAt: row[15]
475
+ };
476
+ }
477
+ exports.setAgentTemplateLatestVersionQuery = `-- name: SetAgentTemplateLatestVersion :one
478
+ UPDATE weave.agent_templates
479
+ SET
480
+ latest_version_id = $1,
481
+ latest_version = $2,
482
+ updated_at = now()
483
+ WHERE organization_id = $3
484
+ AND id = $4
485
+ RETURNING id, organization_id, slug, name, description, status, created_by_user_id, draft_revision, latest_version_id, latest_version, created_at, updated_at`;
486
+ async function setAgentTemplateLatestVersion(client, args) {
487
+ const result = await client.query({
488
+ text: exports.setAgentTemplateLatestVersionQuery,
489
+ values: [args.versionId, args.version, args.organizationId, args.templateId],
490
+ rowMode: "array"
491
+ });
492
+ if (result.rows.length !== 1) {
493
+ return null;
494
+ }
495
+ const row = result.rows[0];
496
+ return {
497
+ id: row[0],
498
+ organizationId: row[1],
499
+ slug: row[2],
500
+ name: row[3],
501
+ description: row[4],
502
+ status: row[5],
503
+ createdByUserId: row[6],
504
+ draftRevision: row[7],
505
+ latestVersionId: row[8],
506
+ latestVersion: row[9],
507
+ createdAt: row[10],
508
+ updatedAt: row[11]
509
+ };
510
+ }
511
+ exports.getAgentTemplateVersionByNumberQuery = `-- name: GetAgentTemplateVersionByNumber :one
512
+ SELECT id, template_id, organization_id, version, source_draft_revision, name, description, instructions, model_id, provider_configuration_id, tool_descriptors, input_schema, output_schema, metadata, published_by_user_id, published_at FROM weave.agent_template_versions
513
+ WHERE organization_id = $1
514
+ AND template_id = $2
515
+ AND version = $3`;
516
+ async function getAgentTemplateVersionByNumber(client, args) {
517
+ const result = await client.query({
518
+ text: exports.getAgentTemplateVersionByNumberQuery,
519
+ values: [args.organizationId, args.templateId, args.version],
520
+ rowMode: "array"
521
+ });
522
+ if (result.rows.length !== 1) {
523
+ return null;
524
+ }
525
+ const row = result.rows[0];
526
+ return {
527
+ id: row[0],
528
+ templateId: row[1],
529
+ organizationId: row[2],
530
+ version: row[3],
531
+ sourceDraftRevision: row[4],
532
+ name: row[5],
533
+ description: row[6],
534
+ instructions: row[7],
535
+ modelId: row[8],
536
+ providerConfigurationId: row[9],
537
+ toolDescriptors: row[10],
538
+ inputSchema: row[11],
539
+ outputSchema: row[12],
540
+ metadata: row[13],
541
+ publishedByUserId: row[14],
542
+ publishedAt: row[15]
543
+ };
544
+ }
545
+ exports.getAgentTemplateVersionByIDQuery = `-- name: GetAgentTemplateVersionByID :one
546
+ SELECT id, template_id, organization_id, version, source_draft_revision, name, description, instructions, model_id, provider_configuration_id, tool_descriptors, input_schema, output_schema, metadata, published_by_user_id, published_at FROM weave.agent_template_versions
547
+ WHERE organization_id = $1
548
+ AND id = $2`;
549
+ async function getAgentTemplateVersionByID(client, args) {
550
+ const result = await client.query({
551
+ text: exports.getAgentTemplateVersionByIDQuery,
552
+ values: [args.organizationId, args.versionId],
553
+ rowMode: "array"
554
+ });
555
+ if (result.rows.length !== 1) {
556
+ return null;
557
+ }
558
+ const row = result.rows[0];
559
+ return {
560
+ id: row[0],
561
+ templateId: row[1],
562
+ organizationId: row[2],
563
+ version: row[3],
564
+ sourceDraftRevision: row[4],
565
+ name: row[5],
566
+ description: row[6],
567
+ instructions: row[7],
568
+ modelId: row[8],
569
+ providerConfigurationId: row[9],
570
+ toolDescriptors: row[10],
571
+ inputSchema: row[11],
572
+ outputSchema: row[12],
573
+ metadata: row[13],
574
+ publishedByUserId: row[14],
575
+ publishedAt: row[15]
576
+ };
577
+ }
578
+ exports.listAgentTemplateVersionsQuery = `-- name: ListAgentTemplateVersions :many
579
+ SELECT id, template_id, organization_id, version, source_draft_revision, name, description, instructions, model_id, provider_configuration_id, tool_descriptors, input_schema, output_schema, metadata, published_by_user_id, published_at FROM weave.agent_template_versions
580
+ WHERE organization_id = $1
581
+ AND template_id = $2
582
+ ORDER BY version DESC
583
+ LIMIT $4 OFFSET $3`;
584
+ async function listAgentTemplateVersions(client, args) {
585
+ const result = await client.query({
586
+ text: exports.listAgentTemplateVersionsQuery,
587
+ values: [args.organizationId, args.templateId, args.pageOffset, args.pageSize],
588
+ rowMode: "array"
589
+ });
590
+ return result.rows.map(row => {
591
+ return {
592
+ id: row[0],
593
+ templateId: row[1],
594
+ organizationId: row[2],
595
+ version: row[3],
596
+ sourceDraftRevision: row[4],
597
+ name: row[5],
598
+ description: row[6],
599
+ instructions: row[7],
600
+ modelId: row[8],
601
+ providerConfigurationId: row[9],
602
+ toolDescriptors: row[10],
603
+ inputSchema: row[11],
604
+ outputSchema: row[12],
605
+ metadata: row[13],
606
+ publishedByUserId: row[14],
607
+ publishedAt: row[15]
608
+ };
609
+ });
610
+ }
611
+ exports.createAgentRunQuery = `-- name: CreateAgentRun :one
612
+ INSERT INTO weave.agent_runs (
613
+ id,
614
+ organization_id,
615
+ agent_template_id,
616
+ agent_version_id,
617
+ status,
618
+ created_by_user_id,
619
+ chat_session_id,
620
+ workflow_run_id,
621
+ workflow_step_run_id,
622
+ input
623
+ ) VALUES (
624
+ $1,
625
+ $2,
626
+ $3,
627
+ $4,
628
+ $5,
629
+ $6,
630
+ $7::uuid,
631
+ $8::uuid,
632
+ $9::uuid,
633
+ $10
634
+ )
635
+ RETURNING id, organization_id, agent_template_id, agent_version_id, status, created_by_user_id, chat_session_id, workflow_run_id, workflow_step_run_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at`;
636
+ async function createAgentRun(client, args) {
637
+ const result = await client.query({
638
+ text: exports.createAgentRunQuery,
639
+ values: [args.id, args.organizationId, args.agentTemplateId, args.agentVersionId, args.status, args.createdByUserId, args.chatSessionId, args.workflowRunId, args.workflowStepRunId, args.input],
640
+ rowMode: "array"
641
+ });
642
+ if (result.rows.length !== 1) {
643
+ return null;
644
+ }
645
+ const row = result.rows[0];
646
+ return {
647
+ id: row[0],
648
+ organizationId: row[1],
649
+ agentTemplateId: row[2],
650
+ agentVersionId: row[3],
651
+ status: row[4],
652
+ createdByUserId: row[5],
653
+ chatSessionId: row[6],
654
+ workflowRunId: row[7],
655
+ workflowStepRunId: row[8],
656
+ input: row[9],
657
+ output: row[10],
658
+ errorCode: row[11],
659
+ safeErrorMessage: row[12],
660
+ createdAt: row[13],
661
+ startedAt: row[14],
662
+ finishedAt: row[15]
663
+ };
664
+ }
665
+ exports.getAgentRunQuery = `-- name: GetAgentRun :one
666
+ SELECT id, organization_id, agent_template_id, agent_version_id, status, created_by_user_id, chat_session_id, workflow_run_id, workflow_step_run_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at FROM weave.agent_runs
667
+ WHERE organization_id = $1
668
+ AND id = $2`;
669
+ async function getAgentRun(client, args) {
670
+ const result = await client.query({
671
+ text: exports.getAgentRunQuery,
672
+ values: [args.organizationId, args.agentRunId],
673
+ rowMode: "array"
674
+ });
675
+ if (result.rows.length !== 1) {
676
+ return null;
677
+ }
678
+ const row = result.rows[0];
679
+ return {
680
+ id: row[0],
681
+ organizationId: row[1],
682
+ agentTemplateId: row[2],
683
+ agentVersionId: row[3],
684
+ status: row[4],
685
+ createdByUserId: row[5],
686
+ chatSessionId: row[6],
687
+ workflowRunId: row[7],
688
+ workflowStepRunId: row[8],
689
+ input: row[9],
690
+ output: row[10],
691
+ errorCode: row[11],
692
+ safeErrorMessage: row[12],
693
+ createdAt: row[13],
694
+ startedAt: row[14],
695
+ finishedAt: row[15]
696
+ };
697
+ }
698
+ exports.listAgentRunsQuery = `-- name: ListAgentRuns :many
699
+ SELECT id, organization_id, agent_template_id, agent_version_id, status, created_by_user_id, chat_session_id, workflow_run_id, workflow_step_run_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at FROM weave.agent_runs
700
+ WHERE organization_id = $1
701
+ AND (
702
+ $2::uuid IS NULL
703
+ OR agent_template_id = $2::uuid
704
+ )
705
+ AND (
706
+ $3::text IS NULL
707
+ OR status = $3::text
708
+ )
709
+ ORDER BY created_at DESC
710
+ LIMIT $5 OFFSET $4`;
711
+ async function listAgentRuns(client, args) {
712
+ const result = await client.query({
713
+ text: exports.listAgentRunsQuery,
714
+ values: [args.organizationId, args.agentTemplateId, args.status, args.pageOffset, args.pageSize],
715
+ rowMode: "array"
716
+ });
717
+ return result.rows.map(row => {
718
+ return {
719
+ id: row[0],
720
+ organizationId: row[1],
721
+ agentTemplateId: row[2],
722
+ agentVersionId: row[3],
723
+ status: row[4],
724
+ createdByUserId: row[5],
725
+ chatSessionId: row[6],
726
+ workflowRunId: row[7],
727
+ workflowStepRunId: row[8],
728
+ input: row[9],
729
+ output: row[10],
730
+ errorCode: row[11],
731
+ safeErrorMessage: row[12],
732
+ createdAt: row[13],
733
+ startedAt: row[14],
734
+ finishedAt: row[15]
735
+ };
736
+ });
737
+ }
738
+ exports.updateAgentRunStatusQuery = `-- name: UpdateAgentRunStatus :one
739
+ UPDATE weave.agent_runs
740
+ SET
741
+ status = $1,
742
+ output = $2,
743
+ error_code = $3,
744
+ safe_error_message = $4,
745
+ started_at = COALESCE(started_at, $5::timestamptz),
746
+ finished_at = $6::timestamptz
747
+ WHERE organization_id = $7
748
+ AND id = $8
749
+ RETURNING id, organization_id, agent_template_id, agent_version_id, status, created_by_user_id, chat_session_id, workflow_run_id, workflow_step_run_id, input, output, error_code, safe_error_message, created_at, started_at, finished_at`;
750
+ async function updateAgentRunStatus(client, args) {
751
+ const result = await client.query({
752
+ text: exports.updateAgentRunStatusQuery,
753
+ values: [args.status, args.output, args.errorCode, args.safeErrorMessage, args.startedAt, args.finishedAt, args.organizationId, args.agentRunId],
754
+ rowMode: "array"
755
+ });
756
+ if (result.rows.length !== 1) {
757
+ return null;
758
+ }
759
+ const row = result.rows[0];
760
+ return {
761
+ id: row[0],
762
+ organizationId: row[1],
763
+ agentTemplateId: row[2],
764
+ agentVersionId: row[3],
765
+ status: row[4],
766
+ createdByUserId: row[5],
767
+ chatSessionId: row[6],
768
+ workflowRunId: row[7],
769
+ workflowStepRunId: row[8],
770
+ input: row[9],
771
+ output: row[10],
772
+ errorCode: row[11],
773
+ safeErrorMessage: row[12],
774
+ createdAt: row[13],
775
+ startedAt: row[14],
776
+ finishedAt: row[15]
777
+ };
778
+ }
779
+ exports.insertAgentRunEventQuery = `-- name: InsertAgentRunEvent :one
780
+ INSERT INTO weave.agent_run_events (
781
+ id,
782
+ organization_id,
783
+ agent_run_id,
784
+ sequence,
785
+ kind,
786
+ message,
787
+ payload
788
+ ) VALUES (
789
+ $1,
790
+ $2,
791
+ $3,
792
+ $4,
793
+ $5,
794
+ $6,
795
+ $7
796
+ )
797
+ RETURNING id, organization_id, agent_run_id, sequence, kind, message, payload, created_at`;
798
+ async function insertAgentRunEvent(client, args) {
799
+ const result = await client.query({
800
+ text: exports.insertAgentRunEventQuery,
801
+ values: [args.id, args.organizationId, args.agentRunId, args.sequence, args.kind, args.message, args.payload],
802
+ rowMode: "array"
803
+ });
804
+ if (result.rows.length !== 1) {
805
+ return null;
806
+ }
807
+ const row = result.rows[0];
808
+ return {
809
+ id: row[0],
810
+ organizationId: row[1],
811
+ agentRunId: row[2],
812
+ sequence: row[3],
813
+ kind: row[4],
814
+ message: row[5],
815
+ payload: row[6],
816
+ createdAt: row[7]
817
+ };
818
+ }
819
+ exports.listAgentRunEventsQuery = `-- name: ListAgentRunEvents :many
820
+ SELECT id, organization_id, agent_run_id, sequence, kind, message, payload, created_at FROM weave.agent_run_events
821
+ WHERE organization_id = $1
822
+ AND agent_run_id = $2
823
+ AND sequence > $3
824
+ ORDER BY sequence
825
+ LIMIT $4`;
826
+ async function listAgentRunEvents(client, args) {
827
+ const result = await client.query({
828
+ text: exports.listAgentRunEventsQuery,
829
+ values: [args.organizationId, args.agentRunId, args.afterSequence, args.pageSize],
830
+ rowMode: "array"
831
+ });
832
+ return result.rows.map(row => {
833
+ return {
834
+ id: row[0],
835
+ organizationId: row[1],
836
+ agentRunId: row[2],
837
+ sequence: row[3],
838
+ kind: row[4],
839
+ message: row[5],
840
+ payload: row[6],
841
+ createdAt: row[7]
842
+ };
843
+ });
844
+ }