mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 08:03:39 +00:00
Merge pull request #513 from austinm911/fix/async-extension-factories
feat(extensions): support async extension factory functions
This commit is contained in:
commit
10e651f99b
3 changed files with 8 additions and 8 deletions
|
|
@ -313,7 +313,7 @@ async function loadExtensionWithBun(
|
|||
setFlagValue,
|
||||
} = createExtensionAPI(handlers, tools, cwd, extensionPath, eventBus, sharedUI);
|
||||
|
||||
factory(api);
|
||||
await factory(api);
|
||||
|
||||
return {
|
||||
extension: {
|
||||
|
|
@ -401,7 +401,7 @@ async function loadExtension(
|
|||
setFlagValue,
|
||||
} = createExtensionAPI(handlers, tools, cwd, extensionPath, eventBus, sharedUI);
|
||||
|
||||
factory(api);
|
||||
await factory(api);
|
||||
|
||||
return {
|
||||
extension: {
|
||||
|
|
@ -436,13 +436,13 @@ async function loadExtension(
|
|||
/**
|
||||
* Create a LoadedExtension from an inline factory function.
|
||||
*/
|
||||
export function loadExtensionFromFactory(
|
||||
export async function loadExtensionFromFactory(
|
||||
factory: ExtensionFactory,
|
||||
cwd: string,
|
||||
eventBus: EventBus,
|
||||
sharedUI: { ui: ExtensionUIContext; hasUI: boolean },
|
||||
name = "<inline>",
|
||||
): LoadedExtension {
|
||||
): Promise<LoadedExtension> {
|
||||
const handlers = new Map<string, HandlerFn[]>();
|
||||
const tools = new Map<string, RegisteredTool>();
|
||||
const {
|
||||
|
|
@ -464,7 +464,7 @@ export function loadExtensionFromFactory(
|
|||
setFlagValue,
|
||||
} = createExtensionAPI(handlers, tools, cwd, name, eventBus, sharedUI);
|
||||
|
||||
factory(api);
|
||||
await factory(api);
|
||||
|
||||
return {
|
||||
path: name,
|
||||
|
|
|
|||
|
|
@ -649,8 +649,8 @@ export interface ExtensionAPI {
|
|||
events: EventBus;
|
||||
}
|
||||
|
||||
/** Extension factory function type. */
|
||||
export type ExtensionFactory = (pi: ExtensionAPI) => void;
|
||||
/** Extension factory function type. Supports both sync and async initialization. */
|
||||
export type ExtensionFactory = (pi: ExtensionAPI) => void | Promise<void>;
|
||||
|
||||
// ============================================================================
|
||||
// Loaded Extension Types
|
||||
|
|
|
|||
|
|
@ -488,7 +488,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|||
};
|
||||
for (let i = 0; i < options.extensions.length; i++) {
|
||||
const factory = options.extensions[i];
|
||||
const loaded = loadExtensionFromFactory(factory, cwd, eventBus, uiHolder, `<inline-${i}>`);
|
||||
const loaded = await loadExtensionFromFactory(factory, cwd, eventBus, uiHolder, `<inline-${i}>`);
|
||||
extensionsResult.extensions.push(loaded);
|
||||
}
|
||||
// Extend setUIContext to update inline extensions too
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue