@useorgx/openclaw-plugin 0.4.1 → 0.4.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/README.md +4 -0
- package/dist/byok-store.js +181 -54
- package/dist/gateway-watchdog-runner.d.ts +1 -0
- package/dist/gateway-watchdog-runner.js +6 -0
- package/dist/gateway-watchdog.d.ts +11 -0
- package/dist/gateway-watchdog.js +221 -0
- package/dist/http-handler.js +705 -78
- package/dist/index.js +7 -0
- package/dist/openclaw-settings.d.ts +17 -0
- package/dist/openclaw-settings.js +118 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ import { clearPersistedApiKey, loadAuthStore, resolveInstallationId, saveAuthSto
|
|
|
21
21
|
import { clearPersistedSnapshot, readPersistedSnapshot, writePersistedSnapshot, } from "./snapshot-store.js";
|
|
22
22
|
import { appendToOutbox, readOutbox, readOutboxSummary, replaceOutbox, } from "./outbox.js";
|
|
23
23
|
import { extractProgressOutboxMessage } from "./reporting/outbox-replay.js";
|
|
24
|
+
import { ensureGatewayWatchdog } from "./gateway-watchdog.js";
|
|
24
25
|
export { OrgXClient } from "./api.js";
|
|
25
26
|
const DEFAULT_BASE_URL = "https://www.useorgx.com";
|
|
26
27
|
const DEFAULT_DOCS_URL = "https://orgx.mintlify.site/guides/openclaw-plugin-setup";
|
|
@@ -1077,6 +1078,12 @@ export default function register(api) {
|
|
|
1077
1078
|
id: "orgx-sync",
|
|
1078
1079
|
start: async () => {
|
|
1079
1080
|
syncServiceRunning = true;
|
|
1081
|
+
const watchdog = ensureGatewayWatchdog(api.log ?? {});
|
|
1082
|
+
if (watchdog.started) {
|
|
1083
|
+
api.log?.info?.("[orgx] Gateway watchdog started", {
|
|
1084
|
+
pid: watchdog.pid,
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1080
1087
|
api.log?.info?.("[orgx] Starting sync service", {
|
|
1081
1088
|
interval: config.syncIntervalMs,
|
|
1082
1089
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type OpenClawProvider = "anthropic" | "openrouter" | "openai";
|
|
2
|
+
export interface OpenClawSettingsSnapshot {
|
|
3
|
+
path: string;
|
|
4
|
+
raw: Record<string, unknown> | null;
|
|
5
|
+
}
|
|
6
|
+
export interface OpenClawProviderModelStats {
|
|
7
|
+
provider: OpenClawProvider;
|
|
8
|
+
total: number;
|
|
9
|
+
sonnetCount: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function readOpenClawSettingsSnapshot(): OpenClawSettingsSnapshot;
|
|
12
|
+
export declare function listOpenClawConfiguredModelKeys(raw: Record<string, unknown> | null): string[];
|
|
13
|
+
export declare function classifyProviderFromModelKey(modelKey: string): OpenClawProvider | null;
|
|
14
|
+
export declare function summarizeOpenClawProviderModels(raw: Record<string, unknown> | null): Record<OpenClawProvider, OpenClawProviderModelStats>;
|
|
15
|
+
export declare function resolvePreferredOpenClawProvider(raw: Record<string, unknown> | null): OpenClawProvider | null;
|
|
16
|
+
export declare function readOpenClawPrimaryModel(raw: Record<string, unknown> | null): string | null;
|
|
17
|
+
export declare function readOpenClawGatewayPort(raw: Record<string, unknown> | null): number;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getOpenClawDir } from "./paths.js";
|
|
4
|
+
function readObject(value) {
|
|
5
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
6
|
+
? value
|
|
7
|
+
: {};
|
|
8
|
+
}
|
|
9
|
+
function parseJsonObject(value) {
|
|
10
|
+
try {
|
|
11
|
+
const parsed = JSON.parse(value);
|
|
12
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
13
|
+
? parsed
|
|
14
|
+
: null;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function readOpenClawSettingsSnapshot() {
|
|
21
|
+
const path = join(getOpenClawDir(), "openclaw.json");
|
|
22
|
+
if (!existsSync(path)) {
|
|
23
|
+
return { path, raw: null };
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const rawText = readFileSync(path, "utf8");
|
|
27
|
+
return { path, raw: parseJsonObject(rawText) };
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return { path, raw: null };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function listOpenClawConfiguredModelKeys(raw) {
|
|
34
|
+
if (!raw)
|
|
35
|
+
return [];
|
|
36
|
+
const agents = readObject(raw.agents);
|
|
37
|
+
const defaults = readObject(agents.defaults);
|
|
38
|
+
const models = readObject(defaults.models);
|
|
39
|
+
const keys = Object.keys(models)
|
|
40
|
+
.map((key) => key.trim())
|
|
41
|
+
.filter((key) => key.length > 0);
|
|
42
|
+
keys.sort((a, b) => a.localeCompare(b));
|
|
43
|
+
return keys;
|
|
44
|
+
}
|
|
45
|
+
export function classifyProviderFromModelKey(modelKey) {
|
|
46
|
+
const normalized = modelKey.trim().toLowerCase();
|
|
47
|
+
if (!normalized)
|
|
48
|
+
return null;
|
|
49
|
+
if (normalized.startsWith("openrouter/"))
|
|
50
|
+
return "openrouter";
|
|
51
|
+
if (normalized.startsWith("anthropic/") || normalized.startsWith("claude/")) {
|
|
52
|
+
return "anthropic";
|
|
53
|
+
}
|
|
54
|
+
if (normalized.startsWith("openai/") ||
|
|
55
|
+
normalized.startsWith("openai-") ||
|
|
56
|
+
normalized.startsWith("gpt")) {
|
|
57
|
+
return "openai";
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
export function summarizeOpenClawProviderModels(raw) {
|
|
62
|
+
const summary = {
|
|
63
|
+
anthropic: { provider: "anthropic", total: 0, sonnetCount: 0 },
|
|
64
|
+
openrouter: { provider: "openrouter", total: 0, sonnetCount: 0 },
|
|
65
|
+
openai: { provider: "openai", total: 0, sonnetCount: 0 },
|
|
66
|
+
};
|
|
67
|
+
for (const key of listOpenClawConfiguredModelKeys(raw)) {
|
|
68
|
+
const provider = classifyProviderFromModelKey(key);
|
|
69
|
+
if (!provider)
|
|
70
|
+
continue;
|
|
71
|
+
const bucket = summary[provider];
|
|
72
|
+
bucket.total += 1;
|
|
73
|
+
if (key.toLowerCase().includes("sonnet")) {
|
|
74
|
+
bucket.sonnetCount += 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return summary;
|
|
78
|
+
}
|
|
79
|
+
export function resolvePreferredOpenClawProvider(raw) {
|
|
80
|
+
const summary = summarizeOpenClawProviderModels(raw);
|
|
81
|
+
const order = ["openrouter", "anthropic", "openai"];
|
|
82
|
+
for (const provider of order) {
|
|
83
|
+
if (summary[provider].sonnetCount > 0) {
|
|
84
|
+
return provider;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (const provider of order) {
|
|
88
|
+
if (summary[provider].total > 0) {
|
|
89
|
+
return provider;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
export function readOpenClawPrimaryModel(raw) {
|
|
95
|
+
if (!raw)
|
|
96
|
+
return null;
|
|
97
|
+
const agents = readObject(raw.agents);
|
|
98
|
+
const defaults = readObject(agents.defaults);
|
|
99
|
+
const model = readObject(defaults.model);
|
|
100
|
+
const primary = typeof model.primary === "string" ? model.primary.trim() : "";
|
|
101
|
+
return primary || null;
|
|
102
|
+
}
|
|
103
|
+
export function readOpenClawGatewayPort(raw) {
|
|
104
|
+
if (!raw)
|
|
105
|
+
return 18789;
|
|
106
|
+
const gateway = readObject(raw.gateway);
|
|
107
|
+
const port = gateway.port;
|
|
108
|
+
if (typeof port === "number" && Number.isFinite(port) && port > 0) {
|
|
109
|
+
return Math.floor(port);
|
|
110
|
+
}
|
|
111
|
+
if (typeof port === "string") {
|
|
112
|
+
const parsed = Number.parseInt(port, 10);
|
|
113
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
114
|
+
return parsed;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return 18789;
|
|
118
|
+
}
|
package/package.json
CHANGED