@openvcs/sdk 0.2.18-edge.20260422.24 → 0.2.18-edge.20260422.26

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.
@@ -5,6 +5,7 @@ type MenubarMenuOptions = {
5
5
  before?: string;
6
6
  after?: string;
7
7
  };
8
+ type MenuSurface = 'menubar' | 'settings';
8
9
  /** Runs a registered action handler by id. */
9
10
  export declare function runRegisteredAction(actionId: string, ...args: unknown[]): Promise<unknown>;
10
11
  export interface MenuHandle {
@@ -17,10 +18,16 @@ export interface MenuHandle {
17
18
  }
18
19
  /** Returns a menu by id, or null when it does not exist. */
19
20
  export declare function getMenu(menuId: string): MenuHandle | null;
20
- /** Returns a menu by id, creating it if needed. */
21
- export declare function getOrCreateMenu(menuId: string, label: string): MenuHandle | null;
22
- /** Creates a menu at a specific position. */
23
- export declare function createMenu(menuId: string, label: string, options?: MenubarMenuOptions): MenuHandle | null;
21
+ /** Returns a menu by id, creating it if needed.
22
+ * @param menuId - Menu identifier
23
+ * @param label - User-visible label
24
+ * @param options - Surface target ('menubar' or 'settings'), MUST be explicitly provided
25
+ */
26
+ export declare function getOrCreateMenu(menuId: string, label: string, options: MenubarMenuOptions & {
27
+ surface: MenuSurface;
28
+ }): MenuHandle | null;
29
+ /** Creates a menu at a specific position (alias for getOrCreateMenu). */
30
+ export declare const createMenu: typeof getOrCreateMenu;
24
31
  /** Adds one item to a menu. */
25
32
  export declare function addMenuItem(menuId: string, item: MenubarItem): void;
26
33
  /** Adds one separator to a menu. */
@@ -2,10 +2,10 @@
2
2
  // Copyright © 2025-2026 OpenVCS Contributors
3
3
  // SPDX-License-Identifier: GPL-3.0-or-later
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.createMenu = void 0;
5
6
  exports.runRegisteredAction = runRegisteredAction;
6
7
  exports.getMenu = getMenu;
7
8
  exports.getOrCreateMenu = getOrCreateMenu;
8
- exports.createMenu = createMenu;
9
9
  exports.addMenuItem = addMenuItem;
10
10
  exports.addMenuSeparator = addMenuSeparator;
11
11
  exports.removeMenu = removeMenu;
@@ -66,16 +66,17 @@ function placeMenuId(menuId, options) {
66
66
  menuOrder.push(id);
67
67
  }
68
68
  /** Ensures a menu record exists for one id. */
69
- function ensureStoredMenu(menuId, label, options) {
69
+ function ensureStoredMenu(menuId, label, options, surface) {
70
70
  const id = normalizeMenuId(menuId);
71
71
  const safeLabel = String(label || '').trim() || id;
72
72
  let menu = menus.get(id);
73
73
  if (!menu) {
74
- menu = { id, label: safeLabel, items: [] };
74
+ menu = { id, label: safeLabel, surface, items: [] };
75
75
  menus.set(id, menu);
76
76
  }
77
77
  else {
78
78
  menu.label = safeLabel;
79
+ menu.surface = surface;
79
80
  }
80
81
  placeMenuId(id, options);
81
82
  return menu;
@@ -148,6 +149,7 @@ function serializeMenus() {
148
149
  id: menu.id,
149
150
  label: menu.label,
150
151
  order: index + 1,
152
+ surface: menu.surface,
151
153
  elements: menu.items
152
154
  .map((item) => serializeMenuItem(item))
153
155
  .filter((item) => Boolean(item)),
@@ -175,7 +177,11 @@ function createMenuHandle(menuId) {
175
177
  const action = String(item?.action || '').trim();
176
178
  if (!label || !action)
177
179
  return;
178
- const menu = getStoredMenu(this.id) || ensureStoredMenu(this.id, this.id);
180
+ let menu = getStoredMenu(this.id);
181
+ if (!menu) {
182
+ // Default to menubar for internal menu handle operations.
183
+ menu = ensureStoredMenu(this.id, this.id, {}, 'menubar');
184
+ }
179
185
  insertMenuItem(menu, {
180
186
  kind: 'button',
181
187
  id: action,
@@ -185,7 +191,11 @@ function createMenuHandle(menuId) {
185
191
  }, item.before, item.after);
186
192
  },
187
193
  addSeparator(beforeAction) {
188
- const menu = getStoredMenu(this.id) || ensureStoredMenu(this.id, this.id);
194
+ let menu = getStoredMenu(this.id);
195
+ if (!menu) {
196
+ // Default to menubar for internal menu handle operations.
197
+ menu = ensureStoredMenu(this.id, this.id, {}, 'menubar');
198
+ }
189
199
  insertMenuItem(menu, {
190
200
  kind: 'separator',
191
201
  id: allocateSyntheticId(`${menu.id}-separator`),
@@ -225,16 +235,19 @@ function getMenu(menuId) {
225
235
  return null;
226
236
  return createMenuHandle(stored.id);
227
237
  }
228
- /** Returns a menu by id, creating it if needed. */
229
- function getOrCreateMenu(menuId, label) {
230
- const stored = ensureStoredMenu(menuId, label);
231
- return createMenuHandle(stored.id);
232
- }
233
- /** Creates a menu at a specific position. */
234
- function createMenu(menuId, label, options) {
235
- const stored = ensureStoredMenu(menuId, label, options);
238
+ /** Returns a menu by id, creating it if needed.
239
+ * @param menuId - Menu identifier
240
+ * @param label - User-visible label
241
+ * @param options - Surface target ('menubar' or 'settings'), MUST be explicitly provided
242
+ */
243
+ function getOrCreateMenu(menuId, label, options) {
244
+ const surface = options.surface;
245
+ const { surface: _, ...restOptions } = options;
246
+ const stored = ensureStoredMenu(menuId, label, restOptions, surface);
236
247
  return createMenuHandle(stored.id);
237
248
  }
249
+ /** Creates a menu at a specific position (alias for getOrCreateMenu). */
250
+ exports.createMenu = getOrCreateMenu;
238
251
  /** Adds one item to a menu. */
239
252
  function addMenuItem(menuId, item) {
240
253
  createMenuHandle(menuId).addItem(item);
@@ -15,8 +15,41 @@ export interface PluginInitializeResult {
15
15
  }
16
16
  /** Describes one optional override returned by a custom initialize handler. */
17
17
  export type PluginInitializeOverride = Partial<PluginInitializeResult>;
18
+ /** Describes the UI surface targeted by one plugin menu definition. */
19
+ export type PluginMenuSurface = 'menubar' | 'settings';
20
+ /** Describes one static text element contributed to a plugin menu. */
21
+ export interface PluginMenuTextElement {
22
+ /** Stores the serialized element kind. */
23
+ type: 'text';
24
+ /** Stores the stable plugin-local element id. */
25
+ id: string;
26
+ /** Stores the rendered text content. */
27
+ content: string;
28
+ }
29
+ /** Describes one button element contributed to a plugin menu. */
30
+ export interface PluginMenuButtonElement {
31
+ /** Stores the serialized element kind. */
32
+ type: 'button';
33
+ /** Stores the stable action id dispatched back to the plugin. */
34
+ id: string;
35
+ /** Stores the user-visible button label. */
36
+ label: string;
37
+ }
38
+ /** Describes one renderable plugin menu element. */
39
+ export type PluginMenuElement = PluginMenuTextElement | PluginMenuButtonElement;
18
40
  /** Describes one plugin-contributed menu definition. */
19
- export type PluginMenuDefinition = Record<string, unknown>;
41
+ export interface PluginMenuDefinition {
42
+ /** Stores the stable plugin-local menu id. */
43
+ id: string;
44
+ /** Stores the user-visible menu label. */
45
+ label: string;
46
+ /** Stores the display ordering hint assigned by the runtime. */
47
+ order: number;
48
+ /** Stores the target UI surface for the menu. */
49
+ surface: PluginMenuSurface;
50
+ /** Stores the renderable elements contributed under the menu. */
51
+ elements: PluginMenuElement[];
52
+ }
20
53
  /** Describes one plugin settings value payload. */
21
54
  export type PluginSettingsValue = Record<string, unknown>;
22
55
  /** Describes the params shape for plugin action handling. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openvcs/sdk",
3
- "version": "0.2.18-edge.20260422.24",
3
+ "version": "0.2.18-edge.20260422.26",
4
4
  "description": "OpenVCS SDK CLI for plugin scaffolding and runtime asset builds",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "homepage": "https://openvcs.app/",
@@ -12,6 +12,7 @@ import type { PluginRuntimeContext } from './contracts.js';
12
12
 
13
13
  type MenubarMenuOptions = { before?: string; after?: string };
14
14
  type MenuEntryKind = 'button' | 'text' | 'separator';
15
+ type MenuSurface = 'menubar' | 'settings';
15
16
 
16
17
  type OpenVCSGlobal = typeof globalThis & {
17
18
  OpenVCS?: {
@@ -34,6 +35,8 @@ interface StoredMenuState {
34
35
  id: string;
35
36
  label: string;
36
37
  hidden?: boolean;
38
+ /** Surface target for rendering ('menubar' or 'settings'), must be explicitly provided. */
39
+ surface: MenuSurface;
37
40
  items: StoredMenuItem[];
38
41
  }
39
42
 
@@ -48,6 +51,7 @@ interface SerializedMenuDefinition {
48
51
  id: string;
49
52
  label: string;
50
53
  order: number;
54
+ surface: 'menubar' | 'settings';
51
55
  elements: SerializedMenuItem[];
52
56
  }
53
57
 
@@ -115,17 +119,19 @@ function placeMenuId(menuId: string, options?: MenubarMenuOptions): void {
115
119
  function ensureStoredMenu(
116
120
  menuId: string,
117
121
  label: string,
118
- options?: MenubarMenuOptions,
122
+ options: MenubarMenuOptions,
123
+ surface: MenuSurface,
119
124
  ): StoredMenuState {
120
125
  const id = normalizeMenuId(menuId);
121
126
  const safeLabel = String(label || '').trim() || id;
122
127
  let menu = menus.get(id);
123
128
 
124
129
  if (!menu) {
125
- menu = { id, label: safeLabel, items: [] };
130
+ menu = { id, label: safeLabel, surface, items: [] };
126
131
  menus.set(id, menu);
127
132
  } else {
128
133
  menu.label = safeLabel;
134
+ menu.surface = surface;
129
135
  }
130
136
 
131
137
  placeMenuId(id, options);
@@ -207,6 +213,7 @@ function serializeMenus(): SerializedMenuDefinition[] {
207
213
  id: menu.id,
208
214
  label: menu.label,
209
215
  order: index + 1,
216
+ surface: menu.surface,
210
217
  elements: menu.items
211
218
  .map((item) => serializeMenuItem(item))
212
219
  .filter((item): item is SerializedMenuItem => Boolean(item)),
@@ -246,7 +253,11 @@ function createMenuHandle(menuId: string): MenuHandle {
246
253
  const action = String(item?.action || '').trim();
247
254
  if (!label || !action) return;
248
255
 
249
- const menu = getStoredMenu(this.id) || ensureStoredMenu(this.id, this.id);
256
+ let menu = getStoredMenu(this.id);
257
+ if (!menu) {
258
+ // Default to menubar for internal menu handle operations.
259
+ menu = ensureStoredMenu(this.id, this.id, {}, 'menubar');
260
+ }
250
261
  insertMenuItem(menu, {
251
262
  kind: 'button',
252
263
  id: action,
@@ -256,7 +267,11 @@ function createMenuHandle(menuId: string): MenuHandle {
256
267
  }, item.before, item.after);
257
268
  },
258
269
  addSeparator(beforeAction?: string) {
259
- const menu = getStoredMenu(this.id) || ensureStoredMenu(this.id, this.id);
270
+ let menu = getStoredMenu(this.id);
271
+ if (!menu) {
272
+ // Default to menubar for internal menu handle operations.
273
+ menu = ensureStoredMenu(this.id, this.id, {}, 'menubar');
274
+ }
260
275
  insertMenuItem(menu, {
261
276
  kind: 'separator',
262
277
  id: allocateSyntheticId(`${menu.id}-separator`),
@@ -292,17 +307,24 @@ export function getMenu(menuId: string): MenuHandle | null {
292
307
  return createMenuHandle(stored.id);
293
308
  }
294
309
 
295
- /** Returns a menu by id, creating it if needed. */
296
- export function getOrCreateMenu(menuId: string, label: string): MenuHandle | null {
297
- const stored = ensureStoredMenu(menuId, label);
310
+ /** Returns a menu by id, creating it if needed.
311
+ * @param menuId - Menu identifier
312
+ * @param label - User-visible label
313
+ * @param options - Surface target ('menubar' or 'settings'), MUST be explicitly provided
314
+ */
315
+ export function getOrCreateMenu(
316
+ menuId: string,
317
+ label: string,
318
+ options: MenubarMenuOptions & { surface: MenuSurface },
319
+ ): MenuHandle | null {
320
+ const surface = options.surface;
321
+ const { surface: _, ...restOptions } = options;
322
+ const stored = ensureStoredMenu(menuId, label, restOptions, surface);
298
323
  return createMenuHandle(stored.id);
299
324
  }
300
325
 
301
- /** Creates a menu at a specific position. */
302
- export function createMenu(menuId: string, label: string, options?: MenubarMenuOptions): MenuHandle | null {
303
- const stored = ensureStoredMenu(menuId, label, options);
304
- return createMenuHandle(stored.id);
305
- }
326
+ /** Creates a menu at a specific position (alias for getOrCreateMenu). */
327
+ export const createMenu = getOrCreateMenu;
306
328
 
307
329
  /** Adds one item to a menu. */
308
330
  export function addMenuItem(menuId: string, item: MenubarItem): void {
@@ -22,8 +22,45 @@ export interface PluginInitializeResult {
22
22
  /** Describes one optional override returned by a custom initialize handler. */
23
23
  export type PluginInitializeOverride = Partial<PluginInitializeResult>;
24
24
 
25
+ /** Describes the UI surface targeted by one plugin menu definition. */
26
+ export type PluginMenuSurface = 'menubar' | 'settings';
27
+
28
+ /** Describes one static text element contributed to a plugin menu. */
29
+ export interface PluginMenuTextElement {
30
+ /** Stores the serialized element kind. */
31
+ type: 'text';
32
+ /** Stores the stable plugin-local element id. */
33
+ id: string;
34
+ /** Stores the rendered text content. */
35
+ content: string;
36
+ }
37
+
38
+ /** Describes one button element contributed to a plugin menu. */
39
+ export interface PluginMenuButtonElement {
40
+ /** Stores the serialized element kind. */
41
+ type: 'button';
42
+ /** Stores the stable action id dispatched back to the plugin. */
43
+ id: string;
44
+ /** Stores the user-visible button label. */
45
+ label: string;
46
+ }
47
+
48
+ /** Describes one renderable plugin menu element. */
49
+ export type PluginMenuElement = PluginMenuTextElement | PluginMenuButtonElement;
50
+
25
51
  /** Describes one plugin-contributed menu definition. */
26
- export type PluginMenuDefinition = Record<string, unknown>;
52
+ export interface PluginMenuDefinition {
53
+ /** Stores the stable plugin-local menu id. */
54
+ id: string;
55
+ /** Stores the user-visible menu label. */
56
+ label: string;
57
+ /** Stores the display ordering hint assigned by the runtime. */
58
+ order: number;
59
+ /** Stores the target UI surface for the menu. */
60
+ surface: PluginMenuSurface;
61
+ /** Stores the renderable elements contributed under the menu. */
62
+ elements: PluginMenuElement[];
63
+ }
27
64
 
28
65
  /** Describes one plugin settings value payload. */
29
66
  export type PluginSettingsValue = Record<string, unknown>;