@syengup/friday-channel-next 0.1.25 → 0.1.27
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/dist/index.js +2 -0
- package/dist/src/http/handlers/health.d.ts +1 -0
- package/dist/src/http/handlers/health.js +2 -0
- package/dist/src/http/handlers/history-messages.js +50 -9
- package/dist/src/http/handlers/messages.d.ts +5 -0
- package/dist/src/http/handlers/messages.js +19 -8
- package/dist/src/http/handlers/plugin-info.d.ts +11 -0
- package/dist/src/http/handlers/plugin-info.js +32 -0
- package/dist/src/http/handlers/plugin-upgrade.d.ts +11 -0
- package/dist/src/http/handlers/plugin-upgrade.js +94 -0
- package/dist/src/http/handlers/sse.js +2 -0
- package/dist/src/http/handlers/status.js +2 -0
- package/dist/src/http/server.js +10 -0
- package/dist/src/plugin-install-info.d.ts +15 -0
- package/dist/src/plugin-install-info.js +87 -0
- package/dist/src/upgrade-runtime.d.ts +39 -0
- package/dist/src/upgrade-runtime.js +27 -0
- package/dist/src/version.d.ts +5 -0
- package/dist/src/version.js +37 -0
- package/index.ts +2 -0
- package/package.json +1 -1
- package/src/http/handlers/health.ts +3 -0
- package/src/http/handlers/history-messages.test.ts +33 -0
- package/src/http/handlers/history-messages.ts +46 -8
- package/src/http/handlers/messages.test.ts +75 -1
- package/src/http/handlers/messages.ts +19 -7
- package/src/http/handlers/plugin-info.ts +51 -0
- package/src/http/handlers/plugin-upgrade.ts +112 -0
- package/src/http/handlers/sse.ts +2 -0
- package/src/http/handlers/status.ts +2 -0
- package/src/http/server.ts +12 -0
- package/src/plugin-install-info.test.ts +28 -0
- package/src/plugin-install-info.ts +95 -0
- package/src/upgrade-runtime.ts +69 -0
- package/src/version.ts +41 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Captures the full plugin runtime (`api.runtime`) at `registerFull` time so the
|
|
3
|
+
* plugin-info / plugin-upgrade HTTP handlers can reach `system.runCommandWithTimeout`
|
|
4
|
+
* and `config.mutateConfigFile` — capabilities the narrow `getFridayNextRuntime()`
|
|
5
|
+
* store does NOT expose (it only carries `config`/`logger`).
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the `setFridayAgentForwardRuntime` capture pattern in agent-forward-runtime.ts.
|
|
8
|
+
*/
|
|
9
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
|
|
10
|
+
|
|
11
|
+
export type SpawnResultLike = {
|
|
12
|
+
code: number | null;
|
|
13
|
+
stdout: string;
|
|
14
|
+
stderr: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ConfigAfterWrite =
|
|
19
|
+
| { mode: "auto" }
|
|
20
|
+
| { mode: "restart"; reason: string }
|
|
21
|
+
| { mode: "none"; reason: string };
|
|
22
|
+
|
|
23
|
+
export type UpgradeRuntime = {
|
|
24
|
+
/** Run a command (argv) with a timeout in ms; resolves with stdout/stderr/code. */
|
|
25
|
+
runCommandWithTimeout: (argv: string[], timeoutMs: number) => Promise<SpawnResultLike>;
|
|
26
|
+
/** Read the current (deep-readonly) OpenClaw config snapshot. */
|
|
27
|
+
currentConfig: () => unknown;
|
|
28
|
+
/** Mutate the config file; `afterWrite: { mode: "restart" }` triggers a safe gateway restart. */
|
|
29
|
+
mutateConfigFile: (params: {
|
|
30
|
+
afterWrite: ConfigAfterWrite;
|
|
31
|
+
mutate: (draft: unknown) => unknown | void;
|
|
32
|
+
}) => Promise<unknown>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
let upgradeRuntime: UpgradeRuntime | null = null;
|
|
36
|
+
|
|
37
|
+
export function setUpgradeRuntime(api: OpenClawPluginApi): void {
|
|
38
|
+
const runtime = api.runtime as unknown as {
|
|
39
|
+
system?: { runCommandWithTimeout?: (argv: string[], opts: unknown) => Promise<SpawnResultLike> };
|
|
40
|
+
config: {
|
|
41
|
+
current: () => unknown;
|
|
42
|
+
mutateConfigFile?: (params: unknown) => Promise<unknown>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
upgradeRuntime = {
|
|
47
|
+
runCommandWithTimeout: async (argv, timeoutMs) => {
|
|
48
|
+
const run = runtime.system?.runCommandWithTimeout;
|
|
49
|
+
if (!run) throw new Error("runtime.system.runCommandWithTimeout unavailable");
|
|
50
|
+
// `runCommandWithTimeout(argv, number | CommandOptions)` — pass the bare ms.
|
|
51
|
+
return run(argv, timeoutMs);
|
|
52
|
+
},
|
|
53
|
+
currentConfig: () => runtime.config.current(),
|
|
54
|
+
mutateConfigFile: async (params) => {
|
|
55
|
+
const mutate = runtime.config.mutateConfigFile;
|
|
56
|
+
if (!mutate) throw new Error("runtime.config.mutateConfigFile unavailable");
|
|
57
|
+
return mutate(params);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function getUpgradeRuntime(): UpgradeRuntime | null {
|
|
63
|
+
return upgradeRuntime;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Vitest-only */
|
|
67
|
+
export function resetUpgradeRuntimeForTest(): void {
|
|
68
|
+
upgradeRuntime = null;
|
|
69
|
+
}
|
package/src/version.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin self-version.
|
|
3
|
+
*
|
|
4
|
+
* Resolved at module load by reading this package's own package.json relative to
|
|
5
|
+
* the compiled module URL. `tsc` does NOT copy package.json into `dist/`, and a
|
|
6
|
+
* JSON `import` would rewrite to a non-existent `dist/package.json`, so we read
|
|
7
|
+
* the real file from disk and walk a couple of candidate paths. Falls back to a
|
|
8
|
+
* hardcoded constant if the file can't be located (keep in sync with package.json).
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
12
|
+
|
|
13
|
+
/** Keep in sync with package.json "version" as a last-resort fallback. */
|
|
14
|
+
const FALLBACK_VERSION = "0.1.27";
|
|
15
|
+
|
|
16
|
+
function resolvePluginVersion(): string {
|
|
17
|
+
// dist layout: <root>/dist/src/version.js → ../../package.json = <root>/package.json
|
|
18
|
+
// source layout (vitest/jiti): <root>/src/version.ts → ../package.json = <root>/package.json
|
|
19
|
+
const candidates = ["../../package.json", "../package.json"];
|
|
20
|
+
for (const rel of candidates) {
|
|
21
|
+
try {
|
|
22
|
+
const path = fileURLToPath(new URL(rel, import.meta.url));
|
|
23
|
+
const raw = readFileSync(path, "utf8");
|
|
24
|
+
const pkg = JSON.parse(raw) as { name?: string; version?: string };
|
|
25
|
+
if (pkg.name === "@syengup/friday-channel-next" && typeof pkg.version === "string" && pkg.version) {
|
|
26
|
+
return pkg.version;
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
// try next candidate
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return FALLBACK_VERSION;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const PLUGIN_VERSION: string = resolvePluginVersion();
|
|
36
|
+
|
|
37
|
+
/** npm package name, used for the upgrade spec and registry lookup. */
|
|
38
|
+
export const PLUGIN_PACKAGE_NAME = "@syengup/friday-channel-next";
|
|
39
|
+
|
|
40
|
+
/** Plugin id as registered with OpenClaw (used to read the install record). */
|
|
41
|
+
export const PLUGIN_ID = "friday-next";
|