@roll-agent/core 0.10.1 → 0.12.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 (64) hide show
  1. package/bin/roll.js +56 -1
  2. package/dist/cli/chat/ink/app.d.ts +15 -0
  3. package/dist/cli/chat/ink/app.js +1 -0
  4. package/dist/cli/chat/ink/commands.d.ts +6 -0
  5. package/dist/cli/chat/ink/commands.js +1 -0
  6. package/dist/cli/chat/ink/confirm-select.d.ts +6 -0
  7. package/dist/cli/chat/ink/confirm-select.js +1 -0
  8. package/dist/cli/chat/ink/history-from-messages.d.ts +3 -0
  9. package/dist/cli/chat/ink/history-from-messages.js +1 -0
  10. package/dist/cli/chat/ink/history-item.d.ts +5 -0
  11. package/dist/cli/chat/ink/history-item.js +1 -0
  12. package/dist/cli/chat/ink/live-region.d.ts +5 -0
  13. package/dist/cli/chat/ink/live-region.js +1 -0
  14. package/dist/cli/chat/ink/markdown.d.ts +4 -0
  15. package/dist/cli/chat/ink/markdown.js +1 -0
  16. package/dist/cli/chat/ink/run-ink-repl.d.ts +13 -0
  17. package/dist/cli/chat/ink/run-ink-repl.js +1 -0
  18. package/dist/cli/chat/ink/slash-popup.d.ts +7 -0
  19. package/dist/cli/chat/ink/slash-popup.js +1 -0
  20. package/dist/cli/chat/ink/spinner.d.ts +2 -0
  21. package/dist/cli/chat/ink/spinner.js +1 -0
  22. package/dist/cli/chat/ink/state.d.ts +95 -0
  23. package/dist/cli/chat/ink/state.js +1 -0
  24. package/dist/cli/chat/ink/status-line.d.ts +5 -0
  25. package/dist/cli/chat/ink/status-line.js +1 -0
  26. package/dist/cli/chat/ink/text-prompt.d.ts +12 -0
  27. package/dist/cli/chat/ink/text-prompt.js +1 -0
  28. package/dist/cli/chat/ink/thinking-text.d.ts +9 -0
  29. package/dist/cli/chat/ink/thinking-text.js +1 -0
  30. package/dist/cli/chat/ink/thinking.d.ts +3 -0
  31. package/dist/cli/chat/ink/thinking.js +1 -0
  32. package/dist/cli/chat/ink/tool-label.d.ts +4 -0
  33. package/dist/cli/chat/ink/tool-label.js +1 -0
  34. package/dist/cli/chat/ink/use-session.d.ts +20 -0
  35. package/dist/cli/chat/ink/use-session.js +1 -0
  36. package/dist/cli/chat/title.d.ts +1 -0
  37. package/dist/cli/chat/title.js +1 -0
  38. package/dist/cli/commands/browser-stop.d.ts +4 -4
  39. package/dist/cli/commands/chat.d.ts +27 -0
  40. package/dist/cli/commands/chat.js +1 -1
  41. package/dist/cli/commands/config-guidance.d.ts +12 -0
  42. package/dist/cli/commands/config-guidance.js +1 -1
  43. package/dist/cli/utils/chat-renderer.d.ts +21 -0
  44. package/dist/cli/utils/chat-renderer.js +1 -0
  45. package/dist/cli/utils/output.d.ts +1 -0
  46. package/dist/cli/utils/output.js +1 -1
  47. package/dist/cli/utils/package-manager.d.ts +5 -0
  48. package/dist/cli/utils/package-manager.js +1 -1
  49. package/dist/cli/utils/token-format.d.ts +18 -0
  50. package/dist/cli/utils/token-format.js +1 -0
  51. package/dist/cli/utils/tool-format.d.ts +1 -0
  52. package/dist/cli/utils/tool-format.js +1 -0
  53. package/dist/config/defaults.js +1 -1
  54. package/dist/config/key-codec.js +1 -1
  55. package/dist/config/loader.js +1 -1
  56. package/dist/config/runtime-env.d.ts +16 -16
  57. package/dist/config/schema.d.ts +246 -22
  58. package/dist/config/schema.js +1 -1
  59. package/dist/llm/providers.d.ts +5 -2
  60. package/dist/llm/providers.js +1 -1
  61. package/dist/mcp/client-manager.d.ts +2 -0
  62. package/dist/mcp/client-manager.js +1 -1
  63. package/dist/types/chat.d.ts +23 -0
  64. package/package.json +40 -6
@@ -63,6 +63,112 @@ export declare const askConfigSchema: z.ZodObject<{
63
63
  llmModel?: string | undefined;
64
64
  confirmThreshold?: number | undefined;
65
65
  }>;
66
+ export declare const runtimeApprovalConfigSchema: z.ZodObject<{
67
+ default: z.ZodDefault<z.ZodEnum<["guarded", "auto", "deny"]>>;
68
+ overrides: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodEnum<["auto", "confirm", "deny"]>>>;
69
+ }, "strip", z.ZodTypeAny, {
70
+ default: "auto" | "guarded" | "deny";
71
+ overrides: Record<string, "auto" | "deny" | "confirm">;
72
+ }, {
73
+ default?: "auto" | "guarded" | "deny" | undefined;
74
+ overrides?: Record<string, "auto" | "deny" | "confirm"> | undefined;
75
+ }>;
76
+ export declare const runtimeCompactionConfigSchema: z.ZodObject<{
77
+ enabled: z.ZodDefault<z.ZodBoolean>;
78
+ strategy: z.ZodDefault<z.ZodEnum<["summarize", "truncate"]>>;
79
+ threshold: z.ZodDefault<z.ZodNumber>;
80
+ keepRecentTurns: z.ZodDefault<z.ZodNumber>;
81
+ keepRecentTokens: z.ZodDefault<z.ZodNumber>;
82
+ }, "strip", z.ZodTypeAny, {
83
+ enabled: boolean;
84
+ strategy: "summarize" | "truncate";
85
+ threshold: number;
86
+ keepRecentTurns: number;
87
+ keepRecentTokens: number;
88
+ }, {
89
+ enabled?: boolean | undefined;
90
+ strategy?: "summarize" | "truncate" | undefined;
91
+ threshold?: number | undefined;
92
+ keepRecentTurns?: number | undefined;
93
+ keepRecentTokens?: number | undefined;
94
+ }>;
95
+ export declare const runtimeThinkingLevels: readonly ["off", "low", "medium", "high"];
96
+ export declare const runtimeConfigSchema: z.ZodObject<{
97
+ provider: z.ZodOptional<z.ZodString>;
98
+ model: z.ZodOptional<z.ZodString>;
99
+ maxSteps: z.ZodDefault<z.ZodNumber>;
100
+ turnTimeoutMs: z.ZodDefault<z.ZodNumber>;
101
+ threadsDir: z.ZodDefault<z.ZodString>;
102
+ contextWindow: z.ZodOptional<z.ZodNumber>;
103
+ thinkingLevel: z.ZodDefault<z.ZodEnum<["off", "low", "medium", "high"]>>;
104
+ approval: z.ZodDefault<z.ZodObject<{
105
+ default: z.ZodDefault<z.ZodEnum<["guarded", "auto", "deny"]>>;
106
+ overrides: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodEnum<["auto", "confirm", "deny"]>>>;
107
+ }, "strip", z.ZodTypeAny, {
108
+ default: "auto" | "guarded" | "deny";
109
+ overrides: Record<string, "auto" | "deny" | "confirm">;
110
+ }, {
111
+ default?: "auto" | "guarded" | "deny" | undefined;
112
+ overrides?: Record<string, "auto" | "deny" | "confirm"> | undefined;
113
+ }>>;
114
+ compaction: z.ZodDefault<z.ZodObject<{
115
+ enabled: z.ZodDefault<z.ZodBoolean>;
116
+ strategy: z.ZodDefault<z.ZodEnum<["summarize", "truncate"]>>;
117
+ threshold: z.ZodDefault<z.ZodNumber>;
118
+ keepRecentTurns: z.ZodDefault<z.ZodNumber>;
119
+ keepRecentTokens: z.ZodDefault<z.ZodNumber>;
120
+ }, "strip", z.ZodTypeAny, {
121
+ enabled: boolean;
122
+ strategy: "summarize" | "truncate";
123
+ threshold: number;
124
+ keepRecentTurns: number;
125
+ keepRecentTokens: number;
126
+ }, {
127
+ enabled?: boolean | undefined;
128
+ strategy?: "summarize" | "truncate" | undefined;
129
+ threshold?: number | undefined;
130
+ keepRecentTurns?: number | undefined;
131
+ keepRecentTokens?: number | undefined;
132
+ }>>;
133
+ }, "strip", z.ZodTypeAny, {
134
+ maxSteps: number;
135
+ turnTimeoutMs: number;
136
+ threadsDir: string;
137
+ thinkingLevel: "off" | "low" | "medium" | "high";
138
+ approval: {
139
+ default: "auto" | "guarded" | "deny";
140
+ overrides: Record<string, "auto" | "deny" | "confirm">;
141
+ };
142
+ compaction: {
143
+ enabled: boolean;
144
+ strategy: "summarize" | "truncate";
145
+ threshold: number;
146
+ keepRecentTurns: number;
147
+ keepRecentTokens: number;
148
+ };
149
+ model?: string | undefined;
150
+ provider?: string | undefined;
151
+ contextWindow?: number | undefined;
152
+ }, {
153
+ model?: string | undefined;
154
+ provider?: string | undefined;
155
+ maxSteps?: number | undefined;
156
+ turnTimeoutMs?: number | undefined;
157
+ threadsDir?: string | undefined;
158
+ contextWindow?: number | undefined;
159
+ thinkingLevel?: "off" | "low" | "medium" | "high" | undefined;
160
+ approval?: {
161
+ default?: "auto" | "guarded" | "deny" | undefined;
162
+ overrides?: Record<string, "auto" | "deny" | "confirm"> | undefined;
163
+ } | undefined;
164
+ compaction?: {
165
+ enabled?: boolean | undefined;
166
+ strategy?: "summarize" | "truncate" | undefined;
167
+ threshold?: number | undefined;
168
+ keepRecentTurns?: number | undefined;
169
+ keepRecentTokens?: number | undefined;
170
+ } | undefined;
171
+ }>;
66
172
  export declare const agentsConfigSchema: z.ZodObject<{
67
173
  dataDir: z.ZodString;
68
174
  /** per-agent 环境变量:键为 agent name,值为 key-value 对 */
@@ -137,12 +243,12 @@ export declare const browserInstanceConfigSchema: z.ZodEffects<z.ZodObject<{
137
243
  channel: "chrome" | "chromium" | "msedge";
138
244
  userDataDir: string;
139
245
  platform?: "zhipin" | "yupao" | undefined;
246
+ args?: string[] | undefined;
140
247
  headless?: boolean | undefined;
141
248
  cdpUrl?: string | undefined;
142
249
  cdpPort?: number | undefined;
143
250
  executablePath?: string | undefined;
144
251
  sessionsDir?: string | undefined;
145
- args?: string[] | undefined;
146
252
  profileName?: string | undefined;
147
253
  profileColor?: string | undefined;
148
254
  windowBounds?: {
@@ -156,6 +262,7 @@ export declare const browserInstanceConfigSchema: z.ZodEffects<z.ZodObject<{
156
262
  userDataDir: string;
157
263
  platform?: "zhipin" | "yupao" | undefined;
158
264
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
265
+ args?: string[] | undefined;
159
266
  headless?: boolean | undefined;
160
267
  cdpUrl?: string | undefined;
161
268
  cdpHost?: string | undefined;
@@ -163,7 +270,6 @@ export declare const browserInstanceConfigSchema: z.ZodEffects<z.ZodObject<{
163
270
  channel?: "chrome" | "chromium" | "msedge" | undefined;
164
271
  executablePath?: string | undefined;
165
272
  sessionsDir?: string | undefined;
166
- args?: string[] | undefined;
167
273
  profileName?: string | undefined;
168
274
  profileColor?: string | undefined;
169
275
  windowBounds?: {
@@ -179,12 +285,12 @@ export declare const browserInstanceConfigSchema: z.ZodEffects<z.ZodObject<{
179
285
  channel: "chrome" | "chromium" | "msedge";
180
286
  userDataDir: string;
181
287
  platform?: "zhipin" | "yupao" | undefined;
288
+ args?: string[] | undefined;
182
289
  headless?: boolean | undefined;
183
290
  cdpUrl?: string | undefined;
184
291
  cdpPort?: number | undefined;
185
292
  executablePath?: string | undefined;
186
293
  sessionsDir?: string | undefined;
187
- args?: string[] | undefined;
188
294
  profileName?: string | undefined;
189
295
  profileColor?: string | undefined;
190
296
  windowBounds?: {
@@ -198,6 +304,7 @@ export declare const browserInstanceConfigSchema: z.ZodEffects<z.ZodObject<{
198
304
  userDataDir: string;
199
305
  platform?: "zhipin" | "yupao" | undefined;
200
306
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
307
+ args?: string[] | undefined;
201
308
  headless?: boolean | undefined;
202
309
  cdpUrl?: string | undefined;
203
310
  cdpHost?: string | undefined;
@@ -205,7 +312,6 @@ export declare const browserInstanceConfigSchema: z.ZodEffects<z.ZodObject<{
205
312
  channel?: "chrome" | "chromium" | "msedge" | undefined;
206
313
  executablePath?: string | undefined;
207
314
  sessionsDir?: string | undefined;
208
- args?: string[] | undefined;
209
315
  profileName?: string | undefined;
210
316
  profileColor?: string | undefined;
211
317
  windowBounds?: {
@@ -255,12 +361,12 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
255
361
  channel: "chrome" | "chromium" | "msedge";
256
362
  userDataDir: string;
257
363
  platform?: "zhipin" | "yupao" | undefined;
364
+ args?: string[] | undefined;
258
365
  headless?: boolean | undefined;
259
366
  cdpUrl?: string | undefined;
260
367
  cdpPort?: number | undefined;
261
368
  executablePath?: string | undefined;
262
369
  sessionsDir?: string | undefined;
263
- args?: string[] | undefined;
264
370
  profileName?: string | undefined;
265
371
  profileColor?: string | undefined;
266
372
  windowBounds?: {
@@ -274,6 +380,7 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
274
380
  userDataDir: string;
275
381
  platform?: "zhipin" | "yupao" | undefined;
276
382
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
383
+ args?: string[] | undefined;
277
384
  headless?: boolean | undefined;
278
385
  cdpUrl?: string | undefined;
279
386
  cdpHost?: string | undefined;
@@ -281,7 +388,6 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
281
388
  channel?: "chrome" | "chromium" | "msedge" | undefined;
282
389
  executablePath?: string | undefined;
283
390
  sessionsDir?: string | undefined;
284
- args?: string[] | undefined;
285
391
  profileName?: string | undefined;
286
392
  profileColor?: string | undefined;
287
393
  windowBounds?: {
@@ -297,12 +403,12 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
297
403
  channel: "chrome" | "chromium" | "msedge";
298
404
  userDataDir: string;
299
405
  platform?: "zhipin" | "yupao" | undefined;
406
+ args?: string[] | undefined;
300
407
  headless?: boolean | undefined;
301
408
  cdpUrl?: string | undefined;
302
409
  cdpPort?: number | undefined;
303
410
  executablePath?: string | undefined;
304
411
  sessionsDir?: string | undefined;
305
- args?: string[] | undefined;
306
412
  profileName?: string | undefined;
307
413
  profileColor?: string | undefined;
308
414
  windowBounds?: {
@@ -316,6 +422,7 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
316
422
  userDataDir: string;
317
423
  platform?: "zhipin" | "yupao" | undefined;
318
424
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
425
+ args?: string[] | undefined;
319
426
  headless?: boolean | undefined;
320
427
  cdpUrl?: string | undefined;
321
428
  cdpHost?: string | undefined;
@@ -323,7 +430,6 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
323
430
  channel?: "chrome" | "chromium" | "msedge" | undefined;
324
431
  executablePath?: string | undefined;
325
432
  sessionsDir?: string | undefined;
326
- args?: string[] | undefined;
327
433
  profileName?: string | undefined;
328
434
  profileColor?: string | undefined;
329
435
  windowBounds?: {
@@ -341,12 +447,12 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
341
447
  channel: "chrome" | "chromium" | "msedge";
342
448
  userDataDir: string;
343
449
  platform?: "zhipin" | "yupao" | undefined;
450
+ args?: string[] | undefined;
344
451
  headless?: boolean | undefined;
345
452
  cdpUrl?: string | undefined;
346
453
  cdpPort?: number | undefined;
347
454
  executablePath?: string | undefined;
348
455
  sessionsDir?: string | undefined;
349
- args?: string[] | undefined;
350
456
  profileName?: string | undefined;
351
457
  profileColor?: string | undefined;
352
458
  windowBounds?: {
@@ -364,6 +470,7 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
364
470
  userDataDir: string;
365
471
  platform?: "zhipin" | "yupao" | undefined;
366
472
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
473
+ args?: string[] | undefined;
367
474
  headless?: boolean | undefined;
368
475
  cdpUrl?: string | undefined;
369
476
  cdpHost?: string | undefined;
@@ -371,7 +478,6 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
371
478
  channel?: "chrome" | "chromium" | "msedge" | undefined;
372
479
  executablePath?: string | undefined;
373
480
  sessionsDir?: string | undefined;
374
- args?: string[] | undefined;
375
481
  profileName?: string | undefined;
376
482
  profileColor?: string | undefined;
377
483
  windowBounds?: {
@@ -389,12 +495,12 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
389
495
  channel: "chrome" | "chromium" | "msedge";
390
496
  userDataDir: string;
391
497
  platform?: "zhipin" | "yupao" | undefined;
498
+ args?: string[] | undefined;
392
499
  headless?: boolean | undefined;
393
500
  cdpUrl?: string | undefined;
394
501
  cdpPort?: number | undefined;
395
502
  executablePath?: string | undefined;
396
503
  sessionsDir?: string | undefined;
397
- args?: string[] | undefined;
398
504
  profileName?: string | undefined;
399
505
  profileColor?: string | undefined;
400
506
  windowBounds?: {
@@ -412,6 +518,7 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
412
518
  userDataDir: string;
413
519
  platform?: "zhipin" | "yupao" | undefined;
414
520
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
521
+ args?: string[] | undefined;
415
522
  headless?: boolean | undefined;
416
523
  cdpUrl?: string | undefined;
417
524
  cdpHost?: string | undefined;
@@ -419,7 +526,6 @@ export declare const browserConfigSchema: z.ZodEffects<z.ZodObject<{
419
526
  channel?: "chrome" | "chromium" | "msedge" | undefined;
420
527
  executablePath?: string | undefined;
421
528
  sessionsDir?: string | undefined;
422
- args?: string[] | undefined;
423
529
  profileName?: string | undefined;
424
530
  profileColor?: string | undefined;
425
531
  windowBounds?: {
@@ -470,6 +576,82 @@ export declare const rollConfigSchema: z.ZodObject<{
470
576
  llmModel?: string | undefined;
471
577
  confirmThreshold?: number | undefined;
472
578
  }>;
579
+ runtime: z.ZodDefault<z.ZodObject<{
580
+ provider: z.ZodOptional<z.ZodString>;
581
+ model: z.ZodOptional<z.ZodString>;
582
+ maxSteps: z.ZodDefault<z.ZodNumber>;
583
+ turnTimeoutMs: z.ZodDefault<z.ZodNumber>;
584
+ threadsDir: z.ZodDefault<z.ZodString>;
585
+ contextWindow: z.ZodOptional<z.ZodNumber>;
586
+ thinkingLevel: z.ZodDefault<z.ZodEnum<["off", "low", "medium", "high"]>>;
587
+ approval: z.ZodDefault<z.ZodObject<{
588
+ default: z.ZodDefault<z.ZodEnum<["guarded", "auto", "deny"]>>;
589
+ overrides: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodEnum<["auto", "confirm", "deny"]>>>;
590
+ }, "strip", z.ZodTypeAny, {
591
+ default: "auto" | "guarded" | "deny";
592
+ overrides: Record<string, "auto" | "deny" | "confirm">;
593
+ }, {
594
+ default?: "auto" | "guarded" | "deny" | undefined;
595
+ overrides?: Record<string, "auto" | "deny" | "confirm"> | undefined;
596
+ }>>;
597
+ compaction: z.ZodDefault<z.ZodObject<{
598
+ enabled: z.ZodDefault<z.ZodBoolean>;
599
+ strategy: z.ZodDefault<z.ZodEnum<["summarize", "truncate"]>>;
600
+ threshold: z.ZodDefault<z.ZodNumber>;
601
+ keepRecentTurns: z.ZodDefault<z.ZodNumber>;
602
+ keepRecentTokens: z.ZodDefault<z.ZodNumber>;
603
+ }, "strip", z.ZodTypeAny, {
604
+ enabled: boolean;
605
+ strategy: "summarize" | "truncate";
606
+ threshold: number;
607
+ keepRecentTurns: number;
608
+ keepRecentTokens: number;
609
+ }, {
610
+ enabled?: boolean | undefined;
611
+ strategy?: "summarize" | "truncate" | undefined;
612
+ threshold?: number | undefined;
613
+ keepRecentTurns?: number | undefined;
614
+ keepRecentTokens?: number | undefined;
615
+ }>>;
616
+ }, "strip", z.ZodTypeAny, {
617
+ maxSteps: number;
618
+ turnTimeoutMs: number;
619
+ threadsDir: string;
620
+ thinkingLevel: "off" | "low" | "medium" | "high";
621
+ approval: {
622
+ default: "auto" | "guarded" | "deny";
623
+ overrides: Record<string, "auto" | "deny" | "confirm">;
624
+ };
625
+ compaction: {
626
+ enabled: boolean;
627
+ strategy: "summarize" | "truncate";
628
+ threshold: number;
629
+ keepRecentTurns: number;
630
+ keepRecentTokens: number;
631
+ };
632
+ model?: string | undefined;
633
+ provider?: string | undefined;
634
+ contextWindow?: number | undefined;
635
+ }, {
636
+ model?: string | undefined;
637
+ provider?: string | undefined;
638
+ maxSteps?: number | undefined;
639
+ turnTimeoutMs?: number | undefined;
640
+ threadsDir?: string | undefined;
641
+ contextWindow?: number | undefined;
642
+ thinkingLevel?: "off" | "low" | "medium" | "high" | undefined;
643
+ approval?: {
644
+ default?: "auto" | "guarded" | "deny" | undefined;
645
+ overrides?: Record<string, "auto" | "deny" | "confirm"> | undefined;
646
+ } | undefined;
647
+ compaction?: {
648
+ enabled?: boolean | undefined;
649
+ strategy?: "summarize" | "truncate" | undefined;
650
+ threshold?: number | undefined;
651
+ keepRecentTurns?: number | undefined;
652
+ keepRecentTokens?: number | undefined;
653
+ } | undefined;
654
+ }>>;
473
655
  agents: z.ZodObject<{
474
656
  dataDir: z.ZodString;
475
657
  /** per-agent 环境变量:键为 agent name,值为 key-value 对 */
@@ -540,12 +722,12 @@ export declare const rollConfigSchema: z.ZodObject<{
540
722
  channel: "chrome" | "chromium" | "msedge";
541
723
  userDataDir: string;
542
724
  platform?: "zhipin" | "yupao" | undefined;
725
+ args?: string[] | undefined;
543
726
  headless?: boolean | undefined;
544
727
  cdpUrl?: string | undefined;
545
728
  cdpPort?: number | undefined;
546
729
  executablePath?: string | undefined;
547
730
  sessionsDir?: string | undefined;
548
- args?: string[] | undefined;
549
731
  profileName?: string | undefined;
550
732
  profileColor?: string | undefined;
551
733
  windowBounds?: {
@@ -559,6 +741,7 @@ export declare const rollConfigSchema: z.ZodObject<{
559
741
  userDataDir: string;
560
742
  platform?: "zhipin" | "yupao" | undefined;
561
743
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
744
+ args?: string[] | undefined;
562
745
  headless?: boolean | undefined;
563
746
  cdpUrl?: string | undefined;
564
747
  cdpHost?: string | undefined;
@@ -566,7 +749,6 @@ export declare const rollConfigSchema: z.ZodObject<{
566
749
  channel?: "chrome" | "chromium" | "msedge" | undefined;
567
750
  executablePath?: string | undefined;
568
751
  sessionsDir?: string | undefined;
569
- args?: string[] | undefined;
570
752
  profileName?: string | undefined;
571
753
  profileColor?: string | undefined;
572
754
  windowBounds?: {
@@ -582,12 +764,12 @@ export declare const rollConfigSchema: z.ZodObject<{
582
764
  channel: "chrome" | "chromium" | "msedge";
583
765
  userDataDir: string;
584
766
  platform?: "zhipin" | "yupao" | undefined;
767
+ args?: string[] | undefined;
585
768
  headless?: boolean | undefined;
586
769
  cdpUrl?: string | undefined;
587
770
  cdpPort?: number | undefined;
588
771
  executablePath?: string | undefined;
589
772
  sessionsDir?: string | undefined;
590
- args?: string[] | undefined;
591
773
  profileName?: string | undefined;
592
774
  profileColor?: string | undefined;
593
775
  windowBounds?: {
@@ -601,6 +783,7 @@ export declare const rollConfigSchema: z.ZodObject<{
601
783
  userDataDir: string;
602
784
  platform?: "zhipin" | "yupao" | undefined;
603
785
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
786
+ args?: string[] | undefined;
604
787
  headless?: boolean | undefined;
605
788
  cdpUrl?: string | undefined;
606
789
  cdpHost?: string | undefined;
@@ -608,7 +791,6 @@ export declare const rollConfigSchema: z.ZodObject<{
608
791
  channel?: "chrome" | "chromium" | "msedge" | undefined;
609
792
  executablePath?: string | undefined;
610
793
  sessionsDir?: string | undefined;
611
- args?: string[] | undefined;
612
794
  profileName?: string | undefined;
613
795
  profileColor?: string | undefined;
614
796
  windowBounds?: {
@@ -626,12 +808,12 @@ export declare const rollConfigSchema: z.ZodObject<{
626
808
  channel: "chrome" | "chromium" | "msedge";
627
809
  userDataDir: string;
628
810
  platform?: "zhipin" | "yupao" | undefined;
811
+ args?: string[] | undefined;
629
812
  headless?: boolean | undefined;
630
813
  cdpUrl?: string | undefined;
631
814
  cdpPort?: number | undefined;
632
815
  executablePath?: string | undefined;
633
816
  sessionsDir?: string | undefined;
634
- args?: string[] | undefined;
635
817
  profileName?: string | undefined;
636
818
  profileColor?: string | undefined;
637
819
  windowBounds?: {
@@ -649,6 +831,7 @@ export declare const rollConfigSchema: z.ZodObject<{
649
831
  userDataDir: string;
650
832
  platform?: "zhipin" | "yupao" | undefined;
651
833
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
834
+ args?: string[] | undefined;
652
835
  headless?: boolean | undefined;
653
836
  cdpUrl?: string | undefined;
654
837
  cdpHost?: string | undefined;
@@ -656,7 +839,6 @@ export declare const rollConfigSchema: z.ZodObject<{
656
839
  channel?: "chrome" | "chromium" | "msedge" | undefined;
657
840
  executablePath?: string | undefined;
658
841
  sessionsDir?: string | undefined;
659
- args?: string[] | undefined;
660
842
  profileName?: string | undefined;
661
843
  profileColor?: string | undefined;
662
844
  windowBounds?: {
@@ -674,12 +856,12 @@ export declare const rollConfigSchema: z.ZodObject<{
674
856
  channel: "chrome" | "chromium" | "msedge";
675
857
  userDataDir: string;
676
858
  platform?: "zhipin" | "yupao" | undefined;
859
+ args?: string[] | undefined;
677
860
  headless?: boolean | undefined;
678
861
  cdpUrl?: string | undefined;
679
862
  cdpPort?: number | undefined;
680
863
  executablePath?: string | undefined;
681
864
  sessionsDir?: string | undefined;
682
- args?: string[] | undefined;
683
865
  profileName?: string | undefined;
684
866
  profileColor?: string | undefined;
685
867
  windowBounds?: {
@@ -697,6 +879,7 @@ export declare const rollConfigSchema: z.ZodObject<{
697
879
  userDataDir: string;
698
880
  platform?: "zhipin" | "yupao" | undefined;
699
881
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
882
+ args?: string[] | undefined;
700
883
  headless?: boolean | undefined;
701
884
  cdpUrl?: string | undefined;
702
885
  cdpHost?: string | undefined;
@@ -704,7 +887,6 @@ export declare const rollConfigSchema: z.ZodObject<{
704
887
  channel?: "chrome" | "chromium" | "msedge" | undefined;
705
888
  executablePath?: string | undefined;
706
889
  sessionsDir?: string | undefined;
707
- args?: string[] | undefined;
708
890
  profileName?: string | undefined;
709
891
  profileColor?: string | undefined;
710
892
  windowBounds?: {
@@ -734,12 +916,12 @@ export declare const rollConfigSchema: z.ZodObject<{
734
916
  channel: "chrome" | "chromium" | "msedge";
735
917
  userDataDir: string;
736
918
  platform?: "zhipin" | "yupao" | undefined;
919
+ args?: string[] | undefined;
737
920
  headless?: boolean | undefined;
738
921
  cdpUrl?: string | undefined;
739
922
  cdpPort?: number | undefined;
740
923
  executablePath?: string | undefined;
741
924
  sessionsDir?: string | undefined;
742
- args?: string[] | undefined;
743
925
  profileName?: string | undefined;
744
926
  profileColor?: string | undefined;
745
927
  windowBounds?: {
@@ -760,6 +942,26 @@ export declare const rollConfigSchema: z.ZodObject<{
760
942
  baseUrl?: string | undefined;
761
943
  }>;
762
944
  };
945
+ runtime: {
946
+ maxSteps: number;
947
+ turnTimeoutMs: number;
948
+ threadsDir: string;
949
+ thinkingLevel: "off" | "low" | "medium" | "high";
950
+ approval: {
951
+ default: "auto" | "guarded" | "deny";
952
+ overrides: Record<string, "auto" | "deny" | "confirm">;
953
+ };
954
+ compaction: {
955
+ enabled: boolean;
956
+ strategy: "summarize" | "truncate";
957
+ threshold: number;
958
+ keepRecentTurns: number;
959
+ keepRecentTokens: number;
960
+ };
961
+ model?: string | undefined;
962
+ provider?: string | undefined;
963
+ contextWindow?: number | undefined;
964
+ };
763
965
  agents: {
764
966
  dataDir: string;
765
967
  env?: Record<string, Record<string, string>> | undefined;
@@ -793,6 +995,7 @@ export declare const rollConfigSchema: z.ZodObject<{
793
995
  userDataDir: string;
794
996
  platform?: "zhipin" | "yupao" | undefined;
795
997
  mode?: "managed-cdp" | "remote-cdp" | "existing-session" | undefined;
998
+ args?: string[] | undefined;
796
999
  headless?: boolean | undefined;
797
1000
  cdpUrl?: string | undefined;
798
1001
  cdpHost?: string | undefined;
@@ -800,7 +1003,6 @@ export declare const rollConfigSchema: z.ZodObject<{
800
1003
  channel?: "chrome" | "chromium" | "msedge" | undefined;
801
1004
  executablePath?: string | undefined;
802
1005
  sessionsDir?: string | undefined;
803
- args?: string[] | undefined;
804
1006
  profileName?: string | undefined;
805
1007
  profileColor?: string | undefined;
806
1008
  windowBounds?: {
@@ -812,7 +1014,29 @@ export declare const rollConfigSchema: z.ZodObject<{
812
1014
  trackingAgentId?: string | undefined;
813
1015
  }> | undefined;
814
1016
  } | undefined;
1017
+ runtime?: {
1018
+ model?: string | undefined;
1019
+ provider?: string | undefined;
1020
+ maxSteps?: number | undefined;
1021
+ turnTimeoutMs?: number | undefined;
1022
+ threadsDir?: string | undefined;
1023
+ contextWindow?: number | undefined;
1024
+ thinkingLevel?: "off" | "low" | "medium" | "high" | undefined;
1025
+ approval?: {
1026
+ default?: "auto" | "guarded" | "deny" | undefined;
1027
+ overrides?: Record<string, "auto" | "deny" | "confirm"> | undefined;
1028
+ } | undefined;
1029
+ compaction?: {
1030
+ enabled?: boolean | undefined;
1031
+ strategy?: "summarize" | "truncate" | undefined;
1032
+ threshold?: number | undefined;
1033
+ keepRecentTurns?: number | undefined;
1034
+ keepRecentTokens?: number | undefined;
1035
+ } | undefined;
1036
+ } | undefined;
815
1037
  }>;
816
1038
  export type RollConfig = z.infer<typeof rollConfigSchema>;
1039
+ export type RuntimeConfig = z.infer<typeof runtimeConfigSchema>;
1040
+ export type RuntimeApprovalConfig = z.infer<typeof runtimeApprovalConfigSchema>;
817
1041
  export type BrowserConfig = z.infer<typeof browserConfigSchema>;
818
1042
  export type InstallConfig = z.infer<typeof installConfigSchema>;
@@ -1 +1 @@
1
- import{z as e}from"zod";const o=["zhipin","yupao"],t=["managed-cdp","remote-cdp","existing-session"],n=["chrome","chromium","msedge"],s=e.string().trim().regex(/^#[\da-fA-F]{6}$/,"profileColor must be a hex RGB color such as #2563EB").transform(e=>e.toUpperCase());export const browserWindowBoundsSchema=e.object({x:e.number().int().optional(),y:e.number().int().optional(),width:e.number().int().positive().optional(),height:e.number().int().positive().optional()});export const providerConfigSchema=e.object({apiKey:e.string(),baseUrl:e.string().optional()});export const llmConfigSchema=e.object({defaultProvider:e.string(),defaultModel:e.string(),providers:e.record(e.string(),providerConfigSchema)});export const askConfigSchema=e.object({llmModel:e.string().optional(),confirmThreshold:e.number().optional()});export const agentsConfigSchema=e.object({dataDir:e.string(),env:e.record(e.string(),e.record(e.string(),e.string())).optional()});export const installConfigSchema=e.object({registry:e.string().trim().url().optional(),fetchRetries:e.number().int().min(0).max(10).default(3),preferOffline:e.boolean().default(!1),networkTimeoutMs:e.number().int().min(1e4).default(12e4)});export const browserInstanceConfigSchema=e.object({platform:e.enum(o).optional(),mode:e.enum(t).default("managed-cdp"),headless:e.boolean().optional(),cdpUrl:e.string().optional(),cdpHost:e.string().default("127.0.0.1"),cdpPort:e.number().int().min(1).max(65535).optional(),channel:e.enum(n).default("chrome"),executablePath:e.string().optional(),userDataDir:e.string().trim().min(1),sessionsDir:e.string().trim().min(1).optional(),args:e.array(e.string()).optional(),profileName:e.string().trim().min(1).optional(),profileColor:s.optional(),windowBounds:browserWindowBoundsSchema.optional(),trackingAgentId:e.string().trim().min(1).optional()}).superRefine((o,t)=>{"managed-cdp"===o.mode&&void 0===o.cdpPort&&t.addIssue({code:e.ZodIssueCode.custom,path:["cdpPort"],message:"managed-cdp browser instance requires cdpPort"}),"remote-cdp"!==o.mode&&"existing-session"!==o.mode||void 0!==o.cdpUrl||t.addIssue({code:e.ZodIssueCode.custom,path:["cdpUrl"],message:`${o.mode} browser instance requires cdpUrl`})});export const browserConfigSchema=e.object({defaultInstance:e.string().trim().min(1).optional(),instances:e.record(e.string(),browserInstanceConfigSchema).default({})}).superRefine((o,t)=>{const n=Object.entries(o.instances);void 0!==o.defaultInstance&&void 0===o.instances[o.defaultInstance]&&t.addIssue({code:e.ZodIssueCode.custom,path:["defaultInstance"],message:`defaultInstance "${o.defaultInstance}" is not declared in browser.instances`});const s=new Map,r=new Map;for(const[o,i]of n){if(void 0!==i.cdpPort){const n=s.get(i.cdpPort);void 0!==n?t.addIssue({code:e.ZodIssueCode.custom,path:["instances",o,"cdpPort"],message:`cdpPort ${String(i.cdpPort)} is already used by browser instance "${n}"`}):s.set(i.cdpPort,o)}const n=r.get(i.userDataDir);void 0!==n?t.addIssue({code:e.ZodIssueCode.custom,path:["instances",o,"userDataDir"],message:`userDataDir is already used by browser instance "${n}"`}):r.set(i.userDataDir,o)}});export const rollConfigSchema=e.object({llm:llmConfigSchema,ask:askConfigSchema,agents:agentsConfigSchema,install:installConfigSchema.default({}),browser:browserConfigSchema.default({})});
1
+ import{z as e}from"zod";const t=["zhipin","yupao"],o=["managed-cdp","remote-cdp","existing-session"],n=["chrome","chromium","msedge"],i=["guarded","auto","deny"],r=["auto","confirm","deny"],a=["summarize","truncate"],s=e.string().trim().regex(/^#[\da-fA-F]{6}$/,"profileColor must be a hex RGB color such as #2563EB").transform(e=>e.toUpperCase());export const browserWindowBoundsSchema=e.object({x:e.number().int().optional(),y:e.number().int().optional(),width:e.number().int().positive().optional(),height:e.number().int().positive().optional()});export const providerConfigSchema=e.object({apiKey:e.string(),baseUrl:e.string().optional()});export const llmConfigSchema=e.object({defaultProvider:e.string(),defaultModel:e.string(),providers:e.record(e.string(),providerConfigSchema)});export const askConfigSchema=e.object({llmModel:e.string().optional(),confirmThreshold:e.number().optional()});export const runtimeApprovalConfigSchema=e.object({default:e.enum(i).default("guarded"),overrides:e.record(e.string(),e.enum(r)).default({})});export const runtimeCompactionConfigSchema=e.object({enabled:e.boolean().default(!0),strategy:e.enum(a).default("summarize"),threshold:e.number().min(.1).max(.95).default(.75),keepRecentTurns:e.number().int().min(1).default(4),keepRecentTokens:e.number().int().min(1).default(32e3)});export const runtimeThinkingLevels=["off","low","medium","high"];export const runtimeConfigSchema=e.object({provider:e.string().optional(),model:e.string().optional(),maxSteps:e.number().int().min(1).default(80),turnTimeoutMs:e.number().int().min(1e4).default(3e5),threadsDir:e.string().default("~/.roll-agent/threads"),contextWindow:e.number().int().min(1).optional(),thinkingLevel:e.enum(runtimeThinkingLevels).default("medium"),approval:runtimeApprovalConfigSchema.default({}),compaction:runtimeCompactionConfigSchema.default({})});export const agentsConfigSchema=e.object({dataDir:e.string(),env:e.record(e.string(),e.record(e.string(),e.string())).optional()});export const installConfigSchema=e.object({registry:e.string().trim().url().optional(),fetchRetries:e.number().int().min(0).max(10).default(3),preferOffline:e.boolean().default(!1),networkTimeoutMs:e.number().int().min(1e4).default(12e4)});export const browserInstanceConfigSchema=e.object({platform:e.enum(t).optional(),mode:e.enum(o).default("managed-cdp"),headless:e.boolean().optional(),cdpUrl:e.string().optional(),cdpHost:e.string().default("127.0.0.1"),cdpPort:e.number().int().min(1).max(65535).optional(),channel:e.enum(n).default("chrome"),executablePath:e.string().optional(),userDataDir:e.string().trim().min(1),sessionsDir:e.string().trim().min(1).optional(),args:e.array(e.string()).optional(),profileName:e.string().trim().min(1).optional(),profileColor:s.optional(),windowBounds:browserWindowBoundsSchema.optional(),trackingAgentId:e.string().trim().min(1).optional()}).superRefine((t,o)=>{"managed-cdp"===t.mode&&void 0===t.cdpPort&&o.addIssue({code:e.ZodIssueCode.custom,path:["cdpPort"],message:"managed-cdp browser instance requires cdpPort"}),"remote-cdp"!==t.mode&&"existing-session"!==t.mode||void 0!==t.cdpUrl||o.addIssue({code:e.ZodIssueCode.custom,path:["cdpUrl"],message:`${t.mode} browser instance requires cdpUrl`})});export const browserConfigSchema=e.object({defaultInstance:e.string().trim().min(1).optional(),instances:e.record(e.string(),browserInstanceConfigSchema).default({})}).superRefine((t,o)=>{const n=Object.entries(t.instances);void 0!==t.defaultInstance&&void 0===t.instances[t.defaultInstance]&&o.addIssue({code:e.ZodIssueCode.custom,path:["defaultInstance"],message:`defaultInstance "${t.defaultInstance}" is not declared in browser.instances`});const i=new Map,r=new Map;for(const[t,a]of n){if(void 0!==a.cdpPort){const n=i.get(a.cdpPort);void 0!==n?o.addIssue({code:e.ZodIssueCode.custom,path:["instances",t,"cdpPort"],message:`cdpPort ${String(a.cdpPort)} is already used by browser instance "${n}"`}):i.set(a.cdpPort,t)}const n=r.get(a.userDataDir);void 0!==n?o.addIssue({code:e.ZodIssueCode.custom,path:["instances",t,"userDataDir"],message:`userDataDir is already used by browser instance "${n}"`}):r.set(a.userDataDir,t)}});export const rollConfigSchema=e.object({llm:llmConfigSchema,ask:askConfigSchema,runtime:runtimeConfigSchema.default({}),agents:agentsConfigSchema,install:installConfigSchema.default({}),browser:browserConfigSchema.default({})});
@@ -1,4 +1,7 @@
1
1
  import type { LanguageModelV3, SharedV3ProviderOptions } from "@ai-sdk/provider";
2
+ import { runtimeThinkingLevels } from "../config/schema.ts";
3
+ export type ThinkingLevel = (typeof runtimeThinkingLevels)[number];
4
+ export declare function thinkingProviderOptions(providerName: string, modelName: string, level: ThinkingLevel): SharedV3ProviderOptions | undefined;
2
5
  /**
3
6
  * 根据 provider 名称创建 AI SDK LanguageModel 实例。
4
7
  *
@@ -6,7 +9,7 @@ import type { LanguageModelV3, SharedV3ProviderOptions } from "@ai-sdk/provider"
6
9
  */
7
10
  export declare function createProviderModel(providerName: string, modelName: string, apiKey: string, baseURL?: string): LanguageModelV3;
8
11
  /** generateText 调用目的 */
9
- export type LLMCallPurpose = "structured-output" | "text" | "sampling";
12
+ export type LLMCallPurpose = "structured-output" | "text" | "sampling" | "chat";
10
13
  /** resolveLLMCall 的返回值 */
11
14
  export interface ResolvedLLMCall {
12
15
  readonly model: LanguageModelV3;
@@ -18,4 +21,4 @@ export interface ResolvedLLMCall {
18
21
  * structured-output 场景下,对 qwen provider 自动注入 enableThinking: false,
19
22
  * 因为阿里云 thinking mode 不支持 structured output。
20
23
  */
21
- export declare function resolveLLMCall(providerName: string, modelName: string, apiKey: string, purpose: LLMCallPurpose, baseURL?: string): ResolvedLLMCall;
24
+ export declare function resolveLLMCall(providerName: string, modelName: string, apiKey: string, purpose: LLMCallPurpose, baseURL?: string, thinkingLevel?: ThinkingLevel): ResolvedLLMCall;
@@ -1 +1 @@
1
- import{createAlibaba as e}from"@ai-sdk/alibaba";import{createAnthropic as o}from"@ai-sdk/anthropic";import{createOpenAI as a}from"@ai-sdk/openai";import{createDeepSeek as i}from"@ai-sdk/deepseek";const r="https://dashscope.aliyuncs.com/compatible-mode/v1",p={anthropic:(e,{apiKey:a,baseURL:i})=>o({apiKey:a,...i?{baseURL:i}:{}})(e),openai:(e,{apiKey:o,baseURL:i})=>a({apiKey:o,...i?{baseURL:i}:{}})(e),deepseek:(e,{apiKey:o,baseURL:a})=>i({apiKey:o,...a?{baseURL:a}:{}})(e),qwen:(o,{apiKey:a,baseURL:i})=>e({apiKey:a,baseURL:i??r})(o)};export function createProviderModel(e,o,a,i){const r=p[e];if(!r){const o=Object.keys(p).join(", ");throw new Error(`Unknown LLM provider "${e}". Supported: ${o}`)}return r(o,{apiKey:a,baseURL:i})}export function resolveLLMCall(e,o,a,i,r){const p=createProviderModel(e,o,a,r);return"structured-output"===i&&"qwen"===e?{model:p,providerOptions:{alibaba:{enableThinking:!1}}}:{model:p}}
1
+ import{createAlibaba as e}from"@ai-sdk/alibaba";import{createAnthropic as i}from"@ai-sdk/anthropic";import{createOpenAI as n}from"@ai-sdk/openai";import{createDeepSeek as o}from"@ai-sdk/deepseek";import{runtimeThinkingLevels as t}from"../config/schema.js";const r={low:2048,medium:8192,high:16384},a=["gpt-5.1","gpt-5.2","gpt-5.3","gpt-5.4"];function p(e){return a.some(i=>e.startsWith(i))}function s(e){const i=/^claude-(?:sonnet|opus)-(\d+)-(\d+)(?:\b|-)/.exec(e),n=i?.[1],o=i?.[2];if(!n||!o)return!1;const t=Number(n),r=Number(o);return t>4||4===t&&r>=6}export function thinkingProviderOptions(e,i,n){return"openai"===e?"off"===n?p(i)?{openai:{reasoningEffort:"none"}}:void 0:{openai:{reasoningEffort:n}}:"anthropic"===e?"off"===n?{anthropic:{thinking:{type:"disabled"}}}:s(i)?{anthropic:{thinking:{type:"adaptive"},effort:n}}:{anthropic:{thinking:{type:"enabled",budgetTokens:r[n]}}}:"qwen"===e?"off"===n?{alibaba:{enableThinking:!1}}:{alibaba:{enableThinking:!0,thinkingBudget:r[n]}}:"deepseek"===e?{deepseek:{thinking:{type:"off"===n?"disabled":"enabled"}}}:void 0}const d="https://dashscope.aliyuncs.com/compatible-mode/v1",c={anthropic:(e,{apiKey:n,baseURL:o})=>i({apiKey:n,...o?{baseURL:o}:{}})(e),openai:(e,{apiKey:i,baseURL:o})=>n({apiKey:i,...o?{baseURL:o}:{}})(e),deepseek:(e,{apiKey:i,baseURL:n})=>o({apiKey:i,...n?{baseURL:n}:{}})(e),qwen:(i,{apiKey:n,baseURL:o})=>e({apiKey:n,baseURL:o??d})(i)};export function createProviderModel(e,i,n,o){const t=c[e];if(!t){const i=Object.keys(c).join(", ");throw new Error(`Unknown LLM provider "${e}". Supported: ${i}`)}return t(i,{apiKey:n,baseURL:o})}export function resolveLLMCall(e,i,n,o,t,r="medium"){const a=createProviderModel(e,i,n,t);if("structured-output"===o&&"qwen"===e)return{model:a,providerOptions:{alibaba:{enableThinking:!1}}};if("chat"===o){const n=thinkingProviderOptions(e,i,r);return n?{model:a,providerOptions:n}:{model:a}}return{model:a}}
@@ -9,6 +9,8 @@ export interface ConnectOptions {
9
9
  /** 注入到 stdio 子进程的环境变量(与 process.env 合并) */
10
10
  readonly env?: Readonly<Record<string, string>>;
11
11
  }
12
+ export declare function buildStdioChildEnv(env?: Readonly<Record<string, string>>): Record<string, string>;
13
+ export declare function shouldSuppressStdioChildStderrLine(line: string): boolean;
12
14
  /**
13
15
  * MCP Client Manager — 管理到子 Agent MCP Server 的连接。
14
16
  *
@@ -1 +1 @@
1
- import{Client as t}from"@modelcontextprotocol/sdk/client/index.js";import{StdioClientTransport as n}from"@modelcontextprotocol/sdk/client/stdio.js";import{StreamableHTTPClientTransport as e}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{registerSamplingHandler as o}from"./sampling-handler.js";const c=3e4;export class McpClientManager{connections=new Map;async connect(s,i,a,l={}){const r=this.connections.get(s);if(r)return r.client;const m=l.timeoutMs??c,p=l.samplingModel?{sampling:{}}:{},d=new t({name:`roll-client-${s}`,version:"0.0.1"},{capabilities:p});l.samplingModel&&o(d,l.samplingModel);const h="streamable-http"===i.type?new e(new URL(i.endpoint)):new n({command:i.command,args:[...i.args??[]],cwd:a,...l.env?{env:{...process.env,...l.env}}:{}}),w=d.connect(h);let g;const y=new Promise((t,n)=>{g=setTimeout(()=>n(new Error(`Connection to "${s}" timed out after ${m}ms`)),m)});try{await Promise.race([w,y])}catch(t){throw await d.close().catch(()=>{}),t}finally{clearTimeout(g)}return this.connections.set(s,{client:d,transportType:i.type}),d}async disconnect(t){const n=this.connections.get(t);n&&(await n.client.close(),this.connections.delete(t))}async disconnectAll(){const t=[...this.connections.keys()];await Promise.all(t.map(t=>this.disconnect(t)))}isConnected(t){return this.connections.has(t)}}
1
+ import{Client as n}from"@modelcontextprotocol/sdk/client/index.js";import{StdioClientTransport as t}from"@modelcontextprotocol/sdk/client/stdio.js";import{StreamableHTTPClientTransport as e}from"@modelcontextprotocol/sdk/client/streamableHttp.js";import{registerSamplingHandler as o}from"./sampling-handler.js";const s=3e4,i="--disable-warning=ExperimentalWarning";export function buildStdioChildEnv(n){const t=n?{...process.env,...n}:{};return{...t,NODE_OPTIONS:r(t.NODE_OPTIONS,i),ROLL_AGENT_LOG_LEVEL:t.ROLL_AGENT_LOG_LEVEL??"warn"}}function r(n,t){const e=n?.trim();if(!e)return t;const o=e.split(/\s+/);return o.includes("--no-warnings")||o.includes(t)?e:`${e} ${t}`}export function shouldSuppressStdioChildStderrLine(n){const t=n.trim();return t.includes("ExperimentalWarning:")||t.startsWith("(Use `node --trace-warnings")||/\[INFO\s*\]\s*\[[^\]]+\]\s*MCP Server running on stdio$/.test(t)}function c(n,e,o){const s=new t({command:n.command,args:[...n.args??[]],cwd:e,env:buildStdioChildEnv(o),stderr:"pipe"});return l(s),s}function l(n){const t=n.stderr;if(!t)return;let e="";const o=n=>{shouldSuppressStdioChildStderrLine(n)||process.stderr.write(`${n}\n`)};t.on("data",n=>{e+=n.toString();const t=e.split(/\r?\n/);e=t.pop()??"";for(const n of t)o(n)}),t.on("end",()=>{e.length>0&&(o(e),e="")})}export class McpClientManager{connections=new Map;async connect(t,i,r,l={}){const a=this.connections.get(t);if(a)return a.client;const d=l.timeoutMs??s,p=l.samplingModel?{sampling:{}}:{},m=new n({name:`roll-client-${t}`,version:"0.0.1"},{capabilities:p});l.samplingModel&&o(m,l.samplingModel);const u="streamable-http"===i.type?new e(new URL(i.endpoint)):c(i,r,l.env),h=m.connect(u);let g;const w=new Promise((n,e)=>{g=setTimeout(()=>e(new Error(`Connection to "${t}" timed out after ${d}ms`)),d)});try{await Promise.race([h,w])}catch(n){throw await m.close().catch(()=>{}),n}finally{clearTimeout(g)}return this.connections.set(t,{client:m,transportType:i.type}),m}async disconnect(n){const t=this.connections.get(n);t&&(await t.client.close(),this.connections.delete(n))}async disconnectAll(){const n=[...this.connections.keys()];await Promise.all(n.map(n=>this.disconnect(n)))}isConnected(n){return this.connections.has(n)}}