@stina/extension-api 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,4 +14,4 @@ export {
14
14
  __require,
15
15
  generateMessageId
16
16
  };
17
- //# sourceMappingURL=chunk-WIDGIYRV.js.map
17
+ //# sourceMappingURL=chunk-U3PEHSBG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/messages.ts"],"sourcesContent":["/**\n * Message protocol between Extension Host and Extension Workers\n */\n\nimport type {\n ChatMessage,\n ChatOptions,\n GetModelsOptions,\n StreamEvent,\n ToolResult,\n ActionResult,\n ModelInfo,\n SchedulerFirePayload,\n} from './types.js'\n\n// ============================================================================\n// Host → Worker Messages\n// ============================================================================\n\nexport type HostToWorkerMessage =\n | ActivateMessage\n | DeactivateMessage\n | SettingsChangedMessage\n | SchedulerFireMessage\n | ProviderChatRequestMessage\n | ProviderModelsRequestMessage\n | ToolExecuteRequestMessage\n | ActionExecuteRequestMessage\n | ResponseMessage\n | StreamingFetchChunkMessage\n | BackgroundTaskStartMessage\n | BackgroundTaskStopMessage\n\nexport interface ActivateMessage {\n type: 'activate'\n id: string\n payload: {\n extensionId: string\n extensionVersion: string\n storagePath: string\n permissions: string[]\n settings: Record<string, unknown>\n }\n}\n\nexport interface DeactivateMessage {\n type: 'deactivate'\n id: string\n}\n\nexport interface SettingsChangedMessage {\n type: 'settings-changed'\n id: string\n payload: {\n key: string\n value: unknown\n }\n}\n\nexport interface SchedulerFireMessage {\n type: 'scheduler-fire'\n id: string\n payload: SchedulerFirePayload\n}\n\nexport interface ProviderChatRequestMessage {\n type: 'provider-chat-request'\n id: string\n payload: {\n providerId: string\n messages: ChatMessage[]\n options: ChatOptions\n }\n}\n\nexport interface ProviderModelsRequestMessage {\n type: 'provider-models-request'\n id: string\n payload: {\n providerId: string\n options?: GetModelsOptions\n }\n}\n\nexport interface ToolExecuteRequestMessage {\n type: 'tool-execute-request'\n id: string\n payload: {\n toolId: string\n params: Record<string, unknown>\n /** User ID if the tool is executed in a user context */\n userId?: string\n }\n}\n\nexport interface ActionExecuteRequestMessage {\n type: 'action-execute-request'\n id: string\n payload: {\n actionId: string\n params: Record<string, unknown>\n /** User ID if the action is executed in a user context */\n userId?: string\n }\n}\n\nexport interface ResponseMessage {\n type: 'response'\n id: string\n payload: {\n requestId: string\n success: boolean\n data?: unknown\n error?: string\n }\n}\n\n/**\n * Message sent from host to worker with streaming fetch data chunks.\n * Used for streaming network responses (e.g., NDJSON streams from Ollama).\n */\nexport interface StreamingFetchChunkMessage {\n type: 'streaming-fetch-chunk'\n id: string\n payload: {\n requestId: string\n chunk: string\n done: boolean\n error?: string\n }\n}\n\n/**\n * Message sent from host to worker to start a registered background task.\n */\nexport interface BackgroundTaskStartMessage {\n type: 'background-task-start'\n id: string\n payload: {\n taskId: string\n }\n}\n\n/**\n * Message sent from host to worker to stop a running background task.\n */\nexport interface BackgroundTaskStopMessage {\n type: 'background-task-stop'\n id: string\n payload: {\n taskId: string\n }\n}\n\n// ============================================================================\n// Worker → Host Messages\n// ============================================================================\n\nexport type WorkerToHostMessage =\n | ReadyMessage\n | RequestMessage\n | ProviderRegisteredMessage\n | ToolRegisteredMessage\n | ActionRegisteredMessage\n | StreamEventMessage\n | LogMessage\n | ProviderModelsResponseMessage\n | ToolExecuteResponseMessage\n | ActionExecuteResponseMessage\n | StreamingFetchAckMessage\n | BackgroundTaskRegisteredMessage\n | BackgroundTaskStatusMessage\n | BackgroundTaskHealthMessage\n\nexport interface ReadyMessage {\n type: 'ready'\n}\n\n/**\n * Message sent from worker to host to acknowledge receipt of a streaming fetch chunk.\n * This enables backpressure control to prevent unbounded memory growth.\n */\nexport interface StreamingFetchAckMessage {\n type: 'streaming-fetch-ack'\n payload: {\n requestId: string\n }\n}\n\nexport interface RequestMessage {\n type: 'request'\n id: string\n method: RequestMethod\n payload: unknown\n}\n\nexport type RequestMethod =\n | 'network.fetch'\n | 'network.fetch-stream'\n | 'settings.getAll'\n | 'settings.get'\n | 'settings.set'\n | 'user.getProfile'\n | 'events.emit'\n | 'scheduler.schedule'\n | 'scheduler.cancel'\n | 'chat.appendInstruction'\n | 'database.execute'\n | 'storage.get'\n | 'storage.set'\n | 'storage.delete'\n | 'storage.keys'\n | 'storage.getForUser'\n | 'storage.setForUser'\n | 'storage.deleteForUser'\n | 'storage.keysForUser'\n\nexport interface ProviderRegisteredMessage {\n type: 'provider-registered'\n payload: {\n id: string\n name: string\n }\n}\n\nexport interface ToolRegisteredMessage {\n type: 'tool-registered'\n payload: {\n id: string\n name: string\n description: string\n parameters?: Record<string, unknown>\n }\n}\n\nexport interface ActionRegisteredMessage {\n type: 'action-registered'\n payload: {\n id: string\n }\n}\n\nexport interface StreamEventMessage {\n type: 'stream-event'\n payload: {\n requestId: string\n event: StreamEvent\n }\n}\n\nexport interface ProviderModelsResponseMessage {\n type: 'provider-models-response'\n payload: {\n requestId: string\n models: ModelInfo[]\n error?: string\n }\n}\n\nexport interface ToolExecuteResponseMessage {\n type: 'tool-execute-response'\n payload: {\n requestId: string\n result: ToolResult\n error?: string\n }\n}\n\nexport interface ActionExecuteResponseMessage {\n type: 'action-execute-response'\n payload: {\n requestId: string\n result: ActionResult\n error?: string\n }\n}\n\nexport interface LogMessage {\n type: 'log'\n payload: {\n level: 'debug' | 'info' | 'warn' | 'error'\n message: string\n data?: Record<string, unknown>\n }\n}\n\n/**\n * Message sent from worker to host when a background task is registered.\n */\nexport interface BackgroundTaskRegisteredMessage {\n type: 'background-task-registered'\n payload: {\n taskId: string\n name: string\n userId: string\n restartPolicy: {\n type: 'always' | 'on-failure' | 'never'\n maxRestarts?: number\n initialDelayMs?: number\n maxDelayMs?: number\n backoffMultiplier?: number\n }\n payload?: Record<string, unknown>\n }\n}\n\n/**\n * Message sent from worker to host with background task status updates.\n */\nexport interface BackgroundTaskStatusMessage {\n type: 'background-task-status'\n payload: {\n taskId: string\n status: 'running' | 'stopped' | 'failed'\n error?: string\n }\n}\n\n/**\n * Message sent from worker to host with background task health reports.\n */\nexport interface BackgroundTaskHealthMessage {\n type: 'background-task-health'\n payload: {\n taskId: string\n status: string\n timestamp: string\n }\n}\n\n// ============================================================================\n// Utility Types\n// ============================================================================\n\nexport interface PendingRequest<T = unknown> {\n resolve: (value: T) => void\n reject: (error: Error) => void\n timeout: ReturnType<typeof setTimeout>\n}\n\n/**\n * Generate a unique message ID\n */\nexport function generateMessageId(): string {\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`\n}\n"],"mappings":";;;;;;;;AAuVO,SAAS,oBAA4B;AAC1C,SAAO,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AACjE;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/types.localization.ts","../src/messages.ts"],"sourcesContent":["/**\n * @stina/extension-api\n *\n * Types and utilities for building Stina extensions.\n *\n * Extensions should import from this package for type definitions.\n * The runtime (worker-side code) should import from '@stina/extension-api/runtime'.\n */\n\n// Localization\nexport type { LocalizedString } from './types.js'\nexport { resolveLocalizedString } from './types.js'\n\n// Types\nexport type {\n // Manifest\n ExtensionManifest,\n Platform,\n ExtensionContributions,\n SettingDefinition,\n SettingOptionsMapping,\n SettingCreateMapping,\n ToolSettingsViewDefinition,\n ToolSettingsView,\n ToolSettingsListView,\n ToolSettingsListMapping,\n ToolSettingsComponentView,\n ToolSettingsActionDataSource,\n PanelDefinition,\n PanelView,\n PanelComponentView,\n PanelActionDataSource,\n PanelUnknownView,\n ProviderDefinition,\n PromptContribution,\n PromptSection,\n ToolDefinition,\n CommandDefinition,\n\n // Provider Configuration Schema\n ProviderConfigSchema,\n ProviderConfigProperty,\n ProviderConfigPropertyType,\n ProviderConfigSelectOption,\n ProviderConfigValidation,\n\n // Permissions\n Permission,\n NetworkPermission,\n StoragePermission,\n UserDataPermission,\n CapabilityPermission,\n SystemPermission,\n\n // Context\n ExtensionContext,\n Disposable,\n NetworkAPI,\n SettingsAPI,\n ProvidersAPI,\n ToolsAPI,\n ActionsAPI,\n EventsAPI,\n SchedulerAPI,\n SchedulerJobRequest,\n SchedulerSchedule,\n SchedulerFirePayload,\n UserAPI,\n UserProfile,\n ChatAPI,\n ChatInstructionMessage,\n DatabaseAPI,\n StorageAPI,\n LogAPI,\n\n // AI Provider\n AIProvider,\n ModelInfo,\n ChatMessage,\n ChatOptions,\n GetModelsOptions,\n StreamEvent,\n ToolCall,\n\n // Tools\n Tool,\n ToolResult,\n\n // Actions\n Action,\n ActionResult,\n\n // Entry point\n ExtensionModule,\n} from './types.js'\n\n// Messages (for host implementation)\nexport type {\n HostToWorkerMessage,\n WorkerToHostMessage,\n ActivateMessage,\n DeactivateMessage,\n SettingsChangedMessage,\n ProviderChatRequestMessage,\n ProviderModelsRequestMessage,\n ToolExecuteRequestMessage,\n ToolExecuteResponseMessage,\n ActionExecuteRequestMessage,\n ActionExecuteResponseMessage,\n ResponseMessage,\n ReadyMessage,\n RequestMessage,\n RequestMethod,\n ProviderRegisteredMessage,\n ToolRegisteredMessage,\n ActionRegisteredMessage,\n StreamEventMessage,\n LogMessage,\n PendingRequest,\n} from './messages.js'\n\nexport { generateMessageId } from './messages.js'\n\n// Component types (for extension UI components)\nexport type {\n // Styling\n AllowedCSSProperty,\n ExtensionComponentStyle,\n // Base types\n ExtensionComponentData,\n // Iteration & Children\n ExtensionComponentIterator,\n ExtensionComponentChildren,\n // Actions\n ExtensionActionCall,\n ExtensionActionRef,\n // Data Sources & Panel Definition\n ExtensionDataSource,\n ExtensionPanelDefinition,\n // Component Props\n HeaderProps,\n LabelProps,\n ParagraphProps,\n ButtonProps,\n TextInputProps,\n DateTimeInputProps,\n SelectProps,\n VerticalStackProps,\n HorizontalStackProps,\n GridProps,\n DividerProps,\n IconProps,\n IconButtonType,\n IconButtonProps,\n PanelAction,\n PanelProps,\n ToggleProps,\n CollapsibleProps,\n PillVariant,\n PillProps,\n CheckboxProps,\n MarkdownProps,\n ModalProps,\n} from './types.components.js'\n","/**\n * Localization Types\n *\n * Types and utilities for localized strings in extensions.\n */\n\n/**\n * A string that can be either a simple string or a map of language codes to localized strings.\n * When a simple string is provided, it's used as the default/fallback value.\n * When a map is provided, the appropriate language is selected at runtime.\n *\n * @example\n * // Simple string (backwards compatible)\n * name: \"Get Weather\"\n *\n * @example\n * // Localized strings\n * name: { en: \"Get Weather\", sv: \"Hämta väder\", de: \"Wetter abrufen\" }\n */\nexport type LocalizedString = string | Record<string, string>\n\n/**\n * Resolves a LocalizedString to an actual string value.\n * @param value The LocalizedString to resolve\n * @param lang The preferred language code (e.g., \"sv\", \"en\")\n * @param fallbackLang The fallback language code (defaults to \"en\")\n * @returns The resolved string value\n */\nexport function resolveLocalizedString(\n value: LocalizedString,\n lang: string,\n fallbackLang = 'en'\n): string {\n if (typeof value === 'string') {\n return value\n }\n // Try preferred language first, then fallback language, then first available, then empty string\n return value[lang] ?? value[fallbackLang] ?? Object.values(value)[0] ?? ''\n}\n","/**\n * Message protocol between Extension Host and Extension Workers\n */\n\nimport type {\n ChatMessage,\n ChatOptions,\n GetModelsOptions,\n StreamEvent,\n ToolResult,\n ActionResult,\n ModelInfo,\n SchedulerFirePayload,\n} from './types.js'\n\n// ============================================================================\n// Host → Worker Messages\n// ============================================================================\n\nexport type HostToWorkerMessage =\n | ActivateMessage\n | DeactivateMessage\n | SettingsChangedMessage\n | SchedulerFireMessage\n | ProviderChatRequestMessage\n | ProviderModelsRequestMessage\n | ToolExecuteRequestMessage\n | ActionExecuteRequestMessage\n | ResponseMessage\n | StreamingFetchChunkMessage\n\nexport interface ActivateMessage {\n type: 'activate'\n id: string\n payload: {\n extensionId: string\n extensionVersion: string\n storagePath: string\n permissions: string[]\n settings: Record<string, unknown>\n }\n}\n\nexport interface DeactivateMessage {\n type: 'deactivate'\n id: string\n}\n\nexport interface SettingsChangedMessage {\n type: 'settings-changed'\n id: string\n payload: {\n key: string\n value: unknown\n }\n}\n\nexport interface SchedulerFireMessage {\n type: 'scheduler-fire'\n id: string\n payload: SchedulerFirePayload\n}\n\nexport interface ProviderChatRequestMessage {\n type: 'provider-chat-request'\n id: string\n payload: {\n providerId: string\n messages: ChatMessage[]\n options: ChatOptions\n }\n}\n\nexport interface ProviderModelsRequestMessage {\n type: 'provider-models-request'\n id: string\n payload: {\n providerId: string\n options?: GetModelsOptions\n }\n}\n\nexport interface ToolExecuteRequestMessage {\n type: 'tool-execute-request'\n id: string\n payload: {\n toolId: string\n params: Record<string, unknown>\n /** User ID if the tool is executed in a user context */\n userId?: string\n }\n}\n\nexport interface ActionExecuteRequestMessage {\n type: 'action-execute-request'\n id: string\n payload: {\n actionId: string\n params: Record<string, unknown>\n /** User ID if the action is executed in a user context */\n userId?: string\n }\n}\n\nexport interface ResponseMessage {\n type: 'response'\n id: string\n payload: {\n requestId: string\n success: boolean\n data?: unknown\n error?: string\n }\n}\n\n/**\n * Message sent from host to worker with streaming fetch data chunks.\n * Used for streaming network responses (e.g., NDJSON streams from Ollama).\n */\nexport interface StreamingFetchChunkMessage {\n type: 'streaming-fetch-chunk'\n id: string\n payload: {\n requestId: string\n chunk: string\n done: boolean\n error?: string\n }\n}\n\n// ============================================================================\n// Worker → Host Messages\n// ============================================================================\n\nexport type WorkerToHostMessage =\n | ReadyMessage\n | RequestMessage\n | ProviderRegisteredMessage\n | ToolRegisteredMessage\n | ActionRegisteredMessage\n | StreamEventMessage\n | LogMessage\n | ProviderModelsResponseMessage\n | ToolExecuteResponseMessage\n | ActionExecuteResponseMessage\n | StreamingFetchAckMessage\n\nexport interface ReadyMessage {\n type: 'ready'\n}\n\n/**\n * Message sent from worker to host to acknowledge receipt of a streaming fetch chunk.\n * This enables backpressure control to prevent unbounded memory growth.\n */\nexport interface StreamingFetchAckMessage {\n type: 'streaming-fetch-ack'\n payload: {\n requestId: string\n }\n}\n\nexport interface RequestMessage {\n type: 'request'\n id: string\n method: RequestMethod\n payload: unknown\n}\n\nexport type RequestMethod =\n | 'network.fetch'\n | 'network.fetch-stream'\n | 'settings.getAll'\n | 'settings.get'\n | 'settings.set'\n | 'user.getProfile'\n | 'events.emit'\n | 'scheduler.schedule'\n | 'scheduler.cancel'\n | 'chat.appendInstruction'\n | 'database.execute'\n | 'storage.get'\n | 'storage.set'\n | 'storage.delete'\n | 'storage.keys'\n | 'storage.getForUser'\n | 'storage.setForUser'\n | 'storage.deleteForUser'\n | 'storage.keysForUser'\n\nexport interface ProviderRegisteredMessage {\n type: 'provider-registered'\n payload: {\n id: string\n name: string\n }\n}\n\nexport interface ToolRegisteredMessage {\n type: 'tool-registered'\n payload: {\n id: string\n name: string\n description: string\n parameters?: Record<string, unknown>\n }\n}\n\nexport interface ActionRegisteredMessage {\n type: 'action-registered'\n payload: {\n id: string\n }\n}\n\nexport interface StreamEventMessage {\n type: 'stream-event'\n payload: {\n requestId: string\n event: StreamEvent\n }\n}\n\nexport interface ProviderModelsResponseMessage {\n type: 'provider-models-response'\n payload: {\n requestId: string\n models: ModelInfo[]\n error?: string\n }\n}\n\nexport interface ToolExecuteResponseMessage {\n type: 'tool-execute-response'\n payload: {\n requestId: string\n result: ToolResult\n error?: string\n }\n}\n\nexport interface ActionExecuteResponseMessage {\n type: 'action-execute-response'\n payload: {\n requestId: string\n result: ActionResult\n error?: string\n }\n}\n\nexport interface LogMessage {\n type: 'log'\n payload: {\n level: 'debug' | 'info' | 'warn' | 'error'\n message: string\n data?: Record<string, unknown>\n }\n}\n\n// ============================================================================\n// Utility Types\n// ============================================================================\n\nexport interface PendingRequest<T = unknown> {\n resolve: (value: T) => void\n reject: (error: Error) => void\n timeout: ReturnType<typeof setTimeout>\n}\n\n/**\n * Generate a unique message ID\n */\nexport function generateMessageId(): string {\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BO,SAAS,uBACd,OACA,MACA,eAAe,MACP;AACR,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,IAAI,KAAK,MAAM,YAAY,KAAK,OAAO,OAAO,KAAK,EAAE,CAAC,KAAK;AAC1E;;;AC0OO,SAAS,oBAA4B;AAC1C,SAAO,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AACjE;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types.localization.ts","../src/messages.ts"],"sourcesContent":["/**\n * @stina/extension-api\n *\n * Types and utilities for building Stina extensions.\n *\n * Extensions should import from this package for type definitions.\n * The runtime (worker-side code) should import from '@stina/extension-api/runtime'.\n */\n\n// Localization\nexport type { LocalizedString } from './types.js'\nexport { resolveLocalizedString } from './types.js'\n\n// Types\nexport type {\n // Manifest\n ExtensionManifest,\n Platform,\n ExtensionContributions,\n SettingDefinition,\n SettingOptionsMapping,\n SettingCreateMapping,\n ToolSettingsViewDefinition,\n ToolSettingsView,\n ToolSettingsListView,\n ToolSettingsListMapping,\n ToolSettingsComponentView,\n ToolSettingsActionDataSource,\n PanelDefinition,\n PanelView,\n PanelComponentView,\n PanelActionDataSource,\n PanelUnknownView,\n ProviderDefinition,\n PromptContribution,\n PromptSection,\n ToolDefinition,\n CommandDefinition,\n\n // Provider Configuration Schema\n ProviderConfigSchema,\n ProviderConfigProperty,\n ProviderConfigPropertyType,\n ProviderConfigSelectOption,\n ProviderConfigValidation,\n\n // Permissions\n Permission,\n NetworkPermission,\n StoragePermission,\n UserDataPermission,\n CapabilityPermission,\n SystemPermission,\n\n // Context\n ExtensionContext,\n Disposable,\n NetworkAPI,\n SettingsAPI,\n ProvidersAPI,\n ToolsAPI,\n ActionsAPI,\n EventsAPI,\n SchedulerAPI,\n SchedulerJobRequest,\n SchedulerSchedule,\n SchedulerFirePayload,\n UserAPI,\n UserProfile,\n ChatAPI,\n ChatInstructionMessage,\n DatabaseAPI,\n StorageAPI,\n LogAPI,\n\n // Background workers\n BackgroundWorkersAPI,\n BackgroundTaskConfig,\n BackgroundTaskCallback,\n BackgroundTaskContext,\n BackgroundTaskHealth,\n BackgroundRestartPolicy,\n\n // AI Provider\n AIProvider,\n ModelInfo,\n ChatMessage,\n ChatOptions,\n GetModelsOptions,\n StreamEvent,\n ToolCall,\n\n // Tools\n Tool,\n ToolResult,\n\n // Actions\n Action,\n ActionResult,\n\n // Entry point\n ExtensionModule,\n} from './types.js'\n\n// Messages (for host implementation)\nexport type {\n HostToWorkerMessage,\n WorkerToHostMessage,\n ActivateMessage,\n DeactivateMessage,\n SettingsChangedMessage,\n ProviderChatRequestMessage,\n ProviderModelsRequestMessage,\n ToolExecuteRequestMessage,\n ToolExecuteResponseMessage,\n ActionExecuteRequestMessage,\n ActionExecuteResponseMessage,\n ResponseMessage,\n ReadyMessage,\n RequestMessage,\n RequestMethod,\n ProviderRegisteredMessage,\n ToolRegisteredMessage,\n ActionRegisteredMessage,\n StreamEventMessage,\n LogMessage,\n PendingRequest,\n // Background task messages\n BackgroundTaskStartMessage,\n BackgroundTaskStopMessage,\n BackgroundTaskRegisteredMessage,\n BackgroundTaskStatusMessage,\n BackgroundTaskHealthMessage,\n} from './messages.js'\n\nexport { generateMessageId } from './messages.js'\n\n// Component types (for extension UI components)\nexport type {\n // Styling\n AllowedCSSProperty,\n ExtensionComponentStyle,\n // Base types\n ExtensionComponentData,\n // Iteration & Children\n ExtensionComponentIterator,\n ExtensionComponentChildren,\n // Actions\n ExtensionActionCall,\n ExtensionActionRef,\n // Data Sources & Panel Definition\n ExtensionDataSource,\n ExtensionPanelDefinition,\n // Component Props\n HeaderProps,\n LabelProps,\n ParagraphProps,\n ButtonProps,\n TextInputProps,\n DateTimeInputProps,\n SelectProps,\n VerticalStackProps,\n HorizontalStackProps,\n GridProps,\n DividerProps,\n IconProps,\n IconButtonType,\n IconButtonProps,\n PanelAction,\n PanelProps,\n ToggleProps,\n CollapsibleProps,\n PillVariant,\n PillProps,\n CheckboxProps,\n MarkdownProps,\n ModalProps,\n ConditionalGroupProps,\n} from './types.components.js'\n","/**\n * Localization Types\n *\n * Types and utilities for localized strings in extensions.\n */\n\n/**\n * A string that can be either a simple string or a map of language codes to localized strings.\n * When a simple string is provided, it's used as the default/fallback value.\n * When a map is provided, the appropriate language is selected at runtime.\n *\n * @example\n * // Simple string (backwards compatible)\n * name: \"Get Weather\"\n *\n * @example\n * // Localized strings\n * name: { en: \"Get Weather\", sv: \"Hämta väder\", de: \"Wetter abrufen\" }\n */\nexport type LocalizedString = string | Record<string, string>\n\n/**\n * Resolves a LocalizedString to an actual string value.\n * @param value The LocalizedString to resolve\n * @param lang The preferred language code (e.g., \"sv\", \"en\")\n * @param fallbackLang The fallback language code (defaults to \"en\")\n * @returns The resolved string value\n */\nexport function resolveLocalizedString(\n value: LocalizedString,\n lang: string,\n fallbackLang = 'en'\n): string {\n if (typeof value === 'string') {\n return value\n }\n // Try preferred language first, then fallback language, then first available, then empty string\n return value[lang] ?? value[fallbackLang] ?? Object.values(value)[0] ?? ''\n}\n","/**\n * Message protocol between Extension Host and Extension Workers\n */\n\nimport type {\n ChatMessage,\n ChatOptions,\n GetModelsOptions,\n StreamEvent,\n ToolResult,\n ActionResult,\n ModelInfo,\n SchedulerFirePayload,\n} from './types.js'\n\n// ============================================================================\n// Host → Worker Messages\n// ============================================================================\n\nexport type HostToWorkerMessage =\n | ActivateMessage\n | DeactivateMessage\n | SettingsChangedMessage\n | SchedulerFireMessage\n | ProviderChatRequestMessage\n | ProviderModelsRequestMessage\n | ToolExecuteRequestMessage\n | ActionExecuteRequestMessage\n | ResponseMessage\n | StreamingFetchChunkMessage\n | BackgroundTaskStartMessage\n | BackgroundTaskStopMessage\n\nexport interface ActivateMessage {\n type: 'activate'\n id: string\n payload: {\n extensionId: string\n extensionVersion: string\n storagePath: string\n permissions: string[]\n settings: Record<string, unknown>\n }\n}\n\nexport interface DeactivateMessage {\n type: 'deactivate'\n id: string\n}\n\nexport interface SettingsChangedMessage {\n type: 'settings-changed'\n id: string\n payload: {\n key: string\n value: unknown\n }\n}\n\nexport interface SchedulerFireMessage {\n type: 'scheduler-fire'\n id: string\n payload: SchedulerFirePayload\n}\n\nexport interface ProviderChatRequestMessage {\n type: 'provider-chat-request'\n id: string\n payload: {\n providerId: string\n messages: ChatMessage[]\n options: ChatOptions\n }\n}\n\nexport interface ProviderModelsRequestMessage {\n type: 'provider-models-request'\n id: string\n payload: {\n providerId: string\n options?: GetModelsOptions\n }\n}\n\nexport interface ToolExecuteRequestMessage {\n type: 'tool-execute-request'\n id: string\n payload: {\n toolId: string\n params: Record<string, unknown>\n /** User ID if the tool is executed in a user context */\n userId?: string\n }\n}\n\nexport interface ActionExecuteRequestMessage {\n type: 'action-execute-request'\n id: string\n payload: {\n actionId: string\n params: Record<string, unknown>\n /** User ID if the action is executed in a user context */\n userId?: string\n }\n}\n\nexport interface ResponseMessage {\n type: 'response'\n id: string\n payload: {\n requestId: string\n success: boolean\n data?: unknown\n error?: string\n }\n}\n\n/**\n * Message sent from host to worker with streaming fetch data chunks.\n * Used for streaming network responses (e.g., NDJSON streams from Ollama).\n */\nexport interface StreamingFetchChunkMessage {\n type: 'streaming-fetch-chunk'\n id: string\n payload: {\n requestId: string\n chunk: string\n done: boolean\n error?: string\n }\n}\n\n/**\n * Message sent from host to worker to start a registered background task.\n */\nexport interface BackgroundTaskStartMessage {\n type: 'background-task-start'\n id: string\n payload: {\n taskId: string\n }\n}\n\n/**\n * Message sent from host to worker to stop a running background task.\n */\nexport interface BackgroundTaskStopMessage {\n type: 'background-task-stop'\n id: string\n payload: {\n taskId: string\n }\n}\n\n// ============================================================================\n// Worker → Host Messages\n// ============================================================================\n\nexport type WorkerToHostMessage =\n | ReadyMessage\n | RequestMessage\n | ProviderRegisteredMessage\n | ToolRegisteredMessage\n | ActionRegisteredMessage\n | StreamEventMessage\n | LogMessage\n | ProviderModelsResponseMessage\n | ToolExecuteResponseMessage\n | ActionExecuteResponseMessage\n | StreamingFetchAckMessage\n | BackgroundTaskRegisteredMessage\n | BackgroundTaskStatusMessage\n | BackgroundTaskHealthMessage\n\nexport interface ReadyMessage {\n type: 'ready'\n}\n\n/**\n * Message sent from worker to host to acknowledge receipt of a streaming fetch chunk.\n * This enables backpressure control to prevent unbounded memory growth.\n */\nexport interface StreamingFetchAckMessage {\n type: 'streaming-fetch-ack'\n payload: {\n requestId: string\n }\n}\n\nexport interface RequestMessage {\n type: 'request'\n id: string\n method: RequestMethod\n payload: unknown\n}\n\nexport type RequestMethod =\n | 'network.fetch'\n | 'network.fetch-stream'\n | 'settings.getAll'\n | 'settings.get'\n | 'settings.set'\n | 'user.getProfile'\n | 'events.emit'\n | 'scheduler.schedule'\n | 'scheduler.cancel'\n | 'chat.appendInstruction'\n | 'database.execute'\n | 'storage.get'\n | 'storage.set'\n | 'storage.delete'\n | 'storage.keys'\n | 'storage.getForUser'\n | 'storage.setForUser'\n | 'storage.deleteForUser'\n | 'storage.keysForUser'\n\nexport interface ProviderRegisteredMessage {\n type: 'provider-registered'\n payload: {\n id: string\n name: string\n }\n}\n\nexport interface ToolRegisteredMessage {\n type: 'tool-registered'\n payload: {\n id: string\n name: string\n description: string\n parameters?: Record<string, unknown>\n }\n}\n\nexport interface ActionRegisteredMessage {\n type: 'action-registered'\n payload: {\n id: string\n }\n}\n\nexport interface StreamEventMessage {\n type: 'stream-event'\n payload: {\n requestId: string\n event: StreamEvent\n }\n}\n\nexport interface ProviderModelsResponseMessage {\n type: 'provider-models-response'\n payload: {\n requestId: string\n models: ModelInfo[]\n error?: string\n }\n}\n\nexport interface ToolExecuteResponseMessage {\n type: 'tool-execute-response'\n payload: {\n requestId: string\n result: ToolResult\n error?: string\n }\n}\n\nexport interface ActionExecuteResponseMessage {\n type: 'action-execute-response'\n payload: {\n requestId: string\n result: ActionResult\n error?: string\n }\n}\n\nexport interface LogMessage {\n type: 'log'\n payload: {\n level: 'debug' | 'info' | 'warn' | 'error'\n message: string\n data?: Record<string, unknown>\n }\n}\n\n/**\n * Message sent from worker to host when a background task is registered.\n */\nexport interface BackgroundTaskRegisteredMessage {\n type: 'background-task-registered'\n payload: {\n taskId: string\n name: string\n userId: string\n restartPolicy: {\n type: 'always' | 'on-failure' | 'never'\n maxRestarts?: number\n initialDelayMs?: number\n maxDelayMs?: number\n backoffMultiplier?: number\n }\n payload?: Record<string, unknown>\n }\n}\n\n/**\n * Message sent from worker to host with background task status updates.\n */\nexport interface BackgroundTaskStatusMessage {\n type: 'background-task-status'\n payload: {\n taskId: string\n status: 'running' | 'stopped' | 'failed'\n error?: string\n }\n}\n\n/**\n * Message sent from worker to host with background task health reports.\n */\nexport interface BackgroundTaskHealthMessage {\n type: 'background-task-health'\n payload: {\n taskId: string\n status: string\n timestamp: string\n }\n}\n\n// ============================================================================\n// Utility Types\n// ============================================================================\n\nexport interface PendingRequest<T = unknown> {\n resolve: (value: T) => void\n reject: (error: Error) => void\n timeout: ReturnType<typeof setTimeout>\n}\n\n/**\n * Generate a unique message ID\n */\nexport function generateMessageId(): string {\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BO,SAAS,uBACd,OACA,MACA,eAAe,MACP;AACR,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,IAAI,KAAK,MAAM,YAAY,KAAK,OAAO,OAAO,KAAK,EAAE,CAAC,KAAK;AAC1E;;;ACiTO,SAAS,oBAA4B;AAC1C,SAAO,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AACjE;","names":[]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as ExtensionContributions, S as SchedulerFirePayload, C as ChatMessage, a as ChatOptions, G as GetModelsOptions, b as StreamEvent, M as ModelInfo, T as ToolResult, A as ActionResult } from './types.tools-DgCozsOW.cjs';
2
- export { $ as AIProvider, a2 as Action, J as ActionsAPI, a4 as AllowedCSSProperty, ag as ButtonProps, W as ChatAPI, X as ChatInstructionMessage, ax as CheckboxProps, au as CollapsibleProps, u as CommandDefinition, Y as DatabaseAPI, ai as DateTimeInputProps, D as Disposable, an as DividerProps, K as EventsAPI, a9 as ExtensionActionCall, aa as ExtensionActionRef, a8 as ExtensionComponentChildren, a6 as ExtensionComponentData, a7 as ExtensionComponentIterator, a5 as ExtensionComponentStyle, B as ExtensionContext, ab as ExtensionDataSource, a3 as ExtensionModule, ac as ExtensionPanelDefinition, am as GridProps, ad as HeaderProps, al as HorizontalStackProps, aq as IconButtonProps, ap as IconButtonType, ao as IconProps, ae as LabelProps, L as LocalizedString, _ as LogAPI, ay as MarkdownProps, az as ModalProps, N as NetworkAPI, ar as PanelAction, n as PanelActionDataSource, m as PanelComponentView, P as PanelDefinition, as as PanelProps, o as PanelUnknownView, l as PanelView, af as ParagraphProps, aw as PillProps, av as PillVariant, q as PromptContribution, s as PromptSection, w as ProviderConfigProperty, x as ProviderConfigPropertyType, v as ProviderConfigSchema, y as ProviderConfigSelectOption, z as ProviderConfigValidation, p as ProviderDefinition, H as ProvidersAPI, O as SchedulerAPI, Q as SchedulerJobRequest, R as SchedulerSchedule, aj as SelectProps, e as SettingCreateMapping, c as SettingDefinition, d as SettingOptionsMapping, F as SettingsAPI, Z as StorageAPI, ah as TextInputProps, at as ToggleProps, a1 as Tool, a0 as ToolCall, t as ToolDefinition, k as ToolSettingsActionDataSource, j as ToolSettingsComponentView, i as ToolSettingsListMapping, h as ToolSettingsListView, g as ToolSettingsView, f as ToolSettingsViewDefinition, I as ToolsAPI, U as UserAPI, V as UserProfile, ak as VerticalStackProps, r as resolveLocalizedString } from './types.tools-DgCozsOW.cjs';
1
+ import { E as ExtensionContributions, S as SchedulerFirePayload, C as ChatMessage, a as ChatOptions, G as GetModelsOptions, b as StreamEvent, M as ModelInfo, T as ToolResult, A as ActionResult } from './types.tools-BXGZf8zc.cjs';
2
+ export { a5 as AIProvider, a8 as Action, J as ActionsAPI, aa as AllowedCSSProperty, a4 as BackgroundRestartPolicy, a1 as BackgroundTaskCallback, a0 as BackgroundTaskConfig, a2 as BackgroundTaskContext, a3 as BackgroundTaskHealth, $ as BackgroundWorkersAPI, am as ButtonProps, W as ChatAPI, X as ChatInstructionMessage, aD as CheckboxProps, aA as CollapsibleProps, u as CommandDefinition, aG as ConditionalGroupProps, Y as DatabaseAPI, ao as DateTimeInputProps, D as Disposable, at as DividerProps, K as EventsAPI, af as ExtensionActionCall, ag as ExtensionActionRef, ae as ExtensionComponentChildren, ac as ExtensionComponentData, ad as ExtensionComponentIterator, ab as ExtensionComponentStyle, B as ExtensionContext, ah as ExtensionDataSource, a9 as ExtensionModule, ai as ExtensionPanelDefinition, as as GridProps, aj as HeaderProps, ar as HorizontalStackProps, aw as IconButtonProps, av as IconButtonType, au as IconProps, ak as LabelProps, L as LocalizedString, _ as LogAPI, aE as MarkdownProps, aF as ModalProps, N as NetworkAPI, ax as PanelAction, n as PanelActionDataSource, m as PanelComponentView, P as PanelDefinition, ay as PanelProps, o as PanelUnknownView, l as PanelView, al as ParagraphProps, aC as PillProps, aB as PillVariant, q as PromptContribution, s as PromptSection, w as ProviderConfigProperty, x as ProviderConfigPropertyType, v as ProviderConfigSchema, y as ProviderConfigSelectOption, z as ProviderConfigValidation, p as ProviderDefinition, H as ProvidersAPI, O as SchedulerAPI, Q as SchedulerJobRequest, R as SchedulerSchedule, ap as SelectProps, e as SettingCreateMapping, c as SettingDefinition, d as SettingOptionsMapping, F as SettingsAPI, Z as StorageAPI, an as TextInputProps, az as ToggleProps, a7 as Tool, a6 as ToolCall, t as ToolDefinition, k as ToolSettingsActionDataSource, j as ToolSettingsComponentView, i as ToolSettingsListMapping, h as ToolSettingsListView, g as ToolSettingsView, f as ToolSettingsViewDefinition, I as ToolsAPI, U as UserAPI, V as UserProfile, aq as VerticalStackProps, r as resolveLocalizedString } from './types.tools-BXGZf8zc.cjs';
3
3
 
4
4
  /**
5
5
  * Permission Types
@@ -14,7 +14,7 @@ type StoragePermission = 'database.own' | 'storage.local';
14
14
  /** User data permissions */
15
15
  type UserDataPermission = 'user.profile.read' | 'user.location.read' | 'chat.history.read' | 'chat.current.read';
16
16
  /** Capability permissions */
17
- type CapabilityPermission = 'provider.register' | 'tools.register' | 'actions.register' | 'settings.register' | 'commands.register' | 'panels.register' | 'events.emit' | 'scheduler.register' | 'chat.message.write';
17
+ type CapabilityPermission = 'provider.register' | 'tools.register' | 'actions.register' | 'settings.register' | 'commands.register' | 'panels.register' | 'events.emit' | 'scheduler.register' | 'chat.message.write' | 'background.workers';
18
18
  /** System permissions */
19
19
  type SystemPermission = 'files.read' | 'files.write' | 'clipboard.read' | 'clipboard.write';
20
20
 
@@ -64,7 +64,7 @@ type Platform = 'web' | 'electron' | 'tui';
64
64
  * Message protocol between Extension Host and Extension Workers
65
65
  */
66
66
 
67
- type HostToWorkerMessage = ActivateMessage | DeactivateMessage | SettingsChangedMessage | SchedulerFireMessage | ProviderChatRequestMessage | ProviderModelsRequestMessage | ToolExecuteRequestMessage | ActionExecuteRequestMessage | ResponseMessage | StreamingFetchChunkMessage;
67
+ type HostToWorkerMessage = ActivateMessage | DeactivateMessage | SettingsChangedMessage | SchedulerFireMessage | ProviderChatRequestMessage | ProviderModelsRequestMessage | ToolExecuteRequestMessage | ActionExecuteRequestMessage | ResponseMessage | StreamingFetchChunkMessage | BackgroundTaskStartMessage | BackgroundTaskStopMessage;
68
68
  interface ActivateMessage {
69
69
  type: 'activate';
70
70
  id: string;
@@ -154,7 +154,27 @@ interface StreamingFetchChunkMessage {
154
154
  error?: string;
155
155
  };
156
156
  }
157
- type WorkerToHostMessage = ReadyMessage | RequestMessage | ProviderRegisteredMessage | ToolRegisteredMessage | ActionRegisteredMessage | StreamEventMessage | LogMessage | ProviderModelsResponseMessage | ToolExecuteResponseMessage | ActionExecuteResponseMessage | StreamingFetchAckMessage;
157
+ /**
158
+ * Message sent from host to worker to start a registered background task.
159
+ */
160
+ interface BackgroundTaskStartMessage {
161
+ type: 'background-task-start';
162
+ id: string;
163
+ payload: {
164
+ taskId: string;
165
+ };
166
+ }
167
+ /**
168
+ * Message sent from host to worker to stop a running background task.
169
+ */
170
+ interface BackgroundTaskStopMessage {
171
+ type: 'background-task-stop';
172
+ id: string;
173
+ payload: {
174
+ taskId: string;
175
+ };
176
+ }
177
+ type WorkerToHostMessage = ReadyMessage | RequestMessage | ProviderRegisteredMessage | ToolRegisteredMessage | ActionRegisteredMessage | StreamEventMessage | LogMessage | ProviderModelsResponseMessage | ToolExecuteResponseMessage | ActionExecuteResponseMessage | StreamingFetchAckMessage | BackgroundTaskRegisteredMessage | BackgroundTaskStatusMessage | BackgroundTaskHealthMessage;
158
178
  interface ReadyMessage {
159
179
  type: 'ready';
160
180
  }
@@ -236,6 +256,47 @@ interface LogMessage {
236
256
  data?: Record<string, unknown>;
237
257
  };
238
258
  }
259
+ /**
260
+ * Message sent from worker to host when a background task is registered.
261
+ */
262
+ interface BackgroundTaskRegisteredMessage {
263
+ type: 'background-task-registered';
264
+ payload: {
265
+ taskId: string;
266
+ name: string;
267
+ userId: string;
268
+ restartPolicy: {
269
+ type: 'always' | 'on-failure' | 'never';
270
+ maxRestarts?: number;
271
+ initialDelayMs?: number;
272
+ maxDelayMs?: number;
273
+ backoffMultiplier?: number;
274
+ };
275
+ payload?: Record<string, unknown>;
276
+ };
277
+ }
278
+ /**
279
+ * Message sent from worker to host with background task status updates.
280
+ */
281
+ interface BackgroundTaskStatusMessage {
282
+ type: 'background-task-status';
283
+ payload: {
284
+ taskId: string;
285
+ status: 'running' | 'stopped' | 'failed';
286
+ error?: string;
287
+ };
288
+ }
289
+ /**
290
+ * Message sent from worker to host with background task health reports.
291
+ */
292
+ interface BackgroundTaskHealthMessage {
293
+ type: 'background-task-health';
294
+ payload: {
295
+ taskId: string;
296
+ status: string;
297
+ timestamp: string;
298
+ };
299
+ }
239
300
  interface PendingRequest<T = unknown> {
240
301
  resolve: (value: T) => void;
241
302
  reject: (error: Error) => void;
@@ -246,4 +307,4 @@ interface PendingRequest<T = unknown> {
246
307
  */
247
308
  declare function generateMessageId(): string;
248
309
 
249
- export { type ActionExecuteRequestMessage, type ActionExecuteResponseMessage, type ActionRegisteredMessage, ActionResult, type ActivateMessage, type CapabilityPermission, ChatMessage, ChatOptions, type DeactivateMessage, ExtensionContributions, type ExtensionManifest, GetModelsOptions, type HostToWorkerMessage, type LogMessage, ModelInfo, type NetworkPermission, type PendingRequest, type Permission, type Platform, type ProviderChatRequestMessage, type ProviderModelsRequestMessage, type ProviderRegisteredMessage, type ReadyMessage, type RequestMessage, type RequestMethod, type ResponseMessage, SchedulerFirePayload, type SettingsChangedMessage, type StoragePermission, StreamEvent, type StreamEventMessage, type SystemPermission, type ToolExecuteRequestMessage, type ToolExecuteResponseMessage, type ToolRegisteredMessage, ToolResult, type UserDataPermission, type WorkerToHostMessage, generateMessageId };
310
+ export { type ActionExecuteRequestMessage, type ActionExecuteResponseMessage, type ActionRegisteredMessage, ActionResult, type ActivateMessage, type BackgroundTaskHealthMessage, type BackgroundTaskRegisteredMessage, type BackgroundTaskStartMessage, type BackgroundTaskStatusMessage, type BackgroundTaskStopMessage, type CapabilityPermission, ChatMessage, ChatOptions, type DeactivateMessage, ExtensionContributions, type ExtensionManifest, GetModelsOptions, type HostToWorkerMessage, type LogMessage, ModelInfo, type NetworkPermission, type PendingRequest, type Permission, type Platform, type ProviderChatRequestMessage, type ProviderModelsRequestMessage, type ProviderRegisteredMessage, type ReadyMessage, type RequestMessage, type RequestMethod, type ResponseMessage, SchedulerFirePayload, type SettingsChangedMessage, type StoragePermission, StreamEvent, type StreamEventMessage, type SystemPermission, type ToolExecuteRequestMessage, type ToolExecuteResponseMessage, type ToolRegisteredMessage, ToolResult, type UserDataPermission, type WorkerToHostMessage, generateMessageId };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as ExtensionContributions, S as SchedulerFirePayload, C as ChatMessage, a as ChatOptions, G as GetModelsOptions, b as StreamEvent, M as ModelInfo, T as ToolResult, A as ActionResult } from './types.tools-DgCozsOW.js';
2
- export { $ as AIProvider, a2 as Action, J as ActionsAPI, a4 as AllowedCSSProperty, ag as ButtonProps, W as ChatAPI, X as ChatInstructionMessage, ax as CheckboxProps, au as CollapsibleProps, u as CommandDefinition, Y as DatabaseAPI, ai as DateTimeInputProps, D as Disposable, an as DividerProps, K as EventsAPI, a9 as ExtensionActionCall, aa as ExtensionActionRef, a8 as ExtensionComponentChildren, a6 as ExtensionComponentData, a7 as ExtensionComponentIterator, a5 as ExtensionComponentStyle, B as ExtensionContext, ab as ExtensionDataSource, a3 as ExtensionModule, ac as ExtensionPanelDefinition, am as GridProps, ad as HeaderProps, al as HorizontalStackProps, aq as IconButtonProps, ap as IconButtonType, ao as IconProps, ae as LabelProps, L as LocalizedString, _ as LogAPI, ay as MarkdownProps, az as ModalProps, N as NetworkAPI, ar as PanelAction, n as PanelActionDataSource, m as PanelComponentView, P as PanelDefinition, as as PanelProps, o as PanelUnknownView, l as PanelView, af as ParagraphProps, aw as PillProps, av as PillVariant, q as PromptContribution, s as PromptSection, w as ProviderConfigProperty, x as ProviderConfigPropertyType, v as ProviderConfigSchema, y as ProviderConfigSelectOption, z as ProviderConfigValidation, p as ProviderDefinition, H as ProvidersAPI, O as SchedulerAPI, Q as SchedulerJobRequest, R as SchedulerSchedule, aj as SelectProps, e as SettingCreateMapping, c as SettingDefinition, d as SettingOptionsMapping, F as SettingsAPI, Z as StorageAPI, ah as TextInputProps, at as ToggleProps, a1 as Tool, a0 as ToolCall, t as ToolDefinition, k as ToolSettingsActionDataSource, j as ToolSettingsComponentView, i as ToolSettingsListMapping, h as ToolSettingsListView, g as ToolSettingsView, f as ToolSettingsViewDefinition, I as ToolsAPI, U as UserAPI, V as UserProfile, ak as VerticalStackProps, r as resolveLocalizedString } from './types.tools-DgCozsOW.js';
1
+ import { E as ExtensionContributions, S as SchedulerFirePayload, C as ChatMessage, a as ChatOptions, G as GetModelsOptions, b as StreamEvent, M as ModelInfo, T as ToolResult, A as ActionResult } from './types.tools-BXGZf8zc.js';
2
+ export { a5 as AIProvider, a8 as Action, J as ActionsAPI, aa as AllowedCSSProperty, a4 as BackgroundRestartPolicy, a1 as BackgroundTaskCallback, a0 as BackgroundTaskConfig, a2 as BackgroundTaskContext, a3 as BackgroundTaskHealth, $ as BackgroundWorkersAPI, am as ButtonProps, W as ChatAPI, X as ChatInstructionMessage, aD as CheckboxProps, aA as CollapsibleProps, u as CommandDefinition, aG as ConditionalGroupProps, Y as DatabaseAPI, ao as DateTimeInputProps, D as Disposable, at as DividerProps, K as EventsAPI, af as ExtensionActionCall, ag as ExtensionActionRef, ae as ExtensionComponentChildren, ac as ExtensionComponentData, ad as ExtensionComponentIterator, ab as ExtensionComponentStyle, B as ExtensionContext, ah as ExtensionDataSource, a9 as ExtensionModule, ai as ExtensionPanelDefinition, as as GridProps, aj as HeaderProps, ar as HorizontalStackProps, aw as IconButtonProps, av as IconButtonType, au as IconProps, ak as LabelProps, L as LocalizedString, _ as LogAPI, aE as MarkdownProps, aF as ModalProps, N as NetworkAPI, ax as PanelAction, n as PanelActionDataSource, m as PanelComponentView, P as PanelDefinition, ay as PanelProps, o as PanelUnknownView, l as PanelView, al as ParagraphProps, aC as PillProps, aB as PillVariant, q as PromptContribution, s as PromptSection, w as ProviderConfigProperty, x as ProviderConfigPropertyType, v as ProviderConfigSchema, y as ProviderConfigSelectOption, z as ProviderConfigValidation, p as ProviderDefinition, H as ProvidersAPI, O as SchedulerAPI, Q as SchedulerJobRequest, R as SchedulerSchedule, ap as SelectProps, e as SettingCreateMapping, c as SettingDefinition, d as SettingOptionsMapping, F as SettingsAPI, Z as StorageAPI, an as TextInputProps, az as ToggleProps, a7 as Tool, a6 as ToolCall, t as ToolDefinition, k as ToolSettingsActionDataSource, j as ToolSettingsComponentView, i as ToolSettingsListMapping, h as ToolSettingsListView, g as ToolSettingsView, f as ToolSettingsViewDefinition, I as ToolsAPI, U as UserAPI, V as UserProfile, aq as VerticalStackProps, r as resolveLocalizedString } from './types.tools-BXGZf8zc.js';
3
3
 
4
4
  /**
5
5
  * Permission Types
@@ -14,7 +14,7 @@ type StoragePermission = 'database.own' | 'storage.local';
14
14
  /** User data permissions */
15
15
  type UserDataPermission = 'user.profile.read' | 'user.location.read' | 'chat.history.read' | 'chat.current.read';
16
16
  /** Capability permissions */
17
- type CapabilityPermission = 'provider.register' | 'tools.register' | 'actions.register' | 'settings.register' | 'commands.register' | 'panels.register' | 'events.emit' | 'scheduler.register' | 'chat.message.write';
17
+ type CapabilityPermission = 'provider.register' | 'tools.register' | 'actions.register' | 'settings.register' | 'commands.register' | 'panels.register' | 'events.emit' | 'scheduler.register' | 'chat.message.write' | 'background.workers';
18
18
  /** System permissions */
19
19
  type SystemPermission = 'files.read' | 'files.write' | 'clipboard.read' | 'clipboard.write';
20
20
 
@@ -64,7 +64,7 @@ type Platform = 'web' | 'electron' | 'tui';
64
64
  * Message protocol between Extension Host and Extension Workers
65
65
  */
66
66
 
67
- type HostToWorkerMessage = ActivateMessage | DeactivateMessage | SettingsChangedMessage | SchedulerFireMessage | ProviderChatRequestMessage | ProviderModelsRequestMessage | ToolExecuteRequestMessage | ActionExecuteRequestMessage | ResponseMessage | StreamingFetchChunkMessage;
67
+ type HostToWorkerMessage = ActivateMessage | DeactivateMessage | SettingsChangedMessage | SchedulerFireMessage | ProviderChatRequestMessage | ProviderModelsRequestMessage | ToolExecuteRequestMessage | ActionExecuteRequestMessage | ResponseMessage | StreamingFetchChunkMessage | BackgroundTaskStartMessage | BackgroundTaskStopMessage;
68
68
  interface ActivateMessage {
69
69
  type: 'activate';
70
70
  id: string;
@@ -154,7 +154,27 @@ interface StreamingFetchChunkMessage {
154
154
  error?: string;
155
155
  };
156
156
  }
157
- type WorkerToHostMessage = ReadyMessage | RequestMessage | ProviderRegisteredMessage | ToolRegisteredMessage | ActionRegisteredMessage | StreamEventMessage | LogMessage | ProviderModelsResponseMessage | ToolExecuteResponseMessage | ActionExecuteResponseMessage | StreamingFetchAckMessage;
157
+ /**
158
+ * Message sent from host to worker to start a registered background task.
159
+ */
160
+ interface BackgroundTaskStartMessage {
161
+ type: 'background-task-start';
162
+ id: string;
163
+ payload: {
164
+ taskId: string;
165
+ };
166
+ }
167
+ /**
168
+ * Message sent from host to worker to stop a running background task.
169
+ */
170
+ interface BackgroundTaskStopMessage {
171
+ type: 'background-task-stop';
172
+ id: string;
173
+ payload: {
174
+ taskId: string;
175
+ };
176
+ }
177
+ type WorkerToHostMessage = ReadyMessage | RequestMessage | ProviderRegisteredMessage | ToolRegisteredMessage | ActionRegisteredMessage | StreamEventMessage | LogMessage | ProviderModelsResponseMessage | ToolExecuteResponseMessage | ActionExecuteResponseMessage | StreamingFetchAckMessage | BackgroundTaskRegisteredMessage | BackgroundTaskStatusMessage | BackgroundTaskHealthMessage;
158
178
  interface ReadyMessage {
159
179
  type: 'ready';
160
180
  }
@@ -236,6 +256,47 @@ interface LogMessage {
236
256
  data?: Record<string, unknown>;
237
257
  };
238
258
  }
259
+ /**
260
+ * Message sent from worker to host when a background task is registered.
261
+ */
262
+ interface BackgroundTaskRegisteredMessage {
263
+ type: 'background-task-registered';
264
+ payload: {
265
+ taskId: string;
266
+ name: string;
267
+ userId: string;
268
+ restartPolicy: {
269
+ type: 'always' | 'on-failure' | 'never';
270
+ maxRestarts?: number;
271
+ initialDelayMs?: number;
272
+ maxDelayMs?: number;
273
+ backoffMultiplier?: number;
274
+ };
275
+ payload?: Record<string, unknown>;
276
+ };
277
+ }
278
+ /**
279
+ * Message sent from worker to host with background task status updates.
280
+ */
281
+ interface BackgroundTaskStatusMessage {
282
+ type: 'background-task-status';
283
+ payload: {
284
+ taskId: string;
285
+ status: 'running' | 'stopped' | 'failed';
286
+ error?: string;
287
+ };
288
+ }
289
+ /**
290
+ * Message sent from worker to host with background task health reports.
291
+ */
292
+ interface BackgroundTaskHealthMessage {
293
+ type: 'background-task-health';
294
+ payload: {
295
+ taskId: string;
296
+ status: string;
297
+ timestamp: string;
298
+ };
299
+ }
239
300
  interface PendingRequest<T = unknown> {
240
301
  resolve: (value: T) => void;
241
302
  reject: (error: Error) => void;
@@ -246,4 +307,4 @@ interface PendingRequest<T = unknown> {
246
307
  */
247
308
  declare function generateMessageId(): string;
248
309
 
249
- export { type ActionExecuteRequestMessage, type ActionExecuteResponseMessage, type ActionRegisteredMessage, ActionResult, type ActivateMessage, type CapabilityPermission, ChatMessage, ChatOptions, type DeactivateMessage, ExtensionContributions, type ExtensionManifest, GetModelsOptions, type HostToWorkerMessage, type LogMessage, ModelInfo, type NetworkPermission, type PendingRequest, type Permission, type Platform, type ProviderChatRequestMessage, type ProviderModelsRequestMessage, type ProviderRegisteredMessage, type ReadyMessage, type RequestMessage, type RequestMethod, type ResponseMessage, SchedulerFirePayload, type SettingsChangedMessage, type StoragePermission, StreamEvent, type StreamEventMessage, type SystemPermission, type ToolExecuteRequestMessage, type ToolExecuteResponseMessage, type ToolRegisteredMessage, ToolResult, type UserDataPermission, type WorkerToHostMessage, generateMessageId };
310
+ export { type ActionExecuteRequestMessage, type ActionExecuteResponseMessage, type ActionRegisteredMessage, ActionResult, type ActivateMessage, type BackgroundTaskHealthMessage, type BackgroundTaskRegisteredMessage, type BackgroundTaskStartMessage, type BackgroundTaskStatusMessage, type BackgroundTaskStopMessage, type CapabilityPermission, ChatMessage, ChatOptions, type DeactivateMessage, ExtensionContributions, type ExtensionManifest, GetModelsOptions, type HostToWorkerMessage, type LogMessage, ModelInfo, type NetworkPermission, type PendingRequest, type Permission, type Platform, type ProviderChatRequestMessage, type ProviderModelsRequestMessage, type ProviderRegisteredMessage, type ReadyMessage, type RequestMessage, type RequestMethod, type ResponseMessage, SchedulerFirePayload, type SettingsChangedMessage, type StoragePermission, StreamEvent, type StreamEventMessage, type SystemPermission, type ToolExecuteRequestMessage, type ToolExecuteResponseMessage, type ToolRegisteredMessage, ToolResult, type UserDataPermission, type WorkerToHostMessage, generateMessageId };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  generateMessageId
3
- } from "./chunk-WIDGIYRV.js";
3
+ } from "./chunk-U3PEHSBG.js";
4
4
 
5
5
  // src/types.localization.ts
6
6
  function resolveLocalizedString(value, lang, fallbackLang = "en") {
package/dist/runtime.cjs CHANGED
@@ -24,6 +24,164 @@ __export(runtime_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(runtime_exports);
26
26
 
27
+ // src/background.ts
28
+ var WorkerBackgroundTaskManager = class {
29
+ tasks = /* @__PURE__ */ new Map();
30
+ options;
31
+ constructor(options) {
32
+ this.options = options;
33
+ }
34
+ /**
35
+ * Register and start a background task.
36
+ * @returns A disposable that stops the task when disposed
37
+ */
38
+ async start(config, callback) {
39
+ const { id: taskId } = config;
40
+ if (this.tasks.has(taskId)) {
41
+ throw new Error(`Background task with id '${taskId}' is already registered`);
42
+ }
43
+ const task = {
44
+ config,
45
+ callback,
46
+ abortController: null,
47
+ status: "pending"
48
+ };
49
+ this.tasks.set(taskId, task);
50
+ this.options.sendTaskRegistered(
51
+ taskId,
52
+ config.name,
53
+ config.userId,
54
+ config.restartPolicy,
55
+ config.payload
56
+ );
57
+ return {
58
+ dispose: () => {
59
+ this.stop(taskId);
60
+ }
61
+ };
62
+ }
63
+ /**
64
+ * Stop a running task.
65
+ */
66
+ stop(taskId) {
67
+ const task = this.tasks.get(taskId);
68
+ if (!task) {
69
+ return;
70
+ }
71
+ if (task.abortController) {
72
+ task.abortController.abort();
73
+ task.abortController = null;
74
+ }
75
+ task.status = "stopped";
76
+ this.options.sendTaskStatus(taskId, "stopped");
77
+ }
78
+ /**
79
+ * Handle start message from host.
80
+ * This is called when the host tells us to actually run the task.
81
+ */
82
+ async handleStart(taskId) {
83
+ const task = this.tasks.get(taskId);
84
+ if (!task) {
85
+ return;
86
+ }
87
+ if (task.abortController) {
88
+ task.abortController.abort();
89
+ task.abortController = null;
90
+ }
91
+ task.abortController = new AbortController();
92
+ task.status = "running";
93
+ task.error = void 0;
94
+ const context = this.buildTaskContext(task);
95
+ this.options.sendTaskStatus(taskId, "running");
96
+ try {
97
+ await task.callback(context);
98
+ if (task.abortController?.signal.aborted) {
99
+ task.status = "stopped";
100
+ this.options.sendTaskStatus(taskId, "stopped");
101
+ } else {
102
+ task.status = "stopped";
103
+ this.options.sendTaskStatus(taskId, "stopped");
104
+ }
105
+ } catch (error) {
106
+ const errorMessage = error instanceof Error ? error.message : String(error);
107
+ task.status = "failed";
108
+ task.error = errorMessage;
109
+ this.options.sendTaskStatus(taskId, "failed", errorMessage);
110
+ } finally {
111
+ task.abortController = null;
112
+ }
113
+ }
114
+ /**
115
+ * Handle stop message from host.
116
+ */
117
+ handleStop(taskId) {
118
+ this.stop(taskId);
119
+ }
120
+ /**
121
+ * Build the execution context for a task.
122
+ */
123
+ buildTaskContext(task) {
124
+ const { config, abortController } = task;
125
+ const signal = abortController.signal;
126
+ const log = this.options.createLogAPI(config.id);
127
+ const context = {
128
+ userId: config.userId,
129
+ extension: {
130
+ id: this.options.extensionId,
131
+ version: this.options.extensionVersion,
132
+ storagePath: this.options.storagePath
133
+ },
134
+ signal,
135
+ reportHealth: (status) => {
136
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
137
+ task.lastHealthStatus = status;
138
+ task.lastHealthTime = timestamp;
139
+ this.options.sendHealthReport(config.id, status, timestamp);
140
+ },
141
+ log
142
+ };
143
+ return context;
144
+ }
145
+ /**
146
+ * Get the status of all tasks.
147
+ */
148
+ getStatus() {
149
+ const result = [];
150
+ for (const task of this.tasks.values()) {
151
+ result.push({
152
+ taskId: task.config.id,
153
+ name: task.config.name,
154
+ userId: task.config.userId,
155
+ status: task.status,
156
+ restartCount: 0,
157
+ // Worker doesn't track restarts, host does
158
+ lastHealthStatus: task.lastHealthStatus,
159
+ lastHealthTime: task.lastHealthTime,
160
+ error: task.error
161
+ });
162
+ }
163
+ return result;
164
+ }
165
+ /**
166
+ * Check if a task exists.
167
+ */
168
+ hasTask(taskId) {
169
+ return this.tasks.has(taskId);
170
+ }
171
+ /**
172
+ * Clean up all tasks.
173
+ * Called during extension deactivation.
174
+ */
175
+ dispose() {
176
+ for (const task of this.tasks.values()) {
177
+ if (task.abortController) {
178
+ task.abortController.abort();
179
+ }
180
+ }
181
+ this.tasks.clear();
182
+ }
183
+ };
184
+
27
185
  // src/messages.ts
28
186
  function generateMessageId() {
29
187
  return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
@@ -51,6 +209,7 @@ var messagePort = getMessagePort();
51
209
  var extensionModule = null;
52
210
  var extensionDisposable = null;
53
211
  var extensionContext = null;
212
+ var backgroundTaskManager = null;
54
213
  var pendingRequests = /* @__PURE__ */ new Map();
55
214
  var registeredProviders = /* @__PURE__ */ new Map();
56
215
  var registeredTools = /* @__PURE__ */ new Map();
@@ -110,6 +269,12 @@ async function handleHostMessage(message) {
110
269
  case "streaming-fetch-chunk":
111
270
  handleStreamingFetchChunk(message.payload);
112
271
  break;
272
+ case "background-task-start":
273
+ await handleBackgroundTaskStart(message.payload.taskId);
274
+ break;
275
+ case "background-task-stop":
276
+ handleBackgroundTaskStop(message.payload.taskId);
277
+ break;
113
278
  }
114
279
  }
115
280
  function handleStreamingFetchChunk(payload) {
@@ -170,12 +335,16 @@ async function handleDeactivate() {
170
335
  if (extensionDisposable) {
171
336
  extensionDisposable.dispose();
172
337
  }
338
+ if (backgroundTaskManager) {
339
+ backgroundTaskManager.dispose();
340
+ }
173
341
  } catch (error) {
174
342
  console.error("Error during deactivation:", error);
175
343
  } finally {
176
344
  extensionModule = null;
177
345
  extensionDisposable = null;
178
346
  extensionContext = null;
347
+ backgroundTaskManager = null;
179
348
  registeredProviders.clear();
180
349
  registeredTools.clear();
181
350
  registeredActions.clear();
@@ -210,6 +379,20 @@ async function handleSchedulerFire(payload) {
210
379
  }
211
380
  });
212
381
  }
382
+ async function handleBackgroundTaskStart(taskId) {
383
+ if (!backgroundTaskManager) {
384
+ console.error("Background task manager not initialized");
385
+ return;
386
+ }
387
+ await backgroundTaskManager.handleStart(taskId);
388
+ }
389
+ function handleBackgroundTaskStop(taskId) {
390
+ if (!backgroundTaskManager) {
391
+ console.error("Background task manager not initialized");
392
+ return;
393
+ }
394
+ backgroundTaskManager.handleStop(taskId);
395
+ }
213
396
  async function handleProviderChatRequest(requestId, payload) {
214
397
  const provider = registeredProviders.get(payload.providerId);
215
398
  if (!provider) {
@@ -613,6 +796,65 @@ function buildContext(extensionId, extensionVersion, storagePath, permissions) {
613
796
  };
614
797
  context.storage = storageApi;
615
798
  }
799
+ if (hasPermission("background.workers")) {
800
+ if (!backgroundTaskManager) {
801
+ backgroundTaskManager = new WorkerBackgroundTaskManager({
802
+ extensionId,
803
+ extensionVersion,
804
+ storagePath,
805
+ sendTaskRegistered: (taskId, name, userId, restartPolicy, payload) => {
806
+ postMessage({
807
+ type: "background-task-registered",
808
+ payload: {
809
+ taskId,
810
+ name,
811
+ userId,
812
+ restartPolicy,
813
+ payload
814
+ }
815
+ });
816
+ },
817
+ sendTaskStatus: (taskId, status, error) => {
818
+ postMessage({
819
+ type: "background-task-status",
820
+ payload: {
821
+ taskId,
822
+ status,
823
+ error
824
+ }
825
+ });
826
+ },
827
+ sendHealthReport: (taskId, status, timestamp) => {
828
+ postMessage({
829
+ type: "background-task-health",
830
+ payload: {
831
+ taskId,
832
+ status,
833
+ timestamp
834
+ }
835
+ });
836
+ },
837
+ createLogAPI: (taskId) => ({
838
+ debug: (message, data) => postMessage({ type: "log", payload: { level: "debug", message: `[${taskId}] ${message}`, data } }),
839
+ info: (message, data) => postMessage({ type: "log", payload: { level: "info", message: `[${taskId}] ${message}`, data } }),
840
+ warn: (message, data) => postMessage({ type: "log", payload: { level: "warn", message: `[${taskId}] ${message}`, data } }),
841
+ error: (message, data) => postMessage({ type: "log", payload: { level: "error", message: `[${taskId}] ${message}`, data } })
842
+ })
843
+ });
844
+ }
845
+ const backgroundWorkersApi = {
846
+ async start(config, callback) {
847
+ return backgroundTaskManager.start(config, callback);
848
+ },
849
+ async stop(taskId) {
850
+ backgroundTaskManager.stop(taskId);
851
+ },
852
+ async getStatus() {
853
+ return backgroundTaskManager.getStatus();
854
+ }
855
+ };
856
+ context.backgroundWorkers = backgroundWorkersApi;
857
+ }
616
858
  return context;
617
859
  }
618
860
  function initializeExtension(module2) {