@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.
@@ -334,6 +334,26 @@ interface ModalProps extends ExtensionComponentData {
334
334
  /** Action to call when the modal is closed. */
335
335
  onCloseAction?: ExtensionActionRef;
336
336
  }
337
+ /**
338
+ * The extension API properties for the ConditionalGroup component.
339
+ * Renders children only when the condition evaluates to true.
340
+ */
341
+ interface ConditionalGroupProps extends ExtensionComponentData {
342
+ component: 'ConditionalGroup';
343
+ /**
344
+ * Condition expression to evaluate.
345
+ * Supports:
346
+ * - Comparison: ==, !=
347
+ * - Logical: && (and), || (or)
348
+ * - Values: $references, 'strings', numbers, true, false, null
349
+ *
350
+ * @example "$form.provider == 'imap'"
351
+ * @example "$form.provider == 'gmail' || $form.provider == 'outlook'"
352
+ */
353
+ condition: string;
354
+ /** Children to render when condition is true. */
355
+ children: ExtensionComponentChildren;
356
+ }
337
357
 
338
358
  /**
339
359
  * Contribution Types
@@ -887,6 +907,8 @@ interface ExtensionContext {
887
907
  readonly database?: DatabaseAPI;
888
908
  /** Local storage (if permitted) */
889
909
  readonly storage?: StorageAPI;
910
+ /** Background workers (if permitted) */
911
+ readonly backgroundWorkers?: BackgroundWorkersAPI;
890
912
  /** Logging (always available) */
891
913
  readonly log: LogAPI;
892
914
  }
@@ -1157,6 +1179,191 @@ interface ExtensionModule {
1157
1179
  */
1158
1180
  deactivate?(): void | Promise<void>;
1159
1181
  }
1182
+ /**
1183
+ * Restart policy for background tasks.
1184
+ * Controls how tasks are restarted after failures.
1185
+ */
1186
+ interface BackgroundRestartPolicy {
1187
+ /**
1188
+ * When to restart the task:
1189
+ * - 'always': Always restart, regardless of exit reason
1190
+ * - 'on-failure': Only restart if the task threw an error
1191
+ * - 'never': Never restart automatically
1192
+ */
1193
+ type: 'always' | 'on-failure' | 'never';
1194
+ /**
1195
+ * Maximum number of restarts before giving up.
1196
+ * 0 means unlimited restarts.
1197
+ * @default 0
1198
+ */
1199
+ maxRestarts?: number;
1200
+ /**
1201
+ * Initial delay in milliseconds before first restart.
1202
+ * @default 1000
1203
+ */
1204
+ initialDelayMs?: number;
1205
+ /**
1206
+ * Maximum delay in milliseconds between restarts.
1207
+ * @default 60000
1208
+ */
1209
+ maxDelayMs?: number;
1210
+ /**
1211
+ * Multiplier for exponential backoff.
1212
+ * @default 2
1213
+ */
1214
+ backoffMultiplier?: number;
1215
+ }
1216
+ /**
1217
+ * Configuration for a background task.
1218
+ */
1219
+ interface BackgroundTaskConfig {
1220
+ /**
1221
+ * Unique identifier for the task within the extension.
1222
+ * Used to reference the task for stopping or checking status.
1223
+ */
1224
+ id: string;
1225
+ /**
1226
+ * Human-readable name for observability and logging.
1227
+ */
1228
+ name: string;
1229
+ /**
1230
+ * User ID that owns this task.
1231
+ * Background tasks are always user-scoped.
1232
+ */
1233
+ userId: string;
1234
+ /**
1235
+ * Policy for restarting the task after failures.
1236
+ */
1237
+ restartPolicy: BackgroundRestartPolicy;
1238
+ /**
1239
+ * Optional payload data passed to the task callback.
1240
+ */
1241
+ payload?: Record<string, unknown>;
1242
+ }
1243
+ /**
1244
+ * Context provided to background task callbacks.
1245
+ * Extends ExecutionContext with task-specific functionality.
1246
+ */
1247
+ interface BackgroundTaskContext extends ExecutionContext {
1248
+ /**
1249
+ * AbortSignal that is triggered when the task should stop.
1250
+ * Check this signal regularly and exit gracefully when aborted.
1251
+ */
1252
+ readonly signal: AbortSignal;
1253
+ /**
1254
+ * Report the current health status of the task.
1255
+ * Use this to provide observability into what the task is doing.
1256
+ *
1257
+ * @param status Human-readable status message
1258
+ */
1259
+ reportHealth(status: string): void;
1260
+ /**
1261
+ * Task-specific logging API.
1262
+ * Messages are tagged with the task ID for easier debugging.
1263
+ */
1264
+ readonly log: LogAPI;
1265
+ }
1266
+ /**
1267
+ * Callback function for background tasks.
1268
+ * The function should run until the signal is aborted, then clean up and return.
1269
+ *
1270
+ * @example
1271
+ * ```typescript
1272
+ * const callback: BackgroundTaskCallback = async (ctx) => {
1273
+ * const connection = await createConnection()
1274
+ * try {
1275
+ * while (!ctx.signal.aborted) {
1276
+ * ctx.reportHealth('Waiting for messages...')
1277
+ * const message = await connection.receive({ signal: ctx.signal })
1278
+ * await processMessage(message)
1279
+ * }
1280
+ * } finally {
1281
+ * await connection.close()
1282
+ * }
1283
+ * }
1284
+ * ```
1285
+ */
1286
+ type BackgroundTaskCallback = (context: BackgroundTaskContext) => Promise<void>;
1287
+ /**
1288
+ * Health status of a background task.
1289
+ */
1290
+ interface BackgroundTaskHealth {
1291
+ /**
1292
+ * Unique task identifier within the extension.
1293
+ */
1294
+ taskId: string;
1295
+ /**
1296
+ * Human-readable task name.
1297
+ */
1298
+ name: string;
1299
+ /**
1300
+ * User ID that owns this task.
1301
+ */
1302
+ userId: string;
1303
+ /**
1304
+ * Current task status.
1305
+ */
1306
+ status: 'pending' | 'running' | 'stopped' | 'failed' | 'restarting';
1307
+ /**
1308
+ * Number of times the task has been restarted.
1309
+ */
1310
+ restartCount: number;
1311
+ /**
1312
+ * Last health status message reported by the task.
1313
+ */
1314
+ lastHealthStatus?: string;
1315
+ /**
1316
+ * Timestamp of the last health report.
1317
+ */
1318
+ lastHealthTime?: string;
1319
+ /**
1320
+ * Error message if the task failed.
1321
+ */
1322
+ error?: string;
1323
+ }
1324
+ /**
1325
+ * API for managing background workers.
1326
+ * Background workers are long-running tasks that can be automatically restarted.
1327
+ *
1328
+ * @example
1329
+ * ```typescript
1330
+ * const task = await context.backgroundWorkers.start({
1331
+ * id: 'my-task',
1332
+ * name: 'My Background Task',
1333
+ * userId: 'user-123',
1334
+ * restartPolicy: { type: 'always', maxRestarts: 0 }
1335
+ * }, async (ctx) => {
1336
+ * while (!ctx.signal.aborted) {
1337
+ * // Do work...
1338
+ * }
1339
+ * })
1340
+ *
1341
+ * // Later, to stop the task:
1342
+ * task.dispose()
1343
+ * ```
1344
+ */
1345
+ interface BackgroundWorkersAPI {
1346
+ /**
1347
+ * Start a new background task.
1348
+ *
1349
+ * @param config Task configuration
1350
+ * @param callback Function to execute as the background task
1351
+ * @returns Disposable that stops the task when disposed
1352
+ */
1353
+ start(config: BackgroundTaskConfig, callback: BackgroundTaskCallback): Promise<Disposable>;
1354
+ /**
1355
+ * Stop a running background task.
1356
+ *
1357
+ * @param taskId The task ID to stop
1358
+ */
1359
+ stop(taskId: string): Promise<void>;
1360
+ /**
1361
+ * Get the health status of all background tasks for this extension.
1362
+ *
1363
+ * @returns Array of task health statuses
1364
+ */
1365
+ getStatus(): Promise<BackgroundTaskHealth[]>;
1366
+ }
1160
1367
 
1161
1368
  /**
1162
1369
  * Tool and Action Types
@@ -1222,4 +1429,4 @@ interface ActionResult {
1222
1429
  error?: string;
1223
1430
  }
1224
1431
 
1225
- export { type AIProvider as $, type ActionResult as A, type ExtensionContext as B, type ChatMessage as C, type Disposable as D, type ExtensionContributions as E, type SettingsAPI as F, type GetModelsOptions as G, type ProvidersAPI as H, type ToolsAPI as I, type ActionsAPI as J, type EventsAPI as K, type LocalizedString as L, type ModelInfo as M, type NetworkAPI as N, type SchedulerAPI as O, type PanelDefinition as P, type SchedulerJobRequest as Q, type SchedulerSchedule as R, type SchedulerFirePayload as S, type ToolResult as T, type UserAPI as U, type UserProfile as V, type ChatAPI as W, type ChatInstructionMessage as X, type DatabaseAPI as Y, type StorageAPI as Z, type LogAPI as _, type ChatOptions as a, type ToolCall as a0, type Tool as a1, type Action as a2, type ExtensionModule as a3, type AllowedCSSProperty as a4, type ExtensionComponentStyle as a5, type ExtensionComponentData as a6, type ExtensionComponentIterator as a7, type ExtensionComponentChildren as a8, type ExtensionActionCall as a9, type ExecutionContext as aA, type ExtensionActionRef as aa, type ExtensionDataSource as ab, type ExtensionPanelDefinition as ac, type HeaderProps as ad, type LabelProps as ae, type ParagraphProps as af, type ButtonProps as ag, type TextInputProps as ah, type DateTimeInputProps as ai, type SelectProps as aj, type VerticalStackProps as ak, type HorizontalStackProps as al, type GridProps as am, type DividerProps as an, type IconProps as ao, type IconButtonType as ap, type IconButtonProps as aq, type PanelAction as ar, type PanelProps as as, type ToggleProps as at, type CollapsibleProps as au, type PillVariant as av, type PillProps as aw, type CheckboxProps as ax, type MarkdownProps as ay, type ModalProps as az, type StreamEvent as b, type SettingDefinition as c, type SettingOptionsMapping as d, type SettingCreateMapping as e, type ToolSettingsViewDefinition as f, type ToolSettingsView as g, type ToolSettingsListView as h, type ToolSettingsListMapping as i, type ToolSettingsComponentView as j, type ToolSettingsActionDataSource as k, type PanelView as l, type PanelComponentView as m, type PanelActionDataSource as n, type PanelUnknownView as o, type ProviderDefinition as p, type PromptContribution as q, resolveLocalizedString as r, type PromptSection as s, type ToolDefinition as t, type CommandDefinition as u, type ProviderConfigSchema as v, type ProviderConfigProperty as w, type ProviderConfigPropertyType as x, type ProviderConfigSelectOption as y, type ProviderConfigValidation as z };
1432
+ export { type BackgroundWorkersAPI as $, type ActionResult as A, type ExtensionContext as B, type ChatMessage as C, type Disposable as D, type ExtensionContributions as E, type SettingsAPI as F, type GetModelsOptions as G, type ProvidersAPI as H, type ToolsAPI as I, type ActionsAPI as J, type EventsAPI as K, type LocalizedString as L, type ModelInfo as M, type NetworkAPI as N, type SchedulerAPI as O, type PanelDefinition as P, type SchedulerJobRequest as Q, type SchedulerSchedule as R, type SchedulerFirePayload as S, type ToolResult as T, type UserAPI as U, type UserProfile as V, type ChatAPI as W, type ChatInstructionMessage as X, type DatabaseAPI as Y, type StorageAPI as Z, type LogAPI as _, type ChatOptions as a, type BackgroundTaskConfig as a0, type BackgroundTaskCallback as a1, type BackgroundTaskContext as a2, type BackgroundTaskHealth as a3, type BackgroundRestartPolicy as a4, type AIProvider as a5, type ToolCall as a6, type Tool as a7, type Action as a8, type ExtensionModule as a9, type CollapsibleProps as aA, type PillVariant as aB, type PillProps as aC, type CheckboxProps as aD, type MarkdownProps as aE, type ModalProps as aF, type ConditionalGroupProps as aG, type ExecutionContext as aH, type AllowedCSSProperty as aa, type ExtensionComponentStyle as ab, type ExtensionComponentData as ac, type ExtensionComponentIterator as ad, type ExtensionComponentChildren as ae, type ExtensionActionCall as af, type ExtensionActionRef as ag, type ExtensionDataSource as ah, type ExtensionPanelDefinition as ai, type HeaderProps as aj, type LabelProps as ak, type ParagraphProps as al, type ButtonProps as am, type TextInputProps as an, type DateTimeInputProps as ao, type SelectProps as ap, type VerticalStackProps as aq, type HorizontalStackProps as ar, type GridProps as as, type DividerProps as at, type IconProps as au, type IconButtonType as av, type IconButtonProps as aw, type PanelAction as ax, type PanelProps as ay, type ToggleProps as az, type StreamEvent as b, type SettingDefinition as c, type SettingOptionsMapping as d, type SettingCreateMapping as e, type ToolSettingsViewDefinition as f, type ToolSettingsView as g, type ToolSettingsListView as h, type ToolSettingsListMapping as i, type ToolSettingsComponentView as j, type ToolSettingsActionDataSource as k, type PanelView as l, type PanelComponentView as m, type PanelActionDataSource as n, type PanelUnknownView as o, type ProviderDefinition as p, type PromptContribution as q, resolveLocalizedString as r, type PromptSection as s, type ToolDefinition as t, type CommandDefinition as u, type ProviderConfigSchema as v, type ProviderConfigProperty as w, type ProviderConfigPropertyType as x, type ProviderConfigSelectOption as y, type ProviderConfigValidation as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stina/extension-api",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",