dsh-plugin-zotero 0.5.0 → 0.5.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.
@@ -173,6 +173,9 @@ async function handleItems(res, params) {
173
173
  const q = params.get('q') ?? undefined;
174
174
  const tags = params.getAll('tag').map((tag) => tag.trim()).filter((tag) => tag !== '');
175
175
  const tagMode = params.get('tagMode') === 'any' ? 'any' : 'all';
176
+ // 排序:只认按标题,方向缺省正序;不认识的取值一律退回原始顺序。
177
+ const sortDirection = params.get('direction') === 'desc' ? 'desc' : 'asc';
178
+ const sort = params.get('sort') === 'title' ? 'title' : undefined;
176
179
  const limit = clampLimit(params.get('limit'));
177
180
  const offset = parseOffset(params.get('offset'));
178
181
  const result = await zotero.listItems({
@@ -181,6 +184,8 @@ async function handleItems(res, params) {
181
184
  q,
182
185
  tags,
183
186
  tagMode,
187
+ sort,
188
+ direction: sort === undefined ? undefined : sortDirection,
184
189
  limit,
185
190
  offset,
186
191
  });
@@ -188,6 +188,9 @@ export interface ListItemsOptions {
188
188
  /** 标签过滤:AND(默认)逐个 `tag=`,OR 合并成 `tag=A || B`。 */
189
189
  tags?: readonly string[];
190
190
  tagMode?: 'all' | 'any';
191
+ /** 排序字段;缺省用 Zotero 的原始顺序。 */
192
+ sort?: 'title';
193
+ direction?: 'asc' | 'desc';
191
194
  limit: number;
192
195
  offset: number;
193
196
  }
@@ -611,6 +611,13 @@ function appendItemFilters(params, options) {
611
611
  params.append('tag', tag);
612
612
  }
613
613
  }
614
+ /** 把排序写进查询参数(本地 API 支持 `sort=title` + `direction=asc|desc`)。 */
615
+ function appendItemSort(params, options) {
616
+ if (options.sort === undefined)
617
+ return;
618
+ params.set('sort', options.sort);
619
+ params.set('direction', options.direction === 'desc' ? 'desc' : 'asc');
620
+ }
614
621
  /** 范围内的顶层条目端点基址(条目列表与标签用量共用同一套范围规则)。 */
615
622
  function itemListBase(options) {
616
623
  return options.scope === 'publications'
@@ -628,6 +635,7 @@ function itemListQuery(options) {
628
635
  start: String(options.offset),
629
636
  });
630
637
  appendItemFilters(params, options);
638
+ appendItemSort(params, options);
631
639
  return { base: itemListBase(options), params };
632
640
  }
633
641
  /**
@@ -639,6 +647,8 @@ async function listUnfiled(options) {
639
647
  for (let start = 0; start < UNFILED_SCAN_MAX; start += PAGE_SIZE) {
640
648
  const params = new URLSearchParams({ limit: String(PAGE_SIZE), start: String(start) });
641
649
  appendItemFilters(params, options);
650
+ // 排序也交给服务端:筛完再排会与分页对不上(扫描顺序决定筛后结果顺序)。
651
+ appendItemSort(params, options);
642
652
  const { body } = await requestJson(`${libraryBase()}/items/top?${params.toString()}`);
643
653
  if (!Array.isArray(body) || body.length === 0)
644
654
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-plugin-zotero",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Map your Zotero library into DSH: let AI operate Zotero for you and help you read papers. Browse collections and tags in the sidebar, read PDFs with highlights in place, and cite excerpts, annotations, notes or whole items into the chat. The model works from the source text for reviews, comparisons and data extraction, and can also search and organize the library, import papers and attach translations back to items; first use needs the Zotero MCP plugin and the local API enabled.",
5
5
  "keywords": [
6
6
  "dsh",