UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

244 lines (243 loc) • 8.69 kB
import { n as tryProcessCwd } from "./safe-cwd-CZqaxroH.mjs"; import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs"; import "./paths-DAcAg5aV.mjs"; import { n as getSecretRedactionRegistryRevision } from "./secret-redaction-registry-Cy0acctn.mjs"; import { a as memoizeFrozenPlainDataProjection } from "./immutable-data-Y7xVjZoy.mjs"; import { n as resolveCommitHash } from "./git-commit-D8Q_PzK2.mjs"; import { t as VERSION } from "./version-GlxUMdxI.mjs"; import { c as loadPluginMetadataSnapshot } from "./plugin-metadata-snapshot-By9ySblt.mjs"; import { l as getActivePluginRegistry, m as listImportedRuntimePluginIds } from "./runtime-ezCEpumg.mjs"; import { a as redactPathForSupport, p as sanitizeSupportSnapshotValue } from "./diagnostic-support-redaction-CA1pCV-N.mjs"; import { r as resolveOsSummary } from "./os-summary-CMRUbVgk.mjs"; import { t as redactConfigObject } from "./redact-snapshot-HHllfRSn.mjs"; //#region src/trajectory/metadata.ts const redactTrajectoryConfig = memoizeFrozenPlainDataProjection((e) => redactConfigObject(e)); function toSortedUniqueStrings(e) { if (!e || e.length === 0) return; return [...new Set(e)].filter((e) => typeof e === "string").map((e) => e.trim()).filter(Boolean).toSorted((e, t) => e.localeCompare(t)); } function buildPluginsFromActiveRegistry() { const e = getActivePluginRegistry(); if (!e || e.plugins.length === 0) return null; return { source: "active-registry", importedRuntimePluginIds: listImportedRuntimePluginIds(), entries: e.plugins.map((e) => ({ id: e.id, name: e.name, version: e.version, description: e.description, origin: e.origin, enabled: e.enabled, explicitlyEnabled: e.explicitlyEnabled, activated: e.activated, imported: e.imported, activationSource: e.activationSource, activationReason: e.activationReason, status: e.status, error: e.error, format: e.format, bundleFormat: e.bundleFormat, bundleCapabilities: e.bundleCapabilities, kind: e.kind, source: e.source, rootDir: e.rootDir, workspaceDir: e.workspaceDir, toolNames: toSortedUniqueStrings(e.toolNames), hookNames: toSortedUniqueStrings(e.hookNames), channelIds: toSortedUniqueStrings(e.channelIds), cliBackendIds: toSortedUniqueStrings(e.cliBackendIds), providerIds: toSortedUniqueStrings(e.providerIds), speechProviderIds: toSortedUniqueStrings(e.speechProviderIds), realtimeTranscriptionProviderIds: toSortedUniqueStrings(e.realtimeTranscriptionProviderIds), realtimeVoiceProviderIds: toSortedUniqueStrings(e.realtimeVoiceProviderIds), mediaUnderstandingProviderIds: toSortedUniqueStrings(e.mediaUnderstandingProviderIds), imageGenerationProviderIds: toSortedUniqueStrings(e.imageGenerationProviderIds), videoGenerationProviderIds: toSortedUniqueStrings(e.videoGenerationProviderIds), musicGenerationProviderIds: toSortedUniqueStrings(e.musicGenerationProviderIds), webFetchProviderIds: toSortedUniqueStrings(e.webFetchProviderIds), webSearchProviderIds: toSortedUniqueStrings(e.webSearchProviderIds), agentHarnessIds: toSortedUniqueStrings(e.agentHarnessIds) })).toSorted((e, t) => e.id.localeCompare(t.id)) }; } function buildPluginsFromManifest(e) { return { source: "manifest-registry", entries: (e.pluginMetadataSnapshot ?? loadPluginMetadataSnapshot({ config: e.config ?? {}, workspaceDir: e.workspaceDir, env: e.env ?? process.env })).plugins.map((e) => ({ id: e.id, name: e.name, version: e.version, description: e.description, origin: e.origin, enabledByDefault: e.enabledByDefault, format: e.format, bundleFormat: e.bundleFormat, bundleCapabilities: toSortedUniqueStrings(e.bundleCapabilities), kind: e.kind, source: e.source, rootDir: e.rootDir, workspaceDir: e.workspaceDir, channels: toSortedUniqueStrings(e.channels), providers: toSortedUniqueStrings(e.providers), cliBackends: toSortedUniqueStrings(e.cliBackends), hooks: toSortedUniqueStrings(e.hooks), skills: toSortedUniqueStrings(e.skills) })).toSorted((e, t) => e.id.localeCompare(t.id)) }; } const skillCaptures = /* @__PURE__ */ new Map(); function captureResolvedSkill(e, t) { return { id: e.name, name: e.name, description: e.description, filePath: redactPathForSupport(e.filePath, t), baseDir: redactPathForSupport(e.baseDir, t), source: e.source, sourceInfo: sanitizeSupportSnapshotValue(e.sourceInfo, t), disableModelInvocation: e.disableModelInvocation, available: true }; } function isFrozenDataRecord(e) { const t = Object.getPrototypeOf(e); return Object.isFrozen(e) && (t === Object.prototype || t === null) && Object.values(Object.getOwnPropertyDescriptors(e)).every((e) => "value" in e); } function buildSkillsCapture(e, t) { if (!e) return; const n = e.resolvedSkills?.filter((e) => typeof e.name === "string" && e.name.length > 0) ?? []; const r = getSecretRedactionRegistryRevision(); const i = t.env.HOME; const a = t.env.USERPROFILE; const o = tryProcessCwd(); const s = JSON.stringify([ r, t.stateDir, i, a, o ]); const isCurrentScope = () => getSecretRedactionRegistryRevision() === r && t.env.HOME === i && t.env.USERPROFILE === a && tryProcessCwd() === o; let c = skillCaptures.get(s); if (!c) { c = /* @__PURE__ */ new WeakMap(); skillCaptures.set(s, c); if (skillCaptures.size > 8) skillCaptures.delete(skillCaptures.keys().next().value); } const l = n.length > 0 ? n.map((e) => { const n = c.get(e); if (n && isCurrentScope()) return n; const r = captureResolvedSkill(e, t); if (isCurrentScope() && isFrozenDataRecord(e) && e.sourceInfo && isFrozenDataRecord(e.sourceInfo) && !t.identifierKeys && Object.values(e.sourceInfo).every((e) => e === null || typeof e !== "object" && typeof e !== "function")) { Object.freeze(r.sourceInfo); c.set(e, Object.freeze(r)); } return r; }) : e.skills.filter((e) => typeof e.name === "string" && e.name.length > 0).map((e) => ({ id: e.name, name: e.name, primaryEnv: e.primaryEnv, requiredEnv: e.requiredEnv, available: true })); return { snapshotVersion: e.version, skillFilter: toSortedUniqueStrings(e.skillFilter), entries: l.toSorted((e, t) => (e.name ?? "").localeCompare(t.name ?? "")) }; } function buildTrajectoryRunMetadata(e) { const t = e.env ?? process.env; const n = { env: t, stateDir: resolveStateDir(t) }; const r = resolveOsSummary(); const i = buildPluginsFromActiveRegistry() ?? buildPluginsFromManifest({ config: e.config, pluginMetadataSnapshot: e.pluginMetadataSnapshot, workspaceDir: e.workspaceDir, env: t }); return { capturedAt: (/* @__PURE__ */ new Date()).toISOString(), harness: { type: "openclaw", name: "OpenClaw", version: VERSION, gitSha: resolveCommitHash({ cwd: e.workspaceDir, env: t, moduleUrl: import.meta.url }) ?? void 0, os: r, runtime: { node: process.version }, invocation: sanitizeSupportSnapshotValue([...process.argv], n, "programArguments"), entrypoint: process.argv[1] ? redactPathForSupport(process.argv[1], n) : void 0, workspaceDir: redactPathForSupport(e.workspaceDir, n), sessionFile: e.sessionFile ? redactPathForSupport(e.sessionFile, n) : void 0 }, model: { provider: e.provider, name: e.modelId, api: e.modelApi, fastMode: e.fastMode ?? false, thinkLevel: e.thinkLevel, reasoningLevel: e.reasoningLevel ?? "off" }, config: { redacted: e.config ? redactTrajectoryConfig(e.config) : void 0, runtime: { timeoutMs: e.timeoutMs, trigger: e.trigger, disableTools: e.disableTools ?? false, toolResultFormat: e.toolResultFormat, toolsAllow: toSortedUniqueStrings(e.toolsAllow) } }, plugins: i, skills: buildSkillsCapture(e.skillsSnapshot, n), prompting: { skillsPrompt: e.skillsSnapshot?.prompt, userPromptPrefixText: e.userPromptPrefixText, systemPromptReport: e.systemPromptReport }, redaction: { config: { mode: "redactConfigObject", secretsMasked: true }, payloads: { mode: "sanitizeDiagnosticPayload", credentialsRemoved: true, imageDataRedacted: true }, harness: { mode: "diagnostic-support-redaction", programArgumentsRedacted: true, localPathsRedacted: true } }, metadata: { sessionKey: e.sessionKey, agentId: e.agentId, messageProvider: e.messageProvider, messageChannel: e.messageChannel } }; } function buildTrajectoryArtifacts(e) { const { status: t, ...n } = e; return { capturedAt: (/* @__PURE__ */ new Date()).toISOString(), finalStatus: t, ...n }; } //#endregion export { buildTrajectoryRunMetadata as n, buildTrajectoryArtifacts as t };