mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:40:44 +00:00
refactor: trim unused exports
This commit is contained in:
@@ -3,7 +3,6 @@ import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import type { ModelCatalogEntry } from "./model-catalog.types.js";
|
||||
import type { ModelRef } from "./model-selection-normalize.js";
|
||||
import {
|
||||
buildAllowedModelSetWithFallbacks,
|
||||
buildModelAliasIndex,
|
||||
getModelRefStatusWithFallbackModels,
|
||||
resolveAllowedModelRefFromAliasIndex,
|
||||
@@ -12,40 +11,18 @@ import {
|
||||
|
||||
export {
|
||||
buildConfiguredAllowlistKeys,
|
||||
buildConfiguredModelCatalog,
|
||||
buildModelAliasIndex,
|
||||
inferUniqueProviderFromConfiguredModels,
|
||||
normalizeModelSelection,
|
||||
resolveConfiguredModelRef,
|
||||
resolveHooksGmailModel,
|
||||
resolveModelRefFromString,
|
||||
} from "./model-selection-shared.js";
|
||||
export type { ModelAliasIndex, ModelRefStatus } from "./model-selection-shared.js";
|
||||
export type { ModelRefStatus } from "./model-selection-shared.js";
|
||||
|
||||
function resolveDefaultFallbackModels(cfg: OpenClawConfig): string[] {
|
||||
return resolveAgentModelFallbackValues(cfg.agents?.defaults?.model);
|
||||
}
|
||||
|
||||
export function buildAllowedModelSet(params: {
|
||||
cfg: OpenClawConfig;
|
||||
catalog: ModelCatalogEntry[];
|
||||
defaultProvider: string;
|
||||
defaultModel?: string;
|
||||
}): {
|
||||
allowAny: boolean;
|
||||
allowedCatalog: ModelCatalogEntry[];
|
||||
allowedKeys: Set<string>;
|
||||
} {
|
||||
const { cfg, catalog, defaultProvider, defaultModel } = params;
|
||||
return buildAllowedModelSetWithFallbacks({
|
||||
cfg,
|
||||
catalog,
|
||||
defaultProvider,
|
||||
defaultModel,
|
||||
fallbackModels: resolveDefaultFallbackModels(cfg),
|
||||
});
|
||||
}
|
||||
|
||||
export function getModelRefStatus(params: {
|
||||
cfg: OpenClawConfig;
|
||||
catalog: ModelCatalogEntry[];
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import fs from "node:fs";
|
||||
import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
type StaticModule = typeof import("./models-config.providers.static.js");
|
||||
|
||||
const fixtureRoot = mkdtempSync(path.join(tmpdir(), "openclaw-provider-catalogs-"));
|
||||
const fixtureExtensionsDir = path.join(fixtureRoot, "dist-runtime", "extensions");
|
||||
|
||||
function writeFixtureCatalog(dirName: string, exportNames: string[]) {
|
||||
const pluginDir = path.join(fixtureExtensionsDir, dirName);
|
||||
fs.mkdirSync(pluginDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(pluginDir, "provider-catalog.js"),
|
||||
exportNames
|
||||
.map((exportName) => `export function ${exportName}() { return "${dirName}"; }`)
|
||||
.join("\n") + "\n",
|
||||
"utf8",
|
||||
);
|
||||
}
|
||||
|
||||
writeFixtureCatalog("openrouter", ["buildOpenrouterProvider"]);
|
||||
writeFixtureCatalog("volcengine", ["buildDoubaoProvider", "buildDoubaoCodingProvider"]);
|
||||
|
||||
let staticModule: StaticModule;
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
vi.doMock("../plugins/bundled-plugin-metadata.js", () => ({
|
||||
listBundledPluginMetadata: (_params: { rootDir: string }) => [
|
||||
{
|
||||
dirName: "openrouter",
|
||||
publicSurfaceArtifacts: ["provider-catalog.js"],
|
||||
manifest: { id: "openrouter", providers: ["openrouter"] },
|
||||
},
|
||||
{
|
||||
dirName: "volcengine",
|
||||
publicSurfaceArtifacts: ["provider-catalog.js"],
|
||||
manifest: { id: "volcengine", providers: ["volcengine", "byteplus"] },
|
||||
},
|
||||
{
|
||||
dirName: "ignored",
|
||||
publicSurfaceArtifacts: ["api.js"],
|
||||
manifest: { id: "ignored", providers: [] },
|
||||
},
|
||||
],
|
||||
resolveBundledPluginPublicSurfacePath: ({
|
||||
rootDir,
|
||||
dirName,
|
||||
artifactBasename,
|
||||
}: {
|
||||
rootDir: string;
|
||||
dirName: string;
|
||||
artifactBasename: string;
|
||||
}) => path.join(rootDir, "dist-runtime", "extensions", dirName, artifactBasename),
|
||||
}));
|
||||
staticModule = await import("./models-config.providers.static.js");
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
vi.doUnmock("../plugins/bundled-plugin-metadata.js");
|
||||
vi.resetModules();
|
||||
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe("models-config bundled provider catalogs", () => {
|
||||
it("detects provider catalogs from plugin folders via metadata artifacts", () => {
|
||||
const entries = staticModule.resolveBundledProviderCatalogEntries({ rootDir: fixtureRoot });
|
||||
expect(entries.map((entry) => entry.dirName)).toEqual(["openrouter", "volcengine"]);
|
||||
expect(entries.find((entry) => entry.dirName === "volcengine")).toMatchObject({
|
||||
dirName: "volcengine",
|
||||
pluginId: "volcengine",
|
||||
});
|
||||
});
|
||||
|
||||
it("loads provider catalog exports from detected plugin folders", async () => {
|
||||
const exports = await staticModule.loadBundledProviderCatalogExportMap({
|
||||
rootDir: fixtureRoot,
|
||||
});
|
||||
expect(exports.buildOpenrouterProvider).toBeTypeOf("function");
|
||||
expect(exports.buildDoubaoProvider).toBeTypeOf("function");
|
||||
expect(exports.buildDoubaoCodingProvider).toBeTypeOf("function");
|
||||
});
|
||||
});
|
||||
@@ -1,123 +0,0 @@
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { listBundledPluginMetadata } from "../plugins/bundled-plugin-metadata.js";
|
||||
import { resolveBundledPluginPublicSurfacePath } from "../plugins/public-surface-runtime.js";
|
||||
|
||||
const PROVIDER_CATALOG_ARTIFACT_BASENAME = "provider-catalog.js";
|
||||
const DEFAULT_PROVIDER_CATALOG_ROOT = path.resolve(import.meta.dirname, "../..");
|
||||
|
||||
export type BundledProviderCatalogEntry = {
|
||||
dirName: string;
|
||||
pluginId: string;
|
||||
providers: readonly string[];
|
||||
artifactPath: string;
|
||||
};
|
||||
|
||||
type ProviderCatalogModule = Record<string, unknown>;
|
||||
type ProviderCatalogExportMap = Record<string, unknown>;
|
||||
|
||||
let providerCatalogEntriesCache: ReadonlyArray<BundledProviderCatalogEntry> | null = null;
|
||||
let providerCatalogModulesPromise: Promise<Readonly<Record<string, ProviderCatalogModule>>> | null =
|
||||
null;
|
||||
let providerCatalogExportMapPromise: Promise<Readonly<ProviderCatalogExportMap>> | null = null;
|
||||
|
||||
export function resolveBundledProviderCatalogEntries(params?: {
|
||||
rootDir?: string;
|
||||
}): ReadonlyArray<BundledProviderCatalogEntry> {
|
||||
const rootDir = params?.rootDir ?? DEFAULT_PROVIDER_CATALOG_ROOT;
|
||||
if (rootDir === DEFAULT_PROVIDER_CATALOG_ROOT && providerCatalogEntriesCache) {
|
||||
return providerCatalogEntriesCache;
|
||||
}
|
||||
|
||||
const entries: BundledProviderCatalogEntry[] = [];
|
||||
for (const entry of listBundledPluginMetadata({ rootDir })) {
|
||||
if (!entry.publicSurfaceArtifacts?.includes(PROVIDER_CATALOG_ARTIFACT_BASENAME)) {
|
||||
continue;
|
||||
}
|
||||
const artifactPath = resolveBundledPluginPublicSurfacePath({
|
||||
rootDir,
|
||||
dirName: entry.dirName,
|
||||
artifactBasename: PROVIDER_CATALOG_ARTIFACT_BASENAME,
|
||||
});
|
||||
if (!artifactPath) {
|
||||
continue;
|
||||
}
|
||||
entries.push({
|
||||
dirName: entry.dirName,
|
||||
pluginId: entry.manifest.id,
|
||||
providers: entry.manifest.providers ?? [],
|
||||
artifactPath,
|
||||
});
|
||||
}
|
||||
entries.sort((left, right) => left.dirName.localeCompare(right.dirName));
|
||||
|
||||
if (rootDir === DEFAULT_PROVIDER_CATALOG_ROOT) {
|
||||
providerCatalogEntriesCache = entries;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
export async function loadBundledProviderCatalogModules(params?: {
|
||||
rootDir?: string;
|
||||
}): Promise<Readonly<Record<string, ProviderCatalogModule>>> {
|
||||
const rootDir = params?.rootDir ?? DEFAULT_PROVIDER_CATALOG_ROOT;
|
||||
if (rootDir === DEFAULT_PROVIDER_CATALOG_ROOT && providerCatalogModulesPromise) {
|
||||
return providerCatalogModulesPromise;
|
||||
}
|
||||
|
||||
const loadPromise = (async () => {
|
||||
const entries = resolveBundledProviderCatalogEntries({ rootDir });
|
||||
const modules = await Promise.all(
|
||||
entries.map(async (entry) => {
|
||||
const module = (await import(
|
||||
pathToFileURL(entry.artifactPath).href
|
||||
)) as ProviderCatalogModule;
|
||||
return [entry.dirName, module] as const;
|
||||
}),
|
||||
);
|
||||
return Object.freeze(Object.fromEntries(modules));
|
||||
})();
|
||||
|
||||
if (rootDir === DEFAULT_PROVIDER_CATALOG_ROOT) {
|
||||
providerCatalogModulesPromise = loadPromise;
|
||||
}
|
||||
return loadPromise;
|
||||
}
|
||||
|
||||
export async function loadBundledProviderCatalogExportMap(params?: {
|
||||
rootDir?: string;
|
||||
}): Promise<Readonly<ProviderCatalogExportMap>> {
|
||||
const rootDir = params?.rootDir ?? DEFAULT_PROVIDER_CATALOG_ROOT;
|
||||
if (rootDir === DEFAULT_PROVIDER_CATALOG_ROOT && providerCatalogExportMapPromise) {
|
||||
return providerCatalogExportMapPromise;
|
||||
}
|
||||
|
||||
const loadPromise = (async () => {
|
||||
const modules = await loadBundledProviderCatalogModules({ rootDir });
|
||||
const exports: ProviderCatalogExportMap = {};
|
||||
const exportOwners = new Map<string, string>();
|
||||
|
||||
for (const [dirName, module] of Object.entries(modules)) {
|
||||
for (const [exportName, exportValue] of Object.entries(module)) {
|
||||
if (exportName === "default") {
|
||||
continue;
|
||||
}
|
||||
const existingOwner = exportOwners.get(exportName);
|
||||
if (existingOwner && existingOwner !== dirName) {
|
||||
throw new Error(
|
||||
`Duplicate provider catalog export "${exportName}" from folders "${existingOwner}" and "${dirName}"`,
|
||||
);
|
||||
}
|
||||
exportOwners.set(exportName, dirName);
|
||||
exports[exportName] = exportValue;
|
||||
}
|
||||
}
|
||||
|
||||
return Object.freeze(exports);
|
||||
})();
|
||||
|
||||
if (rootDir === DEFAULT_PROVIDER_CATALOG_ROOT) {
|
||||
providerCatalogExportMapPromise = loadPromise;
|
||||
}
|
||||
return loadPromise;
|
||||
}
|
||||
@@ -1,12 +1,5 @@
|
||||
export * from "./models-config.providers.static.js";
|
||||
export { resolveImplicitProviders } from "./models-config.providers.implicit.js";
|
||||
export { normalizeProviders } from "./models-config.providers.normalize.js";
|
||||
export type {
|
||||
ProfileApiKeyResolution,
|
||||
ProviderApiKeyResolver,
|
||||
ProviderAuthResolver,
|
||||
ProviderConfig,
|
||||
SecretDefaults,
|
||||
} from "./models-config.providers.secrets.js";
|
||||
export type { ProviderConfig } from "./models-config.providers.secrets.js";
|
||||
export { applyNativeStreamingUsageCompat } from "./models-config.providers.policy.js";
|
||||
export { enforceSourceManagedProviderSecrets } from "./models-config.providers.source-managed.js";
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
export type { MessagingToolSend } from "./pi-embedded-messaging.types.js";
|
||||
|
||||
import { getChannelPlugin, normalizeChannelId } from "../channels/plugins/index.js";
|
||||
import { normalizeOptionalString } from "../shared/string-coerce.js";
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export type { MessagingToolSend } from "./pi-embedded-messaging.types.js";
|
||||
export {
|
||||
compactEmbeddedPiSession,
|
||||
compactEmbeddedPiSession as compactEmbeddedAgentSession,
|
||||
|
||||
@@ -62,11 +62,6 @@ export function collectConfigServiceEnvVars(cfg?: OpenClawConfig): Record<string
|
||||
return collectConfigEnvVarsByTarget(cfg);
|
||||
}
|
||||
|
||||
/** @deprecated Use `collectConfigRuntimeEnvVars` or `collectConfigServiceEnvVars`. */
|
||||
export function collectConfigEnvVars(cfg?: OpenClawConfig): Record<string, string> {
|
||||
return collectConfigRuntimeEnvVars(cfg);
|
||||
}
|
||||
|
||||
export function createConfigRuntimeEnv(
|
||||
cfg: OpenClawConfig,
|
||||
baseEnv: NodeJS.ProcessEnv = process.env,
|
||||
|
||||
@@ -77,16 +77,6 @@ export type ObserveRecoveryDeps = {
|
||||
logger: Pick<typeof console, "warn">;
|
||||
};
|
||||
|
||||
type ObserveSnapshot = {
|
||||
path: string;
|
||||
exists: boolean;
|
||||
valid: boolean;
|
||||
raw: string | null;
|
||||
hash?: string;
|
||||
parsed: unknown;
|
||||
resolved?: unknown;
|
||||
};
|
||||
|
||||
type ConfigHealthFingerprint = {
|
||||
hash: string;
|
||||
bytes: number;
|
||||
@@ -202,17 +192,6 @@ function createConfigObserveAuditAppendParams(
|
||||
};
|
||||
}
|
||||
|
||||
function createConfigObserveAnomalyAuditAppendParams(
|
||||
deps: ObserveRecoveryDeps,
|
||||
params: Omit<ConfigObserveAuditRecordParams, "restoredFromBackup" | "restoredBackupPath">,
|
||||
) {
|
||||
return createConfigObserveAuditAppendParams(deps, {
|
||||
...params,
|
||||
restoredFromBackup: false,
|
||||
restoredBackupPath: null,
|
||||
});
|
||||
}
|
||||
|
||||
function hashConfigRaw(raw: string | null): string {
|
||||
return crypto
|
||||
.createHash("sha256")
|
||||
@@ -780,187 +759,6 @@ export function maybeRecoverSuspiciousConfigReadSync(params: {
|
||||
return { raw: backupRaw, parsed: backupParsed };
|
||||
}
|
||||
|
||||
export async function observeConfigSnapshot(
|
||||
deps: ObserveRecoveryDeps,
|
||||
snapshot: ObserveSnapshot,
|
||||
): Promise<void> {
|
||||
if (!snapshot.exists || typeof snapshot.raw !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
const stat = await deps.fs.promises.stat(snapshot.path).catch(() => null);
|
||||
const now = new Date().toISOString();
|
||||
const current = createConfigHealthFingerprint({
|
||||
hash: resolveConfigSnapshotHash(snapshot) ?? hashConfigRaw(snapshot.raw),
|
||||
raw: snapshot.raw,
|
||||
parsed: snapshot.parsed,
|
||||
gatewaySource: snapshot.resolved,
|
||||
stat: stat as ConfigStatMetadataSource,
|
||||
observedAt: now,
|
||||
});
|
||||
|
||||
let healthState = await readConfigHealthState(deps);
|
||||
const entry = getConfigHealthEntry(healthState, snapshot.path);
|
||||
const backupBaseline =
|
||||
entry.lastKnownGood ??
|
||||
(await readConfigFingerprintForPath(deps, `${snapshot.path}.bak`)) ??
|
||||
undefined;
|
||||
const suspicious = resolveConfigObserveSuspiciousReasons({
|
||||
bytes: current.bytes,
|
||||
hasMeta: current.hasMeta,
|
||||
gatewayMode: current.gatewayMode,
|
||||
parsed: snapshot.parsed,
|
||||
lastKnownGood: backupBaseline,
|
||||
});
|
||||
|
||||
if (suspicious.length === 0) {
|
||||
if (snapshot.valid) {
|
||||
const nextEntry: ConfigHealthEntry = {
|
||||
...entry,
|
||||
lastKnownGood: current,
|
||||
lastObservedSuspiciousSignature: null,
|
||||
};
|
||||
const same =
|
||||
entry.lastKnownGood &&
|
||||
entry.lastKnownGood.hash === current.hash &&
|
||||
entry.lastKnownGood.bytes === current.bytes &&
|
||||
entry.lastKnownGood.mtimeMs === current.mtimeMs &&
|
||||
entry.lastKnownGood.ctimeMs === current.ctimeMs &&
|
||||
entry.lastKnownGood.dev === current.dev &&
|
||||
entry.lastKnownGood.ino === current.ino &&
|
||||
entry.lastKnownGood.mode === current.mode &&
|
||||
entry.lastKnownGood.nlink === current.nlink &&
|
||||
entry.lastKnownGood.uid === current.uid &&
|
||||
entry.lastKnownGood.gid === current.gid &&
|
||||
entry.lastKnownGood.hasMeta === current.hasMeta &&
|
||||
entry.lastKnownGood.gatewayMode === current.gatewayMode;
|
||||
if (!same || entry.lastObservedSuspiciousSignature !== null) {
|
||||
healthState = setConfigHealthEntry(healthState, snapshot.path, nextEntry);
|
||||
await writeConfigHealthState(deps, healthState);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const suspiciousSignature = resolveSuspiciousSignature(current, suspicious);
|
||||
if (entry.lastObservedSuspiciousSignature === suspiciousSignature) {
|
||||
return;
|
||||
}
|
||||
|
||||
const backup =
|
||||
(backupBaseline?.hash ? backupBaseline : null) ??
|
||||
(await readConfigFingerprintForPath(deps, `${snapshot.path}.bak`));
|
||||
const clobberedPath = await persistClobberedConfigSnapshot({
|
||||
deps,
|
||||
configPath: snapshot.path,
|
||||
raw: snapshot.raw,
|
||||
observedAt: now,
|
||||
});
|
||||
|
||||
deps.logger.warn(`Config observe anomaly: ${snapshot.path} (${suspicious.join(", ")})`);
|
||||
await appendConfigAuditRecord(
|
||||
createConfigObserveAnomalyAuditAppendParams(deps, {
|
||||
ts: now,
|
||||
configPath: snapshot.path,
|
||||
valid: snapshot.valid,
|
||||
current,
|
||||
suspicious,
|
||||
lastKnownGood: entry.lastKnownGood,
|
||||
backup,
|
||||
clobberedPath,
|
||||
}),
|
||||
);
|
||||
|
||||
healthState = setConfigHealthEntry(
|
||||
healthState,
|
||||
snapshot.path,
|
||||
createLastObservedSuspiciousEntry(entry, suspiciousSignature),
|
||||
);
|
||||
await writeConfigHealthState(deps, healthState);
|
||||
}
|
||||
|
||||
export function observeConfigSnapshotSync(
|
||||
deps: ObserveRecoveryDeps,
|
||||
snapshot: ObserveSnapshot,
|
||||
): void {
|
||||
if (!snapshot.exists || typeof snapshot.raw !== "string") {
|
||||
return;
|
||||
}
|
||||
|
||||
const stat = deps.fs.statSync(snapshot.path, { throwIfNoEntry: false }) ?? null;
|
||||
const now = new Date().toISOString();
|
||||
const current = createConfigHealthFingerprint({
|
||||
hash: resolveConfigSnapshotHash(snapshot) ?? hashConfigRaw(snapshot.raw),
|
||||
raw: snapshot.raw,
|
||||
parsed: snapshot.parsed,
|
||||
gatewaySource: snapshot.resolved,
|
||||
stat,
|
||||
observedAt: now,
|
||||
});
|
||||
|
||||
let healthState = readConfigHealthStateSync(deps);
|
||||
const entry = getConfigHealthEntry(healthState, snapshot.path);
|
||||
const backupBaseline =
|
||||
entry.lastKnownGood ??
|
||||
readConfigFingerprintForPathSync(deps, `${snapshot.path}.bak`) ??
|
||||
undefined;
|
||||
const suspicious = resolveConfigObserveSuspiciousReasons({
|
||||
bytes: current.bytes,
|
||||
hasMeta: current.hasMeta,
|
||||
gatewayMode: current.gatewayMode,
|
||||
parsed: snapshot.parsed,
|
||||
lastKnownGood: backupBaseline,
|
||||
});
|
||||
|
||||
if (suspicious.length === 0) {
|
||||
if (snapshot.valid) {
|
||||
healthState = setConfigHealthEntry(healthState, snapshot.path, {
|
||||
...entry,
|
||||
lastKnownGood: current,
|
||||
lastObservedSuspiciousSignature: null,
|
||||
});
|
||||
writeConfigHealthStateSync(deps, healthState);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const suspiciousSignature = resolveSuspiciousSignature(current, suspicious);
|
||||
if (entry.lastObservedSuspiciousSignature === suspiciousSignature) {
|
||||
return;
|
||||
}
|
||||
|
||||
const backup =
|
||||
(backupBaseline?.hash ? backupBaseline : null) ??
|
||||
readConfigFingerprintForPathSync(deps, `${snapshot.path}.bak`);
|
||||
const clobberedPath = persistClobberedConfigSnapshotSync({
|
||||
deps,
|
||||
configPath: snapshot.path,
|
||||
raw: snapshot.raw,
|
||||
observedAt: now,
|
||||
});
|
||||
|
||||
deps.logger.warn(`Config observe anomaly: ${snapshot.path} (${suspicious.join(", ")})`);
|
||||
appendConfigAuditRecordSync(
|
||||
createConfigObserveAnomalyAuditAppendParams(deps, {
|
||||
ts: now,
|
||||
configPath: snapshot.path,
|
||||
valid: snapshot.valid,
|
||||
current,
|
||||
suspicious,
|
||||
lastKnownGood: entry.lastKnownGood,
|
||||
backup,
|
||||
clobberedPath,
|
||||
}),
|
||||
);
|
||||
|
||||
healthState = setConfigHealthEntry(
|
||||
healthState,
|
||||
snapshot.path,
|
||||
createLastObservedSuspiciousEntry(entry, suspiciousSignature),
|
||||
);
|
||||
writeConfigHealthStateSync(deps, healthState);
|
||||
}
|
||||
|
||||
export async function promoteConfigSnapshotToLastKnownGood(params: {
|
||||
deps: ObserveRecoveryDeps;
|
||||
snapshot: ConfigFileSnapshot;
|
||||
|
||||
@@ -369,18 +369,6 @@ export const ModelProviderSchema = z
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const BedrockDiscoverySchema = z
|
||||
.object({
|
||||
enabled: z.boolean().optional(),
|
||||
region: z.string().optional(),
|
||||
providerFilter: z.array(z.string()).optional(),
|
||||
refreshInterval: z.number().int().nonnegative().optional(),
|
||||
defaultContextWindow: z.number().int().positive().optional(),
|
||||
defaultMaxTokens: z.number().int().positive().optional(),
|
||||
})
|
||||
.strict()
|
||||
.optional();
|
||||
|
||||
const ModelPricingConfigSchema = z
|
||||
.object({
|
||||
enabled: z.boolean().optional(),
|
||||
|
||||
@@ -59,9 +59,3 @@ export type HookEligibilityContext = {
|
||||
note?: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type HookSnapshot = {
|
||||
hooks: Array<{ name: string; events: string[] }>;
|
||||
resolvedHooks?: Hook[];
|
||||
version?: number;
|
||||
};
|
||||
|
||||
@@ -82,15 +82,6 @@ function isKnownArchNameToken(token: string): boolean {
|
||||
|
||||
type WrapperScanDirective = "continue" | "consume-next" | "stop" | "invalid";
|
||||
|
||||
function withWindowsExeAliases(names: readonly string[]): string[] {
|
||||
const expanded = new Set<string>();
|
||||
for (const name of names) {
|
||||
expanded.add(name);
|
||||
expanded.add(`${name}.exe`);
|
||||
}
|
||||
return Array.from(expanded);
|
||||
}
|
||||
|
||||
export function isEnvAssignment(token: string): boolean {
|
||||
return /^[A-Za-z_][A-Za-z0-9_]*=.*/.test(token);
|
||||
}
|
||||
@@ -540,10 +531,6 @@ const DISPATCH_WRAPPER_SPEC_BY_NAME = new Map(
|
||||
DISPATCH_WRAPPER_SPECS.map((spec) => [spec.name, spec] as const),
|
||||
);
|
||||
|
||||
export const DISPATCH_WRAPPER_EXECUTABLES = new Set(
|
||||
withWindowsExeAliases(DISPATCH_WRAPPER_SPECS.map((spec) => spec.name)),
|
||||
);
|
||||
|
||||
export type DispatchWrapperUnwrapResult =
|
||||
| { kind: "not-wrapper" }
|
||||
| { kind: "blocked"; wrapper: string }
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
export { basenameLower, normalizeExecutableToken } from "./exec-wrapper-tokens.js";
|
||||
export * from "./dispatch-wrapper-resolution.js";
|
||||
export * from "./shell-wrapper-resolution.js";
|
||||
export * from "./exec-wrapper-trust-plan.js";
|
||||
export {
|
||||
extractEnvAssignmentKeysFromDispatchWrappers,
|
||||
isDispatchWrapperExecutable,
|
||||
resolveDispatchWrapperTrustPlan,
|
||||
unwrapDispatchWrappersForResolution,
|
||||
unwrapEnvInvocation,
|
||||
unwrapKnownDispatchWrapperInvocation,
|
||||
} from "./dispatch-wrapper-resolution.js";
|
||||
export {
|
||||
extractShellWrapperCommand,
|
||||
extractShellWrapperInlineCommand,
|
||||
hasEnvManipulationBeforeShellWrapper,
|
||||
isShellWrapperExecutable,
|
||||
isShellWrapperInvocation,
|
||||
POSIX_SHELL_WRAPPERS,
|
||||
POWERSHELL_WRAPPERS,
|
||||
resolveShellWrapperTransportArgv,
|
||||
unwrapKnownShellMultiplexerInvocation,
|
||||
} from "./shell-wrapper-resolution.js";
|
||||
export { resolveExecWrapperTrustPlan } from "./exec-wrapper-trust-plan.js";
|
||||
|
||||
@@ -46,7 +46,6 @@ import type {
|
||||
} from "./session-cost-usage.types.js";
|
||||
|
||||
export type {
|
||||
CostUsageDailyEntry,
|
||||
CostUsageSummary,
|
||||
CostUsageTotals,
|
||||
DiscoveredSession,
|
||||
|
||||
@@ -28,7 +28,7 @@ export interface PendingSessionDeliveryDrainDecision {
|
||||
bypassBackoff?: boolean;
|
||||
}
|
||||
|
||||
export const MAX_SESSION_DELIVERY_RETRIES = 5;
|
||||
const MAX_SESSION_DELIVERY_RETRIES = 5;
|
||||
|
||||
const BACKOFF_MS: readonly number[] = [5_000, 25_000, 120_000, 600_000];
|
||||
const drainInProgress = new Map<string, boolean>();
|
||||
@@ -61,7 +61,7 @@ function releaseRecoveryEntry(entryId: string): void {
|
||||
entriesInProgress.delete(entryId);
|
||||
}
|
||||
|
||||
export function computeSessionDeliveryBackoffMs(retryCount: number): number {
|
||||
function computeSessionDeliveryBackoffMs(retryCount: number): number {
|
||||
if (retryCount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ function resolveQueueEntryPaths(
|
||||
};
|
||||
}
|
||||
|
||||
export async function ensureSessionDeliveryQueueDir(stateDir?: string): Promise<string> {
|
||||
async function ensureSessionDeliveryQueueDir(stateDir?: string): Promise<string> {
|
||||
const queueDir = resolveSessionDeliveryQueueDir(stateDir);
|
||||
await fs.promises.mkdir(queueDir, { recursive: true, mode: 0o700 });
|
||||
await fs.promises.mkdir(resolveFailedDir(stateDir), { recursive: true, mode: 0o700 });
|
||||
|
||||
@@ -1,29 +1,18 @@
|
||||
export {
|
||||
ackSessionDelivery,
|
||||
enqueueSessionDelivery,
|
||||
ensureSessionDeliveryQueueDir,
|
||||
failSessionDelivery,
|
||||
loadPendingSessionDelivery,
|
||||
loadPendingSessionDeliveries,
|
||||
moveSessionDeliveryToFailed,
|
||||
resolveSessionDeliveryQueueDir,
|
||||
} from "./session-delivery-queue-storage.js";
|
||||
export type {
|
||||
QueuedSessionDelivery,
|
||||
QueuedSessionDeliveryPayload,
|
||||
SessionDeliveryContext,
|
||||
SessionDeliveryRoute,
|
||||
} from "./session-delivery-queue-storage.js";
|
||||
export {
|
||||
computeSessionDeliveryBackoffMs,
|
||||
drainPendingSessionDeliveries,
|
||||
isSessionDeliveryEligibleForRetry,
|
||||
MAX_SESSION_DELIVERY_RETRIES,
|
||||
recoverPendingSessionDeliveries,
|
||||
} from "./session-delivery-queue-recovery.js";
|
||||
export type {
|
||||
DeliverSessionDeliveryFn,
|
||||
PendingSessionDeliveryDrainDecision,
|
||||
SessionDeliveryRecoveryLogger,
|
||||
SessionDeliveryRecoverySummary,
|
||||
} from "./session-delivery-queue-recovery.js";
|
||||
export type { SessionDeliveryRecoveryLogger } from "./session-delivery-queue-recovery.js";
|
||||
|
||||
@@ -26,7 +26,6 @@ function withWindowsExeAliases(names: readonly string[]): string[] {
|
||||
}
|
||||
|
||||
export const POSIX_SHELL_WRAPPERS = new Set(POSIX_SHELL_WRAPPER_NAMES);
|
||||
export const WINDOWS_CMD_WRAPPERS = new Set(withWindowsExeAliases(WINDOWS_CMD_WRAPPER_NAMES));
|
||||
export const POWERSHELL_WRAPPERS = new Set(withWindowsExeAliases(POWERSHELL_WRAPPER_NAMES));
|
||||
|
||||
const POSIX_SHELL_WRAPPER_CANONICAL = new Set<string>(POSIX_SHELL_WRAPPER_NAMES);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
export {
|
||||
compareModelCatalogSourceAuthority,
|
||||
mergeModelCatalogRowsByAuthority,
|
||||
} from "./authority.js";
|
||||
export { mergeModelCatalogRowsByAuthority } from "./authority.js";
|
||||
export {
|
||||
buildModelCatalogMergeKey,
|
||||
buildModelCatalogRef,
|
||||
@@ -32,7 +29,6 @@ export type {
|
||||
ManifestModelCatalogPlugin,
|
||||
ManifestModelCatalogRegistry,
|
||||
ManifestModelCatalogSuppressionEntry,
|
||||
ManifestModelCatalogSuppressionPlan,
|
||||
} from "./manifest-planner.js";
|
||||
export type {
|
||||
ModelCatalog,
|
||||
|
||||
Reference in New Issue
Block a user