@useorgx/openclaw-plugin 0.3.2 → 0.4.1
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/dashboard/dist/assets/BqukHQH-.js +8 -0
- package/dashboard/dist/assets/CE5pVdev.js +9 -0
- package/dashboard/dist/assets/Cpr7n8fE.js +1 -0
- package/dashboard/dist/assets/Nip3CrNC.js +1 -0
- package/dashboard/dist/assets/TN5wE36J.js +1 -0
- package/dashboard/dist/assets/X6IcjS74.js +212 -0
- package/dashboard/dist/assets/jyFhCND-.css +1 -0
- package/dashboard/dist/index.html +9 -6
- package/dist/adapters/outbox.d.ts +0 -1
- package/dist/adapters/outbox.js +0 -1
- package/dist/agent-context-store.d.ts +0 -1
- package/dist/agent-context-store.js +0 -1
- package/dist/agent-run-store.d.ts +0 -1
- package/dist/agent-run-store.js +0 -1
- package/dist/api.d.ts +0 -1
- package/dist/api.js +0 -1
- package/dist/auth-store.d.ts +0 -1
- package/dist/auth-store.js +0 -1
- package/dist/byok-store.d.ts +0 -1
- package/dist/byok-store.js +0 -1
- package/dist/contracts/client.d.ts +0 -1
- package/dist/contracts/client.js +0 -1
- package/dist/contracts/types.d.ts +33 -1
- package/dist/contracts/types.js +0 -1
- package/dist/dashboard-api.d.ts +0 -1
- package/dist/dashboard-api.js +0 -1
- package/dist/fs-utils.d.ts +0 -1
- package/dist/fs-utils.js +0 -1
- package/dist/http-handler.d.ts +0 -1
- package/dist/http-handler.js +1331 -111
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/local-openclaw.d.ts +0 -1
- package/dist/local-openclaw.js +0 -1
- package/dist/outbox.d.ts +0 -1
- package/dist/outbox.js +0 -1
- package/dist/paths.d.ts +0 -1
- package/dist/paths.js +0 -1
- package/dist/reporting/outbox-replay.d.ts +0 -1
- package/dist/reporting/outbox-replay.js +0 -1
- package/dist/reporting/rollups.d.ts +0 -1
- package/dist/reporting/rollups.js +0 -1
- package/dist/runtime-instance-store.d.ts +62 -0
- package/dist/runtime-instance-store.js +362 -0
- package/dist/snapshot-store.d.ts +0 -1
- package/dist/snapshot-store.js +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/package.json +2 -2
- package/dashboard/dist/assets/MissionControlView-CthHdl6R.js +0 -1
- package/dashboard/dist/assets/SessionInspector-Dq0Z5WMo.js +0 -1
- package/dashboard/dist/assets/index-CoLgC4zE.js +0 -11
- package/dashboard/dist/assets/index-jfEYE0kO.css +0 -1
- package/dashboard/dist/assets/motion-CVDprFZg.js +0 -9
- package/dashboard/dist/assets/react-vendor-C2t2w4r2.js +0 -32
- package/dashboard/dist/assets/vendor-C-AHK0Ly.js +0 -9
- package/dist/adapters/outbox.d.ts.map +0 -1
- package/dist/adapters/outbox.js.map +0 -1
- package/dist/agent-context-store.d.ts.map +0 -1
- package/dist/agent-context-store.js.map +0 -1
- package/dist/agent-run-store.d.ts.map +0 -1
- package/dist/agent-run-store.js.map +0 -1
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js.map +0 -1
- package/dist/auth-store.d.ts.map +0 -1
- package/dist/auth-store.js.map +0 -1
- package/dist/byok-store.d.ts.map +0 -1
- package/dist/byok-store.js.map +0 -1
- package/dist/contracts/client.d.ts.map +0 -1
- package/dist/contracts/client.js.map +0 -1
- package/dist/contracts/types.d.ts.map +0 -1
- package/dist/contracts/types.js.map +0 -1
- package/dist/dashboard-api.d.ts.map +0 -1
- package/dist/dashboard-api.js.map +0 -1
- package/dist/fs-utils.d.ts.map +0 -1
- package/dist/fs-utils.js.map +0 -1
- package/dist/http-handler.d.ts.map +0 -1
- package/dist/http-handler.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/local-openclaw.d.ts.map +0 -1
- package/dist/local-openclaw.js.map +0 -1
- package/dist/mcp-apps/orgx-live.html +0 -690
- package/dist/outbox.d.ts.map +0 -1
- package/dist/outbox.js.map +0 -1
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/reporting/outbox-replay.d.ts.map +0 -1
- package/dist/reporting/outbox-replay.js.map +0 -1
- package/dist/reporting/rollups.d.ts.map +0 -1
- package/dist/reporting/rollups.js.map +0 -1
- package/dist/snapshot-store.d.ts.map +0 -1
- package/dist/snapshot-store.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- /package/dashboard/dist/assets/{tanstack-C-KIc3Wc.js → C-KIc3Wc.js} +0 -0
- /package/dashboard/dist/assets/{orgx-logo-Fm0FhtnV.png → Fm0FhtnV.png} +0 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/local-openclaw.d.ts
CHANGED
package/dist/local-openclaw.js
CHANGED
package/dist/outbox.d.ts
CHANGED
|
@@ -24,4 +24,3 @@ export declare function replaceOutbox(sessionId: string, events: OutboxEvent[]):
|
|
|
24
24
|
export declare function readAllOutboxItems(): Promise<LiveActivityItem[]>;
|
|
25
25
|
export declare function readOutboxSummary(): Promise<OutboxSummary>;
|
|
26
26
|
export declare function clearOutbox(sessionId: string): Promise<void>;
|
|
27
|
-
//# sourceMappingURL=outbox.d.ts.map
|
package/dist/outbox.js
CHANGED
package/dist/paths.d.ts
CHANGED
package/dist/paths.js
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type RuntimeSourceClient = "openclaw" | "codex" | "claude-code" | "api" | "unknown";
|
|
2
|
+
export type RuntimeInstanceState = "active" | "stale" | "stopped" | "error";
|
|
3
|
+
export type RuntimeHookEvent = "session_start" | "heartbeat" | "progress" | "task_update" | "session_stop" | "error";
|
|
4
|
+
export type RuntimeHookPayload = {
|
|
5
|
+
source_client?: string | null;
|
|
6
|
+
event?: string | null;
|
|
7
|
+
run_id?: string | null;
|
|
8
|
+
correlation_id?: string | null;
|
|
9
|
+
initiative_id?: string | null;
|
|
10
|
+
workstream_id?: string | null;
|
|
11
|
+
task_id?: string | null;
|
|
12
|
+
agent_id?: string | null;
|
|
13
|
+
agent_name?: string | null;
|
|
14
|
+
phase?: string | null;
|
|
15
|
+
progress_pct?: number | null;
|
|
16
|
+
message?: string | null;
|
|
17
|
+
metadata?: Record<string, unknown> | null;
|
|
18
|
+
timestamp?: string | null;
|
|
19
|
+
};
|
|
20
|
+
export type RuntimeInstanceRecord = {
|
|
21
|
+
id: string;
|
|
22
|
+
sourceClient: RuntimeSourceClient;
|
|
23
|
+
displayName: string;
|
|
24
|
+
providerLogo: "openai" | "anthropic" | "openclaw" | "orgx" | "unknown";
|
|
25
|
+
state: RuntimeInstanceState;
|
|
26
|
+
event: RuntimeHookEvent;
|
|
27
|
+
runId: string | null;
|
|
28
|
+
correlationId: string | null;
|
|
29
|
+
initiativeId: string | null;
|
|
30
|
+
workstreamId: string | null;
|
|
31
|
+
taskId: string | null;
|
|
32
|
+
agentId: string | null;
|
|
33
|
+
agentName: string | null;
|
|
34
|
+
phase: string | null;
|
|
35
|
+
progressPct: number | null;
|
|
36
|
+
currentTask: string | null;
|
|
37
|
+
lastHeartbeatAt: string | null;
|
|
38
|
+
lastEventAt: string;
|
|
39
|
+
lastMessage: string | null;
|
|
40
|
+
metadata: Record<string, unknown> | null;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
};
|
|
44
|
+
type PersistedRuntimeInstances = {
|
|
45
|
+
updatedAt: string;
|
|
46
|
+
instances: Record<string, RuntimeInstanceRecord>;
|
|
47
|
+
};
|
|
48
|
+
export declare const DEFAULT_RUNTIME_HEARTBEAT_TIMEOUT_MS = 90000;
|
|
49
|
+
export declare function readRuntimeInstances(): PersistedRuntimeInstances;
|
|
50
|
+
export declare function upsertRuntimeInstanceFromHook(payload: RuntimeHookPayload): RuntimeInstanceRecord;
|
|
51
|
+
export declare function applyRuntimeInstanceStaleness(options?: {
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
nowMs?: number;
|
|
54
|
+
}): PersistedRuntimeInstances;
|
|
55
|
+
export declare function listRuntimeInstances(options?: {
|
|
56
|
+
limit?: number;
|
|
57
|
+
timeoutMs?: number;
|
|
58
|
+
nowMs?: number;
|
|
59
|
+
}): RuntimeInstanceRecord[];
|
|
60
|
+
export declare function clearRuntimeInstances(): void;
|
|
61
|
+
export declare function resolveRuntimeHookToken(): string;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { getOrgxPluginConfigDir, getOrgxPluginConfigPath } from "./paths.js";
|
|
4
|
+
import { backupCorruptFileSync, writeJsonFileAtomicSync } from "./fs-utils.js";
|
|
5
|
+
const MAX_INSTANCES = 600;
|
|
6
|
+
export const DEFAULT_RUNTIME_HEARTBEAT_TIMEOUT_MS = 90_000;
|
|
7
|
+
function runtimeDir() {
|
|
8
|
+
return getOrgxPluginConfigDir();
|
|
9
|
+
}
|
|
10
|
+
function runtimeFile() {
|
|
11
|
+
return getOrgxPluginConfigPath("runtime-instances.json");
|
|
12
|
+
}
|
|
13
|
+
function hookTokenFile() {
|
|
14
|
+
return getOrgxPluginConfigPath("runtime-hook-token.txt");
|
|
15
|
+
}
|
|
16
|
+
function ensureRuntimeDir() {
|
|
17
|
+
const dir = runtimeDir();
|
|
18
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
19
|
+
try {
|
|
20
|
+
chmodSync(dir, 0o700);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
// best effort
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function writeHookTokenFile(token) {
|
|
27
|
+
ensureRuntimeDir();
|
|
28
|
+
const file = hookTokenFile();
|
|
29
|
+
writeFileSync(file, `${token}\n`, { encoding: "utf8", mode: 0o600 });
|
|
30
|
+
try {
|
|
31
|
+
chmodSync(file, 0o600);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// best effort
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function parseJson(value) {
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(value);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function normalizeNullableString(value) {
|
|
46
|
+
if (typeof value !== "string")
|
|
47
|
+
return null;
|
|
48
|
+
const trimmed = value.trim();
|
|
49
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
50
|
+
}
|
|
51
|
+
function normalizeObject(value) {
|
|
52
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
53
|
+
return null;
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
function normalizeSourceClient(value) {
|
|
57
|
+
const normalized = normalizeNullableString(value)?.toLowerCase();
|
|
58
|
+
if (!normalized)
|
|
59
|
+
return "unknown";
|
|
60
|
+
if (normalized === "openclaw")
|
|
61
|
+
return "openclaw";
|
|
62
|
+
if (normalized === "codex")
|
|
63
|
+
return "codex";
|
|
64
|
+
if (normalized === "claude-code")
|
|
65
|
+
return "claude-code";
|
|
66
|
+
if (normalized === "api")
|
|
67
|
+
return "api";
|
|
68
|
+
return "unknown";
|
|
69
|
+
}
|
|
70
|
+
function normalizeHookEvent(value) {
|
|
71
|
+
const normalized = normalizeNullableString(value)?.toLowerCase();
|
|
72
|
+
if (normalized === "session_start")
|
|
73
|
+
return "session_start";
|
|
74
|
+
if (normalized === "heartbeat")
|
|
75
|
+
return "heartbeat";
|
|
76
|
+
if (normalized === "progress")
|
|
77
|
+
return "progress";
|
|
78
|
+
if (normalized === "task_update")
|
|
79
|
+
return "task_update";
|
|
80
|
+
if (normalized === "session_stop")
|
|
81
|
+
return "session_stop";
|
|
82
|
+
if (normalized === "error")
|
|
83
|
+
return "error";
|
|
84
|
+
return "heartbeat";
|
|
85
|
+
}
|
|
86
|
+
function toProviderLogo(sourceClient) {
|
|
87
|
+
if (sourceClient === "codex")
|
|
88
|
+
return "openai";
|
|
89
|
+
if (sourceClient === "claude-code")
|
|
90
|
+
return "anthropic";
|
|
91
|
+
if (sourceClient === "openclaw")
|
|
92
|
+
return "openclaw";
|
|
93
|
+
if (sourceClient === "api")
|
|
94
|
+
return "orgx";
|
|
95
|
+
return "unknown";
|
|
96
|
+
}
|
|
97
|
+
function toDisplayName(sourceClient) {
|
|
98
|
+
if (sourceClient === "codex")
|
|
99
|
+
return "Codex";
|
|
100
|
+
if (sourceClient === "claude-code")
|
|
101
|
+
return "Claude Code";
|
|
102
|
+
if (sourceClient === "openclaw")
|
|
103
|
+
return "OpenClaw";
|
|
104
|
+
if (sourceClient === "api")
|
|
105
|
+
return "OrgX API";
|
|
106
|
+
return "Runtime";
|
|
107
|
+
}
|
|
108
|
+
function normalizeState(value) {
|
|
109
|
+
const normalized = normalizeNullableString(value)?.toLowerCase();
|
|
110
|
+
if (normalized === "active")
|
|
111
|
+
return "active";
|
|
112
|
+
if (normalized === "stale")
|
|
113
|
+
return "stale";
|
|
114
|
+
if (normalized === "stopped")
|
|
115
|
+
return "stopped";
|
|
116
|
+
if (normalized === "error")
|
|
117
|
+
return "error";
|
|
118
|
+
return "active";
|
|
119
|
+
}
|
|
120
|
+
function normalizeIsoTimestamp(value, fallbackIso) {
|
|
121
|
+
const text = normalizeNullableString(value);
|
|
122
|
+
if (!text)
|
|
123
|
+
return fallbackIso;
|
|
124
|
+
const parsed = Date.parse(text);
|
|
125
|
+
if (!Number.isFinite(parsed))
|
|
126
|
+
return fallbackIso;
|
|
127
|
+
return new Date(parsed).toISOString();
|
|
128
|
+
}
|
|
129
|
+
function sanitizeIdPart(value) {
|
|
130
|
+
return value.toLowerCase().replace(/[^a-z0-9:_-]+/g, "-");
|
|
131
|
+
}
|
|
132
|
+
function deriveInstanceId(input) {
|
|
133
|
+
const source = sanitizeIdPart(input.sourceClient);
|
|
134
|
+
const runId = normalizeNullableString(input.runId);
|
|
135
|
+
if (runId)
|
|
136
|
+
return `runtime:${source}:run:${sanitizeIdPart(runId)}`;
|
|
137
|
+
const correlationId = normalizeNullableString(input.correlationId);
|
|
138
|
+
if (correlationId)
|
|
139
|
+
return `runtime:${source}:corr:${sanitizeIdPart(correlationId)}`;
|
|
140
|
+
const agentId = normalizeNullableString(input.agentId);
|
|
141
|
+
const initiativeId = normalizeNullableString(input.initiativeId);
|
|
142
|
+
if (agentId && initiativeId) {
|
|
143
|
+
return `runtime:${source}:agent:${sanitizeIdPart(agentId)}:initiative:${sanitizeIdPart(initiativeId)}`;
|
|
144
|
+
}
|
|
145
|
+
if (agentId)
|
|
146
|
+
return `runtime:${source}:agent:${sanitizeIdPart(agentId)}`;
|
|
147
|
+
return `runtime:${source}:default`;
|
|
148
|
+
}
|
|
149
|
+
function normalizeProgress(value) {
|
|
150
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
151
|
+
return null;
|
|
152
|
+
return Math.max(0, Math.min(100, Math.round(value)));
|
|
153
|
+
}
|
|
154
|
+
function normalizeRecord(input) {
|
|
155
|
+
return {
|
|
156
|
+
id: normalizeNullableString(input.id) ?? input.id,
|
|
157
|
+
sourceClient: normalizeSourceClient(input.sourceClient),
|
|
158
|
+
displayName: normalizeNullableString(input.displayName) ?? "Runtime",
|
|
159
|
+
providerLogo: input.providerLogo,
|
|
160
|
+
state: normalizeState(input.state),
|
|
161
|
+
event: normalizeHookEvent(input.event),
|
|
162
|
+
runId: normalizeNullableString(input.runId),
|
|
163
|
+
correlationId: normalizeNullableString(input.correlationId),
|
|
164
|
+
initiativeId: normalizeNullableString(input.initiativeId),
|
|
165
|
+
workstreamId: normalizeNullableString(input.workstreamId),
|
|
166
|
+
taskId: normalizeNullableString(input.taskId),
|
|
167
|
+
agentId: normalizeNullableString(input.agentId),
|
|
168
|
+
agentName: normalizeNullableString(input.agentName),
|
|
169
|
+
phase: normalizeNullableString(input.phase),
|
|
170
|
+
progressPct: normalizeProgress(input.progressPct),
|
|
171
|
+
currentTask: normalizeNullableString(input.currentTask),
|
|
172
|
+
lastHeartbeatAt: normalizeNullableString(input.lastHeartbeatAt),
|
|
173
|
+
lastEventAt: input.lastEventAt,
|
|
174
|
+
lastMessage: normalizeNullableString(input.lastMessage),
|
|
175
|
+
metadata: normalizeObject(input.metadata),
|
|
176
|
+
createdAt: input.createdAt,
|
|
177
|
+
updatedAt: input.updatedAt,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export function readRuntimeInstances() {
|
|
181
|
+
const file = runtimeFile();
|
|
182
|
+
try {
|
|
183
|
+
if (!existsSync(file)) {
|
|
184
|
+
return { updatedAt: new Date().toISOString(), instances: {} };
|
|
185
|
+
}
|
|
186
|
+
const raw = readFileSync(file, "utf8");
|
|
187
|
+
const parsed = parseJson(raw);
|
|
188
|
+
if (!parsed || typeof parsed !== "object") {
|
|
189
|
+
backupCorruptFileSync(file);
|
|
190
|
+
return { updatedAt: new Date().toISOString(), instances: {} };
|
|
191
|
+
}
|
|
192
|
+
const instances = parsed.instances && typeof parsed.instances === "object"
|
|
193
|
+
? parsed.instances
|
|
194
|
+
: {};
|
|
195
|
+
return {
|
|
196
|
+
updatedAt: typeof parsed.updatedAt === "string"
|
|
197
|
+
? parsed.updatedAt
|
|
198
|
+
: new Date().toISOString(),
|
|
199
|
+
instances: instances,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return { updatedAt: new Date().toISOString(), instances: {} };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function pruneStore(store) {
|
|
207
|
+
const values = Object.values(store.instances);
|
|
208
|
+
if (values.length <= MAX_INSTANCES)
|
|
209
|
+
return;
|
|
210
|
+
values.sort((a, b) => Date.parse(b.lastEventAt) - Date.parse(a.lastEventAt));
|
|
211
|
+
const keep = new Set(values.slice(0, MAX_INSTANCES).map((record) => record.id));
|
|
212
|
+
for (const key of Object.keys(store.instances)) {
|
|
213
|
+
if (!keep.has(key)) {
|
|
214
|
+
delete store.instances[key];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function writeRuntimeInstances(next) {
|
|
219
|
+
ensureRuntimeDir();
|
|
220
|
+
const file = runtimeFile();
|
|
221
|
+
writeJsonFileAtomicSync(file, next, 0o600);
|
|
222
|
+
}
|
|
223
|
+
export function upsertRuntimeInstanceFromHook(payload) {
|
|
224
|
+
const sourceClient = normalizeSourceClient(payload.source_client);
|
|
225
|
+
const event = normalizeHookEvent(payload.event);
|
|
226
|
+
const nowIso = new Date().toISOString();
|
|
227
|
+
const eventAt = normalizeIsoTimestamp(payload.timestamp, nowIso);
|
|
228
|
+
const runId = normalizeNullableString(payload.run_id);
|
|
229
|
+
const correlationId = normalizeNullableString(payload.correlation_id);
|
|
230
|
+
const initiativeId = normalizeNullableString(payload.initiative_id);
|
|
231
|
+
const workstreamId = normalizeNullableString(payload.workstream_id);
|
|
232
|
+
const taskId = normalizeNullableString(payload.task_id);
|
|
233
|
+
const agentId = normalizeNullableString(payload.agent_id);
|
|
234
|
+
const agentName = normalizeNullableString(payload.agent_name);
|
|
235
|
+
const phase = normalizeNullableString(payload.phase);
|
|
236
|
+
const progressPct = normalizeProgress(payload.progress_pct);
|
|
237
|
+
const message = normalizeNullableString(payload.message);
|
|
238
|
+
const metadata = normalizeObject(payload.metadata);
|
|
239
|
+
const id = deriveInstanceId({
|
|
240
|
+
sourceClient,
|
|
241
|
+
runId,
|
|
242
|
+
correlationId,
|
|
243
|
+
agentId,
|
|
244
|
+
initiativeId,
|
|
245
|
+
});
|
|
246
|
+
const store = readRuntimeInstances();
|
|
247
|
+
const existing = store.instances[id] ? normalizeRecord(store.instances[id]) : null;
|
|
248
|
+
let state = existing?.state ?? "active";
|
|
249
|
+
if (event === "session_stop")
|
|
250
|
+
state = "stopped";
|
|
251
|
+
else if (event === "error")
|
|
252
|
+
state = "error";
|
|
253
|
+
else
|
|
254
|
+
state = "active";
|
|
255
|
+
const shouldRefreshHeartbeat = event === "session_start" ||
|
|
256
|
+
event === "heartbeat" ||
|
|
257
|
+
event === "progress" ||
|
|
258
|
+
event === "task_update";
|
|
259
|
+
const record = {
|
|
260
|
+
id,
|
|
261
|
+
sourceClient,
|
|
262
|
+
displayName: toDisplayName(sourceClient),
|
|
263
|
+
providerLogo: toProviderLogo(sourceClient),
|
|
264
|
+
state,
|
|
265
|
+
event,
|
|
266
|
+
runId: runId ?? existing?.runId ?? null,
|
|
267
|
+
correlationId: correlationId ?? existing?.correlationId ?? null,
|
|
268
|
+
initiativeId: initiativeId ?? existing?.initiativeId ?? null,
|
|
269
|
+
workstreamId: workstreamId ?? existing?.workstreamId ?? null,
|
|
270
|
+
taskId: taskId ?? existing?.taskId ?? null,
|
|
271
|
+
agentId: agentId ?? existing?.agentId ?? null,
|
|
272
|
+
agentName: agentName ?? existing?.agentName ?? null,
|
|
273
|
+
phase: phase ?? existing?.phase ?? null,
|
|
274
|
+
progressPct: progressPct ?? existing?.progressPct ?? null,
|
|
275
|
+
currentTask: taskId ?? existing?.currentTask ?? null,
|
|
276
|
+
lastHeartbeatAt: shouldRefreshHeartbeat
|
|
277
|
+
? eventAt
|
|
278
|
+
: existing?.lastHeartbeatAt ?? null,
|
|
279
|
+
lastEventAt: eventAt,
|
|
280
|
+
lastMessage: message ?? existing?.lastMessage ?? null,
|
|
281
|
+
metadata: metadata ?? existing?.metadata ?? null,
|
|
282
|
+
createdAt: existing?.createdAt ?? eventAt,
|
|
283
|
+
updatedAt: nowIso,
|
|
284
|
+
};
|
|
285
|
+
store.instances[id] = record;
|
|
286
|
+
store.updatedAt = nowIso;
|
|
287
|
+
pruneStore(store);
|
|
288
|
+
writeRuntimeInstances(store);
|
|
289
|
+
return record;
|
|
290
|
+
}
|
|
291
|
+
export function applyRuntimeInstanceStaleness(options) {
|
|
292
|
+
const timeoutMs = Math.max(10_000, options?.timeoutMs ?? DEFAULT_RUNTIME_HEARTBEAT_TIMEOUT_MS);
|
|
293
|
+
const nowMs = options?.nowMs ?? Date.now();
|
|
294
|
+
const store = readRuntimeInstances();
|
|
295
|
+
let changed = false;
|
|
296
|
+
for (const [id, rawRecord] of Object.entries(store.instances)) {
|
|
297
|
+
const record = normalizeRecord(rawRecord);
|
|
298
|
+
if (record.state !== "active") {
|
|
299
|
+
if (rawRecord !== record) {
|
|
300
|
+
store.instances[id] = record;
|
|
301
|
+
changed = true;
|
|
302
|
+
}
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
const heartbeatAt = record.lastHeartbeatAt ?? record.lastEventAt;
|
|
306
|
+
const heartbeatEpoch = Date.parse(heartbeatAt);
|
|
307
|
+
if (!Number.isFinite(heartbeatEpoch))
|
|
308
|
+
continue;
|
|
309
|
+
if (nowMs - heartbeatEpoch <= timeoutMs)
|
|
310
|
+
continue;
|
|
311
|
+
store.instances[id] = {
|
|
312
|
+
...record,
|
|
313
|
+
state: "stale",
|
|
314
|
+
updatedAt: new Date(nowMs).toISOString(),
|
|
315
|
+
};
|
|
316
|
+
changed = true;
|
|
317
|
+
}
|
|
318
|
+
if (changed) {
|
|
319
|
+
store.updatedAt = new Date(nowMs).toISOString();
|
|
320
|
+
writeRuntimeInstances(store);
|
|
321
|
+
}
|
|
322
|
+
return store;
|
|
323
|
+
}
|
|
324
|
+
export function listRuntimeInstances(options) {
|
|
325
|
+
const timeoutMs = options?.timeoutMs ?? DEFAULT_RUNTIME_HEARTBEAT_TIMEOUT_MS;
|
|
326
|
+
const nowMs = options?.nowMs ?? Date.now();
|
|
327
|
+
const store = applyRuntimeInstanceStaleness({ timeoutMs, nowMs });
|
|
328
|
+
const limit = Math.max(1, options?.limit ?? MAX_INSTANCES);
|
|
329
|
+
return Object.values(store.instances)
|
|
330
|
+
.map((record) => normalizeRecord(record))
|
|
331
|
+
.sort((a, b) => Date.parse(b.lastEventAt) - Date.parse(a.lastEventAt))
|
|
332
|
+
.slice(0, limit);
|
|
333
|
+
}
|
|
334
|
+
export function clearRuntimeInstances() {
|
|
335
|
+
const file = runtimeFile();
|
|
336
|
+
try {
|
|
337
|
+
rmSync(file, { force: true });
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
// best effort
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
export function resolveRuntimeHookToken() {
|
|
344
|
+
const envToken = normalizeNullableString(process.env.ORGX_HOOK_TOKEN);
|
|
345
|
+
if (envToken)
|
|
346
|
+
return envToken;
|
|
347
|
+
const file = hookTokenFile();
|
|
348
|
+
try {
|
|
349
|
+
if (existsSync(file)) {
|
|
350
|
+
const raw = readFileSync(file, "utf8");
|
|
351
|
+
const token = normalizeNullableString(raw);
|
|
352
|
+
if (token)
|
|
353
|
+
return token;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
// fallback to generated token
|
|
358
|
+
}
|
|
359
|
+
const generated = `orgx_hook_${randomUUID().replace(/-/g, "")}`;
|
|
360
|
+
writeHookTokenFile(generated);
|
|
361
|
+
return generated;
|
|
362
|
+
}
|
package/dist/snapshot-store.d.ts
CHANGED
|
@@ -7,4 +7,3 @@ export declare function readPersistedSnapshot(): PersistedSnapshot | null;
|
|
|
7
7
|
export declare function writePersistedSnapshot(snapshot: OrgSnapshot): PersistedSnapshot;
|
|
8
8
|
export declare function clearPersistedSnapshot(): void;
|
|
9
9
|
export {};
|
|
10
|
-
//# sourceMappingURL=snapshot-store.d.ts.map
|
package/dist/snapshot-store.js
CHANGED
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useorgx/openclaw-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "OrgX plugin for OpenClaw — agent orchestration, quality gates, model routing, and live dashboard",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"ops:launch-checklist": "node ./scripts/run-launch-checklist.mjs",
|
|
42
42
|
"install:dashboard": "npm --prefix dashboard ci",
|
|
43
43
|
"build:dashboard": "npm run install:dashboard && npm --prefix dashboard run build",
|
|
44
|
-
"build:core": "tsc && node ./scripts/copy-manifest.mjs",
|
|
44
|
+
"build:core": "rm -rf dist && tsc && node ./scripts/copy-manifest.mjs",
|
|
45
45
|
"build": "npm run build:dashboard && npm run build:core",
|
|
46
46
|
"clean": "rm -rf dist",
|
|
47
47
|
"pack": "npm run build && mkdir -p artifacts && npm pack --pack-destination artifacts",
|