@zhin.js/adapter-icqq 1.1.0 → 1.1.2

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/README.md +15 -6
  3. package/adapters/{icqq.js → icqq/index.js} +6 -6
  4. package/adapters/{icqq.ts → icqq/index.ts} +10 -10
  5. package/agents/icqq/agent.json +20 -0
  6. package/agents/icqq/boundaries.md +3 -0
  7. package/agents/icqq/conventions.md +3 -0
  8. package/agents/icqq/skills/icqq-directory/SKILL.md +20 -0
  9. package/{tools/friend_list.js → agents/icqq/skills/icqq-directory/tools/friend_list/index.js} +2 -1
  10. package/{tools/friend_list.ts → agents/icqq/skills/icqq-directory/tools/friend_list/index.ts} +2 -1
  11. package/{tools/group_list.js → agents/icqq/skills/icqq-directory/tools/group_list/index.js} +2 -1
  12. package/{tools/group_list.ts → agents/icqq/skills/icqq-directory/tools/group_list/index.ts} +2 -1
  13. package/{tools/group_member_info.js → agents/icqq/skills/icqq-directory/tools/group_member_info/index.js} +3 -1
  14. package/{tools/group_member_info.ts → agents/icqq/skills/icqq-directory/tools/group_member_info/index.ts} +3 -1
  15. package/{tools/user_info.js → agents/icqq/skills/icqq-directory/tools/user_info/index.js} +1 -0
  16. package/{tools/user_info.ts → agents/icqq/skills/icqq-directory/tools/user_info/index.ts} +1 -0
  17. package/agents/icqq/skills/icqq-group-admin/SKILL.md +25 -0
  18. package/{tools/announce.js → agents/icqq/skills/icqq-group-admin/tools/announce/index.js} +2 -0
  19. package/{tools/announce.ts → agents/icqq/skills/icqq-group-admin/tools/announce/index.ts} +2 -0
  20. package/{tools/essence.js → agents/icqq/skills/icqq-group-admin/tools/essence/index.js} +3 -1
  21. package/{tools/essence.ts → agents/icqq/skills/icqq-group-admin/tools/essence/index.ts} +3 -1
  22. package/{tools/group_invite.js → agents/icqq/skills/icqq-group-admin/tools/group_invite/index.js} +1 -1
  23. package/{tools/group_invite.ts → agents/icqq/skills/icqq-group-admin/tools/group_invite/index.ts} +1 -1
  24. package/{tools/group_kick.js → agents/icqq/skills/icqq-group-admin/tools/group_kick/index.js} +4 -3
  25. package/{tools/group_kick.ts → agents/icqq/skills/icqq-group-admin/tools/group_kick/index.ts} +4 -3
  26. package/{tools/set_anonymous.js → agents/icqq/skills/icqq-group-admin/tools/set_anonymous/index.js} +3 -1
  27. package/{tools/set_anonymous.ts → agents/icqq/skills/icqq-group-admin/tools/set_anonymous/index.ts} +3 -1
  28. package/{tools/set_mute.js → agents/icqq/skills/icqq-group-admin/tools/set_mute/index.js} +3 -2
  29. package/{tools/set_mute.ts → agents/icqq/skills/icqq-group-admin/tools/set_mute/index.ts} +3 -2
  30. package/{tools/set_title.js → agents/icqq/skills/icqq-group-admin/tools/set_title/index.js} +3 -2
  31. package/{tools/set_title.ts → agents/icqq/skills/icqq-group-admin/tools/set_title/index.ts} +3 -2
  32. package/agents/icqq/skills/icqq-group-state/SKILL.md +17 -0
  33. package/{tools/group_files.js → agents/icqq/skills/icqq-group-state/tools/group_files/index.js} +3 -1
  34. package/{tools/group_files.ts → agents/icqq/skills/icqq-group-state/tools/group_files/index.ts} +3 -1
  35. package/{tools/list_muted.js → agents/icqq/skills/icqq-group-state/tools/list_muted/index.js} +2 -1
  36. package/{tools/list_muted.ts → agents/icqq/skills/icqq-group-state/tools/list_muted/index.ts} +2 -1
  37. package/agents/icqq/skills/icqq-interaction/SKILL.md +19 -0
  38. package/{tools/group_sign.js → agents/icqq/skills/icqq-interaction/tools/group_sign/index.js} +2 -1
  39. package/{tools/group_sign.ts → agents/icqq/skills/icqq-interaction/tools/group_sign/index.ts} +2 -1
  40. package/{tools/poke.js → agents/icqq/skills/icqq-interaction/tools/poke/index.js} +2 -1
  41. package/{tools/poke.ts → agents/icqq/skills/icqq-interaction/tools/poke/index.ts} +2 -1
  42. package/{tools/send_user_like.js → agents/icqq/skills/icqq-interaction/tools/send_user_like/index.js} +4 -3
  43. package/{tools/send_user_like.ts → agents/icqq/skills/icqq-interaction/tools/send_user_like/index.ts} +3 -3
  44. package/agents/icqq/system.md +3 -0
  45. package/commands/{endpoint/add/[[id]].js → icqq/endpoint/add/[[id]]/index.js} +1 -1
  46. package/commands/icqq/endpoint/add/[[id]]/index.ts +3 -0
  47. package/{lib/icqq-endpoint-commands.js → commands/icqq/endpoint/definition.js} +10 -5
  48. package/{src/icqq-endpoint-commands.ts → commands/icqq/endpoint/definition.ts} +9 -5
  49. package/commands/{endpoint/list.js → icqq/endpoint/list/index.js} +1 -1
  50. package/commands/icqq/endpoint/list/index.ts +3 -0
  51. package/commands/{endpoint/remove/[id].js → icqq/endpoint/remove/[id]/index.js} +1 -1
  52. package/commands/icqq/endpoint/remove/[id]/index.ts +3 -0
  53. package/lib/content-resolver.d.ts +10 -0
  54. package/lib/content-resolver.js +98 -0
  55. package/lib/cq-message.d.ts +1 -1
  56. package/lib/cq-message.js +1 -1
  57. package/lib/endpoint.d.ts +1 -2
  58. package/lib/endpoint.js +34 -77
  59. package/lib/icqq-runtime-state.js +1 -1
  60. package/lib/index.d.ts +1 -1
  61. package/lib/outbound-media.d.ts +1 -1
  62. package/lib/outbound-media.js +1 -1
  63. package/lib/protocol.d.ts +4 -22
  64. package/lib/protocol.js +52 -55
  65. package/lib/types.d.ts +0 -6
  66. package/package.json +29 -23
  67. package/plugin.js +1 -1
  68. package/prompt-sections/platform/index.js +16 -0
  69. package/{agent/prompt-sections/platform.ts → prompt-sections/platform/index.ts} +3 -4
  70. package/schema.json +7 -1
  71. package/src/content-resolver.ts +131 -0
  72. package/src/cq-message.ts +1 -1
  73. package/src/endpoint.ts +43 -97
  74. package/src/icqq-runtime-state.ts +1 -1
  75. package/src/index.ts +1 -1
  76. package/src/outbound-media.ts +2 -2
  77. package/src/protocol.ts +56 -80
  78. package/src/types.ts +0 -7
  79. package/commands/endpoint/add/[[id]].ts +0 -3
  80. package/commands/endpoint/list.ts +0 -3
  81. package/commands/endpoint/remove/[id].ts +0 -3
  82. package/lib/icqq-endpoint-commands.d.ts +0 -1
  83. /package/{agent/PERMITS.md → PERMITS.md} +0 -0
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ export {
5
5
  icqqInboundConversation,
6
6
  icqqOutboundTarget,
7
7
  type ActionResult,
8
- type IcqqAdapterConfig,
8
+ type IcqqEndpointConfig,
9
9
  type IcqqInboundMessage,
10
10
  type IcqqWireSegment,
11
11
  type ParsedIcqqSendTarget,
@@ -2,9 +2,9 @@ import * as fs from "node:fs";
2
2
  import * as os from "node:os";
3
3
  import * as path from "node:path";
4
4
  import * as crypto from "node:crypto";
5
- import { isMediaRef } from "@zhin.js/core";
5
+ import { isMediaRef } from '@zhin.js/im-contract';
6
6
  import type { MessageSegment, SendContent } from "zhin.js";
7
- import type { IcqqEndpointConfig } from "./types.js";
7
+ import type { IcqqEndpointConfig } from "./protocol.js";
8
8
 
9
9
  export type IcqqOutboundMediaMode = "file" | "base64";
10
10
 
package/src/protocol.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { pickCredential } from 'zhin.js/adapter';
2
- import type { MessageElem, Sendable } from '@icqqjs/icqq';
1
+ import type { MessageElem, Sendable, ShareElem } from '@icqqjs/icqq';
3
2
  import type { ConversationRef } from '@zhin.js/im-contract';
4
3
  import type { MessageSegment } from "zhin.js";
5
4
  import { resolveIcqqMediaFile } from "./cq-message.js";
@@ -231,9 +230,9 @@ export const Actions = {
231
230
  GET_NOTIFY: "get_notify",
232
231
  } as const;
233
232
 
234
- /** Plugin Runtime owner config (`plugins.<instanceKey>` / schema.json). */
235
- export interface IcqqAdapterConfig {
236
- readonly id?: string;
233
+ /** One expanded ICQQ endpoint configuration produced by AdapterIndex. */
234
+ export interface IcqqEndpointConfig {
235
+ readonly id: string;
237
236
  readonly autoReconnect?: boolean;
238
237
  readonly outboundMedia?: 'file' | 'base64';
239
238
  readonly password?: string;
@@ -247,24 +246,6 @@ export interface IcqqAdapterConfig {
247
246
  readonly autoServer?: boolean;
248
247
  readonly qqnt?: boolean;
249
248
  readonly ntLogin?: boolean;
250
- /** Transitional: legacy root `endpoints[]` with `context: icqq`. */
251
- readonly endpoints?: ReadonlyArray<{
252
- readonly context?: string;
253
- readonly id?: string;
254
- readonly autoReconnect?: boolean;
255
- readonly outboundMedia?: 'file' | 'base64';
256
- readonly password?: string;
257
- readonly platform?: number;
258
- readonly ver?: string;
259
- readonly dataDir?: string;
260
- readonly signApiAddr?: string;
261
- readonly ignoreSelf?: boolean;
262
- readonly resend?: boolean;
263
- readonly cacheGroupMember?: boolean;
264
- readonly autoServer?: boolean;
265
- readonly qqnt?: boolean;
266
- readonly ntLogin?: boolean;
267
- }>;
268
249
  }
269
250
 
270
251
  export interface ResolvedIcqqConfig {
@@ -311,27 +292,24 @@ export type ParsedIcqqSendTarget =
311
292
  | { readonly kind: 'temp'; readonly groupId: number; readonly userId: number }
312
293
  | { readonly kind: 'channel'; readonly guildId: string; readonly channelId: string };
313
294
 
314
- export function resolveIcqqConfig(config: IcqqAdapterConfig = {}): ResolvedIcqqConfig {
315
- const entry = config.endpoints?.find((item) => item.context === 'icqq');
316
- const id = pickCredential(config.id, entry?.id, process.env.ICQQ_ACCOUNT);
295
+ export function resolveIcqqConfig(config: IcqqEndpointConfig): ResolvedIcqqConfig {
296
+ const id = typeof config.id === 'string' ? config.id.trim() : '';
317
297
  if (!/^\d+$/.test(id)) {
318
- throw new TypeError(
319
- 'ICQQ adapter requires numeric id (QQ uin) via plugins.<key>.id or ICQQ_ACCOUNT',
320
- );
298
+ throw new TypeError('ICQQ endpoint requires a numeric id (QQ uin)');
321
299
  }
322
- const autoReconnect = config.autoReconnect ?? entry?.autoReconnect ?? true;
323
- const outboundMedia = config.outboundMedia ?? entry?.outboundMedia;
324
- const password = config.password ?? entry?.password;
325
- const platform = config.platform ?? entry?.platform ?? 2;
326
- const ver = config.ver ?? entry?.ver ?? '9.1.70';
327
- const dataDir = config.dataDir ?? entry?.dataDir ?? `data/icqq/${id}`;
328
- const signApiAddr = config.signApiAddr ?? entry?.signApiAddr;
329
- const ignoreSelf = config.ignoreSelf ?? entry?.ignoreSelf ?? true;
330
- const resend = config.resend ?? entry?.resend;
331
- const cacheGroupMember = config.cacheGroupMember ?? entry?.cacheGroupMember ?? true;
332
- const autoServer = config.autoServer ?? entry?.autoServer ?? true;
333
- const qqnt = config.qqnt ?? entry?.qqnt;
334
- const ntLogin = config.ntLogin ?? entry?.ntLogin;
300
+ const autoReconnect = config.autoReconnect ?? true;
301
+ const outboundMedia = config.outboundMedia;
302
+ const password = config.password;
303
+ const platform = config.platform ?? 2;
304
+ const ver = config.ver ?? '9.1.70';
305
+ const dataDir = config.dataDir ?? `data/icqq/${id}`;
306
+ const signApiAddr = config.signApiAddr;
307
+ const ignoreSelf = config.ignoreSelf ?? true;
308
+ const resend = config.resend;
309
+ const cacheGroupMember = config.cacheGroupMember ?? true;
310
+ const autoServer = config.autoServer ?? true;
311
+ const qqnt = config.qqnt;
312
+ const ntLogin = config.ntLogin;
335
313
  return {
336
314
  context: 'icqq',
337
315
  id,
@@ -411,6 +389,7 @@ const ICQQ_STANDALONE_ELEMENTS = new Set([
411
389
  'video',
412
390
  'file',
413
391
  'json',
392
+ 'share',
414
393
  'long_msg',
415
394
  ] as const);
416
395
 
@@ -497,7 +476,7 @@ export function formatOutboundBody(payload: unknown): Sendable {
497
476
  return { type: 'long_msg', resid };
498
477
  }
499
478
  case 'share':
500
- return formatMusicShareJson(item.data);
479
+ return formatShare(item.data);
501
480
  default: {
502
481
  const text = item.data?.text;
503
482
  if (typeof text === 'string' && text) return text;
@@ -528,48 +507,45 @@ function isWireSegment(value: unknown): value is IcqqWireSegment {
528
507
  && typeof (value as { type?: unknown }).type === 'string';
529
508
  }
530
509
 
531
- function formatMusicShareJson(data: Record<string, unknown> | undefined): MessageElem {
510
+ function formatShare(data: Record<string, unknown> | undefined): ShareElem {
532
511
  if (!data) throw new TypeError('ICQQ share segment requires data');
533
512
  const config = data.config as {
534
513
  appid?: number;
535
514
  package?: string;
536
- icon?: string;
537
515
  sign?: string;
538
516
  } | undefined;
539
- const title = String(data.title ?? '');
540
- const desc = String(data.artist ?? '');
541
- const jumpUrl = String(data.url ?? '');
542
- const musicUrl = String(data.audio ?? '');
543
- const preview = String(data.image ?? '');
544
- const tag = config?.appid === 100497308 ? 'QQ音乐'
545
- : config?.appid === 100495085 ? '网易云音乐'
546
- : config?.appid === 100243533 ? '酷我音乐'
547
- : config?.appid === 205141 ? '酷狗音乐'
548
- : '音乐';
549
- const json = {
550
- app: 'com.tencent.structmsg',
551
- view: 'music',
552
- ver: '0.0.0.1',
553
- desc: 'music',
554
- prompt: `[分享]${title}`,
555
- meta: {
556
- music: {
557
- action: '',
558
- android_pkg_name: config?.package ?? '',
559
- app_type: 1,
560
- appid: config?.appid ?? 0,
561
- ctime: 0,
562
- desc,
563
- jumpUrl,
564
- musicUrl,
565
- preview,
566
- sourceMsgId: '0',
567
- source_icon: config?.icon ?? '',
568
- source_url: '',
569
- tag,
570
- title,
571
- },
572
- },
517
+ const title = String(data.title ?? '').trim();
518
+ const url = String(data.url ?? '').trim();
519
+ if (!title) throw new TypeError('ICQQ share segment requires title');
520
+ if (!url) throw new TypeError('ICQQ share segment requires url');
521
+
522
+ const optionalString = (value: unknown): string | undefined => {
523
+ const text = String(value ?? '').trim();
524
+ return text || undefined;
525
+ };
526
+ const appid = Number(config?.appid);
527
+ const appname = optionalString(config?.package);
528
+ const appsign = optionalString(config?.sign);
529
+ const shareConfig = Number.isSafeInteger(appid) && appid > 0
530
+ ? {
531
+ appid,
532
+ ...(appname ? { appname } : {}),
533
+ ...(appsign ? { appsign } : {}),
534
+ }
535
+ : undefined;
536
+ const summary = optionalString(data.artist);
537
+ const content = optionalString(data.content);
538
+ const image = optionalString(data.image);
539
+ const audio = optionalString(data.audio);
540
+
541
+ return {
542
+ type: 'share',
543
+ title,
544
+ url,
545
+ ...(summary ? { summary } : {}),
546
+ ...(content ? { content } : {}),
547
+ ...(image ? { image } : {}),
548
+ ...(audio ? { audio } : {}),
549
+ ...(shareConfig ? { config: shareConfig } : {}),
573
550
  };
574
- return { type: 'json', data: json };
575
551
  }
package/src/types.ts CHANGED
@@ -11,13 +11,6 @@ export interface IcqqSenderInfo {
11
11
  title?: string;
12
12
  }
13
13
 
14
- export interface IcqqEndpointConfig {
15
- context: "icqq";
16
- name: `${number}`;
17
- autoReconnect?: boolean;
18
- outboundMedia?: "file" | "base64";
19
- }
20
-
21
14
  export interface FriendInfo {
22
15
  user_id: number;
23
16
  nickname: string;
@@ -1,3 +0,0 @@
1
- import { icqqEndpointCommands } from '../../../src/icqq-endpoint-commands.js';
2
-
3
- export default icqqEndpointCommands.add;
@@ -1,3 +0,0 @@
1
- import { icqqEndpointCommands } from '../../src/icqq-endpoint-commands.js';
2
-
3
- export default icqqEndpointCommands.list;
@@ -1,3 +0,0 @@
1
- import { icqqEndpointCommands } from '../../../src/icqq-endpoint-commands.js';
2
-
3
- export default icqqEndpointCommands.remove;
@@ -1 +0,0 @@
1
- export declare const icqqEndpointCommands: import("@zhin.js/adapter").EndpointCommands<Readonly<import("@zhin.js/command").CommandDefinition<unknown, unknown, import("@zhin.js/command").CommandMessage, string | undefined>>>;
File without changes