Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
391 changes: 323 additions & 68 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts

Large diffs are not rendered by default.

44 changes: 38 additions & 6 deletions apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,14 @@ import * as PortScanner from "../../preview/PortScanner.ts";
import { getCodexServiceTierOptionValue } from "../../codexModelOptions.ts";
import { ServerConfig } from "../../config.ts";
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
import { buildCodexAdditionalContext } from "../../provider/CodexDeveloperInstructions.ts";
import {
resolveCodexComputerUse,
type CodexComputerUseAvailability,
} from "../../provider/CodexComputerUse.ts";
import {
buildCodexAdditionalContext,
buildCodexComputerUseInstructions,
} from "../../provider/CodexDeveloperInstructions.ts";
import {
describeMcpElicitation,
toMcpElicitationResponse,
Expand Down Expand Up @@ -762,6 +769,7 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
readonly modelSelection: ModelSelection;
readonly hasT3Mcp?: boolean;
readonly computerUse?: CodexComputerUseAvailability;
readonly browserToolsAvailable?: boolean;
readonly deviceToolsAvailable?: boolean;
/** ChatGPT token sharing does not accept service tiers. */
Expand Down Expand Up @@ -803,10 +811,19 @@ export const buildCodexTurnStartParams = Effect.fn("CodexAdapterV2.buildCodexTur
},
)
: undefined;
const additionalContext =
t3Context === undefined && Object.keys(appContext).length === 0
? undefined
: { ...t3Context, ...appContext };
const mergedContext = {
...t3Context,
...(input.computerUse === undefined
? {}
: {
t3_code_computer_use: {
kind: "application" as const,
value: buildCodexComputerUseInstructions(input.computerUse),
},
}),
...appContext,
};
const additionalContext = Object.keys(mergedContext).length === 0 ? undefined : mergedContext;
return yield* decodeCodexTurnStartParamsWithCollaborationMode({
threadId: input.nativeThreadId,
input: input.codexInput,
Expand Down Expand Up @@ -1664,7 +1681,10 @@ export type CodexAdapterV2DriverEnv =

export const createCodexAdapterV2 = Effect.fn("CodexAdapterV2.createCodexAdapterV2")(function* (
{ instanceId, environment, enabled, config }: ProviderAdapterDriverCreateInput<CodexSettings>,
hooks: Pick<CodexAdapterV2Options, "onUsageLimits" | "resolveRuntime" | "compatibility"> = {},
hooks: Pick<
CodexAdapterV2Options,
"onUsageLimits" | "resolveRuntime" | "compatibility" | "enableComputerUse"
> = {},
) {
const clientFactory = yield* CodexAppServerClientFactory;
const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
Expand Down Expand Up @@ -1719,6 +1739,7 @@ export interface CodexAdapterV2Options {
readonly settings: CodexSettings;
readonly environment: NodeJS.ProcessEnv;
readonly clientFactory: CodexAppServerClientFactoryShape;
readonly enableComputerUse?: boolean;
readonly onUsageLimits?: ManagedServerProvider["applyUsageLimits"];
readonly resolveRuntime?: Effect.Effect<CodexEffectiveRuntime, ProviderSetupError, Scope.Scope>;
readonly compatibility?: (
Expand All @@ -1744,6 +1765,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
threadId === null ? Effect.undefined : mcpSessions.read(threadId);
const { clientFactory, digest, fileSystem, idAllocator, serverConfig } = adapterOptions;
const continuationRequests = adapterOptions.continuationRequests;
const pathService = yield* Path.Path;

return ProviderAdapter.ProviderAdapterV2.of({
instanceId: adapterOptions.instanceId,
Expand Down Expand Up @@ -6840,8 +6862,18 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
) {
const threadId = yield* getNativeThreadId(turnInput.providerThread);
const mcpSession = yield* mcpSessions.read(turnInput.threadId);
const computerUse =
adapterOptions.enableComputerUse === true &&
(yield* HostProcess.Platform) === "darwin"
? yield* resolveCodexComputerUse({ cwd: turnInput.runtimePolicy.cwd }).pipe(
Effect.provideService(CodexClient.CodexAppServerClient, client),
Effect.provideService(FileSystem.FileSystem, fileSystem),
Effect.provideService(Path.Path, pathService),
)
: undefined;
const turnStartParams = yield* buildCodexTurnStartParams({
nativeThreadId: threadId,
...(computerUse === undefined ? {} : { computerUse }),
codexInput,
runtimePolicy: turnInput.runtimePolicy,
modelSelection: turnInput.modelSelection,
Expand Down
Loading
Loading