dsh-rest-api 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-rest-api contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,136 @@
1
- # Temporary Holding Version
1
+ # dsh-rest-api
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [中文文档](./README.zh.md) · [OpenAPI 3.1 Spec](./openapi.yaml)
4
+
5
+ A standard HTTP REST API plugin for **DeepSeek Harness Web (`dsh web`)**.
6
+
7
+ Invoke DeepSeek Harness agents from any backend service, workflow engine, bot, or script over plain HTTP—while watching every run live inside the `dsh web` UI (tool calls, diffs, deliverables, and interactive takeover/stop).
8
+
9
+ ## Features
10
+
11
+ - **Same-process Web UI Observability**: Mounts directly onto the existing `dsh web` port under `/v1/*`. Every API session is automatically grouped under a dedicated sidebar workspace (default `API Tasks`) with full trajectory, diff, and deliverable inspection.
12
+ - **Three Invocation Modes**:
13
+ - **Synchronous**: `POST /v1/sessions/{session_id}/messages`
14
+ - **Async + Long Polling** (proxy/WAN friendly): `POST /v1/sessions/{session_id}/runs` + `GET /v1/runs/{run_id}?wait=25`
15
+ - **Server-Sent Events (SSE)**: `GET /v1/runs/{run_id}/events` with live tool/message progress and 15s keep-alive heartbeats
16
+ - **Optional Webhooks**: Per-request `webhook_url` or global `defaultWebhookUrl` with exponential-backoff retries
17
+ - **Real Cancellation (Bidirectional)**: `POST /v1/runs/{id}/cancel` and `POST /v1/sessions/{id}/cancel` call `agent.cancel({ kind: 'user' })` to abort active LLM streams and tool subprocesses. Clicking **Stop** inside the Web UI also marks the API run as `cancelled`.
18
+ - **Isolated `headless-task` Preset**: Ships a non-interactive Agent Preset (no blocking `ask_user_question`, `workspace-write` sandbox, `approval: never`, `present` deliverables tool) without affecting your interactive `standard` preset.
19
+ - **Flexible Auth**: `authMode: "loopback"` (default — ideal for local callers or upstream reverse proxies like Pangolin/Nginx/Caddy), `"bearer"` (constant-time `Authorization: Bearer` validation), or `"none"`.
20
+ - **Native Web Settings UI**: Ships a built-in browser configuration panel under **Plugins → Installed → `dsh-rest-api`** in `dsh web` with live health status and hot-reloaded settings (no restart required on save).
21
+
22
+ ## Installation
23
+
24
+ ### Option 1: Install via dsh Plugin Manager (Recommended)
25
+
26
+ Open **Plugins → Add plugin** in `dsh web`, or run:
27
+
28
+ ```bash
29
+ # From npm (once published)
30
+ dsh plugin add dsh-rest-api
31
+
32
+ # Or directly from GitHub
33
+ dsh plugin add https://github.com/Luawig/dsh-rest-api.git
34
+ ```
35
+
36
+ ### Option 2: Add to your `web` profile manually
37
+
38
+ Add `dsh-rest-api` to your `web` profile (`~/.dsh/profiles/web`):
39
+
40
+ ```bash
41
+ cd ~/.dsh/profiles/web
42
+ pnpm add dsh-rest-api
43
+ ```
44
+
45
+ Then add `"dsh-rest-api"` to `dsh.profile.bundles` in `~/.dsh/profiles/web/package.json` and restart `dsh web`.
46
+
47
+ ## Quick Start
48
+
49
+ ### 1. Health Check
50
+
51
+ ```bash
52
+ curl http://127.0.0.1:3080/v1/health
53
+ ```
54
+
55
+ ### 2. Async Submit + Long Polling (Recommended over WAN / Reverse Proxies)
56
+
57
+ ```bash
58
+ # Submit (idempotent on session_id + request_id)
59
+ curl -X POST http://127.0.0.1:3080/v1/sessions/my-session/runs \
60
+ -H "Content-Type: application/json" \
61
+ -d '{"request_id":"req_001","prompt":"Summarize README.md and verify links."}'
62
+
63
+ # Long-poll up to 25 seconds (accepts either run_id or request_id)
64
+ curl "http://127.0.0.1:3080/v1/runs/req_001?wait=25"
65
+ ```
66
+
67
+ ### 3. Live SSE Progress Stream
68
+
69
+ ```bash
70
+ curl -N http://127.0.0.1:3080/v1/runs/req_001/events
71
+ ```
72
+
73
+ ### 4. Real Cancellation
74
+
75
+ ```bash
76
+ # Cancel a specific run (by run_id or request_id)
77
+ curl -X POST "http://127.0.0.1:3080/v1/runs/req_001/cancel?wait=5"
78
+
79
+ # Or cancel the active turn on a session (and clear queued runs)
80
+ curl -X POST "http://127.0.0.1:3080/v1/sessions/my-session/cancel?wait=5"
81
+ ```
82
+
83
+ ### 5. Synchronous Mode
84
+
85
+ ```bash
86
+ curl -X POST http://127.0.0.1:3080/v1/sessions/my-session/messages \
87
+ -H "Content-Type: application/json" \
88
+ -d '{"request_id":"req_002","prompt":"Write hello.txt and present it."}'
89
+ ```
90
+
91
+ ## Configuration
92
+
93
+ Override any setting in `~/.dsh/profiles/web/cordis.patch.yml` (or via the `dsh web` Plugins settings UI):
94
+
95
+ ```yaml
96
+ - id: rest-api
97
+ name: dsh-rest-api
98
+ config:
99
+ routePrefix: /v1
100
+ presetId: headless-task
101
+ provider: "" # empty = inherit dsh default model
102
+ model: "" # empty = inherit dsh default model
103
+ workspaceTitle: API Tasks # sidebar group title
104
+ workspaceDir: "" # empty = ~/.dsh/rest-api-workspace
105
+ authMode: loopback # loopback | bearer | none
106
+ apiKey: "" # used when authMode=bearer
107
+ apiKeyEnv: DSH_REST_API_KEY
108
+ sandboxMode: workspace-write # read-only | workspace-write | danger-full-access
109
+ approvalPolicy: never # ask | never
110
+ allowRequestOverrides: true
111
+ allowCustomWorkspaceDir: false
112
+ defaultWebhookUrl: ""
113
+ webhookTimeoutMs: 10000
114
+ requestTimeoutMs: 960000
115
+ ```
116
+
117
+ ## Exposing Behind Reverse Proxies (Pangolin / Caddy / Nginx)
118
+
119
+ Keep `dsh web` bound to `127.0.0.1:3080` with `authMode: loopback`:
120
+
121
+ - **Pangolin**: Create a Shareable Link on your `dsh web` resource and send `P-Access-Token-Id` + `P-Access-Token` headers from your backend client. Prefer async `/runs` + `?wait=25` or SSE `/events` so reverse-proxy read timeouts never interrupt long tasks.
122
+ - **Direct exposure (`--host 0.0.0.0`)**: Always set `authMode: bearer` with a high-entropy `apiKey` / `DSH_REST_API_KEY`.
123
+
124
+ ## Testing
125
+
126
+ ```bash
127
+ # Offline unit tests (no LLM key or running dsh instance required)
128
+ npm test
129
+
130
+ # Live E2E test against a running dsh web on http://127.0.0.1:3080
131
+ npm run test:e2e
132
+ ```
133
+
134
+ ## License
135
+
136
+ [MIT](./LICENSE)
package/README.zh.md ADDED
@@ -0,0 +1,150 @@
1
+ # dsh-rest-api
2
+
3
+ [English](./README.md) · [OpenAPI 3.1 契约](./openapi.yaml)
4
+
5
+ **DeepSeek Harness Web (`dsh web`)** 的通用 HTTP REST API 插件。
6
+
7
+ 让任意后端服务、工作流编排器(n8n、Dify、Bot、后端微服务、CI 脚本等)通过标准 HTTP 调用 DeepSeek Harness Agent,同时所有任务会话在 `dsh web` 界面中**实时可观测、可查 Diff 与制品、可人工接管或点击停止**。
8
+
9
+ ## 核心特性
10
+
11
+ - **同进程 Web UI 实时观测**:直接挂载在现有 `dsh web` 端口的 `/v1/*` 前缀下;所有 API 会话自动归入侧边栏指定分组(默认 `API Tasks`),不再散落在「未分组」下。
12
+ - **三种调用方式 + Webhook 回调**:
13
+ - **同步模式**:`POST /v1/sessions/{session_id}/messages`
14
+ - **异步提交 + 长轮询(公网 / 反代首选)**:`POST /v1/sessions/{session_id}/runs`(同 `session_id + request_id` 幂等)+ `GET /v1/runs/{id}?wait=25`
15
+ - **SSE 实时进度流**:`GET /v1/runs/{id}/events`(实时推送 `assistant.message`、`tool.call`、`tool.result`、`deliverables.presented` 与终态事件,内置 15s 心跳保活)
16
+ - **Webhook 回调**:支持按请求传 `webhook_url` / `webhook_headers` 或配置全局 `defaultWebhookUrl`,终态自动异步回调(指数退避重试 3 次)
17
+ - **真正停止(双向联动)**:`POST /v1/runs/{id}/cancel` 与 `POST /v1/sessions/{id}/cancel` 直接调用 `agent.cancel({ kind: 'user' })` 中止 LLM 流与运行中的工具子进程;用户在 Web UI 点击「停止」同样会同步将 API Run 标记为 `cancelled`。
18
+ - **隔离的无头预设 `headless-task`**:内置非交互式 Agent Preset(移除会阻塞的 `ask_user_question`,默认 `workspace-write` + `approval: never`,启用 `present` 制品交付工具),完全不干扰日常交互使用的 `standard` 预设。
19
+ - **灵活鉴权模式**:支持 `loopback`(默认,仅放行本机与前置反代)、`bearer`(常量时间校验 `Authorization: Bearer`)与 `none`。
20
+ - **原生 Web 可视化设置页**:内置浏览器侧配置面板,在 `dsh web` 左侧栏 **「插件 → 已安装插件 → dsh-rest-api」** 即可查看实时运行状态并修改全部运行期配置,保存后**立即热生效,无需重启 `dsh web`**。
21
+
22
+ ## 安装
23
+
24
+ ### 方式一:通过 dsh 插件管理安装(推荐)
25
+
26
+ 在 `dsh web` 左侧栏进入 **「插件 → 添加插件」**,或通过命令行安装:
27
+
28
+ ```bash
29
+ # 从 npm 安装(发布后)
30
+ dsh plugin add dsh-rest-api
31
+
32
+ # 或直接从 GitHub 仓库安装
33
+ dsh plugin add https://github.com/Luawig/dsh-rest-api.git
34
+ ```
35
+
36
+ ### 方式二:手动添加到 `web` profile
37
+
38
+ 在你的 `web` profile 目录(`~/.dsh/profiles/web`)安装并加入 bundles:
39
+
40
+ ```bash
41
+ cd ~/.dsh/profiles/web
42
+ pnpm add dsh-rest-api
43
+ ```
44
+
45
+ 在 `~/.dsh/profiles/web/package.json` 的 `dsh.profile.bundles` 中加入 `"dsh-rest-api"`,然后重启 `dsh web`。
46
+
47
+ ## 快速上手
48
+
49
+ ### 1. 健康检查
50
+
51
+ ```bash
52
+ curl http://127.0.0.1:3080/v1/health
53
+ ```
54
+
55
+ ### 2. 异步提交 + 长轮询(公网 / Pangolin 反代推荐)
56
+
57
+ ```bash
58
+ # 提交任务(同一 session_id + request_id 幂等不重复执行)
59
+ curl -X POST http://127.0.0.1:3080/v1/sessions/demo-session/runs \
60
+ -H "Content-Type: application/json" \
61
+ -d '{"request_id":"tsk_001","prompt":"检查当前目录并总结结果"}'
62
+
63
+ # 长轮询等待结果(支持传入 run_id 或 request_id,wait 取值 0..60 秒)
64
+ curl "http://127.0.0.1:3080/v1/runs/tsk_001?wait=25"
65
+ ```
66
+
67
+ ### 3. SSE 实时事件流
68
+
69
+ ```bash
70
+ curl -N http://127.0.0.1:3080/v1/runs/tsk_001/events
71
+ ```
72
+
73
+ ### 4. 真正停止任务
74
+
75
+ ```bash
76
+ # 停止单个 run(可传 run_id 或 request_id)
77
+ curl -X POST "http://127.0.0.1:3080/v1/runs/tsk_001/cancel?wait=5"
78
+
79
+ # 停止指定会话当前正在执行的任务(默认同时清空同会话排队任务)
80
+ curl -X POST "http://127.0.0.1:3080/v1/sessions/demo-session/cancel?wait=5"
81
+ ```
82
+
83
+ ### 5. 同步兼容模式
84
+
85
+ ```bash
86
+ curl -X POST http://127.0.0.1:3080/v1/sessions/demo-session/messages \
87
+ -H "Content-Type: application/json" \
88
+ -d '{"request_id":"tsk_002","prompt":"创建 summary.txt 并调用 present 交付"}'
89
+ ```
90
+
91
+ ### 6. 按请求覆盖分组 / Preset / 模型 / Webhook
92
+
93
+ ```bash
94
+ curl -X POST http://127.0.0.1:3080/v1/sessions/proj-a/runs \
95
+ -H "Content-Type: application/json" \
96
+ -d '{
97
+ "request_id": "tsk_003",
98
+ "prompt": "运行测试并汇报结果",
99
+ "workspace_title": "Project A",
100
+ "preset": "headless-task",
101
+ "webhook_url": "https://example.com/hooks/dsh",
102
+ "webhook_headers": {"X-Webhook-Secret": "my-secret"}
103
+ }'
104
+ ```
105
+
106
+ ## 个性化配置(`~/.dsh/profiles/web/cordis.patch.yml`)
107
+
108
+ ```yaml
109
+ - id: rest-api
110
+ name: dsh-rest-api
111
+ config:
112
+ routePrefix: /v1
113
+ presetId: headless-task
114
+ provider: "" # 留空则继承 dsh 全局默认模型
115
+ model: "" # 留空则继承 dsh 全局默认模型
116
+ workspaceTitle: API Tasks # 侧边栏分组名称
117
+ workspaceDir: "" # 留空则默认 ~/.dsh/rest-api-workspace
118
+ authMode: loopback # loopback | bearer | none
119
+ apiKey: "" # authMode=bearer 时生效
120
+ apiKeyEnv: DSH_REST_API_KEY
121
+ sandboxMode: workspace-write # read-only | workspace-write | danger-full-access
122
+ approvalPolicy: never # ask | never
123
+ allowRequestOverrides: true
124
+ allowCustomWorkspaceDir: false
125
+ defaultWebhookUrl: ""
126
+ webhookTimeoutMs: 10000
127
+ requestTimeoutMs: 960000
128
+ ```
129
+
130
+ ## 配合 Pangolin / 反代暴露到公网
131
+
132
+ 保持 `dsh web` 仅监听 `127.0.0.1:3080` 且 `authMode: loopback`:
133
+
134
+ - 在 Pangolin 中为 `dsh web` 资源创建一个 **Shareable Link**,后端调用方每次请求携带 `P-Access-Token-Id` 与 `P-Access-Token` 请求头即可直接通过 Pangolin 边缘鉴权;
135
+ - 公网链路强烈建议使用**异步提交 `/runs` + 长轮询 `?wait=25`**(或 SSE `/events`),彻底规避反代长连接超时断连;
136
+ - 如直接监听 `0.0.0.0` 暴露内网/公网,请务必启用 `authMode: bearer` 并配置高熵密钥。
137
+
138
+ ## 测试
139
+
140
+ ```bash
141
+ # 离线单元测试(无需真实模型密钥与运行中的 dsh)
142
+ npm test
143
+
144
+ # 端到端集成测试(针对本机运行中的 http://127.0.0.1:3080)
145
+ npm run test:e2e
146
+ ```
147
+
148
+ ## 开源协议
149
+
150
+ [MIT](./LICENSE)
@@ -0,0 +1,103 @@
1
+ # dsh-rest-api bundle patch
2
+ # 1. Registers a general-purpose `headless-task` Agent Preset tailored for
3
+ # non-interactive API automation (isolated prompt, no interactive ask-user
4
+ # blocking, deliverables via `present`, workspace-write sandbox).
5
+ # 2. Mounts the `dsh-rest-api` plugin on the existing dsh web server under `/v1`.
6
+ - insert:
7
+ - id: preset-headless-task
8
+ name: '@deepseek-ai/dsh-agent-preset'
9
+ config:
10
+ id: headless-task
11
+ name: Headless Task
12
+ description: Non-interactive agent preset for REST API tasks (no blocking user-question prompts, workspace-write sandbox, deliverables support).
13
+ order: 90
14
+ plugins:
15
+ - id: persona
16
+ name: '@deepseek-ai/dsh-persona'
17
+ config:
18
+ prefix: |
19
+ You are an autonomous task execution agent invoked programmatically through the DeepSeek Harness REST API.
20
+ Follow these rules strictly:
21
+ 1. Start doing real work immediately (inspect, edit, run commands, verify). Never reply with an empty acknowledgement only.
22
+ 2. Do not attempt to pause for interactive UI dialogs. If essential information is missing and cannot be safely inferred, list the exact clarifying questions in your final response.
23
+ 3. Keep your final response concise, factual, and structured: report outcomes, verification performed, any remaining gaps/risks, and produced deliverables.
24
+ 4. When producing files intended as deliverables for the caller, write them inside the session workspace directory and call the `present` tool to register them.
25
+ 5. Never expose API keys, tokens, credentials, or sensitive host environment variables in your output.
26
+ - id: agent-instructions
27
+ name: '@deepseek-ai/dsh-agent-instructions'
28
+ config:
29
+ maxBytes: 65536
30
+ - id: time-context
31
+ name: '@deepseek-ai/dsh-time-context'
32
+ - id: tool-bash
33
+ name: '@deepseek-ai/dsh-tool-bash'
34
+ disabled: !!js process.platform === 'win32'
35
+ - id: tool-pwsh
36
+ name: '@deepseek-ai/dsh-tool-pwsh'
37
+ disabled: !!js process.platform !== 'win32'
38
+ - id: tool-fs
39
+ name: '@deepseek-ai/dsh-tool-fs'
40
+ config:
41
+ applyPatch: false
42
+ - id: tool-fs-search
43
+ name: '@deepseek-ai/dsh-tool-fs-search'
44
+ config:
45
+ sampleOverCapGlobResults: false
46
+ - id: tool-jobs
47
+ name: '@deepseek-ai/dsh-tool-jobs'
48
+ - id: skill-filesystem
49
+ name: '@deepseek-ai/dsh-skill-filesystem'
50
+ - id: tool-skill
51
+ name: '@deepseek-ai/dsh-tool-skill'
52
+ - id: compaction
53
+ name: cordis:group
54
+ group: true
55
+ isolate:
56
+ compaction: true
57
+ toolResultPruner: true
58
+ config:
59
+ - id: compaction-basic
60
+ name: '@deepseek-ai/dsh-compaction-basic'
61
+ - id: tool-result-pruner
62
+ name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
63
+ config:
64
+ thresholdChars: 8192
65
+ headChars: 4096
66
+ tailChars: 1024
67
+ - id: delegation
68
+ name: cordis:group
69
+ group: true
70
+ isolate:
71
+ workflowEngine: true
72
+ config:
73
+ - id: tool-subagent-control
74
+ name: '@deepseek-ai/dsh-tool-subagent-control'
75
+ - id: tool-subagent
76
+ name: '@deepseek-ai/dsh-tool-subagent'
77
+ config:
78
+ provider: spawn
79
+ toolName: subagent
80
+ modelSelection: true
81
+ modelDiscovery: true
82
+ - id: tool-todo
83
+ name: '@deepseek-ai/dsh-tool-todo'
84
+ config:
85
+ allowParallelInProgress: true
86
+ - id: tool-web
87
+ name: '@deepseek-ai/dsh-tool-web'
88
+ config:
89
+ fetch: true
90
+ searchTimeoutMs: 60000
91
+ - id: present
92
+ name: '@deepseek-ai/dsh-tool-present'
93
+
94
+ - id: rest-api
95
+ name: dsh-rest-api
96
+ config:
97
+ routePrefix: /v1
98
+ presetId: headless-task
99
+ workspaceTitle: API Tasks
100
+ authMode: loopback
101
+ requestTimeoutMs: 960000
102
+ sandboxMode: workspace-write
103
+ approvalPolicy: never
package/icon.svg ADDED
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" fill="none">
2
+ <rect width="128" height="128" rx="28" fill="#0F172A"/>
3
+ <rect x="8" y="8" width="112" height="112" rx="22" stroke="#38BDF8" stroke-opacity="0.35" stroke-width="2"/>
4
+ <path d="M36 44L22 64L36 84" stroke="#38BDF8" stroke-width="8" stroke-linecap="round" stroke-linejoin="round"/>
5
+ <path d="M92 44L106 64L92 84" stroke="#38BDF8" stroke-width="8" stroke-linecap="round" stroke-linejoin="round"/>
6
+ <path d="M52 64H76" stroke="#A78BFA" stroke-width="8" stroke-linecap="round"/>
7
+ <circle cx="48" cy="64" r="6" fill="#34D399"/>
8
+ <circle cx="80" cy="64" r="6" fill="#F472B6"/>
9
+ </svg>