refactor: Reorganize src/ into modular folder structure
Split large monolithic files into focused modules: - cloudcode-client.js (1,107 lines) → src/cloudcode/ (9 files) - account-manager.js (639 lines) → src/account-manager/ (5 files) - Move auth files to src/auth/ (oauth, token-extractor, database) - Move CLI to src/cli/accounts.js Update all import paths and documentation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
68
src/cloudcode/request-builder.js
Normal file
68
src/cloudcode/request-builder.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Request Builder for Cloud Code
|
||||
*
|
||||
* Builds request payloads and headers for the Cloud Code API.
|
||||
*/
|
||||
|
||||
import crypto from 'crypto';
|
||||
import {
|
||||
ANTIGRAVITY_HEADERS,
|
||||
getModelFamily,
|
||||
isThinkingModel
|
||||
} from '../constants.js';
|
||||
import { convertAnthropicToGoogle } from '../format/index.js';
|
||||
import { deriveSessionId } from './session-manager.js';
|
||||
|
||||
/**
|
||||
* Build the wrapped request body for Cloud Code API
|
||||
*
|
||||
* @param {Object} anthropicRequest - The Anthropic-format request
|
||||
* @param {string} projectId - The project ID to use
|
||||
* @returns {Object} The Cloud Code API request payload
|
||||
*/
|
||||
export function buildCloudCodeRequest(anthropicRequest, projectId) {
|
||||
const model = anthropicRequest.model;
|
||||
const googleRequest = convertAnthropicToGoogle(anthropicRequest);
|
||||
|
||||
// Use stable session ID derived from first user message for cache continuity
|
||||
googleRequest.sessionId = deriveSessionId(anthropicRequest);
|
||||
|
||||
const payload = {
|
||||
project: projectId,
|
||||
model: model,
|
||||
request: googleRequest,
|
||||
userAgent: 'antigravity',
|
||||
requestId: 'agent-' + crypto.randomUUID()
|
||||
};
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build headers for Cloud Code API requests
|
||||
*
|
||||
* @param {string} token - OAuth access token
|
||||
* @param {string} model - Model name
|
||||
* @param {string} accept - Accept header value (default: 'application/json')
|
||||
* @returns {Object} Headers object
|
||||
*/
|
||||
export function buildHeaders(token, model, accept = 'application/json') {
|
||||
const headers = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
...ANTIGRAVITY_HEADERS
|
||||
};
|
||||
|
||||
const modelFamily = getModelFamily(model);
|
||||
|
||||
// Add interleaved thinking header only for Claude thinking models
|
||||
if (modelFamily === 'claude' && isThinkingModel(model)) {
|
||||
headers['anthropic-beta'] = 'interleaved-thinking-2025-05-14';
|
||||
}
|
||||
|
||||
if (accept !== 'application/json') {
|
||||
headers['Accept'] = accept;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
Reference in New Issue
Block a user