dsh-deepseek-import 0.2.0 → 0.2.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.
Files changed (2) hide show
  1. package/index.js +61 -31
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -3,55 +3,85 @@
3
3
  *
4
4
  * 提供一个模型可调用的工具:把 Edge 扩展导出的 DeepSeek 对话 JSON
5
5
  * 重建为当前工作区里的 DSH 会话。
6
+ *
7
+ * 关于 defineTool:正常情况下由宿主提供 `@deepseek-ai/dsh-tools`。
8
+ * 但该包不在 profile 的 node_modules 里(核心包在 app.asar 内),
9
+ * 所以这里做惰性加载:拿不到就退回一个等价的本地实现,
10
+ * 保证插件不会因为一条 import 就加载失败。
6
11
  */
7
12
 
8
- import { defineTool } from '@deepseek-ai/dsh-tools';
9
-
10
13
  /** Cordis 插件名 */
11
14
  export const name = 'dsh-deepseek-import';
12
15
 
13
16
  /** 需要工具注册表 */
14
17
  export const inject = ['tools'];
15
18
 
19
+ /** 参数 DSL(与 defineTool 接受的形状一致) */
20
+ const PARAMETERS = {
21
+ file: {
22
+ type: 'string',
23
+ description: 'Absolute path to a dsh-deepseek-*.json export. Renamed exports are recognised by their content.',
24
+ },
25
+ workspace: {
26
+ type: 'string',
27
+ description: 'Target workspace directory. Omit to use the calling session working directory.',
28
+ },
29
+ tail: {
30
+ type: 'number',
31
+ description: 'Import only the last N turns of each conversation (recommended for very long chats).',
32
+ },
33
+ fromMatch: {
34
+ type: 'string',
35
+ description: 'Start the branch at the first user message containing this text.',
36
+ },
37
+ keepInterrupted: {
38
+ type: 'boolean',
39
+ description: 'Keep partial interrupted assistant output instead of a placeholder.',
40
+ },
41
+ dryRun: {
42
+ type: 'boolean',
43
+ description: 'Parse and report only; write nothing.',
44
+ },
45
+ };
46
+
47
+ /** 惰性加载 defineTool;宿主没提供时退回本地实现 */
48
+ async function resolveDefineTool() {
49
+ try {
50
+ const mod = await import('@deepseek-ai/dsh-tools');
51
+ if (typeof mod.defineTool === 'function') return mod.defineTool;
52
+ } catch {
53
+ /* 宿主的核心包不在 profile 的 node_modules 里,属正常情况 */
54
+ }
55
+ // 本地最小实现:把参数 DSL 转成 JSON Schema,其余字段原样透传
56
+ return (options) => {
57
+ const properties = {};
58
+ const required = [];
59
+ for (const [key, spec] of Object.entries(options.parameters || {})) {
60
+ properties[key] = { type: spec.type, description: spec.description };
61
+ if (spec.required !== false) required.push(key);
62
+ }
63
+ return {
64
+ ...options,
65
+ parameters: { type: 'object', properties, ...(required.length ? { required } : {}) },
66
+ };
67
+ };
68
+ }
69
+
16
70
  /**
17
71
  * 注册 import_deepseek_chat。
18
- * @param ctx - 工具注册表(以及可选的 session/agent 服务)
72
+ * @param ctx - 工具注册表
19
73
  * @param config - 插件配置(当前未使用)
20
74
  */
21
- export function apply(ctx, config = {}) {
75
+ export async function apply(ctx, config = {}) {
22
76
  void config;
77
+ const defineTool = await resolveDefineTool();
23
78
 
24
79
  ctx.tools.register(
25
80
  defineTool({
26
81
  name: 'import_deepseek_chat',
27
82
  description:
28
- 'Import a DeepSeek web chat export (the JSON produced by the dsh-deepseek-import Edge extension) into DeepSeek Harness as new session(s) in the current workspace. Returns the created session ids and the sidecar paths (thinking/transcript/references). New sessions become visible in the sidebar on the next session-list refresh; if they do not appear, restart DSH.',
29
- parameters: {
30
- file: {
31
- type: 'string',
32
- description: 'Absolute path to a dsh-deepseek-*.json export. Renamed exports are recognised by their content.',
33
- },
34
- workspace: {
35
- type: 'string',
36
- description: 'Target workspace directory. Omit to use the calling session working directory.',
37
- },
38
- tail: {
39
- type: 'number',
40
- description: 'Import only the last N turns of each conversation (recommended for very long chats).',
41
- },
42
- fromMatch: {
43
- type: 'string',
44
- description: 'Start the branch at the first user message containing this text.',
45
- },
46
- keepInterrupted: {
47
- type: 'boolean',
48
- description: 'Keep partial interrupted assistant output instead of a placeholder.',
49
- },
50
- dryRun: {
51
- type: 'boolean',
52
- description: 'Parse and report only; write nothing.',
53
- },
54
- },
83
+ 'Import a DeepSeek web chat export (the JSON produced by the dsh-deepseek-import Edge extension) into DeepSeek Harness as new session(s) in the current workspace. Returns the created session ids and the workspace. New sessions become visible in the sidebar on the next session-list refresh; if they do not appear, restart DSH.',
84
+ parameters: PARAMETERS,
55
85
  output: {
56
86
  schema: {
57
87
  type: 'object',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-deepseek-import",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "DeepSeek web chat → DeepSeek Harness sessions (Edge extension + importer CLI + DSH plugin)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -20,7 +20,7 @@
20
20
  }
21
21
  },
22
22
  "peerDependencies": {
23
- "@deepseek-ai/dsh-tools": "*"
23
+ "@deepseek-ai/dsh-tools": ">=0.0.0-0"
24
24
  },
25
25
  "peerDependenciesMeta": {
26
26
  "@deepseek-ai/dsh-tools": {