@kafca/agentdock 0.1.41 → 0.1.43
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-BX3RC8l6.js → Badge-CbG6yRSm.js} +1 -1
- package/dist/renderer/assets/{Chat-DJwIciel.js → Chat-BvNNWGGX.js} +1 -1
- package/dist/renderer/assets/{ChatMarkdown-DfGbRR0S.js → ChatMarkdown-Ct-PvJB8.js} +1 -1
- package/dist/renderer/assets/{Config-2x2RDL3j.js → Config-lQX2qVVV.js} +2 -2
- package/dist/renderer/assets/CronList-Dj_3muVG.js +1 -0
- package/dist/renderer/assets/{Dashboard-2Wcx_bvJ.js → Dashboard-eh_RhGYb.js} +2 -2
- package/dist/renderer/assets/{EmptyState-DoCpF2tn.js → EmptyState-Bn2Qh14U.js} +1 -1
- package/dist/renderer/assets/{KnowledgeDetail-CBRu2bXX.js → KnowledgeDetail-Bsz6Ou41.js} +2 -2
- package/dist/renderer/assets/{KnowledgeHome-CItdlDVR.js → KnowledgeHome-Cgj4XFXn.js} +2 -2
- package/dist/renderer/assets/{Logs-Cd_7ZOXc.js → Logs-Dp-NF6GN.js} +1 -1
- package/dist/renderer/assets/{Modal-B4eOiBsB.js → Modal-B6YPPBN6.js} +1 -1
- package/dist/renderer/assets/MonitorList-xEZWg460.js +1 -0
- package/dist/renderer/assets/{Page-C5VH4D9U.js → Page-Bn7RjGOS.js} +1 -1
- package/dist/renderer/assets/{ProjectDetail-D_DA--IP.js → ProjectDetail-Cv_jIE61.js} +2 -2
- package/dist/renderer/assets/{ProjectList-CtCXJ50u.js → ProjectList-BDk5_gqY.js} +1 -1
- package/dist/renderer/assets/{Select-B6E68LcN.js → Select-xshfMIEQ.js} +1 -1
- package/dist/renderer/assets/SessionChat-BkHy90z3.js +1 -0
- package/dist/renderer/assets/{SessionList-Do-5-Xx6.js → SessionList-BZyXT92L.js} +1 -1
- package/dist/renderer/assets/{ThreadChat-B1tEtE3V.js → ThreadChat-DUOIyXrS.js} +7 -7
- package/dist/renderer/assets/{Workspace-BlhS2RFw.js → Workspace-Dl80fNEC.js} +1 -1
- package/dist/renderer/assets/{arrow-left-DF1_F9Pk.js → arrow-left-C54ZI-AS.js} +1 -1
- package/dist/renderer/assets/{book-open-DxRTGpWO.js → book-open-Dl7GO0zn.js} +1 -1
- package/dist/renderer/assets/{check-BAqPPYkf.js → check-CiqgtrOL.js} +1 -1
- package/dist/renderer/assets/{chevron-down-DIZZgSb3.js → chevron-down-DTL2OuVh.js} +1 -1
- package/dist/renderer/assets/{circle-B5raL_XK.js → circle-DaVKfa3P.js} +1 -1
- package/dist/renderer/assets/desktop-C6q6wBae.js +5 -0
- package/dist/renderer/assets/desktop-jaAiayNB.js +1 -0
- package/dist/renderer/assets/en-D2SkCrhG.js +1 -0
- package/dist/renderer/assets/{funnel-BPjLpVSB.js → funnel-CrmnLMJI.js} +1 -1
- package/dist/renderer/assets/{heart-D2M1xN1N.js → heart-BMfQI7y_.js} +1 -1
- package/dist/renderer/assets/{index-Cx71F_Lz.js → index-HPNb1zfx.js} +39 -34
- package/dist/renderer/assets/{index-BijJAYmo.js → index-nreiKY1f.js} +3 -3
- package/dist/renderer/assets/{pencil-DlDr8Mmp.js → pencil-wTQ4l465.js} +1 -1
- package/dist/renderer/assets/{play-BOEG_mY8.js → play-BK--MXmw.js} +1 -1
- package/dist/renderer/assets/{plug-BI27elC-.js → plug-BIx9fjip.js} +1 -1
- package/dist/renderer/assets/{plus-BhURuFIQ.js → plus-Dn7JFWQ8.js} +1 -1
- package/dist/renderer/assets/projects-brJZgwEJ.js +1 -0
- package/dist/renderer/assets/{save-RwkHNm9e.js → save-CC3zOSWb.js} +1 -1
- package/dist/renderer/assets/{search-DMNtm2WP.js → search-CDTy9Czu.js} +1 -1
- package/dist/renderer/assets/{server-CNaxKyAq.js → server-DtQk3t2a.js} +1 -1
- package/dist/renderer/assets/{session-utils-vsALZkZN.js → session-utils-4ep5D66T.js} +1 -1
- package/dist/renderer/assets/{sessions-BY-R1IL_.js → sessions-Dor1LteH.js} +1 -1
- package/dist/renderer/assets/{shield-check-BF-4oJbj.js → shield-check-Cz2LpU6r.js} +1 -1
- package/dist/renderer/assets/{trash-2-DduflM4q.js → trash-2-C2EmWFZV.js} +1 -1
- package/dist/renderer/assets/{user-DBcvnuW4.js → user-I8B-cs5A.js} +1 -1
- package/dist/renderer/assets/{wifi-off-X1nXESYu.js → wifi-off-CPevTQJn.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 +76 -39
- package/dist-electron/services/local-ai-core/src/acp/local-core-acp-session-coordinator.js +13 -0
- package/dist-electron/services/local-ai-core/src/acp/local-core-acp-store.js +4 -1357
- package/dist-electron/services/local-ai-core/src/acp/local-core-slash-commands.js +28 -0
- 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/local-core-lark-gateway.js +101 -29
- 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/weixin/local-core-weixin-gateway.js +51 -33
- 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/router/workspace-router.js +40 -4
- 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 +134 -0
- 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/electron/plugin-kernel.test.js +26 -0
- package/dist-electron/tests/integration/local-core-refactor.test.js +359 -0
- package/package.json +1 -1
- package/dist/renderer/assets/CronList-C6nPAmEo.js +0 -1
- package/dist/renderer/assets/SessionChat-D1HtMdQS.js +0 -1
- package/dist/renderer/assets/desktop-CFcnzwcY.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-DpR972HM.js +0 -1
- package/dist/renderer/assets/zh-Dz5FLTBV.js +0 -1
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactSecrets = exports.LocalCoreAcpStore = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_sqlite_1 = require("node:sqlite");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const desktop_js_1 = require("../../../../../shared/desktop.js");
|
|
8
|
+
const agent_task_store_js_1 = require("./agent-task-store.js");
|
|
9
|
+
const automation_monitor_store_js_1 = require("./automation-monitor-store.js");
|
|
10
|
+
const schema_js_1 = require("./schema.js");
|
|
11
|
+
const platform_store_js_1 = require("./platform-store.js");
|
|
12
|
+
const scheduler_store_js_1 = require("./scheduler-store.js");
|
|
13
|
+
const security_store_js_1 = require("./security-store.js");
|
|
14
|
+
const thread_store_js_1 = require("./thread-store.js");
|
|
15
|
+
const workspace_registry_store_js_1 = require("./workspace-registry-store.js");
|
|
16
|
+
class LocalCoreAcpStore {
|
|
17
|
+
db;
|
|
18
|
+
threads;
|
|
19
|
+
workspaceRegistry;
|
|
20
|
+
security;
|
|
21
|
+
agentTasks;
|
|
22
|
+
scheduler;
|
|
23
|
+
automationMonitors;
|
|
24
|
+
platform;
|
|
25
|
+
constructor(userDataPath) {
|
|
26
|
+
const dbPath = (0, node_path_1.join)(userDataPath, 'runtime', 'local-core.db');
|
|
27
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(dbPath), { recursive: true });
|
|
28
|
+
this.db = new node_sqlite_1.DatabaseSync(dbPath);
|
|
29
|
+
this.threads = new thread_store_js_1.LocalThreadStore(this.db);
|
|
30
|
+
this.workspaceRegistry = new workspace_registry_store_js_1.LocalWorkspaceRegistryStore(this.db);
|
|
31
|
+
this.security = new security_store_js_1.LocalSecurityStore(this.db, (taskId, input) => {
|
|
32
|
+
this.agentTasks.update(taskId, input);
|
|
33
|
+
});
|
|
34
|
+
this.agentTasks = new agent_task_store_js_1.LocalAgentTaskStore(this.db, (input) => {
|
|
35
|
+
this.security.createAuditEvent(input);
|
|
36
|
+
});
|
|
37
|
+
this.scheduler = new scheduler_store_js_1.LocalSchedulerStore(this.db);
|
|
38
|
+
this.automationMonitors = new automation_monitor_store_js_1.LocalAutomationMonitorStore(this.db);
|
|
39
|
+
this.platform = new platform_store_js_1.LocalPlatformStore(this.db);
|
|
40
|
+
(0, schema_js_1.ensureLocalCoreAcpSchema)(this.db);
|
|
41
|
+
}
|
|
42
|
+
close() {
|
|
43
|
+
this.db.close();
|
|
44
|
+
}
|
|
45
|
+
listThreadSummaries(workspaceId) {
|
|
46
|
+
return this.threads.listSummaries(workspaceId);
|
|
47
|
+
}
|
|
48
|
+
countThreads(workspaceId) {
|
|
49
|
+
return this.threads.count(workspaceId);
|
|
50
|
+
}
|
|
51
|
+
createThread(workspaceId, title, agentType = desktop_js_1.LOCALCORE_ACP_AGENT_TYPE, agentMode = 'default') {
|
|
52
|
+
return this.threads.create(workspaceId, title, agentType, agentMode);
|
|
53
|
+
}
|
|
54
|
+
getThread(threadId, selectedKnowledgeBaseIds) {
|
|
55
|
+
return this.threads.get(threadId, selectedKnowledgeBaseIds);
|
|
56
|
+
}
|
|
57
|
+
renameThread(threadId, title) {
|
|
58
|
+
this.threads.rename(threadId, title);
|
|
59
|
+
}
|
|
60
|
+
deleteThread(threadId) {
|
|
61
|
+
this.platform.clearAuthorizedUserThreadByThreadId(threadId);
|
|
62
|
+
this.platform.deletePlatformThreadBindingsByThreadId(threadId);
|
|
63
|
+
this.threads.delete(threadId);
|
|
64
|
+
}
|
|
65
|
+
appendMessage(threadId, role, content, kind, toolCall, bridgeKind, bridgeStatus) {
|
|
66
|
+
return this.threads.appendMessage(threadId, role, content, kind, toolCall, bridgeKind, bridgeStatus);
|
|
67
|
+
}
|
|
68
|
+
upsertMessage(threadId, id, role, content, kind, toolCall, bridgeKind, bridgeStatus) {
|
|
69
|
+
return this.threads.upsertMessage(threadId, id, role, content, kind, toolCall, bridgeKind, bridgeStatus);
|
|
70
|
+
}
|
|
71
|
+
updateRun(runId, threadId, status) {
|
|
72
|
+
this.threads.updateRun(runId, threadId, status);
|
|
73
|
+
}
|
|
74
|
+
getLatestRunForThread(threadId) {
|
|
75
|
+
return this.threads.getLatestRunForThread(threadId);
|
|
76
|
+
}
|
|
77
|
+
getRun(runId) {
|
|
78
|
+
return this.threads.getRun(runId);
|
|
79
|
+
}
|
|
80
|
+
listWorkspaceRegistry() {
|
|
81
|
+
return this.workspaceRegistry.list();
|
|
82
|
+
}
|
|
83
|
+
getWorkspaceRegistryEntry(workspaceId) {
|
|
84
|
+
return this.workspaceRegistry.get(workspaceId);
|
|
85
|
+
}
|
|
86
|
+
upsertWorkspaceRegistryEntry(input) {
|
|
87
|
+
return this.workspaceRegistry.upsert(input);
|
|
88
|
+
}
|
|
89
|
+
updateWorkspaceRegistryEntry(workspaceId, input) {
|
|
90
|
+
return this.workspaceRegistry.update(workspaceId, input);
|
|
91
|
+
}
|
|
92
|
+
deleteWorkspaceRegistryEntry(workspaceId) {
|
|
93
|
+
return this.workspaceRegistry.delete(workspaceId);
|
|
94
|
+
}
|
|
95
|
+
touchWorkspaceRegistryEntry(workspaceId) {
|
|
96
|
+
this.workspaceRegistry.touch(workspaceId);
|
|
97
|
+
}
|
|
98
|
+
getWorkspaceSecuritySettings(workspaceId) {
|
|
99
|
+
return this.security.getWorkspaceSecuritySettings(workspaceId);
|
|
100
|
+
}
|
|
101
|
+
updateWorkspaceSecuritySettings(workspaceId, input) {
|
|
102
|
+
return this.security.updateWorkspaceSecuritySettings(workspaceId, input);
|
|
103
|
+
}
|
|
104
|
+
createApprovalRequest(input) {
|
|
105
|
+
return this.security.createApprovalRequest(input);
|
|
106
|
+
}
|
|
107
|
+
listApprovalRequests(query = {}) {
|
|
108
|
+
return this.security.listApprovalRequests(query);
|
|
109
|
+
}
|
|
110
|
+
getApprovalRequest(approvalId) {
|
|
111
|
+
return this.security.getApprovalRequest(approvalId);
|
|
112
|
+
}
|
|
113
|
+
resolveApprovalRequest(approvalId, input) {
|
|
114
|
+
return this.security.resolveApprovalRequest(approvalId, input);
|
|
115
|
+
}
|
|
116
|
+
createAuditEvent(input) {
|
|
117
|
+
return this.security.createAuditEvent(input);
|
|
118
|
+
}
|
|
119
|
+
listAuditEvents(query = {}) {
|
|
120
|
+
return this.security.listAuditEvents(query);
|
|
121
|
+
}
|
|
122
|
+
createAgentTask(input) {
|
|
123
|
+
return this.agentTasks.create(input);
|
|
124
|
+
}
|
|
125
|
+
listAgentTasks(query = {}) {
|
|
126
|
+
return this.agentTasks.list(query);
|
|
127
|
+
}
|
|
128
|
+
getAgentTask(taskId) {
|
|
129
|
+
return this.agentTasks.get(taskId);
|
|
130
|
+
}
|
|
131
|
+
getAgentTaskByRunId(runId) {
|
|
132
|
+
return this.agentTasks.getByRunId(runId);
|
|
133
|
+
}
|
|
134
|
+
updateAgentTask(taskId, input) {
|
|
135
|
+
return this.agentTasks.update(taskId, input);
|
|
136
|
+
}
|
|
137
|
+
listScheduledJobs(workspaceId) {
|
|
138
|
+
return this.scheduler.listJobs(workspaceId);
|
|
139
|
+
}
|
|
140
|
+
getScheduledJob(jobId) {
|
|
141
|
+
return this.scheduler.getJob(jobId);
|
|
142
|
+
}
|
|
143
|
+
createScheduledJob(input) {
|
|
144
|
+
return this.scheduler.createJob(input);
|
|
145
|
+
}
|
|
146
|
+
updateScheduledJob(jobId, input) {
|
|
147
|
+
return this.scheduler.updateJob(jobId, input);
|
|
148
|
+
}
|
|
149
|
+
deleteScheduledJob(jobId) {
|
|
150
|
+
return this.scheduler.deleteJob(jobId);
|
|
151
|
+
}
|
|
152
|
+
listScheduledJobRuns(jobId) {
|
|
153
|
+
return this.scheduler.listRuns(jobId);
|
|
154
|
+
}
|
|
155
|
+
createScheduledJobRun(jobId, status, input = {}) {
|
|
156
|
+
return this.scheduler.createRun(jobId, status, input);
|
|
157
|
+
}
|
|
158
|
+
getScheduledJobRun(runId) {
|
|
159
|
+
return this.scheduler.getRun(runId);
|
|
160
|
+
}
|
|
161
|
+
updateScheduledJobRun(runId, input) {
|
|
162
|
+
return this.scheduler.updateRun(runId, input);
|
|
163
|
+
}
|
|
164
|
+
updateScheduledJobStatus(jobId, input) {
|
|
165
|
+
this.scheduler.updateJobStatus(jobId, input);
|
|
166
|
+
}
|
|
167
|
+
listAutomationMonitors(workspaceId) {
|
|
168
|
+
return this.automationMonitors.list(workspaceId);
|
|
169
|
+
}
|
|
170
|
+
getAutomationMonitor(monitorId) {
|
|
171
|
+
return this.automationMonitors.get(monitorId);
|
|
172
|
+
}
|
|
173
|
+
createAutomationMonitor(input) {
|
|
174
|
+
return this.automationMonitors.create(input);
|
|
175
|
+
}
|
|
176
|
+
updateAutomationMonitor(monitorId, input) {
|
|
177
|
+
return this.automationMonitors.update(monitorId, input);
|
|
178
|
+
}
|
|
179
|
+
updateAutomationMonitorState(monitorId, input) {
|
|
180
|
+
this.automationMonitors.updateState(monitorId, input);
|
|
181
|
+
}
|
|
182
|
+
deleteAutomationMonitor(monitorId) {
|
|
183
|
+
return this.automationMonitors.delete(monitorId);
|
|
184
|
+
}
|
|
185
|
+
listAutomationMonitorRuns(monitorId) {
|
|
186
|
+
return this.automationMonitors.listRuns(monitorId);
|
|
187
|
+
}
|
|
188
|
+
createAutomationMonitorRun(monitorId, status, input = {}) {
|
|
189
|
+
return this.automationMonitors.createRun(monitorId, status, input);
|
|
190
|
+
}
|
|
191
|
+
getAutomationMonitorRun(runId) {
|
|
192
|
+
return this.automationMonitors.getRun(runId);
|
|
193
|
+
}
|
|
194
|
+
updateAutomationMonitorRun(runId, input) {
|
|
195
|
+
return this.automationMonitors.updateRun(runId, input);
|
|
196
|
+
}
|
|
197
|
+
getThreadRow(threadId) {
|
|
198
|
+
return this.threads.getRow(threadId);
|
|
199
|
+
}
|
|
200
|
+
updateThreadAgentMode(threadId, mode) {
|
|
201
|
+
this.threads.updateAgentMode(threadId, mode);
|
|
202
|
+
}
|
|
203
|
+
updateThreadAgentType(threadId, agentType) {
|
|
204
|
+
this.threads.updateAgentType(threadId, agentType);
|
|
205
|
+
}
|
|
206
|
+
updateThreadSession(threadId, sessionId, supportsLoad) {
|
|
207
|
+
this.threads.updateSession(threadId, sessionId, supportsLoad);
|
|
208
|
+
}
|
|
209
|
+
createPairingRequest(input) {
|
|
210
|
+
this.platform.createPairingRequest(input);
|
|
211
|
+
}
|
|
212
|
+
listPendingPairings(workspaceId) {
|
|
213
|
+
return this.platform.listPendingPairings(workspaceId);
|
|
214
|
+
}
|
|
215
|
+
getPairingRequest(code) {
|
|
216
|
+
return this.platform.getPairingRequest(code);
|
|
217
|
+
}
|
|
218
|
+
updatePairingStatus(code, status) {
|
|
219
|
+
this.platform.updatePairingStatus(code, status);
|
|
220
|
+
}
|
|
221
|
+
expirePendingPairings(nowIso = new Date().toISOString()) {
|
|
222
|
+
this.platform.expirePendingPairings(nowIso);
|
|
223
|
+
}
|
|
224
|
+
getAuthorizedUser(workspaceId, platformUserId, platform = 'lark') {
|
|
225
|
+
return this.platform.getAuthorizedUser(workspaceId, platformUserId, platform);
|
|
226
|
+
}
|
|
227
|
+
listAuthorizedUsers(workspaceId, platform) {
|
|
228
|
+
return this.platform.listAuthorizedUsers(workspaceId, platform);
|
|
229
|
+
}
|
|
230
|
+
createAuthorizedUser(input) {
|
|
231
|
+
this.platform.createAuthorizedUser(input);
|
|
232
|
+
}
|
|
233
|
+
updateAuthorizedUserThread(workspaceId, platformUserId, threadId, platform = 'lark') {
|
|
234
|
+
this.platform.updateAuthorizedUserThread(workspaceId, platformUserId, threadId, platform);
|
|
235
|
+
}
|
|
236
|
+
clearAuthorizedUserThreadByThreadId(threadId) {
|
|
237
|
+
this.platform.clearAuthorizedUserThreadByThreadId(threadId);
|
|
238
|
+
}
|
|
239
|
+
getPlatformThreadBinding(workspaceId, chatId, platformUserId, platform = 'lark') {
|
|
240
|
+
return this.platform.getPlatformThreadBinding(workspaceId, chatId, platformUserId, platform);
|
|
241
|
+
}
|
|
242
|
+
getPlatformThreadBindingByThreadId(threadId) {
|
|
243
|
+
return this.platform.getPlatformThreadBindingByThreadId(threadId);
|
|
244
|
+
}
|
|
245
|
+
deletePlatformThreadBindingsByThreadId(threadId) {
|
|
246
|
+
this.platform.deletePlatformThreadBindingsByThreadId(threadId);
|
|
247
|
+
}
|
|
248
|
+
upsertPlatformThreadBinding(input) {
|
|
249
|
+
this.platform.upsertPlatformThreadBinding(input);
|
|
250
|
+
}
|
|
251
|
+
updatePlatformThreadMessageId(workspaceId, chatId, platformUserId, messageId, platform = 'lark') {
|
|
252
|
+
this.platform.updatePlatformThreadMessageId(workspaceId, chatId, platformUserId, messageId, platform);
|
|
253
|
+
}
|
|
254
|
+
clearPlatformThreadMessageId(workspaceId, chatId, platformUserId, platform = 'lark') {
|
|
255
|
+
this.platform.clearPlatformThreadMessageId(workspaceId, chatId, platformUserId, platform);
|
|
256
|
+
}
|
|
257
|
+
listPairingRequests(workspaceId, platform) {
|
|
258
|
+
return this.platform.listPairingRequests(workspaceId, platform);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.LocalCoreAcpStore = LocalCoreAcpStore;
|
|
262
|
+
var utils_js_1 = require("./utils.js");
|
|
263
|
+
Object.defineProperty(exports, "redactSecrets", { enumerable: true, get: function () { return utils_js_1.redactSecrets; } });
|
|
@@ -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;
|