mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
refactor: move public artifact metadata into plugins
This commit is contained in:
@@ -1,62 +1,6 @@
|
||||
function assertUniqueValues<T extends string>(values: readonly T[], label: string): readonly T[] {
|
||||
const seen = new Set<string>();
|
||||
const duplicates = new Set<string>();
|
||||
for (const value of values) {
|
||||
if (seen.has(value)) {
|
||||
duplicates.add(value);
|
||||
continue;
|
||||
}
|
||||
seen.add(value);
|
||||
}
|
||||
if (duplicates.size > 0) {
|
||||
throw new Error(`Duplicate ${label}: ${Array.from(duplicates).join(", ")}`);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
export function getPublicArtifactBasename(relativePath: string): string {
|
||||
return relativePath.split("/").at(-1) ?? relativePath;
|
||||
}
|
||||
|
||||
export const BUNDLED_RUNTIME_SIDECAR_PATHS = assertUniqueValues(
|
||||
[
|
||||
"dist/extensions/whatsapp/light-runtime-api.js",
|
||||
"dist/extensions/whatsapp/runtime-api.js",
|
||||
"dist/extensions/matrix/helper-api.js",
|
||||
"dist/extensions/matrix/runtime-api.js",
|
||||
"dist/extensions/matrix/thread-bindings-runtime.js",
|
||||
"dist/extensions/msteams/runtime-api.js",
|
||||
] as const,
|
||||
"bundled runtime sidecar path",
|
||||
);
|
||||
|
||||
const EXTRA_GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES = assertUniqueValues(
|
||||
[
|
||||
"action-runtime.runtime.js",
|
||||
"action-runtime-api.js",
|
||||
"allow-from.js",
|
||||
"api.js",
|
||||
"auth-presence.js",
|
||||
"channel-config-api.js",
|
||||
"index.js",
|
||||
"login-qr-api.js",
|
||||
"onboard.js",
|
||||
"openai-codex-catalog.js",
|
||||
"provider-catalog.js",
|
||||
"session-key-api.js",
|
||||
"setup-api.js",
|
||||
"setup-entry.js",
|
||||
"timeouts.js",
|
||||
] as const,
|
||||
"extra guarded extension public surface basename",
|
||||
);
|
||||
|
||||
export const BUNDLED_RUNTIME_SIDECAR_BASENAMES = assertUniqueValues(
|
||||
[...new Set(BUNDLED_RUNTIME_SIDECAR_PATHS.map(getPublicArtifactBasename))],
|
||||
"bundled runtime sidecar basename",
|
||||
);
|
||||
|
||||
export const GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES = assertUniqueValues(
|
||||
[...BUNDLED_RUNTIME_SIDECAR_BASENAMES, ...EXTRA_GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES],
|
||||
"guarded extension public surface basename",
|
||||
);
|
||||
export {
|
||||
BUNDLED_RUNTIME_SIDECAR_BASENAMES,
|
||||
BUNDLED_RUNTIME_SIDECAR_PATHS,
|
||||
GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES,
|
||||
getPublicArtifactBasename,
|
||||
} from "../plugins/public-artifacts.js";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { BUNDLED_RUNTIME_SIDECAR_PATHS } from "../extensions/public-artifacts.js";
|
||||
import { BUNDLED_RUNTIME_SIDECAR_PATHS } from "../plugins/public-artifacts.js";
|
||||
import { pathExists } from "../utils.js";
|
||||
import { readPackageVersion } from "./package-json.js";
|
||||
import { applyPathPrepend } from "./path-prepend.js";
|
||||
|
||||
62
src/plugins/public-artifacts.ts
Normal file
62
src/plugins/public-artifacts.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
function assertUniqueValues<T extends string>(values: readonly T[], label: string): readonly T[] {
|
||||
const seen = new Set<string>();
|
||||
const duplicates = new Set<string>();
|
||||
for (const value of values) {
|
||||
if (seen.has(value)) {
|
||||
duplicates.add(value);
|
||||
continue;
|
||||
}
|
||||
seen.add(value);
|
||||
}
|
||||
if (duplicates.size > 0) {
|
||||
throw new Error(`Duplicate ${label}: ${Array.from(duplicates).join(", ")}`);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
export function getPublicArtifactBasename(relativePath: string): string {
|
||||
return relativePath.split("/").at(-1) ?? relativePath;
|
||||
}
|
||||
|
||||
export const BUNDLED_RUNTIME_SIDECAR_PATHS = assertUniqueValues(
|
||||
[
|
||||
"dist/extensions/whatsapp/light-runtime-api.js",
|
||||
"dist/extensions/whatsapp/runtime-api.js",
|
||||
"dist/extensions/matrix/helper-api.js",
|
||||
"dist/extensions/matrix/runtime-api.js",
|
||||
"dist/extensions/matrix/thread-bindings-runtime.js",
|
||||
"dist/extensions/msteams/runtime-api.js",
|
||||
] as const,
|
||||
"bundled runtime sidecar path",
|
||||
);
|
||||
|
||||
const EXTRA_GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES = assertUniqueValues(
|
||||
[
|
||||
"action-runtime.runtime.js",
|
||||
"action-runtime-api.js",
|
||||
"allow-from.js",
|
||||
"api.js",
|
||||
"auth-presence.js",
|
||||
"channel-config-api.js",
|
||||
"index.js",
|
||||
"login-qr-api.js",
|
||||
"onboard.js",
|
||||
"openai-codex-catalog.js",
|
||||
"provider-catalog.js",
|
||||
"session-key-api.js",
|
||||
"setup-api.js",
|
||||
"setup-entry.js",
|
||||
"timeouts.js",
|
||||
] as const,
|
||||
"extra guarded extension public surface basename",
|
||||
);
|
||||
|
||||
export const BUNDLED_RUNTIME_SIDECAR_BASENAMES = assertUniqueValues(
|
||||
[...new Set(BUNDLED_RUNTIME_SIDECAR_PATHS.map(getPublicArtifactBasename))],
|
||||
"bundled runtime sidecar basename",
|
||||
);
|
||||
|
||||
export const GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES = assertUniqueValues(
|
||||
[...BUNDLED_RUNTIME_SIDECAR_BASENAMES, ...EXTRA_GUARDED_EXTENSION_PUBLIC_SURFACE_BASENAMES],
|
||||
"guarded extension public surface basename",
|
||||
);
|
||||
Reference in New Issue
Block a user