@alexpeng/dsh-custom-plugin 0.4.2 → 0.5.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.
package/lib/index.js CHANGED
@@ -376,14 +376,17 @@ function blockText(block) {
376
376
  switch (block.type) {
377
377
  case "text":
378
378
  case "reasoning": return String(block.text ?? "");
379
- case "image": return "[图片]";
379
+ case "image": return block.offloaded === true ? "[图片(已折叠)]" : "[图片]";
380
+ case "file": return `[文件 ${block.attachment?.name ?? ""}]`;
380
381
  case "tool-call": return `[调用工具 ${block.name ?? ""}]`;
381
- case "tool-result": {
382
- let text = "";
383
- for (const item of block.content ?? []) text += blockText(item);
384
- return `[工具结果] ${text.slice(0, 240)}`;
382
+ case "tool-addition": return `[启用工具 ${block.toolName ?? ""}]`;
383
+ case "tool-removal": return `[移除工具 ${block.toolName ?? ""}]`;
384
+ default: {
385
+ const raw = block;
386
+ if (!Array.isArray(raw.content)) return "";
387
+ const inner = raw.content.map((item) => blockText(item)).join("");
388
+ return raw.toolCallId !== void 0 ? `[工具结果] ${inner.slice(0, 240)}` : inner;
385
389
  }
386
- default: return "";
387
390
  }
388
391
  }
389
392
  /** Flatten a message content array into plain display text. */
@@ -401,6 +404,43 @@ function flagsOf(text) {
401
404
  hasMermaid: text.includes("```mermaid")
402
405
  };
403
406
  }
407
+ /**
408
+ * Searchable text of one event, flattened the same way the export does it.
409
+ * The session-query index is opt-in on current dsh deployments, so the search
410
+ * route falls back to scanning this text over the log it already read.
411
+ */
412
+ function eventSearchText(event) {
413
+ switch (event.type) {
414
+ case "user/message": return messageText(event.data.content);
415
+ case "assistant/message":
416
+ case "system/message":
417
+ case "developer/message": return messageText(event.data.message.content);
418
+ case "tool/call": return `${event.data.name ?? ""} ${event.data.arguments ?? ""}`;
419
+ case "tool/result": return messageText(event.data.message?.content);
420
+ default: return "";
421
+ }
422
+ }
423
+ /** Which conversation role a search hit belongs to, or null when it is not one. */
424
+ function searchKindOf(type) {
425
+ if (type === "user/message") return "user";
426
+ if (type === "assistant/message") return "assistant";
427
+ if (type.startsWith("tool/")) return "tool";
428
+ return null;
429
+ }
430
+ /**
431
+ * Excerpt centered on the match, with the window extended so the whole match
432
+ * fits. The centering already covers ordinary queries (the match starts 1/3 of
433
+ * the window in, so it fits while the query is shorter than the remaining 2/3);
434
+ * the extension only binds for a pasted query longer than that, which would
435
+ * otherwise be cut off and leave a highlighted-but-invisible result row.
436
+ */
437
+ function snippetAround(text, at, needleLength, max) {
438
+ const start = Math.max(0, at - Math.floor(max / 3));
439
+ const end = Math.min(text.length, Math.max(start + max, at + needleLength));
440
+ const lead = start > 0 ? "…" : "";
441
+ const tail = end < text.length ? "…" : "";
442
+ return lead + text.slice(start, end).replace(/\s+/g, " ").trim() + tail;
443
+ }
404
444
  /** Extract one timeline node per direct user message from a session log. */
405
445
  function extractTurns(events) {
406
446
  const items = [];
@@ -482,7 +522,14 @@ async function buildExportRows(snapshot, format, readImage) {
482
522
  text: text.slice(0, 2e3),
483
523
  images: []
484
524
  });
485
- } else if (event.type === "assistant/message") {
525
+ } else if (event.type === "system/message" || event.type === "developer/message") rows.push({
526
+ seq: event.seq,
527
+ time: event.time,
528
+ kind: "context",
529
+ text: messageText(event.data.message.content).slice(0, 2e3),
530
+ images: []
531
+ });
532
+ else if (event.type === "assistant/message") {
486
533
  const message = event.data.message;
487
534
  rows.push({
488
535
  seq: event.seq,
@@ -501,13 +548,13 @@ async function buildExportRows(snapshot, format, readImage) {
501
548
  toolArgs: event.data.arguments ?? ""
502
549
  });
503
550
  } else if (event.type === "tool/result") {
504
- const callId = event.data.message?.source?.callId;
551
+ const callId = event.data.message?.toolCallId ?? event.data.message?.source?.callId;
505
552
  rows.push({
506
553
  seq: event.seq,
507
554
  time: event.time,
508
555
  kind: "tool-result",
509
556
  toolName: (callId !== void 0 ? callNames.get(String(callId)) : void 0) ?? "",
510
- text: messageText(event.data.message.content).slice(0, 3e3)
557
+ text: messageText(event.data.message?.content).slice(0, 3e3)
511
558
  });
512
559
  }
513
560
  }
@@ -1027,13 +1074,14 @@ var CustomPluginHost = class {
1027
1074
  * live/restore paths without that constructor, so fall back to it before
1028
1075
  * surfacing the error. */
1029
1076
  async readSessionLog(sessionId) {
1077
+ const id = sessionId;
1030
1078
  try {
1031
- return await this.sessionQuery.readSession(sessionId);
1079
+ return await this.sessionQuery.readSession(id);
1032
1080
  } catch (error) {
1033
- const engine = this.sessionQuery;
1034
- if (typeof engine.observeSession !== "function") throw error;
1035
- const lease = await engine.observeSession(sessionId, { projectionMode: "none" });
1036
- const events = [...lease.events ?? []];
1081
+ const { observeSession } = this.sessionQuery;
1082
+ if (typeof observeSession !== "function") throw error;
1083
+ const lease = await observeSession.call(this.sessionQuery, id, { projectionMode: "none" });
1084
+ const events = [...lease.events];
1037
1085
  const disposeSymbol = Symbol.dispose;
1038
1086
  if (disposeSymbol !== void 0) {
1039
1087
  const dispose = lease[disposeSymbol];
@@ -1372,33 +1420,52 @@ var CustomPluginHost = class {
1372
1420
  source: "none"
1373
1421
  };
1374
1422
  }
1375
- /** Search one session using DSH's indexed event search and bind hits to a user-turn anchor. */
1423
+ /** Search one session and bind hits to a user-turn anchor.
1424
+ *
1425
+ * DSH's indexed event search is the preferred path, but its shipped web
1426
+ * profile composes `session-query-sqlite` with `openAt: never`, so the index
1427
+ * is absent by default and `searchEvents()` rejects. The full log is read for
1428
+ * the anchor map anyway, so a rejected index degrades to a literal scan of
1429
+ * that log instead of failing the whole feature. */
1376
1430
  async conversationSearch(sessionId, query, kinds) {
1377
1431
  const wanted = new Set(kinds.length > 0 ? kinds : [
1378
1432
  "user",
1379
1433
  "assistant",
1380
1434
  "tool"
1381
1435
  ]);
1436
+ const eventTypes = kinds.length > 0 ? kinds.flatMap((kind) => kind === "user" ? ["user/message"] : kind === "assistant" ? ["assistant/message"] : ["tool/call", "tool/result"]) : [];
1437
+ const request = {
1438
+ sessionId,
1439
+ query,
1440
+ limit: 100,
1441
+ ...eventTypes.length > 0 ? { filters: [{
1442
+ kind: "type",
1443
+ values: eventTypes
1444
+ }] } : {}
1445
+ };
1446
+ const indexRead = Promise.resolve().then(() => this.sessionQuery.searchEvents(request)).then((page) => page, () => null);
1447
+ let snapshot;
1448
+ let page;
1382
1449
  try {
1383
- const eventTypes = kinds.length > 0 ? kinds.flatMap((kind) => kind === "user" ? ["user/message"] : kind === "assistant" ? ["assistant/message"] : ["tool/call", "tool/result"]) : [];
1384
- const [page, snapshot] = await Promise.all([this.sessionQuery.searchEvents({
1385
- sessionId,
1386
- query,
1387
- limit: 100,
1388
- ...eventTypes.length > 0 ? { filters: [{
1389
- kind: "type",
1390
- values: eventTypes
1391
- }] } : {}
1392
- }), this.readSessionLog(sessionId)]);
1393
- const anchors = /* @__PURE__ */ new Map();
1394
- let anchor;
1395
- for (const event of snapshot.events) {
1396
- if (event.type === "user/message") anchor = event.seq;
1397
- if (anchor !== void 0) anchors.set(event.seq, anchor);
1398
- }
1399
- const items = [];
1450
+ const both = await Promise.all([this.readSessionLog(sessionId), indexRead]);
1451
+ snapshot = both[0];
1452
+ page = both[1];
1453
+ } catch (error) {
1454
+ return {
1455
+ ok: false,
1456
+ error: String(error?.message ?? error)
1457
+ };
1458
+ }
1459
+ const anchors = /* @__PURE__ */ new Map();
1460
+ let anchor;
1461
+ for (const event of snapshot.events) {
1462
+ if (event.type === "user/message") anchor = event.seq;
1463
+ if (anchor !== void 0) anchors.set(event.seq, anchor);
1464
+ }
1465
+ const items = [];
1466
+ if (page !== null) {
1400
1467
  for (const hit of page.items) {
1401
- const kind = hit.type === "user/message" ? "user" : hit.type === "assistant/message" ? "assistant" : hit.type.startsWith("tool/") ? "tool" : null;
1468
+ const kind = searchKindOf(hit.type);
1402
1469
  if (kind === null || !wanted.has(kind)) continue;
1403
1470
  const anchorSeq = anchors.get(hit.seq);
1404
1471
  if (anchorSeq === void 0) continue;
@@ -1414,14 +1481,39 @@ var CustomPluginHost = class {
1414
1481
  return {
1415
1482
  ok: true,
1416
1483
  items,
1417
- hasMore: page.nextCursor !== void 0
1418
- };
1419
- } catch (error) {
1420
- return {
1421
- ok: false,
1422
- error: String(error?.message ?? error)
1484
+ hasMore: page.nextCursor !== void 0,
1485
+ source: "index"
1423
1486
  };
1424
1487
  }
1488
+ const needle = query.toLowerCase();
1489
+ let truncated = false;
1490
+ for (const event of snapshot.events) {
1491
+ const kind = searchKindOf(event.type);
1492
+ if (kind === null || !wanted.has(kind)) continue;
1493
+ const anchorSeq = anchors.get(event.seq);
1494
+ if (anchorSeq === void 0) continue;
1495
+ const text = eventSearchText(event);
1496
+ const at = text.toLowerCase().indexOf(needle);
1497
+ if (at < 0) continue;
1498
+ if (items.length >= 100) {
1499
+ truncated = true;
1500
+ break;
1501
+ }
1502
+ items.push({
1503
+ sessionId,
1504
+ seq: event.seq,
1505
+ anchorSeq,
1506
+ kind,
1507
+ time: event.time,
1508
+ snippet: snippetAround(text, at, needle.length, 500)
1509
+ });
1510
+ }
1511
+ return {
1512
+ ok: true,
1513
+ items,
1514
+ hasMore: truncated,
1515
+ source: "scan"
1516
+ };
1425
1517
  }
1426
1518
  async resolveApiKey() {
1427
1519
  return (await this.resolveApiKeyWithSource()).key;
@@ -10,7 +10,6 @@
10
10
  * @module @alexpeng/dsh-custom-plugin/client/custom
11
11
  */
12
12
  import type { SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots';
13
- import type { SessionListState, TurnLocation, WorkspaceListState } from '@deepseek-ai/dsh-client-runtime/client';
14
13
  import type { Context } from '@deepseek-ai/cordis';
15
14
  /** Minimal input-state face the input dock owner provides. */
16
15
  interface InputStateLike {
@@ -20,24 +19,62 @@ interface InputStateLike {
20
19
  interface InputActionsLike {
21
20
  setDraft(text: string, editRange?: unknown): void;
22
21
  }
22
+ /** Minimal workspace row face (official WorkspaceView carries workspaceId). */
23
+ interface WorkspaceRowLike {
24
+ workspaceId: string;
25
+ title?: string;
26
+ path?: string;
27
+ }
28
+ /**
29
+ * The slot-prop data shapes below are declared locally on purpose: the harness
30
+ * controller packages that own them rename and re-shape them across releases,
31
+ * and importing their types would couple this bundle to modules it never loads
32
+ * at runtime. Only the fields actually read are declared.
33
+ */
34
+ /** One Session row of the `useSessions()` list snapshot. */
35
+ interface SessionRowLike {
36
+ readonly id: string;
37
+ readonly displayTitle?: string;
38
+ readonly title?: string;
39
+ readonly running?: boolean;
40
+ }
41
+ /** The `useSessions()` snapshot. `phase` is monotone: `ready` never steps back. */
42
+ interface SessionListLike {
43
+ readonly ids: readonly string[];
44
+ readonly byId: Readonly<Record<string, SessionRowLike>>;
45
+ readonly phase: 'pending' | 'ready';
46
+ }
47
+ /** The `useWorkspaces()` snapshot. */
48
+ interface WorkspaceListLike {
49
+ readonly items?: readonly WorkspaceRowLike[];
50
+ readonly state: 'idle' | 'loading' | 'error';
51
+ }
52
+ /** Turn placement the Chat turnTail slot hands to its entries. */
53
+ interface TurnLocationLike {
54
+ readonly turn: number;
55
+ readonly status?: 'open' | 'closed' | 'unknown';
56
+ }
57
+ /** Standard prop every `scope: 'session'` slot entry receives. */
58
+ interface SessionScopedProps {
59
+ readonly sessionId?: string | null;
60
+ }
23
61
  /** Palette of 20 muted low-saturation backgrounds (with matching tab colors).
24
62
  * 天青灰 leads the list: it is the install default and renders first among
25
63
  * the palette swatches, right after 无颜色 / 极光. */
26
64
  export declare const PALETTE: Array<[string, string, string]>;
27
65
  /** Public component props (the product slot system injects these). */
28
66
  export interface OverlayProps {
29
- useSessions: SnapshotSelectorHook<SessionListState>;
30
- useWorkspaces: SnapshotSelectorHook<WorkspaceListState>;
67
+ useSessions: SnapshotSelectorHook<SessionListLike>;
68
+ useWorkspaces: SnapshotSelectorHook<WorkspaceListLike>;
31
69
  }
32
- export interface QuoteDockProps {
70
+ export interface QuoteDockProps extends SessionScopedProps {
33
71
  input: InputStateLike;
34
72
  inputActions: InputActionsLike;
35
73
  }
36
- export interface TurnTailProps {
37
- turn: TurnLocation;
74
+ export interface TurnTailProps extends SessionScopedProps {
75
+ turn: TurnLocationLike;
38
76
  seq: number;
39
77
  openFile: (path: string) => void;
40
- matched?: number | null;
41
78
  }
42
79
  /** Install the whole Custom UI into the client context. Returns a disposer that unregisters every slot entry. */
43
80
  export declare function installCustomPlugin(ctx: Context, reportDiag: (message: string) => void): () => void;
@@ -10,7 +10,7 @@
10
10
  * additions.
11
11
  * @module @alexpeng/dsh-custom-plugin/client
12
12
  */
13
- import type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client';
13
+ import type { Context as ClientContext } from '@deepseek-ai/cordis';
14
14
  /**
15
15
  * Required services. Deliberately empty: the mount waits on `slots` inside
16
16
  * `apply` (a child fiber) instead of declaring it here, so this entry can
@@ -24,6 +24,22 @@ export declare function flagsOf(text: string): {
24
24
  hasMathml: boolean;
25
25
  hasMermaid: boolean;
26
26
  };
27
+ /**
28
+ * Searchable text of one event, flattened the same way the export does it.
29
+ * The session-query index is opt-in on current dsh deployments, so the search
30
+ * route falls back to scanning this text over the log it already read.
31
+ */
32
+ export declare function eventSearchText(event: SessionEvent): string;
33
+ /** Which conversation role a search hit belongs to, or null when it is not one. */
34
+ export declare function searchKindOf(type: string): 'user' | 'assistant' | 'tool' | null;
35
+ /**
36
+ * Excerpt centered on the match, with the window extended so the whole match
37
+ * fits. The centering already covers ordinary queries (the match starts 1/3 of
38
+ * the window in, so it fits while the query is shorter than the remaining 2/3);
39
+ * the extension only binds for a pasted query longer than that, which would
40
+ * otherwise be cut off and leave a highlighted-but-invisible result row.
41
+ */
42
+ export declare function snippetAround(text: string, at: number, needleLength: number, max: number): string;
27
43
  /** Extract one timeline node per direct user message from a session log. */
28
44
  export declare function extractTurns(events: readonly SessionEvent[]): TimelineItem[];
29
45
  /** One flattened export row. */
@@ -142,7 +142,13 @@ export declare class CustomPluginHost {
142
142
  }>;
143
143
  /** Resolve the key and its source without returning either value to the browser. */
144
144
  private resolveApiKeyWithSource;
145
- /** Search one session using DSH's indexed event search and bind hits to a user-turn anchor. */
145
+ /** Search one session and bind hits to a user-turn anchor.
146
+ *
147
+ * DSH's indexed event search is the preferred path, but its shipped web
148
+ * profile composes `session-query-sqlite` with `openAt: never`, so the index
149
+ * is absent by default and `searchEvents()` rejects. The full log is read for
150
+ * the anchor map anyway, so a rejected index degrades to a literal scan of
151
+ * that log instead of failing the whole feature. */
146
152
  conversationSearch(sessionId: string, query: string, kinds: readonly ConversationSearchKind[]): Promise<{
147
153
  ok: true;
148
154
  } & ConversationSearchResult | {
@@ -154,6 +154,8 @@ export interface ConversationSearchItem {
154
154
  export interface ConversationSearchResult {
155
155
  items: ConversationSearchItem[];
156
156
  hasMore: boolean;
157
+ /** 'index' when dsh's event index answered, 'scan' when the session log was searched directly. */
158
+ source: 'index' | 'scan';
157
159
  }
158
160
  /** Balance payload returned by the DeepSeek balance endpoint. */
159
161
  export interface BalanceInfo {
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Custom Suite",
4
+ "description": "Personalization, message timeline, project folders, prompt library, export and search, Mermaid, quote reply, and DeepSeek balance / token usage for the DSH Web GUI."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Custom 便利套件",
4
+ "description": "为 DSH Web GUI 提供外观个性化、消息时间线、项目文件夹、提示词库、会话导出与搜索、Mermaid 渲染、引用回复,以及 DeepSeek 余额与 token 用量。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@alexpeng/dsh-custom-plugin",
3
3
  "description": "Custom convenience suite for the dsh web GUI: appearance, timeline, folders, prompts, session export/search, Mermaid, quote reply, usage analytics, local budget, key-free backups, and a Ctrl/Cmd+K command palette; dual-face plugin mounted without dsh source changes.",
4
- "version": "0.4.2",
4
+ "version": "0.5.0",
5
5
  "type": "module",
6
+ "icon": "./icon.svg",
6
7
  "main": "lib/index.js",
7
8
  "types": "lib/types/index.d.ts",
8
9
  "exports": {
@@ -14,6 +15,7 @@
14
15
  "types": "./lib/types/client/index.d.ts",
15
16
  "default": "./lib/client.js"
16
17
  },
18
+ "./locale/*.json": "./locale/*.json",
17
19
  "./package.json": "./package.json"
18
20
  },
19
21
  "dsh": {
@@ -21,10 +23,14 @@
21
23
  "patch": "./cordis.patch.yml"
22
24
  },
23
25
  "client": {
26
+ "platform": "web",
24
27
  "inject": [
25
- "@deepseek-ai/dsh-client-runtime"
26
- ],
27
- "platform": "web"
28
+ "@deepseek-ai/dsh-client-ui-chat",
29
+ "@deepseek-ai/dsh-client-ui-conversation",
30
+ "@deepseek-ai/dsh-client-ui-layout",
31
+ "@deepseek-ai/dsh-client-ui-settings",
32
+ "@deepseek-ai/dsh-client-ui-sidebar"
33
+ ]
28
34
  }
29
35
  },
30
36
  "publishConfig": {
@@ -38,7 +44,8 @@
38
44
  "bugs": "https://github.com/AlexPeng07/dsh-custom-plugin/issues",
39
45
  "homepage": "https://github.com/AlexPeng07/dsh-custom-plugin#readme",
40
46
  "engines": {
41
- "node": ">=22"
47
+ "node": ">=22",
48
+ "dsh": ">=0.1.7-rc.2 <0.2.0"
42
49
  },
43
50
  "scripts": {
44
51
  "build": "tsc -p tsconfig.build.json && tsdown",
@@ -53,23 +60,23 @@
53
60
  "prepublishOnly": "pnpm typecheck && pnpm test"
54
61
  },
55
62
  "peerDependencies": {
56
- "@deepseek-ai/cordis": "^4.0.1",
57
- "@deepseek-ai/dsh-tools": "^0.1.1-rc.1"
63
+ "@deepseek-ai/cordis": "^4.0.4",
64
+ "@deepseek-ai/dsh-tools": "^0.1.7-rc.2"
58
65
  },
59
66
  "dependencies": {
60
67
  "mermaid": "^11.6.0"
61
68
  },
62
69
  "devDependencies": {
63
- "@deepseek-ai/cordis": "^4.0.1",
64
- "@deepseek-ai/dsh-attachment": "^0.1.1-rc.1",
65
- "@deepseek-ai/dsh-client-runtime": "^0.1.1-rc.1",
66
- "@deepseek-ai/dsh-client-ui-slots": "^0.1.1-rc.1",
67
- "@deepseek-ai/dsh-client-ui-theme": "^0.1.1-rc.1",
68
- "@deepseek-ai/dsh-host-webserver": "^0.1.1-rc.1",
69
- "@deepseek-ai/dsh-llm": "^0.1.1-rc.1",
70
- "@deepseek-ai/dsh-session": "^0.1.1-rc.1",
71
- "@deepseek-ai/dsh-session-query": "^0.1.1-rc.1",
72
- "@deepseek-ai/dsh-tools": "^0.1.1-rc.1",
70
+ "@deepseek-ai/cordis": "^4.0.4",
71
+ "@deepseek-ai/dsh-attachment": "^0.1.7-rc.2",
72
+ "@deepseek-ai/dsh-client-store": "^0.1.7-rc.2",
73
+ "@deepseek-ai/dsh-client-ui-slots": "^0.1.7-rc.2",
74
+ "@deepseek-ai/dsh-client-ui-theme": "^0.1.7-rc.2",
75
+ "@deepseek-ai/dsh-host-webserver": "^0.1.7-rc.2",
76
+ "@deepseek-ai/dsh-llm": "^0.1.7-rc.2",
77
+ "@deepseek-ai/dsh-session": "^0.1.7-rc.2",
78
+ "@deepseek-ai/dsh-session-query": "^0.1.7-rc.2",
79
+ "@deepseek-ai/dsh-tools": "^0.1.7-rc.2",
73
80
  "@types/node": "^22.20.0",
74
81
  "@types/react": "~18.3.1",
75
82
  "@types/react-dom": "^18.3.5",
@@ -82,6 +89,8 @@
82
89
  },
83
90
  "files": [
84
91
  "lib",
92
+ "locale/*.json",
93
+ "icon.svg",
85
94
  "cordis.patch.yml",
86
95
  "CHANGELOG.md",
87
96
  "README.md",