weave-typescript 0.15.0 → 0.16.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.
- package/dist/weaveapi/atc/v1/service.pb.d.ts +24 -0
- package/dist/weaveapi/atc/v1/service.pb.js +163 -1
- package/dist/weaveapi/provider/v1/provider.pb.d.ts +123 -0
- package/dist/weaveapi/provider/v1/provider.pb.js +914 -0
- package/dist/weaveapi/provider/v1/service.pb.d.ts +198 -0
- package/dist/weaveapi/provider/v1/service.pb.js +1569 -0
- package/dist/weavesql/atcdb/event_sql.d.ts +68 -0
- package/dist/weavesql/atcdb/event_sql.js +143 -1
- package/dist/weavesql/atcdb/run_template_sql.d.ts +122 -0
- package/dist/weavesql/atcdb/run_template_sql.js +197 -0
- package/dist/weavesql/atcdb/snapshot_sql.d.ts +58 -0
- package/dist/weavesql/atcdb/snapshot_sql.js +124 -0
- package/dist/weavesql/atcdb/team_sql.d.ts +111 -0
- package/dist/weavesql/atcdb/team_sql.js +235 -0
- package/dist/weavesql/atcdb/workflow_template_sql.d.ts +122 -0
- package/dist/weavesql/atcdb/workflow_template_sql.js +197 -0
- package/dist/weavesql/weavedb/provider_sql.d.ts +162 -0
- package/dist/weavesql/weavedb/provider_sql.js +358 -0
- package/package.json +2 -2
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listRunSnapshotsQuery = exports.deleteSnapshotQuery = exports.loadSnapshotQuery = exports.upsertSnapshotQuery = void 0;
|
|
4
|
+
exports.upsertSnapshot = upsertSnapshot;
|
|
5
|
+
exports.loadSnapshot = loadSnapshot;
|
|
6
|
+
exports.deleteSnapshot = deleteSnapshot;
|
|
7
|
+
exports.listRunSnapshots = listRunSnapshots;
|
|
8
|
+
exports.upsertSnapshotQuery = `-- name: UpsertSnapshot :one
|
|
9
|
+
INSERT INTO atc.event_snapshots (
|
|
10
|
+
tenant_id,
|
|
11
|
+
run_id,
|
|
12
|
+
sequence,
|
|
13
|
+
snapshot_type,
|
|
14
|
+
data
|
|
15
|
+
) VALUES (
|
|
16
|
+
$1,
|
|
17
|
+
$2,
|
|
18
|
+
$3,
|
|
19
|
+
$4,
|
|
20
|
+
$5
|
|
21
|
+
)
|
|
22
|
+
ON CONFLICT (tenant_id, run_id, snapshot_type)
|
|
23
|
+
DO UPDATE
|
|
24
|
+
SET
|
|
25
|
+
sequence = CASE
|
|
26
|
+
WHEN EXCLUDED.sequence > atc.event_snapshots.sequence THEN EXCLUDED.sequence
|
|
27
|
+
ELSE atc.event_snapshots.sequence
|
|
28
|
+
END,
|
|
29
|
+
data = CASE
|
|
30
|
+
WHEN EXCLUDED.sequence > atc.event_snapshots.sequence THEN EXCLUDED.data
|
|
31
|
+
ELSE atc.event_snapshots.data
|
|
32
|
+
END
|
|
33
|
+
RETURNING tenant_id, run_id, sequence, snapshot_type, data, created_at`;
|
|
34
|
+
async function upsertSnapshot(client, args) {
|
|
35
|
+
const result = await client.query({
|
|
36
|
+
text: exports.upsertSnapshotQuery,
|
|
37
|
+
values: [args.tenantId, args.runId, args.sequence, args.snapshotType, args.data],
|
|
38
|
+
rowMode: "array"
|
|
39
|
+
});
|
|
40
|
+
if (result.rows.length !== 1) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const row = result.rows[0];
|
|
44
|
+
return {
|
|
45
|
+
tenantId: row[0],
|
|
46
|
+
runId: row[1],
|
|
47
|
+
sequence: row[2],
|
|
48
|
+
snapshotType: row[3],
|
|
49
|
+
data: row[4],
|
|
50
|
+
createdAt: row[5]
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.loadSnapshotQuery = `-- name: LoadSnapshot :one
|
|
54
|
+
SELECT
|
|
55
|
+
tenant_id,
|
|
56
|
+
run_id,
|
|
57
|
+
sequence,
|
|
58
|
+
snapshot_type,
|
|
59
|
+
data,
|
|
60
|
+
created_at
|
|
61
|
+
FROM atc.event_snapshots
|
|
62
|
+
WHERE tenant_id = $1
|
|
63
|
+
AND run_id = $2
|
|
64
|
+
AND snapshot_type = $3`;
|
|
65
|
+
async function loadSnapshot(client, args) {
|
|
66
|
+
const result = await client.query({
|
|
67
|
+
text: exports.loadSnapshotQuery,
|
|
68
|
+
values: [args.tenantId, args.runId, args.snapshotType],
|
|
69
|
+
rowMode: "array"
|
|
70
|
+
});
|
|
71
|
+
if (result.rows.length !== 1) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const row = result.rows[0];
|
|
75
|
+
return {
|
|
76
|
+
tenantId: row[0],
|
|
77
|
+
runId: row[1],
|
|
78
|
+
sequence: row[2],
|
|
79
|
+
snapshotType: row[3],
|
|
80
|
+
data: row[4],
|
|
81
|
+
createdAt: row[5]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
exports.deleteSnapshotQuery = `-- name: DeleteSnapshot :exec
|
|
85
|
+
DELETE FROM atc.event_snapshots
|
|
86
|
+
WHERE tenant_id = $1
|
|
87
|
+
AND run_id = $2
|
|
88
|
+
AND snapshot_type = $3`;
|
|
89
|
+
async function deleteSnapshot(client, args) {
|
|
90
|
+
await client.query({
|
|
91
|
+
text: exports.deleteSnapshotQuery,
|
|
92
|
+
values: [args.tenantId, args.runId, args.snapshotType],
|
|
93
|
+
rowMode: "array"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.listRunSnapshotsQuery = `-- name: ListRunSnapshots :many
|
|
97
|
+
SELECT
|
|
98
|
+
tenant_id,
|
|
99
|
+
run_id,
|
|
100
|
+
sequence,
|
|
101
|
+
snapshot_type,
|
|
102
|
+
data,
|
|
103
|
+
created_at
|
|
104
|
+
FROM atc.event_snapshots
|
|
105
|
+
WHERE tenant_id = $1
|
|
106
|
+
AND run_id = $2
|
|
107
|
+
ORDER BY snapshot_type ASC`;
|
|
108
|
+
async function listRunSnapshots(client, args) {
|
|
109
|
+
const result = await client.query({
|
|
110
|
+
text: exports.listRunSnapshotsQuery,
|
|
111
|
+
values: [args.tenantId, args.runId],
|
|
112
|
+
rowMode: "array"
|
|
113
|
+
});
|
|
114
|
+
return result.rows.map(row => {
|
|
115
|
+
return {
|
|
116
|
+
tenantId: row[0],
|
|
117
|
+
runId: row[1],
|
|
118
|
+
sequence: row[2],
|
|
119
|
+
snapshotType: row[3],
|
|
120
|
+
data: row[4],
|
|
121
|
+
createdAt: row[5]
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const insertTeamQuery = "-- name: InsertTeam :one\nINSERT INTO atc.teams (\n id,\n tenant_id,\n parent_id,\n name,\n team_type,\n metadata\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6\n)\nRETURNING id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at";
|
|
6
|
+
export interface InsertTeamArgs {
|
|
7
|
+
id: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
parentId: string | null;
|
|
10
|
+
name: string;
|
|
11
|
+
teamType: string;
|
|
12
|
+
metadata: any;
|
|
13
|
+
}
|
|
14
|
+
export interface InsertTeamRow {
|
|
15
|
+
id: string;
|
|
16
|
+
tenantId: string;
|
|
17
|
+
parentId: string | null;
|
|
18
|
+
name: string;
|
|
19
|
+
teamType: string;
|
|
20
|
+
metadata: any;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
}
|
|
24
|
+
export declare function insertTeam(client: Client, args: InsertTeamArgs): Promise<InsertTeamRow | null>;
|
|
25
|
+
export declare const getTeamQuery = "-- name: GetTeam :one\nSELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at\nFROM atc.teams\nWHERE tenant_id = $1\n AND id = $2";
|
|
26
|
+
export interface GetTeamArgs {
|
|
27
|
+
tenantId: string;
|
|
28
|
+
id: string;
|
|
29
|
+
}
|
|
30
|
+
export interface GetTeamRow {
|
|
31
|
+
id: string;
|
|
32
|
+
tenantId: string;
|
|
33
|
+
parentId: string | null;
|
|
34
|
+
name: string;
|
|
35
|
+
teamType: string;
|
|
36
|
+
metadata: any;
|
|
37
|
+
createdAt: Date;
|
|
38
|
+
updatedAt: Date;
|
|
39
|
+
}
|
|
40
|
+
export declare function getTeam(client: Client, args: GetTeamArgs): Promise<GetTeamRow | null>;
|
|
41
|
+
export declare const listChildTeamsQuery = "-- name: ListChildTeams :many\nSELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at\nFROM atc.teams\nWHERE tenant_id = $1\n AND parent_id = $2\nORDER BY name ASC";
|
|
42
|
+
export interface ListChildTeamsArgs {
|
|
43
|
+
tenantId: string;
|
|
44
|
+
parentId: string | null;
|
|
45
|
+
}
|
|
46
|
+
export interface ListChildTeamsRow {
|
|
47
|
+
id: string;
|
|
48
|
+
tenantId: string;
|
|
49
|
+
parentId: string | null;
|
|
50
|
+
name: string;
|
|
51
|
+
teamType: string;
|
|
52
|
+
metadata: any;
|
|
53
|
+
createdAt: Date;
|
|
54
|
+
updatedAt: Date;
|
|
55
|
+
}
|
|
56
|
+
export declare function listChildTeams(client: Client, args: ListChildTeamsArgs): Promise<ListChildTeamsRow[]>;
|
|
57
|
+
export declare const listTeamAncestorsQuery = "-- name: ListTeamAncestors :many\nWITH RECURSIVE ancestors AS (\n SELECT\n id,\n tenant_id,\n parent_id,\n name,\n team_type,\n metadata,\n created_at,\n updated_at,\n 0 AS depth\n FROM atc.teams AS team\n WHERE team.tenant_id = $1\n AND team.id = $2\n\n UNION ALL\n\n SELECT\n team.id,\n team.tenant_id,\n team.parent_id,\n team.name,\n team.team_type,\n team.metadata,\n team.created_at,\n team.updated_at,\n ancestors.depth + 1\n FROM atc.teams AS team\n JOIN ancestors\n ON team.tenant_id = ancestors.tenant_id\n AND team.id = ancestors.parent_id\n)\nSELECT\n id,\n tenant_id,\n parent_id,\n name,\n team_type,\n metadata,\n created_at,\n updated_at\nFROM ancestors\nORDER BY depth ASC";
|
|
58
|
+
export interface ListTeamAncestorsArgs {
|
|
59
|
+
tenantId: string;
|
|
60
|
+
teamId: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ListTeamAncestorsRow {
|
|
63
|
+
id: string;
|
|
64
|
+
tenantId: string;
|
|
65
|
+
parentId: string | null;
|
|
66
|
+
name: string;
|
|
67
|
+
teamType: string;
|
|
68
|
+
metadata: any;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
updatedAt: Date;
|
|
71
|
+
}
|
|
72
|
+
export declare function listTeamAncestors(client: Client, args: ListTeamAncestorsArgs): Promise<ListTeamAncestorsRow[]>;
|
|
73
|
+
export declare const upsertTeamBudgetQuery = "-- name: UpsertTeamBudget :one\nINSERT INTO atc.team_budgets (\n tenant_id,\n team_id,\n period_start,\n period_end,\n max_cost_cents,\n max_compute,\n max_tool_calls\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7\n)\nON CONFLICT (tenant_id, team_id, period_start)\nDO UPDATE SET\n period_end = EXCLUDED.period_end,\n max_cost_cents = EXCLUDED.max_cost_cents,\n max_compute = EXCLUDED.max_compute,\n max_tool_calls = EXCLUDED.max_tool_calls\nRETURNING tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at";
|
|
74
|
+
export interface UpsertTeamBudgetArgs {
|
|
75
|
+
tenantId: string;
|
|
76
|
+
teamId: string;
|
|
77
|
+
periodStart: Date;
|
|
78
|
+
periodEnd: Date;
|
|
79
|
+
maxCostCents: string;
|
|
80
|
+
maxCompute: string;
|
|
81
|
+
maxToolCalls: string;
|
|
82
|
+
}
|
|
83
|
+
export interface UpsertTeamBudgetRow {
|
|
84
|
+
tenantId: string;
|
|
85
|
+
teamId: string;
|
|
86
|
+
periodStart: Date;
|
|
87
|
+
periodEnd: Date;
|
|
88
|
+
maxCostCents: string;
|
|
89
|
+
maxCompute: string;
|
|
90
|
+
maxToolCalls: string;
|
|
91
|
+
createdAt: Date;
|
|
92
|
+
}
|
|
93
|
+
export declare function upsertTeamBudget(client: Client, args: UpsertTeamBudgetArgs): Promise<UpsertTeamBudgetRow | null>;
|
|
94
|
+
export declare const getTeamBudgetQuery = "-- name: GetTeamBudget :one\nSELECT tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at\nFROM atc.team_budgets\nWHERE tenant_id = $1\n AND team_id = $2\n AND period_start <= $3\n AND period_end > $3";
|
|
95
|
+
export interface GetTeamBudgetArgs {
|
|
96
|
+
tenantId: string;
|
|
97
|
+
teamId: string;
|
|
98
|
+
atTime: Date;
|
|
99
|
+
}
|
|
100
|
+
export interface GetTeamBudgetRow {
|
|
101
|
+
tenantId: string;
|
|
102
|
+
teamId: string;
|
|
103
|
+
periodStart: Date;
|
|
104
|
+
periodEnd: Date;
|
|
105
|
+
maxCostCents: string;
|
|
106
|
+
maxCompute: string;
|
|
107
|
+
maxToolCalls: string;
|
|
108
|
+
createdAt: Date;
|
|
109
|
+
}
|
|
110
|
+
export declare function getTeamBudget(client: Client, args: GetTeamBudgetArgs): Promise<GetTeamBudgetRow | null>;
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTeamBudgetQuery = exports.upsertTeamBudgetQuery = exports.listTeamAncestorsQuery = exports.listChildTeamsQuery = exports.getTeamQuery = exports.insertTeamQuery = void 0;
|
|
4
|
+
exports.insertTeam = insertTeam;
|
|
5
|
+
exports.getTeam = getTeam;
|
|
6
|
+
exports.listChildTeams = listChildTeams;
|
|
7
|
+
exports.listTeamAncestors = listTeamAncestors;
|
|
8
|
+
exports.upsertTeamBudget = upsertTeamBudget;
|
|
9
|
+
exports.getTeamBudget = getTeamBudget;
|
|
10
|
+
exports.insertTeamQuery = `-- name: InsertTeam :one
|
|
11
|
+
INSERT INTO atc.teams (
|
|
12
|
+
id,
|
|
13
|
+
tenant_id,
|
|
14
|
+
parent_id,
|
|
15
|
+
name,
|
|
16
|
+
team_type,
|
|
17
|
+
metadata
|
|
18
|
+
) VALUES (
|
|
19
|
+
$1,
|
|
20
|
+
$2,
|
|
21
|
+
$3,
|
|
22
|
+
$4,
|
|
23
|
+
$5,
|
|
24
|
+
$6
|
|
25
|
+
)
|
|
26
|
+
RETURNING id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at`;
|
|
27
|
+
async function insertTeam(client, args) {
|
|
28
|
+
const result = await client.query({
|
|
29
|
+
text: exports.insertTeamQuery,
|
|
30
|
+
values: [args.id, args.tenantId, args.parentId, args.name, args.teamType, args.metadata],
|
|
31
|
+
rowMode: "array"
|
|
32
|
+
});
|
|
33
|
+
if (result.rows.length !== 1) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const row = result.rows[0];
|
|
37
|
+
return {
|
|
38
|
+
id: row[0],
|
|
39
|
+
tenantId: row[1],
|
|
40
|
+
parentId: row[2],
|
|
41
|
+
name: row[3],
|
|
42
|
+
teamType: row[4],
|
|
43
|
+
metadata: row[5],
|
|
44
|
+
createdAt: row[6],
|
|
45
|
+
updatedAt: row[7]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.getTeamQuery = `-- name: GetTeam :one
|
|
49
|
+
SELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at
|
|
50
|
+
FROM atc.teams
|
|
51
|
+
WHERE tenant_id = $1
|
|
52
|
+
AND id = $2`;
|
|
53
|
+
async function getTeam(client, args) {
|
|
54
|
+
const result = await client.query({
|
|
55
|
+
text: exports.getTeamQuery,
|
|
56
|
+
values: [args.tenantId, args.id],
|
|
57
|
+
rowMode: "array"
|
|
58
|
+
});
|
|
59
|
+
if (result.rows.length !== 1) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const row = result.rows[0];
|
|
63
|
+
return {
|
|
64
|
+
id: row[0],
|
|
65
|
+
tenantId: row[1],
|
|
66
|
+
parentId: row[2],
|
|
67
|
+
name: row[3],
|
|
68
|
+
teamType: row[4],
|
|
69
|
+
metadata: row[5],
|
|
70
|
+
createdAt: row[6],
|
|
71
|
+
updatedAt: row[7]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.listChildTeamsQuery = `-- name: ListChildTeams :many
|
|
75
|
+
SELECT id, tenant_id, parent_id, name, team_type, metadata, created_at, updated_at
|
|
76
|
+
FROM atc.teams
|
|
77
|
+
WHERE tenant_id = $1
|
|
78
|
+
AND parent_id = $2
|
|
79
|
+
ORDER BY name ASC`;
|
|
80
|
+
async function listChildTeams(client, args) {
|
|
81
|
+
const result = await client.query({
|
|
82
|
+
text: exports.listChildTeamsQuery,
|
|
83
|
+
values: [args.tenantId, args.parentId],
|
|
84
|
+
rowMode: "array"
|
|
85
|
+
});
|
|
86
|
+
return result.rows.map(row => {
|
|
87
|
+
return {
|
|
88
|
+
id: row[0],
|
|
89
|
+
tenantId: row[1],
|
|
90
|
+
parentId: row[2],
|
|
91
|
+
name: row[3],
|
|
92
|
+
teamType: row[4],
|
|
93
|
+
metadata: row[5],
|
|
94
|
+
createdAt: row[6],
|
|
95
|
+
updatedAt: row[7]
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
exports.listTeamAncestorsQuery = `-- name: ListTeamAncestors :many
|
|
100
|
+
WITH RECURSIVE ancestors AS (
|
|
101
|
+
SELECT
|
|
102
|
+
id,
|
|
103
|
+
tenant_id,
|
|
104
|
+
parent_id,
|
|
105
|
+
name,
|
|
106
|
+
team_type,
|
|
107
|
+
metadata,
|
|
108
|
+
created_at,
|
|
109
|
+
updated_at,
|
|
110
|
+
0 AS depth
|
|
111
|
+
FROM atc.teams AS team
|
|
112
|
+
WHERE team.tenant_id = $1
|
|
113
|
+
AND team.id = $2
|
|
114
|
+
|
|
115
|
+
UNION ALL
|
|
116
|
+
|
|
117
|
+
SELECT
|
|
118
|
+
team.id,
|
|
119
|
+
team.tenant_id,
|
|
120
|
+
team.parent_id,
|
|
121
|
+
team.name,
|
|
122
|
+
team.team_type,
|
|
123
|
+
team.metadata,
|
|
124
|
+
team.created_at,
|
|
125
|
+
team.updated_at,
|
|
126
|
+
ancestors.depth + 1
|
|
127
|
+
FROM atc.teams AS team
|
|
128
|
+
JOIN ancestors
|
|
129
|
+
ON team.tenant_id = ancestors.tenant_id
|
|
130
|
+
AND team.id = ancestors.parent_id
|
|
131
|
+
)
|
|
132
|
+
SELECT
|
|
133
|
+
id,
|
|
134
|
+
tenant_id,
|
|
135
|
+
parent_id,
|
|
136
|
+
name,
|
|
137
|
+
team_type,
|
|
138
|
+
metadata,
|
|
139
|
+
created_at,
|
|
140
|
+
updated_at
|
|
141
|
+
FROM ancestors
|
|
142
|
+
ORDER BY depth ASC`;
|
|
143
|
+
async function listTeamAncestors(client, args) {
|
|
144
|
+
const result = await client.query({
|
|
145
|
+
text: exports.listTeamAncestorsQuery,
|
|
146
|
+
values: [args.tenantId, args.teamId],
|
|
147
|
+
rowMode: "array"
|
|
148
|
+
});
|
|
149
|
+
return result.rows.map(row => {
|
|
150
|
+
return {
|
|
151
|
+
id: row[0],
|
|
152
|
+
tenantId: row[1],
|
|
153
|
+
parentId: row[2],
|
|
154
|
+
name: row[3],
|
|
155
|
+
teamType: row[4],
|
|
156
|
+
metadata: row[5],
|
|
157
|
+
createdAt: row[6],
|
|
158
|
+
updatedAt: row[7]
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
exports.upsertTeamBudgetQuery = `-- name: UpsertTeamBudget :one
|
|
163
|
+
INSERT INTO atc.team_budgets (
|
|
164
|
+
tenant_id,
|
|
165
|
+
team_id,
|
|
166
|
+
period_start,
|
|
167
|
+
period_end,
|
|
168
|
+
max_cost_cents,
|
|
169
|
+
max_compute,
|
|
170
|
+
max_tool_calls
|
|
171
|
+
) VALUES (
|
|
172
|
+
$1,
|
|
173
|
+
$2,
|
|
174
|
+
$3,
|
|
175
|
+
$4,
|
|
176
|
+
$5,
|
|
177
|
+
$6,
|
|
178
|
+
$7
|
|
179
|
+
)
|
|
180
|
+
ON CONFLICT (tenant_id, team_id, period_start)
|
|
181
|
+
DO UPDATE SET
|
|
182
|
+
period_end = EXCLUDED.period_end,
|
|
183
|
+
max_cost_cents = EXCLUDED.max_cost_cents,
|
|
184
|
+
max_compute = EXCLUDED.max_compute,
|
|
185
|
+
max_tool_calls = EXCLUDED.max_tool_calls
|
|
186
|
+
RETURNING tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at`;
|
|
187
|
+
async function upsertTeamBudget(client, args) {
|
|
188
|
+
const result = await client.query({
|
|
189
|
+
text: exports.upsertTeamBudgetQuery,
|
|
190
|
+
values: [args.tenantId, args.teamId, args.periodStart, args.periodEnd, args.maxCostCents, args.maxCompute, args.maxToolCalls],
|
|
191
|
+
rowMode: "array"
|
|
192
|
+
});
|
|
193
|
+
if (result.rows.length !== 1) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
const row = result.rows[0];
|
|
197
|
+
return {
|
|
198
|
+
tenantId: row[0],
|
|
199
|
+
teamId: row[1],
|
|
200
|
+
periodStart: row[2],
|
|
201
|
+
periodEnd: row[3],
|
|
202
|
+
maxCostCents: row[4],
|
|
203
|
+
maxCompute: row[5],
|
|
204
|
+
maxToolCalls: row[6],
|
|
205
|
+
createdAt: row[7]
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
exports.getTeamBudgetQuery = `-- name: GetTeamBudget :one
|
|
209
|
+
SELECT tenant_id, team_id, period_start, period_end, max_cost_cents, max_compute, max_tool_calls, created_at
|
|
210
|
+
FROM atc.team_budgets
|
|
211
|
+
WHERE tenant_id = $1
|
|
212
|
+
AND team_id = $2
|
|
213
|
+
AND period_start <= $3
|
|
214
|
+
AND period_end > $3`;
|
|
215
|
+
async function getTeamBudget(client, args) {
|
|
216
|
+
const result = await client.query({
|
|
217
|
+
text: exports.getTeamBudgetQuery,
|
|
218
|
+
values: [args.tenantId, args.teamId, args.atTime],
|
|
219
|
+
rowMode: "array"
|
|
220
|
+
});
|
|
221
|
+
if (result.rows.length !== 1) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
const row = result.rows[0];
|
|
225
|
+
return {
|
|
226
|
+
tenantId: row[0],
|
|
227
|
+
teamId: row[1],
|
|
228
|
+
periodStart: row[2],
|
|
229
|
+
periodEnd: row[3],
|
|
230
|
+
maxCostCents: row[4],
|
|
231
|
+
maxCompute: row[5],
|
|
232
|
+
maxToolCalls: row[6],
|
|
233
|
+
createdAt: row[7]
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const insertWorkflowTemplateQuery = "-- name: InsertWorkflowTemplate :one\nINSERT INTO atc.workflow_templates (\n id,\n tenant_id,\n name,\n version,\n handler_type,\n config,\n security_context,\n budget_context,\n pinned_caller,\n created_by\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10\n)\nRETURNING id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at";
|
|
6
|
+
export interface InsertWorkflowTemplateArgs {
|
|
7
|
+
id: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
version: number;
|
|
11
|
+
handlerType: string;
|
|
12
|
+
config: any;
|
|
13
|
+
securityContext: any | null;
|
|
14
|
+
budgetContext: any | null;
|
|
15
|
+
pinnedCaller: any | null;
|
|
16
|
+
createdBy: string;
|
|
17
|
+
}
|
|
18
|
+
export interface InsertWorkflowTemplateRow {
|
|
19
|
+
id: string;
|
|
20
|
+
tenantId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
version: number;
|
|
23
|
+
handlerType: string;
|
|
24
|
+
config: any;
|
|
25
|
+
securityContext: any | null;
|
|
26
|
+
budgetContext: any | null;
|
|
27
|
+
pinnedCaller: any | null;
|
|
28
|
+
createdBy: string;
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
updatedAt: Date;
|
|
31
|
+
}
|
|
32
|
+
export declare function insertWorkflowTemplate(client: Client, args: InsertWorkflowTemplateArgs): Promise<InsertWorkflowTemplateRow | null>;
|
|
33
|
+
export declare const getWorkflowTemplateQuery = "-- name: GetWorkflowTemplate :one\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.workflow_templates\nWHERE tenant_id = $1\n AND id = $2";
|
|
34
|
+
export interface GetWorkflowTemplateArgs {
|
|
35
|
+
tenantId: string;
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
38
|
+
export interface GetWorkflowTemplateRow {
|
|
39
|
+
id: string;
|
|
40
|
+
tenantId: string;
|
|
41
|
+
name: string;
|
|
42
|
+
version: number;
|
|
43
|
+
handlerType: string;
|
|
44
|
+
config: any;
|
|
45
|
+
securityContext: any | null;
|
|
46
|
+
budgetContext: any | null;
|
|
47
|
+
pinnedCaller: any | null;
|
|
48
|
+
createdBy: string;
|
|
49
|
+
createdAt: Date;
|
|
50
|
+
updatedAt: Date;
|
|
51
|
+
}
|
|
52
|
+
export declare function getWorkflowTemplate(client: Client, args: GetWorkflowTemplateArgs): Promise<GetWorkflowTemplateRow | null>;
|
|
53
|
+
export declare const getWorkflowTemplateByNameQuery = "-- name: GetWorkflowTemplateByName :one\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.workflow_templates\nWHERE tenant_id = $1\n AND name = $2\nORDER BY version DESC\nLIMIT 1";
|
|
54
|
+
export interface GetWorkflowTemplateByNameArgs {
|
|
55
|
+
tenantId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
58
|
+
export interface GetWorkflowTemplateByNameRow {
|
|
59
|
+
id: string;
|
|
60
|
+
tenantId: string;
|
|
61
|
+
name: string;
|
|
62
|
+
version: number;
|
|
63
|
+
handlerType: string;
|
|
64
|
+
config: any;
|
|
65
|
+
securityContext: any | null;
|
|
66
|
+
budgetContext: any | null;
|
|
67
|
+
pinnedCaller: any | null;
|
|
68
|
+
createdBy: string;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
updatedAt: Date;
|
|
71
|
+
}
|
|
72
|
+
export declare function getWorkflowTemplateByName(client: Client, args: GetWorkflowTemplateByNameArgs): Promise<GetWorkflowTemplateByNameRow | null>;
|
|
73
|
+
export declare const listWorkflowTemplatesQuery = "-- name: ListWorkflowTemplates :many\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.workflow_templates\nWHERE tenant_id = $1\nORDER BY name ASC, version DESC";
|
|
74
|
+
export interface ListWorkflowTemplatesArgs {
|
|
75
|
+
tenantId: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ListWorkflowTemplatesRow {
|
|
78
|
+
id: string;
|
|
79
|
+
tenantId: string;
|
|
80
|
+
name: string;
|
|
81
|
+
version: number;
|
|
82
|
+
handlerType: string;
|
|
83
|
+
config: any;
|
|
84
|
+
securityContext: any | null;
|
|
85
|
+
budgetContext: any | null;
|
|
86
|
+
pinnedCaller: any | null;
|
|
87
|
+
createdBy: string;
|
|
88
|
+
createdAt: Date;
|
|
89
|
+
updatedAt: Date;
|
|
90
|
+
}
|
|
91
|
+
export declare function listWorkflowTemplates(client: Client, args: ListWorkflowTemplatesArgs): Promise<ListWorkflowTemplatesRow[]>;
|
|
92
|
+
export declare const updateWorkflowTemplateQuery = "-- name: UpdateWorkflowTemplate :one\nUPDATE atc.workflow_templates\nSET\n config = $1,\n security_context = $2,\n budget_context = $3,\n pinned_caller = $4,\n version = version + 1,\n updated_at = now()\nWHERE tenant_id = $5\n AND id = $6\nRETURNING id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at";
|
|
93
|
+
export interface UpdateWorkflowTemplateArgs {
|
|
94
|
+
config: any;
|
|
95
|
+
securityContext: any | null;
|
|
96
|
+
budgetContext: any | null;
|
|
97
|
+
pinnedCaller: any | null;
|
|
98
|
+
tenantId: string;
|
|
99
|
+
id: string;
|
|
100
|
+
}
|
|
101
|
+
export interface UpdateWorkflowTemplateRow {
|
|
102
|
+
id: string;
|
|
103
|
+
tenantId: string;
|
|
104
|
+
name: string;
|
|
105
|
+
version: number;
|
|
106
|
+
handlerType: string;
|
|
107
|
+
config: any;
|
|
108
|
+
securityContext: any | null;
|
|
109
|
+
budgetContext: any | null;
|
|
110
|
+
pinnedCaller: any | null;
|
|
111
|
+
createdBy: string;
|
|
112
|
+
createdAt: Date;
|
|
113
|
+
updatedAt: Date;
|
|
114
|
+
}
|
|
115
|
+
export declare function updateWorkflowTemplate(client: Client, args: UpdateWorkflowTemplateArgs): Promise<UpdateWorkflowTemplateRow | null>;
|
|
116
|
+
export declare const deleteWorkflowTemplateQuery = "-- name: DeleteWorkflowTemplate :exec\nDELETE FROM atc.workflow_templates\nWHERE tenant_id = $1\n AND id = $2";
|
|
117
|
+
export interface DeleteWorkflowTemplateArgs {
|
|
118
|
+
tenantId: string;
|
|
119
|
+
id: string;
|
|
120
|
+
}
|
|
121
|
+
export declare function deleteWorkflowTemplate(client: Client, args: DeleteWorkflowTemplateArgs): Promise<void>;
|
|
122
|
+
export {};
|