@zhin.js/adapter 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/README.md +7 -5
- package/lib/adapter-index.d.ts +7 -7
- package/lib/adapter-index.js +103 -235
- package/lib/definition.d.ts +3 -3
- package/lib/endpoint-control.d.ts +8 -16
- package/lib/endpoint-control.js +3 -51
- package/lib/provider.js +2 -14
- package/package.json +5 -5
- package/src/adapter-index.ts +115 -260
- package/src/definition.ts +3 -3
- package/src/endpoint-control.ts +9 -73
- package/src/provider.ts +3 -16
package/src/endpoint-control.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatLegacyConversationRef,
|
|
3
|
-
formatLegacyMessageRef,
|
|
4
|
-
type ConversationTarget,
|
|
5
|
-
type LegacyEndpointControlSurface,
|
|
6
|
-
type MessageTarget,
|
|
7
|
-
} from '@zhin.js/im-contract';
|
|
8
|
-
|
|
9
|
-
export type { LegacyEndpointControlSurface } from '@zhin.js/im-contract';
|
|
1
|
+
import type { ConversationRef, MessageRef } from '@zhin.js/im-contract';
|
|
10
2
|
|
|
11
3
|
/**
|
|
12
4
|
* Transport-neutral control plane for a live endpoint.
|
|
@@ -16,82 +8,26 @@ export type { LegacyEndpointControlSurface } from '@zhin.js/im-contract';
|
|
|
16
8
|
* to know a protocol's method names or identifier layout.
|
|
17
9
|
*/
|
|
18
10
|
export interface EndpointControl {
|
|
19
|
-
recall?(message:
|
|
20
|
-
edit?(message:
|
|
11
|
+
recall?(message: MessageRef): Promise<void>;
|
|
12
|
+
edit?(message: MessageRef, content: unknown): Promise<string | null>;
|
|
21
13
|
addReaction?(
|
|
22
|
-
message:
|
|
14
|
+
message: MessageRef,
|
|
23
15
|
emoji: string,
|
|
24
16
|
hint?: { readonly sceneType?: string; readonly channelId?: string },
|
|
25
17
|
): Promise<string | null>;
|
|
26
|
-
removeReaction?(message:
|
|
27
|
-
typing?(conversation:
|
|
18
|
+
removeReaction?(message: MessageRef, reactionId: string): Promise<void>;
|
|
19
|
+
typing?(conversation: ConversationRef, active?: boolean): Promise<void>;
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
export interface EndpointWithControl {
|
|
31
23
|
readonly control?: EndpointControl;
|
|
32
24
|
}
|
|
33
25
|
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
* Adapter only: it is a migration bridge for existing classic protocol
|
|
37
|
-
* endpoints (`LegacyEndpointControlSurface` lives in `@zhin.js/im-contract`),
|
|
38
|
-
* not an IM Core extension point. New adapters must expose `control` directly.
|
|
39
|
-
* 下线条件:classic Plugin 轨下线后,legacy 分支与 LegacyEndpointControlSurface
|
|
40
|
-
* 一并删除。
|
|
41
|
-
*/
|
|
42
|
-
export function resolveEndpointControl(endpoint: unknown): EndpointControl | undefined {
|
|
26
|
+
/** Reads the canonical control port without probing protocol-specific methods. */
|
|
27
|
+
export function endpointControlOf(endpoint: unknown): EndpointControl | undefined {
|
|
43
28
|
if (!endpoint || typeof endpoint !== 'object') return undefined;
|
|
44
29
|
const explicit = (endpoint as EndpointWithControl).control;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const legacy = endpoint as LegacyEndpointControlSurface;
|
|
48
|
-
const recall = legacy.recallMessage ?? legacy.$recallMessage;
|
|
49
|
-
const edit = legacy.editMessage ?? legacy.$editMessage;
|
|
50
|
-
const addReaction = legacy.addReaction ?? legacy.$addReaction;
|
|
51
|
-
const removeReaction = legacy.removeReaction ?? legacy.$removeReaction;
|
|
52
|
-
const typing = legacy.typing ?? legacy.$typing;
|
|
53
|
-
if (!recall && !edit && !addReaction && !removeReaction && !typing) return undefined;
|
|
54
|
-
|
|
55
|
-
return Object.freeze({
|
|
56
|
-
...(recall
|
|
57
|
-
? { recall: (message: MessageTarget) => recall.call(endpoint, legacyMessageId(message)) }
|
|
58
|
-
: {}),
|
|
59
|
-
...(edit
|
|
60
|
-
? {
|
|
61
|
-
edit: (message: MessageTarget, content: unknown) =>
|
|
62
|
-
edit.call(endpoint, legacyMessageId(message), content),
|
|
63
|
-
}
|
|
64
|
-
: {}),
|
|
65
|
-
...(addReaction
|
|
66
|
-
? {
|
|
67
|
-
addReaction: (
|
|
68
|
-
message: MessageTarget,
|
|
69
|
-
emoji: string,
|
|
70
|
-
hint?: { readonly sceneType?: string; readonly channelId?: string },
|
|
71
|
-
) => addReaction.call(endpoint, legacyMessageId(message), emoji, hint),
|
|
72
|
-
}
|
|
73
|
-
: {}),
|
|
74
|
-
...(removeReaction
|
|
75
|
-
? {
|
|
76
|
-
removeReaction: (message: MessageTarget, reactionId: string) =>
|
|
77
|
-
removeReaction.call(endpoint, legacyMessageId(message), reactionId),
|
|
78
|
-
}
|
|
79
|
-
: {}),
|
|
80
|
-
...(typing
|
|
81
|
-
? {
|
|
82
|
-
typing: (conversation: ConversationTarget, active?: boolean) =>
|
|
83
|
-
typing.call(endpoint, legacyConversationTarget(conversation), active),
|
|
84
|
-
}
|
|
85
|
-
: {}),
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function legacyMessageId(message: MessageTarget): string {
|
|
90
|
-
return typeof message === 'string' ? message : formatLegacyMessageRef(message);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function legacyConversationTarget(conversation: ConversationTarget): string {
|
|
94
|
-
return typeof conversation === 'string' ? conversation : formatLegacyConversationRef(conversation);
|
|
30
|
+
return explicit && typeof explicit === 'object' ? explicit : undefined;
|
|
95
31
|
}
|
|
96
32
|
|
|
97
33
|
/** Checks only an Endpoint's explicit `control` port, never the legacy bridge. */
|
package/src/provider.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { featureId
|
|
1
|
+
import { featureId } from '@zhin.js/plugin-runtime';
|
|
2
2
|
import { defineFeatureProvider, typeScriptModules } from '@zhin.js/feature-kit';
|
|
3
3
|
import { AdapterIndex } from './adapter-index.js';
|
|
4
4
|
import { parseAdapterDefinition } from './definition.js';
|
|
@@ -18,31 +18,18 @@ const adapterFeature = defineFeatureProvider({
|
|
|
18
18
|
},
|
|
19
19
|
runtime: {
|
|
20
20
|
async project(slots, context) {
|
|
21
|
-
const index = await AdapterIndex.create(slots, context.snapshot);
|
|
22
|
-
let previousIndex: AdapterIndex | undefined;
|
|
21
|
+
const index = await AdapterIndex.create(slots, context.snapshot, context.signal);
|
|
23
22
|
return {
|
|
24
23
|
value: index,
|
|
25
24
|
dispose: () => index.stop(),
|
|
26
25
|
handoff: {
|
|
27
|
-
|
|
28
|
-
previousIndex = previousAdapterIndex(previous);
|
|
29
|
-
return previousIndex?.close();
|
|
30
|
-
},
|
|
31
|
-
activateNext: () => index.start(),
|
|
26
|
+
activateNext: (signal) => index.activate(signal),
|
|
32
27
|
deactivateNext: () => index.stop(),
|
|
33
|
-
resumePrevious() {
|
|
34
|
-
previousIndex?.open();
|
|
35
|
-
},
|
|
36
|
-
openNext: () => index.open(),
|
|
37
28
|
},
|
|
38
29
|
};
|
|
39
30
|
},
|
|
40
31
|
},
|
|
41
32
|
});
|
|
42
33
|
|
|
43
|
-
function previousAdapterIndex(snapshot: RuntimeSnapshot): AdapterIndex | undefined {
|
|
44
|
-
return snapshot.projections.get(adapterFeatureId) as AdapterIndex | undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
34
|
export { adapterFeature };
|
|
48
35
|
export default adapterFeature;
|