@zhin.js/adapter 1.1.7 → 1.1.8

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.
@@ -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: MessageTarget): Promise<void>;
20
- edit?(message: MessageTarget, content: unknown): Promise<string | null>;
11
+ recall?(message: MessageRef): Promise<void>;
12
+ edit?(message: MessageRef, content: unknown): Promise<string | null>;
21
13
  addReaction?(
22
- message: MessageTarget,
14
+ message: MessageRef,
23
15
  emoji: string,
24
16
  hint?: { readonly sceneType?: string; readonly channelId?: string },
25
17
  ): Promise<string | null>;
26
- removeReaction?(message: MessageTarget, reactionId: string): Promise<void>;
27
- typing?(conversation: ConversationTarget, active?: boolean): Promise<void>;
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
- * Resolves the public control port. The legacy branch is deliberately kept in
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
- if (explicit && typeof explicit === 'object') return explicit;
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, type RuntimeSnapshot } from '@zhin.js/plugin-runtime';
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
- quiescePrevious(previous) {
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;