@zhin.js/plugin-music 1.0.25 → 1.1.0

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 (106) hide show
  1. package/README.md +1 -0
  2. package/commands/cookie/delete/[source].js +23 -0
  3. package/commands/cookie/delete/[source].ts +27 -0
  4. package/commands/cookie/get/[source].js +29 -0
  5. package/commands/cookie/get/[source].ts +33 -0
  6. package/commands/cookie/set/[source].js +23 -0
  7. package/commands/cookie/set/[source].ts +27 -0
  8. package/commands/cookie/status.js +25 -0
  9. package/commands/cookie/status.ts +25 -0
  10. package/commands/login/[platform].js +64 -0
  11. package/commands/login/[platform].ts +76 -0
  12. package/commands//347/202/271/346/255/214/[keyword].js +62 -0
  13. package/commands//347/202/271/346/255/214/[keyword].ts +74 -0
  14. package/components/share-music.js +24 -0
  15. package/components/share-music.ts +29 -0
  16. package/lib/config.d.ts +3 -3
  17. package/lib/config.d.ts.map +1 -1
  18. package/lib/config.js +36 -7
  19. package/lib/config.js.map +1 -1
  20. package/lib/credential-store.d.ts +34 -0
  21. package/lib/credential-store.d.ts.map +1 -0
  22. package/lib/credential-store.js +111 -0
  23. package/lib/credential-store.js.map +1 -0
  24. package/lib/index.d.ts +7 -1
  25. package/lib/index.d.ts.map +1 -1
  26. package/lib/index.js +6 -112
  27. package/lib/index.js.map +1 -1
  28. package/lib/login/index.d.ts +20 -0
  29. package/lib/login/index.d.ts.map +1 -0
  30. package/lib/login/index.js +100 -0
  31. package/lib/login/index.js.map +1 -0
  32. package/lib/login/netease.d.ts +6 -0
  33. package/lib/login/netease.d.ts.map +1 -0
  34. package/lib/login/netease.js +58 -0
  35. package/lib/login/netease.js.map +1 -0
  36. package/lib/login/qq.d.ts +7 -0
  37. package/lib/login/qq.d.ts.map +1 -0
  38. package/lib/login/qq.js +139 -0
  39. package/lib/login/qq.js.map +1 -0
  40. package/lib/login/types.d.ts +19 -0
  41. package/lib/login/types.d.ts.map +1 -0
  42. package/lib/login/types.js +11 -0
  43. package/lib/login/types.js.map +1 -0
  44. package/lib/music-lib.d.ts +31 -0
  45. package/lib/music-lib.d.ts.map +1 -0
  46. package/lib/music-lib.js +59 -0
  47. package/lib/music-lib.js.map +1 -0
  48. package/lib/session.d.ts +29 -0
  49. package/lib/session.d.ts.map +1 -0
  50. package/lib/session.js +39 -0
  51. package/lib/session.js.map +1 -0
  52. package/lib/sources/index.d.ts +2 -1
  53. package/lib/sources/index.d.ts.map +1 -1
  54. package/lib/sources/index.js +6 -2
  55. package/lib/sources/index.js.map +1 -1
  56. package/lib/sources/kugou.d.ts +6 -0
  57. package/lib/sources/kugou.d.ts.map +1 -0
  58. package/lib/sources/kugou.js +54 -0
  59. package/lib/sources/kugou.js.map +1 -0
  60. package/lib/sources/kuwo.d.ts +7 -0
  61. package/lib/sources/kuwo.d.ts.map +1 -0
  62. package/lib/sources/kuwo.js +69 -0
  63. package/lib/sources/kuwo.js.map +1 -0
  64. package/lib/sources/netease.d.ts +1 -1
  65. package/lib/sources/netease.d.ts.map +1 -1
  66. package/lib/sources/netease.js +22 -6
  67. package/lib/sources/netease.js.map +1 -1
  68. package/lib/sources/qq.d.ts +1 -14
  69. package/lib/sources/qq.d.ts.map +1 -1
  70. package/lib/sources/qq.js +114 -82
  71. package/lib/sources/qq.js.map +1 -1
  72. package/lib/types.d.ts +4 -24
  73. package/lib/types.d.ts.map +1 -1
  74. package/lib/types.js +0 -1
  75. package/lib/types.js.map +1 -1
  76. package/middlewares/music-selection.js +46 -0
  77. package/middlewares/music-selection.ts +56 -0
  78. package/package.json +62 -13
  79. package/plugin.js +31 -0
  80. package/schema.json +6 -0
  81. package/src/config.ts +54 -30
  82. package/src/credential-store.ts +169 -0
  83. package/src/index.ts +45 -0
  84. package/src/login/index.ts +135 -0
  85. package/src/login/netease.ts +69 -0
  86. package/src/login/qq.ts +154 -0
  87. package/src/login/types.ts +27 -0
  88. package/src/music-lib.ts +70 -0
  89. package/src/session.ts +60 -0
  90. package/src/sources/index.ts +12 -8
  91. package/src/sources/kugou.ts +78 -0
  92. package/src/sources/kuwo.ts +94 -0
  93. package/src/sources/netease.ts +29 -11
  94. package/src/sources/qq.ts +158 -126
  95. package/src/types.ts +6 -28
  96. package/tools/music-search.js +21 -0
  97. package/tools/music-search.ts +27 -0
  98. package/tools/music-share.js +20 -0
  99. package/tools/music-share.ts +24 -0
  100. package/lib/async-jsx.d.ts +0 -19
  101. package/lib/async-jsx.d.ts.map +0 -1
  102. package/lib/async-jsx.js +0 -48
  103. package/lib/async-jsx.js.map +0 -1
  104. package/src/async-jsx.ts +0 -54
  105. package/src/index.tsx +0 -130
  106. /package/{skills/music/SKILL.md → agent/skills/music.md} +0 -0
package/src/index.tsx DELETED
@@ -1,130 +0,0 @@
1
- import { usePlugin, defineComponent, ZhinTool } from "zhin.js";
2
- import { musicServices } from "./sources/index.js";
3
- import { sourceConfigMap } from "./config.js";
4
- import type { MusicSource } from "./types.js";
5
-
6
- const plugin = usePlugin();
7
- const { logger, useContext, addComponent } = plugin;
8
-
9
- // 异步组件:分享音乐
10
- const ShareMusic = defineComponent(async function ShareMusic({ platform, musicId }: { platform: MusicSource, musicId: string }) {
11
- const service = musicServices[platform];
12
- if (!service) return 'unsupported music source';
13
- const { id, source, ...detail } = await service.getDetail(musicId);
14
- return <share {...detail} config={sourceConfigMap[platform]} />
15
- }, 'ShareMusic')
16
- addComponent(ShareMusic)
17
-
18
- // Suspense 组件 - 用于包装异步组件
19
- const Suspense = defineComponent(async function Suspense(
20
- props: { fallback?: string; children?: any },
21
- context
22
- ) {
23
- try {
24
- // 如果 children 是一个 Promise(异步组件),等待它
25
- if (props.children && typeof props.children === 'object' && 'then' in props.children) {
26
- return await props.children;
27
- }
28
- // 否则直接返回
29
- return props.children || '';
30
- } catch (error) {
31
- logger.error('Suspense error:', error);
32
- return props.fallback || '加载失败';
33
- }
34
- }, 'Suspense');
35
-
36
- addComponent(Suspense);
37
-
38
- // ============================================================================
39
- // 点歌工具 (使用 ZhinTool)
40
- // ============================================================================
41
-
42
- const searchMusicTool = new ZhinTool('music_search')
43
- .desc('搜索音乐并返回结果列表')
44
- .tag('music', 'entertainment')
45
- .param('keyword', { type: 'string', description: '搜索关键词' }, true)
46
- .param('source', {
47
- type: 'string',
48
- description: '音乐源: qq, netease(默认两者都搜索)',
49
- enum: ['qq', 'netease']
50
- })
51
- .param('limit', { type: 'number', description: '返回结果数量(默认 5)' })
52
- .execute(async ({ keyword, source, limit = 5 }) => {
53
- const keywordStr = keyword as string;
54
- const limitNum = limit as number;
55
-
56
- // 确定搜索源
57
- const searchSources: MusicSource[] = source
58
- ? [source as MusicSource]
59
- : ['qq', 'netease'];
60
-
61
- logger.info(`AI 搜索音乐: ${keywordStr}, 来源: ${searchSources.join(', ')}`);
62
-
63
- // 并行搜索
64
- const searchPromises = searchSources.map(s =>
65
- musicServices[s].search(keywordStr, limitNum)
66
- );
67
-
68
- const searchResults = await Promise.all(searchPromises);
69
- const allMusic = searchResults.flat().filter(Boolean);
70
-
71
- return {
72
- success: true,
73
- keyword: keywordStr,
74
- results: allMusic.map(m => ({
75
- id: m.id,
76
- title: m.title,
77
- source: m.source,
78
- url: m.url,
79
- })),
80
- total: allMusic.length,
81
- };
82
- })
83
- .platform('icqq'); // 限制为 icqq 平台
84
-
85
- // 分享音乐工具(直接分享指定音乐)
86
- const shareMusicTool = new ZhinTool('music_share')
87
- .desc('分享指定的音乐')
88
- .tag('music', 'entertainment')
89
- .param('id', { type: 'string', description: '音乐 ID' }, true)
90
- .param('source', {
91
- type: 'string',
92
- description: '音乐源: qq 或 netease',
93
- enum: ['qq', 'netease']
94
- }, true)
95
- .platform('icqq')
96
- .execute(async ({ id, source }) => {
97
- const service = musicServices[source as MusicSource];
98
- if (!service) {
99
- return { success: false, error: `不支持的音乐源: ${source}` };
100
- }
101
-
102
- try {
103
- const detail = await service.getDetail(id as string);
104
- return {
105
- success: true,
106
- music: {
107
- id: detail.id,
108
- title: detail.title,
109
- source: detail.source,
110
- url: detail.url,
111
- }
112
- };
113
- } catch (error) {
114
- return { success: false, error: error instanceof Error ? error.message : String(error) };
115
- }
116
- });
117
-
118
- // 注册工具
119
- useContext('tool', (toolService) => {
120
- if (!toolService) return;
121
-
122
- const disposers = [
123
- toolService.addTool(searchMusicTool, 'music'),
124
- toolService.addTool(shareMusicTool, 'music'),
125
- ];
126
-
127
- logger.debug('音乐工具已注册');
128
-
129
- return () => disposers.forEach(d => d());
130
- });