mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Add privacy notice slash command (#2059)
This commit is contained in:
committed by
GitHub
parent
4fbffdf617
commit
a2a46c7c67
@@ -6,28 +6,30 @@
|
||||
|
||||
import { AuthClient } from 'google-auth-library';
|
||||
import {
|
||||
LoadCodeAssistResponse,
|
||||
CodeAssistGlobalUserSettingResponse,
|
||||
LoadCodeAssistRequest,
|
||||
OnboardUserRequest,
|
||||
LoadCodeAssistResponse,
|
||||
LongrunningOperationResponse,
|
||||
OnboardUserRequest,
|
||||
SetCodeAssistGlobalUserSettingRequest,
|
||||
} from './types.js';
|
||||
import {
|
||||
GenerateContentResponse,
|
||||
GenerateContentParameters,
|
||||
CountTokensParameters,
|
||||
EmbedContentResponse,
|
||||
CountTokensResponse,
|
||||
EmbedContentParameters,
|
||||
EmbedContentResponse,
|
||||
GenerateContentParameters,
|
||||
GenerateContentResponse,
|
||||
} from '@google/genai';
|
||||
import * as readline from 'readline';
|
||||
import { ContentGenerator } from '../core/contentGenerator.js';
|
||||
import {
|
||||
CaCountTokenResponse,
|
||||
CaGenerateContentResponse,
|
||||
toGenerateContentRequest,
|
||||
fromCountTokenResponse,
|
||||
fromGenerateContentResponse,
|
||||
toCountTokenRequest,
|
||||
fromCountTokenResponse,
|
||||
CaCountTokenResponse,
|
||||
toGenerateContentRequest,
|
||||
} from './converter.js';
|
||||
import { PassThrough } from 'node:stream';
|
||||
|
||||
@@ -93,6 +95,21 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
);
|
||||
}
|
||||
|
||||
async getCodeAssistGlobalUserSetting(): Promise<CodeAssistGlobalUserSettingResponse> {
|
||||
return await this.getEndpoint<CodeAssistGlobalUserSettingResponse>(
|
||||
'getCodeAssistGlobalUserSetting',
|
||||
);
|
||||
}
|
||||
|
||||
async setCodeAssistGlobalUserSetting(
|
||||
req: SetCodeAssistGlobalUserSettingRequest,
|
||||
): Promise<CodeAssistGlobalUserSettingResponse> {
|
||||
return await this.callEndpoint<CodeAssistGlobalUserSettingResponse>(
|
||||
'setCodeAssistGlobalUserSetting',
|
||||
req,
|
||||
);
|
||||
}
|
||||
|
||||
async countTokens(req: CountTokensParameters): Promise<CountTokensResponse> {
|
||||
const resp = await this.callEndpoint<CaCountTokenResponse>(
|
||||
'countTokens',
|
||||
@@ -126,6 +143,20 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
return res.data as T;
|
||||
}
|
||||
|
||||
async getEndpoint<T>(method: string, signal?: AbortSignal): Promise<T> {
|
||||
const res = await this.auth.request({
|
||||
url: `${CODE_ASSIST_ENDPOINT}/${CODE_ASSIST_API_VERSION}:${method}`,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...this.httpOptions.headers,
|
||||
},
|
||||
responseType: 'json',
|
||||
signal,
|
||||
});
|
||||
return res.data as T;
|
||||
}
|
||||
|
||||
async streamEndpoint<T>(
|
||||
method: string,
|
||||
req: object,
|
||||
|
||||
@@ -173,3 +173,13 @@ export interface HelpLinkUrl {
|
||||
description: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface SetCodeAssistGlobalUserSettingRequest {
|
||||
cloudaicompanionProject?: string;
|
||||
freeTierDataCollectionOptin: boolean;
|
||||
}
|
||||
|
||||
export interface CodeAssistGlobalUserSettingResponse {
|
||||
cloudaicompanionProject?: string;
|
||||
freeTierDataCollectionOptin: boolean;
|
||||
}
|
||||
|
||||
@@ -226,11 +226,6 @@ export class Config {
|
||||
}
|
||||
|
||||
async refreshAuth(authMethod: AuthType) {
|
||||
// Check if this is actually a switch to a different auth method
|
||||
const previousAuthType = this.contentGeneratorConfig?.authType;
|
||||
const _isAuthMethodSwitch =
|
||||
previousAuthType && previousAuthType !== authMethod;
|
||||
|
||||
// Always use the original default model when switching auth methods
|
||||
// This ensures users don't stay on Flash after switching between auth types
|
||||
// and allows API key users to get proper fallback behavior from getEffectiveModel
|
||||
|
||||
@@ -71,7 +71,8 @@ export class GeminiClient {
|
||||
);
|
||||
this.chat = await this.startChat();
|
||||
}
|
||||
private getContentGenerator(): ContentGenerator {
|
||||
|
||||
getContentGenerator(): ContentGenerator {
|
||||
if (!this.contentGenerator) {
|
||||
throw new Error('Content generator not initialized');
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ export async function createContentGeneratorConfig(
|
||||
return contentGeneratorConfig;
|
||||
}
|
||||
|
||||
//
|
||||
if (authType === AuthType.USE_GEMINI && geminiApiKey) {
|
||||
contentGeneratorConfig.apiKey = geminiApiKey;
|
||||
contentGeneratorConfig.model = await getEffectiveModel(
|
||||
|
||||
@@ -21,6 +21,8 @@ export * from './core/nonInteractiveToolExecutor.js';
|
||||
|
||||
export * from './code_assist/codeAssist.js';
|
||||
export * from './code_assist/oauth2.js';
|
||||
export * from './code_assist/server.js';
|
||||
export * from './code_assist/types.js';
|
||||
|
||||
// Export utilities
|
||||
export * from './utils/paths.js';
|
||||
|
||||
Reference in New Issue
Block a user