Repository navigation
Expand file tree
/
Copy pathprovider-device-runtimes.ts
More file actions
45 lines (42 loc) · 1.93 KB
/
Copy pathprovider-device-runtimes.ts
File metadata and controls
45 lines (42 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { ProviderDeviceRuntime } from '@agent-device/contracts/device';
import type { PluginInventoryEntry } from '@agent-device/contracts/plugin-inventory';
import type { PlatformRuntimeProviderRegistration } from './platform-runtime-gateway.ts';
import { builtinProviderCandidates } from './builtin-provider-plugins.ts';
import { PROVIDER_PLUGIN_POLICY } from './provider-plugin-policy.ts';
export type DefaultProviderDeviceRuntimeEnv = NodeJS.ProcessEnv;
export type ProviderRuntimeComposition = Readonly<{
runtimes: readonly ProviderDeviceRuntime[];
platformModules: readonly PlatformRuntimeProviderRegistration[];
/** Every plugin the registry saw, built-in or not, active or failed. */
inventory: readonly PluginInventoryEntry[];
/** Every provider id a plugin claimed, including failed plugins and unconfigured built-ins. */
claimedProviders: readonly string[];
/** Shuts down every registered runtime, then its plugin's cleanup. */
shutdown(): Promise<void>;
}>;
/**
* The daemon's providers from one registry: built-in providers, then the plugin store. A plugin
* that cannot register is listed in the inventory; the others still register.
*/
export async function createDaemonProviderRuntimeComposition(
env: DefaultProviderDeviceRuntimeEnv = process.env,
): Promise<ProviderRuntimeComposition> {
const { startDaemonProviderRegistry } = await import('@agent-device/plugins/load');
const registry = await startDaemonProviderRegistry({
env,
builtin: builtinProviderCandidates(env),
policy: PROVIDER_PLUGIN_POLICY,
});
return Object.freeze({
runtimes: Object.freeze(registry.registrations.map(({ runtime }) => runtime)),
platformModules: Object.freeze(
registry.registrations.map(({ runtime, platformModule }) => ({
runtime,
module: platformModule,
})),
),
inventory: registry.inventory,
claimedProviders: registry.claimedProviders,
shutdown: registry.close,
});
}