@grackle-ai/server 0.75.3 → 0.75.4
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 +17 -61
- package/dist/index.js +8 -24
- package/dist/index.js.map +1 -1
- package/dist/local-powerline-manager.js +1 -1
- package/dist/local-powerline-manager.js.map +1 -1
- package/dist/local-powerline.js +1 -1
- package/dist/local-powerline.js.map +1 -1
- package/package.json +15 -28
- package/dist/adapter-config.d.ts +0 -6
- package/dist/adapter-config.d.ts.map +0 -1
- package/dist/adapter-config.js +0 -19
- package/dist/adapter-config.js.map +0 -1
- package/dist/adapter-manager.d.ts +0 -22
- package/dist/adapter-manager.d.ts.map +0 -1
- package/dist/adapter-manager.js +0 -81
- package/dist/adapter-manager.js.map +0 -1
- package/dist/auto-reconnect.d.ts +0 -23
- package/dist/auto-reconnect.d.ts.map +0 -1
- package/dist/auto-reconnect.js +0 -164
- package/dist/auto-reconnect.js.map +0 -1
- package/dist/compute-task-status.d.ts +0 -28
- package/dist/compute-task-status.d.ts.map +0 -1
- package/dist/compute-task-status.js +0 -70
- package/dist/compute-task-status.js.map +0 -1
- package/dist/credential-bundle.d.ts +0 -12
- package/dist/credential-bundle.d.ts.map +0 -1
- package/dist/credential-bundle.js +0 -183
- package/dist/credential-bundle.js.map +0 -1
- package/dist/event-bus.d.ts +0 -37
- package/dist/event-bus.d.ts.map +0 -1
- package/dist/event-bus.js +0 -65
- package/dist/event-bus.js.map +0 -1
- package/dist/event-processor.d.ts +0 -36
- package/dist/event-processor.d.ts.map +0 -1
- package/dist/event-processor.js +0 -312
- package/dist/event-processor.js.map +0 -1
- package/dist/grpc-service.d.ts +0 -22
- package/dist/grpc-service.d.ts.map +0 -1
- package/dist/grpc-service.js +0 -1724
- package/dist/grpc-service.js.map +0 -1
- package/dist/knowledge-init.d.ts +0 -27
- package/dist/knowledge-init.d.ts.map +0 -1
- package/dist/knowledge-init.js +0 -212
- package/dist/knowledge-init.js.map +0 -1
- package/dist/lifecycle.d.ts +0 -36
- package/dist/lifecycle.d.ts.map +0 -1
- package/dist/lifecycle.js +0 -112
- package/dist/lifecycle.js.map +0 -1
- package/dist/log-writer.d.ts +0 -32
- package/dist/log-writer.d.ts.map +0 -1
- package/dist/log-writer.js +0 -104
- package/dist/log-writer.js.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -10
- package/dist/logger.js.map +0 -1
- package/dist/pipe-delivery.d.ts +0 -41
- package/dist/pipe-delivery.d.ts.map +0 -1
- package/dist/pipe-delivery.js +0 -186
- package/dist/pipe-delivery.js.map +0 -1
- package/dist/processor-registry.d.ts +0 -25
- package/dist/processor-registry.d.ts.map +0 -1
- package/dist/processor-registry.js +0 -58
- package/dist/processor-registry.js.map +0 -1
- package/dist/reanimate-agent.d.ts +0 -12
- package/dist/reanimate-agent.d.ts.map +0 -1
- package/dist/reanimate-agent.js +0 -76
- package/dist/reanimate-agent.js.map +0 -1
- package/dist/session-recovery.d.ts +0 -16
- package/dist/session-recovery.d.ts.map +0 -1
- package/dist/session-recovery.js +0 -129
- package/dist/session-recovery.js.map +0 -1
- package/dist/signals/sigchld.d.ts +0 -7
- package/dist/signals/sigchld.d.ts.map +0 -1
- package/dist/signals/sigchld.js +0 -167
- package/dist/signals/sigchld.js.map +0 -1
- package/dist/signals/signal-delivery.d.ts +0 -14
- package/dist/signals/signal-delivery.d.ts.map +0 -1
- package/dist/signals/signal-delivery.js +0 -166
- package/dist/signals/signal-delivery.js.map +0 -1
- package/dist/stream-hub.d.ts +0 -14
- package/dist/stream-hub.d.ts.map +0 -1
- package/dist/stream-hub.js +0 -95
- package/dist/stream-hub.js.map +0 -1
- package/dist/stream-registry.d.ts +0 -84
- package/dist/stream-registry.d.ts.map +0 -1
- package/dist/stream-registry.js +0 -363
- package/dist/stream-registry.js.map +0 -1
- package/dist/test-utils/integration-setup.d.ts +0 -11
- package/dist/test-utils/integration-setup.d.ts.map +0 -1
- package/dist/test-utils/integration-setup.js +0 -32
- package/dist/test-utils/integration-setup.js.map +0 -1
- package/dist/test-utils/mock-database.d.ts +0 -130
- package/dist/test-utils/mock-database.d.ts.map +0 -1
- package/dist/test-utils/mock-database.js +0 -147
- package/dist/test-utils/mock-database.js.map +0 -1
- package/dist/token-push.d.ts +0 -22
- package/dist/token-push.d.ts.map +0 -1
- package/dist/token-push.js +0 -78
- package/dist/token-push.js.map +0 -1
- package/dist/transcript.d.ts +0 -5
- package/dist/transcript.d.ts.map +0 -1
- package/dist/transcript.js +0 -71
- package/dist/transcript.js.map +0 -1
- package/dist/utils/exec.d.ts +0 -17
- package/dist/utils/exec.d.ts.map +0 -1
- package/dist/utils/exec.js +0 -21
- package/dist/utils/exec.js.map +0 -1
- package/dist/utils/format-gh-error.d.ts +0 -6
- package/dist/utils/format-gh-error.d.ts.map +0 -1
- package/dist/utils/format-gh-error.js +0 -30
- package/dist/utils/format-gh-error.js.map +0 -1
- package/dist/utils/network.d.ts +0 -7
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js +0 -21
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/ports.d.ts +0 -3
- package/dist/utils/ports.d.ts.map +0 -1
- package/dist/utils/ports.js +0 -19
- package/dist/utils/ports.js.map +0 -1
- package/dist/utils/sleep.d.ts +0 -3
- package/dist/utils/sleep.d.ts.map +0 -1
- package/dist/utils/sleep.js +0 -5
- package/dist/utils/sleep.js.map +0 -1
- package/dist/ws-bridge.d.ts +0 -30
- package/dist/ws-bridge.d.ts.map +0 -1
- package/dist/ws-bridge.js +0 -372
- package/dist/ws-bridge.js.map +0 -1
- package/dist/ws-broadcast.d.ts +0 -19
- package/dist/ws-broadcast.d.ts.map +0 -1
- package/dist/ws-broadcast.js +0 -60
- package/dist/ws-broadcast.js.map +0 -1
package/dist/auto-reconnect.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { reconnectOrProvision } from "@grackle-ai/adapter-sdk";
|
|
2
|
-
import { envRegistry } from "@grackle-ai/database";
|
|
3
|
-
import * as adapterManager from "./adapter-manager.js";
|
|
4
|
-
import * as tokenPush from "./token-push.js";
|
|
5
|
-
import { recoverSuspendedSessions } from "./session-recovery.js";
|
|
6
|
-
import { parseAdapterConfig } from "./adapter-config.js";
|
|
7
|
-
import { emit } from "./event-bus.js";
|
|
8
|
-
import { logger } from "./logger.js";
|
|
9
|
-
// ─── Constants ──────────────────────────────────────────────
|
|
10
|
-
/** Initial delay before first reconnect attempt (milliseconds). */
|
|
11
|
-
const RECONNECT_INITIAL_DELAY_MS = 10_000;
|
|
12
|
-
/** Maximum number of reconnect attempts before giving up. */
|
|
13
|
-
const RECONNECT_MAX_RETRIES = 5;
|
|
14
|
-
/** Maximum delay between reconnect attempts (milliseconds). */
|
|
15
|
-
const RECONNECT_MAX_DELAY_MS = 120_000;
|
|
16
|
-
/** Multiplier for exponential backoff. */
|
|
17
|
-
const RECONNECT_BACKOFF_MULTIPLIER = 2;
|
|
18
|
-
/** Tracks reconnect backoff state per environment. */
|
|
19
|
-
const reconnectStates = new Map();
|
|
20
|
-
/** Prevents concurrent reconnect attempts for the same environment. */
|
|
21
|
-
const reconnecting = new Set();
|
|
22
|
-
// ─── Public API ─────────────────────────────────────────────
|
|
23
|
-
/**
|
|
24
|
-
* Scan for disconnected environments and attempt to reconnect eligible ones.
|
|
25
|
-
* Called after each heartbeat tick. Uses exponential backoff per environment
|
|
26
|
-
* and a concurrency lock to prevent overlapping attempts.
|
|
27
|
-
*
|
|
28
|
-
* Fire-and-forget for each environment — logs errors but does not throw.
|
|
29
|
-
*/
|
|
30
|
-
export async function attemptReconnects() {
|
|
31
|
-
const environments = envRegistry.listEnvironments();
|
|
32
|
-
const disconnected = environments.filter((env) => env.status === "disconnected");
|
|
33
|
-
for (const env of disconnected) {
|
|
34
|
-
const state = reconnectStates.get(env.id);
|
|
35
|
-
// First time seeing this environment disconnected — initialize state with delay
|
|
36
|
-
if (!state) {
|
|
37
|
-
reconnectStates.set(env.id, {
|
|
38
|
-
attempts: 0,
|
|
39
|
-
nextRetryAt: Date.now() + RECONNECT_INITIAL_DELAY_MS,
|
|
40
|
-
});
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
// Backoff not elapsed yet
|
|
44
|
-
if (Date.now() < state.nextRetryAt) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
// Max retries exhausted
|
|
48
|
-
if (state.attempts >= RECONNECT_MAX_RETRIES) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
// Already reconnecting
|
|
52
|
-
if (reconnecting.has(env.id)) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
// Attempt reconnect (fire-and-forget)
|
|
56
|
-
tryReconnect(env.id).catch((err) => {
|
|
57
|
-
logger.error({ environmentId: env.id, err }, "Unhandled error during auto-reconnect");
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
// Clean up state for environments that are no longer disconnected
|
|
61
|
-
for (const [envId] of reconnectStates) {
|
|
62
|
-
const env = environments.find((e) => e.id === envId);
|
|
63
|
-
if (env?.status !== "disconnected") {
|
|
64
|
-
reconnectStates.delete(envId);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Clear reconnect state for an environment. Call when the environment is
|
|
70
|
-
* manually provisioned, removed, or otherwise taken out of the reconnect cycle.
|
|
71
|
-
*/
|
|
72
|
-
export function clearReconnectState(environmentId) {
|
|
73
|
-
reconnectStates.delete(environmentId);
|
|
74
|
-
// Note: does not cancel an in-flight tryReconnect — the lock will
|
|
75
|
-
// prevent a new attempt from starting, and the in-flight one will
|
|
76
|
-
// complete or fail on its own.
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Reset reconnect state so the environment is immediately eligible on the
|
|
80
|
-
* next heartbeat tick. Unlike {@link clearReconnectState} (which deletes state,
|
|
81
|
-
* causing the next tick to re-initialize with an initial delay), this sets
|
|
82
|
-
* attempts to zero and nextRetryAt to now.
|
|
83
|
-
*/
|
|
84
|
-
export function resetReconnectState(environmentId) {
|
|
85
|
-
reconnectStates.set(environmentId, { attempts: 0, nextRetryAt: Date.now() });
|
|
86
|
-
}
|
|
87
|
-
/** @internal Reset all reconnect state for testing. */
|
|
88
|
-
export function _resetForTesting() {
|
|
89
|
-
reconnectStates.clear();
|
|
90
|
-
reconnecting.clear();
|
|
91
|
-
}
|
|
92
|
-
// ─── Internal ───────────────────────────────────────────────
|
|
93
|
-
/**
|
|
94
|
-
* Attempt to reconnect a single disconnected environment.
|
|
95
|
-
* Uses the existing `reconnectOrProvision` flow from adapter-sdk.
|
|
96
|
-
*/
|
|
97
|
-
async function tryReconnect(environmentId) {
|
|
98
|
-
reconnecting.add(environmentId);
|
|
99
|
-
try {
|
|
100
|
-
// Re-fetch environment in case it was removed while waiting
|
|
101
|
-
const env = envRegistry.getEnvironment(environmentId);
|
|
102
|
-
if (!env) {
|
|
103
|
-
reconnectStates.delete(environmentId);
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const adapter = adapterManager.getAdapter(env.adapterType);
|
|
107
|
-
if (!adapter) {
|
|
108
|
-
logger.warn({ environmentId, adapterType: env.adapterType }, "No adapter registered — skipping reconnect");
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
logger.info({ environmentId, adapterType: env.adapterType }, "Attempting auto-reconnect");
|
|
112
|
-
envRegistry.updateEnvironmentStatus(environmentId, "connecting");
|
|
113
|
-
emit("environment.changed", {});
|
|
114
|
-
const config = parseAdapterConfig(env.adapterConfig);
|
|
115
|
-
config.defaultRuntime = env.defaultRuntime;
|
|
116
|
-
const powerlineToken = env.powerlineToken;
|
|
117
|
-
// Run reconnectOrProvision — tries fast reconnect if supported, falls back to provision
|
|
118
|
-
for await (const event of reconnectOrProvision(environmentId, adapter, config, powerlineToken, !!env.bootstrapped)) {
|
|
119
|
-
logger.debug({ environmentId, stage: event.stage, message: event.message }, "Reconnect progress");
|
|
120
|
-
}
|
|
121
|
-
// Establish gRPC connection
|
|
122
|
-
const conn = await adapter.connect(environmentId, config, powerlineToken);
|
|
123
|
-
adapterManager.setConnection(environmentId, conn);
|
|
124
|
-
// Push tokens (local environments exclude file tokens)
|
|
125
|
-
if (env.adapterType === "local") {
|
|
126
|
-
await tokenPush.pushToEnv(environmentId, { excludeFileTokens: true });
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
await tokenPush.pushToEnv(environmentId);
|
|
130
|
-
}
|
|
131
|
-
envRegistry.updateEnvironmentStatus(environmentId, "connected");
|
|
132
|
-
envRegistry.markBootstrapped(environmentId);
|
|
133
|
-
emit("environment.changed", {});
|
|
134
|
-
// Auto-recover suspended sessions (fire-and-forget)
|
|
135
|
-
recoverSuspendedSessions(environmentId, conn).catch((err) => {
|
|
136
|
-
logger.error({ environmentId, err }, "Session recovery failed after auto-reconnect");
|
|
137
|
-
});
|
|
138
|
-
logger.info({ environmentId }, "Auto-reconnect successful");
|
|
139
|
-
reconnectStates.delete(environmentId);
|
|
140
|
-
}
|
|
141
|
-
catch (err) {
|
|
142
|
-
// Clean up any partially-established connection to avoid leaking state
|
|
143
|
-
adapterManager.removeConnection(environmentId);
|
|
144
|
-
const state = reconnectStates.get(environmentId) ?? { attempts: 0, nextRetryAt: 0 };
|
|
145
|
-
state.attempts++;
|
|
146
|
-
if (state.attempts >= RECONNECT_MAX_RETRIES) {
|
|
147
|
-
logger.error({ environmentId, attempts: state.attempts, err }, "Auto-reconnect exhausted all retries — giving up");
|
|
148
|
-
envRegistry.updateEnvironmentStatus(environmentId, "error");
|
|
149
|
-
emit("environment.changed", {});
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
const delay = Math.min(RECONNECT_INITIAL_DELAY_MS * Math.pow(RECONNECT_BACKOFF_MULTIPLIER, state.attempts), RECONNECT_MAX_DELAY_MS);
|
|
153
|
-
state.nextRetryAt = Date.now() + delay;
|
|
154
|
-
reconnectStates.set(environmentId, state);
|
|
155
|
-
logger.info({ environmentId, attempts: state.attempts, nextRetryInMs: delay, err }, "Auto-reconnect failed — will retry");
|
|
156
|
-
envRegistry.updateEnvironmentStatus(environmentId, "disconnected");
|
|
157
|
-
emit("environment.changed", {});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
finally {
|
|
161
|
-
reconnecting.delete(environmentId);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
//# sourceMappingURL=auto-reconnect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-reconnect.js","sourceRoot":"","sources":["../src/auto-reconnect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,+DAA+D;AAE/D,mEAAmE;AACnE,MAAM,0BAA0B,GAAW,MAAM,CAAC;AAElD,6DAA6D;AAC7D,MAAM,qBAAqB,GAAW,CAAC,CAAC;AAExC,+DAA+D;AAC/D,MAAM,sBAAsB,GAAW,OAAO,CAAC;AAE/C,0CAA0C;AAC1C,MAAM,4BAA4B,GAAW,CAAC,CAAC;AAY/C,sDAAsD;AACtD,MAAM,eAAe,GAAgC,IAAI,GAAG,EAA0B,CAAC;AAEvF,uEAAuE;AACvE,MAAM,YAAY,GAAgB,IAAI,GAAG,EAAU,CAAC;AAEpD,+DAA+D;AAE/D;;;;;;GAMG;AACH,MAAM,CAAC,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AAG,KAAK,CAAC;YACvC,eAAe,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YAE1C,MAAM,CAAC,IAAI,CACT,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,EAAE,EACtE,oCAAoC,CACrC,CAAC;YACF,WAAW,CAAC,uBAAuB,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;YACnE,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IACrC,CAAC;AACH,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { SessionRow } from "@grackle-ai/database";
|
|
2
|
-
/** Result of computing a task's effective status from its session history. */
|
|
3
|
-
export interface TaskStatusResult {
|
|
4
|
-
/** The computed effective status string (e.g. "working", "paused", "not_started"). */
|
|
5
|
-
status: string;
|
|
6
|
-
/** The ID of the most recent session (by startedAt), or empty string if none. */
|
|
7
|
-
latestSessionId: string;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Compute the effective task status from the stored DB status and the task's
|
|
11
|
-
* session history. Pure function — no DB access, no side effects.
|
|
12
|
-
*
|
|
13
|
-
* Rules:
|
|
14
|
-
* 1. "complete" is sticky — once a human marks done, always returned as-is.
|
|
15
|
-
* 2. "failed" is sticky when no sessions exist (preserves human-set failure).
|
|
16
|
-
* With active sessions, active status takes precedence.
|
|
17
|
-
* 3. No sessions → "not_started" (clamp any stale transient status).
|
|
18
|
-
* 4. Any active session (pending/running/idle):
|
|
19
|
-
* - Any "idle" → "paused"
|
|
20
|
-
* - Otherwise → "working"
|
|
21
|
-
* 5. All sessions terminal → "paused" (work was done, now stopped)
|
|
22
|
-
*
|
|
23
|
-
* @param storedStatus - The task's status as stored in the DB.
|
|
24
|
-
* @param sessions - All sessions for this task, in any order.
|
|
25
|
-
* @returns Computed status and the ID of the latest session.
|
|
26
|
-
*/
|
|
27
|
-
export declare function computeTaskStatus(storedStatus: string, sessions: Pick<SessionRow, "id" | "status" | "startedAt">[]): TaskStatusResult;
|
|
28
|
-
//# sourceMappingURL=compute-task-status.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute-task-status.d.ts","sourceRoot":"","sources":["../src/compute-task-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,8EAA8E;AAC9E,MAAM,WAAW,gBAAgB;IAC/B,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,eAAe,EAAE,MAAM,CAAC;CACzB;AASD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,QAAQ,GAAG,WAAW,CAAC,EAAE,GAC1D,gBAAgB,CAsClB"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { SESSION_STATUS, TASK_STATUS } from "@grackle-ai/common";
|
|
2
|
-
/** Session statuses that indicate the session is actively running. */
|
|
3
|
-
const ACTIVE_SESSION_STATUSES = new Set([
|
|
4
|
-
SESSION_STATUS.PENDING,
|
|
5
|
-
SESSION_STATUS.RUNNING,
|
|
6
|
-
SESSION_STATUS.IDLE,
|
|
7
|
-
]);
|
|
8
|
-
/**
|
|
9
|
-
* Compute the effective task status from the stored DB status and the task's
|
|
10
|
-
* session history. Pure function — no DB access, no side effects.
|
|
11
|
-
*
|
|
12
|
-
* Rules:
|
|
13
|
-
* 1. "complete" is sticky — once a human marks done, always returned as-is.
|
|
14
|
-
* 2. "failed" is sticky when no sessions exist (preserves human-set failure).
|
|
15
|
-
* With active sessions, active status takes precedence.
|
|
16
|
-
* 3. No sessions → "not_started" (clamp any stale transient status).
|
|
17
|
-
* 4. Any active session (pending/running/idle):
|
|
18
|
-
* - Any "idle" → "paused"
|
|
19
|
-
* - Otherwise → "working"
|
|
20
|
-
* 5. All sessions terminal → "paused" (work was done, now stopped)
|
|
21
|
-
*
|
|
22
|
-
* @param storedStatus - The task's status as stored in the DB.
|
|
23
|
-
* @param sessions - All sessions for this task, in any order.
|
|
24
|
-
* @returns Computed status and the ID of the latest session.
|
|
25
|
-
*/
|
|
26
|
-
export function computeTaskStatus(storedStatus, sessions) {
|
|
27
|
-
// "complete" and "failed" are sticky — human-authoritative when no sessions contradict
|
|
28
|
-
if (storedStatus === TASK_STATUS.COMPLETE || storedStatus === TASK_STATUS.FAILED) {
|
|
29
|
-
const latestSessionId = sessions.length > 0
|
|
30
|
-
? getLatestSession(sessions).id
|
|
31
|
-
: "";
|
|
32
|
-
// If there are active sessions, they take precedence over failed (but not complete)
|
|
33
|
-
if (storedStatus === TASK_STATUS.COMPLETE) {
|
|
34
|
-
return { status: TASK_STATUS.COMPLETE, latestSessionId };
|
|
35
|
-
}
|
|
36
|
-
// For "failed" without sessions, keep it; with active sessions, fall through
|
|
37
|
-
if (sessions.length === 0) {
|
|
38
|
-
return { status: TASK_STATUS.FAILED, latestSessionId: "" };
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// No sessions → not_started (clamp any stale transient status)
|
|
42
|
-
if (sessions.length === 0) {
|
|
43
|
-
return { status: TASK_STATUS.NOT_STARTED, latestSessionId: "" };
|
|
44
|
-
}
|
|
45
|
-
// Check for any active sessions
|
|
46
|
-
const activeSessions = sessions.filter((s) => ACTIVE_SESSION_STATUSES.has(s.status));
|
|
47
|
-
if (activeSessions.length > 0) {
|
|
48
|
-
const hasIdle = activeSessions.some((s) => s.status === SESSION_STATUS.IDLE);
|
|
49
|
-
return {
|
|
50
|
-
status: hasIdle ? TASK_STATUS.PAUSED : TASK_STATUS.WORKING,
|
|
51
|
-
latestSessionId: getLatestSession(sessions).id,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
// All sessions are terminal — task is paused (work was done, now stopped)
|
|
55
|
-
const latest = getLatestSession(sessions);
|
|
56
|
-
return { status: TASK_STATUS.PAUSED, latestSessionId: latest.id };
|
|
57
|
-
}
|
|
58
|
-
/** Get the most recent session by startedAt (descending), breaking ties by ID. */
|
|
59
|
-
function getLatestSession(sessions) {
|
|
60
|
-
return sessions.reduce((latest, current) => {
|
|
61
|
-
if (current.startedAt > latest.startedAt) {
|
|
62
|
-
return current;
|
|
63
|
-
}
|
|
64
|
-
if (current.startedAt === latest.startedAt && current.id > latest.id) {
|
|
65
|
-
return current;
|
|
66
|
-
}
|
|
67
|
-
return latest;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=compute-task-status.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compute-task-status.js","sourceRoot":"","sources":["../src/compute-task-status.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAUjE,sEAAsE;AACtE,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IAC3D,cAAc,CAAC,OAAO;IACtB,cAAc,CAAC,OAAO;IACtB,cAAc,CAAC,IAAI;CACpB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,YAAoB,EACpB,QAA2D;IAE3D,uFAAuF;IACvF,IAAI,YAAY,KAAK,WAAW,CAAC,QAAQ,IAAI,YAAY,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;QACjF,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC;YACzC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EAAE;YAC/B,CAAC,CAAC,EAAE,CAAC;QACP,oFAAoF;QACpF,IAAI,YAAY,KAAK,WAAW,CAAC,QAAQ,EAAE,CAAC;YAC1C,OAAO,EAAE,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AAE,OAAO,EAAE,EAAE;QACzC,IAAI,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;YACzC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,IAAI,OAAO,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,EAAE,CAAC;YACrE,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { powerline } from "@grackle-ai/common";
|
|
2
|
-
import { type DatabaseInstance } from "@grackle-ai/database";
|
|
3
|
-
/**
|
|
4
|
-
* Build a token bundle containing enabled provider credentials.
|
|
5
|
-
* When `runtime` is a known {@link RuntimeName}, only providers mapped to that runtime are included.
|
|
6
|
-
* When `runtime` is omitted, all enabled providers are included.
|
|
7
|
-
* When `runtime` is provided but not a recognized {@link RuntimeName}, no providers are included
|
|
8
|
-
* (fails safe rather than exposing all credentials for an unrecognized runtime).
|
|
9
|
-
* Reads values fresh from `process.env` or disk at call time.
|
|
10
|
-
*/
|
|
11
|
-
export declare function buildProviderTokenBundle(runtime?: string, database?: DatabaseInstance): powerline.TokenBundle;
|
|
12
|
-
//# sourceMappingURL=credential-bundle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credential-bundle.d.ts","sourceRoot":"","sources":["../src/credential-bundle.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,SAAS,EAAoB,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAsD,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAejH;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,WAAW,CA0K7G"}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds token bundles from enabled credential providers by reading
|
|
3
|
-
* `process.env` and credential files from disk.
|
|
4
|
-
*
|
|
5
|
-
* Separated from {@link ./credential-providers.ts} (persistence layer) and
|
|
6
|
-
* {@link ./token-push.ts} (network orchestration) to keep each module
|
|
7
|
-
* focused on a single concern.
|
|
8
|
-
*/
|
|
9
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
10
|
-
import { homedir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { create } from "@bufbuild/protobuf";
|
|
13
|
-
import { powerline } from "@grackle-ai/common";
|
|
14
|
-
import { credentialProviders } from "@grackle-ai/database";
|
|
15
|
-
/** Maps each runtime to the credential providers it needs. */
|
|
16
|
-
const RUNTIME_PROVIDERS = {
|
|
17
|
-
"claude-code": ["claude", "github"],
|
|
18
|
-
"copilot": ["copilot", "github"],
|
|
19
|
-
"codex": ["codex", "github"],
|
|
20
|
-
"goose": ["goose", "github"],
|
|
21
|
-
"stub": [],
|
|
22
|
-
// ACP runtimes (experimental) — auth via ACP authenticate method, not credential files
|
|
23
|
-
"claude-code-acp": ["claude", "github"],
|
|
24
|
-
"codex-acp": ["codex", "github"],
|
|
25
|
-
"copilot-acp": ["copilot", "github"],
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Build a token bundle containing enabled provider credentials.
|
|
29
|
-
* When `runtime` is a known {@link RuntimeName}, only providers mapped to that runtime are included.
|
|
30
|
-
* When `runtime` is omitted, all enabled providers are included.
|
|
31
|
-
* When `runtime` is provided but not a recognized {@link RuntimeName}, no providers are included
|
|
32
|
-
* (fails safe rather than exposing all credentials for an unrecognized runtime).
|
|
33
|
-
* Reads values fresh from `process.env` or disk at call time.
|
|
34
|
-
*/
|
|
35
|
-
export function buildProviderTokenBundle(runtime, database) {
|
|
36
|
-
const config = credentialProviders.getCredentialProviders(database);
|
|
37
|
-
// When runtime is given, look it up in the map. Unknown runtimes get [] (empty, not all providers).
|
|
38
|
-
const runtimeProviders = runtime !== undefined
|
|
39
|
-
? (Object.hasOwn(RUNTIME_PROVIDERS, runtime) ? RUNTIME_PROVIDERS[runtime] : [])
|
|
40
|
-
: undefined;
|
|
41
|
-
const allowedProviders = runtimeProviders !== undefined
|
|
42
|
-
? new Set(runtimeProviders)
|
|
43
|
-
: undefined;
|
|
44
|
-
const items = [];
|
|
45
|
-
// Claude provider
|
|
46
|
-
if ((!allowedProviders || allowedProviders.has("claude")) && config.claude === "subscription") {
|
|
47
|
-
const credentialsPath = join(homedir(), ".claude", ".credentials.json");
|
|
48
|
-
if (existsSync(credentialsPath)) {
|
|
49
|
-
const value = readFileSync(credentialsPath, "utf-8");
|
|
50
|
-
if (value.trim()) {
|
|
51
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
52
|
-
name: "claude-credentials",
|
|
53
|
-
type: "file",
|
|
54
|
-
filePath: "~/.claude/.credentials.json",
|
|
55
|
-
value,
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else if ((!allowedProviders || allowedProviders.has("claude")) && config.claude === "api_key") {
|
|
61
|
-
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
62
|
-
if (apiKey) {
|
|
63
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
64
|
-
name: "anthropic-api-key",
|
|
65
|
-
type: "env_var",
|
|
66
|
-
envVar: "ANTHROPIC_API_KEY",
|
|
67
|
-
value: apiKey,
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// GitHub provider
|
|
72
|
-
if ((!allowedProviders || allowedProviders.has("github")) && config.github === "on") {
|
|
73
|
-
for (const varName of ["GITHUB_TOKEN", "GH_TOKEN"]) {
|
|
74
|
-
const value = process.env[varName];
|
|
75
|
-
if (value) {
|
|
76
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
77
|
-
name: varName.toLowerCase().replace(/_/g, "-"),
|
|
78
|
-
type: "env_var",
|
|
79
|
-
envVar: varName,
|
|
80
|
-
value,
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Copilot provider — push the config file so the SDK's useLoggedInUser path works.
|
|
86
|
-
// Also forward env vars for explicit token / BYOK scenarios.
|
|
87
|
-
if ((!allowedProviders || allowedProviders.has("copilot")) && config.copilot === "on") {
|
|
88
|
-
const copilotConfigPath = join(homedir(), ".copilot", "config.json");
|
|
89
|
-
if (existsSync(copilotConfigPath)) {
|
|
90
|
-
const value = readFileSync(copilotConfigPath, "utf-8");
|
|
91
|
-
if (value.trim()) {
|
|
92
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
93
|
-
name: "copilot-config",
|
|
94
|
-
type: "file",
|
|
95
|
-
filePath: "~/.copilot/config.json",
|
|
96
|
-
value,
|
|
97
|
-
}));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
for (const varName of [
|
|
101
|
-
"COPILOT_GITHUB_TOKEN",
|
|
102
|
-
"COPILOT_CLI_URL",
|
|
103
|
-
"COPILOT_CLI_PATH",
|
|
104
|
-
"COPILOT_PROVIDER_CONFIG",
|
|
105
|
-
]) {
|
|
106
|
-
const value = process.env[varName];
|
|
107
|
-
if (value) {
|
|
108
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
109
|
-
name: varName.toLowerCase().replace(/_/g, "-"),
|
|
110
|
-
type: "env_var",
|
|
111
|
-
envVar: varName,
|
|
112
|
-
value,
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Codex provider — push the auth file so the SDK's ChatGPT auth path works.
|
|
118
|
-
// Also forward OPENAI_API_KEY env var for API-key scenarios.
|
|
119
|
-
if ((!allowedProviders || allowedProviders.has("codex")) && config.codex === "on") {
|
|
120
|
-
const codexAuthPath = join(homedir(), ".codex", "auth.json");
|
|
121
|
-
if (existsSync(codexAuthPath)) {
|
|
122
|
-
const value = readFileSync(codexAuthPath, "utf-8");
|
|
123
|
-
if (value.trim()) {
|
|
124
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
125
|
-
name: "codex-auth",
|
|
126
|
-
type: "file",
|
|
127
|
-
filePath: "~/.codex/auth.json",
|
|
128
|
-
value,
|
|
129
|
-
}));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
const openaiKey = process.env.OPENAI_API_KEY;
|
|
133
|
-
if (openaiKey) {
|
|
134
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
135
|
-
name: "openai-api-key",
|
|
136
|
-
type: "env_var",
|
|
137
|
-
envVar: "OPENAI_API_KEY",
|
|
138
|
-
value: openaiKey,
|
|
139
|
-
}));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// Goose provider — forward config file and provider-related env vars.
|
|
143
|
-
// Goose is provider-agnostic so we forward whichever API keys are available.
|
|
144
|
-
if ((!allowedProviders || allowedProviders.has("goose")) && config.goose === "on") {
|
|
145
|
-
const isWindows = process.platform === "win32";
|
|
146
|
-
const gooseConfigPath = isWindows
|
|
147
|
-
? join(process.env.APPDATA || join(homedir(), "AppData", "Roaming"), "Block", "goose", "config", "config.yaml")
|
|
148
|
-
: join(homedir(), ".config", "goose", "config.yaml");
|
|
149
|
-
const gooseConfigFilePath = isWindows
|
|
150
|
-
? "%APPDATA%/Block/goose/config/config.yaml"
|
|
151
|
-
: "~/.config/goose/config.yaml";
|
|
152
|
-
if (existsSync(gooseConfigPath)) {
|
|
153
|
-
const value = readFileSync(gooseConfigPath, "utf-8");
|
|
154
|
-
if (value.trim()) {
|
|
155
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
156
|
-
name: "goose-config",
|
|
157
|
-
type: "file",
|
|
158
|
-
filePath: gooseConfigFilePath,
|
|
159
|
-
value,
|
|
160
|
-
}));
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
for (const varName of [
|
|
164
|
-
"GOOSE_PROVIDER",
|
|
165
|
-
"GOOSE_MODEL",
|
|
166
|
-
"ANTHROPIC_API_KEY",
|
|
167
|
-
"OPENAI_API_KEY",
|
|
168
|
-
"GOOGLE_API_KEY",
|
|
169
|
-
]) {
|
|
170
|
-
const value = process.env[varName];
|
|
171
|
-
if (value) {
|
|
172
|
-
items.push(create(powerline.TokenItemSchema, {
|
|
173
|
-
name: varName.toLowerCase().replace(/_/g, "-"),
|
|
174
|
-
type: "env_var",
|
|
175
|
-
envVar: varName,
|
|
176
|
-
value,
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return create(powerline.TokenBundleSchema, { tokens: items });
|
|
182
|
-
}
|
|
183
|
-
//# sourceMappingURL=credential-bundle.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"credential-bundle.js","sourceRoot":"","sources":["../src/credential-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAoB,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAwD,MAAM,sBAAsB,CAAC;AAEjH,8DAA8D;AAC9D,MAAM,iBAAiB,GAAuD;IAC5E,aAAa,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACnC,SAAS,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;IAChC,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC5B,OAAO,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC5B,MAAM,EAAE,EAAE;IACV,uFAAuF;IACvF,iBAAiB,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;IACvC,WAAW,EA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,CAAC,eAAe,CAAC,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,YAAY,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACrD,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;gBACjB,KAAK,CAAC,IAAI,CACR,MAAM,CAAC,SAAS,CAAC,eAAe,EAAE;oBAChC,IAAI,EAAE,cAAc;oBACpB,IAAI,EAAE,MAAM;oBACZ,QAAQ,EAAE,mBAAmB;oBAC7B,KAAK;iBACN,CAAC,CACH,CAAC;YACJ,CAAC;QACH,CAAC;QACD,KAAK,MAAM,OAAO,IAAI;YACpB,gBAAgB;YAChB,aAAa;YACb,mBAAmB;YACnB,gBAAgB;YAChB,gBAAgB;SACjB,EAAE,CAAC;YACF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACnC,IAAI,KAAK,EAAE,CAAC;gBACV,KAAK,CAAC,IAAI,CACR,MAAM,CAAC,SAAS,CAAC,eAAe,EAAE;oBAChC,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC;oBAC9C,IAAI,EAAE,SAAS;oBACf,MAAM,EAAE,OAAO;oBACf,KAAK;iBACN,CAAC,CACH,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/event-bus.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/** All domain event types emitted by the event bus. */
|
|
2
|
-
export type GrackleEventType = "task.created" | "task.updated" | "task.started" | "task.completed" | "task.deleted" | "workspace.created" | "workspace.archived" | "workspace.updated" | "persona.created" | "persona.updated" | "persona.deleted" | "finding.posted" | "environment.added" | "environment.removed" | "environment.changed" | "environment.provision_progress" | "token.changed" | "credential.providers_changed" | "setting.changed";
|
|
3
|
-
/** A domain event emitted by the event bus. */
|
|
4
|
-
export interface GrackleEvent {
|
|
5
|
-
/** ULID — chronologically sortable unique identifier. */
|
|
6
|
-
id: string;
|
|
7
|
-
/** Dot-notation event type (e.g. "task.created"). */
|
|
8
|
-
type: GrackleEventType;
|
|
9
|
-
/** ISO 8601 timestamp. */
|
|
10
|
-
timestamp: string;
|
|
11
|
-
/** Domain-specific payload. */
|
|
12
|
-
payload: Record<string, unknown>;
|
|
13
|
-
}
|
|
14
|
-
/** Callback signature for event subscribers. */
|
|
15
|
-
export type Subscriber = (event: GrackleEvent) => void;
|
|
16
|
-
/**
|
|
17
|
-
* Emit a domain event. Persists to SQLite synchronously, then
|
|
18
|
-
* fans out to all subscribers asynchronously via queueMicrotask.
|
|
19
|
-
*
|
|
20
|
-
* @param type - The dot-notation event type.
|
|
21
|
-
* @param payload - Domain-specific data.
|
|
22
|
-
* @returns The created GrackleEvent.
|
|
23
|
-
*/
|
|
24
|
-
export declare function emit(type: GrackleEventType, payload: Record<string, unknown>): GrackleEvent;
|
|
25
|
-
/**
|
|
26
|
-
* Register a subscriber to receive all domain events.
|
|
27
|
-
*
|
|
28
|
-
* @param subscriber - Callback invoked for each emitted event.
|
|
29
|
-
* @returns An unsubscribe function.
|
|
30
|
-
*/
|
|
31
|
-
export declare function subscribe(subscriber: Subscriber): () => void;
|
|
32
|
-
/**
|
|
33
|
-
* Reset all subscribers. For use in tests only.
|
|
34
|
-
* @internal
|
|
35
|
-
*/
|
|
36
|
-
export declare function _resetForTesting(): void;
|
|
37
|
-
//# sourceMappingURL=event-bus.d.ts.map
|
package/dist/event-bus.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.d.ts","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAMA,uDAAuD;AACvD,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,cAAc,GACd,cAAc,GACd,gBAAgB,GAChB,cAAc,GACd,mBAAmB,GACnB,oBAAoB,GACpB,mBAAmB,GACnB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,gBAAgB,GAChB,mBAAmB,GACnB,qBAAqB,GACrB,qBAAqB,GACrB,gCAAgC,GAChC,eAAe,GACf,8BAA8B,GAC9B,iBAAiB,CAAC;AAEtB,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,qDAAqD;IACrD,IAAI,EAAE,gBAAgB,CAAC;IACvB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,gDAAgD;AAChD,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAQvD;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAClB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,YAAY,CA+Bd;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,IAAI,CAK5D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC"}
|
package/dist/event-bus.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { ulid } from "ulid";
|
|
2
|
-
import { persistEvent } from "@grackle-ai/database";
|
|
3
|
-
import { logger } from "./logger.js";
|
|
4
|
-
// ─── Module State ─────────────────────────────────────────
|
|
5
|
-
const subscribers = new Set();
|
|
6
|
-
// ─── Public API ───────────────────────────────────────────
|
|
7
|
-
/**
|
|
8
|
-
* Emit a domain event. Persists to SQLite synchronously, then
|
|
9
|
-
* fans out to all subscribers asynchronously via queueMicrotask.
|
|
10
|
-
*
|
|
11
|
-
* @param type - The dot-notation event type.
|
|
12
|
-
* @param payload - Domain-specific data.
|
|
13
|
-
* @returns The created GrackleEvent.
|
|
14
|
-
*/
|
|
15
|
-
export function emit(type, payload) {
|
|
16
|
-
const event = {
|
|
17
|
-
id: ulid(),
|
|
18
|
-
type,
|
|
19
|
-
timestamp: new Date().toISOString(),
|
|
20
|
-
payload,
|
|
21
|
-
};
|
|
22
|
-
// Persist synchronously (SQLite is fast in WAL mode).
|
|
23
|
-
// Intentionally non-fatal: a persistence failure is logged but does not
|
|
24
|
-
// prevent subscribers from receiving the event. Domain events drive live
|
|
25
|
-
// UI updates which must not break if SQLite is temporarily unavailable.
|
|
26
|
-
// Replay/audit consumers should monitor logs for persistence errors.
|
|
27
|
-
try {
|
|
28
|
-
persistEvent(event);
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
logger.error({ err, event }, "Failed to persist domain event");
|
|
32
|
-
}
|
|
33
|
-
// Fan out asynchronously — subscriber errors never block the emitter
|
|
34
|
-
queueMicrotask(() => {
|
|
35
|
-
for (const subscriber of subscribers) {
|
|
36
|
-
try {
|
|
37
|
-
subscriber(event);
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
logger.error({ err, eventType: event.type }, "Subscriber error");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
return event;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Register a subscriber to receive all domain events.
|
|
48
|
-
*
|
|
49
|
-
* @param subscriber - Callback invoked for each emitted event.
|
|
50
|
-
* @returns An unsubscribe function.
|
|
51
|
-
*/
|
|
52
|
-
export function subscribe(subscriber) {
|
|
53
|
-
subscribers.add(subscriber);
|
|
54
|
-
return () => {
|
|
55
|
-
subscribers.delete(subscriber);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Reset all subscribers. For use in tests only.
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
|
-
export function _resetForTesting() {
|
|
63
|
-
subscribers.clear();
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=event-bus.js.map
|
package/dist/event-bus.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAyCrC,6DAA6D;AAE7D,MAAM,WAAW,GAAoB,IAAI,GAAG,EAAE,CAAC;AAE/C,6DAA6D;AAE7D;;;;;;;GAOG;AACH,MAAM,UAAU,IAAI,CAClB,IAAsB,EACtB,OAAgC;IAEhC,MAAM,KAAK,GAAiB;QAC1B,EAAE,EAAE,IAAI,EAAE;QACV,IAAI;QACJ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,OAAO;KACR,CAAC;IAEF,sDAAsD;IACtD,wEAAwE;IACxE,yEAAyE;IACzE,wEAAwE;IACxE,qEAAqE;IACrE,IAAI,CAAC;QACH,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,gCAAgC,CAAC,CAAC;IACjE,CAAC;IAED,qEAAqE;IACrE,cAAc,CAAC,GAAG,EAAE;QAClB,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,UAAU,CAAC,KAAK,CAAC,CAAC;YACpB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE,kBAAkB,CAAC,CAAC;YACnE,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,UAAsB;IAC9C,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC5B,OAAO,GAAG,EAAE;QACV,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,WAAW,CAAC,KAAK,EAAE,CAAC;AACtB,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { powerline } from "@grackle-ai/common";
|
|
2
|
-
import type { ProcessorContext } from "./processor-registry.js";
|
|
3
|
-
/** Options for processing an agent event stream. */
|
|
4
|
-
export interface EventStreamOptions {
|
|
5
|
-
sessionId: string;
|
|
6
|
-
logPath: string;
|
|
7
|
-
workspaceId?: string;
|
|
8
|
-
taskId?: string;
|
|
9
|
-
/** System context injected into the agent session. Emitted as the first event in the stream. */
|
|
10
|
-
systemContext?: string;
|
|
11
|
-
/** Initial user prompt sent to the agent. Emitted as a user_input event after systemContext. */
|
|
12
|
-
prompt?: string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Process a finding event, storing it in the finding store and broadcasting.
|
|
16
|
-
* Shared between live event processing and replay on late-bind.
|
|
17
|
-
*/
|
|
18
|
-
export declare function processFindingEvent(ctx: ProcessorContext, content: string, sessionId: string): void;
|
|
19
|
-
/**
|
|
20
|
-
* Process a subtask creation event, creating a child task and broadcasting.
|
|
21
|
-
* Shared between live event processing and replay on late-bind.
|
|
22
|
-
*/
|
|
23
|
-
export declare function processSubtaskEvent(ctx: ProcessorContext, content: string, subtaskLocalIdMap: Map<string, string>): void;
|
|
24
|
-
/**
|
|
25
|
-
* Process an async iterable of agent events from a PowerLine spawn or resume stream.
|
|
26
|
-
* Handles event transformation, logging, finding interception, status updates, and cleanup.
|
|
27
|
-
*
|
|
28
|
-
* This function is fire-and-forget: it runs in the background and does not throw.
|
|
29
|
-
* Callers should use `onComplete` callback for post-processing.
|
|
30
|
-
*
|
|
31
|
-
* Supports late-binding: if a task is associated with the session after the stream starts,
|
|
32
|
-
* the processor registry notifies this function via a bind listener, and pre-association
|
|
33
|
-
* events are replayed from the session log.
|
|
34
|
-
*/
|
|
35
|
-
export declare function processEventStream(events: AsyncIterable<powerline.AgentEvent>, options: EventStreamOptions): void;
|
|
36
|
-
//# sourceMappingURL=event-processor.d.ts.map
|