w-dispatch-ai 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -6
- 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 +5 -3
- package/docs/dispatchAi.mjs.html +2 -2
- package/docs/dispatchAiFallback.mjs.html +406 -0
- package/docs/dispatchAntigravity.mjs.html +264 -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 +1600 -6
- package/docs/index.html +2 -2
- package/g.mjs +46 -2
- package/package.json +1 -1
- package/src/WDispatchAi.mjs +6 -2
- package/src/adapters.mjs +3 -1
- package/src/dispatchAiFallback.mjs +334 -0
- package/src/dispatchAntigravity.mjs +192 -0
- package/test/tools/fakeCliForTest.mjs +8 -0
- package/test/unit-WDispatchAi.test.mjs +13 -6
- package/test/unit-adapters.test.mjs +5 -3
- package/test/unit-dispatchAi.test.mjs +7 -3
- package/test/unit-dispatchAiFallback.test.mjs +422 -0
- package/test/unit-dispatchAntigravity.test.mjs +173 -0
package/README.md
CHANGED
|
@@ -22,18 +22,22 @@ Note:
|
|
|
22
22
|
- `dispatchClaude` needs [Claude Code CLI](https://claude.com/claude-code) (`claude`) in system PATH, and uses its existing login state.
|
|
23
23
|
- `dispatchCodex` needs [OpenAI Codex CLI](https://github.com/openai/codex) (`codex`) in system PATH, and uses its existing login state.
|
|
24
24
|
- `dispatchOpencode` needs [opencode CLI](https://opencode.ai/) (`opencode`) in system PATH. Unlike the other two, it accepts a per-call `key`+`provider`, injected through `OPENCODE_AUTH_CONTENT`, so multiple api keys can be rotated without rewriting `auth.json`.
|
|
25
|
-
-
|
|
25
|
+
- `dispatchAntigravity` needs [Google Antigravity CLI](https://antigravity.google/) (`agy`, not `antigravity`) in system PATH, and uses its existing OAuth login state (first login requires an interactive desktop session). Unlike the other three, agy takes the prompt via the `--print` flag instead of stdin, so the prompt is capped at 30000 chars (Windows command line limit); longer prompts return an error result.
|
|
26
|
+
- Each adapter also accepts an `exe` option to pin the executable path, useful when the CLI is not in PATH (e.g. Windows Task Scheduler environments).
|
|
27
|
+
- For the other three adapters the prompt is always passed through stdin, never as a positional argument, so a prompt of tens of thousands of characters will not cause `ENAMETOOLONG`.
|
|
26
28
|
- All functions never reject. Success or failure is reported by the `ok` and `error` fields of the result object.
|
|
27
29
|
- **Security**: `dispatchClaude` passes `--dangerously-skip-permissions` by default, so the non-interactive `-p` mode will not hang on permission prompts. If the prompt embeds untrusted content (e.g. a web page to summarize), instructions inside that content would also run without the permission gate. Pass `skipPermissions: false` to keep the CLI permission gate.
|
|
28
30
|
|
|
29
31
|
#### Functions:
|
|
30
32
|
| function | description |
|
|
31
33
|
| --- | --- |
|
|
32
|
-
| `dispatchAi(kind, prompt, opt)` | dispatch to the adapter of `kind`, one of `'opencode'`、`'claude'`、`'codex'` |
|
|
34
|
+
| `dispatchAi(kind, prompt, opt)` | dispatch to the adapter of `kind`, one of `'opencode'`、`'claude'`、`'codex'`、`'antigravity'` |
|
|
35
|
+
| `dispatchAiFallback(prompt, opt)` | call ai with an ordered provider list, auto rotating keys within a group and falling back to the next group |
|
|
33
36
|
| `dispatchOpencode(prompt, opt)` | call an ai model by opencode cli, supports per-call api key and provider config |
|
|
34
37
|
| `dispatchClaude(prompt, opt)` | call a claude model by claude code cli |
|
|
35
38
|
| `dispatchCodex(prompt, opt)` | call a gpt model by openai codex cli |
|
|
36
|
-
| `
|
|
39
|
+
| `dispatchAntigravity(prompt, opt)` | call an ai model by google antigravity cli (`agy`), a multi-model gateway (gemini, claude, gpt-oss) |
|
|
40
|
+
| `KINDS` | array of available kinds, `['opencode', 'claude', 'codex', 'antigravity']` |
|
|
37
41
|
|
|
38
42
|
#### Example:
|
|
39
43
|
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-dispatch-ai/blob/master/g.mjs)]
|
|
@@ -67,7 +71,7 @@ let test = async () => {
|
|
|
67
71
|
|
|
68
72
|
//可用之AI供應商種類
|
|
69
73
|
console.log('KINDS:', wdi.KINDS)
|
|
70
|
-
// => KINDS: [ 'opencode', 'claude', 'codex' ]
|
|
74
|
+
// => KINDS: [ 'opencode', 'claude', 'codex', 'antigravity' ]
|
|
71
75
|
|
|
72
76
|
let prompt = '請只回覆兩個字:完成,不要有任何其他文字'
|
|
73
77
|
|
|
@@ -86,6 +90,11 @@ let test = async () => {
|
|
|
86
90
|
console.log('opencode:', r3.ok, r3.stdout.trim())
|
|
87
91
|
// => opencode: true 完成
|
|
88
92
|
|
|
93
|
+
//以antigravity CLI(agy)呼叫, prompt走--print旗標(長度上限30000字元), model須為`agy models`第一欄slug
|
|
94
|
+
let r3b = await wdi.dispatchAntigravity(prompt, { model: 'gemini-3.6-flash-low' })
|
|
95
|
+
console.log('antigravity:', r3b.ok, r3b.stdout.trim())
|
|
96
|
+
// => antigravity: true 完成
|
|
97
|
+
|
|
89
98
|
//以供應商條目輪替, 一個條目即一組(kind, model, 可選的key與provider與config), 輪到誰就用誰的CLI與模型
|
|
90
99
|
//opencode支援逐次注入金鑰, 故同一provider之多把金鑰可各成一個條目
|
|
91
100
|
let items = [
|
|
@@ -94,6 +103,7 @@ let test = async () => {
|
|
|
94
103
|
{ kind: 'opencode', model: 'opencode/deepseek-v4-flash-free', provider: 'opencode', key: opencodeKeys[0], timeoutMs: 180000 },
|
|
95
104
|
{ kind: 'opencode', model: 'opencode/deepseek-v4-flash-free', provider: 'opencode', key: opencodeKeys[1], timeoutMs: 180000 },
|
|
96
105
|
{ kind: 'opencode', model: 'agnes-ai/agnes-2.0-flash', provider: 'agnes-ai', key: agnesKeys[0], config: configAgnes, timeoutMs: 180000 },
|
|
106
|
+
{ kind: 'antigravity', model: 'gemini-3.6-flash-low' },
|
|
97
107
|
]
|
|
98
108
|
for (let item of items) {
|
|
99
109
|
let r = await wdi.dispatchAi(item.kind, prompt, item)
|
|
@@ -103,12 +113,13 @@ let test = async () => {
|
|
|
103
113
|
// => dispatchAi opencode/deepseek-v4-flash-free: true 完成
|
|
104
114
|
// => dispatchAi opencode/deepseek-v4-flash-free: true 完成
|
|
105
115
|
// => dispatchAi agnes-ai/agnes-2.0-flash: true 完成
|
|
116
|
+
// => dispatchAi gemini-3.6-flash-low: true 完成
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
//未知供應商回傳error結果物件, 不會reject
|
|
109
120
|
let r4 = await wdi.dispatchAi('gemini', prompt)
|
|
110
121
|
console.log('invalid kind:', r4.ok, r4.error)
|
|
111
|
-
// => invalid kind: false unknown ai kind: "gemini" (available: opencode, claude, codex)
|
|
122
|
+
// => invalid kind: false unknown ai kind: "gemini" (available: opencode, claude, codex, antigravity)
|
|
112
123
|
|
|
113
124
|
//prompt非有效字串亦回傳error結果物件
|
|
114
125
|
let r5 = await wdi.dispatchClaude('')
|
|
@@ -124,6 +135,43 @@ let test = async () => {
|
|
|
124
135
|
console.log('invalid key:', r6.ok, r6.code, r6.error, r6.stderr.includes('Invalid API key'))
|
|
125
136
|
// => invalid key: false 1 Exit code 1 true
|
|
126
137
|
|
|
138
|
+
//多供應商自動遞補: providers順序即優先序, 組內keys以游標輪替
|
|
139
|
+
//此例第1把金鑰無效 → 自動換組內下一把成功; 若整組用盡會遞補下一組(claude), 再失敗遞補codex
|
|
140
|
+
let r7 = await wdi.dispatchAiFallback(prompt, {
|
|
141
|
+
providers: [
|
|
142
|
+
{
|
|
143
|
+
id: 'deepseek',
|
|
144
|
+
kind: 'opencode',
|
|
145
|
+
model: 'opencode/deepseek-v4-flash-free',
|
|
146
|
+
provider: 'opencode',
|
|
147
|
+
keys: ['sk-invalid-key-demo', opencodeKeys[0]], //第1把無效, 示範組內輪替
|
|
148
|
+
timeoutMs: 180000,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: 'agnes',
|
|
152
|
+
kind: 'opencode',
|
|
153
|
+
model: 'agnes-ai/agnes-2.0-flash',
|
|
154
|
+
provider: 'agnes-ai',
|
|
155
|
+
keys: agnesKeys,
|
|
156
|
+
config: configAgnes, //第三方provider須另給定義
|
|
157
|
+
timeoutMs: 180000,
|
|
158
|
+
},
|
|
159
|
+
{ id: 'claude', kind: 'claude', model: 'sonnet' },
|
|
160
|
+
{ id: 'codex', kind: 'codex', model: 'gpt-5.6-luna', sandbox: 'read-only' },
|
|
161
|
+
{ id: 'antigravity', kind: 'antigravity', model: 'gemini-3.6-flash-low' },
|
|
162
|
+
],
|
|
163
|
+
budgetMs: 600000,
|
|
164
|
+
onEvent: (ev) => console.log(' event:', ev.type, ev.keyId, ev.error || ''),
|
|
165
|
+
})
|
|
166
|
+
console.log('fallback:', r7.ok, r7.providerId, r7.keyIndex, r7.stdout.trim())
|
|
167
|
+
console.log('tried:', r7.tried.map((x) => `${x.keyId}:${x.outcome}`).join(', '))
|
|
168
|
+
// => event: try deepseek#0
|
|
169
|
+
// => event: next-key deepseek#0 Exit code 1
|
|
170
|
+
// => event: try deepseek#1
|
|
171
|
+
// => event: ok deepseek#1
|
|
172
|
+
// => fallback: true deepseek 1 完成
|
|
173
|
+
// => tried: deepseek#0:next-key, deepseek#1:ok
|
|
174
|
+
|
|
127
175
|
}
|
|
128
176
|
await test()
|
|
129
177
|
.catch((err) => {
|
|
@@ -162,6 +210,43 @@ await test()
|
|
|
162
210
|
| --- | --- | --- | --- |
|
|
163
211
|
| `sandbox` | String | `'workspace-write'` | 沙箱模式,可用`'read-only'`、`'workspace-write'`、`'danger-full-access'` |
|
|
164
212
|
|
|
213
|
+
#### Options only for dispatchAntigravity:
|
|
214
|
+
| key | type | default | description |
|
|
215
|
+
| --- | --- | --- | --- |
|
|
216
|
+
| `model` | String | `''` | 須為`agy models`**第一欄之slug**(如`gemini-3.6-flash-low`);agy錯誤訊息列出的是顯示名稱而非slug,勿照抄 |
|
|
217
|
+
| `effort` | String | `''` | `'low'`、`'medium'`、`'high'`,需agy>=1.1.11;建議搭配不帶檔位之基礎slug(如`gemini-3.1-pro`),與帶檔位slug併用且檔位不一致時agy回conflicts錯誤 |
|
|
218
|
+
| `skipPermissions` | Boolean | `true` | 是否帶`--dangerously-skip-permissions`旗標 |
|
|
219
|
+
| `printTimeout` | String | 由`timeoutMs`推導 | agy自身等待上限(如`'10m'`、`'570s'`),預設`timeoutMs`扣30秒緩衝(下限30秒),令CLI先於外層逾時而回報自身錯誤訊息 |
|
|
220
|
+
| `addDirs` | Array | `[]` | 加入workspace之目錄字串陣列,逐項展開為`--add-dir` |
|
|
221
|
+
| `timeoutMs` | Integer | `300000` | agy為agent型CLI,預設較其他轉接器長 |
|
|
222
|
+
|
|
223
|
+
注意:agy之prompt走`--print`旗標而非stdin(agy介面如此),故prompt長度上限30000字元,超過回傳錯誤結果物件(不reject)。
|
|
224
|
+
|
|
225
|
+
#### Options for dispatchAiFallback:
|
|
226
|
+
| key | type | default | description |
|
|
227
|
+
| --- | --- | --- | --- |
|
|
228
|
+
| `providers` | Array | 必填 | 供應商條目陣列,**順序即優先序**。條目除`id`、`keys`外即該次調用之opt,原樣透傳對應轉接器(`kind`、`model`、`exe`、`provider`、`config`、`sandbox`、`timeoutMs`等皆放條目內) |
|
|
229
|
+
| `providers[].id` | String | 條目索引 | 群組識別,游標以此為鍵,多金鑰條目應給予穩定`id` |
|
|
230
|
+
| `providers[].keys` | Array | `[]` | 同一服務之多把API key,逐次注入輪替(`kind`為`opencode`時須同時給`provider`);省略代表沿用CLI登入狀態 |
|
|
231
|
+
| `budgetMs` | Integer | 不限 | 整輪遞補之時間上限,剩餘預算會壓進每次呼叫之`timeoutMs` |
|
|
232
|
+
| `minAttemptMs` | Integer | `20000` | 單次嘗試之最低剩餘預算,低於此值即停止並回報`budget exhausted` |
|
|
233
|
+
| `store` | Object | 行程內記憶體 | 狀態持久化`{get:()=>state, set:(state)=>{}}`,state僅含`cursors`(逐群組游標);假定單行程序列調用 |
|
|
234
|
+
| `onEvent` | Function | 無 | 事件回調`(ev)=>{}`,`ev.type`為`'try'`、`'ok'`、`'next-key'`、`'skip-group'`、`'budget-out'`;回調拋出例外不影響主流程 |
|
|
235
|
+
|
|
236
|
+
頂層其餘設定(`timeoutMs`、`validate`、`maxRetries`等)為各attempt之共用預設,條目可覆寫;`maxRetries`建議維持預設`0`,韌性交給換家而非重試同一家。
|
|
237
|
+
|
|
238
|
+
**失敗分流規則**:
|
|
239
|
+
| 失敗 | 判定 | 處置 |
|
|
240
|
+
| --- | --- | --- |
|
|
241
|
+
| 逾時 | `error`以`TIMEOUT`開頭 | 整組跳過 |
|
|
242
|
+
| 執行檔不存在 | `error`含`ENOENT` | 整組跳過 |
|
|
243
|
+
| 參數錯誤 | `code === 2` | 整組跳過 |
|
|
244
|
+
| 輸出未過驗證 | `error === 'OUTPUT_VALIDATION_FAILED'` | 整組跳過 |
|
|
245
|
+
| kind無效 | `error`以`unknown ai kind`開頭 | 整組跳過 |
|
|
246
|
+
| 其餘(含額度上限、金鑰無效、服務回錯) | — | 換組內下一把 |
|
|
247
|
+
|
|
248
|
+
整組跳過的理由:同組各金鑰共用同一`exe`與`model`,這些失敗換金鑰必然再敗,逐把嘗試純屬空耗。其餘失敗一律換下一把、**不記憶不停用**——額度視窗形態多樣(5小時滾動、逐時、逐日),停用清單會把已恢復的金鑰閒置,而重探的代價僅一次快速失敗;跨次執行僅記憶游標(成功後推進,令額度在多把金鑰間均攤)。
|
|
249
|
+
|
|
165
250
|
#### Result of dispatch functions:
|
|
166
251
|
```alias
|
|
167
252
|
//成功
|
|
@@ -200,8 +285,25 @@ await test()
|
|
|
200
285
|
}
|
|
201
286
|
```
|
|
202
287
|
|
|
288
|
+
#### Result of dispatchAiFallback:
|
|
289
|
+
於execCli既有欄位外追加:
|
|
290
|
+
```alias
|
|
291
|
+
{
|
|
292
|
+
// ...ok, stdout, stderr, code, error, durationMs, attempts, pid...
|
|
293
|
+
providerId: 'deepseek', //實際使用之群組
|
|
294
|
+
keyIndex: 1, //實際使用之金鑰索引, 無keys時為null
|
|
295
|
+
kind: 'opencode',
|
|
296
|
+
model: 'opencode/deepseek-v4-flash-free',
|
|
297
|
+
tried: [ //完整嘗試歷程, 成功時亦回傳
|
|
298
|
+
{ providerId: 'deepseek', keyIndex: 0, keyId: 'deepseek#0', outcome: 'next-key', error: 'Exit code 1', durationMs: 3049 },
|
|
299
|
+
{ providerId: 'deepseek', keyIndex: 1, keyId: 'deepseek#1', outcome: 'ok', durationMs: 11742 },
|
|
300
|
+
],
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
203
304
|
#### Known design notes:
|
|
204
|
-
- `dispatchAi(kind, prompt, opt)`會把整個`opt`原樣轉傳對應轉接器,該轉接器用不到的鍵(例如輪替條目物件內的`kind`)會被忽略,故「供應商條目物件直接當`opt
|
|
305
|
+
- `dispatchAi(kind, prompt, opt)`會把整個`opt`原樣轉傳對應轉接器,該轉接器用不到的鍵(例如輪替條目物件內的`kind`)會被忽略,故「供應商條目物件直接當`opt`」是預期用法;`dispatchAiFallback`之providers條目沿用同一約定。
|
|
306
|
+
- `dispatchAiFallback`為單向單輪:全數群組試畢即回傳最後一筆失敗結果與`tried`歷程,不回頭重試已敗的組。跨次執行僅記憶游標,不設金鑰停用清單(理由見上方失敗分流說明);需跨次跳過特定金鑰時,由呼叫端依`tried`/`onEvent`內之`error`與`stderr`自行決策。
|
|
205
307
|
- `dispatchOpencode`之`key`與`provider`須同時給予才會注入金鑰;只給其一(或範例中`.env`缺鍵導致`key`為`undefined`)時不會報錯,而是靜默沿用CLI既有登入狀態。
|
|
206
308
|
- 範例中之`process.loadEnvFile`需Node.js >= 20.12,僅範例使用,套件本身無此限制。
|
|
207
309
|
- `config`以`OPENCODE_CONFIG_CONTENT`注入後,與使用者既有`opencode.jsonc`為覆蓋或合併關係未經實測確認;建議`config`內含該次調用所需之完整provider定義,不依賴與既有設定檔之合併行為。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* w-dispatch-ai v1.0.
|
|
2
|
+
* w-dispatch-ai v1.0.2
|
|
3
3
|
* (c) 2018-2021 yuda-lyu(semisphere)
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("child_process"),require("path"),require("fs")):"function"==typeof define&&define.amd?define(["child_process","path","fs"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-dispatch-ai"]=e(t.child_process,t.path,t.fs)}(this,function(t,e,r){"use strict";var n="object"==typeof global&&global&&global.Object===Object&&global,o="object"==typeof self&&self&&self.Object===Object&&self,u=n||o||Function("return this")(),i=u.Symbol,c=Object.prototype,a=c.hasOwnProperty,l=c.toString,s=i?i.toStringTag:void 0;var f=Object.prototype.toString;var p=i?i.toStringTag:void 0;function d(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":p&&p in Object(t)?function(t){var e=a.call(t,s),r=t[s];try{t[s]=void 0;var n=!0}catch(t){}var o=l.call(t);return n&&(e?t[s]=r:delete t[s]),o}(t):function(t){return f.call(t)}(t)}function v(t){return null!=t&&"object"==typeof t}function b(t){return v(t)&&"[object Arguments]"==d(t)}var y=Object.prototype,h=y.hasOwnProperty,j=y.propertyIsEnumerable,g=b(function(){return arguments}())?b:function(t){return v(t)&&h.call(t,"callee")&&!j.call(t,"callee")},m=g,_=Array.isArray;var w="object"==typeof exports&&exports&&!exports.nodeType&&exports,O=w&&"object"==typeof module&&module&&!module.nodeType&&module,x=O&&O.exports===w?u.Buffer:void 0,A=(x?x.isBuffer:void 0)||function(){return!1},S=/^(?:0|[1-9]\d*)$/;function $(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&S.test(t))&&t>-1&&t%1==0&&t<e}function k(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}var N={};function M(t){return function(e){return t(e)}}N["[object Float32Array]"]=N["[object Float64Array]"]=N["[object Int8Array]"]=N["[object Int16Array]"]=N["[object Int32Array]"]=N["[object Uint8Array]"]=N["[object Uint8ClampedArray]"]=N["[object Uint16Array]"]=N["[object Uint32Array]"]=!0,N["[object Arguments]"]=N["[object Array]"]=N["[object ArrayBuffer]"]=N["[object Boolean]"]=N["[object DataView]"]=N["[object Date]"]=N["[object Error]"]=N["[object Function]"]=N["[object Map]"]=N["[object Number]"]=N["[object Object]"]=N["[object RegExp]"]=N["[object Set]"]=N["[object String]"]=N["[object WeakMap]"]=!1;var T="object"==typeof exports&&exports&&!exports.nodeType&&exports,E=T&&"object"==typeof module&&module&&!module.nodeType&&module,P=E&&E.exports===T&&n.process,I=function(){try{var t=E&&E.require&&E.require("util").types;return t||P&&P.binding&&P.binding("util")}catch(t){}}(),F=I&&I.isTypedArray,D=F?M(F):function(t){return v(t)&&k(t.length)&&!!N[d(t)]},z=Object.prototype.hasOwnProperty;function C(t,e){var r=_(t),n=!r&&m(t),o=!r&&!n&&A(t),u=!r&&!n&&!o&&D(t),i=r||n||o||u,c=i?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],a=c.length;for(var l in t)!e&&!z.call(t,l)||i&&("length"==l||o&&("offset"==l||"parent"==l)||u&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||$(l,a))||c.push(l);return c}var U=Object.prototype;function B(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||U)}function L(t,e){return function(r){return t(e(r))}}var R=L(Object.keys,Object),V=Object.prototype.hasOwnProperty;function W(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function q(t){if(!W(t))return!1;var e=d(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}function G(t){return null!=t&&k(t.length)&&!q(t)}function H(t){return G(t)?C(t):function(t){if(!B(t))return R(t);var e=[];for(var r in Object(t))V.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}function J(t){return"symbol"==typeof t||v(t)&&"[object Symbol]"==d(t)}var K=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Y=/^\w*$/;var Q,X=u["__core-js_shared__"],Z=(Q=/[^.]+$/.exec(X&&X.keys&&X.keys.IE_PROTO||""))?"Symbol(src)_1."+Q:"";var tt=Function.prototype.toString;function et(t){if(null!=t){try{return tt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var rt=/^\[object .+?Constructor\]$/,nt=Function.prototype,ot=Object.prototype,ut=nt.toString,it=ot.hasOwnProperty,ct=RegExp("^"+ut.call(it).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function at(t){return!(!W(t)||(e=t,Z&&Z in e))&&(q(t)?ct:rt).test(et(t));var e}function lt(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return at(r)?r:void 0}var st=lt(Object,"create");var ft=Object.prototype.hasOwnProperty;var pt=Object.prototype.hasOwnProperty;function dt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function vt(t,e){return t===e||t!=t&&e!=e}function bt(t,e){for(var r=t.length;r--;)if(vt(t[r][0],e))return r;return-1}dt.prototype.clear=function(){this.__data__=st?st(null):{},this.size=0},dt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},dt.prototype.get=function(t){var e=this.__data__;if(st){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return ft.call(e,t)?e[t]:void 0},dt.prototype.has=function(t){var e=this.__data__;return st?void 0!==e[t]:pt.call(e,t)},dt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=st&&void 0===e?"__lodash_hash_undefined__":e,this};var yt=Array.prototype.splice;function ht(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ht.prototype.clear=function(){this.__data__=[],this.size=0},ht.prototype.delete=function(t){var e=this.__data__,r=bt(e,t);return!(r<0)&&(r==e.length-1?e.pop():yt.call(e,r,1),--this.size,!0)},ht.prototype.get=function(t){var e=this.__data__,r=bt(e,t);return r<0?void 0:e[r][1]},ht.prototype.has=function(t){return bt(this.__data__,t)>-1},ht.prototype.set=function(t,e){var r=this.__data__,n=bt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var jt=lt(u,"Map");function gt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function mt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}mt.prototype.clear=function(){this.size=0,this.__data__={hash:new dt,map:new(jt||ht),string:new dt}},mt.prototype.delete=function(t){var e=gt(this,t).delete(t);return this.size-=e?1:0,e},mt.prototype.get=function(t){return gt(this,t).get(t)},mt.prototype.has=function(t){return gt(this,t).has(t)},mt.prototype.set=function(t,e){var r=gt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function _t(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],u=r.cache;if(u.has(o))return u.get(o);var i=t.apply(this,n);return r.cache=u.set(o,i)||u,i};return r.cache=new(_t.Cache||mt),r}_t.Cache=mt;var wt,Ot,xt,At=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,St=/\\(\\)?/g,$t=(wt=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(At,function(t,r,n,o){e.push(n?o.replace(St,"$1"):r||t)}),e},Ot=_t(wt,function(t){return 500===xt.size&&xt.clear(),t}),xt=Ot.cache,Ot),kt=$t;function Nt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}var Mt=i?i.prototype:void 0,Tt=Mt?Mt.toString:void 0;function Et(t){if("string"==typeof t)return t;if(_(t))return Nt(t,Et)+"";if(J(t))return Tt?Tt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Pt(t){return null==t?"":Et(t)}function It(t,e){return _(t)?t:function(t,e){if(_(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!J(t))||Y.test(t)||!K.test(t)||null!=e&&t in Object(e)}(t,e)?[t]:kt(Pt(t))}function Ft(t){if("string"==typeof t||J(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Dt(t,e){for(var r=0,n=(e=It(e,t)).length;null!=t&&r<n;)t=t[Ft(e[r++])];return r&&r==n?t:void 0}function zt(t,e,r){var n=null==t?void 0:Dt(t,e);return void 0===n?r:n}function Ct(t){var e=this.__data__=new ht(t);this.size=e.size}Ct.prototype.clear=function(){this.__data__=new ht,this.size=0},Ct.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Ct.prototype.get=function(t){return this.__data__.get(t)},Ct.prototype.has=function(t){return this.__data__.has(t)},Ct.prototype.set=function(t,e){var r=this.__data__;if(r instanceof ht){var n=r.__data__;if(!jt||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new mt(n)}return r.set(t,e),this.size=r.size,this};var Ut=function(){try{var t=lt(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Bt=Ut;function Lt(t,e,r){"__proto__"==e&&Bt?Bt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var Rt=Object.prototype.hasOwnProperty;function Vt(t,e,r){var n=t[e];Rt.call(t,e)&&vt(n,r)&&(void 0!==r||e in t)||Lt(t,e,r)}function Wt(t,e,r,n){var o=!r;r||(r={});for(var u=-1,i=e.length;++u<i;){var c=e[u],a=n?n(r[c],t[c],c,r,t):void 0;void 0===a&&(a=t[c]),o?Lt(r,c,a):Vt(r,c,a)}return r}var qt=Object.prototype.hasOwnProperty;function Gt(t){if(!W(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=B(t),r=[];for(var n in t)("constructor"!=n||!e&&qt.call(t,n))&&r.push(n);return r}function Ht(t){return G(t)?C(t,!0):Gt(t)}var Jt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Kt=Jt&&"object"==typeof module&&module&&!module.nodeType&&module,Yt=Kt&&Kt.exports===Jt?u.Buffer:void 0,Qt=Yt?Yt.allocUnsafe:void 0;function Xt(){return[]}var Zt=Object.prototype.propertyIsEnumerable,te=Object.getOwnPropertySymbols,ee=te?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,u=[];++r<n;){var i=t[r];e(i,r,t)&&(u[o++]=i)}return u}(te(t),function(e){return Zt.call(t,e)}))}:Xt,re=ee;function ne(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}var oe=L(Object.getPrototypeOf,Object),ue=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)ne(e,re(t)),t=oe(t);return e}:Xt,ie=ue;function ce(t,e,r){var n=e(t);return _(t)?n:ne(n,r(t))}function ae(t){return ce(t,H,re)}function le(t){return ce(t,Ht,ie)}var se=lt(u,"DataView"),fe=lt(u,"Promise"),pe=lt(u,"Set"),de=lt(u,"WeakMap"),ve="[object Map]",be="[object Promise]",ye="[object Set]",he="[object WeakMap]",je="[object DataView]",ge=et(se),me=et(jt),_e=et(fe),we=et(pe),Oe=et(de),xe=d;(se&&xe(new se(new ArrayBuffer(1)))!=je||jt&&xe(new jt)!=ve||fe&&xe(fe.resolve())!=be||pe&&xe(new pe)!=ye||de&&xe(new de)!=he)&&(xe=function(t){var e=d(t),r="[object Object]"==e?t.constructor:void 0,n=r?et(r):"";if(n)switch(n){case ge:return je;case me:return ve;case _e:return be;case we:return ye;case Oe:return he}return e});var Ae=xe,Se=Object.prototype.hasOwnProperty;var $e=u.Uint8Array;function ke(t){var e=new t.constructor(t.byteLength);return new $e(e).set(new $e(t)),e}var Ne=/\w*$/;var Me=i?i.prototype:void 0,Te=Me?Me.valueOf:void 0;function Ee(t,e,r){var n,o=t.constructor;switch(e){case"[object ArrayBuffer]":return ke(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var r=e?ke(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return function(t,e){var r=e?ke(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case"[object Map]":case"[object Set]":return new o;case"[object Number]":case"[object String]":return new o(t);case"[object RegExp]":return function(t){var e=new t.constructor(t.source,Ne.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return n=t,Te?Object(Te.call(n)):{}}}var Pe=Object.create,Ie=function(){function t(){}return function(e){if(!W(e))return{};if(Pe)return Pe(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Fe=Ie;var De=I&&I.isMap,ze=De?M(De):function(t){return v(t)&&"[object Map]"==Ae(t)};var Ce=I&&I.isSet,Ue=Ce?M(Ce):function(t){return v(t)&&"[object Set]"==Ae(t)},Be="[object Arguments]",Le="[object Function]",Re="[object Object]",Ve={};function We(t,e,r,n,o,u){var i,c=1&e,a=2&e,l=4&e;if(r&&(i=o?r(t,n,o,u):r(t)),void 0!==i)return i;if(!W(t))return t;var s=_(t);if(s){if(i=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&Se.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!c)return function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}(t,i)}else{var f=Ae(t),p=f==Le||"[object GeneratorFunction]"==f;if(A(t))return function(t,e){if(e)return t.slice();var r=t.length,n=Qt?Qt(r):new t.constructor(r);return t.copy(n),n}(t,c);if(f==Re||f==Be||p&&!o){if(i=a||p?{}:function(t){return"function"!=typeof t.constructor||B(t)?{}:Fe(oe(t))}(t),!c)return a?function(t,e){return Wt(t,ie(t),e)}(t,function(t,e){return t&&Wt(e,Ht(e),t)}(i,t)):function(t,e){return Wt(t,re(t),e)}(t,function(t,e){return t&&Wt(e,H(e),t)}(i,t))}else{if(!Ve[f])return o?t:{};i=Ee(t,f,c)}}u||(u=new Ct);var d=u.get(t);if(d)return d;u.set(t,i),Ue(t)?t.forEach(function(n){i.add(We(n,e,r,n,t,u))}):ze(t)&&t.forEach(function(n,o){i.set(o,We(n,e,r,o,t,u))});var v=s?void 0:(l?a?le:ae:a?Ht:H)(t);return function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););}(v||t,function(n,o){v&&(n=t[o=n]),Vt(i,o,We(n,e,r,o,t,u))}),i}function qe(t,e){return e.length<2?t:Dt(t,function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var u=Array(o);++n<o;)u[n]=t[n+e];return u}(e,0,-1))}Ve[Be]=Ve["[object Array]"]=Ve["[object ArrayBuffer]"]=Ve["[object DataView]"]=Ve["[object Boolean]"]=Ve["[object Date]"]=Ve["[object Float32Array]"]=Ve["[object Float64Array]"]=Ve["[object Int8Array]"]=Ve["[object Int16Array]"]=Ve["[object Int32Array]"]=Ve["[object Map]"]=Ve["[object Number]"]=Ve[Re]=Ve["[object RegExp]"]=Ve["[object Set]"]=Ve["[object String]"]=Ve["[object Symbol]"]=Ve["[object Uint8Array]"]=Ve["[object Uint8ClampedArray]"]=Ve["[object Uint16Array]"]=Ve["[object Uint32Array]"]=!0,Ve["[object Error]"]=Ve[Le]=Ve["[object WeakMap]"]=!1;var Ge=Object.prototype.hasOwnProperty;function He(t,e){var r=-1,n=(e=It(e,t)).length;if(!n)return!0;for(;++r<n;){var o=Ft(e[r]);if("__proto__"===o&&!Ge.call(t,"__proto__"))return!1;if(("constructor"===o||"prototype"===o)&&r<n-1)return!1}var u=qe(t,e);return null==u||delete u[Ft(function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0}(e))]}var Je=Function.prototype,Ke=Object.prototype,Ye=Je.toString,Qe=Ke.hasOwnProperty,Xe=Ye.call(Object);function Ze(t){return function(t){if(!v(t)||"[object Object]"!=d(t))return!1;var e=oe(t);if(null===e)return!0;var r=Qe.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Ye.call(r)==Xe}(t)?void 0:t}var tr=i?i.isConcatSpreadable:void 0;function er(t){return _(t)||m(t)||!!(tr&&t&&t[tr])}function rr(t,e,r,n,o){var u=-1,i=t.length;for(r||(r=er),o||(o=[]);++u<i;){var c=t[u];e>0&&r(c)?e>1?rr(c,e-1,r,n,o):ne(o,c):n||(o[o.length]=c)}return o}function nr(t){return(null==t?0:t.length)?rr(t,1):[]}var or=Math.max;var ur=Bt?function(t,e){return Bt(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:function(t){return t},ir=ur,cr=Date.now;var ar=function(t){var e=0,r=0;return function(){var n=cr(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ir),lr=ar;var sr=function(t){return lr(function(t,e,r){return e=or(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,u=or(n.length-e,0),i=Array(u);++o<u;)i[o]=n[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=n[o];return c[e]=r(i),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,c)}}(t,void 0,nr),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=Nt(e,function(e){return e=It(e,t),n||(n=e.length>1),e}),Wt(t,le(t),r),n&&(r=We(r,7,Ze));for(var o=e.length;o--;)He(r,e[o]);return r}),fr=sr;function pr(t){return"[object Object]"===Object.prototype.toString.call(t)}function dr(t){return!(!function(t){return"[object String]"===Object.prototype.toString.call(t)}(t)||""===t)}function vr(){let t,e,r=new Promise(function(){t=arguments[0],e=arguments[1]});return r.resolve=t,r.reject=e,r}function br(t){let e=!1;if(dr(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(function(t){return t!=t}(t))return!1;e=!0}return e}function yr(t=10){br(t)||(t=10);let e=vr();return setTimeout(function(){e.resolve()},t),e}var hr=/\s/;var jr=/^\s+/;function gr(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&hr.test(t.charAt(e)););return e}(t)+1).replace(jr,""):t}var mr=/^[-+]0x[0-9a-f]+$/i,_r=/^0b[01]+$/i,wr=/^0o[0-7]+$/i,Or=parseInt;function xr(t){if("number"==typeof t)return t;if(J(t))return NaN;if(W(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=W(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=gr(t);var r=_r.test(t);return r||wr.test(t)?Or(t.slice(2),r?2:8):mr.test(t)?NaN:+t}var Ar=1/0;function Sr(t){return t?(t=xr(t))===Ar||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function $r(t){var e=Sr(t),r=e%1;return e==e?r?e-r:e:0}var kr=u.isFinite,Nr=Math.min;var Mr=function(t){var e=Math[t];return function(t,r){if(t=xr(t),(r=null==r?0:Nr($r(r),292))&&kr(t)){var n=(Pt(t)+"e").split("e");return+((n=(Pt(e(n[0]+"e"+(+n[1]+r)))+"e").split("e"))[0]+"e"+(+n[1]-r))}return e(t)}}("round"),Tr=Mr;function Er(t){if(!br(t))return 0;return Sr(t)}function Pr(t){if(!br(t))return 0;t=Er(t);let e=Tr(t);return"0"===String(e)?0:e}function Ir(t){return"[object Array]"===Object.prototype.toString.call(t)}function Fr(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function Dr(t){return!!br(t)&&(t=Er(t),"number"==typeof(e=t)&&e==$r(e));var e}function zr(t){if(!Dr(t))return!1;return Pr(t)>0}function Cr(t){if(!Dr(t))return!1;return Pr(t)>=0}function Ur(t,e){return dr(t)&&Cr(e)?0===(e=Pr(e))?"":t.substring(0,e):""}function Br(t,e){return dr(t)&&Cr(e)?0===(e=Pr(e))?t:function(t,e){if(!dr(t))return"";if(!Cr(e))return"";if(0===(e=Pr(e)))return"";let r=t.length-e;return r<0&&(r=0),t.substring(r,r+e)}(t,t.length-e):""}function Lr(t,e,r={}){if(!dr(t))return"";if(!Cr(e))return t;if(e=Pr(e),t.length<=e)return t;let n=zt(r,"funWithMsg"),o="";if(Fr(n)){let r=n(t,e);dr(r)&&(o=r)}return Ur(t,e)+`...${o}`}function Rr(t,e={}){let r=zt(e,"fs");return!!function(t,e={}){let r=zt(e,"fs"),n=!1;try{r.statSync(t),n=!0}catch{n=!1}return n}(t,{fs:r})&&(!r.lstatSync(t).isDirectory()&&!r.lstatSync(t).isSymbolicLink())}function Vr(t){return function(t,e={}){let r=null,n=zt(e,"fs"),o="";try{o=n.readFileSync(t,"utf8")}catch(t){r=t}return null!==r?{error:r}:{success:o}}(t,{fs:r})}function Wr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var qr=t,Gr=qr.spawn,Hr=qr.exec;function Jr(t,e,r){var n={};try{Object.keys(t).forEach(function(r){t[r].forEach(function(t){n[t]||(Kr(t,e),n[t]=1)}),n[r]||(Kr(r,e),n[r]=1)})}catch(t){if(r)return r(t);throw t}if(r)return r()}function Kr(t,e){try{process.kill(parseInt(t,10),e)}catch(t){if("ESRCH"!==t.code)throw t}}function Yr(t,e,r,n,o){var u=n(t),i="";u.stdout.on("data",function(t){t=t.toString("ascii");i+=t});u.on("close",function(u){delete r[t],0==u?i.match(/\d+/g).forEach(function(u){u=parseInt(u,10),e[t].push(u),e[u]=[],r[u]=1,Yr(u,e,r,n,o)}):0==Object.keys(r).length&&o()})}var Qr=Wr(function(t,e,r){if("function"==typeof e&&void 0===r&&(r=e,e=void 0),t=parseInt(t),Number.isNaN(t)){if(r)return r(new Error("pid must be a number"));throw new Error("pid must be a number")}var n={},o={};switch(n[t]=[],o[t]=1,process.platform){case"win32":Hr("taskkill /pid "+t+" /T /F",r);break;case"darwin":Yr(t,n,o,function(t){return Gr("pgrep",["-P",t])},function(){Jr(n,e,r)});break;default:Yr(t,n,o,function(t){return Gr("ps",["-o","pid","--no-headers","--ppid",t])},function(){Jr(n,e,r)})}});function Xr(t){let n=zt(Vr(t),"success","");if(!dr(n))return null;let o=n.match(/%dp0%\\(node_modules\\[^"]+)"/i);if(!o)return null;let u=e.dirname(t),i=e.join(u,o[1]);return Rr(i,{fs:r})?i:null}function Zr(r,n){if("win32"!==process.platform)return{file:r,args:n};let o=function(r){if("win32"!==process.platform)return r;if(/\.(cmd|exe|bat|ps1)$/i.test(r))return r;if(e.isAbsolute(r))return r;try{let e=t.execFileSync("where",[r],{encoding:"utf8",timeout:5e3,windowsHide:!0,shell:!1,stdio:["ignore","pipe","ignore"]}).trim().split(/\r?\n/),n=e.find(t=>/\.cmd$/i.test(t));return n||(e.find(t=>/\.exe$/i.test(t))||e[0]||r)}catch{return r}}(r);if(/\.exe$/i.test(o))return{file:o,args:n};if(/\.(cmd|bat)$/i.test(o)){let t=Xr(o);if(t)return/\.exe$/i.test(t)?{file:t,args:n}:{file:process.execPath,args:[t,...n]};let e=n.map(t=>`"${t.replace(/(\\*)"/g,'$1$1\\"').replace(/(\\*)$/,"$1$1")}"`.replace(/[()%!^"<>&|]/g,"^$&")),r=`${u=o,u.replace(/[()%!^"<>&|;, ]/g,"^$&")} ${e.join(" ")}`;return{file:process.env.comspec||process.env.COMSPEC||"cmd.exe",args:["/d","/s","/c",`"${r}"`],opt:{windowsVerbatimArguments:!0}}}var u;return{file:o,args:n}}let tn={funWithMsg:t=>`(truncated, total ${t.length} chars)`};function en(e,r=[],n={}){let{timeoutMs:o=12e4,cwd:u=process.cwd(),input:i,validate:c,maxBuffer:a=10485760,onStdout:l,onStderr:s,env:f}=n,p=function(t){if(Fr(t))return t;if(!dr(t))return null;let e=t.split(",").map(t=>t.trim()).filter(Boolean);return 0===e.length?null:t=>{for(let r of e)if("nonempty"===r){if(!dr(t)||""===t.trim())return!1}else if("json"===r)try{JSON.parse(t)}catch{return!1}else if("min:"===Ur(r,4)){let e=Br(r,4);if(!br(e))return!1;let n=Pr(e);if(!dr(t)||t.length<n)return!1}return!0}}(c),d=Date.now(),v=vr(),b={...process.env,PYTHONIOENCODING:"utf-8"};if(void 0!==f){if("win32"===process.platform){let t=Object.keys(f).map(t=>t.toLowerCase());for(let e of Object.keys(b))t.includes(e.toLowerCase())&&delete b[e]}b={...b,...f}}let y=Zr(e,r),h=t.spawn(y.file,y.args,{cwd:u,stdio:["pipe","pipe","pipe"],windowsHide:!0,env:b,...y.opt}),j="",g="",m=new TextDecoder("utf-8"),_=new TextDecoder("utf-8"),w=!1,O=!1;h.stdout.on("data",t=>{let e=m.decode(t,{stream:!0});e&&(Fr(l)&&l(e),j.length<a&&(j+=e))}),h.stderr.on("data",t=>{let e=_.decode(t,{stream:!0});e&&(Fr(s)&&s(e),g.length<a&&(g+=e))}),h.stdin.on("error",()=>{}),void 0!==i&&h.stdin.write(i,"utf8"),h.stdin.end();let x=setTimeout(()=>{w||(O=!0,function(t){let e=vr();return Qr(Number(t),"SIGKILL",r=>{r?e.reject(r):e.resolve(`pid[${t}] killed`)}),e}(h.pid).catch(()=>{}),setTimeout(()=>{w||(w=!0,v.resolve({ok:!1,stdout:Lr(j,500,tn),stderr:Lr(g,500,tn),code:null,error:`TIMEOUT after ${o/1e3}s(子進程未能結束)`,durationMs:Date.now()-d,pid:h.pid}))},3e3).unref())},o);return h.on("error",t=>{w||(w=!0,clearTimeout(x),v.resolve({ok:!1,stdout:"",stderr:"",code:null,error:`${t.code||"UNKNOWN"}: ${t.message}`,durationMs:Date.now()-d,pid:h.pid}))}),h.on("close",(t,e)=>{if(w)return;w=!0,clearTimeout(x);let r=m.decode();r&&j.length<a&&(j+=r);let n=_.decode();n&&g.length<a&&(g+=n);let u=Date.now()-d;O?v.resolve({ok:!1,stdout:Lr(j,500,tn),stderr:Lr(g,500,tn),code:t,error:`TIMEOUT after ${o/1e3}s`,durationMs:u,pid:h.pid}):0===t?!p||p(j)?v.resolve({ok:!0,stdout:j,stderr:g,code:0,error:"",durationMs:u,pid:h.pid}):v.resolve({ok:!1,stdout:Lr(j,500,tn),stderr:Lr(g,500,tn),code:0,error:"OUTPUT_VALIDATION_FAILED",durationMs:u,pid:h.pid}):v.resolve({ok:!1,stdout:Lr(j,500,tn),stderr:Lr(g,1e3,tn),code:t,error:e?`Signal: ${e}`:`Exit code ${t}`,durationMs:u,pid:h.pid})}),v}async function rn(t,e=[],r={}){if(!dr(t))return{ok:!1,stdout:"",stderr:"",code:null,error:"command 須為非空字串",durationMs:0,attempts:0};Ir(e)||(e=[]),pr(r)||(r={});let{maxRetries:n=0,retryDelayMs:o=5e3,...u}=r,i=zt(u,"cwd",null);dr(i)?u.cwd=i:u.cwd=process.cwd();let c=zt(u,"input",null);dr(c)?u.input=c:u.input=void 0;let a=zt(u,"env",null);pr(a)?u.env=a:u.env=void 0;let l=zt(u,"validate",null);Fr(l)||dr(l)?u.validate=l:u.validate=void 0;let s=zt(u,"onStdout",null);Fr(s)?u.onStdout=s:u.onStdout=void 0;let f=zt(u,"onStderr",null);Fr(f)?u.onStderr=f:u.onStderr=void 0,n=Cr(n)?Pr(n):0,o=zr(o)?Pr(o):5e3;let p=zt(u,"timeoutMs",null);zr(p)?u.timeoutMs=Pr(p):u.timeoutMs=12e4;let d,v=zt(u,"maxBuffer",null);zr(v)?u.maxBuffer=Pr(v):u.maxBuffer=10485760;let b=0;for(let r=0;r<=n;r++){if(r>0){let t=Math.min(o*r,15e3);await yr(t)}if(d=await en(t,e,u),b=r+1,d.ok)return d.attempts=b,d;if(d.error.includes("ENOENT"))break;if(2===d.code)break}return d.attempts=b,d}function nn(...t){let e=[];for(let r of t)if(Ir(r))for(let t of r)dr(t)&&e.push(t);else dr(r)&&e.push(r);return e}function on(t){return dr(t)||(t="unknown error"),{ok:!1,stdout:"",stderr:"",code:null,error:t,durationMs:0,attempts:0}}let un=["exe","model","key","provider","agent","config","extraArgs","input","env"];async function cn(t,e={}){if(!dr(t))return on("prompt must be a non-empty string");let r=zt(e,"exe",null);dr(r)||(r="opencode");let n=zt(e,"model",null),o=zt(e,"agent",null);dr(o)||(o="build");let u=zt(e,"extraArgs",null),i=nn("run",["--agent",o],dr(n)?["-m",n]:[],u),c=zt(e,"env",null);pr(c)||(c=void 0);let a=zt(e,"config",null);pr(a)&&(a=JSON.stringify(a)),dr(a)&&(c={...c,OPENCODE_CONFIG_CONTENT:a});let l=zt(e,"key",null),s=zt(e,"provider",null);return dr(l)&&dr(s)&&(c={...c,OPENCODE_AUTH_CONTENT:JSON.stringify({[s]:{type:"api",key:l}})}),rn(r,i,{...fr(e,un),input:t,env:c})}function an(t){return!0===(e=t)||!1===e||v(e)&&"[object Boolean]"==d(e);var e}let ln=["exe","model","skipPermissions","extraArgs","input"];async function sn(t,e={}){if(!dr(t))return on("prompt must be a non-empty string");let r=zt(e,"exe",null);dr(r)||(r="claude");let n=zt(e,"model",null),o=zt(e,"skipPermissions",null);an(o)||(o=!0);let u=zt(e,"extraArgs",null);return rn(r,nn("-p",o?"--dangerously-skip-permissions":[],dr(n)?["--model",n]:[],u),{...fr(e,ln),input:t})}let fn=["exe","model","sandbox","extraArgs","input"];async function pn(t,e={}){if(!dr(t))return on("prompt must be a non-empty string");let r=zt(e,"exe",null);dr(r)||(r="codex");let n=zt(e,"model",null),o=zt(e,"sandbox",null);dr(o)||(o="workspace-write");let u=zt(e,"extraArgs",null);return rn(r,nn("exec",["--sandbox",o],"--skip-git-repo-check",dr(n)?["-m",n]:[],u),{...fr(e,fn),input:t})}let dn={opencode:cn,claude:sn,codex:pn};function vn(t){return t!=t}function bn(t){return null==t?[]:function(t,e){return Nt(e,function(e){return t[e]})}(t,H(t))}var yn=Math.max;function hn(t,e,r,n){t=G(t)?t:bn(t),r=r&&!n?$r(r):0;var o=t.length;return r<0&&(r=yn(o+r,0)),function(t){return"string"==typeof t||!_(t)&&v(t)&&"[object String]"==d(t)}(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&function(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1}(t,e,r):function(t,e,r,n){for(var o=t.length,u=r+(n?1:-1);n?u--:++u<o;)if(e(t[u],u,t))return u;return-1}(t,vn,r)}(t,e,r)>-1}return{KINDS:H(dn),dispatchAi:async function(t,e,r={}){let n=H(dn);return dr(t)&&hn(n,t)?(0,dn[t])(e,r):on(`unknown ai kind: "${t}" (available: ${n.join(", ")})`)},dispatchOpencode:cn,dispatchClaude:sn,dispatchCodex:pn}});
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("child_process"),require("path"),require("fs")):"function"==typeof define&&define.amd?define(["child_process","path","fs"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-dispatch-ai"]=e(t.child_process,t.path,t.fs)}(this,function(t,e,r){"use strict";var n="object"==typeof global&&global&&global.Object===Object&&global,o="object"==typeof self&&self&&self.Object===Object&&self,i=n||o||Function("return this")(),u=i.Symbol,c=Object.prototype,a=c.hasOwnProperty,l=c.toString,s=u?u.toStringTag:void 0;var f=Object.prototype.toString;var p=u?u.toStringTag:void 0;function d(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":p&&p in Object(t)?function(t){var e=a.call(t,s),r=t[s];try{t[s]=void 0;var n=!0}catch(t){}var o=l.call(t);return n&&(e?t[s]=r:delete t[s]),o}(t):function(t){return f.call(t)}(t)}function y(t){return null!=t&&"object"==typeof t}function v(t){return y(t)&&"[object Arguments]"==d(t)}var b=Object.prototype,h=b.hasOwnProperty,g=b.propertyIsEnumerable,m=v(function(){return arguments}())?v:function(t){return y(t)&&h.call(t,"callee")&&!g.call(t,"callee")},j=m,_=Array.isArray;var w="object"==typeof exports&&exports&&!exports.nodeType&&exports,O=w&&"object"==typeof module&&module&&!module.nodeType&&module,x=O&&O.exports===w?i.Buffer:void 0,k=(x?x.isBuffer:void 0)||function(){return!1},A=/^(?:0|[1-9]\d*)$/;function I(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&A.test(t))&&t>-1&&t%1==0&&t<e}function S(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}var M={};function $(t){return function(e){return t(e)}}M["[object Float32Array]"]=M["[object Float64Array]"]=M["[object Int8Array]"]=M["[object Int16Array]"]=M["[object Int32Array]"]=M["[object Uint8Array]"]=M["[object Uint8ClampedArray]"]=M["[object Uint16Array]"]=M["[object Uint32Array]"]=!0,M["[object Arguments]"]=M["[object Array]"]=M["[object ArrayBuffer]"]=M["[object Boolean]"]=M["[object DataView]"]=M["[object Date]"]=M["[object Error]"]=M["[object Function]"]=M["[object Map]"]=M["[object Number]"]=M["[object Object]"]=M["[object RegExp]"]=M["[object Set]"]=M["[object String]"]=M["[object WeakMap]"]=!1;var T="object"==typeof exports&&exports&&!exports.nodeType&&exports,N=T&&"object"==typeof module&&module&&!module.nodeType&&module,E=N&&N.exports===T&&n.process,P=function(){try{var t=N&&N.require&&N.require("util").types;return t||E&&E.binding&&E.binding("util")}catch(t){}}(),D=P&&P.isTypedArray,F=D?$(D):function(t){return y(t)&&S(t.length)&&!!M[d(t)]},U=Object.prototype.hasOwnProperty;function z(t,e){var r=_(t),n=!r&&j(t),o=!r&&!n&&k(t),i=!r&&!n&&!o&&F(t),u=r||n||o||i,c=u?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],a=c.length;for(var l in t)!e&&!U.call(t,l)||u&&("length"==l||o&&("offset"==l||"parent"==l)||i&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||I(l,a))||c.push(l);return c}var C=Object.prototype;function B(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||C)}function L(t,e){return function(r){return t(e(r))}}var W=L(Object.keys,Object),V=Object.prototype.hasOwnProperty;function R(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function q(t){if(!R(t))return!1;var e=d(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}function G(t){return null!=t&&S(t.length)&&!q(t)}function H(t){return G(t)?z(t):function(t){if(!B(t))return W(t);var e=[];for(var r in Object(t))V.call(t,r)&&"constructor"!=r&&e.push(r);return e}(t)}function K(t){return"symbol"==typeof t||y(t)&&"[object Symbol]"==d(t)}var J=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Y=/^\w*$/;var Q,X=i["__core-js_shared__"],Z=(Q=/[^.]+$/.exec(X&&X.keys&&X.keys.IE_PROTO||""))?"Symbol(src)_1."+Q:"";var tt=Function.prototype.toString;function et(t){if(null!=t){try{return tt.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var rt=/^\[object .+?Constructor\]$/,nt=Function.prototype,ot=Object.prototype,it=nt.toString,ut=ot.hasOwnProperty,ct=RegExp("^"+it.call(ut).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function at(t){return!(!R(t)||(e=t,Z&&Z in e))&&(q(t)?ct:rt).test(et(t));var e}function lt(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return at(r)?r:void 0}var st=lt(Object,"create");var ft=Object.prototype.hasOwnProperty;var pt=Object.prototype.hasOwnProperty;function dt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function yt(t,e){return t===e||t!=t&&e!=e}function vt(t,e){for(var r=t.length;r--;)if(yt(t[r][0],e))return r;return-1}dt.prototype.clear=function(){this.__data__=st?st(null):{},this.size=0},dt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},dt.prototype.get=function(t){var e=this.__data__;if(st){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return ft.call(e,t)?e[t]:void 0},dt.prototype.has=function(t){var e=this.__data__;return st?void 0!==e[t]:pt.call(e,t)},dt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=st&&void 0===e?"__lodash_hash_undefined__":e,this};var bt=Array.prototype.splice;function ht(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}ht.prototype.clear=function(){this.__data__=[],this.size=0},ht.prototype.delete=function(t){var e=this.__data__,r=vt(e,t);return!(r<0)&&(r==e.length-1?e.pop():bt.call(e,r,1),--this.size,!0)},ht.prototype.get=function(t){var e=this.__data__,r=vt(e,t);return r<0?void 0:e[r][1]},ht.prototype.has=function(t){return vt(this.__data__,t)>-1},ht.prototype.set=function(t,e){var r=this.__data__,n=vt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var gt=lt(i,"Map");function mt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function jt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}jt.prototype.clear=function(){this.size=0,this.__data__={hash:new dt,map:new(gt||ht),string:new dt}},jt.prototype.delete=function(t){var e=mt(this,t).delete(t);return this.size-=e?1:0,e},jt.prototype.get=function(t){return mt(this,t).get(t)},jt.prototype.has=function(t){return mt(this,t).has(t)},jt.prototype.set=function(t,e){var r=mt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function _t(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var u=t.apply(this,n);return r.cache=i.set(o,u)||i,u};return r.cache=new(_t.Cache||jt),r}_t.Cache=jt;var wt,Ot,xt,kt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,At=/\\(\\)?/g,It=(wt=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(kt,function(t,r,n,o){e.push(n?o.replace(At,"$1"):r||t)}),e},Ot=_t(wt,function(t){return 500===xt.size&&xt.clear(),t}),xt=Ot.cache,Ot),St=It;function Mt(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}var $t=u?u.prototype:void 0,Tt=$t?$t.toString:void 0;function Nt(t){if("string"==typeof t)return t;if(_(t))return Mt(t,Nt)+"";if(K(t))return Tt?Tt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Et(t){return null==t?"":Nt(t)}function Pt(t,e){return _(t)?t:function(t,e){if(_(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!K(t))||Y.test(t)||!J.test(t)||null!=e&&t in Object(e)}(t,e)?[t]:St(Et(t))}function Dt(t){if("string"==typeof t||K(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Ft(t,e){for(var r=0,n=(e=Pt(e,t)).length;null!=t&&r<n;)t=t[Dt(e[r++])];return r&&r==n?t:void 0}function Ut(t,e,r){var n=null==t?void 0:Ft(t,e);return void 0===n?r:n}function zt(t){var e=this.__data__=new ht(t);this.size=e.size}zt.prototype.clear=function(){this.__data__=new ht,this.size=0},zt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},zt.prototype.get=function(t){return this.__data__.get(t)},zt.prototype.has=function(t){return this.__data__.has(t)},zt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof ht){var n=r.__data__;if(!gt||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new jt(n)}return r.set(t,e),this.size=r.size,this};var Ct=function(){try{var t=lt(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Bt=Ct;function Lt(t,e,r){"__proto__"==e&&Bt?Bt(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var Wt=Object.prototype.hasOwnProperty;function Vt(t,e,r){var n=t[e];Wt.call(t,e)&&yt(n,r)&&(void 0!==r||e in t)||Lt(t,e,r)}function Rt(t,e,r,n){var o=!r;r||(r={});for(var i=-1,u=e.length;++i<u;){var c=e[i],a=n?n(r[c],t[c],c,r,t):void 0;void 0===a&&(a=t[c]),o?Lt(r,c,a):Vt(r,c,a)}return r}var qt=Object.prototype.hasOwnProperty;function Gt(t){if(!R(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=B(t),r=[];for(var n in t)("constructor"!=n||!e&&qt.call(t,n))&&r.push(n);return r}function Ht(t){return G(t)?z(t,!0):Gt(t)}var Kt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Jt=Kt&&"object"==typeof module&&module&&!module.nodeType&&module,Yt=Jt&&Jt.exports===Kt?i.Buffer:void 0,Qt=Yt?Yt.allocUnsafe:void 0;function Xt(){return[]}var Zt=Object.prototype.propertyIsEnumerable,te=Object.getOwnPropertySymbols,ee=te?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var u=t[r];e(u,r,t)&&(i[o++]=u)}return i}(te(t),function(e){return Zt.call(t,e)}))}:Xt,re=ee;function ne(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}var oe=L(Object.getPrototypeOf,Object),ie=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)ne(e,re(t)),t=oe(t);return e}:Xt,ue=ie;function ce(t,e,r){var n=e(t);return _(t)?n:ne(n,r(t))}function ae(t){return ce(t,H,re)}function le(t){return ce(t,Ht,ue)}var se=lt(i,"DataView"),fe=lt(i,"Promise"),pe=lt(i,"Set"),de=lt(i,"WeakMap"),ye="[object Map]",ve="[object Promise]",be="[object Set]",he="[object WeakMap]",ge="[object DataView]",me=et(se),je=et(gt),_e=et(fe),we=et(pe),Oe=et(de),xe=d;(se&&xe(new se(new ArrayBuffer(1)))!=ge||gt&&xe(new gt)!=ye||fe&&xe(fe.resolve())!=ve||pe&&xe(new pe)!=be||de&&xe(new de)!=he)&&(xe=function(t){var e=d(t),r="[object Object]"==e?t.constructor:void 0,n=r?et(r):"";if(n)switch(n){case me:return ge;case je:return ye;case _e:return ve;case we:return be;case Oe:return he}return e});var ke=xe,Ae=Object.prototype.hasOwnProperty;var Ie=i.Uint8Array;function Se(t){var e=new t.constructor(t.byteLength);return new Ie(e).set(new Ie(t)),e}var Me=/\w*$/;var $e=u?u.prototype:void 0,Te=$e?$e.valueOf:void 0;function Ne(t,e,r){var n,o=t.constructor;switch(e){case"[object ArrayBuffer]":return Se(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var r=e?Se(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return function(t,e){var r=e?Se(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case"[object Map]":case"[object Set]":return new o;case"[object Number]":case"[object String]":return new o(t);case"[object RegExp]":return function(t){var e=new t.constructor(t.source,Me.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return n=t,Te?Object(Te.call(n)):{}}}var Ee=Object.create,Pe=function(){function t(){}return function(e){if(!R(e))return{};if(Ee)return Ee(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),De=Pe;var Fe=P&&P.isMap,Ue=Fe?$(Fe):function(t){return y(t)&&"[object Map]"==ke(t)};var ze=P&&P.isSet,Ce=ze?$(ze):function(t){return y(t)&&"[object Set]"==ke(t)},Be="[object Arguments]",Le="[object Function]",We="[object Object]",Ve={};function Re(t,e,r,n,o,i){var u,c=1&e,a=2&e,l=4&e;if(r&&(u=o?r(t,n,o,i):r(t)),void 0!==u)return u;if(!R(t))return t;var s=_(t);if(s){if(u=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&Ae.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!c)return function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}(t,u)}else{var f=ke(t),p=f==Le||"[object GeneratorFunction]"==f;if(k(t))return function(t,e){if(e)return t.slice();var r=t.length,n=Qt?Qt(r):new t.constructor(r);return t.copy(n),n}(t,c);if(f==We||f==Be||p&&!o){if(u=a||p?{}:function(t){return"function"!=typeof t.constructor||B(t)?{}:De(oe(t))}(t),!c)return a?function(t,e){return Rt(t,ue(t),e)}(t,function(t,e){return t&&Rt(e,Ht(e),t)}(u,t)):function(t,e){return Rt(t,re(t),e)}(t,function(t,e){return t&&Rt(e,H(e),t)}(u,t))}else{if(!Ve[f])return o?t:{};u=Ne(t,f,c)}}i||(i=new zt);var d=i.get(t);if(d)return d;i.set(t,u),Ce(t)?t.forEach(function(n){u.add(Re(n,e,r,n,t,i))}):Ue(t)&&t.forEach(function(n,o){u.set(o,Re(n,e,r,o,t,i))});var y=s?void 0:(l?a?le:ae:a?Ht:H)(t);return function(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););}(y||t,function(n,o){y&&(n=t[o=n]),Vt(u,o,Re(n,e,r,o,t,i))}),u}function qe(t,e){return e.length<2?t:Ft(t,function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i}(e,0,-1))}Ve[Be]=Ve["[object Array]"]=Ve["[object ArrayBuffer]"]=Ve["[object DataView]"]=Ve["[object Boolean]"]=Ve["[object Date]"]=Ve["[object Float32Array]"]=Ve["[object Float64Array]"]=Ve["[object Int8Array]"]=Ve["[object Int16Array]"]=Ve["[object Int32Array]"]=Ve["[object Map]"]=Ve["[object Number]"]=Ve[We]=Ve["[object RegExp]"]=Ve["[object Set]"]=Ve["[object String]"]=Ve["[object Symbol]"]=Ve["[object Uint8Array]"]=Ve["[object Uint8ClampedArray]"]=Ve["[object Uint16Array]"]=Ve["[object Uint32Array]"]=!0,Ve["[object Error]"]=Ve[Le]=Ve["[object WeakMap]"]=!1;var Ge=Object.prototype.hasOwnProperty;function He(t,e){var r=-1,n=(e=Pt(e,t)).length;if(!n)return!0;for(;++r<n;){var o=Dt(e[r]);if("__proto__"===o&&!Ge.call(t,"__proto__"))return!1;if(("constructor"===o||"prototype"===o)&&r<n-1)return!1}var i=qe(t,e);return null==i||delete i[Dt(function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0}(e))]}var Ke=Function.prototype,Je=Object.prototype,Ye=Ke.toString,Qe=Je.hasOwnProperty,Xe=Ye.call(Object);function Ze(t){return function(t){if(!y(t)||"[object Object]"!=d(t))return!1;var e=oe(t);if(null===e)return!0;var r=Qe.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Ye.call(r)==Xe}(t)?void 0:t}var tr=u?u.isConcatSpreadable:void 0;function er(t){return _(t)||j(t)||!!(tr&&t&&t[tr])}function rr(t,e,r,n,o){var i=-1,u=t.length;for(r||(r=er),o||(o=[]);++i<u;){var c=t[i];e>0&&r(c)?e>1?rr(c,e-1,r,n,o):ne(o,c):n||(o[o.length]=c)}return o}function nr(t){return(null==t?0:t.length)?rr(t,1):[]}var or=Math.max;var ir=Bt?function(t,e){return Bt(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:function(t){return t},ur=ir,cr=Date.now;var ar=function(t){var e=0,r=0;return function(){var n=cr(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(ur),lr=ar;var sr=function(t){return lr(function(t,e,r){return e=or(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=or(n.length-e,0),u=Array(i);++o<i;)u[o]=n[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=n[o];return c[e]=r(u),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,c)}}(t,void 0,nr),t+"")}(function(t,e){var r={};if(null==t)return r;var n=!1;e=Mt(e,function(e){return e=Pt(e,t),n||(n=e.length>1),e}),Rt(t,le(t),r),n&&(r=Re(r,7,Ze));for(var o=e.length;o--;)He(r,e[o]);return r}),fr=sr;function pr(t){return"[object Object]"===Object.prototype.toString.call(t)}function dr(t){return!(!function(t){return"[object String]"===Object.prototype.toString.call(t)}(t)||""===t)}function yr(){let t,e,r=new Promise(function(){t=arguments[0],e=arguments[1]});return r.resolve=t,r.reject=e,r}function vr(t){let e=!1;if(dr(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(function(t){return t!=t}(t))return!1;e=!0}return e}function br(t=10){vr(t)||(t=10);let e=yr();return setTimeout(function(){e.resolve()},t),e}var hr=/\s/;var gr=/^\s+/;function mr(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&hr.test(t.charAt(e)););return e}(t)+1).replace(gr,""):t}var jr=/^[-+]0x[0-9a-f]+$/i,_r=/^0b[01]+$/i,wr=/^0o[0-7]+$/i,Or=parseInt;function xr(t){if("number"==typeof t)return t;if(K(t))return NaN;if(R(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=R(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=mr(t);var r=_r.test(t);return r||wr.test(t)?Or(t.slice(2),r?2:8):jr.test(t)?NaN:+t}var kr=1/0;function Ar(t){return t?(t=xr(t))===kr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function Ir(t){var e=Ar(t),r=e%1;return e==e?r?e-r:e:0}var Sr=i.isFinite,Mr=Math.min;var $r=function(t){var e=Math[t];return function(t,r){if(t=xr(t),(r=null==r?0:Mr(Ir(r),292))&&Sr(t)){var n=(Et(t)+"e").split("e");return+((n=(Et(e(n[0]+"e"+(+n[1]+r)))+"e").split("e"))[0]+"e"+(+n[1]-r))}return e(t)}}("round"),Tr=$r;function Nr(t){if(!vr(t))return 0;return Ar(t)}function Er(t){if(!vr(t))return 0;t=Nr(t);let e=Tr(t);return"0"===String(e)?0:e}function Pr(t){return"[object Array]"===Object.prototype.toString.call(t)}function Dr(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function Fr(t){return!!vr(t)&&(t=Nr(t),"number"==typeof(e=t)&&e==Ir(e));var e}function Ur(t){if(!Fr(t))return!1;return Er(t)>0}function zr(t){if(!Fr(t))return!1;return Er(t)>=0}function Cr(t,e){return dr(t)&&zr(e)?0===(e=Er(e))?"":t.substring(0,e):""}function Br(t,e){return dr(t)&&zr(e)?0===(e=Er(e))?t:function(t,e){if(!dr(t))return"";if(!zr(e))return"";if(0===(e=Er(e)))return"";let r=t.length-e;return r<0&&(r=0),t.substring(r,r+e)}(t,t.length-e):""}function Lr(t,e,r={}){if(!dr(t))return"";if(!zr(e))return t;if(e=Er(e),t.length<=e)return t;let n=Ut(r,"funWithMsg"),o="";if(Dr(n)){let r=n(t,e);dr(r)&&(o=r)}return Cr(t,e)+`...${o}`}function Wr(t,e={}){let r=Ut(e,"fs");return!!function(t,e={}){let r=Ut(e,"fs"),n=!1;try{r.statSync(t),n=!0}catch{n=!1}return n}(t,{fs:r})&&(!r.lstatSync(t).isDirectory()&&!r.lstatSync(t).isSymbolicLink())}function Vr(t){return function(t,e={}){let r=null,n=Ut(e,"fs"),o="";try{o=n.readFileSync(t,"utf8")}catch(t){r=t}return null!==r?{error:r}:{success:o}}(t,{fs:r})}function Rr(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var qr=t,Gr=qr.spawn,Hr=qr.exec;function Kr(t,e,r){var n={};try{Object.keys(t).forEach(function(r){t[r].forEach(function(t){n[t]||(Jr(t,e),n[t]=1)}),n[r]||(Jr(r,e),n[r]=1)})}catch(t){if(r)return r(t);throw t}if(r)return r()}function Jr(t,e){try{process.kill(parseInt(t,10),e)}catch(t){if("ESRCH"!==t.code)throw t}}function Yr(t,e,r,n,o){var i=n(t),u="";i.stdout.on("data",function(t){t=t.toString("ascii");u+=t});i.on("close",function(i){delete r[t],0==i?u.match(/\d+/g).forEach(function(i){i=parseInt(i,10),e[t].push(i),e[i]=[],r[i]=1,Yr(i,e,r,n,o)}):0==Object.keys(r).length&&o()})}var Qr=Rr(function(t,e,r){if("function"==typeof e&&void 0===r&&(r=e,e=void 0),t=parseInt(t),Number.isNaN(t)){if(r)return r(new Error("pid must be a number"));throw new Error("pid must be a number")}var n={},o={};switch(n[t]=[],o[t]=1,process.platform){case"win32":Hr("taskkill /pid "+t+" /T /F",r);break;case"darwin":Yr(t,n,o,function(t){return Gr("pgrep",["-P",t])},function(){Kr(n,e,r)});break;default:Yr(t,n,o,function(t){return Gr("ps",["-o","pid","--no-headers","--ppid",t])},function(){Kr(n,e,r)})}});function Xr(t){let n=Ut(Vr(t),"success","");if(!dr(n))return null;let o=n.match(/%dp0%\\(node_modules\\[^"]+)"/i);if(!o)return null;let i=e.dirname(t),u=e.join(i,o[1]);return Wr(u,{fs:r})?u:null}function Zr(r,n){if("win32"!==process.platform)return{file:r,args:n};let o=function(r){if("win32"!==process.platform)return r;if(/\.(cmd|exe|bat|ps1)$/i.test(r))return r;if(e.isAbsolute(r))return r;try{let e=t.execFileSync("where",[r],{encoding:"utf8",timeout:5e3,windowsHide:!0,shell:!1,stdio:["ignore","pipe","ignore"]}).trim().split(/\r?\n/),n=e.find(t=>/\.cmd$/i.test(t));return n||(e.find(t=>/\.exe$/i.test(t))||e[0]||r)}catch{return r}}(r);if(/\.exe$/i.test(o))return{file:o,args:n};if(/\.(cmd|bat)$/i.test(o)){let t=Xr(o);if(t)return/\.exe$/i.test(t)?{file:t,args:n}:{file:process.execPath,args:[t,...n]};let e=n.map(t=>`"${t.replace(/(\\*)"/g,'$1$1\\"').replace(/(\\*)$/,"$1$1")}"`.replace(/[()%!^"<>&|]/g,"^$&")),r=`${i=o,i.replace(/[()%!^"<>&|;, ]/g,"^$&")} ${e.join(" ")}`;return{file:process.env.comspec||process.env.COMSPEC||"cmd.exe",args:["/d","/s","/c",`"${r}"`],opt:{windowsVerbatimArguments:!0}}}var i;return{file:o,args:n}}let tn={funWithMsg:t=>`(truncated, total ${t.length} chars)`};function en(e,r=[],n={}){let{timeoutMs:o=12e4,cwd:i=process.cwd(),input:u,validate:c,maxBuffer:a=10485760,onStdout:l,onStderr:s,env:f}=n,p=function(t){if(Dr(t))return t;if(!dr(t))return null;let e=t.split(",").map(t=>t.trim()).filter(Boolean);return 0===e.length?null:t=>{for(let r of e)if("nonempty"===r){if(!dr(t)||""===t.trim())return!1}else if("json"===r)try{JSON.parse(t)}catch{return!1}else if("min:"===Cr(r,4)){let e=Br(r,4);if(!vr(e))return!1;let n=Er(e);if(!dr(t)||t.length<n)return!1}return!0}}(c),d=Date.now(),y=yr(),v={...process.env,PYTHONIOENCODING:"utf-8"};if(void 0!==f){if("win32"===process.platform){let t=Object.keys(f).map(t=>t.toLowerCase());for(let e of Object.keys(v))t.includes(e.toLowerCase())&&delete v[e]}v={...v,...f}}let b=Zr(e,r),h=t.spawn(b.file,b.args,{cwd:i,stdio:["pipe","pipe","pipe"],windowsHide:!0,env:v,...b.opt}),g="",m="",j=new TextDecoder("utf-8"),_=new TextDecoder("utf-8"),w=!1,O=!1;h.stdout.on("data",t=>{let e=j.decode(t,{stream:!0});e&&(Dr(l)&&l(e),g.length<a&&(g+=e))}),h.stderr.on("data",t=>{let e=_.decode(t,{stream:!0});e&&(Dr(s)&&s(e),m.length<a&&(m+=e))}),h.stdin.on("error",()=>{}),void 0!==u&&h.stdin.write(u,"utf8"),h.stdin.end();let x=setTimeout(()=>{w||(O=!0,function(t){let e=yr();return Qr(Number(t),"SIGKILL",r=>{r?e.reject(r):e.resolve(`pid[${t}] killed`)}),e}(h.pid).catch(()=>{}),setTimeout(()=>{w||(w=!0,y.resolve({ok:!1,stdout:Lr(g,500,tn),stderr:Lr(m,500,tn),code:null,error:`TIMEOUT after ${o/1e3}s(子進程未能結束)`,durationMs:Date.now()-d,pid:h.pid}))},3e3).unref())},o);return h.on("error",t=>{w||(w=!0,clearTimeout(x),y.resolve({ok:!1,stdout:"",stderr:"",code:null,error:`${t.code||"UNKNOWN"}: ${t.message}`,durationMs:Date.now()-d,pid:h.pid}))}),h.on("close",(t,e)=>{if(w)return;w=!0,clearTimeout(x);let r=j.decode();r&&g.length<a&&(g+=r);let n=_.decode();n&&m.length<a&&(m+=n);let i=Date.now()-d;O?y.resolve({ok:!1,stdout:Lr(g,500,tn),stderr:Lr(m,500,tn),code:t,error:`TIMEOUT after ${o/1e3}s`,durationMs:i,pid:h.pid}):0===t?!p||p(g)?y.resolve({ok:!0,stdout:g,stderr:m,code:0,error:"",durationMs:i,pid:h.pid}):y.resolve({ok:!1,stdout:Lr(g,500,tn),stderr:Lr(m,500,tn),code:0,error:"OUTPUT_VALIDATION_FAILED",durationMs:i,pid:h.pid}):y.resolve({ok:!1,stdout:Lr(g,500,tn),stderr:Lr(m,1e3,tn),code:t,error:e?`Signal: ${e}`:`Exit code ${t}`,durationMs:i,pid:h.pid})}),y}async function rn(t,e=[],r={}){if(!dr(t))return{ok:!1,stdout:"",stderr:"",code:null,error:"command 須為非空字串",durationMs:0,attempts:0};Pr(e)||(e=[]),pr(r)||(r={});let{maxRetries:n=0,retryDelayMs:o=5e3,...i}=r,u=Ut(i,"cwd",null);dr(u)?i.cwd=u:i.cwd=process.cwd();let c=Ut(i,"input",null);dr(c)?i.input=c:i.input=void 0;let a=Ut(i,"env",null);pr(a)?i.env=a:i.env=void 0;let l=Ut(i,"validate",null);Dr(l)||dr(l)?i.validate=l:i.validate=void 0;let s=Ut(i,"onStdout",null);Dr(s)?i.onStdout=s:i.onStdout=void 0;let f=Ut(i,"onStderr",null);Dr(f)?i.onStderr=f:i.onStderr=void 0,n=zr(n)?Er(n):0,o=Ur(o)?Er(o):5e3;let p=Ut(i,"timeoutMs",null);Ur(p)?i.timeoutMs=Er(p):i.timeoutMs=12e4;let d,y=Ut(i,"maxBuffer",null);Ur(y)?i.maxBuffer=Er(y):i.maxBuffer=10485760;let v=0;for(let r=0;r<=n;r++){if(r>0){let t=Math.min(o*r,15e3);await br(t)}if(d=await en(t,e,i),v=r+1,d.ok)return d.attempts=v,d;if(d.error.includes("ENOENT"))break;if(2===d.code)break}return d.attempts=v,d}function nn(...t){let e=[];for(let r of t)if(Pr(r))for(let t of r)dr(t)&&e.push(t);else dr(r)&&e.push(r);return e}function on(t){return dr(t)||(t="unknown error"),{ok:!1,stdout:"",stderr:"",code:null,error:t,durationMs:0,attempts:0}}let un=["exe","model","key","provider","agent","config","extraArgs","input","env"];async function cn(t,e={}){if(!dr(t))return on("prompt must be a non-empty string");let r=Ut(e,"exe",null);dr(r)||(r="opencode");let n=Ut(e,"model",null),o=Ut(e,"agent",null);dr(o)||(o="build");let i=Ut(e,"extraArgs",null),u=nn("run",["--agent",o],dr(n)?["-m",n]:[],i),c=Ut(e,"env",null);pr(c)||(c=void 0);let a=Ut(e,"config",null);pr(a)&&(a=JSON.stringify(a)),dr(a)&&(c={...c,OPENCODE_CONFIG_CONTENT:a});let l=Ut(e,"key",null),s=Ut(e,"provider",null);return dr(l)&&dr(s)&&(c={...c,OPENCODE_AUTH_CONTENT:JSON.stringify({[s]:{type:"api",key:l}})}),rn(r,u,{...fr(e,un),input:t,env:c})}function an(t){return!0===(e=t)||!1===e||y(e)&&"[object Boolean]"==d(e);var e}let ln=["exe","model","skipPermissions","extraArgs","input"];async function sn(t,e={}){if(!dr(t))return on("prompt must be a non-empty string");let r=Ut(e,"exe",null);dr(r)||(r="claude");let n=Ut(e,"model",null),o=Ut(e,"skipPermissions",null);an(o)||(o=!0);let i=Ut(e,"extraArgs",null);return rn(r,nn("-p",o?"--dangerously-skip-permissions":[],dr(n)?["--model",n]:[],i),{...fr(e,ln),input:t})}let fn=["exe","model","sandbox","extraArgs","input"];async function pn(t,e={}){if(!dr(t))return on("prompt must be a non-empty string");let r=Ut(e,"exe",null);dr(r)||(r="codex");let n=Ut(e,"model",null),o=Ut(e,"sandbox",null);dr(o)||(o="workspace-write");let i=Ut(e,"extraArgs",null);return rn(r,nn("exec",["--sandbox",o],"--skip-git-repo-check",dr(n)?["-m",n]:[],i),{...fr(e,fn),input:t})}let dn=["exe","model","effort","skipPermissions","printTimeout","addDirs","extraArgs","input"];async function yn(t,e={}){if(!dr(t))return on("prompt must be a non-empty string");if(t.length>3e4)return on(`prompt too long (${t.length} chars > 30000), agy passes prompt via --print flag and Windows command line is capped at 32767 chars`);let r=Ut(e,"exe",null);dr(r)||(r="agy");let n=Ut(e,"model",null),o=Ut(e,"effort",null),i=Ut(e,"skipPermissions",null);an(i)||(i=!0);let u=Ut(e,"timeoutMs",null);u=Ur(u)?Er(u):3e5;let c=Ut(e,"printTimeout",null);dr(c)||(c=`${Math.max(30,Math.floor(u/1e3)-30)}s`);let a=Ut(e,"addDirs",null),l=[];if(Pr(a))for(let t of a)dr(t)&&l.push("--add-dir",t);let s=Ut(e,"extraArgs",null),f=nn(i?"--dangerously-skip-permissions":[],["--print-timeout",c],dr(n)?["--model",n]:[],dr(o)?["--effort",o]:[],l,s,["--print",t]),p=fr(e,dn);try{return await rn(r,f,{...p,timeoutMs:u})}catch(t){return on(`${t.code||"UNKNOWN"}: ${t.message}`)}}let vn={opencode:cn,claude:sn,codex:pn,antigravity:yn};function bn(t){return t!=t}function hn(t){return null==t?[]:function(t,e){return Mt(e,function(e){return t[e]})}(t,H(t))}var gn=Math.max;function mn(t,e,r,n){t=G(t)?t:hn(t),r=r&&!n?Ir(r):0;var o=t.length;return r<0&&(r=gn(o+r,0)),function(t){return"string"==typeof t||!_(t)&&y(t)&&"[object String]"==d(t)}(t)?r<=o&&t.indexOf(e,r)>-1:!!o&&function(t,e,r){return e==e?function(t,e,r){for(var n=r-1,o=t.length;++n<o;)if(t[n]===e)return n;return-1}(t,e,r):function(t,e,r,n){for(var o=t.length,i=r+(n?1:-1);n?i--:++i<o;)if(e(t[i],i,t))return i;return-1}(t,bn,r)}(t,e,r)>-1}async function jn(t,e,r={}){let n=H(vn);return dr(t)&&mn(n,t)?(0,vn[t])(e,r):on(`unknown ai kind: "${t}" (available: ${n.join(", ")})`)}let _n=["providers","budgetMs","minAttemptMs","store","onEvent"],wn=["id","keys"],On={cursors:{}};function xn(t){let e=Ut(t,"error","");dr(e)||(e="");let r=Ut(t,"code",null);return 0===e.indexOf("TIMEOUT")||(!!e.includes("ENOENT")||(2===r||("OUTPUT_VALIDATION_FAILED"===e||0===e.indexOf("unknown ai kind"))))}return{KINDS:H(vn),dispatchAi:jn,dispatchAiFallback:async function(t,e={}){if(!dr(t))return{...on("prompt must be a non-empty string"),tried:[]};let r=Ut(e,"providers",null),n=Pr(r)?r.filter(pr):[];if(0===n.length)return{...on("providers must be a non-empty array"),tried:[]};let o=Ut(e,"budgetMs",null);o=Ur(o)?Er(o):null;let i=null===o?null:Date.now()+o,u=Ut(e,"minAttemptMs",null);u=Ur(u)?Er(u):2e4;let c=Ut(e,"store",null),a=pr(c)&&Dr(c.get)&&Dr(c.set),l=null;if(a)try{l=c.get()}catch{}pr(l)||(l=a?{cursors:{}}:On),pr(l.cursors)||(l.cursors={});let s=()=>{if(a)try{c.set(l)}catch{}},f=Ut(e,"onEvent",null),p=t=>{if(Dr(f))try{f(t)}catch{}},d=fr(e,_n),y=[],v=null,b=null;for(let e=0;e<n.length;e++){let r=n[e],o=Ut(r,"id",null);dr(o)||(o=String(e));let c=Ut(r,"kind",null),a=Ut(r,"model",null),f=Ut(r,"keys",null),h=Pr(f)?f.filter(dr):[],g=h.length,m=fr(r,wn),j=0;if(g>0){let t=Ut(l.cursors,o,0);j=Ur(t)?Er(t)%g:0}let _=g>0?g:1,w=!1;for(let e=0;e<_&&!w;e++){let r=g>0?(j+e)%g:null,n=null===r?o:`${o}#${r}`,f={...d,...m};g>0&&(f.key=h[r]);let _=Ut(f,"timeoutMs",null);if(_=Ur(_)?Er(_):12e4,null!==i){let t=i-Date.now();if(t<u)return p({type:"budget-out",providerId:o,keyIndex:r,keyId:n,remainingMs:t}),y.push({providerId:o,keyIndex:r,keyId:n,outcome:"budget-out"}),{...on("budget exhausted"),tried:y};_=Math.min(_,t)}f.timeoutMs=_,p({type:"try",providerId:o,keyIndex:r,keyId:n,kind:c,model:a});let O=await jn(c,t,f);if(O.ok)return g>0&&(l.cursors[o]=(r+1)%g,s()),p({type:"ok",providerId:o,keyIndex:r,keyId:n,durationMs:O.durationMs}),y.push({providerId:o,keyIndex:r,keyId:n,outcome:"ok",durationMs:O.durationMs}),{...O,providerId:o,keyIndex:r,kind:c,model:a,tried:y};v=O,b={providerId:o,keyIndex:r,kind:c,model:a},xn(O)?(p({type:"skip-group",providerId:o,keyIndex:r,keyId:n,error:O.error}),y.push({providerId:o,keyIndex:r,keyId:n,outcome:"skip-group",error:O.error,durationMs:O.durationMs}),w=!0):(p({type:"next-key",providerId:o,keyIndex:r,keyId:n,error:O.error}),y.push({providerId:o,keyIndex:r,keyId:n,outcome:"next-key",error:O.error,durationMs:O.durationMs}))}}return{...v||on("all providers failed"),...b||{},tried:y}},dispatchOpencode:cn,dispatchClaude:sn,dispatchCodex:pn,dispatchAntigravity:yn}});
|
|
7
7
|
//# sourceMappingURL=w-dispatch-ai.umd.js.map
|