feat(coding-agent): add InlineExtension type for named inline extension factories (#6267)
* feat(coding-agent): add InlineExtension type for named inline extension factories * test(coding-agent): update utilities and add regression test for InlineExtension
This commit is contained in:
@@ -84,6 +84,7 @@ export type {
|
||||
GetThinkingLevelHandler,
|
||||
GrepToolCallEvent,
|
||||
GrepToolResultEvent,
|
||||
InlineExtension,
|
||||
// Events - Input
|
||||
InputEvent,
|
||||
InputEventResult,
|
||||
|
||||
@@ -1446,6 +1446,14 @@ export interface ProviderModelConfig {
|
||||
/** Extension factory function type. Supports both sync and async initialization. */
|
||||
export type ExtensionFactory = (pi: ExtensionAPI) => void | Promise<void>;
|
||||
|
||||
export type InlineExtension =
|
||||
| ExtensionFactory
|
||||
| {
|
||||
/** Display name shown as `<inline:name>` in the startup Extensions list. */
|
||||
name: string;
|
||||
factory: ExtensionFactory;
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Loaded Extension Types
|
||||
// ============================================================================
|
||||
|
||||
@@ -55,6 +55,7 @@ export {
|
||||
ExtensionRunner,
|
||||
type ExtensionShortcut,
|
||||
type ExtensionUIContext,
|
||||
type InlineExtension,
|
||||
type LoadExtensionsResult,
|
||||
type MessageRenderer,
|
||||
type RegisteredCommand,
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
loadExtensionFromFactory,
|
||||
loadExtensionsCached,
|
||||
} from "./extensions/loader.ts";
|
||||
import type { Extension, ExtensionFactory, ExtensionRuntime, LoadExtensionsResult } from "./extensions/types.ts";
|
||||
import type { Extension, ExtensionRuntime, InlineExtension, LoadExtensionsResult } from "./extensions/types.ts";
|
||||
import { DefaultPackageManager, type PathMetadata, type ResolvedResource } from "./package-manager.ts";
|
||||
import type { PromptTemplate } from "./prompt-templates.ts";
|
||||
import { loadPromptTemplates } from "./prompt-templates.ts";
|
||||
@@ -131,7 +131,7 @@ export interface DefaultResourceLoaderOptions {
|
||||
additionalSkillPaths?: string[];
|
||||
additionalPromptTemplatePaths?: string[];
|
||||
additionalThemePaths?: string[];
|
||||
extensionFactories?: ExtensionFactory[];
|
||||
extensionFactories?: InlineExtension[];
|
||||
noExtensions?: boolean;
|
||||
noSkills?: boolean;
|
||||
noPromptTemplates?: boolean;
|
||||
@@ -169,7 +169,7 @@ export class DefaultResourceLoader implements ResourceLoader {
|
||||
private additionalSkillPaths: string[];
|
||||
private additionalPromptTemplatePaths: string[];
|
||||
private additionalThemePaths: string[];
|
||||
private extensionFactories: ExtensionFactory[];
|
||||
private extensionFactories: InlineExtension[];
|
||||
private noExtensions: boolean;
|
||||
private noSkills: boolean;
|
||||
private noPromptTemplates: boolean;
|
||||
@@ -896,8 +896,10 @@ export class DefaultResourceLoader implements ResourceLoader {
|
||||
const extensions: Extension[] = [];
|
||||
const errors: Array<{ path: string; error: string }> = [];
|
||||
|
||||
for (const [index, factory] of this.extensionFactories.entries()) {
|
||||
const extensionPath = `<inline:${index + 1}>`;
|
||||
for (const [index, input] of this.extensionFactories.entries()) {
|
||||
const isNamed = typeof input !== "function";
|
||||
const factory = isNamed ? input.factory : input;
|
||||
const extensionPath = `<inline:${isNamed ? input.name : index + 1}>`;
|
||||
try {
|
||||
const extension = await loadExtensionFromFactory(factory, this.cwd, this.eventBus, runtime, extensionPath);
|
||||
extensions.push(extension);
|
||||
|
||||
@@ -100,6 +100,7 @@ export type {
|
||||
ExtensionCommandContext,
|
||||
ExtensionContext,
|
||||
ExtensionFactory,
|
||||
InlineExtension,
|
||||
SlashCommandInfo,
|
||||
SlashCommandSource,
|
||||
ToolDefinition,
|
||||
|
||||
@@ -100,6 +100,7 @@ export type {
|
||||
ExtensionWidgetOptions,
|
||||
FindToolCallEvent,
|
||||
GrepToolCallEvent,
|
||||
InlineExtension,
|
||||
InputEvent,
|
||||
InputEventResult,
|
||||
InputSource,
|
||||
|
||||
@@ -25,7 +25,7 @@ import {
|
||||
import { formatNoModelsAvailableMessage } from "./core/auth-guidance.ts";
|
||||
import { AuthStorage } from "./core/auth-storage.ts";
|
||||
import { exportFromFile } from "./core/export-html/index.ts";
|
||||
import type { ExtensionFactory } from "./core/extensions/types.ts";
|
||||
import type { InlineExtension } from "./core/extensions/types.ts";
|
||||
import { applyHttpProxySettings, configureHttpDispatcher } from "./core/http-dispatcher.ts";
|
||||
import type { ModelRegistry } from "./core/model-registry.ts";
|
||||
import { resolveCliModel, resolveModelScope, type ScopedModel } from "./core/model-resolver.ts";
|
||||
@@ -462,7 +462,7 @@ async function promptForMissingSessionCwd(
|
||||
}
|
||||
|
||||
export interface MainOptions {
|
||||
extensionFactories?: ExtensionFactory[];
|
||||
extensionFactories?: InlineExtension[];
|
||||
}
|
||||
|
||||
export async function main(args: string[], options?: MainOptions) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
type SelfUpdatePackageTarget,
|
||||
VERSION,
|
||||
} from "./config.ts";
|
||||
import type { ExtensionFactory } from "./core/extensions/types.ts";
|
||||
import type { InlineExtension } from "./core/extensions/types.ts";
|
||||
import { DefaultPackageManager } from "./core/package-manager.ts";
|
||||
import { type AppMode, resolveProjectTrusted } from "./core/project-trust.ts";
|
||||
import { DefaultResourceLoader } from "./core/resource-loader.ts";
|
||||
@@ -484,7 +484,7 @@ function prepareWindowsNpmSelfUpdate(): void {
|
||||
}
|
||||
|
||||
export interface PackageCommandRuntimeOptions {
|
||||
extensionFactories?: ExtensionFactory[];
|
||||
extensionFactories?: InlineExtension[];
|
||||
}
|
||||
|
||||
interface CommandSettingsResult {
|
||||
@@ -507,7 +507,7 @@ async function createCommandSettingsManager(options: {
|
||||
agentDir: string;
|
||||
projectTrustOverride?: boolean;
|
||||
useSavedProjectTrustOnly?: boolean;
|
||||
extensionFactories?: ExtensionFactory[];
|
||||
extensionFactories?: InlineExtension[];
|
||||
}): Promise<CommandSettingsResult> {
|
||||
const settingsManager = SettingsManager.create(options.cwd, options.agentDir, { projectTrusted: false });
|
||||
const projectTrustWarnings: string[] = [];
|
||||
|
||||
Reference in New Issue
Block a user