@clipbus/plugin-sdk 0.9.9 → 0.10.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.
Files changed (49) hide show
  1. package/API.md +94 -27
  2. package/CHANGELOG.md +84 -0
  3. package/README.md +11 -3
  4. package/SPECIFICATION.md +3 -2
  5. package/dist/dom/index.cjs +29 -34
  6. package/dist/dom/index.js +29 -34
  7. package/dist/dom/topicAdapter.d.ts +1 -1
  8. package/dist/generated/capabilities.generated.d.ts +355 -0
  9. package/dist/generated/data.generated.d.ts +33 -0
  10. package/dist/generated/hostClients.generated.d.ts +8 -5
  11. package/dist/generated/hostEvents.generated.d.ts +68 -0
  12. package/dist/generated/nodeIPC.generated.d.ts +106 -0
  13. package/dist/generated/{runtime.definePlugin.generated.d.ts → runtime.registry.generated.d.ts} +2 -2
  14. package/dist/generated/ui.clipbus.generated.d.ts +19 -20
  15. package/dist/generated/wireConstants.generated.d.ts +21 -0
  16. package/dist/internal/capabilities.d.ts +1 -1
  17. package/dist/internal/hostEvents.d.ts +15 -0
  18. package/dist/internal/pluginCall.d.ts +11 -0
  19. package/dist/internal/pluginContext.d.ts +6 -0
  20. package/dist/preview/index.cjs +41 -48
  21. package/dist/preview/index.js +41 -48
  22. package/dist/preview/wire.d.ts +2 -2
  23. package/dist/runtime/defineMessage.d.ts +1 -1
  24. package/dist/runtime/definePlugin.d.ts +2 -0
  25. package/dist/runtime/index.cjs +10 -82
  26. package/dist/runtime/index.d.cts +7 -1
  27. package/dist/runtime/index.d.ts +7 -1
  28. package/dist/runtime/index.js +9 -80
  29. package/dist/ui/index.cjs +107 -169
  30. package/dist/ui/index.d.cts +5 -1
  31. package/dist/ui/index.d.ts +5 -1
  32. package/dist/ui/index.js +107 -169
  33. package/dist/validate/index.d.cts +5 -4
  34. package/dist/validate/index.d.ts +5 -4
  35. package/docs/authoring.md +1 -1
  36. package/docs/capability-detection.md +2 -2
  37. package/docs/entry.md +4 -3
  38. package/docs/item-context.md +5 -3
  39. package/docs/permissions.md +1 -1
  40. package/package.json +6 -4
  41. package/dist/generated/INDEX.runtime.generated.d.ts +0 -6
  42. package/dist/generated/INDEX.ui.generated.d.ts +0 -4
  43. package/dist/generated/capabilityClients.generated.d.ts +0 -231
  44. package/dist/generated/hostBootstrap.generated.d.ts +0 -23
  45. package/dist/generated/runtime.host.generated.d.ts +0 -39
  46. package/dist/generated/topicSubscribers.generated.d.ts +0 -39
  47. package/dist/generated/ui.bootstrap.generated.d.ts +0 -17
  48. package/dist/internal/ipcBus.d.ts +0 -48
  49. package/dist/internal/runtimeInvokeClient.d.ts +0 -3
@@ -1,18 +1,16 @@
1
- import type { PluginActionCompletePayload, PluginActionCompleteResponse, PluginActionSetButtonsPayload, PluginActionSetButtonsResponse, PluginAssetCurrentActionInputImageUrlResponse, PluginAssetCurrentActionInputPathReferenceImageUrlPayload, PluginAssetCurrentActionInputPathReferenceImageUrlResponse, PluginAssetCurrentItemImageUrlResponse, PluginAssetPathReferenceImageUrlPayload, PluginAssetPathReferenceImageUrlResponse, PluginAttachmentRendererSetButtonsPayload, PluginAttachmentRendererSetButtonsResponse, PluginClipboardCopyTextPayload, PluginClipboardCopyTextResponse, PluginConsoleLogPayload, PluginConsoleLogResponse, PluginInfoPanelClosePayload, PluginInfoPanelCloseResponse, PluginInfoPanelOpenPayload, PluginInfoPanelOpenResponse, PluginItemReadAttachmentPayload, PluginItemReadAttachmentResponse, PluginNavigationOpenFilePathPayload, PluginNavigationOpenFilePathResponse, PluginNavigationOpenUrlPayload, PluginNavigationOpenUrlResponse, PluginNavigationRevealInFinderPayload, PluginNavigationRevealInFinderResponse, PluginRuntimeInvokePayload, PluginSettingsGetAllResponse, PluginSettingsGetPayload, PluginSettingsGetResponse, PluginTextInputStateChangedPayload, PluginTextInputStateChangedResponse, PluginWindowAutoFitResponse, PluginWindowSetHeightPayload, PluginWindowSetHeightResponse } from './capabilityClients.generated.js';
2
- import type { PluginActionUIInput, PluginAttachmentPayload, PluginClipboardItem, PluginThemeTokenSnapshot } from './data.generated.js';
3
- import type { PluginActionHostInvokePayload, PluginAttachmentHostInvokePayload, PluginContextPayload, PluginInfoPanelOnActionPayload, PluginInfoPanelOnClosePayload, PluginLocalePayload } from './topicSubscribers.generated.js';
1
+ import type { PluginActionCompletePayload, PluginActionCompleteResponse, PluginActionSetButtonsPayload, PluginActionSetButtonsResponse, PluginAssetCurrentActionInputImageUrlResponse, PluginAssetCurrentActionInputPathReferenceImageUrlPayload, PluginAssetCurrentActionInputPathReferenceImageUrlResponse, PluginAssetCurrentItemImageUrlResponse, PluginAssetPathReferenceImageUrlPayload, PluginAssetPathReferenceImageUrlResponse, PluginAttachmentRendererSetButtonsPayload, PluginAttachmentRendererSetButtonsResponse, PluginClipboardCopyTextPayload, PluginClipboardCopyTextResponse, PluginConsoleDiagnosticPayload, PluginConsoleDiagnosticResponse, PluginConsoleLogPayload, PluginConsoleLogResponse, PluginInfoPanelClosePayload, PluginInfoPanelCloseResponse, PluginInfoPanelOpenPayload, PluginInfoPanelOpenResponse, PluginItemReadAttachmentPayload, PluginItemReadAttachmentResponse, PluginNavigationOpenFilePathPayload, PluginNavigationOpenFilePathResponse, PluginNavigationOpenUrlPayload, PluginNavigationOpenUrlResponse, PluginNavigationRevealInFinderPayload, PluginNavigationRevealInFinderResponse, PluginRuntimeInvokePayload, PluginSettingsGetAllResponse, PluginSettingsGetPayload, PluginSettingsGetResponse, PluginTextInputStateChangedPayload, PluginTextInputStateChangedResponse, PluginWindowAutoFitResponse, PluginWindowSetHeightPayload, PluginWindowSetHeightResponse } from './capabilities.generated.js';
4
2
  export declare const clipbus: {
5
3
  capabilities: import("../internal/capabilities.js").CapabilitiesApi;
6
4
  runtime: {
7
5
  invoke: <TResp = unknown>(payload: PluginRuntimeInvokePayload) => Promise<TResp>;
8
6
  };
9
7
  item: {
10
- current: () => PluginClipboardItem | undefined;
11
- on: (fn: (payload: PluginClipboardItem) => void) => import("../internal/topic.js").Unsubscribe;
8
+ current: () => import("./data.generated.js").PluginClipboardItem | undefined;
9
+ on: (listener: (event: import("./data.generated.js").PluginClipboardItem) => void) => import("../internal/topic.js").Unsubscribe;
12
10
  readAttachment: (payload: PluginItemReadAttachmentPayload) => Promise<PluginItemReadAttachmentResponse>;
13
11
  attachment: {
14
- current: () => PluginAttachmentPayload | undefined;
15
- on: (fn: (payload: PluginAttachmentPayload) => void) => import("../internal/topic.js").Unsubscribe;
12
+ current: () => import("./data.generated.js").PluginAttachmentPayload | undefined;
13
+ on: (listener: (event: import("./data.generated.js").PluginAttachmentPayload) => void) => import("../internal/topic.js").Unsubscribe;
16
14
  };
17
15
  };
18
16
  asset: {
@@ -34,20 +32,20 @@ export declare const clipbus: {
34
32
  complete: (payload: PluginActionCompletePayload) => Promise<PluginActionCompleteResponse>;
35
33
  draft: {
36
34
  current: () => Record<string, unknown> | undefined;
37
- on: (fn: (payload: Record<string, unknown>) => void) => import("../internal/topic.js").Unsubscribe;
35
+ on: (listener: (event: Record<string, unknown>) => void) => import("../internal/topic.js").Unsubscribe;
38
36
  };
39
37
  input: {
40
- current: () => PluginActionUIInput | undefined;
41
- on: (fn: (payload: PluginActionUIInput) => void) => import("../internal/topic.js").Unsubscribe;
38
+ current: () => import("./data.generated.js").PluginActionUIInput | undefined;
39
+ on: (listener: (event: import("./data.generated.js").PluginActionUIInput) => void) => import("../internal/topic.js").Unsubscribe;
42
40
  };
43
41
  onHostInvoke: {
44
- on: (fn: (payload: PluginActionHostInvokePayload) => void) => import("../internal/topic.js").Unsubscribe;
42
+ on: (listener: (event: import("./hostEvents.generated.js").PluginActionHostInvokePayload) => void) => import("../internal/topic.js").Unsubscribe;
45
43
  };
46
44
  };
47
45
  attachmentRenderer: {
48
46
  setButtons: (payload: PluginAttachmentRendererSetButtonsPayload) => Promise<PluginAttachmentRendererSetButtonsResponse>;
49
47
  onHostInvoke: {
50
- on: (fn: (payload: PluginAttachmentHostInvokePayload) => void) => import("../internal/topic.js").Unsubscribe;
48
+ on: (listener: (event: import("./hostEvents.generated.js").PluginAttachmentHostInvokePayload) => void) => import("../internal/topic.js").Unsubscribe;
51
49
  };
52
50
  };
53
51
  window: {
@@ -58,10 +56,10 @@ export declare const clipbus: {
58
56
  open: (payload: PluginInfoPanelOpenPayload) => Promise<PluginInfoPanelOpenResponse>;
59
57
  close: (payload: PluginInfoPanelClosePayload) => Promise<PluginInfoPanelCloseResponse>;
60
58
  onAction: {
61
- on: (fn: (payload: PluginInfoPanelOnActionPayload) => void) => import("../internal/topic.js").Unsubscribe;
59
+ on: (listener: (event: import("./hostEvents.generated.js").PluginInfoPanelOnActionPayload) => void) => import("../internal/topic.js").Unsubscribe;
62
60
  };
63
61
  onClose: {
64
- on: (fn: (payload: PluginInfoPanelOnClosePayload) => void) => import("../internal/topic.js").Unsubscribe;
62
+ on: (listener: (event: import("./hostEvents.generated.js").PluginInfoPanelOnClosePayload) => void) => import("../internal/topic.js").Unsubscribe;
65
63
  };
66
64
  };
67
65
  settings: {
@@ -70,20 +68,21 @@ export declare const clipbus: {
70
68
  };
71
69
  console: {
72
70
  log: (payload: PluginConsoleLogPayload) => Promise<PluginConsoleLogResponse>;
71
+ diagnostic: (payload: PluginConsoleDiagnosticPayload) => Promise<PluginConsoleDiagnosticResponse>;
73
72
  };
74
73
  textInput: {
75
74
  stateChanged: (payload: PluginTextInputStateChangedPayload) => Promise<PluginTextInputStateChangedResponse>;
76
75
  };
77
76
  pluginContext: {
78
- current: () => PluginContextPayload | undefined;
79
- on: (fn: (payload: PluginContextPayload) => void) => import("../internal/topic.js").Unsubscribe;
77
+ current: () => import("./hostEvents.generated.js").PluginContextPayload | undefined;
78
+ on: (listener: (event: import("./hostEvents.generated.js").PluginContextPayload) => void) => import("../internal/topic.js").Unsubscribe;
80
79
  };
81
80
  theme: {
82
- current: () => PluginThemeTokenSnapshot | undefined;
83
- on: (fn: (payload: PluginThemeTokenSnapshot) => void) => import("../internal/topic.js").Unsubscribe;
81
+ current: () => import("./data.generated.js").PluginThemeTokenSnapshot | undefined;
82
+ on: (listener: (event: import("./data.generated.js").PluginThemeTokenSnapshot) => void) => import("../internal/topic.js").Unsubscribe;
84
83
  };
85
84
  locale: {
86
- current: () => PluginLocalePayload | undefined;
87
- on: (fn: (payload: PluginLocalePayload) => void) => import("../internal/topic.js").Unsubscribe;
85
+ current: () => import("./hostEvents.generated.js").PluginLocalePayload | undefined;
86
+ on: (listener: (event: import("./hostEvents.generated.js").PluginLocalePayload) => void) => import("../internal/topic.js").Unsubscribe;
88
87
  };
89
88
  };
@@ -3,3 +3,24 @@ export declare const CAPABILITIES_GLOBAL: "__CLIPBUS_PLUGIN_CAPABILITIES__";
3
3
  export declare const CAPABILITY_UNSUPPORTED_ERROR_NAME: "PluginCapabilityUnsupported";
4
4
  export declare const PLUGIN_CALL_HANDLER_NAME: "clipbusPluginCall";
5
5
  export declare const WINDOW_SET_HEIGHT_METHOD: "window.setHeight";
6
+ export declare const WIRE_ERROR_NAMES: {
7
+ readonly methodNotFound: "PluginRuntimeMethodNotFound";
8
+ readonly handlerNotFound: "PluginRuntimeHandlerNotFound";
9
+ readonly invocationExpired: "PluginRuntimeInvocationExpired";
10
+ readonly hostCallLimitExceeded: "PluginRuntimeHostCallLimitExceeded";
11
+ readonly hostBridgeUnavailable: "PluginHostBridgeUnavailable";
12
+ };
13
+ export declare const NODE_IPC_WIRE_KEYS: {
14
+ readonly id: "id";
15
+ readonly method: "method";
16
+ readonly request: "request";
17
+ readonly response: "response";
18
+ readonly error: "error";
19
+ };
20
+ export declare const NODE_IPC_LIMITS: {
21
+ readonly maximumFrameBytes: 67108864;
22
+ readonly maximumJsonDepth: 64;
23
+ readonly maximumIdentifierCharacters: 128;
24
+ readonly maximumErrorMessageBytes: 4096;
25
+ readonly maximumOutstandingRequests: 1;
26
+ };
@@ -1,4 +1,4 @@
1
- import type { CapabilityMethodName } from '../generated/capabilityClients.generated.js';
1
+ import type { CapabilityMethodName } from '../generated/capabilities.generated.js';
2
2
  /**
3
3
  * 宿主不支持某 capability 时抛出的类型化错误。
4
4
  * 插件可通过 `instanceof CapabilityUnsupportedError` 识别并降级处理。
@@ -0,0 +1,15 @@
1
+ import { type HostEventName, type PluginHostEventMap } from '../generated/hostEvents.generated.js';
2
+ import { type Stream, type Topic } from './topic.js';
3
+ export declare function onHostEvent<K extends HostEventName>(name: K, listener: (payload: PluginHostEventMap[K]) => void): () => void;
4
+ /** Latest-value topic, seeded from the event's window global. */
5
+ export declare function createHostTopic<K extends HostEventName>(name: K): Topic<PluginHostEventMap[K]>;
6
+ export declare function createHostStream<K extends HostEventName>(name: K): Stream<PluginHostEventMap[K]>;
7
+ /** Publish a host event the way the Host does: assign its window global, then dispatch. */
8
+ export declare function publishHostEvent<K extends HostEventName>(name: K, payload: PluginHostEventMap[K]): void;
9
+ /**
10
+ * Publish a bootstrap payload set; `events` is a generated per-context map of
11
+ * field → host event. Absent fields are skipped; order follows the catalog.
12
+ */
13
+ export declare function publishBootstrap<B extends object>(events: {
14
+ readonly [F in keyof B]-?: HostEventName;
15
+ }, payloads: B): void;
@@ -0,0 +1,11 @@
1
+ import type { CapabilityMethodName, PluginCapabilityMap, PluginRuntimeInvokePayload } from '../generated/capabilities.generated.js';
2
+ /**
3
+ * Call a Host capability. Fails loud: throws `PluginHostBridgeUnavailable`
4
+ * outside a plugin WebView and rethrows Host rejections with their structured
5
+ * name and data restored. Fire-and-forget callers must catch explicitly.
6
+ */
7
+ export declare function callPluginMethod<M extends CapabilityMethodName>(method: M, payload: PluginCapabilityMap[M]['payload']): Promise<PluginCapabilityMap[M]['response']>;
8
+ /** `runtime.invoke` with the `{ response }` envelope unwrapped. */
9
+ export declare function callRuntimeInvoke<TResp = unknown>(payload: PluginRuntimeInvokePayload): Promise<TResp>;
10
+ /** Decode a Host rejection, restoring a structured `{ name, message, data }` error when present. */
11
+ export declare function parseReplyError(raw: unknown): Error;
@@ -0,0 +1,6 @@
1
+ import type { PluginContextPayload } from '../generated/hostEvents.generated.js';
2
+ import type { Topic } from './topic.js';
3
+ export declare class PluginContextError extends Error {
4
+ constructor(message: string);
5
+ }
6
+ export declare function guardContext<A extends unknown[], R>(contextTopic: Topic<PluginContextPayload>, expected: PluginContextPayload['mode'], run: (...args: A) => R): (...args: A) => R;
@@ -1337,53 +1337,46 @@ function defaultReplyFor(method) {
1337
1337
  return {};
1338
1338
  }
1339
1339
 
1340
- // src/generated/hostBootstrap.generated.ts
1341
- function emitAttachmentBootstrap(p) {
1342
- if (p.context !== void 0) {
1343
- globalThis["__CLIPBUS_PLUGIN_CONTEXT__"] = p.context;
1344
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-context", { detail: p.context }));
1345
- }
1346
- if (p.item !== void 0) {
1347
- globalThis["__CLIPBUS_PLUGIN_ITEM__"] = p.item;
1348
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-item", { detail: p.item }));
1349
- }
1350
- if (p.attachment !== void 0) {
1351
- globalThis["__CLIPBUS_PLUGIN_ATTACHMENT__"] = p.attachment;
1352
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-attachment", { detail: p.attachment }));
1353
- }
1354
- if (p.theme !== void 0) {
1355
- globalThis["__CLIPBUS_PLUGIN_THEME__"] = p.theme;
1356
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-theme", { detail: p.theme }));
1357
- }
1358
- if (p.locale !== void 0) {
1359
- globalThis["__CLIPBUS_PLUGIN_LOCALE__"] = p.locale;
1360
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-locale", { detail: p.locale }));
1361
- }
1340
+ // src/generated/hostEvents.generated.ts
1341
+ var HOST_EVENT_WINDOW_GLOBALS = {
1342
+ "clipbus-plugin-context": "__CLIPBUS_PLUGIN_CONTEXT__",
1343
+ "clipbus-plugin-item": "__CLIPBUS_PLUGIN_ITEM__",
1344
+ "clipbus-plugin-attachment": "__CLIPBUS_PLUGIN_ATTACHMENT__",
1345
+ "clipbus-plugin-draft": "__CLIPBUS_PLUGIN_DRAFT__",
1346
+ "clipbus-plugin-action-input": "__CLIPBUS_PLUGIN_ACTION_INPUT__",
1347
+ "clipbus-plugin-theme": "__CLIPBUS_PLUGIN_THEME__",
1348
+ "clipbus-plugin-attachment-host-invoke": null,
1349
+ "clipbus-plugin-action-host-invoke": null,
1350
+ "clipbus-plugin-info-panel-on-action": null,
1351
+ "clipbus-plugin-info-panel-on-close": null,
1352
+ "clipbus-plugin-locale": "__CLIPBUS_PLUGIN_LOCALE__"
1353
+ };
1354
+ var ATTACHMENT_BOOTSTRAP_EVENTS = {
1355
+ context: "clipbus-plugin-context",
1356
+ item: "clipbus-plugin-item",
1357
+ attachment: "clipbus-plugin-attachment",
1358
+ theme: "clipbus-plugin-theme",
1359
+ locale: "clipbus-plugin-locale"
1360
+ };
1361
+ var ACTION_BOOTSTRAP_EVENTS = {
1362
+ context: "clipbus-plugin-context",
1363
+ item: "clipbus-plugin-item",
1364
+ draft: "clipbus-plugin-draft",
1365
+ actionInput: "clipbus-plugin-action-input",
1366
+ theme: "clipbus-plugin-theme",
1367
+ locale: "clipbus-plugin-locale"
1368
+ };
1369
+
1370
+ // src/internal/hostEvents.ts
1371
+ function publishHostEvent(name, payload) {
1372
+ const windowGlobal = HOST_EVENT_WINDOW_GLOBALS[name];
1373
+ if (windowGlobal !== null) globalThis[windowGlobal] = payload;
1374
+ globalThis.dispatchEvent(new CustomEvent(name, { detail: payload }));
1362
1375
  }
1363
- function emitActionBootstrap(p) {
1364
- if (p.context !== void 0) {
1365
- globalThis["__CLIPBUS_PLUGIN_CONTEXT__"] = p.context;
1366
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-context", { detail: p.context }));
1367
- }
1368
- if (p.item !== void 0) {
1369
- globalThis["__CLIPBUS_PLUGIN_ITEM__"] = p.item;
1370
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-item", { detail: p.item }));
1371
- }
1372
- if (p.draft !== void 0) {
1373
- globalThis["__CLIPBUS_PLUGIN_DRAFT__"] = p.draft;
1374
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-draft", { detail: p.draft }));
1375
- }
1376
- if (p.actionInput !== void 0) {
1377
- globalThis["__CLIPBUS_PLUGIN_ACTION_INPUT__"] = p.actionInput;
1378
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-action-input", { detail: p.actionInput }));
1379
- }
1380
- if (p.theme !== void 0) {
1381
- globalThis["__CLIPBUS_PLUGIN_THEME__"] = p.theme;
1382
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-theme", { detail: p.theme }));
1383
- }
1384
- if (p.locale !== void 0) {
1385
- globalThis["__CLIPBUS_PLUGIN_LOCALE__"] = p.locale;
1386
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-locale", { detail: p.locale }));
1376
+ function publishBootstrap(events, payloads) {
1377
+ for (const field of Object.keys(events)) {
1378
+ const value = payloads[field];
1379
+ if (value !== void 0) publishHostEvent(events[field], value);
1387
1380
  }
1388
1381
  }
1389
1382
 
@@ -1421,7 +1414,7 @@ function computeWirePayloads(scenario, themeKey = DEFAULT_THEME_KEY) {
1421
1414
  }
1422
1415
  function injectWire(_target, payloads) {
1423
1416
  if (payloads.mode === "attachmentRenderer") {
1424
- emitAttachmentBootstrap({
1417
+ publishBootstrap(ATTACHMENT_BOOTSTRAP_EVENTS, {
1425
1418
  context: payloads.context,
1426
1419
  item: payloads.item,
1427
1420
  attachment: payloads.attachment,
@@ -1429,7 +1422,7 @@ function injectWire(_target, payloads) {
1429
1422
  locale: payloads.locale
1430
1423
  });
1431
1424
  } else {
1432
- emitActionBootstrap({
1425
+ publishBootstrap(ACTION_BOOTSTRAP_EVENTS, {
1433
1426
  context: payloads.context,
1434
1427
  item: payloads.item,
1435
1428
  draft: payloads.draft,
@@ -1294,53 +1294,46 @@ function defaultReplyFor(method) {
1294
1294
  return {};
1295
1295
  }
1296
1296
 
1297
- // src/generated/hostBootstrap.generated.ts
1298
- function emitAttachmentBootstrap(p) {
1299
- if (p.context !== void 0) {
1300
- globalThis["__CLIPBUS_PLUGIN_CONTEXT__"] = p.context;
1301
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-context", { detail: p.context }));
1302
- }
1303
- if (p.item !== void 0) {
1304
- globalThis["__CLIPBUS_PLUGIN_ITEM__"] = p.item;
1305
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-item", { detail: p.item }));
1306
- }
1307
- if (p.attachment !== void 0) {
1308
- globalThis["__CLIPBUS_PLUGIN_ATTACHMENT__"] = p.attachment;
1309
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-attachment", { detail: p.attachment }));
1310
- }
1311
- if (p.theme !== void 0) {
1312
- globalThis["__CLIPBUS_PLUGIN_THEME__"] = p.theme;
1313
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-theme", { detail: p.theme }));
1314
- }
1315
- if (p.locale !== void 0) {
1316
- globalThis["__CLIPBUS_PLUGIN_LOCALE__"] = p.locale;
1317
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-locale", { detail: p.locale }));
1318
- }
1297
+ // src/generated/hostEvents.generated.ts
1298
+ var HOST_EVENT_WINDOW_GLOBALS = {
1299
+ "clipbus-plugin-context": "__CLIPBUS_PLUGIN_CONTEXT__",
1300
+ "clipbus-plugin-item": "__CLIPBUS_PLUGIN_ITEM__",
1301
+ "clipbus-plugin-attachment": "__CLIPBUS_PLUGIN_ATTACHMENT__",
1302
+ "clipbus-plugin-draft": "__CLIPBUS_PLUGIN_DRAFT__",
1303
+ "clipbus-plugin-action-input": "__CLIPBUS_PLUGIN_ACTION_INPUT__",
1304
+ "clipbus-plugin-theme": "__CLIPBUS_PLUGIN_THEME__",
1305
+ "clipbus-plugin-attachment-host-invoke": null,
1306
+ "clipbus-plugin-action-host-invoke": null,
1307
+ "clipbus-plugin-info-panel-on-action": null,
1308
+ "clipbus-plugin-info-panel-on-close": null,
1309
+ "clipbus-plugin-locale": "__CLIPBUS_PLUGIN_LOCALE__"
1310
+ };
1311
+ var ATTACHMENT_BOOTSTRAP_EVENTS = {
1312
+ context: "clipbus-plugin-context",
1313
+ item: "clipbus-plugin-item",
1314
+ attachment: "clipbus-plugin-attachment",
1315
+ theme: "clipbus-plugin-theme",
1316
+ locale: "clipbus-plugin-locale"
1317
+ };
1318
+ var ACTION_BOOTSTRAP_EVENTS = {
1319
+ context: "clipbus-plugin-context",
1320
+ item: "clipbus-plugin-item",
1321
+ draft: "clipbus-plugin-draft",
1322
+ actionInput: "clipbus-plugin-action-input",
1323
+ theme: "clipbus-plugin-theme",
1324
+ locale: "clipbus-plugin-locale"
1325
+ };
1326
+
1327
+ // src/internal/hostEvents.ts
1328
+ function publishHostEvent(name, payload) {
1329
+ const windowGlobal = HOST_EVENT_WINDOW_GLOBALS[name];
1330
+ if (windowGlobal !== null) globalThis[windowGlobal] = payload;
1331
+ globalThis.dispatchEvent(new CustomEvent(name, { detail: payload }));
1319
1332
  }
1320
- function emitActionBootstrap(p) {
1321
- if (p.context !== void 0) {
1322
- globalThis["__CLIPBUS_PLUGIN_CONTEXT__"] = p.context;
1323
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-context", { detail: p.context }));
1324
- }
1325
- if (p.item !== void 0) {
1326
- globalThis["__CLIPBUS_PLUGIN_ITEM__"] = p.item;
1327
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-item", { detail: p.item }));
1328
- }
1329
- if (p.draft !== void 0) {
1330
- globalThis["__CLIPBUS_PLUGIN_DRAFT__"] = p.draft;
1331
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-draft", { detail: p.draft }));
1332
- }
1333
- if (p.actionInput !== void 0) {
1334
- globalThis["__CLIPBUS_PLUGIN_ACTION_INPUT__"] = p.actionInput;
1335
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-action-input", { detail: p.actionInput }));
1336
- }
1337
- if (p.theme !== void 0) {
1338
- globalThis["__CLIPBUS_PLUGIN_THEME__"] = p.theme;
1339
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-theme", { detail: p.theme }));
1340
- }
1341
- if (p.locale !== void 0) {
1342
- globalThis["__CLIPBUS_PLUGIN_LOCALE__"] = p.locale;
1343
- globalThis.dispatchEvent(new CustomEvent("clipbus-plugin-locale", { detail: p.locale }));
1333
+ function publishBootstrap(events, payloads) {
1334
+ for (const field of Object.keys(events)) {
1335
+ const value = payloads[field];
1336
+ if (value !== void 0) publishHostEvent(events[field], value);
1344
1337
  }
1345
1338
  }
1346
1339
 
@@ -1378,7 +1371,7 @@ function computeWirePayloads(scenario, themeKey = DEFAULT_THEME_KEY) {
1378
1371
  }
1379
1372
  function injectWire(_target, payloads) {
1380
1373
  if (payloads.mode === "attachmentRenderer") {
1381
- emitAttachmentBootstrap({
1374
+ publishBootstrap(ATTACHMENT_BOOTSTRAP_EVENTS, {
1382
1375
  context: payloads.context,
1383
1376
  item: payloads.item,
1384
1377
  attachment: payloads.attachment,
@@ -1386,7 +1379,7 @@ function injectWire(_target, payloads) {
1386
1379
  locale: payloads.locale
1387
1380
  });
1388
1381
  } else {
1389
- emitActionBootstrap({
1382
+ publishBootstrap(ACTION_BOOTSTRAP_EVENTS, {
1390
1383
  context: payloads.context,
1391
1384
  item: payloads.item,
1392
1385
  draft: payloads.draft,
@@ -1,5 +1,5 @@
1
1
  import type { PluginThemeTokenSnapshot } from '../generated/data.generated.js';
2
- import type { PluginContextPayload, PluginLocalePayload } from '../generated/hostBootstrap.generated.js';
2
+ import { type PluginContextPayload, type PluginLocalePayload } from '../generated/hostEvents.generated.js';
3
3
  import type { PluginActionUIInput, PluginAttachmentPayload, PluginClipboardItem } from '../generated/data.generated.js';
4
4
  import type { PreviewScenario } from './types.js';
5
5
  /**
@@ -34,7 +34,7 @@ export declare function computeWirePayloads(scenario: PreviewScenario, themeKey?
34
34
  * The `target` parameter is a forward-looking seam for future iframe support.
35
35
  *
36
36
  * No hardcoded global names or event names — all delegation flows through the
37
- * generated emitAttachmentBootstrap / emitActionBootstrap functions.
37
+ * generated per-context bootstrap event sets.
38
38
  */
39
39
  export declare function injectWire(_target: Window, payloads: WirePayloads): void;
40
40
  /**
@@ -1,5 +1,5 @@
1
1
  import type { MessageContract } from '../shared/defineMessage.js';
2
- import type { MessageHandler, MessageHandlerContext } from '../generated/runtime.definePlugin.generated.js';
2
+ import type { MessageHandler, MessageHandlerContext } from '../generated/runtime.registry.generated.js';
3
3
  export interface RuntimeMessageContract<TReq, TResp> extends MessageContract<TReq, TResp> {
4
4
  handle(fn: (req: TReq, ctx: MessageHandlerContext) => Promise<TResp> | TResp): readonly [string, MessageHandler];
5
5
  }
@@ -0,0 +1,2 @@
1
+ import type { PluginRegistry, PluginSetup } from '../generated/runtime.registry.generated.js';
2
+ export declare function definePlugin(definition: PluginRegistry | PluginSetup): PluginSetup;
@@ -23,84 +23,16 @@ __export(index_exports, {
23
23
  CapabilityUnsupportedError: () => CapabilityUnsupportedError,
24
24
  actionResult: () => actionResult,
25
25
  defineMessage: () => defineMessage,
26
- definePlugin: () => definePlugin,
27
- host: () => host
26
+ definePlugin: () => definePlugin
28
27
  });
29
28
  module.exports = __toCommonJS(index_exports);
30
29
 
31
- // src/internal/internalConsole.ts
32
- function pick(method) {
33
- if (typeof globalThis === "undefined") return () => {
34
- };
35
- const g = globalThis;
36
- const fn = g.console?.[method];
37
- if (typeof fn !== "function") return () => {
38
- };
39
- return fn.bind(g.console);
40
- }
41
- var internalConsole = Object.freeze({
42
- log: pick("log"),
43
- warn: pick("warn"),
44
- error: pick("error")
45
- });
46
-
47
- // src/internal/ipcBus.ts
48
- var _instance = null;
49
- var ipcBus = new Proxy({}, {
50
- get(_target, prop) {
51
- if (!_instance) {
52
- throw new Error("[clipbus-plugin] ipcBus accessed before configureIpcBus() was called.");
53
- }
54
- return _instance[prop];
55
- }
56
- });
57
-
58
- // src/generated/runtime.host.generated.ts
59
- var host = {
60
- item: {
61
- setTags: (payload) => ipcBus.request("item.setTags", payload),
62
- addTags: (payload) => ipcBus.request("item.addTags", payload),
63
- removeTags: (payload) => ipcBus.request("item.removeTags", payload),
64
- setPinned: (payload) => ipcBus.request("item.setPinned", payload),
65
- setAttachments: (payload) => ipcBus.request("item.setAttachments", payload),
66
- setSearchExtension: (payload) => ipcBus.request("item.setSearchExtension", payload),
67
- materializeImagePath: () => ipcBus.request("item.materializeImagePath", {}),
68
- readAttachment: (payload) => ipcBus.request("item.readAttachment", payload)
69
- },
70
- asset: {
71
- registerImage: (payload) => ipcBus.request("asset.registerImage", payload)
72
- },
73
- clipboard: {
74
- copyText: (payload) => ipcBus.request("clipboard.copyText", payload)
75
- },
76
- navigation: {
77
- openUrl: (payload) => ipcBus.request("navigation.openUrl", payload),
78
- revealInFinder: (payload) => ipcBus.request("navigation.revealInFinder", payload),
79
- openFilePath: (payload) => ipcBus.request("navigation.openFilePath", payload)
80
- },
81
- action: {
82
- allocateImageTempPath: (payload) => ipcBus.request("action.allocateImageTempPath", payload),
83
- materializeInputImagePath: () => ipcBus.request("action.materializeInputImagePath", {}),
84
- allocateOutputFilePath: (payload) => ipcBus.request("action.allocateOutputFilePath", payload)
85
- },
86
- settings: {
87
- get: (payload) => ipcBus.request("settings.get", payload),
88
- getAll: () => ipcBus.request("settings.getAll", {})
89
- },
90
- console: {
91
- log: (payload) => ipcBus.request("console.log", payload)
92
- },
93
- locale: {
94
- get: () => ipcBus.request("locale.get", {})
95
- }
96
- };
97
-
98
- // src/generated/runtime.definePlugin.generated.ts
30
+ // src/runtime/definePlugin.ts
99
31
  function definePlugin(definition) {
100
32
  if ("setup" in definition) {
101
33
  return {
102
- setup() {
103
- const registry = definition.setup();
34
+ setup(context) {
35
+ const registry = definition.setup(context);
104
36
  validateRegistry(registry);
105
37
  return registry;
106
38
  }
@@ -112,14 +44,11 @@ function definePlugin(definition) {
112
44
  } };
113
45
  }
114
46
  function validateRegistry(registry) {
115
- for (const [id, handler] of Object.entries(registry.attachmentRenderers ?? {})) {
116
- if (handler && typeof handler === "object" && "invokeOperation" in handler) {
117
- throw new Error(`attachmentRenderers["${id}"]: invokeOperation has been removed.`);
118
- }
119
- }
120
- for (const [id, handler] of Object.entries(registry.actions ?? {})) {
121
- if (handler && typeof handler === "object" && "invokeOperation" in handler) {
122
- throw new Error(`actions["${id}"]: invokeOperation has been removed.`);
47
+ for (const key of ["attachmentRenderers", "actions"]) {
48
+ for (const [id, handler] of Object.entries(registry[key] ?? {})) {
49
+ if (handler && typeof handler === "object" && "invokeOperation" in handler) {
50
+ throw new Error(`${key}["${id}"]: invokeOperation has been removed.`);
51
+ }
123
52
  }
124
53
  }
125
54
  }
@@ -167,6 +96,5 @@ var CapabilityUnsupportedError = class extends Error {
167
96
  CapabilityUnsupportedError,
168
97
  actionResult,
169
98
  defineMessage,
170
- definePlugin,
171
- host
99
+ definePlugin
172
100
  });
@@ -1,4 +1,10 @@
1
- export * from '../generated/INDEX.runtime.generated.js';
1
+ export { definePlugin } from './definePlugin.js';
2
+ export { actionResult } from '../generated/runtime.actionResult.generated.js';
2
3
  export { defineMessage } from './defineMessage.js';
3
4
  export type { RuntimeMessageContract } from './defineMessage.js';
4
5
  export { CapabilityUnsupportedError } from '../internal/capabilities.js';
6
+ export type * from '../generated/data.generated.js';
7
+ export type * from '../generated/capabilities.generated.js';
8
+ export type * from '../generated/hostClients.generated.js';
9
+ export type * from '../generated/runtime.handlers.generated.js';
10
+ export type * from '../generated/runtime.registry.generated.js';
@@ -1,4 +1,10 @@
1
- export * from '../generated/INDEX.runtime.generated.js';
1
+ export { definePlugin } from './definePlugin.js';
2
+ export { actionResult } from '../generated/runtime.actionResult.generated.js';
2
3
  export { defineMessage } from './defineMessage.js';
3
4
  export type { RuntimeMessageContract } from './defineMessage.js';
4
5
  export { CapabilityUnsupportedError } from '../internal/capabilities.js';
6
+ export type * from '../generated/data.generated.js';
7
+ export type * from '../generated/capabilities.generated.js';
8
+ export type * from '../generated/hostClients.generated.js';
9
+ export type * from '../generated/runtime.handlers.generated.js';
10
+ export type * from '../generated/runtime.registry.generated.js';