dsh-zhihu-search 1.2.1 → 1.2.3

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.
@@ -41,7 +41,11 @@ export function renderSearch(value) {
41
41
  const lines = [`找到 ${String(value.items.length)} 条关于 "${value.query}" 的知乎结果:`, ''];
42
42
  for (const item of value.items) {
43
43
  lines.push(`### [${escapeLinkText(item.title)}](${item.url})`);
44
- lines.push(`**作者**: ${item.author || '匿名'} | **点赞**: ${String(item.voteUpCount)} | **类型**: ${item.contentType}`);
44
+ const meta = [`**作者**: ${item.author || '匿名'}`, `**点赞**: ${String(item.voteUpCount)}`];
45
+ // 类型缺失时整段省略,而不是渲染成空的「类型: 」。
46
+ if (item.contentType !== '')
47
+ meta.push(`**类型**: ${item.contentType}`);
48
+ lines.push(meta.join(' | '));
45
49
  lines.push(`> ${item.snippet}`);
46
50
  lines.push('');
47
51
  }
@@ -40,7 +40,9 @@ function projectItem(item) {
40
40
  snippet: sanitizeSnippet(typeof item.ContentText === 'string' ? item.ContentText : ''),
41
41
  author: sanitizeSnippet(typeof item.AuthorName === 'string' ? item.AuthorName : '', 60),
42
42
  voteUpCount: typeof item.VoteUpCount === 'number' && Number.isFinite(item.VoteUpCount) ? item.VoteUpCount : 0,
43
- contentType: typeof item.ContentType === 'string' && item.ContentType !== '' ? item.ContentType : 'Article',
43
+ // ContentType 缺失时留空,不编造标签:实测第三方网页(如接单平台)就没有这个字段,
44
+ // 兜底成 'Article' 会让模型把广告页当成知乎文章。
45
+ contentType: typeof item.ContentType === 'string' ? item.ContentType : '',
44
46
  };
45
47
  }
46
48
  /**
@@ -42,7 +42,9 @@ function projectItem(item) {
42
42
  snippet: sanitizeSnippet(typeof item.ContentText === 'string' ? item.ContentText : ''),
43
43
  author: sanitizeSnippet(typeof item.AuthorName === 'string' ? item.AuthorName : '', 60),
44
44
  voteUpCount: typeof item.VoteUpCount === 'number' && Number.isFinite(item.VoteUpCount) ? item.VoteUpCount : 0,
45
- contentType: typeof item.ContentType === 'string' && item.ContentType !== '' ? item.ContentType : 'Answer',
45
+ // ContentType 缺失时留空,不编造标签:实测外部网页根本没有这个字段,
46
+ // 兜底成 'Answer' 会让模型把一个陌生网页当成知乎回答。
47
+ contentType: typeof item.ContentType === 'string' ? item.ContentType : '',
46
48
  };
47
49
  }
48
50
  /**
package/lib/types.d.ts CHANGED
@@ -25,19 +25,23 @@ export interface ZhihuApiResponse<T> {
25
25
  Data: T;
26
26
  }
27
27
  /**
28
- * 站内搜索(`GET /api/v1/content/zhihu_search`)的 `Data` 载荷。
28
+ * 搜索端点(`GET /api/v1/content/zhihu_search` 与 `.../global_search`)的 `Data` 载荷。
29
29
  *
30
- * 该接口在官方文档中**只接受 `Query` 与 `Count` 两个请求参数**——
31
- * 没有 SortBy,也没有 Filter。分页/排序过滤属于全网搜索(global_search),见 ARCHITECTURE。
30
+ * ⚠ 官方文档称站内搜索只接受 `Query` 与 `Count`,**实测不成立**:
31
+ * 它同样识别 `SortBy` 与 `Filter`(`Filter` 限 `publish_time`),
32
+ * 只是文档没写。两个端点的 `Filter` 语法互不兼容——
33
+ * 完整偏差见 ARCHITECTURE 的「与知乎官方文档的偏差」。
32
34
  */
33
35
  export interface ZhihuSearchData {
34
36
  /**
35
- * ⚠ 站内搜索当前**固定返回 false**(官方文档原文)。
36
- * 因此它不能当作「还有下一页」使用,也不能据此提示模型翻页;
37
- * 只有全网搜索的 HasMore 才是真实分页标识。
37
+ * ⚠ 站内搜索按官方文档**固定返回 false**;全网搜索在 12 个宽泛查询的实测里**也全部为 false**。
38
+ * 因此两个端点都不能据此翻页——全网搜索根本没有翻页参数(见 ARCHITECTURE 的防错清单)。
38
39
  */
39
40
  HasMore: boolean;
40
- /** 搜索请求标识,排障用,不面向模型。 */
41
+ /**
42
+ * 搜索请求标识,排障用,不面向模型。
43
+ * ⚠ 实测**不是游标**:原样传回不改变结果(试过 SearchHashId / HashId / Cursor / Offset / Page / Start)。
44
+ */
41
45
  SearchHashId?: string;
42
46
  /** 无结果原因;有结果时为空串。 */
43
47
  EmptyReason?: string;
@@ -70,11 +74,12 @@ export interface ZhihuSearchItem {
70
74
  /** 秒级时间戳(发布时间或更新时间)。 */
71
75
  EditTime: number;
72
76
  /**
73
- * ⚠ 类型待确认:官方文档在 zhihu_search 一节标注为 String,
74
- * 在 global_search 一节又按 1/2/3/4 描述。此处暂按原设计保留 number。
75
- * 该字段不进入 Canonical Output,故即便类型不符也不会污染模型上下文。
77
+ * ⚠ 取实测与文档的并集:站内搜索**实测返回字符串**(`"4"`),
78
+ * 官方文档又按 1/2/3/4 描述,全网搜索一侧尚未实测。
79
+ * 该字段不进入 Canonical Output,宽类型不会污染模型上下文;
80
+ * 将来若要读它,先对两个端点各测一次再收窄。
76
81
  */
77
- AuthorityLevel: number;
82
+ AuthorityLevel: string | number;
78
83
  }
79
84
  /**
80
85
  * 知乎直答(OpenAI 兼容)错误结构。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-zhihu-search",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "DSH plugin: Zhihu in-site search, global web search, and Zhida over the official Zhihu Open Platform API — with a native settings card and source-cited results.",
5
5
  "keywords": [
6
6
  "dsh",