Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/importtype*as http from'http';import*as fs from'fs';import{ join }from'../../../../base/common/path.js';import{ createDecorator }from'../../../instantiation/common/instantiation.js';import{ ILogService }from'../../../log/common/log.js';import{ CopilotApiError, ICopilotApiService }from'../shared/copilotApiService.js';import{ buildForwardedChatError, encodeForwardedChatError }from'../shared/proxyChatError.js';import
ILoopbackProxyHandle
ILoopbackProxyRuntime
IProxyInFlight
LoopbackProxyServer
readProxyRequestBody
baseUrl
nonce
githubToken
_serviceBrand
githubToken ICodexProxyHandle
ICodexProxyService
githubToken
lastPrimaryModel
ILoopbackProxyRuntimeICodexProxyState
_dumpSeq
_dumpSeq
dir processenv
dir
fsdir recursive
dir
res httpServerResponse status type message
resheadersSent reswritableEnded
resstatus
res error type message
_serviceBrand
logService ILogService
_copilotApiService ICopilotApiService
logService
githubToken ICodexProxyState
githubToken lastPrimaryModel
githubToken ICodexProxyHandle
runtime release githubToken
runtimestategithubToken githubToken
disposed
baseUrl runtimebaseUrl
nonce runtimenonce
newToken
disposed
runtimestategithubToken newToken
disposed
disposed
override
req httpIncomingMessage
res httpServerResponse
runtime ICodexProxyRuntime
method reqmethod
pathname requrl pathname
incomingHeaders Objectreqheaders
_logService
method pathname
res
res
authHeader reqheaders
expected
authHeader authHeader expected
res
method pathname
res
res models
method pathname pathname pathname
req res runtime
res
req httpIncomingMessage
res httpServerResponse
runtime ICodexProxyRuntime
body
body req
err
res
remap body runtimestate
remapremappedFrom
_logService
body remapbody
dumpDir
dumpSeq dumpDir
dumpDir dumpSeq
reqFile dumpDir
fsreqFile body
_logService
err
_logService
parsed body
_logService
parsedinput
i i parsedinputlength i
item parsedinputi
type itemtype
keys item item Objectitem item
detail
type
text itemcontenttext
detail
type
detail
type
output itemoutput
detail
type
summary itemsummary itemcontent
detail
detail item
_logService
topLevelKeys Objectparsedk k
_logService
k topLevelKeys
k k
v parsedk
size v vlength vlength
_logService
v parsedk
preview v v v
_logService
_logService
entry IProxyInFlight ac res clientGone
runtimeinFlightentry
entryclientGone
entryac
res onClose
dispatchedToken runtimestategithubToken
headers reqheaders
_logService
upstream _copilotApiServicedispatchedToken body headers signal entryacsignal suppressIntegrationId
contentType upstreamheaders
upstreamHeaders upstreamheadersk v
_logService
resupstreamstatus contentType
upstreambody
res
reader upstreambody
resDumpStream dumpDir dumpSeq
fsdumpDir
sseBuf
eventCounts Record
done value reader
done
entryclientGone
value valuebyteLength
buf Buffervalue
resbuf
resDumpStream
resDumpStreambuf
sseBuf buf
nl
nl sseBuf
line sseBuf nl
sseBuf sseBufnl
line
ev linelength
eventCountsev eventCountsev
reader
resDumpStream
ObjecteventCountslength
summary ObjecteventCountsk v
_logService
res
err
entryclientGone
_logService
err
_logService
marker err
res errstatus
_logService
res err errmessage err
res onClose
runtimeinFlightentry
body
state lastPrimaryModel
body remappedFrom remappedTo
parsed model
parsed body
body
model parsedmodel parsedmodel
model
body
model
statelastPrimaryModel model
body
target statelastPrimaryModel
target
body
parsed model model target
body parsed remappedFrom model remappedTo target
inbound httpIncomingHttpHeaders Record
out Record
userAgent inbound
userAgent userAgentlength
out userAgent
out
userAgent
slashIndex userAgent
slashIndex
/**
* Refcounted handle to the local OpenAI-Responses → CAPI proxy.
*
* The handle owns a nonce that the codex CLI passes as `Bearer <nonce>` on
* every request. The proxy validates that nonce, then re-issues the request
* to CAPI using the **current** GitHub Copilot token — which can rotate
* underneath the codex process without affecting it. Call
* {@link setToken} when the upstream token changes; in-flight requests keep
* using the value they captured at dispatch time, new requests pick up the
* fresh value.
*
* Subprocess-ownership invariant: any subprocess given `baseUrl` / `nonce`
* MUST be killed before this handle is disposed; otherwise the proxy may
* rebind on a different port on next `start()` and the subprocess silently
* loses its endpoint.
*/
export
interface
ICodexProxyHandle
extends
ILoopbackProxyHandle
{
/** e.g. `http://127.0.0.1:54321` — no trailing slash. */
readonly
:
string
;
/** Random per-process nonce used as `Bearer <nonce>` by the codex CLI. */
readonly
:
string
;
/**
* Replace the GitHub Copilot token used for outbound CAPI calls. The
* codex process and its nonce are unchanged.
*/
setToken
(
:
string
)
:
void
;
}
export
interface
ICodexProxyService
{
readonly
:
undefined
;
/**
* Start the proxy (if not already running) and return a refcounted
* handle. The provided token is the initial value; rotate via
* {@link ICodexProxyHandle.setToken}.
*/
start
(
:
string
)
:
Promise
<
>
;
/** Force-close the proxy regardless of refcount. Idempotent. */
dispose
(
)
:
void
;
}
export
const
=
createDecorator<ICodexProxyService>
(
'codexProxyService'
)
;
/** Subclass-owned per-bind mutable state: the active outbound CAPI token. */
interface
ICodexProxyState
{
/** Token cell — read fresh on each outbound request. */
:
string
;
/**
* Most recent *primary* (non-reviewer) model id forwarded on this bind,
* observed from normal turn requests. Used to remap the unsupported
* auto-review reviewer model (see {@link CODEX_AUTO_REVIEW_MODEL}) onto a
* model that is known to be supported by the Copilot CAPI. `undefined`
* until the first primary request is seen.
*
* Bind-global, not per-session: the proxy is a single refcounted bind
* shared by every concurrent Codex session and reviewer requests carry no
* session identity, so this tracks the last primary model seen across all
* sessions. Under the documented single-tenant assumption (one active model
* at a time) that is correct; with two concurrent sessions on *different*
* models where one uses Auto-review, the reviewer may run on the other
* session's model. That only affects reviewer model choice, never
* correctness of the primary turns (which are forwarded verbatim).
*/
:
string
|
undefined
;
}
/**
* Model id the Codex app-server uses for its built-in auto-review reviewer
* (the "Auto-review" permissions preset routes eligible approvals through it).
*
* This is a specialized OpenAI model that is **not** part of the GitHub
* Copilot CAPI catalog, so forwarding it verbatim yields a 400
* `model_not_supported`. The app-server treats that as the review having
* *failed* and rejects the action inline ("Automatic approval review failed")
* without ever emitting an `item/autoApprovalReview/completed` notification —
* which breaks the entire Auto-review preset. We transparently remap it onto
* the session's primary model (see {@link ICodexProxyState.lastPrimaryModel})
* so the reviewer runs on a supported model; only the underlying model
* differs, the app-server's review instructions are unchanged.
*/
const
CODEX_AUTO_REVIEW_MODEL
=
'codex-auto-review'
;
type
ICodexProxyRuntime
=
<
>
;
const
PROXY_USER_FACING_NAME
=
'CodexProxyService'
;
/**
* User-agent prefix applied to outbound CAPI requests so the codex proxy's
* traffic is identifiable server-side. Mirrors `oaiLanguageModelServer.ts`
* in the Copilot Chat extension, which tags Codex requests with the same
* prefix.
*/
const
USER_AGENT_PREFIX
=
'vscode_codex'
;
/**
* When set to an absolute directory path, every `/v1/responses` request body
* and its full upstream response stream are written to that directory as
* `req-NNN-<ts>.json` and `res-NNN-<ts>.txt` so we can diff bodies / decode
* SSE without flooding the log channel. Off by default.
*/
const
DEBUG_DUMP_DIR_ENV
=
'VSCODE_CODEX_PROXY_DUMP_DIR'
;
let
=
0
;
function
nextDumpSeq
(
)
:
string
{
return
String
(
++
)
.
padStart
(
4
,
'0'
)
;
}
function
getDumpDir
(
)
:
string
|
undefined
{
const
=
.
[
DEBUG_DUMP_DIR_ENV
]
;
if
(
!
)
{
return
undefined
;
}
try
{
.
mkdirSync
(
,
{
:
true
}
)
;
return
;
}
catch
{
return
undefined
;
}
}
function
writeJsonError
(
:
.
,
:
number
,
:
string
,
:
string
)
:
void
{
if
(
.
||
.
)
{
return
;
}
.
writeHead
(
,
{
'Content-Type'
:
'application/json'
}
)
;
.
end
(
JSON
.
stringify
(
{
:
{
,
}
}
)
)
;
}
/**
* Local HTTP server that speaks the OpenAI Responses API on its inbound
* side and forwards to {@link ICopilotApiService.responses} on the
* outbound side. The codex app-server connects via env / `--config
* openai_base_url=<baseUrl>/v1` + Bearer `<nonce>` and sees this as a
* real OpenAI endpoint.
*
* Lifecycle: refcounted handles, single shared bind, in-flight requests
* aborted on teardown.
*/
export
class
CodexProxyService
extends
LoopbackProxyServer<ICodexProxyState,string>
implements
ICodexProxyService
{
declare
readonly
:
undefined
;
constructor
(
@ILogService
:
,
@ICopilotApiService
private
readonly
:
,
)
{
super
(
PROXY_USER_FACING_NAME
,
)
;
}
protected
createState
(
:
string
)
:
{
return
{
,
:
undefined
}
;
}
async
start
(
:
string
)
:
Promise
<
>
{
const
{
,
}
=
await
this
.
acquire
(
)
;
// Most recent token wins for the runtime — single-tenant assumption.
// Covers concurrent callers that awaited the same bind.
.
.
=
;
let
=
false
;
return
{
:
.
,
:
.
,
setToken
:
(
:
string
)
=>
{
if
(
)
{
return
;
}
// Update the shared runtime's token cell. In-flight requests
// keep the value they captured at dispatch; new requests
/**
* Compute the outbound `/v1/responses` body, transparently remapping the
* unsupported Codex auto-review reviewer model (see
* {@link CODEX_AUTO_REVIEW_MODEL}) onto the last-seen primary model. Records
* the primary model on `state` as a side effect so a later reviewer request
* can be remapped.
*
* Returns the original body untouched — and forwards verbatim, exactly as
* before — when it is unparseable, carries no `model`, already uses a primary
* model, or when no primary model has been observed yet (graceful
* degradation: the reviewer request still 400s, i.e. no worse than not
* remapping at all).
*/
export
function
remapCodexReviewerModel
(
:
string
,
:
{
:
string
|
undefined
}
,
)
:
{
readonly
:
string
;
readonly
?
:
string
;
readonly
?
:
string
}
{
let
:
{
?
:
unknown
}
;
try
{
=
JSON
.
parse
(
)
;
}
catch
{
return
{
}
;
}
const
=
typeof
.
===
'string'
?
.
:
undefined
;
if
(
!
)
{
return
{
}
;
}
if
(
!==
CODEX_AUTO_REVIEW_MODEL
)
{
// A normal turn request — remember its model so we can substitute it
// for a subsequent reviewer request.
.
=
;
return
{
}
;
}
const
=
.
;
if
(
!
)
{
return
{
}
;
}
(
as
{
:
string
}
)
.
=
;
return
{
:
JSON
.
stringify
(
)
,
:
,
:
}
;
}
function
buildOutboundHeaders
(
:
.
)
:
<
string
,
string
>
{
const
:
<
string
,
string
>
=
{
}
;
const
=
[
'user-agent'
]
;
if
(
typeof
===
'string'
&&
.
>
0
)
{
[
'User-Agent'
]
=
transformUserAgent
(
)
;
}
return
;
}
/**
* Transform an incoming user-agent string by replacing the client name portion
* (before the first `/`) with {@link USER_AGENT_PREFIX}. This mirrors the
* transform in `oaiLanguageModelServer.ts` in the Copilot Chat extension,
* ensuring all Codex requests are tagged with a consistent prefix for
* server-side identification.
*
* Examples:
* - `codex/1.2.3` → `vscode_codex/1.2.3`
* - `OpenAI/Python/1.0` → `vscode_codex/Python/1.0`
* - `unknown` → `vscode_codex/unknown`
*/