@sns-parse/core 0.6.0-alpha.2 → 0.6.0-alpha.4

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/lib/registry.d.ts CHANGED
@@ -25,4 +25,13 @@ export declare function loadWorkflowExtensions(anchor?: NodeRequire): WorkflowEx
25
25
  export declare function loadExtensionContributions(anchor?: NodeRequire): ConfigContribution[];
26
26
  /** 兼容旧名(已废弃:请用 loadWorkflowExtensions) */
27
27
  export declare function loadExtensionImplementations(anchor?: NodeRequire): WorkflowExtension[];
28
+ export interface InstalledFragment {
29
+ name: string;
30
+ version: string;
31
+ }
32
+ /**
33
+ * 已安装碎片清单(core + 聚合×2 + 平台 + 扩展,版本剥离 build 段)。
34
+ * 诊断用:CLI/宿主启动时打印版本戳,一眼识别 dlx/缓存环境是否陈旧。
35
+ */
36
+ export declare function installedFragments(anchor?: NodeRequire): InstalledFragment[];
28
37
  export {};
package/lib/registry.js CHANGED
@@ -5,6 +5,7 @@ exports.collectPlatformLinkRules = collectPlatformLinkRules;
5
5
  exports.loadWorkflowExtensions = loadWorkflowExtensions;
6
6
  exports.loadExtensionContributions = loadExtensionContributions;
7
7
  exports.loadExtensionImplementations = loadExtensionImplementations;
8
+ exports.installedFragments = installedFragments;
8
9
  /**
9
10
  * 已安装碎片包(平台 @sns-parse/platform-* / 扩展 @sns-parse/ext-*)的动态发现。
10
11
  *
@@ -99,3 +100,41 @@ function loadExtensionContributions(anchor) {
99
100
  function loadExtensionImplementations(anchor) {
100
101
  return loadWorkflowExtensions(anchor);
101
102
  }
103
+ /**
104
+ * 已安装碎片清单(core + 聚合×2 + 平台 + 扩展,版本剥离 build 段)。
105
+ * 诊断用:CLI/宿主启动时打印版本戳,一眼识别 dlx/缓存环境是否陈旧。
106
+ */
107
+ function installedFragments(anchor) {
108
+ const nodeRequire = req(anchor);
109
+ const readVersion = (name) => {
110
+ try {
111
+ const pkg = nodeRequire(`${name}/package.json`);
112
+ return String(pkg?.version || '').split('+')[0];
113
+ }
114
+ catch {
115
+ // core 自身(core 仓开发/测试环境):core 不是自己的依赖,回退读自身 package.json
116
+ // (registry.ts 位于 src/ 或 lib/,../package.json 即 core 包根)
117
+ if (name === '@sns-parse/core') {
118
+ try {
119
+ const pkg = nodeRequire('../package.json');
120
+ if (String(pkg?.name || '') === '@sns-parse/core')
121
+ return String(pkg?.version || '').split('+')[0];
122
+ }
123
+ catch { /* ignore */ }
124
+ }
125
+ return '';
126
+ }
127
+ };
128
+ const names = [
129
+ '@sns-parse/core', '@sns-parse/platforms', '@sns-parse/extensions',
130
+ ...PLATFORM_TYPES.map(t => `@sns-parse/platform-${t}`),
131
+ ...EXTENSION_SPECS.map(s => `@sns-parse/${s.name}`),
132
+ ];
133
+ const out = [];
134
+ for (const name of names) {
135
+ const v = readVersion(name);
136
+ if (v)
137
+ out.push({ name: name.replace('@sns-parse/', ''), version: v });
138
+ }
139
+ return out;
140
+ }
package/lib/utils/url.js CHANGED
@@ -50,11 +50,16 @@ function extractAllUrlsFromMessage(session, rules) {
50
50
  const cardsContent = [];
51
51
  if (session.elements) {
52
52
  for (const elem of session.elements) {
53
- if (elem.type === 'xml' && elem.data)
54
- cardsContent.push(elem.data);
55
- else if (elem.type === 'json' && elem.data) {
53
+ // Koishi 元素属性在 elem.attrs(onebot json/xml 分享卡:h.json/h.xml → attrs.data)
54
+ const data = elem.attrs?.data ?? elem.data;
55
+ if (typeof data !== 'string' || !data)
56
+ continue;
57
+ if (elem.type === 'xml') {
58
+ cardsContent.push(data);
59
+ }
60
+ else if (elem.type === 'json') {
56
61
  try {
57
- const json = JSON.parse(elem.data);
62
+ const json = JSON.parse(data);
58
63
  const extract = (obj) => {
59
64
  if (!obj || typeof obj !== 'object')
60
65
  return;
@@ -67,7 +72,10 @@ function extractAllUrlsFromMessage(session, rules) {
67
72
  };
68
73
  extract(json);
69
74
  }
70
- catch { }
75
+ catch {
76
+ // 非 JSON 文本仍按原文扫一遍
77
+ cardsContent.push(data);
78
+ }
71
79
  }
72
80
  }
73
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sns-parse/core",
3
- "version": "0.6.0-alpha.2+upstream.1.6.7",
3
+ "version": "0.6.0-alpha.4+upstream.1.6.7",
4
4
  "description": "sns-parse 核心:契约、宿主抽象、配置 DSL 与解析引擎(fetcher/parser/翻译/X 原生解析/合并/GIF/TLS 指纹客户端)",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",