83
}
84
85
>
export async function publishLocalAgentHostEndpointMetadata(userDataPath: string, metadata: ILocalAgentHostEndpointMetadata): Promise<void> {
localAgentHostMetadata.ts
86
>
const metadataPath = getMetadataPath(userDataPath);
87
>
const temporaryPath = `${metadataPath}.${metadata.instanceId}.tmp`;
88
>
const entries = readMetadata(metadataPath).filter(entry => entry.pid !== metadata.pid || entry.type !== metadata.type);
89
>
entries.push(metadata);
90
>
const handle = await fs.promises.open(temporaryPath, 'wx', 0o600);
91
>
try {
92
>
await handle.writeFile(JSON.stringify(entries), 'utf8');
93
>
await handle.sync();
94
>
} finally {
95
>
await handle.close();
96
>
}
97
>
98
>
try {
99
>
await fs.promises.rename(temporaryPath, metadataPath);
100
>
} finally {
101
>
await fs.promises.rm(temporaryPath, { force: true });
102
>
}
103
>
}
104
105
export function cleanupLocalAgentHostEndpointMetadataSync(userDataPath: string, owner: ILocalAgentHostEndpointMetadata): void {