astrocode-workflow 0.1.40 → 0.1.42
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.
|
@@ -16,7 +16,7 @@ export function createContinuationEnforcer(opts) {
|
|
|
16
16
|
const cur = sessions.get(sessionId);
|
|
17
17
|
if (cur)
|
|
18
18
|
return cur;
|
|
19
|
-
const state = { lastHash: null, lastAtMs: 0, repeats: 0, autoSteps: 0, idleTimer: null };
|
|
19
|
+
const state = { lastHash: null, lastAtMs: 0, repeats: 0, autoSteps: 0, idleTimer: null, periodicTimer: null };
|
|
20
20
|
sessions.set(sessionId, state);
|
|
21
21
|
return state;
|
|
22
22
|
}
|
|
@@ -27,6 +27,13 @@ export function createContinuationEnforcer(opts) {
|
|
|
27
27
|
s.idleTimer = null;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
function clearPeriodicTimer(sessionId) {
|
|
31
|
+
const s = getState(sessionId);
|
|
32
|
+
if (s.periodicTimer) {
|
|
33
|
+
clearInterval(s.periodicTimer);
|
|
34
|
+
s.periodicTimer = null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
30
37
|
function scheduleIdleInjection(sessionId) {
|
|
31
38
|
clearIdleTimer(sessionId);
|
|
32
39
|
if (!config.continuation.enabled)
|
|
@@ -40,6 +47,18 @@ export function createContinuationEnforcer(opts) {
|
|
|
40
47
|
void maybeInjectContinue(sessionId, "idle_timer");
|
|
41
48
|
}, delay);
|
|
42
49
|
}
|
|
50
|
+
function schedulePeriodicInjection(sessionId) {
|
|
51
|
+
clearPeriodicTimer(sessionId);
|
|
52
|
+
if (!config.continuation.enabled)
|
|
53
|
+
return;
|
|
54
|
+
// Inject every 5 minutes (300,000 ms)
|
|
55
|
+
const interval = 5 * 60 * 1000;
|
|
56
|
+
const s = getState(sessionId);
|
|
57
|
+
s.periodicTimer = setInterval(() => {
|
|
58
|
+
// Fire and forget
|
|
59
|
+
void maybeInjectContinue(sessionId, "periodic_timer");
|
|
60
|
+
}, interval);
|
|
61
|
+
}
|
|
43
62
|
function shouldDedupe(sessionId, directive) {
|
|
44
63
|
const s = getState(sessionId);
|
|
45
64
|
const now = Date.now();
|
|
@@ -136,6 +155,8 @@ export function createContinuationEnforcer(opts) {
|
|
|
136
155
|
return;
|
|
137
156
|
if (!config.continuation.inject_on_tool_done_if_run_active)
|
|
138
157
|
return;
|
|
158
|
+
// Inject continuation immediately after any tool execution
|
|
159
|
+
void maybeInjectContinue(sessionId, "tool_execution");
|
|
139
160
|
scheduleIdleInjection(sessionId);
|
|
140
161
|
},
|
|
141
162
|
async onChatMessage(_input) {
|
|
@@ -156,9 +177,11 @@ export function createContinuationEnforcer(opts) {
|
|
|
156
177
|
if (type === "session.created") {
|
|
157
178
|
// When a session is created and there is an active run, nudge.
|
|
158
179
|
scheduleIdleInjection(sessionId);
|
|
180
|
+
schedulePeriodicInjection(sessionId);
|
|
159
181
|
}
|
|
160
182
|
if (type === "session.deleted") {
|
|
161
183
|
clearIdleTimer(sessionId);
|
|
184
|
+
clearPeriodicTimer(sessionId);
|
|
162
185
|
sessions.delete(sessionId);
|
|
163
186
|
}
|
|
164
187
|
},
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ type SessionState = {
|
|
|
13
13
|
repeats: number;
|
|
14
14
|
autoSteps: number;
|
|
15
15
|
idleTimer: NodeJS.Timeout | null;
|
|
16
|
+
periodicTimer: NodeJS.Timeout | null;
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
type ToolExecuteAfterInput = {
|
|
@@ -48,7 +49,7 @@ export function createContinuationEnforcer(opts: {
|
|
|
48
49
|
function getState(sessionId: string): SessionState {
|
|
49
50
|
const cur = sessions.get(sessionId);
|
|
50
51
|
if (cur) return cur;
|
|
51
|
-
const state: SessionState = { lastHash: null, lastAtMs: 0, repeats: 0, autoSteps: 0, idleTimer: null };
|
|
52
|
+
const state: SessionState = { lastHash: null, lastAtMs: 0, repeats: 0, autoSteps: 0, idleTimer: null, periodicTimer: null };
|
|
52
53
|
sessions.set(sessionId, state);
|
|
53
54
|
return state;
|
|
54
55
|
}
|
|
@@ -61,6 +62,14 @@ export function createContinuationEnforcer(opts: {
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
function clearPeriodicTimer(sessionId: string) {
|
|
66
|
+
const s = getState(sessionId);
|
|
67
|
+
if (s.periodicTimer) {
|
|
68
|
+
clearInterval(s.periodicTimer);
|
|
69
|
+
s.periodicTimer = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
64
73
|
function scheduleIdleInjection(sessionId: string) {
|
|
65
74
|
clearIdleTimer(sessionId);
|
|
66
75
|
if (!config.continuation.enabled) return;
|
|
@@ -75,6 +84,20 @@ export function createContinuationEnforcer(opts: {
|
|
|
75
84
|
}, delay);
|
|
76
85
|
}
|
|
77
86
|
|
|
87
|
+
function schedulePeriodicInjection(sessionId: string) {
|
|
88
|
+
clearPeriodicTimer(sessionId);
|
|
89
|
+
if (!config.continuation.enabled) return;
|
|
90
|
+
|
|
91
|
+
// Inject every 5 minutes (300,000 ms)
|
|
92
|
+
const interval = 5 * 60 * 1000;
|
|
93
|
+
|
|
94
|
+
const s = getState(sessionId);
|
|
95
|
+
s.periodicTimer = setInterval(() => {
|
|
96
|
+
// Fire and forget
|
|
97
|
+
void maybeInjectContinue(sessionId, "periodic_timer");
|
|
98
|
+
}, interval);
|
|
99
|
+
}
|
|
100
|
+
|
|
78
101
|
function shouldDedupe(sessionId: string, directive: BuiltDirective): boolean {
|
|
79
102
|
const s = getState(sessionId);
|
|
80
103
|
const now = Date.now();
|
|
@@ -185,6 +208,9 @@ export function createContinuationEnforcer(opts: {
|
|
|
185
208
|
if (!sessionId) return;
|
|
186
209
|
if (!config.continuation.inject_on_tool_done_if_run_active) return;
|
|
187
210
|
|
|
211
|
+
// Inject continuation immediately after any tool execution
|
|
212
|
+
void maybeInjectContinue(sessionId, "tool_execution");
|
|
213
|
+
|
|
188
214
|
scheduleIdleInjection(sessionId);
|
|
189
215
|
},
|
|
190
216
|
|
|
@@ -206,10 +232,12 @@ export function createContinuationEnforcer(opts: {
|
|
|
206
232
|
if (type === "session.created") {
|
|
207
233
|
// When a session is created and there is an active run, nudge.
|
|
208
234
|
scheduleIdleInjection(sessionId);
|
|
235
|
+
schedulePeriodicInjection(sessionId);
|
|
209
236
|
}
|
|
210
237
|
|
|
211
238
|
if (type === "session.deleted") {
|
|
212
239
|
clearIdleTimer(sessionId);
|
|
240
|
+
clearPeriodicTimer(sessionId);
|
|
213
241
|
sessions.delete(sessionId);
|
|
214
242
|
}
|
|
215
243
|
},
|