weave-typescript 0.51.3 → 0.53.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/google/protobuf/duration.pb.d.ts +99 -0
- package/dist/google/protobuf/duration.pb.js +93 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/weave/authz/v1/index.d.ts +1 -0
- package/dist/weave/authz/v1/index.js +38 -0
- package/dist/weave/authz/v1/options.pb.d.ts +52 -0
- package/dist/weave/authz/v1/options.pb.js +403 -0
- package/dist/weave/filter/v1/index.d.ts +1 -0
- package/dist/weave/filter/v1/index.js +38 -0
- package/dist/{weaveapi/atc/v1/message.pb.d.ts → weave/filter/v1/options.pb.d.ts} +33 -21
- package/dist/weave/filter/v1/options.pb.js +417 -0
- package/dist/weave/index.d.ts +2 -0
- package/dist/weave/index.js +39 -0
- package/dist/weaveapi/agent/v1/agent.pb.d.ts +137 -188
- package/dist/weaveapi/agent/v1/agent.pb.js +891 -2151
- package/dist/weaveapi/agent/v1/index.d.ts +1 -1
- package/dist/weaveapi/agent/v1/index.js +2 -2
- package/dist/weaveapi/agent/v1/run.pb.d.ts +289 -0
- package/dist/weaveapi/agent/v1/run.pb.js +2763 -0
- package/dist/weaveapi/auth/v1/auth.pb.d.ts +67 -14
- package/dist/weaveapi/auth/v1/auth.pb.js +829 -89
- package/dist/weaveapi/auth/v1/index.d.ts +4 -1
- package/dist/weaveapi/auth/v1/index.js +5 -2
- package/dist/weaveapi/auth/v1/{service.pb.d.ts → organization_admin.pb.d.ts} +39 -530
- package/dist/weaveapi/auth/v1/{service.pb.js → organization_admin.pb.js} +2978 -5812
- package/dist/weaveapi/auth/v1/personal_access_token.pb.d.ts +114 -0
- package/dist/weaveapi/auth/v1/personal_access_token.pb.js +750 -0
- package/dist/weaveapi/auth/v1/profile.pb.d.ts +161 -0
- package/dist/weaveapi/auth/v1/profile.pb.js +1007 -0
- package/dist/weaveapi/auth/v1/session.pb.d.ts +460 -0
- package/dist/weaveapi/auth/v1/session.pb.js +3544 -0
- package/dist/weaveapi/chat/v1/chat.pb.d.ts +377 -149
- package/dist/weaveapi/chat/v1/chat.pb.js +3492 -1614
- package/dist/weaveapi/chat/v1/index.d.ts +0 -1
- package/dist/weaveapi/chat/v1/index.js +1 -2
- package/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +95 -0
- package/dist/weaveapi/consolidation/v1/consolidation.pb.js +770 -1
- package/dist/weaveapi/consolidation/v1/index.d.ts +0 -1
- package/dist/weaveapi/consolidation/v1/index.js +1 -2
- package/dist/weaveapi/content/v1/content.pb.d.ts +63 -0
- package/dist/weaveapi/content/v1/content.pb.js +470 -0
- package/dist/weaveapi/content/v1/index.d.ts +1 -0
- package/dist/weaveapi/content/v1/index.js +38 -0
- package/dist/weaveapi/gateway/v1/gateway.pb.d.ts +247 -523
- package/dist/weaveapi/gateway/v1/gateway.pb.js +1648 -5783
- package/dist/weaveapi/gateway/v1/index.d.ts +0 -1
- package/dist/weaveapi/gateway/v1/index.js +1 -2
- package/dist/weaveapi/index.d.ts +5 -5
- package/dist/weaveapi/index.js +6 -6
- package/dist/weaveapi/inference/v1/generate.pb.d.ts +120 -0
- package/dist/weaveapi/inference/v1/generate.pb.js +1159 -0
- package/dist/weaveapi/inference/v1/index.d.ts +4 -0
- package/dist/weaveapi/{provider → inference}/v1/index.js +4 -2
- package/dist/weaveapi/{model → inference}/v1/model.pb.d.ts +54 -15
- package/dist/weaveapi/{model → inference}/v1/model.pb.js +573 -116
- package/dist/weaveapi/{model/v1/service.pb.d.ts → inference/v1/model_route.pb.d.ts} +184 -110
- package/dist/weaveapi/{model/v1/service.pb.js → inference/v1/model_route.pb.js} +2240 -1061
- package/dist/weaveapi/inference/v1/provider.pb.d.ts +264 -0
- package/dist/weaveapi/inference/v1/provider.pb.js +2590 -0
- package/dist/weaveapi/ingestion/v1/index.d.ts +0 -2
- package/dist/weaveapi/ingestion/v1/index.js +1 -3
- package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +543 -0
- package/dist/weaveapi/ingestion/v1/ingestion.pb.js +5550 -16
- package/dist/weaveapi/initialization/v1/index.d.ts +1 -0
- package/dist/weaveapi/initialization/v1/index.js +38 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.d.ts +99 -0
- package/dist/weaveapi/initialization/v1/initialization.pb.js +510 -0
- package/dist/weaveapi/organization/v1/index.d.ts +0 -1
- package/dist/weaveapi/organization/v1/index.js +1 -2
- package/dist/weaveapi/organization/v1/organization.pb.d.ts +241 -0
- package/dist/weaveapi/organization/v1/organization.pb.js +1838 -1
- package/dist/weaveapi/reporting/index.d.ts +1 -0
- package/dist/weaveapi/reporting/index.js +38 -0
- package/dist/weaveapi/{task → reporting}/v1/index.d.ts +1 -1
- package/dist/weaveapi/{model → reporting}/v1/index.js +2 -2
- package/dist/weaveapi/reporting/v1/service.pb.d.ts +38 -0
- package/dist/weaveapi/reporting/v1/service.pb.js +167 -0
- package/dist/weaveapi/reporting/v1/usage.pb.d.ts +150 -0
- package/dist/weaveapi/reporting/v1/usage.pb.js +1837 -0
- package/dist/weaveapi/retrieval/v1/index.d.ts +0 -1
- package/dist/weaveapi/retrieval/v1/index.js +1 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +96 -2
- package/dist/weaveapi/retrieval/v1/retrieval.pb.js +690 -10
- package/dist/weaveapi/tool/index.d.ts +1 -0
- package/dist/weaveapi/tool/index.js +38 -0
- package/dist/weaveapi/tool/v1/index.d.ts +1 -0
- package/dist/weaveapi/tool/v1/index.js +38 -0
- package/dist/weaveapi/tool/v1/tool.pb.d.ts +370 -0
- package/dist/weaveapi/tool/v1/tool.pb.js +2717 -0
- package/dist/weaveapi/workflow/v1/index.d.ts +1 -1
- package/dist/weaveapi/workflow/v1/index.js +2 -2
- package/dist/weaveapi/workflow/v1/run.pb.d.ts +244 -0
- package/dist/weaveapi/workflow/v1/run.pb.js +2084 -0
- package/dist/weaveapi/workflow/v1/workflow.pb.d.ts +122 -275
- package/dist/weaveapi/workflow/v1/workflow.pb.js +790 -3261
- package/dist/weavesql/weavedb/agent_sql.d.ts +173 -477
- package/dist/weavesql/weavedb/agent_sql.js +281 -758
- package/dist/weavesql/weavedb/authorization_outbox_sql.d.ts +261 -0
- package/dist/weavesql/weavedb/authorization_outbox_sql.js +445 -0
- package/dist/weavesql/weavedb/chat_sql.d.ts +103 -345
- package/dist/weavesql/weavedb/chat_sql.js +312 -597
- package/dist/weavesql/weavedb/document_consolidation_sql.d.ts +217 -0
- package/dist/weavesql/weavedb/document_consolidation_sql.js +486 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.d.ts +1433 -0
- package/dist/weavesql/weavedb/document_ingestion_sql.js +3488 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.d.ts +314 -0
- package/dist/weavesql/weavedb/document_retrieval_sql.js +965 -0
- package/dist/weavesql/weavedb/document_table_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/document_table_sql.js +12 -12
- package/dist/weavesql/weavedb/identity_sql.d.ts +1021 -0
- package/dist/weavesql/weavedb/identity_sql.js +1818 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.d.ts +167 -0
- package/dist/weavesql/weavedb/inference_model_route_sql.js +483 -0
- package/dist/weavesql/weavedb/inference_provider_sql.d.ts +125 -0
- package/dist/weavesql/weavedb/inference_provider_sql.js +228 -0
- package/dist/weavesql/weavedb/initialization_sql.d.ts +15 -0
- package/dist/weavesql/weavedb/initialization_sql.js +33 -0
- package/dist/weavesql/weavedb/model_catalog_sql.d.ts +6 -6
- package/dist/weavesql/weavedb/model_catalog_sql.js +6 -6
- package/dist/weavesql/weavedb/organization_sql.d.ts +24 -102
- package/dist/weavesql/weavedb/organization_sql.js +56 -262
- package/dist/weavesql/weavedb/tool_sql.d.ts +209 -0
- package/dist/weavesql/weavedb/tool_sql.js +407 -0
- package/dist/weavesql/weavedb/usage_sql.d.ts +356 -0
- package/dist/weavesql/weavedb/usage_sql.js +568 -0
- package/dist/weavesql/weavedb/workflow_sql.d.ts +159 -546
- package/dist/weavesql/weavedb/workflow_sql.js +281 -909
- package/package.json +1 -1
- package/dist/weaveapi/agent/v1/service.pb.d.ts +0 -397
- package/dist/weaveapi/agent/v1/service.pb.js +0 -3152
- package/dist/weaveapi/atc/v1/event.pb.d.ts +0 -134
- package/dist/weaveapi/atc/v1/event.pb.js +0 -1124
- package/dist/weaveapi/atc/v1/index.d.ts +0 -5
- package/dist/weaveapi/atc/v1/index.js +0 -42
- package/dist/weaveapi/atc/v1/message.pb.js +0 -287
- package/dist/weaveapi/atc/v1/process.pb.d.ts +0 -91
- package/dist/weaveapi/atc/v1/process.pb.js +0 -658
- package/dist/weaveapi/atc/v1/run.pb.d.ts +0 -71
- package/dist/weaveapi/atc/v1/run.pb.js +0 -525
- package/dist/weaveapi/atc/v1/service.pb.d.ts +0 -472
- package/dist/weaveapi/atc/v1/service.pb.js +0 -3093
- package/dist/weaveapi/chat/v1/service.pb.d.ts +0 -345
- package/dist/weaveapi/chat/v1/service.pb.js +0 -2545
- package/dist/weaveapi/consolidation/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/consolidation/v1/service.pb.js +0 -427
- package/dist/weaveapi/gateway/v1/service.pb.d.ts +0 -235
- package/dist/weaveapi/gateway/v1/service.pb.js +0 -651
- package/dist/weaveapi/ingestion/v1/service.pb.d.ts +0 -420
- package/dist/weaveapi/ingestion/v1/service.pb.js +0 -2311
- package/dist/weaveapi/ingestion/v1/table.pb.d.ts +0 -121
- package/dist/weaveapi/ingestion/v1/table.pb.js +0 -1478
- package/dist/weaveapi/model/v1/index.d.ts +0 -2
- package/dist/weaveapi/organization/v1/service.pb.d.ts +0 -261
- package/dist/weaveapi/organization/v1/service.pb.js +0 -1561
- package/dist/weaveapi/project/v1/index.d.ts +0 -2
- package/dist/weaveapi/project/v1/index.js +0 -39
- package/dist/weaveapi/project/v1/project.pb.d.ts +0 -105
- package/dist/weaveapi/project/v1/project.pb.js +0 -1004
- package/dist/weaveapi/project/v1/service.pb.d.ts +0 -247
- package/dist/weaveapi/project/v1/service.pb.js +0 -1994
- package/dist/weaveapi/provider/v1/index.d.ts +0 -2
- package/dist/weaveapi/provider/v1/provider.pb.d.ts +0 -137
- package/dist/weaveapi/provider/v1/provider.pb.js +0 -1000
- package/dist/weaveapi/provider/v1/service.pb.d.ts +0 -223
- package/dist/weaveapi/provider/v1/service.pb.js +0 -1888
- package/dist/weaveapi/retrieval/v1/service.pb.d.ts +0 -93
- package/dist/weaveapi/retrieval/v1/service.pb.js +0 -385
- package/dist/weaveapi/task/v1/index.js +0 -39
- package/dist/weaveapi/task/v1/service.pb.d.ts +0 -172
- package/dist/weaveapi/task/v1/service.pb.js +0 -1436
- package/dist/weaveapi/task/v1/task.pb.d.ts +0 -85
- package/dist/weaveapi/task/v1/task.pb.js +0 -802
- package/dist/weaveapi/workflow/v1/service.pb.d.ts +0 -392
- package/dist/weaveapi/workflow/v1/service.pb.js +0 -3146
- /package/dist/{weaveapi/atc → weave/authz}/index.d.ts +0 -0
- /package/dist/{weaveapi/atc → weave/authz}/index.js +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.d.ts +0 -0
- /package/dist/{weaveapi/model → weave/filter}/index.js +0 -0
- /package/dist/weaveapi/{project → content}/index.d.ts +0 -0
- /package/dist/weaveapi/{project → content}/index.js +0 -0
- /package/dist/weaveapi/{provider → inference}/index.d.ts +0 -0
- /package/dist/weaveapi/{provider → inference}/index.js +0 -0
- /package/dist/weaveapi/{task → initialization}/index.d.ts +0 -0
- /package/dist/weaveapi/{task → initialization}/index.js +0 -0
|
@@ -1,49 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getCurrentChatArtifactVersionQuery = exports.getChatArtifactVersionQuery = exports.createChatArtifactVersionQuery = exports.listChatArtifactsQuery = exports.getChatArtifactQuery = exports.bumpChatArtifactVersionQuery = exports.createChatArtifactQuery = exports.listChatMessagesQuery = exports.createChatMessageQuery = exports.updateChatSessionTitleQuery = exports.listChatSessionsByUserQuery = exports.getChatSessionQuery = exports.createChatSessionQuery = void 0;
|
|
4
4
|
exports.createChatSession = createChatSession;
|
|
5
5
|
exports.getChatSession = getChatSession;
|
|
6
|
-
exports.
|
|
7
|
-
exports.listChatSessionsForUserByProject = listChatSessionsForUserByProject;
|
|
8
|
-
exports.updateChatSessionModel = updateChatSessionModel;
|
|
6
|
+
exports.listChatSessionsByUser = listChatSessionsByUser;
|
|
9
7
|
exports.updateChatSessionTitle = updateChatSessionTitle;
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.attachProjectToChatSession = attachProjectToChatSession;
|
|
13
|
-
exports.detachProjectFromChatSession = detachProjectFromChatSession;
|
|
14
|
-
exports.listProjectsForChatSession = listProjectsForChatSession;
|
|
15
|
-
exports.insertChatMessage = insertChatMessage;
|
|
16
|
-
exports.getChatMessage = getChatMessage;
|
|
17
|
-
exports.listChatMessagesForSession = listChatMessagesForSession;
|
|
18
|
-
exports.updateChatMessageToolCallState = updateChatMessageToolCallState;
|
|
19
|
-
exports.completeChatMessage = completeChatMessage;
|
|
20
|
-
exports.createOrganizationApprovedModel = createOrganizationApprovedModel;
|
|
21
|
-
exports.deleteOrganizationApprovedModel = deleteOrganizationApprovedModel;
|
|
22
|
-
exports.listOrganizationApprovedModels = listOrganizationApprovedModels;
|
|
23
|
-
exports.getOrganizationApprovedModel = getOrganizationApprovedModel;
|
|
24
|
-
exports.upsertOrganizationChatSettings = upsertOrganizationChatSettings;
|
|
25
|
-
exports.getOrganizationChatSettings = getOrganizationChatSettings;
|
|
26
|
-
exports.clearOrganizationChatSettingsDefaultIfMatches = clearOrganizationChatSettingsDefaultIfMatches;
|
|
8
|
+
exports.createChatMessage = createChatMessage;
|
|
9
|
+
exports.listChatMessages = listChatMessages;
|
|
27
10
|
exports.createChatArtifact = createChatArtifact;
|
|
28
11
|
exports.bumpChatArtifactVersion = bumpChatArtifactVersion;
|
|
29
|
-
exports.listChatArtifactsForSession = listChatArtifactsForSession;
|
|
30
12
|
exports.getChatArtifact = getChatArtifact;
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
13
|
+
exports.listChatArtifacts = listChatArtifacts;
|
|
14
|
+
exports.createChatArtifactVersion = createChatArtifactVersion;
|
|
33
15
|
exports.getChatArtifactVersion = getChatArtifactVersion;
|
|
34
|
-
exports.
|
|
16
|
+
exports.getCurrentChatArtifactVersion = getCurrentChatArtifactVersion;
|
|
35
17
|
exports.createChatSessionQuery = `-- name: CreateChatSession :one
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
WITH resolved_agent AS (
|
|
19
|
+
SELECT COALESCE($4::uuid, o.default_chat_agent_id) AS root_agent_id
|
|
20
|
+
FROM weave.organization o
|
|
21
|
+
WHERE o.id = $1
|
|
22
|
+
),
|
|
23
|
+
valid_agent AS (
|
|
24
|
+
SELECT r.root_agent_id
|
|
25
|
+
FROM resolved_agent r
|
|
26
|
+
JOIN weave.agent a
|
|
27
|
+
ON a.organization_id = $1
|
|
28
|
+
AND a.id = r.root_agent_id
|
|
41
29
|
)
|
|
42
|
-
|
|
30
|
+
INSERT INTO weave.chat_session (
|
|
31
|
+
organization_id,
|
|
32
|
+
created_by_user_id,
|
|
33
|
+
root_agent_id,
|
|
34
|
+
title
|
|
35
|
+
) SELECT
|
|
36
|
+
$1,
|
|
37
|
+
$2,
|
|
38
|
+
valid_agent.root_agent_id,
|
|
39
|
+
COALESCE($3::text, '')
|
|
40
|
+
FROM valid_agent
|
|
41
|
+
RETURNING id, organization_id, created_by_user_id, root_agent_id, title, last_message_at, created_at, updated_at`;
|
|
43
42
|
async function createChatSession(client, args) {
|
|
44
43
|
const result = await client.query({
|
|
45
44
|
text: exports.createChatSessionQuery,
|
|
46
|
-
values: [args.
|
|
45
|
+
values: [args.organizationId, args.createdByUserId, args.title, args.rootAgentId],
|
|
47
46
|
rowMode: "array"
|
|
48
47
|
});
|
|
49
48
|
if (result.rows.length !== 1) {
|
|
@@ -54,22 +53,23 @@ async function createChatSession(client, args) {
|
|
|
54
53
|
id: row[0],
|
|
55
54
|
organizationId: row[1],
|
|
56
55
|
createdByUserId: row[2],
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
rootAgentId: row[3],
|
|
57
|
+
title: row[4],
|
|
58
|
+
lastMessageAt: row[5],
|
|
60
59
|
createdAt: row[6],
|
|
61
|
-
updatedAt: row[7]
|
|
62
|
-
lastMessageAt: row[8],
|
|
63
|
-
deletedAt: row[9]
|
|
60
|
+
updatedAt: row[7]
|
|
64
61
|
};
|
|
65
62
|
}
|
|
66
63
|
exports.getChatSessionQuery = `-- name: GetChatSession :one
|
|
67
|
-
SELECT id, organization_id, created_by_user_id,
|
|
68
|
-
|
|
64
|
+
SELECT id, organization_id, created_by_user_id, root_agent_id, title, last_message_at, created_at, updated_at
|
|
65
|
+
FROM weave.chat_session
|
|
66
|
+
WHERE organization_id = $1
|
|
67
|
+
AND id = $2
|
|
68
|
+
AND created_by_user_id = $3`;
|
|
69
69
|
async function getChatSession(client, args) {
|
|
70
70
|
const result = await client.query({
|
|
71
71
|
text: exports.getChatSessionQuery,
|
|
72
|
-
values: [args.
|
|
72
|
+
values: [args.organizationId, args.sessionId, args.createdByUserId],
|
|
73
73
|
rowMode: "array"
|
|
74
74
|
});
|
|
75
75
|
if (result.rows.length !== 1) {
|
|
@@ -80,56 +80,25 @@ async function getChatSession(client, args) {
|
|
|
80
80
|
id: row[0],
|
|
81
81
|
organizationId: row[1],
|
|
82
82
|
createdByUserId: row[2],
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
rootAgentId: row[3],
|
|
84
|
+
title: row[4],
|
|
85
|
+
lastMessageAt: row[5],
|
|
86
86
|
createdAt: row[6],
|
|
87
|
-
updatedAt: row[7]
|
|
88
|
-
lastMessageAt: row[8],
|
|
89
|
-
deletedAt: row[9]
|
|
87
|
+
updatedAt: row[7]
|
|
90
88
|
};
|
|
91
89
|
}
|
|
92
|
-
exports.
|
|
93
|
-
SELECT id, organization_id, created_by_user_id,
|
|
90
|
+
exports.listChatSessionsByUserQuery = `-- name: ListChatSessionsByUser :many
|
|
91
|
+
SELECT id, organization_id, created_by_user_id, root_agent_id, title, last_message_at, created_at, updated_at
|
|
92
|
+
FROM weave.chat_session
|
|
94
93
|
WHERE organization_id = $1
|
|
95
94
|
AND created_by_user_id = $2
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
async function
|
|
100
|
-
const result = await client.query({
|
|
101
|
-
text: exports.listChatSessionsForUserQuery,
|
|
102
|
-
values: [args.organizationId, args.createdByUserId, args.limit, args.offset],
|
|
103
|
-
rowMode: "array"
|
|
104
|
-
});
|
|
105
|
-
return result.rows.map(row => {
|
|
106
|
-
return {
|
|
107
|
-
id: row[0],
|
|
108
|
-
organizationId: row[1],
|
|
109
|
-
createdByUserId: row[2],
|
|
110
|
-
title: row[3],
|
|
111
|
-
modelId: row[4],
|
|
112
|
-
providerConfigurationId: row[5],
|
|
113
|
-
createdAt: row[6],
|
|
114
|
-
updatedAt: row[7],
|
|
115
|
-
lastMessageAt: row[8],
|
|
116
|
-
deletedAt: row[9]
|
|
117
|
-
};
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
exports.listChatSessionsForUserByProjectQuery = `-- name: ListChatSessionsForUserByProject :many
|
|
121
|
-
SELECT s.id, s.organization_id, s.created_by_user_id, s.title, s.model_id, s.provider_configuration_id, s.created_at, s.updated_at, s.last_message_at, s.deleted_at FROM weave.chat_sessions s
|
|
122
|
-
JOIN weave.chat_session_projects p ON p.session_id = s.id
|
|
123
|
-
WHERE s.organization_id = $1
|
|
124
|
-
AND s.created_by_user_id = $2
|
|
125
|
-
AND p.project_id = $3
|
|
126
|
-
AND s.deleted_at IS NULL
|
|
127
|
-
ORDER BY s.last_message_at DESC
|
|
128
|
-
LIMIT $4 OFFSET $5`;
|
|
129
|
-
async function listChatSessionsForUserByProject(client, args) {
|
|
95
|
+
ORDER BY last_message_at DESC, created_at DESC
|
|
96
|
+
LIMIT $4::integer
|
|
97
|
+
OFFSET $3::integer`;
|
|
98
|
+
async function listChatSessionsByUser(client, args) {
|
|
130
99
|
const result = await client.query({
|
|
131
|
-
text: exports.
|
|
132
|
-
values: [args.organizationId, args.createdByUserId, args.
|
|
100
|
+
text: exports.listChatSessionsByUserQuery,
|
|
101
|
+
values: [args.organizationId, args.createdByUserId, args.offsetCount, args.limitCount],
|
|
133
102
|
rowMode: "array"
|
|
134
103
|
});
|
|
135
104
|
return result.rows.map(row => {
|
|
@@ -137,55 +106,25 @@ async function listChatSessionsForUserByProject(client, args) {
|
|
|
137
106
|
id: row[0],
|
|
138
107
|
organizationId: row[1],
|
|
139
108
|
createdByUserId: row[2],
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
109
|
+
rootAgentId: row[3],
|
|
110
|
+
title: row[4],
|
|
111
|
+
lastMessageAt: row[5],
|
|
143
112
|
createdAt: row[6],
|
|
144
|
-
updatedAt: row[7]
|
|
145
|
-
lastMessageAt: row[8],
|
|
146
|
-
deletedAt: row[9]
|
|
113
|
+
updatedAt: row[7]
|
|
147
114
|
};
|
|
148
115
|
});
|
|
149
116
|
}
|
|
150
|
-
exports.updateChatSessionModelQuery = `-- name: UpdateChatSessionModel :one
|
|
151
|
-
UPDATE weave.chat_sessions
|
|
152
|
-
SET model_id = $2,
|
|
153
|
-
provider_configuration_id = $3,
|
|
154
|
-
updated_at = now()
|
|
155
|
-
WHERE id = $1
|
|
156
|
-
RETURNING id, organization_id, created_by_user_id, title, model_id, provider_configuration_id, created_at, updated_at, last_message_at, deleted_at`;
|
|
157
|
-
async function updateChatSessionModel(client, args) {
|
|
158
|
-
const result = await client.query({
|
|
159
|
-
text: exports.updateChatSessionModelQuery,
|
|
160
|
-
values: [args.id, args.modelId, args.providerConfigurationId],
|
|
161
|
-
rowMode: "array"
|
|
162
|
-
});
|
|
163
|
-
if (result.rows.length !== 1) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
const row = result.rows[0];
|
|
167
|
-
return {
|
|
168
|
-
id: row[0],
|
|
169
|
-
organizationId: row[1],
|
|
170
|
-
createdByUserId: row[2],
|
|
171
|
-
title: row[3],
|
|
172
|
-
modelId: row[4],
|
|
173
|
-
providerConfigurationId: row[5],
|
|
174
|
-
createdAt: row[6],
|
|
175
|
-
updatedAt: row[7],
|
|
176
|
-
lastMessageAt: row[8],
|
|
177
|
-
deletedAt: row[9]
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
117
|
exports.updateChatSessionTitleQuery = `-- name: UpdateChatSessionTitle :one
|
|
181
|
-
UPDATE weave.
|
|
182
|
-
SET title = $
|
|
183
|
-
WHERE
|
|
184
|
-
|
|
118
|
+
UPDATE weave.chat_session
|
|
119
|
+
SET title = $1
|
|
120
|
+
WHERE organization_id = $2
|
|
121
|
+
AND id = $3
|
|
122
|
+
AND created_by_user_id = $4
|
|
123
|
+
RETURNING id, organization_id, created_by_user_id, root_agent_id, title, last_message_at, created_at, updated_at`;
|
|
185
124
|
async function updateChatSessionTitle(client, args) {
|
|
186
125
|
const result = await client.query({
|
|
187
126
|
text: exports.updateChatSessionTitleQuery,
|
|
188
|
-
values: [args.
|
|
127
|
+
values: [args.title, args.organizationId, args.sessionId, args.createdByUserId],
|
|
189
128
|
rowMode: "array"
|
|
190
129
|
});
|
|
191
130
|
if (result.rows.length !== 1) {
|
|
@@ -196,254 +135,51 @@ async function updateChatSessionTitle(client, args) {
|
|
|
196
135
|
id: row[0],
|
|
197
136
|
organizationId: row[1],
|
|
198
137
|
createdByUserId: row[2],
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
138
|
+
rootAgentId: row[3],
|
|
139
|
+
title: row[4],
|
|
140
|
+
lastMessageAt: row[5],
|
|
202
141
|
createdAt: row[6],
|
|
203
|
-
updatedAt: row[7]
|
|
204
|
-
lastMessageAt: row[8],
|
|
205
|
-
deletedAt: row[9]
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
exports.touchChatSessionLastMessageQuery = `-- name: TouchChatSessionLastMessage :exec
|
|
209
|
-
UPDATE weave.chat_sessions
|
|
210
|
-
SET last_message_at = $2, updated_at = $2
|
|
211
|
-
WHERE id = $1`;
|
|
212
|
-
async function touchChatSessionLastMessage(client, args) {
|
|
213
|
-
await client.query({
|
|
214
|
-
text: exports.touchChatSessionLastMessageQuery,
|
|
215
|
-
values: [args.id, args.lastMessageAt],
|
|
216
|
-
rowMode: "array"
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
exports.softDeleteChatSessionQuery = `-- name: SoftDeleteChatSession :exec
|
|
220
|
-
UPDATE weave.chat_sessions
|
|
221
|
-
SET deleted_at = now(), updated_at = now()
|
|
222
|
-
WHERE id = $1`;
|
|
223
|
-
async function softDeleteChatSession(client, args) {
|
|
224
|
-
await client.query({
|
|
225
|
-
text: exports.softDeleteChatSessionQuery,
|
|
226
|
-
values: [args.id],
|
|
227
|
-
rowMode: "array"
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
exports.attachProjectToChatSessionQuery = `-- name: AttachProjectToChatSession :exec
|
|
231
|
-
INSERT INTO weave.chat_session_projects (
|
|
232
|
-
session_id, project_id, attached_by_user_id
|
|
233
|
-
) VALUES ($1, $2, $3)
|
|
234
|
-
ON CONFLICT DO NOTHING`;
|
|
235
|
-
async function attachProjectToChatSession(client, args) {
|
|
236
|
-
await client.query({
|
|
237
|
-
text: exports.attachProjectToChatSessionQuery,
|
|
238
|
-
values: [args.sessionId, args.projectId, args.attachedByUserId],
|
|
239
|
-
rowMode: "array"
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
exports.detachProjectFromChatSessionQuery = `-- name: DetachProjectFromChatSession :exec
|
|
243
|
-
DELETE FROM weave.chat_session_projects
|
|
244
|
-
WHERE session_id = $1 AND project_id = $2`;
|
|
245
|
-
async function detachProjectFromChatSession(client, args) {
|
|
246
|
-
await client.query({
|
|
247
|
-
text: exports.detachProjectFromChatSessionQuery,
|
|
248
|
-
values: [args.sessionId, args.projectId],
|
|
249
|
-
rowMode: "array"
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
exports.listProjectsForChatSessionQuery = `-- name: ListProjectsForChatSession :many
|
|
253
|
-
SELECT project_id FROM weave.chat_session_projects
|
|
254
|
-
WHERE session_id = $1`;
|
|
255
|
-
async function listProjectsForChatSession(client, args) {
|
|
256
|
-
const result = await client.query({
|
|
257
|
-
text: exports.listProjectsForChatSessionQuery,
|
|
258
|
-
values: [args.sessionId],
|
|
259
|
-
rowMode: "array"
|
|
260
|
-
});
|
|
261
|
-
return result.rows.map(row => {
|
|
262
|
-
return {
|
|
263
|
-
projectId: row[0]
|
|
264
|
-
};
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
exports.insertChatMessageQuery = `-- name: InsertChatMessage :one
|
|
268
|
-
INSERT INTO weave.chat_messages (
|
|
269
|
-
id, session_id, role, content,
|
|
270
|
-
reasoning_content,
|
|
271
|
-
parent_message_id, tool_call_id, tool_call_state,
|
|
272
|
-
model_id, ephemeral_attachment_count, ephemeral_attachment_mime_types,
|
|
273
|
-
token_usage, stream_state
|
|
274
|
-
) VALUES (
|
|
275
|
-
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
|
|
276
|
-
)
|
|
277
|
-
RETURNING id, session_id, role, content, parent_message_id, tool_call_id, tool_call_state, model_id, ephemeral_attachment_count, ephemeral_attachment_mime_types, token_usage, stream_state, created_at, completed_at, reasoning_content`;
|
|
278
|
-
async function insertChatMessage(client, args) {
|
|
279
|
-
const result = await client.query({
|
|
280
|
-
text: exports.insertChatMessageQuery,
|
|
281
|
-
values: [args.id, args.sessionId, args.role, args.content, args.reasoningContent, args.parentMessageId, args.toolCallId, args.toolCallState, args.modelId, args.ephemeralAttachmentCount, args.ephemeralAttachmentMimeTypes, args.tokenUsage, args.streamState],
|
|
282
|
-
rowMode: "array"
|
|
283
|
-
});
|
|
284
|
-
if (result.rows.length !== 1) {
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
const row = result.rows[0];
|
|
288
|
-
return {
|
|
289
|
-
id: row[0],
|
|
290
|
-
sessionId: row[1],
|
|
291
|
-
role: row[2],
|
|
292
|
-
content: row[3],
|
|
293
|
-
parentMessageId: row[4],
|
|
294
|
-
toolCallId: row[5],
|
|
295
|
-
toolCallState: row[6],
|
|
296
|
-
modelId: row[7],
|
|
297
|
-
ephemeralAttachmentCount: row[8],
|
|
298
|
-
ephemeralAttachmentMimeTypes: row[9],
|
|
299
|
-
tokenUsage: row[10],
|
|
300
|
-
streamState: row[11],
|
|
301
|
-
createdAt: row[12],
|
|
302
|
-
completedAt: row[13],
|
|
303
|
-
reasoningContent: row[14]
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
exports.getChatMessageQuery = `-- name: GetChatMessage :one
|
|
307
|
-
SELECT id, session_id, role, content, parent_message_id, tool_call_id, tool_call_state, model_id, ephemeral_attachment_count, ephemeral_attachment_mime_types, token_usage, stream_state, created_at, completed_at, reasoning_content FROM weave.chat_messages WHERE id = $1`;
|
|
308
|
-
async function getChatMessage(client, args) {
|
|
309
|
-
const result = await client.query({
|
|
310
|
-
text: exports.getChatMessageQuery,
|
|
311
|
-
values: [args.id],
|
|
312
|
-
rowMode: "array"
|
|
313
|
-
});
|
|
314
|
-
if (result.rows.length !== 1) {
|
|
315
|
-
return null;
|
|
316
|
-
}
|
|
317
|
-
const row = result.rows[0];
|
|
318
|
-
return {
|
|
319
|
-
id: row[0],
|
|
320
|
-
sessionId: row[1],
|
|
321
|
-
role: row[2],
|
|
322
|
-
content: row[3],
|
|
323
|
-
parentMessageId: row[4],
|
|
324
|
-
toolCallId: row[5],
|
|
325
|
-
toolCallState: row[6],
|
|
326
|
-
modelId: row[7],
|
|
327
|
-
ephemeralAttachmentCount: row[8],
|
|
328
|
-
ephemeralAttachmentMimeTypes: row[9],
|
|
329
|
-
tokenUsage: row[10],
|
|
330
|
-
streamState: row[11],
|
|
331
|
-
createdAt: row[12],
|
|
332
|
-
completedAt: row[13],
|
|
333
|
-
reasoningContent: row[14]
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
exports.listChatMessagesForSessionQuery = `-- name: ListChatMessagesForSession :many
|
|
337
|
-
SELECT id, session_id, role, content, parent_message_id, tool_call_id, tool_call_state, model_id, ephemeral_attachment_count, ephemeral_attachment_mime_types, token_usage, stream_state, created_at, completed_at, reasoning_content FROM weave.chat_messages
|
|
338
|
-
WHERE session_id = $1
|
|
339
|
-
ORDER BY created_at`;
|
|
340
|
-
async function listChatMessagesForSession(client, args) {
|
|
341
|
-
const result = await client.query({
|
|
342
|
-
text: exports.listChatMessagesForSessionQuery,
|
|
343
|
-
values: [args.sessionId],
|
|
344
|
-
rowMode: "array"
|
|
345
|
-
});
|
|
346
|
-
return result.rows.map(row => {
|
|
347
|
-
return {
|
|
348
|
-
id: row[0],
|
|
349
|
-
sessionId: row[1],
|
|
350
|
-
role: row[2],
|
|
351
|
-
content: row[3],
|
|
352
|
-
parentMessageId: row[4],
|
|
353
|
-
toolCallId: row[5],
|
|
354
|
-
toolCallState: row[6],
|
|
355
|
-
modelId: row[7],
|
|
356
|
-
ephemeralAttachmentCount: row[8],
|
|
357
|
-
ephemeralAttachmentMimeTypes: row[9],
|
|
358
|
-
tokenUsage: row[10],
|
|
359
|
-
streamState: row[11],
|
|
360
|
-
createdAt: row[12],
|
|
361
|
-
completedAt: row[13],
|
|
362
|
-
reasoningContent: row[14]
|
|
363
|
-
};
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
exports.updateChatMessageToolCallStateQuery = `-- name: UpdateChatMessageToolCallState :one
|
|
367
|
-
UPDATE weave.chat_messages
|
|
368
|
-
SET tool_call_state = $2
|
|
369
|
-
WHERE id = $1
|
|
370
|
-
RETURNING id, session_id, role, content, parent_message_id, tool_call_id, tool_call_state, model_id, ephemeral_attachment_count, ephemeral_attachment_mime_types, token_usage, stream_state, created_at, completed_at, reasoning_content`;
|
|
371
|
-
async function updateChatMessageToolCallState(client, args) {
|
|
372
|
-
const result = await client.query({
|
|
373
|
-
text: exports.updateChatMessageToolCallStateQuery,
|
|
374
|
-
values: [args.id, args.toolCallState],
|
|
375
|
-
rowMode: "array"
|
|
376
|
-
});
|
|
377
|
-
if (result.rows.length !== 1) {
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
const row = result.rows[0];
|
|
381
|
-
return {
|
|
382
|
-
id: row[0],
|
|
383
|
-
sessionId: row[1],
|
|
384
|
-
role: row[2],
|
|
385
|
-
content: row[3],
|
|
386
|
-
parentMessageId: row[4],
|
|
387
|
-
toolCallId: row[5],
|
|
388
|
-
toolCallState: row[6],
|
|
389
|
-
modelId: row[7],
|
|
390
|
-
ephemeralAttachmentCount: row[8],
|
|
391
|
-
ephemeralAttachmentMimeTypes: row[9],
|
|
392
|
-
tokenUsage: row[10],
|
|
393
|
-
streamState: row[11],
|
|
394
|
-
createdAt: row[12],
|
|
395
|
-
completedAt: row[13],
|
|
396
|
-
reasoningContent: row[14]
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
exports.completeChatMessageQuery = `-- name: CompleteChatMessage :one
|
|
400
|
-
UPDATE weave.chat_messages
|
|
401
|
-
SET stream_state = $2,
|
|
402
|
-
content = $3,
|
|
403
|
-
reasoning_content = $4,
|
|
404
|
-
token_usage = $5,
|
|
405
|
-
completed_at = now()
|
|
406
|
-
WHERE id = $1
|
|
407
|
-
RETURNING id, session_id, role, content, parent_message_id, tool_call_id, tool_call_state, model_id, ephemeral_attachment_count, ephemeral_attachment_mime_types, token_usage, stream_state, created_at, completed_at, reasoning_content`;
|
|
408
|
-
async function completeChatMessage(client, args) {
|
|
409
|
-
const result = await client.query({
|
|
410
|
-
text: exports.completeChatMessageQuery,
|
|
411
|
-
values: [args.id, args.streamState, args.content, args.reasoningContent, args.tokenUsage],
|
|
412
|
-
rowMode: "array"
|
|
413
|
-
});
|
|
414
|
-
if (result.rows.length !== 1) {
|
|
415
|
-
return null;
|
|
416
|
-
}
|
|
417
|
-
const row = result.rows[0];
|
|
418
|
-
return {
|
|
419
|
-
id: row[0],
|
|
420
|
-
sessionId: row[1],
|
|
421
|
-
role: row[2],
|
|
422
|
-
content: row[3],
|
|
423
|
-
parentMessageId: row[4],
|
|
424
|
-
toolCallId: row[5],
|
|
425
|
-
toolCallState: row[6],
|
|
426
|
-
modelId: row[7],
|
|
427
|
-
ephemeralAttachmentCount: row[8],
|
|
428
|
-
ephemeralAttachmentMimeTypes: row[9],
|
|
429
|
-
tokenUsage: row[10],
|
|
430
|
-
streamState: row[11],
|
|
431
|
-
createdAt: row[12],
|
|
432
|
-
completedAt: row[13],
|
|
433
|
-
reasoningContent: row[14]
|
|
142
|
+
updatedAt: row[7]
|
|
434
143
|
};
|
|
435
144
|
}
|
|
436
|
-
exports.
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
145
|
+
exports.createChatMessageQuery = `-- name: CreateChatMessage :one
|
|
146
|
+
WITH created_message AS (
|
|
147
|
+
INSERT INTO weave.chat_message (
|
|
148
|
+
organization_id,
|
|
149
|
+
session_id,
|
|
150
|
+
agent_run_id,
|
|
151
|
+
role,
|
|
152
|
+
parts
|
|
153
|
+
)
|
|
154
|
+
SELECT
|
|
155
|
+
$1,
|
|
156
|
+
$2,
|
|
157
|
+
$3::uuid,
|
|
158
|
+
$4,
|
|
159
|
+
COALESCE($5::jsonb, '[]'::jsonb)
|
|
160
|
+
WHERE EXISTS (
|
|
161
|
+
SELECT 1
|
|
162
|
+
FROM weave.chat_session s
|
|
163
|
+
WHERE s.organization_id = $1
|
|
164
|
+
AND s.id = $2
|
|
165
|
+
AND s.created_by_user_id = $6
|
|
166
|
+
)
|
|
167
|
+
RETURNING id, organization_id, session_id, agent_run_id, role, parts, created_at
|
|
168
|
+
),
|
|
169
|
+
touched_session AS (
|
|
170
|
+
UPDATE weave.chat_session
|
|
171
|
+
SET last_message_at = created_message.created_at
|
|
172
|
+
FROM created_message
|
|
173
|
+
WHERE weave.chat_session.organization_id = created_message.organization_id
|
|
174
|
+
AND weave.chat_session.id = created_message.session_id
|
|
175
|
+
RETURNING weave.chat_session.id
|
|
441
176
|
)
|
|
442
|
-
|
|
443
|
-
|
|
177
|
+
SELECT id, organization_id, session_id, agent_run_id, role, parts, created_at
|
|
178
|
+
FROM created_message`;
|
|
179
|
+
async function createChatMessage(client, args) {
|
|
444
180
|
const result = await client.query({
|
|
445
|
-
text: exports.
|
|
446
|
-
values: [args.
|
|
181
|
+
text: exports.createChatMessageQuery,
|
|
182
|
+
values: [args.organizationId, args.sessionId, args.agentRunId, args.role, args.parts, args.createdByUserId],
|
|
447
183
|
rowMode: "array"
|
|
448
184
|
});
|
|
449
185
|
if (result.rows.length !== 1) {
|
|
@@ -453,52 +189,70 @@ async function createOrganizationApprovedModel(client, args) {
|
|
|
453
189
|
return {
|
|
454
190
|
id: row[0],
|
|
455
191
|
organizationId: row[1],
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
192
|
+
sessionId: row[2],
|
|
193
|
+
agentRunId: row[3],
|
|
194
|
+
role: row[4],
|
|
195
|
+
parts: row[5],
|
|
196
|
+
createdAt: row[6]
|
|
460
197
|
};
|
|
461
198
|
}
|
|
462
|
-
exports.
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
ORDER BY approved_at DESC`;
|
|
476
|
-
async function listOrganizationApprovedModels(client, args) {
|
|
199
|
+
exports.listChatMessagesQuery = `-- name: ListChatMessages :many
|
|
200
|
+
SELECT m.id, m.organization_id, m.session_id, m.agent_run_id, m.role, m.parts, m.created_at
|
|
201
|
+
FROM weave.chat_message m
|
|
202
|
+
JOIN weave.chat_session s
|
|
203
|
+
ON s.organization_id = m.organization_id
|
|
204
|
+
AND s.id = m.session_id
|
|
205
|
+
WHERE m.organization_id = $1
|
|
206
|
+
AND m.session_id = $2
|
|
207
|
+
AND s.created_by_user_id = $3
|
|
208
|
+
ORDER BY m.created_at ASC, m.id ASC
|
|
209
|
+
LIMIT $5::integer
|
|
210
|
+
OFFSET $4::integer`;
|
|
211
|
+
async function listChatMessages(client, args) {
|
|
477
212
|
const result = await client.query({
|
|
478
|
-
text: exports.
|
|
479
|
-
values: [args.organizationId],
|
|
213
|
+
text: exports.listChatMessagesQuery,
|
|
214
|
+
values: [args.organizationId, args.sessionId, args.createdByUserId, args.offsetCount, args.limitCount],
|
|
480
215
|
rowMode: "array"
|
|
481
216
|
});
|
|
482
217
|
return result.rows.map(row => {
|
|
483
218
|
return {
|
|
484
219
|
id: row[0],
|
|
485
220
|
organizationId: row[1],
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
221
|
+
sessionId: row[2],
|
|
222
|
+
agentRunId: row[3],
|
|
223
|
+
role: row[4],
|
|
224
|
+
parts: row[5],
|
|
225
|
+
createdAt: row[6]
|
|
490
226
|
};
|
|
491
227
|
});
|
|
492
228
|
}
|
|
493
|
-
exports.
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
229
|
+
exports.createChatArtifactQuery = `-- name: CreateChatArtifact :one
|
|
230
|
+
WITH visible_session AS (
|
|
231
|
+
SELECT s.id
|
|
232
|
+
FROM weave.chat_session s
|
|
233
|
+
WHERE s.organization_id = $1
|
|
234
|
+
AND s.id = $5
|
|
235
|
+
AND s.created_by_user_id = $6
|
|
236
|
+
)
|
|
237
|
+
INSERT INTO weave.chat_artifact (
|
|
238
|
+
organization_id,
|
|
239
|
+
session_id,
|
|
240
|
+
title,
|
|
241
|
+
kind,
|
|
242
|
+
language
|
|
243
|
+
)
|
|
244
|
+
SELECT
|
|
245
|
+
$1,
|
|
246
|
+
visible_session.id,
|
|
247
|
+
$2,
|
|
248
|
+
$3,
|
|
249
|
+
$4::text
|
|
250
|
+
FROM visible_session
|
|
251
|
+
RETURNING id, organization_id, session_id, title, kind, language, current_version, created_at, updated_at`;
|
|
252
|
+
async function createChatArtifact(client, args) {
|
|
499
253
|
const result = await client.query({
|
|
500
|
-
text: exports.
|
|
501
|
-
values: [args.organizationId, args.
|
|
254
|
+
text: exports.createChatArtifactQuery,
|
|
255
|
+
values: [args.organizationId, args.title, args.kind, args.language, args.sessionId, args.createdByUserId],
|
|
502
256
|
rowMode: "array"
|
|
503
257
|
});
|
|
504
258
|
if (result.rows.length !== 1) {
|
|
@@ -508,82 +262,34 @@ async function getOrganizationApprovedModel(client, args) {
|
|
|
508
262
|
return {
|
|
509
263
|
id: row[0],
|
|
510
264
|
organizationId: row[1],
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
INSERT INTO weave.organization_chat_settings (
|
|
519
|
-
organization_id, default_chat_model_id, default_provider_configuration_id
|
|
520
|
-
) VALUES ($1, $2, $3)
|
|
521
|
-
ON CONFLICT (organization_id) DO UPDATE
|
|
522
|
-
SET default_chat_model_id = EXCLUDED.default_chat_model_id,
|
|
523
|
-
default_provider_configuration_id = EXCLUDED.default_provider_configuration_id,
|
|
524
|
-
updated_at = now()
|
|
525
|
-
RETURNING organization_id, default_chat_model_id, default_provider_configuration_id, updated_at`;
|
|
526
|
-
async function upsertOrganizationChatSettings(client, args) {
|
|
527
|
-
const result = await client.query({
|
|
528
|
-
text: exports.upsertOrganizationChatSettingsQuery,
|
|
529
|
-
values: [args.organizationId, args.defaultChatModelId, args.defaultProviderConfigurationId],
|
|
530
|
-
rowMode: "array"
|
|
531
|
-
});
|
|
532
|
-
if (result.rows.length !== 1) {
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
const row = result.rows[0];
|
|
536
|
-
return {
|
|
537
|
-
organizationId: row[0],
|
|
538
|
-
defaultChatModelId: row[1],
|
|
539
|
-
defaultProviderConfigurationId: row[2],
|
|
540
|
-
updatedAt: row[3]
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
exports.getOrganizationChatSettingsQuery = `-- name: GetOrganizationChatSettings :one
|
|
544
|
-
SELECT organization_id, default_chat_model_id, default_provider_configuration_id, updated_at FROM weave.organization_chat_settings
|
|
545
|
-
WHERE organization_id = $1`;
|
|
546
|
-
async function getOrganizationChatSettings(client, args) {
|
|
547
|
-
const result = await client.query({
|
|
548
|
-
text: exports.getOrganizationChatSettingsQuery,
|
|
549
|
-
values: [args.organizationId],
|
|
550
|
-
rowMode: "array"
|
|
551
|
-
});
|
|
552
|
-
if (result.rows.length !== 1) {
|
|
553
|
-
return null;
|
|
554
|
-
}
|
|
555
|
-
const row = result.rows[0];
|
|
556
|
-
return {
|
|
557
|
-
organizationId: row[0],
|
|
558
|
-
defaultChatModelId: row[1],
|
|
559
|
-
defaultProviderConfigurationId: row[2],
|
|
560
|
-
updatedAt: row[3]
|
|
265
|
+
sessionId: row[2],
|
|
266
|
+
title: row[3],
|
|
267
|
+
kind: row[4],
|
|
268
|
+
language: row[5],
|
|
269
|
+
currentVersion: row[6],
|
|
270
|
+
createdAt: row[7],
|
|
271
|
+
updatedAt: row[8]
|
|
561
272
|
};
|
|
562
273
|
}
|
|
563
|
-
exports.
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
INSERT INTO weave.chat_artifacts (
|
|
580
|
-
id, session_id, title, kind, language, current_version
|
|
581
|
-
) VALUES ($1, $2, $3, $4, $5, 1)
|
|
582
|
-
RETURNING id, session_id, title, kind, language, current_version, created_at, updated_at`;
|
|
583
|
-
async function createChatArtifact(client, args) {
|
|
274
|
+
exports.bumpChatArtifactVersionQuery = `-- name: BumpChatArtifactVersion :one
|
|
275
|
+
WITH visible_session AS (
|
|
276
|
+
SELECT s.id
|
|
277
|
+
FROM weave.chat_session s
|
|
278
|
+
WHERE s.organization_id = $1
|
|
279
|
+
AND s.id = $3
|
|
280
|
+
AND s.created_by_user_id = $4
|
|
281
|
+
)
|
|
282
|
+
UPDATE weave.chat_artifact
|
|
283
|
+
SET current_version = current_version + 1
|
|
284
|
+
FROM visible_session
|
|
285
|
+
WHERE chat_artifact.organization_id = $1
|
|
286
|
+
AND chat_artifact.session_id = visible_session.id
|
|
287
|
+
AND chat_artifact.id = $2
|
|
288
|
+
RETURNING chat_artifact.id, chat_artifact.organization_id, chat_artifact.session_id, chat_artifact.title, chat_artifact.kind, chat_artifact.language, chat_artifact.current_version, chat_artifact.created_at, chat_artifact.updated_at`;
|
|
289
|
+
async function bumpChatArtifactVersion(client, args) {
|
|
584
290
|
const result = await client.query({
|
|
585
|
-
text: exports.
|
|
586
|
-
values: [args.
|
|
291
|
+
text: exports.bumpChatArtifactVersionQuery,
|
|
292
|
+
values: [args.organizationId, args.artifactId, args.sessionId, args.createdByUserId],
|
|
587
293
|
rowMode: "array"
|
|
588
294
|
});
|
|
589
295
|
if (result.rows.length !== 1) {
|
|
@@ -592,25 +298,30 @@ async function createChatArtifact(client, args) {
|
|
|
592
298
|
const row = result.rows[0];
|
|
593
299
|
return {
|
|
594
300
|
id: row[0],
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
301
|
+
organizationId: row[1],
|
|
302
|
+
sessionId: row[2],
|
|
303
|
+
title: row[3],
|
|
304
|
+
kind: row[4],
|
|
305
|
+
language: row[5],
|
|
306
|
+
currentVersion: row[6],
|
|
307
|
+
createdAt: row[7],
|
|
308
|
+
updatedAt: row[8]
|
|
602
309
|
};
|
|
603
310
|
}
|
|
604
|
-
exports.
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
311
|
+
exports.getChatArtifactQuery = `-- name: GetChatArtifact :one
|
|
312
|
+
SELECT a.id, a.organization_id, a.session_id, a.title, a.kind, a.language, a.current_version, a.created_at, a.updated_at
|
|
313
|
+
FROM weave.chat_artifact a
|
|
314
|
+
JOIN weave.chat_session s
|
|
315
|
+
ON s.organization_id = a.organization_id
|
|
316
|
+
AND s.id = a.session_id
|
|
317
|
+
WHERE a.organization_id = $1
|
|
318
|
+
AND a.session_id = $2
|
|
319
|
+
AND a.id = $3
|
|
320
|
+
AND s.created_by_user_id = $4`;
|
|
321
|
+
async function getChatArtifact(client, args) {
|
|
611
322
|
const result = await client.query({
|
|
612
|
-
text: exports.
|
|
613
|
-
values: [args.
|
|
323
|
+
text: exports.getChatArtifactQuery,
|
|
324
|
+
values: [args.organizationId, args.sessionId, args.artifactId, args.createdByUserId],
|
|
614
325
|
rowMode: "array"
|
|
615
326
|
});
|
|
616
327
|
if (result.rows.length !== 1) {
|
|
@@ -619,70 +330,70 @@ async function bumpChatArtifactVersion(client, args) {
|
|
|
619
330
|
const row = result.rows[0];
|
|
620
331
|
return {
|
|
621
332
|
id: row[0],
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
333
|
+
organizationId: row[1],
|
|
334
|
+
sessionId: row[2],
|
|
335
|
+
title: row[3],
|
|
336
|
+
kind: row[4],
|
|
337
|
+
language: row[5],
|
|
338
|
+
currentVersion: row[6],
|
|
339
|
+
createdAt: row[7],
|
|
340
|
+
updatedAt: row[8]
|
|
629
341
|
};
|
|
630
342
|
}
|
|
631
|
-
exports.
|
|
632
|
-
SELECT id, session_id, title, kind, language, current_version, created_at, updated_at
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
343
|
+
exports.listChatArtifactsQuery = `-- name: ListChatArtifacts :many
|
|
344
|
+
SELECT a.id, a.organization_id, a.session_id, a.title, a.kind, a.language, a.current_version, a.created_at, a.updated_at
|
|
345
|
+
FROM weave.chat_artifact a
|
|
346
|
+
JOIN weave.chat_session s
|
|
347
|
+
ON s.organization_id = a.organization_id
|
|
348
|
+
AND s.id = a.session_id
|
|
349
|
+
WHERE a.organization_id = $1
|
|
350
|
+
AND a.session_id = $2
|
|
351
|
+
AND s.created_by_user_id = $3
|
|
352
|
+
ORDER BY a.created_at ASC, a.id ASC`;
|
|
353
|
+
async function listChatArtifacts(client, args) {
|
|
636
354
|
const result = await client.query({
|
|
637
|
-
text: exports.
|
|
638
|
-
values: [args.sessionId],
|
|
355
|
+
text: exports.listChatArtifactsQuery,
|
|
356
|
+
values: [args.organizationId, args.sessionId, args.createdByUserId],
|
|
639
357
|
rowMode: "array"
|
|
640
358
|
});
|
|
641
359
|
return result.rows.map(row => {
|
|
642
360
|
return {
|
|
643
361
|
id: row[0],
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
362
|
+
organizationId: row[1],
|
|
363
|
+
sessionId: row[2],
|
|
364
|
+
title: row[3],
|
|
365
|
+
kind: row[4],
|
|
366
|
+
language: row[5],
|
|
367
|
+
currentVersion: row[6],
|
|
368
|
+
createdAt: row[7],
|
|
369
|
+
updatedAt: row[8]
|
|
651
370
|
};
|
|
652
371
|
});
|
|
653
372
|
}
|
|
654
|
-
exports.
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
exports.insertChatArtifactVersionQuery = `-- name: InsertChatArtifactVersion :one
|
|
678
|
-
INSERT INTO weave.chat_artifact_versions (
|
|
679
|
-
id, artifact_id, version, content, created_by_message_id
|
|
680
|
-
) VALUES ($1, $2, $3, $4, $5)
|
|
681
|
-
RETURNING id, artifact_id, version, content, created_by_message_id, created_at, document_references`;
|
|
682
|
-
async function insertChatArtifactVersion(client, args) {
|
|
373
|
+
exports.createChatArtifactVersionQuery = `-- name: CreateChatArtifactVersion :one
|
|
374
|
+
INSERT INTO weave.chat_artifact_version (
|
|
375
|
+
organization_id,
|
|
376
|
+
artifact_id,
|
|
377
|
+
version,
|
|
378
|
+
content,
|
|
379
|
+
created_by_agent_run_id,
|
|
380
|
+
tool_call_id,
|
|
381
|
+
document_references
|
|
382
|
+
)
|
|
383
|
+
VALUES (
|
|
384
|
+
$1,
|
|
385
|
+
$2,
|
|
386
|
+
$3,
|
|
387
|
+
$4,
|
|
388
|
+
$5::uuid,
|
|
389
|
+
COALESCE($6::text, ''),
|
|
390
|
+
COALESCE($7::jsonb, '[]'::jsonb)
|
|
391
|
+
)
|
|
392
|
+
RETURNING id, organization_id, artifact_id, version, content, created_by_agent_run_id, tool_call_id, document_references, created_at`;
|
|
393
|
+
async function createChatArtifactVersion(client, args) {
|
|
683
394
|
const result = await client.query({
|
|
684
|
-
text: exports.
|
|
685
|
-
values: [args.
|
|
395
|
+
text: exports.createChatArtifactVersionQuery,
|
|
396
|
+
values: [args.organizationId, args.artifactId, args.version, args.content, args.createdByAgentRunId, args.toolCallId, args.documentReferences],
|
|
686
397
|
rowMode: "array"
|
|
687
398
|
});
|
|
688
399
|
if (result.rows.length !== 1) {
|
|
@@ -691,23 +402,34 @@ async function insertChatArtifactVersion(client, args) {
|
|
|
691
402
|
const row = result.rows[0];
|
|
692
403
|
return {
|
|
693
404
|
id: row[0],
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
405
|
+
organizationId: row[1],
|
|
406
|
+
artifactId: row[2],
|
|
407
|
+
version: row[3],
|
|
408
|
+
content: row[4],
|
|
409
|
+
createdByAgentRunId: row[5],
|
|
410
|
+
toolCallId: row[6],
|
|
411
|
+
documentReferences: row[7],
|
|
412
|
+
createdAt: row[8]
|
|
700
413
|
};
|
|
701
414
|
}
|
|
702
|
-
exports.
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
415
|
+
exports.getChatArtifactVersionQuery = `-- name: GetChatArtifactVersion :one
|
|
416
|
+
SELECT v.id, v.organization_id, v.artifact_id, v.version, v.content, v.created_by_agent_run_id, v.tool_call_id, v.document_references, v.created_at
|
|
417
|
+
FROM weave.chat_artifact_version v
|
|
418
|
+
JOIN weave.chat_artifact a
|
|
419
|
+
ON a.organization_id = v.organization_id
|
|
420
|
+
AND a.id = v.artifact_id
|
|
421
|
+
JOIN weave.chat_session s
|
|
422
|
+
ON s.organization_id = a.organization_id
|
|
423
|
+
AND s.id = a.session_id
|
|
424
|
+
WHERE v.organization_id = $1
|
|
425
|
+
AND a.session_id = $2
|
|
426
|
+
AND v.artifact_id = $3
|
|
427
|
+
AND v.version = $4
|
|
428
|
+
AND s.created_by_user_id = $5`;
|
|
429
|
+
async function getChatArtifactVersion(client, args) {
|
|
708
430
|
const result = await client.query({
|
|
709
|
-
text: exports.
|
|
710
|
-
values: [args.
|
|
431
|
+
text: exports.getChatArtifactVersionQuery,
|
|
432
|
+
values: [args.organizationId, args.sessionId, args.artifactId, args.version, args.createdByUserId],
|
|
711
433
|
rowMode: "array"
|
|
712
434
|
});
|
|
713
435
|
if (result.rows.length !== 1) {
|
|
@@ -716,21 +438,34 @@ async function insertChatArtifactVersionWithDocumentReferences(client, args) {
|
|
|
716
438
|
const row = result.rows[0];
|
|
717
439
|
return {
|
|
718
440
|
id: row[0],
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
441
|
+
organizationId: row[1],
|
|
442
|
+
artifactId: row[2],
|
|
443
|
+
version: row[3],
|
|
444
|
+
content: row[4],
|
|
445
|
+
createdByAgentRunId: row[5],
|
|
446
|
+
toolCallId: row[6],
|
|
447
|
+
documentReferences: row[7],
|
|
448
|
+
createdAt: row[8]
|
|
725
449
|
};
|
|
726
450
|
}
|
|
727
|
-
exports.
|
|
728
|
-
SELECT id, artifact_id, version, content,
|
|
729
|
-
|
|
730
|
-
|
|
451
|
+
exports.getCurrentChatArtifactVersionQuery = `-- name: GetCurrentChatArtifactVersion :one
|
|
452
|
+
SELECT v.id, v.organization_id, v.artifact_id, v.version, v.content, v.created_by_agent_run_id, v.tool_call_id, v.document_references, v.created_at
|
|
453
|
+
FROM weave.chat_artifact_version v
|
|
454
|
+
JOIN weave.chat_artifact a
|
|
455
|
+
ON a.organization_id = v.organization_id
|
|
456
|
+
AND a.id = v.artifact_id
|
|
457
|
+
JOIN weave.chat_session s
|
|
458
|
+
ON s.organization_id = a.organization_id
|
|
459
|
+
AND s.id = a.session_id
|
|
460
|
+
WHERE v.organization_id = $1
|
|
461
|
+
AND a.session_id = $2
|
|
462
|
+
AND v.artifact_id = $3
|
|
463
|
+
AND v.version = a.current_version
|
|
464
|
+
AND s.created_by_user_id = $4`;
|
|
465
|
+
async function getCurrentChatArtifactVersion(client, args) {
|
|
731
466
|
const result = await client.query({
|
|
732
|
-
text: exports.
|
|
733
|
-
values: [args.artifactId, args.
|
|
467
|
+
text: exports.getCurrentChatArtifactVersionQuery,
|
|
468
|
+
values: [args.organizationId, args.sessionId, args.artifactId, args.createdByUserId],
|
|
734
469
|
rowMode: "array"
|
|
735
470
|
});
|
|
736
471
|
if (result.rows.length !== 1) {
|
|
@@ -739,33 +474,13 @@ async function getChatArtifactVersion(client, args) {
|
|
|
739
474
|
const row = result.rows[0];
|
|
740
475
|
return {
|
|
741
476
|
id: row[0],
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
477
|
+
organizationId: row[1],
|
|
478
|
+
artifactId: row[2],
|
|
479
|
+
version: row[3],
|
|
480
|
+
content: row[4],
|
|
481
|
+
createdByAgentRunId: row[5],
|
|
482
|
+
toolCallId: row[6],
|
|
483
|
+
documentReferences: row[7],
|
|
484
|
+
createdAt: row[8]
|
|
748
485
|
};
|
|
749
486
|
}
|
|
750
|
-
exports.listChatArtifactVersionsQuery = `-- name: ListChatArtifactVersions :many
|
|
751
|
-
SELECT id, artifact_id, version, content, created_by_message_id, created_at, document_references FROM weave.chat_artifact_versions
|
|
752
|
-
WHERE artifact_id = $1
|
|
753
|
-
ORDER BY version`;
|
|
754
|
-
async function listChatArtifactVersions(client, args) {
|
|
755
|
-
const result = await client.query({
|
|
756
|
-
text: exports.listChatArtifactVersionsQuery,
|
|
757
|
-
values: [args.artifactId],
|
|
758
|
-
rowMode: "array"
|
|
759
|
-
});
|
|
760
|
-
return result.rows.map(row => {
|
|
761
|
-
return {
|
|
762
|
-
id: row[0],
|
|
763
|
-
artifactId: row[1],
|
|
764
|
-
version: row[2],
|
|
765
|
-
content: row[3],
|
|
766
|
-
createdByMessageId: row[4],
|
|
767
|
-
createdAt: row[5],
|
|
768
|
-
documentReferences: row[6]
|
|
769
|
-
};
|
|
770
|
-
});
|
|
771
|
-
}
|