Skip to content

Commit 95d7343

Browse files
committed
refactor(plugin-sdk): expose prepared runtime helper surfaces
1 parent 47158d6 commit 95d7343

7 files changed

Lines changed: 49 additions & 2 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
25d5e7d7532d99d06187813e1cf75d3192fb2bf330862bfd1d4d4a50c91c77c9 plugin-sdk-api-baseline.json
2-
9f9758f36694c4004ab8c2fb772815c91cc2035de872a0e53f053537b2156910 plugin-sdk-api-baseline.jsonl
1+
28e280d21693216c99cfa8da553589b41741d37c0ada956e316ee01d3d6c202c plugin-sdk-api-baseline.json
2+
633dae33da97f6a073c5561709c57d5c0b7ff67af0512d0261f05455c24b38de plugin-sdk-api-baseline.jsonl

scripts/lib/plugin-sdk-doc-metadata.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ export const pluginSdkDocMetadata = {
101101
"runtime-store": {
102102
category: "runtime",
103103
},
104+
"agent-runtime": {
105+
category: "runtime",
106+
},
107+
"speech-core": {
108+
category: "provider",
109+
},
110+
"tts-runtime": {
111+
category: "runtime",
112+
},
104113
"allow-from": {
105114
category: "utilities",
106115
},

src/plugin-sdk/agent-runtime.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export * from "../agents/identity.js";
1010
export * from "../agents/model-auth-markers.js";
1111
export * from "../agents/model-auth.js";
1212
export * from "../agents/model-catalog.js";
13+
export * from "../agents/model-catalog-scope.js";
1314
export * from "../agents/model-selection.js";
1415
export * from "../agents/simple-completion-runtime.js";
1516
export * from "../agents/pi-embedded-block-chunker.js";

src/plugin-sdk/channel-entry-contract.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { createRequire } from "node:module";
33
import path from "node:path";
44
import { fileURLToPath } from "node:url";
55
import { emptyChannelConfigSchema } from "../channels/plugins/config-schema.js";
6+
import type { ChannelOutboundAdapter } from "../channels/plugins/types.adapters.js";
67
import type { ChannelConfigSchema } from "../channels/plugins/types.config.js";
78
import type { ChannelLegacyStateMigrationPlan } from "../channels/plugins/types.core.js";
89
import type { ChannelPlugin } from "../channels/plugins/types.plugin.js";
@@ -52,6 +53,7 @@ type DefineBundledChannelEntryOptions<TPlugin = ChannelPlugin> = {
5253
description: string;
5354
importMetaUrl: string;
5455
plugin: BundledEntryModuleRef;
56+
outbound?: BundledEntryModuleRef;
5557
secrets?: BundledEntryModuleRef;
5658
configSchema?: ChannelEntryConfigSchema<TPlugin> | (() => ChannelEntryConfigSchema<TPlugin>);
5759
runtime?: BundledEntryModuleRef;
@@ -108,6 +110,9 @@ export type BundledChannelEntryContract<TPlugin = ChannelPlugin> = {
108110
features?: BundledChannelEntryFeatures;
109111
register: (api: OpenClawPluginApi) => void;
110112
loadChannelPlugin: (options?: BundledEntryModuleLoadOptions) => TPlugin;
113+
loadChannelOutbound?: (
114+
options?: BundledEntryModuleLoadOptions,
115+
) => ChannelOutboundAdapter | undefined;
111116
loadChannelSecrets?: (
112117
options?: BundledEntryModuleLoadOptions,
113118
) => ChannelPlugin["secrets"] | undefined;
@@ -435,6 +440,7 @@ export function defineBundledChannelEntry<TPlugin = ChannelPlugin>({
435440
description,
436441
importMetaUrl,
437442
plugin,
443+
outbound,
438444
secrets,
439445
configSchema,
440446
runtime,
@@ -449,6 +455,14 @@ export function defineBundledChannelEntry<TPlugin = ChannelPlugin>({
449455
: ((configSchema ?? emptyChannelConfigSchema()) as ChannelEntryConfigSchema<TPlugin>);
450456
const loadChannelPlugin = (options?: BundledEntryModuleLoadOptions) =>
451457
loadBundledEntryExportSync<TPlugin>(importMetaUrl, plugin, options);
458+
const loadChannelOutbound = outbound
459+
? (options?: BundledEntryModuleLoadOptions) =>
460+
loadBundledEntryExportSync<ChannelOutboundAdapter | undefined>(
461+
importMetaUrl,
462+
outbound,
463+
options,
464+
)
465+
: undefined;
452466
const loadChannelSecrets = secrets
453467
? (options?: BundledEntryModuleLoadOptions) =>
454468
loadBundledEntryExportSync<ChannelPlugin["secrets"] | undefined>(
@@ -511,6 +525,7 @@ export function defineBundledChannelEntry<TPlugin = ChannelPlugin>({
511525
profile("bundled-register:registerFull", () => registerFull?.(api));
512526
},
513527
loadChannelPlugin,
528+
...(loadChannelOutbound ? { loadChannelOutbound } : {}),
514529
...(loadChannelSecrets ? { loadChannelSecrets } : {}),
515530
...(loadChannelAccountInspector ? { loadChannelAccountInspector } : {}),
516531
...(setChannelRuntime ? { setChannelRuntime } : {}),

src/plugin-sdk/speech-core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export { parseTtsDirectives } from "../tts/directives.js";
3737
export {
3838
canonicalizeSpeechProviderId,
3939
getSpeechProvider,
40+
listLoadedSpeechProviders,
4041
listSpeechProviders,
4142
normalizeSpeechProviderId,
4243
} from "../tts/provider-registry.js";

src/plugin-sdk/tts-runtime.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function loadFacadeModule(): FacadeModule {
3333
});
3434
}
3535

36+
export function prewarmTtsRuntimeFacade(): void {
37+
loadFacadeModule();
38+
}
39+
3640
export const _test: FacadeModule["_test"] = createLazyFacadeObjectValue(
3741
() => loadFacadeModule()._test,
3842
);

src/tts/provider-registry.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { OpenClawConfig } from "../config/types.js";
2+
import { getActiveRuntimePluginRegistry } from "../plugins/active-runtime-registry.js";
23
import {
34
resolvePluginCapabilityProvider,
45
resolvePluginCapabilityProviders,
@@ -17,6 +18,10 @@ function resolveSpeechProviderPluginEntries(cfg?: OpenClawConfig): SpeechProvide
1718
});
1819
}
1920

21+
function resolveLoadedSpeechProviderPluginEntries(): SpeechProviderPlugin[] {
22+
return (getActiveRuntimePluginRegistry()?.speechProviders ?? []).map((entry) => entry.provider);
23+
}
24+
2025
const defaultSpeechProviderRegistryResolver: SpeechProviderRegistryResolver = {
2126
getProvider: (providerId, cfg) =>
2227
resolvePluginCapabilityProvider({
@@ -31,7 +36,19 @@ const defaultSpeechProviderRegistry = createSpeechProviderRegistry(
3136
defaultSpeechProviderRegistryResolver,
3237
);
3338

39+
const loadedSpeechProviderRegistry = createSpeechProviderRegistry({
40+
getProvider: (providerId) =>
41+
resolveLoadedSpeechProviderPluginEntries().find((provider) => {
42+
if (provider.id === providerId) {
43+
return true;
44+
}
45+
return provider.aliases?.includes(providerId) ?? false;
46+
}),
47+
listProviders: () => resolveLoadedSpeechProviderPluginEntries(),
48+
});
49+
3450
export const listSpeechProviders = defaultSpeechProviderRegistry.listSpeechProviders;
51+
export const listLoadedSpeechProviders = loadedSpeechProviderRegistry.listSpeechProviders;
3552
export const getSpeechProvider = defaultSpeechProviderRegistry.getSpeechProvider;
3653
export const canonicalizeSpeechProviderId =
3754
defaultSpeechProviderRegistry.canonicalizeSpeechProviderId;

0 commit comments

Comments
 (0)