Merge tag 'v0.3.0' into chore/sync-gemini-cli-v0.3.0

This commit is contained in:
mingholy.lmh
2025-09-10 21:01:40 +08:00
583 changed files with 30160 additions and 10770 deletions

View File

@@ -8,14 +8,14 @@ import { Buffer } from 'buffer';
import * as https from 'https';
import { HttpsProxyAgent } from 'https-proxy-agent';
import {
import type {
StartSessionEvent,
EndSessionEvent,
UserPromptEvent,
ToolCallEvent,
ApiRequestEvent,
ApiResponseEvent,
ApiErrorEvent,
FileOperationEvent,
FlashFallbackEvent,
LoopDetectedEvent,
NextSpeakerCheckEvent,
@@ -27,8 +27,10 @@ import {
InvalidChunkEvent,
ContentRetryEvent,
ContentRetryFailureEvent,
ConversationFinishedEvent,
} from '../types.js';
import {
import { EndSessionEvent } from '../types.js';
import type {
RumEvent,
RumViewEvent,
RumActionEvent,
@@ -36,10 +38,10 @@ import {
RumExceptionEvent,
RumPayload,
} from './event-types.js';
import { Config } from '../../config/config.js';
import type { Config } from '../../config/config.js';
import { safeJsonStringify } from '../../utils/safeJsonStringify.js';
import { HttpError, retryWithBackoff } from '../../utils/retry.js';
import { getInstallationId } from '../../utils/user_id.js';
import { type HttpError, retryWithBackoff } from '../../utils/retry.js';
import { InstallationManager } from '../../utils/installationManager.js';
import { FixedDeque } from 'mnemonist';
import { AuthType } from '../../core/contentGenerator.js';
@@ -75,6 +77,7 @@ export interface LogResponse {
export class QwenLogger {
private static instance: QwenLogger;
private config?: Config;
private readonly installationManager: InstallationManager;
/**
* Queue of pending events that need to be flushed to the server. New events
@@ -106,6 +109,7 @@ export class QwenLogger {
private constructor(config?: Config) {
this.config = config;
this.events = new FixedDeque<RumEvent>(Array, MAX_EVENTS);
this.installationManager = new InstallationManager();
this.userId = this.generateUserId();
this.sessionId =
typeof this.config?.getSessionId === 'function'
@@ -114,8 +118,9 @@ export class QwenLogger {
}
private generateUserId(): string {
// Use installation ID as user ID for consistency
return `user-${getInstallationId()}`;
// Use InstallationManager to get installationId for userId
const installationId = this.installationManager.getInstallationId();
return `user-${installationId ?? 'unknown'}`;
}
static getInstance(config?: Config): QwenLogger | undefined {
@@ -421,6 +426,29 @@ export class QwenLogger {
this.flushIfNeeded();
}
logFileOperationEvent(event: FileOperationEvent): void {
const rumEvent = this.createActionEvent(
'file_operation',
`file_operation#${event.tool_name}`,
{
properties: {
tool_name: event.tool_name,
operation: event.operation,
lines: event.lines,
mimetype: event.mimetype,
extension: event.extension,
programming_language: event.programming_language,
},
snapshots: event.diff_stat
? JSON.stringify({ diff_stat: event.diff_stat })
: undefined,
},
);
this.enqueueLogEvent(rumEvent);
this.flushIfNeeded();
}
logApiRequestEvent(event: ApiRequestEvent): void {
const rumEvent = this.createResourceEvent('api', 'api_request', {
properties: {
@@ -557,6 +585,22 @@ export class QwenLogger {
this.flushIfNeeded();
}
logConversationFinishedEvent(event: ConversationFinishedEvent): void {
const rumEvent = this.createActionEvent(
'conversation',
'conversation_finished',
{
snapshots: JSON.stringify({
approval_mode: event.approvalMode,
turn_count: event.turnCount,
}),
},
);
this.enqueueLogEvent(rumEvent);
this.flushIfNeeded();
}
logKittySequenceOverflowEvent(event: KittySequenceOverflowEvent): void {
const rumEvent = this.createExceptionEvent(
'overflow',