zephyr-agent
Version:
Zephyr plugin agent
69 lines (68 loc) • 2.59 kB
JavaScript
import "node:module";
import { createHash } from "node:crypto";
import { ZEPHYR_MANIFEST_VERSION } from "zephyr-edge-contract";
import { ze_log } from "../logging/index.mjs";
import { collectZEPublicVars } from "../env-variables/index.mjs";
function convertResolvedDependencies(dependencies) {
return Object.fromEntries(dependencies.map((dep)=>[
dep.name,
{
name: dep.name,
application_uid: dep.application_uid,
remote_entry_url: dep.remote_entry_url,
manifest_url: dep.manifest_url,
default_url: dep.default_url,
library_type: dep.library_type
}
]));
}
function createZephyrManifest(dependencies, includeEnvVars = true) {
const content = createManifestContent(dependencies, includeEnvVars);
const asset = createManifestAsset(content);
return {
content,
asset
};
}
function createManifestContent(dependencies, includeEnvVars = true) {
ze_log.manifest('Creating manifest with dependencies:', dependencies?.length || 0);
const dependenciesMap = {};
dependencies.forEach((dep)=>{
dependenciesMap[dep.name] = {
name: dep.name,
application_uid: dep.application_uid,
remote_entry_url: dep.remote_entry_url,
manifest_url: dep.manifest_url,
default_url: dep.default_url,
library_type: dep.library_type
};
});
const manifest = {
version: ZEPHYR_MANIFEST_VERSION,
timestamp: new Date().toISOString(),
dependencies: dependenciesMap,
zeVars: {}
};
if (includeEnvVars) {
const envVars = collectZEPublicVars(process.env);
if (Object.keys(envVars).length > 0) {
manifest.zeVars = envVars;
ze_log.manifest(`Environment variables: ${Object.keys(envVars).length} ZE_PUBLIC_* vars`);
}
}
ze_log.manifest(`Dependencies: ${Object.keys(dependenciesMap).join(', ') || 'none'}`);
return JSON.stringify(manifest, null, 2);
}
function createManifestAsset(content) {
const contentBuffer = Buffer.from(content);
const hash = createHash('sha256').update(content + 'zephyr-manifest.json').digest('hex');
return {
path: 'zephyr-manifest.json',
extname: '.json',
hash,
size: contentBuffer.length,
buffer: contentBuffer
};
}
export { convertResolvedDependencies, createManifestAsset, createManifestContent, createZephyrManifest };
//# sourceMappingURL=ze-create-manifest.mjs.map