@stina/extension-api 0.25.0 → 0.26.0-alpha.ea677a6
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.
- package/README.md +75 -0
- package/dist/{chunk-PTPOHFA4.js → chunk-VSPMXOO7.js} +1 -1
- package/dist/{chunk-PTPOHFA4.js.map → chunk-VSPMXOO7.js.map} +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/runtime.cjs +112 -143
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/runtime.js +113 -144
- package/dist/runtime.js.map +1 -1
- package/dist/schemas/index.cjs +9 -0
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +48 -1
- package/dist/schemas/index.d.ts +48 -1
- package/dist/schemas/index.js +8 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/{types.tools-6o0mTWW-.d.cts → types.tools-ymsggUiN.d.cts} +24 -1
- package/dist/{types.tools-6o0mTWW-.d.ts → types.tools-ymsggUiN.d.ts} +24 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/messages.ts +1 -0
- package/src/runtime/executionContext.ts +37 -0
- package/src/runtime/index.ts +8 -0
- package/src/runtime/secretsApi.ts +48 -0
- package/src/runtime/storageApi.ts +67 -0
- package/src/runtime.ts +33 -164
- package/src/schemas/components.schema.ts +12 -0
- package/src/schemas/index.ts +2 -0
- package/src/types.components.ts +8 -0
- package/src/types.contributions.ts +17 -0
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -168,6 +168,81 @@ interface ToolResult {
|
|
|
168
168
|
}
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
### Tool confirmation
|
|
172
|
+
|
|
173
|
+
For tools that perform sensitive or potentially destructive actions (e.g., sending emails, deleting data, making purchases), you can require user confirmation before the tool executes.
|
|
174
|
+
|
|
175
|
+
Add a `confirmation` field to your tool definition:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
context.tools?.register({
|
|
179
|
+
id: 'my-extension.send-email',
|
|
180
|
+
name: {
|
|
181
|
+
en: 'Send Email',
|
|
182
|
+
sv: 'Skicka e-post',
|
|
183
|
+
},
|
|
184
|
+
description: 'Sends an email to the specified recipient',
|
|
185
|
+
parameters: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: {
|
|
188
|
+
to: { type: 'string', description: 'Recipient email' },
|
|
189
|
+
subject: { type: 'string', description: 'Email subject' },
|
|
190
|
+
body: { type: 'string', description: 'Email body' },
|
|
191
|
+
},
|
|
192
|
+
required: ['to', 'subject', 'body'],
|
|
193
|
+
},
|
|
194
|
+
confirmation: {
|
|
195
|
+
prompt: {
|
|
196
|
+
en: 'Allow sending email to {{to}}?',
|
|
197
|
+
sv: 'Tillåt att skicka e-post till {{to}}?',
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
execute: async (params) => {
|
|
201
|
+
// Only runs after user confirms
|
|
202
|
+
await sendEmail(params.to, params.subject, params.body)
|
|
203
|
+
return { success: true }
|
|
204
|
+
},
|
|
205
|
+
})
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
You can also declare confirmation in `manifest.json`:
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"contributes": {
|
|
213
|
+
"tools": [
|
|
214
|
+
{
|
|
215
|
+
"id": "my-extension.send-email",
|
|
216
|
+
"name": { "en": "Send Email", "sv": "Skicka e-post" },
|
|
217
|
+
"description": "Sends an email",
|
|
218
|
+
"confirmation": {
|
|
219
|
+
"prompt": {
|
|
220
|
+
"en": "Allow sending this email?",
|
|
221
|
+
"sv": "Tillåt att skicka detta e-postmeddelande?"
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**How confirmation works:**
|
|
231
|
+
|
|
232
|
+
1. When the AI calls the tool, Stina pauses execution and shows a confirmation dialog
|
|
233
|
+
2. The user sees the confirmation prompt (or a default "Allow {toolName} to run?")
|
|
234
|
+
3. The user can approve, deny, or deny with a custom message
|
|
235
|
+
4. If approved, the tool executes normally
|
|
236
|
+
5. If denied, the AI receives an error message explaining the denial
|
|
237
|
+
|
|
238
|
+
**Configuration options:**
|
|
239
|
+
|
|
240
|
+
- `confirmation.prompt` (optional): Custom prompt to show the user. Can be a string or localized object. If omitted, a generic prompt is shown.
|
|
241
|
+
|
|
242
|
+
**AI custom messages:**
|
|
243
|
+
|
|
244
|
+
The AI can provide a custom confirmation message by including a `_confirmationMessage` parameter when calling the tool. This allows context-aware prompts like "May I send an email to john@example.com about the project deadline?"
|
|
245
|
+
|
|
171
246
|
## Common patterns
|
|
172
247
|
|
|
173
248
|
- Use `contributes` in `manifest.json` for UI definitions.
|
|
@@ -1 +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 // Simple key-value storage methods\n | 'storage.set'\n | 'storage.keys'\n | 'storage.setForUser'\n | 'storage.keysForUser'\n // Collection-based storage methods\n | 'storage.put'\n | 'storage.get'\n | 'storage.delete'\n | 'storage.find'\n | 'storage.findOne'\n | 'storage.count'\n | 'storage.putMany'\n | 'storage.deleteMany'\n | 'storage.dropCollection'\n | 'storage.listCollections'\n | 'storage.putForUser'\n | 'storage.getForUser'\n | 'storage.deleteForUser'\n | 'storage.findForUser'\n | 'storage.findOneForUser'\n | 'storage.countForUser'\n | 'storage.putManyForUser'\n | 'storage.deleteManyForUser'\n | 'storage.dropCollectionForUser'\n | 'storage.listCollectionsForUser'\n // Secrets methods\n | 'secrets.set'\n | 'secrets.get'\n | 'secrets.delete'\n | 'secrets.list'\n | 'secrets.setForUser'\n | 'secrets.getForUser'\n | 'secrets.deleteForUser'\n | 'secrets.listForUser'\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":";
|
|
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 | 'scheduler.reportFireResult'\n | 'chat.appendInstruction'\n | 'database.execute'\n // Simple key-value storage methods\n | 'storage.set'\n | 'storage.keys'\n | 'storage.setForUser'\n | 'storage.keysForUser'\n // Collection-based storage methods\n | 'storage.put'\n | 'storage.get'\n | 'storage.delete'\n | 'storage.find'\n | 'storage.findOne'\n | 'storage.count'\n | 'storage.putMany'\n | 'storage.deleteMany'\n | 'storage.dropCollection'\n | 'storage.listCollections'\n | 'storage.putForUser'\n | 'storage.getForUser'\n | 'storage.deleteForUser'\n | 'storage.findForUser'\n | 'storage.findOneForUser'\n | 'storage.countForUser'\n | 'storage.putManyForUser'\n | 'storage.deleteManyForUser'\n | 'storage.dropCollectionForUser'\n | 'storage.listCollectionsForUser'\n // Secrets methods\n | 'secrets.set'\n | 'secrets.get'\n | 'secrets.delete'\n | 'secrets.list'\n | 'secrets.setForUser'\n | 'secrets.getForUser'\n | 'secrets.deleteForUser'\n | 'secrets.listForUser'\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":";AAmXO,SAAS,oBAA4B;AAC1C,SAAO,GAAG,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AACjE;","names":[]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 LogAPI,\n\n // Background workers\n BackgroundWorkersAPI,\n BackgroundTaskConfig,\n BackgroundTaskCallback,\n BackgroundTaskContext,\n BackgroundTaskHealth,\n BackgroundRestartPolicy,\n\n // Storage and Secrets\n Query,\n QueryOptions,\n StorageAPI,\n SecretsAPI,\n StorageCollectionConfig,\n StorageContributions,\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 // Simple key-value storage methods\n | 'storage.set'\n | 'storage.keys'\n | 'storage.setForUser'\n | 'storage.keysForUser'\n // Collection-based storage methods\n | 'storage.put'\n | 'storage.get'\n | 'storage.delete'\n | 'storage.find'\n | 'storage.findOne'\n | 'storage.count'\n | 'storage.putMany'\n | 'storage.deleteMany'\n | 'storage.dropCollection'\n | 'storage.listCollections'\n | 'storage.putForUser'\n | 'storage.getForUser'\n | 'storage.deleteForUser'\n | 'storage.findForUser'\n | 'storage.findOneForUser'\n | 'storage.countForUser'\n | 'storage.putManyForUser'\n | 'storage.deleteManyForUser'\n | 'storage.dropCollectionForUser'\n | 'storage.listCollectionsForUser'\n // Secrets methods\n | 'secrets.set'\n | 'secrets.get'\n | 'secrets.delete'\n | 'secrets.list'\n | 'secrets.setForUser'\n | 'secrets.getForUser'\n | 'secrets.deleteForUser'\n | 'secrets.listForUser'\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;;;AC4UO,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 ToolConfirmationConfig,\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 LogAPI,\n\n // Background workers\n BackgroundWorkersAPI,\n BackgroundTaskConfig,\n BackgroundTaskCallback,\n BackgroundTaskContext,\n BackgroundTaskHealth,\n BackgroundRestartPolicy,\n\n // Storage and Secrets\n Query,\n QueryOptions,\n StorageAPI,\n SecretsAPI,\n StorageCollectionConfig,\n StorageContributions,\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 IconPickerProps,\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 | 'scheduler.reportFireResult'\n | 'chat.appendInstruction'\n | 'database.execute'\n // Simple key-value storage methods\n | 'storage.set'\n | 'storage.keys'\n | 'storage.setForUser'\n | 'storage.keysForUser'\n // Collection-based storage methods\n | 'storage.put'\n | 'storage.get'\n | 'storage.delete'\n | 'storage.find'\n | 'storage.findOne'\n | 'storage.count'\n | 'storage.putMany'\n | 'storage.deleteMany'\n | 'storage.dropCollection'\n | 'storage.listCollections'\n | 'storage.putForUser'\n | 'storage.getForUser'\n | 'storage.deleteForUser'\n | 'storage.findForUser'\n | 'storage.findOneForUser'\n | 'storage.countForUser'\n | 'storage.putManyForUser'\n | 'storage.deleteManyForUser'\n | 'storage.dropCollectionForUser'\n | 'storage.listCollectionsForUser'\n // Secrets methods\n | 'secrets.set'\n | 'secrets.get'\n | 'secrets.delete'\n | 'secrets.list'\n | 'secrets.setForUser'\n | 'secrets.getForUser'\n | 'secrets.deleteForUser'\n | 'secrets.listForUser'\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;;;AC6UO,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-
|
|
2
|
-
export {
|
|
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-ymsggUiN.cjs';
|
|
2
|
+
export { aa as AIProvider, ad as Action, K as ActionsAPI, af as AllowedCSSProperty, a3 as BackgroundRestartPolicy, a0 as BackgroundTaskCallback, $ as BackgroundTaskConfig, a1 as BackgroundTaskContext, a2 as BackgroundTaskHealth, _ as BackgroundWorkersAPI, ar as ButtonProps, X as ChatAPI, Y as ChatInstructionMessage, aJ as CheckboxProps, aG as CollapsibleProps, v as CommandDefinition, aM as ConditionalGroupProps, at as DateTimeInputProps, F as Disposable, az as DividerProps, O as EventsAPI, ak as ExtensionActionCall, al as ExtensionActionRef, aj as ExtensionComponentChildren, ah as ExtensionComponentData, ai as ExtensionComponentIterator, ag as ExtensionComponentStyle, D as ExtensionContext, am as ExtensionDataSource, ae as ExtensionModule, an as ExtensionPanelDefinition, ay as GridProps, ao as HeaderProps, ax as HorizontalStackProps, aC as IconButtonProps, aB as IconButtonType, av as IconPickerProps, aA as IconProps, ap as LabelProps, L as LocalizedString, Z as LogAPI, aK as MarkdownProps, aL as ModalProps, N as NetworkAPI, aD as PanelAction, n as PanelActionDataSource, m as PanelComponentView, P as PanelDefinition, aE as PanelProps, o as PanelUnknownView, l as PanelView, aq as ParagraphProps, aI as PillProps, aH as PillVariant, q as PromptContribution, s as PromptSection, x as ProviderConfigProperty, y as ProviderConfigPropertyType, w as ProviderConfigSchema, z as ProviderConfigSelectOption, B as ProviderConfigValidation, p as ProviderDefinition, I as ProvidersAPI, a4 as Query, a5 as QueryOptions, Q as SchedulerAPI, R as SchedulerJobRequest, U as SchedulerSchedule, a7 as SecretsAPI, au as SelectProps, e as SettingCreateMapping, c as SettingDefinition, d as SettingOptionsMapping, H as SettingsAPI, a6 as StorageAPI, a8 as StorageCollectionConfig, a9 as StorageContributions, as as TextInputProps, aF as ToggleProps, ac as Tool, ab as ToolCall, u as ToolConfirmationConfig, t as ToolDefinition, k as ToolSettingsActionDataSource, j as ToolSettingsComponentView, i as ToolSettingsListMapping, h as ToolSettingsListView, g as ToolSettingsView, f as ToolSettingsViewDefinition, J as ToolsAPI, V as UserAPI, W as UserProfile, aw as VerticalStackProps, r as resolveLocalizedString } from './types.tools-ymsggUiN.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Permission Types
|
|
@@ -194,7 +194,7 @@ interface RequestMessage {
|
|
|
194
194
|
method: RequestMethod;
|
|
195
195
|
payload: unknown;
|
|
196
196
|
}
|
|
197
|
-
type RequestMethod = 'network.fetch' | 'network.fetch-stream' | 'settings.getAll' | 'settings.get' | 'settings.set' | 'user.getProfile' | 'events.emit' | 'scheduler.schedule' | 'scheduler.cancel' | 'chat.appendInstruction' | 'database.execute' | 'storage.set' | 'storage.keys' | 'storage.setForUser' | 'storage.keysForUser' | 'storage.put' | 'storage.get' | 'storage.delete' | 'storage.find' | 'storage.findOne' | 'storage.count' | 'storage.putMany' | 'storage.deleteMany' | 'storage.dropCollection' | 'storage.listCollections' | 'storage.putForUser' | 'storage.getForUser' | 'storage.deleteForUser' | 'storage.findForUser' | 'storage.findOneForUser' | 'storage.countForUser' | 'storage.putManyForUser' | 'storage.deleteManyForUser' | 'storage.dropCollectionForUser' | 'storage.listCollectionsForUser' | 'secrets.set' | 'secrets.get' | 'secrets.delete' | 'secrets.list' | 'secrets.setForUser' | 'secrets.getForUser' | 'secrets.deleteForUser' | 'secrets.listForUser';
|
|
197
|
+
type RequestMethod = 'network.fetch' | 'network.fetch-stream' | 'settings.getAll' | 'settings.get' | 'settings.set' | 'user.getProfile' | 'events.emit' | 'scheduler.schedule' | 'scheduler.cancel' | 'scheduler.reportFireResult' | 'chat.appendInstruction' | 'database.execute' | 'storage.set' | 'storage.keys' | 'storage.setForUser' | 'storage.keysForUser' | 'storage.put' | 'storage.get' | 'storage.delete' | 'storage.find' | 'storage.findOne' | 'storage.count' | 'storage.putMany' | 'storage.deleteMany' | 'storage.dropCollection' | 'storage.listCollections' | 'storage.putForUser' | 'storage.getForUser' | 'storage.deleteForUser' | 'storage.findForUser' | 'storage.findOneForUser' | 'storage.countForUser' | 'storage.putManyForUser' | 'storage.deleteManyForUser' | 'storage.dropCollectionForUser' | 'storage.listCollectionsForUser' | 'secrets.set' | 'secrets.get' | 'secrets.delete' | 'secrets.list' | 'secrets.setForUser' | 'secrets.getForUser' | 'secrets.deleteForUser' | 'secrets.listForUser';
|
|
198
198
|
interface ProviderRegisteredMessage {
|
|
199
199
|
type: 'provider-registered';
|
|
200
200
|
payload: {
|
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-
|
|
2
|
-
export {
|
|
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-ymsggUiN.js';
|
|
2
|
+
export { aa as AIProvider, ad as Action, K as ActionsAPI, af as AllowedCSSProperty, a3 as BackgroundRestartPolicy, a0 as BackgroundTaskCallback, $ as BackgroundTaskConfig, a1 as BackgroundTaskContext, a2 as BackgroundTaskHealth, _ as BackgroundWorkersAPI, ar as ButtonProps, X as ChatAPI, Y as ChatInstructionMessage, aJ as CheckboxProps, aG as CollapsibleProps, v as CommandDefinition, aM as ConditionalGroupProps, at as DateTimeInputProps, F as Disposable, az as DividerProps, O as EventsAPI, ak as ExtensionActionCall, al as ExtensionActionRef, aj as ExtensionComponentChildren, ah as ExtensionComponentData, ai as ExtensionComponentIterator, ag as ExtensionComponentStyle, D as ExtensionContext, am as ExtensionDataSource, ae as ExtensionModule, an as ExtensionPanelDefinition, ay as GridProps, ao as HeaderProps, ax as HorizontalStackProps, aC as IconButtonProps, aB as IconButtonType, av as IconPickerProps, aA as IconProps, ap as LabelProps, L as LocalizedString, Z as LogAPI, aK as MarkdownProps, aL as ModalProps, N as NetworkAPI, aD as PanelAction, n as PanelActionDataSource, m as PanelComponentView, P as PanelDefinition, aE as PanelProps, o as PanelUnknownView, l as PanelView, aq as ParagraphProps, aI as PillProps, aH as PillVariant, q as PromptContribution, s as PromptSection, x as ProviderConfigProperty, y as ProviderConfigPropertyType, w as ProviderConfigSchema, z as ProviderConfigSelectOption, B as ProviderConfigValidation, p as ProviderDefinition, I as ProvidersAPI, a4 as Query, a5 as QueryOptions, Q as SchedulerAPI, R as SchedulerJobRequest, U as SchedulerSchedule, a7 as SecretsAPI, au as SelectProps, e as SettingCreateMapping, c as SettingDefinition, d as SettingOptionsMapping, H as SettingsAPI, a6 as StorageAPI, a8 as StorageCollectionConfig, a9 as StorageContributions, as as TextInputProps, aF as ToggleProps, ac as Tool, ab as ToolCall, u as ToolConfirmationConfig, t as ToolDefinition, k as ToolSettingsActionDataSource, j as ToolSettingsComponentView, i as ToolSettingsListMapping, h as ToolSettingsListView, g as ToolSettingsView, f as ToolSettingsViewDefinition, J as ToolsAPI, V as UserAPI, W as UserProfile, aw as VerticalStackProps, r as resolveLocalizedString } from './types.tools-ymsggUiN.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Permission Types
|
|
@@ -194,7 +194,7 @@ interface RequestMessage {
|
|
|
194
194
|
method: RequestMethod;
|
|
195
195
|
payload: unknown;
|
|
196
196
|
}
|
|
197
|
-
type RequestMethod = 'network.fetch' | 'network.fetch-stream' | 'settings.getAll' | 'settings.get' | 'settings.set' | 'user.getProfile' | 'events.emit' | 'scheduler.schedule' | 'scheduler.cancel' | 'chat.appendInstruction' | 'database.execute' | 'storage.set' | 'storage.keys' | 'storage.setForUser' | 'storage.keysForUser' | 'storage.put' | 'storage.get' | 'storage.delete' | 'storage.find' | 'storage.findOne' | 'storage.count' | 'storage.putMany' | 'storage.deleteMany' | 'storage.dropCollection' | 'storage.listCollections' | 'storage.putForUser' | 'storage.getForUser' | 'storage.deleteForUser' | 'storage.findForUser' | 'storage.findOneForUser' | 'storage.countForUser' | 'storage.putManyForUser' | 'storage.deleteManyForUser' | 'storage.dropCollectionForUser' | 'storage.listCollectionsForUser' | 'secrets.set' | 'secrets.get' | 'secrets.delete' | 'secrets.list' | 'secrets.setForUser' | 'secrets.getForUser' | 'secrets.deleteForUser' | 'secrets.listForUser';
|
|
197
|
+
type RequestMethod = 'network.fetch' | 'network.fetch-stream' | 'settings.getAll' | 'settings.get' | 'settings.set' | 'user.getProfile' | 'events.emit' | 'scheduler.schedule' | 'scheduler.cancel' | 'scheduler.reportFireResult' | 'chat.appendInstruction' | 'database.execute' | 'storage.set' | 'storage.keys' | 'storage.setForUser' | 'storage.keysForUser' | 'storage.put' | 'storage.get' | 'storage.delete' | 'storage.find' | 'storage.findOne' | 'storage.count' | 'storage.putMany' | 'storage.deleteMany' | 'storage.dropCollection' | 'storage.listCollections' | 'storage.putForUser' | 'storage.getForUser' | 'storage.deleteForUser' | 'storage.findForUser' | 'storage.findOneForUser' | 'storage.countForUser' | 'storage.putManyForUser' | 'storage.deleteManyForUser' | 'storage.dropCollectionForUser' | 'storage.listCollectionsForUser' | 'secrets.set' | 'secrets.get' | 'secrets.delete' | 'secrets.list' | 'secrets.setForUser' | 'secrets.getForUser' | 'secrets.deleteForUser' | 'secrets.listForUser';
|
|
198
198
|
interface ProviderRegisteredMessage {
|
|
199
199
|
type: 'provider-registered';
|
|
200
200
|
payload: {
|
package/dist/index.js
CHANGED
package/dist/runtime.cjs
CHANGED
|
@@ -195,6 +195,99 @@ function generateMessageId() {
|
|
|
195
195
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
// src/runtime/storageApi.ts
|
|
199
|
+
function buildStorageAPI(sendRequest2, methodSuffix, userId) {
|
|
200
|
+
const extraPayload = userId ? { userId } : {};
|
|
201
|
+
return {
|
|
202
|
+
async put(collection, id, data) {
|
|
203
|
+
return sendRequest2(`storage.put${methodSuffix}`, { ...extraPayload, collection, id, data });
|
|
204
|
+
},
|
|
205
|
+
async get(collection, id) {
|
|
206
|
+
return sendRequest2(`storage.get${methodSuffix}`, { ...extraPayload, collection, id });
|
|
207
|
+
},
|
|
208
|
+
async delete(collection, id) {
|
|
209
|
+
return sendRequest2(`storage.delete${methodSuffix}`, { ...extraPayload, collection, id });
|
|
210
|
+
},
|
|
211
|
+
async find(collection, query, options) {
|
|
212
|
+
return sendRequest2(`storage.find${methodSuffix}`, { ...extraPayload, collection, query, options });
|
|
213
|
+
},
|
|
214
|
+
async findOne(collection, query) {
|
|
215
|
+
return sendRequest2(`storage.findOne${methodSuffix}`, { ...extraPayload, collection, query });
|
|
216
|
+
},
|
|
217
|
+
async count(collection, query) {
|
|
218
|
+
return sendRequest2(`storage.count${methodSuffix}`, { ...extraPayload, collection, query });
|
|
219
|
+
},
|
|
220
|
+
async putMany(collection, docs) {
|
|
221
|
+
return sendRequest2(`storage.putMany${methodSuffix}`, { ...extraPayload, collection, docs });
|
|
222
|
+
},
|
|
223
|
+
async deleteMany(collection, query) {
|
|
224
|
+
return sendRequest2(`storage.deleteMany${methodSuffix}`, { ...extraPayload, collection, query });
|
|
225
|
+
},
|
|
226
|
+
async dropCollection(collection) {
|
|
227
|
+
return sendRequest2(`storage.dropCollection${methodSuffix}`, { ...extraPayload, collection });
|
|
228
|
+
},
|
|
229
|
+
async listCollections() {
|
|
230
|
+
return sendRequest2(`storage.listCollections${methodSuffix}`, { ...extraPayload });
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function buildExtensionStorageAPI(sendRequest2) {
|
|
235
|
+
return buildStorageAPI(sendRequest2, "");
|
|
236
|
+
}
|
|
237
|
+
function buildUserStorageAPI(sendRequest2, userId) {
|
|
238
|
+
return buildStorageAPI(sendRequest2, "ForUser", userId);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/runtime/secretsApi.ts
|
|
242
|
+
function buildExtensionSecretsAPI(sendRequest2) {
|
|
243
|
+
return {
|
|
244
|
+
async set(key, value) {
|
|
245
|
+
return sendRequest2("secrets.set", { key, value });
|
|
246
|
+
},
|
|
247
|
+
async get(key) {
|
|
248
|
+
return sendRequest2("secrets.get", { key });
|
|
249
|
+
},
|
|
250
|
+
async delete(key) {
|
|
251
|
+
return sendRequest2("secrets.delete", { key });
|
|
252
|
+
},
|
|
253
|
+
async list() {
|
|
254
|
+
return sendRequest2("secrets.list", {});
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function buildUserSecretsAPI(sendRequest2, userId) {
|
|
259
|
+
return {
|
|
260
|
+
async set(key, value) {
|
|
261
|
+
return sendRequest2("secrets.setForUser", { userId, key, value });
|
|
262
|
+
},
|
|
263
|
+
async get(key) {
|
|
264
|
+
return sendRequest2("secrets.getForUser", { userId, key });
|
|
265
|
+
},
|
|
266
|
+
async delete(key) {
|
|
267
|
+
return sendRequest2("secrets.deleteForUser", { userId, key });
|
|
268
|
+
},
|
|
269
|
+
async list() {
|
|
270
|
+
return sendRequest2("secrets.listForUser", { userId });
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/runtime/executionContext.ts
|
|
276
|
+
function createExecutionContext(sendRequest2, extensionContext2, userId) {
|
|
277
|
+
return {
|
|
278
|
+
userId,
|
|
279
|
+
extension: {
|
|
280
|
+
id: extensionContext2.extension.id,
|
|
281
|
+
version: extensionContext2.extension.version,
|
|
282
|
+
storagePath: extensionContext2.extension.storagePath
|
|
283
|
+
},
|
|
284
|
+
storage: buildExtensionStorageAPI(sendRequest2),
|
|
285
|
+
userStorage: userId ? buildUserStorageAPI(sendRequest2, userId) : buildExtensionStorageAPI(sendRequest2),
|
|
286
|
+
secrets: buildExtensionSecretsAPI(sendRequest2),
|
|
287
|
+
userSecrets: userId ? buildUserSecretsAPI(sendRequest2, userId) : buildExtensionSecretsAPI(sendRequest2)
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
198
291
|
// src/runtime.ts
|
|
199
292
|
function getMessagePort() {
|
|
200
293
|
if (typeof process !== "undefined" && process.versions?.node) {
|
|
@@ -369,127 +462,25 @@ function handleSettingsChanged(key, value) {
|
|
|
369
462
|
}
|
|
370
463
|
}
|
|
371
464
|
}
|
|
372
|
-
function buildExtensionStorageAPI() {
|
|
373
|
-
return {
|
|
374
|
-
async put(collection, id, data) {
|
|
375
|
-
return sendRequest("storage.put", { collection, id, data });
|
|
376
|
-
},
|
|
377
|
-
async get(collection, id) {
|
|
378
|
-
return sendRequest("storage.get", { collection, id });
|
|
379
|
-
},
|
|
380
|
-
async delete(collection, id) {
|
|
381
|
-
return sendRequest("storage.delete", { collection, id });
|
|
382
|
-
},
|
|
383
|
-
async find(collection, query, options) {
|
|
384
|
-
return sendRequest("storage.find", { collection, query, options });
|
|
385
|
-
},
|
|
386
|
-
async findOne(collection, query) {
|
|
387
|
-
return sendRequest("storage.findOne", { collection, query });
|
|
388
|
-
},
|
|
389
|
-
async count(collection, query) {
|
|
390
|
-
return sendRequest("storage.count", { collection, query });
|
|
391
|
-
},
|
|
392
|
-
async putMany(collection, docs) {
|
|
393
|
-
return sendRequest("storage.putMany", { collection, docs });
|
|
394
|
-
},
|
|
395
|
-
async deleteMany(collection, query) {
|
|
396
|
-
return sendRequest("storage.deleteMany", { collection, query });
|
|
397
|
-
},
|
|
398
|
-
async dropCollection(collection) {
|
|
399
|
-
return sendRequest("storage.dropCollection", { collection });
|
|
400
|
-
},
|
|
401
|
-
async listCollections() {
|
|
402
|
-
return sendRequest("storage.listCollections", {});
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
function buildUserStorageAPI(userId) {
|
|
407
|
-
return {
|
|
408
|
-
async put(collection, id, data) {
|
|
409
|
-
return sendRequest("storage.putForUser", { userId, collection, id, data });
|
|
410
|
-
},
|
|
411
|
-
async get(collection, id) {
|
|
412
|
-
return sendRequest("storage.getForUser", { userId, collection, id });
|
|
413
|
-
},
|
|
414
|
-
async delete(collection, id) {
|
|
415
|
-
return sendRequest("storage.deleteForUser", { userId, collection, id });
|
|
416
|
-
},
|
|
417
|
-
async find(collection, query, options) {
|
|
418
|
-
return sendRequest("storage.findForUser", { userId, collection, query, options });
|
|
419
|
-
},
|
|
420
|
-
async findOne(collection, query) {
|
|
421
|
-
return sendRequest("storage.findOneForUser", { userId, collection, query });
|
|
422
|
-
},
|
|
423
|
-
async count(collection, query) {
|
|
424
|
-
return sendRequest("storage.countForUser", { userId, collection, query });
|
|
425
|
-
},
|
|
426
|
-
async putMany(collection, docs) {
|
|
427
|
-
return sendRequest("storage.putManyForUser", { userId, collection, docs });
|
|
428
|
-
},
|
|
429
|
-
async deleteMany(collection, query) {
|
|
430
|
-
return sendRequest("storage.deleteManyForUser", { userId, collection, query });
|
|
431
|
-
},
|
|
432
|
-
async dropCollection(collection) {
|
|
433
|
-
return sendRequest("storage.dropCollectionForUser", { userId, collection });
|
|
434
|
-
},
|
|
435
|
-
async listCollections() {
|
|
436
|
-
return sendRequest("storage.listCollectionsForUser", { userId });
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
function buildExtensionSecretsAPI() {
|
|
441
|
-
return {
|
|
442
|
-
async set(key, value) {
|
|
443
|
-
return sendRequest("secrets.set", { key, value });
|
|
444
|
-
},
|
|
445
|
-
async get(key) {
|
|
446
|
-
return sendRequest("secrets.get", { key });
|
|
447
|
-
},
|
|
448
|
-
async delete(key) {
|
|
449
|
-
return sendRequest("secrets.delete", { key });
|
|
450
|
-
},
|
|
451
|
-
async list() {
|
|
452
|
-
return sendRequest("secrets.list", {});
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
function buildUserSecretsAPI(userId) {
|
|
457
|
-
return {
|
|
458
|
-
async set(key, value) {
|
|
459
|
-
return sendRequest("secrets.setForUser", { userId, key, value });
|
|
460
|
-
},
|
|
461
|
-
async get(key) {
|
|
462
|
-
return sendRequest("secrets.getForUser", { userId, key });
|
|
463
|
-
},
|
|
464
|
-
async delete(key) {
|
|
465
|
-
return sendRequest("secrets.deleteForUser", { userId, key });
|
|
466
|
-
},
|
|
467
|
-
async list() {
|
|
468
|
-
return sendRequest("secrets.listForUser", { userId });
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
465
|
async function handleSchedulerFire(payload) {
|
|
473
|
-
const execContext =
|
|
474
|
-
userId: payload.userId,
|
|
475
|
-
extension: {
|
|
476
|
-
id: extensionContext.extension.id,
|
|
477
|
-
version: extensionContext.extension.version,
|
|
478
|
-
storagePath: extensionContext.extension.storagePath
|
|
479
|
-
},
|
|
480
|
-
storage: buildExtensionStorageAPI(),
|
|
481
|
-
userStorage: payload.userId ? buildUserStorageAPI(payload.userId) : buildExtensionStorageAPI(),
|
|
482
|
-
secrets: buildExtensionSecretsAPI(),
|
|
483
|
-
userSecrets: payload.userId ? buildUserSecretsAPI(payload.userId) : buildExtensionSecretsAPI()
|
|
484
|
-
};
|
|
466
|
+
const execContext = createExecutionContext(sendRequest, extensionContext, payload.userId);
|
|
485
467
|
const results = await Promise.allSettled(
|
|
486
|
-
schedulerCallbacks.map((callback) => callback(payload, execContext))
|
|
468
|
+
schedulerCallbacks.map((callback) => Promise.resolve(callback(payload, execContext)))
|
|
487
469
|
);
|
|
488
470
|
results.forEach((result, index) => {
|
|
489
471
|
if (result.status === "rejected") {
|
|
490
472
|
console.error(`Error in scheduler callback ${index}:`, result.reason);
|
|
491
473
|
}
|
|
492
474
|
});
|
|
475
|
+
const failed = results.find((r) => r.status === "rejected");
|
|
476
|
+
try {
|
|
477
|
+
await sendRequest("scheduler.reportFireResult", {
|
|
478
|
+
jobId: payload.id,
|
|
479
|
+
success: !failed,
|
|
480
|
+
error: failed ? String(failed.reason) : void 0
|
|
481
|
+
});
|
|
482
|
+
} catch {
|
|
483
|
+
}
|
|
493
484
|
}
|
|
494
485
|
async function handleBackgroundTaskStart(taskId) {
|
|
495
486
|
if (!backgroundTaskManager) {
|
|
@@ -601,18 +592,7 @@ async function handleToolExecuteRequest(requestId, payload) {
|
|
|
601
592
|
return;
|
|
602
593
|
}
|
|
603
594
|
try {
|
|
604
|
-
const execContext =
|
|
605
|
-
userId: payload.userId,
|
|
606
|
-
extension: {
|
|
607
|
-
id: extensionContext.extension.id,
|
|
608
|
-
version: extensionContext.extension.version,
|
|
609
|
-
storagePath: extensionContext.extension.storagePath
|
|
610
|
-
},
|
|
611
|
-
storage: buildExtensionStorageAPI(),
|
|
612
|
-
userStorage: payload.userId ? buildUserStorageAPI(payload.userId) : buildExtensionStorageAPI(),
|
|
613
|
-
secrets: buildExtensionSecretsAPI(),
|
|
614
|
-
userSecrets: payload.userId ? buildUserSecretsAPI(payload.userId) : buildExtensionSecretsAPI()
|
|
615
|
-
};
|
|
595
|
+
const execContext = createExecutionContext(sendRequest, extensionContext, payload.userId);
|
|
616
596
|
const result = await tool.execute(payload.params, execContext);
|
|
617
597
|
postMessage({
|
|
618
598
|
type: "tool-execute-response",
|
|
@@ -647,18 +627,7 @@ async function handleActionExecuteRequest(requestId, payload) {
|
|
|
647
627
|
return;
|
|
648
628
|
}
|
|
649
629
|
try {
|
|
650
|
-
const execContext =
|
|
651
|
-
userId: payload.userId,
|
|
652
|
-
extension: {
|
|
653
|
-
id: extensionContext.extension.id,
|
|
654
|
-
version: extensionContext.extension.version,
|
|
655
|
-
storagePath: extensionContext.extension.storagePath
|
|
656
|
-
},
|
|
657
|
-
storage: buildExtensionStorageAPI(),
|
|
658
|
-
userStorage: payload.userId ? buildUserStorageAPI(payload.userId) : buildExtensionStorageAPI(),
|
|
659
|
-
secrets: buildExtensionSecretsAPI(),
|
|
660
|
-
userSecrets: payload.userId ? buildUserSecretsAPI(payload.userId) : buildExtensionSecretsAPI()
|
|
661
|
-
};
|
|
630
|
+
const execContext = createExecutionContext(sendRequest, extensionContext, payload.userId);
|
|
662
631
|
const result = await action.execute(payload.params, execContext);
|
|
663
632
|
postMessage({
|
|
664
633
|
type: "action-execute-response",
|
|
@@ -879,11 +848,11 @@ function buildContext(extensionId, extensionVersion, storagePath, permissions) {
|
|
|
879
848
|
}
|
|
880
849
|
if (hasPermission("storage.collections")) {
|
|
881
850
|
;
|
|
882
|
-
context.storage = buildExtensionStorageAPI();
|
|
851
|
+
context.storage = buildExtensionStorageAPI(sendRequest);
|
|
883
852
|
}
|
|
884
853
|
if (hasPermission("secrets.manage")) {
|
|
885
854
|
;
|
|
886
|
-
context.secrets = buildExtensionSecretsAPI();
|
|
855
|
+
context.secrets = buildExtensionSecretsAPI(sendRequest);
|
|
887
856
|
}
|
|
888
857
|
if (hasPermission("background.workers")) {
|
|
889
858
|
if (!backgroundTaskManager) {
|
|
@@ -929,10 +898,10 @@ function buildContext(extensionId, extensionVersion, storagePath, permissions) {
|
|
|
929
898
|
warn: (message, data) => postMessage({ type: "log", payload: { level: "warn", message: `[${taskId}] ${message}`, data } }),
|
|
930
899
|
error: (message, data) => postMessage({ type: "log", payload: { level: "error", message: `[${taskId}] ${message}`, data } })
|
|
931
900
|
}),
|
|
932
|
-
createStorageAPI: () => buildExtensionStorageAPI(),
|
|
933
|
-
createUserStorageAPI: (userId) => buildUserStorageAPI(userId),
|
|
934
|
-
createSecretsAPI: () => buildExtensionSecretsAPI(),
|
|
935
|
-
createUserSecretsAPI: (userId) => buildUserSecretsAPI(userId)
|
|
901
|
+
createStorageAPI: () => buildExtensionStorageAPI(sendRequest),
|
|
902
|
+
createUserStorageAPI: (userId) => buildUserStorageAPI(sendRequest, userId),
|
|
903
|
+
createSecretsAPI: () => buildExtensionSecretsAPI(sendRequest),
|
|
904
|
+
createUserSecretsAPI: (userId) => buildUserSecretsAPI(sendRequest, userId)
|
|
936
905
|
});
|
|
937
906
|
}
|
|
938
907
|
const backgroundWorkersApi = {
|