w-dispatch-ai 1.0.7 → 1.0.8

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 (51) hide show
  1. package/README.md +27 -1
  2. package/dist/w-dispatch-ai.umd.js +2 -2
  3. package/dist/w-dispatch-ai.umd.js.map +1 -1
  4. package/docs/WDispatchAi.mjs.html +4 -3
  5. package/docs/adapters.mjs.html +2 -2
  6. package/docs/castPintOr.mjs.html +109 -0
  7. package/docs/dfTimeoutMs.mjs.html +2 -2
  8. package/docs/dispatchAi.mjs.html +14 -13
  9. package/docs/dispatchAiFallback.mjs.html +156 -97
  10. package/docs/dispatchAiWkf.mjs.html +2 -2
  11. package/docs/dispatchAntigravity.mjs.html +10 -14
  12. package/docs/dispatchApiOpenaiCompat.mjs.html +50 -64
  13. package/docs/dispatchClaude.mjs.html +8 -13
  14. package/docs/dispatchCodex.mjs.html +8 -13
  15. package/docs/dispatchOpencode.mjs.html +8 -13
  16. package/docs/getCliArgs.mjs.html +2 -2
  17. package/docs/getErrorResult.mjs.html +12 -5
  18. package/docs/getErrorType.mjs.html +171 -0
  19. package/docs/global.html +1275 -88
  20. package/docs/index.html +2 -2
  21. package/docs/resolveProviders.mjs.html +2 -2
  22. package/docs/wkf_callAiWithFallback.mjs.html +14 -10
  23. package/docs/wkf_extractJsonLoose.mjs.html +2 -2
  24. package/docs/wkf_runFanout.mjs.html +8 -8
  25. package/docs/wkf_runFanoutPipeline.mjs.html +14 -18
  26. package/docs/wkf_runRolePipeline.mjs.html +5 -4
  27. package/package.json +1 -1
  28. package/src/WDispatchAi.mjs +2 -1
  29. package/src/castPintOr.mjs +37 -0
  30. package/src/dispatchAi.mjs +12 -11
  31. package/src/dispatchAiFallback.mjs +154 -95
  32. package/src/dispatchAntigravity.mjs +8 -12
  33. package/src/dispatchApiOpenaiCompat.mjs +48 -62
  34. package/src/dispatchClaude.mjs +6 -11
  35. package/src/dispatchCodex.mjs +6 -11
  36. package/src/dispatchOpencode.mjs +6 -11
  37. package/src/getErrorResult.mjs +10 -3
  38. package/src/getErrorType.mjs +99 -0
  39. package/src/wkf/callAiWithFallback.mjs +12 -8
  40. package/src/wkf/runFanout.mjs +6 -6
  41. package/src/wkf/runFanoutPipeline.mjs +12 -16
  42. package/src/wkf/runRolePipeline.mjs +3 -2
  43. package/test/tools/fakeServerForApiTest.mjs +4 -1
  44. package/test/unit-callAiWithFallback.test.mjs +24 -0
  45. package/test/unit-castPintOr.test.mjs +28 -0
  46. package/test/unit-dispatchAiFallback.test.mjs +137 -0
  47. package/test/unit-dispatchApiOpenaiCompat.test.mjs +39 -0
  48. package/test/unit-getErrorResult.test.mjs +13 -1
  49. package/test/unit-getErrorType.test.mjs +36 -0
  50. package/test/unit-runFanout.test.mjs +14 -0
  51. package/test/unit-runRolePipeline.test.mjs +12 -0
@@ -0,0 +1,171 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>getErrorType.mjs - Documentation</title>
7
+
8
+
9
+ <script src="scripts/prettify/prettify.js"></script>
10
+ <script src="scripts/prettify/lang-css.js"></script>
11
+ <!--[if lt IE 9]>
12
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
13
+ <![endif]-->
14
+ <link type="text/css" rel="stylesheet" href="styles/prettify.css">
15
+ <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
16
+ <script src="scripts/nav.js" defer></script>
17
+
18
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
19
+ </head>
20
+ <body>
21
+
22
+ <input type="checkbox" id="nav-trigger" class="nav-trigger" />
23
+ <label for="nav-trigger" class="navicon-button x">
24
+ <div class="navicon"></div>
25
+ </label>
26
+
27
+ <label for="nav-trigger" class="overlay"></label>
28
+
29
+ <nav >
30
+
31
+
32
+ <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WDispatchAi">WDispatchAi</a></li><li><a href="global.html#adapters">adapters</a></li><li><a href="global.html#attachErrorType">attachErrorType</a></li><li><a href="global.html#buildChain">buildChain</a></li><li><a href="global.html#buildValidator">buildValidator</a></li><li><a href="global.html#callAiWithFallback">callAiWithFallback</a></li><li><a href="global.html#callOnce">callOnce</a></li><li><a href="global.html#castPintOr">castPintOr</a></li><li><a href="global.html#defaultIntegratePrompt">defaultIntegratePrompt</a></li><li><a href="global.html#dfTimeoutMs">dfTimeoutMs</a></li><li><a href="global.html#dispatchAi">dispatchAi</a></li><li><a href="global.html#dispatchAiFallback">dispatchAiFallback</a></li><li><a href="global.html#dispatchAiWkf">dispatchAiWkf</a></li><li><a href="global.html#dispatchAntigravity">dispatchAntigravity</a></li><li><a href="global.html#dispatchApiOpenaiCompat">dispatchApiOpenaiCompat</a></li><li><a href="global.html#dispatchClaude">dispatchClaude</a></li><li><a href="global.html#dispatchCodex">dispatchCodex</a></li><li><a href="global.html#dispatchOpencode">dispatchOpencode</a></li><li><a href="global.html#extractJsonLoose">extractJsonLoose</a></li><li><a href="global.html#getCliArgs">getCliArgs</a></li><li><a href="global.html#getErrorResult">getErrorResult</a></li><li><a href="global.html#getErrorType">getErrorType</a></li><li><a href="global.html#initState">initState</a></li><li><a href="global.html#isKeyIndependentFail">isKeyIndependentFail</a></li><li><a href="global.html#reorderByCooling">reorderByCooling</a></li><li><a href="global.html#resolveProviders">resolveProviders</a></li><li><a href="global.html#runFanout">runFanout</a></li><li><a href="global.html#runFanoutPipeline">runFanoutPipeline</a></li><li><a href="global.html#runRolePipeline">runRolePipeline</a></li></ul>
33
+
34
+ </nav>
35
+
36
+ <div id="main">
37
+
38
+ <h1 class="page-title">getErrorType.mjs</h1>
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ <section>
47
+ <article>
48
+ <pre class="prettyprint source linenums"><code>import get from 'lodash-es/get.js'
49
+ import isestr from 'wsemi/src/isestr.mjs'
50
+
51
+
52
+ // getErrorType.mjs — 由失敗結果推導機器可讀之errorType
53
+ //
54
+ // 【為何需要】失敗分類原本只能靠error字串前綴(TIMEOUT/ENOENT/OUTPUT_VALIDATION_FAILED...)
55
+ // 比對, 呼叫端各自重寫字串規則既脆弱又易漂移。errorType提供穩定的機器可讀分類,
56
+ // error字串保留不動(人讀), 兩者並存。
57
+ //
58
+ // 【只判機械可判者, 不猜測】本函數僅涵蓋「由error字樣/結構即可100%確定」的類別,
59
+ // 與dispatchAiFallback之isKeyIndependentFail同一組機械判準; 各家CLI的其餘失敗
60
+ // (額度上限/金鑰無效/服務端錯誤等, 字樣各家不同且隨版本漂移)一律歸'exec',
61
+ // 不維護簽章表(與否決金鑰停用清單同一理由, 呼叫端需細分時用coolDetect式注入自判)。
62
+ //
63
+ // 【errorType一覽(僅失敗結果帶此欄, 成功結果無)】
64
+ // 'params' 參數/設定檢核失敗(進入執行前即被擋, getErrorResult預設)
65
+ // 'timeout' 逾時(execCli強殺或API abort, error以TIMEOUT開頭)
66
+ // 'spawn' 子進程無法啟動(執行檔不存在ENOENT/命令列過長ENAMETOOLONG)
67
+ // 'validation' stdout未過validate(OUTPUT_VALIDATION_FAILED)
68
+ // 'exec' CLI非零離開碼之一般執行失敗(未能再機械細分)
69
+ // 'http' HTTP非2xx(code為狀態碼, 僅api類)
70
+ // 'fetch' 網路層錯誤(DNS/連線拒絕, 僅api類)
71
+ // 'tool-unsupported' 模型回tool_calls而本轉接器不支援工具(僅api類)
72
+ // 'invalid-response' 回應缺choices[0].message.content(僅api類)
73
+ // 'aborted' shouldStop中止(僅dispatchAiFallback)
74
+ // 'budget' 時間預算用盡(僅dispatchAiFallback)
75
+
76
+
77
+ /**
78
+ * 由失敗結果物件推導機器可讀之errorType(僅機械可判者,其餘歸'exec',不猜測)
79
+ *
80
+ * 判準與dispatchAiFallback之isKeyIndependentFail同組:error以TIMEOUT開頭為'timeout'、
81
+ * 含ENOENT或ENAMETOOLONG為'spawn'、恰為OUTPUT_VALIDATION_FAILED為'validation',
82
+ * 其餘失敗一律'exec'(各家CLI字樣不同且隨版本漂移,不維護簽章表)
83
+ *
84
+ * @param {Object} r 輸入失敗結果物件(取其error欄位判別)
85
+ * @returns {String} 回傳errorType字串
86
+ * @example
87
+ *
88
+ * import getErrorType from './src/getErrorType.mjs'
89
+ *
90
+ * console.log(getErrorType({ error: 'TIMEOUT after 300s' }))
91
+ * // => 'timeout'
92
+ *
93
+ * console.log(getErrorType({ error: 'spawn cli ENOENT' }))
94
+ * // => 'spawn'
95
+ *
96
+ * console.log(getErrorType({ error: 'Exit code 1' }))
97
+ * // => 'exec'
98
+ *
99
+ */
100
+ function getErrorType(r) {
101
+ let error = get(r, 'error', '')
102
+ if (!isestr(error)) {
103
+ return 'exec'
104
+ }
105
+ if (error.indexOf('TIMEOUT') === 0) {
106
+ return 'timeout'
107
+ }
108
+ if (error.includes('ENOENT') || error.includes('ENAMETOOLONG')) {
109
+ return 'spawn'
110
+ }
111
+ if (error === 'OUTPUT_VALIDATION_FAILED') {
112
+ return 'validation'
113
+ }
114
+ return 'exec'
115
+ }
116
+
117
+
118
+ /**
119
+ * 失敗結果補上errorType欄位(已帶有效errorType或成功結果則原樣回傳)
120
+ *
121
+ * @param {Object} r 輸入結果物件
122
+ * @returns {Object} 回傳結果物件,失敗且未帶errorType時追加之
123
+ * @example
124
+ *
125
+ * import { attachErrorType } from './src/getErrorType.mjs'
126
+ *
127
+ * console.log(attachErrorType({ ok: false, error: 'TIMEOUT after 10s' }).errorType)
128
+ * // => 'timeout'
129
+ *
130
+ * console.log(attachErrorType({ ok: true, stdout: 'abc' }).errorType)
131
+ * // => undefined
132
+ *
133
+ */
134
+ function attachErrorType(r) {
135
+ if (get(r, 'ok', false) === true) {
136
+ return r
137
+ }
138
+ if (isestr(get(r, 'errorType', null))) {
139
+ return r
140
+ }
141
+ return { ...r, errorType: getErrorType(r) }
142
+ }
143
+
144
+
145
+ export default getErrorType
146
+ export { attachErrorType }
147
+ </code></pre>
148
+ </article>
149
+ </section>
150
+
151
+
152
+
153
+
154
+
155
+
156
+ </div>
157
+
158
+ <br class="clear">
159
+
160
+ <footer>
161
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Aug 15 2026 08:45:29 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
162
+ </footer>
163
+
164
+ <script>prettyPrint();</script>
165
+ <script src="scripts/polyfill.js"></script>
166
+ <script src="scripts/linenumber.js"></script>
167
+
168
+
169
+
170
+ </body>
171
+ </html>