MCPcopy Create free account
hub / github.com/anus-dev/ANUS / createContentGenerator

Function createContentGenerator

packages/core/src/core/contentGenerator.ts:121–184  ·  view source on GitHub ↗
(
  config: ContentGeneratorConfig,
  gcConfig: Config,
  sessionId?: string,
)

Source from the content-addressed store, hash-verified

119}
120
121export async function createContentGenerator(
122 config: ContentGeneratorConfig,
123 gcConfig: Config,
124 sessionId?: string,
125): Promise<ContentGenerator> {
126 const version = process.env['CLI_VERSION'] || process.version;
127 const userAgent = `AnusCLI/${version} (${process.platform}; ${process.arch})`;
128 const baseHeaders: Record<string, string> = {
129 'User-Agent': userAgent,
130 };
131
132 if (
133 config.authType === AuthType.LOGIN_WITH_GOOGLE ||
134 config.authType === AuthType.CLOUD_SHELL
135 ) {
136 const httpOptions = { headers: baseHeaders };
137 return new LoggingContentGenerator(
138 await createCodeAssistContentGenerator(
139 httpOptions,
140 config.authType,
141 gcConfig,
142 sessionId,
143 ),
144 gcConfig,
145 );
146 }
147
148 // Provider registry: route to GrokContentGenerator if provider is GROK
149 // or if a Grok-compatible key is present (implicit provider selection).
150 // When createContentGeneratorConfig detects a Grok key, it sets provider=GROK and apiKey accordingly.
151 const isGrokSelected =
152 config.provider === Provider.GROK || config.authType === AuthType.USE_GROK;
153 if (isGrokSelected) {
154 const { GrokContentGenerator } = await import(
155 '../providers/grok/contentGenerator.js'
156 );
157 return new LoggingContentGenerator(
158 new GrokContentGenerator(config.model, config.apiKey),
159 gcConfig,
160 );
161 }
162
163 if (config.authType === AuthType.USE_VERTEX_AI) {
164 let headers: Record<string, string> = { ...baseHeaders };
165 if (gcConfig?.getUsageStatisticsEnabled()) {
166 const installationId = getInstallationId();
167 headers = {
168 ...headers,
169 'x-anus-api-privileged-user-id': `${installationId}`,
170 };
171 }
172 const httpOptions = { headers };
173
174 const googleGenAI = new GoogleGenAI({
175 apiKey: config.apiKey === '' ? undefined : config.apiKey,
176 vertexai: config.vertexai,
177 httpOptions,
178 });

Callers 4

createChatObjectMethod · 0.85
initializeMethod · 0.85

Calls 3

getInstallationIdFunction · 0.85

Tested by

no test coverage detected