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