@qwen-code/qwen-code 0.15.11-preview.1 → 0.15.11
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/bundled/qc-helper/docs/configuration/settings.md +4 -4
- package/cli.js +694 -346
- package/package.json +2 -2
package/cli.js
CHANGED
|
@@ -21650,7 +21650,7 @@ var init_atomicFileWrite = __esm({
|
|
|
21650
21650
|
});
|
|
21651
21651
|
|
|
21652
21652
|
// packages/core/src/telemetry/constants.ts
|
|
21653
|
-
var SERVICE_NAME, EVENT_USER_PROMPT, EVENT_USER_RETRY, EVENT_TOOL_CALL, EVENT_API_REQUEST, EVENT_API_ERROR, EVENT_API_CANCEL, EVENT_API_RESPONSE, EVENT_CLI_CONFIG, EVENT_EXTENSION_DISABLE, EVENT_EXTENSION_ENABLE, EVENT_EXTENSION_INSTALL, EVENT_EXTENSION_UNINSTALL, EVENT_EXTENSION_UPDATE, EVENT_FLASH_FALLBACK, EVENT_RIPGREP_FALLBACK, EVENT_NEXT_SPEAKER_CHECK, EVENT_SLASH_COMMAND, EVENT_IDE_CONNECTION, EVENT_CHAT_COMPRESSION, EVENT_CONTENT_RETRY, EVENT_CONTENT_RETRY_FAILURE, EVENT_CONVERSATION_FINISHED, EVENT_FILE_OPERATION, EVENT_MODEL_SLASH_COMMAND, EVENT_SUBAGENT_EXECUTION, EVENT_SKILL_LAUNCH, EVENT_AUTH, EVENT_USER_FEEDBACK, EVENT_PROMPT_SUGGESTION, EVENT_SPECULATION, EVENT_ARENA_SESSION_STARTED, EVENT_ARENA_AGENT_COMPLETED, EVENT_ARENA_SESSION_ENDED, EVENT_MEMORY_EXTRACT, EVENT_MEMORY_DREAM, EVENT_MEMORY_RECALL;
|
|
21653
|
+
var SERVICE_NAME, EVENT_USER_PROMPT, EVENT_USER_RETRY, EVENT_TOOL_CALL, EVENT_API_REQUEST, EVENT_API_ERROR, EVENT_API_CANCEL, EVENT_API_RESPONSE, EVENT_CLI_CONFIG, EVENT_EXTENSION_DISABLE, EVENT_EXTENSION_ENABLE, EVENT_EXTENSION_INSTALL, EVENT_EXTENSION_UNINSTALL, EVENT_EXTENSION_UPDATE, EVENT_FLASH_FALLBACK, EVENT_RIPGREP_FALLBACK, EVENT_NEXT_SPEAKER_CHECK, EVENT_SLASH_COMMAND, EVENT_IDE_CONNECTION, EVENT_CHAT_COMPRESSION, EVENT_CONTENT_RETRY, EVENT_CONTENT_RETRY_FAILURE, EVENT_CONVERSATION_FINISHED, EVENT_FILE_OPERATION, EVENT_MODEL_SLASH_COMMAND, EVENT_SUBAGENT_EXECUTION, EVENT_SKILL_LAUNCH, EVENT_AUTH, EVENT_USER_FEEDBACK, EVENT_PROMPT_SUGGESTION, EVENT_SPECULATION, EVENT_ARENA_SESSION_STARTED, EVENT_ARENA_AGENT_COMPLETED, EVENT_ARENA_SESSION_ENDED, EVENT_MEMORY_EXTRACT, EVENT_MEMORY_DREAM, EVENT_MEMORY_RECALL, SPAN_INTERACTION, SPAN_LLM_REQUEST, SPAN_TOOL, SPAN_TOOL_EXECUTION;
|
|
21654
21654
|
var init_constants = __esm({
|
|
21655
21655
|
"packages/core/src/telemetry/constants.ts"() {
|
|
21656
21656
|
"use strict";
|
|
@@ -21692,6 +21692,10 @@ var init_constants = __esm({
|
|
|
21692
21692
|
EVENT_MEMORY_EXTRACT = "qwen-code.memory.extract";
|
|
21693
21693
|
EVENT_MEMORY_DREAM = "qwen-code.memory.dream";
|
|
21694
21694
|
EVENT_MEMORY_RECALL = "qwen-code.memory.recall";
|
|
21695
|
+
SPAN_INTERACTION = "qwen-code.interaction";
|
|
21696
|
+
SPAN_LLM_REQUEST = "qwen-code.llm_request";
|
|
21697
|
+
SPAN_TOOL = "qwen-code.tool";
|
|
21698
|
+
SPAN_TOOL_EXECUTION = "qwen-code.tool.execution";
|
|
21695
21699
|
}
|
|
21696
21700
|
});
|
|
21697
21701
|
|
|
@@ -139636,14 +139640,14 @@ var require_B3MultiPropagator = __commonJS({
|
|
|
139636
139640
|
return "";
|
|
139637
139641
|
}
|
|
139638
139642
|
__name(getTraceId, "getTraceId");
|
|
139639
|
-
function
|
|
139643
|
+
function getSpanId2(carrier, getter) {
|
|
139640
139644
|
const spanId = getHeaderValue2(carrier, getter, constants_1.X_B3_SPAN_ID);
|
|
139641
139645
|
if (typeof spanId === "string") {
|
|
139642
139646
|
return spanId;
|
|
139643
139647
|
}
|
|
139644
139648
|
return "";
|
|
139645
139649
|
}
|
|
139646
|
-
__name(
|
|
139650
|
+
__name(getSpanId2, "getSpanId");
|
|
139647
139651
|
function getDebug(carrier, getter) {
|
|
139648
139652
|
const debug3 = getHeaderValue2(carrier, getter, constants_1.X_B3_FLAGS);
|
|
139649
139653
|
return debug3 === "1" ? "1" : void 0;
|
|
@@ -139680,7 +139684,7 @@ var require_B3MultiPropagator = __commonJS({
|
|
|
139680
139684
|
}
|
|
139681
139685
|
extract(context2, carrier, getter) {
|
|
139682
139686
|
const traceId = getTraceId(carrier, getter);
|
|
139683
|
-
const spanId =
|
|
139687
|
+
const spanId = getSpanId2(carrier, getter);
|
|
139684
139688
|
const traceFlags = getTraceFlags(carrier, getter);
|
|
139685
139689
|
const debug3 = getDebug(carrier, getter);
|
|
139686
139690
|
if ((0, api_1.isValidTraceId)(traceId) && (0, api_1.isValidSpanId)(spanId) && isValidSampledValue(traceFlags)) {
|
|
@@ -142436,6 +142440,283 @@ var init_tracer = __esm({
|
|
|
142436
142440
|
}
|
|
142437
142441
|
});
|
|
142438
142442
|
|
|
142443
|
+
// packages/core/src/telemetry/session-tracing.ts
|
|
142444
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
142445
|
+
function ensureCleanupInterval() {
|
|
142446
|
+
if (cleanupIntervalStarted) return;
|
|
142447
|
+
cleanupIntervalStarted = true;
|
|
142448
|
+
const interval = setInterval(() => {
|
|
142449
|
+
const cutoff = Date.now() - SPAN_TTL_MS;
|
|
142450
|
+
for (const [spanId, weakRef] of activeSpans) {
|
|
142451
|
+
const ctx = weakRef.deref();
|
|
142452
|
+
if (ctx === void 0) {
|
|
142453
|
+
activeSpans.delete(spanId);
|
|
142454
|
+
strongSpans.delete(spanId);
|
|
142455
|
+
} else if (ctx.startTime < cutoff) {
|
|
142456
|
+
if (!ctx.ended) {
|
|
142457
|
+
ctx.ended = true;
|
|
142458
|
+
ctx.span.end();
|
|
142459
|
+
}
|
|
142460
|
+
activeSpans.delete(spanId);
|
|
142461
|
+
strongSpans.delete(spanId);
|
|
142462
|
+
}
|
|
142463
|
+
}
|
|
142464
|
+
}, 6e4);
|
|
142465
|
+
if (typeof interval.unref === "function") {
|
|
142466
|
+
interval.unref();
|
|
142467
|
+
}
|
|
142468
|
+
}
|
|
142469
|
+
function getSpanId(span) {
|
|
142470
|
+
return span.spanContext().spanId || "";
|
|
142471
|
+
}
|
|
142472
|
+
function getTracer() {
|
|
142473
|
+
return trace.getTracer(SERVICE_NAME, "1.0.0");
|
|
142474
|
+
}
|
|
142475
|
+
function startInteractionSpan(config2, options2) {
|
|
142476
|
+
if (!isTelemetrySdkInitialized()) return;
|
|
142477
|
+
ensureCleanupInterval();
|
|
142478
|
+
interactionSequence++;
|
|
142479
|
+
const attributes = {
|
|
142480
|
+
"session.id": config2.getSessionId(),
|
|
142481
|
+
"qwen-code.prompt_id": options2.promptId,
|
|
142482
|
+
"qwen-code.message_type": options2.messageType,
|
|
142483
|
+
"qwen-code.model": options2.model,
|
|
142484
|
+
"qwen-code.approval_mode": config2.getApprovalMode(),
|
|
142485
|
+
"interaction.sequence": interactionSequence
|
|
142486
|
+
};
|
|
142487
|
+
const span = getTracer().startSpan(SPAN_INTERACTION, {
|
|
142488
|
+
kind: SpanKind.INTERNAL,
|
|
142489
|
+
attributes
|
|
142490
|
+
});
|
|
142491
|
+
const spanId = getSpanId(span);
|
|
142492
|
+
const spanContextObj = {
|
|
142493
|
+
span,
|
|
142494
|
+
startTime: Date.now(),
|
|
142495
|
+
attributes,
|
|
142496
|
+
type: "interaction"
|
|
142497
|
+
};
|
|
142498
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
142499
|
+
strongSpans.set(spanId, spanContextObj);
|
|
142500
|
+
lastInteractionCtx = spanContextObj;
|
|
142501
|
+
interactionContext.enterWith(spanContextObj);
|
|
142502
|
+
}
|
|
142503
|
+
function endInteractionSpan(status, metadata2) {
|
|
142504
|
+
const spanCtx = interactionContext.getStore() ?? lastInteractionCtx;
|
|
142505
|
+
if (!spanCtx || spanCtx.ended) return;
|
|
142506
|
+
spanCtx.ended = true;
|
|
142507
|
+
lastInteractionCtx = void 0;
|
|
142508
|
+
const duration3 = Date.now() - spanCtx.startTime;
|
|
142509
|
+
spanCtx.span.setAttributes({
|
|
142510
|
+
"interaction.duration_ms": duration3,
|
|
142511
|
+
"qwen-code.turn_status": status
|
|
142512
|
+
});
|
|
142513
|
+
if (status === "error") {
|
|
142514
|
+
spanCtx.span.setStatus({
|
|
142515
|
+
code: SpanStatusCode.ERROR,
|
|
142516
|
+
message: metadata2?.errorMessage ?? "unknown error"
|
|
142517
|
+
});
|
|
142518
|
+
} else {
|
|
142519
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
142520
|
+
}
|
|
142521
|
+
spanCtx.span.end();
|
|
142522
|
+
const spanId = getSpanId(spanCtx.span);
|
|
142523
|
+
activeSpans.delete(spanId);
|
|
142524
|
+
strongSpans.delete(spanId);
|
|
142525
|
+
interactionContext.enterWith(void 0);
|
|
142526
|
+
}
|
|
142527
|
+
function startLLMRequestSpan(model, promptId) {
|
|
142528
|
+
if (!isTelemetrySdkInitialized()) {
|
|
142529
|
+
return NOOP_SPAN;
|
|
142530
|
+
}
|
|
142531
|
+
const parentCtx = interactionContext.getStore();
|
|
142532
|
+
const ctx = parentCtx ? trace.setSpan(context.active(), parentCtx.span) : context.active();
|
|
142533
|
+
const attributes = {
|
|
142534
|
+
"qwen-code.model": model,
|
|
142535
|
+
"qwen-code.prompt_id": promptId,
|
|
142536
|
+
"llm_request.context": parentCtx ? "interaction" : "standalone"
|
|
142537
|
+
};
|
|
142538
|
+
const span = getTracer().startSpan(
|
|
142539
|
+
SPAN_LLM_REQUEST,
|
|
142540
|
+
{ kind: SpanKind.INTERNAL, attributes },
|
|
142541
|
+
ctx
|
|
142542
|
+
);
|
|
142543
|
+
const spanId = getSpanId(span);
|
|
142544
|
+
const spanContextObj = {
|
|
142545
|
+
span,
|
|
142546
|
+
startTime: Date.now(),
|
|
142547
|
+
attributes,
|
|
142548
|
+
type: "llm_request"
|
|
142549
|
+
};
|
|
142550
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
142551
|
+
strongSpans.set(spanId, spanContextObj);
|
|
142552
|
+
return span;
|
|
142553
|
+
}
|
|
142554
|
+
function endLLMRequestSpan(span, metadata2) {
|
|
142555
|
+
const spanId = getSpanId(span);
|
|
142556
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
142557
|
+
if (!spanCtx || spanCtx.ended) return;
|
|
142558
|
+
spanCtx.ended = true;
|
|
142559
|
+
const duration3 = metadata2?.durationMs ?? Date.now() - spanCtx.startTime;
|
|
142560
|
+
const endAttributes = { duration_ms: duration3 };
|
|
142561
|
+
if (metadata2) {
|
|
142562
|
+
if (metadata2.inputTokens !== void 0)
|
|
142563
|
+
endAttributes["input_tokens"] = metadata2.inputTokens;
|
|
142564
|
+
if (metadata2.outputTokens !== void 0)
|
|
142565
|
+
endAttributes["output_tokens"] = metadata2.outputTokens;
|
|
142566
|
+
endAttributes["success"] = metadata2.success;
|
|
142567
|
+
if (metadata2.error !== void 0) endAttributes["error"] = metadata2.error;
|
|
142568
|
+
}
|
|
142569
|
+
span.setAttributes(endAttributes);
|
|
142570
|
+
if (metadata2 === void 0 || metadata2.success) {
|
|
142571
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
142572
|
+
} else {
|
|
142573
|
+
span.setStatus({
|
|
142574
|
+
code: SpanStatusCode.ERROR,
|
|
142575
|
+
message: metadata2.error ?? "unknown error"
|
|
142576
|
+
});
|
|
142577
|
+
}
|
|
142578
|
+
span.end();
|
|
142579
|
+
activeSpans.delete(spanId);
|
|
142580
|
+
strongSpans.delete(spanId);
|
|
142581
|
+
}
|
|
142582
|
+
function startToolSpan(toolName, attrs) {
|
|
142583
|
+
if (!isTelemetrySdkInitialized()) {
|
|
142584
|
+
return NOOP_SPAN;
|
|
142585
|
+
}
|
|
142586
|
+
const parentCtx = interactionContext.getStore();
|
|
142587
|
+
const ctx = parentCtx ? trace.setSpan(context.active(), parentCtx.span) : context.active();
|
|
142588
|
+
const attributes = {
|
|
142589
|
+
"tool.name": toolName,
|
|
142590
|
+
...attrs
|
|
142591
|
+
};
|
|
142592
|
+
const span = getTracer().startSpan(
|
|
142593
|
+
SPAN_TOOL,
|
|
142594
|
+
{ kind: SpanKind.INTERNAL, attributes },
|
|
142595
|
+
ctx
|
|
142596
|
+
);
|
|
142597
|
+
const spanId = getSpanId(span);
|
|
142598
|
+
const spanContextObj = {
|
|
142599
|
+
span,
|
|
142600
|
+
startTime: Date.now(),
|
|
142601
|
+
attributes,
|
|
142602
|
+
type: "tool"
|
|
142603
|
+
};
|
|
142604
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
142605
|
+
strongSpans.set(spanId, spanContextObj);
|
|
142606
|
+
return span;
|
|
142607
|
+
}
|
|
142608
|
+
function endToolSpan(span, metadata2) {
|
|
142609
|
+
const spanId = getSpanId(span);
|
|
142610
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
142611
|
+
if (!spanCtx || spanCtx.ended) return;
|
|
142612
|
+
spanCtx.ended = true;
|
|
142613
|
+
const duration3 = Date.now() - spanCtx.startTime;
|
|
142614
|
+
const endAttributes = { duration_ms: duration3 };
|
|
142615
|
+
if (metadata2) {
|
|
142616
|
+
if (metadata2.success !== void 0)
|
|
142617
|
+
endAttributes["success"] = metadata2.success;
|
|
142618
|
+
if (metadata2.error !== void 0) endAttributes["error"] = metadata2.error;
|
|
142619
|
+
}
|
|
142620
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
142621
|
+
if (metadata2?.success !== false) {
|
|
142622
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
142623
|
+
} else {
|
|
142624
|
+
spanCtx.span.setStatus({
|
|
142625
|
+
code: SpanStatusCode.ERROR,
|
|
142626
|
+
message: metadata2?.error ?? "tool error"
|
|
142627
|
+
});
|
|
142628
|
+
}
|
|
142629
|
+
spanCtx.span.end();
|
|
142630
|
+
activeSpans.delete(spanId);
|
|
142631
|
+
strongSpans.delete(spanId);
|
|
142632
|
+
}
|
|
142633
|
+
function startToolExecutionSpan(parentToolSpan) {
|
|
142634
|
+
if (!isTelemetrySdkInitialized()) {
|
|
142635
|
+
return NOOP_SPAN;
|
|
142636
|
+
}
|
|
142637
|
+
const ctx = trace.setSpan(context.active(), parentToolSpan);
|
|
142638
|
+
const span = getTracer().startSpan(
|
|
142639
|
+
SPAN_TOOL_EXECUTION,
|
|
142640
|
+
{ kind: SpanKind.INTERNAL },
|
|
142641
|
+
ctx
|
|
142642
|
+
);
|
|
142643
|
+
const spanId = getSpanId(span);
|
|
142644
|
+
const spanContextObj = {
|
|
142645
|
+
span,
|
|
142646
|
+
startTime: Date.now(),
|
|
142647
|
+
attributes: {},
|
|
142648
|
+
type: "tool.execution"
|
|
142649
|
+
};
|
|
142650
|
+
activeSpans.set(spanId, new WeakRef(spanContextObj));
|
|
142651
|
+
strongSpans.set(spanId, spanContextObj);
|
|
142652
|
+
return span;
|
|
142653
|
+
}
|
|
142654
|
+
function endToolExecutionSpan(span, metadata2) {
|
|
142655
|
+
const spanId = getSpanId(span);
|
|
142656
|
+
const spanCtx = activeSpans.get(spanId)?.deref();
|
|
142657
|
+
if (!spanCtx || spanCtx.ended) return;
|
|
142658
|
+
spanCtx.ended = true;
|
|
142659
|
+
const duration3 = Date.now() - spanCtx.startTime;
|
|
142660
|
+
const endAttributes = { duration_ms: duration3 };
|
|
142661
|
+
if (metadata2) {
|
|
142662
|
+
if (metadata2.success !== void 0)
|
|
142663
|
+
endAttributes["success"] = metadata2.success;
|
|
142664
|
+
if (metadata2.error !== void 0) endAttributes["error"] = metadata2.error;
|
|
142665
|
+
}
|
|
142666
|
+
spanCtx.span.setAttributes(endAttributes);
|
|
142667
|
+
if (metadata2?.success !== false) {
|
|
142668
|
+
spanCtx.span.setStatus({ code: SpanStatusCode.OK });
|
|
142669
|
+
} else {
|
|
142670
|
+
spanCtx.span.setStatus({
|
|
142671
|
+
code: SpanStatusCode.ERROR,
|
|
142672
|
+
message: metadata2?.error ?? "tool execution error"
|
|
142673
|
+
});
|
|
142674
|
+
}
|
|
142675
|
+
spanCtx.span.end();
|
|
142676
|
+
activeSpans.delete(spanId);
|
|
142677
|
+
strongSpans.delete(spanId);
|
|
142678
|
+
}
|
|
142679
|
+
function clearSessionTracingForTesting() {
|
|
142680
|
+
activeSpans.clear();
|
|
142681
|
+
strongSpans.clear();
|
|
142682
|
+
interactionContext.enterWith(void 0);
|
|
142683
|
+
interactionSequence = 0;
|
|
142684
|
+
lastInteractionCtx = void 0;
|
|
142685
|
+
}
|
|
142686
|
+
var NOOP_SPAN, interactionContext, activeSpans, strongSpans, interactionSequence, lastInteractionCtx, cleanupIntervalStarted, SPAN_TTL_MS;
|
|
142687
|
+
var init_session_tracing = __esm({
|
|
142688
|
+
"packages/core/src/telemetry/session-tracing.ts"() {
|
|
142689
|
+
"use strict";
|
|
142690
|
+
init_esbuild_shims();
|
|
142691
|
+
init_esm();
|
|
142692
|
+
init_constants();
|
|
142693
|
+
init_sdk();
|
|
142694
|
+
NOOP_SPAN = trace.wrapSpanContext({
|
|
142695
|
+
traceId: "0".repeat(32),
|
|
142696
|
+
spanId: "0".repeat(16),
|
|
142697
|
+
traceFlags: 0
|
|
142698
|
+
});
|
|
142699
|
+
interactionContext = new AsyncLocalStorage4();
|
|
142700
|
+
activeSpans = /* @__PURE__ */ new Map();
|
|
142701
|
+
strongSpans = /* @__PURE__ */ new Map();
|
|
142702
|
+
interactionSequence = 0;
|
|
142703
|
+
cleanupIntervalStarted = false;
|
|
142704
|
+
SPAN_TTL_MS = 30 * 60 * 1e3;
|
|
142705
|
+
__name(ensureCleanupInterval, "ensureCleanupInterval");
|
|
142706
|
+
__name(getSpanId, "getSpanId");
|
|
142707
|
+
__name(getTracer, "getTracer");
|
|
142708
|
+
__name(startInteractionSpan, "startInteractionSpan");
|
|
142709
|
+
__name(endInteractionSpan, "endInteractionSpan");
|
|
142710
|
+
__name(startLLMRequestSpan, "startLLMRequestSpan");
|
|
142711
|
+
__name(endLLMRequestSpan, "endLLMRequestSpan");
|
|
142712
|
+
__name(startToolSpan, "startToolSpan");
|
|
142713
|
+
__name(endToolSpan, "endToolSpan");
|
|
142714
|
+
__name(startToolExecutionSpan, "startToolExecutionSpan");
|
|
142715
|
+
__name(endToolExecutionSpan, "endToolExecutionSpan");
|
|
142716
|
+
__name(clearSessionTracingForTesting, "clearSessionTracingForTesting");
|
|
142717
|
+
}
|
|
142718
|
+
});
|
|
142719
|
+
|
|
142439
142720
|
// packages/core/src/telemetry/sdk.ts
|
|
142440
142721
|
function createTelemetryDiagLogger() {
|
|
142441
142722
|
const debugLogger192 = createDebugLogger("OTEL");
|
|
@@ -142617,6 +142898,7 @@ async function shutdownTelemetry() {
|
|
|
142617
142898
|
if (!telemetryInitialized || !sdk) {
|
|
142618
142899
|
return;
|
|
142619
142900
|
}
|
|
142901
|
+
endInteractionSpan("cancelled");
|
|
142620
142902
|
const currentSdk = sdk;
|
|
142621
142903
|
const debugLogger192 = createDebugLogger("OTEL");
|
|
142622
142904
|
telemetryShutdownPromise = (async () => {
|
|
@@ -142688,6 +142970,7 @@ var init_sdk = __esm({
|
|
|
142688
142970
|
init_log_to_span_processor();
|
|
142689
142971
|
init_tracer();
|
|
142690
142972
|
init_session_context();
|
|
142973
|
+
init_session_tracing();
|
|
142691
142974
|
__name(createTelemetryDiagLogger, "createTelemetryDiagLogger");
|
|
142692
142975
|
diag2.setLogger(createTelemetryDiagLogger(), DiagLogLevel.WARN);
|
|
142693
142976
|
OTLP_SIGNAL_PATHS = {
|
|
@@ -147547,13 +147830,13 @@ var init_converter = __esm({
|
|
|
147547
147830
|
});
|
|
147548
147831
|
|
|
147549
147832
|
// packages/core/src/core/openaiContentGenerator/requestCaptureContext.ts
|
|
147550
|
-
import { AsyncLocalStorage as
|
|
147833
|
+
import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
|
|
147551
147834
|
var openaiRequestCaptureContext;
|
|
147552
147835
|
var init_requestCaptureContext = __esm({
|
|
147553
147836
|
"packages/core/src/core/openaiContentGenerator/requestCaptureContext.ts"() {
|
|
147554
147837
|
"use strict";
|
|
147555
147838
|
init_esbuild_shims();
|
|
147556
|
-
openaiRequestCaptureContext = new
|
|
147839
|
+
openaiRequestCaptureContext = new AsyncLocalStorage5();
|
|
147557
147840
|
}
|
|
147558
147841
|
});
|
|
147559
147842
|
|
|
@@ -147646,6 +147929,11 @@ var init_esm_node = __esm({
|
|
|
147646
147929
|
import * as path16 from "node:path";
|
|
147647
147930
|
import { promises as fs19 } from "node:fs";
|
|
147648
147931
|
import * as os7 from "os";
|
|
147932
|
+
function sanitizePromptIdForFilename(promptId) {
|
|
147933
|
+
if (!promptId || !isInternalPromptId(promptId)) return void 0;
|
|
147934
|
+
const sanitized = promptId.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
147935
|
+
return sanitized || void 0;
|
|
147936
|
+
}
|
|
147649
147937
|
var debugLogger12, OpenAILogger, openaiLogger;
|
|
147650
147938
|
var init_openaiLogger = __esm({
|
|
147651
147939
|
"packages/core/src/utils/openaiLogger.ts"() {
|
|
@@ -147653,7 +147941,9 @@ var init_openaiLogger = __esm({
|
|
|
147653
147941
|
init_esbuild_shims();
|
|
147654
147942
|
init_esm_node();
|
|
147655
147943
|
init_debugLogger();
|
|
147944
|
+
init_internalPromptIds();
|
|
147656
147945
|
debugLogger12 = createDebugLogger("OPENAI_LOGGER");
|
|
147946
|
+
__name(sanitizePromptIdForFilename, "sanitizePromptIdForFilename");
|
|
147657
147947
|
OpenAILogger = class {
|
|
147658
147948
|
static {
|
|
147659
147949
|
__name(this, "OpenAILogger");
|
|
@@ -147699,15 +147989,18 @@ var init_openaiLogger = __esm({
|
|
|
147699
147989
|
* @param request The request sent to OpenAI
|
|
147700
147990
|
* @param response The response received from OpenAI
|
|
147701
147991
|
* @param error Optional error if the request failed
|
|
147992
|
+
* @param promptId Optional prompt id; internal prompt ids are appended to
|
|
147993
|
+
* the filename after timestamp and id.
|
|
147702
147994
|
* @returns The file path where the log was written
|
|
147703
147995
|
*/
|
|
147704
|
-
async logInteraction(request4, response, error40) {
|
|
147996
|
+
async logInteraction(request4, response, error40, promptId) {
|
|
147705
147997
|
if (!this.initialized) {
|
|
147706
147998
|
await this.initialize();
|
|
147707
147999
|
}
|
|
147708
148000
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/:/g, "-");
|
|
147709
148001
|
const id = v4_default().slice(0, 8);
|
|
147710
|
-
const
|
|
148002
|
+
const promptIdSuffix = sanitizePromptIdForFilename(promptId);
|
|
148003
|
+
const filename = promptIdSuffix ? `openai-${timestamp}-${id}-${promptIdSuffix}.json` : `openai-${timestamp}-${id}.json`;
|
|
147711
148004
|
const filePath = path16.join(this.logDir, filename);
|
|
147712
148005
|
const logData = {
|
|
147713
148006
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -147891,7 +148184,7 @@ var init_loggingContentGenerator = __esm({
|
|
|
147891
148184
|
async (span) => {
|
|
147892
148185
|
const startTime = Date.now();
|
|
147893
148186
|
const isInternal = isInternalPromptId(userPromptId);
|
|
147894
|
-
const session = this.startCaptureSession(
|
|
148187
|
+
const session = this.startCaptureSession();
|
|
147895
148188
|
try {
|
|
147896
148189
|
if (!isInternal) {
|
|
147897
148190
|
this.logApiRequest(
|
|
@@ -147913,18 +148206,15 @@ var init_loggingContentGenerator = __esm({
|
|
|
147913
148206
|
response.usageMetadata,
|
|
147914
148207
|
responseText
|
|
147915
148208
|
);
|
|
147916
|
-
|
|
147917
|
-
|
|
147918
|
-
await
|
|
147919
|
-
|
|
147920
|
-
|
|
147921
|
-
|
|
147922
|
-
|
|
147923
|
-
|
|
147924
|
-
|
|
147925
|
-
loggingError
|
|
147926
|
-
);
|
|
147927
|
-
}
|
|
148209
|
+
try {
|
|
148210
|
+
await this.safelyLogOpenAIInteraction(
|
|
148211
|
+
await session.resolve(req),
|
|
148212
|
+
response,
|
|
148213
|
+
void 0,
|
|
148214
|
+
userPromptId
|
|
148215
|
+
);
|
|
148216
|
+
} catch (loggingError) {
|
|
148217
|
+
debugLogger13.warn("Failed to log OpenAI interaction:", loggingError);
|
|
147928
148218
|
}
|
|
147929
148219
|
return response;
|
|
147930
148220
|
} catch (error40) {
|
|
@@ -147936,19 +148226,15 @@ var init_loggingContentGenerator = __esm({
|
|
|
147936
148226
|
req.model,
|
|
147937
148227
|
userPromptId
|
|
147938
148228
|
);
|
|
147939
|
-
|
|
147940
|
-
|
|
147941
|
-
await
|
|
147942
|
-
|
|
147943
|
-
|
|
147944
|
-
|
|
147945
|
-
|
|
147946
|
-
|
|
147947
|
-
|
|
147948
|
-
"Failed to log OpenAI interaction:",
|
|
147949
|
-
loggingError
|
|
147950
|
-
);
|
|
147951
|
-
}
|
|
148229
|
+
try {
|
|
148230
|
+
await this.safelyLogOpenAIInteraction(
|
|
148231
|
+
await session.resolve(req),
|
|
148232
|
+
void 0,
|
|
148233
|
+
error40,
|
|
148234
|
+
userPromptId
|
|
148235
|
+
);
|
|
148236
|
+
} catch (loggingError) {
|
|
148237
|
+
debugLogger13.warn("Failed to log OpenAI interaction:", loggingError);
|
|
147952
148238
|
}
|
|
147953
148239
|
safeSetStatus(span, {
|
|
147954
148240
|
code: SpanStatusCode.ERROR,
|
|
@@ -147967,7 +148253,7 @@ var init_loggingContentGenerator = __esm({
|
|
|
147967
148253
|
const spanContext = trace.setSpan(context.active(), span);
|
|
147968
148254
|
const startTime = Date.now();
|
|
147969
148255
|
const isInternal = isInternalPromptId(userPromptId);
|
|
147970
|
-
const session = this.startCaptureSession(
|
|
148256
|
+
const session = this.startCaptureSession();
|
|
147971
148257
|
let stream5;
|
|
147972
148258
|
try {
|
|
147973
148259
|
stream5 = await runInContext(async () => {
|
|
@@ -147995,21 +148281,20 @@ var init_loggingContentGenerator = __esm({
|
|
|
147995
148281
|
span.end();
|
|
147996
148282
|
} catch {
|
|
147997
148283
|
}
|
|
147998
|
-
|
|
147999
|
-
|
|
148000
|
-
await
|
|
148001
|
-
|
|
148002
|
-
|
|
148003
|
-
|
|
148004
|
-
|
|
148005
|
-
|
|
148006
|
-
|
|
148007
|
-
}
|
|
148284
|
+
try {
|
|
148285
|
+
await this.safelyLogOpenAIInteraction(
|
|
148286
|
+
await session.resolve(req),
|
|
148287
|
+
void 0,
|
|
148288
|
+
error40,
|
|
148289
|
+
userPromptId
|
|
148290
|
+
);
|
|
148291
|
+
} catch (loggingError) {
|
|
148292
|
+
debugLogger13.warn("Failed to log OpenAI interaction:", loggingError);
|
|
148008
148293
|
}
|
|
148009
148294
|
throw error40;
|
|
148010
148295
|
}
|
|
148011
148296
|
let resolvedRequest;
|
|
148012
|
-
if (
|
|
148297
|
+
if (this.openaiLogger) {
|
|
148013
148298
|
try {
|
|
148014
148299
|
resolvedRequest = await session.resolve(req);
|
|
148015
148300
|
} catch (loggingError) {
|
|
@@ -148028,18 +148313,19 @@ var init_loggingContentGenerator = __esm({
|
|
|
148028
148313
|
)
|
|
148029
148314
|
);
|
|
148030
148315
|
}
|
|
148031
|
-
startCaptureSession(
|
|
148316
|
+
startCaptureSession() {
|
|
148032
148317
|
let captured;
|
|
148033
|
-
const skipCapture =
|
|
148318
|
+
const skipCapture = !this.openaiLogger;
|
|
148034
148319
|
return {
|
|
148035
148320
|
wrap: /* @__PURE__ */ __name((fn) => skipCapture ? fn() : openaiRequestCaptureContext.run((built) => {
|
|
148036
148321
|
captured = built;
|
|
148037
148322
|
}, fn), "wrap"),
|
|
148038
|
-
resolve: /* @__PURE__ */ __name(async (req) => captured ?? await this.buildOpenAIRequestForLogging(req), "resolve")
|
|
148323
|
+
resolve: /* @__PURE__ */ __name(async (req) => this.openaiLogger ? captured ?? await this.buildOpenAIRequestForLogging(req) : void 0, "resolve")
|
|
148039
148324
|
};
|
|
148040
148325
|
}
|
|
148041
148326
|
async *loggingStreamWrapper(stream5, startTime, userPromptId, model, openaiRequest, span, spanContext) {
|
|
148042
148327
|
const isInternal = isInternalPromptId(userPromptId);
|
|
148328
|
+
const shouldCollectResponses = !isInternal || !!this.openaiLogger;
|
|
148043
148329
|
const responses = [];
|
|
148044
148330
|
let firstResponseId = "";
|
|
148045
148331
|
let firstModelVersion = "";
|
|
@@ -148054,7 +148340,7 @@ var init_loggingContentGenerator = __esm({
|
|
|
148054
148340
|
if (!firstModelVersion && response.modelVersion) {
|
|
148055
148341
|
firstModelVersion = response.modelVersion;
|
|
148056
148342
|
}
|
|
148057
|
-
if (
|
|
148343
|
+
if (shouldCollectResponses) {
|
|
148058
148344
|
responses.push(response);
|
|
148059
148345
|
}
|
|
148060
148346
|
if (response.usageMetadata) {
|
|
@@ -148063,7 +148349,7 @@ var init_loggingContentGenerator = __esm({
|
|
|
148063
148349
|
yield response;
|
|
148064
148350
|
}
|
|
148065
148351
|
const durationMs = Date.now() - startTime;
|
|
148066
|
-
const consolidatedResponse =
|
|
148352
|
+
const consolidatedResponse = shouldCollectResponses ? this.consolidateGeminiResponsesForLogging(responses) : void 0;
|
|
148067
148353
|
runInSpan(
|
|
148068
148354
|
() => this.safelyLogApiResponse(
|
|
148069
148355
|
firstResponseId,
|
|
@@ -148071,14 +148357,17 @@ var init_loggingContentGenerator = __esm({
|
|
|
148071
148357
|
firstModelVersion || model,
|
|
148072
148358
|
userPromptId,
|
|
148073
148359
|
lastUsageMetadata,
|
|
148074
|
-
this.extractResponseText(consolidatedResponse)
|
|
148360
|
+
isInternal ? void 0 : this.extractResponseText(consolidatedResponse)
|
|
148361
|
+
)
|
|
148362
|
+
);
|
|
148363
|
+
await runInSpan(
|
|
148364
|
+
() => this.safelyLogOpenAIInteraction(
|
|
148365
|
+
openaiRequest,
|
|
148366
|
+
consolidatedResponse,
|
|
148367
|
+
void 0,
|
|
148368
|
+
userPromptId
|
|
148075
148369
|
)
|
|
148076
148370
|
);
|
|
148077
|
-
if (!isInternal) {
|
|
148078
|
-
await runInSpan(
|
|
148079
|
-
() => this.safelyLogOpenAIInteraction(openaiRequest, consolidatedResponse)
|
|
148080
|
-
);
|
|
148081
|
-
}
|
|
148082
148371
|
terminalStatusAttempted = true;
|
|
148083
148372
|
if (span) {
|
|
148084
148373
|
safeSetStatus(span, { code: SpanStatusCode.OK });
|
|
@@ -148094,11 +148383,14 @@ var init_loggingContentGenerator = __esm({
|
|
|
148094
148383
|
userPromptId
|
|
148095
148384
|
)
|
|
148096
148385
|
);
|
|
148097
|
-
|
|
148098
|
-
|
|
148099
|
-
|
|
148100
|
-
|
|
148101
|
-
|
|
148386
|
+
await runInSpan(
|
|
148387
|
+
() => this.safelyLogOpenAIInteraction(
|
|
148388
|
+
openaiRequest,
|
|
148389
|
+
void 0,
|
|
148390
|
+
error40,
|
|
148391
|
+
userPromptId
|
|
148392
|
+
)
|
|
148393
|
+
);
|
|
148102
148394
|
terminalStatusAttempted = true;
|
|
148103
148395
|
if (span) {
|
|
148104
148396
|
safeSetStatus(span, {
|
|
@@ -148165,7 +148457,7 @@ var init_loggingContentGenerator = __esm({
|
|
|
148165
148457
|
startTime: 0
|
|
148166
148458
|
};
|
|
148167
148459
|
}
|
|
148168
|
-
async logOpenAIInteraction(openaiRequest, response, error40) {
|
|
148460
|
+
async logOpenAIInteraction(openaiRequest, response, error40, promptId) {
|
|
148169
148461
|
if (!this.openaiLogger || !openaiRequest) {
|
|
148170
148462
|
return;
|
|
148171
148463
|
}
|
|
@@ -148173,12 +148465,13 @@ var init_loggingContentGenerator = __esm({
|
|
|
148173
148465
|
await this.openaiLogger.logInteraction(
|
|
148174
148466
|
openaiRequest,
|
|
148175
148467
|
openaiResponse,
|
|
148176
|
-
error40 instanceof Error ? error40 : error40 ? new Error(String(error40)) : void 0
|
|
148468
|
+
error40 instanceof Error ? error40 : error40 ? new Error(String(error40)) : void 0,
|
|
148469
|
+
promptId
|
|
148177
148470
|
);
|
|
148178
148471
|
}
|
|
148179
|
-
async safelyLogOpenAIInteraction(openaiRequest, response, error40) {
|
|
148472
|
+
async safelyLogOpenAIInteraction(openaiRequest, response, error40, promptId) {
|
|
148180
148473
|
try {
|
|
148181
|
-
await this.logOpenAIInteraction(openaiRequest, response, error40);
|
|
148474
|
+
await this.logOpenAIInteraction(openaiRequest, response, error40, promptId);
|
|
148182
148475
|
} catch (loggingError) {
|
|
148183
148476
|
debugLogger13.warn("Failed to log OpenAI interaction:", loggingError);
|
|
148184
148477
|
}
|
|
@@ -174155,7 +174448,7 @@ __export(geminiContentGenerator_exports, {
|
|
|
174155
174448
|
createGeminiContentGenerator: () => createGeminiContentGenerator
|
|
174156
174449
|
});
|
|
174157
174450
|
function createGeminiContentGenerator(config2, gcConfig) {
|
|
174158
|
-
const version2 = "0.15.11
|
|
174451
|
+
const version2 = "0.15.11";
|
|
174159
174452
|
const userAgent2 = config2.userAgent || `QwenCode/${version2} (${process.platform}; ${process.arch})`;
|
|
174160
174453
|
const baseHeaders = {
|
|
174161
174454
|
"User-Agent": userAgent2
|
|
@@ -182417,6 +182710,7 @@ var init_telemetry = __esm({
|
|
|
182417
182710
|
init_metrics2();
|
|
182418
182711
|
init_qwen_logger();
|
|
182419
182712
|
init_sanitize();
|
|
182713
|
+
init_session_tracing();
|
|
182420
182714
|
TelemetryTarget = /* @__PURE__ */ ((TelemetryTarget2) => {
|
|
182421
182715
|
TelemetryTarget2["GCP"] = "gcp";
|
|
182422
182716
|
TelemetryTarget2["LOCAL"] = "local";
|
|
@@ -182517,7 +182811,7 @@ var init_store = __esm({
|
|
|
182517
182811
|
});
|
|
182518
182812
|
|
|
182519
182813
|
// packages/core/src/agents/runtime/agent-context.ts
|
|
182520
|
-
import { AsyncLocalStorage as
|
|
182814
|
+
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
182521
182815
|
function runWithAgentContext(agentId, fn) {
|
|
182522
182816
|
const current = storage.getStore() ?? {};
|
|
182523
182817
|
return storage.run({ ...current, agentId }, fn);
|
|
@@ -182537,7 +182831,7 @@ var init_agent_context = __esm({
|
|
|
182537
182831
|
"packages/core/src/agents/runtime/agent-context.ts"() {
|
|
182538
182832
|
"use strict";
|
|
182539
182833
|
init_esbuild_shims();
|
|
182540
|
-
storage = new
|
|
182834
|
+
storage = new AsyncLocalStorage6();
|
|
182541
182835
|
__name(runWithAgentContext, "runWithAgentContext");
|
|
182542
182836
|
__name(runWithRuntimeContentGenerator, "runWithRuntimeContentGenerator");
|
|
182543
182837
|
__name(getCurrentAgentId, "getCurrentAgentId");
|
|
@@ -226042,7 +226336,7 @@ ${userMemory.trim()}`;
|
|
|
226042
226336
|
});
|
|
226043
226337
|
|
|
226044
226338
|
// packages/core/src/tools/agent/fork-subagent.ts
|
|
226045
|
-
import { AsyncLocalStorage as
|
|
226339
|
+
import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
|
|
226046
226340
|
function runInForkContext(fn) {
|
|
226047
226341
|
return forkExecutionStorage.run({ marker: true }, fn);
|
|
226048
226342
|
}
|
|
@@ -226125,7 +226419,7 @@ var init_fork_subagent = __esm({
|
|
|
226125
226419
|
systemPrompt: "You are a forked worker process. Follow the directive in the conversation history. Execute tasks directly using available tools. Do not spawn sub-agents.",
|
|
226126
226420
|
level: "session"
|
|
226127
226421
|
};
|
|
226128
|
-
forkExecutionStorage = new
|
|
226422
|
+
forkExecutionStorage = new AsyncLocalStorage7();
|
|
226129
226423
|
__name(runInForkContext, "runInForkContext");
|
|
226130
226424
|
__name(isInForkExecution, "isInForkExecution");
|
|
226131
226425
|
FORK_PLACEHOLDER_RESULT = "Fork started \u2014 processing in background";
|
|
@@ -242206,13 +242500,13 @@ var init_nextSpeakerChecker = __esm({
|
|
|
242206
242500
|
});
|
|
242207
242501
|
|
|
242208
242502
|
// packages/core/src/utils/promptIdContext.ts
|
|
242209
|
-
import { AsyncLocalStorage as
|
|
242503
|
+
import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
|
|
242210
242504
|
var promptIdContext;
|
|
242211
242505
|
var init_promptIdContext = __esm({
|
|
242212
242506
|
"packages/core/src/utils/promptIdContext.ts"() {
|
|
242213
242507
|
"use strict";
|
|
242214
242508
|
init_esbuild_shims();
|
|
242215
|
-
promptIdContext = new
|
|
242509
|
+
promptIdContext = new AsyncLocalStorage8();
|
|
242216
242510
|
}
|
|
242217
242511
|
});
|
|
242218
242512
|
|
|
@@ -242813,310 +243107,355 @@ var init_client4 = __esm({
|
|
|
242813
243107
|
if (messageType === "notification" /* Notification */) {
|
|
242814
243108
|
this.config.getChatRecordingService()?.recordNotification(request4, options2?.notificationDisplayText);
|
|
242815
243109
|
}
|
|
242816
|
-
|
|
243110
|
+
const isTopLevelInteraction = messageType === "userQuery" /* UserQuery */ || messageType === "cron" /* Cron */ || messageType === "notification" /* Notification */;
|
|
243111
|
+
if (isTopLevelInteraction) {
|
|
242817
243112
|
this.loopDetector.reset(prompt_id);
|
|
242818
243113
|
this.lastPromptId = prompt_id;
|
|
243114
|
+
startInteractionSpan(this.config, {
|
|
243115
|
+
promptId: prompt_id,
|
|
243116
|
+
model: options2?.modelOverride ?? this.config.getModel(),
|
|
243117
|
+
messageType
|
|
243118
|
+
});
|
|
242819
243119
|
}
|
|
242820
|
-
|
|
242821
|
-
if (
|
|
242822
|
-
|
|
242823
|
-
|
|
242824
|
-
|
|
242825
|
-
|
|
242826
|
-
|
|
242827
|
-
|
|
242828
|
-
|
|
242829
|
-
|
|
242830
|
-
|
|
242831
|
-
|
|
242832
|
-
|
|
242833
|
-
|
|
242834
|
-
|
|
242835
|
-
|
|
242836
|
-
|
|
242837
|
-
|
|
242838
|
-
|
|
242839
|
-
|
|
242840
|
-
|
|
242841
|
-
|
|
242842
|
-
|
|
242843
|
-
|
|
242844
|
-
|
|
243120
|
+
try {
|
|
243121
|
+
if (messageType === "userQuery" /* UserQuery */ || messageType === "cron" /* Cron */) {
|
|
243122
|
+
if (this.config.getManagedAutoMemoryEnabled()) {
|
|
243123
|
+
const recallAbortController = new AbortController();
|
|
243124
|
+
const rawRecallPromise = this.config.getMemoryManager().recall(this.config.getProjectRoot(), partToString(request4), {
|
|
243125
|
+
config: this.config,
|
|
243126
|
+
excludedFilePaths: this.surfacedRelevantAutoMemoryPaths,
|
|
243127
|
+
abortSignal: recallAbortController.signal
|
|
243128
|
+
}).catch((error40) => {
|
|
243129
|
+
if (error40 instanceof DOMException && error40.name === "AbortError") {
|
|
243130
|
+
debugLogger61.debug(
|
|
243131
|
+
"Auto-memory recall aborted by deadline.",
|
|
243132
|
+
error40
|
|
243133
|
+
);
|
|
243134
|
+
} else {
|
|
243135
|
+
debugLogger61.warn(
|
|
243136
|
+
"Managed auto-memory recall prefetch failed.",
|
|
243137
|
+
error40
|
|
243138
|
+
);
|
|
243139
|
+
}
|
|
243140
|
+
return EMPTY_RELEVANT_AUTO_MEMORY_RESULT;
|
|
243141
|
+
});
|
|
243142
|
+
this.pendingRecallAbortController = recallAbortController;
|
|
243143
|
+
relevantAutoMemoryPromise = resolveAutoMemoryWithDeadline(
|
|
243144
|
+
rawRecallPromise,
|
|
243145
|
+
() => recallAbortController.abort()
|
|
243146
|
+
);
|
|
243147
|
+
}
|
|
243148
|
+
const attributionService = CommitAttributionService.getInstance();
|
|
243149
|
+
if (messageType === "userQuery" /* UserQuery */) {
|
|
243150
|
+
attributionService.incrementPromptCount();
|
|
243151
|
+
}
|
|
243152
|
+
if (messageType === "cron" /* Cron */) {
|
|
243153
|
+
this.config.getChatRecordingService()?.recordCronPrompt(request4, options2?.notificationDisplayText);
|
|
243154
|
+
} else {
|
|
243155
|
+
this.config.getChatRecordingService()?.recordUserMessage(request4);
|
|
243156
|
+
}
|
|
243157
|
+
const mcResult = microcompactHistory(
|
|
243158
|
+
this.getChat().getHistory(),
|
|
243159
|
+
this.lastApiCompletionTimestamp,
|
|
243160
|
+
this.config.getClearContextOnIdle()
|
|
242845
243161
|
);
|
|
243162
|
+
if (mcResult.meta) {
|
|
243163
|
+
this.getChat().setHistory(mcResult.history);
|
|
243164
|
+
debugLogger61.debug("[FILE_READ_CACHE] clear after microcompaction");
|
|
243165
|
+
this.config.getFileReadCache().clear();
|
|
243166
|
+
const m3 = mcResult.meta;
|
|
243167
|
+
debugLogger61.debug(
|
|
243168
|
+
`[TIME-BASED MC] gap ${m3.gapMinutes}min > ${m3.thresholdMinutes}min, cleared ${m3.toolsCleared} tool results (~${m3.tokensSaved} tokens), kept last ${m3.toolsKept}`
|
|
243169
|
+
);
|
|
243170
|
+
}
|
|
242846
243171
|
}
|
|
242847
|
-
|
|
242848
|
-
|
|
242849
|
-
|
|
242850
|
-
}
|
|
242851
|
-
if (messageType === "cron" /* Cron */) {
|
|
242852
|
-
this.config.getChatRecordingService()?.recordCronPrompt(request4, options2?.notificationDisplayText);
|
|
242853
|
-
} else {
|
|
242854
|
-
this.config.getChatRecordingService()?.recordUserMessage(request4);
|
|
242855
|
-
}
|
|
242856
|
-
const mcResult = microcompactHistory(
|
|
242857
|
-
this.getChat().getHistory(),
|
|
242858
|
-
this.lastApiCompletionTimestamp,
|
|
242859
|
-
this.config.getClearContextOnIdle()
|
|
242860
|
-
);
|
|
242861
|
-
if (mcResult.meta) {
|
|
242862
|
-
this.getChat().setHistory(mcResult.history);
|
|
242863
|
-
debugLogger61.debug("[FILE_READ_CACHE] clear after microcompaction");
|
|
242864
|
-
this.config.getFileReadCache().clear();
|
|
242865
|
-
const m3 = mcResult.meta;
|
|
242866
|
-
debugLogger61.debug(
|
|
242867
|
-
`[TIME-BASED MC] gap ${m3.gapMinutes}min > ${m3.thresholdMinutes}min, cleared ${m3.toolsCleared} tool results (~${m3.tokensSaved} tokens), kept last ${m3.toolsKept}`
|
|
243172
|
+
if (messageType !== "retry" /* Retry */) {
|
|
243173
|
+
this.config.getChatRecordingService()?.recordAttributionSnapshot(
|
|
243174
|
+
CommitAttributionService.getInstance().toSnapshot()
|
|
242868
243175
|
);
|
|
243176
|
+
this.sessionTurnCount++;
|
|
243177
|
+
if (this.config.getMaxSessionTurns() > 0 && this.sessionTurnCount > this.config.getMaxSessionTurns()) {
|
|
243178
|
+
this.pendingRecallAbortController?.abort();
|
|
243179
|
+
this.pendingRecallAbortController = void 0;
|
|
243180
|
+
yield { type: "max_session_turns" /* MaxSessionTurns */ };
|
|
243181
|
+
if (isTopLevelInteraction)
|
|
243182
|
+
endInteractionSpan("error", {
|
|
243183
|
+
errorMessage: "max session turns exceeded"
|
|
243184
|
+
});
|
|
243185
|
+
return new Turn(this.getChat(), prompt_id);
|
|
243186
|
+
}
|
|
242869
243187
|
}
|
|
242870
|
-
|
|
242871
|
-
|
|
242872
|
-
this.config.getChatRecordingService()?.recordAttributionSnapshot(
|
|
242873
|
-
CommitAttributionService.getInstance().toSnapshot()
|
|
242874
|
-
);
|
|
242875
|
-
this.sessionTurnCount++;
|
|
242876
|
-
if (this.config.getMaxSessionTurns() > 0 && this.sessionTurnCount > this.config.getMaxSessionTurns()) {
|
|
242877
|
-
this.pendingRecallAbortController?.abort();
|
|
242878
|
-
this.pendingRecallAbortController = void 0;
|
|
242879
|
-
yield { type: "max_session_turns" /* MaxSessionTurns */ };
|
|
242880
|
-
return new Turn(this.getChat(), prompt_id);
|
|
242881
|
-
}
|
|
242882
|
-
}
|
|
242883
|
-
const boundedTurns = Math.min(turns, MAX_TURNS2);
|
|
242884
|
-
if (!boundedTurns) {
|
|
242885
|
-
this.pendingRecallAbortController?.abort();
|
|
242886
|
-
this.pendingRecallAbortController = void 0;
|
|
242887
|
-
return new Turn(this.getChat(), prompt_id);
|
|
242888
|
-
}
|
|
242889
|
-
const sessionTokenLimit = this.config.getSessionTokenLimit();
|
|
242890
|
-
if (sessionTokenLimit > 0) {
|
|
242891
|
-
const lastPromptTokenCount = uiTelemetryService.getLastPromptTokenCount();
|
|
242892
|
-
if (lastPromptTokenCount > sessionTokenLimit) {
|
|
243188
|
+
const boundedTurns = Math.min(turns, MAX_TURNS2);
|
|
243189
|
+
if (!boundedTurns) {
|
|
242893
243190
|
this.pendingRecallAbortController?.abort();
|
|
242894
243191
|
this.pendingRecallAbortController = void 0;
|
|
242895
|
-
|
|
242896
|
-
|
|
242897
|
-
value: {
|
|
242898
|
-
currentTokens: lastPromptTokenCount,
|
|
242899
|
-
limit: sessionTokenLimit,
|
|
242900
|
-
message: `Session token limit exceeded: ${lastPromptTokenCount} tokens > ${sessionTokenLimit} limit. Please start a new session or increase the sessionTokenLimit in your settings.json.`
|
|
242901
|
-
}
|
|
242902
|
-
};
|
|
243192
|
+
if (isTopLevelInteraction)
|
|
243193
|
+
endInteractionSpan("error", { errorMessage: "max turns exhausted" });
|
|
242903
243194
|
return new Turn(this.getChat(), prompt_id);
|
|
242904
243195
|
}
|
|
242905
|
-
|
|
242906
|
-
|
|
242907
|
-
|
|
242908
|
-
|
|
242909
|
-
|
|
242910
|
-
|
|
242911
|
-
|
|
242912
|
-
|
|
242913
|
-
|
|
242914
|
-
|
|
242915
|
-
|
|
242916
|
-
|
|
242917
|
-
|
|
243196
|
+
const sessionTokenLimit = this.config.getSessionTokenLimit();
|
|
243197
|
+
if (sessionTokenLimit > 0) {
|
|
243198
|
+
const lastPromptTokenCount = uiTelemetryService.getLastPromptTokenCount();
|
|
243199
|
+
if (lastPromptTokenCount > sessionTokenLimit) {
|
|
243200
|
+
this.pendingRecallAbortController?.abort();
|
|
243201
|
+
this.pendingRecallAbortController = void 0;
|
|
243202
|
+
yield {
|
|
243203
|
+
type: "session_token_limit_exceeded" /* SessionTokenLimitExceeded */,
|
|
243204
|
+
value: {
|
|
243205
|
+
currentTokens: lastPromptTokenCount,
|
|
243206
|
+
limit: sessionTokenLimit,
|
|
243207
|
+
message: `Session token limit exceeded: ${lastPromptTokenCount} tokens > ${sessionTokenLimit} limit. Please start a new session or increase the sessionTokenLimit in your settings.json.`
|
|
243208
|
+
}
|
|
243209
|
+
};
|
|
243210
|
+
if (isTopLevelInteraction)
|
|
243211
|
+
endInteractionSpan("error", {
|
|
243212
|
+
errorMessage: "session token limit exceeded"
|
|
243213
|
+
});
|
|
243214
|
+
return new Turn(this.getChat(), prompt_id);
|
|
243215
|
+
}
|
|
242918
243216
|
}
|
|
242919
|
-
|
|
242920
|
-
|
|
242921
|
-
|
|
242922
|
-
|
|
242923
|
-
|
|
242924
|
-
|
|
242925
|
-
if (controlSignal) {
|
|
242926
|
-
debugLogger61.info(
|
|
242927
|
-
`Arena control signal received: ${controlSignal.type} - ${controlSignal.reason}`
|
|
243217
|
+
const history = this.getHistory();
|
|
243218
|
+
const lastMessage = history.length > 0 ? history[history.length - 1] : void 0;
|
|
243219
|
+
const hasPendingToolCall = !!lastMessage && lastMessage.role === "model" && (lastMessage.parts?.some((p2) => "functionCall" in p2) || false);
|
|
243220
|
+
if (this.config.getIdeMode() && !hasPendingToolCall) {
|
|
243221
|
+
const { contextParts, newIdeContext } = this.getIdeContextParts(
|
|
243222
|
+
this.forceFullIdeContext || history.length === 0
|
|
242928
243223
|
);
|
|
242929
|
-
|
|
242930
|
-
|
|
242931
|
-
|
|
242932
|
-
|
|
243224
|
+
if (contextParts.length > 0) {
|
|
243225
|
+
this.getChat().addHistory({
|
|
243226
|
+
role: "user",
|
|
243227
|
+
parts: [{ text: contextParts.join("\n") }]
|
|
243228
|
+
});
|
|
243229
|
+
}
|
|
243230
|
+
this.lastSentIdeContext = newIdeContext;
|
|
243231
|
+
this.forceFullIdeContext = false;
|
|
242933
243232
|
}
|
|
242934
|
-
|
|
242935
|
-
|
|
242936
|
-
|
|
242937
|
-
|
|
242938
|
-
|
|
242939
|
-
|
|
242940
|
-
|
|
242941
|
-
|
|
242942
|
-
|
|
242943
|
-
|
|
242944
|
-
|
|
242945
|
-
|
|
242946
|
-
|
|
242947
|
-
}
|
|
242948
|
-
}
|
|
242949
|
-
const hasAgentTool = await this.config.getToolRegistry().ensureTool(ToolNames.AGENT);
|
|
242950
|
-
const subagents = (await this.config.getSubagentManager().listSubagents()).filter((subagent) => subagent.level !== "builtin").map((subagent) => subagent.name);
|
|
242951
|
-
if (hasAgentTool && subagents.length > 0) {
|
|
242952
|
-
systemReminders.push(getSubagentSystemReminder(subagents));
|
|
242953
|
-
}
|
|
242954
|
-
if (this.config.getApprovalMode() === "plan" /* PLAN */) {
|
|
242955
|
-
systemReminders.push(
|
|
242956
|
-
getPlanModeSystemReminder(this.config.getSdkMode())
|
|
242957
|
-
);
|
|
243233
|
+
const arenaAgentClient = this.config.getArenaAgentClient();
|
|
243234
|
+
if (arenaAgentClient) {
|
|
243235
|
+
const controlSignal = await arenaAgentClient.checkControlSignal();
|
|
243236
|
+
if (controlSignal) {
|
|
243237
|
+
debugLogger61.info(
|
|
243238
|
+
`Arena control signal received: ${controlSignal.type} - ${controlSignal.reason}`
|
|
243239
|
+
);
|
|
243240
|
+
await arenaAgentClient.reportCancelled();
|
|
243241
|
+
this.pendingRecallAbortController?.abort();
|
|
243242
|
+
this.pendingRecallAbortController = void 0;
|
|
243243
|
+
if (isTopLevelInteraction) endInteractionSpan("cancelled");
|
|
243244
|
+
return new Turn(this.getChat(), prompt_id);
|
|
243245
|
+
}
|
|
242958
243246
|
}
|
|
242959
|
-
const
|
|
242960
|
-
|
|
242961
|
-
|
|
242962
|
-
|
|
242963
|
-
|
|
242964
|
-
|
|
242965
|
-
|
|
243247
|
+
const turn = new Turn(this.getChat(), prompt_id);
|
|
243248
|
+
const model = options2?.modelOverride ?? this.config.getModel();
|
|
243249
|
+
let requestToSent = await flatMapTextParts(request4, async (text) => [
|
|
243250
|
+
text
|
|
243251
|
+
]);
|
|
243252
|
+
if (messageType === "userQuery" /* UserQuery */ || messageType === "cron" /* Cron */) {
|
|
243253
|
+
const systemReminders = [];
|
|
243254
|
+
this.pendingRecallAbortController = void 0;
|
|
243255
|
+
const relevantAutoMemory = relevantAutoMemoryPromise ? await relevantAutoMemoryPromise : EMPTY_RELEVANT_AUTO_MEMORY_RESULT;
|
|
243256
|
+
const relevantAutoMemoryPrompt = relevantAutoMemory.prompt;
|
|
243257
|
+
if (relevantAutoMemoryPrompt) {
|
|
243258
|
+
systemReminders.push(relevantAutoMemoryPrompt);
|
|
243259
|
+
for (const doc of relevantAutoMemory.selectedDocs) {
|
|
243260
|
+
this.surfacedRelevantAutoMemoryPaths.add(doc.filePath);
|
|
243261
|
+
}
|
|
243262
|
+
}
|
|
243263
|
+
const hasAgentTool = await this.config.getToolRegistry().ensureTool(ToolNames.AGENT);
|
|
243264
|
+
const subagents = (await this.config.getSubagentManager().listSubagents()).filter((subagent) => subagent.level !== "builtin").map((subagent) => subagent.name);
|
|
243265
|
+
if (hasAgentTool && subagents.length > 0) {
|
|
243266
|
+
systemReminders.push(getSubagentSystemReminder(subagents));
|
|
243267
|
+
}
|
|
243268
|
+
if (this.config.getApprovalMode() === "plan" /* PLAN */) {
|
|
243269
|
+
systemReminders.push(
|
|
243270
|
+
getPlanModeSystemReminder(this.config.getSdkMode())
|
|
243271
|
+
);
|
|
243272
|
+
}
|
|
243273
|
+
const arenaManager = this.config.getArenaManager();
|
|
243274
|
+
if (arenaManager) {
|
|
243275
|
+
try {
|
|
243276
|
+
const sessionDir = arenaManager.getArenaSessionDir();
|
|
243277
|
+
const configPath = `${sessionDir}/config.json`;
|
|
243278
|
+
systemReminders.push(getArenaSystemReminder(configPath));
|
|
243279
|
+
} catch {
|
|
243280
|
+
}
|
|
242966
243281
|
}
|
|
243282
|
+
requestToSent = [...systemReminders, ...requestToSent];
|
|
242967
243283
|
}
|
|
242968
|
-
|
|
242969
|
-
|
|
242970
|
-
|
|
242971
|
-
|
|
242972
|
-
|
|
242973
|
-
|
|
242974
|
-
|
|
242975
|
-
|
|
242976
|
-
|
|
242977
|
-
|
|
242978
|
-
|
|
243284
|
+
const resultStream = turn.run(model, requestToSent, signal);
|
|
243285
|
+
for await (const event of resultStream) {
|
|
243286
|
+
if (!this.config.getSkipLoopDetection()) {
|
|
243287
|
+
if (this.loopDetector.addAndCheck(event)) {
|
|
243288
|
+
const loopType = this.loopDetector.getLastLoopType();
|
|
243289
|
+
yield {
|
|
243290
|
+
type: "loop_detected" /* LoopDetected */,
|
|
243291
|
+
...loopType && { value: { loopType } }
|
|
243292
|
+
};
|
|
243293
|
+
if (arenaAgentClient) {
|
|
243294
|
+
await arenaAgentClient.reportError("Loop detected");
|
|
243295
|
+
}
|
|
243296
|
+
this.lastApiCompletionTimestamp = Date.now();
|
|
243297
|
+
if (isTopLevelInteraction)
|
|
243298
|
+
endInteractionSpan("error", { errorMessage: "loop detected" });
|
|
243299
|
+
return turn;
|
|
243300
|
+
}
|
|
243301
|
+
}
|
|
243302
|
+
if (arenaAgentClient && event.type === "finished" /* Finished */) {
|
|
243303
|
+
await arenaAgentClient.updateStatus();
|
|
243304
|
+
}
|
|
243305
|
+
if (event.type === "chat_compressed" /* ChatCompressed */) {
|
|
243306
|
+
this.forceFullIdeContext = true;
|
|
243307
|
+
}
|
|
243308
|
+
yield event;
|
|
243309
|
+
if (event.type === "error" /* Error */) {
|
|
242979
243310
|
if (arenaAgentClient) {
|
|
242980
|
-
|
|
243311
|
+
const errorMsg = event.value instanceof Error ? event.value.message : "Unknown error";
|
|
243312
|
+
await arenaAgentClient.reportError(errorMsg);
|
|
242981
243313
|
}
|
|
242982
243314
|
this.lastApiCompletionTimestamp = Date.now();
|
|
243315
|
+
if (isTopLevelInteraction) {
|
|
243316
|
+
const errMsg = event.value instanceof Error ? "[API error]" : "unknown error";
|
|
243317
|
+
endInteractionSpan("error", { errorMessage: errMsg });
|
|
243318
|
+
}
|
|
242983
243319
|
return turn;
|
|
242984
243320
|
}
|
|
242985
243321
|
}
|
|
242986
|
-
|
|
242987
|
-
|
|
242988
|
-
|
|
242989
|
-
|
|
242990
|
-
|
|
242991
|
-
|
|
242992
|
-
|
|
242993
|
-
|
|
242994
|
-
|
|
242995
|
-
|
|
242996
|
-
|
|
242997
|
-
|
|
242998
|
-
|
|
242999
|
-
|
|
243000
|
-
}
|
|
243001
|
-
}
|
|
243002
|
-
this.lastApiCompletionTimestamp = Date.now();
|
|
243003
|
-
if (hooksEnabled && messageBus && !turn.pendingToolCalls.length && signal && !signal.aborted && this.config.hasHooksForEvent("Stop")) {
|
|
243004
|
-
const history2 = this.getHistory();
|
|
243005
|
-
const lastModelMessage = history2.filter((msg) => msg.role === "model").pop();
|
|
243006
|
-
const responseText = lastModelMessage?.parts?.filter((p2) => "text" in p2).map((p2) => p2.text).join("") || "[no response text]";
|
|
243007
|
-
const response = await messageBus.request(
|
|
243008
|
-
{
|
|
243009
|
-
type: "hook-execution-request" /* HOOK_EXECUTION_REQUEST */,
|
|
243010
|
-
eventName: "Stop",
|
|
243011
|
-
input: {
|
|
243012
|
-
stop_hook_active: true,
|
|
243013
|
-
last_assistant_message: responseText
|
|
243322
|
+
this.lastApiCompletionTimestamp = Date.now();
|
|
243323
|
+
if (hooksEnabled && messageBus && !turn.pendingToolCalls.length && signal && !signal.aborted && this.config.hasHooksForEvent("Stop")) {
|
|
243324
|
+
const history2 = this.getHistory();
|
|
243325
|
+
const lastModelMessage = history2.filter((msg) => msg.role === "model").pop();
|
|
243326
|
+
const responseText = lastModelMessage?.parts?.filter((p2) => "text" in p2).map((p2) => p2.text).join("") || "[no response text]";
|
|
243327
|
+
const response = await messageBus.request(
|
|
243328
|
+
{
|
|
243329
|
+
type: "hook-execution-request" /* HOOK_EXECUTION_REQUEST */,
|
|
243330
|
+
eventName: "Stop",
|
|
243331
|
+
input: {
|
|
243332
|
+
stop_hook_active: true,
|
|
243333
|
+
last_assistant_message: responseText
|
|
243334
|
+
},
|
|
243335
|
+
signal
|
|
243014
243336
|
},
|
|
243015
|
-
|
|
243016
|
-
|
|
243017
|
-
"hook-execution-response" /* HOOK_EXECUTION_RESPONSE */
|
|
243018
|
-
);
|
|
243019
|
-
if (signal.aborted) {
|
|
243020
|
-
return turn;
|
|
243021
|
-
}
|
|
243022
|
-
const hookOutput = response.output ? createHookOutput("Stop", response.output) : void 0;
|
|
243023
|
-
const stopOutput = hookOutput;
|
|
243024
|
-
if (stopOutput?.systemMessage) {
|
|
243025
|
-
yield {
|
|
243026
|
-
type: "hook_system_message" /* HookSystemMessage */,
|
|
243027
|
-
value: stopOutput.systemMessage
|
|
243028
|
-
};
|
|
243029
|
-
}
|
|
243030
|
-
if (stopOutput?.isBlockingDecision() || stopOutput?.shouldStopExecution()) {
|
|
243337
|
+
"hook-execution-response" /* HOOK_EXECUTION_RESPONSE */
|
|
243338
|
+
);
|
|
243031
243339
|
if (signal.aborted) {
|
|
243340
|
+
if (isTopLevelInteraction) endInteractionSpan("cancelled");
|
|
243032
243341
|
return turn;
|
|
243033
243342
|
}
|
|
243034
|
-
const
|
|
243035
|
-
const
|
|
243036
|
-
|
|
243037
|
-
...options2?.stopHookState?.reasons ?? [],
|
|
243038
|
-
continueReason
|
|
243039
|
-
];
|
|
243040
|
-
if (currentIterationCount > 1) {
|
|
243343
|
+
const hookOutput = response.output ? createHookOutput("Stop", response.output) : void 0;
|
|
243344
|
+
const stopOutput = hookOutput;
|
|
243345
|
+
if (stopOutput?.systemMessage) {
|
|
243041
243346
|
yield {
|
|
243042
|
-
type: "
|
|
243043
|
-
value:
|
|
243044
|
-
iterationCount: currentIterationCount,
|
|
243045
|
-
reasons: currentReasons,
|
|
243046
|
-
stopHookCount: response.stopHookCount ?? 1
|
|
243047
|
-
}
|
|
243347
|
+
type: "hook_system_message" /* HookSystemMessage */,
|
|
243348
|
+
value: stopOutput.systemMessage
|
|
243048
243349
|
};
|
|
243049
243350
|
}
|
|
243050
|
-
|
|
243051
|
-
|
|
243052
|
-
|
|
243351
|
+
if (stopOutput?.isBlockingDecision() || stopOutput?.shouldStopExecution()) {
|
|
243352
|
+
if (signal.aborted) {
|
|
243353
|
+
if (isTopLevelInteraction) endInteractionSpan("cancelled");
|
|
243354
|
+
return turn;
|
|
243355
|
+
}
|
|
243356
|
+
const continueReason = stopOutput.getEffectiveReason();
|
|
243357
|
+
const currentIterationCount = (options2?.stopHookState?.iterationCount ?? 0) + 1;
|
|
243358
|
+
const currentReasons = [
|
|
243359
|
+
...options2?.stopHookState?.reasons ?? [],
|
|
243360
|
+
continueReason
|
|
243361
|
+
];
|
|
243362
|
+
if (currentIterationCount > 1) {
|
|
243363
|
+
yield {
|
|
243364
|
+
type: "stop_hook_loop" /* StopHookLoop */,
|
|
243365
|
+
value: {
|
|
243366
|
+
iterationCount: currentIterationCount,
|
|
243367
|
+
reasons: currentReasons,
|
|
243368
|
+
stopHookCount: response.stopHookCount ?? 1
|
|
243369
|
+
}
|
|
243370
|
+
};
|
|
243371
|
+
}
|
|
243372
|
+
const continueRequest = [{ text: continueReason }];
|
|
243373
|
+
const hookTurn = yield* this.sendMessageStream(
|
|
243374
|
+
continueRequest,
|
|
243375
|
+
signal,
|
|
243376
|
+
prompt_id,
|
|
243377
|
+
{
|
|
243378
|
+
type: "hook" /* Hook */,
|
|
243379
|
+
modelOverride: options2?.modelOverride,
|
|
243380
|
+
stopHookState: {
|
|
243381
|
+
iterationCount: currentIterationCount,
|
|
243382
|
+
reasons: currentReasons
|
|
243383
|
+
}
|
|
243384
|
+
},
|
|
243385
|
+
boundedTurns - 1
|
|
243386
|
+
);
|
|
243387
|
+
if (isTopLevelInteraction)
|
|
243388
|
+
endInteractionSpan(signal.aborted ? "cancelled" : "ok");
|
|
243389
|
+
return hookTurn;
|
|
243390
|
+
}
|
|
243391
|
+
}
|
|
243392
|
+
if (!turn.pendingToolCalls.length && signal && !signal.aborted) {
|
|
243393
|
+
try {
|
|
243394
|
+
const chat = this.getChat();
|
|
243395
|
+
const fullHistory = chat.getHistory(true);
|
|
243396
|
+
const maxHistoryForCache = 40;
|
|
243397
|
+
const cachedHistory = fullHistory.length > maxHistoryForCache ? fullHistory.slice(-maxHistoryForCache) : fullHistory;
|
|
243398
|
+
saveCacheSafeParams(
|
|
243399
|
+
chat.getGenerationConfig(),
|
|
243400
|
+
cachedHistory,
|
|
243401
|
+
this.config.getModel()
|
|
243402
|
+
);
|
|
243403
|
+
} catch {
|
|
243404
|
+
}
|
|
243405
|
+
if (this.config.getSkipNextSpeakerCheck()) {
|
|
243406
|
+
this.runManagedAutoMemoryBackgroundTasks(messageType);
|
|
243407
|
+
if (arenaAgentClient) {
|
|
243408
|
+
await arenaAgentClient.reportCompleted();
|
|
243409
|
+
}
|
|
243410
|
+
if (isTopLevelInteraction) endInteractionSpan("ok");
|
|
243411
|
+
return turn;
|
|
243412
|
+
}
|
|
243413
|
+
const nextSpeakerCheck = await checkNextSpeaker(
|
|
243414
|
+
this.getChat(),
|
|
243415
|
+
this.config,
|
|
243053
243416
|
signal,
|
|
243054
|
-
prompt_id
|
|
243055
|
-
{
|
|
243056
|
-
type: "hook" /* Hook */,
|
|
243057
|
-
modelOverride: options2?.modelOverride,
|
|
243058
|
-
stopHookState: {
|
|
243059
|
-
iterationCount: currentIterationCount,
|
|
243060
|
-
reasons: currentReasons
|
|
243061
|
-
}
|
|
243062
|
-
},
|
|
243063
|
-
boundedTurns - 1
|
|
243417
|
+
prompt_id
|
|
243064
243418
|
);
|
|
243065
|
-
|
|
243066
|
-
|
|
243067
|
-
|
|
243068
|
-
|
|
243069
|
-
|
|
243070
|
-
|
|
243071
|
-
|
|
243072
|
-
const cachedHistory = fullHistory.length > maxHistoryForCache ? fullHistory.slice(-maxHistoryForCache) : fullHistory;
|
|
243073
|
-
saveCacheSafeParams(
|
|
243074
|
-
chat.getGenerationConfig(),
|
|
243075
|
-
cachedHistory,
|
|
243076
|
-
this.config.getModel()
|
|
243419
|
+
logNextSpeakerCheck(
|
|
243420
|
+
this.config,
|
|
243421
|
+
new NextSpeakerCheckEvent(
|
|
243422
|
+
prompt_id,
|
|
243423
|
+
turn.finishReason?.toString() || "",
|
|
243424
|
+
nextSpeakerCheck?.next_speaker || ""
|
|
243425
|
+
)
|
|
243077
243426
|
);
|
|
243078
|
-
|
|
243079
|
-
|
|
243080
|
-
|
|
243427
|
+
if (nextSpeakerCheck?.next_speaker === "model") {
|
|
243428
|
+
const nextRequest = [{ text: "Please continue." }];
|
|
243429
|
+
const continueTurn = yield* this.sendMessageStream(
|
|
243430
|
+
nextRequest,
|
|
243431
|
+
signal,
|
|
243432
|
+
prompt_id,
|
|
243433
|
+
{ ...options2, type: "hook" /* Hook */ },
|
|
243434
|
+
boundedTurns - 1
|
|
243435
|
+
);
|
|
243436
|
+
if (isTopLevelInteraction)
|
|
243437
|
+
endInteractionSpan(signal.aborted ? "cancelled" : "ok");
|
|
243438
|
+
return continueTurn;
|
|
243439
|
+
}
|
|
243081
243440
|
this.runManagedAutoMemoryBackgroundTasks(messageType);
|
|
243082
243441
|
if (arenaAgentClient) {
|
|
243083
243442
|
await arenaAgentClient.reportCompleted();
|
|
243084
243443
|
}
|
|
243085
|
-
return turn;
|
|
243086
243444
|
}
|
|
243087
|
-
|
|
243088
|
-
|
|
243089
|
-
this.config,
|
|
243090
|
-
signal,
|
|
243091
|
-
prompt_id
|
|
243092
|
-
);
|
|
243093
|
-
logNextSpeakerCheck(
|
|
243094
|
-
this.config,
|
|
243095
|
-
new NextSpeakerCheckEvent(
|
|
243096
|
-
prompt_id,
|
|
243097
|
-
turn.finishReason?.toString() || "",
|
|
243098
|
-
nextSpeakerCheck?.next_speaker || ""
|
|
243099
|
-
)
|
|
243100
|
-
);
|
|
243101
|
-
if (nextSpeakerCheck?.next_speaker === "model") {
|
|
243102
|
-
const nextRequest = [{ text: "Please continue." }];
|
|
243103
|
-
return yield* this.sendMessageStream(
|
|
243104
|
-
nextRequest,
|
|
243105
|
-
signal,
|
|
243106
|
-
prompt_id,
|
|
243107
|
-
options2,
|
|
243108
|
-
boundedTurns - 1
|
|
243109
|
-
);
|
|
243445
|
+
if (signal?.aborted && arenaAgentClient) {
|
|
243446
|
+
await arenaAgentClient.reportCancelled();
|
|
243110
243447
|
}
|
|
243111
|
-
|
|
243112
|
-
|
|
243113
|
-
|
|
243448
|
+
if (isTopLevelInteraction) {
|
|
243449
|
+
endInteractionSpan(signal?.aborted ? "cancelled" : "ok");
|
|
243450
|
+
}
|
|
243451
|
+
return turn;
|
|
243452
|
+
} finally {
|
|
243453
|
+
if (isTopLevelInteraction) {
|
|
243454
|
+
endInteractionSpan(signal?.aborted ? "cancelled" : "error", {
|
|
243455
|
+
errorMessage: "unexpected exit"
|
|
243456
|
+
});
|
|
243114
243457
|
}
|
|
243115
243458
|
}
|
|
243116
|
-
if (signal?.aborted && arenaAgentClient) {
|
|
243117
|
-
await arenaAgentClient.reportCancelled();
|
|
243118
|
-
}
|
|
243119
|
-
return turn;
|
|
243120
243459
|
}
|
|
243121
243460
|
async generateContent(contents, generationConfig, abortSignal, model, promptIdOverride) {
|
|
243122
243461
|
const promptId = promptIdOverride ?? promptIdContext.getStore() ?? this.lastPromptId;
|
|
@@ -319265,6 +319604,7 @@ __export(src_exports2, {
|
|
|
319265
319604
|
clearCachedCredentialFile: () => clearCachedCredentialFile,
|
|
319266
319605
|
clearQwenCredentials: () => clearQwenCredentials,
|
|
319267
319606
|
clearRuntimeStatus: () => clearRuntimeStatus,
|
|
319607
|
+
clearSessionTracingForTesting: () => clearSessionTracingForTesting,
|
|
319268
319608
|
clearWelcomeBackState: () => clearWelcomeBackState,
|
|
319269
319609
|
cliSource: () => cliSource,
|
|
319270
319610
|
cloneFromGit: () => cloneFromGit,
|
|
@@ -319313,6 +319653,10 @@ __export(src_exports2, {
|
|
|
319313
319653
|
encodeInsightProgressMessage: () => encodeInsightProgressMessage,
|
|
319314
319654
|
encodeInsightReadyMessage: () => encodeInsightReadyMessage,
|
|
319315
319655
|
encodeTagName: () => encodeTagName,
|
|
319656
|
+
endInteractionSpan: () => endInteractionSpan,
|
|
319657
|
+
endLLMRequestSpan: () => endLLMRequestSpan,
|
|
319658
|
+
endToolExecutionSpan: () => endToolExecutionSpan,
|
|
319659
|
+
endToolSpan: () => endToolSpan,
|
|
319316
319660
|
ensureAutoMemoryScaffold: () => ensureAutoMemoryScaffold,
|
|
319317
319661
|
ensureCrlfLineEndings: () => ensureCrlfLineEndings,
|
|
319318
319662
|
ensureMacBinarySigned: () => ensureMacBinarySigned,
|
|
@@ -319662,7 +320006,11 @@ __export(src_exports2, {
|
|
|
319662
320006
|
splitCommands: () => splitCommands,
|
|
319663
320007
|
splitCompoundCommand: () => splitCompoundCommand,
|
|
319664
320008
|
splitConditionalSkills: () => splitConditionalSkills,
|
|
320009
|
+
startInteractionSpan: () => startInteractionSpan,
|
|
320010
|
+
startLLMRequestSpan: () => startLLMRequestSpan,
|
|
319665
320011
|
startSpeculation: () => startSpeculation,
|
|
320012
|
+
startToolExecutionSpan: () => startToolExecutionSpan,
|
|
320013
|
+
startToolSpan: () => startToolSpan,
|
|
319666
320014
|
stringify: () => stringify2,
|
|
319667
320015
|
stripShellWrapper: () => stripShellWrapper,
|
|
319668
320016
|
stripStartupContext: () => stripStartupContext,
|
|
@@ -470165,7 +470513,7 @@ var patchConsole = /* @__PURE__ */ __name((callback) => {
|
|
|
470165
470513
|
var dist_default2 = patchConsole;
|
|
470166
470514
|
|
|
470167
470515
|
// node_modules/ink/build/ink.js
|
|
470168
|
-
var
|
|
470516
|
+
var import_constants38 = __toESM(require_constants12(), 1);
|
|
470169
470517
|
|
|
470170
470518
|
// node_modules/yoga-layout/dist/src/index.js
|
|
470171
470519
|
init_esbuild_shims();
|
|
@@ -472408,7 +472756,7 @@ var isDev = /* @__PURE__ */ __name(() => process17.env["DEV"] === "true", "isDev
|
|
|
472408
472756
|
// node_modules/ink/build/reconciler.js
|
|
472409
472757
|
init_esbuild_shims();
|
|
472410
472758
|
var import_react_reconciler = __toESM(require_react_reconciler(), 1);
|
|
472411
|
-
var
|
|
472759
|
+
var import_constants37 = __toESM(require_constants12(), 1);
|
|
472412
472760
|
var Scheduler2 = __toESM(require_scheduler(), 1);
|
|
472413
472761
|
var import_react = __toESM(require_react(), 1);
|
|
472414
472762
|
|
|
@@ -474687,7 +475035,7 @@ var cleanupYogaNode = /* @__PURE__ */ __name((node) => {
|
|
|
474687
475035
|
node?.unsetMeasureFunc();
|
|
474688
475036
|
node?.freeRecursive();
|
|
474689
475037
|
}, "cleanupYogaNode");
|
|
474690
|
-
var currentUpdatePriority =
|
|
475038
|
+
var currentUpdatePriority = import_constants37.NoEventPriority;
|
|
474691
475039
|
var currentRootNode;
|
|
474692
475040
|
async function loadPackageJson() {
|
|
474693
475041
|
const fs154 = await import("node:fs");
|
|
@@ -474859,10 +475207,10 @@ var reconciler_default = (0, import_react_reconciler.default)({
|
|
|
474859
475207
|
},
|
|
474860
475208
|
getCurrentUpdatePriority: /* @__PURE__ */ __name(() => currentUpdatePriority, "getCurrentUpdatePriority"),
|
|
474861
475209
|
resolveUpdatePriority() {
|
|
474862
|
-
if (currentUpdatePriority !==
|
|
475210
|
+
if (currentUpdatePriority !== import_constants37.NoEventPriority) {
|
|
474863
475211
|
return currentUpdatePriority;
|
|
474864
475212
|
}
|
|
474865
|
-
return
|
|
475213
|
+
return import_constants37.DefaultEventPriority;
|
|
474866
475214
|
},
|
|
474867
475215
|
maySuspendCommit() {
|
|
474868
475216
|
return true;
|
|
@@ -478793,7 +479141,7 @@ var Ink = class {
|
|
|
478793
479141
|
this.lastOutputHeight = 0;
|
|
478794
479142
|
this.lastTerminalWidth = this.getTerminalWidth();
|
|
478795
479143
|
this.fullStaticOutput = "";
|
|
478796
|
-
const rootTag = options2.concurrent ?
|
|
479144
|
+
const rootTag = options2.concurrent ? import_constants38.ConcurrentRoot : import_constants38.LegacyRoot;
|
|
478797
479145
|
this.container = reconciler_default.createContainer(this.rootNode, rootTag, null, false, null, "id", () => {
|
|
478798
479146
|
}, () => {
|
|
478799
479147
|
}, () => {
|
|
@@ -479243,7 +479591,7 @@ var getInstance = /* @__PURE__ */ __name((stdout, createInstance3, concurrent) =
|
|
|
479243
479591
|
|
|
479244
479592
|
// node_modules/ink/build/render-to-string.js
|
|
479245
479593
|
init_esbuild_shims();
|
|
479246
|
-
var
|
|
479594
|
+
var import_constants39 = __toESM(require_constants12(), 1);
|
|
479247
479595
|
|
|
479248
479596
|
// node_modules/ink/build/components/Static.js
|
|
479249
479597
|
init_esbuild_shims();
|
|
@@ -491106,7 +491454,7 @@ __name(getPackageJson, "getPackageJson");
|
|
|
491106
491454
|
// packages/cli/src/utils/version.ts
|
|
491107
491455
|
async function getCliVersion() {
|
|
491108
491456
|
const pkgJson = await getPackageJson();
|
|
491109
|
-
return "0.15.11
|
|
491457
|
+
return "0.15.11";
|
|
491110
491458
|
}
|
|
491111
491459
|
__name(getCliVersion, "getCliVersion");
|
|
491112
491460
|
|
|
@@ -501739,7 +502087,7 @@ var formatDuration = /* @__PURE__ */ __name((milliseconds, options2) => {
|
|
|
501739
502087
|
|
|
501740
502088
|
// packages/cli/src/generated/git-commit.ts
|
|
501741
502089
|
init_esbuild_shims();
|
|
501742
|
-
var GIT_COMMIT_INFO = "
|
|
502090
|
+
var GIT_COMMIT_INFO = "782403d71";
|
|
501743
502091
|
|
|
501744
502092
|
// packages/cli/src/utils/systemInfo.ts
|
|
501745
502093
|
async function getNpmVersion() {
|
|
@@ -585291,7 +585639,7 @@ var QwenAgent = class {
|
|
|
585291
585639
|
async initialize(args2) {
|
|
585292
585640
|
this.clientCapabilities = args2.clientCapabilities;
|
|
585293
585641
|
const authMethods = buildAuthMethods();
|
|
585294
|
-
const version2 = "0.15.11
|
|
585642
|
+
const version2 = "0.15.11";
|
|
585295
585643
|
return {
|
|
585296
585644
|
protocolVersion: PROTOCOL_VERSION,
|
|
585297
585645
|
agentInfo: {
|