@janole/ai-sdk-provider-codex-asp 0.2.2 → 0.2.4
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/README.md +1 -1
- package/dist/index.cjs +210 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -22
- package/dist/index.d.ts +130 -22
- package/dist/index.js +209 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV3CallOptions, LanguageModelV3, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, LanguageModelV3StreamPart,
|
|
1
|
+
import { LanguageModelV3CallOptions, LanguageModelV3, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, LanguageModelV3StreamPart, ProviderV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
/** Base error type for this provider package. */
|
|
4
4
|
declare class CodexProviderError extends Error {
|
|
@@ -132,6 +132,10 @@ type CommandExecutionRequestApprovalParams = {
|
|
|
132
132
|
* Optional proposed network policy amendments (allow/deny host) for future requests.
|
|
133
133
|
*/
|
|
134
134
|
proposedNetworkPolicyAmendments?: Array<NetworkPolicyAmendment> | null;
|
|
135
|
+
/**
|
|
136
|
+
* Ordered list of decisions the client may present for this prompt.
|
|
137
|
+
*/
|
|
138
|
+
availableDecisions?: Array<CommandExecutionApprovalDecision> | null;
|
|
135
139
|
};
|
|
136
140
|
|
|
137
141
|
type CommandExecutionRequestApprovalResponse = {
|
|
@@ -454,6 +458,16 @@ type CollabAgentToolCallStatus = "inProgress" | "completed" | "failed";
|
|
|
454
458
|
|
|
455
459
|
type CommandExecutionStatus = "inProgress" | "completed" | "failed" | "declined";
|
|
456
460
|
|
|
461
|
+
type DynamicToolCallOutputContentItem = {
|
|
462
|
+
"type": "inputText";
|
|
463
|
+
text: string;
|
|
464
|
+
} | {
|
|
465
|
+
"type": "inputImage";
|
|
466
|
+
imageUrl: string;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
type DynamicToolCallStatus = "inProgress" | "completed" | "failed";
|
|
470
|
+
|
|
457
471
|
type PatchChangeKind = {
|
|
458
472
|
"type": "add";
|
|
459
473
|
} | {
|
|
@@ -606,6 +620,18 @@ type ThreadItem = {
|
|
|
606
620
|
* The duration of the MCP tool call in milliseconds.
|
|
607
621
|
*/
|
|
608
622
|
durationMs: number | null;
|
|
623
|
+
} | {
|
|
624
|
+
"type": "dynamicToolCall";
|
|
625
|
+
id: string;
|
|
626
|
+
tool: string;
|
|
627
|
+
arguments: JsonValue;
|
|
628
|
+
status: DynamicToolCallStatus;
|
|
629
|
+
contentItems: Array<DynamicToolCallOutputContentItem> | null;
|
|
630
|
+
success: boolean | null;
|
|
631
|
+
/**
|
|
632
|
+
* The duration of the dynamic tool call in milliseconds.
|
|
633
|
+
*/
|
|
634
|
+
durationMs: number | null;
|
|
609
635
|
} | {
|
|
610
636
|
"type": "collabAgentToolCall";
|
|
611
637
|
/**
|
|
@@ -1129,20 +1155,29 @@ interface CodexWorkerPoolSettings {
|
|
|
1129
1155
|
transportFactory: () => CodexTransport;
|
|
1130
1156
|
idleTimeoutMs?: number;
|
|
1131
1157
|
}
|
|
1158
|
+
interface AcquireOptions {
|
|
1159
|
+
signal?: AbortSignal;
|
|
1160
|
+
}
|
|
1132
1161
|
declare class CodexWorkerPool {
|
|
1133
1162
|
private readonly workers;
|
|
1134
1163
|
private shutdownCalled;
|
|
1164
|
+
private readonly waiters;
|
|
1135
1165
|
constructor(settings: CodexWorkerPoolSettings);
|
|
1136
|
-
acquire(): CodexWorker
|
|
1166
|
+
acquire(options?: AcquireOptions): Promise<CodexWorker>;
|
|
1137
1167
|
release(worker: CodexWorker): void;
|
|
1138
1168
|
shutdown(): Promise<void>;
|
|
1169
|
+
private removeWaiter;
|
|
1170
|
+
/** Remove the abort listener so it doesn't fire after the waiter is already served. */
|
|
1171
|
+
private clearWaiterAbortHandler;
|
|
1139
1172
|
}
|
|
1140
1173
|
|
|
1141
1174
|
interface PersistentTransportSettings {
|
|
1142
1175
|
pool: CodexWorkerPool;
|
|
1176
|
+
signal?: AbortSignal;
|
|
1143
1177
|
}
|
|
1144
1178
|
declare class PersistentTransport implements CodexTransport {
|
|
1145
1179
|
private readonly pool;
|
|
1180
|
+
private readonly signal;
|
|
1146
1181
|
private worker;
|
|
1147
1182
|
private pendingInitializeId;
|
|
1148
1183
|
private initializeIntercepted;
|
|
@@ -1281,7 +1316,7 @@ interface CodexProviderSettings {
|
|
|
1281
1316
|
defaultThreadSettings?: CodexThreadDefaults;
|
|
1282
1317
|
defaultTurnSettings?: CodexTurnDefaults;
|
|
1283
1318
|
compaction?: CodexCompactionSettings;
|
|
1284
|
-
transportFactory?: () => CodexTransport;
|
|
1319
|
+
transportFactory?: (signal?: AbortSignal) => CodexTransport;
|
|
1285
1320
|
/** Tools with schema (description + inputSchema) advertised to Codex + local handlers. */
|
|
1286
1321
|
tools?: Record<string, DynamicToolDefinition>;
|
|
1287
1322
|
/** Legacy: handler-only tools, not advertised to Codex. Use `tools` for full schema support. */
|
|
@@ -1368,24 +1403,6 @@ declare class CodexEventMapper {
|
|
|
1368
1403
|
map(event: CodexEventMapperInput): LanguageModelV3StreamPart[];
|
|
1369
1404
|
}
|
|
1370
1405
|
|
|
1371
|
-
/**
|
|
1372
|
-
* Extracts system messages from the prompt and concatenates them into a single
|
|
1373
|
-
* string suitable for `developerInstructions` on `thread/start` or
|
|
1374
|
-
* `thread/resume`. Returns `undefined` when no system content is present.
|
|
1375
|
-
*/
|
|
1376
|
-
declare function mapSystemPrompt(prompt: LanguageModelV3Prompt): string | undefined;
|
|
1377
|
-
/**
|
|
1378
|
-
* Maps the prompt to the `input` array for a `turn/start` request.
|
|
1379
|
-
*
|
|
1380
|
-
* System messages are **not** included here — they are routed to
|
|
1381
|
-
* `developerInstructions` via {@link mapSystemPrompt} instead.
|
|
1382
|
-
*
|
|
1383
|
-
* @param isResume - When true the thread already holds the full history on
|
|
1384
|
-
* disk, so only the last user message is extracted and sent. When false
|
|
1385
|
-
* (fresh thread) all user text is folded into a single item.
|
|
1386
|
-
*/
|
|
1387
|
-
declare function mapPromptToTurnInput(prompt: LanguageModelV3Prompt, isResume?: boolean): CodexTurnInputItem[];
|
|
1388
|
-
|
|
1389
1406
|
declare const CODEX_PROVIDER_ID = "@janole/ai-sdk-provider-codex-asp";
|
|
1390
1407
|
declare function codexProviderMetadata(threadId: string | undefined): {
|
|
1391
1408
|
"@janole/ai-sdk-provider-codex-asp": {
|
|
@@ -1407,4 +1424,95 @@ declare const codexAppServer: CodexProvider;
|
|
|
1407
1424
|
*/
|
|
1408
1425
|
declare const createCodexProvider: typeof createCodexAppServer;
|
|
1409
1426
|
|
|
1410
|
-
|
|
1427
|
+
/**
|
|
1428
|
+
* Extracts system messages from the prompt and concatenates them into a single
|
|
1429
|
+
* string suitable for `developerInstructions` on `thread/start` or
|
|
1430
|
+
* `thread/resume`. Returns `undefined` when no system content is present.
|
|
1431
|
+
*/
|
|
1432
|
+
declare function mapSystemPrompt(prompt: LanguageModelV3Prompt): string | undefined;
|
|
1433
|
+
/**
|
|
1434
|
+
* Pluggable backend for persisting inline binary data so that the Codex
|
|
1435
|
+
* protocol can reference it by URL.
|
|
1436
|
+
*
|
|
1437
|
+
* Implement this interface to use a different storage backend (e.g. S3, GCS).
|
|
1438
|
+
*
|
|
1439
|
+
* - A `file:` URL maps to `{ type: "localImage", path }` in the Codex protocol.
|
|
1440
|
+
* - An `http(s):` URL maps to `{ type: "image", url }`.
|
|
1441
|
+
*/
|
|
1442
|
+
interface FileWriter {
|
|
1443
|
+
/** Persist `data` and return a URL that Codex can use to access it. */
|
|
1444
|
+
write(data: Uint8Array | string, mediaType: string): Promise<URL>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Remove previously written files. Best-effort — implementations should
|
|
1447
|
+
* never throw.
|
|
1448
|
+
*/
|
|
1449
|
+
cleanup(urls: URL[]): Promise<void>;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* A {@link FileWriter} that writes to `os.tmpdir()` and returns `file:` URLs.
|
|
1453
|
+
*/
|
|
1454
|
+
declare class LocalFileWriter implements FileWriter {
|
|
1455
|
+
write(data: Uint8Array | string, mediaType: string): Promise<URL>;
|
|
1456
|
+
cleanup(urls: URL[]): Promise<void>;
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Resolves inline binary data in AI SDK prompts and maps user content to
|
|
1460
|
+
* {@link CodexTurnInputItem} arrays ready for `turn/start`.
|
|
1461
|
+
*
|
|
1462
|
+
* Instantiate with an optional custom {@link FileWriter} for non-local storage
|
|
1463
|
+
* (e.g. S3). Tracks all written URLs so that {@link cleanup} can remove them
|
|
1464
|
+
* after the turn completes.
|
|
1465
|
+
*
|
|
1466
|
+
* @example
|
|
1467
|
+
* ```ts
|
|
1468
|
+
* const fileResolver = new PromptFileResolver();
|
|
1469
|
+
* const turnInput = await fileResolver.resolve(prompt, isResume);
|
|
1470
|
+
* // … after the turn …
|
|
1471
|
+
* await fileResolver.cleanup();
|
|
1472
|
+
* ```
|
|
1473
|
+
*/
|
|
1474
|
+
declare class PromptFileResolver {
|
|
1475
|
+
private readonly writer;
|
|
1476
|
+
private readonly written;
|
|
1477
|
+
constructor(writer?: FileWriter);
|
|
1478
|
+
/**
|
|
1479
|
+
* Resolve inline file data and map user content to Codex input items.
|
|
1480
|
+
*
|
|
1481
|
+
* - Inline image data (base64 / Uint8Array) is written via the
|
|
1482
|
+
* {@link FileWriter} and converted to `localImage` or `image` items.
|
|
1483
|
+
* - URL-based image file parts are converted directly.
|
|
1484
|
+
* - Inline text file data is decoded and inlined as text.
|
|
1485
|
+
* - Unsupported media types are silently skipped.
|
|
1486
|
+
*
|
|
1487
|
+
* @param isResume - When true only the last user message is extracted.
|
|
1488
|
+
* When false (fresh thread) all user text is accumulated with images
|
|
1489
|
+
* flushing the text buffer to preserve ordering.
|
|
1490
|
+
*/
|
|
1491
|
+
resolve(prompt: LanguageModelV3Prompt, isResume?: boolean): Promise<CodexTurnInputItem[]>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Remove all files created by previous {@link resolve} calls.
|
|
1494
|
+
* Best-effort — never throws.
|
|
1495
|
+
*/
|
|
1496
|
+
cleanup(): Promise<void>;
|
|
1497
|
+
/**
|
|
1498
|
+
* Convert a resolved image URL to a Codex input item.
|
|
1499
|
+
*/
|
|
1500
|
+
private mapImageUrl;
|
|
1501
|
+
/**
|
|
1502
|
+
* Resolve a single file part: write inline data via the writer, then
|
|
1503
|
+
* convert to a Codex input item. Text files are decoded and returned
|
|
1504
|
+
* as text items. Returns `null` for unsupported media types.
|
|
1505
|
+
*/
|
|
1506
|
+
private resolveFilePart;
|
|
1507
|
+
/**
|
|
1508
|
+
* Resume path: extract parts from the last user message individually.
|
|
1509
|
+
*/
|
|
1510
|
+
private resolveResumed;
|
|
1511
|
+
/**
|
|
1512
|
+
* Fresh thread path: accumulate text chunks across all user messages,
|
|
1513
|
+
* flushing before each image to preserve ordering.
|
|
1514
|
+
*/
|
|
1515
|
+
private resolveFresh;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
export { type AgentMessageDeltaNotification, AppServerClient, type AppServerClientSettings, ApprovalsDispatcher, type ApprovalsDispatcherSettings, type AskForApproval, CODEX_PROVIDER_ID, type CodexCommandApprovalRequest, type CodexDynamicToolDefinition, CodexEventMapper, type CodexEventMapperInput, type CodexEventMapperOptions, type CodexFileChangeApprovalRequest, type CodexInitializeParams, type CodexInitializeResult, type CodexInitializedNotification, CodexLanguageModel, type CodexLanguageModelSettings, type CodexModelConfig, CodexNotImplementedError, type CodexNotification, type CodexProvider, CodexProviderError, type CodexProviderSettings, type CodexThreadDefaults, type CodexThreadResumeParams, type CodexThreadResumeResult, type CodexThreadStartParams, type CodexThreadStartResult, type CodexToolCallDeltaNotification, type CodexToolCallFinishedNotification, type CodexToolCallRequestParams, type CodexToolCallResult, type CodexToolCallStartedNotification, type CodexToolResultContentItem, type CodexTransport, type CodexTransportEventMap, type CodexTurnInputImage, type CodexTurnInputItem, type CodexTurnInputLocalImage, type CodexTurnInputMention, type CodexTurnInputSkill, type CodexTurnInputText, type CodexTurnStartParams, type CodexTurnStartResult, CodexWorker, CodexWorkerPool, type CodexWorkerPoolSettings, type CodexWorkerSettings, type CommandApprovalHandler, type CommandExecutionApprovalDecision, type CommandExecutionRequestApprovalParams, type CommandExecutionRequestApprovalResponse, type DynamicToolDefinition, type DynamicToolExecutionContext, type DynamicToolHandler, DynamicToolsDispatcher, type DynamicToolsDispatcherSettings, type FileChangeApprovalDecision, type FileChangeApprovalHandler, type FileChangeRequestApprovalParams, type FileChangeRequestApprovalResponse, type FileWriter, type ItemCompletedNotification, type ItemStartedNotification, JsonRpcError, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcMessageBase, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, LocalFileWriter, PACKAGE_NAME, PACKAGE_VERSION, type PendingToolCall, PersistentTransport, type PersistentTransportSettings, PromptFileResolver, type SandboxMode, StdioTransport, type StdioTransportSettings, type ThreadTokenUsageUpdatedNotification, type TurnCompletedNotification, type TurnStartedNotification, WebSocketTransport, type WebSocketTransportSettings, codexAppServer, codexProviderMetadata, createCodexAppServer, createCodexProvider, mapSystemPrompt, withProviderMetadata };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModelV3CallOptions, LanguageModelV3, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, LanguageModelV3StreamPart,
|
|
1
|
+
import { LanguageModelV3CallOptions, LanguageModelV3, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, LanguageModelV3StreamPart, ProviderV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
/** Base error type for this provider package. */
|
|
4
4
|
declare class CodexProviderError extends Error {
|
|
@@ -132,6 +132,10 @@ type CommandExecutionRequestApprovalParams = {
|
|
|
132
132
|
* Optional proposed network policy amendments (allow/deny host) for future requests.
|
|
133
133
|
*/
|
|
134
134
|
proposedNetworkPolicyAmendments?: Array<NetworkPolicyAmendment> | null;
|
|
135
|
+
/**
|
|
136
|
+
* Ordered list of decisions the client may present for this prompt.
|
|
137
|
+
*/
|
|
138
|
+
availableDecisions?: Array<CommandExecutionApprovalDecision> | null;
|
|
135
139
|
};
|
|
136
140
|
|
|
137
141
|
type CommandExecutionRequestApprovalResponse = {
|
|
@@ -454,6 +458,16 @@ type CollabAgentToolCallStatus = "inProgress" | "completed" | "failed";
|
|
|
454
458
|
|
|
455
459
|
type CommandExecutionStatus = "inProgress" | "completed" | "failed" | "declined";
|
|
456
460
|
|
|
461
|
+
type DynamicToolCallOutputContentItem = {
|
|
462
|
+
"type": "inputText";
|
|
463
|
+
text: string;
|
|
464
|
+
} | {
|
|
465
|
+
"type": "inputImage";
|
|
466
|
+
imageUrl: string;
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
type DynamicToolCallStatus = "inProgress" | "completed" | "failed";
|
|
470
|
+
|
|
457
471
|
type PatchChangeKind = {
|
|
458
472
|
"type": "add";
|
|
459
473
|
} | {
|
|
@@ -606,6 +620,18 @@ type ThreadItem = {
|
|
|
606
620
|
* The duration of the MCP tool call in milliseconds.
|
|
607
621
|
*/
|
|
608
622
|
durationMs: number | null;
|
|
623
|
+
} | {
|
|
624
|
+
"type": "dynamicToolCall";
|
|
625
|
+
id: string;
|
|
626
|
+
tool: string;
|
|
627
|
+
arguments: JsonValue;
|
|
628
|
+
status: DynamicToolCallStatus;
|
|
629
|
+
contentItems: Array<DynamicToolCallOutputContentItem> | null;
|
|
630
|
+
success: boolean | null;
|
|
631
|
+
/**
|
|
632
|
+
* The duration of the dynamic tool call in milliseconds.
|
|
633
|
+
*/
|
|
634
|
+
durationMs: number | null;
|
|
609
635
|
} | {
|
|
610
636
|
"type": "collabAgentToolCall";
|
|
611
637
|
/**
|
|
@@ -1129,20 +1155,29 @@ interface CodexWorkerPoolSettings {
|
|
|
1129
1155
|
transportFactory: () => CodexTransport;
|
|
1130
1156
|
idleTimeoutMs?: number;
|
|
1131
1157
|
}
|
|
1158
|
+
interface AcquireOptions {
|
|
1159
|
+
signal?: AbortSignal;
|
|
1160
|
+
}
|
|
1132
1161
|
declare class CodexWorkerPool {
|
|
1133
1162
|
private readonly workers;
|
|
1134
1163
|
private shutdownCalled;
|
|
1164
|
+
private readonly waiters;
|
|
1135
1165
|
constructor(settings: CodexWorkerPoolSettings);
|
|
1136
|
-
acquire(): CodexWorker
|
|
1166
|
+
acquire(options?: AcquireOptions): Promise<CodexWorker>;
|
|
1137
1167
|
release(worker: CodexWorker): void;
|
|
1138
1168
|
shutdown(): Promise<void>;
|
|
1169
|
+
private removeWaiter;
|
|
1170
|
+
/** Remove the abort listener so it doesn't fire after the waiter is already served. */
|
|
1171
|
+
private clearWaiterAbortHandler;
|
|
1139
1172
|
}
|
|
1140
1173
|
|
|
1141
1174
|
interface PersistentTransportSettings {
|
|
1142
1175
|
pool: CodexWorkerPool;
|
|
1176
|
+
signal?: AbortSignal;
|
|
1143
1177
|
}
|
|
1144
1178
|
declare class PersistentTransport implements CodexTransport {
|
|
1145
1179
|
private readonly pool;
|
|
1180
|
+
private readonly signal;
|
|
1146
1181
|
private worker;
|
|
1147
1182
|
private pendingInitializeId;
|
|
1148
1183
|
private initializeIntercepted;
|
|
@@ -1281,7 +1316,7 @@ interface CodexProviderSettings {
|
|
|
1281
1316
|
defaultThreadSettings?: CodexThreadDefaults;
|
|
1282
1317
|
defaultTurnSettings?: CodexTurnDefaults;
|
|
1283
1318
|
compaction?: CodexCompactionSettings;
|
|
1284
|
-
transportFactory?: () => CodexTransport;
|
|
1319
|
+
transportFactory?: (signal?: AbortSignal) => CodexTransport;
|
|
1285
1320
|
/** Tools with schema (description + inputSchema) advertised to Codex + local handlers. */
|
|
1286
1321
|
tools?: Record<string, DynamicToolDefinition>;
|
|
1287
1322
|
/** Legacy: handler-only tools, not advertised to Codex. Use `tools` for full schema support. */
|
|
@@ -1368,24 +1403,6 @@ declare class CodexEventMapper {
|
|
|
1368
1403
|
map(event: CodexEventMapperInput): LanguageModelV3StreamPart[];
|
|
1369
1404
|
}
|
|
1370
1405
|
|
|
1371
|
-
/**
|
|
1372
|
-
* Extracts system messages from the prompt and concatenates them into a single
|
|
1373
|
-
* string suitable for `developerInstructions` on `thread/start` or
|
|
1374
|
-
* `thread/resume`. Returns `undefined` when no system content is present.
|
|
1375
|
-
*/
|
|
1376
|
-
declare function mapSystemPrompt(prompt: LanguageModelV3Prompt): string | undefined;
|
|
1377
|
-
/**
|
|
1378
|
-
* Maps the prompt to the `input` array for a `turn/start` request.
|
|
1379
|
-
*
|
|
1380
|
-
* System messages are **not** included here — they are routed to
|
|
1381
|
-
* `developerInstructions` via {@link mapSystemPrompt} instead.
|
|
1382
|
-
*
|
|
1383
|
-
* @param isResume - When true the thread already holds the full history on
|
|
1384
|
-
* disk, so only the last user message is extracted and sent. When false
|
|
1385
|
-
* (fresh thread) all user text is folded into a single item.
|
|
1386
|
-
*/
|
|
1387
|
-
declare function mapPromptToTurnInput(prompt: LanguageModelV3Prompt, isResume?: boolean): CodexTurnInputItem[];
|
|
1388
|
-
|
|
1389
1406
|
declare const CODEX_PROVIDER_ID = "@janole/ai-sdk-provider-codex-asp";
|
|
1390
1407
|
declare function codexProviderMetadata(threadId: string | undefined): {
|
|
1391
1408
|
"@janole/ai-sdk-provider-codex-asp": {
|
|
@@ -1407,4 +1424,95 @@ declare const codexAppServer: CodexProvider;
|
|
|
1407
1424
|
*/
|
|
1408
1425
|
declare const createCodexProvider: typeof createCodexAppServer;
|
|
1409
1426
|
|
|
1410
|
-
|
|
1427
|
+
/**
|
|
1428
|
+
* Extracts system messages from the prompt and concatenates them into a single
|
|
1429
|
+
* string suitable for `developerInstructions` on `thread/start` or
|
|
1430
|
+
* `thread/resume`. Returns `undefined` when no system content is present.
|
|
1431
|
+
*/
|
|
1432
|
+
declare function mapSystemPrompt(prompt: LanguageModelV3Prompt): string | undefined;
|
|
1433
|
+
/**
|
|
1434
|
+
* Pluggable backend for persisting inline binary data so that the Codex
|
|
1435
|
+
* protocol can reference it by URL.
|
|
1436
|
+
*
|
|
1437
|
+
* Implement this interface to use a different storage backend (e.g. S3, GCS).
|
|
1438
|
+
*
|
|
1439
|
+
* - A `file:` URL maps to `{ type: "localImage", path }` in the Codex protocol.
|
|
1440
|
+
* - An `http(s):` URL maps to `{ type: "image", url }`.
|
|
1441
|
+
*/
|
|
1442
|
+
interface FileWriter {
|
|
1443
|
+
/** Persist `data` and return a URL that Codex can use to access it. */
|
|
1444
|
+
write(data: Uint8Array | string, mediaType: string): Promise<URL>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Remove previously written files. Best-effort — implementations should
|
|
1447
|
+
* never throw.
|
|
1448
|
+
*/
|
|
1449
|
+
cleanup(urls: URL[]): Promise<void>;
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* A {@link FileWriter} that writes to `os.tmpdir()` and returns `file:` URLs.
|
|
1453
|
+
*/
|
|
1454
|
+
declare class LocalFileWriter implements FileWriter {
|
|
1455
|
+
write(data: Uint8Array | string, mediaType: string): Promise<URL>;
|
|
1456
|
+
cleanup(urls: URL[]): Promise<void>;
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Resolves inline binary data in AI SDK prompts and maps user content to
|
|
1460
|
+
* {@link CodexTurnInputItem} arrays ready for `turn/start`.
|
|
1461
|
+
*
|
|
1462
|
+
* Instantiate with an optional custom {@link FileWriter} for non-local storage
|
|
1463
|
+
* (e.g. S3). Tracks all written URLs so that {@link cleanup} can remove them
|
|
1464
|
+
* after the turn completes.
|
|
1465
|
+
*
|
|
1466
|
+
* @example
|
|
1467
|
+
* ```ts
|
|
1468
|
+
* const fileResolver = new PromptFileResolver();
|
|
1469
|
+
* const turnInput = await fileResolver.resolve(prompt, isResume);
|
|
1470
|
+
* // … after the turn …
|
|
1471
|
+
* await fileResolver.cleanup();
|
|
1472
|
+
* ```
|
|
1473
|
+
*/
|
|
1474
|
+
declare class PromptFileResolver {
|
|
1475
|
+
private readonly writer;
|
|
1476
|
+
private readonly written;
|
|
1477
|
+
constructor(writer?: FileWriter);
|
|
1478
|
+
/**
|
|
1479
|
+
* Resolve inline file data and map user content to Codex input items.
|
|
1480
|
+
*
|
|
1481
|
+
* - Inline image data (base64 / Uint8Array) is written via the
|
|
1482
|
+
* {@link FileWriter} and converted to `localImage` or `image` items.
|
|
1483
|
+
* - URL-based image file parts are converted directly.
|
|
1484
|
+
* - Inline text file data is decoded and inlined as text.
|
|
1485
|
+
* - Unsupported media types are silently skipped.
|
|
1486
|
+
*
|
|
1487
|
+
* @param isResume - When true only the last user message is extracted.
|
|
1488
|
+
* When false (fresh thread) all user text is accumulated with images
|
|
1489
|
+
* flushing the text buffer to preserve ordering.
|
|
1490
|
+
*/
|
|
1491
|
+
resolve(prompt: LanguageModelV3Prompt, isResume?: boolean): Promise<CodexTurnInputItem[]>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Remove all files created by previous {@link resolve} calls.
|
|
1494
|
+
* Best-effort — never throws.
|
|
1495
|
+
*/
|
|
1496
|
+
cleanup(): Promise<void>;
|
|
1497
|
+
/**
|
|
1498
|
+
* Convert a resolved image URL to a Codex input item.
|
|
1499
|
+
*/
|
|
1500
|
+
private mapImageUrl;
|
|
1501
|
+
/**
|
|
1502
|
+
* Resolve a single file part: write inline data via the writer, then
|
|
1503
|
+
* convert to a Codex input item. Text files are decoded and returned
|
|
1504
|
+
* as text items. Returns `null` for unsupported media types.
|
|
1505
|
+
*/
|
|
1506
|
+
private resolveFilePart;
|
|
1507
|
+
/**
|
|
1508
|
+
* Resume path: extract parts from the last user message individually.
|
|
1509
|
+
*/
|
|
1510
|
+
private resolveResumed;
|
|
1511
|
+
/**
|
|
1512
|
+
* Fresh thread path: accumulate text chunks across all user messages,
|
|
1513
|
+
* flushing before each image to preserve ordering.
|
|
1514
|
+
*/
|
|
1515
|
+
private resolveFresh;
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
export { type AgentMessageDeltaNotification, AppServerClient, type AppServerClientSettings, ApprovalsDispatcher, type ApprovalsDispatcherSettings, type AskForApproval, CODEX_PROVIDER_ID, type CodexCommandApprovalRequest, type CodexDynamicToolDefinition, CodexEventMapper, type CodexEventMapperInput, type CodexEventMapperOptions, type CodexFileChangeApprovalRequest, type CodexInitializeParams, type CodexInitializeResult, type CodexInitializedNotification, CodexLanguageModel, type CodexLanguageModelSettings, type CodexModelConfig, CodexNotImplementedError, type CodexNotification, type CodexProvider, CodexProviderError, type CodexProviderSettings, type CodexThreadDefaults, type CodexThreadResumeParams, type CodexThreadResumeResult, type CodexThreadStartParams, type CodexThreadStartResult, type CodexToolCallDeltaNotification, type CodexToolCallFinishedNotification, type CodexToolCallRequestParams, type CodexToolCallResult, type CodexToolCallStartedNotification, type CodexToolResultContentItem, type CodexTransport, type CodexTransportEventMap, type CodexTurnInputImage, type CodexTurnInputItem, type CodexTurnInputLocalImage, type CodexTurnInputMention, type CodexTurnInputSkill, type CodexTurnInputText, type CodexTurnStartParams, type CodexTurnStartResult, CodexWorker, CodexWorkerPool, type CodexWorkerPoolSettings, type CodexWorkerSettings, type CommandApprovalHandler, type CommandExecutionApprovalDecision, type CommandExecutionRequestApprovalParams, type CommandExecutionRequestApprovalResponse, type DynamicToolDefinition, type DynamicToolExecutionContext, type DynamicToolHandler, DynamicToolsDispatcher, type DynamicToolsDispatcherSettings, type FileChangeApprovalDecision, type FileChangeApprovalHandler, type FileChangeRequestApprovalParams, type FileChangeRequestApprovalResponse, type FileWriter, type ItemCompletedNotification, type ItemStartedNotification, JsonRpcError, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcMessageBase, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, LocalFileWriter, PACKAGE_NAME, PACKAGE_VERSION, type PendingToolCall, PersistentTransport, type PersistentTransportSettings, PromptFileResolver, type SandboxMode, StdioTransport, type StdioTransportSettings, type ThreadTokenUsageUpdatedNotification, type TurnCompletedNotification, type TurnStartedNotification, WebSocketTransport, type WebSocketTransportSettings, codexAppServer, codexProviderMetadata, createCodexAppServer, createCodexProvider, mapSystemPrompt, withProviderMetadata };
|