@kafca/agentdock 0.1.42 → 0.1.44
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/README.md +10 -0
- package/dist/renderer/assets/{Badge-D-WU4kUV.js → Badge-Qk9qHovH.js} +1 -1
- package/dist/renderer/assets/{Chat-BGkC5tAe.js → Chat-BK-fm0Xr.js} +1 -1
- package/dist/renderer/assets/{ChatMarkdown-CfbC1jRd.js → ChatMarkdown-BKdW8OON.js} +1 -1
- package/dist/renderer/assets/{Config-qQb4bX5D.js → Config-B93CQGvY.js} +2 -2
- package/dist/renderer/assets/CronList-Z3TvSRKP.js +1 -0
- package/dist/renderer/assets/{Dashboard-xn6cUy_n.js → Dashboard-Ch3QkWwf.js} +2 -2
- package/dist/renderer/assets/{EmptyState-BdKBBUpr.js → EmptyState-kD9yAwtw.js} +1 -1
- package/dist/renderer/assets/{KnowledgeDetail-Duk8IQP3.js → KnowledgeDetail-BAMCLrjz.js} +2 -2
- package/dist/renderer/assets/{KnowledgeHome-BfjX_4Sv.js → KnowledgeHome-ChvjOfrc.js} +2 -2
- package/dist/renderer/assets/{Logs-Bfq61QMn.js → Logs-Cv0nth3j.js} +1 -1
- package/dist/renderer/assets/{Modal-B3vlBmBr.js → Modal-DwY4lecS.js} +1 -1
- package/dist/renderer/assets/MonitorList-JEvMoWUm.js +1 -0
- package/dist/renderer/assets/{Page-CPsLOP3z.js → Page-CnB9ePsb.js} +1 -1
- package/dist/renderer/assets/{ProjectDetail-D-g46wyF.js → ProjectDetail-DJa3sMmU.js} +2 -2
- package/dist/renderer/assets/{ProjectList-BrQEKDQ8.js → ProjectList-D6CXumR_.js} +1 -1
- package/dist/renderer/assets/{Select-C4CFMQmF.js → Select-zfoksLGB.js} +1 -1
- package/dist/renderer/assets/SessionChat-DUTh4WoM.js +1 -0
- package/dist/renderer/assets/{SessionList-DPWIUbOg.js → SessionList-D9o-lUst.js} +1 -1
- package/dist/renderer/assets/{ThreadChat-BjtU-j9q.js → ThreadChat-BYXlT-Kc.js} +7 -7
- package/dist/renderer/assets/{Workspace-BcNmHuJx.js → Workspace-BrhSwRQ-.js} +1 -1
- package/dist/renderer/assets/{arrow-left-DPzSmidS.js → arrow-left-CNEAuElg.js} +1 -1
- package/dist/renderer/assets/{book-open-B0xhoRqZ.js → book-open-BNJMhNI-.js} +1 -1
- package/dist/renderer/assets/{check-BTJTyd0C.js → check-BnclClRU.js} +1 -1
- package/dist/renderer/assets/{chevron-down-B6jJXlhi.js → chevron-down-Bh53e0O-.js} +1 -1
- package/dist/renderer/assets/{circle-qRhJR9qR.js → circle-ClZTWCWO.js} +1 -1
- package/dist/renderer/assets/desktop-C5vBT0yM.js +1 -0
- package/dist/renderer/assets/desktop-C6q6wBae.js +5 -0
- package/dist/renderer/assets/en-D2SkCrhG.js +1 -0
- package/dist/renderer/assets/{funnel-CbYKGTn8.js → funnel-_5hsz0xI.js} +1 -1
- package/dist/renderer/assets/{heart-DjwWJfkz.js → heart-u4Q1aOqj.js} +1 -1
- package/dist/renderer/assets/{index-BWmHJRhe.js → index-B36eowj-.js} +39 -34
- package/dist/renderer/assets/{index-CyZs_2NJ.js → index-BNFx4uYv.js} +3 -3
- package/dist/renderer/assets/{pencil-1dfAivmj.js → pencil-DLh9QNmT.js} +1 -1
- package/dist/renderer/assets/{play-CB3w1G6S.js → play-BDTk9Scm.js} +1 -1
- package/dist/renderer/assets/{plug-Bvep5o3r.js → plug-BG0JHW6B.js} +1 -1
- package/dist/renderer/assets/{plus-DJVg9m09.js → plus-BSc8POsz.js} +1 -1
- package/dist/renderer/assets/projects-DwfZwxDW.js +1 -0
- package/dist/renderer/assets/{save-xjJn3qf2.js → save-D5AO_G6a.js} +1 -1
- package/dist/renderer/assets/{search-BK3UrQxM.js → search-CniPk7Ey.js} +1 -1
- package/dist/renderer/assets/{server-Dyd2eXJu.js → server-GsXyQAZm.js} +1 -1
- package/dist/renderer/assets/{session-utils-eXC0020s.js → session-utils-BDxzgTBC.js} +1 -1
- package/dist/renderer/assets/{sessions-WLYpkyUt.js → sessions-CLcKA1Tt.js} +1 -1
- package/dist/renderer/assets/{shield-check-C0N6aWzF.js → shield-check-4i0E3hmf.js} +1 -1
- package/dist/renderer/assets/{trash-2-BGMTNJA6.js → trash-2-DhtOCsO5.js} +1 -1
- package/dist/renderer/assets/{user-BcGMLyhu.js → user-BtC_pVXV.js} +1 -1
- package/dist/renderer/assets/{wifi-off-FhcQx0HK.js → wifi-off-BHPzPY_B.js} +1 -1
- package/dist/renderer/assets/zh-DIcdHycM.js +1 -0
- package/dist/renderer/index.html +1 -1
- package/dist-electron/packages/contracts/src/local-core.js +28 -0
- package/dist-electron/packages/core-sdk/src/index.js +32 -0
- package/dist-electron/services/local-ai-core/src/acp/local-core-acp-backend.js +51 -0
- package/dist-electron/services/local-ai-core/src/acp/local-core-acp-store.js +4 -1364
- package/dist-electron/services/local-ai-core/src/acp/store/agent-task-store.js +166 -0
- package/dist-electron/services/local-ai-core/src/acp/store/automation-monitor-store.js +231 -0
- package/dist-electron/services/local-ai-core/src/acp/store/local-core-acp-store.js +263 -0
- package/dist-electron/services/local-ai-core/src/acp/store/platform-store.js +186 -0
- package/dist-electron/services/local-ai-core/src/acp/store/scheduler-store.js +201 -0
- package/dist-electron/services/local-ai-core/src/acp/store/schema.js +275 -0
- package/dist-electron/services/local-ai-core/src/acp/store/security-store.js +266 -0
- package/dist-electron/services/local-ai-core/src/acp/store/thread-store.js +232 -0
- package/dist-electron/services/local-ai-core/src/acp/store/utils.js +47 -0
- package/dist-electron/services/local-ai-core/src/acp/store/workspace-registry-store.js +109 -0
- package/dist-electron/services/local-ai-core/src/automation/automation-conversation-executor.js +136 -0
- package/dist-electron/services/local-ai-core/src/automation/automation-monitor-repository.js +56 -0
- package/dist-electron/services/local-ai-core/src/automation/automation-monitor-service.js +359 -0
- package/dist-electron/services/local-ai-core/src/automation/condition-evaluator.js +77 -0
- package/dist-electron/services/local-ai-core/src/automation/mock-stock-provider.js +40 -0
- package/dist-electron/services/local-ai-core/src/automation/monitor-id.js +10 -0
- package/dist-electron/services/local-ai-core/src/channel/lark/cards.js +55 -0
- package/dist-electron/services/local-ai-core/src/channel/lark/config.js +2 -0
- package/dist-electron/services/local-ai-core/src/channel/lark/inbound.js +114 -0
- package/dist-electron/services/local-ai-core/src/channel/lark/local-core-lark-gateway.js +153 -94
- package/dist-electron/services/local-ai-core/src/channel/shared/session-command-runtime.js +53 -0
- package/dist-electron/services/local-ai-core/src/channel/shared/thread-routing.js +34 -0
- package/dist-electron/services/local-ai-core/src/channel/weixin/local-core-weixin-gateway.js +63 -51
- package/dist-electron/services/local-ai-core/src/cli/lac.js +196 -0
- package/dist-electron/services/local-ai-core/src/cli/monitor-cli-parsers.js +37 -0
- package/dist-electron/services/local-ai-core/src/kernel/bootstrap.js +43 -0
- package/dist-electron/services/local-ai-core/src/kernel/capability-registry.js +12 -0
- package/dist-electron/services/local-ai-core/src/plugins/builtin/monitor-stock-plugin.js +30 -0
- package/dist-electron/services/local-ai-core/src/runtime/local-core-controller.js +41 -0
- package/dist-electron/services/local-ai-core/src/runtime/server-routes.js +31 -0
- package/dist-electron/services/local-ai-core/src/runtime/server.js +36 -0
- package/dist-electron/services/local-ai-core/src/scheduler/scheduled-bridge-session.js +25 -11
- package/dist-electron/services/local-ai-core/src/thread/session-command-service.js +275 -0
- package/dist-electron/services/local-ai-core/src/thread/slash-command-registry.js +27 -0
- package/dist-electron/services/local-ai-core/src/thread/thread-command-service.js +15 -15
- package/dist-electron/shared/desktop.js +21 -1
- package/dist-electron/tests/contracts/local-core-contracts.test.js +9 -0
- package/dist-electron/tests/electron/automation-monitor.test.js +38 -0
- package/dist-electron/tests/electron/lac-cli.test.js +146 -0
- package/dist-electron/tests/integration/channel-gateways.test.js +32 -0
- package/dist-electron/tests/integration/lark-gateway.test.js +1918 -0
- package/dist-electron/tests/integration/local-core-acp-progress.test.js +1772 -0
- package/dist-electron/tests/integration/local-core-refactor.test.js +216 -4566
- package/dist-electron/tests/integration/local-core-routes.test.js +204 -0
- package/dist-electron/tests/integration/weixin-gateway.test.js +927 -0
- package/package.json +1 -1
- package/dist/renderer/assets/CronList-CKhggzYk.js +0 -1
- package/dist/renderer/assets/SessionChat-06Jny5_G.js +0 -1
- package/dist/renderer/assets/desktop-DXmXjjUR.js +0 -1
- package/dist/renderer/assets/desktop-O8_6ZCVZ.js +0 -4
- package/dist/renderer/assets/en-CKhCF6St.js +0 -1
- package/dist/renderer/assets/projects-xnW0fTtq.js +0 -1
- package/dist/renderer/assets/zh-Dz5FLTBV.js +0 -1
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalPlatformStore = void 0;
|
|
4
|
+
class LocalPlatformStore {
|
|
5
|
+
db;
|
|
6
|
+
constructor(db) {
|
|
7
|
+
this.db = db;
|
|
8
|
+
}
|
|
9
|
+
createPairingRequest(input) {
|
|
10
|
+
this.db.prepare(`
|
|
11
|
+
INSERT INTO platform_pairings (code, workspace_id, platform, platform_user_id, chat_id, display_name, requested_at, expires_at, status)
|
|
12
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
13
|
+
`).run(input.code, input.workspace_id, input.platform || 'lark', input.platform_user_id, input.chat_id, input.display_name, input.requested_at, input.expires_at, input.status);
|
|
14
|
+
}
|
|
15
|
+
listPendingPairings(workspaceId) {
|
|
16
|
+
const query = workspaceId
|
|
17
|
+
? `
|
|
18
|
+
SELECT code, workspace_id, platform, platform_user_id, chat_id, display_name, requested_at, expires_at, status
|
|
19
|
+
FROM platform_pairings
|
|
20
|
+
WHERE workspace_id = ? AND status = 'pending'
|
|
21
|
+
ORDER BY requested_at DESC
|
|
22
|
+
`
|
|
23
|
+
: `
|
|
24
|
+
SELECT code, workspace_id, platform, platform_user_id, chat_id, display_name, requested_at, expires_at, status
|
|
25
|
+
FROM platform_pairings
|
|
26
|
+
WHERE status = 'pending'
|
|
27
|
+
ORDER BY requested_at DESC
|
|
28
|
+
`;
|
|
29
|
+
return this.db.prepare(query).all(...(workspaceId ? [workspaceId] : []));
|
|
30
|
+
}
|
|
31
|
+
getPairingRequest(code) {
|
|
32
|
+
return this.db.prepare(`
|
|
33
|
+
SELECT code, workspace_id, platform, platform_user_id, chat_id, display_name, requested_at, expires_at, status
|
|
34
|
+
FROM platform_pairings
|
|
35
|
+
WHERE code = ?
|
|
36
|
+
`).get(code);
|
|
37
|
+
}
|
|
38
|
+
updatePairingStatus(code, status) {
|
|
39
|
+
this.db.prepare('UPDATE platform_pairings SET status = ? WHERE code = ?').run(status, code);
|
|
40
|
+
}
|
|
41
|
+
expirePendingPairings(nowIso = new Date().toISOString()) {
|
|
42
|
+
this.db.prepare(`
|
|
43
|
+
UPDATE platform_pairings
|
|
44
|
+
SET status = 'expired'
|
|
45
|
+
WHERE status = 'pending' AND expires_at < ?
|
|
46
|
+
`).run(nowIso);
|
|
47
|
+
}
|
|
48
|
+
getAuthorizedUser(workspaceId, platformUserId, platform = 'lark') {
|
|
49
|
+
return this.db.prepare(`
|
|
50
|
+
SELECT id, workspace_id, platform, platform_user_id, chat_id, display_name, thread_id, authorized_at
|
|
51
|
+
FROM platform_users
|
|
52
|
+
WHERE workspace_id = ? AND platform = ? AND platform_user_id = ?
|
|
53
|
+
`).get(workspaceId, platform, platformUserId);
|
|
54
|
+
}
|
|
55
|
+
listAuthorizedUsers(workspaceId, platform) {
|
|
56
|
+
const params = [];
|
|
57
|
+
const predicates = [];
|
|
58
|
+
if (workspaceId) {
|
|
59
|
+
predicates.push('workspace_id = ?');
|
|
60
|
+
params.push(workspaceId);
|
|
61
|
+
}
|
|
62
|
+
if (platform) {
|
|
63
|
+
predicates.push('platform = ?');
|
|
64
|
+
params.push(platform);
|
|
65
|
+
}
|
|
66
|
+
const where = predicates.length > 0 ? `WHERE ${predicates.join(' AND ')}` : '';
|
|
67
|
+
const query = `
|
|
68
|
+
SELECT id, workspace_id, platform, platform_user_id, chat_id, display_name, thread_id, authorized_at
|
|
69
|
+
FROM platform_users
|
|
70
|
+
${where}
|
|
71
|
+
ORDER BY authorized_at DESC
|
|
72
|
+
`;
|
|
73
|
+
const rows = this.db.prepare(query).all(...params);
|
|
74
|
+
return rows.map((row) => ({
|
|
75
|
+
id: row.id,
|
|
76
|
+
workspaceId: row.workspace_id,
|
|
77
|
+
platform: row.platform,
|
|
78
|
+
participantId: row.platform_user_id,
|
|
79
|
+
channelId: row.chat_id,
|
|
80
|
+
platformUserId: row.platform_user_id,
|
|
81
|
+
chatId: row.chat_id,
|
|
82
|
+
displayName: row.display_name,
|
|
83
|
+
threadId: row.thread_id || undefined,
|
|
84
|
+
authorizedAt: row.authorized_at,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
createAuthorizedUser(input) {
|
|
88
|
+
this.db.prepare(`
|
|
89
|
+
INSERT INTO platform_users (id, workspace_id, platform, platform_user_id, chat_id, display_name, thread_id, authorized_at)
|
|
90
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
91
|
+
ON CONFLICT(workspace_id, platform, platform_user_id) DO UPDATE SET
|
|
92
|
+
chat_id = excluded.chat_id,
|
|
93
|
+
display_name = excluded.display_name,
|
|
94
|
+
thread_id = COALESCE(excluded.thread_id, platform_users.thread_id),
|
|
95
|
+
authorized_at = excluded.authorized_at
|
|
96
|
+
`).run(input.id, input.workspace_id, input.platform || 'lark', input.platform_user_id, input.chat_id, input.display_name, input.thread_id, input.authorized_at);
|
|
97
|
+
}
|
|
98
|
+
updateAuthorizedUserThread(workspaceId, platformUserId, threadId, platform = 'lark') {
|
|
99
|
+
this.db.prepare(`
|
|
100
|
+
UPDATE platform_users
|
|
101
|
+
SET thread_id = ?
|
|
102
|
+
WHERE workspace_id = ? AND platform = ? AND platform_user_id = ?
|
|
103
|
+
`).run(threadId, workspaceId, platform, platformUserId);
|
|
104
|
+
}
|
|
105
|
+
clearAuthorizedUserThreadByThreadId(threadId) {
|
|
106
|
+
this.db.prepare('UPDATE platform_users SET thread_id = NULL WHERE thread_id = ?').run(threadId);
|
|
107
|
+
}
|
|
108
|
+
getPlatformThreadBinding(workspaceId, chatId, platformUserId, platform = 'lark') {
|
|
109
|
+
return this.db.prepare(`
|
|
110
|
+
SELECT workspace_id, platform, chat_id, platform_user_id, thread_id, last_platform_message_id, created_at, updated_at
|
|
111
|
+
FROM platform_thread_bindings
|
|
112
|
+
WHERE workspace_id = ? AND platform = ? AND chat_id = ? AND platform_user_id = ?
|
|
113
|
+
`).get(workspaceId, platform, chatId, platformUserId);
|
|
114
|
+
}
|
|
115
|
+
getPlatformThreadBindingByThreadId(threadId) {
|
|
116
|
+
return this.db.prepare(`
|
|
117
|
+
SELECT workspace_id, platform, chat_id, platform_user_id, thread_id, last_platform_message_id, created_at, updated_at
|
|
118
|
+
FROM platform_thread_bindings
|
|
119
|
+
WHERE thread_id = ?
|
|
120
|
+
ORDER BY updated_at DESC
|
|
121
|
+
LIMIT 1
|
|
122
|
+
`).get(threadId);
|
|
123
|
+
}
|
|
124
|
+
deletePlatformThreadBindingsByThreadId(threadId) {
|
|
125
|
+
this.db.prepare('DELETE FROM platform_thread_bindings WHERE thread_id = ?').run(threadId);
|
|
126
|
+
}
|
|
127
|
+
upsertPlatformThreadBinding(input) {
|
|
128
|
+
this.db.prepare(`
|
|
129
|
+
INSERT INTO platform_thread_bindings
|
|
130
|
+
(workspace_id, platform, chat_id, platform_user_id, thread_id, last_platform_message_id, created_at, updated_at)
|
|
131
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
132
|
+
ON CONFLICT(workspace_id, platform, chat_id, platform_user_id) DO UPDATE SET
|
|
133
|
+
thread_id = excluded.thread_id,
|
|
134
|
+
last_platform_message_id = COALESCE(excluded.last_platform_message_id, platform_thread_bindings.last_platform_message_id),
|
|
135
|
+
updated_at = excluded.updated_at
|
|
136
|
+
`).run(input.workspace_id, input.platform || 'lark', input.chat_id, input.platform_user_id, input.thread_id, input.last_platform_message_id, input.created_at, input.updated_at);
|
|
137
|
+
}
|
|
138
|
+
updatePlatformThreadMessageId(workspaceId, chatId, platformUserId, messageId, platform = 'lark') {
|
|
139
|
+
this.db.prepare(`
|
|
140
|
+
UPDATE platform_thread_bindings
|
|
141
|
+
SET last_platform_message_id = ?, updated_at = ?
|
|
142
|
+
WHERE workspace_id = ? AND platform = ? AND chat_id = ? AND platform_user_id = ?
|
|
143
|
+
`).run(messageId, new Date().toISOString(), workspaceId, platform, chatId, platformUserId);
|
|
144
|
+
}
|
|
145
|
+
clearPlatformThreadMessageId(workspaceId, chatId, platformUserId, platform = 'lark') {
|
|
146
|
+
this.db.prepare(`
|
|
147
|
+
UPDATE platform_thread_bindings
|
|
148
|
+
SET last_platform_message_id = NULL, updated_at = ?
|
|
149
|
+
WHERE workspace_id = ? AND platform = ? AND chat_id = ? AND platform_user_id = ?
|
|
150
|
+
`).run(new Date().toISOString(), workspaceId, platform, chatId, platformUserId);
|
|
151
|
+
}
|
|
152
|
+
listPairingRequests(workspaceId, platform) {
|
|
153
|
+
const params = [];
|
|
154
|
+
const predicates = [];
|
|
155
|
+
if (workspaceId) {
|
|
156
|
+
predicates.push('workspace_id = ?');
|
|
157
|
+
params.push(workspaceId);
|
|
158
|
+
}
|
|
159
|
+
if (platform) {
|
|
160
|
+
predicates.push('platform = ?');
|
|
161
|
+
params.push(platform);
|
|
162
|
+
}
|
|
163
|
+
const where = predicates.length > 0 ? `WHERE ${predicates.join(' AND ')}` : '';
|
|
164
|
+
const query = `
|
|
165
|
+
SELECT code, workspace_id, platform, platform_user_id, chat_id, display_name, requested_at, expires_at, status
|
|
166
|
+
FROM platform_pairings
|
|
167
|
+
${where}
|
|
168
|
+
ORDER BY requested_at DESC
|
|
169
|
+
`;
|
|
170
|
+
const rows = this.db.prepare(query).all(...params);
|
|
171
|
+
return rows.map((row) => ({
|
|
172
|
+
code: row.code,
|
|
173
|
+
workspaceId: row.workspace_id,
|
|
174
|
+
platform: row.platform,
|
|
175
|
+
participantId: row.platform_user_id,
|
|
176
|
+
channelId: row.chat_id,
|
|
177
|
+
platformUserId: row.platform_user_id,
|
|
178
|
+
chatId: row.chat_id,
|
|
179
|
+
displayName: row.display_name,
|
|
180
|
+
requestedAt: row.requested_at,
|
|
181
|
+
expiresAt: row.expires_at,
|
|
182
|
+
status: row.status,
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.LocalPlatformStore = LocalPlatformStore;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalSchedulerStore = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const index_js_1 = require("../../../../../packages/contracts/src/index.js");
|
|
6
|
+
const job_id_js_1 = require("../../scheduler/job-id.js");
|
|
7
|
+
const utils_js_1 = require("./utils.js");
|
|
8
|
+
class LocalSchedulerStore {
|
|
9
|
+
db;
|
|
10
|
+
constructor(db) {
|
|
11
|
+
this.db = db;
|
|
12
|
+
}
|
|
13
|
+
listJobs(workspaceId) {
|
|
14
|
+
const query = workspaceId
|
|
15
|
+
? `
|
|
16
|
+
SELECT id, workspace_id, platform, route_type, route_config, trigger_type, cron_expr, run_at, prompt_template, description,
|
|
17
|
+
enabled, concurrency_policy, created_at, updated_at, last_run_at, last_status, last_error, execution_mode
|
|
18
|
+
FROM scheduled_jobs
|
|
19
|
+
WHERE workspace_id = ?
|
|
20
|
+
ORDER BY updated_at DESC
|
|
21
|
+
`
|
|
22
|
+
: `
|
|
23
|
+
SELECT id, workspace_id, platform, route_type, route_config, trigger_type, cron_expr, run_at, prompt_template, description,
|
|
24
|
+
enabled, concurrency_policy, created_at, updated_at, last_run_at, last_status, last_error, execution_mode
|
|
25
|
+
FROM scheduled_jobs
|
|
26
|
+
ORDER BY updated_at DESC
|
|
27
|
+
`;
|
|
28
|
+
const rows = this.db.prepare(query).all(...(workspaceId ? [workspaceId] : []));
|
|
29
|
+
return rows.map((row) => this.toScheduledJob(row));
|
|
30
|
+
}
|
|
31
|
+
getJob(jobId) {
|
|
32
|
+
const row = this.db.prepare(`
|
|
33
|
+
SELECT id, workspace_id, platform, route_type, route_config, trigger_type, cron_expr, run_at, prompt_template, description,
|
|
34
|
+
enabled, concurrency_policy, created_at, updated_at, last_run_at, last_status, last_error, execution_mode
|
|
35
|
+
FROM scheduled_jobs
|
|
36
|
+
WHERE id = ?
|
|
37
|
+
`).get(jobId);
|
|
38
|
+
return row ? this.toScheduledJob(row) : undefined;
|
|
39
|
+
}
|
|
40
|
+
createJob(input) {
|
|
41
|
+
if (!input.platform || !input.route) {
|
|
42
|
+
throw new Error('Scheduled job creation requires a resolved platform and route.');
|
|
43
|
+
}
|
|
44
|
+
let id = (0, job_id_js_1.createScheduledJobId)();
|
|
45
|
+
for (let attempt = 0; attempt < 5 && this.getJob(id); attempt += 1) {
|
|
46
|
+
id = (0, job_id_js_1.createScheduledJobId)();
|
|
47
|
+
}
|
|
48
|
+
if (this.getJob(id)) {
|
|
49
|
+
throw new Error('Unable to allocate a unique scheduled job id.');
|
|
50
|
+
}
|
|
51
|
+
const now = new Date().toISOString();
|
|
52
|
+
this.db.prepare(`
|
|
53
|
+
INSERT INTO scheduled_jobs (
|
|
54
|
+
id, workspace_id, platform, route_type, route_config, execution_mode, trigger_type, cron_expr, run_at,
|
|
55
|
+
prompt_template, description, enabled, concurrency_policy, created_at, updated_at
|
|
56
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'skip_if_running', ?, ?)
|
|
57
|
+
`).run(id, input.workspaceId, (0, index_js_1.normalizeChannelPlatform)(input.platform), input.route.type, JSON.stringify(input.route), (0, index_js_1.normalizeScheduledJobExecutionMode)(input.executionMode), (0, index_js_1.normalizeScheduledJobTriggerType)(input.triggerType), input.cronExpr || null, input.runAt || null, input.promptTemplate, input.description || '', input.enabled === false ? 0 : 1, now, now);
|
|
58
|
+
return this.getJob(id);
|
|
59
|
+
}
|
|
60
|
+
updateJob(jobId, input) {
|
|
61
|
+
const existing = this.getJob(jobId);
|
|
62
|
+
if (!existing) {
|
|
63
|
+
throw new Error(`Scheduled job not found: ${jobId}`);
|
|
64
|
+
}
|
|
65
|
+
const next = {
|
|
66
|
+
...existing,
|
|
67
|
+
...(input.route ? { route: input.route } : {}),
|
|
68
|
+
...(input.executionMode ? { executionMode: (0, index_js_1.normalizeScheduledJobExecutionMode)(input.executionMode) } : {}),
|
|
69
|
+
...(input.triggerType ? { triggerType: (0, index_js_1.normalizeScheduledJobTriggerType)(input.triggerType) } : {}),
|
|
70
|
+
...(Object.prototype.hasOwnProperty.call(input, 'cronExpr') ? { cronExpr: input.cronExpr || undefined } : {}),
|
|
71
|
+
...(Object.prototype.hasOwnProperty.call(input, 'runAt') ? { runAt: input.runAt || undefined } : {}),
|
|
72
|
+
...(typeof input.promptTemplate === 'string' ? { promptTemplate: input.promptTemplate } : {}),
|
|
73
|
+
...(typeof input.description === 'string' ? { description: input.description } : {}),
|
|
74
|
+
...(typeof input.enabled === 'boolean' ? { enabled: input.enabled } : {}),
|
|
75
|
+
updatedAt: new Date().toISOString(),
|
|
76
|
+
};
|
|
77
|
+
this.db.prepare(`
|
|
78
|
+
UPDATE scheduled_jobs
|
|
79
|
+
SET route_type = ?, route_config = ?, execution_mode = ?, trigger_type = ?, cron_expr = ?, run_at = ?, prompt_template = ?,
|
|
80
|
+
description = ?, enabled = ?, updated_at = ?
|
|
81
|
+
WHERE id = ?
|
|
82
|
+
`).run(next.route.type, JSON.stringify(next.route), next.executionMode, next.triggerType, next.cronExpr || null, next.runAt || null, next.promptTemplate, next.description, next.enabled ? 1 : 0, next.updatedAt, jobId);
|
|
83
|
+
return this.getJob(jobId);
|
|
84
|
+
}
|
|
85
|
+
deleteJob(jobId) {
|
|
86
|
+
const result = this.db.prepare('DELETE FROM scheduled_jobs WHERE id = ?').run(jobId);
|
|
87
|
+
if (result.changes === 0) {
|
|
88
|
+
throw new Error(`Scheduled job not found: ${jobId}`);
|
|
89
|
+
}
|
|
90
|
+
return { deleted: true };
|
|
91
|
+
}
|
|
92
|
+
listRuns(jobId) {
|
|
93
|
+
const rows = this.db.prepare(`
|
|
94
|
+
SELECT id, job_id, status, triggered_at, started_at, finished_at, error, thread_id, run_id, platform_message_id, platform_message_ids_json, delivery_mode, delivery_status, delivery_error, last_bridge_event_at
|
|
95
|
+
FROM scheduled_job_runs
|
|
96
|
+
WHERE job_id = ?
|
|
97
|
+
ORDER BY triggered_at DESC
|
|
98
|
+
`).all(jobId);
|
|
99
|
+
return rows.map((row) => this.toScheduledJobRun(row));
|
|
100
|
+
}
|
|
101
|
+
createRun(jobId, status, input = {}) {
|
|
102
|
+
const id = `jobrun:${(0, node_crypto_1.randomUUID)()}`;
|
|
103
|
+
const triggeredAt = input.triggeredAt || new Date().toISOString();
|
|
104
|
+
const normalizedStatus = (0, index_js_1.normalizeScheduledJobRunStatus)(status);
|
|
105
|
+
this.db.prepare(`
|
|
106
|
+
INSERT INTO scheduled_job_runs (id, job_id, status, triggered_at, started_at, finished_at, error, thread_id, run_id, platform_message_id, platform_message_ids_json, delivery_mode, delivery_status, delivery_error, last_bridge_event_at)
|
|
107
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
108
|
+
`).run(id, jobId, normalizedStatus, triggeredAt, input.startedAt || null, input.finishedAt || null, input.error || null, input.threadId || null, input.runId || null, input.platformMessageId || null, JSON.stringify(input.platformMessageIds || []), input.deliveryMode || null, input.deliveryStatus || null, input.deliveryError || null, input.lastBridgeEventAt || null);
|
|
109
|
+
this.updateJobStatus(jobId, {
|
|
110
|
+
lastRunAt: triggeredAt,
|
|
111
|
+
lastStatus: normalizedStatus,
|
|
112
|
+
lastError: input.error || '',
|
|
113
|
+
});
|
|
114
|
+
return this.getRun(id);
|
|
115
|
+
}
|
|
116
|
+
getRun(runId) {
|
|
117
|
+
const row = this.db.prepare(`
|
|
118
|
+
SELECT id, job_id, status, triggered_at, started_at, finished_at, error, thread_id, run_id, platform_message_id, platform_message_ids_json, delivery_mode, delivery_status, delivery_error, last_bridge_event_at
|
|
119
|
+
FROM scheduled_job_runs
|
|
120
|
+
WHERE id = ?
|
|
121
|
+
`).get(runId);
|
|
122
|
+
return row ? this.toScheduledJobRun(row) : undefined;
|
|
123
|
+
}
|
|
124
|
+
updateRun(runId, input) {
|
|
125
|
+
const existing = this.getRun(runId);
|
|
126
|
+
if (!existing) {
|
|
127
|
+
throw new Error(`Scheduled job run not found: ${runId}`);
|
|
128
|
+
}
|
|
129
|
+
const next = {
|
|
130
|
+
...existing,
|
|
131
|
+
...input,
|
|
132
|
+
...(input.status ? { status: (0, index_js_1.normalizeScheduledJobRunStatus)(input.status) } : {}),
|
|
133
|
+
};
|
|
134
|
+
this.db.prepare(`
|
|
135
|
+
UPDATE scheduled_job_runs
|
|
136
|
+
SET status = ?, triggered_at = ?, started_at = ?, finished_at = ?, error = ?, thread_id = ?, run_id = ?, platform_message_id = ?, platform_message_ids_json = ?, delivery_mode = ?, delivery_status = ?, delivery_error = ?, last_bridge_event_at = ?
|
|
137
|
+
WHERE id = ?
|
|
138
|
+
`).run(next.status, next.triggeredAt, next.startedAt || null, next.finishedAt || null, next.error || null, next.threadId || null, next.runId || null, next.platformMessageId || null, JSON.stringify(next.platformMessageIds || []), next.deliveryMode || null, next.deliveryStatus || null, next.deliveryError || null, next.lastBridgeEventAt || null, runId);
|
|
139
|
+
if (input.status || Object.prototype.hasOwnProperty.call(input, 'error') || input.finishedAt || input.triggeredAt) {
|
|
140
|
+
this.updateJobStatus(existing.jobId, {
|
|
141
|
+
lastRunAt: next.triggeredAt,
|
|
142
|
+
lastStatus: next.status,
|
|
143
|
+
lastError: next.error || '',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return this.getRun(runId);
|
|
147
|
+
}
|
|
148
|
+
updateJobStatus(jobId, input) {
|
|
149
|
+
this.db.prepare(`
|
|
150
|
+
UPDATE scheduled_jobs
|
|
151
|
+
SET last_run_at = COALESCE(?, last_run_at),
|
|
152
|
+
last_status = COALESCE(?, last_status),
|
|
153
|
+
last_error = CASE WHEN ? IS NULL THEN last_error ELSE ? END,
|
|
154
|
+
enabled = CASE WHEN ? IS NULL THEN enabled ELSE ? END,
|
|
155
|
+
updated_at = ?
|
|
156
|
+
WHERE id = ?
|
|
157
|
+
`).run(input.lastRunAt || null, input.lastStatus || null, input.lastError == null ? null : input.lastError, input.lastError == null ? null : input.lastError, typeof input.enabled === 'boolean' ? (input.enabled ? 1 : 0) : null, typeof input.enabled === 'boolean' ? (input.enabled ? 1 : 0) : null, new Date().toISOString(), jobId);
|
|
158
|
+
}
|
|
159
|
+
toScheduledJob(row) {
|
|
160
|
+
const route = JSON.parse(row.route_config);
|
|
161
|
+
return {
|
|
162
|
+
id: row.id,
|
|
163
|
+
workspaceId: row.workspace_id,
|
|
164
|
+
platform: (0, index_js_1.normalizeChannelPlatform)(row.platform),
|
|
165
|
+
route,
|
|
166
|
+
executionMode: (0, index_js_1.normalizeScheduledJobExecutionMode)(row.execution_mode),
|
|
167
|
+
triggerType: (0, index_js_1.normalizeScheduledJobTriggerType)(row.trigger_type),
|
|
168
|
+
cronExpr: row.cron_expr || undefined,
|
|
169
|
+
runAt: row.run_at || undefined,
|
|
170
|
+
promptTemplate: row.prompt_template,
|
|
171
|
+
description: row.description,
|
|
172
|
+
enabled: Boolean(row.enabled),
|
|
173
|
+
concurrencyPolicy: row.concurrency_policy,
|
|
174
|
+
createdAt: row.created_at,
|
|
175
|
+
updatedAt: row.updated_at,
|
|
176
|
+
lastRunAt: row.last_run_at || undefined,
|
|
177
|
+
lastStatus: row.last_status ? (0, index_js_1.normalizeScheduledJobRunStatus)(row.last_status) : undefined,
|
|
178
|
+
lastError: row.last_error || undefined,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
toScheduledJobRun(row) {
|
|
182
|
+
return {
|
|
183
|
+
id: row.id,
|
|
184
|
+
jobId: row.job_id,
|
|
185
|
+
status: (0, index_js_1.normalizeScheduledJobRunStatus)(row.status),
|
|
186
|
+
triggeredAt: row.triggered_at,
|
|
187
|
+
startedAt: row.started_at || undefined,
|
|
188
|
+
finishedAt: row.finished_at || undefined,
|
|
189
|
+
error: row.error || undefined,
|
|
190
|
+
threadId: row.thread_id || undefined,
|
|
191
|
+
runId: row.run_id || undefined,
|
|
192
|
+
platformMessageId: row.platform_message_id || undefined,
|
|
193
|
+
platformMessageIds: (0, utils_js_1.parseJson)(row.platform_message_ids_json || '[]', []),
|
|
194
|
+
deliveryMode: row.delivery_mode || undefined,
|
|
195
|
+
deliveryStatus: row.delivery_status || undefined,
|
|
196
|
+
deliveryError: row.delivery_error || undefined,
|
|
197
|
+
lastBridgeEventAt: row.last_bridge_event_at || undefined,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.LocalSchedulerStore = LocalSchedulerStore;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureLocalCoreAcpSchema = ensureLocalCoreAcpSchema;
|
|
4
|
+
function ensureLocalCoreAcpSchema(db) {
|
|
5
|
+
db.exec(`
|
|
6
|
+
PRAGMA foreign_keys = ON;
|
|
7
|
+
CREATE TABLE IF NOT EXISTS threads (
|
|
8
|
+
id TEXT PRIMARY KEY,
|
|
9
|
+
workspace_id TEXT NOT NULL,
|
|
10
|
+
session_id TEXT NOT NULL,
|
|
11
|
+
bridge_session_key TEXT NOT NULL,
|
|
12
|
+
title TEXT NOT NULL,
|
|
13
|
+
agent_type TEXT NOT NULL,
|
|
14
|
+
created_at TEXT NOT NULL,
|
|
15
|
+
updated_at TEXT NOT NULL,
|
|
16
|
+
history_count INTEGER NOT NULL DEFAULT 0,
|
|
17
|
+
excerpt TEXT NOT NULL DEFAULT '',
|
|
18
|
+
acp_session_id TEXT,
|
|
19
|
+
acp_supports_load INTEGER NOT NULL DEFAULT 0,
|
|
20
|
+
agent_mode TEXT NOT NULL DEFAULT 'default'
|
|
21
|
+
);
|
|
22
|
+
CREATE INDEX IF NOT EXISTS idx_threads_workspace_updated ON threads (workspace_id, updated_at DESC);
|
|
23
|
+
CREATE TABLE IF NOT EXISTS messages (
|
|
24
|
+
id TEXT PRIMARY KEY,
|
|
25
|
+
thread_id TEXT NOT NULL,
|
|
26
|
+
role TEXT NOT NULL,
|
|
27
|
+
content TEXT NOT NULL,
|
|
28
|
+
tool_call_json TEXT,
|
|
29
|
+
bridge_kind TEXT,
|
|
30
|
+
bridge_status TEXT,
|
|
31
|
+
timestamp TEXT NOT NULL,
|
|
32
|
+
kind TEXT NOT NULL,
|
|
33
|
+
seq INTEGER NOT NULL,
|
|
34
|
+
FOREIGN KEY (thread_id) REFERENCES threads(id) ON DELETE CASCADE
|
|
35
|
+
);
|
|
36
|
+
CREATE INDEX IF NOT EXISTS idx_messages_thread_seq ON messages (thread_id, seq ASC);
|
|
37
|
+
CREATE TABLE IF NOT EXISTS runs (
|
|
38
|
+
id TEXT PRIMARY KEY,
|
|
39
|
+
thread_id TEXT NOT NULL,
|
|
40
|
+
status TEXT NOT NULL,
|
|
41
|
+
started_at TEXT NOT NULL,
|
|
42
|
+
updated_at TEXT NOT NULL,
|
|
43
|
+
FOREIGN KEY (thread_id) REFERENCES threads(id) ON DELETE CASCADE
|
|
44
|
+
);
|
|
45
|
+
CREATE INDEX IF NOT EXISTS idx_runs_thread_updated ON runs (thread_id, updated_at DESC);
|
|
46
|
+
CREATE TABLE IF NOT EXISTS platform_pairings (
|
|
47
|
+
code TEXT PRIMARY KEY,
|
|
48
|
+
workspace_id TEXT NOT NULL,
|
|
49
|
+
platform TEXT NOT NULL,
|
|
50
|
+
platform_user_id TEXT NOT NULL,
|
|
51
|
+
chat_id TEXT NOT NULL,
|
|
52
|
+
display_name TEXT NOT NULL,
|
|
53
|
+
requested_at TEXT NOT NULL,
|
|
54
|
+
expires_at TEXT NOT NULL,
|
|
55
|
+
status TEXT NOT NULL
|
|
56
|
+
);
|
|
57
|
+
CREATE INDEX IF NOT EXISTS idx_platform_pairings_workspace_status ON platform_pairings (workspace_id, status, expires_at DESC);
|
|
58
|
+
CREATE TABLE IF NOT EXISTS platform_users (
|
|
59
|
+
id TEXT PRIMARY KEY,
|
|
60
|
+
workspace_id TEXT NOT NULL,
|
|
61
|
+
platform TEXT NOT NULL,
|
|
62
|
+
platform_user_id TEXT NOT NULL,
|
|
63
|
+
chat_id TEXT NOT NULL,
|
|
64
|
+
display_name TEXT NOT NULL,
|
|
65
|
+
thread_id TEXT,
|
|
66
|
+
authorized_at TEXT NOT NULL,
|
|
67
|
+
UNIQUE(workspace_id, platform, platform_user_id)
|
|
68
|
+
);
|
|
69
|
+
CREATE INDEX IF NOT EXISTS idx_platform_users_workspace_platform ON platform_users (workspace_id, platform);
|
|
70
|
+
CREATE TABLE IF NOT EXISTS platform_thread_bindings (
|
|
71
|
+
workspace_id TEXT NOT NULL,
|
|
72
|
+
platform TEXT NOT NULL,
|
|
73
|
+
chat_id TEXT NOT NULL,
|
|
74
|
+
platform_user_id TEXT NOT NULL,
|
|
75
|
+
thread_id TEXT NOT NULL,
|
|
76
|
+
last_platform_message_id TEXT,
|
|
77
|
+
created_at TEXT NOT NULL,
|
|
78
|
+
updated_at TEXT NOT NULL,
|
|
79
|
+
PRIMARY KEY (workspace_id, platform, chat_id, platform_user_id)
|
|
80
|
+
);
|
|
81
|
+
CREATE INDEX IF NOT EXISTS idx_platform_thread_bindings_thread ON platform_thread_bindings (thread_id);
|
|
82
|
+
CREATE TABLE IF NOT EXISTS scheduled_jobs (
|
|
83
|
+
id TEXT PRIMARY KEY,
|
|
84
|
+
workspace_id TEXT NOT NULL,
|
|
85
|
+
platform TEXT NOT NULL,
|
|
86
|
+
route_type TEXT NOT NULL,
|
|
87
|
+
route_config TEXT NOT NULL,
|
|
88
|
+
execution_mode TEXT NOT NULL DEFAULT 'same-thread',
|
|
89
|
+
trigger_type TEXT NOT NULL,
|
|
90
|
+
cron_expr TEXT,
|
|
91
|
+
run_at TEXT,
|
|
92
|
+
prompt_template TEXT NOT NULL,
|
|
93
|
+
description TEXT NOT NULL DEFAULT '',
|
|
94
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
95
|
+
concurrency_policy TEXT NOT NULL DEFAULT 'skip_if_running',
|
|
96
|
+
created_at TEXT NOT NULL,
|
|
97
|
+
updated_at TEXT NOT NULL,
|
|
98
|
+
last_run_at TEXT,
|
|
99
|
+
last_status TEXT,
|
|
100
|
+
last_error TEXT
|
|
101
|
+
);
|
|
102
|
+
CREATE INDEX IF NOT EXISTS idx_scheduled_jobs_workspace_updated ON scheduled_jobs (workspace_id, updated_at DESC);
|
|
103
|
+
CREATE INDEX IF NOT EXISTS idx_scheduled_jobs_enabled ON scheduled_jobs (enabled, trigger_type, run_at);
|
|
104
|
+
CREATE TABLE IF NOT EXISTS scheduled_job_runs (
|
|
105
|
+
id TEXT PRIMARY KEY,
|
|
106
|
+
job_id TEXT NOT NULL,
|
|
107
|
+
status TEXT NOT NULL,
|
|
108
|
+
triggered_at TEXT NOT NULL,
|
|
109
|
+
started_at TEXT,
|
|
110
|
+
finished_at TEXT,
|
|
111
|
+
error TEXT,
|
|
112
|
+
thread_id TEXT,
|
|
113
|
+
run_id TEXT,
|
|
114
|
+
platform_message_id TEXT,
|
|
115
|
+
platform_message_ids_json TEXT,
|
|
116
|
+
delivery_mode TEXT,
|
|
117
|
+
delivery_status TEXT,
|
|
118
|
+
delivery_error TEXT,
|
|
119
|
+
last_bridge_event_at TEXT,
|
|
120
|
+
FOREIGN KEY (job_id) REFERENCES scheduled_jobs(id) ON DELETE CASCADE
|
|
121
|
+
);
|
|
122
|
+
CREATE INDEX IF NOT EXISTS idx_scheduled_job_runs_job_triggered ON scheduled_job_runs (job_id, triggered_at DESC);
|
|
123
|
+
CREATE TABLE IF NOT EXISTS automation_monitors (
|
|
124
|
+
id TEXT PRIMARY KEY,
|
|
125
|
+
workspace_id TEXT NOT NULL,
|
|
126
|
+
title TEXT NOT NULL,
|
|
127
|
+
source_type TEXT NOT NULL,
|
|
128
|
+
source_config_json TEXT NOT NULL DEFAULT '{}',
|
|
129
|
+
condition_json TEXT NOT NULL,
|
|
130
|
+
prompt_template TEXT NOT NULL,
|
|
131
|
+
platform TEXT NOT NULL,
|
|
132
|
+
route_type TEXT NOT NULL,
|
|
133
|
+
route_config TEXT NOT NULL,
|
|
134
|
+
execution_mode TEXT NOT NULL DEFAULT 'side-thread',
|
|
135
|
+
enabled INTEGER NOT NULL DEFAULT 1,
|
|
136
|
+
cooldown_ms INTEGER NOT NULL DEFAULT 900000,
|
|
137
|
+
concurrency_policy TEXT NOT NULL DEFAULT 'skip_if_running',
|
|
138
|
+
last_state_json TEXT,
|
|
139
|
+
created_at TEXT NOT NULL,
|
|
140
|
+
updated_at TEXT NOT NULL,
|
|
141
|
+
last_triggered_at TEXT,
|
|
142
|
+
last_status TEXT,
|
|
143
|
+
last_error TEXT
|
|
144
|
+
);
|
|
145
|
+
CREATE INDEX IF NOT EXISTS idx_automation_monitors_workspace_updated ON automation_monitors (workspace_id, updated_at DESC);
|
|
146
|
+
CREATE INDEX IF NOT EXISTS idx_automation_monitors_enabled ON automation_monitors (enabled, source_type);
|
|
147
|
+
CREATE TABLE IF NOT EXISTS automation_monitor_runs (
|
|
148
|
+
id TEXT PRIMARY KEY,
|
|
149
|
+
monitor_id TEXT NOT NULL,
|
|
150
|
+
status TEXT NOT NULL,
|
|
151
|
+
triggered_at TEXT NOT NULL,
|
|
152
|
+
started_at TEXT,
|
|
153
|
+
finished_at TEXT,
|
|
154
|
+
error TEXT,
|
|
155
|
+
event_snapshot_json TEXT,
|
|
156
|
+
thread_id TEXT,
|
|
157
|
+
run_id TEXT,
|
|
158
|
+
delivery_mode TEXT,
|
|
159
|
+
delivery_status TEXT,
|
|
160
|
+
delivery_error TEXT,
|
|
161
|
+
last_bridge_event_at TEXT,
|
|
162
|
+
FOREIGN KEY (monitor_id) REFERENCES automation_monitors(id) ON DELETE CASCADE
|
|
163
|
+
);
|
|
164
|
+
CREATE INDEX IF NOT EXISTS idx_automation_monitor_runs_monitor_triggered ON automation_monitor_runs (monitor_id, triggered_at DESC);
|
|
165
|
+
CREATE TABLE IF NOT EXISTS workspace_registry (
|
|
166
|
+
id TEXT PRIMARY KEY,
|
|
167
|
+
display_name TEXT NOT NULL,
|
|
168
|
+
path TEXT NOT NULL,
|
|
169
|
+
device_id TEXT NOT NULL,
|
|
170
|
+
default_runtime_id TEXT,
|
|
171
|
+
git_json TEXT NOT NULL DEFAULT '{}',
|
|
172
|
+
health_json TEXT NOT NULL DEFAULT '{}',
|
|
173
|
+
metadata_json TEXT NOT NULL DEFAULT '{}',
|
|
174
|
+
created_at TEXT NOT NULL,
|
|
175
|
+
updated_at TEXT NOT NULL,
|
|
176
|
+
last_opened_at TEXT
|
|
177
|
+
);
|
|
178
|
+
CREATE INDEX IF NOT EXISTS idx_workspace_registry_updated ON workspace_registry (updated_at DESC);
|
|
179
|
+
CREATE TABLE IF NOT EXISTS agent_tasks (
|
|
180
|
+
id TEXT PRIMARY KEY,
|
|
181
|
+
workspace_id TEXT NOT NULL,
|
|
182
|
+
device_id TEXT NOT NULL,
|
|
183
|
+
runtime_id TEXT NOT NULL,
|
|
184
|
+
thread_id TEXT,
|
|
185
|
+
run_id TEXT,
|
|
186
|
+
title TEXT NOT NULL,
|
|
187
|
+
prompt TEXT,
|
|
188
|
+
status TEXT NOT NULL,
|
|
189
|
+
created_at TEXT NOT NULL,
|
|
190
|
+
updated_at TEXT NOT NULL,
|
|
191
|
+
queued_at TEXT,
|
|
192
|
+
started_at TEXT,
|
|
193
|
+
completed_at TEXT,
|
|
194
|
+
summary TEXT,
|
|
195
|
+
error TEXT,
|
|
196
|
+
timeline_json TEXT NOT NULL DEFAULT '[]',
|
|
197
|
+
logs_json TEXT NOT NULL DEFAULT '[]',
|
|
198
|
+
artifacts_json TEXT NOT NULL DEFAULT '[]',
|
|
199
|
+
approval_ids_json TEXT NOT NULL DEFAULT '[]',
|
|
200
|
+
metadata_json TEXT NOT NULL DEFAULT '{}'
|
|
201
|
+
);
|
|
202
|
+
CREATE INDEX IF NOT EXISTS idx_agent_tasks_workspace_updated ON agent_tasks (workspace_id, updated_at DESC);
|
|
203
|
+
CREATE INDEX IF NOT EXISTS idx_agent_tasks_status_updated ON agent_tasks (status, updated_at DESC);
|
|
204
|
+
CREATE INDEX IF NOT EXISTS idx_agent_tasks_run ON agent_tasks (run_id);
|
|
205
|
+
CREATE TABLE IF NOT EXISTS workspace_security_settings (
|
|
206
|
+
workspace_id TEXT PRIMARY KEY,
|
|
207
|
+
permissions_json TEXT NOT NULL,
|
|
208
|
+
allow_paths_json TEXT NOT NULL DEFAULT '[]',
|
|
209
|
+
deny_paths_json TEXT NOT NULL DEFAULT '[]',
|
|
210
|
+
updated_at TEXT NOT NULL,
|
|
211
|
+
updated_by TEXT
|
|
212
|
+
);
|
|
213
|
+
CREATE TABLE IF NOT EXISTS approval_requests (
|
|
214
|
+
id TEXT PRIMARY KEY,
|
|
215
|
+
workspace_id TEXT NOT NULL,
|
|
216
|
+
task_id TEXT,
|
|
217
|
+
thread_id TEXT,
|
|
218
|
+
run_id TEXT,
|
|
219
|
+
device_id TEXT NOT NULL,
|
|
220
|
+
kind TEXT NOT NULL,
|
|
221
|
+
status TEXT NOT NULL,
|
|
222
|
+
risk_level TEXT NOT NULL,
|
|
223
|
+
title TEXT NOT NULL,
|
|
224
|
+
description TEXT NOT NULL,
|
|
225
|
+
requested_action TEXT NOT NULL,
|
|
226
|
+
command TEXT,
|
|
227
|
+
scopes_json TEXT NOT NULL DEFAULT '[]',
|
|
228
|
+
options_json TEXT NOT NULL DEFAULT '[]',
|
|
229
|
+
requested_by TEXT,
|
|
230
|
+
resolved_by TEXT,
|
|
231
|
+
resolution TEXT,
|
|
232
|
+
created_at TEXT NOT NULL,
|
|
233
|
+
updated_at TEXT NOT NULL,
|
|
234
|
+
resolved_at TEXT,
|
|
235
|
+
expires_at TEXT,
|
|
236
|
+
metadata_json TEXT NOT NULL DEFAULT '{}'
|
|
237
|
+
);
|
|
238
|
+
CREATE INDEX IF NOT EXISTS idx_approval_requests_workspace_updated ON approval_requests (workspace_id, updated_at DESC);
|
|
239
|
+
CREATE INDEX IF NOT EXISTS idx_approval_requests_status_updated ON approval_requests (status, updated_at DESC);
|
|
240
|
+
CREATE INDEX IF NOT EXISTS idx_approval_requests_task ON approval_requests (task_id);
|
|
241
|
+
CREATE INDEX IF NOT EXISTS idx_approval_requests_run ON approval_requests (run_id);
|
|
242
|
+
CREATE TABLE IF NOT EXISTS audit_events (
|
|
243
|
+
id TEXT PRIMARY KEY,
|
|
244
|
+
type TEXT NOT NULL,
|
|
245
|
+
workspace_id TEXT,
|
|
246
|
+
task_id TEXT,
|
|
247
|
+
approval_id TEXT,
|
|
248
|
+
actor TEXT,
|
|
249
|
+
summary TEXT NOT NULL,
|
|
250
|
+
risk_level TEXT,
|
|
251
|
+
created_at TEXT NOT NULL,
|
|
252
|
+
metadata_json TEXT NOT NULL DEFAULT '{}'
|
|
253
|
+
);
|
|
254
|
+
CREATE INDEX IF NOT EXISTS idx_audit_events_workspace_created ON audit_events (workspace_id, created_at DESC);
|
|
255
|
+
CREATE INDEX IF NOT EXISTS idx_audit_events_task_created ON audit_events (task_id, created_at DESC);
|
|
256
|
+
CREATE INDEX IF NOT EXISTS idx_audit_events_type_created ON audit_events (type, created_at DESC);
|
|
257
|
+
`);
|
|
258
|
+
ensureColumn(db, 'messages', 'tool_call_json', 'TEXT');
|
|
259
|
+
ensureColumn(db, 'messages', 'bridge_kind', 'TEXT');
|
|
260
|
+
ensureColumn(db, 'messages', 'bridge_status', 'TEXT');
|
|
261
|
+
ensureColumn(db, 'scheduled_jobs', 'execution_mode', "TEXT NOT NULL DEFAULT 'same-thread'");
|
|
262
|
+
ensureColumn(db, 'scheduled_job_runs', 'platform_message_ids_json', 'TEXT');
|
|
263
|
+
ensureColumn(db, 'scheduled_job_runs', 'delivery_mode', 'TEXT');
|
|
264
|
+
ensureColumn(db, 'scheduled_job_runs', 'delivery_status', 'TEXT');
|
|
265
|
+
ensureColumn(db, 'scheduled_job_runs', 'delivery_error', 'TEXT');
|
|
266
|
+
ensureColumn(db, 'scheduled_job_runs', 'last_bridge_event_at', 'TEXT');
|
|
267
|
+
ensureColumn(db, 'threads', 'agent_mode', "TEXT NOT NULL DEFAULT 'default'");
|
|
268
|
+
}
|
|
269
|
+
function ensureColumn(db, table, column, definition) {
|
|
270
|
+
const rows = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
271
|
+
if (rows.some((row) => row.name === column)) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
275
|
+
}
|