w-dispatch-ai 1.0.6 → 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 +31 -2
  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 +182 -58
  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 +1336 -109
  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 +12 -9
  25. package/docs/wkf_runFanoutPipeline.mjs.html +15 -19
  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 +180 -56
  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 +10 -7
  41. package/src/wkf/runFanoutPipeline.mjs +13 -17
  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 +232 -0
  47. package/test/unit-dispatchApiOpenaiCompat.test.mjs +67 -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 +60 -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#line189">line 189</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,23 +3041,16 @@ await test()
2631
3041
  </tr>
2632
3042
 
2633
3043
 
2634
- </tbody>
2635
- </table>
2636
-
2637
- </td>
2638
- </tr>
2639
-
2640
-
2641
3044
 
2642
3045
  <tr>
2643
3046
 
2644
- <td class="name"><code>budgetMs</code></td>
3047
+ <td class="name"><code>meta</code></td>
2645
3048
 
2646
3049
 
2647
3050
  <td class="type">
2648
3051
 
2649
3052
 
2650
- <span class="param-type">Number</span>
3053
+ <span class="param-type">*</span>
2651
3054
 
2652
3055
 
2653
3056
 
@@ -2669,19 +3072,24 @@ await test()
2669
3072
 
2670
3073
  <td class="default">
2671
3074
 
2672
- <code>null</code>
2673
-
2674
3075
  </td>
2675
3076
 
2676
3077
 
2677
- <td class="description last"><p>輸入整輪遞補之時間上限毫秒正整數,剩餘預算會壓進每次呼叫之timeoutMs,預設null代表不限</p></td>
3078
+ <td class="description last"><p>輸入呼叫端自有資訊(分類、標籤、註記),保留鍵保證永不轉傳對應轉接器——條目其餘鍵一律原樣轉傳,自有欄位放此鍵可與轉傳機制永久絕緣,預設undefined</p></td>
3079
+ </tr>
3080
+
3081
+
3082
+ </tbody>
3083
+ </table>
3084
+
3085
+ </td>
2678
3086
  </tr>
2679
3087
 
2680
3088
 
2681
3089
 
2682
3090
  <tr>
2683
3091
 
2684
- <td class="name"><code>minAttemptMs</code></td>
3092
+ <td class="name"><code>budgetMs</code></td>
2685
3093
 
2686
3094
 
2687
3095
  <td class="type">
@@ -2709,25 +3117,25 @@ await test()
2709
3117
 
2710
3118
  <td class="default">
2711
3119
 
2712
- <code>20000</code>
3120
+ <code>null</code>
2713
3121
 
2714
3122
  </td>
2715
3123
 
2716
3124
 
2717
- <td class="description last"><p>輸入單次嘗試之最低剩餘預算毫秒正整數,剩餘低於此值即停止嘗試回報budget exhausted,預設20000</p></td>
3125
+ <td class="description last"><p>輸入整輪遞補之時間上限毫秒正整數,剩餘預算會壓進每次呼叫之timeoutMs,預設null代表不限</p></td>
2718
3126
  </tr>
2719
3127
 
2720
3128
 
2721
3129
 
2722
3130
  <tr>
2723
3131
 
2724
- <td class="name"><code>store</code></td>
3132
+ <td class="name"><code>minAttemptMs</code></td>
2725
3133
 
2726
3134
 
2727
3135
  <td class="type">
2728
3136
 
2729
3137
 
2730
- <span class="param-type">Object</span>
3138
+ <span class="param-type">Number</span>
2731
3139
 
2732
3140
 
2733
3141
 
@@ -2749,25 +3157,25 @@ await test()
2749
3157
 
2750
3158
  <td class="default">
2751
3159
 
2752
- <code>null</code>
3160
+ <code>20000</code>
2753
3161
 
2754
3162
  </td>
2755
3163
 
2756
3164
 
2757
- <td class="description last"><p>輸入狀態持久化物件{get:()=&gt;state,set:(state)=&gt;{}},state內含cursors(逐群組游標),省略代表用行程內記憶體(跨呼叫有效,重啟歸零)。假定單行程序列調用,並行請自行加鎖</p></td>
3165
+ <td class="description last"><p>輸入單次嘗試之最低剩餘預算毫秒正整數,剩餘低於此值即停止嘗試回報budget exhausted,預設20000</p></td>
2758
3166
  </tr>
2759
3167
 
2760
3168
 
2761
3169
 
2762
3170
  <tr>
2763
3171
 
2764
- <td class="name"><code>onEvent</code></td>
3172
+ <td class="name"><code>store</code></td>
2765
3173
 
2766
3174
 
2767
3175
  <td class="type">
2768
3176
 
2769
3177
 
2770
- <span class="param-type">function</span>
3178
+ <span class="param-type">Object</span>
2771
3179
 
2772
3180
 
2773
3181
 
@@ -2794,7 +3202,205 @@ await test()
2794
3202
  </td>
2795
3203
 
2796
3204
 
2797
- <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>
3205
+ <td class="description last"><p>輸入狀態持久化物件{get:()=&gt;state,set:(state)=&gt;{}}state內含cursors(逐群組游標)與cooling(供應商冷卻時間戳,僅cooldownMs&gt;0時使用),省略代表用行程內記憶體(跨呼叫有效,重啟歸零)。假定單行程序列調用,並行請自行加鎖</p></td>
3206
+ </tr>
3207
+
3208
+
3209
+
3210
+ <tr>
3211
+
3212
+ <td class="name"><code>cooldownMs</code></td>
3213
+
3214
+
3215
+ <td class="type">
3216
+
3217
+
3218
+ <span class="param-type">Number</span>
3219
+
3220
+
3221
+
3222
+
3223
+ </td>
3224
+
3225
+
3226
+ <td class="attributes">
3227
+
3228
+ &lt;optional><br>
3229
+
3230
+
3231
+
3232
+
3233
+
3234
+ </td>
3235
+
3236
+
3237
+
3238
+ <td class="default">
3239
+
3240
+ <code>0</code>
3241
+
3242
+ </td>
3243
+
3244
+
3245
+ <td class="description last"><p>輸入供應商冷卻視窗毫秒非負整數,&gt;0啟用:條目(限有明給id者)遭遇限流(HTTP 429,僅api類可偵測;CLI類可經coolDetect注入判定)或逾時(TIMEOUT開頭)後,於冷卻視窗內之後續呼叫中被移至鏈尾——只降序不移除,前面全敗時仍會被嘗試,任一次成功立即解除;注意啟用時「providers順序即優先序」會被暫時重排,此即本機制之目的;預設0代表不啟用</p></td>
3246
+ </tr>
3247
+
3248
+
3249
+
3250
+ <tr>
3251
+
3252
+ <td class="name"><code>coolDetect</code></td>
3253
+
3254
+
3255
+ <td class="type">
3256
+
3257
+
3258
+ <span class="param-type">function</span>
3259
+
3260
+
3261
+
3262
+
3263
+ </td>
3264
+
3265
+
3266
+ <td class="attributes">
3267
+
3268
+ &lt;optional><br>
3269
+
3270
+
3271
+
3272
+
3273
+
3274
+ </td>
3275
+
3276
+
3277
+
3278
+ <td class="default">
3279
+
3280
+ <code>null</code>
3281
+
3282
+ </td>
3283
+
3284
+
3285
+ <td class="description last"><p>輸入冷卻觸發判定函數(r)=&gt;Boolean,收完整失敗結果物件(含stdout、stderr、code、error),回傳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>
2798
3404
  </tr>
2799
3405
 
2800
3406
 
@@ -2948,7 +3554,7 @@ await test()
2948
3554
 
2949
3555
 
2950
3556
  <div class="param-desc">
2951
- <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>
2952
3558
  </div>
2953
3559
 
2954
3560
 
@@ -4037,7 +4643,7 @@ prompt走HTTP body,無命令列長度限制;
4037
4643
 
4038
4644
  <dt class="tag-source">Source:</dt>
4039
4645
  <dd class="tag-source"><ul class="dummy"><li>
4040
- <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>
4041
4647
  </li></ul></dd>
4042
4648
 
4043
4649
 
@@ -4668,7 +5274,7 @@ await test()
4668
5274
 
4669
5275
 
4670
5276
  <div class="param-desc">
4671
- <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>
4672
5278
  </div>
4673
5279
 
4674
5280
 
@@ -7042,7 +7648,7 @@ console.log(getCliArgs('-p', null, 123, ['', '--verbose']))
7042
7648
 
7043
7649
 
7044
7650
 
7045
- <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>
7046
7652
 
7047
7653
 
7048
7654
 
@@ -7061,7 +7667,7 @@ console.log(getCliArgs('-p', null, 123, ['', '--verbose']))
7061
7667
 
7062
7668
  <dt class="tag-source">Source:</dt>
7063
7669
  <dd class="tag-source"><ul class="dummy"><li>
7064
- <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>
7065
7671
  </li></ul></dd>
7066
7672
 
7067
7673
 
@@ -7111,7 +7717,7 @@ console.log(getCliArgs('-p', null, 123, ['', '--verbose']))
7111
7717
  <pre class="prettyprint"><code>import getErrorResult from './src/getErrorResult.mjs'
7112
7718
 
7113
7719
  console.log(getErrorResult('prompt must be a non-empty string'))
7114
- // => { 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 }
7115
7721
 
7116
7722
  console.log(getErrorResult(null).error)
7117
7723
  // => 'unknown error'</code></pre>
@@ -7132,8 +7738,12 @@ console.log(getErrorResult(null).error)
7132
7738
  <th>Type</th>
7133
7739
 
7134
7740
 
7741
+ <th>Attributes</th>
7742
+
7135
7743
 
7136
7744
 
7745
+ <th>Default</th>
7746
+
7137
7747
 
7138
7748
  <th class="last">Description</th>
7139
7749
  </tr>
@@ -7158,13 +7768,65 @@ console.log(getErrorResult(null).error)
7158
7768
  </td>
7159
7769
 
7160
7770
 
7771
+ <td class="attributes">
7772
+
7773
+
7774
+
7775
+
7776
+
7777
+ </td>
7778
+
7161
7779
 
7162
7780
 
7781
+ <td class="default">
7782
+
7783
+ </td>
7784
+
7163
7785
 
7164
7786
  <td class="description last"><p>輸入錯誤訊息字串</p></td>
7165
7787
  </tr>
7166
7788
 
7167
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
+
7168
7830
  </tbody>
7169
7831
  </table>
7170
7832
 
@@ -7187,7 +7849,7 @@ console.log(getErrorResult(null).error)
7187
7849
 
7188
7850
 
7189
7851
  <div class="param-desc">
7190
- <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>
7191
7853
  </div>
7192
7854
 
7193
7855
 
@@ -7214,7 +7876,7 @@ console.log(getErrorResult(null).error)
7214
7876
 
7215
7877
 
7216
7878
 
7217
- <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>
7218
7880
 
7219
7881
 
7220
7882
 
@@ -7224,13 +7886,16 @@ console.log(getErrorResult(null).error)
7224
7886
  <dl class="details">
7225
7887
 
7226
7888
  <dt class="tag-description">Description:</dt>
7227
- <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>
7228
7893
 
7229
7894
 
7230
7895
 
7231
7896
  <dt class="tag-source">Source:</dt>
7232
7897
  <dd class="tag-source"><ul class="dummy"><li>
7233
- <a href="dispatchAiFallback.mjs.html">dispatchAiFallback.mjs</a>, <a href="dispatchAiFallback.mjs.html#line85">line 85</a>
7898
+ <a href="getErrorType.mjs.html">getErrorType.mjs</a>, <a href="getErrorType.mjs.html#line53">line 53</a>
7234
7899
  </li></ul></dd>
7235
7900
 
7236
7901
 
@@ -7275,6 +7940,20 @@ console.log(getErrorResult(null).error)
7275
7940
 
7276
7941
 
7277
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
+
7278
7957
 
7279
7958
 
7280
7959
  <h5 class="h5-parameters">Parameters:</h5>
@@ -7319,7 +7998,7 @@ console.log(getErrorResult(null).error)
7319
7998
 
7320
7999
 
7321
8000
 
7322
- <td class="description last"><p>輸入dispatchAi失敗結果物件</p></td>
8001
+ <td class="description last"><p>輸入失敗結果物件(取其error欄位判別)</p></td>
7323
8002
  </tr>
7324
8003
 
7325
8004
 
@@ -7345,7 +8024,7 @@ console.log(getErrorResult(null).error)
7345
8024
 
7346
8025
 
7347
8026
  <div class="param-desc">
7348
- <p>回傳是否應整組跳過之布林值</p>
8027
+ <p>回傳errorType字串</p>
7349
8028
  </div>
7350
8029
 
7351
8030
 
@@ -7356,7 +8035,555 @@ console.log(getErrorResult(null).error)
7356
8035
  </dt>
7357
8036
  <dd>
7358
8037
 
7359
- <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>
7360
8587
 
7361
8588
 
7362
8589
 
@@ -8018,7 +9245,7 @@ await test()
8018
9245
  </td>
8019
9246
 
8020
9247
 
8021
- <td class="description last"><p>輸入前段名額規格陣列,各元素{ use, fallback, maxRetries?, timeoutMs? }等(use/fallback外之鍵覆寫該名額呼叫設定)</p></td>
9248
+ <td class="description last"><p>輸入前段名額規格陣列,各元素{ use, fallback, check?, maxRetries?, timeoutMs? }等(check可覆寫頂層檢核;除use/fallback/check/meta外之鍵覆寫該名額呼叫設定;meta為保留鍵,呼叫端自有資訊掛此鍵保證永不轉傳下層)</p></td>
8022
9249
  </tr>
8023
9250
 
8024
9251
 
@@ -8054,7 +9281,7 @@ await test()
8054
9281
  </td>
8055
9282
 
8056
9283
 
8057
- <td class="description last"><p>輸入整合名額規格物件{ use, fallback, prompt?, ... },prompt可為(candidates)=&gt;String自訂整合提示詞,省略用預設模板</p></td>
9284
+ <td class="description last"><p>輸入整合名額規格物件{ use, fallback, prompt?, check?, ... },prompt可為(candidates)=&gt;String自訂整合提示詞(省略用預設模板);check為終稿專屬檢核(終稿判準常與候選不同,如須含固定段落),未給則沿用頂層check;meta為保留鍵同agents</p></td>
8058
9285
  </tr>
8059
9286
 
8060
9287
 
@@ -8094,7 +9321,7 @@ await test()
8094
9321
  </td>
8095
9322
 
8096
9323
 
8097
- <td class="description last"><p>輸入候選與終稿共用之檢核函數(json)=&gt;Boolean,預設null</p></td>
9324
+ <td class="description last"><p>輸入檢核函數(json)=&gt;Boolean,作為候選與終稿之共用預設,名額規格與integrate可各自帶check覆寫,預設null</p></td>
8098
9325
  </tr>
8099
9326
 
8100
9327
 
@@ -8294,7 +9521,7 @@ await test()
8294
9521
 
8295
9522
  <dt class="tag-source">Source:</dt>
8296
9523
  <dd class="tag-source"><ul class="dummy"><li>
8297
- <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>
8298
9525
  </li></ul></dd>
8299
9526
 
8300
9527
 
@@ -8679,7 +9906,7 @@ await test()
8679
9906
  </td>
8680
9907
 
8681
9908
 
8682
- <td class="description last"><p>輸入前段共用檢核函數,後段各階段自帶check,預設null</p></td>
9909
+ <td class="description last"><p>輸入前段共用檢核函數(前段名額規格與integrate可各自帶check覆寫,同runFanout),後段各階段自帶check,預設null</p></td>
8683
9910
  </tr>
8684
9911
 
8685
9912
 
@@ -8880,7 +10107,7 @@ await test()
8880
10107
 
8881
10108
  <dt class="tag-source">Source:</dt>
8882
10109
  <dd class="tag-source"><ul class="dummy"><li>
8883
- <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>
8884
10111
  </li></ul></dd>
8885
10112
 
8886
10113
 
@@ -9155,7 +10382,7 @@ await test()
9155
10382
  </td>
9156
10383
 
9157
10384
 
9158
- <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>
9159
10386
  </tr>
9160
10387
 
9161
10388
 
@@ -9270,7 +10497,7 @@ await test()
9270
10497
  <br class="clear">
9271
10498
 
9272
10499
  <footer>
9273
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri Aug 14 2026 12:30:07 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.
9274
10501
  </footer>
9275
10502
 
9276
10503
  <script>prettyPrint();</script>