w-dispatch-ai 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +207 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +16 -0
  9. package/dist/w-dispatch-ai.umd.js +7 -0
  10. package/dist/w-dispatch-ai.umd.js.map +1 -0
  11. package/docs/WDispatchAi.mjs.html +110 -0
  12. package/docs/adapters.mjs.html +100 -0
  13. package/docs/dispatchAi.mjs.html +133 -0
  14. package/docs/dispatchClaude.mjs.html +190 -0
  15. package/docs/dispatchCodex.mjs.html +191 -0
  16. package/docs/dispatchOpencode.mjs.html +260 -0
  17. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  20. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  21. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  22. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  23. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  24. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  30. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  31. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  32. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  33. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  34. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  35. package/docs/getCliArgs.mjs.html +126 -0
  36. package/docs/getErrorResult.mjs.html +115 -0
  37. package/docs/global.html +2924 -0
  38. package/docs/index.html +84 -0
  39. package/docs/scripts/collapse.js +39 -0
  40. package/docs/scripts/commonNav.js +28 -0
  41. package/docs/scripts/linenumber.js +25 -0
  42. package/docs/scripts/nav.js +12 -0
  43. package/docs/scripts/polyfill.js +4 -0
  44. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  45. package/docs/scripts/prettify/lang-css.js +2 -0
  46. package/docs/scripts/prettify/prettify.js +28 -0
  47. package/docs/scripts/search.js +99 -0
  48. package/docs/styles/jsdoc.css +776 -0
  49. package/docs/styles/prettify.css +80 -0
  50. package/g.mjs +94 -0
  51. package/package.json +38 -0
  52. package/script.txt +17 -0
  53. package/src/WDispatchAi.mjs +38 -0
  54. package/src/adapters.mjs +28 -0
  55. package/src/dispatchAi.mjs +61 -0
  56. package/src/dispatchClaude.mjs +118 -0
  57. package/src/dispatchCodex.mjs +119 -0
  58. package/src/dispatchOpencode.mjs +188 -0
  59. package/src/getCliArgs.mjs +54 -0
  60. package/src/getErrorResult.mjs +43 -0
  61. package/test/tools/fakeCliForTest.mjs +139 -0
  62. package/test/unit-WDispatchAi.test.mjs +79 -0
  63. package/test/unit-adapters.test.mjs +34 -0
  64. package/test/unit-dispatchAi.test.mjs +104 -0
  65. package/test/unit-dispatchClaude.test.mjs +144 -0
  66. package/test/unit-dispatchCodex.test.mjs +113 -0
  67. package/test/unit-dispatchOpencode.test.mjs +176 -0
  68. package/test/unit-getCliArgs.test.mjs +55 -0
  69. package/test/unit-getErrorResult.test.mjs +45 -0
  70. package/toolg/addVersion.mjs +4 -0
  71. package/toolg/cleanFolder.mjs +5 -0
  72. package/toolg/gDistRollup.mjs +24 -0
  73. package/toolg/modifyReadme.mjs +4 -0
@@ -0,0 +1,2924 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+
5
+ <meta charset="utf-8">
6
+ <title>Global - 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#dispatchAi">dispatchAi</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></ul>
33
+
34
+ </nav>
35
+
36
+ <div id="main">
37
+
38
+ <h1 class="page-title">Global</h1>
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ <section>
47
+
48
+ <header>
49
+
50
+ <h2>
51
+
52
+
53
+
54
+ </h2>
55
+
56
+
57
+ </header>
58
+
59
+ <article>
60
+
61
+ <div class="container-overview">
62
+
63
+
64
+
65
+ <dl class="details">
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ </dl>
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ </div>
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+ <h3 class="subsection-title">Members</h3>
125
+
126
+
127
+
128
+ <h4 class="name" id="WDispatchAi"><span class="type-signature"></span>WDispatchAi<span class="type-signature"></span></h4>
129
+
130
+
131
+
132
+
133
+
134
+ <dl class="details">
135
+
136
+ <dt class="tag-description">Description:</dt>
137
+ <dd class="tag-description"><ul class="dummy"><li><p>AI供應商分派</p></li></ul></dd>
138
+
139
+
140
+
141
+ <dt class="tag-source">Source:</dt>
142
+ <dd class="tag-source"><ul class="dummy"><li>
143
+ <a href="WDispatchAi.mjs.html">WDispatchAi.mjs</a>, <a href="WDispatchAi.mjs.html#line29">line 29</a>
144
+ </li></ul></dd>
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+ </dl>
177
+
178
+
179
+
180
+
181
+
182
+ <div class="description usertext">
183
+ <p>AI供應商分派</p>
184
+ </div>
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+ <h5 class="h5-examples">Example</h5>
193
+
194
+ <pre class="prettyprint"><code>詳見dispatchAi、dispatchOpencode、dispatchClaude、dispatchCodex範例</code></pre>
195
+
196
+
197
+
198
+
199
+
200
+ <h4 class="name" id="adapters"><span class="type-signature"></span>adapters<span class="type-signature"></span></h4>
201
+
202
+
203
+
204
+
205
+
206
+ <dl class="details">
207
+
208
+ <dt class="tag-description">Description:</dt>
209
+ <dd class="tag-description"><ul class="dummy"><li><p>各AI供應商種類(kind)對CLI轉接器函數之對照表</p>
210
+ <p>本對照表為kind之唯一來源,dispatchAi以其鍵值分派,WDispatchAi以其鍵名產生KINDS,
211
+ 新增供應商時僅須於此加入一個鍵值對即可</p></li></ul></dd>
212
+
213
+
214
+
215
+ <dt class="tag-source">Source:</dt>
216
+ <dd class="tag-source"><ul class="dummy"><li>
217
+ <a href="adapters.mjs.html">adapters.mjs</a>, <a href="adapters.mjs.html#line21">line 21</a>
218
+ </li></ul></dd>
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+ </dl>
251
+
252
+
253
+
254
+
255
+
256
+ <div class="description usertext">
257
+ <p>各AI供應商種類(kind)對CLI轉接器函數之對照表</p>
258
+ <p>本對照表為kind之唯一來源,dispatchAi以其鍵值分派,WDispatchAi以其鍵名產生KINDS,
259
+ 新增供應商時僅須於此加入一個鍵值對即可</p>
260
+ </div>
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+ <h5 class="h5-examples">Example</h5>
269
+
270
+ <pre class="prettyprint"><code>import adapters from './src/adapters.mjs'
271
+
272
+ console.log(Object.keys(adapters))
273
+ // => ['opencode', 'claude', 'codex']</code></pre>
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+ <h3 class="subsection-title">Methods</h3>
282
+
283
+
284
+
285
+
286
+
287
+
288
+ <h4 class="name" id="dispatchAi"><span class="type-signature type-signature-async">(async) </span>dispatchAi<span class="signature">(kind, prompt, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
289
+
290
+
291
+
292
+
293
+
294
+
295
+ <dl class="details">
296
+
297
+ <dt class="tag-description">Description:</dt>
298
+ <dd class="tag-description"><ul class="dummy"><li><p>依供應商種類(kind)分派至對應之CLI轉接器</p>
299
+ <p>三種供應商的差異(2026-08-08於本機實測確認):
300
+ opencode支援逐次注入金鑰(OPENCODE_AUTH_CONTENT),故可多把金鑰輪替;
301
+ claude與codex則沿用CLI既有登入狀態,無逐次金鑰概念。
302
+ 故「輪替」的單位是「供應商條目」而非單純的金鑰:一個條目即一組(kind, model, 可選的key/provider),
303
+ 輪到誰就用誰的CLI與模型</p></li></ul></dd>
304
+
305
+
306
+
307
+ <dt class="tag-source">Source:</dt>
308
+ <dd class="tag-source"><ul class="dummy"><li>
309
+ <a href="dispatchAi.mjs.html">dispatchAi.mjs</a>, <a href="dispatchAi.mjs.html#line43">line 43</a>
310
+ </li></ul></dd>
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+ </dl>
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+ <h5 class="h5-examples">Example</h5>
355
+
356
+ <pre class="prettyprint"><code>//need claude, codex or opencode cli in system PATH
357
+
358
+ import dispatchAi from './src/dispatchAi.mjs'
359
+
360
+ let test = async () => {
361
+
362
+ let r = await dispatchAi('claude', '請只回覆兩個字:完成', { model: 'sonnet' })
363
+ console.log(r.ok, r.stdout.trim())
364
+ // => true '完成'
365
+
366
+ let re = await dispatchAi('gemini', 'abc')
367
+ console.log(re.ok, re.error)
368
+ // => false 'unknown ai kind: "gemini" (available: opencode, claude, codex)'
369
+
370
+ }
371
+ await test()
372
+ .catch((err) => {
373
+ console.log(err)
374
+ })</code></pre>
375
+
376
+
377
+
378
+
379
+ <h5 class="h5-parameters">Parameters:</h5>
380
+
381
+
382
+ <table class="params">
383
+ <thead>
384
+ <tr>
385
+
386
+ <th>Name</th>
387
+
388
+
389
+ <th>Type</th>
390
+
391
+
392
+ <th>Attributes</th>
393
+
394
+
395
+
396
+ <th>Default</th>
397
+
398
+
399
+ <th class="last">Description</th>
400
+ </tr>
401
+ </thead>
402
+
403
+ <tbody>
404
+
405
+
406
+ <tr>
407
+
408
+ <td class="name"><code>kind</code></td>
409
+
410
+
411
+ <td class="type">
412
+
413
+
414
+ <span class="param-type">String</span>
415
+
416
+
417
+
418
+
419
+ </td>
420
+
421
+
422
+ <td class="attributes">
423
+
424
+
425
+
426
+
427
+
428
+ </td>
429
+
430
+
431
+
432
+ <td class="default">
433
+
434
+ </td>
435
+
436
+
437
+ <td class="description last"><p>輸入供應商種類字串,可選'opencode'、'claude'、'codex'</p></td>
438
+ </tr>
439
+
440
+
441
+
442
+ <tr>
443
+
444
+ <td class="name"><code>prompt</code></td>
445
+
446
+
447
+ <td class="type">
448
+
449
+
450
+ <span class="param-type">String</span>
451
+
452
+
453
+
454
+
455
+ </td>
456
+
457
+
458
+ <td class="attributes">
459
+
460
+
461
+
462
+
463
+
464
+ </td>
465
+
466
+
467
+
468
+ <td class="default">
469
+
470
+ </td>
471
+
472
+
473
+ <td class="description last"><p>輸入提示詞字串,一律以stdin傳入子進程</p></td>
474
+ </tr>
475
+
476
+
477
+
478
+ <tr>
479
+
480
+ <td class="name"><code>opt</code></td>
481
+
482
+
483
+ <td class="type">
484
+
485
+
486
+ <span class="param-type">Object</span>
487
+
488
+
489
+
490
+
491
+ </td>
492
+
493
+
494
+ <td class="attributes">
495
+
496
+ &lt;optional><br>
497
+
498
+
499
+
500
+
501
+
502
+ </td>
503
+
504
+
505
+
506
+ <td class="default">
507
+
508
+ <code>{}</code>
509
+
510
+ </td>
511
+
512
+
513
+ <td class="description last"><p>輸入設定物件,原樣轉傳對應轉接器,各轉接器可用設定詳見dispatchOpencode、dispatchClaude、dispatchCodex,預設{}</p></td>
514
+ </tr>
515
+
516
+
517
+ </tbody>
518
+ </table>
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+ <h5 class="h5-returns">Returns:</h5>
536
+
537
+
538
+ <div class="param-desc">
539
+ <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(標準輸出字串)、stderr(標準錯誤字串)、code(離開碼)、error(錯誤訊息字串,成功時為空字串)、durationMs(耗時毫秒)、attempts(實際嘗試次數),本函數不會reject</p>
540
+ </div>
541
+
542
+
543
+
544
+ <dl class="param-type">
545
+ <dt>
546
+ Type
547
+ </dt>
548
+ <dd>
549
+
550
+ <span class="param-type">Promise</span>
551
+
552
+
553
+
554
+ </dd>
555
+ </dl>
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+ <h4 class="name" id="dispatchClaude"><span class="type-signature type-signature-async">(async) </span>dispatchClaude<span class="signature">(prompt, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
567
+
568
+
569
+
570
+
571
+
572
+
573
+ <dl class="details">
574
+
575
+ <dt class="tag-description">Description:</dt>
576
+ <dd class="tag-description"><ul class="dummy"><li><p>以Claude Code CLI呼叫Claude模型</p>
577
+ <p>特點:
578
+ prompt一律走stdin而非位置參數,因摘要內文可達數萬字,當命令列參數會spawn ENAMETOOLONG;
579
+ 沿用Claude Code既有登入狀態,無逐次注入API key之概念,故無key參數;
580
+ 未給model時不帶<code>--model</code>旗標,由CLI自行決定使用模型;
581
+ 預設帶<code>--dangerously-skip-permissions</code>令非互動之<code>-p</code>模式不因權限確認而卡住,
582
+ 惟prompt含不可信內容(例如待摘要之網頁)時該內容之指示亦將無權限閘門執行,
583
+ 可給予skipPermissions為false保留CLI權限閘門;
584
+ 本函數不會reject,一律以結果物件之ok與error欄位回報成敗</p></li></ul></dd>
585
+
586
+
587
+
588
+ <dt class="tag-source">Source:</dt>
589
+ <dd class="tag-source"><ul class="dummy"><li>
590
+ <a href="dispatchClaude.mjs.html">dispatchClaude.mjs</a>, <a href="dispatchClaude.mjs.html#line74">line 74</a>
591
+ </li></ul></dd>
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+ </dl>
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
633
+
634
+
635
+ <h5 class="h5-examples">Example</h5>
636
+
637
+ <pre class="prettyprint"><code>//need claude cli in system PATH
638
+
639
+ import dispatchClaude from './src/dispatchClaude.mjs'
640
+
641
+ let test = async () => {
642
+
643
+ let r = await dispatchClaude('請只回覆兩個字:完成', { model: 'sonnet', timeoutMs: 120000 })
644
+ console.log(r.ok, r.stdout.trim())
645
+ // => true '完成'
646
+
647
+ let re = await dispatchClaude('')
648
+ console.log(re.ok, re.error)
649
+ // => false 'prompt must be a non-empty string'
650
+
651
+ }
652
+ await test()
653
+ .catch((err) => {
654
+ console.log(err)
655
+ })</code></pre>
656
+
657
+
658
+
659
+
660
+ <h5 class="h5-parameters">Parameters:</h5>
661
+
662
+
663
+ <table class="params">
664
+ <thead>
665
+ <tr>
666
+
667
+ <th>Name</th>
668
+
669
+
670
+ <th>Type</th>
671
+
672
+
673
+ <th>Attributes</th>
674
+
675
+
676
+
677
+ <th>Default</th>
678
+
679
+
680
+ <th class="last">Description</th>
681
+ </tr>
682
+ </thead>
683
+
684
+ <tbody>
685
+
686
+
687
+ <tr>
688
+
689
+ <td class="name"><code>prompt</code></td>
690
+
691
+
692
+ <td class="type">
693
+
694
+
695
+ <span class="param-type">String</span>
696
+
697
+
698
+
699
+
700
+ </td>
701
+
702
+
703
+ <td class="attributes">
704
+
705
+
706
+
707
+
708
+
709
+ </td>
710
+
711
+
712
+
713
+ <td class="default">
714
+
715
+ </td>
716
+
717
+
718
+ <td class="description last"><p>輸入提示詞字串,一律以stdin傳入子進程</p></td>
719
+ </tr>
720
+
721
+
722
+
723
+ <tr>
724
+
725
+ <td class="name"><code>opt</code></td>
726
+
727
+
728
+ <td class="type">
729
+
730
+
731
+ <span class="param-type">Object</span>
732
+
733
+
734
+
735
+
736
+ </td>
737
+
738
+
739
+ <td class="attributes">
740
+
741
+ &lt;optional><br>
742
+
743
+
744
+
745
+
746
+
747
+ </td>
748
+
749
+
750
+
751
+ <td class="default">
752
+
753
+ <code>{}</code>
754
+
755
+ </td>
756
+
757
+
758
+ <td class="description last"><p>輸入設定物件,預設{}</p>
759
+ <h6>Properties</h6>
760
+
761
+
762
+ <table class="params">
763
+ <thead>
764
+ <tr>
765
+
766
+ <th>Name</th>
767
+
768
+
769
+ <th>Type</th>
770
+
771
+
772
+ <th>Attributes</th>
773
+
774
+
775
+
776
+ <th>Default</th>
777
+
778
+
779
+ <th class="last">Description</th>
780
+ </tr>
781
+ </thead>
782
+
783
+ <tbody>
784
+
785
+
786
+ <tr>
787
+
788
+ <td class="name"><code>exe</code></td>
789
+
790
+
791
+ <td class="type">
792
+
793
+
794
+ <span class="param-type">String</span>
795
+
796
+
797
+
798
+
799
+ </td>
800
+
801
+
802
+ <td class="attributes">
803
+
804
+ &lt;optional><br>
805
+
806
+
807
+
808
+
809
+
810
+ </td>
811
+
812
+
813
+
814
+ <td class="default">
815
+
816
+ <code>'claude'</code>
817
+
818
+ </td>
819
+
820
+
821
+ <td class="description last"><p>輸入claude執行檔名稱或絕對路徑字串,給予名稱時由execCli自系統PATH解析,預設'claude'</p></td>
822
+ </tr>
823
+
824
+
825
+
826
+ <tr>
827
+
828
+ <td class="name"><code>model</code></td>
829
+
830
+
831
+ <td class="type">
832
+
833
+
834
+ <span class="param-type">String</span>
835
+
836
+
837
+
838
+
839
+ </td>
840
+
841
+
842
+ <td class="attributes">
843
+
844
+ &lt;optional><br>
845
+
846
+
847
+
848
+
849
+
850
+ </td>
851
+
852
+
853
+
854
+ <td class="default">
855
+
856
+ <code>''</code>
857
+
858
+ </td>
859
+
860
+
861
+ <td class="description last"><p>輸入模型別名或模型ID字串,例如'sonnet'、'opus',預設''代表不帶<code>--model</code>旗標</p></td>
862
+ </tr>
863
+
864
+
865
+
866
+ <tr>
867
+
868
+ <td class="name"><code>skipPermissions</code></td>
869
+
870
+
871
+ <td class="type">
872
+
873
+
874
+ <span class="param-type">Boolean</span>
875
+
876
+
877
+
878
+
879
+ </td>
880
+
881
+
882
+ <td class="attributes">
883
+
884
+ &lt;optional><br>
885
+
886
+
887
+
888
+
889
+
890
+ </td>
891
+
892
+
893
+
894
+ <td class="default">
895
+
896
+ <code>true</code>
897
+
898
+ </td>
899
+
900
+
901
+ <td class="description last"><p>輸入是否帶<code>--dangerously-skip-permissions</code>旗標布林值,false代表保留CLI權限閘門,預設true</p></td>
902
+ </tr>
903
+
904
+
905
+
906
+ <tr>
907
+
908
+ <td class="name"><code>extraArgs</code></td>
909
+
910
+
911
+ <td class="type">
912
+
913
+
914
+ <span class="param-type">Array</span>
915
+
916
+
917
+
918
+
919
+ </td>
920
+
921
+
922
+ <td class="attributes">
923
+
924
+ &lt;optional><br>
925
+
926
+
927
+
928
+
929
+
930
+ </td>
931
+
932
+
933
+
934
+ <td class="default">
935
+
936
+ <code>[]</code>
937
+
938
+ </td>
939
+
940
+
941
+ <td class="description last"><p>輸入額外命令列旗標字串陣列,將接於固定旗標之後,預設[]</p></td>
942
+ </tr>
943
+
944
+
945
+
946
+ <tr>
947
+
948
+ <td class="name"><code>timeoutMs</code></td>
949
+
950
+
951
+ <td class="type">
952
+
953
+
954
+ <span class="param-type">Number</span>
955
+
956
+
957
+
958
+
959
+ </td>
960
+
961
+
962
+ <td class="attributes">
963
+
964
+ &lt;optional><br>
965
+
966
+
967
+
968
+
969
+
970
+ </td>
971
+
972
+
973
+
974
+ <td class="default">
975
+
976
+ <code>120000</code>
977
+
978
+ </td>
979
+
980
+
981
+ <td class="description last"><p>輸入逾時毫秒正整數,逾時將強制關閉子進程及其子孫程序,預設120000</p></td>
982
+ </tr>
983
+
984
+
985
+
986
+ <tr>
987
+
988
+ <td class="name"><code>cwd</code></td>
989
+
990
+
991
+ <td class="type">
992
+
993
+
994
+ <span class="param-type">String</span>
995
+
996
+
997
+
998
+
999
+ </td>
1000
+
1001
+
1002
+ <td class="attributes">
1003
+
1004
+ &lt;optional><br>
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+ </td>
1011
+
1012
+
1013
+
1014
+ <td class="default">
1015
+
1016
+ <code>process.cwd()</code>
1017
+
1018
+ </td>
1019
+
1020
+
1021
+ <td class="description last"><p>輸入子進程工作目錄字串,預設process.cwd()</p></td>
1022
+ </tr>
1023
+
1024
+
1025
+
1026
+ <tr>
1027
+
1028
+ <td class="name"><code>validate</code></td>
1029
+
1030
+
1031
+ <td class="type">
1032
+
1033
+
1034
+ <span class="param-type">String</span>
1035
+ |
1036
+
1037
+ <span class="param-type">function</span>
1038
+
1039
+
1040
+
1041
+
1042
+ </td>
1043
+
1044
+
1045
+ <td class="attributes">
1046
+
1047
+ &lt;optional><br>
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+ </td>
1054
+
1055
+
1056
+
1057
+ <td class="default">
1058
+
1059
+ </td>
1060
+
1061
+
1062
+ <td class="description last"><p>輸入stdout驗證規則字串或自訂驗證函數,規則字串支援'nonempty'、'json'、'min:100',多規則可用逗號串接,預設undefined代表不驗證</p></td>
1063
+ </tr>
1064
+
1065
+
1066
+
1067
+ <tr>
1068
+
1069
+ <td class="name"><code>maxRetries</code></td>
1070
+
1071
+
1072
+ <td class="type">
1073
+
1074
+
1075
+ <span class="param-type">Number</span>
1076
+
1077
+
1078
+
1079
+
1080
+ </td>
1081
+
1082
+
1083
+ <td class="attributes">
1084
+
1085
+ &lt;optional><br>
1086
+
1087
+
1088
+
1089
+
1090
+
1091
+ </td>
1092
+
1093
+
1094
+
1095
+ <td class="default">
1096
+
1097
+ <code>0</code>
1098
+
1099
+ </td>
1100
+
1101
+
1102
+ <td class="description last"><p>輸入失敗後最大重試次數非負整數,預設0</p></td>
1103
+ </tr>
1104
+
1105
+
1106
+ </tbody>
1107
+ </table>
1108
+
1109
+ </td>
1110
+ </tr>
1111
+
1112
+
1113
+ </tbody>
1114
+ </table>
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+
1122
+
1123
+
1124
+
1125
+
1126
+
1127
+
1128
+
1129
+
1130
+
1131
+ <h5 class="h5-returns">Returns:</h5>
1132
+
1133
+
1134
+ <div class="param-desc">
1135
+ <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(標準輸出字串)、stderr(標準錯誤字串)、code(離開碼)、error(錯誤訊息字串,成功時為空字串)、durationMs(耗時毫秒)、attempts(實際嘗試次數),本函數不會reject</p>
1136
+ </div>
1137
+
1138
+
1139
+
1140
+ <dl class="param-type">
1141
+ <dt>
1142
+ Type
1143
+ </dt>
1144
+ <dd>
1145
+
1146
+ <span class="param-type">Promise</span>
1147
+
1148
+
1149
+
1150
+ </dd>
1151
+ </dl>
1152
+
1153
+
1154
+
1155
+
1156
+
1157
+
1158
+
1159
+
1160
+
1161
+
1162
+ <h4 class="name" id="dispatchCodex"><span class="type-signature type-signature-async">(async) </span>dispatchCodex<span class="signature">(prompt, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
1169
+ <dl class="details">
1170
+
1171
+ <dt class="tag-description">Description:</dt>
1172
+ <dd class="tag-description"><ul class="dummy"><li><p>以OpenAI Codex CLI呼叫GPT模型</p>
1173
+ <p>特點:
1174
+ prompt一律走stdin而非位置參數,因摘要內文可達數萬字,當命令列參數會spawn ENAMETOOLONG;
1175
+ 固定帶<code>--skip-git-repo-check</code>,令非git倉庫之工作目錄亦可執行;
1176
+ 沿用Codex CLI既有登入狀態,無逐次注入API key之概念,故無key參數;
1177
+ 未給model時不帶<code>-m</code>旗標,由CLI自行決定使用模型;
1178
+ 本函數不會reject,一律以結果物件之ok與error欄位回報成敗</p></li></ul></dd>
1179
+
1180
+
1181
+
1182
+ <dt class="tag-source">Source:</dt>
1183
+ <dd class="tag-source"><ul class="dummy"><li>
1184
+ <a href="dispatchCodex.mjs.html">dispatchCodex.mjs</a>, <a href="dispatchCodex.mjs.html#line74">line 74</a>
1185
+ </li></ul></dd>
1186
+
1187
+
1188
+
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+
1203
+
1204
+
1205
+
1206
+
1207
+
1208
+
1209
+
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1216
+
1217
+ </dl>
1218
+
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+
1225
+
1226
+
1227
+
1228
+
1229
+ <h5 class="h5-examples">Example</h5>
1230
+
1231
+ <pre class="prettyprint"><code>//need codex cli in system PATH
1232
+
1233
+ import dispatchCodex from './src/dispatchCodex.mjs'
1234
+
1235
+ let test = async () => {
1236
+
1237
+ let r = await dispatchCodex('請只回覆兩個字:完成', { model: 'gpt-5.6-luna', sandbox: 'read-only' })
1238
+ console.log(r.ok, r.stdout.includes('完成'))
1239
+ // => true true
1240
+
1241
+ let re = await dispatchCodex('abc', { exe: 'codex-not-exist' })
1242
+ console.log(re.ok, re.error.includes('ENOENT'))
1243
+ // => false true
1244
+
1245
+ }
1246
+ await test()
1247
+ .catch((err) => {
1248
+ console.log(err)
1249
+ })</code></pre>
1250
+
1251
+
1252
+
1253
+
1254
+ <h5 class="h5-parameters">Parameters:</h5>
1255
+
1256
+
1257
+ <table class="params">
1258
+ <thead>
1259
+ <tr>
1260
+
1261
+ <th>Name</th>
1262
+
1263
+
1264
+ <th>Type</th>
1265
+
1266
+
1267
+ <th>Attributes</th>
1268
+
1269
+
1270
+
1271
+ <th>Default</th>
1272
+
1273
+
1274
+ <th class="last">Description</th>
1275
+ </tr>
1276
+ </thead>
1277
+
1278
+ <tbody>
1279
+
1280
+
1281
+ <tr>
1282
+
1283
+ <td class="name"><code>prompt</code></td>
1284
+
1285
+
1286
+ <td class="type">
1287
+
1288
+
1289
+ <span class="param-type">String</span>
1290
+
1291
+
1292
+
1293
+
1294
+ </td>
1295
+
1296
+
1297
+ <td class="attributes">
1298
+
1299
+
1300
+
1301
+
1302
+
1303
+ </td>
1304
+
1305
+
1306
+
1307
+ <td class="default">
1308
+
1309
+ </td>
1310
+
1311
+
1312
+ <td class="description last"><p>輸入提示詞字串,一律以stdin傳入子進程</p></td>
1313
+ </tr>
1314
+
1315
+
1316
+
1317
+ <tr>
1318
+
1319
+ <td class="name"><code>opt</code></td>
1320
+
1321
+
1322
+ <td class="type">
1323
+
1324
+
1325
+ <span class="param-type">Object</span>
1326
+
1327
+
1328
+
1329
+
1330
+ </td>
1331
+
1332
+
1333
+ <td class="attributes">
1334
+
1335
+ &lt;optional><br>
1336
+
1337
+
1338
+
1339
+
1340
+
1341
+ </td>
1342
+
1343
+
1344
+
1345
+ <td class="default">
1346
+
1347
+ <code>{}</code>
1348
+
1349
+ </td>
1350
+
1351
+
1352
+ <td class="description last"><p>輸入設定物件,預設{}</p>
1353
+ <h6>Properties</h6>
1354
+
1355
+
1356
+ <table class="params">
1357
+ <thead>
1358
+ <tr>
1359
+
1360
+ <th>Name</th>
1361
+
1362
+
1363
+ <th>Type</th>
1364
+
1365
+
1366
+ <th>Attributes</th>
1367
+
1368
+
1369
+
1370
+ <th>Default</th>
1371
+
1372
+
1373
+ <th class="last">Description</th>
1374
+ </tr>
1375
+ </thead>
1376
+
1377
+ <tbody>
1378
+
1379
+
1380
+ <tr>
1381
+
1382
+ <td class="name"><code>exe</code></td>
1383
+
1384
+
1385
+ <td class="type">
1386
+
1387
+
1388
+ <span class="param-type">String</span>
1389
+
1390
+
1391
+
1392
+
1393
+ </td>
1394
+
1395
+
1396
+ <td class="attributes">
1397
+
1398
+ &lt;optional><br>
1399
+
1400
+
1401
+
1402
+
1403
+
1404
+ </td>
1405
+
1406
+
1407
+
1408
+ <td class="default">
1409
+
1410
+ <code>'codex'</code>
1411
+
1412
+ </td>
1413
+
1414
+
1415
+ <td class="description last"><p>輸入codex執行檔名稱或絕對路徑字串,給予名稱時由execCli自系統PATH解析,預設'codex'</p></td>
1416
+ </tr>
1417
+
1418
+
1419
+
1420
+ <tr>
1421
+
1422
+ <td class="name"><code>model</code></td>
1423
+
1424
+
1425
+ <td class="type">
1426
+
1427
+
1428
+ <span class="param-type">String</span>
1429
+
1430
+
1431
+
1432
+
1433
+ </td>
1434
+
1435
+
1436
+ <td class="attributes">
1437
+
1438
+ &lt;optional><br>
1439
+
1440
+
1441
+
1442
+
1443
+
1444
+ </td>
1445
+
1446
+
1447
+
1448
+ <td class="default">
1449
+
1450
+ <code>''</code>
1451
+
1452
+ </td>
1453
+
1454
+
1455
+ <td class="description last"><p>輸入模型ID字串,例如'gpt-5.6-luna',預設''代表不帶<code>-m</code>旗標</p></td>
1456
+ </tr>
1457
+
1458
+
1459
+
1460
+ <tr>
1461
+
1462
+ <td class="name"><code>sandbox</code></td>
1463
+
1464
+
1465
+ <td class="type">
1466
+
1467
+
1468
+ <span class="param-type">String</span>
1469
+
1470
+
1471
+
1472
+
1473
+ </td>
1474
+
1475
+
1476
+ <td class="attributes">
1477
+
1478
+ &lt;optional><br>
1479
+
1480
+
1481
+
1482
+
1483
+
1484
+ </td>
1485
+
1486
+
1487
+
1488
+ <td class="default">
1489
+
1490
+ <code>'workspace-write'</code>
1491
+
1492
+ </td>
1493
+
1494
+
1495
+ <td class="description last"><p>輸入沙箱模式字串,例如'read-only'、'workspace-write'、'danger-full-access',預設'workspace-write'</p></td>
1496
+ </tr>
1497
+
1498
+
1499
+
1500
+ <tr>
1501
+
1502
+ <td class="name"><code>extraArgs</code></td>
1503
+
1504
+
1505
+ <td class="type">
1506
+
1507
+
1508
+ <span class="param-type">Array</span>
1509
+
1510
+
1511
+
1512
+
1513
+ </td>
1514
+
1515
+
1516
+ <td class="attributes">
1517
+
1518
+ &lt;optional><br>
1519
+
1520
+
1521
+
1522
+
1523
+
1524
+ </td>
1525
+
1526
+
1527
+
1528
+ <td class="default">
1529
+
1530
+ <code>[]</code>
1531
+
1532
+ </td>
1533
+
1534
+
1535
+ <td class="description last"><p>輸入額外命令列旗標字串陣列,例如['--config', 'model_reasoning_effort=&quot;max&quot;'],將接於固定旗標之後,預設[]</p></td>
1536
+ </tr>
1537
+
1538
+
1539
+
1540
+ <tr>
1541
+
1542
+ <td class="name"><code>timeoutMs</code></td>
1543
+
1544
+
1545
+ <td class="type">
1546
+
1547
+
1548
+ <span class="param-type">Number</span>
1549
+
1550
+
1551
+
1552
+
1553
+ </td>
1554
+
1555
+
1556
+ <td class="attributes">
1557
+
1558
+ &lt;optional><br>
1559
+
1560
+
1561
+
1562
+
1563
+
1564
+ </td>
1565
+
1566
+
1567
+
1568
+ <td class="default">
1569
+
1570
+ <code>120000</code>
1571
+
1572
+ </td>
1573
+
1574
+
1575
+ <td class="description last"><p>輸入逾時毫秒正整數,逾時將強制關閉子進程及其子孫程序,預設120000</p></td>
1576
+ </tr>
1577
+
1578
+
1579
+
1580
+ <tr>
1581
+
1582
+ <td class="name"><code>cwd</code></td>
1583
+
1584
+
1585
+ <td class="type">
1586
+
1587
+
1588
+ <span class="param-type">String</span>
1589
+
1590
+
1591
+
1592
+
1593
+ </td>
1594
+
1595
+
1596
+ <td class="attributes">
1597
+
1598
+ &lt;optional><br>
1599
+
1600
+
1601
+
1602
+
1603
+
1604
+ </td>
1605
+
1606
+
1607
+
1608
+ <td class="default">
1609
+
1610
+ <code>process.cwd()</code>
1611
+
1612
+ </td>
1613
+
1614
+
1615
+ <td class="description last"><p>輸入子進程工作目錄字串,預設process.cwd()</p></td>
1616
+ </tr>
1617
+
1618
+
1619
+
1620
+ <tr>
1621
+
1622
+ <td class="name"><code>validate</code></td>
1623
+
1624
+
1625
+ <td class="type">
1626
+
1627
+
1628
+ <span class="param-type">String</span>
1629
+ |
1630
+
1631
+ <span class="param-type">function</span>
1632
+
1633
+
1634
+
1635
+
1636
+ </td>
1637
+
1638
+
1639
+ <td class="attributes">
1640
+
1641
+ &lt;optional><br>
1642
+
1643
+
1644
+
1645
+
1646
+
1647
+ </td>
1648
+
1649
+
1650
+
1651
+ <td class="default">
1652
+
1653
+ </td>
1654
+
1655
+
1656
+ <td class="description last"><p>輸入stdout驗證規則字串或自訂驗證函數,規則字串支援'nonempty'、'json'、'min:100',多規則可用逗號串接,預設undefined代表不驗證</p></td>
1657
+ </tr>
1658
+
1659
+
1660
+
1661
+ <tr>
1662
+
1663
+ <td class="name"><code>maxRetries</code></td>
1664
+
1665
+
1666
+ <td class="type">
1667
+
1668
+
1669
+ <span class="param-type">Number</span>
1670
+
1671
+
1672
+
1673
+
1674
+ </td>
1675
+
1676
+
1677
+ <td class="attributes">
1678
+
1679
+ &lt;optional><br>
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+ </td>
1686
+
1687
+
1688
+
1689
+ <td class="default">
1690
+
1691
+ <code>0</code>
1692
+
1693
+ </td>
1694
+
1695
+
1696
+ <td class="description last"><p>輸入失敗後最大重試次數非負整數,預設0</p></td>
1697
+ </tr>
1698
+
1699
+
1700
+ </tbody>
1701
+ </table>
1702
+
1703
+ </td>
1704
+ </tr>
1705
+
1706
+
1707
+ </tbody>
1708
+ </table>
1709
+
1710
+
1711
+
1712
+
1713
+
1714
+
1715
+
1716
+
1717
+
1718
+
1719
+
1720
+
1721
+
1722
+
1723
+
1724
+
1725
+ <h5 class="h5-returns">Returns:</h5>
1726
+
1727
+
1728
+ <div class="param-desc">
1729
+ <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(標準輸出字串)、stderr(標準錯誤字串)、code(離開碼)、error(錯誤訊息字串,成功時為空字串)、durationMs(耗時毫秒)、attempts(實際嘗試次數),本函數不會reject</p>
1730
+ </div>
1731
+
1732
+
1733
+
1734
+ <dl class="param-type">
1735
+ <dt>
1736
+ Type
1737
+ </dt>
1738
+ <dd>
1739
+
1740
+ <span class="param-type">Promise</span>
1741
+
1742
+
1743
+
1744
+ </dd>
1745
+ </dl>
1746
+
1747
+
1748
+
1749
+
1750
+
1751
+
1752
+
1753
+
1754
+
1755
+
1756
+ <h4 class="name" id="dispatchOpencode"><span class="type-signature type-signature-async">(async) </span>dispatchOpencode<span class="signature">(prompt, opt<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise}</span></h4>
1757
+
1758
+
1759
+
1760
+
1761
+
1762
+
1763
+ <dl class="details">
1764
+
1765
+ <dt class="tag-description">Description:</dt>
1766
+ <dd class="tag-description"><ul class="dummy"><li><p>以opencode CLI呼叫AI模型</p>
1767
+ <p>特點:
1768
+ prompt一律走stdin而非位置參數,因摘要內文可達數萬字,當命令列參數會spawn ENAMETOOLONG,
1769
+ 而opencode run未帶位置message時即從stdin讀取;
1770
+ 同時給予key與provider時,以OPENCODE_AUTH_CONTENT環境變數逐次注入金鑰,
1771
+ 該注入僅作用於當次子進程且不改寫auth.json,故可多把金鑰輪替並與其他程序並行;
1772
+ 未給key或provider時沿用CLI既有登入狀態;
1773
+ 使用opencode未內建之第三方provider時,須另以config給予其provider定義;
1774
+ 本函數不會reject,一律以結果物件之ok與error欄位回報成敗</p></li></ul></dd>
1775
+
1776
+
1777
+
1778
+ <dt class="tag-source">Source:</dt>
1779
+ <dd class="tag-source"><ul class="dummy"><li>
1780
+ <a href="dispatchOpencode.mjs.html">dispatchOpencode.mjs</a>, <a href="dispatchOpencode.mjs.html#line115">line 115</a>
1781
+ </li></ul></dd>
1782
+
1783
+
1784
+
1785
+
1786
+
1787
+
1788
+
1789
+
1790
+
1791
+
1792
+
1793
+
1794
+
1795
+
1796
+
1797
+
1798
+
1799
+
1800
+
1801
+
1802
+
1803
+
1804
+
1805
+
1806
+
1807
+
1808
+
1809
+
1810
+
1811
+
1812
+
1813
+ </dl>
1814
+
1815
+
1816
+
1817
+
1818
+
1819
+
1820
+
1821
+
1822
+
1823
+
1824
+
1825
+ <h5 class="h5-examples">Example</h5>
1826
+
1827
+ <pre class="prettyprint"><code>//need opencode cli in system PATH
1828
+
1829
+ import dispatchOpencode from './src/dispatchOpencode.mjs'
1830
+
1831
+ let test = async () => {
1832
+
1833
+ //沿用CLI既有登入狀態
1834
+ let r1 = await dispatchOpencode('請只回覆兩個字:完成', { model: 'opencode/deepseek-v4-flash-free' })
1835
+ console.log(r1.ok, r1.stdout.includes('完成'))
1836
+ // => true true
1837
+
1838
+ //逐次注入金鑰, key與provider與model須為同一組
1839
+ let r2 = await dispatchOpencode('請只回覆兩個字:完成', {
1840
+ model: 'opencode/deepseek-v4-flash-free',
1841
+ provider: 'opencode',
1842
+ key: 'sk-xxxxxx',
1843
+ })
1844
+ console.log(r2.ok)
1845
+ // => true
1846
+
1847
+ //opencode未內建之第三方provider, 須另以config給予其定義
1848
+ let r3 = await dispatchOpencode('請只回覆兩個字:完成', {
1849
+ model: 'agnes-ai/agnes-2.0-flash',
1850
+ provider: 'agnes-ai',
1851
+ key: 'sk-xxxxxx',
1852
+ config: {
1853
+ provider: {
1854
+ 'agnes-ai': {
1855
+ npm: '@ai-sdk/openai-compatible',
1856
+ name: 'Agnes',
1857
+ options: { baseURL: 'https://apihub.agnes-ai.com/v1' },
1858
+ models: { 'agnes-2.0-flash': { name: 'Agnes 2.0 Flash' } },
1859
+ },
1860
+ },
1861
+ },
1862
+ })
1863
+ console.log(r3.ok)
1864
+ // => true
1865
+
1866
+ }
1867
+ await test()
1868
+ .catch((err) => {
1869
+ console.log(err)
1870
+ })</code></pre>
1871
+
1872
+
1873
+
1874
+
1875
+ <h5 class="h5-parameters">Parameters:</h5>
1876
+
1877
+
1878
+ <table class="params">
1879
+ <thead>
1880
+ <tr>
1881
+
1882
+ <th>Name</th>
1883
+
1884
+
1885
+ <th>Type</th>
1886
+
1887
+
1888
+ <th>Attributes</th>
1889
+
1890
+
1891
+
1892
+ <th>Default</th>
1893
+
1894
+
1895
+ <th class="last">Description</th>
1896
+ </tr>
1897
+ </thead>
1898
+
1899
+ <tbody>
1900
+
1901
+
1902
+ <tr>
1903
+
1904
+ <td class="name"><code>prompt</code></td>
1905
+
1906
+
1907
+ <td class="type">
1908
+
1909
+
1910
+ <span class="param-type">String</span>
1911
+
1912
+
1913
+
1914
+
1915
+ </td>
1916
+
1917
+
1918
+ <td class="attributes">
1919
+
1920
+
1921
+
1922
+
1923
+
1924
+ </td>
1925
+
1926
+
1927
+
1928
+ <td class="default">
1929
+
1930
+ </td>
1931
+
1932
+
1933
+ <td class="description last"><p>輸入提示詞字串,一律以stdin傳入子進程</p></td>
1934
+ </tr>
1935
+
1936
+
1937
+
1938
+ <tr>
1939
+
1940
+ <td class="name"><code>opt</code></td>
1941
+
1942
+
1943
+ <td class="type">
1944
+
1945
+
1946
+ <span class="param-type">Object</span>
1947
+
1948
+
1949
+
1950
+
1951
+ </td>
1952
+
1953
+
1954
+ <td class="attributes">
1955
+
1956
+ &lt;optional><br>
1957
+
1958
+
1959
+
1960
+
1961
+
1962
+ </td>
1963
+
1964
+
1965
+
1966
+ <td class="default">
1967
+
1968
+ <code>{}</code>
1969
+
1970
+ </td>
1971
+
1972
+
1973
+ <td class="description last"><p>輸入設定物件,預設{}</p>
1974
+ <h6>Properties</h6>
1975
+
1976
+
1977
+ <table class="params">
1978
+ <thead>
1979
+ <tr>
1980
+
1981
+ <th>Name</th>
1982
+
1983
+
1984
+ <th>Type</th>
1985
+
1986
+
1987
+ <th>Attributes</th>
1988
+
1989
+
1990
+
1991
+ <th>Default</th>
1992
+
1993
+
1994
+ <th class="last">Description</th>
1995
+ </tr>
1996
+ </thead>
1997
+
1998
+ <tbody>
1999
+
2000
+
2001
+ <tr>
2002
+
2003
+ <td class="name"><code>exe</code></td>
2004
+
2005
+
2006
+ <td class="type">
2007
+
2008
+
2009
+ <span class="param-type">String</span>
2010
+
2011
+
2012
+
2013
+
2014
+ </td>
2015
+
2016
+
2017
+ <td class="attributes">
2018
+
2019
+ &lt;optional><br>
2020
+
2021
+
2022
+
2023
+
2024
+
2025
+ </td>
2026
+
2027
+
2028
+
2029
+ <td class="default">
2030
+
2031
+ <code>'opencode'</code>
2032
+
2033
+ </td>
2034
+
2035
+
2036
+ <td class="description last"><p>輸入opencode執行檔名稱或絕對路徑字串,給予名稱時由execCli自系統PATH解析,預設'opencode'</p></td>
2037
+ </tr>
2038
+
2039
+
2040
+
2041
+ <tr>
2042
+
2043
+ <td class="name"><code>model</code></td>
2044
+
2045
+
2046
+ <td class="type">
2047
+
2048
+
2049
+ <span class="param-type">String</span>
2050
+
2051
+
2052
+
2053
+
2054
+ </td>
2055
+
2056
+
2057
+ <td class="attributes">
2058
+
2059
+ &lt;optional><br>
2060
+
2061
+
2062
+
2063
+
2064
+
2065
+ </td>
2066
+
2067
+
2068
+
2069
+ <td class="default">
2070
+
2071
+ <code>''</code>
2072
+
2073
+ </td>
2074
+
2075
+
2076
+ <td class="description last"><p>輸入模型ID字串,例如'opencode/deepseek-v4-flash-free',預設''代表不帶<code>-m</code>旗標</p></td>
2077
+ </tr>
2078
+
2079
+
2080
+
2081
+ <tr>
2082
+
2083
+ <td class="name"><code>key</code></td>
2084
+
2085
+
2086
+ <td class="type">
2087
+
2088
+
2089
+ <span class="param-type">String</span>
2090
+
2091
+
2092
+
2093
+
2094
+ </td>
2095
+
2096
+
2097
+ <td class="attributes">
2098
+
2099
+ &lt;optional><br>
2100
+
2101
+
2102
+
2103
+
2104
+
2105
+ </td>
2106
+
2107
+
2108
+
2109
+ <td class="default">
2110
+
2111
+ <code>''</code>
2112
+
2113
+ </td>
2114
+
2115
+
2116
+ <td class="description last"><p>輸入該provider之API key字串,須與provider同時給予才會注入,預設''代表沿用CLI既有登入狀態</p></td>
2117
+ </tr>
2118
+
2119
+
2120
+
2121
+ <tr>
2122
+
2123
+ <td class="name"><code>provider</code></td>
2124
+
2125
+
2126
+ <td class="type">
2127
+
2128
+
2129
+ <span class="param-type">String</span>
2130
+
2131
+
2132
+
2133
+
2134
+ </td>
2135
+
2136
+
2137
+ <td class="attributes">
2138
+
2139
+ &lt;optional><br>
2140
+
2141
+
2142
+
2143
+
2144
+
2145
+ </td>
2146
+
2147
+
2148
+
2149
+ <td class="default">
2150
+
2151
+ <code>''</code>
2152
+
2153
+ </td>
2154
+
2155
+
2156
+ <td class="description last"><p>輸入key所屬provider名稱字串,須與key同時給予才會注入,且須與model為同一組,預設''</p></td>
2157
+ </tr>
2158
+
2159
+
2160
+
2161
+ <tr>
2162
+
2163
+ <td class="name"><code>config</code></td>
2164
+
2165
+
2166
+ <td class="type">
2167
+
2168
+
2169
+ <span class="param-type">Object</span>
2170
+ |
2171
+
2172
+ <span class="param-type">String</span>
2173
+
2174
+
2175
+
2176
+
2177
+ </td>
2178
+
2179
+
2180
+ <td class="attributes">
2181
+
2182
+ &lt;optional><br>
2183
+
2184
+
2185
+
2186
+
2187
+
2188
+ </td>
2189
+
2190
+
2191
+
2192
+ <td class="default">
2193
+
2194
+ <code>null</code>
2195
+
2196
+ </td>
2197
+
2198
+
2199
+ <td class="description last"><p>輸入opencode設定內容物件或其JSON字串,將以OPENCODE_CONFIG_CONTENT逐次注入,供補上第三方provider之定義,預設null代表沿用使用者既有設定檔</p></td>
2200
+ </tr>
2201
+
2202
+
2203
+
2204
+ <tr>
2205
+
2206
+ <td class="name"><code>agent</code></td>
2207
+
2208
+
2209
+ <td class="type">
2210
+
2211
+
2212
+ <span class="param-type">String</span>
2213
+
2214
+
2215
+
2216
+
2217
+ </td>
2218
+
2219
+
2220
+ <td class="attributes">
2221
+
2222
+ &lt;optional><br>
2223
+
2224
+
2225
+
2226
+
2227
+
2228
+ </td>
2229
+
2230
+
2231
+
2232
+ <td class="default">
2233
+
2234
+ <code>'build'</code>
2235
+
2236
+ </td>
2237
+
2238
+
2239
+ <td class="description last"><p>輸入opencode代理名稱字串,預設'build'</p></td>
2240
+ </tr>
2241
+
2242
+
2243
+
2244
+ <tr>
2245
+
2246
+ <td class="name"><code>extraArgs</code></td>
2247
+
2248
+
2249
+ <td class="type">
2250
+
2251
+
2252
+ <span class="param-type">Array</span>
2253
+
2254
+
2255
+
2256
+
2257
+ </td>
2258
+
2259
+
2260
+ <td class="attributes">
2261
+
2262
+ &lt;optional><br>
2263
+
2264
+
2265
+
2266
+
2267
+
2268
+ </td>
2269
+
2270
+
2271
+
2272
+ <td class="default">
2273
+
2274
+ <code>[]</code>
2275
+
2276
+ </td>
2277
+
2278
+
2279
+ <td class="description last"><p>輸入額外命令列旗標字串陣列,將接於固定旗標之後,預設[]</p></td>
2280
+ </tr>
2281
+
2282
+
2283
+
2284
+ <tr>
2285
+
2286
+ <td class="name"><code>env</code></td>
2287
+
2288
+
2289
+ <td class="type">
2290
+
2291
+
2292
+ <span class="param-type">Object</span>
2293
+
2294
+
2295
+
2296
+
2297
+ </td>
2298
+
2299
+
2300
+ <td class="attributes">
2301
+
2302
+ &lt;optional><br>
2303
+
2304
+
2305
+
2306
+
2307
+
2308
+ </td>
2309
+
2310
+
2311
+
2312
+ <td class="default">
2313
+
2314
+ </td>
2315
+
2316
+
2317
+ <td class="description last"><p>輸入本次調用額外注入之環境變數物件,同時給予key與provider時會再併入OPENCODE_AUTH_CONTENT,預設undefined</p></td>
2318
+ </tr>
2319
+
2320
+
2321
+
2322
+ <tr>
2323
+
2324
+ <td class="name"><code>timeoutMs</code></td>
2325
+
2326
+
2327
+ <td class="type">
2328
+
2329
+
2330
+ <span class="param-type">Number</span>
2331
+
2332
+
2333
+
2334
+
2335
+ </td>
2336
+
2337
+
2338
+ <td class="attributes">
2339
+
2340
+ &lt;optional><br>
2341
+
2342
+
2343
+
2344
+
2345
+
2346
+ </td>
2347
+
2348
+
2349
+
2350
+ <td class="default">
2351
+
2352
+ <code>120000</code>
2353
+
2354
+ </td>
2355
+
2356
+
2357
+ <td class="description last"><p>輸入逾時毫秒正整數,逾時將強制關閉子進程及其子孫程序,預設120000</p></td>
2358
+ </tr>
2359
+
2360
+
2361
+
2362
+ <tr>
2363
+
2364
+ <td class="name"><code>cwd</code></td>
2365
+
2366
+
2367
+ <td class="type">
2368
+
2369
+
2370
+ <span class="param-type">String</span>
2371
+
2372
+
2373
+
2374
+
2375
+ </td>
2376
+
2377
+
2378
+ <td class="attributes">
2379
+
2380
+ &lt;optional><br>
2381
+
2382
+
2383
+
2384
+
2385
+
2386
+ </td>
2387
+
2388
+
2389
+
2390
+ <td class="default">
2391
+
2392
+ <code>process.cwd()</code>
2393
+
2394
+ </td>
2395
+
2396
+
2397
+ <td class="description last"><p>輸入子進程工作目錄字串,預設process.cwd()</p></td>
2398
+ </tr>
2399
+
2400
+
2401
+
2402
+ <tr>
2403
+
2404
+ <td class="name"><code>validate</code></td>
2405
+
2406
+
2407
+ <td class="type">
2408
+
2409
+
2410
+ <span class="param-type">String</span>
2411
+ |
2412
+
2413
+ <span class="param-type">function</span>
2414
+
2415
+
2416
+
2417
+
2418
+ </td>
2419
+
2420
+
2421
+ <td class="attributes">
2422
+
2423
+ &lt;optional><br>
2424
+
2425
+
2426
+
2427
+
2428
+
2429
+ </td>
2430
+
2431
+
2432
+
2433
+ <td class="default">
2434
+
2435
+ </td>
2436
+
2437
+
2438
+ <td class="description last"><p>輸入stdout驗證規則字串或自訂驗證函數,規則字串支援'nonempty'、'json'、'min:100',多規則可用逗號串接,預設undefined代表不驗證</p></td>
2439
+ </tr>
2440
+
2441
+
2442
+
2443
+ <tr>
2444
+
2445
+ <td class="name"><code>maxRetries</code></td>
2446
+
2447
+
2448
+ <td class="type">
2449
+
2450
+
2451
+ <span class="param-type">Number</span>
2452
+
2453
+
2454
+
2455
+
2456
+ </td>
2457
+
2458
+
2459
+ <td class="attributes">
2460
+
2461
+ &lt;optional><br>
2462
+
2463
+
2464
+
2465
+
2466
+
2467
+ </td>
2468
+
2469
+
2470
+
2471
+ <td class="default">
2472
+
2473
+ <code>0</code>
2474
+
2475
+ </td>
2476
+
2477
+
2478
+ <td class="description last"><p>輸入失敗後最大重試次數非負整數,預設0</p></td>
2479
+ </tr>
2480
+
2481
+
2482
+ </tbody>
2483
+ </table>
2484
+
2485
+ </td>
2486
+ </tr>
2487
+
2488
+
2489
+ </tbody>
2490
+ </table>
2491
+
2492
+
2493
+
2494
+
2495
+
2496
+
2497
+
2498
+
2499
+
2500
+
2501
+
2502
+
2503
+
2504
+
2505
+
2506
+
2507
+ <h5 class="h5-returns">Returns:</h5>
2508
+
2509
+
2510
+ <div class="param-desc">
2511
+ <p>回傳Promise,resolve回傳結果物件,內含ok(是否成功布林值)、stdout(標準輸出字串)、stderr(標準錯誤字串)、code(離開碼)、error(錯誤訊息字串,成功時為空字串)、durationMs(耗時毫秒)、attempts(實際嘗試次數),本函數不會reject</p>
2512
+ </div>
2513
+
2514
+
2515
+
2516
+ <dl class="param-type">
2517
+ <dt>
2518
+ Type
2519
+ </dt>
2520
+ <dd>
2521
+
2522
+ <span class="param-type">Promise</span>
2523
+
2524
+
2525
+
2526
+ </dd>
2527
+ </dl>
2528
+
2529
+
2530
+
2531
+
2532
+
2533
+
2534
+
2535
+
2536
+
2537
+
2538
+ <h4 class="name" id="getCliArgs"><span class="type-signature"></span>getCliArgs<span class="signature">(&hellip;args)</span><span class="type-signature"> &rarr; {Array}</span></h4>
2539
+
2540
+
2541
+
2542
+
2543
+
2544
+
2545
+ <dl class="details">
2546
+
2547
+ <dt class="tag-description">Description:</dt>
2548
+ <dd class="tag-description"><ul class="dummy"><li><p>將各段命令列參數展平為字串陣列,並濾除非有效字串</p>
2549
+ <p>各轉接器之參數為「固定旗標」加「可選旗標」加「額外旗標」之組合,
2550
+ 其中可選旗標於未給值時須整段消失(例如未給model就不可出現懸空的<code>--model</code>),
2551
+ 故呼叫端須以「整段陣列給或不給」表達,本函數僅負責展平與濾除非有效字串,不判斷旗標配對;
2552
+ 過濾之必要在於Nodejs之spawn要求各參數必為字串,混入undefined或數字會直接拋出TypeError,
2553
+ 破壞本套件「不reject、僅以結果物件回報」之約定</p></li></ul></dd>
2554
+
2555
+
2556
+
2557
+ <dt class="tag-source">Source:</dt>
2558
+ <dd class="tag-source"><ul class="dummy"><li>
2559
+ <a href="getCliArgs.mjs.html">getCliArgs.mjs</a>, <a href="getCliArgs.mjs.html#line27">line 27</a>
2560
+ </li></ul></dd>
2561
+
2562
+
2563
+
2564
+
2565
+
2566
+
2567
+
2568
+
2569
+
2570
+
2571
+
2572
+
2573
+
2574
+
2575
+
2576
+
2577
+
2578
+
2579
+
2580
+
2581
+
2582
+
2583
+
2584
+
2585
+
2586
+
2587
+
2588
+
2589
+
2590
+
2591
+
2592
+ </dl>
2593
+
2594
+
2595
+
2596
+
2597
+
2598
+
2599
+
2600
+
2601
+
2602
+
2603
+
2604
+ <h5 class="h5-examples">Example</h5>
2605
+
2606
+ <pre class="prettyprint"><code>import getCliArgs from './src/getCliArgs.mjs'
2607
+
2608
+ console.log(getCliArgs('-p', ['--model', 'sonnet']))
2609
+ // => ['-p', '--model', 'sonnet']
2610
+
2611
+ console.log(getCliArgs('-p', null, 123, ['', '--verbose']))
2612
+ // => ['-p', '--verbose']</code></pre>
2613
+
2614
+
2615
+
2616
+
2617
+ <h5 class="h5-parameters">Parameters:</h5>
2618
+
2619
+
2620
+ <table class="params">
2621
+ <thead>
2622
+ <tr>
2623
+
2624
+ <th>Name</th>
2625
+
2626
+
2627
+ <th>Type</th>
2628
+
2629
+
2630
+ <th>Attributes</th>
2631
+
2632
+
2633
+
2634
+
2635
+ <th class="last">Description</th>
2636
+ </tr>
2637
+ </thead>
2638
+
2639
+ <tbody>
2640
+
2641
+
2642
+ <tr>
2643
+
2644
+ <td class="name"><code>args</code></td>
2645
+
2646
+
2647
+ <td class="type">
2648
+
2649
+
2650
+ <span class="param-type">String</span>
2651
+ |
2652
+
2653
+ <span class="param-type">Array</span>
2654
+
2655
+
2656
+
2657
+
2658
+ </td>
2659
+
2660
+
2661
+ <td class="attributes">
2662
+
2663
+
2664
+
2665
+
2666
+
2667
+ &lt;repeatable><br>
2668
+
2669
+ </td>
2670
+
2671
+
2672
+
2673
+
2674
+ <td class="description last"><p>輸入參數字串或參數字串陣列,可給多個</p></td>
2675
+ </tr>
2676
+
2677
+
2678
+ </tbody>
2679
+ </table>
2680
+
2681
+
2682
+
2683
+
2684
+
2685
+
2686
+
2687
+
2688
+
2689
+
2690
+
2691
+
2692
+
2693
+
2694
+
2695
+
2696
+ <h5 class="h5-returns">Returns:</h5>
2697
+
2698
+
2699
+ <div class="param-desc">
2700
+ <p>回傳展平且濾除非有效字串後之參數字串陣列</p>
2701
+ </div>
2702
+
2703
+
2704
+
2705
+ <dl class="param-type">
2706
+ <dt>
2707
+ Type
2708
+ </dt>
2709
+ <dd>
2710
+
2711
+ <span class="param-type">Array</span>
2712
+
2713
+
2714
+
2715
+ </dd>
2716
+ </dl>
2717
+
2718
+
2719
+
2720
+
2721
+
2722
+
2723
+
2724
+
2725
+
2726
+
2727
+ <h4 class="name" id="getErrorResult"><span class="type-signature"></span>getErrorResult<span class="signature">(error)</span><span class="type-signature"> &rarr; {Object}</span></h4>
2728
+
2729
+
2730
+
2731
+
2732
+
2733
+
2734
+ <dl class="details">
2735
+
2736
+ <dt class="tag-description">Description:</dt>
2737
+ <dd class="tag-description"><ul class="dummy"><li><p>產生與execCli同結構之錯誤結果物件</p>
2738
+ <p>本套件各dispatch函數一律不reject,參數檢核失敗時即以本函數回傳錯誤結果物件,
2739
+ 其欄位與wsemi之execCli回傳結構一致,故呼叫端可用同一套欄位判斷成敗,
2740
+ 無須區分「參數錯誤」與「CLI執行失敗」兩種來源</p></li></ul></dd>
2741
+
2742
+
2743
+
2744
+ <dt class="tag-source">Source:</dt>
2745
+ <dd class="tag-source"><ul class="dummy"><li>
2746
+ <a href="getErrorResult.mjs.html">getErrorResult.mjs</a>, <a href="getErrorResult.mjs.html#line24">line 24</a>
2747
+ </li></ul></dd>
2748
+
2749
+
2750
+
2751
+
2752
+
2753
+
2754
+
2755
+
2756
+
2757
+
2758
+
2759
+
2760
+
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+
2767
+
2768
+
2769
+
2770
+
2771
+
2772
+
2773
+
2774
+
2775
+
2776
+
2777
+
2778
+
2779
+ </dl>
2780
+
2781
+
2782
+
2783
+
2784
+
2785
+
2786
+
2787
+
2788
+
2789
+
2790
+
2791
+ <h5 class="h5-examples">Example</h5>
2792
+
2793
+ <pre class="prettyprint"><code>import getErrorResult from './src/getErrorResult.mjs'
2794
+
2795
+ console.log(getErrorResult('prompt must be a non-empty string'))
2796
+ // => { ok: false, stdout: '', stderr: '', code: null, error: 'prompt must be a non-empty string', durationMs: 0, attempts: 0 }
2797
+
2798
+ console.log(getErrorResult(null).error)
2799
+ // => 'unknown error'</code></pre>
2800
+
2801
+
2802
+
2803
+
2804
+ <h5 class="h5-parameters">Parameters:</h5>
2805
+
2806
+
2807
+ <table class="params">
2808
+ <thead>
2809
+ <tr>
2810
+
2811
+ <th>Name</th>
2812
+
2813
+
2814
+ <th>Type</th>
2815
+
2816
+
2817
+
2818
+
2819
+
2820
+ <th class="last">Description</th>
2821
+ </tr>
2822
+ </thead>
2823
+
2824
+ <tbody>
2825
+
2826
+
2827
+ <tr>
2828
+
2829
+ <td class="name"><code>error</code></td>
2830
+
2831
+
2832
+ <td class="type">
2833
+
2834
+
2835
+ <span class="param-type">String</span>
2836
+
2837
+
2838
+
2839
+
2840
+ </td>
2841
+
2842
+
2843
+
2844
+
2845
+
2846
+ <td class="description last"><p>輸入錯誤訊息字串</p></td>
2847
+ </tr>
2848
+
2849
+
2850
+ </tbody>
2851
+ </table>
2852
+
2853
+
2854
+
2855
+
2856
+
2857
+
2858
+
2859
+
2860
+
2861
+
2862
+
2863
+
2864
+
2865
+
2866
+
2867
+
2868
+ <h5 class="h5-returns">Returns:</h5>
2869
+
2870
+
2871
+ <div class="param-desc">
2872
+ <p>回傳結果物件,內含ok(布林值,恆為false)、stdout(空字串)、stderr(空字串)、code(null)、error(錯誤訊息字串)、durationMs(0)、attempts(0)</p>
2873
+ </div>
2874
+
2875
+
2876
+
2877
+ <dl class="param-type">
2878
+ <dt>
2879
+ Type
2880
+ </dt>
2881
+ <dd>
2882
+
2883
+ <span class="param-type">Object</span>
2884
+
2885
+
2886
+
2887
+ </dd>
2888
+ </dl>
2889
+
2890
+
2891
+
2892
+
2893
+
2894
+
2895
+
2896
+
2897
+
2898
+
2899
+
2900
+ </article>
2901
+
2902
+ </section>
2903
+
2904
+
2905
+
2906
+
2907
+
2908
+
2909
+ </div>
2910
+
2911
+ <br class="clear">
2912
+
2913
+ <footer>
2914
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Aug 09 2026 22:39:08 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
2915
+ </footer>
2916
+
2917
+ <script>prettyPrint();</script>
2918
+ <script src="scripts/polyfill.js"></script>
2919
+ <script src="scripts/linenumber.js"></script>
2920
+
2921
+
2922
+
2923
+ </body>
2924
+ </html>