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
package/docs/global.html CHANGED
@@ -29,7 +29,7 @@
29
29
  <nav >
30
30
 
31
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#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#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#isKeyIndependentFail">isKeyIndependentFail</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>
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
33
 
34
34
  </nav>
35
35
 
@@ -140,7 +140,7 @@
140
140
 
141
141
  <dt class="tag-source">Source:</dt>
142
142
  <dd class="tag-source"><ul class="dummy"><li>
143
- <a href="WDispatchAi.mjs.html">WDispatchAi.mjs</a>, <a href="WDispatchAi.mjs.html#line35">line 35</a>
143
+ <a href="WDispatchAi.mjs.html">WDispatchAi.mjs</a>, <a href="WDispatchAi.mjs.html#line36">line 36</a>
144
144
  </li></ul></dd>
145
145
 
146
146
 
@@ -360,6 +360,175 @@ console.log(dfTimeoutMs)
360
360
 
361
361
 
362
362
 
363
+ <h4 class="name" id="attachErrorType"><span class="type-signature"></span>attachErrorType<span class="signature">(r)</span><span class="type-signature"> &rarr; {Object}</span></h4>
364
+
365
+
366
+
367
+
368
+
369
+
370
+ <dl class="details">
371
+
372
+ <dt class="tag-description">Description:</dt>
373
+ <dd class="tag-description"><ul class="dummy"><li><p>失敗結果補上errorType欄位(已帶有效errorType或成功結果則原樣回傳)</p></li></ul></dd>
374
+
375
+
376
+
377
+ <dt class="tag-source">Source:</dt>
378
+ <dd class="tag-source"><ul class="dummy"><li>
379
+ <a href="getErrorType.mjs.html">getErrorType.mjs</a>, <a href="getErrorType.mjs.html#line87">line 87</a>
380
+ </li></ul></dd>
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+ </dl>
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+ <h5 class="h5-examples">Example</h5>
425
+
426
+ <pre class="prettyprint"><code>import { attachErrorType } from './src/getErrorType.mjs'
427
+
428
+ console.log(attachErrorType({ ok: false, error: 'TIMEOUT after 10s' }).errorType)
429
+ // => 'timeout'
430
+
431
+ console.log(attachErrorType({ ok: true, stdout: 'abc' }).errorType)
432
+ // => undefined</code></pre>
433
+
434
+
435
+
436
+
437
+ <h5 class="h5-parameters">Parameters:</h5>
438
+
439
+
440
+ <table class="params">
441
+ <thead>
442
+ <tr>
443
+
444
+ <th>Name</th>
445
+
446
+
447
+ <th>Type</th>
448
+
449
+
450
+
451
+
452
+
453
+ <th class="last">Description</th>
454
+ </tr>
455
+ </thead>
456
+
457
+ <tbody>
458
+
459
+
460
+ <tr>
461
+
462
+ <td class="name"><code>r</code></td>
463
+
464
+
465
+ <td class="type">
466
+
467
+
468
+ <span class="param-type">Object</span>
469
+
470
+
471
+
472
+
473
+ </td>
474
+
475
+
476
+
477
+
478
+
479
+ <td class="description last"><p>輸入結果物件</p></td>
480
+ </tr>
481
+
482
+
483
+ </tbody>
484
+ </table>
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+ <h5 class="h5-returns">Returns:</h5>
502
+
503
+
504
+ <div class="param-desc">
505
+ <p>回傳結果物件,失敗且未帶errorType時追加之</p>
506
+ </div>
507
+
508
+
509
+
510
+ <dl class="param-type">
511
+ <dt>
512
+ Type
513
+ </dt>
514
+ <dd>
515
+
516
+ <span class="param-type">Object</span>
517
+
518
+
519
+
520
+ </dd>
521
+ </dl>
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
363
532
  <h4 class="name" id="buildChain"><span class="type-signature"></span>buildChain<span class="signature">(providers, spec)</span><span class="type-signature"> &rarr; {Object}</span></h4>
364
533
 
365
534
 
@@ -376,7 +545,7 @@ console.log(dfTimeoutMs)
376
545
 
377
546
  <dt class="tag-source">Source:</dt>
378
547
  <dd class="tag-source"><ul class="dummy"><li>
379
- <a href="wkf_callAiWithFallback.mjs.html">wkf/callAiWithFallback.mjs</a>, <a href="wkf_callAiWithFallback.mjs.html#line70">line 70</a>
548
+ <a href="wkf_callAiWithFallback.mjs.html">wkf/callAiWithFallback.mjs</a>, <a href="wkf_callAiWithFallback.mjs.html#line71">line 71</a>
380
549
  </li></ul></dd>
381
550
 
382
551
 
@@ -567,7 +736,7 @@ console.log(buildChain(providers, { use: 'a', fallback: ['b', 'c'] }))
567
736
 
568
737
  <dt class="tag-source">Source:</dt>
569
738
  <dd class="tag-source"><ul class="dummy"><li>
570
- <a href="dispatchApiOpenaiCompat.mjs.html">dispatchApiOpenaiCompat.mjs</a>, <a href="dispatchApiOpenaiCompat.mjs.html#line71">line 71</a>
739
+ <a href="dispatchApiOpenaiCompat.mjs.html">dispatchApiOpenaiCompat.mjs</a>, <a href="dispatchApiOpenaiCompat.mjs.html#line75">line 75</a>
571
740
  </li></ul></dd>
572
741
 
573
742
 
@@ -736,7 +905,7 @@ parse+check接進遞補層之validate——非法回覆視為該家失敗而
736
905
 
737
906
  <dt class="tag-source">Source:</dt>
738
907
  <dd class="tag-source"><ul class="dummy"><li>
739
- <a href="wkf_callAiWithFallback.mjs.html">wkf/callAiWithFallback.mjs</a>, <a href="wkf_callAiWithFallback.mjs.html#line144">line 144</a>
908
+ <a href="wkf_callAiWithFallback.mjs.html">wkf/callAiWithFallback.mjs</a>, <a href="wkf_callAiWithFallback.mjs.html#line146">line 146</a>
740
909
  </li></ul></dd>
741
910
 
742
911
 
@@ -1410,6 +1579,44 @@ await test()
1410
1579
 
1411
1580
 
1412
1581
 
1582
+ <tr>
1583
+
1584
+ <td class="name"><code>meta</code></td>
1585
+
1586
+
1587
+ <td class="type">
1588
+
1589
+
1590
+ <span class="param-type">*</span>
1591
+
1592
+
1593
+
1594
+
1595
+ </td>
1596
+
1597
+
1598
+ <td class="attributes">
1599
+
1600
+ &lt;optional><br>
1601
+
1602
+
1603
+
1604
+
1605
+
1606
+ </td>
1607
+
1608
+
1609
+
1610
+ <td class="default">
1611
+
1612
+ </td>
1613
+
1614
+
1615
+ <td class="description last"><p>輸入呼叫端自有資訊(分類、標籤、註記),保留鍵保證永不轉傳下層,預設undefined</p></td>
1616
+ </tr>
1617
+
1618
+
1619
+
1413
1620
  <tr>
1414
1621
 
1415
1622
  <td class="name"><code>onEvent</code></td>
@@ -1445,7 +1652,7 @@ await test()
1445
1652
  </td>
1446
1653
 
1447
1654
 
1448
- <td class="description last"><p>輸入遞補層事件回調函數,預設null。除上列外之其餘鍵(retryDelayMs、maxBuffer、onStdout等)亦一律原樣轉傳dispatchAiFallback</p></td>
1655
+ <td class="description last"><p>輸入遞補層事件回調函數,預設null。除上列外之其餘鍵(retryDelayMs、maxBuffer、shouldStop、coolDetect、cooldownMs等)亦一律原樣轉傳dispatchAiFallback</p></td>
1449
1656
  </tr>
1450
1657
 
1451
1658
 
@@ -1478,7 +1685,7 @@ await test()
1478
1685
 
1479
1686
 
1480
1687
  <div class="param-desc">
1481
- <p>回傳Promise,resolve回傳結果物件,內含ok(是否取得可用結果布林值)、json(解析後物件,rawText模式下為文字)、providerId(實際使用之名稱)、keyIndex、keyId、ms(總耗時毫秒)、tried(遞補嘗試歷程陣列)、error(錯誤訊息字串),本函數不會reject</p>
1688
+ <p>回傳Promise,resolve回傳結果物件,內含ok(是否取得可用結果布林值)、json(解析後物件,rawText模式下為文字)、providerId(實際使用之名稱)、keyIndex、keyId、ms(總耗時毫秒)、tried(遞補嘗試歷程陣列)、usage(api類之token用量原樣透傳,CLI類為null)、error(錯誤訊息字串)、errorType(僅失敗時,機器可讀錯誤類別字串,一覽見getErrorType.mjs檔頭),本函數不會reject</p>
1482
1689
  </div>
1483
1690
 
1484
1691
 
@@ -1521,7 +1728,7 @@ await test()
1521
1728
 
1522
1729
  <dt class="tag-source">Source:</dt>
1523
1730
  <dd class="tag-source"><ul class="dummy"><li>
1524
- <a href="dispatchApiOpenaiCompat.mjs.html">dispatchApiOpenaiCompat.mjs</a>, <a href="dispatchApiOpenaiCompat.mjs.html#line137">line 137</a>
1731
+ <a href="dispatchApiOpenaiCompat.mjs.html">dispatchApiOpenaiCompat.mjs</a>, <a href="dispatchApiOpenaiCompat.mjs.html#line141">line 141</a>
1525
1732
  </li></ul></dd>
1526
1733
 
1527
1734
 
@@ -1762,7 +1969,7 @@ await test()
1762
1969
 
1763
1970
 
1764
1971
 
1765
- <h4 class="name" id="defaultIntegratePrompt"><span class="type-signature"></span>defaultIntegratePrompt<span class="signature">(candidates, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {String}</span></h4>
1972
+ <h4 class="name" id="castPintOr"><span class="type-signature"></span>castPintOr<span class="signature">(v, df)</span><span class="type-signature"> &rarr; {Number|*}</span></h4>
1766
1973
 
1767
1974
 
1768
1975
 
@@ -1772,13 +1979,16 @@ await test()
1772
1979
  <dl class="details">
1773
1980
 
1774
1981
  <dt class="tag-description">Description:</dt>
1775
- <dd class="tag-description"><ul class="dummy"><li><p>預設整合提示詞模板:把成功候選JSON併入整合任務</p></li></ul></dd>
1982
+ <dd class="tag-description"><ul class="dummy"><li><p>正整數正規化:有效正整數即轉整數回傳,否則回傳預設值</p>
1983
+ <p>本套件各層之數值設定(timeoutMs、budgetMs、minAttemptMs、cooldownMs、retryDelayMs等)
1984
+ 皆採同一寬容策略「無效即靜默回退預設」,統一收斂於此,
1985
+ 避免同一7行判斷區塊散落各轉接器(曾重複6處)</p></li></ul></dd>
1776
1986
 
1777
1987
 
1778
1988
 
1779
1989
  <dt class="tag-source">Source:</dt>
1780
1990
  <dd class="tag-source"><ul class="dummy"><li>
1781
- <a href="wkf_runFanout.mjs.html">wkf/runFanout.mjs</a>, <a href="wkf_runFanout.mjs.html#line31">line 31</a>
1991
+ <a href="castPintOr.mjs.html">castPintOr.mjs</a>, <a href="castPintOr.mjs.html#line29">line 29</a>
1782
1992
  </li></ul></dd>
1783
1993
 
1784
1994
 
@@ -1823,6 +2033,20 @@ await test()
1823
2033
 
1824
2034
 
1825
2035
 
2036
+ <h5 class="h5-examples">Example</h5>
2037
+
2038
+ <pre class="prettyprint"><code>import castPintOr from './src/castPintOr.mjs'
2039
+
2040
+ console.log(castPintOr(5000, 300000))
2041
+ // => 5000
2042
+
2043
+ console.log(castPintOr('abc', 300000))
2044
+ // => 300000
2045
+
2046
+ console.log(castPintOr(undefined, null))
2047
+ // => null</code></pre>
2048
+
2049
+
1826
2050
 
1827
2051
 
1828
2052
  <h5 class="h5-parameters">Parameters:</h5>
@@ -1838,12 +2062,8 @@ await test()
1838
2062
  <th>Type</th>
1839
2063
 
1840
2064
 
1841
- <th>Attributes</th>
1842
-
1843
2065
 
1844
2066
 
1845
- <th>Default</th>
1846
-
1847
2067
 
1848
2068
  <th class="last">Description</th>
1849
2069
  </tr>
@@ -1854,13 +2074,13 @@ await test()
1854
2074
 
1855
2075
  <tr>
1856
2076
 
1857
- <td class="name"><code>candidates</code></td>
2077
+ <td class="name"><code>v</code></td>
1858
2078
 
1859
2079
 
1860
2080
  <td class="type">
1861
2081
 
1862
2082
 
1863
- <span class="param-type">Array</span>
2083
+ <span class="param-type">*</span>
1864
2084
 
1865
2085
 
1866
2086
 
@@ -1868,35 +2088,23 @@ await test()
1868
2088
  </td>
1869
2089
 
1870
2090
 
1871
- <td class="attributes">
1872
-
1873
-
1874
-
1875
-
1876
-
1877
- </td>
1878
-
1879
2091
 
1880
2092
 
1881
- <td class="default">
1882
-
1883
- </td>
1884
-
1885
2093
 
1886
- <td class="description last"><p>輸入成功候選物件陣列</p></td>
2094
+ <td class="description last"><p>輸入待正規化之值</p></td>
1887
2095
  </tr>
1888
2096
 
1889
2097
 
1890
2098
 
1891
2099
  <tr>
1892
2100
 
1893
- <td class="name"><code>opt</code></td>
2101
+ <td class="name"><code>df</code></td>
1894
2102
 
1895
2103
 
1896
2104
  <td class="type">
1897
2105
 
1898
2106
 
1899
- <span class="param-type">Object</span>
2107
+ <span class="param-type">*</span>
1900
2108
 
1901
2109
 
1902
2110
 
@@ -1904,26 +2112,10 @@ await test()
1904
2112
  </td>
1905
2113
 
1906
2114
 
1907
- <td class="attributes">
1908
-
1909
- &lt;optional><br>
1910
-
1911
-
1912
-
1913
-
1914
-
1915
- </td>
1916
-
1917
2115
 
1918
2116
 
1919
- <td class="default">
1920
-
1921
- <code>{}</code>
1922
-
1923
- </td>
1924
-
1925
2117
 
1926
- <td class="description last"><p>輸入設定物件(取schema作為輸出格式示意),預設{}</p></td>
2118
+ <td class="description last"><p>輸入無效時之預設值(可為null代表不限)</p></td>
1927
2119
  </tr>
1928
2120
 
1929
2121
 
@@ -1949,7 +2141,7 @@ await test()
1949
2141
 
1950
2142
 
1951
2143
  <div class="param-desc">
1952
- <p>回傳整合提示詞字串</p>
2144
+ <p>回傳正規化後之正整數,v非有效正整數時回傳df</p>
1953
2145
  </div>
1954
2146
 
1955
2147
 
@@ -1960,7 +2152,10 @@ await test()
1960
2152
  </dt>
1961
2153
  <dd>
1962
2154
 
1963
- <span class="param-type">String</span>
2155
+ <span class="param-type">Number</span>
2156
+ |
2157
+
2158
+ <span class="param-type">*</span>
1964
2159
 
1965
2160
 
1966
2161
 
@@ -1976,7 +2171,7 @@ await test()
1976
2171
 
1977
2172
 
1978
2173
 
1979
- <h4 class="name" id="dispatchAi"><span class="type-signature type-signature-async">(async) </span>dispatchAi<span class="signature">(kind, prompt, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
2174
+ <h4 class="name" id="defaultIntegratePrompt"><span class="type-signature"></span>defaultIntegratePrompt<span class="signature">(candidates, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {String}</span></h4>
1980
2175
 
1981
2176
 
1982
2177
 
@@ -1986,18 +2181,233 @@ await test()
1986
2181
  <dl class="details">
1987
2182
 
1988
2183
  <dt class="tag-description">Description:</dt>
1989
- <dd class="tag-description"><ul class="dummy"><li><p>依供應商種類(kind)分派至對應之CLI轉接器</p>
1990
- <p>三種供應商的差異(2026-08-08於本機實測確認):
1991
- opencode支援逐次注入金鑰(OPENCODE_AUTH_CONTENT),故可多把金鑰輪替;
1992
- claude與codex則沿用CLI既有登入狀態,無逐次金鑰概念。
1993
- 故「輪替」的單位是「供應商條目」而非單純的金鑰:一個條目即一組(kind, model, 可選的key/provider),
1994
- 輪到誰就用誰的CLI與模型</p></li></ul></dd>
2184
+ <dd class="tag-description"><ul class="dummy"><li><p>預設整合提示詞模板:把成功候選JSON併入整合任務</p></li></ul></dd>
1995
2185
 
1996
2186
 
1997
2187
 
1998
2188
  <dt class="tag-source">Source:</dt>
1999
2189
  <dd class="tag-source"><ul class="dummy"><li>
2000
- <a href="dispatchAi.mjs.html">dispatchAi.mjs</a>, <a href="dispatchAi.mjs.html#line43">line 43</a>
2190
+ <a href="wkf_runFanout.mjs.html">wkf/runFanout.mjs</a>, <a href="wkf_runFanout.mjs.html#line31">line 31</a>
2191
+ </li></ul></dd>
2192
+
2193
+
2194
+
2195
+
2196
+
2197
+
2198
+
2199
+
2200
+
2201
+
2202
+
2203
+
2204
+
2205
+
2206
+
2207
+
2208
+
2209
+
2210
+
2211
+
2212
+
2213
+
2214
+
2215
+
2216
+
2217
+
2218
+
2219
+
2220
+
2221
+
2222
+
2223
+ </dl>
2224
+
2225
+
2226
+
2227
+
2228
+
2229
+
2230
+
2231
+
2232
+
2233
+
2234
+
2235
+
2236
+
2237
+ <h5 class="h5-parameters">Parameters:</h5>
2238
+
2239
+
2240
+ <table class="params">
2241
+ <thead>
2242
+ <tr>
2243
+
2244
+ <th>Name</th>
2245
+
2246
+
2247
+ <th>Type</th>
2248
+
2249
+
2250
+ <th>Attributes</th>
2251
+
2252
+
2253
+
2254
+ <th>Default</th>
2255
+
2256
+
2257
+ <th class="last">Description</th>
2258
+ </tr>
2259
+ </thead>
2260
+
2261
+ <tbody>
2262
+
2263
+
2264
+ <tr>
2265
+
2266
+ <td class="name"><code>candidates</code></td>
2267
+
2268
+
2269
+ <td class="type">
2270
+
2271
+
2272
+ <span class="param-type">Array</span>
2273
+
2274
+
2275
+
2276
+
2277
+ </td>
2278
+
2279
+
2280
+ <td class="attributes">
2281
+
2282
+
2283
+
2284
+
2285
+
2286
+ </td>
2287
+
2288
+
2289
+
2290
+ <td class="default">
2291
+
2292
+ </td>
2293
+
2294
+
2295
+ <td class="description last"><p>輸入成功候選物件陣列</p></td>
2296
+ </tr>
2297
+
2298
+
2299
+
2300
+ <tr>
2301
+
2302
+ <td class="name"><code>opt</code></td>
2303
+
2304
+
2305
+ <td class="type">
2306
+
2307
+
2308
+ <span class="param-type">Object</span>
2309
+
2310
+
2311
+
2312
+
2313
+ </td>
2314
+
2315
+
2316
+ <td class="attributes">
2317
+
2318
+ &lt;optional><br>
2319
+
2320
+
2321
+
2322
+
2323
+
2324
+ </td>
2325
+
2326
+
2327
+
2328
+ <td class="default">
2329
+
2330
+ <code>{}</code>
2331
+
2332
+ </td>
2333
+
2334
+
2335
+ <td class="description last"><p>輸入設定物件(取schema作為輸出格式示意),預設{}</p></td>
2336
+ </tr>
2337
+
2338
+
2339
+ </tbody>
2340
+ </table>
2341
+
2342
+
2343
+
2344
+
2345
+
2346
+
2347
+
2348
+
2349
+
2350
+
2351
+
2352
+
2353
+
2354
+
2355
+
2356
+
2357
+ <h5 class="h5-returns">Returns:</h5>
2358
+
2359
+
2360
+ <div class="param-desc">
2361
+ <p>回傳整合提示詞字串</p>
2362
+ </div>
2363
+
2364
+
2365
+
2366
+ <dl class="param-type">
2367
+ <dt>
2368
+ Type
2369
+ </dt>
2370
+ <dd>
2371
+
2372
+ <span class="param-type">String</span>
2373
+
2374
+
2375
+
2376
+ </dd>
2377
+ </dl>
2378
+
2379
+
2380
+
2381
+
2382
+
2383
+
2384
+
2385
+
2386
+
2387
+
2388
+ <h4 class="name" id="dispatchAi"><span class="type-signature type-signature-async">(async) </span>dispatchAi<span class="signature">(kind, prompt, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
2389
+
2390
+
2391
+
2392
+
2393
+
2394
+
2395
+ <dl class="details">
2396
+
2397
+ <dt class="tag-description">Description:</dt>
2398
+ <dd class="tag-description"><ul class="dummy"><li><p>依供應商種類(kind)分派至對應之轉接器</p>
2399
+ <p>kind清單以adapters.mjs對照表為唯一來源(目前為'opencode'、'claude'、'codex'、'antigravity'、
2400
+ 'api-openai-compat',CLI或API之選型判準見adapters.mjs檔頭)。
2401
+ 各家金鑰模式不同(2026-08-08起於本機實測確認):opencode與api-openai-compat支援逐次注入金鑰,
2402
+ 故可多把金鑰輪替;claude/codex/antigravity沿用CLI既有登入狀態,無逐次金鑰概念。
2403
+ 故「輪替」的單位是「供應商條目」而非單純的金鑰:一個條目即一組(kind, model, 可選的key/provider),
2404
+ 輪到誰就用誰的轉接器與模型</p></li></ul></dd>
2405
+
2406
+
2407
+
2408
+ <dt class="tag-source">Source:</dt>
2409
+ <dd class="tag-source"><ul class="dummy"><li>
2410
+ <a href="dispatchAi.mjs.html">dispatchAi.mjs</a>, <a href="dispatchAi.mjs.html#line44">line 44</a>
2001
2411
  </li></ul></dd>
2002
2412
 
2003
2413
 
@@ -2055,8 +2465,8 @@ let test = async () => {
2055
2465
  // => true '完成'
2056
2466
 
2057
2467
  let re = await dispatchAi('gemini', 'abc')
2058
- console.log(re.ok, re.error)
2059
- // => false 'unknown ai kind: "gemini" (available: opencode, claude, codex)'
2468
+ console.log(re.ok, re.error.indexOf('unknown ai kind: "gemini"') === 0)
2469
+ // => false true
2060
2470
 
2061
2471
  }
2062
2472
  await test()
@@ -2125,7 +2535,7 @@ await test()
2125
2535
  </td>
2126
2536
 
2127
2537
 
2128
- <td class="description last"><p>輸入供應商種類字串,可選'opencode'、'claude'、'codex'</p></td>
2538
+ <td class="description last"><p>輸入供應商種類字串,須為adapters.mjs對照表之鍵名,目前可選'opencode'、'claude'、'codex'、'antigravity'、'api-openai-compat'</p></td>
2129
2539
  </tr>
2130
2540
 
2131
2541
 
@@ -2161,7 +2571,7 @@ await test()
2161
2571
  </td>
2162
2572
 
2163
2573
 
2164
- <td class="description last"><p>輸入提示詞字串,一律以stdin傳入子進程</p></td>
2574
+ <td class="description last"><p>輸入提示詞字串</p></td>
2165
2575
  </tr>
2166
2576
 
2167
2577
 
@@ -2201,7 +2611,7 @@ await test()
2201
2611
  </td>
2202
2612
 
2203
2613
 
2204
- <td class="description last"><p>輸入設定物件,原樣轉傳對應轉接器,各轉接器可用設定詳見dispatchOpencode、dispatchClaude、dispatchCodex,預設{}</p></td>
2614
+ <td class="description last"><p>輸入設定物件,原樣轉傳對應轉接器,各轉接器可用設定詳見dispatchOpencode、dispatchClaude、dispatchCodex、dispatchAntigravity、dispatchApiOpenaiCompat,預設{}</p></td>
2205
2615
  </tr>
2206
2616
 
2207
2617
 
@@ -2227,7 +2637,7 @@ await test()
2227
2637
 
2228
2638
 
2229
2639
  <div class="param-desc">
2230
- <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(標準輸出字串)、stderr(標準錯誤字串)、code(離開碼)、error(錯誤訊息字串,成功時為空字串)、durationMs(耗時毫秒)、attempts(實際嘗試次數),本函數不會reject</p>
2640
+ <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(標準輸出字串)、stderr(標準錯誤字串)、code(離開碼)、error(錯誤訊息字串,成功時為空字串)、errorType(僅失敗時,機器可讀錯誤類別字串)、durationMs(耗時毫秒)、attempts(實際嘗試次數),本函數不會reject</p>
2231
2641
  </div>
2232
2642
 
2233
2643
 
@@ -2278,7 +2688,7 @@ providers陣列順序即優先序,排前面的先用;
2278
2688
 
2279
2689
  <dt class="tag-source">Source:</dt>
2280
2690
  <dd class="tag-source"><ul class="dummy"><li>
2281
- <a href="dispatchAiFallback.mjs.html">dispatchAiFallback.mjs</a>, <a href="dispatchAiFallback.mjs.html#line199">line 199</a>
2691
+ <a href="dispatchAiFallback.mjs.html">dispatchAiFallback.mjs</a>, <a href="dispatchAiFallback.mjs.html#line292">line 292</a>
2282
2692
  </li></ul></dd>
2283
2693
 
2284
2694
 
@@ -2631,6 +3041,44 @@ await test()
2631
3041
  </tr>
2632
3042
 
2633
3043
 
3044
+
3045
+ <tr>
3046
+
3047
+ <td class="name"><code>meta</code></td>
3048
+
3049
+
3050
+ <td class="type">
3051
+
3052
+
3053
+ <span class="param-type">*</span>
3054
+
3055
+
3056
+
3057
+
3058
+ </td>
3059
+
3060
+
3061
+ <td class="attributes">
3062
+
3063
+ &lt;optional><br>
3064
+
3065
+
3066
+
3067
+
3068
+
3069
+ </td>
3070
+
3071
+
3072
+
3073
+ <td class="default">
3074
+
3075
+ </td>
3076
+
3077
+
3078
+ <td class="description last"><p>輸入呼叫端自有資訊(分類、標籤、註記),保留鍵保證永不轉傳對應轉接器——條目其餘鍵一律原樣轉傳,自有欄位放此鍵可與轉傳機制永久絕緣,預設undefined</p></td>
3079
+ </tr>
3080
+
3081
+
2634
3082
  </tbody>
2635
3083
  </table>
2636
3084
 
@@ -2794,14 +3242,14 @@ await test()
2794
3242
  </td>
2795
3243
 
2796
3244
 
2797
- <td class="description last"><p>輸入供應商冷卻視窗毫秒非負整數,&gt;0啟用:條目(限有明給id者)遭遇限流(HTTP 429,僅api類可偵測)或逾時(TIMEOUT開頭)後,於冷卻視窗內之後續呼叫中被移至鏈尾——只降序不移除,前面全敗時仍會被嘗試,任一次成功立即解除;注意啟用時「providers順序即優先序」會被暫時重排,此即本機制之目的;預設0代表不啟用</p></td>
3245
+ <td class="description last"><p>輸入供應商冷卻視窗毫秒非負整數,&gt;0啟用:條目(限有明給id者)遭遇限流(HTTP 429,僅api類可偵測;CLI類可經coolDetect注入判定)或逾時(TIMEOUT開頭)後,於冷卻視窗內之後續呼叫中被移至鏈尾——只降序不移除,前面全敗時仍會被嘗試,任一次成功立即解除;注意啟用時「providers順序即優先序」會被暫時重排,此即本機制之目的;預設0代表不啟用</p></td>
2798
3246
  </tr>
2799
3247
 
2800
3248
 
2801
3249
 
2802
3250
  <tr>
2803
3251
 
2804
- <td class="name"><code>onEvent</code></td>
3252
+ <td class="name"><code>coolDetect</code></td>
2805
3253
 
2806
3254
 
2807
3255
  <td class="type">
@@ -2834,7 +3282,125 @@ await test()
2834
3282
  </td>
2835
3283
 
2836
3284
 
2837
- <td class="description last"><p>輸入事件回調函數(ev)=&gt;{},ev.type可為'try''ok''next-key''skip-group'、'budget-out';失敗事件(next-key/skip-group)另帶stdout(被拒回覆)stderr(錯誤輸出)供診斷,兩者於失敗路徑已由轉接器截斷;回調拋出例外不影響主流程,預設null</p></td>
3285
+ <td class="description last"><p>輸入冷卻觸發判定函數(r)=&gt;Boolean,收完整失敗結果物件(含stdoutstderrcodeerror),回傳true即視同冷卻觸發(內建429/TIMEOUT觸發不受影響)——CLI類限流埋在stderr且各家字樣不同,簽章表由觀察到字樣的呼叫端維護,如(r)=&gt;/FreeUsageLimitError/i.test(r.stderr||'');僅cooldownMs&gt;0時有效,回調拋出例外視同false,預設null</p></td>
3286
+ </tr>
3287
+
3288
+
3289
+
3290
+ <tr>
3291
+
3292
+ <td class="name"><code>shouldStop</code></td>
3293
+
3294
+
3295
+ <td class="type">
3296
+
3297
+
3298
+ <span class="param-type">function</span>
3299
+
3300
+
3301
+
3302
+
3303
+ </td>
3304
+
3305
+
3306
+ <td class="attributes">
3307
+
3308
+ &lt;optional><br>
3309
+
3310
+
3311
+
3312
+
3313
+
3314
+ </td>
3315
+
3316
+
3317
+
3318
+ <td class="default">
3319
+
3320
+ <code>null</code>
3321
+
3322
+ </td>
3323
+
3324
+
3325
+ <td class="description last"><p>輸入中止判定函數()=&gt;Boolean,於每次嘗試之間檢查,回傳true即停止遞補回報ABORTED(不中止進行中之嘗試)——供呼叫端於成果已無人接收時(如客戶端斷線)止損;經工作流層原樣轉傳,中止後各後續呼叫進門即回ABORTED令整條工作流快速收束;回調拋出例外視同false,預設null</p></td>
3326
+ </tr>
3327
+
3328
+
3329
+
3330
+ <tr>
3331
+
3332
+ <td class="name"><code>meta</code></td>
3333
+
3334
+
3335
+ <td class="type">
3336
+
3337
+
3338
+ <span class="param-type">*</span>
3339
+
3340
+
3341
+
3342
+
3343
+ </td>
3344
+
3345
+
3346
+ <td class="attributes">
3347
+
3348
+ &lt;optional><br>
3349
+
3350
+
3351
+
3352
+
3353
+
3354
+ </td>
3355
+
3356
+
3357
+
3358
+ <td class="default">
3359
+
3360
+ </td>
3361
+
3362
+
3363
+ <td class="description last"><p>輸入呼叫端自有資訊,保留鍵保證永不轉傳各轉接器,預設undefined</p></td>
3364
+ </tr>
3365
+
3366
+
3367
+
3368
+ <tr>
3369
+
3370
+ <td class="name"><code>onEvent</code></td>
3371
+
3372
+
3373
+ <td class="type">
3374
+
3375
+
3376
+ <span class="param-type">function</span>
3377
+
3378
+
3379
+
3380
+
3381
+ </td>
3382
+
3383
+
3384
+ <td class="attributes">
3385
+
3386
+ &lt;optional><br>
3387
+
3388
+
3389
+
3390
+
3391
+
3392
+ </td>
3393
+
3394
+
3395
+
3396
+ <td class="default">
3397
+
3398
+ <code>null</code>
3399
+
3400
+ </td>
3401
+
3402
+
3403
+ <td class="description last"><p>輸入事件回調函數(ev)=&gt;{},ev.type可為'try'、'ok'、'next-key'、'skip-group'、'budget-out'、'aborted'、'cooled'(冷卻觸發,帶error與cooldownMs,僅cooldownMs&gt;0時出現);失敗事件(next-key/skip-group)另帶errorType、stdout(被拒回覆)與stderr(錯誤輸出)供診斷,後兩者於失敗路徑已由轉接器截斷;回調拋出例外不影響主流程,預設null</p></td>
2838
3404
  </tr>
2839
3405
 
2840
3406
 
@@ -2988,7 +3554,7 @@ await test()
2988
3554
 
2989
3555
 
2990
3556
  <div class="param-desc">
2991
- <p>回傳Promise,resolve回傳結果物件,除execCli既有欄位(ok、stdout、stderr、code、error、durationMs、attempts、pid)外,追加providerId(實際使用之群組)、keyIndex(實際使用之金鑰索引,無keys時為null)、kind、model、tried(全部嘗試歷程陣列,成功時亦回傳;失敗項含stdout與stderr供診斷被拒原因),本函數不會reject</p>
3557
+ <p>回傳Promise,resolve回傳結果物件,除execCli既有欄位(ok、stdout、stderr、code、error、durationMs、attempts、pid)外,追加providerId(實際使用之群組)、keyIndex(實際使用之金鑰索引,無keys時為null)、kind、model、tried(全部嘗試歷程陣列,成功時亦回傳;失敗項含errorType、stdout與stderr供診斷被拒原因);失敗結果帶機器可讀之errorType(一覽見getErrorType.mjs檔頭);api類轉接器提供usage(token用量)時原樣流出於結果與tried各項,CLI類無此欄;本函數不會reject</p>
2992
3558
  </div>
2993
3559
 
2994
3560
 
@@ -4077,7 +4643,7 @@ prompt走HTTP body,無命令列長度限制;
4077
4643
 
4078
4644
  <dt class="tag-source">Source:</dt>
4079
4645
  <dd class="tag-source"><ul class="dummy"><li>
4080
- <a href="dispatchApiOpenaiCompat.mjs.html">dispatchApiOpenaiCompat.mjs</a>, <a href="dispatchApiOpenaiCompat.mjs.html#line327">line 327</a>
4646
+ <a href="dispatchApiOpenaiCompat.mjs.html">dispatchApiOpenaiCompat.mjs</a>, <a href="dispatchApiOpenaiCompat.mjs.html#line325">line 325</a>
4081
4647
  </li></ul></dd>
4082
4648
 
4083
4649
 
@@ -4708,7 +5274,7 @@ await test()
4708
5274
 
4709
5275
 
4710
5276
  <div class="param-desc">
4711
- <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(回覆內容字串)、stderr(失敗時之原始回應本體)、code(HTTP狀態碼,網路錯誤與逾時為null)、error(錯誤訊息字串,成功時為空字串)、durationMs(耗時毫秒)、attempts(實際嘗試次數),本函數不會reject</p>
5277
+ <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(回覆內容字串)、stderr(失敗時之原始回應本體)、code(HTTP狀態碼,網路錯誤與逾時為null)、error(錯誤訊息字串,成功時為空字串)、errorType(僅失敗時,機器可讀錯誤類別字串,一覽見getErrorType.mjs檔頭)、durationMs(耗時毫秒)、attempts(實際嘗試次數)、usage(原始回應之token用量物件原樣透傳,無則null),本函數不會reject</p>
4712
5278
  </div>
4713
5279
 
4714
5280
 
@@ -7082,7 +7648,7 @@ console.log(getCliArgs('-p', null, 123, ['', '--verbose']))
7082
7648
 
7083
7649
 
7084
7650
 
7085
- <h4 class="name" id="getErrorResult"><span class="type-signature"></span>getErrorResult<span class="signature">(error)</span><span class="type-signature"> &rarr; {Object}</span></h4>
7651
+ <h4 class="name" id="getErrorResult"><span class="type-signature"></span>getErrorResult<span class="signature">(error, errorType<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Object}</span></h4>
7086
7652
 
7087
7653
 
7088
7654
 
@@ -7101,7 +7667,7 @@ console.log(getCliArgs('-p', null, 123, ['', '--verbose']))
7101
7667
 
7102
7668
  <dt class="tag-source">Source:</dt>
7103
7669
  <dd class="tag-source"><ul class="dummy"><li>
7104
- <a href="getErrorResult.mjs.html">getErrorResult.mjs</a>, <a href="getErrorResult.mjs.html#line24">line 24</a>
7670
+ <a href="getErrorResult.mjs.html">getErrorResult.mjs</a>, <a href="getErrorResult.mjs.html#line25">line 25</a>
7105
7671
  </li></ul></dd>
7106
7672
 
7107
7673
 
@@ -7151,7 +7717,7 @@ console.log(getCliArgs('-p', null, 123, ['', '--verbose']))
7151
7717
  <pre class="prettyprint"><code>import getErrorResult from './src/getErrorResult.mjs'
7152
7718
 
7153
7719
  console.log(getErrorResult('prompt must be a non-empty string'))
7154
- // => { ok: false, stdout: '', stderr: '', code: null, error: 'prompt must be a non-empty string', durationMs: 0, attempts: 0 }
7720
+ // => { ok: false, stdout: '', stderr: '', code: null, error: 'prompt must be a non-empty string', errorType: 'params', durationMs: 0, attempts: 0 }
7155
7721
 
7156
7722
  console.log(getErrorResult(null).error)
7157
7723
  // => 'unknown error'</code></pre>
@@ -7172,8 +7738,12 @@ console.log(getErrorResult(null).error)
7172
7738
  <th>Type</th>
7173
7739
 
7174
7740
 
7741
+ <th>Attributes</th>
7742
+
7175
7743
 
7176
7744
 
7745
+ <th>Default</th>
7746
+
7177
7747
 
7178
7748
  <th class="last">Description</th>
7179
7749
  </tr>
@@ -7198,13 +7768,65 @@ console.log(getErrorResult(null).error)
7198
7768
  </td>
7199
7769
 
7200
7770
 
7771
+ <td class="attributes">
7772
+
7773
+
7774
+
7775
+
7776
+
7777
+ </td>
7778
+
7201
7779
 
7202
7780
 
7781
+ <td class="default">
7782
+
7783
+ </td>
7784
+
7203
7785
 
7204
7786
  <td class="description last"><p>輸入錯誤訊息字串</p></td>
7205
7787
  </tr>
7206
7788
 
7207
7789
 
7790
+
7791
+ <tr>
7792
+
7793
+ <td class="name"><code>errorType</code></td>
7794
+
7795
+
7796
+ <td class="type">
7797
+
7798
+
7799
+ <span class="param-type">String</span>
7800
+
7801
+
7802
+
7803
+
7804
+ </td>
7805
+
7806
+
7807
+ <td class="attributes">
7808
+
7809
+ &lt;optional><br>
7810
+
7811
+
7812
+
7813
+
7814
+
7815
+ </td>
7816
+
7817
+
7818
+
7819
+ <td class="default">
7820
+
7821
+ <code>'params'</code>
7822
+
7823
+ </td>
7824
+
7825
+
7826
+ <td class="description last"><p>輸入機器可讀之錯誤類別字串(一覽見getErrorType.mjs檔頭),預設'params'(參數/設定檢核失敗)</p></td>
7827
+ </tr>
7828
+
7829
+
7208
7830
  </tbody>
7209
7831
  </table>
7210
7832
 
@@ -7227,7 +7849,7 @@ console.log(getErrorResult(null).error)
7227
7849
 
7228
7850
 
7229
7851
  <div class="param-desc">
7230
- <p>回傳結果物件,內含ok(布林值,恆為false)、stdout(空字串)、stderr(空字串)、code(null)、error(錯誤訊息字串)、durationMs(0)、attempts(0)</p>
7852
+ <p>回傳結果物件,內含ok(布林值,恆為false)、stdout(空字串)、stderr(空字串)、code(null)、error(錯誤訊息字串)、errorType(錯誤類別字串)、durationMs(0)、attempts(0)</p>
7231
7853
  </div>
7232
7854
 
7233
7855
 
@@ -7254,7 +7876,7 @@ console.log(getErrorResult(null).error)
7254
7876
 
7255
7877
 
7256
7878
 
7257
- <h4 class="name" id="isKeyIndependentFail"><span class="type-signature"></span>isKeyIndependentFail<span class="signature">(r)</span><span class="type-signature"> &rarr; {Boolean}</span></h4>
7879
+ <h4 class="name" id="getErrorType"><span class="type-signature"></span>getErrorType<span class="signature">(r)</span><span class="type-signature"> &rarr; {String}</span></h4>
7258
7880
 
7259
7881
 
7260
7882
 
@@ -7264,13 +7886,16 @@ console.log(getErrorResult(null).error)
7264
7886
  <dl class="details">
7265
7887
 
7266
7888
  <dt class="tag-description">Description:</dt>
7267
- <dd class="tag-description"><ul class="dummy"><li><p>判斷失敗結果是否與「哪一把金鑰」無關(換組內金鑰必然再敗, 應整組跳過)</p></li></ul></dd>
7889
+ <dd class="tag-description"><ul class="dummy"><li><p>由失敗結果物件推導機器可讀之errorType(僅機械可判者,其餘歸'exec',不猜測)</p>
7890
+ <p>判準與dispatchAiFallback之isKeyIndependentFail同組:error以TIMEOUT開頭為'timeout'、
7891
+ 含ENOENT或ENAMETOOLONG為'spawn'、恰為OUTPUT_VALIDATION_FAILED為'validation',
7892
+ 其餘失敗一律'exec'(各家CLI字樣不同且隨版本漂移,不維護簽章表)</p></li></ul></dd>
7268
7893
 
7269
7894
 
7270
7895
 
7271
7896
  <dt class="tag-source">Source:</dt>
7272
7897
  <dd class="tag-source"><ul class="dummy"><li>
7273
- <a href="dispatchAiFallback.mjs.html">dispatchAiFallback.mjs</a>, <a href="dispatchAiFallback.mjs.html#line94">line 94</a>
7898
+ <a href="getErrorType.mjs.html">getErrorType.mjs</a>, <a href="getErrorType.mjs.html#line53">line 53</a>
7274
7899
  </li></ul></dd>
7275
7900
 
7276
7901
 
@@ -7315,6 +7940,20 @@ console.log(getErrorResult(null).error)
7315
7940
 
7316
7941
 
7317
7942
 
7943
+ <h5 class="h5-examples">Example</h5>
7944
+
7945
+ <pre class="prettyprint"><code>import getErrorType from './src/getErrorType.mjs'
7946
+
7947
+ console.log(getErrorType({ error: 'TIMEOUT after 300s' }))
7948
+ // => 'timeout'
7949
+
7950
+ console.log(getErrorType({ error: 'spawn cli ENOENT' }))
7951
+ // => 'spawn'
7952
+
7953
+ console.log(getErrorType({ error: 'Exit code 1' }))
7954
+ // => 'exec'</code></pre>
7955
+
7956
+
7318
7957
 
7319
7958
 
7320
7959
  <h5 class="h5-parameters">Parameters:</h5>
@@ -7359,7 +7998,7 @@ console.log(getErrorResult(null).error)
7359
7998
 
7360
7999
 
7361
8000
 
7362
- <td class="description last"><p>輸入dispatchAi失敗結果物件</p></td>
8001
+ <td class="description last"><p>輸入失敗結果物件(取其error欄位判別)</p></td>
7363
8002
  </tr>
7364
8003
 
7365
8004
 
@@ -7385,7 +8024,7 @@ console.log(getErrorResult(null).error)
7385
8024
 
7386
8025
 
7387
8026
  <div class="param-desc">
7388
- <p>回傳是否應整組跳過之布林值</p>
8027
+ <p>回傳errorType字串</p>
7389
8028
  </div>
7390
8029
 
7391
8030
 
@@ -7396,7 +8035,555 @@ console.log(getErrorResult(null).error)
7396
8035
  </dt>
7397
8036
  <dd>
7398
8037
 
7399
- <span class="param-type">Boolean</span>
8038
+ <span class="param-type">String</span>
8039
+
8040
+
8041
+
8042
+ </dd>
8043
+ </dl>
8044
+
8045
+
8046
+
8047
+
8048
+
8049
+
8050
+
8051
+
8052
+
8053
+
8054
+ <h4 class="name" id="initState"><span class="type-signature"></span>initState<span class="signature">(store)</span><span class="type-signature"> &rarr; {Object}</span></h4>
8055
+
8056
+
8057
+
8058
+
8059
+
8060
+
8061
+ <dl class="details">
8062
+
8063
+ <dt class="tag-description">Description:</dt>
8064
+ <dd class="tag-description"><ul class="dummy"><li><p>初始化游標與冷卻狀態(store有效即載入持久化狀態, 否則用行程內記憶體)</p></li></ul></dd>
8065
+
8066
+
8067
+
8068
+ <dt class="tag-source">Source:</dt>
8069
+ <dd class="tag-source"><ul class="dummy"><li>
8070
+ <a href="dispatchAiFallback.mjs.html">dispatchAiFallback.mjs</a>, <a href="dispatchAiFallback.mjs.html#line110">line 110</a>
8071
+ </li></ul></dd>
8072
+
8073
+
8074
+
8075
+
8076
+
8077
+
8078
+
8079
+
8080
+
8081
+
8082
+
8083
+
8084
+
8085
+
8086
+
8087
+
8088
+
8089
+
8090
+
8091
+
8092
+
8093
+
8094
+
8095
+
8096
+
8097
+
8098
+
8099
+
8100
+
8101
+
8102
+
8103
+ </dl>
8104
+
8105
+
8106
+
8107
+
8108
+
8109
+
8110
+
8111
+
8112
+
8113
+
8114
+
8115
+
8116
+
8117
+ <h5 class="h5-parameters">Parameters:</h5>
8118
+
8119
+
8120
+ <table class="params">
8121
+ <thead>
8122
+ <tr>
8123
+
8124
+ <th>Name</th>
8125
+
8126
+
8127
+ <th>Type</th>
8128
+
8129
+
8130
+
8131
+
8132
+
8133
+ <th class="last">Description</th>
8134
+ </tr>
8135
+ </thead>
8136
+
8137
+ <tbody>
8138
+
8139
+
8140
+ <tr>
8141
+
8142
+ <td class="name"><code>store</code></td>
8143
+
8144
+
8145
+ <td class="type">
8146
+
8147
+
8148
+ <span class="param-type">Object</span>
8149
+
8150
+
8151
+
8152
+
8153
+ </td>
8154
+
8155
+
8156
+
8157
+
8158
+
8159
+ <td class="description last"><p>輸入狀態持久化物件{get,set},無效代表用行程內記憶體</p></td>
8160
+ </tr>
8161
+
8162
+
8163
+ </tbody>
8164
+ </table>
8165
+
8166
+
8167
+
8168
+
8169
+
8170
+
8171
+
8172
+
8173
+
8174
+
8175
+
8176
+
8177
+
8178
+
8179
+
8180
+
8181
+ <h5 class="h5-returns">Returns:</h5>
8182
+
8183
+
8184
+ <div class="param-desc">
8185
+ <p>回傳物件,內含state(狀態物件,保證有cursors與cooling)與saveState(寫回函數,store無效或寫入失敗皆靜默)</p>
8186
+ </div>
8187
+
8188
+
8189
+
8190
+ <dl class="param-type">
8191
+ <dt>
8192
+ Type
8193
+ </dt>
8194
+ <dd>
8195
+
8196
+ <span class="param-type">Object</span>
8197
+
8198
+
8199
+
8200
+ </dd>
8201
+ </dl>
8202
+
8203
+
8204
+
8205
+
8206
+
8207
+
8208
+
8209
+
8210
+
8211
+
8212
+ <h4 class="name" id="isKeyIndependentFail"><span class="type-signature"></span>isKeyIndependentFail<span class="signature">(r)</span><span class="type-signature"> &rarr; {Boolean}</span></h4>
8213
+
8214
+
8215
+
8216
+
8217
+
8218
+
8219
+ <dl class="details">
8220
+
8221
+ <dt class="tag-description">Description:</dt>
8222
+ <dd class="tag-description"><ul class="dummy"><li><p>判斷失敗結果是否與「哪一把金鑰」無關(換組內金鑰必然再敗, 應整組跳過)</p></li></ul></dd>
8223
+
8224
+
8225
+
8226
+ <dt class="tag-source">Source:</dt>
8227
+ <dd class="tag-source"><ul class="dummy"><li>
8228
+ <a href="dispatchAiFallback.mjs.html">dispatchAiFallback.mjs</a>, <a href="dispatchAiFallback.mjs.html#line183">line 183</a>
8229
+ </li></ul></dd>
8230
+
8231
+
8232
+
8233
+
8234
+
8235
+
8236
+
8237
+
8238
+
8239
+
8240
+
8241
+
8242
+
8243
+
8244
+
8245
+
8246
+
8247
+
8248
+
8249
+
8250
+
8251
+
8252
+
8253
+
8254
+
8255
+
8256
+
8257
+
8258
+
8259
+
8260
+
8261
+ </dl>
8262
+
8263
+
8264
+
8265
+
8266
+
8267
+
8268
+
8269
+
8270
+
8271
+
8272
+
8273
+
8274
+
8275
+ <h5 class="h5-parameters">Parameters:</h5>
8276
+
8277
+
8278
+ <table class="params">
8279
+ <thead>
8280
+ <tr>
8281
+
8282
+ <th>Name</th>
8283
+
8284
+
8285
+ <th>Type</th>
8286
+
8287
+
8288
+
8289
+
8290
+
8291
+ <th class="last">Description</th>
8292
+ </tr>
8293
+ </thead>
8294
+
8295
+ <tbody>
8296
+
8297
+
8298
+ <tr>
8299
+
8300
+ <td class="name"><code>r</code></td>
8301
+
8302
+
8303
+ <td class="type">
8304
+
8305
+
8306
+ <span class="param-type">Object</span>
8307
+
8308
+
8309
+
8310
+
8311
+ </td>
8312
+
8313
+
8314
+
8315
+
8316
+
8317
+ <td class="description last"><p>輸入dispatchAi失敗結果物件</p></td>
8318
+ </tr>
8319
+
8320
+
8321
+ </tbody>
8322
+ </table>
8323
+
8324
+
8325
+
8326
+
8327
+
8328
+
8329
+
8330
+
8331
+
8332
+
8333
+
8334
+
8335
+
8336
+
8337
+
8338
+
8339
+ <h5 class="h5-returns">Returns:</h5>
8340
+
8341
+
8342
+ <div class="param-desc">
8343
+ <p>回傳是否應整組跳過之布林值</p>
8344
+ </div>
8345
+
8346
+
8347
+
8348
+ <dl class="param-type">
8349
+ <dt>
8350
+ Type
8351
+ </dt>
8352
+ <dd>
8353
+
8354
+ <span class="param-type">Boolean</span>
8355
+
8356
+
8357
+
8358
+ </dd>
8359
+ </dl>
8360
+
8361
+
8362
+
8363
+
8364
+
8365
+
8366
+
8367
+
8368
+
8369
+
8370
+ <h4 class="name" id="reorderByCooling"><span class="type-signature"></span>reorderByCooling<span class="signature">(providers, state, cooldownMs, saveState)</span><span class="type-signature"> &rarr; {Array}</span></h4>
8371
+
8372
+
8373
+
8374
+
8375
+
8376
+
8377
+ <dl class="details">
8378
+
8379
+ <dt class="tag-description">Description:</dt>
8380
+ <dd class="tag-description"><ul class="dummy"><li><p>依冷卻狀態重排providers:冷卻中的條目「只降序不移除」——移到鏈尾, 前面全敗時仍會被嘗試,
8381
+ 故不存在把已恢復服務冰住的問題(此為與「金鑰停用清單」的關鍵差異, 後者已被否決)。
8382
+ 僅追蹤有明給id之條目(索引式id會因重排而錯位); 過期紀錄順手清除並寫回</p></li></ul></dd>
8383
+
8384
+
8385
+
8386
+ <dt class="tag-source">Source:</dt>
8387
+ <dd class="tag-source"><ul class="dummy"><li>
8388
+ <a href="dispatchAiFallback.mjs.html">dispatchAiFallback.mjs</a>, <a href="dispatchAiFallback.mjs.html#line151">line 151</a>
8389
+ </li></ul></dd>
8390
+
8391
+
8392
+
8393
+
8394
+
8395
+
8396
+
8397
+
8398
+
8399
+
8400
+
8401
+
8402
+
8403
+
8404
+
8405
+
8406
+
8407
+
8408
+
8409
+
8410
+
8411
+
8412
+
8413
+
8414
+
8415
+
8416
+
8417
+
8418
+
8419
+
8420
+
8421
+ </dl>
8422
+
8423
+
8424
+
8425
+
8426
+
8427
+
8428
+
8429
+
8430
+
8431
+
8432
+
8433
+
8434
+
8435
+ <h5 class="h5-parameters">Parameters:</h5>
8436
+
8437
+
8438
+ <table class="params">
8439
+ <thead>
8440
+ <tr>
8441
+
8442
+ <th>Name</th>
8443
+
8444
+
8445
+ <th>Type</th>
8446
+
8447
+
8448
+
8449
+
8450
+
8451
+ <th class="last">Description</th>
8452
+ </tr>
8453
+ </thead>
8454
+
8455
+ <tbody>
8456
+
8457
+
8458
+ <tr>
8459
+
8460
+ <td class="name"><code>providers</code></td>
8461
+
8462
+
8463
+ <td class="type">
8464
+
8465
+
8466
+ <span class="param-type">Array</span>
8467
+
8468
+
8469
+
8470
+
8471
+ </td>
8472
+
8473
+
8474
+
8475
+
8476
+
8477
+ <td class="description last"><p>輸入供應商條目陣列</p></td>
8478
+ </tr>
8479
+
8480
+
8481
+
8482
+ <tr>
8483
+
8484
+ <td class="name"><code>state</code></td>
8485
+
8486
+
8487
+ <td class="type">
8488
+
8489
+
8490
+ <span class="param-type">Object</span>
8491
+
8492
+
8493
+
8494
+
8495
+ </td>
8496
+
8497
+
8498
+
8499
+
8500
+
8501
+ <td class="description last"><p>輸入狀態物件(取其cooling)</p></td>
8502
+ </tr>
8503
+
8504
+
8505
+
8506
+ <tr>
8507
+
8508
+ <td class="name"><code>cooldownMs</code></td>
8509
+
8510
+
8511
+ <td class="type">
8512
+
8513
+
8514
+ <span class="param-type">Number</span>
8515
+
8516
+
8517
+
8518
+
8519
+ </td>
8520
+
8521
+
8522
+
8523
+
8524
+
8525
+ <td class="description last"><p>輸入冷卻視窗毫秒正整數</p></td>
8526
+ </tr>
8527
+
8528
+
8529
+
8530
+ <tr>
8531
+
8532
+ <td class="name"><code>saveState</code></td>
8533
+
8534
+
8535
+ <td class="type">
8536
+
8537
+
8538
+ <span class="param-type">function</span>
8539
+
8540
+
8541
+
8542
+
8543
+ </td>
8544
+
8545
+
8546
+
8547
+
8548
+
8549
+ <td class="description last"><p>輸入狀態寫回函數</p></td>
8550
+ </tr>
8551
+
8552
+
8553
+ </tbody>
8554
+ </table>
8555
+
8556
+
8557
+
8558
+
8559
+
8560
+
8561
+
8562
+
8563
+
8564
+
8565
+
8566
+
8567
+
8568
+
8569
+
8570
+
8571
+ <h5 class="h5-returns">Returns:</h5>
8572
+
8573
+
8574
+ <div class="param-desc">
8575
+ <p>回傳重排後之條目陣列(active在前, 冷卻中殿後, 各自保持原相對順序)</p>
8576
+ </div>
8577
+
8578
+
8579
+
8580
+ <dl class="param-type">
8581
+ <dt>
8582
+ Type
8583
+ </dt>
8584
+ <dd>
8585
+
8586
+ <span class="param-type">Array</span>
7400
8587
 
7401
8588
 
7402
8589
 
@@ -8058,7 +9245,7 @@ await test()
8058
9245
  </td>
8059
9246
 
8060
9247
 
8061
- <td class="description last"><p>輸入前段名額規格陣列,各元素{ use, fallback, check?, maxRetries?, timeoutMs? }等(check可覆寫頂層檢核;除use/fallback/check外之鍵覆寫該名額呼叫設定)</p></td>
9248
+ <td class="description last"><p>輸入前段名額規格陣列,各元素{ use, fallback, check?, maxRetries?, timeoutMs? }等(check可覆寫頂層檢核;除use/fallback/check/meta外之鍵覆寫該名額呼叫設定;meta為保留鍵,呼叫端自有資訊掛此鍵保證永不轉傳下層)</p></td>
8062
9249
  </tr>
8063
9250
 
8064
9251
 
@@ -8094,7 +9281,7 @@ await test()
8094
9281
  </td>
8095
9282
 
8096
9283
 
8097
- <td class="description last"><p>輸入整合名額規格物件{ use, fallback, prompt?, check?, ... },prompt可為(candidates)=&gt;String自訂整合提示詞(省略用預設模板);check為終稿專屬檢核(終稿判準常與候選不同,如須含固定段落),未給則沿用頂層check</p></td>
9284
+ <td class="description last"><p>輸入整合名額規格物件{ use, fallback, prompt?, check?, ... },prompt可為(candidates)=&gt;String自訂整合提示詞(省略用預設模板);check為終稿專屬檢核(終稿判準常與候選不同,如須含固定段落),未給則沿用頂層check;meta為保留鍵同agents</p></td>
8098
9285
  </tr>
8099
9286
 
8100
9287
 
@@ -8334,7 +9521,7 @@ await test()
8334
9521
 
8335
9522
  <dt class="tag-source">Source:</dt>
8336
9523
  <dd class="tag-source"><ul class="dummy"><li>
8337
- <a href="wkf_runFanoutPipeline.mjs.html">wkf/runFanoutPipeline.mjs</a>, <a href="wkf_runFanoutPipeline.mjs.html#line69">line 69</a>
9524
+ <a href="wkf_runFanoutPipeline.mjs.html">wkf/runFanoutPipeline.mjs</a>, <a href="wkf_runFanoutPipeline.mjs.html#line76">line 76</a>
8338
9525
  </li></ul></dd>
8339
9526
 
8340
9527
 
@@ -8920,7 +10107,7 @@ await test()
8920
10107
 
8921
10108
  <dt class="tag-source">Source:</dt>
8922
10109
  <dd class="tag-source"><ul class="dummy"><li>
8923
- <a href="wkf_runRolePipeline.mjs.html">wkf/runRolePipeline.mjs</a>, <a href="wkf_runRolePipeline.mjs.html#line75">line 75</a>
10110
+ <a href="wkf_runRolePipeline.mjs.html">wkf/runRolePipeline.mjs</a>, <a href="wkf_runRolePipeline.mjs.html#line76">line 76</a>
8924
10111
  </li></ul></dd>
8925
10112
 
8926
10113
 
@@ -9195,7 +10382,7 @@ await test()
9195
10382
  </td>
9196
10383
 
9197
10384
 
9198
- <td class="description last"><p>輸入階段規格陣列,各元素{ id, use, fallback, prompt:(ctx)=&gt;String, check?, rawText?, maxRetries?, timeoutMs? }等</p></td>
10385
+ <td class="description last"><p>輸入階段規格陣列,各元素{ id, use, fallback, prompt:(ctx)=&gt;String, check?, rawText?, maxRetries?, timeoutMs? }等;meta為保留鍵,呼叫端自有資訊(分類、標籤)掛此鍵保證永不轉傳下層</p></td>
9199
10386
  </tr>
9200
10387
 
9201
10388
 
@@ -9310,7 +10497,7 @@ await test()
9310
10497
  <br class="clear">
9311
10498
 
9312
10499
  <footer>
9313
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri Aug 14 2026 15:11:06 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
10500
+ 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.
9314
10501
  </footer>
9315
10502
 
9316
10503
  <script>prettyPrint();</script>