@qping/plugin-bus 0.4.0 → 0.7.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.
- package/dist/actions.d.ts +5 -0
- package/dist/bootstrap.d.ts +1 -2
- package/dist/bootstrap.mjs +2 -8
- package/dist/i18n.mjs +1 -1
- package/dist/node.mjs +3 -9
- package/dist/protocol.d.ts +0 -1
- package/dist/router.d.ts +0 -2
- package/dist/webClient.mjs +1 -3
- package/package.json +1 -1
- package/src/actions.ts +37 -31
- package/src/bootstrap.ts +4 -6
- package/src/node.ts +0 -1
- package/src/protocol.ts +0 -1
- package/src/router.ts +1 -5
- package/src/webClient.ts +0 -2
package/dist/actions.d.ts
CHANGED
|
@@ -151,6 +151,8 @@ export type DetailRequest = {
|
|
|
151
151
|
page?: string;
|
|
152
152
|
title?: string;
|
|
153
153
|
initialState?: unknown;
|
|
154
|
+
/** Restricts the action bar for this detail page. Omit to expose every registered action. */
|
|
155
|
+
actions?: string[];
|
|
154
156
|
};
|
|
155
157
|
export type ActionTarget =
|
|
156
158
|
/** Run one privileged host-side action (clipboard, process launch, browser, ...). */
|
|
@@ -210,6 +212,8 @@ export type ActionDefinition<TItem = any> = {
|
|
|
210
212
|
title: LocalizedText;
|
|
211
213
|
description?: LocalizedText;
|
|
212
214
|
hotkey?: Hotkey;
|
|
215
|
+
/** Keep this action visible in the host action bar instead of the overflow menu. */
|
|
216
|
+
pinned?: boolean;
|
|
213
217
|
execute: (context: ActionContext<TItem>) => ActionOutcome | void | Promise<ActionOutcome | void>;
|
|
214
218
|
};
|
|
215
219
|
/** The registry shape sent to the host in the initialize response (no `execute`). */
|
|
@@ -218,6 +222,7 @@ export type ActionManifestEntry = {
|
|
|
218
222
|
title: LocalizedText;
|
|
219
223
|
description?: LocalizedText;
|
|
220
224
|
hotkey?: Hotkey;
|
|
225
|
+
pinned?: boolean;
|
|
221
226
|
};
|
|
222
227
|
export declare function toActionManifest(definition: ActionDefinition): ActionManifestEntry;
|
|
223
228
|
export {};
|
package/dist/bootstrap.d.ts
CHANGED
|
@@ -26,11 +26,10 @@ export interface PluginRuntime {
|
|
|
26
26
|
export declare function runPlugin(handlers: PluginHandlers): Promise<PluginRuntime>;
|
|
27
27
|
/**
|
|
28
28
|
* Sends bus.handshake with the bootstrap token and waits for the host response that binds
|
|
29
|
-
* plugin/
|
|
29
|
+
* plugin/session/endpoint identity. Rejects on HandshakeFailed / ProtocolMismatch / timeout.
|
|
30
30
|
*/
|
|
31
31
|
export declare function completeHandshake(transport: NodeTransport, token: string, timeoutMs?: number): Promise<{
|
|
32
32
|
pluginId: string;
|
|
33
|
-
entryId: string;
|
|
34
33
|
sessionId: string;
|
|
35
34
|
endpointId: string;
|
|
36
35
|
}>;
|
package/dist/bootstrap.mjs
CHANGED
|
@@ -295,7 +295,6 @@ var HandlerRouter = class {
|
|
|
295
295
|
handlers = /* @__PURE__ */ new Map();
|
|
296
296
|
pendingHostCalls = /* @__PURE__ */ new Map();
|
|
297
297
|
pluginId = "p";
|
|
298
|
-
entryId = "e";
|
|
299
298
|
sessionId = "s";
|
|
300
299
|
endpointId = EndpointIds.NodeMain;
|
|
301
300
|
/** Injected transport send fn; tests can override `router.send` directly. */
|
|
@@ -306,7 +305,6 @@ var HandlerRouter = class {
|
|
|
306
305
|
/** Sets the bound identity stamped on outbound messages (after handshake). */
|
|
307
306
|
setIdentity(ids) {
|
|
308
307
|
this.pluginId = ids.pluginId;
|
|
309
|
-
this.entryId = ids.entryId;
|
|
310
308
|
this.sessionId = ids.sessionId;
|
|
311
309
|
this.endpointId = ids.endpointId;
|
|
312
310
|
}
|
|
@@ -355,7 +353,6 @@ var HandlerRouter = class {
|
|
|
355
353
|
traceId: id,
|
|
356
354
|
sessionId: this.sessionId,
|
|
357
355
|
pluginId: this.pluginId,
|
|
358
|
-
entryId: this.entryId,
|
|
359
356
|
endpointId: this.endpointId,
|
|
360
357
|
kind: MessageKind.Request,
|
|
361
358
|
route,
|
|
@@ -402,7 +399,6 @@ var HandlerRouter = class {
|
|
|
402
399
|
traceId: req.traceId,
|
|
403
400
|
sessionId: req.sessionId,
|
|
404
401
|
pluginId: req.pluginId,
|
|
405
|
-
entryId: req.entryId,
|
|
406
402
|
endpointId: this.endpointId,
|
|
407
403
|
kind: MessageKind.Response,
|
|
408
404
|
route: req.route,
|
|
@@ -483,7 +479,6 @@ async function completeHandshake(transport, token, timeoutMs = 1e4) {
|
|
|
483
479
|
traceId: id,
|
|
484
480
|
sessionId: "",
|
|
485
481
|
pluginId: "",
|
|
486
|
-
entryId: "",
|
|
487
482
|
endpointId: EndpointIds.NodeMain,
|
|
488
483
|
kind: MessageKind.Request,
|
|
489
484
|
route: Routes.Bus.Handshake,
|
|
@@ -509,14 +504,13 @@ async function completeHandshake(transport, token, timeoutMs = 1e4) {
|
|
|
509
504
|
}
|
|
510
505
|
const p = env.payload ?? {};
|
|
511
506
|
const pluginId = String(p.pluginId ?? "");
|
|
512
|
-
const entryId = String(p.entryId ?? "");
|
|
513
507
|
const sessionId = String(p.sessionId ?? "");
|
|
514
508
|
const endpointId = String(p.endpointId ?? EndpointIds.NodeMain);
|
|
515
|
-
if (!pluginId || !
|
|
509
|
+
if (!pluginId || !sessionId) {
|
|
516
510
|
reject(new Error("bus.handshake success response missing bound identity"));
|
|
517
511
|
return;
|
|
518
512
|
}
|
|
519
|
-
resolve({ pluginId,
|
|
513
|
+
resolve({ pluginId, sessionId, endpointId });
|
|
520
514
|
});
|
|
521
515
|
transport.send(req);
|
|
522
516
|
});
|
package/dist/i18n.mjs
CHANGED
package/dist/node.mjs
CHANGED
|
@@ -304,7 +304,6 @@ var HandlerRouter = class {
|
|
|
304
304
|
handlers = /* @__PURE__ */ new Map();
|
|
305
305
|
pendingHostCalls = /* @__PURE__ */ new Map();
|
|
306
306
|
pluginId = "p";
|
|
307
|
-
entryId = "e";
|
|
308
307
|
sessionId = "s";
|
|
309
308
|
endpointId = EndpointIds.NodeMain;
|
|
310
309
|
/** Injected transport send fn; tests can override `router.send` directly. */
|
|
@@ -315,7 +314,6 @@ var HandlerRouter = class {
|
|
|
315
314
|
/** Sets the bound identity stamped on outbound messages (after handshake). */
|
|
316
315
|
setIdentity(ids) {
|
|
317
316
|
this.pluginId = ids.pluginId;
|
|
318
|
-
this.entryId = ids.entryId;
|
|
319
317
|
this.sessionId = ids.sessionId;
|
|
320
318
|
this.endpointId = ids.endpointId;
|
|
321
319
|
}
|
|
@@ -364,7 +362,6 @@ var HandlerRouter = class {
|
|
|
364
362
|
traceId: id,
|
|
365
363
|
sessionId: this.sessionId,
|
|
366
364
|
pluginId: this.pluginId,
|
|
367
|
-
entryId: this.entryId,
|
|
368
365
|
endpointId: this.endpointId,
|
|
369
366
|
kind: MessageKind.Request,
|
|
370
367
|
route,
|
|
@@ -411,7 +408,6 @@ var HandlerRouter = class {
|
|
|
411
408
|
traceId: req.traceId,
|
|
412
409
|
sessionId: req.sessionId,
|
|
413
410
|
pluginId: req.pluginId,
|
|
414
|
-
entryId: req.entryId,
|
|
415
411
|
endpointId: this.endpointId,
|
|
416
412
|
kind: MessageKind.Response,
|
|
417
413
|
route: req.route,
|
|
@@ -492,7 +488,6 @@ async function completeHandshake(transport, token, timeoutMs = 1e4) {
|
|
|
492
488
|
traceId: id,
|
|
493
489
|
sessionId: "",
|
|
494
490
|
pluginId: "",
|
|
495
|
-
entryId: "",
|
|
496
491
|
endpointId: EndpointIds.NodeMain,
|
|
497
492
|
kind: MessageKind.Request,
|
|
498
493
|
route: Routes.Bus.Handshake,
|
|
@@ -518,14 +513,13 @@ async function completeHandshake(transport, token, timeoutMs = 1e4) {
|
|
|
518
513
|
}
|
|
519
514
|
const p = env.payload ?? {};
|
|
520
515
|
const pluginId = String(p.pluginId ?? "");
|
|
521
|
-
const entryId = String(p.entryId ?? "");
|
|
522
516
|
const sessionId = String(p.sessionId ?? "");
|
|
523
517
|
const endpointId = String(p.endpointId ?? EndpointIds.NodeMain);
|
|
524
|
-
if (!pluginId || !
|
|
518
|
+
if (!pluginId || !sessionId) {
|
|
525
519
|
reject(new Error("bus.handshake success response missing bound identity"));
|
|
526
520
|
return;
|
|
527
521
|
}
|
|
528
|
-
resolve({ pluginId,
|
|
522
|
+
resolve({ pluginId, sessionId, endpointId });
|
|
529
523
|
});
|
|
530
524
|
transport.send(req);
|
|
531
525
|
});
|
|
@@ -632,6 +626,7 @@ function toActionManifest(definition) {
|
|
|
632
626
|
};
|
|
633
627
|
if (definition.description) entry.description = definition.description;
|
|
634
628
|
if (definition.hotkey) entry.hotkey = definition.hotkey;
|
|
629
|
+
if (definition.pinned) entry.pinned = true;
|
|
635
630
|
return entry;
|
|
636
631
|
}
|
|
637
632
|
|
|
@@ -696,7 +691,6 @@ var Plugin = class {
|
|
|
696
691
|
traceId: crypto.randomUUID().replace(/-/g, "").slice(0, 32),
|
|
697
692
|
sessionId: "",
|
|
698
693
|
pluginId: "",
|
|
699
|
-
entryId: "",
|
|
700
694
|
endpointId: EndpointIds.NodeMain,
|
|
701
695
|
kind: MessageKind.Event,
|
|
702
696
|
route,
|
package/dist/protocol.d.ts
CHANGED
package/dist/router.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export declare class HandlerRouter {
|
|
|
16
16
|
private handlers;
|
|
17
17
|
private pendingHostCalls;
|
|
18
18
|
private pluginId;
|
|
19
|
-
private entryId;
|
|
20
19
|
private sessionId;
|
|
21
20
|
private endpointId;
|
|
22
21
|
/** Injected transport send fn; tests can override `router.send` directly. */
|
|
@@ -27,7 +26,6 @@ export declare class HandlerRouter {
|
|
|
27
26
|
/** Sets the bound identity stamped on outbound messages (after handshake). */
|
|
28
27
|
setIdentity(ids: {
|
|
29
28
|
pluginId: string;
|
|
30
|
-
entryId: string;
|
|
31
29
|
sessionId: string;
|
|
32
30
|
endpointId: string;
|
|
33
31
|
}): void;
|
package/dist/webClient.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// node_modules/i18next/dist/esm/i18next.js
|
|
2
2
|
var isString = (obj) => typeof obj === "string";
|
|
3
3
|
var defer = () => {
|
|
4
4
|
let res;
|
|
@@ -2545,7 +2545,6 @@ function createWebBusClient(options) {
|
|
|
2545
2545
|
traceId: id,
|
|
2546
2546
|
sessionId: "",
|
|
2547
2547
|
pluginId: "",
|
|
2548
|
-
entryId: "",
|
|
2549
2548
|
endpointId: "",
|
|
2550
2549
|
kind: MessageKind.Request,
|
|
2551
2550
|
route,
|
|
@@ -2607,7 +2606,6 @@ function handshake(timeoutMs) {
|
|
|
2607
2606
|
traceId: id,
|
|
2608
2607
|
sessionId: "",
|
|
2609
2608
|
pluginId: "",
|
|
2610
|
-
entryId: "",
|
|
2611
2609
|
endpointId: "web",
|
|
2612
2610
|
kind: MessageKind.Request,
|
|
2613
2611
|
route: Routes.Bus.Handshake,
|
package/package.json
CHANGED
package/src/actions.ts
CHANGED
|
@@ -89,37 +89,39 @@ export type HostActionRequest =
|
|
|
89
89
|
| { kind: typeof HostAction.Run; command: RunSpec }
|
|
90
90
|
| { kind: typeof HostAction.Kill; pid: number };
|
|
91
91
|
|
|
92
|
-
/** Opens a web detail page. `page` defaults to the entry declared in plugin.json. */
|
|
93
|
-
export type DetailRequest = {
|
|
94
|
-
page?: string;
|
|
95
|
-
title?: string;
|
|
96
|
-
initialState?: unknown;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
| { kind: "
|
|
104
|
-
/**
|
|
105
|
-
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
type
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
| { target
|
|
122
|
-
|
|
92
|
+
/** Opens a web detail page. `page` defaults to the entry declared in plugin.json. */
|
|
93
|
+
export type DetailRequest = {
|
|
94
|
+
page?: string;
|
|
95
|
+
title?: string;
|
|
96
|
+
initialState?: unknown;
|
|
97
|
+
/** Restricts the action bar for this detail page. Omit to expose every registered action. */
|
|
98
|
+
actions?: string[];
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type ActionTarget =
|
|
102
|
+
/** Run one privileged host-side action (clipboard, process launch, browser, ...). */
|
|
103
|
+
| { kind: "host"; action: HostActionRequest }
|
|
104
|
+
/** Hand off to the currently active detail page as host.event.detailAction. */
|
|
105
|
+
| { kind: "web"; payload?: unknown }
|
|
106
|
+
/** Open a new web detail page. */
|
|
107
|
+
| ({ kind: "detail" } & DetailRequest);
|
|
108
|
+
|
|
109
|
+
export type ActionAfter = "keep" | "close" | "refresh";
|
|
110
|
+
|
|
111
|
+
type ActionOutcomeBase = {
|
|
112
|
+
/** Status bar text. */
|
|
113
|
+
message?: LocalizedText;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The result of running an action. An action selects at most one execution target. Host targets
|
|
118
|
+
* may choose a follow-up lifecycle action; web and detail targets keep their current surface alive.
|
|
119
|
+
*/
|
|
120
|
+
export type ActionOutcome = ActionOutcomeBase & (
|
|
121
|
+
| { target?: undefined; after?: ActionAfter }
|
|
122
|
+
| { target: Extract<ActionTarget, { kind: "host" }>; after?: ActionAfter }
|
|
123
|
+
| { target: Exclude<ActionTarget, { kind: "host" }>; after?: "keep" }
|
|
124
|
+
);
|
|
123
125
|
|
|
124
126
|
/**
|
|
125
127
|
* What an action sees when it runs. `item` is the original object returned by `search()`,
|
|
@@ -142,6 +144,8 @@ export type ActionDefinition<TItem = any> = {
|
|
|
142
144
|
title: LocalizedText;
|
|
143
145
|
description?: LocalizedText;
|
|
144
146
|
hotkey?: Hotkey;
|
|
147
|
+
/** Keep this action visible in the host action bar instead of the overflow menu. */
|
|
148
|
+
pinned?: boolean;
|
|
145
149
|
execute: (context: ActionContext<TItem>) => ActionOutcome | void | Promise<ActionOutcome | void>;
|
|
146
150
|
};
|
|
147
151
|
|
|
@@ -151,6 +155,7 @@ export type ActionManifestEntry = {
|
|
|
151
155
|
title: LocalizedText;
|
|
152
156
|
description?: LocalizedText;
|
|
153
157
|
hotkey?: Hotkey;
|
|
158
|
+
pinned?: boolean;
|
|
154
159
|
};
|
|
155
160
|
|
|
156
161
|
export function toActionManifest(definition: ActionDefinition): ActionManifestEntry {
|
|
@@ -160,5 +165,6 @@ export function toActionManifest(definition: ActionDefinition): ActionManifestEn
|
|
|
160
165
|
};
|
|
161
166
|
if (definition.description) entry.description = definition.description;
|
|
162
167
|
if (definition.hotkey) entry.hotkey = definition.hotkey;
|
|
168
|
+
if (definition.pinned) entry.pinned = true;
|
|
163
169
|
return entry;
|
|
164
170
|
}
|
package/src/bootstrap.ts
CHANGED
|
@@ -102,13 +102,13 @@ async function readBootstrapLine(): Promise<{ pipePath: string; token: string }>
|
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Sends bus.handshake with the bootstrap token and waits for the host response that binds
|
|
105
|
-
* plugin/
|
|
105
|
+
* plugin/session/endpoint identity. Rejects on HandshakeFailed / ProtocolMismatch / timeout.
|
|
106
106
|
*/
|
|
107
107
|
export async function completeHandshake(
|
|
108
108
|
transport: NodeTransport,
|
|
109
109
|
token: string,
|
|
110
110
|
timeoutMs = 10000,
|
|
111
|
-
): Promise<{ pluginId: string;
|
|
111
|
+
): Promise<{ pluginId: string; sessionId: string; endpointId: string }> {
|
|
112
112
|
const id = randomBytes(16).toString("hex");
|
|
113
113
|
const req: Envelope = {
|
|
114
114
|
version: ProtocolVersion,
|
|
@@ -116,7 +116,6 @@ export async function completeHandshake(
|
|
|
116
116
|
traceId: id,
|
|
117
117
|
sessionId: "",
|
|
118
118
|
pluginId: "",
|
|
119
|
-
entryId: "",
|
|
120
119
|
endpointId: EndpointIds.NodeMain,
|
|
121
120
|
kind: MessageKind.Request,
|
|
122
121
|
route: Routes.Bus.Handshake,
|
|
@@ -144,14 +143,13 @@ export async function completeHandshake(
|
|
|
144
143
|
}
|
|
145
144
|
const p = (env.payload ?? {}) as Record<string, unknown>;
|
|
146
145
|
const pluginId = String(p.pluginId ?? "");
|
|
147
|
-
const entryId = String(p.entryId ?? "");
|
|
148
146
|
const sessionId = String(p.sessionId ?? "");
|
|
149
147
|
const endpointId = String(p.endpointId ?? EndpointIds.NodeMain);
|
|
150
|
-
if (!pluginId || !
|
|
148
|
+
if (!pluginId || !sessionId) {
|
|
151
149
|
reject(new Error("bus.handshake success response missing bound identity"));
|
|
152
150
|
return;
|
|
153
151
|
}
|
|
154
|
-
resolve({ pluginId,
|
|
152
|
+
resolve({ pluginId, sessionId, endpointId });
|
|
155
153
|
});
|
|
156
154
|
|
|
157
155
|
transport.send(req);
|
package/src/node.ts
CHANGED
package/src/protocol.ts
CHANGED
package/src/router.ts
CHANGED
|
@@ -62,7 +62,6 @@ export class HandlerRouter {
|
|
|
62
62
|
private handlers = new Map<string, Handler>();
|
|
63
63
|
private pendingHostCalls = new Map<string, PendingHostCall>();
|
|
64
64
|
private pluginId = "p";
|
|
65
|
-
private entryId = "e";
|
|
66
65
|
private sessionId = "s";
|
|
67
66
|
private endpointId: string = EndpointIds.NodeMain;
|
|
68
67
|
|
|
@@ -74,9 +73,8 @@ export class HandlerRouter {
|
|
|
74
73
|
}
|
|
75
74
|
|
|
76
75
|
/** Sets the bound identity stamped on outbound messages (after handshake). */
|
|
77
|
-
setIdentity(ids: { pluginId: string;
|
|
76
|
+
setIdentity(ids: { pluginId: string; sessionId: string; endpointId: string }): void {
|
|
78
77
|
this.pluginId = ids.pluginId;
|
|
79
|
-
this.entryId = ids.entryId;
|
|
80
78
|
this.sessionId = ids.sessionId;
|
|
81
79
|
this.endpointId = ids.endpointId;
|
|
82
80
|
}
|
|
@@ -133,7 +131,6 @@ export class HandlerRouter {
|
|
|
133
131
|
traceId: id,
|
|
134
132
|
sessionId: this.sessionId,
|
|
135
133
|
pluginId: this.pluginId,
|
|
136
|
-
entryId: this.entryId,
|
|
137
134
|
endpointId: this.endpointId,
|
|
138
135
|
kind: MessageKind.Request,
|
|
139
136
|
route,
|
|
@@ -176,7 +173,6 @@ export class HandlerRouter {
|
|
|
176
173
|
traceId: req.traceId,
|
|
177
174
|
sessionId: req.sessionId,
|
|
178
175
|
pluginId: req.pluginId,
|
|
179
|
-
entryId: req.entryId,
|
|
180
176
|
endpointId: this.endpointId,
|
|
181
177
|
kind: MessageKind.Response,
|
|
182
178
|
route: req.route,
|
package/src/webClient.ts
CHANGED
|
@@ -208,7 +208,6 @@ export function createWebBusClient(options?: {
|
|
|
208
208
|
traceId: id,
|
|
209
209
|
sessionId: "",
|
|
210
210
|
pluginId: "",
|
|
211
|
-
entryId: "",
|
|
212
211
|
endpointId: "",
|
|
213
212
|
kind: MessageKind.Request,
|
|
214
213
|
route,
|
|
@@ -277,7 +276,6 @@ function handshake(timeoutMs: number): Promise<string> {
|
|
|
277
276
|
traceId: id,
|
|
278
277
|
sessionId: "",
|
|
279
278
|
pluginId: "",
|
|
280
|
-
entryId: "",
|
|
281
279
|
endpointId: "web",
|
|
282
280
|
kind: MessageKind.Request,
|
|
283
281
|
route: Routes.Bus.Handshake,
|