@tangle-network/sdk-provider-codex 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (c) 2025 Tangle Network
2
+
3
+ All rights reserved.
4
+
5
+ This software and associated documentation files (the "Software") are proprietary
6
+ and confidential. No part of this Software may be reproduced, distributed, or
7
+ transmitted in any form or by any means, including photocopying, recording, or
8
+ other electronic or mechanical methods, without the prior written permission of
9
+ Tangle Network.
10
+
11
+ For licensing inquiries, contact: hello@tangle.tools
@@ -0,0 +1,274 @@
1
+ import { AgentExecutionInput, AgentExecutionResult, BackendCapabilities, CliAuthFile, InteractionResponse, McpConfig, SdkHostServices, StreamEvent } from "@tangle-network/agent-interface";
2
+ import * as _$_tangle_network_sdk_cli_runner0 from "@tangle-network/sdk-cli-runner";
3
+ import { RpcBridge, StreamParserConfig } from "@tangle-network/sdk-cli-runner";
4
+ import { CliExecArgs, CliProviderAdapterBase, CliProviderConfig, CliProviderOptions, CliTurnProcess, CliTurnSpawn, ExecutionState, HarnessId, PreparedAttachment, WorkspacePlanApplication } from "@tangle-network/sdk-provider-cli-base";
5
+
6
+ //#region src/app-server-protocol.d.ts
7
+ type NativeMcp = {
8
+ enabled?: boolean;
9
+ url?: string;
10
+ command?: string;
11
+ args?: string[];
12
+ env?: Record<string, string>;
13
+ env_vars?: string[];
14
+ http_headers?: Record<string, string>;
15
+ env_http_headers?: Record<string, string>;
16
+ [key: string]: unknown;
17
+ };
18
+ //#endregion
19
+ //#region src/types.d.ts
20
+ /** Codex accepts an explicit OpenAI API key or CLI-managed ChatGPT OAuth. */
21
+ type CodexAuthMode = "api-key" | "oauth";
22
+ interface CodexConfig extends CliProviderConfig {
23
+ /**
24
+ * Authentication mode.
25
+ * - "api-key": Use apiKey or OPENAI_API_KEY env var
26
+ * - "oauth": Use CLI-managed OAuth (for ChatGPT Plus/Pro subscriptions)
27
+ * Default: "api-key" if apiKey is provided, otherwise "oauth"
28
+ */
29
+ authMode?: CodexAuthMode;
30
+ /**
31
+ * Sandbox mode when bypassPermissions is false.
32
+ * Options: "read-only", "workspace-write", "danger-full-access"
33
+ */
34
+ sandboxMode?: "read-only" | "workspace-write" | "danger-full-access";
35
+ /**
36
+ * Opt in to the interactive permission path: instead of the one-way
37
+ * `codex exec --json` run (which cannot route approvals), drive
38
+ * `codex app-server` (JSON-RPC) so each command-execution / file-change
39
+ * approval is escalated through the unified interaction broker. When unset
40
+ * (the default) the adapter behaves exactly as before. Requires a non-bypass
41
+ * sandbox + an escalating approval policy for codex to actually ask.
42
+ */
43
+ interactivePermissions?: boolean;
44
+ /**
45
+ * Approval policy sent to `codex app-server` when `interactivePermissions`
46
+ * is on. Interactive turns need an escalating value (codex never asks under
47
+ * "never" or a bypass sandbox); "never" is the question-only posture, where
48
+ * approvals are deliberately bypassed but `request_user_input` questions still
49
+ * fire. Default: "on-request" (interactive) / "never" (question-only).
50
+ */
51
+ approvalPolicy?: "untrusted" | "on-failure" | "on-request" | "never";
52
+ }
53
+ /**
54
+ * Codex CLI event types based on --json output format.
55
+ * These match the JSONL output from `codex exec --json`.
56
+ */
57
+ /**
58
+ * Session started event.
59
+ */
60
+ interface CodexSessionStartedEvent {
61
+ type: "session_started";
62
+ session_id: string;
63
+ }
64
+ /**
65
+ * Thread started event — the modern `codex exec --json` wire's session
66
+ * announcement. `thread_id` is the handle `codex exec resume <id>` takes.
67
+ */
68
+ interface CodexThreadStartedEvent {
69
+ type: "thread.started";
70
+ thread_id: string;
71
+ }
72
+ /**
73
+ * Message event wrapper.
74
+ */
75
+ interface CodexMessageEvent {
76
+ type: "message";
77
+ role: "user" | "assistant" | "system";
78
+ message: CodexMessage;
79
+ }
80
+ /**
81
+ * Codex message content.
82
+ */
83
+ interface CodexMessage {
84
+ content?: CodexContentBlock[];
85
+ status?: string;
86
+ }
87
+ /**
88
+ * Content block types.
89
+ */
90
+ type CodexContentBlock = CodexTextContent | CodexToolUseContent | CodexToolResultContent | CodexThinkingContent;
91
+ interface CodexTextContent {
92
+ type: "text";
93
+ text: string;
94
+ }
95
+ interface CodexToolUseContent {
96
+ type: "tool_use";
97
+ id: string;
98
+ name: string;
99
+ input: unknown;
100
+ }
101
+ interface CodexToolResultContent {
102
+ type: "tool_result";
103
+ tool_use_id: string;
104
+ content: unknown;
105
+ is_error?: boolean;
106
+ }
107
+ interface CodexThinkingContent {
108
+ type: "thinking";
109
+ thinking: string;
110
+ }
111
+ /**
112
+ * Task started event.
113
+ */
114
+ interface CodexTaskStartedEvent {
115
+ type: "task_started";
116
+ task_id: string;
117
+ task_type?: string;
118
+ }
119
+ /**
120
+ * Error event.
121
+ */
122
+ interface CodexErrorEvent {
123
+ type: "error";
124
+ message: string;
125
+ code?: string;
126
+ }
127
+ /**
128
+ * One file touched by an exec-path `file_change` item. The exec `--json`
129
+ * stream carries only `path` + `kind` ("add" | "update" | "delete") — no
130
+ * diff, unlike the app-server's FileUpdateChange. Fields are optional so a
131
+ * malformed change degrades to "no file signal" instead of a crash.
132
+ */
133
+ interface CodexFileChange {
134
+ path?: string;
135
+ kind?: string;
136
+ }
137
+ /**
138
+ * Raw item completion event emitted by newer Codex CLI builds.
139
+ * We care about assistant message completions because they may contain
140
+ * the final full text even when incremental message events were absent,
141
+ * and `file_change` completions because they are the exec path's only
142
+ * signal that the agent wrote files (surfaced as file parts).
143
+ */
144
+ interface CodexItemCompletedEvent {
145
+ type: "item.completed";
146
+ item: {
147
+ id?: string;
148
+ type?: string;
149
+ text?: string;
150
+ status?: string;
151
+ changes?: CodexFileChange[]; /** command_execution */
152
+ command?: string;
153
+ aggregated_output?: string;
154
+ exit_code?: number | null; /** mcp_tool_call */
155
+ server?: string;
156
+ tool?: string;
157
+ arguments?: unknown;
158
+ result?: unknown;
159
+ error?: unknown; /** web_search */
160
+ query?: string;
161
+ };
162
+ }
163
+ /** A tool item the agent began; its `item.completed` follows. */
164
+ interface CodexItemStartedEvent {
165
+ type: "item.started";
166
+ item: CodexItemCompletedEvent["item"];
167
+ }
168
+ /** The turn's end, with the tokens it used (`codex exec --json`). */
169
+ interface CodexTurnCompletedEvent {
170
+ type: "turn.completed";
171
+ usage?: Record<string, unknown>;
172
+ }
173
+ /**
174
+ * Union of all Codex CLI events.
175
+ */
176
+ type CodexEvent = CodexSessionStartedEvent | CodexThreadStartedEvent | CodexMessageEvent | CodexTaskStartedEvent | CodexErrorEvent | CodexItemCompletedEvent | CodexItemStartedEvent | CodexTurnCompletedEvent;
177
+ //#endregion
178
+ //#region src/codex-connection-config.d.ts
179
+ declare function normalizeExplicitCodexModel(model: string): string;
180
+ declare function resolveCodexApiKeyBaseUrl(config: Pick<CodexConfig, "apiKey" | "baseUrl">): string;
181
+ declare function resolveCodexConnection(config: CodexConfig, explicitModel?: string): {
182
+ baseUrl?: string;
183
+ model?: string;
184
+ };
185
+ //#endregion
186
+ //#region src/codex-native-launch.d.ts
187
+ declare abstract class CodexNativeLaunchAdapter extends CliProviderAdapterBase<CodexConfig, CodexEvent> {
188
+ protected readonly inheritProcessEnv = false;
189
+ protected nativeAttachmentKinds(): ReadonlyArray<"image" | "file">;
190
+ protected nativeConfigArgs(config: CodexConfig, connection: ReturnType<typeof resolveCodexConnection>, prompts: {
191
+ systemPrompt?: string;
192
+ appendSystemPrompt?: string;
193
+ }, flags: readonly string[]): string[];
194
+ protected buildExecArgs(params: {
195
+ message: string;
196
+ config: CodexConfig;
197
+ model?: string;
198
+ sessionId?: string;
199
+ workspaceRoot: string;
200
+ systemPrompt?: string;
201
+ appendSystemPrompt?: string;
202
+ attachments?: PreparedAttachment[];
203
+ }): CliExecArgs;
204
+ protected buildExecEnv(config: CodexConfig): Record<string, string | undefined>;
205
+ protected buildAppServerEnv(profilePlan: WorkspacePlanApplication | undefined, workspaceRoot: string): Record<string, string | undefined>;
206
+ getManagedAuthFiles(): CliAuthFile[];
207
+ }
208
+ //#endregion
209
+ //#region src/codex-secret-profile.d.ts
210
+ declare abstract class CodexSecretProfileAdapter extends CodexNativeLaunchAdapter {
211
+ protected readonly supportsSecretProfileRevisions = true;
212
+ private readonly mcpOwner;
213
+ private binary?;
214
+ constructor(options?: CliProviderOptions<CodexConfig>);
215
+ private refuse;
216
+ protected getCliPath(): string;
217
+ protected secretProfileVerificationScope(): string;
218
+ protected verifyPreparedSecretProfileRevision(input: AgentExecutionInput, plan: WorkspacePlanApplication): Promise<void>;
219
+ private readNativeConfig;
220
+ private readNativeControls;
221
+ protected nativeArgs(input: AgentExecutionInput, plan: WorkspacePlanApplication | undefined, mcp?: Record<string, unknown>): string[];
222
+ protected prepareSecretCodexTurn(input: AgentExecutionInput, plan: WorkspacePlanApplication, sessionId: string): Promise<{
223
+ cwd: string;
224
+ env: Record<string, string | undefined>;
225
+ args: string[];
226
+ release: (() => void | Promise<void>) | undefined;
227
+ validate: (bridge: RpcBridge, extra: Record<string, unknown>) => Promise<Record<string, NativeMcp>>;
228
+ }>;
229
+ shutdown(): Promise<void>;
230
+ }
231
+ //#endregion
232
+ //#region src/codex-app-server-adapter.d.ts
233
+ declare abstract class CodexAppServerAdapter extends CodexSecretProfileAdapter {
234
+ private readonly permissions;
235
+ getCapabilities(): BackendCapabilities;
236
+ respondToInteraction(response: InteractionResponse): Promise<void>;
237
+ execute(input: AgentExecutionInput, services: SdkHostServices, onEvent?: (event: StreamEvent) => void): Promise<AgentExecutionResult>;
238
+ private executeViaAppServer;
239
+ /** Capture session binding, profile/prompt and native callbacks before acquiring resources.
240
+ * Field construction stays one preparation record; launch/run/cleanup have separate owners. */
241
+ private prepareAppServerTurn;
242
+ private launchAppServerTurn;
243
+ private spawnAppServer;
244
+ private runAppServerTurn;
245
+ private closeAppServerTurn;
246
+ private bindPlanMcp;
247
+ }
248
+ //#endregion
249
+ //#region src/adapter.d.ts
250
+ /** Codex provider adapter. */
251
+ declare class CodexProviderAdapter extends CodexAppServerAdapter {
252
+ readonly provider = "codex";
253
+ protected readonly profileHarness: HarnessId;
254
+ protected readonly defaultCliPath = "codex";
255
+ /** Start the process the box's first turn will adopt: `codex exec` launched as an ordinary new-session managed turn. */
256
+ prewarmProcess(workspaceRootOrUndefined: string | undefined, launch: {
257
+ systemPrompt: string;
258
+ }): Promise<{
259
+ ready: Promise<boolean>;
260
+ }>;
261
+ /** A new session takes the spare in its HOME when its own launch is the spare's: the same. */
262
+ protected spawnExecutionProcess(request: CliTurnSpawn<CodexConfig, CodexEvent>): CliTurnProcess | Promise<CliTurnProcess>;
263
+ protected createEventParser(state: ExecutionState, onEvent?: (event: StreamEvent) => void): StreamParserConfig<CodexEvent>;
264
+ protected buildMcpAddArgs(name: string, config: McpConfig): string[];
265
+ protected buildMcpListArgs(): string[] | null;
266
+ protected formatStdinMessage(message: string): string;
267
+ private mapEventToStreamEvents;
268
+ }
269
+ //#endregion
270
+ //#region src/held-spare.d.ts
271
+ declare const codexHeldSpares: _$_tangle_network_sdk_cli_runner0.HeldSpareRegistry<CodexEvent, object>;
272
+ //#endregion
273
+ export { type CodexAuthMode, type CodexConfig, type CodexContentBlock, type CodexErrorEvent, type CodexEvent, type CodexMessage, type CodexMessageEvent, CodexProviderAdapter, type CodexSessionStartedEvent, type CodexTaskStartedEvent, type CodexTextContent, type CodexThinkingContent, type CodexToolResultContent, type CodexToolUseContent, codexHeldSpares, normalizeExplicitCodexModel, resolveCodexApiKeyBaseUrl };
274
+ //# sourceMappingURL=index.d.mts.map