@ai-setting/roy-agent-cli 1.7.21 → 1.7.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/roy-agent.js +114 -987
- package/dist/index.js +114 -987
- package/dist/roy-agent-linux-x64/bin/roy-agent +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -359,97 +359,6 @@ var init_markdown_renderer = __esm(() => {
|
|
|
359
359
|
], MarkdownRenderer.prototype, "push", null);
|
|
360
360
|
});
|
|
361
361
|
|
|
362
|
-
// src/services/stdout-batcher.ts
|
|
363
|
-
function createStdoutBatcher(options = {}) {
|
|
364
|
-
const flushIntervalMs = options.flushIntervalMs ?? 16;
|
|
365
|
-
const maxBufferBytes = options.maxBufferBytes ?? 4096;
|
|
366
|
-
const writeFn = options.writeFn ?? ((chunk) => {
|
|
367
|
-
process.stdout.write(chunk);
|
|
368
|
-
return true;
|
|
369
|
-
});
|
|
370
|
-
const onFlush = options.onFlush;
|
|
371
|
-
let buffer = "";
|
|
372
|
-
let queuedWrites = 0;
|
|
373
|
-
let timer = null;
|
|
374
|
-
let totalBatches = 0;
|
|
375
|
-
let totalWrites = 0;
|
|
376
|
-
let totalBytes = 0;
|
|
377
|
-
let lastBatchWrites = 0;
|
|
378
|
-
function performFlush() {
|
|
379
|
-
if (buffer.length === 0)
|
|
380
|
-
return;
|
|
381
|
-
const chunk = buffer;
|
|
382
|
-
buffer = "";
|
|
383
|
-
lastBatchWrites = queuedWrites;
|
|
384
|
-
queuedWrites = 0;
|
|
385
|
-
totalBatches += 1;
|
|
386
|
-
totalBytes += chunk.length;
|
|
387
|
-
writeFn(chunk);
|
|
388
|
-
if (onFlush) {
|
|
389
|
-
onFlush({
|
|
390
|
-
writesInLastBatch: lastBatchWrites,
|
|
391
|
-
totalBatches,
|
|
392
|
-
totalBytes
|
|
393
|
-
});
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function scheduleFlush() {
|
|
397
|
-
if (timer !== null)
|
|
398
|
-
return;
|
|
399
|
-
timer = setTimeout(() => {
|
|
400
|
-
timer = null;
|
|
401
|
-
performFlush();
|
|
402
|
-
}, flushIntervalMs);
|
|
403
|
-
}
|
|
404
|
-
function maybeForceFlush() {
|
|
405
|
-
if (buffer.length >= maxBufferBytes) {
|
|
406
|
-
if (timer !== null) {
|
|
407
|
-
clearTimeout(timer);
|
|
408
|
-
timer = null;
|
|
409
|
-
}
|
|
410
|
-
performFlush();
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
function write(chunk) {
|
|
414
|
-
if (chunk.length === 0)
|
|
415
|
-
return;
|
|
416
|
-
buffer += chunk;
|
|
417
|
-
queuedWrites += 1;
|
|
418
|
-
totalWrites += 1;
|
|
419
|
-
scheduleFlush();
|
|
420
|
-
maybeForceFlush();
|
|
421
|
-
}
|
|
422
|
-
function flushNow() {
|
|
423
|
-
if (timer !== null) {
|
|
424
|
-
clearTimeout(timer);
|
|
425
|
-
timer = null;
|
|
426
|
-
}
|
|
427
|
-
performFlush();
|
|
428
|
-
}
|
|
429
|
-
function cancel() {
|
|
430
|
-
if (timer !== null) {
|
|
431
|
-
clearTimeout(timer);
|
|
432
|
-
timer = null;
|
|
433
|
-
}
|
|
434
|
-
buffer = "";
|
|
435
|
-
queuedWrites = 0;
|
|
436
|
-
}
|
|
437
|
-
function getStats() {
|
|
438
|
-
return {
|
|
439
|
-
batches: totalBatches,
|
|
440
|
-
queuedWrites: totalWrites,
|
|
441
|
-
totalBytes,
|
|
442
|
-
writesInLastBatch: lastBatchWrites
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
|
-
return {
|
|
446
|
-
write,
|
|
447
|
-
flushNow,
|
|
448
|
-
cancel,
|
|
449
|
-
getStats
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
|
|
453
362
|
// src/services/stream-output.service.ts
|
|
454
363
|
var exports_stream_output_service = {};
|
|
455
364
|
__export(exports_stream_output_service, {
|
|
@@ -460,26 +369,14 @@ __export(exports_stream_output_service, {
|
|
|
460
369
|
COLORS: () => COLORS
|
|
461
370
|
});
|
|
462
371
|
import chalk2 from "chalk";
|
|
463
|
-
import {
|
|
464
|
-
createLogger as createLogger2,
|
|
465
|
-
TracedAs as TracedAs2,
|
|
466
|
-
wrapFunction
|
|
467
|
-
} from "@ai-setting/roy-agent-core";
|
|
468
|
-
function isStdoutBatchEnabled() {
|
|
469
|
-
const v = process.env.ROY_AGENT_BATCH_STDOUT;
|
|
470
|
-
if (v === undefined)
|
|
471
|
-
return true;
|
|
472
|
-
if (v === "0" || v === "false" || v === "no")
|
|
473
|
-
return false;
|
|
474
|
-
return true;
|
|
475
|
-
}
|
|
372
|
+
import { createLogger as createLogger2, TracedAs as TracedAs2 } from "@ai-setting/roy-agent-core";
|
|
476
373
|
function resetStreamAbort() {
|
|
477
374
|
streamAbortSignal.aborted = false;
|
|
478
375
|
}
|
|
479
376
|
function abortStream() {
|
|
480
377
|
streamAbortSignal.aborted = true;
|
|
481
378
|
}
|
|
482
|
-
var logger2, COLORS,
|
|
379
|
+
var logger2, COLORS, streamAbortSignal, StreamOutputService;
|
|
483
380
|
var init_stream_output_service = __esm(() => {
|
|
484
381
|
init_markdown_renderer();
|
|
485
382
|
logger2 = createLogger2("stream-output");
|
|
@@ -499,28 +396,6 @@ var init_stream_output_service = __esm(() => {
|
|
|
499
396
|
error: chalk2.red,
|
|
500
397
|
progress: chalk2.dim
|
|
501
398
|
};
|
|
502
|
-
emitBatchFlushSpan = wrapFunction(emitBatchFlushSpanImpl, "cli.stream-output.writeStdout-batched", {
|
|
503
|
-
recordParams: true,
|
|
504
|
-
recordResult: false,
|
|
505
|
-
log: false,
|
|
506
|
-
paramFilter: (args) => {
|
|
507
|
-
const s = args[0] ?? {};
|
|
508
|
-
return {
|
|
509
|
-
writesInLastBatch: s.writesInLastBatch ?? 0,
|
|
510
|
-
totalBatches: s.batches ?? 0,
|
|
511
|
-
totalBytes: s.totalBytes ?? 0
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
});
|
|
515
|
-
emitSilentModeSkippedSpan = wrapFunction(emitSilentModeSkippedSpanImpl, "stream-output.silent-mode-skipped", {
|
|
516
|
-
recordParams: true,
|
|
517
|
-
recordResult: false,
|
|
518
|
-
log: false,
|
|
519
|
-
paramFilter: (args) => ({
|
|
520
|
-
"text.length": typeof args[0] === "number" ? args[0] : 0,
|
|
521
|
-
reason: "silent=true (Ink mode)"
|
|
522
|
-
})
|
|
523
|
-
});
|
|
524
399
|
streamAbortSignal = {
|
|
525
400
|
aborted: false
|
|
526
401
|
};
|
|
@@ -539,7 +414,6 @@ var init_stream_output_service = __esm(() => {
|
|
|
539
414
|
reasoningClosedByText = false;
|
|
540
415
|
chunkCallback = undefined;
|
|
541
416
|
silent = false;
|
|
542
|
-
stdoutBatcher = null;
|
|
543
417
|
constructor(options = {}) {
|
|
544
418
|
this.options = options;
|
|
545
419
|
this.silent = options.silent ?? false;
|
|
@@ -564,33 +438,9 @@ var init_stream_output_service = __esm(() => {
|
|
|
564
438
|
}
|
|
565
439
|
}
|
|
566
440
|
writeStdout(text) {
|
|
567
|
-
if (this.silent)
|
|
568
|
-
emitSilentModeSkippedSpan(text.length);
|
|
569
|
-
return;
|
|
570
|
-
}
|
|
571
|
-
if (!isStdoutBatchEnabled()) {
|
|
572
|
-
process.stdout.write(text);
|
|
441
|
+
if (this.silent)
|
|
573
442
|
return;
|
|
574
|
-
|
|
575
|
-
if (this.stdoutBatcher === null) {
|
|
576
|
-
this.stdoutBatcher = createStdoutBatcher({
|
|
577
|
-
flushIntervalMs: 16,
|
|
578
|
-
onFlush: (stats) => {
|
|
579
|
-
emitBatchFlushSpan(stats);
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
this.stdoutBatcher.write(text);
|
|
584
|
-
}
|
|
585
|
-
flushStdout() {
|
|
586
|
-
if (this.stdoutBatcher !== null) {
|
|
587
|
-
this.stdoutBatcher.flushNow();
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
cancelStdout() {
|
|
591
|
-
if (this.stdoutBatcher !== null) {
|
|
592
|
-
this.stdoutBatcher.cancel();
|
|
593
|
-
}
|
|
443
|
+
process.stdout.write(text);
|
|
594
444
|
}
|
|
595
445
|
logStdout(message) {
|
|
596
446
|
if (this.silent)
|
|
@@ -835,60 +685,8 @@ ${COLORS.system("[已中断]")}
|
|
|
835
685
|
this.reasoningStarted = false;
|
|
836
686
|
this.reasoningClosedByText = false;
|
|
837
687
|
this.thinkingPrinted = false;
|
|
838
|
-
this.flushStdout();
|
|
839
688
|
}
|
|
840
689
|
};
|
|
841
|
-
__legacyDecorateClassTS([
|
|
842
|
-
TracedAs2("cli.stream-output.writeStdout", {
|
|
843
|
-
recordParams: true,
|
|
844
|
-
recordResult: false,
|
|
845
|
-
log: false,
|
|
846
|
-
paramFilter: (args) => ({
|
|
847
|
-
"text.length": typeof args[0] === "string" ? args[0].length : 0,
|
|
848
|
-
"text.head": typeof args[0] === "string" ? args[0].slice(0, 32) : "",
|
|
849
|
-
"text.tail": typeof args[0] === "string" ? args[0].slice(-32) : "",
|
|
850
|
-
"batch.enabled": isStdoutBatchEnabled() ? 1 : 0
|
|
851
|
-
})
|
|
852
|
-
}),
|
|
853
|
-
__legacyMetadataTS("design:type", Function),
|
|
854
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
855
|
-
String
|
|
856
|
-
]),
|
|
857
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
858
|
-
], StreamOutputService.prototype, "writeStdout", null);
|
|
859
|
-
__legacyDecorateClassTS([
|
|
860
|
-
TracedAs2("stream.handle-event", {
|
|
861
|
-
recordParams: true,
|
|
862
|
-
recordResult: false,
|
|
863
|
-
paramFilter: (args) => {
|
|
864
|
-
const e = args[0] ?? {};
|
|
865
|
-
const payload = e.payload ?? {};
|
|
866
|
-
return {
|
|
867
|
-
"event.type": e.type ?? "unknown",
|
|
868
|
-
"event.payload.kind": payload && typeof payload === "object" ? Object.keys(payload).join(",") : ""
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
}),
|
|
872
|
-
__legacyMetadataTS("design:type", Function),
|
|
873
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
874
|
-
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
875
|
-
]),
|
|
876
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
877
|
-
], StreamOutputService.prototype, "handleEvent", null);
|
|
878
|
-
__legacyDecorateClassTS([
|
|
879
|
-
TracedAs2("stream.handle-start", {
|
|
880
|
-
recordParams: true,
|
|
881
|
-
recordResult: false,
|
|
882
|
-
paramFilter: (args) => ({
|
|
883
|
-
model: args[0]?.metadata?.model ?? ""
|
|
884
|
-
})
|
|
885
|
-
}),
|
|
886
|
-
__legacyMetadataTS("design:type", Function),
|
|
887
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
888
|
-
Object
|
|
889
|
-
]),
|
|
890
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
891
|
-
], StreamOutputService.prototype, "handleStart", null);
|
|
892
690
|
__legacyDecorateClassTS([
|
|
893
691
|
TracedAs2("stream.handle-text", {
|
|
894
692
|
recordParams: true,
|
|
@@ -904,102 +702,6 @@ ${COLORS.system("[已中断]")}
|
|
|
904
702
|
]),
|
|
905
703
|
__legacyMetadataTS("design:returntype", undefined)
|
|
906
704
|
], StreamOutputService.prototype, "handleText", null);
|
|
907
|
-
__legacyDecorateClassTS([
|
|
908
|
-
TracedAs2("stream.handle-reasoning", {
|
|
909
|
-
recordParams: true,
|
|
910
|
-
recordResult: false,
|
|
911
|
-
paramFilter: (args) => ({
|
|
912
|
-
"delta.length": args[0]?.delta?.length ?? 0,
|
|
913
|
-
"content.length": args[0]?.content?.length ?? 0,
|
|
914
|
-
phase: args[0]?.phase ?? ""
|
|
915
|
-
})
|
|
916
|
-
}),
|
|
917
|
-
__legacyMetadataTS("design:type", Function),
|
|
918
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
919
|
-
Object
|
|
920
|
-
]),
|
|
921
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
922
|
-
], StreamOutputService.prototype, "handleReasoning", null);
|
|
923
|
-
__legacyDecorateClassTS([
|
|
924
|
-
TracedAs2("stream.handle-tool-call", {
|
|
925
|
-
recordParams: true,
|
|
926
|
-
recordResult: false,
|
|
927
|
-
log: true,
|
|
928
|
-
paramFilter: (args) => {
|
|
929
|
-
const p = args[0] ?? {};
|
|
930
|
-
return {
|
|
931
|
-
"tool.name": p.name ?? "unknown",
|
|
932
|
-
"tool.id": p.id ?? "",
|
|
933
|
-
"tool.args.keys": p.arguments ? Object.keys(p.arguments).join(",") : ""
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
}),
|
|
937
|
-
__legacyMetadataTS("design:type", Function),
|
|
938
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
939
|
-
Object
|
|
940
|
-
]),
|
|
941
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
942
|
-
], StreamOutputService.prototype, "handleToolCall", null);
|
|
943
|
-
__legacyDecorateClassTS([
|
|
944
|
-
TracedAs2("stream.handle-tool-result", {
|
|
945
|
-
recordParams: true,
|
|
946
|
-
recordResult: false,
|
|
947
|
-
log: true,
|
|
948
|
-
paramFilter: (args) => {
|
|
949
|
-
const p = args[0] ?? {};
|
|
950
|
-
const result = p.result?.output ?? p.result?.error;
|
|
951
|
-
return {
|
|
952
|
-
"tool.name": p.name ?? "unknown",
|
|
953
|
-
"tool.result.kind": result !== undefined ? typeof result : "none",
|
|
954
|
-
"tool.result.preview": typeof result === "string" ? result.substring(0, 80) : typeof result === "object" && result !== null ? JSON.stringify(result).substring(0, 80) : ""
|
|
955
|
-
};
|
|
956
|
-
}
|
|
957
|
-
}),
|
|
958
|
-
__legacyMetadataTS("design:type", Function),
|
|
959
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
960
|
-
Object
|
|
961
|
-
]),
|
|
962
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
963
|
-
], StreamOutputService.prototype, "handleToolResult", null);
|
|
964
|
-
__legacyDecorateClassTS([
|
|
965
|
-
TracedAs2("stream.handle-tool-error", {
|
|
966
|
-
recordParams: true,
|
|
967
|
-
recordResult: false,
|
|
968
|
-
log: true,
|
|
969
|
-
paramFilter: (args) => {
|
|
970
|
-
const p = args[0] ?? {};
|
|
971
|
-
return {
|
|
972
|
-
"tool.name": p.toolName ?? "unknown",
|
|
973
|
-
"tool.error.preview": typeof p.error === "string" ? p.error.substring(0, 120) : ""
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
}),
|
|
977
|
-
__legacyMetadataTS("design:type", Function),
|
|
978
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
979
|
-
Object
|
|
980
|
-
]),
|
|
981
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
982
|
-
], StreamOutputService.prototype, "handleToolError", null);
|
|
983
|
-
__legacyDecorateClassTS([
|
|
984
|
-
TracedAs2("stream.handle-completed", {
|
|
985
|
-
recordParams: true,
|
|
986
|
-
recordResult: false,
|
|
987
|
-
paramFilter: (args) => {
|
|
988
|
-
const meta = args[0]?.metadata;
|
|
989
|
-
return {
|
|
990
|
-
model: meta?.model ?? "",
|
|
991
|
-
"usage.promptTokens": meta?.usage?.promptTokens ?? 0,
|
|
992
|
-
"usage.completionTokens": meta?.usage?.completionTokens ?? 0,
|
|
993
|
-
"usage.totalTokens": meta?.usage?.totalTokens ?? 0
|
|
994
|
-
};
|
|
995
|
-
}
|
|
996
|
-
}),
|
|
997
|
-
__legacyMetadataTS("design:type", Function),
|
|
998
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
999
|
-
Object
|
|
1000
|
-
]),
|
|
1001
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
1002
|
-
], StreamOutputService.prototype, "handleCompleted", null);
|
|
1003
705
|
});
|
|
1004
706
|
|
|
1005
707
|
// src/commands/ui/mascot/glasses-girl.ts
|
|
@@ -1388,7 +1090,6 @@ var init_slash_command_popup = __esm(() => {
|
|
|
1388
1090
|
// src/render/markdown.ts
|
|
1389
1091
|
import { Marked } from "marked";
|
|
1390
1092
|
import { highlight } from "cli-highlight";
|
|
1391
|
-
import { wrapFunction as wrapFunction2 } from "@ai-setting/roy-agent-core";
|
|
1392
1093
|
function setMarkdownEnabled(enabled) {
|
|
1393
1094
|
markdownEnabled = enabled;
|
|
1394
1095
|
}
|
|
@@ -1631,50 +1332,7 @@ function wrapLine(line, width) {
|
|
|
1631
1332
|
return out.join(`
|
|
1632
1333
|
`);
|
|
1633
1334
|
}
|
|
1634
|
-
function
|
|
1635
|
-
for (let i = 0;i < renderCache.length; i++) {
|
|
1636
|
-
if (renderCache[i].key === key) {
|
|
1637
|
-
const entry = renderCache[i];
|
|
1638
|
-
if (i > 0) {
|
|
1639
|
-
renderCache.splice(i, 1);
|
|
1640
|
-
renderCache.unshift(entry);
|
|
1641
|
-
}
|
|
1642
|
-
return entry.value;
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return;
|
|
1646
|
-
}
|
|
1647
|
-
function cacheInsert(key, value, text, width) {
|
|
1648
|
-
if (renderCache.length >= MAX_CACHE_ENTRIES) {
|
|
1649
|
-
renderCache.pop();
|
|
1650
|
-
}
|
|
1651
|
-
renderCache.unshift({ key, value, text, width });
|
|
1652
|
-
renderCacheStats.size = renderCache.length;
|
|
1653
|
-
}
|
|
1654
|
-
function findPrefixCacheEntry(text, width) {
|
|
1655
|
-
let best;
|
|
1656
|
-
let bestLen = -1;
|
|
1657
|
-
for (let i = 0;i < renderCache.length; i++) {
|
|
1658
|
-
const e = renderCache[i];
|
|
1659
|
-
if (e.width !== width)
|
|
1660
|
-
continue;
|
|
1661
|
-
if (e.text.length === 0)
|
|
1662
|
-
continue;
|
|
1663
|
-
if (text.startsWith(e.text) && e.text.length > bestLen) {
|
|
1664
|
-
best = e;
|
|
1665
|
-
bestLen = e.text.length;
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
return best;
|
|
1669
|
-
}
|
|
1670
|
-
function isSuffixSafeToLexIndependently(suffix) {
|
|
1671
|
-
if (suffix.length === 0)
|
|
1672
|
-
return true;
|
|
1673
|
-
if (suffix.charCodeAt(0) !== 10)
|
|
1674
|
-
return true;
|
|
1675
|
-
return false;
|
|
1676
|
-
}
|
|
1677
|
-
function renderMarkdownImpl(text, options = {}) {
|
|
1335
|
+
function renderMarkdown(text, options = {}) {
|
|
1678
1336
|
const width = options.width ?? 80;
|
|
1679
1337
|
if (!markdownEnabled) {
|
|
1680
1338
|
return wrapLine(text, width);
|
|
@@ -1682,28 +1340,6 @@ function renderMarkdownImpl(text, options = {}) {
|
|
|
1682
1340
|
if (!text || text.trim() === "") {
|
|
1683
1341
|
return "";
|
|
1684
1342
|
}
|
|
1685
|
-
const key = text + "\x00" + width;
|
|
1686
|
-
const cached = cacheLookup(key);
|
|
1687
|
-
if (cached !== undefined) {
|
|
1688
|
-
renderCacheStats.hits++;
|
|
1689
|
-
renderCacheStats.cachedHits++;
|
|
1690
|
-
return cached;
|
|
1691
|
-
}
|
|
1692
|
-
const prefixEntry = findPrefixCacheEntry(text, width);
|
|
1693
|
-
if (prefixEntry !== undefined) {
|
|
1694
|
-
const suffix = text.slice(prefixEntry.text.length);
|
|
1695
|
-
if (isSuffixSafeToLexIndependently(suffix)) {
|
|
1696
|
-
const suffixRender = renderMarkdownImpl(suffix, { width });
|
|
1697
|
-
const combined = prefixEntry.value + suffixRender;
|
|
1698
|
-
cacheInsert(key, combined, text, width);
|
|
1699
|
-
renderCacheStats.hits++;
|
|
1700
|
-
renderCacheStats.prefixHits++;
|
|
1701
|
-
renderCacheStats.partialParses++;
|
|
1702
|
-
return combined;
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
renderCacheStats.misses++;
|
|
1706
|
-
renderCacheStats.partialParses++;
|
|
1707
1343
|
let tokens;
|
|
1708
1344
|
try {
|
|
1709
1345
|
tokens = marked.lexer(text);
|
|
@@ -1717,11 +1353,9 @@ function renderMarkdownImpl(text, options = {}) {
|
|
|
1717
1353
|
lines.push(block);
|
|
1718
1354
|
}
|
|
1719
1355
|
}
|
|
1720
|
-
|
|
1356
|
+
return lines.join(`
|
|
1721
1357
|
|
|
1722
1358
|
`);
|
|
1723
|
-
cacheInsert(key, result, text, width);
|
|
1724
|
-
return result;
|
|
1725
1359
|
}
|
|
1726
1360
|
function truncateForTerminal(text, maxLines) {
|
|
1727
1361
|
if (maxLines <= 0) {
|
|
@@ -1817,7 +1451,7 @@ function tailTruncateToRows(line, rows, width) {
|
|
|
1817
1451
|
const tail = segments.join("");
|
|
1818
1452
|
return tail + ANSI2.reset;
|
|
1819
1453
|
}
|
|
1820
|
-
var ANSI2, DEFAULT_THEME, markdownEnabled = true, marked,
|
|
1454
|
+
var ANSI2, DEFAULT_THEME, markdownEnabled = true, marked, ANSI_CSI_RE;
|
|
1821
1455
|
var init_markdown = __esm(() => {
|
|
1822
1456
|
ANSI2 = {
|
|
1823
1457
|
reset: "\x1B[0m",
|
|
@@ -1859,32 +1493,6 @@ var init_markdown = __esm(() => {
|
|
|
1859
1493
|
breaks: false,
|
|
1860
1494
|
pedantic: false
|
|
1861
1495
|
});
|
|
1862
|
-
renderCache = [];
|
|
1863
|
-
renderCacheStats = {
|
|
1864
|
-
hits: 0,
|
|
1865
|
-
prefixHits: 0,
|
|
1866
|
-
misses: 0,
|
|
1867
|
-
partialParses: 0,
|
|
1868
|
-
cachedHits: 0,
|
|
1869
|
-
size: 0
|
|
1870
|
-
};
|
|
1871
|
-
renderMarkdown = wrapFunction2(renderMarkdownImpl, "markdown.render", {
|
|
1872
|
-
recordParams: true,
|
|
1873
|
-
recordResult: true,
|
|
1874
|
-
paramFilter: (args) => ({
|
|
1875
|
-
"input.length": typeof args[0] === "string" ? args[0].length : 0,
|
|
1876
|
-
"options.width": typeof args[1]?.width === "number" ? args[1].width : 0
|
|
1877
|
-
}),
|
|
1878
|
-
resultFilter: (result) => ({
|
|
1879
|
-
"output.length": typeof result === "string" ? result.length : 0,
|
|
1880
|
-
"cache.hits": renderCacheStats.hits,
|
|
1881
|
-
"cache.prefixHits": renderCacheStats.prefixHits,
|
|
1882
|
-
"cache.misses": renderCacheStats.misses,
|
|
1883
|
-
"cache.partialParses": renderCacheStats.partialParses,
|
|
1884
|
-
"cache.size": renderCacheStats.size
|
|
1885
|
-
}),
|
|
1886
|
-
log: false
|
|
1887
|
-
});
|
|
1888
1496
|
ANSI_CSI_RE = /\u001b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
1889
1497
|
});
|
|
1890
1498
|
|
|
@@ -9852,7 +9460,7 @@ class CliQuietModeService {
|
|
|
9852
9460
|
// package.json
|
|
9853
9461
|
var package_default = {
|
|
9854
9462
|
name: "@ai-setting/roy-agent-cli",
|
|
9855
|
-
version: "1.7.
|
|
9463
|
+
version: "1.7.30",
|
|
9856
9464
|
type: "module",
|
|
9857
9465
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
9858
9466
|
main: "./dist/index.js",
|
|
@@ -11007,21 +10615,6 @@ function finalizeActStdout(args) {
|
|
|
11007
10615
|
output.log(result);
|
|
11008
10616
|
}
|
|
11009
10617
|
|
|
11010
|
-
// src/commands/shared/debug-trace.ts
|
|
11011
|
-
function printTraceIdAfterResponse(traceId, options) {
|
|
11012
|
-
const enabled = typeof options === "boolean" ? options : options.enabled;
|
|
11013
|
-
if (!enabled)
|
|
11014
|
-
return;
|
|
11015
|
-
const writer = typeof options === "object" && options.write ? options.write : (chunk) => process.stderr.write(chunk);
|
|
11016
|
-
writer(`[Trace] ${traceId}
|
|
11017
|
-
`);
|
|
11018
|
-
if (typeof options === "object" && typeof options.tuiSink === "function") {
|
|
11019
|
-
try {
|
|
11020
|
-
options.tuiSink(traceId);
|
|
11021
|
-
} catch (_tuiErr) {}
|
|
11022
|
-
}
|
|
11023
|
-
}
|
|
11024
|
-
|
|
11025
10618
|
// src/commands/act.ts
|
|
11026
10619
|
function detectWorkspaceRoot(cwd = process.cwd(), runGit = execFileSync) {
|
|
11027
10620
|
try {
|
|
@@ -11089,10 +10682,6 @@ function createActCommand(externalEnvService) {
|
|
|
11089
10682
|
describe: "附加图片到消息(可多次传入;支持本地路径 / http(s) URL / data:base64)",
|
|
11090
10683
|
type: "array",
|
|
11091
10684
|
string: true
|
|
11092
|
-
}).option("debug-on", {
|
|
11093
|
-
describe: "调试模式:响应结束后输出 [Trace] <traceId>(stderr),便于追踪调用 trace",
|
|
11094
|
-
type: "boolean",
|
|
11095
|
-
default: false
|
|
11096
10685
|
}),
|
|
11097
10686
|
async handler(args) {
|
|
11098
10687
|
const quiet = args.quiet ?? true;
|
|
@@ -11329,6 +10918,9 @@ function createActCommand(externalEnvService) {
|
|
|
11329
10918
|
}
|
|
11330
10919
|
});
|
|
11331
10920
|
const traceId = rootSpan.spanContext.traceId;
|
|
10921
|
+
if (!quiet) {
|
|
10922
|
+
output.info(`[Trace] ${traceId}`);
|
|
10923
|
+
}
|
|
11332
10924
|
provider.setGlobalContext(rootSpan.spanContext);
|
|
11333
10925
|
const contextHandler = new ContextHandlerService(env, sessionComponent, { maxRetries: 1, autoCompact: true });
|
|
11334
10926
|
const context = {
|
|
@@ -11363,7 +10955,6 @@ function createActCommand(externalEnvService) {
|
|
|
11363
10955
|
streamService,
|
|
11364
10956
|
output
|
|
11365
10957
|
});
|
|
11366
|
-
printTraceIdAfterResponse(traceId, args.debugOn ?? false);
|
|
11367
10958
|
if (!quiet) {
|
|
11368
10959
|
if (isWorkflowPausedActResult(result)) {
|
|
11369
10960
|
output.warn("工作流已暂停,等待用户输入(见上方 resume 提示)");
|
|
@@ -11682,35 +11273,6 @@ class QueryExecutor {
|
|
|
11682
11273
|
}
|
|
11683
11274
|
}
|
|
11684
11275
|
}
|
|
11685
|
-
__legacyDecorateClassTS([
|
|
11686
|
-
TracedAs4("cli.query-executor.setChunkCallback", {
|
|
11687
|
-
recordParams: true,
|
|
11688
|
-
recordResult: false,
|
|
11689
|
-
log: true,
|
|
11690
|
-
paramFilter: (args) => ({
|
|
11691
|
-
"cb.isFunction": typeof args[0] === "function"
|
|
11692
|
-
})
|
|
11693
|
-
}),
|
|
11694
|
-
__legacyMetadataTS("design:type", Function),
|
|
11695
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
11696
|
-
typeof StreamChunkCallback === "undefined" ? Object : StreamChunkCallback
|
|
11697
|
-
]),
|
|
11698
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
11699
|
-
], QueryExecutor.prototype, "setChunkCallback", null);
|
|
11700
|
-
__legacyDecorateClassTS([
|
|
11701
|
-
TracedAs4("cli.query-executor.handleEvent", {
|
|
11702
|
-
recordParams: true,
|
|
11703
|
-
recordResult: false,
|
|
11704
|
-
paramFilter: (args) => ({
|
|
11705
|
-
"event.type": args[0]?.type ?? "unknown"
|
|
11706
|
-
})
|
|
11707
|
-
}),
|
|
11708
|
-
__legacyMetadataTS("design:type", Function),
|
|
11709
|
-
__legacyMetadataTS("design:paramtypes", [
|
|
11710
|
-
Object
|
|
11711
|
-
]),
|
|
11712
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
11713
|
-
], QueryExecutor.prototype, "handleEvent", null);
|
|
11714
11276
|
__legacyDecorateClassTS([
|
|
11715
11277
|
TracedAs4("cli.query-executor.execute", { recordParams: true, log: true }),
|
|
11716
11278
|
__legacyMetadataTS("design:type", Function),
|
|
@@ -12137,16 +11699,6 @@ class EventHandler {
|
|
|
12137
11699
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
12138
11700
|
}
|
|
12139
11701
|
}
|
|
12140
|
-
__legacyDecorateClassTS([
|
|
12141
|
-
TracedAs5("cli.event-handler.start", {
|
|
12142
|
-
recordParams: false,
|
|
12143
|
-
recordResult: false,
|
|
12144
|
-
log: true
|
|
12145
|
-
}),
|
|
12146
|
-
__legacyMetadataTS("design:type", Function),
|
|
12147
|
-
__legacyMetadataTS("design:paramtypes", []),
|
|
12148
|
-
__legacyMetadataTS("design:returntype", Function)
|
|
12149
|
-
], EventHandler.prototype, "start", null);
|
|
12150
11702
|
__legacyDecorateClassTS([
|
|
12151
11703
|
TracedAs5("cli.event-handler.handleEvent", { recordParams: true }),
|
|
12152
11704
|
__legacyMetadataTS("design:type", Function),
|
|
@@ -12155,16 +11707,6 @@ __legacyDecorateClassTS([
|
|
|
12155
11707
|
]),
|
|
12156
11708
|
__legacyMetadataTS("design:returntype", undefined)
|
|
12157
11709
|
], EventHandler.prototype, "handleEvent", null);
|
|
12158
|
-
__legacyDecorateClassTS([
|
|
12159
|
-
TracedAs5("cli.event-handler.processQueue", {
|
|
12160
|
-
recordParams: false,
|
|
12161
|
-
recordResult: false,
|
|
12162
|
-
log: true
|
|
12163
|
-
}),
|
|
12164
|
-
__legacyMetadataTS("design:type", Function),
|
|
12165
|
-
__legacyMetadataTS("design:paramtypes", []),
|
|
12166
|
-
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
12167
|
-
], EventHandler.prototype, "processQueue", null);
|
|
12168
11710
|
|
|
12169
11711
|
// src/commands/shared/esc-active-descendant.ts
|
|
12170
11712
|
function hasActiveDescendants(env, parentSessionId) {
|
|
@@ -13111,23 +12653,8 @@ ${COLORS.system("[没有正在执行的请求]")}`);
|
|
|
13111
12653
|
onSubmit: async (input) => {
|
|
13112
12654
|
this.isExecuting = true;
|
|
13113
12655
|
inkApiRef?.setMode("executing");
|
|
13114
|
-
const inkTracerProvider = getTracerProvider3();
|
|
13115
|
-
const inkTracer = inkTracerProvider.getTracer("roy-tracer");
|
|
13116
|
-
const inkExistingContext = inkTracerProvider.getGlobalContext();
|
|
13117
|
-
let inkRootSpan;
|
|
13118
|
-
let inkTurnTraceId;
|
|
13119
|
-
if (inkExistingContext) {
|
|
13120
|
-
inkRootSpan = inkTracer.startSpan("interactive.execute", {
|
|
13121
|
-
parent: inkExistingContext
|
|
13122
|
-
});
|
|
13123
|
-
inkTurnTraceId = inkExistingContext.traceId;
|
|
13124
|
-
} else {
|
|
13125
|
-
inkRootSpan = inkTracer.startSpan("interactive.execute");
|
|
13126
|
-
inkTurnTraceId = inkRootSpan.spanContext.traceId;
|
|
13127
|
-
inkTracerProvider.setGlobalContext(inkRootSpan.spanContext);
|
|
13128
|
-
}
|
|
13129
12656
|
try {
|
|
13130
|
-
await this.options.onExecute(input
|
|
12657
|
+
await this.options.onExecute(input);
|
|
13131
12658
|
inkApiRef?.setMode("ready");
|
|
13132
12659
|
if (this.options.onAfterExecute) {
|
|
13133
12660
|
try {
|
|
@@ -13142,26 +12669,6 @@ ${COLORS.system("[没有正在执行的请求]")}`);
|
|
|
13142
12669
|
inkApiRef?.appendMessage({ role: "system", content: `[Error] ${msg}` });
|
|
13143
12670
|
throw err;
|
|
13144
12671
|
} finally {
|
|
13145
|
-
try {
|
|
13146
|
-
printTraceIdAfterResponse(inkTurnTraceId, {
|
|
13147
|
-
enabled: this.options.debugOn ?? false,
|
|
13148
|
-
tuiSink: (traceId) => {
|
|
13149
|
-
inkApiRef?.appendMessage({
|
|
13150
|
-
role: "system",
|
|
13151
|
-
content: `\uD83D\uDD0D [Trace] ${traceId}`
|
|
13152
|
-
});
|
|
13153
|
-
}
|
|
13154
|
-
});
|
|
13155
|
-
} catch (traceErr) {
|
|
13156
|
-
logger5.warn("printTraceIdAfterResponse failed (ink path)", {
|
|
13157
|
-
error: String(traceErr)
|
|
13158
|
-
});
|
|
13159
|
-
}
|
|
13160
|
-
try {
|
|
13161
|
-
inkRootSpan.end();
|
|
13162
|
-
} catch (spanErr) {
|
|
13163
|
-
logger5.warn("inkRootSpan.end failed", { error: String(spanErr) });
|
|
13164
|
-
}
|
|
13165
12672
|
this.isExecuting = false;
|
|
13166
12673
|
}
|
|
13167
12674
|
},
|
|
@@ -13431,6 +12938,7 @@ ${COLORS.system("[通知2] ❯ " + message.replace(/\n/g, `
|
|
|
13431
12938
|
traceId = rootSpan.spanContext.traceId;
|
|
13432
12939
|
provider.setGlobalContext(rootSpan.spanContext);
|
|
13433
12940
|
}
|
|
12941
|
+
console.log(`${COLORS.system("[Trace] " + traceId)}`);
|
|
13434
12942
|
console.log(`${COLORS.progress("[thinking...]")}`);
|
|
13435
12943
|
try {
|
|
13436
12944
|
await this.options.onExecute(message, traceId, agentContext);
|
|
@@ -13453,7 +12961,6 @@ ${COLORS.error("❌ 执行失败: " + error)}
|
|
|
13453
12961
|
}
|
|
13454
12962
|
} finally {
|
|
13455
12963
|
rootSpan.end();
|
|
13456
|
-
printTraceIdAfterResponse(traceId, this.options.debugOn ?? false);
|
|
13457
12964
|
if (existingContext) {
|
|
13458
12965
|
provider.setGlobalContext(existingContext);
|
|
13459
12966
|
} else {
|
|
@@ -13794,10 +13301,6 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
13794
13301
|
describe: "Default agent 名字(默认 Roy,可被覆盖)",
|
|
13795
13302
|
type: "string",
|
|
13796
13303
|
default: "Roy"
|
|
13797
|
-
}).option("debug-on", {
|
|
13798
|
-
describe: "调试模式:每次 turn 结束后输出 [Trace] <traceId>(stderr),便于追踪调用 trace",
|
|
13799
|
-
type: "boolean",
|
|
13800
|
-
default: false
|
|
13801
13304
|
}),
|
|
13802
13305
|
async handler(args) {
|
|
13803
13306
|
CliQuietModeService.getInstance().setQuiet(true);
|
|
@@ -13964,7 +13467,6 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
13964
13467
|
model: args.model,
|
|
13965
13468
|
version: getPackageVersion(),
|
|
13966
13469
|
useInk,
|
|
13967
|
-
debugOn: args.debugOn ?? false,
|
|
13968
13470
|
onExecute: async (message, traceId, agentContext) => {
|
|
13969
13471
|
resetStreamAbort();
|
|
13970
13472
|
const preloadedPrompts = eventSourceSystemPrompts;
|
|
@@ -14139,16 +13641,15 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
14139
13641
|
var InteractiveCommand = createInteractiveCommand();
|
|
14140
13642
|
|
|
14141
13643
|
// src/commands/run.ts
|
|
14142
|
-
import
|
|
13644
|
+
import React6 from "react";
|
|
14143
13645
|
import { render } from "ink";
|
|
14144
13646
|
|
|
14145
13647
|
// src/RunTui.tsx
|
|
14146
|
-
import { useState as useState6, useCallback as useCallback4, useRef as
|
|
14147
|
-
import { Box as
|
|
13648
|
+
import { useState as useState6, useCallback as useCallback4, useRef as useRef2, useEffect as useEffect5 } from "react";
|
|
13649
|
+
import { Box as Box6, Text as Text8, useApp as useApp2 } from "ink";
|
|
14148
13650
|
|
|
14149
13651
|
// src/tui/App.tsx
|
|
14150
13652
|
init_Markdown();
|
|
14151
|
-
import React4, { useEffect as useEffect4, useRef as useRef2 } from "react";
|
|
14152
13653
|
import { Box as Box4, Static as Static2, Text as Text6 } from "ink";
|
|
14153
13654
|
|
|
14154
13655
|
// src/tui/Spinner.tsx
|
|
@@ -14187,45 +13688,12 @@ var Spinner = ({
|
|
|
14187
13688
|
// src/tui/App.tsx
|
|
14188
13689
|
init_StatusBar();
|
|
14189
13690
|
init_theme();
|
|
14190
|
-
import { wrapFunction as wrapFunction3 } from "@ai-setting/roy-agent-core";
|
|
14191
13691
|
import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
|
|
14192
13692
|
var ROLE_PREFIX = {
|
|
14193
13693
|
user: "\uD83D\uDC64 You",
|
|
14194
13694
|
assistant: "\uD83E\uDD16 Agent",
|
|
14195
13695
|
tool: "\uD83D\uDD27 Tool"
|
|
14196
13696
|
};
|
|
14197
|
-
var emitAppRenderSpanImpl = (snapshot) => {};
|
|
14198
|
-
var emitAppRenderSpan = wrapFunction3(emitAppRenderSpanImpl, "tui.app.render", {
|
|
14199
|
-
recordParams: true,
|
|
14200
|
-
recordResult: false,
|
|
14201
|
-
log: true,
|
|
14202
|
-
paramFilter: (args) => {
|
|
14203
|
-
const s = args[0] ?? {};
|
|
14204
|
-
return {
|
|
14205
|
-
renderCount: s.renderCount ?? 0,
|
|
14206
|
-
historyLength: s.historyLength ?? 0,
|
|
14207
|
-
status: s.status ?? "unknown"
|
|
14208
|
-
};
|
|
14209
|
-
}
|
|
14210
|
-
});
|
|
14211
|
-
var emitRenderScheduledSpanImpl = (parentRenderCount) => {};
|
|
14212
|
-
var emitRenderScheduledSpan = wrapFunction3(emitRenderScheduledSpanImpl, "tui.app.render-scheduled", {
|
|
14213
|
-
recordParams: true,
|
|
14214
|
-
recordResult: false,
|
|
14215
|
-
log: false,
|
|
14216
|
-
paramFilter: (args) => ({
|
|
14217
|
-
parentRenderCount: args[0] ?? 0
|
|
14218
|
-
})
|
|
14219
|
-
});
|
|
14220
|
-
var emitRenderThrottledSpanImpl = (parentRenderCount) => {};
|
|
14221
|
-
var emitRenderThrottledSpan = wrapFunction3(emitRenderThrottledSpanImpl, "tui.app.render-throttled", {
|
|
14222
|
-
recordParams: true,
|
|
14223
|
-
recordResult: false,
|
|
14224
|
-
log: false,
|
|
14225
|
-
paramFilter: (args) => ({
|
|
14226
|
-
parentRenderCount: args[0] ?? 0
|
|
14227
|
-
})
|
|
14228
|
-
});
|
|
14229
13697
|
var RoleLabel = ({ role }) => {
|
|
14230
13698
|
const theme = getTheme();
|
|
14231
13699
|
const roleColor = role === "user" ? theme.user : role === "assistant" ? theme.assistant : theme.tool;
|
|
@@ -14293,18 +13761,10 @@ var App = ({
|
|
|
14293
13761
|
status,
|
|
14294
13762
|
model,
|
|
14295
13763
|
workdir,
|
|
13764
|
+
streamingText,
|
|
14296
13765
|
tokenCount
|
|
14297
13766
|
}) => {
|
|
14298
13767
|
const theme = getTheme();
|
|
14299
|
-
const renderCountRef = useRef2(0);
|
|
14300
|
-
renderCountRef.current += 1;
|
|
14301
|
-
useEffect4(() => {
|
|
14302
|
-
emitAppRenderSpan({
|
|
14303
|
-
renderCount: renderCountRef.current,
|
|
14304
|
-
historyLength: history.length,
|
|
14305
|
-
status
|
|
14306
|
-
});
|
|
14307
|
-
});
|
|
14308
13768
|
return /* @__PURE__ */ jsxDEV6(Box4, {
|
|
14309
13769
|
flexDirection: "column",
|
|
14310
13770
|
minHeight: 20,
|
|
@@ -14338,7 +13798,21 @@ var App = ({
|
|
|
14338
13798
|
label: "Agent is thinking..."
|
|
14339
13799
|
}, undefined, false, undefined, this)
|
|
14340
13800
|
}, undefined, false, undefined, this) : null,
|
|
14341
|
-
status === "streaming" ? /* @__PURE__ */ jsxDEV6(Box4, {
|
|
13801
|
+
status === "streaming" && streamingText ? /* @__PURE__ */ jsxDEV6(Box4, {
|
|
13802
|
+
flexDirection: "column",
|
|
13803
|
+
marginBottom: 1,
|
|
13804
|
+
children: [
|
|
13805
|
+
/* @__PURE__ */ jsxDEV6(RoleLabel, {
|
|
13806
|
+
role: "assistant"
|
|
13807
|
+
}, undefined, false, undefined, this),
|
|
13808
|
+
/* @__PURE__ */ jsxDEV6(Box4, {
|
|
13809
|
+
marginLeft: 2,
|
|
13810
|
+
children: /* @__PURE__ */ jsxDEV6(Markdown, {
|
|
13811
|
+
text: streamingText
|
|
13812
|
+
}, undefined, false, undefined, this)
|
|
13813
|
+
}, undefined, false, undefined, this)
|
|
13814
|
+
]
|
|
13815
|
+
}, undefined, true, undefined, this) : status === "streaming" ? /* @__PURE__ */ jsxDEV6(Box4, {
|
|
14342
13816
|
marginBottom: 1,
|
|
14343
13817
|
children: /* @__PURE__ */ jsxDEV6(Spinner, {
|
|
14344
13818
|
label: "Generating response..."
|
|
@@ -14355,144 +13829,15 @@ var App = ({
|
|
|
14355
13829
|
]
|
|
14356
13830
|
}, undefined, true, undefined, this);
|
|
14357
13831
|
};
|
|
14358
|
-
function areAppPropsEqual(prev, next) {
|
|
14359
|
-
if (prev.status !== next.status)
|
|
14360
|
-
return false;
|
|
14361
|
-
if (prev.model !== next.model)
|
|
14362
|
-
return false;
|
|
14363
|
-
if (prev.workdir !== next.workdir)
|
|
14364
|
-
return false;
|
|
14365
|
-
if (prev.tokenCount !== next.tokenCount)
|
|
14366
|
-
return false;
|
|
14367
|
-
if (prev.history !== next.history)
|
|
14368
|
-
return false;
|
|
14369
|
-
return true;
|
|
14370
|
-
}
|
|
14371
|
-
var parentRenderCountRef = { current: 0 };
|
|
14372
|
-
var AppThrottledImpl = (props) => {
|
|
14373
|
-
parentRenderCountRef.current += 1;
|
|
14374
|
-
emitRenderScheduledSpan(parentRenderCountRef.current);
|
|
14375
|
-
return /* @__PURE__ */ jsxDEV6(App, {
|
|
14376
|
-
...props
|
|
14377
|
-
}, undefined, false, undefined, this);
|
|
14378
|
-
};
|
|
14379
|
-
var AppThrottled = React4.memo(AppThrottledImpl, areAppPropsEqual);
|
|
14380
|
-
AppThrottled.displayName = "App(throttled)";
|
|
14381
|
-
var lastMemoResult = null;
|
|
14382
|
-
var instrumentedAreEqual = (prev, next) => {
|
|
14383
|
-
const equal = areAppPropsEqual(prev, next);
|
|
14384
|
-
if (equal && lastMemoResult !== true) {
|
|
14385
|
-
emitRenderThrottledSpan(parentRenderCountRef.current);
|
|
14386
|
-
}
|
|
14387
|
-
lastMemoResult = equal;
|
|
14388
|
-
return equal;
|
|
14389
|
-
};
|
|
14390
|
-
var AppMemo = React4.memo(AppThrottledImpl, instrumentedAreEqual);
|
|
14391
|
-
AppMemo.displayName = "App(memo-throttled)";
|
|
14392
|
-
// src/tui/StreamingOverlay.tsx
|
|
14393
|
-
init_Markdown();
|
|
14394
|
-
import { useEffect as useEffect5, useRef as useRef3 } from "react";
|
|
14395
|
-
import { Box as Box5, Text as Text7 } from "ink";
|
|
14396
|
-
import { wrapFunction as wrapFunction4 } from "@ai-setting/roy-agent-core";
|
|
14397
|
-
import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
|
|
14398
|
-
var emitOverlayRenderSpanImpl = (snapshot) => {};
|
|
14399
|
-
var emitOverlayRenderSpan = wrapFunction4(emitOverlayRenderSpanImpl, "streaming-overlay.render", {
|
|
14400
|
-
recordParams: true,
|
|
14401
|
-
recordResult: false,
|
|
14402
|
-
log: false,
|
|
14403
|
-
paramFilter: (args) => {
|
|
14404
|
-
const s = args[0] ?? {};
|
|
14405
|
-
return {
|
|
14406
|
-
renderCount: s.renderCount ?? 0,
|
|
14407
|
-
streamingTextLength: s.streamingTextLength ?? 0,
|
|
14408
|
-
status: s.status ?? "unknown"
|
|
14409
|
-
};
|
|
14410
|
-
}
|
|
14411
|
-
});
|
|
14412
|
-
var emitOverlayMarkdownSpanImpl = (snapshot) => {};
|
|
14413
|
-
var emitOverlayMarkdownSpan = wrapFunction4(emitOverlayMarkdownSpanImpl, "streaming-overlay.markdown-render", {
|
|
14414
|
-
recordParams: true,
|
|
14415
|
-
recordResult: false,
|
|
14416
|
-
log: false,
|
|
14417
|
-
paramFilter: (args) => {
|
|
14418
|
-
const s = args[0] ?? {};
|
|
14419
|
-
return {
|
|
14420
|
-
inputLength: s.inputLength ?? 0,
|
|
14421
|
-
renderCount: s.renderCount ?? 0
|
|
14422
|
-
};
|
|
14423
|
-
}
|
|
14424
|
-
});
|
|
14425
|
-
var StreamingOverlay = ({
|
|
14426
|
-
streamingText,
|
|
14427
|
-
status,
|
|
14428
|
-
markdownEnabled: markdownEnabled2,
|
|
14429
|
-
width
|
|
14430
|
-
}) => {
|
|
14431
|
-
const renderCountRef = useRef3(0);
|
|
14432
|
-
renderCountRef.current += 1;
|
|
14433
|
-
useEffect5(() => {
|
|
14434
|
-
emitOverlayRenderSpan({
|
|
14435
|
-
renderCount: renderCountRef.current,
|
|
14436
|
-
streamingTextLength: streamingText.length,
|
|
14437
|
-
status
|
|
14438
|
-
});
|
|
14439
|
-
});
|
|
14440
|
-
if (status === "thinking") {
|
|
14441
|
-
return /* @__PURE__ */ jsxDEV7(Box5, {
|
|
14442
|
-
marginBottom: 1,
|
|
14443
|
-
children: /* @__PURE__ */ jsxDEV7(Text7, {
|
|
14444
|
-
dimColor: true,
|
|
14445
|
-
children: "\uD83E\uDD14 thinking..."
|
|
14446
|
-
}, undefined, false, undefined, this)
|
|
14447
|
-
}, undefined, false, undefined, this);
|
|
14448
|
-
}
|
|
14449
|
-
if (status === "idle") {
|
|
14450
|
-
return null;
|
|
14451
|
-
}
|
|
14452
|
-
if (!streamingText) {
|
|
14453
|
-
return /* @__PURE__ */ jsxDEV7(Box5, {
|
|
14454
|
-
marginBottom: 1,
|
|
14455
|
-
children: /* @__PURE__ */ jsxDEV7(Text7, {
|
|
14456
|
-
dimColor: true,
|
|
14457
|
-
children: "⏳ generating response..."
|
|
14458
|
-
}, undefined, false, undefined, this)
|
|
14459
|
-
}, undefined, false, undefined, this);
|
|
14460
|
-
}
|
|
14461
|
-
const effectiveWidth = width ?? process.stdout.columns ?? 80;
|
|
14462
|
-
emitOverlayMarkdownSpan({
|
|
14463
|
-
inputLength: streamingText.length,
|
|
14464
|
-
renderCount: renderCountRef.current
|
|
14465
|
-
});
|
|
14466
|
-
return /* @__PURE__ */ jsxDEV7(Box5, {
|
|
14467
|
-
flexDirection: "column",
|
|
14468
|
-
marginBottom: 1,
|
|
14469
|
-
children: [
|
|
14470
|
-
/* @__PURE__ */ jsxDEV7(Text7, {
|
|
14471
|
-
bold: true,
|
|
14472
|
-
color: "cyan",
|
|
14473
|
-
children: "\uD83E\uDD16 Agent"
|
|
14474
|
-
}, undefined, false, undefined, this),
|
|
14475
|
-
/* @__PURE__ */ jsxDEV7(Box5, {
|
|
14476
|
-
marginLeft: 2,
|
|
14477
|
-
children: markdownEnabled2 ? /* @__PURE__ */ jsxDEV7(Markdown, {
|
|
14478
|
-
text: streamingText,
|
|
14479
|
-
width: effectiveWidth
|
|
14480
|
-
}, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV7(Text7, {
|
|
14481
|
-
children: streamingText
|
|
14482
|
-
}, undefined, false, undefined, this)
|
|
14483
|
-
}, undefined, false, undefined, this)
|
|
14484
|
-
]
|
|
14485
|
-
}, undefined, true, undefined, this);
|
|
14486
|
-
};
|
|
14487
13832
|
|
|
14488
13833
|
// src/tui/index.ts
|
|
14489
13834
|
init_Markdown();
|
|
14490
13835
|
init_StatusBar();
|
|
14491
13836
|
|
|
14492
13837
|
// src/tui/TextInput.tsx
|
|
14493
|
-
import { useEffect as
|
|
14494
|
-
import { Box as
|
|
14495
|
-
import { jsxDEV as
|
|
13838
|
+
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
13839
|
+
import { Box as Box5, Text as Text7, useInput as useInput3 } from "ink";
|
|
13840
|
+
import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
|
|
14496
13841
|
var TextInput = ({
|
|
14497
13842
|
label,
|
|
14498
13843
|
prefix,
|
|
@@ -14504,7 +13849,7 @@ var TextInput = ({
|
|
|
14504
13849
|
const [value, setValue] = useState4("");
|
|
14505
13850
|
const [historyIndex, setHistoryIndex] = useState4(-1);
|
|
14506
13851
|
const [draft, setDraft] = useState4("");
|
|
14507
|
-
|
|
13852
|
+
useEffect4(() => {
|
|
14508
13853
|
setHistoryIndex(-1);
|
|
14509
13854
|
}, [history.length]);
|
|
14510
13855
|
useInput3((input, key) => {
|
|
@@ -14558,9 +13903,9 @@ var TextInput = ({
|
|
|
14558
13903
|
setValue((v) => v + input);
|
|
14559
13904
|
}
|
|
14560
13905
|
});
|
|
14561
|
-
return /* @__PURE__ */
|
|
13906
|
+
return /* @__PURE__ */ jsxDEV7(Box5, {
|
|
14562
13907
|
children: [
|
|
14563
|
-
/* @__PURE__ */
|
|
13908
|
+
/* @__PURE__ */ jsxDEV7(Text7, {
|
|
14564
13909
|
bold: true,
|
|
14565
13910
|
color: "green",
|
|
14566
13911
|
children: [
|
|
@@ -14568,21 +13913,21 @@ var TextInput = ({
|
|
|
14568
13913
|
" "
|
|
14569
13914
|
]
|
|
14570
13915
|
}, undefined, true, undefined, this),
|
|
14571
|
-
/* @__PURE__ */
|
|
13916
|
+
/* @__PURE__ */ jsxDEV7(Text7, {
|
|
14572
13917
|
bold: true,
|
|
14573
13918
|
children: [
|
|
14574
13919
|
label,
|
|
14575
13920
|
": "
|
|
14576
13921
|
]
|
|
14577
13922
|
}, undefined, true, undefined, this),
|
|
14578
|
-
/* @__PURE__ */
|
|
13923
|
+
/* @__PURE__ */ jsxDEV7(Text7, {
|
|
14579
13924
|
children: value
|
|
14580
13925
|
}, undefined, false, undefined, this),
|
|
14581
|
-
!value && placeholder ? /* @__PURE__ */
|
|
13926
|
+
!value && placeholder ? /* @__PURE__ */ jsxDEV7(Text7, {
|
|
14582
13927
|
dimColor: true,
|
|
14583
13928
|
children: placeholder
|
|
14584
13929
|
}, undefined, false, undefined, this) : null,
|
|
14585
|
-
historyIndex !== -1 ? /* @__PURE__ */
|
|
13930
|
+
historyIndex !== -1 ? /* @__PURE__ */ jsxDEV7(Text7, {
|
|
14586
13931
|
dimColor: true,
|
|
14587
13932
|
children: " (history)"
|
|
14588
13933
|
}, undefined, false, undefined, this) : null
|
|
@@ -14595,98 +13940,36 @@ init_theme();
|
|
|
14595
13940
|
init_welcome_card2();
|
|
14596
13941
|
|
|
14597
13942
|
// src/tui/use-streaming-accumulator.ts
|
|
14598
|
-
import { useCallback as useCallback3,
|
|
14599
|
-
import { wrapFunction as wrapFunction5 } from "@ai-setting/roy-agent-core";
|
|
13943
|
+
import { useCallback as useCallback3, useState as useState5 } from "react";
|
|
14600
13944
|
function useStreamingAccumulator() {
|
|
14601
13945
|
const [status, setStatus] = useState5("idle");
|
|
14602
13946
|
const [streamingText, setStreamingText] = useState5("");
|
|
14603
|
-
const
|
|
14604
|
-
const pendingBufferRef = useRef4("");
|
|
14605
|
-
const flushScheduledRef = useRef4(false);
|
|
14606
|
-
const flushBuffer = useCallback3(() => {
|
|
14607
|
-
flushScheduledRef.current = false;
|
|
14608
|
-
const buf = pendingBufferRef.current;
|
|
14609
|
-
if (buf.length === 0)
|
|
14610
|
-
return;
|
|
14611
|
-
pendingBufferRef.current = "";
|
|
14612
|
-
setStreamingText((prev) => prev + buf);
|
|
14613
|
-
}, []);
|
|
14614
|
-
const lastStatusRef = useRef4("idle");
|
|
14615
|
-
const startImpl = useCallback3(() => {
|
|
13947
|
+
const start = useCallback3(() => {
|
|
14616
13948
|
setStreamingText("");
|
|
14617
13949
|
setStatus("thinking");
|
|
14618
|
-
lastStatusRef.current = "thinking";
|
|
14619
|
-
appendCountRef.current = 0;
|
|
14620
13950
|
}, []);
|
|
14621
|
-
const
|
|
14622
|
-
|
|
14623
|
-
|
|
14624
|
-
|
|
14625
|
-
|
|
14626
|
-
|
|
14627
|
-
if (lastStatusRef.current !== "streaming") {
|
|
14628
|
-
setStatus("streaming");
|
|
14629
|
-
lastStatusRef.current = "streaming";
|
|
14630
|
-
}
|
|
14631
|
-
appendCountRef.current += 1;
|
|
14632
|
-
}, [flushBuffer]);
|
|
14633
|
-
const finishImpl = useCallback3(() => {
|
|
14634
|
-
if (pendingBufferRef.current.length > 0) {
|
|
14635
|
-
flushBuffer();
|
|
14636
|
-
}
|
|
13951
|
+
const append = useCallback3((chunk) => {
|
|
13952
|
+
setStatus("streaming");
|
|
13953
|
+
setStreamingText((prev) => prev + chunk);
|
|
13954
|
+
}, []);
|
|
13955
|
+
const finish = useCallback3(() => {
|
|
13956
|
+
setStatus("idle");
|
|
14637
13957
|
let snapshot = "";
|
|
14638
13958
|
setStreamingText((prev) => {
|
|
14639
13959
|
snapshot = prev;
|
|
14640
13960
|
return "";
|
|
14641
13961
|
});
|
|
14642
|
-
setStatus("idle");
|
|
14643
|
-
lastStatusRef.current = "idle";
|
|
14644
13962
|
return snapshot;
|
|
14645
|
-
}, [
|
|
14646
|
-
const
|
|
14647
|
-
|
|
14648
|
-
flushBuffer();
|
|
14649
|
-
}
|
|
13963
|
+
}, []);
|
|
13964
|
+
const fail = useCallback3((_err) => {
|
|
13965
|
+
setStatus("idle");
|
|
14650
13966
|
let snapshot = "";
|
|
14651
13967
|
setStreamingText((prev) => {
|
|
14652
13968
|
snapshot = prev;
|
|
14653
13969
|
return "";
|
|
14654
13970
|
});
|
|
14655
|
-
setStatus("idle");
|
|
14656
|
-
lastStatusRef.current = "idle";
|
|
14657
13971
|
return snapshot;
|
|
14658
|
-
}, [
|
|
14659
|
-
const start = wrapFunction5(startImpl, "streaming.start", {
|
|
14660
|
-
recordParams: false,
|
|
14661
|
-
recordResult: false,
|
|
14662
|
-
log: true
|
|
14663
|
-
});
|
|
14664
|
-
const append = wrapFunction5(appendImpl, "streaming.append", {
|
|
14665
|
-
recordParams: true,
|
|
14666
|
-
recordResult: false,
|
|
14667
|
-
log: true,
|
|
14668
|
-
paramFilter: (args) => ({
|
|
14669
|
-
"chunk.length": typeof args[0] === "string" ? args[0].length : 0,
|
|
14670
|
-
"chunk.head": typeof args[0] === "string" ? args[0].slice(0, 32) : "",
|
|
14671
|
-
"chunk.tail": typeof args[0] === "string" ? args[0].slice(-32) : ""
|
|
14672
|
-
})
|
|
14673
|
-
});
|
|
14674
|
-
const finish = wrapFunction5(finishImpl, "streaming.finish", {
|
|
14675
|
-
recordParams: false,
|
|
14676
|
-
recordResult: true,
|
|
14677
|
-
log: true,
|
|
14678
|
-
resultFilter: (result) => ({
|
|
14679
|
-
"snapshot.length": typeof result === "string" ? result.length : 0
|
|
14680
|
-
})
|
|
14681
|
-
});
|
|
14682
|
-
const fail = wrapFunction5(failImpl, "streaming.fail", {
|
|
14683
|
-
recordParams: true,
|
|
14684
|
-
recordResult: false,
|
|
14685
|
-
log: true,
|
|
14686
|
-
paramFilter: (args) => ({
|
|
14687
|
-
"err.message": args[0] instanceof Error ? args[0].message : String(args[0])
|
|
14688
|
-
})
|
|
14689
|
-
});
|
|
13972
|
+
}, []);
|
|
14690
13973
|
return { status, streamingText, start, append, finish, fail };
|
|
14691
13974
|
}
|
|
14692
13975
|
|
|
@@ -14766,8 +14049,7 @@ function dispatchSlashCommand(raw, ctx) {
|
|
|
14766
14049
|
}
|
|
14767
14050
|
|
|
14768
14051
|
// src/RunTui.tsx
|
|
14769
|
-
import {
|
|
14770
|
-
import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
|
|
14052
|
+
import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
|
|
14771
14053
|
var RunScreen = ({
|
|
14772
14054
|
handleQuery,
|
|
14773
14055
|
streamHandleQuery,
|
|
@@ -14785,17 +14067,17 @@ var RunScreen = ({
|
|
|
14785
14067
|
const stream = useStreamingAccumulator();
|
|
14786
14068
|
const status = stream.status;
|
|
14787
14069
|
const { exit } = useApp2();
|
|
14788
|
-
const userTurnCountRef =
|
|
14789
|
-
const assistantTurnCountRef =
|
|
14790
|
-
const isProcessingRef =
|
|
14791
|
-
const executeQueryRef =
|
|
14792
|
-
const historyIdRef =
|
|
14070
|
+
const userTurnCountRef = useRef2(0);
|
|
14071
|
+
const assistantTurnCountRef = useRef2(0);
|
|
14072
|
+
const isProcessingRef = useRef2(0);
|
|
14073
|
+
const executeQueryRef = useRef2(null);
|
|
14074
|
+
const historyIdRef = useRef2(0);
|
|
14793
14075
|
const width = process.stdout.columns ?? 80;
|
|
14794
14076
|
const doExit = useCallback4(() => {
|
|
14795
14077
|
onExit?.();
|
|
14796
14078
|
exit();
|
|
14797
14079
|
}, [onExit, exit]);
|
|
14798
|
-
const
|
|
14080
|
+
const executeQuery = useCallback4(async (message) => {
|
|
14799
14081
|
isProcessingRef.current += 1;
|
|
14800
14082
|
stream.start();
|
|
14801
14083
|
try {
|
|
@@ -14827,24 +14109,13 @@ var RunScreen = ({
|
|
|
14827
14109
|
isProcessingRef.current -= 1;
|
|
14828
14110
|
}
|
|
14829
14111
|
}, [handleQuery, markdownEnabled2, maxLines, stream, streamHandleQuery, width]);
|
|
14830
|
-
|
|
14831
|
-
recordParams: true,
|
|
14832
|
-
recordResult: false,
|
|
14833
|
-
log: true,
|
|
14834
|
-
paramFilter: (args) => ({
|
|
14835
|
-
"message.length": typeof args[0] === "string" ? args[0].length : 0,
|
|
14836
|
-
"message.head": typeof args[0] === "string" ? args[0].slice(0, 60) : "",
|
|
14837
|
-
"isProcessingRef.before": (isProcessingRef.current ?? 0) + 1,
|
|
14838
|
-
streaming: !!streamHandleQuery
|
|
14839
|
-
})
|
|
14840
|
-
}), [executeQueryImpl, streamHandleQuery]);
|
|
14841
|
-
useEffect7(() => {
|
|
14112
|
+
useEffect5(() => {
|
|
14842
14113
|
executeQueryRef.current = executeQuery;
|
|
14843
14114
|
}, [executeQuery]);
|
|
14844
|
-
|
|
14115
|
+
useEffect5(() => {
|
|
14845
14116
|
if (!onRegisterHandlers)
|
|
14846
14117
|
return;
|
|
14847
|
-
const
|
|
14118
|
+
const handleNotification = async (message, _envEvent) => {
|
|
14848
14119
|
const notifId = `h${++historyIdRef.current}`;
|
|
14849
14120
|
setHistory((h) => [
|
|
14850
14121
|
...h,
|
|
@@ -14854,31 +14125,10 @@ var RunScreen = ({
|
|
|
14854
14125
|
await executeQueryRef.current(message);
|
|
14855
14126
|
}
|
|
14856
14127
|
};
|
|
14857
|
-
const handleNotification = wrapFunction6(handleNotificationImpl, "tui.run-tui.handleNotification", {
|
|
14858
|
-
recordParams: true,
|
|
14859
|
-
recordResult: false,
|
|
14860
|
-
log: true,
|
|
14861
|
-
paramFilter: (args) => ({
|
|
14862
|
-
"message.length": typeof args[0] === "string" ? args[0].length : 0,
|
|
14863
|
-
"message.head": typeof args[0] === "string" ? args[0].slice(0, 60) : "",
|
|
14864
|
-
isProcessingRef: isProcessingRef.current ?? 0
|
|
14865
|
-
})
|
|
14866
|
-
});
|
|
14867
14128
|
const isIdle = () => {
|
|
14868
14129
|
return isProcessingRef.current === 0;
|
|
14869
14130
|
};
|
|
14870
|
-
|
|
14871
|
-
const traceIdItemId = `h${++historyIdRef.current}`;
|
|
14872
|
-
setHistory((h) => [
|
|
14873
|
-
...h,
|
|
14874
|
-
{ role: "tool", content: `\uD83D\uDD0D [Trace] ${traceId}`, id: traceIdItemId }
|
|
14875
|
-
]);
|
|
14876
|
-
};
|
|
14877
|
-
onRegisterHandlers({
|
|
14878
|
-
onNotification: handleNotification,
|
|
14879
|
-
isIdle,
|
|
14880
|
-
appendTraceId
|
|
14881
|
-
});
|
|
14131
|
+
onRegisterHandlers({ onNotification: handleNotification, isIdle });
|
|
14882
14132
|
}, [onRegisterHandlers]);
|
|
14883
14133
|
const handleSubmit = useCallback4(async (raw) => {
|
|
14884
14134
|
const trimmed = raw.trim();
|
|
@@ -14966,24 +14216,19 @@ var RunScreen = ({
|
|
|
14966
14216
|
const handleCancel = useCallback4(() => {
|
|
14967
14217
|
doExit();
|
|
14968
14218
|
}, [doExit]);
|
|
14969
|
-
return /* @__PURE__ */
|
|
14219
|
+
return /* @__PURE__ */ jsxDEV8(Box6, {
|
|
14970
14220
|
flexDirection: "column",
|
|
14971
14221
|
children: [
|
|
14972
|
-
/* @__PURE__ */
|
|
14222
|
+
/* @__PURE__ */ jsxDEV8(App, {
|
|
14973
14223
|
history,
|
|
14974
14224
|
status,
|
|
14975
14225
|
model,
|
|
14976
|
-
workdir
|
|
14226
|
+
workdir,
|
|
14227
|
+
streamingText: stream.streamingText
|
|
14977
14228
|
}, undefined, false, undefined, this),
|
|
14978
|
-
status
|
|
14979
|
-
streamingText: stream.streamingText,
|
|
14980
|
-
status,
|
|
14981
|
-
markdownEnabled: markdownEnabled2,
|
|
14982
|
-
width
|
|
14983
|
-
}, undefined, false, undefined, this) : null,
|
|
14984
|
-
status === "idle" ? /* @__PURE__ */ jsxDEV9(Box7, {
|
|
14229
|
+
status === "idle" ? /* @__PURE__ */ jsxDEV8(Box6, {
|
|
14985
14230
|
marginTop: 1,
|
|
14986
|
-
children: /* @__PURE__ */
|
|
14231
|
+
children: /* @__PURE__ */ jsxDEV8(TextInput, {
|
|
14987
14232
|
label: "You",
|
|
14988
14233
|
prefix: "\uD83D\uDC64",
|
|
14989
14234
|
placeholder: 'Type a message, "/help", or "exit"',
|
|
@@ -14992,9 +14237,9 @@ var RunScreen = ({
|
|
|
14992
14237
|
history: userHistory
|
|
14993
14238
|
}, undefined, false, undefined, this)
|
|
14994
14239
|
}, undefined, false, undefined, this) : null,
|
|
14995
|
-
errorMessage ? /* @__PURE__ */
|
|
14240
|
+
errorMessage ? /* @__PURE__ */ jsxDEV8(Box6, {
|
|
14996
14241
|
marginTop: 1,
|
|
14997
|
-
children: /* @__PURE__ */
|
|
14242
|
+
children: /* @__PURE__ */ jsxDEV8(Text8, {
|
|
14998
14243
|
color: "red",
|
|
14999
14244
|
children: [
|
|
15000
14245
|
"⚠ ",
|
|
@@ -15092,11 +14337,7 @@ async function shutdownRunSteps(deps) {
|
|
|
15092
14337
|
}
|
|
15093
14338
|
|
|
15094
14339
|
// src/commands/run.ts
|
|
15095
|
-
|
|
15096
|
-
wrapFunction as wrapFunction7,
|
|
15097
|
-
getTracerProvider as getTracerProvider4
|
|
15098
|
-
} from "@ai-setting/roy-agent-core";
|
|
15099
|
-
async function loadHandleQueryImpl(options, hooks) {
|
|
14340
|
+
async function loadHandleQuery(options, hooks) {
|
|
15100
14341
|
const quiet = CliQuietModeService.getInstance().isQuiet();
|
|
15101
14342
|
const output = new OutputService2;
|
|
15102
14343
|
output.configure({ quiet });
|
|
@@ -15161,7 +14402,7 @@ async function loadHandleQueryImpl(options, hooks) {
|
|
|
15161
14402
|
}
|
|
15162
14403
|
const llmComponent = envService.getLLM();
|
|
15163
14404
|
queryExecutor.initStreamOutput(llmComponent ?? null);
|
|
15164
|
-
const
|
|
14405
|
+
const handleQuery = async (message) => {
|
|
15165
14406
|
const mergedContext = {
|
|
15166
14407
|
...agentContext,
|
|
15167
14408
|
model: options.model,
|
|
@@ -15178,14 +14419,6 @@ async function loadHandleQueryImpl(options, hooks) {
|
|
|
15178
14419
|
}, undefined, mergedContext);
|
|
15179
14420
|
return String(result ?? "");
|
|
15180
14421
|
};
|
|
15181
|
-
const handleQuery = wrapFunction7(handleQueryImpl, "cli.run.handleQuery", {
|
|
15182
|
-
recordParams: true,
|
|
15183
|
-
recordResult: false,
|
|
15184
|
-
log: true,
|
|
15185
|
-
paramFilter: (args) => ({
|
|
15186
|
-
"message.length": typeof args[0] === "string" ? args[0].length : 0
|
|
15187
|
-
})
|
|
15188
|
-
});
|
|
15189
14422
|
const taskEventHandler = new TaskEventHandler({
|
|
15190
14423
|
env,
|
|
15191
14424
|
enabled: true
|
|
@@ -15217,80 +14450,17 @@ async function loadHandleQueryImpl(options, hooks) {
|
|
|
15217
14450
|
sessionManager
|
|
15218
14451
|
};
|
|
15219
14452
|
}
|
|
15220
|
-
|
|
15221
|
-
|
|
15222
|
-
|
|
15223
|
-
log: true,
|
|
15224
|
-
paramFilter: (args) => {
|
|
15225
|
-
const opts = args[0] ?? {};
|
|
15226
|
-
return {
|
|
15227
|
-
"options.model": opts.model ?? "",
|
|
15228
|
-
"options.workdir": opts.workdir ?? "",
|
|
15229
|
-
"options.session": opts.session ?? "",
|
|
15230
|
-
"options.eventSource": Array.isArray(opts.eventSource) ? opts.eventSource.join(",") : opts.eventSource ?? "",
|
|
15231
|
-
"has.onNotification": !!args[1]?.onNotification
|
|
15232
|
-
};
|
|
15233
|
-
}
|
|
15234
|
-
});
|
|
15235
|
-
function createStreamHandleQuery(queryExecutor, sessionId, options, agentContext, eventSourceSystemPrompt, onTraceId) {
|
|
15236
|
-
const innerStreamHandler = async (message, onChunk) => {
|
|
15237
|
-
const onChunkInstrumented = wrapFunction7((chunk) => {
|
|
15238
|
-
onChunk(chunk);
|
|
15239
|
-
}, "cli.run.chunkCallbackImpl.onChunk-called", {
|
|
15240
|
-
recordParams: true,
|
|
15241
|
-
recordResult: false,
|
|
15242
|
-
log: false,
|
|
15243
|
-
paramFilter: (args) => ({
|
|
15244
|
-
"chunk.length": typeof args[0] === "string" ? args[0].length : 0,
|
|
15245
|
-
"chunk.head": typeof args[0] === "string" ? args[0].slice(0, 32) : ""
|
|
15246
|
-
})
|
|
15247
|
-
});
|
|
15248
|
-
const chunkCallbackImpl = (event) => {
|
|
14453
|
+
function createStreamHandleQuery(queryExecutor, sessionId, options, agentContext, eventSourceSystemPrompt) {
|
|
14454
|
+
return async (message, onChunk) => {
|
|
14455
|
+
queryExecutor.setChunkCallback((event) => {
|
|
15249
14456
|
if (event.type === "llm.text") {
|
|
15250
14457
|
if (event.delta) {
|
|
15251
|
-
|
|
14458
|
+
onChunk(event.delta);
|
|
15252
14459
|
} else if (event.content) {
|
|
15253
|
-
|
|
14460
|
+
onChunk(event.content);
|
|
15254
14461
|
}
|
|
15255
|
-
return;
|
|
15256
|
-
}
|
|
15257
|
-
if (event.type === "tool.call") {
|
|
15258
|
-
const toolName = event.toolName || "unknown";
|
|
15259
|
-
const toolId = event.toolId || "";
|
|
15260
|
-
onChunkInstrumented(`
|
|
15261
|
-
\uD83D\uDD27 tool: ${toolName} (${toolId})
|
|
15262
|
-
`);
|
|
15263
|
-
return;
|
|
15264
14462
|
}
|
|
15265
|
-
|
|
15266
|
-
onChunkInstrumented(`
|
|
15267
|
-
✓ done
|
|
15268
|
-
`);
|
|
15269
|
-
return;
|
|
15270
|
-
}
|
|
15271
|
-
if (event.type === "tool.error") {
|
|
15272
|
-
const msg = event.toolError || "error";
|
|
15273
|
-
onChunkInstrumented(`
|
|
15274
|
-
✗ ${msg}
|
|
15275
|
-
`);
|
|
15276
|
-
return;
|
|
15277
|
-
}
|
|
15278
|
-
};
|
|
15279
|
-
queryExecutor.setChunkCallback(wrapFunction7(chunkCallbackImpl, "cli.run.chunkCallback", {
|
|
15280
|
-
recordParams: true,
|
|
15281
|
-
recordResult: false,
|
|
15282
|
-
log: true,
|
|
15283
|
-
paramFilter: (args) => {
|
|
15284
|
-
const e = args[0] ?? {};
|
|
15285
|
-
return {
|
|
15286
|
-
"event.type": e.type ?? "unknown",
|
|
15287
|
-
"event.delta.length": typeof e.delta === "string" ? e.delta.length : 0,
|
|
15288
|
-
"event.content.length": typeof e.content === "string" ? e.content.length : 0,
|
|
15289
|
-
"event.toolName": e.toolName ?? "",
|
|
15290
|
-
"event.toolId": e.toolId ?? ""
|
|
15291
|
-
};
|
|
15292
|
-
}
|
|
15293
|
-
}));
|
|
14463
|
+
});
|
|
15294
14464
|
const mergedContext = {
|
|
15295
14465
|
...agentContext,
|
|
15296
14466
|
model: options.model,
|
|
@@ -15300,37 +14470,13 @@ function createStreamHandleQuery(queryExecutor, sessionId, options, agentContext
|
|
|
15300
14470
|
defaultAgentName: options.defaultAgentName
|
|
15301
14471
|
}
|
|
15302
14472
|
};
|
|
15303
|
-
const
|
|
15304
|
-
|
|
15305
|
-
|
|
15306
|
-
|
|
15307
|
-
|
|
15308
|
-
showReasoning: options.reasoning ?? true,
|
|
15309
|
-
showToolCalls: options.toolCalls ?? true,
|
|
15310
|
-
showToolResults: options.toolResults ?? false
|
|
15311
|
-
}, undefined, mergedContext);
|
|
15312
|
-
turnSpan.end(result);
|
|
15313
|
-
} catch (error) {
|
|
15314
|
-
turnSpan.setAttribute("error", String(error));
|
|
15315
|
-
turnSpan.end(undefined, error instanceof Error ? error : new Error(String(error)));
|
|
15316
|
-
throw error;
|
|
15317
|
-
} finally {
|
|
15318
|
-
try {
|
|
15319
|
-
onTraceId?.(turnTraceId);
|
|
15320
|
-
} catch (cbErr) {
|
|
15321
|
-
console.warn(`[Trace] sink failed: ${cbErr instanceof Error ? cbErr.message : String(cbErr)}`);
|
|
15322
|
-
}
|
|
15323
|
-
}
|
|
14473
|
+
const result = await queryExecutor.execute(message, sessionId, {
|
|
14474
|
+
showReasoning: options.reasoning ?? true,
|
|
14475
|
+
showToolCalls: options.toolCalls ?? true,
|
|
14476
|
+
showToolResults: options.toolResults ?? false
|
|
14477
|
+
}, undefined, mergedContext);
|
|
15324
14478
|
return String(result ?? "");
|
|
15325
14479
|
};
|
|
15326
|
-
return wrapFunction7(innerStreamHandler, "cli.run.createStreamHandleQuery", {
|
|
15327
|
-
recordParams: true,
|
|
15328
|
-
recordResult: false,
|
|
15329
|
-
log: true,
|
|
15330
|
-
paramFilter: (args) => ({
|
|
15331
|
-
"message.length": typeof args[0] === "string" ? args[0].length : 0
|
|
15332
|
-
})
|
|
15333
|
-
});
|
|
15334
14480
|
}
|
|
15335
14481
|
function createRunCommand() {
|
|
15336
14482
|
return {
|
|
@@ -15403,10 +14549,6 @@ function createRunCommand() {
|
|
|
15403
14549
|
type: "string",
|
|
15404
14550
|
describe: "Default agent 名字(默认 Roy,可被覆盖)",
|
|
15405
14551
|
default: "Roy"
|
|
15406
|
-
}).option("debug-on", {
|
|
15407
|
-
type: "boolean",
|
|
15408
|
-
describe: "调试模式:每次 turn 结束后输出 [Trace] <traceId>(stderr),便于追踪调用 trace",
|
|
15409
|
-
default: false
|
|
15410
14552
|
}),
|
|
15411
14553
|
handler: async (argv) => {
|
|
15412
14554
|
if (argv.markdown === false) {
|
|
@@ -15448,17 +14590,10 @@ function createRunCommand() {
|
|
|
15448
14590
|
logger: undefined
|
|
15449
14591
|
});
|
|
15450
14592
|
});
|
|
15451
|
-
const
|
|
15452
|
-
let appendTraceIdTui;
|
|
15453
|
-
const streamHandleQuery = createStreamHandleQuery(queryExecutor, sessionId, argv, agentContext, eventSourceSystemPrompt, (traceId) => {
|
|
15454
|
-
printTraceIdAfterResponse(traceId, {
|
|
15455
|
-
enabled: debugOn,
|
|
15456
|
-
tuiSink: appendTraceIdTui
|
|
15457
|
-
});
|
|
15458
|
-
});
|
|
14593
|
+
const streamHandleQuery = createStreamHandleQuery(queryExecutor, sessionId, argv, agentContext, eventSourceSystemPrompt);
|
|
15459
14594
|
const stopEventHandler = eventHandler.start();
|
|
15460
14595
|
const stopTaskEventHandler = taskEventHandler.start();
|
|
15461
|
-
const { waitUntilExit } = render(
|
|
14596
|
+
const { waitUntilExit } = render(React6.createElement(RunTui_default, {
|
|
15462
14597
|
handleQuery,
|
|
15463
14598
|
streamHandleQuery,
|
|
15464
14599
|
model: argv.model,
|
|
@@ -15468,7 +14603,6 @@ function createRunCommand() {
|
|
|
15468
14603
|
onRegisterHandlers: (handlers) => {
|
|
15469
14604
|
runState.onNotification = handlers.onNotification;
|
|
15470
14605
|
runState.isIdle = handlers.isIdle;
|
|
15471
|
-
appendTraceIdTui = handlers.appendTraceId;
|
|
15472
14606
|
},
|
|
15473
14607
|
onExit: () => {}
|
|
15474
14608
|
}), { exitOnCtrlC: true });
|
|
@@ -15496,14 +14630,14 @@ function createRunCommand() {
|
|
|
15496
14630
|
var RunCommand = createRunCommand();
|
|
15497
14631
|
|
|
15498
14632
|
// src/commands/chat.ts
|
|
15499
|
-
import
|
|
14633
|
+
import React8 from "react";
|
|
15500
14634
|
import { render as render2 } from "ink";
|
|
15501
14635
|
|
|
15502
14636
|
// src/ChatTui.tsx
|
|
15503
|
-
import { useEffect as
|
|
15504
|
-
import { Box as
|
|
14637
|
+
import { useEffect as useEffect6, useRef as useRef3, useState as useState7 } from "react";
|
|
14638
|
+
import { Box as Box7, useApp as useApp3 } from "ink";
|
|
15505
14639
|
init_markdown();
|
|
15506
|
-
import { jsxDEV as
|
|
14640
|
+
import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
|
|
15507
14641
|
var ChatScreen = ({
|
|
15508
14642
|
handleQuery,
|
|
15509
14643
|
streamHandleQuery,
|
|
@@ -15516,11 +14650,11 @@ var ChatScreen = ({
|
|
|
15516
14650
|
const [history, setHistory] = useState7([
|
|
15517
14651
|
{ role: "user", content: message, id: "h-init-1" }
|
|
15518
14652
|
]);
|
|
15519
|
-
const historyIdRef =
|
|
14653
|
+
const historyIdRef = useRef3(1);
|
|
15520
14654
|
const stream = useStreamingAccumulator();
|
|
15521
14655
|
const { exit } = useApp3();
|
|
15522
14656
|
const width = process.stdout.columns ?? 80;
|
|
15523
|
-
|
|
14657
|
+
useEffect6(() => {
|
|
15524
14658
|
let cancelled = false;
|
|
15525
14659
|
stream.start();
|
|
15526
14660
|
(async () => {
|
|
@@ -15559,23 +14693,16 @@ var ChatScreen = ({
|
|
|
15559
14693
|
cancelled = true;
|
|
15560
14694
|
};
|
|
15561
14695
|
}, [handleQuery, streamHandleQuery, message, maxLines, markdownEnabled2, exit, width, stream]);
|
|
15562
|
-
return /* @__PURE__ */
|
|
14696
|
+
return /* @__PURE__ */ jsxDEV9(Box7, {
|
|
15563
14697
|
flexDirection: "column",
|
|
15564
|
-
children:
|
|
15565
|
-
|
|
15566
|
-
|
|
15567
|
-
|
|
15568
|
-
|
|
15569
|
-
|
|
15570
|
-
|
|
15571
|
-
|
|
15572
|
-
streamingText: stream.streamingText,
|
|
15573
|
-
status: stream.status,
|
|
15574
|
-
markdownEnabled: markdownEnabled2,
|
|
15575
|
-
width
|
|
15576
|
-
}, undefined, false, undefined, this) : null
|
|
15577
|
-
]
|
|
15578
|
-
}, undefined, true, undefined, this);
|
|
14698
|
+
children: /* @__PURE__ */ jsxDEV9(App, {
|
|
14699
|
+
history,
|
|
14700
|
+
status: stream.status,
|
|
14701
|
+
model,
|
|
14702
|
+
workdir,
|
|
14703
|
+
streamingText: stream.streamingText
|
|
14704
|
+
}, undefined, false, undefined, this)
|
|
14705
|
+
}, undefined, false, undefined, this);
|
|
15579
14706
|
};
|
|
15580
14707
|
var ChatTui_default = ChatScreen;
|
|
15581
14708
|
|
|
@@ -15654,7 +14781,7 @@ function createChatCommand() {
|
|
|
15654
14781
|
}
|
|
15655
14782
|
const maxLines = Number.parseInt(argv.maxLines ?? "500", 10);
|
|
15656
14783
|
const handleQuery = await loadHandleQuery2(argv);
|
|
15657
|
-
const { waitUntilExit } = render2(
|
|
14784
|
+
const { waitUntilExit } = render2(React8.createElement(ChatTui_default, {
|
|
15658
14785
|
handleQuery,
|
|
15659
14786
|
message: argv.message,
|
|
15660
14787
|
model: argv.model,
|
|
@@ -25025,9 +24152,9 @@ import chalk73 from "chalk";
|
|
|
25025
24152
|
import fs5 from "fs";
|
|
25026
24153
|
import path8 from "path";
|
|
25027
24154
|
import { createRunWorkflowTool } from "@ai-setting/roy-agent-core/env/workflow/tools";
|
|
25028
|
-
import { getTracerProvider as
|
|
24155
|
+
import { getTracerProvider as getTracerProvider4, propagation, wrapFunction } from "@ai-setting/roy-agent-core";
|
|
25029
24156
|
import { isValidSessionId } from "@ai-setting/roy-agent-core/env/session";
|
|
25030
|
-
var runWorkflow =
|
|
24157
|
+
var runWorkflow = wrapFunction(async function runWorkflowImpl(args) {
|
|
25031
24158
|
const output = new OutputService2;
|
|
25032
24159
|
const envService = new EnvironmentService(output);
|
|
25033
24160
|
const traceparent = process.env.TRACEPARENT;
|
|
@@ -25047,7 +24174,7 @@ var runWorkflow = wrapFunction8(async function runWorkflowImpl(args) {
|
|
|
25047
24174
|
output.info(`[OTel Trace] TRACEPARENT=${traceparent || "none"}, traceId=${traceId}, parentSpanId=${parentSpanId}`);
|
|
25048
24175
|
let workflowSpan = undefined;
|
|
25049
24176
|
try {
|
|
25050
|
-
const provider =
|
|
24177
|
+
const provider = getTracerProvider4();
|
|
25051
24178
|
await provider.initialize();
|
|
25052
24179
|
const tracer = provider.getTracer("roy-tracer");
|
|
25053
24180
|
const restoredContext = tracer.getCurrentContext();
|
|
@@ -25304,8 +24431,8 @@ var WorkflowRunCommand = {
|
|
|
25304
24431
|
// src/commands/workflow/commands/stop.ts
|
|
25305
24432
|
import chalk74 from "chalk";
|
|
25306
24433
|
import { createWorkflowRunStopTool } from "@ai-setting/roy-agent-core/env/workflow/tools";
|
|
25307
|
-
import { wrapFunction as
|
|
25308
|
-
var stopWorkflow =
|
|
24434
|
+
import { wrapFunction as wrapFunction2 } from "@ai-setting/roy-agent-core";
|
|
24435
|
+
var stopWorkflow = wrapFunction2(async function stopWorkflowImpl(args) {
|
|
25309
24436
|
const output = new OutputService2;
|
|
25310
24437
|
const envService = new EnvironmentService(output);
|
|
25311
24438
|
try {
|
|
@@ -25960,7 +25087,7 @@ Error: ${error.message}`));
|
|
|
25960
25087
|
|
|
25961
25088
|
// src/commands/workflow/commands/search.ts
|
|
25962
25089
|
import chalk78 from "chalk";
|
|
25963
|
-
import { wrapFunction as
|
|
25090
|
+
import { wrapFunction as wrapFunction3 } from "@ai-setting/roy-agent-core";
|
|
25964
25091
|
var WorkflowSearchCommand = {
|
|
25965
25092
|
command: "search",
|
|
25966
25093
|
describe: "Search workflows by keyword and/or tags (multiple tags use AND filter). v2: returns available_tags.",
|
|
@@ -26135,14 +25262,14 @@ var _runWorkflowSearchImpl = async function(opts) {
|
|
|
26135
25262
|
}
|
|
26136
25263
|
}
|
|
26137
25264
|
};
|
|
26138
|
-
var runWorkflowSearch =
|
|
25265
|
+
var runWorkflowSearch = wrapFunction3(_runWorkflowSearchImpl, "workflow.cli.search", {
|
|
26139
25266
|
recordParams: true,
|
|
26140
25267
|
recordResult: false,
|
|
26141
25268
|
log: false
|
|
26142
25269
|
});
|
|
26143
25270
|
|
|
26144
25271
|
// src/commands/workflow/commands/tag.ts
|
|
26145
|
-
import { wrapFunction as
|
|
25272
|
+
import { wrapFunction as wrapFunction4 } from "@ai-setting/roy-agent-core";
|
|
26146
25273
|
import chalk79 from "chalk";
|
|
26147
25274
|
var WorkflowTagListCommand = {
|
|
26148
25275
|
command: "list",
|
|
@@ -26342,12 +25469,12 @@ function formatDate2(iso) {
|
|
|
26342
25469
|
return iso;
|
|
26343
25470
|
}
|
|
26344
25471
|
}
|
|
26345
|
-
var runWorkflowTagList =
|
|
25472
|
+
var runWorkflowTagList = wrapFunction4(_runWorkflowTagListImpl, "workflow.cli.tag.list", {
|
|
26346
25473
|
recordParams: true,
|
|
26347
25474
|
recordResult: false,
|
|
26348
25475
|
log: false
|
|
26349
25476
|
});
|
|
26350
|
-
var runWorkflowTagGet =
|
|
25477
|
+
var runWorkflowTagGet = wrapFunction4(_runWorkflowTagGetImpl, "workflow.cli.tag.get", {
|
|
26351
25478
|
recordParams: true,
|
|
26352
25479
|
recordResult: false,
|
|
26353
25480
|
log: false
|