@deepseek-ai/dsh-web-fetch-http 0.2.2-rc.5 → 0.2.3-alpha.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.
package/README.i18n.yaml CHANGED
@@ -30,8 +30,8 @@
30
30
  en: 4c5618124337446e
31
31
  zh: 45c7378c8b0bba45
32
32
  /deepseek-ai-dsh-web-fetch-http/use-this-package/failures-and-recovery:
33
- en: 34095d9d4231d73a
34
- zh: be0ed903adbb124f
33
+ en: c8cc3ab50ee6de0a
34
+ zh: 52710e3e2f82cd87
35
35
  /deepseek-ai-dsh-web-fetch-http/understand-the-implementation:
36
36
  en: 9842c69ad3636bb3
37
37
  zh: 3cdc3f816cbdd0cb
@@ -39,8 +39,8 @@
39
39
  en: 422128dac5eebdde
40
40
  zh: 25ba5f49b305a056
41
41
  /deepseek-ai-dsh-web-fetch-http/understand-the-implementation/source-map:
42
- en: 1f355ec2726ff61b
43
- zh: 076a0c259c94f22a
42
+ en: 9a60dc44a74f499d
43
+ zh: a96991347a773e54
44
44
  /deepseek-ai-dsh-web-fetch-http/understand-the-implementation/read-path:
45
45
  en: 4836d06bc065477d
46
46
  zh: 5a7ddc805a7c67d8
@@ -48,8 +48,8 @@
48
48
  en: eeaaf0b455673a1c
49
49
  zh: 0874f9f44ff9a220
50
50
  /deepseek-ai-dsh-web-fetch-http/model-experience:
51
- en: 5c488f8d23ce3e90
52
- zh: 3cc8f8dc3ab60b65
51
+ en: 90622667adea8ba3
52
+ zh: 6a38fa2d715fe33a
53
53
  /deepseek-ai-dsh-web-fetch-http/model-experience/kv-cache-effect:
54
54
  en: 40294c1c31b74824
55
55
  zh: d75d48f485447a74
package/README.md CHANGED
@@ -67,7 +67,7 @@ A malformed comma- or whitespace-joined charset declaration containing a UTF-8 l
67
67
 
68
68
  ### Failures and recovery
69
69
 
70
- Failures throw `WebError` with a machine-routable code: `WEB_INVALID_URL`, `WEB_BLOCKED_URL`, `WEB_FETCH_TOO_LARGE`, `WEB_FETCH_TIMEOUT`, `WEB_REDIRECT_BLOCKED`, `WEB_UNSUPPORTED_CONTENT_TYPE`, `WEB_ABORTED`, or `WEB_PROVIDER_ERROR`. `WEB_UNSUPPORTED_CONTENT_TYPE` covers unsupported media types, unsupported charset declarations, and invalid UTF-8 during malformed-declaration recovery. Direct callers can route on the code; the model-facing `web_fetch` tool surfaces the failure text to the model under its own error wrapper.
70
+ Failures throw `WebError` with a machine-routable code: `WEB_INVALID_URL`, `WEB_BLOCKED_URL`, `WEB_FETCH_TOO_LARGE`, `WEB_FETCH_TIMEOUT`, `WEB_REDIRECT_BLOCKED`, `WEB_UNSUPPORTED_CONTENT_TYPE`, `WEB_ABORTED`, a transport failure code, or `WEB_PROVIDER_ERROR`. `WEB_UNSUPPORTED_CONTENT_TYPE` covers unsupported media types, unsupported charset declarations, and invalid UTF-8 during malformed-declaration recovery. A network failure before or during the response is classified by its system error code as `WEB_FETCH_DNS_FAILED`, `WEB_FETCH_CONNECTION_REFUSED`, `WEB_FETCH_CONNECTION_TIMEOUT`, `WEB_FETCH_CERTIFICATE_INVALID`, `WEB_FETCH_CONNECTION_INTERRUPTED`, or `WEB_FETCH_NETWORK_UNREACHABLE`; a missing, unrecognized, or mixed code yields `WEB_FETCH_NETWORK_ERROR`. Its message states the class, the system code when known, and the underlying error, for example `web fetch failed: could not resolve the host name (ENOTFOUND): getaddrinfo ENOTFOUND host`. The detail lists at most four connection attempts, counts the rest, and keeps at most 500 characters. Direct callers can route on the code; the model-facing `web_fetch` tool surfaces the failure text to the model under its own error wrapper.
71
71
 
72
72
  -----
73
73
 
@@ -92,6 +92,7 @@ The package is built on one separation and one layered timeout:
92
92
  |---|---|
93
93
  | [`src/index.ts`](src/index.ts) | Plugin entry: config schema, limit validation, provider registration |
94
94
  | [`src/provider.ts`](src/provider.ts) | The `HttpFetchProvider`: transport, redirect following, capped reads, charset decoding |
95
+ | [`src/transport-failure.ts`](src/transport-failure.ts) | Transport failure classes: system error code to `WEB_FETCH_*` code, summary, and bounded detail |
95
96
  | [`src/policy.ts`](src/policy.ts) | URL validation, same-origin checks, content-type classification, charset parsing |
96
97
 
97
98
  ### Read path
@@ -119,7 +120,7 @@ Read these pages when the package-level contract is not enough. They move from t
119
120
  <a id="model-experience"></a>
120
121
  ## Model Experience
121
122
 
122
- Indirectly, through `dsh-tool-web`, which renders this provider's `maxBodyChars`-bounded decoded text or markdown-shaped HTML under its fetch-result wrapper while redirects, headers, and transport limits remain hidden.
123
+ Indirectly, through `dsh-tool-web`, which renders this provider's `maxBodyChars`-bounded decoded text or markdown-shaped HTML under its fetch-result wrapper while redirects, headers, and transport limits remain hidden. A network failure reaches the model as its classified message.
123
124
 
124
125
  #### KV Cache effect
125
126
 
package/README.zh.md CHANGED
@@ -67,7 +67,7 @@ const page = await ctx.web.fetch({ url: 'https://example.com' })
67
67
 
68
68
  ### 失败与恢复
69
69
 
70
- 失败会抛出 `WebError`,其中包含可供程序路由的错误码:`WEB_INVALID_URL`、`WEB_BLOCKED_URL`、`WEB_FETCH_TOO_LARGE`、`WEB_FETCH_TIMEOUT`、`WEB_REDIRECT_BLOCKED`、`WEB_UNSUPPORTED_CONTENT_TYPE`、`WEB_ABORTED` 或 `WEB_PROVIDER_ERROR`。`WEB_UNSUPPORTED_CONTENT_TYPE` 涵盖不支持的媒体类型、不支持的 charset 声明,以及畸形声明恢复过程中遇到的非法 UTF-8。直接调用方可以按错误码路由;面向模型的 `web_fetch` 工具会在自己的错误包装层内把失败文本呈现给模型。
70
+ 失败会抛出 `WebError`,其中包含可供程序路由的错误码:`WEB_INVALID_URL`、`WEB_BLOCKED_URL`、`WEB_FETCH_TOO_LARGE`、`WEB_FETCH_TIMEOUT`、`WEB_REDIRECT_BLOCKED`、`WEB_UNSUPPORTED_CONTENT_TYPE`、`WEB_ABORTED`、某个传输故障错误码,或 `WEB_PROVIDER_ERROR`。`WEB_UNSUPPORTED_CONTENT_TYPE` 涵盖不支持的媒体类型、不支持的 charset 声明,以及畸形声明恢复过程中遇到的非法 UTF-8。响应之前或响应期间发生的网络故障会按其系统错误码归类为 `WEB_FETCH_DNS_FAILED`、`WEB_FETCH_CONNECTION_REFUSED`、`WEB_FETCH_CONNECTION_TIMEOUT`、`WEB_FETCH_CERTIFICATE_INVALID`、`WEB_FETCH_CONNECTION_INTERRUPTED` 或 `WEB_FETCH_NETWORK_UNREACHABLE`;系统错误码缺失、无法识别或相互混杂时,结果为 `WEB_FETCH_NETWORK_ERROR`。错误消息会写明故障类别、已知时的系统错误码以及底层错误,例如 `web fetch failed: could not resolve the host name (ENOTFOUND): getaddrinfo ENOTFOUND host`。详情最多列出四次连接尝试,其余尝试只计数,且最多保留 500 个字符。直接调用方可以按错误码路由;面向模型的 `web_fetch` 工具会在自己的错误包装层内把失败文本呈现给模型。
71
71
 
72
72
  -----
73
73
 
@@ -92,6 +92,7 @@ const page = await ctx.web.fetch({ url: 'https://example.com' })
92
92
  |---|---|
93
93
  | [`src/index.ts`](src/index.ts) | 插件入口:配置 schema、上限验证、提供方注册 |
94
94
  | [`src/provider.ts`](src/provider.ts) | `HttpFetchProvider`:传输、重定向跟随、有界读取、charset 解码 |
95
+ | [`src/transport-failure.ts`](src/transport-failure.ts) | 传输故障类别:系统错误码到 `WEB_FETCH_*` 错误码的映射、摘要和有界详情 |
95
96
  | [`src/policy.ts`](src/policy.ts) | URL 校验、同源检查、内容类型分类、charset 解析 |
96
97
 
97
98
  ### 读取路径
@@ -119,7 +120,7 @@ const page = await ctx.web.fetch({ url: 'https://example.com' })
119
120
  <a id="model-experience"></a>
120
121
  ## 模型体验
121
122
 
122
- 间接地,通过 `dsh-tool-web`:该工具把本提供方经 `maxBodyChars` 限制的解码文本或由 HTML 转换得到的 markdown 置于抓取结果包装层内,而重定向、标头与传输上限保持隐藏。
123
+ 间接地,通过 `dsh-tool-web`:该工具把本提供方经 `maxBodyChars` 限制的解码文本或由 HTML 转换得到的 markdown 置于抓取结果包装层内,而重定向、标头与传输上限保持隐藏。网络故障会以其分类后的消息呈现给模型。
123
124
 
124
125
  #### KV Cache 影响
125
126
 
package/lib/index.js CHANGED
@@ -1,6 +1,143 @@
1
1
  import z from "@deepseek-ai/schemastery";
2
2
  import { WebError } from "@deepseek-ai/dsh-web";
3
3
  import { deadline, timeoutOf } from "@deepseek-ai/dsh-timeout";
4
+ //#region lib/types/transport-failure.js
5
+ /**
6
+ * Classification of fetch transport failures: maps the system or undici error code found in a
7
+ * rejection's cause chain to a stable `WebError` code and a short model-visible summary, and keeps
8
+ * a bounded technical detail.
9
+ * @module @deepseek-ai/dsh-web-fetch-http/transport-failure
10
+ */
11
+ /** The class a dual-stack connection attempt yields when its address family has no route. */
12
+ const UNREACHABLE = {
13
+ code: "WEB_FETCH_NETWORK_UNREACHABLE",
14
+ summary: "the network or host is unreachable",
15
+ systemCodes: [
16
+ "ENETUNREACH",
17
+ "EHOSTUNREACH",
18
+ "ENETDOWN",
19
+ "EHOSTDOWN"
20
+ ]
21
+ };
22
+ const FAILURE_CLASSES = [
23
+ {
24
+ code: "WEB_FETCH_DNS_FAILED",
25
+ summary: "could not resolve the host name",
26
+ systemCodes: [
27
+ "ENOTFOUND",
28
+ "EAI_AGAIN",
29
+ "EAI_FAIL",
30
+ "EAI_NONAME",
31
+ "EAI_NODATA"
32
+ ]
33
+ },
34
+ {
35
+ code: "WEB_FETCH_CONNECTION_REFUSED",
36
+ summary: "the server refused the connection",
37
+ systemCodes: ["ECONNREFUSED"]
38
+ },
39
+ {
40
+ code: "WEB_FETCH_CONNECTION_TIMEOUT",
41
+ summary: "the connection timed out",
42
+ systemCodes: ["ETIMEDOUT", "UND_ERR_CONNECT_TIMEOUT"]
43
+ },
44
+ {
45
+ code: "WEB_FETCH_CERTIFICATE_INVALID",
46
+ summary: "the server certificate could not be verified",
47
+ systemCodes: [
48
+ "CERT_HAS_EXPIRED",
49
+ "CERT_NOT_YET_VALID",
50
+ "CERT_REVOKED",
51
+ "CERT_UNTRUSTED",
52
+ "CERT_REJECTED",
53
+ "CERT_SIGNATURE_FAILURE",
54
+ "DEPTH_ZERO_SELF_SIGNED_CERT",
55
+ "SELF_SIGNED_CERT_IN_CHAIN",
56
+ "UNABLE_TO_GET_ISSUER_CERT",
57
+ "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
58
+ "UNABLE_TO_VERIFY_LEAF_SIGNATURE",
59
+ "UNABLE_TO_DECRYPT_CERT_SIGNATURE",
60
+ "CERT_CHAIN_TOO_LONG",
61
+ "INVALID_CA",
62
+ "HOSTNAME_MISMATCH",
63
+ "ERR_TLS_CERT_ALTNAME_INVALID"
64
+ ]
65
+ },
66
+ {
67
+ code: "WEB_FETCH_CONNECTION_INTERRUPTED",
68
+ summary: "the connection was interrupted",
69
+ systemCodes: [
70
+ "ECONNRESET",
71
+ "ECONNABORTED",
72
+ "EPIPE",
73
+ "UND_ERR_SOCKET"
74
+ ]
75
+ },
76
+ UNREACHABLE
77
+ ];
78
+ /** Code and summary of a failure whose system code is missing, mixed, or unrecognized. */
79
+ const UNCLASSIFIED = {
80
+ code: "WEB_FETCH_NETWORK_ERROR",
81
+ summary: "the network request failed"
82
+ };
83
+ /** Cause hops followed below a transport rejection; a deeper or cyclic chain is cut there. */
84
+ const MAX_CAUSE_HOPS = 4;
85
+ /** `AggregateError` members named in a transport failure; the rest are counted. */
86
+ const MAX_ATTEMPTS = 4;
87
+ /** Characters of the technical detail kept in the message; the summary is never cut. */
88
+ const MAX_DETAIL_CHARS = 500;
89
+ /**
90
+ * Classify a transport rejection. Undici rejects with a generic `TypeError: fetch failed` whose
91
+ * `cause` holds the system error, such as `getaddrinfo ENOTFOUND host`; a connection attempt across
92
+ * several resolved addresses nests those errors in an `AggregateError`. A failure is classified only
93
+ * when its code, or every attempt's code, belongs to one class; an unreachable attempt beside attempts
94
+ * of one other class, as an IPv6 attempt on an IPv4-only network, takes that other class.
95
+ * @param error - the rejection of the request or body read.
96
+ * @returns the failure's code and model-visible message.
97
+ */
98
+ function classifyTransportFailure(error) {
99
+ const innermost = innermostCause(error);
100
+ const aggregate = innermost instanceof AggregateError && innermost.errors.length > 0;
101
+ const attempts = aggregate ? innermost.errors.map(innermostCause) : [innermost];
102
+ const systemCodes = attempts.map(systemCodeOf);
103
+ const classes = new Set(systemCodes.map((code) => FAILURE_CLASSES.find((entry) => code !== void 0 && entry.systemCodes.includes(code))));
104
+ if (classes.size === 2) classes.delete(UNREACHABLE);
105
+ const [only] = classes;
106
+ const failure = classes.size === 1 && only !== void 0 ? only : UNCLASSIFIED;
107
+ const systemCode = new Set(systemCodes).size === 1 ? systemCodes[0] : void 0;
108
+ const detail = bounded(aggregate ? attemptsDetail(attempts, error) : messageOf(innermost, error));
109
+ return {
110
+ code: failure.code,
111
+ message: `${failure.summary}${systemCode === void 0 ? "" : ` (${systemCode})`}: ${detail}`
112
+ };
113
+ }
114
+ /** Follow `cause` up to the hop cap. */
115
+ function innermostCause(error) {
116
+ let current = error;
117
+ for (let hop = 0; hop < MAX_CAUSE_HOPS && current instanceof Error && current.cause !== void 0; hop++) current = current.cause;
118
+ return current;
119
+ }
120
+ /** The string `code` property Node and undici attach to system errors. */
121
+ function systemCodeOf(error) {
122
+ if (!(error instanceof Error) || !("code" in error)) return void 0;
123
+ return typeof error.code === "string" ? error.code : void 0;
124
+ }
125
+ /** Name at most `MAX_ATTEMPTS` attempts and count the rest. */
126
+ function attemptsDetail(attempts, fallback) {
127
+ const named = attempts.slice(0, MAX_ATTEMPTS).map((attempt) => messageOf(attempt, fallback));
128
+ const rest = attempts.length - named.length;
129
+ return named.join("; ") + (rest > 0 ? `; ${rest} more` : "");
130
+ }
131
+ /** An error's message, or the rejection's text when the message is empty. */
132
+ function messageOf(error, fallback) {
133
+ const message = error instanceof Error ? error.message : String(error);
134
+ return message === "" ? String(fallback) : message;
135
+ }
136
+ /** Cut a detail to `MAX_DETAIL_CHARS`. */
137
+ function bounded(detail) {
138
+ return detail.length > MAX_DETAIL_CHARS ? `${detail.slice(0, MAX_DETAIL_CHARS)}…` : detail;
139
+ }
140
+ //#endregion
4
141
  //#region lib/types/policy.js
5
142
  /**
6
143
  * URL validation, content-type classification, and charset resolution for the
@@ -381,13 +518,14 @@ function resolveRedirect(location, base) {
381
518
  * recovering OUR reason means our timeout fired (`WEB_FETCH_TIMEOUT`); any other
382
519
  * abort — an upstream cancel, or a foreign/outer deadline's timeout under
383
520
  * nesting — is `WEB_ABORTED`; a throw with the signal NOT aborted is a
384
- * transport/network failure (`WEB_PROVIDER_ERROR`).
521
+ * transport failure, classified by {@link classifyTransportFailure}.
385
522
  */
386
523
  function translateAbortOrNetwork(error, signal) {
387
524
  const timeout = timeoutOf(signal, "WEB_FETCH_TIMEOUT");
388
525
  if (timeout !== void 0) return new WebError("web fetch timed out", "WEB_FETCH_TIMEOUT", { cause: timeout });
389
526
  if (signal.aborted) return new WebError("web fetch aborted", "WEB_ABORTED", { cause: error });
390
- return new WebError(`web fetch failed: ${String(error)}`, "WEB_PROVIDER_ERROR", { cause: error });
527
+ const failure = classifyTransportFailure(error);
528
+ return new WebError(`web fetch failed: ${failure.message}`, failure.code, { cause: error });
391
529
  }
392
530
  //#endregion
393
531
  //#region lib/types/index.js
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAgB,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAK3G,oFAAoF;AACpF,MAAM,WAAW,eAAe;IAC9B,uEAAuE;IACvE,gBAAgB,EAAE,MAAM,CAAA;IACxB,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAA;IACpB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAA;IACpB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,+CAA+C;AAC/C,eAAO,MAAM,uBAAuB,SAAS,CAAA;AAE7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B,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;AAC7F,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Classification of fetch transport failures: maps the system or undici error code found in a
3
+ * rejection's cause chain to a stable `WebError` code and a short model-visible summary, and keeps
4
+ * a bounded technical detail.
5
+ * @module @deepseek-ai/dsh-web-fetch-http/transport-failure
6
+ */
7
+ /** A classified transport failure. */
8
+ export interface TransportFailure {
9
+ /** Stable `WebError` code of the failure class. */
10
+ code: string;
11
+ /** Model-visible text: the class summary, the system code when known, and the bounded detail. */
12
+ message: string;
13
+ }
14
+ /**
15
+ * Classify a transport rejection. Undici rejects with a generic `TypeError: fetch failed` whose
16
+ * `cause` holds the system error, such as `getaddrinfo ENOTFOUND host`; a connection attempt across
17
+ * several resolved addresses nests those errors in an `AggregateError`. A failure is classified only
18
+ * when its code, or every attempt's code, belongs to one class; an unreachable attempt beside attempts
19
+ * of one other class, as an IPv6 attempt on an IPv4-only network, takes that other class.
20
+ * @param error - the rejection of the request or body read.
21
+ * @returns the failure's code and model-visible message.
22
+ */
23
+ export declare function classifyTransportFailure(error: unknown): TransportFailure;
24
+ //# sourceMappingURL=transport-failure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport-failure.d.ts","sourceRoot":"","sources":["../../src/transport-failure.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAC/B,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAA;IACZ,iGAAiG;IACjG,OAAO,EAAE,MAAM,CAAA;CAChB;AAuDD;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAYzE"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport-failure.js","sourceRoot":"","sources":["../../src/transport-failure.ts"],"names":[],"mappings":"AAAA;;;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CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAC9D,CAAC;AAED,6EAA6E;AAC7E,SAAS,SAAS,CAAC,KAAc,EAAE,QAAiB;IAClD,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACtE,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;AACpD,CAAC;AAED,0CAA0C;AAC1C,SAAS,OAAO,CAAC,MAAc;IAC7B,OAAO,MAAM,CAAC,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAA;AAC5F,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-web-fetch-http",
3
3
  "description": "Anonymous HTTP(S) fetch provider for the DeepSeek Harness web capability seam (ctx.web)",
4
- "version": "0.2.2-rc.5",
4
+ "version": "0.2.3-alpha.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -32,18 +32,18 @@
32
32
  ],
33
33
  "license": "MIT",
34
34
  "peerDependencies": {
35
- "@deepseek-ai/cordis": "~4.1.0",
36
- "@deepseek-ai/dsh-timeout": "0.2.2-rc.5",
37
- "@deepseek-ai/dsh-web": "0.2.2-rc.5"
35
+ "@deepseek-ai/cordis": "~4.2.0-alpha.1",
36
+ "@deepseek-ai/dsh-timeout": "0.2.3-alpha.2",
37
+ "@deepseek-ai/dsh-web": "0.2.3-alpha.2"
38
38
  },
39
39
  "dependencies": {
40
- "@deepseek-ai/schemastery": "~3.19.0",
41
- "undici": "8.11.2"
40
+ "@deepseek-ai/schemastery": "~3.20.0-alpha.1",
41
+ "undici": "8.12.4"
42
42
  },
43
43
  "devDependencies": {
44
- "@deepseek-ai/cordis": "~4.1.0",
45
- "@deepseek-ai/dsh-timeout": "0.2.2-rc.5",
46
- "@deepseek-ai/dsh-web": "0.2.2-rc.5",
47
- "@deepseek-ai/dsh-http-proxy": "0.2.2-rc.5"
44
+ "@deepseek-ai/cordis": "~4.2.0-alpha.1",
45
+ "@deepseek-ai/dsh-timeout": "0.2.3-alpha.2",
46
+ "@deepseek-ai/dsh-web": "0.2.3-alpha.2",
47
+ "@deepseek-ai/dsh-http-proxy": "0.2.3-alpha.2"
48
48
  }
49
49
  }
package/src/provider.ts CHANGED
@@ -10,6 +10,7 @@ import { WebError } from '@deepseek-ai/dsh-web'
10
10
  import type { WebFetchBody, WebFetchProvider, WebFetchRequest, WebFetchResult } from '@deepseek-ai/dsh-web'
11
11
  import { deadline, timeoutOf } from '@deepseek-ai/dsh-timeout'
12
12
  import type { Response } from 'undici'
13
+ import { classifyTransportFailure } from './transport-failure.ts'
13
14
  import { classifyContentType, decoderForCharset, isSameOrigin, parseCharset, validateFetchUrl } from './policy.ts'
14
15
 
15
16
  /** Resolved provider limits (the plugin's schemastery Config supplies defaults). */
@@ -249,11 +250,12 @@ function resolveRedirect(location: string, base: URL): URL {
249
250
  * recovering OUR reason means our timeout fired (`WEB_FETCH_TIMEOUT`); any other
250
251
  * abort — an upstream cancel, or a foreign/outer deadline's timeout under
251
252
  * nesting — is `WEB_ABORTED`; a throw with the signal NOT aborted is a
252
- * transport/network failure (`WEB_PROVIDER_ERROR`).
253
+ * transport failure, classified by {@link classifyTransportFailure}.
253
254
  */
254
255
  function translateAbortOrNetwork(error: unknown, signal: AbortSignal): WebError {
255
256
  const timeout = timeoutOf(signal, 'WEB_FETCH_TIMEOUT')
256
257
  if (timeout !== undefined) return new WebError('web fetch timed out', 'WEB_FETCH_TIMEOUT', { cause: timeout })
257
258
  if (signal.aborted) return new WebError('web fetch aborted', 'WEB_ABORTED', { cause: error })
258
- return new WebError(`web fetch failed: ${String(error)}`, 'WEB_PROVIDER_ERROR', { cause: error })
259
+ const failure = classifyTransportFailure(error)
260
+ return new WebError(`web fetch failed: ${failure.message}`, failure.code, { cause: error })
259
261
  }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Classification of fetch transport failures: maps the system or undici error code found in a
3
+ * rejection's cause chain to a stable `WebError` code and a short model-visible summary, and keeps
4
+ * a bounded technical detail.
5
+ * @module @deepseek-ai/dsh-web-fetch-http/transport-failure
6
+ */
7
+
8
+ /** A classified transport failure. */
9
+ export interface TransportFailure {
10
+ /** Stable `WebError` code of the failure class. */
11
+ code: string
12
+ /** Model-visible text: the class summary, the system code when known, and the bounded detail. */
13
+ message: string
14
+ }
15
+
16
+ /** One failure class: its `WebError` code, summary, and the system codes it covers. */
17
+ interface FailureClass {
18
+ readonly code: string
19
+ readonly summary: string
20
+ readonly systemCodes: readonly string[]
21
+ }
22
+
23
+ /** The class a dual-stack connection attempt yields when its address family has no route. */
24
+ const UNREACHABLE: FailureClass = {
25
+ code: 'WEB_FETCH_NETWORK_UNREACHABLE',
26
+ summary: 'the network or host is unreachable',
27
+ systemCodes: ['ENETUNREACH', 'EHOSTUNREACH', 'ENETDOWN', 'EHOSTDOWN'],
28
+ }
29
+
30
+ const FAILURE_CLASSES: readonly FailureClass[] = [
31
+ {
32
+ code: 'WEB_FETCH_DNS_FAILED',
33
+ summary: 'could not resolve the host name',
34
+ systemCodes: ['ENOTFOUND', 'EAI_AGAIN', 'EAI_FAIL', 'EAI_NONAME', 'EAI_NODATA'],
35
+ },
36
+ { code: 'WEB_FETCH_CONNECTION_REFUSED', summary: 'the server refused the connection', systemCodes: ['ECONNREFUSED'] },
37
+ { code: 'WEB_FETCH_CONNECTION_TIMEOUT', summary: 'the connection timed out', systemCodes: ['ETIMEDOUT', 'UND_ERR_CONNECT_TIMEOUT'] },
38
+ {
39
+ code: 'WEB_FETCH_CERTIFICATE_INVALID',
40
+ summary: 'the server certificate could not be verified',
41
+ systemCodes: [
42
+ 'CERT_HAS_EXPIRED', 'CERT_NOT_YET_VALID', 'CERT_REVOKED', 'CERT_UNTRUSTED', 'CERT_REJECTED',
43
+ 'CERT_SIGNATURE_FAILURE', 'DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN',
44
+ 'UNABLE_TO_GET_ISSUER_CERT', 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
45
+ 'UNABLE_TO_DECRYPT_CERT_SIGNATURE', 'CERT_CHAIN_TOO_LONG', 'INVALID_CA', 'HOSTNAME_MISMATCH',
46
+ 'ERR_TLS_CERT_ALTNAME_INVALID',
47
+ ],
48
+ },
49
+ {
50
+ code: 'WEB_FETCH_CONNECTION_INTERRUPTED',
51
+ summary: 'the connection was interrupted',
52
+ systemCodes: ['ECONNRESET', 'ECONNABORTED', 'EPIPE', 'UND_ERR_SOCKET'],
53
+ },
54
+ UNREACHABLE,
55
+ ]
56
+
57
+ /** Code and summary of a failure whose system code is missing, mixed, or unrecognized. */
58
+ const UNCLASSIFIED = { code: 'WEB_FETCH_NETWORK_ERROR', summary: 'the network request failed' } as const
59
+
60
+ /** Cause hops followed below a transport rejection; a deeper or cyclic chain is cut there. */
61
+ const MAX_CAUSE_HOPS = 4
62
+
63
+ /** `AggregateError` members named in a transport failure; the rest are counted. */
64
+ const MAX_ATTEMPTS = 4
65
+
66
+ /** Characters of the technical detail kept in the message; the summary is never cut. */
67
+ const MAX_DETAIL_CHARS = 500
68
+
69
+ /**
70
+ * Classify a transport rejection. Undici rejects with a generic `TypeError: fetch failed` whose
71
+ * `cause` holds the system error, such as `getaddrinfo ENOTFOUND host`; a connection attempt across
72
+ * several resolved addresses nests those errors in an `AggregateError`. A failure is classified only
73
+ * when its code, or every attempt's code, belongs to one class; an unreachable attempt beside attempts
74
+ * of one other class, as an IPv6 attempt on an IPv4-only network, takes that other class.
75
+ * @param error - the rejection of the request or body read.
76
+ * @returns the failure's code and model-visible message.
77
+ */
78
+ export function classifyTransportFailure(error: unknown): TransportFailure {
79
+ const innermost = innermostCause(error)
80
+ const aggregate = innermost instanceof AggregateError && innermost.errors.length > 0
81
+ const attempts = aggregate ? innermost.errors.map(innermostCause) : [innermost]
82
+ const systemCodes = attempts.map(systemCodeOf)
83
+ const classes = new Set(systemCodes.map(code => FAILURE_CLASSES.find(entry => code !== undefined && entry.systemCodes.includes(code))))
84
+ if (classes.size === 2) classes.delete(UNREACHABLE)
85
+ const [only] = classes
86
+ const failure = classes.size === 1 && only !== undefined ? only : UNCLASSIFIED
87
+ const systemCode = new Set(systemCodes).size === 1 ? systemCodes[0] : undefined
88
+ const detail = bounded(aggregate ? attemptsDetail(attempts, error) : messageOf(innermost, error))
89
+ return { code: failure.code, message: `${failure.summary}${systemCode === undefined ? '' : ` (${systemCode})`}: ${detail}` }
90
+ }
91
+
92
+ /** Follow `cause` up to the hop cap. */
93
+ function innermostCause(error: unknown): unknown {
94
+ let current = error
95
+ for (let hop = 0; hop < MAX_CAUSE_HOPS && current instanceof Error && current.cause !== undefined; hop++) current = current.cause
96
+ return current
97
+ }
98
+
99
+ /** The string `code` property Node and undici attach to system errors. */
100
+ function systemCodeOf(error: unknown): string | undefined {
101
+ if (!(error instanceof Error) || !('code' in error)) return undefined
102
+ return typeof error.code === 'string' ? error.code : undefined
103
+ }
104
+
105
+ /** Name at most `MAX_ATTEMPTS` attempts and count the rest. */
106
+ function attemptsDetail(attempts: readonly unknown[], fallback: unknown): string {
107
+ const named = attempts.slice(0, MAX_ATTEMPTS).map(attempt => messageOf(attempt, fallback))
108
+ const rest = attempts.length - named.length
109
+ return named.join('; ') + (rest > 0 ? `; ${rest} more` : '')
110
+ }
111
+
112
+ /** An error's message, or the rejection's text when the message is empty. */
113
+ function messageOf(error: unknown, fallback: unknown): string {
114
+ const message = error instanceof Error ? error.message : String(error)
115
+ return message === '' ? String(fallback) : message
116
+ }
117
+
118
+ /** Cut a detail to `MAX_DETAIL_CHARS`. */
119
+ function bounded(detail: string): string {
120
+ return detail.length > MAX_DETAIL_CHARS ? `${detail.slice(0, MAX_DETAIL_CHARS)}…` : detail
121
+ }