@zhin.js/adapter 1.1.3 → 1.1.5

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 CHANGED
@@ -27,9 +27,9 @@ Adapter definitions declare `capabilities` for inbound/outbound admission and
27
27
  instead of probing optional endpoint methods. The zero-dependency types live in
28
28
  [`@zhin.js/im-contract`](../im-contract/README.md).
29
29
 
30
- New framework-facing outbound code should carry a structured `ConversationRef`.
31
- `EndpointSendRequest.target` remains temporarily for platform codecs that still
32
- need their legacy target string; it is not a general-purpose message identity.
30
+ Framework-facing outbound code carries a structured `ConversationRef`.
31
+ `EndpointSendRequest` is `{ conversation, payload }`; platform adapters derive
32
+ their native target from `conversation` at the endpoint boundary.
33
33
 
34
34
  ## Endpoint Control Port
35
35
 
@@ -12,19 +12,9 @@ export type AdapterOutboundMedia = 'url' | 'path' | 'base64' | 'upload';
12
12
  /** 交互段(卡片/按钮等富交互)的端点消费方式。 */
13
13
  export type AdapterInteractiveMode = 'native' | 'text';
14
14
  export interface EndpointSendRequest {
15
- /**
16
- * Structured identity for new callers. The target remains until every
17
- * platform adapter has migrated its native boundary codec.
18
- */
19
- readonly conversation?: ConversationRef;
20
- /** @deprecated Use conversation for framework-facing code. */
21
- readonly target: string;
15
+ /** 结构化会话寻址;端点在平台边界自行派生原生 target。 */
16
+ readonly conversation: ConversationRef;
22
17
  readonly payload: unknown;
23
- readonly parent?: {
24
- readonly type?: string;
25
- readonly id?: string;
26
- readonly name?: string;
27
- };
28
18
  }
29
19
  export interface EndpointInstance<TResult = unknown> {
30
20
  /** Optional platform-neutral Console/Host management surface. */
@@ -89,8 +89,9 @@ export interface EndpointCommandsSpec {
89
89
  * provider 层不允许 import @zhin.js/command,故 defineCommand 由调用方注入,
90
90
  * 这里只描述结构;适配器侧传入 defineCommand 后 TCommand 即 Readonly<CommandDefinition>。
91
91
  *
92
- * `params` 值域须与 CommandParameterValue 对齐(含 null / 结构化对象),
93
- * 否则注入的 defineCommand 会因 TS 逆变检查失败(TS2345)。
92
+ * `params` 值域须与 CommandParameterValue 对齐(含 null / 结构化对象 / rest 段的
93
+ * `ReadonlyArray<string | number | boolean>`),否则注入的 defineCommand 会因
94
+ * TS 逆变检查失败(TS2345)。
94
95
  */
95
96
  export interface EndpointCommandContext {
96
97
  readonly config: unknown;
@@ -101,11 +102,16 @@ export interface EndpointCommandContext {
101
102
  */
102
103
  readonly input?: unknown;
103
104
  readonly args: readonly string[];
104
- readonly params: Readonly<Record<string, string | number | boolean | Readonly<Record<string, unknown>> | null>>;
105
+ readonly params: Readonly<Record<string, string | number | boolean | ReadonlyArray<string | number | boolean> | Readonly<Record<string, unknown>> | null>>;
105
106
  readonly use: EndpointCommandUse;
106
107
  }
107
108
  export interface EndpointCommandDefinition {
108
109
  readonly description?: string;
110
+ readonly params?: Readonly<Record<string, {
111
+ readonly type: 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'word' | 'text' | 'mention' | 'image' | 'face' | 'reply' | 'forward' | 'dice' | 'rps';
112
+ readonly default?: string | number | boolean | ReadonlyArray<string | number | boolean> | Readonly<Record<string, unknown>> | null;
113
+ readonly description?: string;
114
+ }>>;
109
115
  execute(context: EndpointCommandContext): unknown;
110
116
  }
111
117
  export interface EndpointCommands<TCommand = EndpointCommandDefinition> {
@@ -20,7 +20,7 @@
20
20
  * 3. src 下 `export const telegramEndpointCommands = createEndpointCommands({ adapterKey: 'telegram', ... }, defineCommand)`
21
21
  * (defineCommand 由调用方从 @zhin.js/command 传入——provider 包之间禁止互相 import,
22
22
  * 见 scripts/check-architecture-layers.mjs,故 defineCommand 走依赖注入)。
23
- * 4. commands/endpoint/{list.ts, add/[name:string].ts, remove/[name:string].ts} 分别
23
+ * 4. commands/endpoint/{list.ts, add/[name].ts, remove/[name].ts} 分别
24
24
  * `export default telegramEndpointCommands.list|add|remove`。
25
25
  *
26
26
  * 注意:adapterKey 即实例 key(zhin.config.yml 的 plugins.<key>);多实例自定义 key 时
@@ -355,6 +355,7 @@ export function createEndpointCommands(spec, defineCommand) {
355
355
  add: defineCommand({
356
356
  description: spec.addDescription
357
357
  ?? `手动添加 ${spec.adapterDisplayName} endpoint(凭据写入 .env 并追加到 zhin.config.yml,重启生效)`,
358
+ params: { name: { type: 'string', description: 'endpoint 名称' } },
358
359
  execute({ config, input, params, args, use }) {
359
360
  if (!isEndpointOperator(config, input))
360
361
  return forbidden;
@@ -375,6 +376,7 @@ export function createEndpointCommands(spec, defineCommand) {
375
376
  }),
376
377
  remove: defineCommand({
377
378
  description: `从 zhin.config.yml 的 plugins.${spec.adapterKey}.endpoints 移除指定 endpoint(重启生效)`,
379
+ params: { name: { type: 'string', description: 'endpoint 名称' } },
378
380
  execute({ config, input, params }) {
379
381
  if (!isEndpointOperator(config, input))
380
382
  return forbidden;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Convention-based Adapter and Endpoint Feature for Zhin Plugin Runtime",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -18,15 +18,15 @@
18
18
  ],
19
19
  "dependencies": {
20
20
  "yaml": "^2.9.0",
21
- "@zhin.js/feature-kit": "1.0.4",
22
- "@zhin.js/im-contract": "1.0.0",
21
+ "@zhin.js/feature-kit": "1.0.6",
22
+ "@zhin.js/im-contract": "1.0.1",
23
23
  "@zhin.js/logger": "1.0.75",
24
- "@zhin.js/plugin-runtime": "1.1.1"
24
+ "@zhin.js/plugin-runtime": "1.1.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^26.1.2",
28
28
  "typescript": "^6.0.3",
29
- "@zhin.js/command": "1.0.5"
29
+ "@zhin.js/command": "1.0.7"
30
30
  },
31
31
  "zhin": {
32
32
  "protocol": 1,
package/src/definition.ts CHANGED
@@ -22,15 +22,9 @@ export type AdapterOutboundMedia = 'url' | 'path' | 'base64' | 'upload';
22
22
  export type AdapterInteractiveMode = 'native' | 'text';
23
23
 
24
24
  export interface EndpointSendRequest {
25
- /**
26
- * Structured identity for new callers. The target remains until every
27
- * platform adapter has migrated its native boundary codec.
28
- */
29
- readonly conversation?: ConversationRef;
30
- /** @deprecated Use conversation for framework-facing code. */
31
- readonly target: string;
25
+ /** 结构化会话寻址;端点在平台边界自行派生原生 target。 */
26
+ readonly conversation: ConversationRef;
32
27
  readonly payload: unknown;
33
- readonly parent?: { readonly type?: string; readonly id?: string; readonly name?: string };
34
28
  }
35
29
 
36
30
  export interface EndpointInstance<TResult = unknown> {
@@ -20,7 +20,7 @@
20
20
  * 3. src 下 `export const telegramEndpointCommands = createEndpointCommands({ adapterKey: 'telegram', ... }, defineCommand)`
21
21
  * (defineCommand 由调用方从 @zhin.js/command 传入——provider 包之间禁止互相 import,
22
22
  * 见 scripts/check-architecture-layers.mjs,故 defineCommand 走依赖注入)。
23
- * 4. commands/endpoint/{list.ts, add/[name:string].ts, remove/[name:string].ts} 分别
23
+ * 4. commands/endpoint/{list.ts, add/[name].ts, remove/[name].ts} 分别
24
24
  * `export default telegramEndpointCommands.list|add|remove`。
25
25
  *
26
26
  * 注意:adapterKey 即实例 key(zhin.config.yml 的 plugins.<key>);多实例自定义 key 时
@@ -355,8 +355,9 @@ export interface EndpointCommandsSpec {
355
355
  * provider 层不允许 import @zhin.js/command,故 defineCommand 由调用方注入,
356
356
  * 这里只描述结构;适配器侧传入 defineCommand 后 TCommand 即 Readonly<CommandDefinition>。
357
357
  *
358
- * `params` 值域须与 CommandParameterValue 对齐(含 null / 结构化对象),
359
- * 否则注入的 defineCommand 会因 TS 逆变检查失败(TS2345)。
358
+ * `params` 值域须与 CommandParameterValue 对齐(含 null / 结构化对象 / rest 段的
359
+ * `ReadonlyArray<string | number | boolean>`),否则注入的 defineCommand 会因
360
+ * TS 逆变检查失败(TS2345)。
360
361
  */
361
362
  export interface EndpointCommandContext {
362
363
  readonly config: unknown;
@@ -369,13 +370,33 @@ export interface EndpointCommandContext {
369
370
  readonly args: readonly string[];
370
371
  readonly params: Readonly<Record<
371
372
  string,
372
- string | number | boolean | Readonly<Record<string, unknown>> | null
373
+ | string
374
+ | number
375
+ | boolean
376
+ | ReadonlyArray<string | number | boolean>
377
+ | Readonly<Record<string, unknown>>
378
+ | null
373
379
  >>;
374
380
  readonly use: EndpointCommandUse;
375
381
  }
376
382
 
377
383
  export interface EndpointCommandDefinition {
378
384
  readonly description?: string;
385
+ // 与 @zhin.js/command 的 CommandParamSchema 结构对齐(provider 层不能 import
386
+ // command,字面量联合在此镜像声明;新增参数类型须两侧同步)。
387
+ readonly params?: Readonly<Record<string, {
388
+ readonly type:
389
+ | 'string' | 'number' | 'integer' | 'float' | 'boolean' | 'word' | 'text'
390
+ | 'mention' | 'image' | 'face' | 'reply' | 'forward' | 'dice' | 'rps';
391
+ readonly default?:
392
+ | string
393
+ | number
394
+ | boolean
395
+ | ReadonlyArray<string | number | boolean>
396
+ | Readonly<Record<string, unknown>>
397
+ | null;
398
+ readonly description?: string;
399
+ }>>;
379
400
  execute(context: EndpointCommandContext): unknown;
380
401
  }
381
402
 
@@ -532,6 +553,7 @@ export function createEndpointCommands<TCommand>(
532
553
  add: defineCommand({
533
554
  description: spec.addDescription
534
555
  ?? `手动添加 ${spec.adapterDisplayName} endpoint(凭据写入 .env 并追加到 zhin.config.yml,重启生效)`,
556
+ params: { name: { type: 'string', description: 'endpoint 名称' } },
535
557
  execute({ config, input, params, args, use }) {
536
558
  if (!isEndpointOperator(config, input)) return forbidden;
537
559
  const name = endpointNameParam(params);
@@ -550,6 +572,7 @@ export function createEndpointCommands<TCommand>(
550
572
  }),
551
573
  remove: defineCommand({
552
574
  description: `从 zhin.config.yml 的 plugins.${spec.adapterKey}.endpoints 移除指定 endpoint(重启生效)`,
575
+ params: { name: { type: 'string', description: 'endpoint 名称' } },
553
576
  execute({ config, input, params }) {
554
577
  if (!isEndpointOperator(config, input)) return forbidden;
555
578
  return removeEndpointByName(spec, String(params.name ?? ''));