w-dispatch-ai 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -35
- package/dist/w-dispatch-ai.umd.js +2 -2
- package/dist/w-dispatch-ai.umd.js.map +1 -1
- package/docs/WDispatchAi.mjs.html +8 -4
- package/docs/adapters.mjs.html +43 -7
- package/docs/dispatchAi.mjs.html +2 -2
- package/docs/dispatchAiFallback.mjs.html +42 -8
- package/docs/dispatchAiWkf.mjs.html +197 -0
- package/docs/dispatchAntigravity.mjs.html +2 -2
- package/docs/dispatchApiOpenaiCompat.mjs.html +516 -0
- package/docs/dispatchClaude.mjs.html +2 -2
- package/docs/dispatchCodex.mjs.html +2 -2
- package/docs/dispatchOpencode.mjs.html +2 -2
- package/docs/getCliArgs.mjs.html +2 -2
- package/docs/getErrorResult.mjs.html +2 -2
- package/docs/global.html +5768 -1469
- package/docs/index.html +2 -2
- package/docs/wkf_callAiWithFallback.mjs.html +282 -0
- package/docs/wkf_extractJsonLoose.mjs.html +180 -0
- package/docs/wkf_runFanout.mjs.html +227 -0
- package/docs/wkf_runFanoutPipeline.mjs.html +178 -0
- package/docs/wkf_runRolePipeline.mjs.html +195 -0
- package/g.mjs +41 -25
- package/package.json +1 -1
- package/src/WDispatchAi.mjs +6 -2
- package/src/adapters.mjs +41 -5
- package/src/dispatchAiFallback.mjs +40 -6
- package/src/dispatchAiWkf.mjs +125 -0
- package/src/dispatchApiOpenaiCompat.mjs +444 -0
- package/src/wkf/callAiWithFallback.mjs +210 -0
- package/src/wkf/extractJsonLoose.mjs +108 -0
- package/src/wkf/runFanout.mjs +155 -0
- package/src/wkf/runFanoutPipeline.mjs +106 -0
- package/src/wkf/runRolePipeline.mjs +123 -0
- package/test/tools/fakeServerForApiTest.mjs +151 -0
- package/test/unit-WDispatchAi.test.mjs +13 -6
- package/test/unit-adapters.test.mjs +5 -3
- package/test/unit-callAiWithFallback.test.mjs +146 -0
- package/test/unit-dispatchAi.test.mjs +1 -1
- package/test/unit-dispatchAiWkf.test.mjs +118 -0
- package/test/unit-dispatchApiOpenaiCompat.test.mjs +264 -0
- package/test/unit-extractJsonLoose.test.mjs +78 -0
- package/test/unit-runFanout.test.mjs +166 -0
- package/test/unit-runFanoutPipeline.test.mjs +86 -0
- package/test/unit-runRolePipeline.test.mjs +163 -0
|
@@ -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#dispatchAi">dispatchAi</a></li><li><a href="global.html#dispatchAiFallback">dispatchAiFallback</a></li><li><a href="global.html#dispatchAntigravity">dispatchAntigravity</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#getCliArgs">getCliArgs</a></li><li><a href="global.html#getErrorResult">getErrorResult</a></li><li><a href="global.html#isKeyIndependentFail">isKeyIndependentFail</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#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#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#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
|
|
|
@@ -75,6 +75,32 @@ import getErrorResult from './getErrorResult.mjs'
|
|
|
75
75
|
//
|
|
76
76
|
// 【時間預算】budgetMs限制整輪遞補的總時長, 剩餘預算會壓進每次呼叫的timeoutMs,
|
|
77
77
|
// 防止多家連續卡逾時而撞破外部排程的執行上限。
|
|
78
|
+
//
|
|
79
|
+
// ══ 條目id之設計規則(呼叫端負責, 本套件不解讀其內容) ══
|
|
80
|
+
//
|
|
81
|
+
// id於本套件內只有兩個用途: 游標的物件鍵(state.cursors[id])與日誌標籤
|
|
82
|
+
// (providerId、keyId=`${id}#${keyIndex}`)。不查表、不比對、無格式要求,
|
|
83
|
+
// 純粹是呼叫端的命名空間——故「什麼算同一個供應商」由呼叫端定義, 本套件不猜。
|
|
84
|
+
//
|
|
85
|
+
// ① id須能區分到「模型」而非只到「廠商」
|
|
86
|
+
// ✗ id:'claude' —— 日後要同時掛sonnet與opus就無法並存, 且日誌看不出用了哪個模型
|
|
87
|
+
// ✓ id:'claude:sonnet' / id:'claude:opus'
|
|
88
|
+
//
|
|
89
|
+
// ② 同一模型經不同路徑取得時, id須帶上路徑
|
|
90
|
+
// 同一個laguna可經Poolside官方REST、OpenRouter、opencode CLI三條路,
|
|
91
|
+
// 三者額度池與故障域各自獨立, 屬三個供應商:
|
|
92
|
+
// ✓ 'poolside:laguna-s-2.1' / 'or:poolside/laguna-s-2.1:free' / 'oc:poolside/poolside/laguna-s-2.1'
|
|
93
|
+
//
|
|
94
|
+
// ③ id務必給且務必唯一
|
|
95
|
+
// 未給時本套件回退為「陣列索引字串」——索引是位置不是身分, 日後於鏈中插入條目
|
|
96
|
+
// 會讓後續條目繼承他人的游標進度(輪替張冠李戴), 故正式設定一律明給。
|
|
97
|
+
// 兩個條目同id則共用同一游標且日誌無法區分, 屬設定錯誤。
|
|
98
|
+
//
|
|
99
|
+
// ④ 同一組金鑰用於多個條目時, 各條目游標獨立
|
|
100
|
+
// 例如agnes的CLI版與REST版共用同一批金鑰時, 兩者各自從游標起點輪替,
|
|
101
|
+
// 同一把金鑰可能被連續使用而另一把閒置(帳號額度未均攤)。
|
|
102
|
+
// 要讓它們共享輪替進度就給相同id(代價: 日誌無法區分兩者);
|
|
103
|
+
// 要能區分就分開命名(代價: 額度不均攤)。此取捨由呼叫端依實際需求決定。
|
|
78
104
|
|
|
79
105
|
|
|
80
106
|
//fallback層自用之設定鍵, 其餘鍵作為各attempt之共用預設原樣轉傳
|
|
@@ -153,7 +179,7 @@ function isKeyIndependentFail(r) {
|
|
|
153
179
|
* @param {String} prompt 輸入提示詞字串,一律以stdin傳入子進程
|
|
154
180
|
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
155
181
|
* @param {Array} opt.providers 輸入供應商條目物件陣列,順序即優先序。各條目除下列鍵外,其餘鍵(kind、model、exe、provider、config、sandbox、timeoutMs等)即該條目之opt原樣透傳對應轉接器
|
|
156
|
-
* @param {String} [opt.providers[].id=條目索引字串]
|
|
182
|
+
* @param {String} [opt.providers[].id=條目索引字串] 輸入群組識別字串,游標以此為鍵、亦為日誌標籤,本套件不解讀其內容。須區分到「模型」而非只到「廠商」(如'claude:sonnet'而非'claude'),同一模型經不同路徑取得時須帶上路徑(如'poolside:laguna-s-2.1'與'or:poolside/laguna-s-2.1:free'),且務必唯一。省略時回退為陣列索引字串——索引是位置不是身分,日後插入條目會令後續條目繼承他人游標進度,故正式設定一律明給。詳見本檔檔頭之id設計規則
|
|
157
183
|
* @param {Array} [opt.providers[].keys=[]] 輸入同一服務之多把API key字串陣列,逐次注入輪替(kind為opencode時須同時於條目給予provider),省略代表沿用CLI既有登入狀態之單一虛擬金鑰
|
|
158
184
|
* @param {Number} [opt.budgetMs=null] 輸入整輪遞補之時間上限毫秒正整數,剩餘預算會壓進每次呼叫之timeoutMs,預設null代表不限
|
|
159
185
|
* @param {Number} [opt.minAttemptMs=20000] 輸入單次嘗試之最低剩餘預算毫秒正整數,剩餘低於此值即停止嘗試回報budget exhausted,預設20000
|
|
@@ -173,21 +199,29 @@ function isKeyIndependentFail(r) {
|
|
|
173
199
|
* let r = await dispatchAiFallback('請只回覆兩個字:完成', {
|
|
174
200
|
* providers: [
|
|
175
201
|
* {
|
|
176
|
-
* id
|
|
202
|
+
* //id區分到模型且帶路徑: 同一模型經REST與CLI取得屬兩個供應商
|
|
203
|
+
* id: 'zen:deepseek-v4-flash-free',
|
|
204
|
+
* kind: 'api-openai-compat',
|
|
205
|
+
* baseURL: 'https://opencode.ai/zen/v1',
|
|
206
|
+
* model: 'deepseek-v4-flash-free',
|
|
207
|
+
* keys: ['sk-aaa', 'sk-bbb'], //多把金鑰, 某把失敗自動換下一把
|
|
208
|
+
* },
|
|
209
|
+
* {
|
|
210
|
+
* id: 'oc:opencode/deepseek-v4-flash-free', //同一模型之CLI版(有工具, 較慢)
|
|
177
211
|
* kind: 'opencode',
|
|
178
212
|
* model: 'opencode/deepseek-v4-flash-free',
|
|
179
213
|
* provider: 'opencode',
|
|
180
|
-
* keys: ['sk-aaa', 'sk-bbb'],
|
|
214
|
+
* keys: ['sk-aaa', 'sk-bbb'],
|
|
181
215
|
* timeoutMs: 180000,
|
|
182
216
|
* },
|
|
183
|
-
* { id: 'claude', kind: 'claude', model: 'sonnet' },
|
|
184
|
-
* { id: 'codex', kind: 'codex', model: 'gpt-5.6-luna', sandbox: 'read-only' },
|
|
217
|
+
* { id: 'claude:sonnet', kind: 'claude', model: 'sonnet' }, //以上全敗時遞補
|
|
218
|
+
* { id: 'codex:gpt-5.6-luna', kind: 'codex', model: 'gpt-5.6-luna', sandbox: 'read-only' },
|
|
185
219
|
* ],
|
|
186
220
|
* budgetMs: 600000,
|
|
187
221
|
* onEvent: (ev) => console.log(ev.type, ev.providerId, ev.keyIndex),
|
|
188
222
|
* })
|
|
189
223
|
* console.log(r.ok, r.providerId, r.keyIndex, r.tried.length)
|
|
190
|
-
* // => true 'deepseek' 0 1
|
|
224
|
+
* // => true 'zen:deepseek-v4-flash-free' 0 1
|
|
191
225
|
*
|
|
192
226
|
* }
|
|
193
227
|
* await test()
|
|
@@ -393,7 +427,7 @@ export default dispatchAiFallback
|
|
|
393
427
|
<br class="clear">
|
|
394
428
|
|
|
395
429
|
<footer>
|
|
396
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
430
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu Aug 13 2026 21:57:54 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
397
431
|
</footer>
|
|
398
432
|
|
|
399
433
|
<script>prettyPrint();</script>
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>dispatchAiWkf.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#WDispatchAi">WDispatchAi</a></li><li><a href="global.html#adapters">adapters</a></li><li><a href="global.html#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#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#runFanout">runFanout</a></li><li><a href="global.html#runFanoutPipeline">runFanoutPipeline</a></li><li><a href="global.html#runRolePipeline">runRolePipeline</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">dispatchAiWkf.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import get from 'lodash-es/get.js'
|
|
49
|
+
import isobj from 'wsemi/src/isobj.mjs'
|
|
50
|
+
import callAiWithFallback from './wkf/callAiWithFallback.mjs'
|
|
51
|
+
import runFanout from './wkf/runFanout.mjs'
|
|
52
|
+
import runRolePipeline from './wkf/runRolePipeline.mjs'
|
|
53
|
+
import runFanoutPipeline from './wkf/runFanoutPipeline.mjs'
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// dispatchAiWkf.mjs — 工作流工廠: 注入provider定義表與共用預設, 回傳綁定版API
|
|
57
|
+
//
|
|
58
|
+
// 【用途】專案端只需注入一次providers(名稱 → dispatchAiFallback條目)與共用設定
|
|
59
|
+
// (cwd、store、onEvent、timeoutMs…), 之後以名稱宣告工作流即可, 不必每次傳定義表。
|
|
60
|
+
//
|
|
61
|
+
// 【並行與游標之說明】多名額並行且共用同一store時, 游標read-modify-write
|
|
62
|
+
// 可能交錯, 造成金鑰輪替不完全均攤——只影響公平性、不影響正確性(每把金鑰仍有效),
|
|
63
|
+
// 故不加鎖; 要求嚴格均攤者可注入自帶佇列的store。
|
|
64
|
+
//
|
|
65
|
+
// 【本函數為同步工廠會throw】providers無效屬設定錯誤, 應於啟動期即失敗(fail fast),
|
|
66
|
+
// 與各dispatch函數「不reject」之約定不衝突——後者是執行期呼叫, 前者是組裝期設定。
|
|
67
|
+
//
|
|
68
|
+
// 【定義表之鍵名即條目id】該鍵名會成為dispatchAiFallback之條目id(游標鍵與日誌標籤),
|
|
69
|
+
// 須區分到「模型」而非只到「廠商」——鍵名取'claude'則日後無法同時掛sonnet與opus,
|
|
70
|
+
// 且日誌看不出實際用了哪個模型; 同一模型經不同路徑(REST/CLI/不同閘道)取得時,
|
|
71
|
+
// 額度池與故障域各自獨立而屬不同供應商, 鍵名須帶上路徑加以區分。
|
|
72
|
+
// 命名規則與取捨詳見dispatchAiFallback.mjs檔頭之「條目id之設計規則」。
|
|
73
|
+
//
|
|
74
|
+
// 【定義providers時如何選kind: CLI或API】判準是「該階段需不需要工具」:
|
|
75
|
+
// 需要讀本機檔案、grep、執行指令、抓網頁 → CLI類kind(opencode/claude/codex/antigravity);
|
|
76
|
+
// 純文字生成(素材皆已在prompt內) → API類kind(api-openai-compat), 免安裝免登入且較快。
|
|
77
|
+
// 工作流常態是混用: runFanout之候選生成與整合、runRolePipeline之審計修訂等
|
|
78
|
+
// 多屬純文字階段可走API; 唯獨需要實際翻閱專案檔案的階段必須走CLI。
|
|
79
|
+
// API類不支援工具且不會自建工具迴圈, 理由詳見adapters.mjs檔頭之選型判準區塊。
|
|
80
|
+
//
|
|
81
|
+
// 【工具無法向上層轉送】工作流各名額(如runFanout之agents)只是同行程之async函數呼叫,
|
|
82
|
+
// 非獨立agent; 模型回傳之tool_calls受會話束縛而無法外傳給上層agent(如hermes)代跑,
|
|
83
|
+
// 故「讓外殼提供工具給工作流內的模型使用」在本架構下不成立——需要工具就選CLI類kind。
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 建立AI工作流執行環境(工廠),注入provider定義表與共用預設後回傳綁定版API
|
|
88
|
+
*
|
|
89
|
+
* 特點:
|
|
90
|
+
* providers為名稱對dispatchAiFallback條目之定義表,之後各工作流以名稱宣告主模型與遞補鏈;
|
|
91
|
+
* defaults為共用呼叫設定,各工作流之callOpt與名額規格可逐項覆寫;
|
|
92
|
+
* 回傳之各函數皆不reject;本工廠為同步函數,providers無效時throw(設定錯誤應於啟動期即失敗)
|
|
93
|
+
*
|
|
94
|
+
* @param {Object} opt 輸入設定物件
|
|
95
|
+
* @param {Object} opt.providers 輸入provider定義表物件(名稱 → dispatchAiFallback條目:{ kind, model, keys, exe, provider, config, sandbox, extraArgs... })
|
|
96
|
+
* @param {Object} [opt.defaults={}] 輸入共用呼叫設定物件(cwd、store、onEvent、timeoutMs、budgetMs、maxRetries、promptPrefix、parse等),預設{}
|
|
97
|
+
* @returns {Object} 回傳綁定版API物件,內含callAi(單一名額呼叫)、runFanout(多開+整合)、runRolePipeline(串行角色鏈)、runFanoutPipeline(多開+整合+角色鏈)、providers(定義表原樣)
|
|
98
|
+
* @example
|
|
99
|
+
* //need cli in system PATH
|
|
100
|
+
*
|
|
101
|
+
* import dispatchAiWkf from './src/dispatchAiWkf.mjs'
|
|
102
|
+
*
|
|
103
|
+
* //定義表之鍵名即dispatchAiFallback之條目id, 須區分到模型而非只到廠商,
|
|
104
|
+
* //同一模型經不同路徑取得時須帶上路徑(REST與CLI屬兩個供應商, 能力與速度皆不同)
|
|
105
|
+
* let wkf = dispatchAiWkf({
|
|
106
|
+
* providers: {
|
|
107
|
+
* 'zen:deepseek-v4-flash-free': { kind: 'api-openai-compat', baseURL: 'https://opencode.ai/zen/v1', model: 'deepseek-v4-flash-free', keys: ['sk-xxx'] },
|
|
108
|
+
* 'oc:opencode/deepseek-v4-flash-free': { kind: 'opencode', model: 'opencode/deepseek-v4-flash-free', provider: 'opencode', keys: ['sk-xxx'] },
|
|
109
|
+
* 'claude:sonnet': { kind: 'claude', model: 'sonnet' },
|
|
110
|
+
* 'claude:opus': { kind: 'claude', model: 'opus' },
|
|
111
|
+
* 'codex:gpt-5.6-luna': { kind: 'codex', model: 'gpt-5.6-luna' },
|
|
112
|
+
* },
|
|
113
|
+
* defaults: { timeoutMs: 300000 },
|
|
114
|
+
* })
|
|
115
|
+
*
|
|
116
|
+
* let test = async () => {
|
|
117
|
+
*
|
|
118
|
+
* //單一名額: 主模型+遞補鏈
|
|
119
|
+
* let r1 = await wkf.callAi('只回覆JSON: {"a":1}', { spec: { use: 'zen:deepseek-v4-flash-free', fallback: ['claude:sonnet'] }, check: (j) => j.a === 1 })
|
|
120
|
+
* console.log(r1.ok, r1.json)
|
|
121
|
+
* // => true { a: 1 }
|
|
122
|
+
*
|
|
123
|
+
* //Fanout工作流: 多開執行+單點整合
|
|
124
|
+
* //純文字階段用REST(快), 需要讀專案檔案之階段才用CLI(有工具)
|
|
125
|
+
* let r2 = await wkf.runFanout({
|
|
126
|
+
* task: '分析並只回覆JSON: {"essence":"..."}',
|
|
127
|
+
* agents: [
|
|
128
|
+
* { use: 'zen:deepseek-v4-flash-free', fallback: ['claude:sonnet'] },
|
|
129
|
+
* { use: 'claude:sonnet' },
|
|
130
|
+
* ],
|
|
131
|
+
* integrate: { use: 'codex:gpt-5.6-luna' },
|
|
132
|
+
* check: (j) => !!j.essence,
|
|
133
|
+
* })
|
|
134
|
+
* console.log(r2.ok, r2.integrated)
|
|
135
|
+
* // => true true
|
|
136
|
+
*
|
|
137
|
+
* }
|
|
138
|
+
* await test()
|
|
139
|
+
* .catch((err) => {
|
|
140
|
+
* console.log(err)
|
|
141
|
+
* })
|
|
142
|
+
*
|
|
143
|
+
*/
|
|
144
|
+
function dispatchAiWkf(opt = {}) {
|
|
145
|
+
let providers = get(opt, 'providers', null)
|
|
146
|
+
if (!isobj(providers)) {
|
|
147
|
+
throw new Error('dispatchAiWkf: opt.providers must be an object (name → provider entry)')
|
|
148
|
+
}
|
|
149
|
+
let defaults = get(opt, 'defaults', null)
|
|
150
|
+
if (!isobj(defaults)) {
|
|
151
|
+
defaults = {}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
providers,
|
|
156
|
+
|
|
157
|
+
//單一名額呼叫: callAi(prompt, { spec:{use,fallback}, check, ... })
|
|
158
|
+
callAi: (prompt, o = {}) => callAiWithFallback(prompt, { ...defaults, ...o, providers }),
|
|
159
|
+
|
|
160
|
+
//Fanout工作流: runFanout({ task, agents, integrate, check, schema, minCandidates, callOpt? })
|
|
161
|
+
runFanout: (o = {}) => runFanout({ ...o, providers, callOpt: { ...defaults, ...get(o, 'callOpt', {}) } }),
|
|
162
|
+
|
|
163
|
+
//RolePipeline工作流: runRolePipeline({ input, stages, callOpt? })
|
|
164
|
+
runRolePipeline: (o = {}) => runRolePipeline({ ...o, providers, callOpt: { ...defaults, ...get(o, 'callOpt', {}) } }),
|
|
165
|
+
|
|
166
|
+
//FanoutPipeline工作流: runFanoutPipeline({ task, agents, integrate, stages, check, schema, callOpt? })
|
|
167
|
+
runFanoutPipeline: (o = {}) => runFanoutPipeline({ ...o, providers, callOpt: { ...defaults, ...get(o, 'callOpt', {}) } }),
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
export default dispatchAiWkf
|
|
173
|
+
</code></pre>
|
|
174
|
+
</article>
|
|
175
|
+
</section>
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<br class="clear">
|
|
185
|
+
|
|
186
|
+
<footer>
|
|
187
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu Aug 13 2026 21:57:54 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
188
|
+
</footer>
|
|
189
|
+
|
|
190
|
+
<script>prettyPrint();</script>
|
|
191
|
+
<script src="scripts/polyfill.js"></script>
|
|
192
|
+
<script src="scripts/linenumber.js"></script>
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
</body>
|
|
197
|
+
</html>
|
|
@@ -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#dispatchAi">dispatchAi</a></li><li><a href="global.html#dispatchAiFallback">dispatchAiFallback</a></li><li><a href="global.html#dispatchAntigravity">dispatchAntigravity</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#getCliArgs">getCliArgs</a></li><li><a href="global.html#getErrorResult">getErrorResult</a></li><li><a href="global.html#isKeyIndependentFail">isKeyIndependentFail</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#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#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#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
|
|
|
@@ -251,7 +251,7 @@ export default dispatchAntigravity
|
|
|
251
251
|
<br class="clear">
|
|
252
252
|
|
|
253
253
|
<footer>
|
|
254
|
-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on
|
|
254
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Thu Aug 13 2026 21:57:54 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
255
255
|
</footer>
|
|
256
256
|
|
|
257
257
|
<script>prettyPrint();</script>
|