@zhin.js/plugin-runtime 1.1.7 → 1.1.9
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/lib/admission.d.ts +3 -0
- package/lib/admission.js +25 -0
- package/lib/database-host.d.ts +1 -0
- package/lib/database-host.js +1 -0
- package/lib/html-renderer.d.ts +2 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/outbound-host.d.ts +25 -0
- package/lib/outbound-host.js +1 -0
- package/lib/plugin.d.ts +26 -0
- package/lib/plugin.js +22 -0
- package/lib/schedule-host.d.ts +1 -1
- package/lib/schedule-host.js +1 -1
- package/package.json +1 -1
package/lib/admission.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export declare class GenerationAdmissionGate {
|
|
|
7
7
|
constructor();
|
|
8
8
|
get active(): boolean;
|
|
9
9
|
acquire(): (() => void) | undefined;
|
|
10
|
+
/** Observe the first commit which publishes this generation. */
|
|
11
|
+
onActivate(listener: () => void): () => void;
|
|
10
12
|
/**
|
|
11
13
|
* Observe retirement of the generation that owns this gate. The callback is
|
|
12
14
|
* synchronous and must not fail; it is intended for closing process-owned
|
|
@@ -19,6 +21,7 @@ export declare function createGenerationAdmissionGate(): GenerationAdmissionGate
|
|
|
19
21
|
/** Resource hook used by CapabilityContext to bind an ingress dependency. */
|
|
20
22
|
export declare const generationAdmissionBinder: unique symbol;
|
|
21
23
|
export interface GenerationAdmissionBindable<T> {
|
|
24
|
+
/** @internal Runtime lifecycle wiring; never called by plugin authors. */
|
|
22
25
|
[generationAdmissionBinder](gate: GenerationAdmissionGate): T;
|
|
23
26
|
}
|
|
24
27
|
/** Snapshot value hook used to declare lifecycle-owned ingress gates. */
|
package/lib/admission.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
export class GenerationAdmissionGate {
|
|
7
7
|
constructor() {
|
|
8
8
|
admissionState.set(this, { active: false });
|
|
9
|
+
admissionActivationListeners.set(this, new Set());
|
|
9
10
|
admissionDeactivationListeners.set(this, new Set());
|
|
10
11
|
}
|
|
11
12
|
get active() {
|
|
@@ -15,6 +16,18 @@ export class GenerationAdmissionGate {
|
|
|
15
16
|
const state = admissionState.get(this);
|
|
16
17
|
return state?.active ? state.acquire?.() : undefined;
|
|
17
18
|
}
|
|
19
|
+
/** Observe the first commit which publishes this generation. */
|
|
20
|
+
onActivate(listener) {
|
|
21
|
+
const listeners = admissionActivationListeners.get(this);
|
|
22
|
+
if (!listeners)
|
|
23
|
+
throw new Error('Unknown generation admission gate');
|
|
24
|
+
if (this.active) {
|
|
25
|
+
listener();
|
|
26
|
+
return () => undefined;
|
|
27
|
+
}
|
|
28
|
+
listeners.add(listener);
|
|
29
|
+
return () => { listeners.delete(listener); };
|
|
30
|
+
}
|
|
18
31
|
/**
|
|
19
32
|
* Observe retirement of the generation that owns this gate. The callback is
|
|
20
33
|
* synchronous and must not fail; it is intended for closing process-owned
|
|
@@ -50,6 +63,7 @@ export class GenerationAdmissionGate {
|
|
|
50
63
|
}
|
|
51
64
|
const admissionState = new WeakMap();
|
|
52
65
|
const admissionOwners = new WeakMap();
|
|
66
|
+
const admissionActivationListeners = new WeakMap();
|
|
53
67
|
const admissionDeactivationListeners = new WeakMap();
|
|
54
68
|
export function createGenerationAdmissionGate() {
|
|
55
69
|
return new GenerationAdmissionGate();
|
|
@@ -111,6 +125,17 @@ export function replaceGenerationAdmissions(previous, next, owner, acquireNext)
|
|
|
111
125
|
}
|
|
112
126
|
for (const gate of next) {
|
|
113
127
|
admissionState.set(gate, { active: true, acquire: acquireNext });
|
|
128
|
+
const listeners = admissionActivationListeners.get(gate);
|
|
129
|
+
for (const listener of listeners ?? []) {
|
|
130
|
+
try {
|
|
131
|
+
listener();
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Admission publication is an infallible pointer switch. Buffered
|
|
135
|
+
// ingress reports through its own dispatch path.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
listeners?.clear();
|
|
114
139
|
}
|
|
115
140
|
}
|
|
116
141
|
function assertClaimableAdmission(gate, owner) {
|
package/lib/database-host.d.ts
CHANGED
|
@@ -128,6 +128,7 @@ export declare function unwrapPluginDatabaseHost(host: DatabaseHost | PluginData
|
|
|
128
128
|
* The owner encoding keeps `root/a` and `root/a/b` disjoint, so a parent
|
|
129
129
|
* facade cannot accidentally enumerate a descendant's tables.
|
|
130
130
|
*/
|
|
131
|
+
/** @public Plugin-facing database facade bound to the current owner. */
|
|
131
132
|
export declare const databaseHostToken: import("./token.js").Token<PluginDatabaseHost>;
|
|
132
133
|
/** Root-only process host for CLI composition and Console administration. */
|
|
133
134
|
export declare const databaseRootHostToken: import("./token.js").Token<DatabaseHost>;
|
package/lib/database-host.js
CHANGED
|
@@ -66,6 +66,7 @@ function assertLogicalResourceName(name) {
|
|
|
66
66
|
* The owner encoding keeps `root/a` and `root/a/b` disjoint, so a parent
|
|
67
67
|
* facade cannot accidentally enumerate a descendant's tables.
|
|
68
68
|
*/
|
|
69
|
+
/** @public Plugin-facing database facade bound to the current owner. */
|
|
69
70
|
export const databaseHostToken = createToken('zhin.database.host', 'Plugin Runtime scoped database host');
|
|
70
71
|
/** Root-only process host for CLI composition and Console administration. */
|
|
71
72
|
export const databaseRootHostToken = createToken('zhin.database.root-host', 'Plugin Runtime root database host');
|
package/lib/html-renderer.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export interface HtmlRenderOptions {
|
|
2
2
|
readonly width?: number;
|
|
3
|
+
/** 兼容旧调用方;当前实现传 `svg` 也会降级为 png。 */
|
|
3
4
|
readonly format?: 'png' | 'svg';
|
|
4
5
|
readonly backgroundColor?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface HtmlRenderResult {
|
|
7
|
-
/**
|
|
8
|
+
/** 当前实现恒为 png:Buffer/Uint8Array。 */
|
|
8
9
|
readonly data: unknown;
|
|
9
10
|
readonly format: 'png' | 'svg';
|
|
10
11
|
readonly width: number;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/outbound-host.d.ts
CHANGED
|
@@ -42,6 +42,22 @@ export interface OutboundRecallInput {
|
|
|
42
42
|
readonly endpointKey: string;
|
|
43
43
|
readonly message: OutboundMessage;
|
|
44
44
|
}
|
|
45
|
+
export type OutboundEndpointOperation = 'recall' | 'edit' | 'reaction' | 'typing';
|
|
46
|
+
export interface OutboundEndpointInput {
|
|
47
|
+
readonly adapter: string;
|
|
48
|
+
readonly endpointKey: string;
|
|
49
|
+
}
|
|
50
|
+
export interface OutboundEndpointCapabilities {
|
|
51
|
+
readonly operations: readonly OutboundEndpointOperation[];
|
|
52
|
+
}
|
|
53
|
+
export interface OutboundEditInput extends OutboundEndpointInput {
|
|
54
|
+
readonly message: OutboundMessage;
|
|
55
|
+
readonly content: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface OutboundTypingInput extends OutboundEndpointInput {
|
|
58
|
+
readonly conversation: OutboundMessage['conversation'];
|
|
59
|
+
readonly active?: boolean;
|
|
60
|
+
}
|
|
45
61
|
/** Structured message identity; structurally compatible with IM MessageRef. */
|
|
46
62
|
export interface OutboundMessage {
|
|
47
63
|
readonly conversation: OutboundConversation & Readonly<{
|
|
@@ -53,6 +69,10 @@ export interface OutboundMessage {
|
|
|
53
69
|
readonly id: string;
|
|
54
70
|
}
|
|
55
71
|
export interface OutboundHost {
|
|
72
|
+
/** Runs related operations against one IM Runtime snapshot captured at ingress. */
|
|
73
|
+
runWithView?<T>(operation: () => Promise<T>): Promise<T>;
|
|
74
|
+
/** Exact operations declared by one live Endpoint. */
|
|
75
|
+
capabilities?(input: OutboundEndpointInput): OutboundEndpointCapabilities | undefined;
|
|
56
76
|
/** Returns platform message id when available (activity-feedback needs it). */
|
|
57
77
|
send(input: OutboundSendInput): Promise<string | null>;
|
|
58
78
|
/** Optional: platform message reactions (icqq group emoji, etc.). */
|
|
@@ -60,5 +80,10 @@ export interface OutboundHost {
|
|
|
60
80
|
removeReaction?(input: OutboundRemoveReactionInput): Promise<void>;
|
|
61
81
|
/** Optional: recall/delete a status message (activity-feedback autoRemove). */
|
|
62
82
|
recall?(input: OutboundRecallInput): Promise<void>;
|
|
83
|
+
/** Optional: update a previously sent status message. */
|
|
84
|
+
edit?(input: OutboundEditInput): Promise<string | null>;
|
|
85
|
+
/** Optional: toggle the platform-native typing indicator. */
|
|
86
|
+
typing?(input: OutboundTypingInput): Promise<void>;
|
|
63
87
|
}
|
|
88
|
+
/** @public Plugin-facing cross-platform outbound messaging Host. */
|
|
64
89
|
export declare const outboundHostToken: import("./token.js").Token<OutboundHost>;
|
package/lib/outbound-host.js
CHANGED
package/lib/plugin.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical plugin definition consumed from `zhin.js`.
|
|
3
|
+
* @module zhin.js
|
|
4
|
+
*/
|
|
1
5
|
import type { Dispose, DisposeStack } from './dispose.js';
|
|
2
6
|
import type { GenerationHandoffRegistry } from './handoff.js';
|
|
3
7
|
import type { FeatureId, PluginId } from './identity.js';
|
|
@@ -27,6 +31,7 @@ export interface PluginSetupContext<TConfig = unknown> {
|
|
|
27
31
|
/**
|
|
28
32
|
* Registers an in-memory definition through the same validation and
|
|
29
33
|
* projection transaction used by convention-discovered capabilities.
|
|
34
|
+
* @internal Runtime bridge for feature installers; plugin authors use convention files.
|
|
30
35
|
*/
|
|
31
36
|
addFeature<TDefinition>(feature: FeatureId | string, localName: string, definition: TDefinition): void;
|
|
32
37
|
}
|
|
@@ -36,4 +41,25 @@ export interface PluginDefinition<TConfig = unknown> {
|
|
|
36
41
|
readonly requires?: readonly Token<unknown>[];
|
|
37
42
|
setup?(context: PluginSetupContext<TConfig>): void | Dispose | Promise<void | Dispose>;
|
|
38
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Define the canonical `plugin.ts` entry point.
|
|
46
|
+
* Setup runs against one candidate generation and may return its disposer.
|
|
47
|
+
*
|
|
48
|
+
* @public
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { definePlugin } from 'zhin.js';
|
|
52
|
+
*
|
|
53
|
+
* // plugin.ts
|
|
54
|
+
* export default definePlugin({
|
|
55
|
+
* name: 'hello',
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* Put capabilities in convention files such as `commands/hello.ts`, each with
|
|
60
|
+
* one default export.
|
|
61
|
+
*/
|
|
39
62
|
export declare function definePlugin<TConfig = unknown>(definition: PluginDefinition<TConfig>): Readonly<PluginDefinition<TConfig>>;
|
|
63
|
+
export { databaseHostToken, type DatabaseHostConsole, type DatabaseHostModel, type DatabaseHostSelection, type DatabaseHostSelectResult, type DatabaseHostTable, type DatabaseHostType, type PluginDatabaseHost, } from './database-host.js';
|
|
64
|
+
export { outboundHostToken, type OutboundConversation, type OutboundEditInput, type OutboundEndpointCapabilities, type OutboundEndpointInput, type OutboundEndpointOperation, type OutboundHost, type OutboundMessage, type OutboundReactionInput, type OutboundRecallInput, type OutboundRemoveReactionInput, type OutboundSendInput, type OutboundTypingInput, } from './outbound-host.js';
|
|
65
|
+
export { scheduleHostToken, type PluginScheduleHost, type ScheduleJobRegistration, } from './schedule-host.js';
|
package/lib/plugin.js
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
const pluginNamePattern = /^[a-z][a-z0-9-]*$/;
|
|
2
|
+
/**
|
|
3
|
+
* Define the canonical `plugin.ts` entry point.
|
|
4
|
+
* Setup runs against one candidate generation and may return its disposer.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { definePlugin } from 'zhin.js';
|
|
10
|
+
*
|
|
11
|
+
* // plugin.ts
|
|
12
|
+
* export default definePlugin({
|
|
13
|
+
* name: 'hello',
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Put capabilities in convention files such as `commands/hello.ts`, each with
|
|
18
|
+
* one default export.
|
|
19
|
+
*/
|
|
2
20
|
export function definePlugin(definition) {
|
|
3
21
|
if (!pluginNamePattern.test(definition.name)) {
|
|
4
22
|
throw new TypeError(`Invalid plugin name: ${definition.name}`);
|
|
@@ -9,3 +27,7 @@ export function definePlugin(definition) {
|
|
|
9
27
|
requires: Object.freeze([...(definition.requires ?? [])]),
|
|
10
28
|
});
|
|
11
29
|
}
|
|
30
|
+
// The application facade exposes these Host contracts beside definePlugin.
|
|
31
|
+
export { databaseHostToken, } from './database-host.js';
|
|
32
|
+
export { outboundHostToken, } from './outbound-host.js';
|
|
33
|
+
export { scheduleHostToken, } from './schedule-host.js';
|
package/lib/schedule-host.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export declare function unqualifyPluginScheduleId(owner: PluginId, id: string):
|
|
|
37
37
|
export declare function createPluginScheduleHost(owner: PluginId, host: ScheduleHost): PluginScheduleHost;
|
|
38
38
|
/** See unwrapPluginDatabaseHost: preserves legacy custom RootResource installers. */
|
|
39
39
|
export declare function unwrapPluginScheduleHost(host: ScheduleHost | PluginScheduleHost): ScheduleHost;
|
|
40
|
-
/** Plugin-facing token; Runtime injects a facade bound to the current owner. */
|
|
40
|
+
/** @public Plugin-facing token; Runtime injects a facade bound to the current owner. */
|
|
41
41
|
export declare const scheduleHostToken: import("./token.js").Token<PluginScheduleHost>;
|
|
42
42
|
/** Root-only process scheduler for CLI composition and Console administration. */
|
|
43
43
|
export declare const scheduleRootHostToken: import("./token.js").Token<ScheduleHost>;
|
package/lib/schedule-host.js
CHANGED
|
@@ -46,7 +46,7 @@ function assertLogicalJobId(id) {
|
|
|
46
46
|
throw new TypeError(`Invalid plugin schedule id: ${id}`);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
/** Plugin-facing token; Runtime injects a facade bound to the current owner. */
|
|
49
|
+
/** @public Plugin-facing token; Runtime injects a facade bound to the current owner. */
|
|
50
50
|
export const scheduleHostToken = createToken('zhin.schedule.host', 'Plugin Runtime scoped solar cron host');
|
|
51
51
|
/** Root-only process scheduler for CLI composition and Console administration. */
|
|
52
52
|
export const scheduleRootHostToken = createToken('zhin.schedule.root-host', 'Plugin Runtime root solar cron host');
|