@dsh-enhanced/assistant-automations 0.1.3
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/LICENSE +21 -0
- package/README.md +135 -0
- package/cordis.patch.yml +36 -0
- package/lib/artifacts.d.ts +15 -0
- package/lib/artifacts.d.ts.map +1 -0
- package/lib/artifacts.js +68 -0
- package/lib/artifacts.js.map +1 -0
- package/lib/coordinator.d.ts +126 -0
- package/lib/coordinator.d.ts.map +1 -0
- package/lib/coordinator.js +374 -0
- package/lib/coordinator.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/operator.d.ts +4 -0
- package/lib/operator.d.ts.map +1 -0
- package/lib/operator.js +12 -0
- package/lib/operator.js.map +1 -0
- package/lib/proposals.d.ts +89 -0
- package/lib/proposals.d.ts.map +1 -0
- package/lib/proposals.js +499 -0
- package/lib/proposals.js.map +1 -0
- package/lib/runner.d.ts +34 -0
- package/lib/runner.d.ts.map +1 -0
- package/lib/runner.js +272 -0
- package/lib/runner.js.map +1 -0
- package/lib/schedule.d.ts +32 -0
- package/lib/schedule.d.ts.map +1 -0
- package/lib/schedule.js +245 -0
- package/lib/schedule.js.map +1 -0
- package/lib/service.d.ts +159 -0
- package/lib/service.d.ts.map +1 -0
- package/lib/service.js +445 -0
- package/lib/service.js.map +1 -0
- package/lib/sqlite.d.ts +8 -0
- package/lib/sqlite.d.ts.map +1 -0
- package/lib/sqlite.js +281 -0
- package/lib/sqlite.js.map +1 -0
- package/lib/store.d.ts +169 -0
- package/lib/store.d.ts.map +1 -0
- package/lib/store.js +1002 -0
- package/lib/store.js.map +1 -0
- package/lib/tools.d.ts +4 -0
- package/lib/tools.d.ts.map +1 -0
- package/lib/tools.js +226 -0
- package/lib/tools.js.map +1 -0
- package/lib/types.d.ts +182 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +2 -0
- package/lib/version.js.map +1 -0
- package/package.json +106 -0
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { AutomationStoreError } from './store.js';
|
|
2
|
+
export class AutomationRunnerAmbiguousError extends Error {
|
|
3
|
+
constructor(message, options) {
|
|
4
|
+
super(message, options);
|
|
5
|
+
this.name = 'AutomationRunnerAmbiguousError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function sessionId(task) {
|
|
9
|
+
return `automation-${task.occurrenceId}-${task.attemptCount + 1}`;
|
|
10
|
+
}
|
|
11
|
+
function preview(value, maximumBytes = 8_192) {
|
|
12
|
+
const bytes = Buffer.from(value, 'utf8');
|
|
13
|
+
if (bytes.byteLength <= maximumBytes)
|
|
14
|
+
return value;
|
|
15
|
+
return bytes.subarray(0, maximumBytes).toString('utf8').replace(/\uFFFD$/u, '');
|
|
16
|
+
}
|
|
17
|
+
function boundedText(value, maximumBytes) {
|
|
18
|
+
if (typeof value !== 'string')
|
|
19
|
+
return undefined;
|
|
20
|
+
const normalized = value.normalize('NFC').trim();
|
|
21
|
+
if (normalized === '' || Buffer.byteLength(normalized, 'utf8') > maximumBytes)
|
|
22
|
+
return undefined;
|
|
23
|
+
return normalized;
|
|
24
|
+
}
|
|
25
|
+
const exposureReceiptTimeoutMs = 2_000;
|
|
26
|
+
export class AutomationCoordinator {
|
|
27
|
+
store;
|
|
28
|
+
artifacts;
|
|
29
|
+
runner;
|
|
30
|
+
ownerId;
|
|
31
|
+
now;
|
|
32
|
+
dutyLeaseMs;
|
|
33
|
+
taskLeaseMs;
|
|
34
|
+
misfireGraceMs;
|
|
35
|
+
maxCatchUp;
|
|
36
|
+
maxConcurrency;
|
|
37
|
+
tickIntervalMs;
|
|
38
|
+
active = new Map();
|
|
39
|
+
delivery;
|
|
40
|
+
outcomeRecorder;
|
|
41
|
+
fencingToken;
|
|
42
|
+
timer;
|
|
43
|
+
stopped = false;
|
|
44
|
+
constructor(options) {
|
|
45
|
+
if (!Number.isSafeInteger(options.maxConcurrency) || options.maxConcurrency <= 0 || options.maxConcurrency > 100) {
|
|
46
|
+
throw new Error('assistant-automations: maxConcurrency must be between 1 and 100');
|
|
47
|
+
}
|
|
48
|
+
this.store = options.store;
|
|
49
|
+
this.artifacts = options.artifacts;
|
|
50
|
+
this.runner = options.runner;
|
|
51
|
+
this.ownerId = options.ownerId;
|
|
52
|
+
this.now = options.now ?? Date.now;
|
|
53
|
+
this.dutyLeaseMs = options.dutyLeaseMs;
|
|
54
|
+
this.taskLeaseMs = options.taskLeaseMs;
|
|
55
|
+
this.misfireGraceMs = options.misfireGraceMs;
|
|
56
|
+
this.maxCatchUp = options.maxCatchUp;
|
|
57
|
+
this.maxConcurrency = options.maxConcurrency;
|
|
58
|
+
this.tickIntervalMs = options.tickIntervalMs ?? Math.max(1_000, Math.floor(options.dutyLeaseMs / 3));
|
|
59
|
+
}
|
|
60
|
+
start() {
|
|
61
|
+
if (this.stopped)
|
|
62
|
+
throw new Error('assistant-automations coordinator is stopped');
|
|
63
|
+
if (this.timer !== undefined)
|
|
64
|
+
return;
|
|
65
|
+
this.timer = setInterval(() => void this.tick().catch(() => { }), this.tickIntervalMs);
|
|
66
|
+
this.timer.unref?.();
|
|
67
|
+
void this.tick().catch(() => { });
|
|
68
|
+
}
|
|
69
|
+
async tick() {
|
|
70
|
+
if (this.stopped)
|
|
71
|
+
throw new Error('assistant-automations coordinator is stopped');
|
|
72
|
+
const now = this.now();
|
|
73
|
+
if (!this.ensureDuty(now))
|
|
74
|
+
return;
|
|
75
|
+
this.dispatchPendingEvidence();
|
|
76
|
+
this.dispatchPendingDeliveries();
|
|
77
|
+
this.store.recoverExpiredTasks({ now, limit: this.maxCatchUp });
|
|
78
|
+
this.store.materializeDue({ now, misfireGraceMs: this.misfireGraceMs, maxCatchUp: this.maxCatchUp });
|
|
79
|
+
while (this.active.size < this.maxConcurrency) {
|
|
80
|
+
const claimed = this.store.claimNextTask({
|
|
81
|
+
ownerId: this.ownerId,
|
|
82
|
+
fencingToken: this.fencingToken,
|
|
83
|
+
now,
|
|
84
|
+
leaseMs: this.taskLeaseMs,
|
|
85
|
+
});
|
|
86
|
+
if (claimed === undefined)
|
|
87
|
+
break;
|
|
88
|
+
if (claimed.status !== 'claimed')
|
|
89
|
+
continue;
|
|
90
|
+
this.abortRequestedActive();
|
|
91
|
+
this.launch(claimed);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
setDeliveryDispatcher(delivery) {
|
|
95
|
+
this.delivery = delivery;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Attach an optional sink for finished-run outcomes.
|
|
99
|
+
*
|
|
100
|
+
* Kept optional and one-way so the scheduler never depends on a learning
|
|
101
|
+
* plugin: if no recorder is attached, or the recorder throws, runs proceed
|
|
102
|
+
* unchanged. Evidence collection must never be able to break execution.
|
|
103
|
+
*/
|
|
104
|
+
setOutcomeRecorder(recorder) {
|
|
105
|
+
this.outcomeRecorder = recorder;
|
|
106
|
+
}
|
|
107
|
+
async whenIdle() {
|
|
108
|
+
while (this.active.size > 0) {
|
|
109
|
+
await Promise.all([...this.active.values()].map(value => value.promise));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async cancel(taskId) {
|
|
113
|
+
this.store.requestCancellation({ taskId, now: this.now() });
|
|
114
|
+
this.active.get(taskId)?.controller.abort('cancel-requested');
|
|
115
|
+
}
|
|
116
|
+
async stop() {
|
|
117
|
+
if (this.stopped)
|
|
118
|
+
return;
|
|
119
|
+
this.stopped = true;
|
|
120
|
+
if (this.timer !== undefined) {
|
|
121
|
+
clearInterval(this.timer);
|
|
122
|
+
this.timer = undefined;
|
|
123
|
+
}
|
|
124
|
+
for (const value of this.active.values())
|
|
125
|
+
value.controller.abort('coordinator-stop');
|
|
126
|
+
await this.whenIdle();
|
|
127
|
+
}
|
|
128
|
+
ensureDuty(now) {
|
|
129
|
+
if (this.fencingToken !== undefined) {
|
|
130
|
+
try {
|
|
131
|
+
const renewed = this.store.renewDuty({
|
|
132
|
+
ownerId: this.ownerId,
|
|
133
|
+
fencingToken: this.fencingToken,
|
|
134
|
+
now,
|
|
135
|
+
leaseMs: this.dutyLeaseMs,
|
|
136
|
+
});
|
|
137
|
+
return renewed.acquired;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (!(error instanceof AutomationStoreError) || error.code !== 'stale-fence')
|
|
141
|
+
throw error;
|
|
142
|
+
this.fencingToken = undefined;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const acquired = this.store.acquireDuty({ ownerId: this.ownerId, now, leaseMs: this.dutyLeaseMs });
|
|
146
|
+
if (acquired.acquired)
|
|
147
|
+
this.fencingToken = acquired.fencingToken;
|
|
148
|
+
return acquired.acquired;
|
|
149
|
+
}
|
|
150
|
+
launch(claimed) {
|
|
151
|
+
const controller = new AbortController();
|
|
152
|
+
const promise = this.execute(claimed, controller).finally(() => this.active.delete(claimed.id));
|
|
153
|
+
this.active.set(claimed.id, { controller, promise });
|
|
154
|
+
void promise.catch(() => { });
|
|
155
|
+
}
|
|
156
|
+
abortRequestedActive() {
|
|
157
|
+
for (const [taskId, value] of this.active) {
|
|
158
|
+
if (this.store.getTaskRecord(taskId)?.cancelRequested === true)
|
|
159
|
+
value.controller.abort('cancel-previous');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
async execute(claimed, controller) {
|
|
163
|
+
const automation = this.store.get(claimed.automationId);
|
|
164
|
+
const occurrence = this.store.getOccurrence(claimed.occurrenceId);
|
|
165
|
+
if (automation === undefined || occurrence === undefined || this.fencingToken === undefined) {
|
|
166
|
+
throw new Error('assistant-automations: claimed task snapshot is missing');
|
|
167
|
+
}
|
|
168
|
+
const fence = this.fencingToken;
|
|
169
|
+
const freshSessionId = sessionId(claimed);
|
|
170
|
+
const started = this.store.startTask({
|
|
171
|
+
taskId: claimed.id,
|
|
172
|
+
ownerId: this.ownerId,
|
|
173
|
+
fencingToken: fence,
|
|
174
|
+
now: this.now(),
|
|
175
|
+
leaseMs: this.taskLeaseMs,
|
|
176
|
+
sessionId: freshSessionId,
|
|
177
|
+
});
|
|
178
|
+
let timedOut = false;
|
|
179
|
+
const timeout = setTimeout(() => {
|
|
180
|
+
timedOut = true;
|
|
181
|
+
controller.abort('timeout');
|
|
182
|
+
}, automation.definition.timeoutMs);
|
|
183
|
+
timeout.unref?.();
|
|
184
|
+
const heartbeat = setInterval(() => {
|
|
185
|
+
try {
|
|
186
|
+
const now = this.now();
|
|
187
|
+
this.store.renewDuty({
|
|
188
|
+
ownerId: this.ownerId,
|
|
189
|
+
fencingToken: fence,
|
|
190
|
+
now,
|
|
191
|
+
leaseMs: this.dutyLeaseMs,
|
|
192
|
+
});
|
|
193
|
+
this.store.heartbeatTask({
|
|
194
|
+
taskId: started.id,
|
|
195
|
+
ownerId: this.ownerId,
|
|
196
|
+
fencingToken: fence,
|
|
197
|
+
now,
|
|
198
|
+
leaseMs: this.taskLeaseMs,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
controller.abort('lease-lost');
|
|
203
|
+
}
|
|
204
|
+
}, Math.max(250, Math.floor(Math.min(this.dutyLeaseMs, this.taskLeaseMs) / 3)));
|
|
205
|
+
heartbeat.unref?.();
|
|
206
|
+
let result;
|
|
207
|
+
try {
|
|
208
|
+
result = await this.runner.run({
|
|
209
|
+
automation,
|
|
210
|
+
occurrence,
|
|
211
|
+
task: started,
|
|
212
|
+
sessionId: freshSessionId,
|
|
213
|
+
signal: controller.signal,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
result = {
|
|
218
|
+
outcome: controller.signal.aborted
|
|
219
|
+
? 'cancelled'
|
|
220
|
+
: error instanceof AutomationRunnerAmbiguousError ? 'unknown' : 'failed',
|
|
221
|
+
output: error instanceof Error ? error.message : String(error),
|
|
222
|
+
usage: {},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
finally {
|
|
226
|
+
clearTimeout(timeout);
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const evidenceSessionId = result.sessionId === freshSessionId ? freshSessionId : undefined;
|
|
230
|
+
const exposure = evidenceSessionId === undefined
|
|
231
|
+
? undefined
|
|
232
|
+
: await this.getExposure(automation, evidenceSessionId);
|
|
233
|
+
const outcome = timedOut
|
|
234
|
+
? 'timed_out'
|
|
235
|
+
: controller.signal.aborted ? 'cancelled' : result.outcome;
|
|
236
|
+
const outputPreview = preview(result.output);
|
|
237
|
+
const artifactRef = this.artifacts.write(occurrence.id, {
|
|
238
|
+
occurrenceId: occurrence.id,
|
|
239
|
+
automationId: automation.id,
|
|
240
|
+
taskId: started.id,
|
|
241
|
+
outcome,
|
|
242
|
+
sessionId: result.sessionId ?? freshSessionId,
|
|
243
|
+
output: result.output,
|
|
244
|
+
usage: result.usage,
|
|
245
|
+
});
|
|
246
|
+
const run = this.store.completeTask({
|
|
247
|
+
taskId: started.id,
|
|
248
|
+
ownerId: this.ownerId,
|
|
249
|
+
fencingToken: fence,
|
|
250
|
+
now: this.now(),
|
|
251
|
+
outcome,
|
|
252
|
+
sessionId: result.sessionId ?? freshSessionId,
|
|
253
|
+
artifactRef,
|
|
254
|
+
outputPreview,
|
|
255
|
+
usage: result.usage,
|
|
256
|
+
...(evidenceSessionId === undefined
|
|
257
|
+
? {}
|
|
258
|
+
: {
|
|
259
|
+
evidenceAttribution: {
|
|
260
|
+
sessionId: evidenceSessionId,
|
|
261
|
+
...(exposure === undefined ? {} : exposure),
|
|
262
|
+
},
|
|
263
|
+
}),
|
|
264
|
+
});
|
|
265
|
+
this.dispatchRunDelivery(run);
|
|
266
|
+
this.dispatchRunEvidence(run);
|
|
267
|
+
}
|
|
268
|
+
finally {
|
|
269
|
+
clearInterval(heartbeat);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async getExposure(automation, actualSessionId) {
|
|
273
|
+
const recorder = this.outcomeRecorder;
|
|
274
|
+
if (recorder?.captureAutomationExposure === undefined)
|
|
275
|
+
return undefined;
|
|
276
|
+
let timeout;
|
|
277
|
+
try {
|
|
278
|
+
const captured = await Promise.race([
|
|
279
|
+
Promise.resolve(recorder.captureAutomationExposure({
|
|
280
|
+
workspace: automation.definition.workspace,
|
|
281
|
+
agentPreset: automation.definition.agentPreset,
|
|
282
|
+
automationId: automation.id,
|
|
283
|
+
sessionId: actualSessionId,
|
|
284
|
+
})),
|
|
285
|
+
new Promise(resolve => {
|
|
286
|
+
timeout = setTimeout(() => resolve(undefined), exposureReceiptTimeoutMs);
|
|
287
|
+
}),
|
|
288
|
+
]);
|
|
289
|
+
if (captured === undefined)
|
|
290
|
+
return undefined;
|
|
291
|
+
const ruleId = boundedText(captured.ruleId, 200);
|
|
292
|
+
if (ruleId === undefined
|
|
293
|
+
|| !Number.isSafeInteger(captured.guidanceVersion)
|
|
294
|
+
|| captured.guidanceVersion < 1
|
|
295
|
+
|| captured.guidanceVersion > 1_000_000_000) {
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
return { ruleId, guidanceVersion: captured.guidanceVersion };
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
if (timeout !== undefined)
|
|
305
|
+
clearTimeout(timeout);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
dispatchPendingEvidence() {
|
|
309
|
+
if (this.outcomeRecorder === undefined)
|
|
310
|
+
return;
|
|
311
|
+
for (const run of this.store.listPendingEvidence(100))
|
|
312
|
+
this.dispatchRunEvidence(run);
|
|
313
|
+
}
|
|
314
|
+
dispatchRunEvidence(run) {
|
|
315
|
+
const recorder = this.outcomeRecorder;
|
|
316
|
+
if (recorder === undefined || run.evidenceStatus !== 'pending' || run.evidence === undefined)
|
|
317
|
+
return;
|
|
318
|
+
try {
|
|
319
|
+
recorder.recordAutomationOutcome(run.evidence);
|
|
320
|
+
this.store.completeRunEvidence({ runId: run.id, expectedStatus: 'pending', now: this.now() });
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
// Evidence is an outbox lane: the run remains terminal and a later leader
|
|
324
|
+
// tick repeats the same recorder idempotency key. Move a poison row behind
|
|
325
|
+
// its peers so a bounded batch cannot starve newer evidence indefinitely.
|
|
326
|
+
try {
|
|
327
|
+
this.store.deferRunEvidence({ runId: run.id, expectedStatus: 'pending', now: this.now() });
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
// A concurrent settlement or store shutdown already owns the next step.
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
dispatchPendingDeliveries() {
|
|
335
|
+
for (const run of this.store.listPendingDeliveries(100))
|
|
336
|
+
this.dispatchRunDelivery(run);
|
|
337
|
+
}
|
|
338
|
+
dispatchRunDelivery(run) {
|
|
339
|
+
if (run.deliveryStatus !== 'pending')
|
|
340
|
+
return;
|
|
341
|
+
const automation = this.store.get(run.automationId);
|
|
342
|
+
const bindingId = automation?.definition.deliveryBindingId;
|
|
343
|
+
if (automation === undefined || bindingId === undefined)
|
|
344
|
+
return;
|
|
345
|
+
const normalizedOutput = run.outputPreview.normalize('NFC').trim();
|
|
346
|
+
if (normalizedOutput === '' || automation.definition.deliverySuppressExact?.includes(normalizedOutput) === true) {
|
|
347
|
+
this.store.suppressRunDelivery({ runId: run.id, expectedStatus: 'pending', now: this.now() });
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (this.delivery === undefined)
|
|
351
|
+
return;
|
|
352
|
+
try {
|
|
353
|
+
const outbox = this.delivery.enqueueBackground({
|
|
354
|
+
sourceId: automation.id,
|
|
355
|
+
workspace: automation.definition.workspace,
|
|
356
|
+
bindingId,
|
|
357
|
+
idempotencyKey: `automation:${run.occurrenceId}:${bindingId}`,
|
|
358
|
+
text: run.outputPreview,
|
|
359
|
+
format: 'markdown',
|
|
360
|
+
});
|
|
361
|
+
this.store.completeRunDelivery({
|
|
362
|
+
runId: run.id,
|
|
363
|
+
expectedStatus: 'pending',
|
|
364
|
+
deliveryRef: outbox.id,
|
|
365
|
+
now: this.now(),
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
// The successful execution remains authoritative. A later tick repeats the
|
|
370
|
+
// same Delivery idempotency key and cannot create a second outbound intent.
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=coordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinator.js","sourceRoot":"","sources":["../src/coordinator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,YAAY,CAAA;AAsEvE,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACvD,YAAY,OAAe,EAAE,OAAsB;QACjD,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAA;IAC9C,CAAC;CACF;AAgBD,SAAS,SAAS,CAAC,IAAoB;IACrC,OAAO,cAAc,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,GAAG,CAAC,EAAE,CAAA;AACnE,CAAC;AAED,SAAS,OAAO,CAAC,KAAa,EAAE,YAAY,GAAG,KAAK;IAClD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACxC,IAAI,KAAK,CAAC,UAAU,IAAI,YAAY;QAAE,OAAO,KAAK,CAAA;IAClD,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;AACjF,CAAC;AAED,SAAS,WAAW,CAAC,KAAc,EAAE,YAAoB;IACvD,IAAI,OAAO,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AAU,CAAC,UAAU,CAAC,SAAS;gBAC1C,SAAS;gBACT,cAAc,EAAE,cAAc,GAAG,CAAC,YAAY,IAAI,SAAS,EAAE;gBAC7D,IAAI,EAAE,GAAG,CAAC,aAAa;gBACvB,MAAM,EAAE,UAAU;aACnB,CAAC,CAAA;YACF,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC;gBAC7B,KAAK,EAAE,GAAG,CAAC,EAAE;gBACb,cAAc,EAAE,SAAS;gBACzB,WAAW,EAAE,MAAM,CAAC,EAAE;gBACtB,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;aAChB,CAAC,CAAA;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,2EAA2E;YAC3E,4EAA4E;QAC9E,CAAC;IACH,CAAC;CACF"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { AssistantAutomationsService, Config } from './service.js';
|
|
3
|
+
import { version } from './version.js';
|
|
4
|
+
export declare const name = "dsh-enhanced-assistant-automations";
|
|
5
|
+
export { AssistantAutomationsService, Config, version };
|
|
6
|
+
export type { PendingAutomationProposal, SystemAutomationReconcileInput } from './service.js';
|
|
7
|
+
export * from './types.js';
|
|
8
|
+
export { listActiveAutomationsLocally } from './operator.js';
|
|
9
|
+
export declare function apply(ctx: Context, config: import('./service.js').Config): void;
|
|
10
|
+
export default AssistantAutomationsService;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,eAAO,MAAM,IAAI,uCAAuC,CAAA;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;AACvD,YAAY,EAAE,yBAAyB,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAA;AAC7F,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA;AAE5D,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,cAAc,EAAE,MAAM,GAAG,IAAI,CAE/E;AAED,eAAe,2BAA2B,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AssistantAutomationsService, Config } from './service.js';
|
|
2
|
+
import { version } from './version.js';
|
|
3
|
+
export const name = 'dsh-enhanced-assistant-automations';
|
|
4
|
+
export { AssistantAutomationsService, Config, version };
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export { listActiveAutomationsLocally } from './operator.js';
|
|
7
|
+
export function apply(ctx, config) {
|
|
8
|
+
new AssistantAutomationsService(ctx, config);
|
|
9
|
+
}
|
|
10
|
+
export default AssistantAutomationsService;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,CAAC,MAAM,IAAI,GAAG,oCAAoC,CAAA;AACxD,OAAO,EAAE,2BAA2B,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;AAEvD,cAAc,YAAY,CAAA;AAC1B,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAA;AAE5D,MAAM,UAAU,KAAK,CAAC,GAAY,EAAE,MAAqC;IACvE,IAAI,2BAA2B,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;AAC9C,CAAC;AAED,eAAe,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAGlD,8EAA8E;AAC9E,wBAAgB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAOrF"}
|
package/lib/operator.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AutomationStore } from './store.js';
|
|
2
|
+
/** Read-only local inspection for setup tools; never starts the scheduler. */
|
|
3
|
+
export function listActiveAutomationsLocally(databasePath) {
|
|
4
|
+
const store = new AutomationStore({ path: databasePath });
|
|
5
|
+
try {
|
|
6
|
+
return store.list().filter(record => record.status === 'active');
|
|
7
|
+
}
|
|
8
|
+
finally {
|
|
9
|
+
store.close();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=operator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator.js","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C,8EAA8E;AAC9E,MAAM,UAAU,4BAA4B,CAAC,YAAoB;IAC/D,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAA;IACzD,IAAI,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAA;IAClE,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,KAAK,EAAE,CAAA;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { ApprovalDecisionInput, ApprovalDispatchRoute, ApprovalProposalRecoveryInput, ApprovalProposalRecoveryResult, ApprovalProposalResult, ApprovalProposalSnapshot } from '@dsh-enhanced/assistant-policy';
|
|
2
|
+
import { type AutomationStore } from './store.js';
|
|
3
|
+
import type { AutomationMutation, AutomationProposalDecisionInput, AutomationProposalInput, AutomationProposalResult, AutomationProposalStatus, StoredAutomationProposal } from './types.js';
|
|
4
|
+
export type AutomationProposalStoreErrorCode = 'idempotency-conflict' | 'invalid-input' | 'invalid-path' | 'invalid-state' | 'not-found' | 'schema-too-new' | 'unauthorized';
|
|
5
|
+
export declare class AutomationProposalStoreError extends Error {
|
|
6
|
+
readonly code: AutomationProposalStoreErrorCode;
|
|
7
|
+
constructor(code: AutomationProposalStoreErrorCode, message: string);
|
|
8
|
+
}
|
|
9
|
+
export interface AutomationApprovalPolicy {
|
|
10
|
+
recoverOrCreateProposal(input: ApprovalProposalRecoveryInput): ApprovalProposalRecoveryResult;
|
|
11
|
+
decideProposal(input: ApprovalDecisionInput): ApprovalProposalResult;
|
|
12
|
+
getProposal(proposalId: string): ApprovalProposalSnapshot | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare class AutomationProposalStore {
|
|
15
|
+
private readonly database;
|
|
16
|
+
private readonly now;
|
|
17
|
+
private closed;
|
|
18
|
+
constructor(options: {
|
|
19
|
+
path: string;
|
|
20
|
+
now?: () => number;
|
|
21
|
+
});
|
|
22
|
+
close(): void;
|
|
23
|
+
get(proposalId: string): StoredAutomationProposal | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* List proposals still pending locally, oldest first, so a reconciler can pair
|
|
26
|
+
* them with their policy decision.
|
|
27
|
+
*/
|
|
28
|
+
listPending(limit: number): StoredAutomationProposal[];
|
|
29
|
+
prepare(input: {
|
|
30
|
+
proposalId: string;
|
|
31
|
+
idempotencyKey: string;
|
|
32
|
+
requester: string;
|
|
33
|
+
principal: string;
|
|
34
|
+
dispatch?: Readonly<ApprovalDispatchRoute>;
|
|
35
|
+
requestHash: string;
|
|
36
|
+
mutation: AutomationMutation;
|
|
37
|
+
expiresAt: number;
|
|
38
|
+
ttlMs: number;
|
|
39
|
+
}): {
|
|
40
|
+
proposal: StoredAutomationProposal;
|
|
41
|
+
replayed: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** Move an inspected, still-pending row behind older peers using a durable monotonic timestamp. */
|
|
44
|
+
deferPending(proposalId: string): void;
|
|
45
|
+
attachPolicy(proposalId: string, policyProposalId: string, expiresAt: number): StoredAutomationProposal;
|
|
46
|
+
settle(input: {
|
|
47
|
+
proposalId: string;
|
|
48
|
+
status: Exclude<AutomationProposalStatus, 'pending'>;
|
|
49
|
+
version: number;
|
|
50
|
+
resultAutomationId?: string;
|
|
51
|
+
}): {
|
|
52
|
+
proposal: StoredAutomationProposal;
|
|
53
|
+
replayed: boolean;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export declare class AutomationProposalManager {
|
|
57
|
+
private readonly automations;
|
|
58
|
+
private readonly proposals;
|
|
59
|
+
private readonly policy;
|
|
60
|
+
private readonly now;
|
|
61
|
+
constructor(automations: AutomationStore, proposals: AutomationProposalStore, policy: AutomationApprovalPolicy, now?: () => number);
|
|
62
|
+
propose(input: AutomationProposalInput): AutomationProposalResult;
|
|
63
|
+
decide(input: AutomationProposalDecisionInput): AutomationProposalResult;
|
|
64
|
+
/**
|
|
65
|
+
* Commit locally pending proposals whose policy decision already settled
|
|
66
|
+
* elsewhere, for example on an approval card minutes after the turn ended.
|
|
67
|
+
*
|
|
68
|
+
* Approval is never inferred: the terminal status is read back from the policy
|
|
69
|
+
* ledger and applied through the same settle path `decide()` uses, so repeated
|
|
70
|
+
* reconciles are idempotent.
|
|
71
|
+
*/
|
|
72
|
+
reconcile(limit: number): AutomationProposalResult[];
|
|
73
|
+
private policyIdentity;
|
|
74
|
+
/**
|
|
75
|
+
* Atomically recover or create the Policy half under the locally frozen
|
|
76
|
+
* deadline. An abandoned result is terminal and must never be resurrected.
|
|
77
|
+
*/
|
|
78
|
+
private recoverOrCreatePolicyProposal;
|
|
79
|
+
private settleValidated;
|
|
80
|
+
private settleSecurityConflict;
|
|
81
|
+
/**
|
|
82
|
+
* Apply one already-terminal policy status to a pending automation proposal. A
|
|
83
|
+
* store conflict downgrades the proposal to `conflicted` instead of losing the
|
|
84
|
+
* decision, matching the rule that a decision is never re-asked.
|
|
85
|
+
*/
|
|
86
|
+
private settleDecided;
|
|
87
|
+
get(proposalId: string): AutomationProposalResult | undefined;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=proposals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposals.d.ts","sourceRoot":"","sources":["../src/proposals.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,6BAA6B,EAC7B,8BAA8B,EAC9B,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EACV,kBAAkB,EAClB,+BAA+B,EAC/B,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,gCAAgC,GACxC,sBAAsB,GACtB,eAAe,GACf,cAAc,GACd,eAAe,GACf,WAAW,GACX,gBAAgB,GAChB,cAAc,CAAA;AAElB,qBAAa,4BAA6B,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,gCAAgC;gBAAtC,IAAI,EAAE,gCAAgC,EAAE,OAAO,EAAE,MAAM;CAI7E;AAED,MAAM,WAAW,wBAAwB;IACvC,uBAAuB,CAAC,KAAK,EAAE,6BAA6B,GAAG,8BAA8B,CAAA;IAC7F,cAAc,CAAC,KAAK,EAAE,qBAAqB,GAAG,sBAAsB,CAAA;IACpE,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAAA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