@jaco-tech/dsh-web-fetch-crw 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 +21 -0
- package/README.md +93 -0
- package/lib/index.js +138 -0
- package/lib/types/index.d.ts +79 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jaco
|
|
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
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# dsh-web-fetch-crw
|
|
2
|
+
|
|
3
|
+
[](https://github.com/topics/dsh-plugin)
|
|
4
|
+
[](https://github.com/jaco-tech/dsh-web-fetch-crw/actions/workflows/ci.yml)
|
|
5
|
+
|
|
6
|
+
[crw](https://github.com/us/crw) (Firecrawl-compatible) fetch provider plugin for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
|
|
7
|
+
|
|
8
|
+
Registers a `WebFetchProvider` into `ctx.web` so that the existing `web_fetch` model tool retrieves page content through your [crw](https://github.com/us/crw) instance — which converts HTML to clean markdown. No auth, no API key.
|
|
9
|
+
|
|
10
|
+
crw is a self-hosted web scraping and crawling service that implements the [Firecrawl](https://github.com/nicknisi/firecrawl) API. It provides a drop-in replacement for the Firecrawl `/v1/scrape` endpoint.
|
|
11
|
+
|
|
12
|
+
## Status
|
|
13
|
+
|
|
14
|
+
⚠️ **Not yet published to npm.** The CI/CD workflow builds on every push and publishes automatically when a `v*` tag is pushed. Once the first release is cut:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @jaco-tech/dsh-web-fetch-crw
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Configure
|
|
21
|
+
|
|
22
|
+
Add to your DSH profile's `cordis.patch.yml`:
|
|
23
|
+
|
|
24
|
+
```yaml
|
|
25
|
+
- insert:
|
|
26
|
+
- id: web-fetch-crw
|
|
27
|
+
name: '@jaco-tech/dsh-web-fetch-crw'
|
|
28
|
+
config:
|
|
29
|
+
baseURL: 'http://your-crw-instance:3000'
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Optionally pin `ctx.web` to use this provider explicitly:
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
- replace:
|
|
36
|
+
- id: web
|
|
37
|
+
config:
|
|
38
|
+
fetchProvider: crw
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## How it works
|
|
42
|
+
|
|
43
|
+
This is a [Cordis](https://github.com/cordiverse/cordis) plugin that implements the `WebFetchProvider` interface from `@deepseek-ai/dsh-web`:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
export const name = "web-fetch-crw"
|
|
47
|
+
export const inject = ["web"]
|
|
48
|
+
|
|
49
|
+
export function apply(ctx, config) {
|
|
50
|
+
ctx.web.registerFetchProvider({
|
|
51
|
+
id: "crw",
|
|
52
|
+
available() { /* URL.canParse(config.baseURL) */ },
|
|
53
|
+
async fetch(request, signal) {
|
|
54
|
+
// POST /v1/scrape { url, formats: ["markdown"] }
|
|
55
|
+
// maps response to WebFetchResult (body as markdown text)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The existing `@deepseek-ai/dsh-tool-web` consumer calls `ctx.web.fetch()` — your crw instance serves the content automatically.
|
|
62
|
+
|
|
63
|
+
## Provider interface
|
|
64
|
+
|
|
65
|
+
| Method | Behavior |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `available()` | Returns `true` when `baseURL` is a valid URL |
|
|
68
|
+
| `fetch(request, signal?)` | `POST /v1/scrape` with `{ url, formats: ["markdown"] }`. Returns the scraped markdown as `kind: "text"` body (no double-conversion through turndown). |
|
|
69
|
+
|
|
70
|
+
## Upstream
|
|
71
|
+
|
|
72
|
+
This plugin communicates with [crw](https://github.com/us/crw) via its Firecrawl-compatible API (`POST /v1/scrape`). crw is a self-hosted web scraping and crawling service that renders pages (via Lightpanda or Chromium) and produces clean markdown. You need a running crw instance to use this plugin.
|
|
73
|
+
|
|
74
|
+
## Release process
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Tag and push — the CI workflow builds and publishes to npm automatically
|
|
78
|
+
git tag v0.1.0
|
|
79
|
+
git push origin v0.1.0
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Requires the `NPM_TOKEN` secret to be set in the repository.
|
|
83
|
+
|
|
84
|
+
## Development
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm install
|
|
88
|
+
npm run build
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
import { WebError } from "@deepseek-ai/dsh-web";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region provider
|
|
5
|
+
/**
|
|
6
|
+
* Stable id this fetch provider registers under.
|
|
7
|
+
*/
|
|
8
|
+
const CRW_PROVIDER_ID = "crw";
|
|
9
|
+
/**
|
|
10
|
+
* Map a crw scrape response to the seam's normalized `WebFetchResult`.
|
|
11
|
+
* crw returns markdown through `data.markdown` (Firecrawl-compatible API).
|
|
12
|
+
*/
|
|
13
|
+
function mapCrwResponse(url, body) {
|
|
14
|
+
if (!body.success) {
|
|
15
|
+
const message = body.error ?? body.message ?? "crw scrape returned success: false";
|
|
16
|
+
throw new WebError(`crw scrape failed: ${message}`, "WEB_PROVIDER_ERROR");
|
|
17
|
+
}
|
|
18
|
+
const data = body.data ?? {};
|
|
19
|
+
const markdown = data.markdown ?? data.raw ?? "";
|
|
20
|
+
const metadata = data.metadata ?? {};
|
|
21
|
+
const effectiveUrl = metadata.sourceURL ?? url;
|
|
22
|
+
const statusCode = metadata.statusCode ?? 200;
|
|
23
|
+
// crw already returns markdown — send as 'text' to avoid double-conversion
|
|
24
|
+
// through turndown in dsh-tool-web.
|
|
25
|
+
const truncated = data.truncated === true;
|
|
26
|
+
return {
|
|
27
|
+
url: effectiveUrl,
|
|
28
|
+
statusCode,
|
|
29
|
+
body: { kind: "text", content: markdown },
|
|
30
|
+
truncated,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The crw-backed fetch provider. Each call issues a POST to `/v1/scrape`
|
|
35
|
+
* with the target URL and receives markdown content back.
|
|
36
|
+
*
|
|
37
|
+
* crw is a Firecrawl-compatible crawl/scrape service. No auth, no API key.
|
|
38
|
+
*/
|
|
39
|
+
class CrwFetchProvider {
|
|
40
|
+
resolveOptions;
|
|
41
|
+
id = CRW_PROVIDER_ID;
|
|
42
|
+
constructor(resolveOptions) {
|
|
43
|
+
this.resolveOptions = resolveOptions;
|
|
44
|
+
}
|
|
45
|
+
available() {
|
|
46
|
+
const options = this.resolveOptions();
|
|
47
|
+
return URL.canParse(options.baseURL);
|
|
48
|
+
}
|
|
49
|
+
async fetch(request, signal) {
|
|
50
|
+
const options = this.resolveOptions();
|
|
51
|
+
throwIfAborted(signal);
|
|
52
|
+
const endpoint = `${options.baseURL}/v1/scrape`;
|
|
53
|
+
throwIfAborted(signal);
|
|
54
|
+
let response;
|
|
55
|
+
try {
|
|
56
|
+
response = await fetch(endpoint, {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers: {
|
|
59
|
+
"content-type": "application/json",
|
|
60
|
+
accept: "application/json",
|
|
61
|
+
"user-agent": "deepseek-harness/0.0.1",
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({ url: request.url, formats: ["markdown"] }),
|
|
64
|
+
...signal !== void 0 ? { signal } : {},
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (signal?.aborted === true || isAbortError(error))
|
|
69
|
+
throw aborted(signal, error);
|
|
70
|
+
throw new WebError(`crw fetch request failed: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
71
|
+
}
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
let message = `crw API error (HTTP ${response.status})`;
|
|
74
|
+
try {
|
|
75
|
+
const parsed = (await response.json());
|
|
76
|
+
if (parsed.error != null && parsed.error.length > 0)
|
|
77
|
+
message = parsed.error;
|
|
78
|
+
else if (parsed.message != null && parsed.message.length > 0)
|
|
79
|
+
message = parsed.message;
|
|
80
|
+
}
|
|
81
|
+
catch { /* ignore parse failure on error body */ }
|
|
82
|
+
throw new WebError(message, "WEB_PROVIDER_ERROR");
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
return mapCrwResponse(request.url, (await response.json()));
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (signal?.aborted === true || isAbortError(error))
|
|
89
|
+
throw aborted(signal, error);
|
|
90
|
+
if (error instanceof WebError)
|
|
91
|
+
throw error;
|
|
92
|
+
throw new WebError(`crw returned an unprocessable response: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region plugin
|
|
98
|
+
/**
|
|
99
|
+
* Register a crw-backed fetch provider in `ctx.web`. crw is a Firecrawl-
|
|
100
|
+
* compatible crawl/scrape service. No auth, no API key.
|
|
101
|
+
*
|
|
102
|
+
* ## Usage
|
|
103
|
+
*
|
|
104
|
+
* ```yaml
|
|
105
|
+
* # cordis.patch.yml
|
|
106
|
+
* - insert:
|
|
107
|
+
* - id: web-fetch-crw
|
|
108
|
+
* name: '@jaco-tech/dsh-web-fetch-crw'
|
|
109
|
+
* config:
|
|
110
|
+
* baseURL: 'http://your-crw-instance:3000'
|
|
111
|
+
* ```
|
|
112
|
+
* @module @jaco-tech/dsh-web-fetch-crw
|
|
113
|
+
*/
|
|
114
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
115
|
+
const name = "web-fetch-crw";
|
|
116
|
+
/** The web seam this provider registers into. */
|
|
117
|
+
const inject = ["web"];
|
|
118
|
+
const Config = z.object({
|
|
119
|
+
baseURL: z.string().required(),
|
|
120
|
+
});
|
|
121
|
+
function apply(ctx, config) {
|
|
122
|
+
const current = () => config;
|
|
123
|
+
ctx.web.registerFetchProvider(new CrwFetchProvider(() => current()));
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region helpers
|
|
127
|
+
function throwIfAborted(signal) {
|
|
128
|
+
if (signal?.aborted === true)
|
|
129
|
+
throw aborted(signal);
|
|
130
|
+
}
|
|
131
|
+
function aborted(signal, fallback) {
|
|
132
|
+
return new WebError("crw fetch aborted", "WEB_ABORTED", { cause: signal?.aborted === true ? signal.reason : fallback });
|
|
133
|
+
}
|
|
134
|
+
function isAbortError(error) {
|
|
135
|
+
return error instanceof DOMException && error.name === "AbortError";
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { CRW_PROVIDER_ID, CrwFetchProvider, Config, apply, inject, name, mapCrwResponse };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import z from "@deepseek-ai/schemastery";
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { WebFetchProvider, WebFetchRequest, WebFetchResult } from "@deepseek-ai/dsh-web";
|
|
4
|
+
interface CrwScrapeResponse {
|
|
5
|
+
success: boolean;
|
|
6
|
+
data?: {
|
|
7
|
+
markdown?: string;
|
|
8
|
+
raw?: string;
|
|
9
|
+
metadata?: {
|
|
10
|
+
sourceURL?: string;
|
|
11
|
+
statusCode?: number;
|
|
12
|
+
title?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
language?: string;
|
|
15
|
+
};
|
|
16
|
+
truncated?: boolean;
|
|
17
|
+
creditCost?: number;
|
|
18
|
+
};
|
|
19
|
+
error?: string;
|
|
20
|
+
message?: string;
|
|
21
|
+
warning?: string;
|
|
22
|
+
warnings?: string[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Stable id this fetch provider registers under.
|
|
26
|
+
*/
|
|
27
|
+
declare const CRW_PROVIDER_ID = "crw";
|
|
28
|
+
/**
|
|
29
|
+
* Map a crw scrape response to the seam's normalized `WebFetchResult`.
|
|
30
|
+
* crw returns markdown through `data.markdown` (Firecrawl-compatible API).
|
|
31
|
+
*/
|
|
32
|
+
declare function mapCrwResponse(url: string, body: CrwScrapeResponse): WebFetchResult;
|
|
33
|
+
/**
|
|
34
|
+
* The crw-backed fetch provider. Each call issues a POST to `/v1/scrape`
|
|
35
|
+
* with the target URL and receives markdown content back.
|
|
36
|
+
*
|
|
37
|
+
* crw is a Firecrawl-compatible crawl/scrape service. No auth, no API key.
|
|
38
|
+
*/
|
|
39
|
+
declare class CrwFetchProvider implements WebFetchProvider {
|
|
40
|
+
readonly resolveOptions: () => {
|
|
41
|
+
baseURL: string;
|
|
42
|
+
};
|
|
43
|
+
readonly id = "crw";
|
|
44
|
+
constructor(resolveOptions: () => {
|
|
45
|
+
baseURL: string;
|
|
46
|
+
});
|
|
47
|
+
available(): boolean;
|
|
48
|
+
fetch(request: WebFetchRequest, signal?: AbortSignal): Promise<WebFetchResult>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Register a crw-backed fetch provider in `ctx.web`. crw is a Firecrawl-
|
|
52
|
+
* compatible crawl/scrape service. No auth, no API key.
|
|
53
|
+
*
|
|
54
|
+
* ## Usage
|
|
55
|
+
*
|
|
56
|
+
* ```yaml
|
|
57
|
+
* # cordis.patch.yml
|
|
58
|
+
* - insert:
|
|
59
|
+
* - id: web-fetch-crw
|
|
60
|
+
* name: '@jaco-tech/dsh-web-fetch-crw'
|
|
61
|
+
* config:
|
|
62
|
+
* baseURL: 'http://your-crw-instance:3000'
|
|
63
|
+
* ```
|
|
64
|
+
* @module @jaco-tech/dsh-web-fetch-crw
|
|
65
|
+
*/
|
|
66
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
67
|
+
declare const name = "web-fetch-crw";
|
|
68
|
+
/** The web seam this provider registers into. */
|
|
69
|
+
declare const inject: string[];
|
|
70
|
+
/**
|
|
71
|
+
* Plugin configuration. `baseURL` is required (point at your crw instance).
|
|
72
|
+
*/
|
|
73
|
+
interface Config {
|
|
74
|
+
/** Base URL of the crw service (without /v1/scrape suffix). */
|
|
75
|
+
baseURL: string;
|
|
76
|
+
}
|
|
77
|
+
declare const Config: z<Config>;
|
|
78
|
+
declare function apply(ctx: Context, config: Config): void;
|
|
79
|
+
export { CRW_PROVIDER_ID, CrwFetchProvider, Config, apply, inject, name, mapCrwResponse };
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jaco-tech/dsh-web-fetch-crw",
|
|
3
|
+
"description": "crw (Firecrawl-compatible) fetch provider for the DeepSeek Harness web capability seam (ctx.web). No auth, no API key.",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/jaco-tech/dsh-web-fetch-crw.git"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "lib/index.js",
|
|
14
|
+
"types": "lib/types/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./lib/types/index.d.ts",
|
|
18
|
+
"default": "./lib/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib/index.js",
|
|
24
|
+
"lib/types/**/*.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"keywords": [
|
|
28
|
+
"dsh-plugin",
|
|
29
|
+
"deepseek-harness",
|
|
30
|
+
"firecrawl",
|
|
31
|
+
"web-fetch",
|
|
32
|
+
"crawler",
|
|
33
|
+
"cordis-plugin"
|
|
34
|
+
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@deepseek-ai/dsh-web": "^0.1.0-rc.7",
|
|
37
|
+
"@deepseek-ai/cordis": "^4.0.1"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@deepseek-ai/schemastery": "^3.18.1"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@deepseek-ai/dsh-web": "^0.1.0-rc.7",
|
|
44
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
45
|
+
"typescript": "^5.7.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"prepublishOnly": "tsc"
|
|
50
|
+
}
|
|
51
|
+
}
|